Loading core/java/android/app/ActivityManagerNative.java +20 −0 Original line number Diff line number Diff line Loading @@ -2513,6 +2513,14 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM return true; } case UPDATE_DEVICE_OWNER_TRANSACTION: { data.enforceInterface(IActivityManager.descriptor); String packageName = data.readString(); updateDeviceOwner(packageName); reply.writeNoException(); return true; } case GET_PACKAGE_PROCESS_STATE_TRANSACTION: { data.enforceInterface(IActivityManager.descriptor); String pkg = data.readString(); Loading Loading @@ -5800,6 +5808,18 @@ class ActivityManagerProxy implements IActivityManager reply.recycle(); } @Override public void updateDeviceOwner(String packageName) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writeInterfaceToken(IActivityManager.descriptor); data.writeString(packageName); mRemote.transact(UPDATE_DEVICE_OWNER_TRANSACTION, data, reply, 0); reply.readException(); data.recycle(); reply.recycle(); } @Override public int getPackageProcessState(String packageName) throws RemoteException { Parcel data = Parcel.obtain(); Loading core/java/android/app/IActivityManager.java +2 −0 Original line number Diff line number Diff line Loading @@ -495,6 +495,7 @@ public interface IActivityManager extends IInterface { public void setVoiceKeepAwake(IVoiceInteractionSession session, boolean keepAwake) throws RemoteException; public void updateLockTaskPackages(int userId, String[] packages) throws RemoteException; public void updateDeviceOwner(String packageName) throws RemoteException; public int getPackageProcessState(String packageName) throws RemoteException; Loading Loading @@ -837,4 +838,5 @@ public interface IActivityManager extends IInterface { int NOTE_ALARM_FINISH_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+292; int GET_PACKAGE_PROCESS_STATE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+293; int SHOW_LOCK_TASK_ESCAPE_MESSAGE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+294; int UPDATE_DEVICE_OWNER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+295; } services/core/java/com/android/server/am/ActivityManagerService.java +19 −0 Original line number Diff line number Diff line Loading @@ -437,6 +437,11 @@ public final class ActivityManagerService extends ActivityManagerNative */ SparseArray<String[]> mLockTaskPackages = new SparseArray<>(); /** * The package name of the DeviceOwner. This package is not permitted to have its data cleared. */ String mDeviceOwnerName; public class PendingAssistExtras extends Binder implements Runnable { public final ActivityRecord activity; public final Bundle extras; Loading Loading @@ -4831,6 +4836,9 @@ public final class ActivityManagerService extends ActivityManagerNative public boolean clearApplicationUserData(final String packageName, final IPackageDataObserver observer, int userId) { enforceNotIsolatedCaller("clearApplicationUserData"); if (packageName != null && packageName.equals(mDeviceOwnerName)) { throw new SecurityException("Clearing DeviceOwner data is forbidden."); } int uid = Binder.getCallingUid(); int pid = Binder.getCallingPid(); userId = handleIncomingUser(pid, uid, Loading Loading @@ -8562,6 +8570,17 @@ public final class ActivityManagerService extends ActivityManagerNative } } @Override public void updateDeviceOwner(String packageName) { final int callingUid = Binder.getCallingUid(); if (callingUid != 0 && callingUid != Process.SYSTEM_UID) { throw new SecurityException("updateDeviceOwner called from non-system process"); } synchronized (this) { mDeviceOwnerName = packageName; } } @Override public void updateLockTaskPackages(int userId, String[] packages) { final int callingUid = Binder.getCallingUid(); Loading services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +18 −7 Original line number Diff line number Diff line Loading @@ -1106,6 +1106,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { void loadDeviceOwner() { synchronized (this) { mDeviceOwner = DeviceOwner.load(); updateDeviceOwnerLocked(); } } Loading Loading @@ -1667,6 +1668,18 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } } private void updateDeviceOwnerLocked() { IActivityManager am = ActivityManagerNative.getDefault(); long ident = Binder.clearCallingIdentity(); try { am.updateDeviceOwner(mDeviceOwner.getDeviceOwnerPackageName()); } catch (RemoteException e) { // Not gonna happen. } finally { Binder.restoreCallingIdentity(ident); } } static void validateQualityConstant(int quality) { switch (quality) { case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED: Loading Loading @@ -3990,16 +4003,15 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (mDeviceOwner == null) { // Device owner is not set and does not exist, set it. mDeviceOwner = DeviceOwner.createWithDeviceOwner(packageName, ownerName); mDeviceOwner.writeOwnerFile(); return true; } else { // Device owner is not set but a profile owner exists, update Device owner state. mDeviceOwner.setDeviceOwner(packageName, ownerName); } mDeviceOwner.writeOwnerFile(); updateDeviceOwnerLocked(); return true; } } } @Override public boolean isDeviceOwner(String packageName) { Loading Loading @@ -4079,6 +4091,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (mDeviceOwner != null) { mDeviceOwner.clearDeviceOwner(); mDeviceOwner.writeOwnerFile(); updateDeviceOwnerLocked(); } } finally { Binder.restoreCallingIdentity(ident); Loading Loading @@ -4107,15 +4120,13 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (mDeviceOwner == null) { // Device owner state does not exist, create it. mDeviceOwner = DeviceOwner.createWithDeviceInitializer( initializer, ownerName); mDeviceOwner = DeviceOwner.createWithDeviceInitializer(initializer, ownerName); } else { // Device owner already exists, update it. mDeviceOwner.setDeviceInitializer(initializer, ownerName); } addDeviceInitializerToLockTaskPackagesLocked(UserHandle.USER_OWNER); mDeviceOwner.writeOwnerFile(); return true; } Loading Loading
core/java/android/app/ActivityManagerNative.java +20 −0 Original line number Diff line number Diff line Loading @@ -2513,6 +2513,14 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM return true; } case UPDATE_DEVICE_OWNER_TRANSACTION: { data.enforceInterface(IActivityManager.descriptor); String packageName = data.readString(); updateDeviceOwner(packageName); reply.writeNoException(); return true; } case GET_PACKAGE_PROCESS_STATE_TRANSACTION: { data.enforceInterface(IActivityManager.descriptor); String pkg = data.readString(); Loading Loading @@ -5800,6 +5808,18 @@ class ActivityManagerProxy implements IActivityManager reply.recycle(); } @Override public void updateDeviceOwner(String packageName) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); data.writeInterfaceToken(IActivityManager.descriptor); data.writeString(packageName); mRemote.transact(UPDATE_DEVICE_OWNER_TRANSACTION, data, reply, 0); reply.readException(); data.recycle(); reply.recycle(); } @Override public int getPackageProcessState(String packageName) throws RemoteException { Parcel data = Parcel.obtain(); Loading
core/java/android/app/IActivityManager.java +2 −0 Original line number Diff line number Diff line Loading @@ -495,6 +495,7 @@ public interface IActivityManager extends IInterface { public void setVoiceKeepAwake(IVoiceInteractionSession session, boolean keepAwake) throws RemoteException; public void updateLockTaskPackages(int userId, String[] packages) throws RemoteException; public void updateDeviceOwner(String packageName) throws RemoteException; public int getPackageProcessState(String packageName) throws RemoteException; Loading Loading @@ -837,4 +838,5 @@ public interface IActivityManager extends IInterface { int NOTE_ALARM_FINISH_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+292; int GET_PACKAGE_PROCESS_STATE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+293; int SHOW_LOCK_TASK_ESCAPE_MESSAGE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+294; int UPDATE_DEVICE_OWNER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+295; }
services/core/java/com/android/server/am/ActivityManagerService.java +19 −0 Original line number Diff line number Diff line Loading @@ -437,6 +437,11 @@ public final class ActivityManagerService extends ActivityManagerNative */ SparseArray<String[]> mLockTaskPackages = new SparseArray<>(); /** * The package name of the DeviceOwner. This package is not permitted to have its data cleared. */ String mDeviceOwnerName; public class PendingAssistExtras extends Binder implements Runnable { public final ActivityRecord activity; public final Bundle extras; Loading Loading @@ -4831,6 +4836,9 @@ public final class ActivityManagerService extends ActivityManagerNative public boolean clearApplicationUserData(final String packageName, final IPackageDataObserver observer, int userId) { enforceNotIsolatedCaller("clearApplicationUserData"); if (packageName != null && packageName.equals(mDeviceOwnerName)) { throw new SecurityException("Clearing DeviceOwner data is forbidden."); } int uid = Binder.getCallingUid(); int pid = Binder.getCallingPid(); userId = handleIncomingUser(pid, uid, Loading Loading @@ -8562,6 +8570,17 @@ public final class ActivityManagerService extends ActivityManagerNative } } @Override public void updateDeviceOwner(String packageName) { final int callingUid = Binder.getCallingUid(); if (callingUid != 0 && callingUid != Process.SYSTEM_UID) { throw new SecurityException("updateDeviceOwner called from non-system process"); } synchronized (this) { mDeviceOwnerName = packageName; } } @Override public void updateLockTaskPackages(int userId, String[] packages) { final int callingUid = Binder.getCallingUid(); Loading
services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +18 −7 Original line number Diff line number Diff line Loading @@ -1106,6 +1106,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { void loadDeviceOwner() { synchronized (this) { mDeviceOwner = DeviceOwner.load(); updateDeviceOwnerLocked(); } } Loading Loading @@ -1667,6 +1668,18 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } } private void updateDeviceOwnerLocked() { IActivityManager am = ActivityManagerNative.getDefault(); long ident = Binder.clearCallingIdentity(); try { am.updateDeviceOwner(mDeviceOwner.getDeviceOwnerPackageName()); } catch (RemoteException e) { // Not gonna happen. } finally { Binder.restoreCallingIdentity(ident); } } static void validateQualityConstant(int quality) { switch (quality) { case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED: Loading Loading @@ -3990,16 +4003,15 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (mDeviceOwner == null) { // Device owner is not set and does not exist, set it. mDeviceOwner = DeviceOwner.createWithDeviceOwner(packageName, ownerName); mDeviceOwner.writeOwnerFile(); return true; } else { // Device owner is not set but a profile owner exists, update Device owner state. mDeviceOwner.setDeviceOwner(packageName, ownerName); } mDeviceOwner.writeOwnerFile(); updateDeviceOwnerLocked(); return true; } } } @Override public boolean isDeviceOwner(String packageName) { Loading Loading @@ -4079,6 +4091,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (mDeviceOwner != null) { mDeviceOwner.clearDeviceOwner(); mDeviceOwner.writeOwnerFile(); updateDeviceOwnerLocked(); } } finally { Binder.restoreCallingIdentity(ident); Loading Loading @@ -4107,15 +4120,13 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (mDeviceOwner == null) { // Device owner state does not exist, create it. mDeviceOwner = DeviceOwner.createWithDeviceInitializer( initializer, ownerName); mDeviceOwner = DeviceOwner.createWithDeviceInitializer(initializer, ownerName); } else { // Device owner already exists, update it. mDeviceOwner.setDeviceInitializer(initializer, ownerName); } addDeviceInitializerToLockTaskPackagesLocked(UserHandle.USER_OWNER); mDeviceOwner.writeOwnerFile(); return true; } Loading