Merge changes from topic "revert-22327091-br-cts-hsum-PYDKVUKIOU" into udc-dev am: 619bfd9214
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23126759 Change-Id: I5f1affa21d9b0fb8ade914cc6675a5bde98e5c39 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -1515,45 +1515,34 @@ public class BackupManagerService extends IBackupManager.Stub {
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void dumpWithoutCheckingPermission(FileDescriptor fd, PrintWriter pw, String[] args) {
|
void dumpWithoutCheckingPermission(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||||
int argIndex = 0;
|
int userId = binderGetCallingUserId();
|
||||||
|
if (!isUserReadyForBackup(userId)) {
|
||||||
String op = nextArg(args, argIndex);
|
pw.println("Inactive");
|
||||||
argIndex++;
|
|
||||||
|
|
||||||
if ("--help".equals(op)) {
|
|
||||||
showDumpUsage(pw);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ("users".equals(op)) {
|
|
||||||
|
if (args != null) {
|
||||||
|
for (String arg : args) {
|
||||||
|
if ("-h".equals(arg)) {
|
||||||
|
pw.println("'dumpsys backup' optional arguments:");
|
||||||
|
pw.println(" -h : this help text");
|
||||||
|
pw.println(" a[gents] : dump information about defined backup agents");
|
||||||
|
pw.println(" transportclients : dump information about transport clients");
|
||||||
|
pw.println(" transportstats : dump transport statts");
|
||||||
|
pw.println(" users : dump the list of users for which backup service "
|
||||||
|
+ "is running");
|
||||||
|
return;
|
||||||
|
} else if ("users".equals(arg.toLowerCase())) {
|
||||||
pw.print(DUMP_RUNNING_USERS_MESSAGE);
|
pw.print(DUMP_RUNNING_USERS_MESSAGE);
|
||||||
for (int i = 0; i < mUserServices.size(); i++) {
|
for (int i = 0; i < mUserServices.size(); i++) {
|
||||||
UserBackupManagerService userBackupManagerService =
|
pw.print(" " + mUserServices.keyAt(i));
|
||||||
getServiceForUserIfCallerHasPermission(mUserServices.keyAt(i),
|
|
||||||
"dump()");
|
|
||||||
if (userBackupManagerService != null) {
|
|
||||||
pw.print(" " + userBackupManagerService.getUserId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pw.println();
|
pw.println();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ("--user".equals(op)) {
|
|
||||||
String userArg = nextArg(args, argIndex);
|
|
||||||
argIndex++;
|
|
||||||
if (userArg == null) {
|
|
||||||
showDumpUsage(pw);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
int userId = UserHandle.parseUserArg(userArg);
|
|
||||||
UserBackupManagerService userBackupManagerService =
|
|
||||||
getServiceForUserIfCallerHasPermission(userId, "dump()");
|
|
||||||
if (userBackupManagerService != null) {
|
|
||||||
userBackupManagerService.dump(fd, pw, args);
|
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (op == null || "agents".startsWith(op) || "transportclients".equals(op)
|
|
||||||
|| "transportstats".equals(op)) {
|
|
||||||
for (int i = 0; i < mUserServices.size(); i++) {
|
for (int i = 0; i < mUserServices.size(); i++) {
|
||||||
UserBackupManagerService userBackupManagerService =
|
UserBackupManagerService userBackupManagerService =
|
||||||
getServiceForUserIfCallerHasPermission(mUserServices.keyAt(i), "dump()");
|
getServiceForUserIfCallerHasPermission(mUserServices.keyAt(i), "dump()");
|
||||||
@@ -1561,27 +1550,6 @@ public class BackupManagerService extends IBackupManager.Stub {
|
|||||||
userBackupManagerService.dump(fd, pw, args);
|
userBackupManagerService.dump(fd, pw, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
showDumpUsage(pw);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String nextArg(String[] args, int argIndex) {
|
|
||||||
if (argIndex >= args.length) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return args[argIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void showDumpUsage(PrintWriter pw) {
|
|
||||||
pw.println("'dumpsys backup' optional arguments:");
|
|
||||||
pw.println(" --help : this help text");
|
|
||||||
pw.println(" a[gents] : dump information about defined backup agents");
|
|
||||||
pw.println(" transportclients : dump information about transport clients");
|
|
||||||
pw.println(" transportstats : dump transport stats");
|
|
||||||
pw.println(" users : dump the list of users for which backup service is running");
|
|
||||||
pw.println(" --user <userId> : dump information for user userId");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1686,7 +1654,7 @@ public class BackupManagerService extends IBackupManager.Stub {
|
|||||||
* @param message A message to include in the exception if it is thrown.
|
* @param message A message to include in the exception if it is thrown.
|
||||||
*/
|
*/
|
||||||
void enforceCallingPermissionOnUserId(@UserIdInt int userId, String message) {
|
void enforceCallingPermissionOnUserId(@UserIdInt int userId, String message) {
|
||||||
if (binderGetCallingUserId() != userId) {
|
if (Binder.getCallingUserHandle().getIdentifier() != userId) {
|
||||||
mContext.enforceCallingOrSelfPermission(
|
mContext.enforceCallingOrSelfPermission(
|
||||||
Manifest.permission.INTERACT_ACROSS_USERS_FULL, message);
|
Manifest.permission.INTERACT_ACROSS_USERS_FULL, message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ import com.android.server.SystemService;
|
|||||||
import com.android.server.backup.utils.RandomAccessFileUtils;
|
import com.android.server.backup.utils.RandomAccessFileUtils;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -616,50 +615,6 @@ public class BackupManagerServiceTest {
|
|||||||
verify(mNonSystemUserBackupManagerService, never()).dump(any(), any(), any());
|
verify(mNonSystemUserBackupManagerService, never()).dump(any(), any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDumpForOneUser_callerDoesNotHaveInteractAcrossUsersFullPermission_ignored() {
|
|
||||||
mService.setBackupServiceActive(NON_SYSTEM_USER, true);
|
|
||||||
simulateUserUnlocked(NON_SYSTEM_USER);
|
|
||||||
|
|
||||||
doThrow(new SecurityException())
|
|
||||||
.when(mContextMock)
|
|
||||||
.enforceCallingOrSelfPermission(
|
|
||||||
eq(Manifest.permission.INTERACT_ACROSS_USERS_FULL), anyString());
|
|
||||||
|
|
||||||
String[] args = new String[]{"--user", Integer.toString(NON_SYSTEM_USER)};
|
|
||||||
Assert.assertThrows(SecurityException.class,
|
|
||||||
() -> mService.dumpWithoutCheckingPermission(mFileDescriptorStub, mPrintWriterMock,
|
|
||||||
args));
|
|
||||||
|
|
||||||
verify(mNonSystemUserBackupManagerService, never()).dump(any(), any(), any());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void
|
|
||||||
testDumpForOneUser_callerHasInteractAcrossUsersFullPermission_dumpsOnlySpecifiedUser() {
|
|
||||||
mService.setBackupServiceActive(NON_SYSTEM_USER, true);
|
|
||||||
simulateUserUnlocked(NON_SYSTEM_USER);
|
|
||||||
|
|
||||||
String[] args = new String[]{"--user", Integer.toString(UserHandle.USER_SYSTEM)};
|
|
||||||
mService.dumpWithoutCheckingPermission(mFileDescriptorStub, mPrintWriterMock, args);
|
|
||||||
|
|
||||||
verify(mSystemUserBackupManagerService).dump(any(), any(), any());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDumpForAllUsers_callerHasInteractAcrossUsersFullPermission_dumpsAllUsers() {
|
|
||||||
mService.setBackupServiceActive(NON_SYSTEM_USER, true);
|
|
||||||
simulateUserUnlocked(NON_SYSTEM_USER);
|
|
||||||
|
|
||||||
String[] args = new String[]{"users"};
|
|
||||||
mService.dumpWithoutCheckingPermission(mFileDescriptorStub, mPrintWriterMock, args);
|
|
||||||
|
|
||||||
// Check that dump() invocations are not called on user's Backup service,
|
|
||||||
// as 'dumpsys backup users' only list users for whom Backup service is running.
|
|
||||||
verify(mSystemUserBackupManagerService, never()).dump(any(), any(), any());
|
|
||||||
verify(mNonSystemUserBackupManagerService, never()).dump(any(), any(), any());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that {@link BackupManagerService#dump(FileDescriptor, PrintWriter, String[])} dumps
|
* Test that {@link BackupManagerService#dump(FileDescriptor, PrintWriter, String[])} dumps
|
||||||
* system user information before non-system user information.
|
* system user information before non-system user information.
|
||||||
|
|||||||
Reference in New Issue
Block a user