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

Commit 9be10314 authored by Piotr Karzelek (xWF)'s avatar Piotr Karzelek (xWF) Committed by Android (Google) Code Review
Browse files

Merge "add provisioningContext to ActiveAdmin to store metadata about when the...

Merge "add provisioningContext to ActiveAdmin to store metadata about when the admin was set" into main
parents 250bac9e 157e480a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -618,6 +618,7 @@ package android.app.admin {
    method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public void resetDefaultCrossProfileIntentFilters(int);
    method @RequiresPermission(android.Manifest.permission.MANAGE_ROLE_HOLDERS) public void resetShouldAllowBypassingDevicePolicyManagementRoleQualificationState();
    method @RequiresPermission(allOf={android.Manifest.permission.MANAGE_DEVICE_ADMINS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}) public void setActiveAdmin(@NonNull android.content.ComponentName, boolean, int);
    method @FlaggedApi("android.app.admin.flags.provisioning_context_parameter") @RequiresPermission(allOf={android.Manifest.permission.MANAGE_DEVICE_ADMINS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}) public void setActiveAdmin(@NonNull android.content.ComponentName, boolean, int, @Nullable String);
    method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public boolean setDeviceOwner(@NonNull android.content.ComponentName, int);
    method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public boolean setDeviceOwnerOnly(@NonNull android.content.ComponentName, int);
    method public void setDeviceOwnerType(@NonNull android.content.ComponentName, int);
+43 −11
Original line number Diff line number Diff line
@@ -9199,6 +9199,14 @@ public class DevicePolicyManager {
        }
    }
    /**
     * @hide
     */
    @UnsupportedAppUsage
    public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
        setActiveAdmin(policyReceiver, refreshing, myUserId());
    }
    /**
     * @hide
     */
@@ -9210,21 +9218,45 @@ public class DevicePolicyManager {
    })
    public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
            int userHandle) {
        if (mService != null) {
            try {
                mService.setActiveAdmin(policyReceiver, refreshing, userHandle);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
        setActiveAdminInternal(policyReceiver, refreshing, userHandle, null);
    }
    /**
     * @hide
     */
    @UnsupportedAppUsage
    public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
        setActiveAdmin(policyReceiver, refreshing, myUserId());
    @TestApi
    @RequiresPermission(allOf = {
            MANAGE_DEVICE_ADMINS,
            INTERACT_ACROSS_USERS_FULL
    })
    @FlaggedApi(Flags.FLAG_PROVISIONING_CONTEXT_PARAMETER)
    public void setActiveAdmin(
            @NonNull ComponentName policyReceiver,
            boolean refreshing,
            int userHandle,
            @Nullable String provisioningContext
    ) {
        setActiveAdminInternal(policyReceiver, refreshing, userHandle, provisioningContext);
    }
    private void setActiveAdminInternal(
            @NonNull ComponentName policyReceiver,
            boolean refreshing,
            int userHandle,
            @Nullable String provisioningContext
    ) {
        if (mService != null) {
            try {
                mService.setActiveAdmin(
                        policyReceiver,
                        refreshing,
                        userHandle,
                        provisioningContext
                );
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
    }
    /**
@@ -9678,7 +9710,7 @@ public class DevicePolicyManager {
        if (mService != null) {
            try {
                final int myUserId = myUserId();
                mService.setActiveAdmin(admin, false, myUserId);
                mService.setActiveAdmin(admin, false, myUserId, null);
                return mService.setProfileOwner(admin, myUserId);
            } catch (RemoteException re) {
                throw re.rethrowFromSystemServer();
+2 −1
Original line number Diff line number Diff line
@@ -160,7 +160,8 @@ interface IDevicePolicyManager {
    void setKeyguardDisabledFeatures(in ComponentName who, String callerPackageName, int which, boolean parent);
    int getKeyguardDisabledFeatures(in ComponentName who, int userHandle, boolean parent);

    void setActiveAdmin(in ComponentName policyReceiver, boolean refreshing, int userHandle);
    void setActiveAdmin(in ComponentName policyReceiver, boolean refreshing,
        int userHandle, String provisioningContext);
    boolean isAdminActive(in ComponentName policyReceiver, int userHandle);
    List<ComponentName> getActiveAdmins(int userHandle);
    @UnsupportedAppUsage
+10 −0
Original line number Diff line number Diff line
@@ -393,3 +393,13 @@ flag {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "provisioning_context_parameter"
    namespace: "enterprise"
    description: "Add provisioningContext to store metadata about when the admin was set"
    bug: "326525847"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+34 −0
Original line number Diff line number Diff line
@@ -182,6 +182,7 @@ class ActiveAdmin {
    private static final String TAG_CREDENTIAL_MANAGER_POLICY = "credential-manager-policy";
    private static final String TAG_DIALER_PACKAGE = "dialer_package";
    private static final String TAG_SMS_PACKAGE = "sms_package";
    private static final String TAG_PROVISIONING_CONTEXT = "provisioning-context";

    // If the ActiveAdmin is a permission-based admin, then info will be null because the
    // permission-based admin is not mapped to a device administrator component.
@@ -359,6 +360,8 @@ class ActiveAdmin {
    int mWifiMinimumSecurityLevel = DevicePolicyManager.WIFI_SECURITY_OPEN;
    String mDialerPackage;
    String mSmsPackage;
    private String mProvisioningContext;
    private static final int PROVISIONING_CONTEXT_LENGTH_LIMIT = 1000;

    ActiveAdmin(DeviceAdminInfo info, boolean isParent) {
        this.userId = -1;
@@ -404,6 +407,23 @@ class ActiveAdmin {
        return UserHandle.of(UserHandle.getUserId(info.getActivityInfo().applicationInfo.uid));
    }

    /**
     * Stores metadata about context of setting an active admin
     * @param provisioningContext some metadata, for example test method name
     */
    public void setProvisioningContext(@Nullable String provisioningContext) {
        if (Flags.provisioningContextParameter()
                && !TextUtils.isEmpty(provisioningContext)
                && !provisioningContext.isBlank()) {
            if (provisioningContext.length() > PROVISIONING_CONTEXT_LENGTH_LIMIT) {
                mProvisioningContext = provisioningContext.substring(
                        0, PROVISIONING_CONTEXT_LENGTH_LIMIT);
            } else {
                mProvisioningContext = provisioningContext;
            }
        }
    }

    void writeToXml(TypedXmlSerializer out)
            throws IllegalArgumentException, IllegalStateException, IOException {
        if (info != null) {
@@ -694,6 +714,12 @@ class ActiveAdmin {
        if (!TextUtils.isEmpty(mSmsPackage)) {
            writeAttributeValueToXml(out, TAG_SMS_PACKAGE, mSmsPackage);
        }

        if (Flags.provisioningContextParameter() && !TextUtils.isEmpty(mProvisioningContext)) {
            out.startTag(null, TAG_PROVISIONING_CONTEXT);
            out.attribute(null, ATTR_VALUE, mProvisioningContext);
            out.endTag(null, TAG_PROVISIONING_CONTEXT);
        }
    }

    private void writePackagePolicy(TypedXmlSerializer out, String tag,
@@ -1006,6 +1032,9 @@ class ActiveAdmin {
                mDialerPackage = parser.getAttributeValue(null, ATTR_VALUE);
            } else if (TAG_SMS_PACKAGE.equals(tag)) {
                mSmsPackage = parser.getAttributeValue(null, ATTR_VALUE);
            } else if (Flags.provisioningContextParameter()
                    && TAG_PROVISIONING_CONTEXT.equals(tag)) {
                mProvisioningContext = parser.getAttributeValue(null, ATTR_VALUE);
            } else {
                Slogf.w(LOG_TAG, "Unknown admin tag: %s", tag);
                XmlUtils.skipCurrentTag(parser);
@@ -1496,5 +1525,10 @@ class ActiveAdmin {
        pw.println(mDialerPackage);
        pw.print("mSmsPackage=");
        pw.println(mSmsPackage);

        if (Flags.provisioningContextParameter()) {
            pw.print("mProvisioningContext=");
            pw.println(mProvisioningContext);
        }
    }
}
Loading