@Test public void testGetAvailableRestoreSets_forEmptyRestoreSets() throws Exception { mShadowApplication.grantPermissions(android.Manifest.permission.BACKUP); TransportMock transportMock = setUpTransport(mTransport); when(transportMock.transport.getAvailableRestoreSets()).thenReturn(new RestoreSet[0]); IRestoreSession restoreSession = createActiveRestoreSession(PACKAGE_1, mTransport); int result = restoreSession.getAvailableRestoreSets(mObserver, mMonitor); mShadowBackupLooper.runToEndOfTasks(); assertThat(result).isEqualTo(0); verify(mObserver).restoreSetsAvailable(aryEq(new RestoreSet[0])); assertThat(ShadowEventLog.hasEvent(EventLogTags.RESTORE_TRANSPORT_FAILURE)).isFalse(); }
public synchronized int getAvailableRestoreSets(IRestoreObserver observer, IBackupManagerMonitor monitor) { mBackupManagerService.getContext().enforceCallingOrSelfPermission( android.Manifest.permission.BACKUP, "getAvailableRestoreSets"); if (observer == null) { throw new IllegalArgumentException("Observer must not be null"); } if (mEnded) { throw new IllegalStateException("Restore session already ended"); } if (mTimedOut) { Slog.i(TAG, "Session already timed out"); return -1; } long oldId = Binder.clearCallingIdentity(); try { TransportClient transportClient = mTransportManager.getTransportClient( mTransportName, "RestoreSession.getAvailableRestoreSets()"); if (transportClient == null) { Slog.w(TAG, "Null transport client getting restore sets"); return -1; } mBackupManagerService.getBackupHandler().removeMessages(MSG_RESTORE_SESSION_TIMEOUT); PowerManager.WakeLock wakelock = mBackupManagerService.getWakelock(); wakelock.acquire(); TransportManager transportManager = mTransportManager; OnTaskFinishedListener listener = caller -> { transportManager.disposeOfTransportClient(transportClient, caller); wakelock.release(); }; Message msg = mBackupManagerService.getBackupHandler().obtainMessage( MSG_RUN_GET_RESTORE_SETS, new RestoreGetSetsParams(transportClient, this, observer, monitor, listener)); mBackupManagerService.getBackupHandler().sendMessage(msg); return 0; } catch (Exception e) { Slog.e(TAG, "Error in getAvailableRestoreSets", e); return -1; } finally { Binder.restoreCallingIdentity(oldId); } }
ActiveRestoreSession extends IRestoreSession.Stub { public synchronized int getAvailableRestoreSets(IRestoreObserver observer, IBackupManagerMonitor monitor) { mBackupManagerService.getContext().enforceCallingOrSelfPermission( android.Manifest.permission.BACKUP, "getAvailableRestoreSets"); if (observer == null) { throw new IllegalArgumentException("Observer must not be null"); } if (mEnded) { throw new IllegalStateException("Restore session already ended"); } if (mTimedOut) { Slog.i(TAG, "Session already timed out"); return -1; } long oldId = Binder.clearCallingIdentity(); try { TransportClient transportClient = mTransportManager.getTransportClient( mTransportName, "RestoreSession.getAvailableRestoreSets()"); if (transportClient == null) { Slog.w(TAG, "Null transport client getting restore sets"); return -1; } mBackupManagerService.getBackupHandler().removeMessages(MSG_RESTORE_SESSION_TIMEOUT); PowerManager.WakeLock wakelock = mBackupManagerService.getWakelock(); wakelock.acquire(); TransportManager transportManager = mTransportManager; OnTaskFinishedListener listener = caller -> { transportManager.disposeOfTransportClient(transportClient, caller); wakelock.release(); }; Message msg = mBackupManagerService.getBackupHandler().obtainMessage( MSG_RUN_GET_RESTORE_SETS, new RestoreGetSetsParams(transportClient, this, observer, monitor, listener)); mBackupManagerService.getBackupHandler().sendMessage(msg); return 0; } catch (Exception e) { Slog.e(TAG, "Error in getAvailableRestoreSets", e); return -1; } finally { Binder.restoreCallingIdentity(oldId); } } }
ActiveRestoreSession extends IRestoreSession.Stub { public synchronized int getAvailableRestoreSets(IRestoreObserver observer, IBackupManagerMonitor monitor) { mBackupManagerService.getContext().enforceCallingOrSelfPermission( android.Manifest.permission.BACKUP, "getAvailableRestoreSets"); if (observer == null) { throw new IllegalArgumentException("Observer must not be null"); } if (mEnded) { throw new IllegalStateException("Restore session already ended"); } if (mTimedOut) { Slog.i(TAG, "Session already timed out"); return -1; } long oldId = Binder.clearCallingIdentity(); try { TransportClient transportClient = mTransportManager.getTransportClient( mTransportName, "RestoreSession.getAvailableRestoreSets()"); if (transportClient == null) { Slog.w(TAG, "Null transport client getting restore sets"); return -1; } mBackupManagerService.getBackupHandler().removeMessages(MSG_RESTORE_SESSION_TIMEOUT); PowerManager.WakeLock wakelock = mBackupManagerService.getWakelock(); wakelock.acquire(); TransportManager transportManager = mTransportManager; OnTaskFinishedListener listener = caller -> { transportManager.disposeOfTransportClient(transportClient, caller); wakelock.release(); }; Message msg = mBackupManagerService.getBackupHandler().obtainMessage( MSG_RUN_GET_RESTORE_SETS, new RestoreGetSetsParams(transportClient, this, observer, monitor, listener)); mBackupManagerService.getBackupHandler().sendMessage(msg); return 0; } catch (Exception e) { Slog.e(TAG, "Error in getAvailableRestoreSets", e); return -1; } finally { Binder.restoreCallingIdentity(oldId); } } ActiveRestoreSession(
            BackupManagerService backupManagerService,
            @Nullable String packageName,
            String transportName); }
ActiveRestoreSession extends IRestoreSession.Stub { public synchronized int getAvailableRestoreSets(IRestoreObserver observer, IBackupManagerMonitor monitor) { mBackupManagerService.getContext().enforceCallingOrSelfPermission( android.Manifest.permission.BACKUP, "getAvailableRestoreSets"); if (observer == null) { throw new IllegalArgumentException("Observer must not be null"); } if (mEnded) { throw new IllegalStateException("Restore session already ended"); } if (mTimedOut) { Slog.i(TAG, "Session already timed out"); return -1; } long oldId = Binder.clearCallingIdentity(); try { TransportClient transportClient = mTransportManager.getTransportClient( mTransportName, "RestoreSession.getAvailableRestoreSets()"); if (transportClient == null) { Slog.w(TAG, "Null transport client getting restore sets"); return -1; } mBackupManagerService.getBackupHandler().removeMessages(MSG_RESTORE_SESSION_TIMEOUT); PowerManager.WakeLock wakelock = mBackupManagerService.getWakelock(); wakelock.acquire(); TransportManager transportManager = mTransportManager; OnTaskFinishedListener listener = caller -> { transportManager.disposeOfTransportClient(transportClient, caller); wakelock.release(); }; Message msg = mBackupManagerService.getBackupHandler().obtainMessage( MSG_RUN_GET_RESTORE_SETS, new RestoreGetSetsParams(transportClient, this, observer, monitor, listener)); mBackupManagerService.getBackupHandler().sendMessage(msg); return 0; } catch (Exception e) { Slog.e(TAG, "Error in getAvailableRestoreSets", e); return -1; } finally { Binder.restoreCallingIdentity(oldId); } } 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 getAvailableRestoreSets(IRestoreObserver observer, IBackupManagerMonitor monitor) { mBackupManagerService.getContext().enforceCallingOrSelfPermission( android.Manifest.permission.BACKUP, "getAvailableRestoreSets"); if (observer == null) { throw new IllegalArgumentException("Observer must not be null"); } if (mEnded) { throw new IllegalStateException("Restore session already ended"); } if (mTimedOut) { Slog.i(TAG, "Session already timed out"); return -1; } long oldId = Binder.clearCallingIdentity(); try { TransportClient transportClient = mTransportManager.getTransportClient( mTransportName, "RestoreSession.getAvailableRestoreSets()"); if (transportClient == null) { Slog.w(TAG, "Null transport client getting restore sets"); return -1; } mBackupManagerService.getBackupHandler().removeMessages(MSG_RESTORE_SESSION_TIMEOUT); PowerManager.WakeLock wakelock = mBackupManagerService.getWakelock(); wakelock.acquire(); TransportManager transportManager = mTransportManager; OnTaskFinishedListener listener = caller -> { transportManager.disposeOfTransportClient(transportClient, caller); wakelock.release(); }; Message msg = mBackupManagerService.getBackupHandler().obtainMessage( MSG_RUN_GET_RESTORE_SETS, new RestoreGetSetsParams(transportClient, this, observer, monitor, listener)); mBackupManagerService.getBackupHandler().sendMessage(msg); return 0; } catch (Exception e) { Slog.e(TAG, "Error in getAvailableRestoreSets", e); return -1; } finally { Binder.restoreCallingIdentity(oldId); } } 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; }