Android BackupManager

主要源文件
BackupManagerService.java
Bmgr.java

配置文件指定默认transport
frameworks/base/packages/SettingsProvider/res/values/defaults.xml

gms默认配置

<string name="def_backup_transport">com.google.android.backup/.BackupTransportService</string>

AOSP默认配置transport: LocalTransport

<string name="def_backup_transport" translatable="false">android/com.android.internal.backup.LocalTransport</string>

其他参考

<service
android:name="com.android.internal.backup.LocalTransportService"
android:permission="android.permission.CONFIRM_FULL_BACKUP"
android:exported="false">

<intent-filter>
<action android:name="android.backup.TRANSPORT_HOST" />
</intent-filter>
</service>

BackupManagerService会从PackageManger中找到所有能接收android.backup.TRANSPORT_HOST的service,

List<ResolveInfo> hosts = mPackageManager.queryIntentServicesAsUser(
mTransportServiceIntent, 0, UserHandle.USER_OWNER);

之后就可以用bmgr list transports列出

shell@bg4ct_spruce:/ # bmgr list transports
android/com.android.internal.backup.LocalTransport
* com.google.android.gms/.backup.BackupTransportService


root@bg4ct_spruce:/ # bmgr enabled
Backup Manager currently disabled

root@bg4ct_spruce:/ # bmgr enable true
Backup Manager now enabled

切换android transport

bmgr transport android/com.android.internal.backup.LocalTransport