From 81709c37b83445e12c79e7d8fe16c34a0d73ebe5 Mon Sep 17 00:00:00 2001 From: kholoud mohamed Date: Fri, 11 Mar 2022 14:52:03 +0000 Subject: [PATCH 1/2] RESTRICT AUTOMERGE hide device policy resources constants Bug: 218875965 Bug: 217388602 Test: atest EnterpriseResourcesTests Change-Id: Iac71c0d5b451e8ec77c0ca0113e2248ef21cc412 --- core/api/current.txt | 24 - core/api/system-current.txt | 37 - .../admin/DevicePolicyDrawableResource.java | 28 +- .../app/admin/DevicePolicyManager.java | 130 +- .../app/admin/DevicePolicyResources.java | 1247 +---------------- .../app/admin/DevicePolicyStringResource.java | 7 +- .../DeviceManagementResourcesProvider.java | 41 +- 7 files changed, 100 insertions(+), 1414 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index 98bb6d78857d2..5f6848c116518 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -7839,31 +7839,7 @@ package android.app.admin { } public final class DevicePolicyResources { - } - - public static final class DevicePolicyResources.Drawables { field public static final String UNDEFINED = "UNDEFINED"; - field public static final String WORK_PROFILE_ICON = "WORK_PROFILE_ICON"; - field public static final String WORK_PROFILE_ICON_BADGE = "WORK_PROFILE_ICON_BADGE"; - field public static final String WORK_PROFILE_OFF_ICON = "WORK_PROFILE_OFF_ICON"; - field public static final String WORK_PROFILE_USER_ICON = "WORK_PROFILE_USER_ICON"; - } - - public static final class DevicePolicyResources.Drawables.Source { - field public static final String HOME_WIDGET = "HOME_WIDGET"; - field public static final String LAUNCHER_OFF_BUTTON = "LAUNCHER_OFF_BUTTON"; - field public static final String NOTIFICATION = "NOTIFICATION"; - field public static final String PROFILE_SWITCH_ANIMATION = "PROFILE_SWITCH_ANIMATION"; - field public static final String QUICK_SETTINGS = "QUICK_SETTINGS"; - field public static final String STATUS_BAR = "STATUS_BAR"; - field public static final String UNDEFINED = "UNDEFINED"; - } - - public static final class DevicePolicyResources.Drawables.Style { - field public static final String DEFAULT = "DEFAULT"; - field public static final String OUTLINE = "OUTLINE"; - field public static final String SOLID_COLORED = "SOLID_COLORED"; - field public static final String SOLID_NOT_COLORED = "SOLID_NOT_COLORED"; } public final class DnsEvent extends android.app.admin.NetworkEvent implements android.os.Parcelable { diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 66bd6b3780855..b9e9fbb3e8ead 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -1198,43 +1198,6 @@ package android.app.admin { } public static final class DevicePolicyResources.Strings { - field public static final String UNDEFINED = "UNDEFINED"; - } - - public static final class DevicePolicyResources.Strings.Dialer { - field public static final String NOTIFICATION_INCOMING_WORK_CALL_TITLE = "Dialer.NOTIFICATION_INCOMING_WORK_CALL_TITLE"; - field public static final String NOTIFICATION_MISSED_WORK_CALL_TITLE = "Dialer.NOTIFICATION_MISSED_WORK_CALL_TITLE"; - field public static final String NOTIFICATION_ONGOING_WORK_CALL_TITLE = "Dialer.NOTIFICATION_ONGOING_WORK_CALL_TITLE"; - field public static final String NOTIFICATION_WIFI_WORK_CALL_LABEL = "Dialer.NOTIFICATION_WIFI_WORK_CALL_LABEL"; - } - - public static final class DevicePolicyResources.Strings.DocumentsUi { - field public static final String CANT_SAVE_TO_PERSONAL_MESSAGE = "DocumentsUi.CANT_SAVE_TO_PERSONAL_MESSAGE"; - field public static final String CANT_SAVE_TO_PERSONAL_TITLE = "DocumentsUi.CANT_SAVE_TO_PERSONAL_TITLE"; - field public static final String CANT_SAVE_TO_WORK_MESSAGE = "DocumentsUi.CANT_SAVE_TO_WORK_MESSAGE"; - field public static final String CANT_SAVE_TO_WORK_TITLE = "DocumentsUi.CANT_SAVE_TO_WORK_TITLE"; - field public static final String CANT_SELECT_PERSONAL_FILES_MESSAGE = "DocumentsUi.CANT_SELECT_PERSONAL_FILES_MESSAGE"; - field public static final String CANT_SELECT_PERSONAL_FILES_TITLE = "DocumentsUi.CANT_SELECT_PERSONAL_FILES_TITLE"; - field public static final String CANT_SELECT_WORK_FILES_MESSAGE = "DocumentsUi.CANT_SELECT_WORK_FILES_MESSAGE"; - field public static final String CANT_SELECT_WORK_FILES_TITLE = "DocumentsUi.CANT_SELECT_WORK_FILES_TITLE"; - field public static final String CROSS_PROFILE_NOT_ALLOWED_MESSAGE = "DocumentsUi.CROSS_PROFILE_NOT_ALLOWED_MESSAGE"; - field public static final String CROSS_PROFILE_NOT_ALLOWED_TITLE = "DocumentsUi.CROSS_PROFILE_NOT_ALLOWED_TITLE"; - field public static final String PERSONAL_TAB = "DocumentsUi.PERSONAL_TAB"; - field public static final String PREVIEW_WORK_FILE_ACCESSIBILITY = "DocumentsUi.PREVIEW_WORK_FILE_ACCESSIBILITY"; - field public static final String WORK_ACCESSIBILITY = "DocumentsUi.WORK_ACCESSIBILITY"; - field public static final String WORK_PROFILE_OFF_ENABLE_BUTTON = "DocumentsUi.WORK_PROFILE_OFF_ENABLE_BUTTON"; - field public static final String WORK_PROFILE_OFF_ERROR_TITLE = "DocumentsUi.WORK_PROFILE_OFF_ERROR_TITLE"; - field public static final String WORK_TAB = "DocumentsUi.WORK_TAB"; - } - - public static final class DevicePolicyResources.Strings.MediaProvider { - field public static final String BLOCKED_BY_ADMIN_TITLE = "MediaProvider.BLOCKED_BY_ADMIN_TITLE"; - field public static final String BLOCKED_FROM_PERSONAL_MESSAGE = "MediaProvider.BLOCKED_FROM_PERSONAL_MESSAGE"; - field public static final String BLOCKED_FROM_WORK_MESSAGE = "MediaProvider.BLOCKED_FROM_WORK_MESSAGE"; - field public static final String SWITCH_TO_PERSONAL_MESSAGE = "MediaProvider.SWITCH_TO_PERSONAL_MESSAGE"; - field public static final String SWITCH_TO_WORK_MESSAGE = "MediaProvider.SWITCH_TO_WORK_MESSAGE"; - field public static final String WORK_PROFILE_PAUSED_MESSAGE = "MediaProvider.WORK_PROFILE_PAUSED_MESSAGE"; - field public static final String WORK_PROFILE_PAUSED_TITLE = "MediaProvider.WORK_PROFILE_PAUSED_TITLE"; } public static final class DevicePolicyResources.Strings.PermissionController { diff --git a/core/java/android/app/admin/DevicePolicyDrawableResource.java b/core/java/android/app/admin/DevicePolicyDrawableResource.java index 7fd8e896bac23..1d7aab9ef7d1e 100644 --- a/core/java/android/app/admin/DevicePolicyDrawableResource.java +++ b/core/java/android/app/admin/DevicePolicyDrawableResource.java @@ -20,7 +20,6 @@ import android.annotation.DrawableRes; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; -import android.app.admin.DevicePolicyResources.Drawables; import android.content.Context; import android.os.Parcel; import android.os.Parcelable; @@ -35,9 +34,9 @@ import java.util.Objects; */ @SystemApi public final class DevicePolicyDrawableResource implements Parcelable { - @NonNull private final @DevicePolicyResources.UpdatableDrawableId String mDrawableId; - @NonNull private final @DevicePolicyResources.UpdatableDrawableStyle String mDrawableStyle; - @NonNull private final @DevicePolicyResources.UpdatableDrawableSource String mDrawableSource; + @NonNull private final String mDrawableId; + @NonNull private final String mDrawableStyle; + @NonNull private final String mDrawableSource; private final @DrawableRes int mResourceIdInCallingPackage; @NonNull private ParcelableResource mResource; @@ -60,9 +59,9 @@ public final class DevicePolicyDrawableResource implements Parcelable { */ public DevicePolicyDrawableResource( @NonNull Context context, - @NonNull @DevicePolicyResources.UpdatableDrawableId String drawableId, - @NonNull @DevicePolicyResources.UpdatableDrawableStyle String drawableStyle, - @NonNull @DevicePolicyResources.UpdatableDrawableSource String drawableSource, + @NonNull String drawableId, + @NonNull String drawableStyle, + @NonNull String drawableSource, @DrawableRes int resourceIdInCallingPackage) { this(drawableId, drawableStyle, drawableSource, resourceIdInCallingPackage, new ParcelableResource(context, resourceIdInCallingPackage, @@ -70,9 +69,9 @@ public final class DevicePolicyDrawableResource implements Parcelable { } private DevicePolicyDrawableResource( - @NonNull @DevicePolicyResources.UpdatableDrawableId String drawableId, - @NonNull @DevicePolicyResources.UpdatableDrawableStyle String drawableStyle, - @NonNull @DevicePolicyResources.UpdatableDrawableSource String drawableSource, + @NonNull String drawableId, + @NonNull String drawableStyle, + @NonNull String drawableSource, @DrawableRes int resourceIdInCallingPackage, @NonNull ParcelableResource resource) { @@ -105,10 +104,10 @@ public final class DevicePolicyDrawableResource implements Parcelable { */ public DevicePolicyDrawableResource( @NonNull Context context, - @NonNull @DevicePolicyResources.UpdatableDrawableId String drawableId, - @NonNull @DevicePolicyResources.UpdatableDrawableStyle String drawableStyle, + @NonNull String drawableId, + @NonNull String drawableStyle, @DrawableRes int resourceIdInCallingPackage) { - this(context, drawableId, drawableStyle, Drawables.Source.UNDEFINED, + this(context, drawableId, drawableStyle, DevicePolicyResources.UNDEFINED, resourceIdInCallingPackage); } @@ -116,7 +115,6 @@ public final class DevicePolicyDrawableResource implements Parcelable { * Returns the ID of the drawable to update. */ @NonNull - @DevicePolicyResources.UpdatableDrawableId public String getDrawableId() { return mDrawableId; } @@ -125,7 +123,6 @@ public final class DevicePolicyDrawableResource implements Parcelable { * Returns the style of the drawable to update */ @NonNull - @DevicePolicyResources.UpdatableDrawableStyle public String getDrawableStyle() { return mDrawableStyle; } @@ -134,7 +131,6 @@ public final class DevicePolicyDrawableResource implements Parcelable { * Returns the source of the drawable to update. */ @NonNull - @DevicePolicyResources.UpdatableDrawableSource public String getDrawableSource() { return mDrawableSource; } diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index b3db93b440160..d8f20cf8146d6 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -15304,19 +15304,16 @@ public class DevicePolicyManager { /** * For each {@link DevicePolicyDrawableResource} item in {@code drawables}, if - * {@link DevicePolicyDrawableResource#getDrawableSource()} is not set or is set to - * {@link DevicePolicyResources.Drawables.Source#UNDEFINED}, it updates the drawable resource for - * the combination of {@link DevicePolicyDrawableResource#getDrawableId()} and - * {@link DevicePolicyDrawableResource#getDrawableStyle()}, (see - * {@link DevicePolicyResources.Drawables} and {@link DevicePolicyResources.Drawables.Style}) to - * the drawable with ID {@link DevicePolicyDrawableResource#getResourceIdInCallingPackage()}, - * meaning any system UI surface calling {@link #getDrawable} - * with {@code drawableId} and {@code drawableStyle} will get the new resource after this API - * is called. + * {@link DevicePolicyDrawableResource#getDrawableSource()} is not set, it updates the drawable + * resource for the combination of {@link DevicePolicyDrawableResource#getDrawableId()} and + * {@link DevicePolicyDrawableResource#getDrawableStyle()} to the drawable with resource ID + * {@link DevicePolicyDrawableResource#getResourceIdInCallingPackage()}, + * meaning any system UI surface calling {@link #getDrawable} with {@code drawableId} and + * {@code drawableStyle} will get the new resource after this API is called. * - *

Otherwise, if {@link DevicePolicyDrawableResource#getDrawableSource()} is set (see - * {@link DevicePolicyResources.Drawables.Source}, it overrides any drawables that was set for - * the same {@code drawableId} and {@code drawableStyle} for the provided source. + *

Otherwise, if {@link DevicePolicyDrawableResource#getDrawableSource()} is set, it + * overrides any drawables that was set for the same {@code drawableId} and + * {@code drawableStyle} for the provided source. * *

Sends a broadcast with action {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to * registered receivers when a resource has been updated successfully. @@ -15350,12 +15347,10 @@ public class DevicePolicyManager { } /** - * Removes all updated drawables for the list of {@code drawableIds} (see - * {@link DevicePolicyResources.Drawables} that was previously set by calling - * {@link #setDrawables}, meaning any subsequent calls to {@link #getDrawable} for the provided - * IDs with any {@link DevicePolicyResources.Drawables.Style} and any - * {@link DevicePolicyResources.Drawables.Source} will return the default drawable from - * {@code defaultDrawableLoader}. + * Removes all updated drawables for the list of {@code drawableIds} that was previously set by + * calling {@link #setDrawables}, meaning any subsequent calls to {@link #getDrawable} for the + * provided IDs with any {@code drawableStyle} and any {@code drawableSource} will return the + * default drawable from {@code defaultDrawableLoader}. * *

Sends a broadcast with action {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to * registered receivers when a resource has been reset successfully. @@ -15377,13 +15372,12 @@ public class DevicePolicyManager { } /** - * Returns the appropriate updated drawable for the {@code drawableId} - * (see {@link DevicePolicyResources.Drawables}), with style {@code drawableStyle} - * (see {@link DevicePolicyResources.Drawables.Style}) if one was set using - * {@code setDrawables}, otherwise returns the drawable from {@code defaultDrawableLoader}. + * Returns the appropriate updated drawable for the {@code drawableId} with style + * {@code drawableStyle} if one was set using {@code setDrawables}, otherwise returns the + * drawable from {@code defaultDrawableLoader}. * - *

Also returns the drawable from {@code defaultDrawableLoader} if - * {@link DevicePolicyResources.Drawables#UNDEFINED} was passed. + *

Also returns the drawable from {@code defaultDrawableLoader} if {@code drawableId} + * is {@link DevicePolicyResources#UNDEFINED}. * *

Calls to this API will not return {@code null} unless no updated drawable was found * and the call to {@code defaultDrawableLoader} returned {@code null}. @@ -15405,19 +15399,22 @@ public class DevicePolicyManager { */ @Nullable public Drawable getDrawable( - @NonNull @DevicePolicyResources.UpdatableDrawableId String drawableId, - @NonNull @DevicePolicyResources.UpdatableDrawableStyle String drawableStyle, + @NonNull String drawableId, + @NonNull String drawableStyle, @NonNull Supplier defaultDrawableLoader) { return getDrawable( - drawableId, drawableStyle, Drawables.Source.UNDEFINED, defaultDrawableLoader); + drawableId, drawableStyle, DevicePolicyResources.UNDEFINED, defaultDrawableLoader); } /** * Similar to {@link #getDrawable(String, String, Supplier)}, but also accepts - * a {@code drawableSource} (see {@link DevicePolicyResources.Drawables.Source}) which - * could result in returning a different drawable than - * {@link #getDrawable(String, String, Supplier)} - * if an override was set for that specific source. + * a {@code drawableSource} which could result in returning a different drawable than + * {@link #getDrawable(String, String, Supplier)} if an override was set for that specific + * source. + * + *

If {@code drawableSource} is {@link DevicePolicyResources#UNDEFINED}, it returns the + * appropriate string for {@code drawableId} and {@code drawableStyle} similar to + * {@link #getDrawable(String, String, Supplier)}. * *

Calls to this API will not return {@code null} unless no updated drawable was found * and the call to {@code defaultDrawableLoader} returned {@code null}. @@ -15433,9 +15430,9 @@ public class DevicePolicyManager { */ @Nullable public Drawable getDrawable( - @NonNull @DevicePolicyResources.UpdatableDrawableId String drawableId, - @NonNull @DevicePolicyResources.UpdatableDrawableStyle String drawableStyle, - @NonNull @DevicePolicyResources.UpdatableDrawableSource String drawableSource, + @NonNull String drawableId, + @NonNull String drawableStyle, + @NonNull String drawableSource, @NonNull Supplier defaultDrawableLoader) { Objects.requireNonNull(drawableId, "drawableId can't be null"); @@ -15443,7 +15440,7 @@ public class DevicePolicyManager { Objects.requireNonNull(drawableSource, "drawableSource can't be null"); Objects.requireNonNull(defaultDrawableLoader, "defaultDrawableLoader can't be null"); - if (Drawables.UNDEFINED.equals(drawableId)) { + if (drawableId.equals(DevicePolicyResources.UNDEFINED)) { return ParcelableResource.loadDefaultDrawable(defaultDrawableLoader); } if (mService != null) { @@ -15490,14 +15487,14 @@ public class DevicePolicyManager { */ @Nullable public Drawable getDrawableForDensity( - @NonNull @DevicePolicyResources.UpdatableDrawableId String drawableId, - @NonNull @DevicePolicyResources.UpdatableDrawableStyle String drawableStyle, + @NonNull String drawableId, + @NonNull String drawableStyle, int density, @NonNull Supplier defaultDrawableLoader) { return getDrawableForDensity( drawableId, drawableStyle, - Drawables.Source.UNDEFINED, + DevicePolicyResources.UNDEFINED, density, defaultDrawableLoader); } @@ -15506,8 +15503,8 @@ public class DevicePolicyManager { * Similar to {@link #getDrawable(String, String, String, Supplier)}, but also accepts * {@code density}. See {@link Resources#getDrawableForDensity(int, int, Resources.Theme)}. * - *

Calls to this API will not return {@code null} unless no updated drawable was found - * and the call to {@code defaultDrawableLoader} returned {@code null}. + *

Calls to this API will not return {@code null} unless no updated drawable was found + * and the call to {@code defaultDrawableLoader} returned {@code null}. * *

Callers should register for {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to get * notified when a resource has been updated. @@ -15523,9 +15520,9 @@ public class DevicePolicyManager { */ @Nullable public Drawable getDrawableForDensity( - @NonNull @DevicePolicyResources.UpdatableDrawableId String drawableId, - @NonNull @DevicePolicyResources.UpdatableDrawableStyle String drawableStyle, - @NonNull @DevicePolicyResources.UpdatableDrawableSource String drawableSource, + @NonNull String drawableId, + @NonNull String drawableStyle, + @NonNull String drawableSource, int density, @NonNull Supplier defaultDrawableLoader) { @@ -15534,7 +15531,7 @@ public class DevicePolicyManager { Objects.requireNonNull(drawableSource, "drawableSource can't be null"); Objects.requireNonNull(defaultDrawableLoader, "defaultDrawableLoader can't be null"); - if (Drawables.UNDEFINED.equals(drawableId)) { + if (drawableId.equals(DevicePolicyResources.UNDEFINED)) { return ParcelableResource.loadDefaultDrawable(defaultDrawableLoader); } if (mService != null) { @@ -15568,16 +15565,16 @@ public class DevicePolicyManager { */ @Nullable public Icon getDrawableAsIcon( - @NonNull @DevicePolicyResources.UpdatableDrawableId String drawableId, - @NonNull @DevicePolicyResources.UpdatableDrawableStyle String drawableStyle, - @NonNull @DevicePolicyResources.UpdatableDrawableSource String drawableSource, + @NonNull String drawableId, + @NonNull String drawableStyle, + @NonNull String drawableSource, @Nullable Icon defaultIcon) { Objects.requireNonNull(drawableId, "drawableId can't be null"); Objects.requireNonNull(drawableStyle, "drawableStyle can't be null"); Objects.requireNonNull(drawableSource, "drawableSource can't be null"); Objects.requireNonNull(defaultIcon, "defaultIcon can't be null"); - if (Drawables.UNDEFINED.equals(drawableId)) { + if (drawableId.equals(DevicePolicyResources.UNDEFINED)) { return defaultIcon; } if (mService != null) { @@ -15609,30 +15606,28 @@ public class DevicePolicyManager { */ @Nullable public Icon getDrawableAsIcon( - @NonNull @DevicePolicyResources.UpdatableDrawableId String drawableId, - @NonNull @DevicePolicyResources.UpdatableDrawableStyle String drawableStyle, + @NonNull String drawableId, + @NonNull String drawableStyle, @Nullable Icon defaultIcon) { return getDrawableAsIcon( - drawableId, drawableStyle, Drawables.Source.UNDEFINED, defaultIcon); + drawableId, drawableStyle, DevicePolicyResources.UNDEFINED, defaultIcon); } /** * For each {@link DevicePolicyStringResource} item in {@code strings}, it updates the string * resource for {@link DevicePolicyStringResource#getStringId()} to the string with ID - * {@code callingPackageResourceId} (see {@link DevicePolicyResources.Strings}), meaning any - * system UI surface calling {@link #getString} with {@code stringId} will get - * the new resource after this API is called. + * {@code callingPackageResourceId}, meaning any system UI surface calling {@link #getString} + * with {@code stringId} will get the new resource after this API is called. * *

Sends a broadcast with action {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to * registered receivers when a resource has been updated successfully. * *

Important notes to consider when using this API: *