diff options
author | Bernardo Rufino <brufino@google.com> | 2019-08-15 15:54:13 +0100 |
---|---|---|
committer | Bernardo Rufino <brufino@google.com> | 2019-08-15 18:56:23 +0100 |
commit | 0948c30a119f4f08763608d8fa86f495abcc56da (patch) | |
tree | e97783862e74f3f93b9dc45eaf606ba8602a2eb0 /services/backup/java | |
parent | f410de02e25e5a75300f3d15720c17abf0cafde5 (diff) |
Move dump() to Trampoline
From BMS.
Test: atest BackupManagerServiceTest TrampolineRoboTest TrampolineTest
Bug: 135661048
Change-Id: I49bb231552eca269f4e694fe9ec91814f67822dc
Diffstat (limited to 'services/backup/java')
-rw-r--r-- | services/backup/java/com/android/server/backup/BackupManagerService.java | 46 | ||||
-rw-r--r-- | services/backup/java/com/android/server/backup/Trampoline.java | 32 |
2 files changed, 28 insertions, 50 deletions
diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java index bd30a86dcee1..5824be72ca3e 100644 --- a/services/backup/java/com/android/server/backup/BackupManagerService.java +++ b/services/backup/java/com/android/server/backup/BackupManagerService.java @@ -22,16 +22,11 @@ import android.annotation.Nullable; import android.annotation.UserIdInt; import android.content.Context; import android.os.IBinder; -import android.os.UserHandle; import android.util.SparseArray; import com.android.internal.annotations.VisibleForTesting; -import com.android.internal.util.DumpUtils; import com.android.server.SystemService; -import java.io.FileDescriptor; -import java.io.PrintWriter; - /** * Definition of the system service that performs backup/restore operations. * @@ -45,9 +40,6 @@ public class BackupManagerService { public static final boolean MORE_DEBUG = false; public static final boolean DEBUG_SCHEDULING = true; - @VisibleForTesting - static final String DUMP_RUNNING_USERS_MESSAGE = "Backup Manager is running for users:"; - private final Context mContext; private final Trampoline mTrampoline; private final SparseArray<UserBackupManagerService> mServiceUsers; @@ -81,44 +73,6 @@ public class BackupManagerService { return mTrampoline.getServiceForUserIfCallerHasPermission(userId, caller); } - /* - * 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): Stop hardcoding system user when we pass in user id as a parameter - - // --------------------------------------------- - // SERVICE OPERATIONS - // --------------------------------------------- - - /** Prints service state for 'dumpsys backup'. */ - public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { - if (!DumpUtils.checkDumpAndUsageStatsPermission(mContext, TAG, pw)) { - return; - } - - if (args != null) { - for (String arg : args) { - if ("users".equals(arg.toLowerCase())) { - pw.print(DUMP_RUNNING_USERS_MESSAGE); - for (int i = 0; i < mServiceUsers.size(); i++) { - pw.print(" " + mServiceUsers.keyAt(i)); - } - pw.println(); - return; - } - } - } - - UserBackupManagerService userBackupManagerService = - getServiceForUserIfCallerHasPermission(UserHandle.USER_SYSTEM, "dump()"); - - if (userBackupManagerService != null) { - userBackupManagerService.dump(fd, pw, args); - } - } - /** Implementation to receive lifecycle event callbacks for system services. */ public static class Lifecycle extends SystemService { public Lifecycle(Context context) { diff --git a/services/backup/java/com/android/server/backup/Trampoline.java b/services/backup/java/com/android/server/backup/Trampoline.java index 109d6369fcc1..4cd1e17ca578 100644 --- a/services/backup/java/com/android/server/backup/Trampoline.java +++ b/services/backup/java/com/android/server/backup/Trampoline.java @@ -90,6 +90,9 @@ import java.util.Set; * UserHandle#USER_SYSTEM} and disables backup for all users. */ public class Trampoline extends IBackupManager.Stub { + @VisibleForTesting + static final String DUMP_RUNNING_USERS_MESSAGE = "Backup Manager is running for users:"; + /** * Name of file that disables the backup service. If this file exists, then backup is disabled * for all users. @@ -1442,12 +1445,33 @@ public class Trampoline extends IBackupManager.Stub { @Override public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { - if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; + if (!DumpUtils.checkDumpAndUsageStatsPermission(mContext, TAG, pw)) { + return; + } int userId = binderGetCallingUserId(); - if (isUserReadyForBackup(userId)) { - mService.dump(fd, pw, args); - } else { + if (!isUserReadyForBackup(userId)) { pw.println("Inactive"); + return; + } + + if (args != null) { + for (String arg : args) { + if ("users".equals(arg.toLowerCase())) { + pw.print(DUMP_RUNNING_USERS_MESSAGE); + for (int i = 0; i < mUserServices.size(); i++) { + pw.print(" " + mUserServices.keyAt(i)); + } + pw.println(); + return; + } + } + } + + UserBackupManagerService userBackupManagerService = + getServiceForUserIfCallerHasPermission(UserHandle.USER_SYSTEM, "dump()"); + + if (userBackupManagerService != null) { + userBackupManagerService.dump(fd, pw, args); } } |