Android `adb shell dumpsys [service]` 命令是否有通用的手册页或文档?

Is there a generalized man page or documentation for the Android `adb shell dumpsys [service]` command?

问题

是否有 Android adb shell dumpsys [service] 命令的通用手册页或文档?我不是说 this 因为这似乎没有给出特定服务输出的细节,例如adb shell dumpsys backup

背景

我通读了 this question with regards to the dumpsys command in general, but it seems there is no link to any generalized documentation or man page. This answer stems from the user reading through the source C code and describing their observations, while this answer 似乎只是一些特定的 use-cases 用户认为有帮助。甚至有评论问

Is this from a document somewhere or just your own experimentation?

没有回复。

特别是,我来到之前链接的问题是因为我不确定我从 adb shell dumpsys backup 的输出中看到了什么。

Android docs状态:

To look up backup tokens, run adb shell dumpsys backup. The token is the hexadecimal string following the labels Ancestral: and Current:. The ancestral token refers to the backup dataset that was used to restore the device when it was initially setup (with the device-setup wizard). The current token refers to the device's current backup dataset (the dataset that the device is currently sending its backup data to).

我的输出的截断版本是:

Backup Manager is enabled / provisioned / not pending init
Auto-restore is enabled
Last backup pass started: 0 (now = 1575271089047)
  next scheduled: 1575281388106
Transport whitelist:
    android/com.android.internal.backup.LocalTransportService
    com.google.android.gms/.backup.component.D2dTransportService
    com.google.android.gms/.backup.BackupTransportService
Available transports:
    android/com.android.internal.backup.LocalTransport
       destination: Backing up to debug-only private cache
       intent: null
  * com.google.android.gms/.backup.BackupTransportService
       destination: *****@gmail.com
       intent: Intent { cmp=com.google.android.gms/.backup.SetBackupAccountActivity }
       @pm@ - 3794 state bytes
       com.google.android.dialer - 124 state bytes
       com.google.android.videos - 72 state bytes
       com.android.providers.settings - 76 state bytes
       ...
Pending init: 0
Ancestral: 0
Current:   39b423cbcb6862e5
Participants:
  uid: 1000
    com.android.providers.settings
    android
  uid: 1027
    com.android.nfc
  uid: 10004
    com.android.providers.userdictionary
    com.android.providers.blockednumber
    com.android.calllogbackup
  ...
Ancestral packages: none
Ever backed up: 66
    com.android.cellbroadcastreceiver
    com.allrecipes.spinner.free
    com.google.android.youtube
    ...
Pending key/value backup: 47
    BackupRequest{pkg=com.google.android.dialer}
    BackupRequest{pkg=com.google.android.videos}
    BackupRequest{pkg=com.android.cellbroadcastreceiver}
    ...
Full backup queue:68
    0 : com.jb.gokeyboard.langpack.ja
    0 : com.Splitwise.SplitwiseMobile
    1575154802432 : com.google.android.gsf.login
    1575156372751 : com.google.android.backuptransport
    1575159051168 : com.google.android.ext.services
    ...

Backup Manager is enabled / provisioned / not pending init
Auto-restore is enabled
Last backup pass started: 0 (now = 1575271089047)
  next scheduled: 1575281388106
Transport whitelist:
    android/com.android.internal.backup.LocalTransportService
    com.google.android.gms/.backup.component.D2dTransportService
    com.google.android.gms/.backup.BackupTransportService
Available transports:
    android/com.android.internal.backup.LocalTransport
       destination: Backing up to debug-only private cache
       intent: null
  * com.google.android.gms/.backup.BackupTransportService
       destination: *****@gmail.com
       intent: Intent { cmp=com.google.android.gms/.backup.SetBackupAccountActivity }
       @pm@ - 3794 state bytes
       com.google.android.dialer - 124 state bytes
       com.google.android.videos - 72 state bytes
       com.android.providers.settings - 76 state bytes
       ...
Pending init: 0
Ancestral: 0
Current:   39b423cbcb6862e5
Participants:
  uid: 1000
    com.android.providers.settings
    android
  uid: 1027
    com.android.nfc
  uid: 10004
    com.android.providers.userdictionary
    com.android.providers.blockednumber
    com.android.calllogbackup
  ...
Ancestral packages: none
Ever backed up: 66
    com.android.cellbroadcastreceiver
    com.allrecipes.spinner.free
    com.google.android.youtube
    ...
Pending key/value backup: 47
    BackupRequest{pkg=com.google.android.dialer}
    BackupRequest{pkg=com.google.android.videos}
    BackupRequest{pkg=com.android.cellbroadcastreceiver}
    ...
Full backup queue:68
    0 : com.jb.gokeyboard.langpack.ja
    0 : com.Splitwise.SplitwiseMobile
    1575154802432 : com.google.android.gsf.login
    1575156372751 : com.google.android.backuptransport
    1575159051168 : com.google.android.ext.services
    ...
Backup Manager is enabled / provisioned / not pending init
Auto-restore is enabled
Last backup pass started: 0 (now = 1575271089047)
  next scheduled: 1575281388106
Transport whitelist:
    android/com.android.internal.backup.LocalTransportService
    com.google.android.gms/.backup.component.D2dTransportService
    com.google.android.gms/.backup.BackupTransportService
Available transports:
    android/com.android.internal.backup.LocalTransport
       destination: Backing up to debug-only private cache
       intent: null
  * com.google.android.gms/.backup.BackupTransportService
       destination: *****@gmail.com
       intent: Intent { cmp=com.google.android.gms/.backup.SetBackupAccountActivity }
       @pm@ - 3794 state bytes
       com.google.android.dialer - 124 state bytes
       com.google.android.videos - 72 state bytes
       com.android.providers.settings - 76 state bytes
       ...
Pending init: 0
Ancestral: 0
Current:   39b423cbcb6862e5
Participants:
  uid: 1000
    com.android.providers.settings
    android
  uid: 1027
    com.android.nfc
  uid: 10004
    com.android.providers.userdictionary
    com.android.providers.blockednumber
    com.android.calllogbackup
  ...
Ancestral packages: none
Ever backed up: 66
    com.android.cellbroadcastreceiver
    com.allrecipes.spinner.free
    com.google.android.youtube
    ...
Pending key/value backup: 47
    BackupRequest{pkg=com.google.android.dialer}
    BackupRequest{pkg=com.google.android.videos}
    BackupRequest{pkg=com.android.cellbroadcastreceiver}
    ...
Full backup queue:68
    0 : com.jb.gokeyboard.langpack.ja
    0 : com.Splitwise.SplitwiseMobile
    1575154802432 : com.google.android.gsf.login
    1575156372751 : com.google.android.backuptransport
    1575159051168 : com.google.android.ext.services
    ...

上面引用的文字中提到的部分似乎有道理,但是有大量的附加信息我不确定如何处理。特别是,我正在寻找一种方法来验证备份了什么,什么没有备份,但是对于像 "Participants, Ancestral packages, Ever backed up, Pending key/value backup, Full backup queue" 这样的标题,我不确定什么是备份的,什么没有备份。

我试过 adb shell dumpsys backup -h 但这没有任何帮助:

$ adb shell dumpsys backup -h
'dumpsys backup' optional arguments:
  -h       : this help text
  a[gents] : dump information about defined backup agents

总结

我正在寻求 adb shell dumpsys backup 及其所有 headers 输出的解释。另外,是否有任何文档更详细地讨论这个问题?也许有 none,这就是为什么人们求助于阅读源代码代替它的原因?

我一直在寻找同样的东西,但运气不佳。但我发现了一堆我将在这里的答案中粘在一起的部分 - 没有完整性或“绝对正确性”的声明:我不是 Android 开发人员,只是一个狂热(高级)用户。在末尾(脚注)找到我的来源,并从片段中引用。我将根据 dumpsys backup 的输出结果对我发现的内容进行评论。


备份管理器状态

Backup Manager is enabled / provisioned / not pending init
Auto-restore is enabled
Last backup pass started: 0 (now = 1575271089047)
  next scheduled: 1575281388106

这部分应该比较清楚了。可以使用 bmgr enable 0|1 来(取消)激活备份管理器。停用后,不会进行任何备份(除非通过 adb backup 触发)。第 3+4 行中的值为 Unix timestamps0 除外,这仅表示尚未进行任何备份。

交通工具

Transport whitelist:
    android/com.android.internal.backup.LocalTransportService
    com.google.android.gms/.backup.component.D2dTransportService
    com.google.android.gms/.backup.BackupTransportService

这些是系统白名单传输[2])——尽管消息来源没有解释这意味着什么。它们似乎对应于下一个区块的“可用传输”。

Available transports:
    android/com.android.internal.backup.LocalTransport
       destination: Backing up to debug-only private cache
       intent: null
  * com.google.android.gms/.backup.BackupTransportService
       destination: *****@gmail.com
       intent: Intent { cmp=com.google.android.gms/.backup.SetBackupAccountActivity }
       @pm@ - 3794 state bytes
       com.google.android.dialer - 124 state bytes
       com.google.android.videos - 72 state bytes
       com.android.providers.settings - 76 state bytes
       ...

可用于备份的传输列表。 Google 云的 BackupTransportService 是默认的(由 * 标记),但需要在设备上设置帐户 ([1])(设备到设备传输也是如此D2dTransportService 在我看来)。据我了解,可以使用 bmgr transport <transportName> 更改默认值 – 并使用 bmgr run 运行 备份(对于所有待处理的备份到默认传输?)。

请注意,此列表对应于 bmgr list transports 的输出。本地备份 (LocalTransport) 似乎是由 adb backup.

触发的

代币

Pending init: 0
Ancestral: 0
Current:   39b423cbcb6862e5

引用来源 [5]:

To look up backup tokens, run adb shell dumpsys backup. The token is the hexidecimal string following the labels Ancestral: and Current:. The ancestral token refers to the backup dataset that was used to restore the device when it was initially setup (with the device-setup wizard). The current token refers to the device's current backup dataset (the dataset that the device is currently sending its backup data to).

这也应该解释“祖先包”(在输出中进一步向下)的含义。

可以请求备份的应用程序

Participants:
  uid: 1000
    com.android.providers.settings
    android
  uid: 1027
    com.android.nfc
  uid: 10004
    com.android.providers.userdictionary
    com.android.providers.blockednumber
    com.android.calllogbackup
  ...

参与者为可以请求备份的应用,按AID排序。 ([1])

备份统计

Ancestral packages: none

对于祖传包,请另见上文。我不知道如果有的话会是什么样子(但我假设类似于下面的 ever backed up);我自己 运行 我的 Android 设备“Google 免费”(LineageOS,没有 Google 应用程序),因此从未使用过这部分。关于这些的更多注意事项:它们似乎来自不是在同一设备上创建的备份集(或者至少不是来自相同的“迭代”,即如果它们来自同一物理设备,那是因为工厂-重启)。在 [2] 源代码的第 481 行,我们找到注释:

The ancestral work profile corresponds to the profile that was used to restore to the callers profile.

此外,在 [3] BackupManager 参考中:

The ancestral serial number will have a corresponding UserHandle if the device has a work profile that was restored from another work profile with serial number ancestralSerialNumber.

最后,在[4]备份指南中:

During the initial device setup wizard, the user is shown a list of available backup datasets and is asked which one to restore the data from. Whichever backup dataset is selected becomes the ancestral dataset for the device. The device can restore from either its own backups or the ancestral dataset. The device prioritize its own backup if backups from both sources are available. If the user didn't go through the device setup wizard, then the device can restore only from its own backups.

Ever backed up: 66
    com.android.cellbroadcastreceiver
    com.allrecipes.spinner.free
    com.google.android.youtube
    ...

这似乎不言自明:已经属于备份集的应用程序的数量和列表。

Pending key/value backup: 47
    BackupRequest{pkg=com.google.android.dialer}
    BackupRequest{pkg=com.google.android.videos}
    BackupRequest{pkg=com.android.cellbroadcastreceiver}
    ...

我没有找到这方面的参考,但从上面可以很好地猜测这些是“参与者”已经请求备份,他们的请求尚未得到处理。

Full backup queue:68
    0 : com.jb.gokeyboard.langpack.ja
    0 : com.Splitwise.SplitwiseMobile
    1575154802432 : com.google.android.gsf.login
    1575156372751 : com.google.android.backuptransport
    1575159051168 : com.google.android.ext.services
    ...

在这个 [1] 评论中,它是 Last backup : package name 的列表(Last backup 很可能又是一个 Unix 时间戳或 0 当它还没有被备份时).在设备上,备份队列位于 /data/backup.

中的设备上

我希望我能够阐明一些问题,以上信息对您(和其他人)有用。您可能会通过下面提到的来源找到更多详细信息——尤其是在扫描源代码时 ([2]),我可能遗漏了一些。

来源

  1. Android Internals::A Confectioner's Cookbook - WikiLeaks by Jonathan Levin. The relevant part is available as an excerpt: Application Backup & Restore; find details on the book's website
  2. Source code for BackupManagerService.java
  3. BackupManager Reference Manual
  4. Developer's guide on auto-backup
  5. Developer's guide on backup testing