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

Commit 3b378b1f authored by kholoud mohamed's avatar kholoud mohamed
Browse files

Add APIs to allow updating enterprise related drawables

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

Bug: 203548565
Bug: 188410712
Test: manual
Change-Id: Iab29db23a87e1481ba7e2996a704dcb2702444be
parent 60c20f23
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -7274,6 +7274,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 public CharSequence getEndUserSessionMessage(@NonNull android.content.ComponentName);
    method @NonNull public String getEnrollmentSpecificId();
    method @Nullable public android.app.admin.FactoryResetProtectionPolicy getFactoryResetProtectionPolicy(@Nullable android.content.ComponentName);
@@ -7666,6 +7670,35 @@ package android.app.admin {
    method public void onApplicationUserDataCleared(String, boolean);
  }
  public final class DevicePolicyResources {
    ctor public DevicePolicyResources();
  }
  public static final class DevicePolicyResources.Drawable {
    field public static final int INVALID_ID = -1; // 0xffffffff
    field public static final int WORK_PROFILE_ICON = 1; // 0x1
    field public static final int WORK_PROFILE_ICON_BADGE = 0; // 0x0
    field public static final int WORK_PROFILE_OFF_ICON = 2; // 0x2
    field public static final int WORK_PROFILE_USER_ICON = 3; // 0x3
  }
  public static final class DevicePolicyResources.Drawable.Source {
    field public static final int HOME_WIDGET = 2; // 0x2
    field public static final int LAUNCHER_OFF_BUTTON = 3; // 0x3
    field public static final int NOTIFICATION = 0; // 0x0
    field public static final int PROFILE_SWITCH_ANIMATION = 1; // 0x1
    field public static final int QUICK_SETTINGS = 4; // 0x4
    field public static final int STATUS_BAR = 5; // 0x5
    field public static final int UNDEFINED = -1; // 0xffffffff
  }
  public static final class DevicePolicyResources.Drawable.Style {
    field public static final int DEFAULT = -1; // 0xffffffff
    field public static final int OUTLINE = 2; // 0x2
    field public static final int SOLID_COLORED = 0; // 0x0
    field public static final int SOLID_NOT_COLORED = 1; // 0x1
  }
  public final class DnsEvent extends android.app.admin.NetworkEvent implements android.os.Parcelable {
    method public String getHostname();
    method public java.util.List<java.net.InetAddress> getInetAddresses();
+14 −0
Original line number Diff line number Diff line
@@ -993,6 +993,18 @@ package android.app {
package android.app.admin {
  public final class DevicePolicyDrawableResource implements android.os.Parcelable {
    ctor public DevicePolicyDrawableResource(@NonNull android.content.Context, int, int, int, @DrawableRes int);
    ctor public DevicePolicyDrawableResource(@NonNull android.content.Context, int, int, @DrawableRes int);
    method public int describeContents();
    method @DrawableRes public int getCallingPackageResourceId();
    method public int getDrawableId();
    method public int getDrawableSource();
    method public int getDrawableStyle();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.app.admin.DevicePolicyDrawableResource> CREATOR;
  }
  public class DevicePolicyKeyguardService extends android.app.Service {
    ctor public DevicePolicyKeyguardService();
    method @Nullable public void dismiss();
@@ -1025,8 +1037,10 @@ 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(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 @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.MANAGE_PROFILE_AND_DEVICE_OWNERS) public void setUserProvisioningState(int, @NonNull android.os.UserHandle);
+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 DevicePolicyDrawableResource;
+203 −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;

import android.annotation.DrawableRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.Objects;

/**
 * Used to pass in the required information for updating an enterprise drawable resource using
 * {@link DevicePolicyManager#setDrawables}.
 *
 * @hide
 */
@SystemApi
public final class DevicePolicyDrawableResource implements Parcelable {
    private final @DevicePolicyResources.UpdatableDrawableId int mDrawableId;
    private final @DevicePolicyResources.UpdatableDrawableStyle int mDrawableStyle;
    private final @DevicePolicyResources.UpdatableDrawableSource int mDrawableSource;
    private final @DrawableRes int mCallingPackageResourceId;
    @NonNull private ParcelableResource mResource;

    /**
     * Creates an object containing the required information for updating an enterprise drawable
     * resource using {@link DevicePolicyManager#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
     * {@code callingPackageResourceId} in the calling package</p>
     *
     * @param drawableId The ID of the drawable to update.
     * @param drawableStyle The style of the drawable to update.
     * @param drawableSource The source of the drawable to update.
     * @param callingPackageResourceId The ID of the drawable resource in the calling package to
     *        use as an updated resource.
     *
     * @throws IllegalStateException if the resource with ID
     * {@code callingPackageResourceId} doesn't exist in the {@code context} package.
     */
    public DevicePolicyDrawableResource(
            @NonNull Context context,
            @DevicePolicyResources.UpdatableDrawableId int drawableId,
            @DevicePolicyResources.UpdatableDrawableStyle int drawableStyle,
            @DevicePolicyResources.UpdatableDrawableSource int drawableSource,
            @DrawableRes int callingPackageResourceId) {
        this(drawableId, drawableStyle, drawableSource, callingPackageResourceId,
                new ParcelableResource(context, callingPackageResourceId,
                        ParcelableResource.RESOURCE_TYPE_DRAWABLE));
    }

    private DevicePolicyDrawableResource(
            @DevicePolicyResources.UpdatableDrawableId int drawableId,
            @DevicePolicyResources.UpdatableDrawableStyle int drawableStyle,
            @DevicePolicyResources.UpdatableDrawableSource int drawableSource,
            @DrawableRes int callingPackageResourceId,
            @NonNull ParcelableResource resource) {
        this.mDrawableId = drawableId;
        this.mDrawableStyle = drawableStyle;
        this.mDrawableSource = drawableSource;
        this.mCallingPackageResourceId = callingPackageResourceId;
        this.mResource = resource;
    }

    /**
     * Creates an object containing the required information for updating an enterprise drawable
     * resource using {@link DevicePolicyManager#setDrawables}.
     * <p>It will be used to update the drawable defined by {@code drawableId} with style
     * {@code drawableStyle} to the drawable with ID {@code callingPackageResourceId} in the
     * calling package</p>
     *
     * @param drawableId The ID of the drawable to update.
     * @param drawableStyle The style of the drawable to update.
     * @param callingPackageResourceId The ID of the drawable resource in the calling package to
     *        use as an updated resource.
     *
     * @throws IllegalStateException if the resource with ID
     * {@code callingPackageResourceId} doesn't exist in the calling package.
     */
    public DevicePolicyDrawableResource(
            @NonNull Context context,
            @DevicePolicyResources.UpdatableDrawableId int drawableId,
            @DevicePolicyResources.UpdatableDrawableStyle int drawableStyle,
            @DrawableRes int callingPackageResourceId) {
       this(context, drawableId, drawableStyle, DevicePolicyResources.Drawable.Source.UNDEFINED,
               callingPackageResourceId);
    }

    /**
     * Returns the ID of the drawable to update.
     */
    @DevicePolicyResources.UpdatableDrawableId
    public int getDrawableId() {
        return mDrawableId;
    }

    /**
     * Returns the style of the drawable to update
     */
    @DevicePolicyResources.UpdatableDrawableStyle
    public int getDrawableStyle() {
        return mDrawableStyle;
    }

    /**
     * Returns the source of the drawable to update.
     */
    @DevicePolicyResources.UpdatableDrawableSource
    public int getDrawableSource() {
        return mDrawableSource;
    }

    /**
     * Returns the ID of the drawable resource in the calling package to use as an updated
     * resource.
     */
    @DrawableRes
    public int getCallingPackageResourceId() {
        return mCallingPackageResourceId;
    }

    /**
     * Returns the {@link ParcelableResource} of the drawable.
     *
     * @hide
     */
    @NonNull
    public ParcelableResource getResource() {
        return mResource;
    }

    @Override
    public boolean equals(@Nullable Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        DevicePolicyDrawableResource other = (DevicePolicyDrawableResource) o;
        return mDrawableId == other.mDrawableId
                && mDrawableStyle == other.mDrawableStyle
                && mDrawableSource == other.mDrawableSource
                && mCallingPackageResourceId == other.mCallingPackageResourceId
                && mResource.equals(other.mResource);
    }

    @Override
    public int hashCode() {
        return Objects.hash(
                mDrawableId, mDrawableStyle, mDrawableSource, mCallingPackageResourceId, mResource);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeInt(mDrawableId);
        dest.writeInt(mDrawableStyle);
        dest.writeInt(mDrawableSource);
        dest.writeInt(mCallingPackageResourceId);
        dest.writeTypedObject(mResource, flags);
    }

    public static final @NonNull Creator<DevicePolicyDrawableResource> CREATOR =
            new Creator<DevicePolicyDrawableResource>() {
                @Override
                public DevicePolicyDrawableResource createFromParcel(Parcel in) {
                    int drawableId = in.readInt();
                    int drawableStyle = in.readInt();
                    int drawableSource = in.readInt();
                    int callingPackageResourceId = in.readInt();
                    ParcelableResource resource = in.readTypedObject(ParcelableResource.CREATOR);

                    return new DevicePolicyDrawableResource(
                            drawableId, drawableStyle, drawableSource, callingPackageResourceId,
                            resource);
                }

                @Override
                public DevicePolicyDrawableResource[] newArray(int size) {
                    return new DevicePolicyDrawableResource[size];
                }
            };
}
+229 −0

File changed.

Preview size limit exceeded, changes collapsed.

Loading