Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 968b1b20 authored by kholoud mohamed's avatar kholoud mohamed Committed by Kholoud Mohamed
Browse files

Add APIs to allow updating enterprise related strings

Add APIs to update and retrieve enterprise-related system strings,
the APIs are guarded by a new permission that will be granted to the new
device management role holder.

Bug: 188410712
Bug: 211422509
Test: manual
Change-Id: I336b5f1856f621e2ed9886780fc838f3e18fdf9f
parent 165edbb1
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -7291,10 +7291,10 @@ package android.app.admin {
    method @Nullable public java.util.List<java.lang.String> getDelegatePackages(@NonNull android.content.ComponentName, @NonNull String);
    method @NonNull public java.util.List<java.lang.String> getDelegatedScopes(@Nullable android.content.ComponentName, @NonNull String);
    method public CharSequence getDeviceOwnerLockScreenInfo();
    method @Nullable public android.graphics.drawable.Drawable getDrawable(int, int, @NonNull java.util.concurrent.Callable<android.graphics.drawable.Drawable>);
    method @Nullable public android.graphics.drawable.Drawable getDrawable(int, int, int, @NonNull java.util.concurrent.Callable<android.graphics.drawable.Drawable>);
    method @Nullable public android.graphics.drawable.Drawable getDrawableForDensity(int, int, int, @NonNull java.util.concurrent.Callable<android.graphics.drawable.Drawable>);
    method @Nullable public android.graphics.drawable.Drawable getDrawableForDensity(int, int, int, int, @NonNull java.util.concurrent.Callable<android.graphics.drawable.Drawable>);
    method @NonNull public android.graphics.drawable.Drawable getDrawable(int, int, @NonNull java.util.concurrent.Callable<android.graphics.drawable.Drawable>);
    method @NonNull public android.graphics.drawable.Drawable getDrawable(int, int, int, @NonNull java.util.concurrent.Callable<android.graphics.drawable.Drawable>);
    method @NonNull public android.graphics.drawable.Drawable getDrawableForDensity(int, int, int, @NonNull java.util.concurrent.Callable<android.graphics.drawable.Drawable>);
    method @NonNull public android.graphics.drawable.Drawable getDrawableForDensity(int, int, int, int, @NonNull java.util.concurrent.Callable<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);
@@ -7597,6 +7597,7 @@ package android.app.admin {
    field public static final String EXTRA_PROVISIONING_WIFI_USER_CERTIFICATE = "android.app.extra.PROVISIONING_WIFI_USER_CERTIFICATE";
    field public static final String EXTRA_RESOURCE_ID = "android.app.extra.RESOURCE_ID";
    field public static final String EXTRA_RESOURCE_TYPE_DRAWABLE = "android.app.extra.RESOURCE_TYPE_DRAWABLE";
    field public static final String EXTRA_RESOURCE_TYPE_STRING = "android.app.extra.RESOURCE_TYPE_STRING";
    field public static final int FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY = 1; // 0x1
    field public static final int FLAG_MANAGED_CAN_ACCESS_PARENT = 2; // 0x2
    field public static final int FLAG_PARENT_CAN_ACCESS_MANAGED = 1; // 0x1
+16 −0
Original line number Diff line number Diff line
@@ -1036,6 +1036,7 @@ package android.app.admin {
    method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.QUERY_ADMIN_POLICY}) public java.util.List<java.lang.String> getPermittedInputMethodsForCurrentUser();
    method @Nullable public android.content.ComponentName getProfileOwner() throws java.lang.IllegalArgumentException;
    method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS}) public String getProfileOwnerNameAsUser(int) throws java.lang.IllegalArgumentException;
    method @NonNull public String getString(@NonNull String, @NonNull java.util.concurrent.Callable<java.lang.String>);
    method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS}) public int getUserProvisioningState();
    method public boolean isDeviceManaged();
    method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public boolean isDeviceProvisioned();
@@ -1048,11 +1049,13 @@ package android.app.admin {
    method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) public boolean packageHasActiveAdmins(String);
    method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) 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 int[]);
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES) public void resetStrings(@NonNull String[]);
    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.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);
    field public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_ALLOWED = "android.account.DEVICE_OR_PROFILE_OWNER_ALLOWED";
    field public static final String ACCOUNT_FEATURE_DEVICE_OR_PROFILE_OWNER_DISALLOWED = "android.account.DEVICE_OR_PROFILE_OWNER_DISALLOWED";
@@ -1120,6 +1123,19 @@ package android.app.admin {
    field public static final int STATE_USER_UNMANAGED = 0; // 0x0
  }
  public static final class DevicePolicyResources.Strings {
    field public static final String INVALID_ID = "INVALID_ID";
  }
  public final class DevicePolicyStringResource implements android.os.Parcelable {
    ctor public DevicePolicyStringResource(@NonNull android.content.Context, @NonNull String, @StringRes int);
    method public int describeContents();
    method public int getCallingPackageResourceId();
    method @NonNull public String getStringId();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.app.admin.DevicePolicyStringResource> CREATOR;
  }
  public final class FullyManagedDeviceProvisioningParams implements android.os.Parcelable {
    method public boolean canDeviceOwnerGrantSensorsPermissions();
    method public int describeContents();
+147 −15
Original line number Diff line number Diff line
@@ -3256,14 +3256,15 @@ public class DevicePolicyManager {
    /**
     * Broadcast action: notify system apps (e.g. settings, SysUI, etc) that the device management
     * resources with IDs {@link #EXTRA_RESOURCE_ID} has been updated using, the updated resources
     * can be retrieved using {@link #getDrawable}.
     * resources with IDs {@link #EXTRA_RESOURCE_ID} has been updated, the updated resources can be
     * retrieved using {@link #getDrawable} and {@code #getString}.
     *
     * <p>This broadcast is sent to registered receivers only.
     *
     * <p> The following extras will be included to identify the type of resource being updated:
     * <ul>
     *     <li>{@link #EXTRA_RESOURCE_TYPE_DRAWABLE} for drawable resources</li>
     *     <li>{@link #EXTRA_RESOURCE_TYPE_STRING} for string resources</li>
     * </ul>
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
@@ -3277,9 +3278,17 @@ public class DevicePolicyManager {
    public static final String EXTRA_RESOURCE_TYPE_DRAWABLE =
            "android.app.extra.RESOURCE_TYPE_DRAWABLE";
    /**
     * A boolean extra for {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to indicate that a
     * resource of type {@link String} is being updated.
     */
    public static final String EXTRA_RESOURCE_TYPE_STRING =
            "android.app.extra.RESOURCE_TYPE_STRING";
    /**
     * An integer array extra for {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to indicate which
     * drawable IDs (see {@link DevicePolicyResources.UpdatableDrawableId}) have been updated.
     * resource IDs (see {@link DevicePolicyResources.UpdatableDrawableId} and
     * {@link DevicePolicyResources.UpdatableStringId}) have been updated.
     */
    public static final String EXTRA_RESOURCE_ID =
            "android.app.extra.RESOURCE_ID";
@@ -14509,11 +14518,6 @@ public class DevicePolicyManager {
     *
     * @param drawables The list of {@link DevicePolicyDrawableResource} to update.
     *
     * @throws IllegalArgumentException if {@link DevicePolicyDrawableResource#getDrawableId()},
     * {@link DevicePolicyDrawableResource#getDrawableStyle()}, or
     * {@link DevicePolicyDrawableResource#getDrawableSource()} aren't defined in
     * {@link DevicePolicyResources.Drawable}.
     *
     * @hide
     */
    @SystemApi
@@ -14541,9 +14545,6 @@ public class DevicePolicyManager {
     *
     * @param drawableIds The list of IDs  to remove.
     *
     * @throws IllegalArgumentException if IDs are not defined in
     * {@link DevicePolicyResources.Drawable}
     *
     * @hide
     */
    @SystemApi
@@ -14567,6 +14568,9 @@ public class DevicePolicyManager {
     * <p>Also returns the drawable from {@code defaultDrawableLoader} if
     * {@link DevicePolicyResources.Drawable#INVALID_ID} was passed.
     *
     * <p>{@code defaultDrawableLoader} must return a non {@code null} {@link Drawable}, otherwise a
     * {@link NullPointerException} is thrown.
     *
     * <p>This API uses the screen density returned from {@link Resources#getConfiguration()}, to
     * set a different value use
     * {@link #getDrawableForDensity(int, int, int, Callable)}.
@@ -14582,7 +14586,7 @@ public class DevicePolicyManager {
     * @param defaultDrawableLoader To get the default drawable if no updated drawable was set for
     *                              the provided params.
     */
    @Nullable
    @NonNull
    public Drawable getDrawable(
            @DevicePolicyResources.UpdatableDrawableId int drawableId,
            @DevicePolicyResources.UpdatableDrawableStyle int drawableStyle,
@@ -14596,6 +14600,9 @@ public class DevicePolicyManager {
     * could result in returning a different drawable than {@link #getDrawable(int, int, Callable)}
     * if an override was set for that specific source.
     *
     * <p>{@code defaultDrawableLoader} must return a non {@code null} {@link Drawable}, otherwise a
     * {@link NullPointerException} is thrown.
     *
     * <p>Callers should register for {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to get
     * notified when a resource has been updated.
     *
@@ -14605,7 +14612,7 @@ public class DevicePolicyManager {
     * @param defaultDrawableLoader To get the default drawable if no updated drawable was set for
     *                              the provided params.
     */
    @Nullable
    @NonNull
    public Drawable getDrawable(
            @DevicePolicyResources.UpdatableDrawableId int drawableId,
            @DevicePolicyResources.UpdatableDrawableStyle int drawableStyle,
@@ -14643,6 +14650,9 @@ public class DevicePolicyManager {
     * Similar to {@link #getDrawable(int, int, Callable)}, but also accepts
     * {@code density}. See {@link Resources#getDrawableForDensity(int, int, Resources.Theme)}.
     *
     * <p>{@code defaultDrawableLoader} must return a non {@code null} {@link Drawable}, otherwise a
     * {@link NullPointerException} is thrown.
     *
     * <p>Callers should register for {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to get
     * notified when a resource has been updated.
     *
@@ -14654,7 +14664,7 @@ public class DevicePolicyManager {
     * @param defaultDrawableLoader To get the default drawable if no updated drawable was set for
     *                              the provided params.
     */
    @Nullable
    @NonNull
    public Drawable getDrawableForDensity(
            @DevicePolicyResources.UpdatableDrawableId int drawableId,
            @DevicePolicyResources.UpdatableDrawableStyle int drawableStyle,
@@ -14672,6 +14682,9 @@ public class DevicePolicyManager {
     * Similar to {@link #getDrawable(int, int, int, Callable)}, but also accepts
     * {@code density}. See {@link Resources#getDrawableForDensity(int, int, Resources.Theme)}.
     *
     * <p>{@code defaultDrawableLoader} must return a non {@code null} {@link Drawable}, otherwise a
     * {@link NullPointerException} is thrown.
     *
     * <p>Callers should register for {@link #ACTION_DEVICE_POLICY_RESOURCE_UPDATED} to get
     * notified when a resource has been updated.
     *
@@ -14684,7 +14697,7 @@ public class DevicePolicyManager {
     * @param defaultDrawableLoader To get the default drawable if no updated drawable was set for
     *                              the provided params.
     */
    @Nullable
    @NonNull
    public Drawable getDrawableForDensity(
            @DevicePolicyResources.UpdatableDrawableId int drawableId,
            @DevicePolicyResources.UpdatableDrawableStyle int drawableStyle,
@@ -14714,4 +14727,123 @@ public class DevicePolicyManager {
        }
        return ParcelableResource.loadDefaultDrawable(defaultDrawableLoader);
    }
    /**
     * 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.String}), 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.String}) 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 String[] stringIds) {
        if (mService != null) {
            try {
                mService.resetStrings(stringIds);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
    }
    /**
     * Returns the appropriate updated string for the {@code stringId} (see
     * {@link DevicePolicyResources.String}) if one was set using
     * {@link #setStrings}, otherwise returns the string from {@code defaultStringLoader}.
     *
     * <p>Also returns the string from {@code defaultStringLoader} if
     * {@link DevicePolicyResources.String#INVALID_ID} was passed.
     *
     * <p>{@code defaultStringLoader} must return a non {@code null} {@link String}, otherwise a
     * {@link NullPointerException} is thrown.
     *
     * <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
     * {@link #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}.
     *
     * @hide
     */
    @SystemApi
    @NonNull
    public String getString(
            @NonNull @DevicePolicyResources.UpdatableStringId String stringId,
            @NonNull Callable<String> defaultStringLoader) {
        Objects.requireNonNull(stringId, "stringId can't be null");
        Objects.requireNonNull(defaultStringLoader, "defaultStringLoader can't be null");
        if (stringId.equals(INVALID_ID)) {
            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);
    }
}
+167 −2

File changed.

Preview size limit exceeded, changes collapsed.

+19 −0
Original line number Diff line number Diff line
/*
 * 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;

parcelable DevicePolicyStringResource;
Loading