Skip to content
Snippets Groups Projects
Commit 36b47d53 authored by Nicolas Sleiman's avatar Nicolas Sleiman Committed by Automerger Merge Worker
Browse files

Merge "Override work profile OEM telephony shortcuts with defaults" into...

Merge "Override work profile OEM telephony shortcuts with defaults" into udc-dev am: 0b2cda77 am: 9e602157

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22990097



Change-Id: Ida736be0e0b2a59fb3523a50137b06c2205560e6
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents d79d21c9 9e602157
No related branches found
No related tags found
No related merge requests found
......@@ -3611,10 +3611,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
if (isProfileOwnerOfOrganizationOwnedDevice(userId)
&& getManagedSubscriptionsPolicy().getPolicyType()
== ManagedSubscriptionsPolicy.TYPE_ALL_MANAGED_SUBSCRIPTIONS) {
String defaultDialerPackageName = getOemDefaultDialerPackage();
String defaultSmsPackageName = getOemDefaultSmsPackage();
updateDialerAndSmsManagedShortcutsOverrideCache(defaultDialerPackageName,
defaultSmsPackageName);
updateDialerAndSmsManagedShortcutsOverrideCache();
}
 
startOwnerService(userId, "start-user");
......@@ -10728,15 +10725,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
return UserHandle.USER_NULL;
}
 
private @UserIdInt int getManagedProfileUserId() {
for (UserInfo ui : mUserManagerInternal.getUserInfos()) {
if (ui.isManagedProfile()) {
return ui.id;
}
}
return UserHandle.USER_NULL;
}
/**
* This API is cached: invalidate with invalidateBinderCaches().
*/
......@@ -11599,6 +11587,12 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
synchronized (getLockObject()) {
final ActiveAdmin activeAdmin = getParentOfAdminIfRequired(
getProfileOwnerOrDeviceOwnerLocked(caller.getUserId()), parent);
if (isManagedProfile(userId)) {
mInjector.binderWithCleanCallingIdentity(
() -> updateDialerAndSmsManagedShortcutsOverrideCache());
}
if (!Objects.equals(activeAdmin.mSmsPackage, packageName)) {
activeAdmin.mSmsPackage = packageName;
saveSettingsLocked(caller.getUserId());
......@@ -11644,6 +11638,11 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
});
// Only save the package when the setting the role succeeded without exception.
synchronized (getLockObject()) {
if (isManagedProfile(callerUserId)) {
mInjector.binderWithCleanCallingIdentity(
() -> updateDialerAndSmsManagedShortcutsOverrideCache());
}
final ActiveAdmin admin = getProfileOwnerOrDeviceOwnerLocked(callerUserId);
if (!Objects.equals(admin.mDialerPackage, packageName)) {
admin.mDialerPackage = packageName;
......@@ -23934,8 +23933,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
Slogf.w(LOG_TAG, "Couldn't install sms app, sms app package is null");
}
 
updateDialerAndSmsManagedShortcutsOverrideCache(defaultDialerPackageName,
defaultSmsPackageName);
updateDialerAndSmsManagedShortcutsOverrideCache();
} catch (RemoteException re) {
// shouldn't happen
Slogf.wtf(LOG_TAG, "Failed to install dialer/sms app", re);
......@@ -23951,17 +23949,28 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
return mContext.getString(R.string.config_defaultSms);
}
 
private void updateDialerAndSmsManagedShortcutsOverrideCache(
String defaultDialerPackageName, String defaultSmsPackageName) {
private void updateDialerAndSmsManagedShortcutsOverrideCache() {
ArrayMap<String, String> shortcutOverrides = new ArrayMap<>();
int managedUserId = getManagedUserId();
List<String> dialerRoleHolders = mRoleManager.getRoleHoldersAsUser(RoleManager.ROLE_DIALER,
UserHandle.of(managedUserId));
List<String> smsRoleHolders = mRoleManager.getRoleHoldersAsUser(RoleManager.ROLE_SMS,
UserHandle.of(managedUserId));
 
if (defaultDialerPackageName != null) {
shortcutOverrides.put(defaultDialerPackageName, defaultDialerPackageName);
}
String dialerPackageToOverride = getOemDefaultDialerPackage();
String smsPackageToOverride = getOemDefaultSmsPackage();
 
if (defaultSmsPackageName != null) {
shortcutOverrides.put(defaultSmsPackageName, defaultSmsPackageName);
// To get the default app, we can get all the role holders and get the first element.
if (dialerPackageToOverride != null) {
shortcutOverrides.put(dialerPackageToOverride,
dialerRoleHolders.isEmpty() ? dialerPackageToOverride
: dialerRoleHolders.get(0));
}
if (smsPackageToOverride != null) {
shortcutOverrides.put(smsPackageToOverride,
smsRoleHolders.isEmpty() ? smsPackageToOverride : smsRoleHolders.get(0));
}
mPolicyCache.setLauncherShortcutOverrides(shortcutOverrides);
}
 
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment