diff options
author | 2023-02-03 17:25:14 +0000 | |
---|---|---|
committer | 2024-04-10 17:42:14 +0100 | |
commit | f98823a3aa1d31189fcedd05f62d963781e766f3 (patch) | |
tree | 1bb793e76d79f7c2e0b3d59304ba5a4433e71e27 /services/robotests/backup | |
parent | efc35f89fd67ad7a66a42df7ddef51f3d44d48c8 (diff) |
Improve `dumpsys backup`
This is a re-submit of the previously reverted ag/22327091 by
piee@google.com.
Original description:
This change refactors `dumpsys backup` code and adds some improvements -
- Removes `isUserReadyForBackup()` check on calling user. This check is not needed, as it prevents a User with INTERACT_ACROSS_USERS_FULL permission, but not Backup activated, to get info about Backup service on other users. This is particularly relevant in case of headless mode, as Backup service isn't running for SYSTEM_USER.
- Adds `--user <userId>` optional parameter for `dumpsys backup`, which will return info about Backup service for the user passed in argument. This is also helpul in case of multiple users on the device.
Changes by sarpm@google.com over the original:
- Some test improvements: remove @VisibleForTesting, increase
coverage slightly.
- Remove redundant robo tests that are now covered by the unit
tests.
Bug: 267755698
Test: atest BackupManagerServiceTest
Manual test by running dumpsys backup with optional arguments.
Change-Id: Id7790a501a8befb12a212f66adfc0cd8cc9f9e8b
Diffstat (limited to 'services/robotests/backup')
-rw-r--r-- | services/robotests/backup/src/com/android/server/backup/BackupManagerServiceRoboTest.java | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/services/robotests/backup/src/com/android/server/backup/BackupManagerServiceRoboTest.java b/services/robotests/backup/src/com/android/server/backup/BackupManagerServiceRoboTest.java index 94ee0a871448..a547d0f94ea3 100644 --- a/services/robotests/backup/src/com/android/server/backup/BackupManagerServiceRoboTest.java +++ b/services/robotests/backup/src/com/android/server/backup/BackupManagerServiceRoboTest.java @@ -17,9 +17,7 @@ package com.android.server.backup; import static android.Manifest.permission.BACKUP; -import static android.Manifest.permission.DUMP; import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL; -import static android.Manifest.permission.PACKAGE_USAGE_STATS; import static com.android.server.backup.testing.TransportData.backupTransport; @@ -73,10 +71,7 @@ import org.robolectric.shadow.api.Shadow; import org.robolectric.shadows.ShadowContextWrapper; import java.io.File; -import java.io.FileDescriptor; import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; /** Tests for {@link BackupManagerService}. */ @RunWith(RobolectricTestRunner.class) @@ -1461,67 +1456,12 @@ public class BackupManagerServiceRoboTest { // Service tests // --------------------------------------------- - /** Test that the backup service routes methods correctly to the user that requests it. */ - @Test - public void testDump_onRegisteredUser_callsMethodForUser() throws Exception { - grantDumpPermissions(); - BackupManagerService backupManagerService = createSystemRegisteredService(); - File testFile = createTestFile(); - FileDescriptor fileDescriptor = new FileDescriptor(); - PrintWriter printWriter = new PrintWriter(testFile); - String[] args = {"1", "2"}; - ShadowBinder.setCallingUserHandle(UserHandle.of(UserHandle.USER_SYSTEM)); - - backupManagerService.dump(fileDescriptor, printWriter, args); - - verify(mUserSystemService).dump(fileDescriptor, printWriter, args); - } - - /** Test that the backup service does not route methods for non-registered users. */ - @Test - public void testDump_onUnknownUser_doesNotPropagateCall() throws Exception { - grantDumpPermissions(); - BackupManagerService backupManagerService = createService(); - File testFile = createTestFile(); - FileDescriptor fileDescriptor = new FileDescriptor(); - PrintWriter printWriter = new PrintWriter(testFile); - String[] args = {"1", "2"}; - - backupManagerService.dump(fileDescriptor, printWriter, args); - - verify(mUserOneService, never()).dump(fileDescriptor, printWriter, args); - } - - /** Test that 'dumpsys backup users' dumps the list of users registered in backup service*/ - @Test - public void testDump_users_dumpsListOfRegisteredUsers() { - grantDumpPermissions(); - BackupManagerService backupManagerService = createSystemRegisteredService(); - registerUser(backupManagerService, mUserOneId, mUserOneService); - StringWriter out = new StringWriter(); - PrintWriter writer = new PrintWriter(out); - String[] args = {"users"}; - - backupManagerService.dump(null, writer, args); - - writer.flush(); - assertEquals( - String.format("%s %d %d\n", BackupManagerService.DUMP_RUNNING_USERS_MESSAGE, - UserHandle.USER_SYSTEM, mUserOneId), - out.toString()); - } - private File createTestFile() throws IOException { File testFile = new File(mContext.getFilesDir(), "test"); testFile.createNewFile(); return testFile; } - private void grantDumpPermissions() { - mShadowContext.grantPermissions(DUMP); - mShadowContext.grantPermissions(PACKAGE_USAGE_STATS); - } - /** * Test that the backup services throws a {@link SecurityException} if the caller does not have * INTERACT_ACROSS_USERS_FULL permission and passes a different user id. |