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

Commit 4e5275f3 authored by Kholoud Mohamed's avatar Kholoud Mohamed Committed by Android (Google) Code Review
Browse files

Merge changes from topic "updateStrings"

* changes:
  Add getString override that accepts format args
  Add APIs to allow updating enterprise related strings
parents 1ad353bd ddf2c6da
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);
@@ -7598,6 +7598,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
+17 −0
Original line number Diff line number Diff line
@@ -1039,6 +1039,8 @@ 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 @NonNull public String getString(@NonNull String, @NonNull java.util.concurrent.Callable<java.lang.String>, @NonNull java.lang.Object...);
    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();
@@ -1051,11 +1053,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";
@@ -1123,6 +1127,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();
+191 −15
Original line number Diff line number Diff line
@@ -3282,14 +3282,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)
@@ -3303,9 +3304,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";
@@ -14535,11 +14544,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
@@ -14567,9 +14571,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
@@ -14593,6 +14594,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)}.
@@ -14608,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,
@@ -14622,6 +14626,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.
     *
@@ -14631,7 +14638,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,
@@ -14669,6 +14676,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.
     *
@@ -14680,7 +14690,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,
@@ -14698,6 +14708,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.
     *
@@ -14710,7 +14723,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,
@@ -14740,4 +14753,167 @@ 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(DevicePolicyResources.Strings.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);
    }
    /**
     * Similar to {@link #getString(String, Callable)} 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>{@code defaultStringLoader} must return a non {@code null} {@link String}, otherwise a
     * {@link NullPointerException} is thrown.
     *
     * @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.
     *
     * @hide
     */
    @SystemApi
    @NonNull
    @SuppressLint("SamShouldBeLast")
    public String getString(
            @NonNull @DevicePolicyResources.UpdatableStringId String stringId,
            @NonNull Callable<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.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, formatArgs);
            } catch (RemoteException e) {
                Log.e(
                        TAG,
                        "Error getting the updated string from DevicePolicyManagerService.",
                        e);
                return ParcelableResource.loadDefaultString(defaultStringLoader);
            }
        }
        return ParcelableResource.loadDefaultString(defaultStringLoader);
    }
}
+502 −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