diff options
| author | kholoud mohamed <kholoudm@google.com> | 2022-03-14 11:08:31 +0000 |
|---|---|---|
| committer | kholoud mohamed <kholoudm@google.com> | 2022-03-19 00:22:17 +0000 |
| commit | b7aedc6f3d838440d1128de167578191e8ea1f5d (patch) | |
| tree | a14231d8e473914a8b7a6b7b93d507d6eba032dc /core/java | |
| parent | 7cb1133b160555e72443019bfa63677e0cdbefd7 (diff) | |
RESTRICT AUTOMERGE Refactor device policy resource APIs to a separate class
Bug: 217388602
Bug: 218875965
Test: atest EnterpriseResourcesTests
Test: manual
Change-Id: I8af03136e67057d171e97cb5a43187aa6c7f4fe7
Diffstat (limited to 'core/java')
14 files changed, 44 insertions, 48 deletions
diff --git a/core/java/android/accounts/CantAddAccountActivity.java b/core/java/android/accounts/CantAddAccountActivity.java index 107efc3cce95..3fac1a0bdea0 100644 --- a/core/java/android/accounts/CantAddAccountActivity.java +++ b/core/java/android/accounts/CantAddAccountActivity.java @@ -39,7 +39,7 @@ public class CantAddAccountActivity extends Activity { setContentView(R.layout.app_not_authorized); TextView view = findViewById(R.id.description); - String text = getSystemService(DevicePolicyManager.class).getString( + String text = getSystemService(DevicePolicyManager.class).getResources().getString( CANT_ADD_ACCOUNT_MESSAGE, () -> getString(R.string.error_message_change_not_allowed)); view.setText(text); diff --git a/core/java/android/accounts/ChooseTypeAndAccountActivity.java b/core/java/android/accounts/ChooseTypeAndAccountActivity.java index 0d82ac942148..f623295dee3e 100644 --- a/core/java/android/accounts/ChooseTypeAndAccountActivity.java +++ b/core/java/android/accounts/ChooseTypeAndAccountActivity.java @@ -205,7 +205,7 @@ public class ChooseTypeAndAccountActivity extends Activity setContentView(R.layout.app_not_authorized); TextView view = findViewById(R.id.description); - String text = getSystemService(DevicePolicyManager.class).getString( + String text = getSystemService(DevicePolicyManager.class).getResources().getString( CANT_ADD_ACCOUNT_MESSAGE, () -> getString(R.string.error_message_change_not_allowed)); view.setText(text); diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java index 7ffa61be7604..d641a3b469a6 100644 --- a/core/java/android/app/ApplicationPackageManager.java +++ b/core/java/android/app/ApplicationPackageManager.java @@ -18,9 +18,9 @@ package android.app; import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_COLORED; import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_NOT_COLORED; -import static android.app.admin.DevicePolicyResources.Drawables.UNDEFINED; import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON; import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON_BADGE; +import static android.app.admin.DevicePolicyResources.UNDEFINED; import static android.content.pm.Checksum.TYPE_PARTIAL_MERKLE_ROOT_1M_SHA256; import static android.content.pm.Checksum.TYPE_PARTIAL_MERKLE_ROOT_1M_SHA512; import static android.content.pm.Checksum.TYPE_WHOLE_MD5; @@ -1886,7 +1886,7 @@ public class ApplicationPackageManager extends PackageManager { return icon; } - final Drawable badgeForeground = getDevicePolicyManager().getDrawable( + final Drawable badgeForeground = getDevicePolicyManager().getResources().getDrawable( getUpdatableUserIconBadgeId(user), SOLID_COLORED, () -> getDefaultUserIconBadge(user)); @@ -1938,11 +1938,12 @@ public class ApplicationPackageManager extends PackageManager { return null; } - final Drawable badgeForeground = getDevicePolicyManager().getDrawableForDensity( - getUpdatableUserBadgeId(user), - SOLID_COLORED, - density, - () -> getDefaultUserBadgeForDensity(user, density)); + final Drawable badgeForeground = getDevicePolicyManager().getResources() + .getDrawableForDensity( + getUpdatableUserBadgeId(user), + SOLID_COLORED, + density, + () -> getDefaultUserBadgeForDensity(user, density)); badgeForeground.setTint(getUserBadgeColor(user, false)); Drawable badge = new LayerDrawable(new Drawable[] {badgeColor, badgeForeground }); @@ -1968,7 +1969,7 @@ public class ApplicationPackageManager extends PackageManager { return null; } - final Drawable badge = getDevicePolicyManager().getDrawableForDensity( + final Drawable badge = getDevicePolicyManager().getResources().getDrawableForDensity( getUpdatableUserBadgeId(user), SOLID_NOT_COLORED, density, diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 7e0cea8921a4..6e1d1cd2e4c9 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -19,8 +19,8 @@ package android.app; import static android.annotation.Dimension.DP; import static android.app.admin.DevicePolicyResources.Drawables.Source.NOTIFICATION; import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_COLORED; -import static android.app.admin.DevicePolicyResources.Drawables.UNDEFINED; import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON; +import static android.app.admin.DevicePolicyResources.UNDEFINED; import static android.graphics.drawable.Icon.TYPE_URI; import static android.graphics.drawable.Icon.TYPE_URI_ADAPTIVE_BITMAP; @@ -5079,7 +5079,7 @@ public class Notification implements Parcelable // Note: This assumes that the current user can read the profile badge of the // originating user. DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class); - return dpm.getDrawable( + return dpm.getResources().getDrawable( getUpdatableProfileBadgeId(), SOLID_COLORED, NOTIFICATION, this::getDefaultProfileBadgeDrawable); } diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index a34feb4b6b93..d48e9f495257 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -41,7 +41,6 @@ import android.annotation.WorkerThread; import android.app.Activity; import android.app.IServiceConnection; import android.app.KeyguardManager; -import android.app.admin.DevicePolicyResources.Drawables; import android.app.admin.SecurityLog.SecurityEvent; import android.compat.annotation.UnsupportedAppUsage; import android.content.ComponentName; @@ -55,10 +54,8 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ParceledListSlice; import android.content.pm.UserInfo; -import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; -import android.graphics.drawable.Icon; import android.net.PrivateDnsConnectivityChecker; import android.net.ProxyInfo; import android.net.Uri; @@ -97,7 +94,6 @@ import android.telephony.data.ApnSetting; import android.text.TextUtils; import android.util.ArraySet; import android.util.DebugUtils; -import android.util.DisplayMetrics; import android.util.Log; import android.util.Pair; @@ -138,7 +134,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; import java.util.function.Consumer; -import java.util.function.Supplier; // TODO(b/172376923) - add CarDevicePolicyManager examples below (or remove reference to it). /** diff --git a/core/java/android/content/pm/CrossProfileApps.java b/core/java/android/content/pm/CrossProfileApps.java index b6917e269916..66c6c817e9ea 100644 --- a/core/java/android/content/pm/CrossProfileApps.java +++ b/core/java/android/content/pm/CrossProfileApps.java @@ -326,7 +326,7 @@ public class CrossProfileApps { final boolean isManagedProfile = mUserManager.isManagedProfile(userHandle.getIdentifier()); final DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class); - return dpm.getString( + return dpm.getResources().getString( getUpdatableProfileSwitchingLabelId(isManagedProfile), () -> getDefaultProfileSwitchingLabel(isManagedProfile)); } diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java index 2448a0504302..608c424451b7 100644 --- a/core/java/android/os/UserManager.java +++ b/core/java/android/os/UserManager.java @@ -17,7 +17,7 @@ package android.os; import static android.app.admin.DevicePolicyResources.Strings.Core.WORK_PROFILE_BADGED_LABEL; -import static android.app.admin.DevicePolicyResources.Strings.UNDEFINED; +import static android.app.admin.DevicePolicyResources.UNDEFINED; import android.Manifest; import android.accounts.AccountManager; @@ -4749,7 +4749,7 @@ public class UserManager { return label; } DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class); - return dpm.getString( + return dpm.getResources().getString( getUpdatableUserBadgedLabelId(userId), () -> getDefaultUserBadgedLabel(label, userId), /* formatArgs= */ label); diff --git a/core/java/android/util/IconDrawableFactory.java b/core/java/android/util/IconDrawableFactory.java index 5bb263a1f463..e3bc510b8e40 100644 --- a/core/java/android/util/IconDrawableFactory.java +++ b/core/java/android/util/IconDrawableFactory.java @@ -16,8 +16,8 @@ package android.util; import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_COLORED; -import static android.app.admin.DevicePolicyResources.Drawables.UNDEFINED; import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON_BADGE; +import static android.app.admin.DevicePolicyResources.UNDEFINED; import android.annotation.UserIdInt; import android.app.admin.DevicePolicyManager; @@ -88,7 +88,7 @@ public class IconDrawableFactory { } if (mUm.hasBadge(userId)) { - Drawable badge = mDpm.getDrawable( + Drawable badge = mDpm.getResources().getDrawable( getUpdatableUserIconBadgeId(userId), SOLID_COLORED, () -> getDefaultUserIconBadge(userId)); diff --git a/core/java/com/android/internal/app/ChooserMultiProfilePagerAdapter.java b/core/java/com/android/internal/app/ChooserMultiProfilePagerAdapter.java index 393bff483a20..916408984674 100644 --- a/core/java/com/android/internal/app/ChooserMultiProfilePagerAdapter.java +++ b/core/java/com/android/internal/app/ChooserMultiProfilePagerAdapter.java @@ -247,54 +247,54 @@ public class ChooserMultiProfilePagerAdapter extends AbstractMultiProfilePagerAd } private String getWorkAppPausedTitle() { - return getContext().getSystemService(DevicePolicyManager.class).getString( + return getContext().getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_WORK_PAUSED_TITLE, () -> getContext().getString(R.string.resolver_turn_on_work_apps)); } private String getCrossProfileBlockedTitle() { - return getContext().getSystemService(DevicePolicyManager.class).getString( + return getContext().getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_CROSS_PROFILE_BLOCKED_TITLE, () -> getContext().getString(R.string.resolver_cross_profile_blocked)); } private String getCantShareWithWorkMessage() { - return getContext().getSystemService(DevicePolicyManager.class).getString( + return getContext().getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_CANT_SHARE_WITH_WORK, () -> getContext().getString( R.string.resolver_cant_share_with_work_apps_explanation)); } private String getCantShareWithPersonalMessage() { - return getContext().getSystemService(DevicePolicyManager.class).getString( + return getContext().getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_CANT_SHARE_WITH_PERSONAL, () -> getContext().getString( R.string.resolver_cant_share_with_personal_apps_explanation)); } private String getCantAccessWorkMessage() { - return getContext().getSystemService(DevicePolicyManager.class).getString( + return getContext().getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_CANT_ACCESS_WORK, () -> getContext().getString( R.string.resolver_cant_access_work_apps_explanation)); } private String getCantAccessPersonalMessage() { - return getContext().getSystemService(DevicePolicyManager.class).getString( + return getContext().getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_CANT_ACCESS_PERSONAL, () -> getContext().getString( R.string.resolver_cant_access_personal_apps_explanation)); } private String getNoWorkAppsAvailableMessage() { - return getContext().getSystemService(DevicePolicyManager.class).getString( + return getContext().getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_NO_WORK_APPS, () -> getContext().getString( R.string.resolver_no_work_apps_available)); } private String getNoPersonalAppsAvailableMessage() { - return getContext().getSystemService(DevicePolicyManager.class).getString( + return getContext().getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_NO_PERSONAL_APPS, () -> getContext().getString( R.string.resolver_no_personal_apps_available)); diff --git a/core/java/com/android/internal/app/IntentForwarderActivity.java b/core/java/com/android/internal/app/IntentForwarderActivity.java index 25b8dba2870b..6e7690678d21 100644 --- a/core/java/com/android/internal/app/IntentForwarderActivity.java +++ b/core/java/com/android/internal/app/IntentForwarderActivity.java @@ -163,13 +163,13 @@ public class IntentForwarderActivity extends Activity { } private String getForwardToPersonalMessage() { - return getSystemService(DevicePolicyManager.class).getString( + return getSystemService(DevicePolicyManager.class).getResources().getString( FORWARD_INTENT_TO_PERSONAL, () -> getString(com.android.internal.R.string.forward_intent_to_owner)); } private String getForwardToWorkMessage() { - return getSystemService(DevicePolicyManager.class).getString( + return getSystemService(DevicePolicyManager.class).getResources().getString( FORWARD_INTENT_TO_WORK, () -> getString(com.android.internal.R.string.forward_intent_to_work)); } diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index fd5eac8071bd..5ebb148760c6 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -850,13 +850,13 @@ public class ResolverActivity extends Activity implements } private String getForwardToPersonalMsg() { - return getSystemService(DevicePolicyManager.class).getString( + return getSystemService(DevicePolicyManager.class).getResources().getString( FORWARD_INTENT_TO_PERSONAL, () -> getString(com.android.internal.R.string.forward_intent_to_owner)); } private String getForwardToWorkMsg() { - return getSystemService(DevicePolicyManager.class).getString( + return getSystemService(DevicePolicyManager.class).getResources().getString( FORWARD_INTENT_TO_WORK, () -> getString(com.android.internal.R.string.forward_intent_to_work)); } @@ -1150,7 +1150,7 @@ public class ResolverActivity extends Activity implements } private String getWorkProfileNotSupportedMsg(String launcherName) { - return getSystemService(DevicePolicyManager.class).getString( + return getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_WORK_PROFILE_NOT_SUPPORTED, () -> getString( com.android.internal.R.string.activity_resolver_work_profiles_support, @@ -1879,12 +1879,12 @@ public class ResolverActivity extends Activity implements } private String getPersonalTabLabel() { - return getSystemService(DevicePolicyManager.class).getString( + return getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_PERSONAL_TAB, () -> getString(R.string.resolver_personal_tab)); } private String getWorkTabLabel() { - return getSystemService(DevicePolicyManager.class).getString( + return getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_WORK_TAB, () -> getString(R.string.resolver_work_tab)); } @@ -1935,13 +1935,13 @@ public class ResolverActivity extends Activity implements } private String getPersonalTabAccessibilityLabel() { - return getSystemService(DevicePolicyManager.class).getString( + return getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_PERSONAL_TAB_ACCESSIBILITY, () -> getString(R.string.resolver_personal_tab_accessibility)); } private String getWorkTabAccessibilityLabel() { - return getSystemService(DevicePolicyManager.class).getString( + return getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_WORK_TAB_ACCESSIBILITY, () -> getString(R.string.resolver_work_tab_accessibility)); } diff --git a/core/java/com/android/internal/app/ResolverMultiProfilePagerAdapter.java b/core/java/com/android/internal/app/ResolverMultiProfilePagerAdapter.java index 4da59a3e77d9..f4e568b6676a 100644 --- a/core/java/com/android/internal/app/ResolverMultiProfilePagerAdapter.java +++ b/core/java/com/android/internal/app/ResolverMultiProfilePagerAdapter.java @@ -242,40 +242,40 @@ public class ResolverMultiProfilePagerAdapter extends AbstractMultiProfilePagerA } private String getWorkAppPausedTitle() { - return getContext().getSystemService(DevicePolicyManager.class).getString( + return getContext().getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_WORK_PAUSED_TITLE, () -> getContext().getString(R.string.resolver_turn_on_work_apps)); } private String getCrossProfileBlockedTitle() { - return getContext().getSystemService(DevicePolicyManager.class).getString( + return getContext().getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_CROSS_PROFILE_BLOCKED_TITLE, () -> getContext().getString(R.string.resolver_cross_profile_blocked)); } private String getCantAccessWorkMessage() { - return getContext().getSystemService(DevicePolicyManager.class).getString( + return getContext().getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_CANT_ACCESS_WORK, () -> getContext().getString( R.string.resolver_cant_access_work_apps_explanation)); } private String getCantAccessPersonalMessage() { - return getContext().getSystemService(DevicePolicyManager.class).getString( + return getContext().getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_CANT_ACCESS_PERSONAL, () -> getContext().getString( R.string.resolver_cant_access_personal_apps_explanation)); } private String getNoWorkAppsAvailableMessage() { - return getContext().getSystemService(DevicePolicyManager.class).getString( + return getContext().getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_NO_WORK_APPS, () -> getContext().getString( R.string.resolver_no_work_apps_available)); } private String getNoPersonalAppsAvailableMessage() { - return getContext().getSystemService(DevicePolicyManager.class).getString( + return getContext().getSystemService(DevicePolicyManager.class).getResources().getString( RESOLVER_NO_PERSONAL_APPS, () -> getContext().getString( R.string.resolver_no_personal_apps_available)); diff --git a/core/java/com/android/internal/app/UnlaunchableAppActivity.java b/core/java/com/android/internal/app/UnlaunchableAppActivity.java index 3531fad353db..957a6365739d 100644 --- a/core/java/com/android/internal/app/UnlaunchableAppActivity.java +++ b/core/java/com/android/internal/app/UnlaunchableAppActivity.java @@ -95,12 +95,12 @@ public class UnlaunchableAppActivity extends Activity } private String getDialogTitle() { - return getSystemService(DevicePolicyManager.class).getString( + return getSystemService(DevicePolicyManager.class).getResources().getString( UNLAUNCHABLE_APP_WORK_PAUSED_TITLE, () -> getString(R.string.work_mode_off_title)); } private String getDialogMessage() { - return getSystemService(DevicePolicyManager.class).getString( + return getSystemService(DevicePolicyManager.class).getResources().getString( UNLAUNCHABLE_APP_WORK_PAUSED_MESSAGE, () -> getString(R.string.work_mode_off_message)); } diff --git a/core/java/com/android/internal/notification/SystemNotificationChannels.java b/core/java/com/android/internal/notification/SystemNotificationChannels.java index b79c0bed4564..a93c487db7d7 100644 --- a/core/java/com/android/internal/notification/SystemNotificationChannels.java +++ b/core/java/com/android/internal/notification/SystemNotificationChannels.java @@ -221,7 +221,7 @@ public class SystemNotificationChannels { private static String getDeviceAdminNotificationChannelName(Context context) { DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class); - return dpm.getString(NOTIFICATION_CHANNEL_DEVICE_ADMIN, + return dpm.getResources().getString(NOTIFICATION_CHANNEL_DEVICE_ADMIN, () -> context.getString(R.string.notification_channel_device_admin)); } |
