@Test public void testRestoreSome_for2Packages_createsSystemRestoreTask() throws Exception { mShadowApplication.grantPermissions(android.Manifest.permission.BACKUP); setUpTransport(mTransport); IRestoreSession restoreSession = createActiveRestoreSessionWithRestoreSets(null, mTransport, mRestoreSet1); restoreSession.restoreSome( TOKEN_1, mObserver, mMonitor, new String[] {PACKAGE_1, PACKAGE_2}); mShadowBackupLooper.runToEndOfTasks(); assertThat(ShadowPerformUnifiedRestoreTask.getLastCreated().isFullSystemRestore()).isTrue(); }
public synchronized int restoreSome(long token, IRestoreObserver observer, IBackupManagerMonitor monitor, String[] packages) { mBackupManagerService.getContext().enforceCallingOrSelfPermission( android.Manifest.permission.BACKUP, "performRestore"); if (DEBUG) { StringBuilder b = new StringBuilder(128); b.append("restoreSome token="); b.append(Long.toHexString(token)); b.append(" observer="); b.append(observer.toString()); b.append(" monitor="); if (monitor == null) { b.append("null"); } else { b.append(monitor.toString()); } b.append(" packages="); if (packages == null) { b.append("null"); } else { b.append('{'); boolean first = true; for (String s : packages) { if (!first) { b.append(", "); } else { first = false; } b.append(s); } b.append('}'); } Slog.d(TAG, b.toString()); } if (mEnded) { throw new IllegalStateException("Restore session already ended"); } if (mTimedOut) { Slog.i(TAG, "Session already timed out"); return -1; } if (mRestoreSets == null) { Slog.e(TAG, "Ignoring restoreAll() with no restore set"); return -1; } if (mPackageName != null) { Slog.e(TAG, "Ignoring restoreAll() on single-package session"); return -1; } if (!mTransportManager.isTransportRegistered(mTransportName)) { Slog.e(TAG, "Transport " + mTransportName + " not registered"); return -1; } synchronized (mBackupManagerService.getQueueLock()) { for (int i = 0; i < mRestoreSets.length; i++) { if (token == mRestoreSets[i].token) { long oldId = Binder.clearCallingIdentity(); try { return sendRestoreToHandlerLocked( (transportClient, listener) -> RestoreParams.createForRestoreSome( transportClient, observer, monitor, token, packages, packages.length > 1, listener), "RestoreSession.restoreSome(" + packages.length + " packages)"); } finally { Binder.restoreCallingIdentity(oldId); } } } } Slog.w(TAG, "Restore token " + Long.toHexString(token) + " not found"); return -1; }
ActiveRestoreSession extends IRestoreSession.Stub { public synchronized int restoreSome(long token, IRestoreObserver observer, IBackupManagerMonitor monitor, String[] packages) { mBackupManagerService.getContext().enforceCallingOrSelfPermission( android.Manifest.permission.BACKUP, "performRestore"); if (DEBUG) { StringBuilder b = new StringBuilder(128); b.append("restoreSome token="); b.append(Long.toHexString(token)); b.append(" observer="); b.append(observer.toString()); b.append(" monitor="); if (monitor == null) { b.append("null"); } else { b.append(monitor.toString()); } b.append(" packages="); if (packages == null) { b.append("null"); } else { b.append('{'); boolean first = true; for (String s : packages) { if (!first) { b.append(", "); } else { first = false; } b.append(s); } b.append('}'); } Slog.d(TAG, b.toString()); } if (mEnded) { throw new IllegalStateException("Restore session already ended"); } if (mTimedOut) { Slog.i(TAG, "Session already timed out"); return -1; } if (mRestoreSets == null) { Slog.e(TAG, "Ignoring restoreAll() with no restore set"); return -1; } if (mPackageName != null) { Slog.e(TAG, "Ignoring restoreAll() on single-package session"); return -1; } if (!mTransportManager.isTransportRegistered(mTransportName)) { Slog.e(TAG, "Transport " + mTransportName + " not registered"); return -1; } synchronized (mBackupManagerService.getQueueLock()) { for (int i = 0; i < mRestoreSets.length; i++) { if (token == mRestoreSets[i].token) { long oldId = Binder.clearCallingIdentity(); try { return sendRestoreToHandlerLocked( (transportClient, listener) -> RestoreParams.createForRestoreSome( transportClient, observer, monitor, token, packages, packages.length > 1, listener), "RestoreSession.restoreSome(" + packages.length + " packages)"); } finally { Binder.restoreCallingIdentity(oldId); } } } } Slog.w(TAG, "Restore token " + Long.toHexString(token) + " not found"); return -1; } }
ActiveRestoreSession extends IRestoreSession.Stub { public synchronized int restoreSome(long token, IRestoreObserver observer, IBackupManagerMonitor monitor, String[] packages) { mBackupManagerService.getContext().enforceCallingOrSelfPermission( android.Manifest.permission.BACKUP, "performRestore"); if (DEBUG) { StringBuilder b = new StringBuilder(128); b.append("restoreSome token="); b.append(Long.toHexString(token)); b.append(" observer="); b.append(observer.toString()); b.append(" monitor="); if (monitor == null) { b.append("null"); } else { b.append(monitor.toString()); } b.append(" packages="); if (packages == null) { b.append("null"); } else { b.append('{'); boolean first = true; for (String s : packages) { if (!first) { b.append(", "); } else { first = false; } b.append(s); } b.append('}'); } Slog.d(TAG, b.toString()); } if (mEnded) { throw new IllegalStateException("Restore session already ended"); } if (mTimedOut) { Slog.i(TAG, "Session already timed out"); return -1; } if (mRestoreSets == null) { Slog.e(TAG, "Ignoring restoreAll() with no restore set"); return -1; } if (mPackageName != null) { Slog.e(TAG, "Ignoring restoreAll() on single-package session"); return -1; } if (!mTransportManager.isTransportRegistered(mTransportName)) { Slog.e(TAG, "Transport " + mTransportName + " not registered"); return -1; } synchronized (mBackupManagerService.getQueueLock()) { for (int i = 0; i < mRestoreSets.length; i++) { if (token == mRestoreSets[i].token) { long oldId = Binder.clearCallingIdentity(); try { return sendRestoreToHandlerLocked( (transportClient, listener) -> RestoreParams.createForRestoreSome( transportClient, observer, monitor, token, packages, packages.length > 1, listener), "RestoreSession.restoreSome(" + packages.length + " packages)"); } finally { Binder.restoreCallingIdentity(oldId); } } } } Slog.w(TAG, "Restore token " + Long.toHexString(token) + " not found"); return -1; } ActiveRestoreSession(
            BackupManagerService backupManagerService,
            @Nullable String packageName,
            String transportName); }
ActiveRestoreSession extends IRestoreSession.Stub { public synchronized int restoreSome(long token, IRestoreObserver observer, IBackupManagerMonitor monitor, String[] packages) { mBackupManagerService.getContext().enforceCallingOrSelfPermission( android.Manifest.permission.BACKUP, "performRestore"); if (DEBUG) { StringBuilder b = new StringBuilder(128); b.append("restoreSome token="); b.append(Long.toHexString(token)); b.append(" observer="); b.append(observer.toString()); b.append(" monitor="); if (monitor == null) { b.append("null"); } else { b.append(monitor.toString()); } b.append(" packages="); if (packages == null) { b.append("null"); } else { b.append('{'); boolean first = true; for (String s : packages) { if (!first) { b.append(", "); } else { first = false; } b.append(s); } b.append('}'); } Slog.d(TAG, b.toString()); } if (mEnded) { throw new IllegalStateException("Restore session already ended"); } if (mTimedOut) { Slog.i(TAG, "Session already timed out"); return -1; } if (mRestoreSets == null) { Slog.e(TAG, "Ignoring restoreAll() with no restore set"); return -1; } if (mPackageName != null) { Slog.e(TAG, "Ignoring restoreAll() on single-package session"); return -1; } if (!mTransportManager.isTransportRegistered(mTransportName)) { Slog.e(TAG, "Transport " + mTransportName + " not registered"); return -1; } synchronized (mBackupManagerService.getQueueLock()) { for (int i = 0; i < mRestoreSets.length; i++) { if (token == mRestoreSets[i].token) { long oldId = Binder.clearCallingIdentity(); try { return sendRestoreToHandlerLocked( (transportClient, listener) -> RestoreParams.createForRestoreSome( transportClient, observer, monitor, token, packages, packages.length > 1, listener), "RestoreSession.restoreSome(" + packages.length + " packages)"); } finally { Binder.restoreCallingIdentity(oldId); } } } } Slog.w(TAG, "Restore token " + Long.toHexString(token) + " not found"); return -1; } ActiveRestoreSession(
            BackupManagerService backupManagerService,
            @Nullable String packageName,
            String transportName); void markTimedOut(); synchronized int getAvailableRestoreSets(IRestoreObserver observer,
            IBackupManagerMonitor monitor); synchronized int restoreAll(long token, IRestoreObserver observer,
            IBackupManagerMonitor monitor); synchronized int restoreSome(long token, IRestoreObserver observer,
            IBackupManagerMonitor monitor, String[] packages); synchronized int restorePackage(String packageName, IRestoreObserver observer,
            IBackupManagerMonitor monitor); void setRestoreSets(RestoreSet[] restoreSets); synchronized void endRestoreSession(); }
ActiveRestoreSession extends IRestoreSession.Stub { public synchronized int restoreSome(long token, IRestoreObserver observer, IBackupManagerMonitor monitor, String[] packages) { mBackupManagerService.getContext().enforceCallingOrSelfPermission( android.Manifest.permission.BACKUP, "performRestore"); if (DEBUG) { StringBuilder b = new StringBuilder(128); b.append("restoreSome token="); b.append(Long.toHexString(token)); b.append(" observer="); b.append(observer.toString()); b.append(" monitor="); if (monitor == null) { b.append("null"); } else { b.append(monitor.toString()); } b.append(" packages="); if (packages == null) { b.append("null"); } else { b.append('{'); boolean first = true; for (String s : packages) { if (!first) { b.append(", "); } else { first = false; } b.append(s); } b.append('}'); } Slog.d(TAG, b.toString()); } if (mEnded) { throw new IllegalStateException("Restore session already ended"); } if (mTimedOut) { Slog.i(TAG, "Session already timed out"); return -1; } if (mRestoreSets == null) { Slog.e(TAG, "Ignoring restoreAll() with no restore set"); return -1; } if (mPackageName != null) { Slog.e(TAG, "Ignoring restoreAll() on single-package session"); return -1; } if (!mTransportManager.isTransportRegistered(mTransportName)) { Slog.e(TAG, "Transport " + mTransportName + " not registered"); return -1; } synchronized (mBackupManagerService.getQueueLock()) { for (int i = 0; i < mRestoreSets.length; i++) { if (token == mRestoreSets[i].token) { long oldId = Binder.clearCallingIdentity(); try { return sendRestoreToHandlerLocked( (transportClient, listener) -> RestoreParams.createForRestoreSome( transportClient, observer, monitor, token, packages, packages.length > 1, listener), "RestoreSession.restoreSome(" + packages.length + " packages)"); } finally { Binder.restoreCallingIdentity(oldId); } } } } Slog.w(TAG, "Restore token " + Long.toHexString(token) + " not found"); return -1; } ActiveRestoreSession(
            BackupManagerService backupManagerService,
            @Nullable String packageName,
            String transportName); void markTimedOut(); synchronized int getAvailableRestoreSets(IRestoreObserver observer,
            IBackupManagerMonitor monitor); synchronized int restoreAll(long token, IRestoreObserver observer,
            IBackupManagerMonitor monitor); synchronized int restoreSome(long token, IRestoreObserver observer,
            IBackupManagerMonitor monitor, String[] packages); synchronized int restorePackage(String packageName, IRestoreObserver observer,
            IBackupManagerMonitor monitor); void setRestoreSets(RestoreSet[] restoreSets); synchronized void endRestoreSession(); public RestoreSet[] mRestoreSets; }