// require frequent starting and stopping.
mConstants.start();
- // Set up the various sorts of package tracking we do
- mFullBackupScheduleFile = new File(mBaseStateDir, "fb-schedule");
- initPackageTracking();
-
// Build our mapping of uid to backup client services. This implicitly
// schedules a backup pass on the Package Manager metadata the first
// time anything needs to be backed up.
// Power management
mWakelock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*backup*-" + userId);
+
+ // Set up the various sorts of package tracking we do
+ mFullBackupScheduleFile = new File(mBaseStateDir, "fb-schedule");
+ initPackageTracking();
}
void initializeBackupEnableState() {
return mDataDir;
}
+ @VisibleForTesting
+ BroadcastReceiver getPackageTrackingReceiver() {
+ return mBroadcastReceiver;
+ }
+
@Nullable
public DataChangedJournal getJournal() {
return mJournal;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
import android.app.backup.BackupManager;
import android.app.backup.IBackupObserver;
import android.app.backup.ISelectBackupTransportCallback;
+import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.ContextWrapper;
import android.os.HandlerThread;
import android.os.PowerManager;
import android.os.PowerSaveState;
+import android.os.UserHandle;
import android.platform.test.annotations.Presubmit;
import android.provider.Settings;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
/* transportManager */ null));
}
+ /**
+ * Test verifying that creating a new instance registers the broadcast receiver for package
+ * tracking
+ */
+ @Test
+ public void testCreateAndInitializeService_registersPackageTrackingReceiver() throws Exception {
+ Context contextSpy = Mockito.spy(mContext);
+
+ UserBackupManagerService service = UserBackupManagerService.createAndInitializeService(
+ USER_ID,
+ contextSpy,
+ new Trampoline(mContext),
+ mBackupThread,
+ mBaseStateDir,
+ mDataDir,
+ mTransportManager);
+
+ BroadcastReceiver packageTrackingReceiver = service.getPackageTrackingReceiver();
+ assertThat(packageTrackingReceiver).isNotNull();
+
+ // One call for package changes and one call for sd card events.
+ verify(contextSpy, times(2)).registerReceiverAsUser(
+ eq(packageTrackingReceiver), eq(UserHandle.of(USER_ID)), any(), any(), any());
+ }
+
private UserBackupManagerService createUserBackupManagerServiceAndRunTasks() {
return BackupManagerServiceTestUtils.createUserBackupManagerServiceAndRunTasks(
USER_ID, mContext, mBackupThread, mBaseStateDir, mDataDir, mTransportManager);