summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/backup/java/com/android/server/backup/BackupAgentTimeoutParameters.java15
-rw-r--r--services/backup/java/com/android/server/backup/BackupManagerConstants.java19
-rw-r--r--services/backup/java/com/android/server/backup/FileMetadata.java2
-rw-r--r--services/backup/java/com/android/server/backup/FullBackupJob.java4
-rw-r--r--services/backup/java/com/android/server/backup/GlobalBackupManagerService.java633
-rw-r--r--services/backup/java/com/android/server/backup/KeyValueAdbBackupEngine.java9
-rw-r--r--services/backup/java/com/android/server/backup/KeyValueAdbRestoreEngine.java4
-rw-r--r--services/backup/java/com/android/server/backup/KeyValueBackupJob.java6
-rw-r--r--services/backup/java/com/android/server/backup/ProcessedPackagesJournal.java4
-rw-r--r--services/backup/java/com/android/server/backup/Trampoline.java109
-rw-r--r--services/backup/java/com/android/server/backup/UserBackupManagerService.java (renamed from services/backup/java/com/android/server/backup/BackupManagerService.java)182
-rw-r--r--services/backup/java/com/android/server/backup/fullbackup/AppMetadataBackupWriter.java10
-rw-r--r--services/backup/java/com/android/server/backup/fullbackup/FullBackupEngine.java20
-rw-r--r--services/backup/java/com/android/server/backup/fullbackup/FullBackupObbConnection.java12
-rw-r--r--services/backup/java/com/android/server/backup/fullbackup/FullBackupTask.java2
-rw-r--r--services/backup/java/com/android/server/backup/fullbackup/PerformAdbBackupTask.java18
-rw-r--r--services/backup/java/com/android/server/backup/fullbackup/PerformFullTransportBackupTask.java20
-rw-r--r--services/backup/java/com/android/server/backup/internal/BackupHandler.java12
-rw-r--r--services/backup/java/com/android/server/backup/internal/ClearDataObserver.java6
-rw-r--r--services/backup/java/com/android/server/backup/internal/PerformClearTask.java8
-rw-r--r--services/backup/java/com/android/server/backup/internal/PerformInitializeTask.java10
-rw-r--r--services/backup/java/com/android/server/backup/internal/ProvisionedObserver.java10
-rw-r--r--services/backup/java/com/android/server/backup/internal/RunBackupReceiver.java14
-rw-r--r--services/backup/java/com/android/server/backup/internal/RunInitializeReceiver.java12
-rw-r--r--services/backup/java/com/android/server/backup/keyvalue/KeyValueBackupReporter.java11
-rw-r--r--services/backup/java/com/android/server/backup/keyvalue/KeyValueBackupTask.java39
-rw-r--r--services/backup/java/com/android/server/backup/remote/ServiceBackupCallback.java6
-rw-r--r--services/backup/java/com/android/server/backup/restore/ActiveRestoreSession.java14
-rw-r--r--services/backup/java/com/android/server/backup/restore/AdbRestoreFinishedLatch.java10
-rw-r--r--services/backup/java/com/android/server/backup/restore/AdbRestoreFinishedRunnable.java6
-rw-r--r--services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java21
-rw-r--r--services/backup/java/com/android/server/backup/restore/PerformAdbRestoreTask.java26
-rw-r--r--services/backup/java/com/android/server/backup/restore/PerformUnifiedRestoreTask.java22
-rw-r--r--services/backup/java/com/android/server/backup/restore/RestoreFileRunnable.java6
-rw-r--r--services/backup/java/com/android/server/backup/utils/AppBackupUtils.java6
-rw-r--r--services/backup/java/com/android/server/backup/utils/BackupManagerMonitorUtils.java4
-rw-r--r--services/backup/java/com/android/server/backup/utils/BackupObserverUtils.java4
-rw-r--r--services/backup/java/com/android/server/backup/utils/FullBackupRestoreObserverUtils.java2
-rw-r--r--services/backup/java/com/android/server/backup/utils/FullBackupUtils.java2
-rw-r--r--services/backup/java/com/android/server/backup/utils/PasswordUtils.java2
-rw-r--r--services/backup/java/com/android/server/backup/utils/RestoreUtils.java4
-rw-r--r--services/backup/java/com/android/server/backup/utils/TarBackupReader.java16
-rw-r--r--services/java/com/android/server/SystemServer.java2
-rw-r--r--services/robotests/src/com/android/server/backup/GlobalBackupManagerServiceTest.java525
-rw-r--r--services/robotests/src/com/android/server/backup/UserBackupManagerServiceTest.java (renamed from services/robotests/src/com/android/server/backup/BackupManagerServiceTest.java)251
-rw-r--r--services/robotests/src/com/android/server/backup/fullbackup/AppMetadataBackupWriterTest.java10
-rw-r--r--services/robotests/src/com/android/server/backup/internal/PerformInitializeTaskTest.java9
-rw-r--r--services/robotests/src/com/android/server/backup/keyvalue/KeyValueBackupReporterTest.java4
-rw-r--r--services/robotests/src/com/android/server/backup/keyvalue/KeyValueBackupTaskTest.java14
-rw-r--r--services/robotests/src/com/android/server/backup/restore/ActiveRestoreSessionTest.java4
-rw-r--r--services/robotests/src/com/android/server/backup/testing/BackupManagerServiceTestUtils.java21
-rw-r--r--services/robotests/src/com/android/server/testing/shadows/ShadowKeyValueBackupTask.java4
-rw-r--r--services/robotests/src/com/android/server/testing/shadows/ShadowPerformUnifiedRestoreTask.java6
-rw-r--r--services/tests/servicestests/src/com/android/server/backup/TrampolineTest.java6
-rw-r--r--services/tests/servicestests/src/com/android/server/backup/utils/AppBackupUtilsTest.java4
-rw-r--r--services/tests/servicestests/src/com/android/server/backup/utils/TarBackupReaderTest.java4
56 files changed, 1602 insertions, 604 deletions
diff --git a/services/backup/java/com/android/server/backup/BackupAgentTimeoutParameters.java b/services/backup/java/com/android/server/backup/BackupAgentTimeoutParameters.java
index df46d260b961..ab639c3c9ce1 100644
--- a/services/backup/java/com/android/server/backup/BackupAgentTimeoutParameters.java
+++ b/services/backup/java/com/android/server/backup/BackupAgentTimeoutParameters.java
@@ -16,12 +16,15 @@
package com.android.server.backup;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG_SCHEDULING;
+
import android.content.ContentResolver;
import android.os.Handler;
import android.provider.Settings;
import android.util.KeyValueListParser;
import android.util.KeyValueSettingObserver;
import android.util.Slog;
+
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
@@ -137,7 +140,7 @@ public class BackupAgentTimeoutParameters extends KeyValueSettingObserver {
public long getKvBackupAgentTimeoutMillis() {
synchronized (mLock) {
- if (BackupManagerService.DEBUG_SCHEDULING) {
+ if (DEBUG_SCHEDULING) {
Slog.v(TAG, "getKvBackupAgentTimeoutMillis(): " + mKvBackupAgentTimeoutMillis);
}
return mKvBackupAgentTimeoutMillis;
@@ -146,7 +149,7 @@ public class BackupAgentTimeoutParameters extends KeyValueSettingObserver {
public long getFullBackupAgentTimeoutMillis() {
synchronized (mLock) {
- if (BackupManagerService.DEBUG_SCHEDULING) {
+ if (DEBUG_SCHEDULING) {
Slog.v(TAG, "getFullBackupAgentTimeoutMillis(): " + mFullBackupAgentTimeoutMillis);
}
return mFullBackupAgentTimeoutMillis;
@@ -155,7 +158,7 @@ public class BackupAgentTimeoutParameters extends KeyValueSettingObserver {
public long getSharedBackupAgentTimeoutMillis() {
synchronized (mLock) {
- if (BackupManagerService.DEBUG_SCHEDULING) {
+ if (DEBUG_SCHEDULING) {
Slog.v(
TAG,
"getSharedBackupAgentTimeoutMillis(): " + mSharedBackupAgentTimeoutMillis);
@@ -166,7 +169,7 @@ public class BackupAgentTimeoutParameters extends KeyValueSettingObserver {
public long getRestoreAgentTimeoutMillis() {
synchronized (mLock) {
- if (BackupManagerService.DEBUG_SCHEDULING) {
+ if (DEBUG_SCHEDULING) {
Slog.v(TAG, "getRestoreAgentTimeoutMillis(): " + mRestoreAgentTimeoutMillis);
}
return mRestoreAgentTimeoutMillis;
@@ -175,7 +178,7 @@ public class BackupAgentTimeoutParameters extends KeyValueSettingObserver {
public long getRestoreAgentFinishedTimeoutMillis() {
synchronized (mLock) {
- if (BackupManagerService.DEBUG_SCHEDULING) {
+ if (DEBUG_SCHEDULING) {
Slog.v(
TAG,
"getRestoreAgentFinishedTimeoutMillis(): "
@@ -187,7 +190,7 @@ public class BackupAgentTimeoutParameters extends KeyValueSettingObserver {
public long getQuotaExceededTimeoutMillis() {
synchronized (mLock) {
- if (BackupManagerService.DEBUG_SCHEDULING) {
+ if (DEBUG_SCHEDULING) {
Slog.v(
TAG,
"getQuotaExceededTimeoutMillis(): "
diff --git a/services/backup/java/com/android/server/backup/BackupManagerConstants.java b/services/backup/java/com/android/server/backup/BackupManagerConstants.java
index ec219615dfd4..e3fa0dc3c509 100644
--- a/services/backup/java/com/android/server/backup/BackupManagerConstants.java
+++ b/services/backup/java/com/android/server/backup/BackupManagerConstants.java
@@ -16,6 +16,8 @@
package com.android.server.backup;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG_SCHEDULING;
+
import android.app.AlarmManager;
import android.content.ContentResolver;
import android.os.Handler;
@@ -24,6 +26,7 @@ import android.text.TextUtils;
import android.util.KeyValueListParser;
import android.util.KeyValueSettingObserver;
import android.util.Slog;
+
import com.android.internal.annotations.VisibleForTesting;
/**
@@ -151,7 +154,7 @@ public class BackupManagerConstants extends KeyValueSettingObserver {
// group the calls of these methods in a block syncrhonized on
// a reference of this object.
public synchronized long getKeyValueBackupIntervalMilliseconds() {
- if (BackupManagerService.DEBUG_SCHEDULING) {
+ if (DEBUG_SCHEDULING) {
Slog.v(
TAG,
"getKeyValueBackupIntervalMilliseconds(...) returns "
@@ -161,7 +164,7 @@ public class BackupManagerConstants extends KeyValueSettingObserver {
}
public synchronized long getKeyValueBackupFuzzMilliseconds() {
- if (BackupManagerService.DEBUG_SCHEDULING) {
+ if (DEBUG_SCHEDULING) {
Slog.v(
TAG,
"getKeyValueBackupFuzzMilliseconds(...) returns "
@@ -171,7 +174,7 @@ public class BackupManagerConstants extends KeyValueSettingObserver {
}
public synchronized boolean getKeyValueBackupRequireCharging() {
- if (BackupManagerService.DEBUG_SCHEDULING) {
+ if (DEBUG_SCHEDULING) {
Slog.v(
TAG,
"getKeyValueBackupRequireCharging(...) returns "
@@ -181,7 +184,7 @@ public class BackupManagerConstants extends KeyValueSettingObserver {
}
public synchronized int getKeyValueBackupRequiredNetworkType() {
- if (BackupManagerService.DEBUG_SCHEDULING) {
+ if (DEBUG_SCHEDULING) {
Slog.v(
TAG,
"getKeyValueBackupRequiredNetworkType(...) returns "
@@ -191,7 +194,7 @@ public class BackupManagerConstants extends KeyValueSettingObserver {
}
public synchronized long getFullBackupIntervalMilliseconds() {
- if (BackupManagerService.DEBUG_SCHEDULING) {
+ if (DEBUG_SCHEDULING) {
Slog.v(
TAG,
"getFullBackupIntervalMilliseconds(...) returns "
@@ -201,14 +204,14 @@ public class BackupManagerConstants extends KeyValueSettingObserver {
}
public synchronized boolean getFullBackupRequireCharging() {
- if (BackupManagerService.DEBUG_SCHEDULING) {
+ if (DEBUG_SCHEDULING) {
Slog.v(TAG, "getFullBackupRequireCharging(...) returns " + mFullBackupRequireCharging);
}
return mFullBackupRequireCharging;
}
public synchronized int getFullBackupRequiredNetworkType() {
- if (BackupManagerService.DEBUG_SCHEDULING) {
+ if (DEBUG_SCHEDULING) {
Slog.v(
TAG,
"getFullBackupRequiredNetworkType(...) returns "
@@ -219,7 +222,7 @@ public class BackupManagerConstants extends KeyValueSettingObserver {
/** Returns an array of package names that should be notified whenever a backup finishes. */
public synchronized String[] getBackupFinishedNotificationReceivers() {
- if (BackupManagerService.DEBUG_SCHEDULING) {
+ if (DEBUG_SCHEDULING) {
Slog.v(
TAG,
"getBackupFinishedNotificationReceivers(...) returns "
diff --git a/services/backup/java/com/android/server/backup/FileMetadata.java b/services/backup/java/com/android/server/backup/FileMetadata.java
index fe75041eeaca..84d987de3b22 100644
--- a/services/backup/java/com/android/server/backup/FileMetadata.java
+++ b/services/backup/java/com/android/server/backup/FileMetadata.java
@@ -16,7 +16,7 @@
package com.android.server.backup;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
import android.app.backup.BackupAgent;
import android.util.Slog;
diff --git a/services/backup/java/com/android/server/backup/FullBackupJob.java b/services/backup/java/com/android/server/backup/FullBackupJob.java
index 82638b4ecee4..ce024765b4db 100644
--- a/services/backup/java/com/android/server/backup/FullBackupJob.java
+++ b/services/backup/java/com/android/server/backup/FullBackupJob.java
@@ -61,7 +61,7 @@ public class FullBackupJob extends JobService {
@Override
public boolean onStartJob(JobParameters params) {
mParams = params;
- Trampoline service = BackupManagerService.getInstance();
+ Trampoline service = GlobalBackupManagerService.getInstance();
return service.beginFullBackup(this);
}
@@ -69,7 +69,7 @@ public class FullBackupJob extends JobService {
public boolean onStopJob(JobParameters params) {
if (mParams != null) {
mParams = null;
- Trampoline service = BackupManagerService.getInstance();
+ Trampoline service = GlobalBackupManagerService.getInstance();
service.endFullBackup();
}
return false;
diff --git a/services/backup/java/com/android/server/backup/GlobalBackupManagerService.java b/services/backup/java/com/android/server/backup/GlobalBackupManagerService.java
new file mode 100644
index 000000000000..9a1662e702ae
--- /dev/null
+++ b/services/backup/java/com/android/server/backup/GlobalBackupManagerService.java
@@ -0,0 +1,633 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.backup;
+
+import android.annotation.Nullable;
+import android.app.ActivityManager;
+import android.app.backup.IBackupManagerMonitor;
+import android.app.backup.IBackupObserver;
+import android.app.backup.IFullBackupRestoreObserver;
+import android.app.backup.IRestoreSession;
+import android.app.backup.ISelectBackupTransportCallback;
+import android.app.job.JobParameters;
+import android.app.job.JobScheduler;
+import android.app.job.JobService;
+import android.content.ComponentName;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.Environment;
+import android.os.HandlerThread;
+import android.os.IBinder;
+import android.os.ParcelFileDescriptor;
+import android.os.RemoteException;
+import android.os.Trace;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.text.TextUtils;
+import android.util.Slog;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.server.SystemConfig;
+import com.android.server.SystemService;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * Definition of the system service that performs backup/restore operations.
+ *
+ * <p>This class is responsible for handling user-aware operations and acts as a delegator, routing
+ * incoming calls to the appropriate per-user {@link UserBackupManagerService} to handle the
+ * corresponding backup/restore operation.
+ */
+public class GlobalBackupManagerService {
+ public static final String TAG = "BackupManagerService";
+ public static final boolean DEBUG = true;
+ public static final boolean MORE_DEBUG = false;
+ public static final boolean DEBUG_SCHEDULING = true;
+
+ // File containing backup-enabled state. Contains a single byte to denote enabled status.
+ // Nonzero is enabled; file missing or a zero byte is disabled.
+ private static final String BACKUP_ENABLE_FILE = "backup_enabled";
+
+ // The published binder is a singleton Trampoline object that calls through to the proper code.
+ // This indirection lets us turn down the heavy implementation object on the fly without
+ // disturbing binders that have been cached elsewhere in the system.
+ private static Trampoline sInstance;
+
+ static Trampoline getInstance() {
+ // Always constructed during system bring up, so no need to lazy-init.
+ return sInstance;
+ }
+
+ /** Helper to create the {@link GlobalBackupManagerService} instance. */
+ public static GlobalBackupManagerService create(
+ Context context,
+ Trampoline parent,
+ HandlerThread backupThread) {
+ // Set up our transport options and initialize the default transport
+ SystemConfig systemConfig = SystemConfig.getInstance();
+ Set<ComponentName> transportWhitelist = systemConfig.getBackupTransportWhitelist();
+ if (transportWhitelist == null) {
+ transportWhitelist = Collections.emptySet();
+ }
+
+ String transport =
+ Settings.Secure.getString(
+ context.getContentResolver(), Settings.Secure.BACKUP_TRANSPORT);
+ if (TextUtils.isEmpty(transport)) {
+ transport = null;
+ }
+ if (DEBUG) {
+ Slog.v(TAG, "Starting with transport " + transport);
+ }
+ TransportManager transportManager =
+ new TransportManager(
+ context,
+ transportWhitelist,
+ transport);
+
+ // If encrypted file systems is enabled or disabled, this call will return the
+ // correct directory.
+ File baseStateDir = new File(Environment.getDataDirectory(), "backup");
+
+ // This dir on /cache is managed directly in init.rc
+ File dataDir = new File(Environment.getDownloadCacheDirectory(), "backup_stage");
+
+ return new GlobalBackupManagerService(
+ context,
+ parent,
+ backupThread,
+ baseStateDir,
+ dataDir,
+ transportManager);
+ }
+
+ private UserBackupManagerService mUserBackupManagerService;
+
+ /** Instantiate a new instance of {@link GlobalBackupManagerService}. */
+ public GlobalBackupManagerService(
+ Context context,
+ Trampoline trampoline,
+ HandlerThread backupThread,
+ File baseStateDir,
+ File dataDir,
+ TransportManager transportManager) {
+ mUserBackupManagerService =
+ new UserBackupManagerService(
+ context, trampoline, backupThread, baseStateDir, dataDir, transportManager);
+ }
+
+ // TODO(b/118520567): Remove when tests are modified to use per-user instance.
+ @VisibleForTesting
+ void setUserBackupManagerService(UserBackupManagerService userBackupManagerService) {
+ mUserBackupManagerService = userBackupManagerService;
+ }
+
+ /**
+ * Called through Trampoline from {@link Lifecycle#onUnlockUser(int)}. We run the heavy work on
+ * a background thread to keep the unlock time down.
+ */
+ public void unlockSystemUser() {
+ // Migrate legacy setting
+ Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backup migrate");
+ if (!backupSettingMigrated(UserHandle.USER_SYSTEM)) {
+ if (DEBUG) {
+ Slog.i(TAG, "Backup enable apparently not migrated");
+ }
+ ContentResolver resolver = sInstance.getContext().getContentResolver();
+ int enableState = Settings.Secure.getIntForUser(resolver,
+ Settings.Secure.BACKUP_ENABLED, -1, UserHandle.USER_SYSTEM);
+ if (enableState >= 0) {
+ if (DEBUG) {
+ Slog.i(TAG, "Migrating enable state " + (enableState != 0));
+ }
+ writeBackupEnableState(enableState != 0, UserHandle.USER_SYSTEM);
+ Settings.Secure.putStringForUser(resolver,
+ Settings.Secure.BACKUP_ENABLED, null, UserHandle.USER_SYSTEM);
+ } else {
+ if (DEBUG) {
+ Slog.i(TAG, "Backup not yet configured; retaining null enable state");
+ }
+ }
+ }
+ Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
+
+ Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backup enable");
+ try {
+ sInstance.setBackupEnabled(readBackupEnableState(UserHandle.USER_SYSTEM));
+ } catch (RemoteException e) {
+ // can't happen; it's a local object
+ }
+ Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
+ }
+
+ /*
+ * The following methods are implementations of IBackupManager methods called from Trampoline.
+ * They delegate to the appropriate per-user instance of UserBackupManagerService to perform the
+ * action on the passed in user. Currently this is a straight redirection (see TODO).
+ */
+ // TODO (b/118520567): Take in user id and call per-user instance of UserBackupManagerService.
+
+ // ---------------------------------------------
+ // BACKUP AGENT OPERATIONS
+ // ---------------------------------------------
+
+ /**
+ * An app's backup agent calls this method to let the service know that there's new data to
+ * backup for their app {@code packageName}. Only used for apps participating in key-value
+ * backup.
+ */
+ public void dataChanged(String packageName) {
+ mUserBackupManagerService.dataChanged(packageName);
+ }
+
+ /**
+ * Callback: a requested backup agent has been instantiated. This should only be called from the
+ * {@link ActivityManager}.
+ */
+ public void agentConnected(String packageName, IBinder agentBinder) {
+ mUserBackupManagerService.agentConnected(packageName, agentBinder);
+ }
+
+ /**
+ * Callback: a backup agent has failed to come up, or has unexpectedly quit. This should only be
+ * called from the {@link ActivityManager}.
+ */
+ public void agentDisconnected(String packageName) {
+ mUserBackupManagerService.agentDisconnected(packageName);
+ }
+
+ /**
+ * Used by a currently-active backup agent to notify the service that it has completed its given
+ * outstanding asynchronous backup/restore operation.
+ */
+ public void opComplete(int token, long result) {
+ mUserBackupManagerService.opComplete(token, result);
+ }
+
+ // ---------------------------------------------
+ // TRANSPORT OPERATIONS
+ // ---------------------------------------------
+
+ /** Run an initialize operation for the given transports {@code transportNames}. */
+ public void initializeTransports(String[] transportNames, IBackupObserver observer) {
+ mUserBackupManagerService.initializeTransports(transportNames, observer);
+ }
+
+ /**
+ * Clear the given package {@code packageName}'s backup data from the transport {@code
+ * transportName}.
+ */
+ public void clearBackupData(String transportName, String packageName) {
+ mUserBackupManagerService.clearBackupData(transportName, packageName);
+ }
+
+ /** Return the name of the currently active transport. */
+ public String getCurrentTransport() {
+ return mUserBackupManagerService.getCurrentTransport();
+ }
+
+ /**
+ * Returns the {@link ComponentName} of the host service of the selected transport or {@code
+ * null} if no transport selected or if the transport selected is not registered.
+ */
+ public ComponentName getCurrentTransportComponent() {
+ return mUserBackupManagerService.getCurrentTransportComponent();
+ }
+
+ /** Report all known, available backup transports by name. */
+ public String[] listAllTransports() {
+ return mUserBackupManagerService.listAllTransports();
+ }
+
+ /** Report all known, available backup transports by {@link ComponentName}. */
+ public ComponentName[] listAllTransportComponents() {
+ return mUserBackupManagerService.listAllTransportComponents();
+ }
+
+ /** Report all system whitelisted transports. */
+ public String[] getTransportWhitelist() {
+ return mUserBackupManagerService.getTransportWhitelist();
+ }
+
+ /**
+ * Update the attributes of the transport identified by {@code transportComponent}. If the
+ * specified transport has not been bound at least once (for registration), this call will be
+ * ignored. Only the host process of the transport can change its description, otherwise a
+ * {@link SecurityException} will be thrown.
+ *
+ * @param transportComponent The identity of the transport being described.
+ * @param name A {@link String} with the new name for the transport. This is NOT for
+ * identification. MUST NOT be {@code null}.
+ * @param configurationIntent An {@link Intent} that can be passed to {@link
+ * Context#startActivity} in order to launch the transport's configuration UI. It may be
+ * {@code null} if the transport does not offer any user-facing configuration UI.
+ * @param currentDestinationString A {@link String} describing the destination to which the
+ * transport is currently sending data. MUST NOT be {@code null}.
+ * @param dataManagementIntent An {@link Intent} that can be passed to {@link
+ * Context#startActivity} in order to launch the transport's data-management UI. It may be
+ * {@code null} if the transport does not offer any user-facing data management UI.
+ * @param dataManagementLabel A {@link String} to be used as the label for the transport's data
+ * management affordance. This MUST be {@code null} when dataManagementIntent is {@code
+ * null} and MUST NOT be {@code null} when dataManagementIntent is not {@code null}.
+ * @throws SecurityException If the UID of the calling process differs from the package UID of
+ * {@code transportComponent} or if the caller does NOT have BACKUP permission.
+ */
+ public void updateTransportAttributes(
+ ComponentName transportComponent,
+ String name,
+ @Nullable Intent configurationIntent,
+ String currentDestinationString,
+ @Nullable Intent dataManagementIntent,
+ String dataManagementLabel) {
+ mUserBackupManagerService.updateTransportAttributes(
+ transportComponent,
+ name,
+ configurationIntent,
+ currentDestinationString,
+ dataManagementIntent,
+ dataManagementLabel);
+ }
+
+ /**
+ * Selects transport {@code transportName} and returns the previously selected transport.
+ *
+ * @deprecated Use {@link #selectBackupTransportAsync(ComponentName,
+ * ISelectBackupTransportCallback)} instead.
+ */
+ @Deprecated
+ @Nullable
+ public String selectBackupTransport(String transportName) {
+ return mUserBackupManagerService.selectBackupTransport(transportName);
+ }
+
+ /**
+ * Selects transport {@code transportComponent} asynchronously and notifies {@code listener}
+ * with the result upon completion.
+ */
+ public void selectBackupTransportAsync(
+ ComponentName transportComponent, ISelectBackupTransportCallback listener) {
+ mUserBackupManagerService.selectBackupTransportAsync(transportComponent, listener);
+ }
+
+ /**
+ * Supply the configuration intent for the given transport. If the name is not one of the
+ * available transports, or if the transport does not supply any configuration UI, the method
+ * returns {@code null}.
+ */
+ public Intent getConfigurationIntent(String transportName) {
+ return mUserBackupManagerService.getConfigurationIntent(transportName);
+ }
+
+ /**
+ * Supply the current destination string for the given transport. If the name is not one of the
+ * registered transports the method will return null.
+ *
+ * <p>This string is used VERBATIM as the summary text of the relevant Settings item.
+ *
+ * @param transportName The name of the registered transport.
+ * @return The current destination string or null if the transport is not registered.
+ */
+ public String getDestinationString(String transportName) {
+ return mUserBackupManagerService.getDestinationString(transportName);
+ }
+
+ /** Supply the manage-data intent for the given transport. */
+ public Intent getDataManagementIntent(String transportName) {
+ return mUserBackupManagerService.getDataManagementIntent(transportName);
+ }
+
+ /**
+ * Supply the menu label for affordances that fire the manage-data intent for the given
+ * transport.
+ */
+ public String getDataManagementLabel(String transportName) {
+ return mUserBackupManagerService.getDataManagementLabel(transportName);
+ }
+
+ // ---------------------------------------------
+ // SETTINGS OPERATIONS
+ // ---------------------------------------------
+
+ /** Enable/disable the backup service. This is user-configurable via backup settings. */
+ public void setBackupEnabled(boolean enable) {
+ mUserBackupManagerService.setBackupEnabled(enable);
+ }
+
+ /** Enable/disable automatic restore of app data at install time. */
+ public void setAutoRestore(boolean autoRestore) {
+ mUserBackupManagerService.setAutoRestore(autoRestore);
+ }
+
+ /** Mark the backup service as having been provisioned (device has gone through SUW). */
+ public void setBackupProvisioned(boolean provisioned) {
+ mUserBackupManagerService.setBackupProvisioned(provisioned);
+ }
+
+ /**
+ * Return {@code true} if the backup mechanism is currently enabled, else returns {@code false}.
+ */
+ public boolean isBackupEnabled() {
+ return mUserBackupManagerService.isBackupEnabled();
+ }
+
+ // ---------------------------------------------
+ // BACKUP OPERATIONS
+ // ---------------------------------------------
+
+ /** Checks if the given package {@code packageName} is eligible for backup. */
+ public boolean isAppEligibleForBackup(String packageName) {
+ return mUserBackupManagerService.isAppEligibleForBackup(packageName);
+ }
+
+ /**
+ * Returns from the inputted packages {@code packages}, the ones that are eligible for backup.
+ */
+ public String[] filterAppsEligibleForBackup(String[] packages) {
+ return mUserBackupManagerService.filterAppsEligibleForBackup(packages);
+ }
+
+ /**
+ * Run a backup pass immediately for any key-value backup applications that have declared that
+ * they have pending updates.
+ */
+ public void backupNow() {
+ mUserBackupManagerService.backupNow();
+ }
+
+ /**
+ * Requests a backup for the inputted {@code packages} with a specified callback {@link
+ * IBackupManagerMonitor} for receiving events during the operation.
+ */
+ public int requestBackup(
+ String[] packages, IBackupObserver observer, IBackupManagerMonitor monitor, int flags) {
+ return mUserBackupManagerService.requestBackup(packages, observer, monitor, flags);
+ }
+
+ /** Cancel all running backup operations. */
+ public void cancelBackups() {
+ mUserBackupManagerService.cancelBackups();
+ }
+
+ /**
+ * Used by the {@link JobScheduler} to run a full backup when conditions are right. The model we
+ * use is to perform one app backup per scheduled job execution, and to reschedule the job with
+ * zero latency as long as conditions remain right and we still have work to do.
+ *
+ * @return Whether ongoing work will continue. The return value here will be passed along as the
+ * return value to the callback {@link JobService#onStartJob(JobParameters)}.
+ */
+ public boolean beginFullBackup(FullBackupJob scheduledJob) {
+ return mUserBackupManagerService.beginFullBackup(scheduledJob);
+ }
+
+ /**
+ * Used by the {@link JobScheduler} to end the current full backup task when conditions are no
+ * longer met for running the full backup job.
+ */
+ public void endFullBackup() {
+ mUserBackupManagerService.endFullBackup();
+ }
+
+ /**
+ * Run a full backup pass for the given packages {@code packageNames}. Used by 'adb shell bmgr'.
+ */
+ public void fullTransportBackup(String[] packageNames) {
+ mUserBackupManagerService.fullTransportBackup(packageNames);
+ }
+
+ // ---------------------------------------------
+ // RESTORE OPERATIONS
+ // ---------------------------------------------
+
+ /**
+ * Used to run a restore pass for an application that is being installed. This should only be
+ * called from the {@link PackageManager}.
+ */
+ public void restoreAtInstall(String packageName, int token) {
+ mUserBackupManagerService.restoreAtInstall(packageName, token);
+ }
+
+ /**
+ * Begin a restore for the specified package {@code packageName} using the specified transport
+ * {@code transportName}.
+ */
+ public IRestoreSession beginRestoreSession(String packageName, String transportName) {
+ return mUserBackupManagerService.beginRestoreSession(packageName, transportName);
+ }
+
+ /**
+ * Get the restore-set token for the best-available restore set for this {@code packageName}:
+ * the active set if possible, else the ancestral one. Returns zero if none available.
+ */
+ public long getAvailableRestoreToken(String packageName) {
+ return mUserBackupManagerService.getAvailableRestoreToken(packageName);
+ }
+
+ // ---------------------------------------------
+ // ADB BACKUP/RESTORE OPERATIONS
+ // ---------------------------------------------
+
+ /** Sets the backup password used when running adb backup. */
+ public boolean setBackupPassword(String currentPassword, String newPassword) {
+ return mUserBackupManagerService.setBackupPassword(currentPassword, newPassword);
+ }
+
+ /** Returns {@code true} if adb backup was run with a password, else returns {@code false}. */
+ public boolean hasBackupPassword() {
+ return mUserBackupManagerService.hasBackupPassword();
+ }
+
+ /**
+ * Used by 'adb backup' to run a backup pass for packages {@code packageNames} supplied via the
+ * command line, writing the resulting data stream to the supplied {@code fd}. This method is
+ * synchronous and does not return to the caller until the backup has been completed. It
+ * requires on-screen confirmation by the user.
+ */
+ public void adbBackup(
+ ParcelFileDescriptor fd,
+ boolean includeApks,
+ boolean includeObbs,
+ boolean includeShared,
+ boolean doWidgets,
+ boolean doAllApps,
+ boolean includeSystem,
+ boolean doCompress,
+ boolean doKeyValue,
+ String[] packageNames) {
+ mUserBackupManagerService.adbBackup(
+ fd,
+ includeApks,
+ includeObbs,
+ includeShared,
+ doWidgets,
+ doAllApps,
+ includeSystem,
+ doCompress,
+ doKeyValue,
+ packageNames);
+ }
+
+ /**
+ * Used by 'adb restore' to run a restore pass reading from the supplied {@code fd}. This method
+ * is synchronous and does not return to the caller until the restore has been completed. It
+ * requires on-screen confirmation by the user.
+ */
+ public void adbRestore(ParcelFileDescriptor fd) {
+ mUserBackupManagerService.adbRestore(fd);
+ }
+
+ /**
+ * Confirm that the previously requested adb backup/restore operation can proceed. This is used
+ * to require a user-facing disclosure about the operation.
+ */
+ public void acknowledgeAdbBackupOrRestore(
+ int token,
+ boolean allow,
+ String currentPassword,
+ String encryptionPassword,
+ IFullBackupRestoreObserver observer) {
+ mUserBackupManagerService.acknowledgeAdbBackupOrRestore(
+ token, allow, currentPassword, encryptionPassword, observer);
+ }
+
+ // ---------------------------------------------
+ // SERVICE OPERATIONS
+ // ---------------------------------------------
+
+ /** Prints service state for 'dumpsys backup'. */
+ public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+ mUserBackupManagerService.dump(fd, pw, args);
+ }
+
+ private static boolean backupSettingMigrated(int userId) {
+ File base = new File(Environment.getDataDirectory(), "backup");
+ File enableFile = new File(base, BACKUP_ENABLE_FILE);
+ return enableFile.exists();
+ }
+
+ private static boolean readBackupEnableState(int userId) {
+ File base = new File(Environment.getDataDirectory(), "backup");
+ File enableFile = new File(base, BACKUP_ENABLE_FILE);
+ if (enableFile.exists()) {
+ try (FileInputStream fin = new FileInputStream(enableFile)) {
+ int state = fin.read();
+ return state != 0;
+ } catch (IOException e) {
+ // can't read the file; fall through to assume disabled
+ Slog.e(TAG, "Cannot read enable state; assuming disabled");
+ }
+ } else {
+ if (DEBUG) {
+ Slog.i(TAG, "isBackupEnabled() => false due to absent settings file");
+ }
+ }
+ return false;
+ }
+
+ static void writeBackupEnableState(boolean enable, int userId) {
+ File base = new File(Environment.getDataDirectory(), "backup");
+ File enableFile = new File(base, BACKUP_ENABLE_FILE);
+ File stage = new File(base, BACKUP_ENABLE_FILE + "-stage");
+ try (FileOutputStream fout = new FileOutputStream(stage)) {
+ fout.write(enable ? 1 : 0);
+ fout.close();
+ stage.renameTo(enableFile);
+ // will be synced immediately by the try-with-resources call to close()
+ } catch (IOException | RuntimeException e) {
+ // Whoops; looks like we're doomed. Roll everything out, disabled,
+ // including the legacy state.
+ Slog.e(TAG, "Unable to record backup enable state; reverting to disabled: "
+ + e.getMessage());
+
+ ContentResolver resolver = sInstance.getContext().getContentResolver();
+ Settings.Secure.putStringForUser(resolver,
+ Settings.Secure.BACKUP_ENABLED, null, userId);
+ enableFile.delete();
+ stage.delete();
+ }
+ }
+
+ /** Implementation to receive lifecycle event callbacks for system services. */
+ public static final class Lifecycle extends SystemService {
+ public Lifecycle(Context context) {
+ super(context);
+ sInstance = new Trampoline(context);
+ }
+
+ @Override
+ public void onStart() {
+ publishBinderService(Context.BACKUP_SERVICE, sInstance);
+ }
+
+ @Override
+ public void onUnlockUser(int userId) {
+ if (userId == UserHandle.USER_SYSTEM) {
+ sInstance.unlockSystemUser();
+ }
+ }
+ }
+}
diff --git a/services/backup/java/com/android/server/backup/KeyValueAdbBackupEngine.java b/services/backup/java/com/android/server/backup/KeyValueAdbBackupEngine.java
index 125c2250d7d1..92c2ee4c4e71 100644
--- a/services/backup/java/com/android/server/backup/KeyValueAdbBackupEngine.java
+++ b/services/backup/java/com/android/server/backup/KeyValueAdbBackupEngine.java
@@ -5,7 +5,8 @@ import static android.os.ParcelFileDescriptor.MODE_READ_ONLY;
import static android.os.ParcelFileDescriptor.MODE_READ_WRITE;
import static android.os.ParcelFileDescriptor.MODE_TRUNCATE;
-import static com.android.server.backup.BackupManagerService.OP_TYPE_BACKUP_WAIT;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_MANIFEST_FILENAME;
+import static com.android.server.backup.UserBackupManagerService.OP_TYPE_BACKUP_WAIT;
import android.app.ApplicationThreadConstants;
import android.app.IBackupAgent;
@@ -50,7 +51,7 @@ public class KeyValueAdbBackupEngine {
private static final String BACKUP_KEY_VALUE_BACKUP_DATA_FILENAME_SUFFIX = ".data";
private static final String BACKUP_KEY_VALUE_NEW_STATE_FILENAME_SUFFIX = ".new";
- private BackupManagerService mBackupManagerService;
+ private UserBackupManagerService mBackupManagerService;
private final PackageManager mPackageManager;
private final OutputStream mOutput;
private final PackageInfo mCurrentPackage;
@@ -66,7 +67,7 @@ public class KeyValueAdbBackupEngine {
private final BackupAgentTimeoutParameters mAgentTimeoutParameters;
public KeyValueAdbBackupEngine(OutputStream output, PackageInfo packageInfo,
- BackupManagerService backupManagerService, PackageManager packageManager,
+ UserBackupManagerService backupManagerService, PackageManager packageManager,
File baseStateDir, File dataDir) {
mOutput = output;
mCurrentPackage = packageInfo;
@@ -85,7 +86,7 @@ public class KeyValueAdbBackupEngine {
mNewStateName = new File(mStateDir,
pkg + BACKUP_KEY_VALUE_NEW_STATE_FILENAME_SUFFIX);
- mManifestFile = new File(mDataDir, BackupManagerService.BACKUP_MANIFEST_FILENAME);
+ mManifestFile = new File(mDataDir, BACKUP_MANIFEST_FILENAME);
mAgentTimeoutParameters = Preconditions.checkNotNull(
backupManagerService.getAgentTimeoutParameters(),
"Timeout parameters cannot be null");
diff --git a/services/backup/java/com/android/server/backup/KeyValueAdbRestoreEngine.java b/services/backup/java/com/android/server/backup/KeyValueAdbRestoreEngine.java
index bb145769fc8c..bed520e9f068 100644
--- a/services/backup/java/com/android/server/backup/KeyValueAdbRestoreEngine.java
+++ b/services/backup/java/com/android/server/backup/KeyValueAdbRestoreEngine.java
@@ -39,7 +39,7 @@ public class KeyValueAdbRestoreEngine implements Runnable {
private static final String TAG = "KeyValueAdbRestoreEngine";
private static final boolean DEBUG = false;
- private final BackupManagerService mBackupManagerService;
+ private final UserBackupManagerService mBackupManagerService;
private final File mDataDir;
FileMetadata mInfo;
@@ -48,7 +48,7 @@ public class KeyValueAdbRestoreEngine implements Runnable {
IBackupAgent mAgent;
int mToken;
- public KeyValueAdbRestoreEngine(BackupManagerService backupManagerService,
+ public KeyValueAdbRestoreEngine(UserBackupManagerService backupManagerService,
File dataDir, FileMetadata info, ParcelFileDescriptor inFD, IBackupAgent agent,
int token) {
mBackupManagerService = backupManagerService;
diff --git a/services/backup/java/com/android/server/backup/KeyValueBackupJob.java b/services/backup/java/com/android/server/backup/KeyValueBackupJob.java
index c805783103be..8156095cf576 100644
--- a/services/backup/java/com/android/server/backup/KeyValueBackupJob.java
+++ b/services/backup/java/com/android/server/backup/KeyValueBackupJob.java
@@ -16,6 +16,8 @@
package com.android.server.backup;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG_SCHEDULING;
+
import android.app.AlarmManager;
import android.app.job.JobInfo;
import android.app.job.JobParameters;
@@ -71,7 +73,7 @@ public class KeyValueBackupJob extends JobService {
if (delay <= 0) {
delay = interval + new Random().nextInt((int) fuzz);
}
- if (BackupManagerService.DEBUG_SCHEDULING) {
+ if (DEBUG_SCHEDULING) {
Slog.v(TAG, "Scheduling k/v pass in " + (delay / 1000 / 60) + " minutes");
}
JobInfo.Builder builder = new JobInfo.Builder(JOB_ID, sKeyValueJobService)
@@ -116,7 +118,7 @@ public class KeyValueBackupJob extends JobService {
}
// Time to run a key/value backup!
- Trampoline service = BackupManagerService.getInstance();
+ Trampoline service = GlobalBackupManagerService.getInstance();
try {
service.backupNow();
} catch (RemoteException e) {}
diff --git a/services/backup/java/com/android/server/backup/ProcessedPackagesJournal.java b/services/backup/java/com/android/server/backup/ProcessedPackagesJournal.java
index b5db5e2c5850..dd91381779e4 100644
--- a/services/backup/java/com/android/server/backup/ProcessedPackagesJournal.java
+++ b/services/backup/java/com/android/server/backup/ProcessedPackagesJournal.java
@@ -23,8 +23,8 @@ import com.android.internal.annotations.GuardedBy;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.EOFException;
-import java.io.FileInputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.HashSet;
@@ -46,7 +46,7 @@ import java.util.Set;
final class ProcessedPackagesJournal {
private static final String TAG = "ProcessedPackagesJournal";
private static final String JOURNAL_FILE_NAME = "processed";
- private static final boolean DEBUG = BackupManagerService.DEBUG || false;
+ private static final boolean DEBUG = GlobalBackupManagerService.DEBUG;
// using HashSet instead of ArraySet since we expect 100-500 elements range
@GuardedBy("mProcessedPackages")
diff --git a/services/backup/java/com/android/server/backup/Trampoline.java b/services/backup/java/com/android/server/backup/Trampoline.java
index 32fd7e0f1607..22edebc982dd 100644
--- a/services/backup/java/com/android/server/backup/Trampoline.java
+++ b/services/backup/java/com/android/server/backup/Trampoline.java
@@ -16,7 +16,7 @@
package com.android.server.backup;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
import android.annotation.Nullable;
import android.app.admin.DevicePolicyManager;
@@ -42,20 +42,22 @@ import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
import android.util.Slog;
+
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.DumpUtils;
+
import java.io.File;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter;
/**
- * A proxy to BackupManagerService implementation.
+ * A proxy to the {@link GlobalBackupManagerService} implementation.
*
- * <p>This is an external interface to the BackupManagerService which is being accessed via
- * published binder (see BackupManagerService$Lifecycle). This lets us turn down the heavy
- * implementation object on the fly without disturbing binders that have been cached somewhere in
- * the system.
+ * <p>This is an external interface to the {@link GlobalBackupManagerService} which is being
+ * accessed via published binder {@link GlobalBackupManagerService.Lifecycle}. This lets us turn
+ * down the heavy implementation object on the fly without disturbing binders that have been cached
+ * somewhere in the system.
*
* <p>Trampoline determines whether the backup service is available. It can be disabled in the
* following two ways:
@@ -87,7 +89,7 @@ public class Trampoline extends IBackupManager.Stub {
private final boolean mGlobalDisable;
private final Object mStateLock = new Object();
- private volatile BackupManagerService mService;
+ private volatile GlobalBackupManagerService mService;
private HandlerThread mHandlerThread;
public Trampoline(Context context) {
@@ -114,12 +116,12 @@ public class Trampoline extends IBackupManager.Stub {
return mContext;
}
- protected BackupManagerService createBackupManagerService() {
- return BackupManagerService.create(mContext, this, mHandlerThread);
+ protected GlobalBackupManagerService createBackupManagerService() {
+ return GlobalBackupManagerService.create(mContext, this, mHandlerThread);
}
/**
- * Initialize {@link BackupManagerService} if the backup service is not disabled. Only the
+ * Initialize {@link GlobalBackupManagerService} if the backup service is not disabled. Only the
* system user can initialize the service.
*/
/* package */ void initializeService(int userId) {
@@ -143,10 +145,11 @@ public class Trampoline extends IBackupManager.Stub {
}
/**
- * Called from {@link BackupManagerService$Lifecycle} when the system user is unlocked. Attempts
- * to initialize {@link BackupManagerService} and set backup state for the system user.
+ * Called from {@link GlobalBackupManagerService.Lifecycle} when the system user is unlocked.
+ * Attempts to initialize {@link GlobalBackupManagerService} and set backup state for the system
+ * user.
*
- * @see BackupManagerService#unlockSystemUser()
+ * @see GlobalBackupManagerService#unlockSystemUser()
*/
void unlockSystemUser() {
mHandlerThread = new HandlerThread("backup", Process.THREAD_PRIORITY_BACKGROUND);
@@ -159,7 +162,7 @@ public class Trampoline extends IBackupManager.Stub {
initializeService(UserHandle.USER_SYSTEM);
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
- BackupManagerService service = mService;
+ GlobalBackupManagerService service = mService;
if (service != null) {
Slog.i(TAG, "Unlocking system user");
service.unlockSystemUser();
@@ -231,7 +234,7 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public void dataChanged(String packageName) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.dataChanged(packageName);
}
@@ -240,7 +243,7 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public void initializeTransports(String[] transportNames, IBackupObserver observer)
throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.initializeTransports(transportNames, observer);
}
@@ -249,7 +252,7 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public void clearBackupData(String transportName, String packageName)
throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.clearBackupData(transportName, packageName);
}
@@ -257,7 +260,7 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public void agentConnected(String packageName, IBinder agent) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.agentConnected(packageName, agent);
}
@@ -265,7 +268,7 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public void agentDisconnected(String packageName) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.agentDisconnected(packageName);
}
@@ -273,7 +276,7 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public void restoreAtInstall(String packageName, int token) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.restoreAtInstall(packageName, token);
}
@@ -281,7 +284,7 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public void setBackupEnabled(boolean isEnabled) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.setBackupEnabled(isEnabled);
}
@@ -289,7 +292,7 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public void setAutoRestore(boolean doAutoRestore) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.setAutoRestore(doAutoRestore);
}
@@ -297,7 +300,7 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public void setBackupProvisioned(boolean isProvisioned) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.setBackupProvisioned(isProvisioned);
}
@@ -305,25 +308,25 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public boolean isBackupEnabled() throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.isBackupEnabled() : false;
}
@Override
public boolean setBackupPassword(String currentPw, String newPw) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.setBackupPassword(currentPw, newPw) : false;
}
@Override
public boolean hasBackupPassword() throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.hasBackupPassword() : false;
}
@Override
public void backupNow() throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.backupNow();
}
@@ -334,7 +337,7 @@ public class Trampoline extends IBackupManager.Stub {
boolean includeShared, boolean doWidgets, boolean allApps,
boolean allIncludesSystem, boolean doCompress, boolean doKeyValue, String[] packageNames)
throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.adbBackup(fd, includeApks, includeObbs, includeShared, doWidgets,
allApps, allIncludesSystem, doCompress, doKeyValue, packageNames);
@@ -343,7 +346,7 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public void fullTransportBackup(String[] packageNames) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.fullTransportBackup(packageNames);
}
@@ -351,7 +354,7 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public void adbRestore(ParcelFileDescriptor fd) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.adbRestore(fd);
}
@@ -361,7 +364,7 @@ public class Trampoline extends IBackupManager.Stub {
public void acknowledgeFullBackupOrRestore(int token, boolean allow, String curPassword,
String encryptionPassword, IFullBackupRestoreObserver observer)
throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.acknowledgeAdbBackupOrRestore(token, allow,
curPassword, encryptionPassword, observer);
@@ -370,7 +373,7 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public String getCurrentTransport() throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.getCurrentTransport() : null;
}
@@ -381,25 +384,25 @@ public class Trampoline extends IBackupManager.Stub {
@Override
@Nullable
public ComponentName getCurrentTransportComponent() {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.getCurrentTransportComponent() : null;
}
@Override
public String[] listAllTransports() throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.listAllTransports() : null;
}
@Override
public ComponentName[] listAllTransportComponents() throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.listAllTransportComponents() : null;
}
@Override
public String[] getTransportWhitelist() {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.getTransportWhitelist() : null;
}
@@ -411,7 +414,7 @@ public class Trampoline extends IBackupManager.Stub {
String currentDestinationString,
@Nullable Intent dataManagementIntent,
String dataManagementLabel) {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.updateTransportAttributes(
transportComponent,
@@ -425,14 +428,14 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public String selectBackupTransport(String transport) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.selectBackupTransport(transport) : null;
}
@Override
public void selectBackupTransportAsync(ComponentName transport,
ISelectBackupTransportCallback listener) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.selectBackupTransportAsync(transport, listener);
} else {
@@ -448,38 +451,38 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public Intent getConfigurationIntent(String transport) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.getConfigurationIntent(transport) : null;
}
@Override
public String getDestinationString(String transport) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.getDestinationString(transport) : null;
}
@Override
public Intent getDataManagementIntent(String transport) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.getDataManagementIntent(transport) : null;
}
@Override
public String getDataManagementLabel(String transport) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.getDataManagementLabel(transport) : null;
}
@Override
public IRestoreSession beginRestoreSession(String packageName, String transportID)
throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.beginRestoreSession(packageName, transportID) : null;
}
@Override
public void opComplete(int token, long result) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.opComplete(token, result);
}
@@ -487,26 +490,26 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public long getAvailableRestoreToken(String packageName) {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.getAvailableRestoreToken(packageName) : 0;
}
@Override
public boolean isAppEligibleForBackup(String packageName) {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.isAppEligibleForBackup(packageName) : false;
}
@Override
public String[] filterAppsEligibleForBackup(String[] packages) {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.filterAppsEligibleForBackup(packages) : null;
}
@Override
public int requestBackup(String[] packages, IBackupObserver observer,
IBackupManagerMonitor monitor, int flags) throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc == null) {
return BackupManager.ERROR_BACKUP_NOT_ALLOWED;
}
@@ -515,7 +518,7 @@ public class Trampoline extends IBackupManager.Stub {
@Override
public void cancelBackups() throws RemoteException {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.cancelBackups();
}
@@ -525,7 +528,7 @@ public class Trampoline extends IBackupManager.Stub {
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.dump(fd, pw, args);
} else {
@@ -536,12 +539,12 @@ public class Trampoline extends IBackupManager.Stub {
// Full backup/restore entry points - non-Binder; called directly
// by the full-backup scheduled job
/* package */ boolean beginFullBackup(FullBackupJob scheduledJob) {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
return (svc != null) ? svc.beginFullBackup(scheduledJob) : false;
}
/* package */ void endFullBackup() {
- BackupManagerService svc = mService;
+ GlobalBackupManagerService svc = mService;
if (svc != null) {
svc.endFullBackup();
}
diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/UserBackupManagerService.java
index e4b4bc525514..4855ae0358bc 100644
--- a/services/backup/java/com/android/server/backup/BackupManagerService.java
+++ b/services/backup/java/com/android/server/backup/UserBackupManagerService.java
@@ -18,6 +18,10 @@ package com.android.server.backup;
import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_BACKUP_IN_FOREGROUND;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG_SCHEDULING;
+import static com.android.server.backup.GlobalBackupManagerService.MORE_DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
import static com.android.server.backup.internal.BackupHandler.MSG_BACKUP_OPERATION_TIMEOUT;
import static com.android.server.backup.internal.BackupHandler.MSG_FULL_CONFIRMATION_TIMEOUT;
import static com.android.server.backup.internal.BackupHandler.MSG_OP_COMPLETE;
@@ -64,7 +68,6 @@ import android.database.ContentObserver;
import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
-import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
@@ -78,13 +81,11 @@ import android.os.RemoteException;
import android.os.SELinux;
import android.os.ServiceManager;
import android.os.SystemClock;
-import android.os.Trace;
import android.os.UserHandle;
import android.os.WorkSource;
import android.os.storage.IStorageManager;
import android.os.storage.StorageManager;
import android.provider.Settings;
-import android.text.TextUtils;
import android.util.ArraySet;
import android.util.AtomicFile;
import android.util.EventLog;
@@ -99,8 +100,6 @@ import com.android.internal.util.DumpUtils;
import com.android.internal.util.Preconditions;
import com.android.server.AppWidgetBackupBridge;
import com.android.server.EventLogTags;
-import com.android.server.SystemConfig;
-import com.android.server.SystemService;
import com.android.server.backup.fullbackup.FullBackupEntry;
import com.android.server.backup.fullbackup.PerformFullTransportBackupTask;
import com.android.server.backup.internal.BackupHandler;
@@ -160,12 +159,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
/** System service that performs backup/restore operations. */
-public class BackupManagerService {
- public static final String TAG = "BackupManagerService";
- public static final boolean DEBUG = true;
- public static final boolean MORE_DEBUG = false;
- public static final boolean DEBUG_SCHEDULING = true;
-
+public class UserBackupManagerService {
// File containing backup-enabled state. Contains a single byte;
// nonzero == enabled. File missing or contains a zero byte == disabled.
private static final String BACKUP_ENABLE_FILE = "backup_enabled";
@@ -249,59 +243,6 @@ public class BackupManagerService {
private static final long BUSY_BACKOFF_MIN_MILLIS = 1000 * 60 * 60; // one hour
private static final int BUSY_BACKOFF_FUZZ = 1000 * 60 * 60 * 2; // two hours
- // The published binder is a singleton Trampoline object that calls through to the proper code.
- // This indirection lets us turn down the heavy implementation object on the fly without
- // disturbing binders that have been cached elsewhere in the system.
- private static Trampoline sInstance;
-
- static Trampoline getInstance() {
- // Always constructed during system bring up, so no need to lazy-init.
- return sInstance;
- }
-
- /** Helper to create the {@link BackupManagerService} instance. */
- public static BackupManagerService create(
- Context context,
- Trampoline parent,
- HandlerThread backupThread) {
- // Set up our transport options and initialize the default transport
- SystemConfig systemConfig = SystemConfig.getInstance();
- Set<ComponentName> transportWhitelist = systemConfig.getBackupTransportWhitelist();
- if (transportWhitelist == null) {
- transportWhitelist = Collections.emptySet();
- }
-
- String transport =
- Settings.Secure.getString(
- context.getContentResolver(), Settings.Secure.BACKUP_TRANSPORT);
- if (TextUtils.isEmpty(transport)) {
- transport = null;
- }
- if (DEBUG) {
- Slog.v(TAG, "Starting with transport " + transport);
- }
- TransportManager transportManager =
- new TransportManager(
- context,
- transportWhitelist,
- transport);
-
- // If encrypted file systems is enabled or disabled, this call will return the
- // correct directory.
- File baseStateDir = new File(Environment.getDataDirectory(), "backup");
-
- // This dir on /cache is managed directly in init.rc
- File dataDir = new File(Environment.getDownloadCacheDirectory(), "backup_stage");
-
- return new BackupManagerService(
- context,
- parent,
- backupThread,
- baseStateDir,
- dataDir,
- transportManager);
- }
-
private final BackupAgentTimeoutParameters mAgentTimeoutParameters;
private final TransportManager mTransportManager;
@@ -386,7 +327,7 @@ public class BackupManagerService {
* A BackupRestore task gets notified of ack/timeout for the operation via
* BackupRestoreTask#handleCancel, BackupRestoreTask#operationComplete and notifyAll called
* on the mCurrentOpLock.
- * {@link BackupManagerService#waitUntilOperationComplete(int)} is
+ * {@link UserBackupManagerService#waitUntilOperationComplete(int)} is
* used in various places to 'wait' for notifyAll and detect change of pending state of an
* operation. So typically, an operation will be removed from this array by:
* - BackupRestoreTask#handleCancel and
@@ -420,7 +361,7 @@ public class BackupManagerService {
private long mCurrentToken = 0;
@VisibleForTesting
- public BackupManagerService(
+ public UserBackupManagerService(
Context context,
Trampoline parent,
HandlerThread backupThread,
@@ -782,44 +723,6 @@ public class BackupManagerService {
}
/**
- * Called through Trampoline from {@link Lifecycle#onUnlockUser(int)}. We run the heavy work on
- * a background thread to keep the unlock time down.
- */
- public void unlockSystemUser() {
- // Migrate legacy setting
- Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backup migrate");
- if (!backupSettingMigrated(UserHandle.USER_SYSTEM)) {
- if (DEBUG) {
- Slog.i(TAG, "Backup enable apparently not migrated");
- }
- ContentResolver resolver = sInstance.getContext().getContentResolver();
- int enableState = Settings.Secure.getIntForUser(resolver,
- Settings.Secure.BACKUP_ENABLED, -1, UserHandle.USER_SYSTEM);
- if (enableState >= 0) {
- if (DEBUG) {
- Slog.i(TAG, "Migrating enable state " + (enableState != 0));
- }
- writeBackupEnableState(enableState != 0, UserHandle.USER_SYSTEM);
- Settings.Secure.putStringForUser(resolver,
- Settings.Secure.BACKUP_ENABLED, null, UserHandle.USER_SYSTEM);
- } else {
- if (DEBUG) {
- Slog.i(TAG, "Backup not yet configured; retaining null enable state");
- }
- }
- }
- Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
-
- Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "backup enable");
- try {
- sInstance.setBackupEnabled(readBackupEnableState(UserHandle.USER_SYSTEM));
- } catch (RemoteException e) {
- // can't happen; it's a local object
- }
- Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
- }
-
- /**
* Utility: build a new random integer token. The low bits are the ordinal of the operation for
* near-time uniqueness, and the upper bits are random for app-side unpredictability.
*/
@@ -2761,7 +2664,8 @@ public class BackupManagerService {
try {
boolean wasEnabled = mEnabled;
synchronized (this) {
- writeBackupEnableState(enable, UserHandle.USER_SYSTEM);
+ // TODO(b/118520567): Clean up writing backup enabled logic.
+ GlobalBackupManagerService.writeBackupEnableState(enable, UserHandle.USER_SYSTEM);
mEnabled = enable;
}
@@ -3594,72 +3498,4 @@ public class BackupManagerService {
public IBackupManager getBackupManagerBinder() {
return mBackupManagerBinder;
}
-
- private static boolean backupSettingMigrated(int userId) {
- File base = new File(Environment.getDataDirectory(), "backup");
- File enableFile = new File(base, BACKUP_ENABLE_FILE);
- return enableFile.exists();
- }
-
- private static boolean readBackupEnableState(int userId) {
- File base = new File(Environment.getDataDirectory(), "backup");
- File enableFile = new File(base, BACKUP_ENABLE_FILE);
- if (enableFile.exists()) {
- try (FileInputStream fin = new FileInputStream(enableFile)) {
- int state = fin.read();
- return state != 0;
- } catch (IOException e) {
- // can't read the file; fall through to assume disabled
- Slog.e(TAG, "Cannot read enable state; assuming disabled");
- }
- } else {
- if (DEBUG) {
- Slog.i(TAG, "isBackupEnabled() => false due to absent settings file");
- }
- }
- return false;
- }
-
- private static void writeBackupEnableState(boolean enable, int userId) {
- File base = new File(Environment.getDataDirectory(), "backup");
- File enableFile = new File(base, BACKUP_ENABLE_FILE);
- File stage = new File(base, BACKUP_ENABLE_FILE + "-stage");
- try (FileOutputStream fout = new FileOutputStream(stage)) {
- fout.write(enable ? 1 : 0);
- fout.close();
- stage.renameTo(enableFile);
- // will be synced immediately by the try-with-resources call to close()
- } catch (IOException | RuntimeException e) {
- // Whoops; looks like we're doomed. Roll everything out, disabled,
- // including the legacy state.
- Slog.e(TAG, "Unable to record backup enable state; reverting to disabled: "
- + e.getMessage());
-
- ContentResolver resolver = sInstance.getContext().getContentResolver();
- Settings.Secure.putStringForUser(resolver,
- Settings.Secure.BACKUP_ENABLED, null, userId);
- enableFile.delete();
- stage.delete();
- }
- }
-
- /** Implementation to receive lifecycle event callbacks for system services. */
- public static final class Lifecycle extends SystemService {
- public Lifecycle(Context context) {
- super(context);
- sInstance = new Trampoline(context);
- }
-
- @Override
- public void onStart() {
- publishBinderService(Context.BACKUP_SERVICE, sInstance);
- }
-
- @Override
- public void onUnlockUser(int userId) {
- if (userId == UserHandle.USER_SYSTEM) {
- sInstance.unlockSystemUser();
- }
- }
- }
}
diff --git a/services/backup/java/com/android/server/backup/fullbackup/AppMetadataBackupWriter.java b/services/backup/java/com/android/server/backup/fullbackup/AppMetadataBackupWriter.java
index 94365d7dc02d..725bc74a66c6 100644
--- a/services/backup/java/com/android/server/backup/fullbackup/AppMetadataBackupWriter.java
+++ b/services/backup/java/com/android/server/backup/fullbackup/AppMetadataBackupWriter.java
@@ -1,10 +1,10 @@
package com.android.server.backup.fullbackup;
-import static com.android.server.backup.BackupManagerService.BACKUP_MANIFEST_VERSION;
-import static com.android.server.backup.BackupManagerService.BACKUP_METADATA_VERSION;
-import static com.android.server.backup.BackupManagerService.BACKUP_WIDGET_METADATA_TOKEN;
-import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.MORE_DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_MANIFEST_VERSION;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_METADATA_VERSION;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_WIDGET_METADATA_TOKEN;
import android.annotation.Nullable;
import android.app.backup.FullBackup;
diff --git a/services/backup/java/com/android/server/backup/fullbackup/FullBackupEngine.java b/services/backup/java/com/android/server/backup/fullbackup/FullBackupEngine.java
index c9f72181bcaf..e9aad020bf28 100644
--- a/services/backup/java/com/android/server/backup/fullbackup/FullBackupEngine.java
+++ b/services/backup/java/com/android/server/backup/fullbackup/FullBackupEngine.java
@@ -16,13 +16,13 @@
package com.android.server.backup.fullbackup;
-import static com.android.server.backup.BackupManagerService.BACKUP_MANIFEST_FILENAME;
-import static com.android.server.backup.BackupManagerService.BACKUP_METADATA_FILENAME;
-import static com.android.server.backup.BackupManagerService.DEBUG;
-import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
-import static com.android.server.backup.BackupManagerService.OP_TYPE_BACKUP_WAIT;
-import static com.android.server.backup.BackupManagerService.SHARED_BACKUP_AGENT_PACKAGE;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.MORE_DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_MANIFEST_FILENAME;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_METADATA_FILENAME;
+import static com.android.server.backup.UserBackupManagerService.OP_TYPE_BACKUP_WAIT;
+import static com.android.server.backup.UserBackupManagerService.SHARED_BACKUP_AGENT_PACKAGE;
import android.app.ApplicationThreadConstants;
import android.app.IBackupAgent;
@@ -39,8 +39,8 @@ import android.util.Slog;
import com.android.internal.util.Preconditions;
import com.android.server.AppWidgetBackupBridge;
import com.android.server.backup.BackupAgentTimeoutParameters;
-import com.android.server.backup.BackupManagerService;
import com.android.server.backup.BackupRestoreTask;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.remote.RemoteCall;
import com.android.server.backup.utils.FullBackupUtils;
@@ -53,7 +53,7 @@ import java.io.OutputStream;
* and emitting it to the designated OutputStream.
*/
public class FullBackupEngine {
- private BackupManagerService backupManagerService;
+ private UserBackupManagerService backupManagerService;
OutputStream mOutput;
FullBackupPreflight mPreflightHook;
BackupRestoreTask mTimeoutMonitor;
@@ -181,7 +181,7 @@ public class FullBackupEngine {
}
public FullBackupEngine(
- BackupManagerService backupManagerService,
+ UserBackupManagerService backupManagerService,
OutputStream output,
FullBackupPreflight preflightHook,
PackageInfo pkg,
diff --git a/services/backup/java/com/android/server/backup/fullbackup/FullBackupObbConnection.java b/services/backup/java/com/android/server/backup/fullbackup/FullBackupObbConnection.java
index bc7d9fc691dd..24784ea92c73 100644
--- a/services/backup/java/com/android/server/backup/fullbackup/FullBackupObbConnection.java
+++ b/services/backup/java/com/android/server/backup/fullbackup/FullBackupObbConnection.java
@@ -16,9 +16,9 @@
package com.android.server.backup.fullbackup;
-import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
-import static com.android.server.backup.BackupManagerService.OP_TYPE_BACKUP_WAIT;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.MORE_DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
+import static com.android.server.backup.UserBackupManagerService.OP_TYPE_BACKUP_WAIT;
import android.app.backup.IBackupManager;
import android.content.ComponentName;
@@ -34,7 +34,7 @@ import android.util.Slog;
import com.android.internal.backup.IObbBackupService;
import com.android.internal.util.Preconditions;
import com.android.server.backup.BackupAgentTimeoutParameters;
-import com.android.server.backup.BackupManagerService;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.utils.FullBackupUtils;
import java.io.IOException;
@@ -45,11 +45,11 @@ import java.io.OutputStream;
*/
public class FullBackupObbConnection implements ServiceConnection {
- private BackupManagerService backupManagerService;
+ private UserBackupManagerService backupManagerService;
volatile IObbBackupService mService;
private final BackupAgentTimeoutParameters mAgentTimeoutParameters;
- public FullBackupObbConnection(BackupManagerService backupManagerService) {
+ public FullBackupObbConnection(UserBackupManagerService backupManagerService) {
this.backupManagerService = backupManagerService;
mService = null;
mAgentTimeoutParameters = Preconditions.checkNotNull(
diff --git a/services/backup/java/com/android/server/backup/fullbackup/FullBackupTask.java b/services/backup/java/com/android/server/backup/fullbackup/FullBackupTask.java
index 8f6923b6c05b..0ed75bb4a1b4 100644
--- a/services/backup/java/com/android/server/backup/fullbackup/FullBackupTask.java
+++ b/services/backup/java/com/android/server/backup/fullbackup/FullBackupTask.java
@@ -16,7 +16,7 @@
package com.android.server.backup.fullbackup;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
import android.app.backup.IFullBackupRestoreObserver;
import android.os.RemoteException;
diff --git a/services/backup/java/com/android/server/backup/fullbackup/PerformAdbBackupTask.java b/services/backup/java/com/android/server/backup/fullbackup/PerformAdbBackupTask.java
index 44edabce72b6..2f7687fc7009 100644
--- a/services/backup/java/com/android/server/backup/fullbackup/PerformAdbBackupTask.java
+++ b/services/backup/java/com/android/server/backup/fullbackup/PerformAdbBackupTask.java
@@ -17,12 +17,12 @@
package com.android.server.backup.fullbackup;
import static com.android.server.backup.BackupPasswordManager.PBKDF_CURRENT;
-import static com.android.server.backup.BackupManagerService.BACKUP_FILE_HEADER_MAGIC;
-import static com.android.server.backup.BackupManagerService.BACKUP_FILE_VERSION;
-import static com.android.server.backup.BackupManagerService.DEBUG;
-import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
-import static com.android.server.backup.BackupManagerService.SHARED_BACKUP_AGENT_PACKAGE;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.MORE_DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_FILE_HEADER_MAGIC;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_FILE_VERSION;
+import static com.android.server.backup.UserBackupManagerService.SHARED_BACKUP_AGENT_PACKAGE;
import android.app.backup.IFullBackupRestoreObserver;
import android.content.pm.ApplicationInfo;
@@ -37,7 +37,7 @@ import android.util.Slog;
import com.android.server.AppWidgetBackupBridge;
import com.android.server.backup.BackupRestoreTask;
import com.android.server.backup.KeyValueAdbBackupEngine;
-import com.android.server.backup.BackupManagerService;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.utils.AppBackupUtils;
import com.android.server.backup.utils.PasswordUtils;
@@ -66,7 +66,7 @@ import javax.crypto.spec.SecretKeySpec;
*/
public class PerformAdbBackupTask extends FullBackupTask implements BackupRestoreTask {
- private BackupManagerService backupManagerService;
+ private UserBackupManagerService backupManagerService;
FullBackupEngine mBackupEngine;
final AtomicBoolean mLatch;
@@ -86,7 +86,7 @@ public class PerformAdbBackupTask extends FullBackupTask implements BackupRestor
String mEncryptPassword;
private final int mCurrentOpToken;
- public PerformAdbBackupTask(BackupManagerService backupManagerService,
+ public PerformAdbBackupTask(UserBackupManagerService backupManagerService,
ParcelFileDescriptor fd, IFullBackupRestoreObserver observer,
boolean includeApks, boolean includeObbs, boolean includeShared, boolean doWidgets,
String curPassword, String encryptPassword, boolean doAllApps, boolean doSystem,
diff --git a/services/backup/java/com/android/server/backup/fullbackup/PerformFullTransportBackupTask.java b/services/backup/java/com/android/server/backup/fullbackup/PerformFullTransportBackupTask.java
index 755095ec1b18..0d14e7ef3e55 100644
--- a/services/backup/java/com/android/server/backup/fullbackup/PerformFullTransportBackupTask.java
+++ b/services/backup/java/com/android/server/backup/fullbackup/PerformFullTransportBackupTask.java
@@ -16,12 +16,12 @@
package com.android.server.backup.fullbackup;
-import static com.android.server.backup.BackupManagerService.DEBUG;
-import static com.android.server.backup.BackupManagerService.DEBUG_SCHEDULING;
-import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
-import static com.android.server.backup.BackupManagerService.OP_PENDING;
-import static com.android.server.backup.BackupManagerService.OP_TYPE_BACKUP;
-import static com.android.server.backup.BackupManagerService.OP_TYPE_BACKUP_WAIT;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG_SCHEDULING;
+import static com.android.server.backup.GlobalBackupManagerService.MORE_DEBUG;
+import static com.android.server.backup.UserBackupManagerService.OP_PENDING;
+import static com.android.server.backup.UserBackupManagerService.OP_TYPE_BACKUP;
+import static com.android.server.backup.UserBackupManagerService.OP_TYPE_BACKUP_WAIT;
import android.annotation.Nullable;
import android.app.IBackupAgent;
@@ -45,10 +45,10 @@ import com.android.internal.backup.IBackupTransport;
import com.android.internal.util.Preconditions;
import com.android.server.EventLogTags;
import com.android.server.backup.BackupAgentTimeoutParameters;
-import com.android.server.backup.BackupManagerService;
import com.android.server.backup.BackupRestoreTask;
import com.android.server.backup.FullBackupJob;
import com.android.server.backup.TransportManager;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.internal.OnTaskFinishedListener;
import com.android.server.backup.internal.Operation;
import com.android.server.backup.remote.RemoteCall;
@@ -97,7 +97,7 @@ import java.util.concurrent.atomic.AtomicLong;
*/
public class PerformFullTransportBackupTask extends FullBackupTask implements BackupRestoreTask {
public static PerformFullTransportBackupTask newWithCurrentTransport(
- BackupManagerService backupManagerService,
+ UserBackupManagerService backupManagerService,
IFullBackupRestoreObserver observer,
String[] whichPackages,
boolean updateSchedule,
@@ -128,7 +128,7 @@ public class PerformFullTransportBackupTask extends FullBackupTask implements Ba
private static final String TAG = "PFTBT";
- private BackupManagerService backupManagerService;
+ private UserBackupManagerService backupManagerService;
private final Object mCancelLock = new Object();
ArrayList<PackageInfo> mPackages;
@@ -150,7 +150,7 @@ public class PerformFullTransportBackupTask extends FullBackupTask implements Ba
private final int mCurrentOpToken;
private final BackupAgentTimeoutParameters mAgentTimeoutParameters;
- public PerformFullTransportBackupTask(BackupManagerService backupManagerService,
+ public PerformFullTransportBackupTask(UserBackupManagerService backupManagerService,
TransportClient transportClient,
IFullBackupRestoreObserver observer,
String[] whichPackages, boolean updateSchedule,
diff --git a/services/backup/java/com/android/server/backup/internal/BackupHandler.java b/services/backup/java/com/android/server/backup/internal/BackupHandler.java
index f66d8cc8a9a5..fd0946679655 100644
--- a/services/backup/java/com/android/server/backup/internal/BackupHandler.java
+++ b/services/backup/java/com/android/server/backup/internal/BackupHandler.java
@@ -16,9 +16,9 @@
package com.android.server.backup.internal;
-import static com.android.server.backup.BackupManagerService.DEBUG;
-import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.MORE_DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
import android.app.backup.RestoreSet;
import android.content.Intent;
@@ -35,10 +35,10 @@ import com.android.internal.backup.IBackupTransport;
import com.android.internal.util.Preconditions;
import com.android.server.EventLogTags;
import com.android.server.backup.BackupAgentTimeoutParameters;
-import com.android.server.backup.BackupManagerService;
import com.android.server.backup.BackupRestoreTask;
import com.android.server.backup.DataChangedJournal;
import com.android.server.backup.TransportManager;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.fullbackup.PerformAdbBackupTask;
import com.android.server.backup.fullbackup.PerformFullTransportBackupTask;
import com.android.server.backup.keyvalue.BackupRequest;
@@ -84,10 +84,10 @@ public class BackupHandler extends Handler {
public static final int MSG_BACKUP_RESTORE_STEP = 20;
public static final int MSG_OP_COMPLETE = 21;
- private final BackupManagerService backupManagerService;
+ private final UserBackupManagerService backupManagerService;
private final BackupAgentTimeoutParameters mAgentTimeoutParameters;
- public BackupHandler(BackupManagerService backupManagerService, Looper looper) {
+ public BackupHandler(UserBackupManagerService backupManagerService, Looper looper) {
super(looper);
this.backupManagerService = backupManagerService;
mAgentTimeoutParameters = Preconditions.checkNotNull(
diff --git a/services/backup/java/com/android/server/backup/internal/ClearDataObserver.java b/services/backup/java/com/android/server/backup/internal/ClearDataObserver.java
index b0b8037dbc64..396f36951a52 100644
--- a/services/backup/java/com/android/server/backup/internal/ClearDataObserver.java
+++ b/services/backup/java/com/android/server/backup/internal/ClearDataObserver.java
@@ -18,13 +18,13 @@ package com.android.server.backup.internal;
import android.content.pm.IPackageDataObserver;
-import com.android.server.backup.BackupManagerService;
+import com.android.server.backup.UserBackupManagerService;
public class ClearDataObserver extends IPackageDataObserver.Stub {
- private BackupManagerService backupManagerService;
+ private UserBackupManagerService backupManagerService;
- public ClearDataObserver(BackupManagerService backupManagerService) {
+ public ClearDataObserver(UserBackupManagerService backupManagerService) {
this.backupManagerService = backupManagerService;
}
diff --git a/services/backup/java/com/android/server/backup/internal/PerformClearTask.java b/services/backup/java/com/android/server/backup/internal/PerformClearTask.java
index d0281040452e..2bad5fe7ae1e 100644
--- a/services/backup/java/com/android/server/backup/internal/PerformClearTask.java
+++ b/services/backup/java/com/android/server/backup/internal/PerformClearTask.java
@@ -16,26 +16,26 @@
package com.android.server.backup.internal;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
import android.content.pm.PackageInfo;
import android.util.Slog;
import com.android.internal.backup.IBackupTransport;
-import com.android.server.backup.BackupManagerService;
import com.android.server.backup.TransportManager;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.transport.TransportClient;
import java.io.File;
public class PerformClearTask implements Runnable {
- private final BackupManagerService mBackupManagerService;
+ private final UserBackupManagerService mBackupManagerService;
private final TransportManager mTransportManager;
private final TransportClient mTransportClient;
private final PackageInfo mPackage;
private final OnTaskFinishedListener mListener;
- PerformClearTask(BackupManagerService backupManagerService,
+ PerformClearTask(UserBackupManagerService backupManagerService,
TransportClient transportClient, PackageInfo packageInfo,
OnTaskFinishedListener listener) {
mBackupManagerService = backupManagerService;
diff --git a/services/backup/java/com/android/server/backup/internal/PerformInitializeTask.java b/services/backup/java/com/android/server/backup/internal/PerformInitializeTask.java
index 1ef740db614f..1637e559acb7 100644
--- a/services/backup/java/com/android/server/backup/internal/PerformInitializeTask.java
+++ b/services/backup/java/com/android/server/backup/internal/PerformInitializeTask.java
@@ -16,7 +16,7 @@
package com.android.server.backup.internal;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
import android.annotation.Nullable;
import android.app.AlarmManager;
@@ -30,8 +30,8 @@ import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.backup.IBackupTransport;
import com.android.server.EventLogTags;
-import com.android.server.backup.BackupManagerService;
import com.android.server.backup.TransportManager;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.transport.TransportClient;
import java.io.File;
@@ -49,7 +49,7 @@ import java.util.List;
* operation was successful then it's {@link BackupTransport#TRANSPORT_OK}.
*/
public class PerformInitializeTask implements Runnable {
- private final BackupManagerService mBackupManagerService;
+ private final UserBackupManagerService mBackupManagerService;
private final TransportManager mTransportManager;
private final String[] mQueue;
private final File mBaseStateDir;
@@ -57,7 +57,7 @@ public class PerformInitializeTask implements Runnable {
@Nullable private IBackupObserver mObserver;
public PerformInitializeTask(
- BackupManagerService backupManagerService,
+ UserBackupManagerService backupManagerService,
String[] transportNames,
@Nullable IBackupObserver observer,
OnTaskFinishedListener listener) {
@@ -72,7 +72,7 @@ public class PerformInitializeTask implements Runnable {
@VisibleForTesting
PerformInitializeTask(
- BackupManagerService backupManagerService,
+ UserBackupManagerService backupManagerService,
TransportManager transportManager,
String[] transportNames,
@Nullable IBackupObserver observer,
diff --git a/services/backup/java/com/android/server/backup/internal/ProvisionedObserver.java b/services/backup/java/com/android/server/backup/internal/ProvisionedObserver.java
index 69720d4ee07c..eab86629e75b 100644
--- a/services/backup/java/com/android/server/backup/internal/ProvisionedObserver.java
+++ b/services/backup/java/com/android/server/backup/internal/ProvisionedObserver.java
@@ -16,22 +16,22 @@
package com.android.server.backup.internal;
-import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.MORE_DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
import android.database.ContentObserver;
import android.os.Handler;
import android.util.Slog;
-import com.android.server.backup.BackupManagerService;
import com.android.server.backup.KeyValueBackupJob;
+import com.android.server.backup.UserBackupManagerService;
public class ProvisionedObserver extends ContentObserver {
- private BackupManagerService backupManagerService;
+ private UserBackupManagerService backupManagerService;
public ProvisionedObserver(
- BackupManagerService backupManagerService, Handler handler) {
+ UserBackupManagerService backupManagerService, Handler handler) {
super(handler);
this.backupManagerService = backupManagerService;
}
diff --git a/services/backup/java/com/android/server/backup/internal/RunBackupReceiver.java b/services/backup/java/com/android/server/backup/internal/RunBackupReceiver.java
index 6f574caabc23..d869f044f5a4 100644
--- a/services/backup/java/com/android/server/backup/internal/RunBackupReceiver.java
+++ b/services/backup/java/com/android/server/backup/internal/RunBackupReceiver.java
@@ -16,10 +16,10 @@
package com.android.server.backup.internal;
-import static com.android.server.backup.BackupManagerService.DEBUG;
-import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
-import static com.android.server.backup.BackupManagerService.RUN_BACKUP_ACTION;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.MORE_DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
+import static com.android.server.backup.UserBackupManagerService.RUN_BACKUP_ACTION;
import static com.android.server.backup.internal.BackupHandler.MSG_RUN_BACKUP;
import android.app.PendingIntent;
@@ -29,13 +29,13 @@ import android.content.Intent;
import android.os.Message;
import android.util.Slog;
-import com.android.server.backup.BackupManagerService;
+import com.android.server.backup.UserBackupManagerService;
public class RunBackupReceiver extends BroadcastReceiver {
- private BackupManagerService backupManagerService;
+ private UserBackupManagerService backupManagerService;
- public RunBackupReceiver(BackupManagerService backupManagerService) {
+ public RunBackupReceiver(UserBackupManagerService backupManagerService) {
this.backupManagerService = backupManagerService;
}
diff --git a/services/backup/java/com/android/server/backup/internal/RunInitializeReceiver.java b/services/backup/java/com/android/server/backup/internal/RunInitializeReceiver.java
index 548c580f78fb..880e608a2fdb 100644
--- a/services/backup/java/com/android/server/backup/internal/RunInitializeReceiver.java
+++ b/services/backup/java/com/android/server/backup/internal/RunInitializeReceiver.java
@@ -16,9 +16,9 @@
package com.android.server.backup.internal;
-import static com.android.server.backup.BackupManagerService.DEBUG;
-import static com.android.server.backup.BackupManagerService.RUN_INITIALIZE_ACTION;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
+import static com.android.server.backup.UserBackupManagerService.RUN_INITIALIZE_ACTION;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -27,12 +27,12 @@ import android.os.PowerManager;
import android.util.ArraySet;
import android.util.Slog;
-import com.android.server.backup.BackupManagerService;
+import com.android.server.backup.UserBackupManagerService;
public class RunInitializeReceiver extends BroadcastReceiver {
- private final BackupManagerService mBackupManagerService;
+ private final UserBackupManagerService mBackupManagerService;
- public RunInitializeReceiver(BackupManagerService backupManagerService) {
+ public RunInitializeReceiver(UserBackupManagerService backupManagerService) {
mBackupManagerService = backupManagerService;
}
diff --git a/services/backup/java/com/android/server/backup/keyvalue/KeyValueBackupReporter.java b/services/backup/java/com/android/server/backup/keyvalue/KeyValueBackupReporter.java
index bb8a1d1339a7..437abd22d249 100644
--- a/services/backup/java/com/android/server/backup/keyvalue/KeyValueBackupReporter.java
+++ b/services/backup/java/com/android/server/backup/keyvalue/KeyValueBackupReporter.java
@@ -28,8 +28,9 @@ import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.EventLogTags;
-import com.android.server.backup.BackupManagerService;
import com.android.server.backup.DataChangedJournal;
+import com.android.server.backup.GlobalBackupManagerService;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.remote.RemoteResult;
import com.android.server.backup.utils.BackupManagerMonitorUtils;
import com.android.server.backup.utils.BackupObserverUtils;
@@ -53,8 +54,8 @@ import java.util.List;
@VisibleForTesting
public class KeyValueBackupReporter {
@VisibleForTesting static final String TAG = "KeyValueBackupTask";
- private static final boolean DEBUG = BackupManagerService.DEBUG;
- @VisibleForTesting static final boolean MORE_DEBUG = BackupManagerService.MORE_DEBUG || false;
+ private static final boolean DEBUG = GlobalBackupManagerService.DEBUG;
+ @VisibleForTesting static final boolean MORE_DEBUG = GlobalBackupManagerService.MORE_DEBUG;
static void onNewThread(String threadName) {
if (DEBUG) {
@@ -62,12 +63,12 @@ public class KeyValueBackupReporter {
}
}
- private final BackupManagerService mBackupManagerService;
+ private final UserBackupManagerService mBackupManagerService;
private final IBackupObserver mObserver;
@Nullable private IBackupManagerMonitor mMonitor;
KeyValueBackupReporter(
- BackupManagerService backupManagerService,
+ UserBackupManagerService backupManagerService,
IBackupObserver observer,
@Nullable IBackupManagerMonitor monitor) {
mBackupManagerService = backupManagerService;
diff --git a/services/backup/java/com/android/server/backup/keyvalue/KeyValueBackupTask.java b/services/backup/java/com/android/server/backup/keyvalue/KeyValueBackupTask.java
index d6f2a8775518..f39d795735f3 100644
--- a/services/backup/java/com/android/server/backup/keyvalue/KeyValueBackupTask.java
+++ b/services/backup/java/com/android/server/backup/keyvalue/KeyValueBackupTask.java
@@ -22,9 +22,9 @@ import static android.os.ParcelFileDescriptor.MODE_READ_ONLY;
import static android.os.ParcelFileDescriptor.MODE_READ_WRITE;
import static android.os.ParcelFileDescriptor.MODE_TRUNCATE;
-import static com.android.server.backup.BackupManagerService.KEY_WIDGET_STATE;
-import static com.android.server.backup.BackupManagerService.OP_PENDING;
-import static com.android.server.backup.BackupManagerService.OP_TYPE_BACKUP;
+import static com.android.server.backup.UserBackupManagerService.KEY_WIDGET_STATE;
+import static com.android.server.backup.UserBackupManagerService.OP_PENDING;
+import static com.android.server.backup.UserBackupManagerService.OP_TYPE_BACKUP;
import android.annotation.IntDef;
import android.annotation.Nullable;
@@ -35,7 +35,6 @@ import android.app.backup.BackupDataOutput;
import android.app.backup.BackupManager;
import android.app.backup.BackupTransport;
import android.app.backup.IBackupCallback;
-import android.app.backup.IBackupManager;
import android.app.backup.IBackupManagerMonitor;
import android.app.backup.IBackupObserver;
import android.content.pm.ApplicationInfo;
@@ -55,11 +54,11 @@ import com.android.internal.backup.IBackupTransport;
import com.android.internal.util.Preconditions;
import com.android.server.AppWidgetBackupBridge;
import com.android.server.backup.BackupAgentTimeoutParameters;
-import com.android.server.backup.BackupManagerService;
import com.android.server.backup.BackupRestoreTask;
import com.android.server.backup.DataChangedJournal;
import com.android.server.backup.KeyValueBackupJob;
import com.android.server.backup.TransportManager;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.fullbackup.PerformFullTransportBackupTask;
import com.android.server.backup.internal.OnTaskFinishedListener;
import com.android.server.backup.internal.Operation;
@@ -95,12 +94,12 @@ import java.util.concurrent.atomic.AtomicInteger;
* <p>A few definitions:
*
* <ul>
- * <li>State directory: {@link BackupManagerService#getBaseStateDir()}/&lt;transport&gt;
+ * <li>State directory: {@link UserBackupManagerService#getBaseStateDir()}/&lt;transport&gt;
* <li>State file: {@link
- * BackupManagerService#getBaseStateDir()}/&lt;transport&gt;/&lt;package&gt;<br>
+ * UserBackupManagerService#getBaseStateDir()}/&lt;transport&gt;/&lt;package&gt;<br>
* Represents the state of the backup data for a specific package in the current dataset.
- * <li>Stage directory: {@link BackupManagerService#getDataDir()}
- * <li>Stage file: {@link BackupManagerService#getDataDir()}/&lt;package&gt;.data<br>
+ * <li>Stage directory: {@link UserBackupManagerService#getDataDir()}
+ * <li>Stage file: {@link UserBackupManagerService#getDataDir()}/&lt;package&gt;.data<br>
* Contains staged data that the agents wrote via {@link BackupDataOutput}, to be transmitted
* to the transport.
* </ul>
@@ -112,7 +111,7 @@ import java.util.concurrent.atomic.AtomicInteger;
* of incremental choice. If non-incremental, PM will only be backed-up if specified in the queue,
* and if it's the case it will be re-positioned at the head of the queue.
*
- * <p>Before starting, this task will register itself in {@link BackupManagerService} current
+ * <p>Before starting, this task will register itself in {@link UserBackupManagerService} current
* operations.
*
* <p>In summary, this task will for each package:
@@ -121,7 +120,7 @@ import java.util.concurrent.atomic.AtomicInteger;
* <li>Bind to its {@link IBackupAgent}.
* <li>Request transport quota and flags.
* <li>Call {@link IBackupAgent#doBackup(ParcelFileDescriptor, ParcelFileDescriptor,
- * ParcelFileDescriptor, long, int, IBackupManager, int)} via {@link RemoteCall} passing the
+ * ParcelFileDescriptor, long, IBackupCallback, int)} via {@link RemoteCall} passing the
* old state file descriptor (read), the backup data file descriptor (write), the new state
* file descriptor (write), the quota and the transport flags. This will call {@link
* BackupAgent#onBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor)} with
@@ -131,7 +130,7 @@ import java.util.concurrent.atomic.AtomicInteger;
* <ul>
* <li>Agent response.
* <li>Agent time-out (specified via {@link
- * BackupManagerService#getAgentTimeoutParameters()}.
+ * UserBackupManagerService#getAgentTimeoutParameters()}.
* <li>External cancellation or thread interrupt.
* </ul>
* <li>Unbind the agent.
@@ -149,11 +148,11 @@ import java.util.concurrent.atomic.AtomicInteger;
* <li>Mark data-changed for the remaining packages in the queue (skipped packages).
* <li>Delete the {@link DataChangedJournal} provided. Note that this should not be the current
* journal.
- * <li>Set {@link BackupManagerService} current token as {@link
+ * <li>Set {@link UserBackupManagerService} current token as {@link
* IBackupTransport#getCurrentRestoreSet()}, if applicable.
* <li>Add the transport to the list of transports pending initialization ({@link
- * BackupManagerService#getPendingInits()}) and kick-off initialization if the transport ever
- * returned {@link BackupTransport#TRANSPORT_NOT_INITIALIZED}.
+ * UserBackupManagerService#getPendingInits()}) and kick-off initialization if the transport
+ * ever returned {@link BackupTransport#TRANSPORT_NOT_INITIALIZED}.
* <li>Unregister the task in current operations.
* <li>Release the wakelock.
* <li>Kick-off {@link PerformFullTransportBackupTask} if a list of full-backup packages was
@@ -174,7 +173,7 @@ public class KeyValueBackupTask implements BackupRestoreTask, Runnable {
private static final int THREAD_PRIORITY = Process.THREAD_PRIORITY_BACKGROUND;
private static final AtomicInteger THREAD_COUNT = new AtomicInteger();
private static final String BLANK_STATE_FILE_NAME = "blank_state";
- private static final String PM_PACKAGE = BackupManagerService.PACKAGE_MANAGER_SENTINEL;
+ private static final String PM_PACKAGE = UserBackupManagerService.PACKAGE_MANAGER_SENTINEL;
@VisibleForTesting public static final String STAGING_FILE_SUFFIX = ".data";
@VisibleForTesting public static final String NEW_STATE_FILE_SUFFIX = ".new";
@@ -182,7 +181,7 @@ public class KeyValueBackupTask implements BackupRestoreTask, Runnable {
* Creates a new {@link KeyValueBackupTask} for key-value backup operation, spins up a new
* dedicated thread and kicks off the operation in it.
*
- * @param backupManagerService The {@link BackupManagerService} system service.
+ * @param backupManagerService The {@link UserBackupManagerService} instance.
* @param transportClient The {@link TransportClient} that contains the transport used for the
* operation.
* @param transportDirName The value of {@link IBackupTransport#transportDirName()} for the
@@ -201,7 +200,7 @@ public class KeyValueBackupTask implements BackupRestoreTask, Runnable {
* @return The {@link KeyValueBackupTask} that was started.
*/
public static KeyValueBackupTask start(
- BackupManagerService backupManagerService,
+ UserBackupManagerService backupManagerService,
TransportClient transportClient,
String transportDirName,
List<String> queue,
@@ -232,7 +231,7 @@ public class KeyValueBackupTask implements BackupRestoreTask, Runnable {
return task;
}
- private final BackupManagerService mBackupManagerService;
+ private final UserBackupManagerService mBackupManagerService;
private final PackageManager mPackageManager;
private final TransportManager mTransportManager;
private final TransportClient mTransportClient;
@@ -289,7 +288,7 @@ public class KeyValueBackupTask implements BackupRestoreTask, Runnable {
@VisibleForTesting
public KeyValueBackupTask(
- BackupManagerService backupManagerService,
+ UserBackupManagerService backupManagerService,
TransportClient transportClient,
String transportDirName,
List<String> queue,
diff --git a/services/backup/java/com/android/server/backup/remote/ServiceBackupCallback.java b/services/backup/java/com/android/server/backup/remote/ServiceBackupCallback.java
index 28d85a694d4b..bfc97ae81f97 100644
--- a/services/backup/java/com/android/server/backup/remote/ServiceBackupCallback.java
+++ b/services/backup/java/com/android/server/backup/remote/ServiceBackupCallback.java
@@ -20,12 +20,12 @@ import android.app.backup.IBackupCallback;
import android.app.backup.IBackupManager;
import android.os.RemoteException;
-import com.android.server.backup.BackupManagerService;
+import com.android.server.backup.UserBackupManagerService;
/**
* An implementation of {@link IBackupCallback} that routes the result to {@link
- * BackupManagerService} via {@link IBackupManager#opComplete(int, long)} passing the token provided
- * in the constructor.
+ * UserBackupManagerService} via {@link IBackupManager#opComplete(int, long)} passing the token
+ * provided in the constructor.
*/
public class ServiceBackupCallback extends IBackupCallback.Stub {
private final IBackupManager mBackupManager;
diff --git a/services/backup/java/com/android/server/backup/restore/ActiveRestoreSession.java b/services/backup/java/com/android/server/backup/restore/ActiveRestoreSession.java
index 140dded1cb74..5c05371aedda 100644
--- a/services/backup/java/com/android/server/backup/restore/ActiveRestoreSession.java
+++ b/services/backup/java/com/android/server/backup/restore/ActiveRestoreSession.java
@@ -16,8 +16,8 @@
package com.android.server.backup.restore;
-import static com.android.server.backup.BackupManagerService.DEBUG;
-import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.MORE_DEBUG;
import static com.android.server.backup.internal.BackupHandler.MSG_RESTORE_SESSION_TIMEOUT;
import static com.android.server.backup.internal.BackupHandler.MSG_RUN_GET_RESTORE_SETS;
import static com.android.server.backup.internal.BackupHandler.MSG_RUN_RESTORE;
@@ -36,8 +36,8 @@ import android.os.Message;
import android.os.PowerManager;
import android.util.Slog;
-import com.android.server.backup.BackupManagerService;
import com.android.server.backup.TransportManager;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.internal.OnTaskFinishedListener;
import com.android.server.backup.params.RestoreGetSetsParams;
import com.android.server.backup.params.RestoreParams;
@@ -53,14 +53,14 @@ public class ActiveRestoreSession extends IRestoreSession.Stub {
private final TransportManager mTransportManager;
private final String mTransportName;
- private final BackupManagerService mBackupManagerService;
+ private final UserBackupManagerService mBackupManagerService;
@Nullable private final String mPackageName;
public RestoreSet[] mRestoreSets = null;
boolean mEnded = false;
boolean mTimedOut = false;
public ActiveRestoreSession(
- BackupManagerService backupManagerService,
+ UserBackupManagerService backupManagerService,
@Nullable String packageName,
String transportName) {
mBackupManagerService = backupManagerService;
@@ -405,10 +405,10 @@ public class ActiveRestoreSession extends IRestoreSession.Stub {
// Posted to the handler to tear down a restore session in a cleanly synchronized way
public class EndRestoreRunnable implements Runnable {
- BackupManagerService mBackupManager;
+ UserBackupManagerService mBackupManager;
ActiveRestoreSession mSession;
- public EndRestoreRunnable(BackupManagerService manager, ActiveRestoreSession session) {
+ public EndRestoreRunnable(UserBackupManagerService manager, ActiveRestoreSession session) {
mBackupManager = manager;
mSession = session;
}
diff --git a/services/backup/java/com/android/server/backup/restore/AdbRestoreFinishedLatch.java b/services/backup/java/com/android/server/backup/restore/AdbRestoreFinishedLatch.java
index a8c7ce6ad832..8196e709f2ee 100644
--- a/services/backup/java/com/android/server/backup/restore/AdbRestoreFinishedLatch.java
+++ b/services/backup/java/com/android/server/backup/restore/AdbRestoreFinishedLatch.java
@@ -16,15 +16,15 @@
package com.android.server.backup.restore;
-import static com.android.server.backup.BackupManagerService.DEBUG;
-import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.MORE_DEBUG;
import android.util.Slog;
import com.android.internal.util.Preconditions;
import com.android.server.backup.BackupAgentTimeoutParameters;
-import com.android.server.backup.BackupManagerService;
import com.android.server.backup.BackupRestoreTask;
+import com.android.server.backup.UserBackupManagerService;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -35,12 +35,12 @@ import java.util.concurrent.TimeUnit;
public class AdbRestoreFinishedLatch implements BackupRestoreTask {
private static final String TAG = "AdbRestoreFinishedLatch";
- private BackupManagerService backupManagerService;
+ private UserBackupManagerService backupManagerService;
final CountDownLatch mLatch;
private final int mCurrentOpToken;
private final BackupAgentTimeoutParameters mAgentTimeoutParameters;
- public AdbRestoreFinishedLatch(BackupManagerService backupManagerService,
+ public AdbRestoreFinishedLatch(UserBackupManagerService backupManagerService,
int currentOpToken) {
this.backupManagerService = backupManagerService;
mLatch = new CountDownLatch(1);
diff --git a/services/backup/java/com/android/server/backup/restore/AdbRestoreFinishedRunnable.java b/services/backup/java/com/android/server/backup/restore/AdbRestoreFinishedRunnable.java
index dc7044e450b7..184a6d03428f 100644
--- a/services/backup/java/com/android/server/backup/restore/AdbRestoreFinishedRunnable.java
+++ b/services/backup/java/com/android/server/backup/restore/AdbRestoreFinishedRunnable.java
@@ -3,7 +3,7 @@ package com.android.server.backup.restore;
import android.app.IBackupAgent;
import android.os.RemoteException;
-import com.android.server.backup.BackupManagerService;
+import com.android.server.backup.UserBackupManagerService;
/**
* Runner that can be placed on a separate thread to do in-process invocation of the "restore
@@ -13,10 +13,10 @@ public class AdbRestoreFinishedRunnable implements Runnable {
private final IBackupAgent mAgent;
private final int mToken;
- private final BackupManagerService mBackupManagerService;
+ private final UserBackupManagerService mBackupManagerService;
AdbRestoreFinishedRunnable(IBackupAgent agent, int token,
- BackupManagerService backupManagerService) {
+ UserBackupManagerService backupManagerService) {
mAgent = agent;
mToken = token;
mBackupManagerService = backupManagerService;
diff --git a/services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java b/services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java
index 1084f52ed36d..ee08902aca05 100644
--- a/services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java
+++ b/services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java
@@ -16,13 +16,13 @@
package com.android.server.backup.restore;
-import static com.android.server.backup.BackupManagerService.BACKUP_MANIFEST_FILENAME;
-import static com.android.server.backup.BackupManagerService.BACKUP_METADATA_FILENAME;
-import static com.android.server.backup.BackupManagerService.DEBUG;
-import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
-import static com.android.server.backup.BackupManagerService.OP_TYPE_RESTORE_WAIT;
-import static com.android.server.backup.BackupManagerService.SHARED_BACKUP_AGENT_PACKAGE;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.MORE_DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_MANIFEST_FILENAME;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_METADATA_FILENAME;
+import static com.android.server.backup.UserBackupManagerService.OP_TYPE_RESTORE_WAIT;
+import static com.android.server.backup.UserBackupManagerService.SHARED_BACKUP_AGENT_PACKAGE;
import static com.android.server.backup.internal.BackupHandler.MSG_RESTORE_OPERATION_TIMEOUT;
import android.app.ApplicationThreadConstants;
@@ -44,10 +44,10 @@ import android.util.Slog;
import com.android.internal.util.Preconditions;
import com.android.server.LocalServices;
import com.android.server.backup.BackupAgentTimeoutParameters;
-import com.android.server.backup.BackupManagerService;
import com.android.server.backup.BackupRestoreTask;
import com.android.server.backup.FileMetadata;
import com.android.server.backup.KeyValueAdbRestoreEngine;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.fullbackup.FullBackupObbConnection;
import com.android.server.backup.utils.BytesReadListener;
import com.android.server.backup.utils.FullBackupRestoreObserverUtils;
@@ -57,7 +57,6 @@ import com.android.server.backup.utils.TarBackupReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@@ -68,7 +67,7 @@ import java.util.List;
*/
public class FullRestoreEngine extends RestoreEngine {
- private final BackupManagerService mBackupManagerService;
+ private final UserBackupManagerService mBackupManagerService;
// Task in charge of monitoring timeouts
private final BackupRestoreTask mMonitorTask;
@@ -129,7 +128,7 @@ public class FullRestoreEngine extends RestoreEngine {
private final BackupAgentTimeoutParameters mAgentTimeoutParameters;
final boolean mIsAdbRestore;
- public FullRestoreEngine(BackupManagerService backupManagerService,
+ public FullRestoreEngine(UserBackupManagerService backupManagerService,
BackupRestoreTask monitorTask, IFullBackupRestoreObserver observer,
IBackupManagerMonitor monitor, PackageInfo onlyPackage, boolean allowApks,
boolean allowObbs, int ephemeralOpToken, boolean isAdbRestore) {
diff --git a/services/backup/java/com/android/server/backup/restore/PerformAdbRestoreTask.java b/services/backup/java/com/android/server/backup/restore/PerformAdbRestoreTask.java
index 32dbad9f92db..381252dafe07 100644
--- a/services/backup/java/com/android/server/backup/restore/PerformAdbRestoreTask.java
+++ b/services/backup/java/com/android/server/backup/restore/PerformAdbRestoreTask.java
@@ -16,18 +16,15 @@
package com.android.server.backup.restore;
-import static com.android.server.backup.BackupManagerService.BACKUP_FILE_HEADER_MAGIC;
-import static com.android.server.backup.BackupManagerService.BACKUP_FILE_VERSION;
-import static com.android.server.backup.BackupManagerService.DEBUG;
-import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
-import static com.android.server.backup.BackupManagerService.OP_TYPE_RESTORE_WAIT;
-import static com.android.server.backup.BackupManagerService.SETTINGS_PACKAGE;
-import static com.android.server.backup.BackupManagerService.SHARED_BACKUP_AGENT_PACKAGE;
-import static com.android.server.backup.BackupManagerService.TAG;
import static com.android.server.backup.BackupPasswordManager.PBKDF_CURRENT;
import static com.android.server.backup.BackupPasswordManager.PBKDF_FALLBACK;
-import static com.android.server.backup.internal.BackupHandler.MSG_RESTORE_OPERATION_TIMEOUT;
-
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.MORE_DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_FILE_HEADER_MAGIC;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_FILE_VERSION;
+import static com.android.server.backup.UserBackupManagerService.SETTINGS_PACKAGE;
+import static com.android.server.backup.UserBackupManagerService.SHARED_BACKUP_AGENT_PACKAGE;
import android.app.IBackupAgent;
import android.app.backup.BackupAgent;
@@ -36,15 +33,12 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.Signature;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
-import android.os.RemoteException;
import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.Preconditions;
-import com.android.server.LocalServices;
import com.android.server.backup.BackupAgentTimeoutParameters;
-import com.android.server.backup.BackupManagerService;
-import com.android.server.backup.PackageManagerBackupAgent;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.fullbackup.FullBackupObbConnection;
import com.android.server.backup.utils.FullBackupRestoreObserverUtils;
import com.android.server.backup.utils.PasswordUtils;
@@ -72,7 +66,7 @@ import javax.crypto.spec.SecretKeySpec;
public class PerformAdbRestoreTask implements Runnable {
- private final BackupManagerService mBackupManagerService;
+ private final UserBackupManagerService mBackupManagerService;
private final ParcelFileDescriptor mInputFile;
private final String mCurrentPassword;
private final String mDecryptPassword;
@@ -106,7 +100,7 @@ public class PerformAdbRestoreTask implements Runnable {
// Packages we've already wiped data on when restoring their first file
private final HashSet<String> mClearedPackages = new HashSet<>();
- public PerformAdbRestoreTask(BackupManagerService backupManagerService,
+ public PerformAdbRestoreTask(UserBackupManagerService backupManagerService,
ParcelFileDescriptor fd, String curPassword, String decryptPassword,
IFullBackupRestoreObserver observer, AtomicBoolean latch) {
this.mBackupManagerService = backupManagerService;
diff --git a/services/backup/java/com/android/server/backup/restore/PerformUnifiedRestoreTask.java b/services/backup/java/com/android/server/backup/restore/PerformUnifiedRestoreTask.java
index 580f70a046b5..7530356fff4d 100644
--- a/services/backup/java/com/android/server/backup/restore/PerformUnifiedRestoreTask.java
+++ b/services/backup/java/com/android/server/backup/restore/PerformUnifiedRestoreTask.java
@@ -16,13 +16,13 @@
package com.android.server.backup.restore;
-import static com.android.server.backup.BackupManagerService.DEBUG;
-import static com.android.server.backup.BackupManagerService.KEY_WIDGET_STATE;
-import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
-import static com.android.server.backup.BackupManagerService.OP_TYPE_RESTORE_WAIT;
-import static com.android.server.backup.BackupManagerService.PACKAGE_MANAGER_SENTINEL;
-import static com.android.server.backup.BackupManagerService.SETTINGS_PACKAGE;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.MORE_DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
+import static com.android.server.backup.UserBackupManagerService.KEY_WIDGET_STATE;
+import static com.android.server.backup.UserBackupManagerService.OP_TYPE_RESTORE_WAIT;
+import static com.android.server.backup.UserBackupManagerService.PACKAGE_MANAGER_SENTINEL;
+import static com.android.server.backup.UserBackupManagerService.SETTINGS_PACKAGE;
import static com.android.server.backup.internal.BackupHandler.MSG_BACKUP_RESTORE_STEP;
import static com.android.server.backup.internal.BackupHandler.MSG_RESTORE_OPERATION_TIMEOUT;
import static com.android.server.backup.internal.BackupHandler.MSG_RESTORE_SESSION_TIMEOUT;
@@ -40,8 +40,8 @@ import android.app.backup.RestoreDescription;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
-import android.content.pm.PackageManagerInternal;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.PackageManagerInternal;
import android.os.Bundle;
import android.os.Message;
import android.os.ParcelFileDescriptor;
@@ -62,8 +62,8 @@ import com.android.server.backup.BackupRestoreTask;
import com.android.server.backup.BackupUtils;
import com.android.server.backup.PackageManagerBackupAgent;
import com.android.server.backup.PackageManagerBackupAgent.Metadata;
-import com.android.server.backup.BackupManagerService;
import com.android.server.backup.TransportManager;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.internal.OnTaskFinishedListener;
import com.android.server.backup.transport.TransportClient;
import com.android.server.backup.utils.AppBackupUtils;
@@ -80,7 +80,7 @@ import java.util.List;
public class PerformUnifiedRestoreTask implements BackupRestoreTask {
- private BackupManagerService backupManagerService;
+ private UserBackupManagerService backupManagerService;
private final TransportManager mTransportManager;
// Transport client we're working with to do the restore
private final TransportClient mTransportClient;
@@ -164,7 +164,7 @@ public class PerformUnifiedRestoreTask implements BackupRestoreTask {
// This task can assume that the wakelock is properly held for it and doesn't have to worry
// about releasing it.
public PerformUnifiedRestoreTask(
- BackupManagerService backupManagerService,
+ UserBackupManagerService backupManagerService,
TransportClient transportClient,
IRestoreObserver observer,
IBackupManagerMonitor monitor,
diff --git a/services/backup/java/com/android/server/backup/restore/RestoreFileRunnable.java b/services/backup/java/com/android/server/backup/restore/RestoreFileRunnable.java
index 635b6d6bd431..c4aa2d745970 100644
--- a/services/backup/java/com/android/server/backup/restore/RestoreFileRunnable.java
+++ b/services/backup/java/com/android/server/backup/restore/RestoreFileRunnable.java
@@ -21,7 +21,7 @@ import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import com.android.server.backup.FileMetadata;
-import com.android.server.backup.BackupManagerService;
+import com.android.server.backup.UserBackupManagerService;
import java.io.IOException;
@@ -35,9 +35,9 @@ class RestoreFileRunnable implements Runnable {
private final FileMetadata mInfo;
private final ParcelFileDescriptor mSocket;
private final int mToken;
- private final BackupManagerService mBackupManagerService;
+ private final UserBackupManagerService mBackupManagerService;
- RestoreFileRunnable(BackupManagerService backupManagerService, IBackupAgent agent,
+ RestoreFileRunnable(UserBackupManagerService backupManagerService, IBackupAgent agent,
FileMetadata info, ParcelFileDescriptor socket, int token) throws IOException {
mAgent = agent;
mInfo = info;
diff --git a/services/backup/java/com/android/server/backup/utils/AppBackupUtils.java b/services/backup/java/com/android/server/backup/utils/AppBackupUtils.java
index c933833fa7a3..2452e4868c80 100644
--- a/services/backup/java/com/android/server/backup/utils/AppBackupUtils.java
+++ b/services/backup/java/com/android/server/backup/utils/AppBackupUtils.java
@@ -16,9 +16,9 @@
package com.android.server.backup.utils;
-import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
-import static com.android.server.backup.BackupManagerService.SHARED_BACKUP_AGENT_PACKAGE;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.MORE_DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
+import static com.android.server.backup.UserBackupManagerService.SHARED_BACKUP_AGENT_PACKAGE;
import android.annotation.Nullable;
import android.app.backup.BackupTransport;
diff --git a/services/backup/java/com/android/server/backup/utils/BackupManagerMonitorUtils.java b/services/backup/java/com/android/server/backup/utils/BackupManagerMonitorUtils.java
index 6f083760980d..8b931d43dfe0 100644
--- a/services/backup/java/com/android/server/backup/utils/BackupManagerMonitorUtils.java
+++ b/services/backup/java/com/android/server/backup/utils/BackupManagerMonitorUtils.java
@@ -18,8 +18,8 @@ package com.android.server.backup.utils;
import static android.app.backup.BackupManagerMonitor.EXTRA_LOG_EVENT_PACKAGE_NAME;
-import static com.android.server.backup.BackupManagerService.DEBUG;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
import android.annotation.Nullable;
import android.app.backup.BackupManagerMonitor;
diff --git a/services/backup/java/com/android/server/backup/utils/BackupObserverUtils.java b/services/backup/java/com/android/server/backup/utils/BackupObserverUtils.java
index c0cf2ef86920..9674c3db9c75 100644
--- a/services/backup/java/com/android/server/backup/utils/BackupObserverUtils.java
+++ b/services/backup/java/com/android/server/backup/utils/BackupObserverUtils.java
@@ -16,8 +16,8 @@
package com.android.server.backup.utils;
-import static com.android.server.backup.BackupManagerService.DEBUG;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
import android.app.backup.BackupProgress;
import android.app.backup.IBackupObserver;
diff --git a/services/backup/java/com/android/server/backup/utils/FullBackupRestoreObserverUtils.java b/services/backup/java/com/android/server/backup/utils/FullBackupRestoreObserverUtils.java
index fa856ce2c6de..92cdf0de48c7 100644
--- a/services/backup/java/com/android/server/backup/utils/FullBackupRestoreObserverUtils.java
+++ b/services/backup/java/com/android/server/backup/utils/FullBackupRestoreObserverUtils.java
@@ -16,7 +16,7 @@
package com.android.server.backup.utils;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
import android.app.backup.IFullBackupRestoreObserver;
import android.os.RemoteException;
diff --git a/services/backup/java/com/android/server/backup/utils/FullBackupUtils.java b/services/backup/java/com/android/server/backup/utils/FullBackupUtils.java
index dbe3cd9225b5..a6fdbf004726 100644
--- a/services/backup/java/com/android/server/backup/utils/FullBackupUtils.java
+++ b/services/backup/java/com/android/server/backup/utils/FullBackupUtils.java
@@ -16,7 +16,7 @@
package com.android.server.backup.utils;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
import android.os.ParcelFileDescriptor;
import android.util.Slog;
diff --git a/services/backup/java/com/android/server/backup/utils/PasswordUtils.java b/services/backup/java/com/android/server/backup/utils/PasswordUtils.java
index a7eb644713ba..65adf4ee267d 100644
--- a/services/backup/java/com/android/server/backup/utils/PasswordUtils.java
+++ b/services/backup/java/com/android/server/backup/utils/PasswordUtils.java
@@ -16,7 +16,7 @@
package com.android.server.backup.utils;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
import android.util.Slog;
diff --git a/services/backup/java/com/android/server/backup/utils/RestoreUtils.java b/services/backup/java/com/android/server/backup/utils/RestoreUtils.java
index df7e6d45ba0f..91567d7aa0e5 100644
--- a/services/backup/java/com/android/server/backup/utils/RestoreUtils.java
+++ b/services/backup/java/com/android/server/backup/utils/RestoreUtils.java
@@ -16,8 +16,8 @@
package com.android.server.backup.utils;
-import static com.android.server.backup.BackupManagerService.DEBUG;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
import android.content.Context;
import android.content.IIntentReceiver;
diff --git a/services/backup/java/com/android/server/backup/utils/TarBackupReader.java b/services/backup/java/com/android/server/backup/utils/TarBackupReader.java
index 6dd5284879f0..c295684d0732 100644
--- a/services/backup/java/com/android/server/backup/utils/TarBackupReader.java
+++ b/services/backup/java/com/android/server/backup/utils/TarBackupReader.java
@@ -34,14 +34,14 @@ import static android.app.backup.BackupManagerMonitor.LOG_EVENT_ID_SYSTEM_APP_NO
import static android.app.backup.BackupManagerMonitor.LOG_EVENT_ID_VERSIONS_MATCH;
import static android.app.backup.BackupManagerMonitor.LOG_EVENT_ID_VERSION_OF_BACKUP_OLDER;
-import static com.android.server.backup.BackupManagerService.BACKUP_MANIFEST_FILENAME;
-import static com.android.server.backup.BackupManagerService.BACKUP_MANIFEST_VERSION;
-import static com.android.server.backup.BackupManagerService.BACKUP_METADATA_FILENAME;
-import static com.android.server.backup.BackupManagerService.BACKUP_WIDGET_METADATA_TOKEN;
-import static com.android.server.backup.BackupManagerService.DEBUG;
-import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
-import static com.android.server.backup.BackupManagerService.SHARED_BACKUP_AGENT_PACKAGE;
-import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.GlobalBackupManagerService.DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.MORE_DEBUG;
+import static com.android.server.backup.GlobalBackupManagerService.TAG;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_MANIFEST_FILENAME;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_MANIFEST_VERSION;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_METADATA_FILENAME;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_WIDGET_METADATA_TOKEN;
+import static com.android.server.backup.UserBackupManagerService.SHARED_BACKUP_AGENT_PACKAGE;
import android.app.backup.BackupAgent;
import android.app.backup.BackupManagerMonitor;
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index f8ac41f3c40c..fbfb284e2d17 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -178,7 +178,7 @@ public final class SystemServer {
* them from the build system somehow.
*/
private static final String BACKUP_MANAGER_SERVICE_CLASS =
- "com.android.server.backup.BackupManagerService$Lifecycle";
+ "com.android.server.backup.GlobalBackupManagerService$Lifecycle";
private static final String APPWIDGET_SERVICE_CLASS =
"com.android.server.appwidget.AppWidgetService";
private static final String VOICE_RECOGNITION_MANAGER_SERVICE_CLASS =
diff --git a/services/robotests/src/com/android/server/backup/GlobalBackupManagerServiceTest.java b/services/robotests/src/com/android/server/backup/GlobalBackupManagerServiceTest.java
new file mode 100644
index 000000000000..3108c804b6f4
--- /dev/null
+++ b/services/robotests/src/com/android/server/backup/GlobalBackupManagerServiceTest.java
@@ -0,0 +1,525 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.backup;
+
+import static com.android.server.backup.testing.TransportData.backupTransport;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import android.app.Application;
+import android.app.backup.IBackupManagerMonitor;
+import android.app.backup.IBackupObserver;
+import android.app.backup.IFullBackupRestoreObserver;
+import android.app.backup.ISelectBackupTransportCallback;
+import android.content.Context;
+import android.content.Intent;
+import android.os.IBinder;
+import android.os.ParcelFileDescriptor;
+import android.platform.test.annotations.Presubmit;
+
+import com.android.server.backup.testing.BackupManagerServiceTestUtils;
+import com.android.server.backup.testing.TransportData;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+
+/** Tests for the user-aware backup/restore system service {@link GlobalBackupManagerService}. */
+@RunWith(RobolectricTestRunner.class)
+@Presubmit
+public class GlobalBackupManagerServiceTest {
+ private static final String TEST_PACKAGE = "package";
+ private static final String TEST_TRANSPORT = "transport";
+
+ @Mock private UserBackupManagerService mUserBackupManagerService;
+ @Mock private TransportManager mTransportManager;
+ private GlobalBackupManagerService mGlobalBackupManagerService;
+ private Context mContext;
+
+ /** Initialize {@link GlobalBackupManagerService}. */
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ Application application = RuntimeEnvironment.application;
+ mContext = application;
+ mGlobalBackupManagerService =
+ new GlobalBackupManagerService(
+ application,
+ new Trampoline(application),
+ BackupManagerServiceTestUtils.startBackupThread(null),
+ new File(application.getCacheDir(), "base_state"),
+ new File(application.getCacheDir(), "data"),
+ mTransportManager);
+ mGlobalBackupManagerService.setUserBackupManagerService(mUserBackupManagerService);
+ }
+
+ /**
+ * Test verifying that {@link GlobalBackupManagerService#MORE_DEBUG} is set to {@code false}.
+ * This is specifically to prevent overloading the logs in production.
+ */
+ @Test
+ public void testMoreDebug_isFalse() throws Exception {
+ boolean moreDebug = GlobalBackupManagerService.MORE_DEBUG;
+
+ assertThat(moreDebug).isFalse();
+ }
+
+ // TODO(b/118520567): Change the following tests to use the per-user instance of
+ // UserBackupManagerService once it's implemented. Currently these tests only test the straight
+ // forward redirection.
+
+ // ---------------------------------------------
+ // Backup agent tests
+ // ---------------------------------------------
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testDataChanged_callsDataChangedForUser() throws Exception {
+ mGlobalBackupManagerService.dataChanged(TEST_PACKAGE);
+
+ verify(mUserBackupManagerService).dataChanged(TEST_PACKAGE);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testAgentConnected_callsAgentConnectedForUser() throws Exception {
+ IBinder agentBinder = mock(IBinder.class);
+
+ mGlobalBackupManagerService.agentConnected(TEST_PACKAGE, agentBinder);
+
+ verify(mUserBackupManagerService).agentConnected(TEST_PACKAGE, agentBinder);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testAgentDisconnected_callsAgentDisconnectedForUser() throws Exception {
+ mGlobalBackupManagerService.agentDisconnected(TEST_PACKAGE);
+
+ verify(mUserBackupManagerService).agentDisconnected(TEST_PACKAGE);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testOpComplete_callsOpCompleteForUser() throws Exception {
+ mGlobalBackupManagerService.opComplete(/* token */ 0, /* result */ 0L);
+
+ verify(mUserBackupManagerService).opComplete(/* token */ 0, /* result */ 0L);
+ }
+
+ // ---------------------------------------------
+ // Transport tests
+ // ---------------------------------------------
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testInitializeTransports_callsInitializeTransportsForUser() throws Exception {
+ String[] transports = {TEST_TRANSPORT};
+
+ mGlobalBackupManagerService.initializeTransports(transports, /* observer */ null);
+
+ verify(mUserBackupManagerService).initializeTransports(transports, /* observer */ null);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testClearBackupData_callsClearBackupDataForUser() throws Exception {
+ mGlobalBackupManagerService.clearBackupData(TEST_TRANSPORT, TEST_PACKAGE);
+
+ verify(mUserBackupManagerService).clearBackupData(TEST_TRANSPORT, TEST_PACKAGE);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testGetCurrentTransport_callsGetCurrentTransportForUser() throws Exception {
+ mGlobalBackupManagerService.getCurrentTransport();
+
+ verify(mUserBackupManagerService).getCurrentTransport();
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testGetCurrentTransportComponent_callsGetCurrentTransportComponentForUser()
+ throws Exception {
+ mGlobalBackupManagerService.getCurrentTransportComponent();
+
+ verify(mUserBackupManagerService).getCurrentTransportComponent();
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testListAllTransports_callsListAllTransportsForUser() throws Exception {
+ mGlobalBackupManagerService.listAllTransports();
+
+ verify(mUserBackupManagerService).listAllTransports();
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testListAllTransportComponents_callsListAllTransportComponentsForUser()
+ throws Exception {
+ mGlobalBackupManagerService.listAllTransportComponents();
+
+ verify(mUserBackupManagerService).listAllTransportComponents();
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testGetTransportWhitelist_callsGetTransportWhitelistForUser() throws Exception {
+ mGlobalBackupManagerService.getTransportWhitelist();
+
+ verify(mUserBackupManagerService).getTransportWhitelist();
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testUpdateTransportAttributes_callsUpdateTransportAttributesForUser()
+ throws Exception {
+ TransportData transport = backupTransport();
+ Intent configurationIntent = new Intent();
+ Intent dataManagementIntent = new Intent();
+
+ mGlobalBackupManagerService.updateTransportAttributes(
+ transport.getTransportComponent(),
+ transport.transportName,
+ configurationIntent,
+ "currentDestinationString",
+ dataManagementIntent,
+ "dataManagementLabel");
+
+ verify(mUserBackupManagerService)
+ .updateTransportAttributes(
+ transport.getTransportComponent(),
+ transport.transportName,
+ configurationIntent,
+ "currentDestinationString",
+ dataManagementIntent,
+ "dataManagementLabel");
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testSelectBackupTransport_callsSelectBackupTransportForUser() throws Exception {
+ mGlobalBackupManagerService.selectBackupTransport(TEST_TRANSPORT);
+
+ verify(mUserBackupManagerService).selectBackupTransport(TEST_TRANSPORT);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testSelectTransportAsync_callsSelectTransportAsyncForUser() throws Exception {
+ TransportData transport = backupTransport();
+ ISelectBackupTransportCallback callback = mock(ISelectBackupTransportCallback.class);
+
+ mGlobalBackupManagerService.selectBackupTransportAsync(
+ transport.getTransportComponent(), callback);
+
+ verify(mUserBackupManagerService)
+ .selectBackupTransportAsync(transport.getTransportComponent(), callback);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testGetConfigurationIntent_callsGetConfigurationIntentForUser() throws Exception {
+ mGlobalBackupManagerService.getConfigurationIntent(TEST_TRANSPORT);
+
+ verify(mUserBackupManagerService).getConfigurationIntent(TEST_TRANSPORT);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testGetDestinationString_callsGetDestinationStringForUser() throws Exception {
+ mGlobalBackupManagerService.getDestinationString(TEST_TRANSPORT);
+
+ verify(mUserBackupManagerService).getDestinationString(TEST_TRANSPORT);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testGetDataManagementIntent_callsGetDataManagementIntentForUser() throws Exception {
+ mGlobalBackupManagerService.getDataManagementIntent(TEST_TRANSPORT);
+
+ verify(mUserBackupManagerService).getDataManagementIntent(TEST_TRANSPORT);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testGetDataManagementLabel_callsGetDataManagementLabelForUser() throws Exception {
+ mGlobalBackupManagerService.getDataManagementLabel(TEST_TRANSPORT);
+
+ verify(mUserBackupManagerService).getDataManagementLabel(TEST_TRANSPORT);
+ }
+
+ // ---------------------------------------------
+ // Settings tests
+ // ---------------------------------------------
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void setBackupEnabled_callsSetBackupEnabledForUser() throws Exception {
+ mGlobalBackupManagerService.setBackupEnabled(true);
+
+ verify(mUserBackupManagerService).setBackupEnabled(true);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void setAutoRestore_callsSetAutoRestoreForUser() throws Exception {
+ mGlobalBackupManagerService.setAutoRestore(true);
+
+ verify(mUserBackupManagerService).setAutoRestore(true);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testSetBackupProvisioned_callsSetBackupProvisionedForUser() throws Exception {
+ mGlobalBackupManagerService.setBackupProvisioned(true);
+
+ verify(mUserBackupManagerService).setBackupProvisioned(true);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testIsBackupEnabled_callsIsBackupEnabledForUser() throws Exception {
+ mGlobalBackupManagerService.isBackupEnabled();
+
+ verify(mUserBackupManagerService).isBackupEnabled();
+ }
+
+ // ---------------------------------------------
+ // Backup tests
+ // ---------------------------------------------
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testIsAppEligibleForBackup_callsIsAppEligibleForBackupForUser() throws Exception {
+ mGlobalBackupManagerService.isAppEligibleForBackup(TEST_PACKAGE);
+
+ verify(mUserBackupManagerService).isAppEligibleForBackup(TEST_PACKAGE);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testFilterAppsEligibleForBackup_callsFilterAppsEligibleForBackupForUser()
+ throws Exception {
+ String[] packages = {TEST_PACKAGE};
+
+ mGlobalBackupManagerService.filterAppsEligibleForBackup(packages);
+
+ verify(mUserBackupManagerService).filterAppsEligibleForBackup(packages);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testBackupNow_callsBackupNowForUser() throws Exception {
+ mGlobalBackupManagerService.backupNow();
+
+ verify(mUserBackupManagerService).backupNow();
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testRequestBackup_callsRequestBackupForUser() throws Exception {
+ String[] packages = {TEST_PACKAGE};
+ IBackupObserver observer = mock(IBackupObserver.class);
+ IBackupManagerMonitor monitor = mock(IBackupManagerMonitor.class);
+
+ mGlobalBackupManagerService.requestBackup(packages, observer, monitor, /* flags */ 0);
+
+ verify(mUserBackupManagerService).requestBackup(packages, observer, monitor, /* flags */ 0);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testCancelBackups_callsCancelBackupsForUser() throws Exception {
+ mGlobalBackupManagerService.cancelBackups();
+
+ verify(mUserBackupManagerService).cancelBackups();
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testBeginFullBackup_callsBeginFullBackupForUser() throws Exception {
+ FullBackupJob job = new FullBackupJob();
+
+ mGlobalBackupManagerService.beginFullBackup(job);
+
+ verify(mUserBackupManagerService).beginFullBackup(job);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testEndFullBackup_callsEndFullBackupForUser() throws Exception {
+ mGlobalBackupManagerService.endFullBackup();
+
+ verify(mUserBackupManagerService).endFullBackup();
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testFullTransportBackup_callsFullTransportBackupForUser() throws Exception {
+ String[] packages = {TEST_PACKAGE};
+
+ mGlobalBackupManagerService.fullTransportBackup(packages);
+
+ verify(mUserBackupManagerService).fullTransportBackup(packages);
+ }
+
+ // ---------------------------------------------
+ // Restore tests
+ // ---------------------------------------------
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testRestoreAtInstall_callsRestoreAtInstallForUser() throws Exception {
+ mGlobalBackupManagerService.restoreAtInstall(TEST_PACKAGE, /* token */ 0);
+
+ verify(mUserBackupManagerService).restoreAtInstall(TEST_PACKAGE, /* token */ 0);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testBeginRestoreSession_callsBeginRestoreSessionForUser() throws Exception {
+ mGlobalBackupManagerService.beginRestoreSession(TEST_PACKAGE, TEST_TRANSPORT);
+
+ verify(mUserBackupManagerService).beginRestoreSession(TEST_PACKAGE, TEST_TRANSPORT);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testGetAvailableRestoreToken_callsGetAvailableRestoreTokenForUser()
+ throws Exception {
+ mGlobalBackupManagerService.getAvailableRestoreToken(TEST_PACKAGE);
+
+ verify(mUserBackupManagerService).getAvailableRestoreToken(TEST_PACKAGE);
+ }
+
+ // ---------------------------------------------
+ // Adb backup/restore tests
+ // ---------------------------------------------
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testSetBackupPassword_callsSetBackupPasswordForUser() throws Exception {
+ mGlobalBackupManagerService.setBackupPassword("currentPassword", "newPassword");
+
+ verify(mUserBackupManagerService).setBackupPassword("currentPassword", "newPassword");
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testHasBackupPassword_callsHasBackupPasswordForUser() throws Exception {
+ mGlobalBackupManagerService.hasBackupPassword();
+
+ verify(mUserBackupManagerService).hasBackupPassword();
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testAdbBackup_callsAdbBackupForUser() throws Exception {
+ File testFile = new File(mContext.getFilesDir(), "test");
+ testFile.createNewFile();
+ ParcelFileDescriptor parcelFileDescriptor =
+ ParcelFileDescriptor.open(testFile, ParcelFileDescriptor.MODE_READ_WRITE);
+ String[] packages = {TEST_PACKAGE};
+
+ mGlobalBackupManagerService.adbBackup(
+ parcelFileDescriptor,
+ /* includeApks */ true,
+ /* includeObbs */ true,
+ /* includeShared */ true,
+ /* doWidgets */ true,
+ /* doAllApps */ true,
+ /* includeSystem */ true,
+ /* doCompress */ true,
+ /* doKeyValue */ true,
+ packages);
+
+ verify(mUserBackupManagerService)
+ .adbBackup(
+ parcelFileDescriptor,
+ /* includeApks */ true,
+ /* includeObbs */ true,
+ /* includeShared */ true,
+ /* doWidgets */ true,
+ /* doAllApps */ true,
+ /* includeSystem */ true,
+ /* doCompress */ true,
+ /* doKeyValue */ true,
+ packages);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testAdbRestore_callsAdbRestoreForUser() throws Exception {
+ File testFile = new File(mContext.getFilesDir(), "test");
+ testFile.createNewFile();
+ ParcelFileDescriptor parcelFileDescriptor =
+ ParcelFileDescriptor.open(testFile, ParcelFileDescriptor.MODE_READ_WRITE);
+
+ mGlobalBackupManagerService.adbRestore(parcelFileDescriptor);
+
+ verify(mUserBackupManagerService).adbRestore(parcelFileDescriptor);
+ }
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testAcknowledgeAdbBackupOrRestore_callsAcknowledgeAdbBackupOrRestoreForUser()
+ throws Exception {
+ IFullBackupRestoreObserver observer = mock(IFullBackupRestoreObserver.class);
+
+ mGlobalBackupManagerService.acknowledgeAdbBackupOrRestore(
+ /* token */ 0, /* allow */ true, "currentPassword", "encryptionPassword", observer);
+
+ verify(mUserBackupManagerService)
+ .acknowledgeAdbBackupOrRestore(
+ /* token */ 0,
+ /* allow */ true,
+ "currentPassword",
+ "encryptionPassword",
+ observer);
+ }
+
+ // ---------------------------------------------
+ // Service tests
+ // ---------------------------------------------
+
+ /** Test that the backup service routes methods correctly to the user that requests it. */
+ @Test
+ public void testDump_callsDumpForUser() throws Exception {
+ File testFile = new File(mContext.getFilesDir(), "test");
+ testFile.createNewFile();
+ FileDescriptor fileDescriptor = new FileDescriptor();
+ PrintWriter printWriter = new PrintWriter(testFile);
+ String[] args = {"1", "2"};
+
+ mGlobalBackupManagerService.dump(fileDescriptor, printWriter, args);
+
+ verify(mUserBackupManagerService).dump(fileDescriptor, printWriter, args);
+ }
+}
diff --git a/services/robotests/src/com/android/server/backup/BackupManagerServiceTest.java b/services/robotests/src/com/android/server/backup/UserBackupManagerServiceTest.java
index f7bb68c61a42..9d4381914608 100644
--- a/services/robotests/src/com/android/server/backup/BackupManagerServiceTest.java
+++ b/services/robotests/src/com/android/server/backup/UserBackupManagerServiceTest.java
@@ -76,11 +76,14 @@ import org.robolectric.shadows.ShadowSettings;
import java.io.File;
import java.util.List;
-/** Tests for the system service {@link BackupManagerService} that performs backup/restore. */
+/**
+ * Tests for the per-user instance of the backup/restore system service {@link
+ * UserBackupManagerService} that performs operations for its target user.
+ */
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowAppBackupUtils.class})
@Presubmit
-public class BackupManagerServiceTest {
+public class UserBackupManagerServiceTest {
private static final String TAG = "BMSTest";
private static final String PACKAGE_1 = "some.package.1";
private static final String PACKAGE_2 = "some.package.2";
@@ -97,8 +100,9 @@ public class BackupManagerServiceTest {
private ShadowPackageManager mShadowPackageManager;
/**
- * Initialize state that {@link BackupManagerService} operations interact with. This includes
- * setting up the transport, starting the backup thread, and creating backup data directories.
+ * Initialize state that {@link UserBackupManagerService} operations interact with. This
+ * includes setting up the transport, starting the backup thread, and creating backup data
+ * directories.
*/
@Before
public void setUp() throws Exception {
@@ -126,7 +130,7 @@ public class BackupManagerServiceTest {
}
/**
- * Clean up and reset state that was created for testing {@link BackupManagerService}
+ * Clean up and reset state that was created for testing {@link UserBackupManagerService}
* operations.
*/
@After
@@ -136,18 +140,7 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#MORE_DEBUG} is set to {@code false}. This is
- * specifically to prevent overloading the logs in production.
- */
- @Test
- public void testMoreDebug_isFalse() {
- boolean moreDebug = BackupManagerService.MORE_DEBUG;
-
- assertThat(moreDebug).isFalse();
- }
-
- /**
- * Test verifying that {@link BackupManagerService#getDestinationString(String)} returns the
+ * Test verifying that {@link UserBackupManagerService#getDestinationString(String)} returns the
* current destination string of inputted transport if the transport is registered.
*/
@Test
@@ -155,7 +148,7 @@ public class BackupManagerServiceTest {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
when(mTransportManager.getTransportCurrentDestinationString(eq(mTransportName)))
.thenReturn("destinationString");
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
String destination = backupManagerService.getDestinationString(mTransportName);
@@ -163,15 +156,15 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#getDestinationString(String)} returns {@code
- * null} if the inputted transport is not registered.
+ * Test verifying that {@link UserBackupManagerService#getDestinationString(String)} returns
+ * {@code null} if the inputted transport is not registered.
*/
@Test
public void testDestinationString_whenTransportNotRegistered() throws Exception {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
when(mTransportManager.getTransportCurrentDestinationString(eq(mTransportName)))
.thenThrow(TransportNotRegisteredException.class);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
String destination = backupManagerService.getDestinationString(mTransportName);
@@ -179,15 +172,15 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#getDestinationString(String)} throws a {@link
- * SecurityException} if the caller does not have backup permission.
+ * Test verifying that {@link UserBackupManagerService#getDestinationString(String)} throws a
+ * {@link SecurityException} if the caller does not have backup permission.
*/
@Test
public void testDestinationString_withoutPermission() throws Exception {
mShadowContext.denyPermissions(android.Manifest.permission.BACKUP);
when(mTransportManager.getTransportCurrentDestinationString(eq(mTransportName)))
.thenThrow(TransportNotRegisteredException.class);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
expectThrows(
SecurityException.class,
@@ -195,14 +188,14 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#isAppEligibleForBackup(String)} returns
+ * Test verifying that {@link UserBackupManagerService#isAppEligibleForBackup(String)} returns
* {@code false} when the given app is not eligible for backup.
*/
@Test
public void testIsAppEligibleForBackup_whenAppNotEligible() throws Exception {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
setUpCurrentTransport(mTransportManager, mTransport);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
boolean result = backupManagerService.isAppEligibleForBackup(PACKAGE_1);
@@ -210,7 +203,7 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#isAppEligibleForBackup(String)} returns
+ * Test verifying that {@link UserBackupManagerService#isAppEligibleForBackup(String)} returns
* {@code true} when the given app is eligible for backup.
*/
@Test
@@ -218,7 +211,7 @@ public class BackupManagerServiceTest {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
TransportMock transportMock = setUpCurrentTransport(mTransportManager, backupTransport());
ShadowAppBackupUtils.setAppRunningAndEligibleForBackupWithTransport(PACKAGE_1);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
boolean result = backupManagerService.isAppEligibleForBackup(PACKAGE_1);
@@ -228,7 +221,7 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#isAppEligibleForBackup(String)} throws a
+ * Test verifying that {@link UserBackupManagerService#isAppEligibleForBackup(String)} throws a
* {@link SecurityException} if the caller does not have backup permission.
*/
@Test
@@ -236,7 +229,7 @@ public class BackupManagerServiceTest {
mShadowContext.denyPermissions(android.Manifest.permission.BACKUP);
setUpCurrentTransport(mTransportManager, mTransport);
ShadowAppBackupUtils.setAppRunningAndEligibleForBackupWithTransport(PACKAGE_1);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
expectThrows(
SecurityException.class,
@@ -244,7 +237,7 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#filterAppsEligibleForBackup(String[])}
+ * Test verifying that {@link UserBackupManagerService#filterAppsEligibleForBackup(String[])}
* returns an {@code array} of only apps that are eligible for backup from an {@array} of
* inputted apps.
*/
@@ -253,7 +246,7 @@ public class BackupManagerServiceTest {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
TransportMock transportMock = setUpCurrentTransport(mTransportManager, mTransport);
ShadowAppBackupUtils.setAppRunningAndEligibleForBackupWithTransport(PACKAGE_1);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
String[] filtered =
backupManagerService.filterAppsEligibleForBackup(
@@ -265,13 +258,13 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#filterAppsEligibleForBackup(String[])}
+ * Test verifying that {@link UserBackupManagerService#filterAppsEligibleForBackup(String[])}
* returns an empty {@code array} if no inputted apps are eligible for backup.
*/
@Test
public void testFilterAppsEligibleForBackup_whenNoneIsEligible() throws Exception {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
String[] filtered =
backupManagerService.filterAppsEligibleForBackup(
@@ -281,14 +274,14 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#filterAppsEligibleForBackup(String[])} throws
- * a {@link SecurityException} if the caller does not have backup permission.
+ * Test verifying that {@link UserBackupManagerService#filterAppsEligibleForBackup(String[])}
+ * throws a {@link SecurityException} if the caller does not have backup permission.
*/
@Test
public void testFilterAppsEligibleForBackup_withoutPermission() throws Exception {
mShadowContext.denyPermissions(android.Manifest.permission.BACKUP);
setUpCurrentTransport(mTransportManager, mTransport);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
expectThrows(
SecurityException.class,
@@ -318,15 +311,15 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#selectBackupTransport(String)} successfully
- * switches the current transport to the inputted transport, returns the name of the old
- * transport, and disposes of the transport client after the operation.
+ * Test verifying that {@link UserBackupManagerService#selectBackupTransport(String)}
+ * successfully switches the current transport to the inputted transport, returns the name of
+ * the old transport, and disposes of the transport client after the operation.
*/
@Test
public void testSelectBackupTransport() throws Exception {
setUpForSelectTransport();
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
String oldTransport =
backupManagerService.selectBackupTransport(mNewTransport.transportName);
@@ -338,14 +331,14 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#selectBackupTransport(String)} throws a
+ * Test verifying that {@link UserBackupManagerService#selectBackupTransport(String)} throws a
* {@link SecurityException} if the caller does not have backup permission.
*/
@Test
public void testSelectBackupTransport_withoutPermission() throws Exception {
setUpForSelectTransport();
mShadowContext.denyPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
expectThrows(
SecurityException.class,
@@ -353,7 +346,7 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#selectBackupTransportAsync(ComponentName,
+ * Test verifying that {@link UserBackupManagerService#selectBackupTransportAsync(ComponentName,
* ISelectBackupTransportCallback)} successfully switches the current transport to the inputted
* transport and disposes of the transport client after the operation.
*/
@@ -363,7 +356,7 @@ public class BackupManagerServiceTest {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
when(mTransportManager.registerAndSelectTransport(eq(mNewTransportComponent)))
.thenReturn(BackupManager.SUCCESS);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
ISelectBackupTransportCallback callback = mock(ISelectBackupTransportCallback.class);
backupManagerService.selectBackupTransportAsync(mNewTransportComponent, callback);
@@ -376,7 +369,7 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#selectBackupTransportAsync(ComponentName,
+ * Test verifying that {@link UserBackupManagerService#selectBackupTransportAsync(ComponentName,
* ISelectBackupTransportCallback)} does not switch the current transport to the inputted
* transport and notifies the inputted callback of failure when it fails to register the
* transport.
@@ -387,7 +380,7 @@ public class BackupManagerServiceTest {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
when(mTransportManager.registerAndSelectTransport(eq(mNewTransportComponent)))
.thenReturn(BackupManager.ERROR_TRANSPORT_UNAVAILABLE);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
ISelectBackupTransportCallback callback = mock(ISelectBackupTransportCallback.class);
backupManagerService.selectBackupTransportAsync(mNewTransportComponent, callback);
@@ -398,7 +391,7 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#selectBackupTransportAsync(ComponentName,
+ * Test verifying that {@link UserBackupManagerService#selectBackupTransportAsync(ComponentName,
* ISelectBackupTransportCallback)} does not switch the current transport to the inputted
* transport and notifies the inputted callback of failure when the transport gets unregistered.
*/
@@ -409,7 +402,7 @@ public class BackupManagerServiceTest {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
when(mTransportManager.registerAndSelectTransport(eq(newTransportComponent)))
.thenReturn(BackupManager.SUCCESS);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
ISelectBackupTransportCallback callback = mock(ISelectBackupTransportCallback.class);
backupManagerService.selectBackupTransportAsync(newTransportComponent, callback);
@@ -420,7 +413,7 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#selectBackupTransportAsync(ComponentName,
+ * Test verifying that {@link UserBackupManagerService#selectBackupTransportAsync(ComponentName,
* ISelectBackupTransportCallback)} throws a {@link SecurityException} if the caller does not
* have backup permission.
*/
@@ -428,7 +421,7 @@ public class BackupManagerServiceTest {
public void testSelectBackupTransportAsync_withoutPermission() throws Exception {
setUpForSelectTransport();
mShadowContext.denyPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
ComponentName newTransportComponent = mNewTransport.getTransportComponent();
expectThrows(
@@ -444,15 +437,15 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#getCurrentTransportComponent()} returns the
- * {@link ComponentName} of the currently selected transport.
+ * Test verifying that {@link UserBackupManagerService#getCurrentTransportComponent()} returns
+ * the {@link ComponentName} of the currently selected transport.
*/
@Test
public void testGetCurrentTransportComponent() throws Exception {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
when(mTransportManager.getCurrentTransportComponent())
.thenReturn(mTransport.getTransportComponent());
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
ComponentName transportComponent = backupManagerService.getCurrentTransportComponent();
@@ -460,14 +453,14 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#getCurrentTransportComponent()} returns
+ * Test verifying that {@link UserBackupManagerService#getCurrentTransportComponent()} returns
* {@code null} if there is no currently selected transport.
*/
@Test
public void testGetCurrentTransportComponent_whenNoTransportSelected() throws Exception {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
when(mTransportManager.getCurrentTransportComponent()).thenReturn(null);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
ComponentName transportComponent = backupManagerService.getCurrentTransportComponent();
@@ -475,7 +468,7 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#getCurrentTransportComponent()} returns
+ * Test verifying that {@link UserBackupManagerService#getCurrentTransportComponent()} returns
* {@code null} if the currently selected transport is not registered.
*/
@Test
@@ -483,7 +476,7 @@ public class BackupManagerServiceTest {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
when(mTransportManager.getCurrentTransportComponent())
.thenThrow(TransportNotRegisteredException.class);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
ComponentName transportComponent = backupManagerService.getCurrentTransportComponent();
@@ -491,13 +484,13 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#getCurrentTransportComponent()} throws a
+ * Test verifying that {@link UserBackupManagerService#getCurrentTransportComponent()} throws a
* {@link SecurityException} if the caller does not have backup permission.
*/
@Test
public void testGetCurrentTransportComponent_withoutPermission() throws Exception {
mShadowContext.denyPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
expectThrows(SecurityException.class, backupManagerService::getCurrentTransportComponent);
}
@@ -520,9 +513,9 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#updateTransportAttributes(int, ComponentName,
- * String, Intent, String, Intent, String)} succeeds if the uid of the transport is same as the
- * uid of the caller.
+ * Test verifying that {@link UserBackupManagerService#updateTransportAttributes(int,
+ * ComponentName, String, Intent, String, Intent, String)} succeeds if the uid of the transport
+ * is same as the uid of the caller.
*/
@Test
public void
@@ -532,7 +525,7 @@ public class BackupManagerServiceTest {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
Intent configurationIntent = new Intent();
Intent dataManagementIntent = new Intent();
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
backupManagerService.updateTransportAttributes(
mTransportUid,
@@ -554,16 +547,16 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#updateTransportAttributes(int, ComponentName,
- * String, Intent, String, Intent, String)} throws a {@link SecurityException} if the uid of the
- * transport is not equal to the uid of the caller.
+ * Test verifying that {@link UserBackupManagerService#updateTransportAttributes(int,
+ * ComponentName, String, Intent, String, Intent, String)} throws a {@link SecurityException} if
+ * the uid of the transport is not equal to the uid of the caller.
*/
@Test
public void testUpdateTransportAttributes_whenTransportUidNotEqualToCallingUid_throwsException()
throws Exception {
setUpForUpdateTransportAttributes();
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
expectThrows(
SecurityException.class,
@@ -579,16 +572,16 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#updateTransportAttributes(int, ComponentName,
- * String, Intent, String, Intent, String)} throws a {@link RuntimeException} if given a {@code
- * null} transport component.
+ * Test verifying that {@link UserBackupManagerService#updateTransportAttributes(int,
+ * ComponentName, String, Intent, String, Intent, String)} throws a {@link RuntimeException} if
+ * given a {@code null} transport component.
*/
@Test
public void testUpdateTransportAttributes_whenTransportComponentNull_throwsException()
throws Exception {
setUpForUpdateTransportAttributes();
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
expectThrows(
RuntimeException.class,
@@ -604,15 +597,15 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#updateTransportAttributes(int, ComponentName,
- * String, Intent, String, Intent, String)} throws a {@link RuntimeException} if given a {@code
- * null} transport name.
+ * Test verifying that {@link UserBackupManagerService#updateTransportAttributes(int,
+ * ComponentName, String, Intent, String, Intent, String)} throws a {@link RuntimeException} if
+ * given a {@code null} transport name.
*/
@Test
public void testUpdateTransportAttributes_whenNameNull_throwsException() throws Exception {
setUpForUpdateTransportAttributes();
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
expectThrows(
RuntimeException.class,
@@ -628,16 +621,16 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#updateTransportAttributes(int, ComponentName,
- * String, Intent, String, Intent, String)} throws a {@link RuntimeException} if given a {@code
- * null} destination string.
+ * Test verifying that {@link UserBackupManagerService#updateTransportAttributes(int,
+ * ComponentName, String, Intent, String, Intent, String)} throws a {@link RuntimeException} if
+ * given a {@code null} destination string.
*/
@Test
public void testUpdateTransportAttributes_whenCurrentDestinationStringNull_throwsException()
throws Exception {
setUpForUpdateTransportAttributes();
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
expectThrows(
RuntimeException.class,
@@ -653,9 +646,10 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#updateTransportAttributes(int, ComponentName,
- * String, Intent, String, Intent, String)} throws a {@link RuntimeException} if given either a
- * {@code null} data management label or {@code null} data management intent, but not both.
+ * Test verifying that {@link UserBackupManagerService#updateTransportAttributes(int,
+ * ComponentName, String, Intent, String, Intent, String)} throws a {@link RuntimeException} if
+ * given either a {@code null} data management label or {@code null} data management intent, but
+ * not both.
*/
@Test
public void
@@ -663,7 +657,7 @@ public class BackupManagerServiceTest {
throws Exception {
setUpForUpdateTransportAttributes();
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
expectThrows(
RuntimeException.class,
@@ -691,8 +685,9 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#updateTransportAttributes(int, ComponentName,
- * String, Intent, String, Intent, String)} succeeds if the caller has backup permission.
+ * Test verifying that {@link UserBackupManagerService#updateTransportAttributes(int,
+ * ComponentName, String, Intent, String, Intent, String)} succeeds if the caller has backup
+ * permission.
*/
@Test
public void testUpdateTransportAttributes_whenPermissionGranted_callsThroughToTransportManager()
@@ -701,7 +696,7 @@ public class BackupManagerServiceTest {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
Intent configurationIntent = new Intent();
Intent dataManagementIntent = new Intent();
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
backupManagerService.updateTransportAttributes(
mTransportUid,
@@ -723,16 +718,16 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#updateTransportAttributes(int, ComponentName,
- * String, Intent, String, Intent, String)} throws a {@link SecurityException} if the caller
- * does not have backup permission.
+ * Test verifying that {@link UserBackupManagerService#updateTransportAttributes(int,
+ * ComponentName, String, Intent, String, Intent, String)} throws a {@link SecurityException} if
+ * the caller does not have backup permission.
*/
@Test
public void testUpdateTransportAttributes_whenPermissionDenied_throwsSecurityException()
throws Exception {
setUpForUpdateTransportAttributes();
mShadowContext.denyPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
expectThrows(
SecurityException.class,
@@ -765,13 +760,13 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#requestBackup(String[], IBackupObserver,
+ * Test verifying that {@link UserBackupManagerService#requestBackup(String[], IBackupObserver,
* int)} throws a {@link SecurityException} if the caller does not have backup permission.
*/
@Test
public void testRequestBackup_whenPermissionDenied() throws Exception {
mShadowContext.denyPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
expectThrows(
SecurityException.class,
@@ -779,13 +774,13 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#requestBackup(String[], IBackupObserver,
+ * Test verifying that {@link UserBackupManagerService#requestBackup(String[], IBackupObserver,
* int)} throws an {@link IllegalArgumentException} if passed {@null} for packages.
*/
@Test
public void testRequestBackup_whenPackagesNull() throws Exception {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
expectThrows(
IllegalArgumentException.class,
@@ -794,14 +789,14 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#requestBackup(String[], IBackupObserver,
+ * Test verifying that {@link UserBackupManagerService#requestBackup(String[], IBackupObserver,
* int)} throws an {@link IllegalArgumentException} if passed an empty {@code array} for
* packages.
*/
@Test
public void testRequestBackup_whenPackagesEmpty() throws Exception {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
expectThrows(
IllegalArgumentException.class,
@@ -810,13 +805,13 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#requestBackup(String[], IBackupObserver,
+ * Test verifying that {@link UserBackupManagerService#requestBackup(String[], IBackupObserver,
* int)} returns {@link BackupManager#ERROR_BACKUP_NOT_ALLOWED} if backup is disabled.
*/
@Test
public void testRequestBackup_whenBackupDisabled() throws Exception {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
backupManagerService.setEnabled(false);
int result = backupManagerService.requestBackup(new String[] {PACKAGE_1}, mObserver, 0);
@@ -826,14 +821,14 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#requestBackup(String[], IBackupObserver,
+ * Test verifying that {@link UserBackupManagerService#requestBackup(String[], IBackupObserver,
* int)} returns {@link BackupManager#ERROR_BACKUP_NOT_ALLOWED} if the system user hasn't gone
* through SUW.
*/
@Test
public void testRequestBackup_whenNotProvisioned() throws Exception {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
backupManagerService.setProvisioned(false);
int result = backupManagerService.requestBackup(new String[] {PACKAGE_1}, mObserver, 0);
@@ -843,7 +838,7 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#requestBackup(String[], IBackupObserver,
+ * Test verifying that {@link UserBackupManagerService#requestBackup(String[], IBackupObserver,
* int)} returns {@link BackupManager#ERROR_TRANSPORT_ABORTED} if the current transport is not
* registered.
*/
@@ -851,7 +846,7 @@ public class BackupManagerServiceTest {
public void testRequestBackup_whenTransportNotRegistered() throws Exception {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
setUpCurrentTransport(mTransportManager, mTransport.unregistered());
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
backupManagerService.setEnabled(true);
backupManagerService.setProvisioned(true);
@@ -862,7 +857,7 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#requestBackup(String[], IBackupObserver,
+ * Test verifying that {@link UserBackupManagerService#requestBackup(String[], IBackupObserver,
* int)} returns {@link BackupManager#SUCCESS} and notifies the observer of {@link
* BackupManager#ERROR_BACKUP_NOT_ALLOWED} if the specified app is not eligible for backup.
*/
@@ -871,7 +866,7 @@ public class BackupManagerServiceTest {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
mShadowPackageManager.addPackage(PACKAGE_1);
setUpCurrentTransport(mTransportManager, mTransport);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
backupManagerService.setEnabled(true);
backupManagerService.setProvisioned(true);
// Haven't set PACKAGE_1 as eligible
@@ -885,7 +880,7 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#requestBackup(String[], IBackupObserver,
+ * Test verifying that {@link UserBackupManagerService#requestBackup(String[], IBackupObserver,
* int)} returns {@link BackupManager#SUCCESS} and updates bookkeeping if backup for a key value
* package succeeds.
*/
@@ -893,7 +888,8 @@ public class BackupManagerServiceTest {
@Config(shadows = ShadowKeyValueBackupTask.class)
public void testRequestBackup_whenPackageIsKeyValue() throws Exception {
setUpForRequestBackup(PACKAGE_1);
- BackupManagerService backupManagerService = createBackupManagerServiceForRequestBackup();
+ UserBackupManagerService backupManagerService =
+ createBackupManagerServiceForRequestBackup();
int result = backupManagerService.requestBackup(new String[] {PACKAGE_1}, mObserver, 0);
@@ -907,7 +903,7 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#requestBackup(String[], IBackupObserver,
+ * Test verifying that {@link UserBackupManagerService#requestBackup(String[], IBackupObserver,
* int)} returns {@link BackupManager#SUCCESS} and updates bookkeeping if backup for a full
* backup package succeeds.
*/
@@ -916,7 +912,8 @@ public class BackupManagerServiceTest {
public void testRequestBackup_whenPackageIsFullBackup() throws Exception {
setUpForRequestBackup(PACKAGE_1);
ShadowAppBackupUtils.setAppGetsFullBackup(PACKAGE_1);
- BackupManagerService backupManagerService = createBackupManagerServiceForRequestBackup();
+ UserBackupManagerService backupManagerService =
+ createBackupManagerServiceForRequestBackup();
int result = backupManagerService.requestBackup(new String[] {PACKAGE_1}, mObserver, 0);
@@ -930,14 +927,14 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#backupNow()} clears the calling identity
+ * Test verifying that {@link UserBackupManagerService#backupNow()} clears the calling identity
* for scheduling a job and then restores the original calling identity after the operation.
*/
@Test
@Config(shadows = {ShadowBinder.class, ShadowKeyValueBackupJob.class})
public void testBackupNow_clearsCallingIdentityForJobScheduler() {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
setUpPowerManager(backupManagerService);
ShadowBinder.setCallingUid(1);
@@ -948,14 +945,14 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that {@link BackupManagerService#backupNow()} restores the original calling
- * identity if an exception is thrown during execution.
+ * Test verifying that {@link UserBackupManagerService#backupNow()} restores the original
+ * calling identity if an exception is thrown during execution.
*/
@Test
@Config(shadows = {ShadowBinder.class, ShadowKeyValueBackupJobException.class})
public void testBackupNow_whenExceptionThrown_restoresCallingIdentity() {
mShadowContext.grantPermissions(android.Manifest.permission.BACKUP);
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
setUpPowerManager(backupManagerService);
ShadowBinder.setCallingUid(1);
@@ -965,17 +962,17 @@ public class BackupManagerServiceTest {
assertThat(Binder.getCallingUid()).isEqualTo(1);
}
- private BackupManagerService createBackupManagerServiceForRequestBackup() {
- BackupManagerService backupManagerService = createInitializedBackupManagerService();
+ private UserBackupManagerService createBackupManagerServiceForRequestBackup() {
+ UserBackupManagerService backupManagerService = createInitializedBackupManagerService();
backupManagerService.setEnabled(true);
backupManagerService.setProvisioned(true);
return backupManagerService;
}
/**
- * Test verifying that {@link BackupManagerService#BackupManagerService(Context, Trampoline,
- * HandlerThread, File, File, TransportManager)} posts a transport registration task to the
- * backup handler thread.
+ * Test verifying that {@link UserBackupManagerService#UserBackupManagerService(Context,
+ * Trampoline, HandlerThread, File, File, TransportManager)} posts a transport registration task
+ * to the backup handler thread.
*/
@Test
public void testConstructor_postRegisterTransports() {
@@ -988,9 +985,9 @@ public class BackupManagerServiceTest {
}
/**
- * Test verifying that the {@link BackupManagerService#BackupManagerService(Context, Trampoline,
- * HandlerThread, File, File, TransportManager)} does not directly register transports in its
- * own thread.
+ * Test verifying that the {@link UserBackupManagerService#UserBackupManagerService(Context,
+ * Trampoline, HandlerThread, File, File, TransportManager)} does not directly register
+ * transports in its own thread.
*/
@Test
public void testConstructor_doesNotRegisterTransportsSynchronously() {
@@ -1002,8 +999,8 @@ public class BackupManagerServiceTest {
verify(mTransportManager, never()).registerTransports();
}
- private BackupManagerService createBackupManagerService() {
- return new BackupManagerService(
+ private UserBackupManagerService createBackupManagerService() {
+ return new UserBackupManagerService(
mContext,
new Trampoline(mContext),
mBackupThread,
@@ -1012,12 +1009,12 @@ public class BackupManagerServiceTest {
mTransportManager);
}
- private BackupManagerService createInitializedBackupManagerService() {
- return BackupManagerServiceTestUtils.createInitializedBackupManagerService(
+ private UserBackupManagerService createInitializedBackupManagerService() {
+ return BackupManagerServiceTestUtils.createInitializedUserBackupManagerService(
mContext, mBackupThread, mBaseStateDir, mDataDir, mTransportManager);
}
- private void setUpPowerManager(BackupManagerService backupManagerService) {
+ private void setUpPowerManager(UserBackupManagerService backupManagerService) {
PowerManager powerManagerMock = mock(PowerManager.class);
when(powerManagerMock.getPowerSaveState(anyInt()))
.thenReturn(new PowerSaveState.Builder().setBatterySaverEnabled(true).build());
diff --git a/services/robotests/src/com/android/server/backup/fullbackup/AppMetadataBackupWriterTest.java b/services/robotests/src/com/android/server/backup/fullbackup/AppMetadataBackupWriterTest.java
index fd7ced2d58b6..423512ce4b70 100644
--- a/services/robotests/src/com/android/server/backup/fullbackup/AppMetadataBackupWriterTest.java
+++ b/services/robotests/src/com/android/server/backup/fullbackup/AppMetadataBackupWriterTest.java
@@ -1,10 +1,10 @@
package com.android.server.backup.fullbackup;
-import static com.android.server.backup.BackupManagerService.BACKUP_MANIFEST_FILENAME;
-import static com.android.server.backup.BackupManagerService.BACKUP_MANIFEST_VERSION;
-import static com.android.server.backup.BackupManagerService.BACKUP_METADATA_FILENAME;
-import static com.android.server.backup.BackupManagerService.BACKUP_METADATA_VERSION;
-import static com.android.server.backup.BackupManagerService.BACKUP_WIDGET_METADATA_TOKEN;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_MANIFEST_FILENAME;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_MANIFEST_VERSION;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_METADATA_FILENAME;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_METADATA_VERSION;
+import static com.android.server.backup.UserBackupManagerService.BACKUP_WIDGET_METADATA_TOKEN;
import static com.google.common.truth.Truth.assertThat;
diff --git a/services/robotests/src/com/android/server/backup/internal/PerformInitializeTaskTest.java b/services/robotests/src/com/android/server/backup/internal/PerformInitializeTaskTest.java
index 6ee6eb67dd57..8ec0759e52db 100644
--- a/services/robotests/src/com/android/server/backup/internal/PerformInitializeTaskTest.java
+++ b/services/robotests/src/com/android/server/backup/internal/PerformInitializeTaskTest.java
@@ -44,8 +44,9 @@ import android.platform.test.annotations.Presubmit;
import android.util.Log;
import com.android.internal.backup.IBackupTransport;
-import com.android.server.backup.BackupManagerService;
+import com.android.server.backup.GlobalBackupManagerService;
import com.android.server.backup.TransportManager;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.testing.TransportData;
import com.android.server.backup.testing.TransportTestUtils;
import com.android.server.backup.testing.TransportTestUtils.TransportMock;
@@ -71,7 +72,7 @@ import java.util.stream.Stream;
@Config(shadows = ShadowSlog.class)
@Presubmit
public class PerformInitializeTaskTest {
- @Mock private BackupManagerService mBackupManagerService;
+ @Mock private UserBackupManagerService mBackupManagerService;
@Mock private TransportManager mTransportManager;
@Mock private OnTaskFinishedListener mListener;
@Mock private IBackupTransport mTransportBinder;
@@ -211,7 +212,7 @@ public class PerformInitializeTaskTest {
performInitializeTask.run();
assertLogcatContains(
- BackupManagerService.TAG,
+ GlobalBackupManagerService.TAG,
log -> log.msg.contains("finishBackup()") && log.type >= Log.ERROR);
}
@@ -224,7 +225,7 @@ public class PerformInitializeTaskTest {
performInitializeTask.run();
assertLogcatContains(
- BackupManagerService.TAG,
+ GlobalBackupManagerService.TAG,
log -> log.msg.contains("initializeDevice()") && log.type >= Log.ERROR);
}
diff --git a/services/robotests/src/com/android/server/backup/keyvalue/KeyValueBackupReporterTest.java b/services/robotests/src/com/android/server/backup/keyvalue/KeyValueBackupReporterTest.java
index a0afb5e0d84e..a1b8a9520524 100644
--- a/services/robotests/src/com/android/server/backup/keyvalue/KeyValueBackupReporterTest.java
+++ b/services/robotests/src/com/android/server/backup/keyvalue/KeyValueBackupReporterTest.java
@@ -26,7 +26,7 @@ import android.app.backup.IBackupObserver;
import android.platform.test.annotations.Presubmit;
import android.util.Log;
-import com.android.server.backup.BackupManagerService;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.testing.shadows.ShadowEventLog;
import com.android.server.testing.shadows.ShadowSlog;
@@ -41,7 +41,7 @@ import org.robolectric.annotation.Config;
@Config(shadows = {ShadowEventLog.class, ShadowSlog.class})
@Presubmit
public class KeyValueBackupReporterTest {
- @Mock private BackupManagerService mBackupManagerService;
+ @Mock private UserBackupManagerService mBackupManagerService;
@Mock private IBackupObserver mObserver;
@Mock private IBackupManagerMonitor mMonitor;
diff --git a/services/robotests/src/com/android/server/backup/keyvalue/KeyValueBackupTaskTest.java b/services/robotests/src/com/android/server/backup/keyvalue/KeyValueBackupTaskTest.java
index a69f007dfe08..1aa4999b1d3a 100644
--- a/services/robotests/src/com/android/server/backup/keyvalue/KeyValueBackupTaskTest.java
+++ b/services/robotests/src/com/android/server/backup/keyvalue/KeyValueBackupTaskTest.java
@@ -26,7 +26,7 @@ import static android.app.backup.ForwardingBackupAgent.forward;
import static com.android.server.backup.testing.BackupManagerServiceTestUtils.createBackupWakeLock;
import static com.android.server.backup.testing.BackupManagerServiceTestUtils
- .createInitializedBackupManagerService;
+ .createInitializedUserBackupManagerService;
import static com.android.server.backup.testing.BackupManagerServiceTestUtils
.setUpBackupManagerServiceBasics;
import static com.android.server.backup.testing.BackupManagerServiceTestUtils
@@ -103,12 +103,12 @@ import android.util.Pair;
import com.android.internal.backup.IBackupTransport;
import com.android.server.EventLogTags;
-import com.android.server.backup.BackupManagerService;
import com.android.server.backup.BackupRestoreTask;
import com.android.server.backup.DataChangedJournal;
import com.android.server.backup.KeyValueBackupJob;
import com.android.server.backup.PackageManagerBackupAgent;
import com.android.server.backup.TransportManager;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.internal.BackupHandler;
import com.android.server.backup.internal.OnTaskFinishedListener;
import com.android.server.backup.remote.RemoteCall;
@@ -178,7 +178,7 @@ public class KeyValueBackupTaskTest {
@Mock private IBackupObserver mObserver;
@Mock private IBackupManagerMonitor mMonitor;
@Mock private OnTaskFinishedListener mListener;
- private BackupManagerService mBackupManagerService;
+ private UserBackupManagerService mBackupManagerService;
private TransportData mTransport;
private ShadowLooper mShadowBackupLooper;
private Handler mBackupHandler;
@@ -227,7 +227,7 @@ public class KeyValueBackupTaskTest {
setUpBinderCallerAndApplicationAsSystem(mApplication);
mBackupManagerService =
spy(
- createInitializedBackupManagerService(
+ createInitializedUserBackupManagerService(
mContext, mBaseStateDir, mDataDir, mTransportManager));
setUpBackupManagerServiceBasics(
mBackupManagerService,
@@ -720,7 +720,7 @@ public class KeyValueBackupTaskTest {
}
/**
- * Agent unavailable means {@link BackupManagerService#bindToAgentSynchronous(ApplicationInfo,
+ * Agent unavailable means {@link UserBackupManagerService#bindToAgentSynchronous(ApplicationInfo,
* int)} returns {@code null}.
*
* @see #setUpAgent(PackageData)
@@ -2597,7 +2597,7 @@ public class KeyValueBackupTaskTest {
*
* <ul>
* <li>The transport being initialized with {@link IBackupTransport#initializeDevice()}
- * <li>{@link BackupManagerService#resetBackupState(File)} being called, which will:
+ * <li>{@link UserBackupManagerService#resetBackupState(File)} being called, which will:
* <ul>
* <li>Reset processed packages journal.
* <li>Reset current token to 0.
@@ -2617,7 +2617,7 @@ public class KeyValueBackupTaskTest {
/**
* Forces transport initialization and call to {@link
- * BackupManagerService#resetBackupState(File)}
+ * UserBackupManagerService#resetBackupState(File)}
*/
private void deletePmStateFile() throws IOException {
Files.deleteIfExists(getStateFile(mTransport, PM_PACKAGE));
diff --git a/services/robotests/src/com/android/server/backup/restore/ActiveRestoreSessionTest.java b/services/robotests/src/com/android/server/backup/restore/ActiveRestoreSessionTest.java
index 0e2b95b3167d..859392d80d36 100644
--- a/services/robotests/src/com/android/server/backup/restore/ActiveRestoreSessionTest.java
+++ b/services/robotests/src/com/android/server/backup/restore/ActiveRestoreSessionTest.java
@@ -51,8 +51,8 @@ import android.platform.test.annotations.Presubmit;
import com.android.server.EventLogTags;
import com.android.server.backup.BackupAgentTimeoutParameters;
-import com.android.server.backup.BackupManagerService;
import com.android.server.backup.TransportManager;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.internal.BackupHandler;
import com.android.server.backup.testing.TransportData;
import com.android.server.backup.testing.TransportTestUtils;
@@ -85,7 +85,7 @@ public class ActiveRestoreSessionTest {
private static final long TOKEN_1 = 1L;
private static final long TOKEN_2 = 2L;
- @Mock private BackupManagerService mBackupManagerService;
+ @Mock private UserBackupManagerService mBackupManagerService;
@Mock private TransportManager mTransportManager;
@Mock private IRestoreObserver mObserver;
@Mock private IBackupManagerMonitor mMonitor;
diff --git a/services/robotests/src/com/android/server/backup/testing/BackupManagerServiceTestUtils.java b/services/robotests/src/com/android/server/backup/testing/BackupManagerServiceTestUtils.java
index f3077309d222..bacc44e685f4 100644
--- a/services/robotests/src/com/android/server/backup/testing/BackupManagerServiceTestUtils.java
+++ b/services/robotests/src/com/android/server/backup/testing/BackupManagerServiceTestUtils.java
@@ -37,9 +37,9 @@ import android.os.Process;
import android.util.Log;
import com.android.server.backup.BackupAgentTimeoutParameters;
-import com.android.server.backup.BackupManagerService;
import com.android.server.backup.Trampoline;
import com.android.server.backup.TransportManager;
+import com.android.server.backup.UserBackupManagerService;
import org.mockito.stubbing.Answer;
import org.robolectric.shadows.ShadowApplication;
@@ -49,26 +49,26 @@ import java.io.File;
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.concurrent.atomic.AtomicReference;
-/** Test utils for {@link BackupManagerService} and friends. */
+/** Test utils for {@link UserBackupManagerService} and friends. */
public class BackupManagerServiceTestUtils {
/**
* If the class-under-test is going to execute methods as the system, it's a good idea to also
* call {@link #setUpBinderCallerAndApplicationAsSystem(Application)} before this method.
*/
- public static BackupManagerService createInitializedBackupManagerService(
+ public static UserBackupManagerService createInitializedUserBackupManagerService(
Context context, File baseStateDir, File dataDir, TransportManager transportManager) {
- return createInitializedBackupManagerService(
+ return createInitializedUserBackupManagerService(
context, startBackupThread(null), baseStateDir, dataDir, transportManager);
}
- public static BackupManagerService createInitializedBackupManagerService(
+ public static UserBackupManagerService createInitializedUserBackupManagerService(
Context context,
HandlerThread backupThread,
File baseStateDir,
File dataDir,
TransportManager transportManager) {
- BackupManagerService backupManagerService =
- new BackupManagerService(
+ UserBackupManagerService backupManagerService =
+ new UserBackupManagerService(
context,
new Trampoline(context),
backupThread,
@@ -80,15 +80,16 @@ public class BackupManagerServiceTestUtils {
}
/**
- * Sets up basic mocks for {@link BackupManagerService} mock. If {@code backupManagerService} is
- * a spy, make sure you provide in the arguments the same objects that the original object uses.
+ * Sets up basic mocks for {@link UserBackupManagerService} mock. If {@code
+ * backupManagerService} is a spy, make sure you provide in the arguments the same objects that
+ * the original object uses.
*
* <p>If the class-under-test is going to execute methods as the system, it's a good idea to
* also call {@link #setUpBinderCallerAndApplicationAsSystem(Application)}.
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
public static void setUpBackupManagerServiceBasics(
- BackupManagerService backupManagerService,
+ UserBackupManagerService backupManagerService,
Application application,
TransportManager transportManager,
PackageManager packageManager,
diff --git a/services/robotests/src/com/android/server/testing/shadows/ShadowKeyValueBackupTask.java b/services/robotests/src/com/android/server/testing/shadows/ShadowKeyValueBackupTask.java
index ca8066403eca..ac5d2da9c3cf 100644
--- a/services/robotests/src/com/android/server/testing/shadows/ShadowKeyValueBackupTask.java
+++ b/services/robotests/src/com/android/server/testing/shadows/ShadowKeyValueBackupTask.java
@@ -18,8 +18,8 @@ package com.android.server.testing.shadows;
import android.annotation.Nullable;
-import com.android.server.backup.BackupManagerService;
import com.android.server.backup.DataChangedJournal;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.internal.OnTaskFinishedListener;
import com.android.server.backup.keyvalue.KeyValueBackupReporter;
import com.android.server.backup.keyvalue.KeyValueBackupTask;
@@ -54,7 +54,7 @@ public class ShadowKeyValueBackupTask {
@Implementation
protected void __constructor__(
- BackupManagerService backupManagerService,
+ UserBackupManagerService backupManagerService,
TransportClient transportClient,
String transportDirName,
List<String> queue,
diff --git a/services/robotests/src/com/android/server/testing/shadows/ShadowPerformUnifiedRestoreTask.java b/services/robotests/src/com/android/server/testing/shadows/ShadowPerformUnifiedRestoreTask.java
index 228d4eb818a4..2cebbebfbaf4 100644
--- a/services/robotests/src/com/android/server/testing/shadows/ShadowPerformUnifiedRestoreTask.java
+++ b/services/robotests/src/com/android/server/testing/shadows/ShadowPerformUnifiedRestoreTask.java
@@ -21,7 +21,7 @@ import android.app.backup.IBackupManagerMonitor;
import android.app.backup.IRestoreObserver;
import android.content.pm.PackageInfo;
-import com.android.server.backup.BackupManagerService;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.internal.OnTaskFinishedListener;
import com.android.server.backup.restore.PerformUnifiedRestoreTask;
import com.android.server.backup.transport.TransportClient;
@@ -47,7 +47,7 @@ public class ShadowPerformUnifiedRestoreTask {
sLastShadow = null;
}
- private BackupManagerService mBackupManagerService;
+ private UserBackupManagerService mBackupManagerService;
@Nullable private PackageInfo mPackage;
private boolean mIsFullSystemRestore;
@Nullable private String[] mFilterSet;
@@ -55,7 +55,7 @@ public class ShadowPerformUnifiedRestoreTask {
@Implementation
protected void __constructor__(
- BackupManagerService backupManagerService,
+ UserBackupManagerService backupManagerService,
TransportClient transportClient,
IRestoreObserver observer,
IBackupManagerMonitor monitor,
diff --git a/services/tests/servicestests/src/com/android/server/backup/TrampolineTest.java b/services/tests/servicestests/src/com/android/server/backup/TrampolineTest.java
index 7c002995a769..c99e2a850679 100644
--- a/services/tests/servicestests/src/com/android/server/backup/TrampolineTest.java
+++ b/services/tests/servicestests/src/com/android/server/backup/TrampolineTest.java
@@ -83,7 +83,7 @@ public class TrampolineTest {
};
private final int NON_USER_SYSTEM = UserHandle.USER_SYSTEM + 1;
- @Mock private BackupManagerService mBackupManagerServiceMock;
+ @Mock private GlobalBackupManagerService mBackupManagerServiceMock;
@Mock private Context mContextMock;
@Mock private File mSuppressFileMock;
@Mock private File mSuppressFileParentMock;
@@ -864,7 +864,7 @@ public class TrampolineTest {
static boolean sBackupDisabled = false;
static File sSuppressFile = null;
static int sCallingUid = -1;
- static BackupManagerService sBackupManagerServiceMock = null;
+ static GlobalBackupManagerService sBackupManagerServiceMock = null;
private int mCreateServiceCallsCount = 0;
TrampolineTestable(Context context) {
@@ -887,7 +887,7 @@ public class TrampolineTest {
}
@Override
- protected BackupManagerService createBackupManagerService() {
+ protected GlobalBackupManagerService createBackupManagerService() {
mCreateServiceCallsCount++;
return sBackupManagerServiceMock;
}
diff --git a/services/tests/servicestests/src/com/android/server/backup/utils/AppBackupUtilsTest.java b/services/tests/servicestests/src/com/android/server/backup/utils/AppBackupUtilsTest.java
index d52051eec5bd..479a19b93ca7 100644
--- a/services/tests/servicestests/src/com/android/server/backup/utils/AppBackupUtilsTest.java
+++ b/services/tests/servicestests/src/com/android/server/backup/utils/AppBackupUtilsTest.java
@@ -34,7 +34,7 @@ import android.platform.test.annotations.Presubmit;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
-import com.android.server.backup.BackupManagerService;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.testutils.PackageManagerStub;
import org.junit.Before;
@@ -97,7 +97,7 @@ public class AppBackupUtilsTest {
applicationInfo.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;
applicationInfo.uid = Process.SYSTEM_UID;
applicationInfo.backupAgentName = CUSTOM_BACKUP_AGENT_NAME;
- applicationInfo.packageName = BackupManagerService.SHARED_BACKUP_AGENT_PACKAGE;
+ applicationInfo.packageName = UserBackupManagerService.SHARED_BACKUP_AGENT_PACKAGE;
boolean isEligible = AppBackupUtils.appIsEligibleForBackup(applicationInfo,
mPackageManagerStub);
diff --git a/services/tests/servicestests/src/com/android/server/backup/utils/TarBackupReaderTest.java b/services/tests/servicestests/src/com/android/server/backup/utils/TarBackupReaderTest.java
index 47749856a7ec..d43b677d0e50 100644
--- a/services/tests/servicestests/src/com/android/server/backup/utils/TarBackupReaderTest.java
+++ b/services/tests/servicestests/src/com/android/server/backup/utils/TarBackupReaderTest.java
@@ -51,8 +51,8 @@ import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.frameworks.servicestests.R;
-import com.android.server.backup.BackupManagerService;
import com.android.server.backup.FileMetadata;
+import com.android.server.backup.UserBackupManagerService;
import com.android.server.backup.restore.PerformAdbRestoreTask;
import com.android.server.backup.restore.RestorePolicy;
import com.android.server.backup.testutils.PackageManagerStub;
@@ -150,7 +150,7 @@ public class TarBackupReaderTest {
assertThat(restorePolicy).isEqualTo(RestorePolicy.IGNORE);
assertThat(fileMetadata.packageName).isEqualTo(TEST_PACKAGE_NAME);
- assertThat(fileMetadata.path).isEqualTo(BackupManagerService.BACKUP_MANIFEST_FILENAME);
+ assertThat(fileMetadata.path).isEqualTo(UserBackupManagerService.BACKUP_MANIFEST_FILENAME);
tarBackupReader.skipTarPadding(fileMetadata.size);