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

Commit 73145f4e authored by phweiss's avatar phweiss
Browse files

Create public API for policy transparency outside of Settings

The new DPM.createAdminSupportIntent() returns an intent that shows the
"This action was disabled by your admin"-dialog from settings.
This enables apps to inform the user about the cause of restricted
functionality.

A new extra for the intent allows to specialize the dialog for different
restricted features, instead of a generic message for all features.

Bug: 31215663
Test: runtest -c com.android.server.devicepolicy.DevicePolicyManagerTest frameworks-services

Change-Id: I3de7aeec0f88b8f013a63957aec803cd123fbedc
parent 1b60614a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -6123,6 +6123,7 @@ package android.app.admin {
    method public void clearPackagePersistentPreferredActivities(android.content.ComponentName, java.lang.String);
    method public void clearProfileOwner(android.content.ComponentName);
    method public void clearUserRestriction(android.content.ComponentName, java.lang.String);
    method public android.content.Intent createAdminSupportIntent(java.lang.String);
    method public android.os.UserHandle createAndManageUser(android.content.ComponentName, java.lang.String, android.content.ComponentName, android.os.PersistableBundle, int);
    method public void enableSystemApp(android.content.ComponentName, java.lang.String);
    method public int enableSystemApp(android.content.ComponentName, android.content.Intent);
@@ -6353,6 +6354,8 @@ package android.app.admin {
    field public static final int PERMISSION_POLICY_AUTO_DENY = 2; // 0x2
    field public static final int PERMISSION_POLICY_AUTO_GRANT = 1; // 0x1
    field public static final int PERMISSION_POLICY_PROMPT = 0; // 0x0
    field public static final java.lang.String POLICY_DISABLE_CAMERA = "policy_disable_camera";
    field public static final java.lang.String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";
    field public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 2; // 0x2
    field public static final int RESET_PASSWORD_REQUIRE_ENTRY = 1; // 0x1
    field public static final int SKIP_SETUP_WIZARD = 1; // 0x1
+3 −0
Original line number Diff line number Diff line
@@ -6319,6 +6319,7 @@ package android.app.admin {
    method public void clearPackagePersistentPreferredActivities(android.content.ComponentName, java.lang.String);
    method public void clearProfileOwner(android.content.ComponentName);
    method public void clearUserRestriction(android.content.ComponentName, java.lang.String);
    method public android.content.Intent createAdminSupportIntent(java.lang.String);
    method public android.os.UserHandle createAndManageUser(android.content.ComponentName, java.lang.String, android.content.ComponentName, android.os.PersistableBundle, int);
    method public void enableSystemApp(android.content.ComponentName, java.lang.String);
    method public int enableSystemApp(android.content.ComponentName, android.content.Intent);
@@ -6576,6 +6577,8 @@ package android.app.admin {
    field public static final int PERMISSION_POLICY_AUTO_DENY = 2; // 0x2
    field public static final int PERMISSION_POLICY_AUTO_GRANT = 1; // 0x1
    field public static final int PERMISSION_POLICY_PROMPT = 0; // 0x0
    field public static final java.lang.String POLICY_DISABLE_CAMERA = "policy_disable_camera";
    field public static final java.lang.String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";
    field public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 2; // 0x2
    field public static final int RESET_PASSWORD_REQUIRE_ENTRY = 1; // 0x1
    field public static final int SKIP_SETUP_WIZARD = 1; // 0x1
+4 −0
Original line number Diff line number Diff line
@@ -6140,6 +6140,7 @@ package android.app.admin {
    method public void clearPackagePersistentPreferredActivities(android.content.ComponentName, java.lang.String);
    method public void clearProfileOwner(android.content.ComponentName);
    method public void clearUserRestriction(android.content.ComponentName, java.lang.String);
    method public android.content.Intent createAdminSupportIntent(java.lang.String);
    method public android.os.UserHandle createAndManageUser(android.content.ComponentName, java.lang.String, android.content.ComponentName, android.os.PersistableBundle, int);
    method public void enableSystemApp(android.content.ComponentName, java.lang.String);
    method public int enableSystemApp(android.content.ComponentName, android.content.Intent);
@@ -6348,6 +6349,7 @@ package android.app.admin {
    field public static final java.lang.String EXTRA_PROVISIONING_WIFI_PROXY_PORT = "android.app.extra.PROVISIONING_WIFI_PROXY_PORT";
    field public static final java.lang.String EXTRA_PROVISIONING_WIFI_SECURITY_TYPE = "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE";
    field public static final java.lang.String EXTRA_PROVISIONING_WIFI_SSID = "android.app.extra.PROVISIONING_WIFI_SSID";
    field public static final java.lang.String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION";
    field public static final int FLAG_EVICT_CE_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
@@ -6375,6 +6377,8 @@ package android.app.admin {
    field public static final int PERMISSION_POLICY_AUTO_DENY = 2; // 0x2
    field public static final int PERMISSION_POLICY_AUTO_GRANT = 1; // 0x1
    field public static final int PERMISSION_POLICY_PROMPT = 0; // 0x0
    field public static final java.lang.String POLICY_DISABLE_CAMERA = "policy_disable_camera";
    field public static final java.lang.String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";
    field public static final int RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT = 2; // 0x2
    field public static final int RESET_PASSWORD_REQUIRE_ENTRY = 1; // 0x1
    field public static final int SKIP_SETUP_WIZARD = 1; // 0x1
+51 −0
Original line number Diff line number Diff line
@@ -1090,6 +1090,30 @@ public class DevicePolicyManager {
     */
    public static final String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";

    /**
     * Constant to indicate the feature of disabling the camera. Used as argument to
     * {@link #createAdminSupportIntent(String)}.
     * @see #setCameraDisabled(ComponentName, boolean)
     */
    public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera";

    /**
     * Constant to indicate the feature of disabling screen captures. Used as argument to
     * {@link #createAdminSupportIntent(String)}.
     * @see #setScreenCaptureDisabled(ComponentName, boolean)
     */
    public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";

    /**
     * A String indicating a specific restricted feature. Can be a user restriction from the
     * {@link UserManager}, e.g. {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the values
     * {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
     * @see #createAdminSupportIntent(String)
     * @hide
     */
    @TestApi
    public static final String EXTRA_RESTRICTION = "android.app.extra.RESTRICTION";

    /**
     * Activity action: have the user enter a new password. This activity should
     * be launched after using {@link #setPasswordQuality(ComponentName, int)},
@@ -5826,6 +5850,33 @@ public class DevicePolicyManager {
        return ret == null ? new Bundle() : ret;
    }

    /**
     * Called by any app to display a support dialog when a feature was disabled by an admin.
     * This returns an intent that can be used with {@link Context#startActivity(Intent)} to
     * display the dialog. It will tell the user that the feature indicated by {@code restriction}
     * was disabled by an admin, and include a link for more information. The default content of
     * the dialog can be changed by the restricting admin via
     * {@link #setShortSupportMessage(ComponentName, CharSequence)}. If the restriction is not
     * set (i.e. the feature is available), then the return value will be {@code null}.
     * @param restriction Indicates for which feature the dialog should be displayed. Can be a
     *            user restriction from {@link UserManager}, e.g.
     *            {@link UserManager#DISALLOW_ADJUST_VOLUME}, or one of the constants
     *            {@link #POLICY_DISABLE_CAMERA} or {@link #POLICY_DISABLE_SCREEN_CAPTURE}.
     * @return Intent An intent to be used to start the dialog-activity if the restriction is
     *            set by an admin, or null if the restriction does not exist or no admin set it.
     */
    public Intent createAdminSupportIntent(@NonNull String restriction) {
        throwIfParentInstance("createAdminSupportIntent");
        if (mService != null) {
            try {
                return mService.createAdminSupportIntent(restriction);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
        return null;
    }

    /**
     * Hide or unhide packages. When a package is hidden it is unavailable for use, but the data and
     * actual package file remain. This function can be called by a device owner, profile owner, or
+1 −0
Original line number Diff line number Diff line
@@ -201,6 +201,7 @@ interface IDevicePolicyManager {
    List getPermittedInputMethodsForCurrentUser();
    boolean isInputMethodPermittedByAdmin(in ComponentName admin, String packageName, int userId);

    Intent createAdminSupportIntent(in String restriction);
    boolean setApplicationHidden(in ComponentName admin, in String callerPackage, in String packageName, boolean hidden);
    boolean isApplicationHidden(in ComponentName admin, in String callerPackage, in String packageName);

Loading