It would be helpful to be more explicit in what you're doing, like specific adb commands, although I think I'm running into the same issue.
I believe what's happening in your situation is that you're (unintentionally) taking a backup of the Owner user. Since you are in the secondary user profile, you will not see the prompt to start the backup for the Owner user. So adb hangs waiting for a confirmation that you never see.
An important thing to note is that adb sessions always run in the context of the Owner user. So if you are not passing a user id to the backup process, it will be doing a backup of the Owner profile.
So how does one initiate a backup/restore to a non-Owner profile? It helps to know that the adb backup and restore commands end up executing bu
on the system. When you run bu help
from the adb shell here's the output I get:
sunfish:/ $ bu help
backup [-user USER_ID] [-f FILE] [-apk|-noapk] [-obb|-noobb] [-shared|-noshared]
[-all] [-system|-nosystem] [-keyvalue|-nokeyvalue] [PACKAGE...]
write an archive of the device's data to FILE [default=backup.adb]
package list optional if -all/-shared are supplied
-user: user ID for which to perform the operation (default - system user)
-apk/-noapk: do/don't back up .apk files (default -noapk)
-obb/-noobb: do/don't back up .obb files (default -noobb)
-shared|-noshared: do/don't back up shared storage (default -noshared)
-all: back up all installed applications
-system|-nosystem: include system apps in -all (default -system)
-keyvalue|-nokeyvalue: include apps that perform key/value backups.
(default -nokeyvalue)
restore [-user USER_ID] FILE restore device contents from FILE
-user: user ID for which to perform the operation (default - system user)
Okay great, so apparently there is a -user
option. Great! So now I try running a restore for a secondary user from adb and here's what I get:
$ ./platform-tools/adb restore -user 11 <path to android backup>
WARNING: adb restore is deprecated and may be removed in a future release
adb: restore requires an argument
Okay, maybe its finicky and wants the backup file as the first argument. But this results in the same output. I haven't figured out why adb won't take the -user
argument.
But there's another option, we can run bu
directly from the adb shell. Unfortunately, I've yet to get this to work either, but I get farther along. I first upload the backup to the Owner profile and run bu
from the Owner profile using the adb shell. I know of no way to get an adb shell on a non-Owner profile. This shouldn't be a problem though because that's what the -user
argument is for. I've tried two scenarios to no avail.
- Run
bu -user <uid> <backup file>
while logged in to the profile of that uid, in this case uid 11. I see no restore confirmation prompt or anything visually happen. Here are relevant logcat lines:
03-14 17:58:29.286 11753 11753 D AndroidRuntime: Calling main entry com.android.commands.bu.Backup
03-14 17:58:29.288 11753 11753 D bu : Beginning: restore
03-14 17:58:29.289 1493 1731 I BackupManagerService: [UserID:11] Beginning restore...
03-14 17:58:29.289 1493 1731 D BackupManagerService: [UserID:11] Starting restore confirmation UI, token=30388736403-14 17:58:29.289 1493 1731 I ActivityTaskManager: START u0 {act=fullrest flg=0x20000000 cmp=com.android.backupconfirm/.BackupRestoreConfirmation (has extras)} from uid 1000
03-14 17:58:29.289 1493 1731 W ActivityTaskManager: startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent {act=fullrest flg=0x20800000 cmp=com.android.backupconfirm/.BackupRestoreConfirmation (has extras) }
03-14 17:58:29.293 1493 1731 D BackupManagerService: [UserID:11] Waiting for restore completion...
03-14 17:59:29.388 1493 25093 I BackupManagerService: Full backup/restore timedout waiting for user confirmation
03-14 17:59:29.388 1493 1731 I BackupManagerService: [UserID:11] adb restore processing complete.
03-14 17:59:29.388 11753 11753 D bu : Finished.
As can be seen, the BackupManagerService knows that I'm requesting a restore of uid 11. Also it says its starting the confirmation UI, even though I see nothing come up. Eventually the requests times out.
- Run
bu -user <uid> <backup file>
while logged in to the Owner profile. Here are relevant logcat lines:
03-14 18:00:39.448 11948 11948 D AndroidRuntime: Calling main entry com.android.commands.bu.Backup
03-14 18:00:39.450 11948 11948 D bu : Beginning: restore
03-14 18:00:39.451 1493 2786 I BackupManagerService: [UserID:11] Beginning restore...
03-14 18:00:39.451 1493 2786 D BackupManagerService: [UserID:11] Starting restore confirmation UI, token=606614021
03-14 18:00:39.451 1493 2786 I ActivityTaskManager: START u0 {act=fullrest flg=0x20000000 cmp=com.android.backupconfirm/.BackupRestoreConfirmation (has extras)} from uid 1000
03-14 18:00:39.451 1493 2786 W ActivityTaskManager: startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { act=fullrest flg=0x20800000 cmp=com.android.backupconfirm/.BackupRestoreConfirmation (has extras) }
03-14 18:00:39.459 1493 1994 W ActivityTaskManager: Tried to set launchTime (0) < mLastActivityLaunchTime (22366588)
03-14 18:00:39.462 1493 2786 D BackupManagerService: [UserID:11] Waiting for restore completion...
03-14 18:00:39.572 1493 1757 I ActivityTaskManager: Displayed com.android.backupconfirm/.BackupRestoreConfirmation: +112ms
03-14 18:00:43.431 1493 5565 D BackupManagerService: [UserID:0] acknowledgeAdbBackupOrRestore : token=606614021 allow=true
03-14 18:00:43.432 1493 5565 W BackupManagerService: [UserID:0] Attempted to ack full backup/restore with invalid token
03-14 18:00:46.213 1493 2063 D InputDispatcher: Waiting to send key to Window{200410c u0 com.android.backupconfirm/com.android.backupconfirm.BackupRestoreConfirmation} because there are unprocessed events that may cause focus to change
03-14 18:01:39.563 1493 25093 I BackupManagerService: Full backup/restore timed out waiting for user confirmation
03-14 18:01:39.563 1493 2786 I BackupManagerService: [UserID:11] adb restore processing complete.
03-14 18:01:39.564 11948 11948 D bu : Finished.
As in the first attempt, we see that the BackupManagerService is trying to do a restore for uid 11. It starts the confirmation UI, which does pop up. I then confirm the restore. But then we see that its uid 0 which confirms the restore and I believe that's why the resulting token is invalid. Makes sense, why should one profile be able to cnofirm the backup/restore of another? (make a little more sense for the Owner profile to be able to do that)
So I think I've hit a roadblock here. I'm not sure how to get the confirmation UI to run in the correct user. I suspect this has (still!) not been tested by the android community, though why have a -user
option at all?
Here are some other log messages that may be clues to a way forward:
03-14 18:00:28.422 1493 5597 W WindowManager: Attempted to set replacing window on app token with no content Token{b3c5879 ActivityRecord{23cb9be u0 com.android.backupconfirm/.BackupRestoreConfirmation t1100006}}
03-14 18:00:28.610 1493 2786 I ActivityTaskManager: Activity reported stop, but no longer stopping: ActivityRecord{23cb9be u0 com.android.backupconfirm/.BackupRestoreConfirmation t1100006}
03-14 18:00:37.042 1493 2063 D InputDispatcher: Waiting to send key to Window{6f7d966 u0 com.android.backupconfirm/com.android.backupconfirm.BackupRestoreConfirmation} because there are unprocessed events that may cause focus to change
adb devices
list the Nexus?adb devices
- but when I runadb backup...
and it says "unlock your device and confirm..." nothing is ever displayed on the tablet. Again, as owner the message is displayed and the backup works.