diff options
author | Julia Reynolds <juliacr@google.com> | 2015-04-20 16:42:54 -0400 |
---|---|---|
committer | Julia Reynolds <juliacr@google.com> | 2015-04-27 12:57:15 -0400 |
commit | 13c58bacc8f1ff35bb24ba19069bab8a41aabf68 (patch) | |
tree | 2b0774ae106086381d7884929124f226f6d91589 /services/devicepolicy/java/com/android | |
parent | 28b5b1444965fcdb471a8c2ff09f6f2eb53b337b (diff) | |
download | frameworks_base-13c58bacc8f1ff35bb24ba19069bab8a41aabf68.zip frameworks_base-13c58bacc8f1ff35bb24ba19069bab8a41aabf68.tar.gz frameworks_base-13c58bacc8f1ff35bb24ba19069bab8a41aabf68.tar.bz2 |
Allow device initializers to set a preferred setup activity.
This activity will launch by default on device reboot or user switch
during user initialization, even if there are higher priority 'home'
activities.
Bug: 20223050
Change-Id: I335aeb010a1ae5db07a4343d26e160c74bd299e1
Diffstat (limited to 'services/devicepolicy/java/com/android')
-rw-r--r-- | services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 2b88158..31d7f74 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -181,6 +181,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { private static final String ATTR_PERMISSION_PROVIDER = "permission-provider"; private static final String ATTR_SETUP_COMPLETE = "setup-complete"; + private static final String ATTR_PREFERRED_SETUP_ACTIVITY = "setup-activity"; private static final String ATTR_DELEGATED_CERT_INSTALLER = "delegated-cert-installer"; @@ -315,6 +316,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { boolean doNotAskCredentialsOnBoot = false; + ComponentName mPreferredSetupActivity; + public DevicePolicyData(int userHandle) { mUserHandle = userHandle; } @@ -1410,7 +1413,12 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { out.attribute(null, ATTR_DELEGATED_CERT_INSTALLER, policy.mDelegatedCertInstallerPackage); } - + if (policy.mPreferredSetupActivity != null) { + out.attribute(null, ATTR_PREFERRED_SETUP_ACTIVITY, + policy.mPreferredSetupActivity.flattenToString()); + } else { + out.attribute(null, ATTR_PREFERRED_SETUP_ACTIVITY, ""); + } final int N = policy.mAdminList.size(); for (int i=0; i<N; i++) { @@ -1531,6 +1539,12 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } policy.mDelegatedCertInstallerPackage = parser.getAttributeValue(null, ATTR_DELEGATED_CERT_INSTALLER); + String preferredSetupActivity = + parser.getAttributeValue(null, ATTR_PREFERRED_SETUP_ACTIVITY); + if (preferredSetupActivity != null) { + policy.mPreferredSetupActivity = + ComponentName.unflattenFromString(preferredSetupActivity); + } type = parser.next(); int outerDepth = parser.getDepth(); @@ -1654,6 +1668,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!policy.mStatusBarEnabledState) { setStatusBarEnabledStateInternal(policy.mStatusBarEnabledState, userHandle); } + updatePreferredSetupActivityLocked(userHandle); } private void updateLockTaskPackagesLocked(List<String> packages, int userId) { @@ -4632,6 +4647,43 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } @Override + public void setPreferredSetupActivity(ComponentName who, ComponentName activity) { + if (!mHasFeature) { + return; + } + Preconditions.checkNotNull(who, "ComponentName is null"); + synchronized (this) { + ActiveAdmin activeAdmin = + getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); + if (!isDeviceInitializer(activeAdmin.info.getPackageName())) { + throw new SecurityException( + "This method can only be called by device initializers"); + } + int userHandle = UserHandle.getCallingUserId(); + DevicePolicyData userData = getUserData(userHandle); + userData.mPreferredSetupActivity = activity; + saveSettingsLocked(userHandle); + updatePreferredSetupActivityLocked(userHandle); + } + } + + private void updatePreferredSetupActivityLocked(int userHandle) { + if (!mHasFeature) { + return; + } + IActivityManager am = ActivityManagerNative.getDefault(); + long ident = Binder.clearCallingIdentity(); + try { + am.updatePreferredSetupActivity( + getUserData(userHandle).mPreferredSetupActivity, userHandle); + } catch (RemoteException e) { + // Not gonna happen. + } finally { + Binder.restoreCallingIdentity(ident); + } + } + + @Override public void setApplicationRestrictions(ComponentName who, String packageName, Bundle settings) { Preconditions.checkNotNull(who, "ComponentName is null"); final UserHandle userHandle = new UserHandle(UserHandle.getCallingUserId()); @@ -6000,6 +6052,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!policy.mUserSetupComplete) { policy.mUserSetupComplete = true; synchronized (this) { + // Clear the preferred setup activity. + policy.mPreferredSetupActivity = null; + updatePreferredSetupActivityLocked(userHandle); // The DeviceInitializer was whitelisted but now should be removed. removeDeviceInitializerFromLockTaskPackages(userHandle); saveSettingsLocked(userHandle); |