Merge changes from topic "cherrypicker-L96900000953714853:N25700001248135378"
* changes: RESTRICT AUTOMERGE move device policy resource APIs to a separate class RESTRICT AUTOMERGE hide device policy resources constants
This commit is contained in:
committed by
Android (Google) Code Review
commit
2ca56df0db
@@ -7418,12 +7418,6 @@ package android.app.admin {
|
||||
method @NonNull public java.util.List<java.lang.String> getDelegatedScopes(@Nullable android.content.ComponentName, @NonNull String);
|
||||
method public CharSequence getDeviceOwnerLockScreenInfo();
|
||||
method @Nullable public String getDevicePolicyManagementRoleHolderPackage();
|
||||
method @Nullable public android.graphics.drawable.Drawable getDrawable(@NonNull String, @NonNull String, @NonNull java.util.function.Supplier<android.graphics.drawable.Drawable>);
|
||||
method @Nullable public android.graphics.drawable.Drawable getDrawable(@NonNull String, @NonNull String, @NonNull String, @NonNull java.util.function.Supplier<android.graphics.drawable.Drawable>);
|
||||
method @Nullable public android.graphics.drawable.Icon getDrawableAsIcon(@NonNull String, @NonNull String, @NonNull String, @Nullable android.graphics.drawable.Icon);
|
||||
method @Nullable public android.graphics.drawable.Icon getDrawableAsIcon(@NonNull String, @NonNull String, @Nullable android.graphics.drawable.Icon);
|
||||
method @Nullable public android.graphics.drawable.Drawable getDrawableForDensity(@NonNull String, @NonNull String, int, @NonNull java.util.function.Supplier<android.graphics.drawable.Drawable>);
|
||||
method @Nullable public android.graphics.drawable.Drawable getDrawableForDensity(@NonNull String, @NonNull String, @NonNull String, int, @NonNull java.util.function.Supplier<android.graphics.drawable.Drawable>);
|
||||
method public CharSequence getEndUserSessionMessage(@NonNull android.content.ComponentName);
|
||||
method @NonNull public String getEnrollmentSpecificId();
|
||||
method @Nullable public android.app.admin.FactoryResetProtectionPolicy getFactoryResetProtectionPolicy(@Nullable android.content.ComponentName);
|
||||
@@ -7470,14 +7464,13 @@ package android.app.admin {
|
||||
method @NonNull public java.util.List<android.app.admin.PreferentialNetworkServiceConfig> getPreferentialNetworkServiceConfigs();
|
||||
method public int getRequiredPasswordComplexity();
|
||||
method public long getRequiredStrongAuthTimeout(@Nullable android.content.ComponentName);
|
||||
method @NonNull public android.app.admin.DevicePolicyResourcesManager getResources();
|
||||
method public boolean getScreenCaptureDisabled(@Nullable android.content.ComponentName);
|
||||
method public java.util.List<android.os.UserHandle> getSecondaryUsers(@NonNull android.content.ComponentName);
|
||||
method public CharSequence getShortSupportMessage(@NonNull android.content.ComponentName);
|
||||
method public CharSequence getStartUserSessionMessage(@NonNull android.content.ComponentName);
|
||||
method @Deprecated public boolean getStorageEncryption(@Nullable android.content.ComponentName);
|
||||
method public int getStorageEncryptionStatus();
|
||||
method @Nullable public String getString(@NonNull String, @NonNull java.util.function.Supplier<java.lang.String>);
|
||||
method @Nullable public String getString(@NonNull String, @NonNull java.util.function.Supplier<java.lang.String>, @NonNull java.lang.Object...);
|
||||
method @Nullable public android.app.admin.SystemUpdatePolicy getSystemUpdatePolicy();
|
||||
method @Nullable public android.os.PersistableBundle getTransferOwnershipBundle();
|
||||
method @Nullable public java.util.List<android.os.PersistableBundle> getTrustAgentConfiguration(@Nullable android.content.ComponentName, @NonNull android.content.ComponentName);
|
||||
@@ -7839,31 +7832,18 @@ 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 class DevicePolicyResourcesManager {
|
||||
method @Nullable public android.graphics.drawable.Drawable getDrawable(@NonNull String, @NonNull String, @NonNull java.util.function.Supplier<android.graphics.drawable.Drawable>);
|
||||
method @Nullable public android.graphics.drawable.Drawable getDrawable(@NonNull String, @NonNull String, @NonNull String, @NonNull java.util.function.Supplier<android.graphics.drawable.Drawable>);
|
||||
method @Nullable public android.graphics.drawable.Icon getDrawableAsIcon(@NonNull String, @NonNull String, @NonNull String, @Nullable android.graphics.drawable.Icon);
|
||||
method @Nullable public android.graphics.drawable.Icon getDrawableAsIcon(@NonNull String, @NonNull String, @Nullable android.graphics.drawable.Icon);
|
||||
method @Nullable public android.graphics.drawable.Drawable getDrawableForDensity(@NonNull String, @NonNull String, int, @NonNull java.util.function.Supplier<android.graphics.drawable.Drawable>);
|
||||
method @Nullable public android.graphics.drawable.Drawable getDrawableForDensity(@NonNull String, @NonNull String, @NonNull String, int, @NonNull java.util.function.Supplier<android.graphics.drawable.Drawable>);
|
||||
method @Nullable public String getString(@NonNull String, @NonNull java.util.function.Supplier<java.lang.String>);
|
||||
method @Nullable public String getString(@NonNull String, @NonNull java.util.function.Supplier<java.lang.String>, @NonNull java.lang.Object...);
|
||||
}
|
||||
|
||||
public final class DnsEvent extends android.app.admin.NetworkEvent implements android.os.Parcelable {
|
||||
|
||||
@@ -1109,16 +1109,12 @@ package android.app.admin {
|
||||
method @RequiresPermission("android.permission.NOTIFY_PENDING_SYSTEM_UPDATE") public void notifyPendingSystemUpdate(long, boolean);
|
||||
method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) public boolean packageHasActiveAdmins(String);
|
||||
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS, android.Manifest.permission.PROVISION_DEMO_DEVICE}) public void provisionFullyManagedDevice(@NonNull android.app.admin.FullyManagedDeviceProvisioningParams) throws android.app.admin.ProvisioningException;
|
||||
method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES) public void resetDrawables(@NonNull java.util.Set<java.lang.String>);
|
||||
method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES) public void resetStrings(@NonNull java.util.Set<java.lang.String>);
|
||||
method @RequiresPermission(android.Manifest.permission.TRIGGER_LOST_MODE) public void sendLostModeLocationUpdate(@NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Boolean>);
|
||||
method @Deprecated @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS) public boolean setActiveProfileOwner(@NonNull android.content.ComponentName, String) throws java.lang.IllegalArgumentException;
|
||||
method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public void setDeviceProvisioningConfigApplied();
|
||||
method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public void setDpcDownloaded(boolean);
|
||||
method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES) public void setDrawables(@NonNull java.util.Set<android.app.admin.DevicePolicyDrawableResource>);
|
||||
method @Deprecated @RequiresPermission(value=android.Manifest.permission.GRANT_PROFILE_OWNER_DEVICE_IDS_ACCESS, conditional=true) public void setProfileOwnerCanAccessDeviceIds(@NonNull android.content.ComponentName);
|
||||
method public void setSecondaryLockscreenEnabled(@NonNull android.content.ComponentName, boolean);
|
||||
method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES) public void setStrings(@NonNull java.util.Set<android.app.admin.DevicePolicyStringResource>);
|
||||
method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public void setUserProvisioningState(int, @NonNull android.os.UserHandle);
|
||||
method @RequiresPermission(android.Manifest.permission.MANAGE_ROLE_HOLDERS) public boolean shouldAllowBypassingDevicePolicyManagementRoleQualification();
|
||||
field public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED = "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
|
||||
@@ -1198,43 +1194,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 {
|
||||
@@ -1246,6 +1205,13 @@ package android.app.admin {
|
||||
field public static final String WORK_PROFILE_DEFAULT_APPS_TITLE = "PermissionController.WORK_PROFILE_DEFAULT_APPS_TITLE";
|
||||
}
|
||||
|
||||
public class DevicePolicyResourcesManager {
|
||||
method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES) public void resetDrawables(@NonNull java.util.Set<java.lang.String>);
|
||||
method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES) public void resetStrings(@NonNull java.util.Set<java.lang.String>);
|
||||
method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES) public void setDrawables(@NonNull java.util.Set<android.app.admin.DevicePolicyDrawableResource>);
|
||||
method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES) public void setStrings(@NonNull java.util.Set<android.app.admin.DevicePolicyStringResource>);
|
||||
}
|
||||
|
||||
public final class DevicePolicyStringResource implements android.os.Parcelable {
|
||||
ctor public DevicePolicyStringResource(@NonNull android.content.Context, @NonNull String, @StringRes int);
|
||||
method public int describeContents();
|
||||
|
||||
@@ -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;
|
||||
@@ -29,21 +28,21 @@ import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Used to pass in the required information for updating an enterprise drawable resource using
|
||||
* {@link DevicePolicyManager#setDrawables}.
|
||||
* {@link DevicePolicyResourcesManager#setDrawables}.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@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;
|
||||
|
||||
/**
|
||||
* Creates an object containing the required information for updating an enterprise drawable
|
||||
* resource using {@link DevicePolicyManager#setDrawables}.
|
||||
* resource using {@link DevicePolicyResourcesManager#setDrawables}.
|
||||
*
|
||||
* <p>It will be used to update the drawable defined by {@code drawableId} with style
|
||||
* {@code drawableStyle} located in source {@code drawableSource} to the drawable with ID
|
||||
@@ -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) {
|
||||
|
||||
@@ -90,7 +89,7 @@ public final class DevicePolicyDrawableResource implements Parcelable {
|
||||
|
||||
/**
|
||||
* Creates an object containing the required information for updating an enterprise drawable
|
||||
* resource using {@link DevicePolicyManager#setDrawables}.
|
||||
* resource using {@link DevicePolicyResourcesManager#setDrawables}.
|
||||
* <p>It will be used to update the drawable defined by {@code drawableId} with style
|
||||
* {@code drawableStyle} to the drawable with ID {@code resourceIdInCallingPackage} in the
|
||||
* calling package</p>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -167,6 +167,7 @@ public class DevicePolicyManager {
|
||||
private final Context mContext;
|
||||
private final IDevicePolicyManager mService;
|
||||
private final boolean mParentInstance;
|
||||
private final DevicePolicyResourcesManager mResourcesManager;
|
||||
|
||||
/** @hide */
|
||||
public DevicePolicyManager(Context context, IDevicePolicyManager service) {
|
||||
@@ -180,6 +181,7 @@ public class DevicePolicyManager {
|
||||
mContext = context;
|
||||
mService = service;
|
||||
mParentInstance = parentInstance;
|
||||
mResourcesManager = new DevicePolicyResourcesManager(context, service);
|
||||
}
|
||||
|
||||
/** @hide test will override it. */
|
||||
@@ -3739,7 +3741,8 @@ public class DevicePolicyManager {
|
||||
/**
|
||||
* Broadcast action: notify system apps (e.g. settings, SysUI, etc) that the device management
|
||||
* resources with IDs {@link #EXTRA_RESOURCE_IDS} has been updated, the updated resources can be
|
||||
* retrieved using {@link #getDrawable} and {@code #getString}.
|
||||
* retrieved using {@link DevicePolicyResourcesManager#getDrawable} and
|
||||
* {@link DevicePolicyResourcesManager#getString}.
|
||||
*
|
||||
* <p>This broadcast is sent to registered receivers only.
|
||||
*
|
||||
@@ -15265,475 +15268,12 @@ 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.
|
||||
*
|
||||
* <p>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.
|
||||
*
|
||||
* <p>Sends a broadcast with action {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to
|
||||
* registered receivers when a resource has been updated successfully.
|
||||
*
|
||||
* <p>Important notes to consider when using this API:
|
||||
* <ul>
|
||||
* <li>{@link #getDrawable} references the resource
|
||||
* {@link DevicePolicyDrawableResource#getResourceIdInCallingPackage()} in the
|
||||
* calling package each time it gets called. You have to ensure that the resource is always
|
||||
* available in the calling package as long as it is used as an updated resource.
|
||||
* <li>You still have to re-call {@code setDrawables} even if you only make changes to the
|
||||
* content of the resource with ID
|
||||
* {@link DevicePolicyDrawableResource#getResourceIdInCallingPackage()} as the content might be
|
||||
* cached and would need updating.
|
||||
* </ul>
|
||||
*
|
||||
* @param drawables The list of {@link DevicePolicyDrawableResource} to update.
|
||||
*
|
||||
* @hide
|
||||
* Returns a {@link DevicePolicyResourcesManager} containing the required APIs to set, reset,
|
||||
* and get device policy related resources.
|
||||
*/
|
||||
@SystemApi
|
||||
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES)
|
||||
public void setDrawables(@NonNull Set<DevicePolicyDrawableResource> drawables) {
|
||||
if (mService != null) {
|
||||
try {
|
||||
mService.setDrawables(new ArrayList<>(drawables));
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}.
|
||||
*
|
||||
* <p>Sends a broadcast with action {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to
|
||||
* registered receivers when a resource has been reset successfully.
|
||||
*
|
||||
* @param drawableIds The list of IDs to remove.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES)
|
||||
public void resetDrawables(@NonNull Set<String> drawableIds) {
|
||||
if (mService != null) {
|
||||
try {
|
||||
mService.resetDrawables(new ArrayList<>(drawableIds));
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}.
|
||||
*
|
||||
* <p>Also returns the drawable from {@code defaultDrawableLoader} if
|
||||
* {@link DevicePolicyResources.Drawables#UNDEFINED} was passed.
|
||||
*
|
||||
* <p>Calls to this API will not return {@code null} unless no updated drawable was found
|
||||
* and the call to {@code defaultDrawableLoader} returned {@code null}.
|
||||
*
|
||||
* <p>This API uses the screen density returned from {@link Resources#getConfiguration()}, to
|
||||
* set a different value use
|
||||
* {@link #getDrawableForDensity(String, String, int, Supplier)}.
|
||||
*
|
||||
* <p>Callers should register for {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to get
|
||||
* notified when a resource has been updated.
|
||||
*
|
||||
* <p>Note that each call to this API loads the resource from the package that called
|
||||
* {@code setDrawables} to set the updated resource.
|
||||
*
|
||||
* @param drawableId The drawable ID to get the updated resource for.
|
||||
* @param drawableStyle The drawable style to use.
|
||||
* @param defaultDrawableLoader To get the default drawable if no updated drawable was set for
|
||||
* the provided params.
|
||||
*/
|
||||
@Nullable
|
||||
public Drawable getDrawable(
|
||||
@NonNull @DevicePolicyResources.UpdatableDrawableId String drawableId,
|
||||
@NonNull @DevicePolicyResources.UpdatableDrawableStyle String drawableStyle,
|
||||
@NonNull Supplier<Drawable> defaultDrawableLoader) {
|
||||
return getDrawable(
|
||||
drawableId, drawableStyle, Drawables.Source.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.
|
||||
*
|
||||
* <p>Calls to this API will not return {@code null} unless no updated drawable was found
|
||||
* and the call to {@code defaultDrawableLoader} returned {@code null}.
|
||||
*
|
||||
* <p>Callers should register for {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to get
|
||||
* notified when a resource has been updated.
|
||||
*
|
||||
* @param drawableId The drawable ID to get the updated resource for.
|
||||
* @param drawableStyle The drawable style to use.
|
||||
* @param drawableSource The source for the caller.
|
||||
* @param defaultDrawableLoader To get the default drawable if no updated drawable was set for
|
||||
* the provided params.
|
||||
*/
|
||||
@Nullable
|
||||
public Drawable getDrawable(
|
||||
@NonNull @DevicePolicyResources.UpdatableDrawableId String drawableId,
|
||||
@NonNull @DevicePolicyResources.UpdatableDrawableStyle String drawableStyle,
|
||||
@NonNull @DevicePolicyResources.UpdatableDrawableSource String drawableSource,
|
||||
@NonNull Supplier<Drawable> defaultDrawableLoader) {
|
||||
|
||||
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(defaultDrawableLoader, "defaultDrawableLoader can't be null");
|
||||
|
||||
if (Drawables.UNDEFINED.equals(drawableId)) {
|
||||
return ParcelableResource.loadDefaultDrawable(defaultDrawableLoader);
|
||||
}
|
||||
if (mService != null) {
|
||||
try {
|
||||
ParcelableResource resource = mService.getDrawable(
|
||||
drawableId, drawableStyle, drawableSource);
|
||||
if (resource == null) {
|
||||
return ParcelableResource.loadDefaultDrawable(
|
||||
defaultDrawableLoader);
|
||||
}
|
||||
return resource.getDrawable(
|
||||
mContext,
|
||||
/* density= */ 0,
|
||||
defaultDrawableLoader);
|
||||
|
||||
} catch (RemoteException e) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Error getting the updated drawable from DevicePolicyManagerService.",
|
||||
e);
|
||||
return ParcelableResource.loadDefaultDrawable(defaultDrawableLoader);
|
||||
}
|
||||
}
|
||||
return ParcelableResource.loadDefaultDrawable(defaultDrawableLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to {@link #getDrawable(String, String, Supplier)}, but also accepts
|
||||
* {@code density}. See {@link Resources#getDrawableForDensity(int, int, Resources.Theme)}.
|
||||
*
|
||||
* <p>Calls to this API will not return {@code null} unless no updated drawable was found
|
||||
* and the call to {@code defaultDrawableLoader} returned {@code null}.
|
||||
*
|
||||
* <p>Callers should register for {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to get
|
||||
* notified when a resource has been updated.
|
||||
*
|
||||
* @param drawableId The drawable ID to get the updated resource for.
|
||||
* @param drawableStyle The drawable style to use.
|
||||
* @param density The desired screen density indicated by the resource as
|
||||
* found in {@link DisplayMetrics}. A value of 0 means to use the
|
||||
* density returned from {@link Resources#getConfiguration()}.
|
||||
* @param defaultDrawableLoader To get the default drawable if no updated drawable was set for
|
||||
* the provided params.
|
||||
*/
|
||||
@Nullable
|
||||
public Drawable getDrawableForDensity(
|
||||
@NonNull @DevicePolicyResources.UpdatableDrawableId String drawableId,
|
||||
@NonNull @DevicePolicyResources.UpdatableDrawableStyle String drawableStyle,
|
||||
int density,
|
||||
@NonNull Supplier<Drawable> defaultDrawableLoader) {
|
||||
return getDrawableForDensity(
|
||||
drawableId,
|
||||
drawableStyle,
|
||||
Drawables.Source.UNDEFINED,
|
||||
density,
|
||||
defaultDrawableLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to {@link #getDrawable(String, String, String, Supplier)}, but also accepts
|
||||
* {@code density}. See {@link Resources#getDrawableForDensity(int, int, Resources.Theme)}.
|
||||
*
|
||||
* <p>Calls to this API will not return {@code null} unless no updated drawable was found
|
||||
* and the call to {@code defaultDrawableLoader} returned {@code null}.
|
||||
*
|
||||
* <p>Callers should register for {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to get
|
||||
* notified when a resource has been updated.
|
||||
*
|
||||
* @param drawableId The drawable ID to get the updated resource for.
|
||||
* @param drawableStyle The drawable style to use.
|
||||
* @param drawableSource The source for the caller.
|
||||
* @param density The desired screen density indicated by the resource as
|
||||
* found in {@link DisplayMetrics}. A value of 0 means to use the
|
||||
* density returned from {@link Resources#getConfiguration()}.
|
||||
* @param defaultDrawableLoader To get the default drawable if no updated drawable was set for
|
||||
* the provided params.
|
||||
*/
|
||||
@Nullable
|
||||
public Drawable getDrawableForDensity(
|
||||
@NonNull @DevicePolicyResources.UpdatableDrawableId String drawableId,
|
||||
@NonNull @DevicePolicyResources.UpdatableDrawableStyle String drawableStyle,
|
||||
@NonNull @DevicePolicyResources.UpdatableDrawableSource String drawableSource,
|
||||
int density,
|
||||
@NonNull Supplier<Drawable> defaultDrawableLoader) {
|
||||
|
||||
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(defaultDrawableLoader, "defaultDrawableLoader can't be null");
|
||||
|
||||
if (Drawables.UNDEFINED.equals(drawableId)) {
|
||||
return ParcelableResource.loadDefaultDrawable(defaultDrawableLoader);
|
||||
}
|
||||
if (mService != null) {
|
||||
try {
|
||||
ParcelableResource resource = mService.getDrawable(
|
||||
drawableId, drawableStyle, drawableSource);
|
||||
if (resource == null) {
|
||||
return ParcelableResource.loadDefaultDrawable(
|
||||
defaultDrawableLoader);
|
||||
}
|
||||
return resource.getDrawable(mContext, density, defaultDrawableLoader);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Error getting the updated drawable from DevicePolicyManagerService.",
|
||||
e);
|
||||
return ParcelableResource.loadDefaultDrawable(defaultDrawableLoader);
|
||||
}
|
||||
}
|
||||
return ParcelableResource.loadDefaultDrawable(defaultDrawableLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to {@link #getDrawable(String, String, String, Supplier)} but returns an
|
||||
* {@link Icon} instead of a {@link Drawable}.
|
||||
*
|
||||
* @param drawableId The drawable ID to get the updated resource for.
|
||||
* @param drawableStyle The drawable style to use.
|
||||
* @param drawableSource The source for the caller.
|
||||
* @param defaultIcon Returned if no updated drawable was set for the provided params.
|
||||
*/
|
||||
@Nullable
|
||||
public Icon getDrawableAsIcon(
|
||||
@NonNull @DevicePolicyResources.UpdatableDrawableId String drawableId,
|
||||
@NonNull @DevicePolicyResources.UpdatableDrawableStyle String drawableStyle,
|
||||
@NonNull @DevicePolicyResources.UpdatableDrawableSource 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)) {
|
||||
return defaultIcon;
|
||||
}
|
||||
if (mService != null) {
|
||||
try {
|
||||
ParcelableResource resource = mService.getDrawable(
|
||||
drawableId, drawableStyle, drawableSource);
|
||||
if (resource == null) {
|
||||
return defaultIcon;
|
||||
}
|
||||
return Icon.createWithResource(resource.getPackageName(), resource.getResourceId());
|
||||
} catch (RemoteException e) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Error getting the updated drawable from DevicePolicyManagerService.",
|
||||
e);
|
||||
return defaultIcon;
|
||||
}
|
||||
}
|
||||
return defaultIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to {@link #getDrawable(String, String, Supplier)} but returns an {@link Icon}
|
||||
* instead of a {@link Drawable}.
|
||||
*
|
||||
* @param drawableId The drawable ID to get the updated resource for.
|
||||
* @param drawableStyle The drawable style to use.
|
||||
* @param defaultIcon Returned if no updated drawable was set for the provided params.
|
||||
*/
|
||||
@Nullable
|
||||
public Icon getDrawableAsIcon(
|
||||
@NonNull @DevicePolicyResources.UpdatableDrawableId String drawableId,
|
||||
@NonNull @DevicePolicyResources.UpdatableDrawableStyle String drawableStyle,
|
||||
@Nullable Icon defaultIcon) {
|
||||
return getDrawableAsIcon(
|
||||
drawableId, drawableStyle, Drawables.Source.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.
|
||||
*
|
||||
* <p>Sends a broadcast with action {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to
|
||||
* registered receivers when a resource has been updated successfully.
|
||||
*
|
||||
* <p>Important notes to consider when using this API:
|
||||
* <ul>
|
||||
* <li> {@link #getString} references the resource
|
||||
* {@code callingPackageResourceId} in the calling package each time it gets called. You have to
|
||||
* ensure that the resource is always available in the calling package as long as it is used as
|
||||
* an updated resource.
|
||||
* <li> You still have to re-call {@code setStrings} even if you only make changes to the
|
||||
* content of the resource with ID {@code callingPackageResourceId} as the content might be
|
||||
* cached and would need updating.
|
||||
* </ul>
|
||||
*
|
||||
* @param strings The list of {@link DevicePolicyStringResource} to update.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES)
|
||||
public void setStrings(@NonNull Set<DevicePolicyStringResource> strings) {
|
||||
if (mService != null) {
|
||||
try {
|
||||
mService.setStrings(new ArrayList<>(strings));
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the updated strings for the list of {@code stringIds} (see
|
||||
* {@link DevicePolicyResources.Strings}) that was previously set by calling {@link #setStrings},
|
||||
* meaning any subsequent calls to {@link #getString} for the provided IDs will
|
||||
* return the default string from {@code defaultStringLoader}.
|
||||
*
|
||||
* <p>Sends a broadcast with action {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to
|
||||
* registered receivers when a resource has been reset successfully.
|
||||
*
|
||||
* @param stringIds The list of IDs to remove the updated resources for.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES)
|
||||
public void resetStrings(@NonNull Set<String> stringIds) {
|
||||
if (mService != null) {
|
||||
try {
|
||||
mService.resetStrings(new ArrayList<>(stringIds));
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the appropriate updated string for the {@code stringId} (see
|
||||
* {@link DevicePolicyResources.Strings}) if one was set using
|
||||
* {@code setStrings}, otherwise returns the string from {@code defaultStringLoader}.
|
||||
*
|
||||
* <p>Also returns the string from {@code defaultStringLoader} if
|
||||
* {@link DevicePolicyResources.Strings#UNDEFINED} was passed.
|
||||
*
|
||||
* <p>Calls to this API will not return {@code null} unless no updated drawable was found
|
||||
* and the call to {@code defaultStringLoader} returned {@code null}.
|
||||
*
|
||||
* <p>Callers should register for {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to get
|
||||
* notified when a resource has been updated.
|
||||
*
|
||||
* <p>Note that each call to this API loads the resource from the package that called
|
||||
* {@code setStrings} to set the updated resource.
|
||||
*
|
||||
* @param stringId The IDs to get the updated resource for.
|
||||
* @param defaultStringLoader To get the default string if no updated string was set for
|
||||
* {@code stringId}.
|
||||
*/
|
||||
@Nullable
|
||||
public String getString(
|
||||
@NonNull @DevicePolicyResources.UpdatableStringId String stringId,
|
||||
@NonNull Supplier<String> defaultStringLoader) {
|
||||
|
||||
Objects.requireNonNull(stringId, "stringId can't be null");
|
||||
Objects.requireNonNull(defaultStringLoader, "defaultStringLoader can't be null");
|
||||
|
||||
if (stringId.equals(DevicePolicyResources.Strings.UNDEFINED)) {
|
||||
return ParcelableResource.loadDefaultString(defaultStringLoader);
|
||||
}
|
||||
if (mService != null) {
|
||||
try {
|
||||
ParcelableResource resource = mService.getString(stringId);
|
||||
if (resource == null) {
|
||||
return ParcelableResource.loadDefaultString(defaultStringLoader);
|
||||
}
|
||||
return resource.getString(mContext, defaultStringLoader);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Error getting the updated string from DevicePolicyManagerService.",
|
||||
e);
|
||||
return ParcelableResource.loadDefaultString(defaultStringLoader);
|
||||
}
|
||||
}
|
||||
return ParcelableResource.loadDefaultString(defaultStringLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to {@link #getString(String, Supplier)} but accepts {@code formatArgs} and returns a
|
||||
* localized formatted string, substituting the format arguments as defined in
|
||||
* {@link java.util.Formatter} and {@link java.lang.String#format}, (see
|
||||
* {@link Resources#getString(int, Object...)}).
|
||||
*
|
||||
* <p>Calls to this API will not return {@code null} unless no updated drawable was found
|
||||
* and the call to {@code defaultStringLoader} returned {@code null}.
|
||||
*
|
||||
* @param stringId The IDs to get the updated resource for.
|
||||
* @param defaultStringLoader To get the default string if no updated string was set for
|
||||
* {@code stringId}.
|
||||
* @param formatArgs The format arguments that will be used for substitution.
|
||||
*/
|
||||
@Nullable
|
||||
@SuppressLint("SamShouldBeLast")
|
||||
public String getString(
|
||||
@NonNull @DevicePolicyResources.UpdatableStringId String stringId,
|
||||
@NonNull Supplier<String> defaultStringLoader,
|
||||
@NonNull Object... formatArgs) {
|
||||
|
||||
Objects.requireNonNull(stringId, "stringId can't be null");
|
||||
Objects.requireNonNull(defaultStringLoader, "defaultStringLoader can't be null");
|
||||
|
||||
if (stringId.equals(DevicePolicyResources.Strings.UNDEFINED)) {
|
||||
return ParcelableResource.loadDefaultString(defaultStringLoader);
|
||||
}
|
||||
if (mService != null) {
|
||||
try {
|
||||
ParcelableResource resource = mService.getString(stringId);
|
||||
if (resource == null) {
|
||||
return ParcelableResource.loadDefaultString(defaultStringLoader);
|
||||
}
|
||||
return resource.getString(mContext, defaultStringLoader, formatArgs);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Error getting the updated string from DevicePolicyManagerService.",
|
||||
e);
|
||||
return ParcelableResource.loadDefaultString(defaultStringLoader);
|
||||
}
|
||||
}
|
||||
return ParcelableResource.loadDefaultString(defaultStringLoader);
|
||||
@NonNull
|
||||
public DevicePolicyResourcesManager getResources() {
|
||||
return mResourcesManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
528
core/java/android/app/admin/DevicePolicyResourcesManager.java
Normal file
528
core/java/android/app/admin/DevicePolicyResourcesManager.java
Normal file
@@ -0,0 +1,528 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.app.admin;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.SystemApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.RemoteException;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Class containing required APIs to set, reset, and get device policy related resources.
|
||||
*/
|
||||
public class DevicePolicyResourcesManager {
|
||||
private static String TAG = "DevicePolicyResourcesManager";
|
||||
|
||||
private final Context mContext;
|
||||
private final IDevicePolicyManager mService;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
protected DevicePolicyResourcesManager(Context context, IDevicePolicyManager service) {
|
||||
mContext = context;
|
||||
mService = service;
|
||||
}
|
||||
|
||||
/**
|
||||
* For each {@link DevicePolicyDrawableResource} item in {@code drawables}, if
|
||||
* {@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.
|
||||
*
|
||||
* <p>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.
|
||||
*
|
||||
* <p>Sends a broadcast with action
|
||||
* {@link DevicePolicyManager#ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to registered receivers
|
||||
* when a resource has been updated successfully.
|
||||
*
|
||||
* <p>Important notes to consider when using this API:
|
||||
* <ul>
|
||||
* <li>{@link #getDrawable} references the resource
|
||||
* {@link DevicePolicyDrawableResource#getResourceIdInCallingPackage()} in the
|
||||
* calling package each time it gets called. You have to ensure that the resource is always
|
||||
* available in the calling package as long as it is used as an updated resource.
|
||||
* <li>You still have to re-call {@code setDrawables} even if you only make changes to the
|
||||
* content of the resource with ID
|
||||
* {@link DevicePolicyDrawableResource#getResourceIdInCallingPackage()} as the content might be
|
||||
* cached and would need updating.
|
||||
* </ul>
|
||||
*
|
||||
* @param drawables The list of {@link DevicePolicyDrawableResource} to update.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES)
|
||||
public void setDrawables(@NonNull Set<DevicePolicyDrawableResource> drawables) {
|
||||
if (mService != null) {
|
||||
try {
|
||||
mService.setDrawables(new ArrayList<>(drawables));
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}.
|
||||
*
|
||||
* <p>Sends a broadcast with action
|
||||
* {@link DevicePolicyManager#ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to registered receivers
|
||||
* when a resource has been reset successfully.
|
||||
*
|
||||
* @param drawableIds The list of IDs to remove.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES)
|
||||
public void resetDrawables(@NonNull Set<String> drawableIds) {
|
||||
if (mService != null) {
|
||||
try {
|
||||
mService.resetDrawables(new ArrayList<>(drawableIds));
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}.
|
||||
*
|
||||
* <p>Also returns the drawable from {@code defaultDrawableLoader} if {@code drawableId}
|
||||
* is {@link DevicePolicyResources#UNDEFINED}.
|
||||
*
|
||||
* <p>Calls to this API will not return {@code null} unless no updated drawable was found
|
||||
* and the call to {@code defaultDrawableLoader} returned {@code null}.
|
||||
*
|
||||
* <p>This API uses the screen density returned from {@link Resources#getConfiguration()}, to
|
||||
* set a different value use
|
||||
* {@link #getDrawableForDensity(String, String, int, Supplier)}.
|
||||
*
|
||||
* <p>Callers should register for
|
||||
* {@link DevicePolicyManager#ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to get notified when a
|
||||
* resource has been updated.
|
||||
*
|
||||
* <p>Note that each call to this API loads the resource from the package that called
|
||||
* {@code setDrawables} to set the updated resource.
|
||||
*
|
||||
* @param drawableId The drawable ID to get the updated resource for.
|
||||
* @param drawableStyle The drawable style to use.
|
||||
* @param defaultDrawableLoader To get the default drawable if no updated drawable was set for
|
||||
* the provided params.
|
||||
*/
|
||||
@Nullable
|
||||
public Drawable getDrawable(
|
||||
@NonNull String drawableId,
|
||||
@NonNull String drawableStyle,
|
||||
@NonNull Supplier<Drawable> defaultDrawableLoader) {
|
||||
return getDrawable(
|
||||
drawableId, drawableStyle, DevicePolicyResources.UNDEFINED, defaultDrawableLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to {@link #getDrawable(String, String, Supplier)}, but also accepts
|
||||
* 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.
|
||||
*
|
||||
* <p> 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)}.
|
||||
*
|
||||
* <p>Calls to this API will not return {@code null} unless no updated drawable was found
|
||||
* and the call to {@code defaultDrawableLoader} returned {@code null}.
|
||||
*
|
||||
* <p>Callers should register for
|
||||
* {@link DevicePolicyManager#ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to get notified when a
|
||||
* resource has been updated.
|
||||
*
|
||||
* @param drawableId The drawable ID to get the updated resource for.
|
||||
* @param drawableStyle The drawable style to use.
|
||||
* @param drawableSource The source for the caller.
|
||||
* @param defaultDrawableLoader To get the default drawable if no updated drawable was set for
|
||||
* the provided params.
|
||||
*/
|
||||
@Nullable
|
||||
public Drawable getDrawable(
|
||||
@NonNull String drawableId,
|
||||
@NonNull String drawableStyle,
|
||||
@NonNull String drawableSource,
|
||||
@NonNull Supplier<Drawable> defaultDrawableLoader) {
|
||||
|
||||
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(defaultDrawableLoader, "defaultDrawableLoader can't be null");
|
||||
|
||||
if (drawableId.equals(DevicePolicyResources.UNDEFINED)) {
|
||||
return ParcelableResource.loadDefaultDrawable(defaultDrawableLoader);
|
||||
}
|
||||
if (mService != null) {
|
||||
try {
|
||||
ParcelableResource resource = mService.getDrawable(
|
||||
drawableId, drawableStyle, drawableSource);
|
||||
if (resource == null) {
|
||||
return ParcelableResource.loadDefaultDrawable(
|
||||
defaultDrawableLoader);
|
||||
}
|
||||
return resource.getDrawable(
|
||||
mContext,
|
||||
/* density= */ 0,
|
||||
defaultDrawableLoader);
|
||||
|
||||
} catch (RemoteException e) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Error getting the updated drawable from DevicePolicyManagerService.",
|
||||
e);
|
||||
return ParcelableResource.loadDefaultDrawable(defaultDrawableLoader);
|
||||
}
|
||||
}
|
||||
return ParcelableResource.loadDefaultDrawable(defaultDrawableLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to {@link #getDrawable(String, String, Supplier)}, but also accepts
|
||||
* {@code density}. See {@link Resources#getDrawableForDensity(int, int, Resources.Theme)}.
|
||||
*
|
||||
* <p>Calls to this API will not return {@code null} unless no updated drawable was found
|
||||
* and the call to {@code defaultDrawableLoader} returned {@code null}.
|
||||
*
|
||||
* <p>Callers should register for
|
||||
* {@link DevicePolicyManager#ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to get notified when a
|
||||
* resource has been updated.
|
||||
*
|
||||
* @param drawableId The drawable ID to get the updated resource for.
|
||||
* @param drawableStyle The drawable style to use.
|
||||
* @param density The desired screen density indicated by the resource as
|
||||
* found in {@link DisplayMetrics}. A value of 0 means to use the
|
||||
* density returned from {@link Resources#getConfiguration()}.
|
||||
* @param defaultDrawableLoader To get the default drawable if no updated drawable was set for
|
||||
* the provided params.
|
||||
*/
|
||||
@Nullable
|
||||
public Drawable getDrawableForDensity(
|
||||
@NonNull String drawableId,
|
||||
@NonNull String drawableStyle,
|
||||
int density,
|
||||
@NonNull Supplier<Drawable> defaultDrawableLoader) {
|
||||
return getDrawableForDensity(
|
||||
drawableId,
|
||||
drawableStyle,
|
||||
DevicePolicyResources.UNDEFINED,
|
||||
density,
|
||||
defaultDrawableLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to {@link #getDrawable(String, String, String, Supplier)}, but also accepts
|
||||
* {@code density}. See {@link Resources#getDrawableForDensity(int, int, Resources.Theme)}.
|
||||
*
|
||||
* <p>Calls to this API will not return {@code null} unless no updated drawable was found
|
||||
* and the call to {@code defaultDrawableLoader} returned {@code null}.
|
||||
*
|
||||
* <p>Callers should register for
|
||||
* {@link DevicePolicyManager#ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to get notified when a
|
||||
* resource has been updated.
|
||||
*
|
||||
* @param drawableId The drawable ID to get the updated resource for.
|
||||
* @param drawableStyle The drawable style to use.
|
||||
* @param drawableSource The source for the caller.
|
||||
* @param density The desired screen density indicated by the resource as
|
||||
* found in {@link DisplayMetrics}. A value of 0 means to use the
|
||||
* density returned from {@link Resources#getConfiguration()}.
|
||||
* @param defaultDrawableLoader To get the default drawable if no updated drawable was set for
|
||||
* the provided params.
|
||||
*/
|
||||
@Nullable
|
||||
public Drawable getDrawableForDensity(
|
||||
@NonNull String drawableId,
|
||||
@NonNull String drawableStyle,
|
||||
@NonNull String drawableSource,
|
||||
int density,
|
||||
@NonNull Supplier<Drawable> defaultDrawableLoader) {
|
||||
|
||||
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(defaultDrawableLoader, "defaultDrawableLoader can't be null");
|
||||
|
||||
if (drawableId.equals(DevicePolicyResources.UNDEFINED)) {
|
||||
return ParcelableResource.loadDefaultDrawable(defaultDrawableLoader);
|
||||
}
|
||||
if (mService != null) {
|
||||
try {
|
||||
ParcelableResource resource = mService.getDrawable(
|
||||
drawableId, drawableStyle, drawableSource);
|
||||
if (resource == null) {
|
||||
return ParcelableResource.loadDefaultDrawable(
|
||||
defaultDrawableLoader);
|
||||
}
|
||||
return resource.getDrawable(mContext, density, defaultDrawableLoader);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Error getting the updated drawable from DevicePolicyManagerService.",
|
||||
e);
|
||||
return ParcelableResource.loadDefaultDrawable(defaultDrawableLoader);
|
||||
}
|
||||
}
|
||||
return ParcelableResource.loadDefaultDrawable(defaultDrawableLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to {@link #getDrawable(String, String, String, Supplier)} but returns an
|
||||
* {@link Icon} instead of a {@link Drawable}.
|
||||
*
|
||||
* @param drawableId The drawable ID to get the updated resource for.
|
||||
* @param drawableStyle The drawable style to use.
|
||||
* @param drawableSource The source for the caller.
|
||||
* @param defaultIcon Returned if no updated drawable was set for the provided params.
|
||||
*/
|
||||
@Nullable
|
||||
public Icon getDrawableAsIcon(
|
||||
@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 (drawableId.equals(DevicePolicyResources.UNDEFINED)) {
|
||||
return defaultIcon;
|
||||
}
|
||||
if (mService != null) {
|
||||
try {
|
||||
ParcelableResource resource = mService.getDrawable(
|
||||
drawableId, drawableStyle, drawableSource);
|
||||
if (resource == null) {
|
||||
return defaultIcon;
|
||||
}
|
||||
return Icon.createWithResource(resource.getPackageName(), resource.getResourceId());
|
||||
} catch (RemoteException e) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Error getting the updated drawable from DevicePolicyManagerService.",
|
||||
e);
|
||||
return defaultIcon;
|
||||
}
|
||||
}
|
||||
return defaultIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to {@link #getDrawable(String, String, Supplier)} but returns an {@link Icon}
|
||||
* instead of a {@link Drawable}.
|
||||
*
|
||||
* @param drawableId The drawable ID to get the updated resource for.
|
||||
* @param drawableStyle The drawable style to use.
|
||||
* @param defaultIcon Returned if no updated drawable was set for the provided params.
|
||||
*/
|
||||
@Nullable
|
||||
public Icon getDrawableAsIcon(
|
||||
@NonNull String drawableId,
|
||||
@NonNull String drawableStyle,
|
||||
@Nullable Icon defaultIcon) {
|
||||
return getDrawableAsIcon(
|
||||
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}, meaning any system UI surface calling {@link #getString}
|
||||
* with {@code stringId} will get the new resource after this API is called.
|
||||
*
|
||||
* <p>Sends a broadcast with action
|
||||
* {@link DevicePolicyManager#ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to registered receivers
|
||||
* when a resource has been updated successfully.
|
||||
*
|
||||
* <p>Important notes to consider when using this API:
|
||||
* <ul>
|
||||
* <li> {@link #getString} references the resource {@code callingPackageResourceId} in the
|
||||
* calling package each time it gets called. You have to ensure that the resource is always
|
||||
* available in the calling package as long as it is used as an updated resource.
|
||||
* <li> You still have to re-call {@code setStrings} even if you only make changes to the
|
||||
* content of the resource with ID {@code callingPackageResourceId} as the content might be
|
||||
* cached and would need updating.
|
||||
* </ul>
|
||||
*
|
||||
* @param strings The list of {@link DevicePolicyStringResource} to update.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES)
|
||||
public void setStrings(@NonNull Set<DevicePolicyStringResource> strings) {
|
||||
if (mService != null) {
|
||||
try {
|
||||
mService.setStrings(new ArrayList<>(strings));
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the updated strings for the list of {@code stringIds} that was previously set by
|
||||
* calling {@link #setStrings}, meaning any subsequent calls to {@link #getString} for the
|
||||
* provided IDs will return the default string from {@code defaultStringLoader}.
|
||||
*
|
||||
* <p>Sends a broadcast with action
|
||||
* {@link DevicePolicyManager#ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to registered receivers
|
||||
* when a resource has been reset successfully.
|
||||
*
|
||||
* @param stringIds The list of IDs to remove the updated resources for.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES)
|
||||
public void resetStrings(@NonNull Set<String> stringIds) {
|
||||
if (mService != null) {
|
||||
try {
|
||||
mService.resetStrings(new ArrayList<>(stringIds));
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the appropriate updated string for the {@code stringId} (see
|
||||
* {@link DevicePolicyResources.Strings}) if one was set using
|
||||
* {@code setStrings}, otherwise returns the string from {@code defaultStringLoader}.
|
||||
*
|
||||
* <p>Also returns the string from {@code defaultStringLoader} if {@code stringId} is
|
||||
* {@link DevicePolicyResources#UNDEFINED}.
|
||||
*
|
||||
* <p>Calls to this API will not return {@code null} unless no updated drawable was found
|
||||
* and the call to {@code defaultStringLoader} returned {@code null}.
|
||||
*
|
||||
* <p>Callers should register for
|
||||
* {@link DevicePolicyManager#ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to get notified when a
|
||||
* resource has been updated.
|
||||
*
|
||||
* <p>Note that each call to this API loads the resource from the package that called
|
||||
* {@code setStrings} to set the updated resource.
|
||||
*
|
||||
* @param stringId The IDs to get the updated resource for.
|
||||
* @param defaultStringLoader To get the default string if no updated string was set for
|
||||
* {@code stringId}.
|
||||
*/
|
||||
@Nullable
|
||||
public String getString(
|
||||
@NonNull String stringId,
|
||||
@NonNull Supplier<String> defaultStringLoader) {
|
||||
|
||||
Objects.requireNonNull(stringId, "stringId can't be null");
|
||||
Objects.requireNonNull(defaultStringLoader, "defaultStringLoader can't be null");
|
||||
|
||||
if (stringId.equals(DevicePolicyResources.UNDEFINED)) {
|
||||
return ParcelableResource.loadDefaultString(defaultStringLoader);
|
||||
}
|
||||
if (mService != null) {
|
||||
try {
|
||||
ParcelableResource resource = mService.getString(stringId);
|
||||
if (resource == null) {
|
||||
return ParcelableResource.loadDefaultString(defaultStringLoader);
|
||||
}
|
||||
return resource.getString(mContext, defaultStringLoader);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Error getting the updated string from DevicePolicyManagerService.",
|
||||
e);
|
||||
return ParcelableResource.loadDefaultString(defaultStringLoader);
|
||||
}
|
||||
}
|
||||
return ParcelableResource.loadDefaultString(defaultStringLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to {@link #getString(String, Supplier)} but accepts {@code formatArgs} and returns a
|
||||
* localized formatted string, substituting the format arguments as defined in
|
||||
* {@link java.util.Formatter} and {@link java.lang.String#format}, (see
|
||||
* {@link Resources#getString(int, Object...)}).
|
||||
*
|
||||
* <p>Calls to this API will not return {@code null} unless no updated drawable was found
|
||||
* and the call to {@code defaultStringLoader} returned {@code null}.
|
||||
*
|
||||
* @param stringId The IDs to get the updated resource for.
|
||||
* @param defaultStringLoader To get the default string if no updated string was set for
|
||||
* {@code stringId}.
|
||||
* @param formatArgs The format arguments that will be used for substitution.
|
||||
*/
|
||||
@Nullable
|
||||
@SuppressLint("SamShouldBeLast")
|
||||
public String getString(
|
||||
@NonNull String stringId,
|
||||
@NonNull Supplier<String> defaultStringLoader,
|
||||
@NonNull Object... formatArgs) {
|
||||
|
||||
Objects.requireNonNull(stringId, "stringId can't be null");
|
||||
Objects.requireNonNull(defaultStringLoader, "defaultStringLoader can't be null");
|
||||
|
||||
if (stringId.equals(DevicePolicyResources.UNDEFINED)) {
|
||||
return ParcelableResource.loadDefaultString(defaultStringLoader);
|
||||
}
|
||||
if (mService != null) {
|
||||
try {
|
||||
ParcelableResource resource = mService.getString(stringId);
|
||||
if (resource == null) {
|
||||
return ParcelableResource.loadDefaultString(defaultStringLoader);
|
||||
}
|
||||
return resource.getString(mContext, defaultStringLoader, formatArgs);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Error getting the updated string from DevicePolicyManagerService.",
|
||||
e);
|
||||
return ParcelableResource.loadDefaultString(defaultStringLoader);
|
||||
}
|
||||
}
|
||||
return ParcelableResource.loadDefaultString(defaultStringLoader);
|
||||
}
|
||||
}
|
||||
@@ -28,19 +28,19 @@ import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Used to pass in the required information for updating an enterprise string resource using
|
||||
* {@link DevicePolicyManager#setStrings}.
|
||||
* {@link DevicePolicyResourcesManager#setStrings}.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
public final class DevicePolicyStringResource implements Parcelable {
|
||||
@NonNull private final @DevicePolicyResources.UpdatableStringId String mStringId;
|
||||
@NonNull private final String mStringId;
|
||||
private final @StringRes int mResourceIdInCallingPackage;
|
||||
@NonNull private ParcelableResource mResource;
|
||||
|
||||
/**
|
||||
* Creates an object containing the required information for updating an enterprise string
|
||||
* resource using {@link DevicePolicyManager#setStrings}.
|
||||
* resource using {@link DevicePolicyResourcesManager#setStrings}.
|
||||
*
|
||||
* <p>It will be used to update the string defined by {@code stringId} to the string with ID
|
||||
* {@code resourceIdInCallingPackage} in the calling package</p>
|
||||
@@ -54,14 +54,14 @@ public final class DevicePolicyStringResource implements Parcelable {
|
||||
*/
|
||||
public DevicePolicyStringResource(
|
||||
@NonNull Context context,
|
||||
@NonNull @DevicePolicyResources.UpdatableStringId String stringId,
|
||||
@NonNull String stringId,
|
||||
@StringRes int resourceIdInCallingPackage) {
|
||||
this(stringId, resourceIdInCallingPackage, new ParcelableResource(
|
||||
context, resourceIdInCallingPackage, ParcelableResource.RESOURCE_TYPE_STRING));
|
||||
}
|
||||
|
||||
private DevicePolicyStringResource(
|
||||
@NonNull @DevicePolicyResources.UpdatableStringId String stringId,
|
||||
@NonNull String stringId,
|
||||
@StringRes int resourceIdInCallingPackage,
|
||||
@NonNull ParcelableResource resource) {
|
||||
Objects.requireNonNull(stringId, "stringId must be provided.");
|
||||
@@ -75,7 +75,6 @@ public final class DevicePolicyStringResource implements Parcelable {
|
||||
/**
|
||||
* Returns the ID of the string to update.
|
||||
*/
|
||||
@DevicePolicyResources.UpdatableStringId
|
||||
@NonNull
|
||||
public String getStringId() {
|
||||
return mStringId;
|
||||
|
||||
@@ -43,7 +43,8 @@ import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Used to store the required information to load a resource that was updated using
|
||||
* {@link DevicePolicyManager#setDrawables} and {@link DevicePolicyManager#setStrings}.
|
||||
* {@link DevicePolicyResourcesManager#setDrawables} and
|
||||
* {@link DevicePolicyResourcesManager#setStrings}.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
|
||||
@@ -16,17 +16,14 @@
|
||||
|
||||
package com.android.server.devicepolicy;
|
||||
|
||||
import static android.app.admin.DevicePolicyResources.Drawables.Source.UPDATABLE_DRAWABLE_SOURCES;
|
||||
import static android.app.admin.DevicePolicyResources.Drawables.Style;
|
||||
import static android.app.admin.DevicePolicyResources.Drawables.Style.UPDATABLE_DRAWABLE_STYLES;
|
||||
import static android.app.admin.DevicePolicyResources.Drawables.UPDATABLE_DRAWABLE_IDS;
|
||||
import static android.app.admin.DevicePolicyResources.Strings.UPDATABLE_STRING_IDS;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.admin.DevicePolicyDrawableResource;
|
||||
import android.app.admin.DevicePolicyResources;
|
||||
import android.app.admin.DevicePolicyResources.Drawables;
|
||||
import android.app.admin.DevicePolicyStringResource;
|
||||
import android.app.admin.ParcelableResource;
|
||||
@@ -113,7 +110,7 @@ class DeviceManagementResourcesProvider {
|
||||
Objects.requireNonNull(drawableSource, "drawableSource must be provided.");
|
||||
Objects.requireNonNull(resource, "ParcelableResource must be provided.");
|
||||
|
||||
if (Drawables.Source.UNDEFINED.equals(drawableSource)) {
|
||||
if (DevicePolicyResources.UNDEFINED.equals(drawableSource)) {
|
||||
updated |= updateDrawable(drawableId, drawableStyle, resource);
|
||||
} else {
|
||||
updated |= updateDrawableForSource(drawableId, drawableSource, resource);
|
||||
@@ -130,12 +127,6 @@ class DeviceManagementResourcesProvider {
|
||||
|
||||
private boolean updateDrawable(
|
||||
String drawableId, String drawableStyle, ParcelableResource updatableResource) {
|
||||
if (!UPDATABLE_DRAWABLE_IDS.contains(drawableId)) {
|
||||
Log.w(TAG, "Updating a resource for an unknown drawable id " + drawableId);
|
||||
}
|
||||
if (!UPDATABLE_DRAWABLE_STYLES.contains(drawableStyle)) {
|
||||
Log.w(TAG, "Updating a resource for an unknown style id " + drawableStyle);
|
||||
}
|
||||
synchronized (mLock) {
|
||||
if (!mUpdatedDrawablesForStyle.containsKey(drawableId)) {
|
||||
mUpdatedDrawablesForStyle.put(drawableId, new HashMap<>());
|
||||
@@ -153,12 +144,6 @@ class DeviceManagementResourcesProvider {
|
||||
// TODO(b/214576716): change this to respect style
|
||||
private boolean updateDrawableForSource(
|
||||
String drawableId, String drawableSource, ParcelableResource updatableResource) {
|
||||
if (!UPDATABLE_DRAWABLE_IDS.contains(drawableId)) {
|
||||
Log.w(TAG, "Updating a resource for an unknown drawable id " + drawableId);
|
||||
}
|
||||
if (!UPDATABLE_DRAWABLE_SOURCES.contains(drawableSource)) {
|
||||
Log.w(TAG, "Updating a resource for an unknown source id " + drawableSource);
|
||||
}
|
||||
synchronized (mLock) {
|
||||
if (!mUpdatedDrawablesForSource.containsKey(drawableId)) {
|
||||
mUpdatedDrawablesForSource.put(drawableId, new HashMap<>());
|
||||
@@ -195,17 +180,6 @@ class DeviceManagementResourcesProvider {
|
||||
@Nullable
|
||||
ParcelableResource getDrawable(
|
||||
String drawableId, String drawableStyle, String drawableSource) {
|
||||
if (!UPDATABLE_DRAWABLE_IDS.contains(drawableId)) {
|
||||
Log.w(TAG, "Getting an updated resource for an unknown drawable id " + drawableId);
|
||||
}
|
||||
if (!UPDATABLE_DRAWABLE_STYLES.contains(drawableStyle)) {
|
||||
Log.w(TAG, "Getting an updated resource for an unknown drawable style "
|
||||
+ drawableStyle);
|
||||
}
|
||||
if (!UPDATABLE_DRAWABLE_SOURCES.contains(drawableSource)) {
|
||||
Log.w(TAG, "Getting an updated resource for an unknown drawable Source "
|
||||
+ drawableSource);
|
||||
}
|
||||
if (mUpdatedDrawablesForSource.containsKey(drawableId)
|
||||
&& mUpdatedDrawablesForSource.get(drawableId).containsKey(drawableSource)) {
|
||||
return mUpdatedDrawablesForSource.get(drawableId).get(drawableSource);
|
||||
@@ -217,10 +191,6 @@ class DeviceManagementResourcesProvider {
|
||||
if (mUpdatedDrawablesForStyle.get(drawableId).containsKey(drawableStyle)) {
|
||||
return mUpdatedDrawablesForStyle.get(drawableId).get(drawableStyle);
|
||||
}
|
||||
|
||||
if (mUpdatedDrawablesForStyle.get(drawableId).containsKey(Style.DEFAULT)) {
|
||||
return mUpdatedDrawablesForStyle.get(drawableId).get(Style.DEFAULT);
|
||||
}
|
||||
Log.d(TAG, "No updated drawable found for drawable id " + drawableId);
|
||||
return null;
|
||||
}
|
||||
@@ -249,9 +219,6 @@ class DeviceManagementResourcesProvider {
|
||||
}
|
||||
|
||||
private boolean updateString(String stringId, ParcelableResource updatableResource) {
|
||||
if (!UPDATABLE_STRING_IDS.contains(stringId)) {
|
||||
Log.w(TAG, "Updating a resource for an unknown string id " + stringId);
|
||||
}
|
||||
synchronized (mLock) {
|
||||
ParcelableResource current = mUpdatedStrings.get(stringId);
|
||||
if (updatableResource.equals(current)) {
|
||||
@@ -282,10 +249,6 @@ class DeviceManagementResourcesProvider {
|
||||
|
||||
@Nullable
|
||||
ParcelableResource getString(String stringId) {
|
||||
if (!UPDATABLE_STRING_IDS.contains(stringId)) {
|
||||
Log.w(TAG, "Getting an updated resource for an unknown string id " + stringId);
|
||||
}
|
||||
|
||||
if (mUpdatedStrings.containsKey(stringId)) {
|
||||
return mUpdatedStrings.get(stringId);
|
||||
}
|
||||
|
||||
@@ -158,6 +158,7 @@ import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.internal.util.collections.Sets;
|
||||
@@ -186,6 +187,7 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
@SmallTest
|
||||
@Presubmit
|
||||
@Ignore("b/225415867")
|
||||
public class DevicePolicyManagerTest extends DpmTestBase {
|
||||
|
||||
private static final String TAG = DevicePolicyManagerTest.class.getSimpleName();
|
||||
|
||||
Reference in New Issue
Block a user