From 0707849bf304d5609135df72911e7ea9ca0b83b7 Mon Sep 17 00:00:00 2001 From: Pavel Grafov Date: Thu, 17 Feb 2022 11:51:36 +0000 Subject: [PATCH] Remove mDeviceOwnerName - it's never read And remove all the code whose only effect is modifying this unused variable. Bug: 219944571 Test: compiles Change-Id: Ie484c4dcd3691e427365382b447e6d5a86f95cf4 Merged-In: Ie484c4dcd3691e427365382b447e6d5a86f95cf4 (cherry picked from commit 8a168e8a403ec7c7d697713b1139f7f5a556c895) --- core/java/android/app/IActivityManager.aidl | 1 - .../server/am/ActivityManagerService.java | 17 -------------- .../DevicePolicyManagerService.java | 22 ------------------- .../devicepolicy/DevicePolicyManagerTest.java | 16 -------------- 4 files changed, 56 deletions(-) diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl index 7c48a5738e515..fe0edfea59c80 100644 --- a/core/java/android/app/IActivityManager.aidl +++ b/core/java/android/app/IActivityManager.aidl @@ -510,7 +510,6 @@ interface IActivityManager { void noteAlarmFinish(in IIntentSender sender, in WorkSource workSource, int sourceUid, in String tag); @UnsupportedAppUsage int getPackageProcessState(in String packageName, in String callingPackage); - void updateDeviceOwner(in String packageName); // Start of N transactions // Start Binder transaction tracking for all applications. diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 6813f3f83135d..f249784ab4db6 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -694,12 +694,6 @@ public class ActivityManagerService extends IActivityManager.Stub return (isFg) ? mFgBroadcastQueue : mBgBroadcastQueue; } - /** - * The package name of the DeviceOwner. This package is not permitted to have its data cleared. - *

Not actually used

- */ - private volatile String mDeviceOwnerName; - private volatile int mDeviceOwnerUid = INVALID_UID; /** @@ -6237,17 +6231,6 @@ public class ActivityManagerService extends IActivityManager.Stub return ActivityClient.getInstance().getTaskForActivity(token, onlyRoot); } - @Override - public void updateDeviceOwner(String packageName) { - final int callingUid = Binder.getCallingUid(); - if (callingUid != 0 && callingUid != SYSTEM_UID) { - throw new SecurityException("updateDeviceOwner called from non-system process"); - } - synchronized (this) { - mDeviceOwnerName = packageName; - } - } - @Override public void updateLockTaskPackages(int userId, String[] packages) { mActivityTaskManager.updateLockTaskPackages(userId, packages); diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 091d879a1876f..8977390dad508 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -1999,9 +1999,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { mOwners.load(); setDeviceOwnershipSystemPropertyLocked(); findOwnerComponentIfNecessaryLocked(); - - // TODO PO may not have a class name either due to b/17652534. Address that too. - updateDeviceOwnerLocked(); } } @@ -3142,23 +3139,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } } - private void updateDeviceOwnerLocked() { - long ident = mInjector.binderClearCallingIdentity(); - try { - // TODO This is to prevent DO from getting "clear data"ed, but it should also check the - // user id and also protect all other DAs too. - final ComponentName deviceOwnerComponent = mOwners.getDeviceOwnerComponent(); - if (deviceOwnerComponent != null) { - mInjector.getIActivityManager() - .updateDeviceOwner(deviceOwnerComponent.getPackageName()); - } - } catch (RemoteException e) { - // Not gonna happen. - } finally { - mInjector.binderRestoreCallingIdentity(ident); - } - } - static void validateQualityConstant(int quality) { switch (quality) { case PASSWORD_QUALITY_UNSPECIFIED: @@ -8590,7 +8570,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { mOwners.setDeviceOwner(admin, ownerName, userId); mOwners.writeDeviceOwner(); - updateDeviceOwnerLocked(); setDeviceOwnershipSystemPropertyLocked(); //TODO(b/180371154): when provisionFullyManagedDevice is used in tests, remove this @@ -8951,7 +8930,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { mOwners.clearDeviceOwner(); mOwners.writeDeviceOwner(); - updateDeviceOwnerLocked(); clearDeviceOwnerUserRestriction(UserHandle.of(userId)); mInjector.securityLogSetLoggingEnabledProperty(false); diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java index fe110e5398cab..f1236a61cf549 100644 --- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java @@ -1137,9 +1137,6 @@ public class DevicePolicyManagerTest extends DpmTestBase { mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID; // Verify internal calls. - verify(getServices().iactivityManager, times(1)).updateDeviceOwner( - eq(admin1.getPackageName())); - verify(getServices().userManager, times(1)).setUserRestriction( eq(UserManager.DISALLOW_ADD_MANAGED_PROFILE), eq(true), eq(UserHandle.SYSTEM)); @@ -1205,9 +1202,6 @@ public class DevicePolicyManagerTest extends DpmTestBase { assertThat(dpm.getDeviceOwnerComponentOnAnyUser()).isEqualTo(admin1); // Verify internal calls. - verify(getServices().iactivityManager).updateDeviceOwner( - eq(admin1.getPackageName())); - verify(mContext.spiedContext).sendBroadcastAsUser( MockUtils.checkIntentAction(DevicePolicyManager.ACTION_DEVICE_OWNER_CHANGED), MockUtils.checkUserHandle(UserHandle.USER_SYSTEM)); @@ -1392,11 +1386,6 @@ public class DevicePolicyManagerTest extends DpmTestBase { setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_SYSTEM_USER_UID); dpm.setActiveAdmin(admin1, /* replace =*/ false); assertThat(dpm.setDeviceOwner(admin1, "owner-name", UserHandle.USER_SYSTEM)).isTrue(); - - // Verify internal calls. - verify(getServices().iactivityManager, times(1)).updateDeviceOwner( - eq(admin1.getPackageName())); - assertThat(dpm.getDeviceOwnerComponentOnAnyUser()).isEqualTo(admin1); dpm.addUserRestriction(admin1, UserManager.DISALLOW_ADD_USER); @@ -1501,11 +1490,6 @@ public class DevicePolicyManagerTest extends DpmTestBase { setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_SYSTEM_USER_UID); dpm.setActiveAdmin(admin1, /* replace =*/ false); assertThat(dpm.setDeviceOwner(admin1, "owner-name", UserHandle.USER_SYSTEM)).isTrue(); - - // Verify internal calls. - verify(getServices().iactivityManager, times(1)).updateDeviceOwner( - eq(admin1.getPackageName())); - assertThat(dpm.getDeviceOwnerComponentOnAnyUser()).isEqualTo(admin1); // Now call clear from the secondary user, which should throw.