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

Commit e539379e authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Add separate clear method for audit log callback

Currently clients have to provide an executor even when callback is null
which doesn't make any sense. With this CL both executor and callback
are non-nullable, and instead a separate clearing method is added.

+ also add 'throw' before rethrowFromSystemServer

Bug: 295324350
Test: atest CtsDevicePolicyTestCases:SecurityLoggingTest
Change-Id: I2262a7c2d8d433220bca125570aa04dd5c1c7df7
parent 6c29e1ea
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1307,6 +1307,7 @@ package android.app.admin {
  public class DevicePolicyManager {
    method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public int checkProvisioningPrecondition(@NonNull String, @NonNull String);
    method @FlaggedApi("android.app.admin.flags.security_log_v2_enabled") @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_POLICY_AUDIT_LOGGING) public void clearAuditLogEventCallback();
    method @Nullable @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public android.os.UserHandle createAndProvisionManagedProfile(@NonNull android.app.admin.ManagedProfileProvisioningParams) throws android.app.admin.ProvisioningException;
    method @Nullable public android.content.Intent createProvisioningIntentFromNfcIntent(@NonNull android.content.Intent);
    method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public void finalizeWorkProfileProvisioning(@NonNull android.os.UserHandle, @Nullable android.accounts.Account);
@@ -1343,7 +1344,7 @@ package android.app.admin {
    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_DEVICE_POLICY_APP_EXEMPTIONS) public void setApplicationExemptions(@NonNull String, @NonNull java.util.Set<java.lang.Integer>) throws android.content.pm.PackageManager.NameNotFoundException;
    method @FlaggedApi("android.app.admin.flags.security_log_v2_enabled") @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_POLICY_AUDIT_LOGGING) public void setAuditLogEnabled(boolean);
    method @FlaggedApi("android.app.admin.flags.security_log_v2_enabled") @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_POLICY_AUDIT_LOGGING) public void setAuditLogEventCallback(@NonNull java.util.concurrent.Executor, @Nullable java.util.function.Consumer<java.util.List<android.app.admin.SecurityLog.SecurityEvent>>);
    method @FlaggedApi("android.app.admin.flags.security_log_v2_enabled") @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_POLICY_AUDIT_LOGGING) public void setAuditLogEventCallback(@NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.util.List<android.app.admin.SecurityLog.SecurityEvent>>);
    method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public void setDeviceProvisioningConfigApplied();
    method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public void setDpcDownloaded(boolean);
    method @FlaggedApi("android.app.admin.flags.device_policy_size_tracking_enabled") @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public void setMaxPolicyStorageLimit(int);
+25 −10
Original line number Diff line number Diff line
@@ -14090,9 +14090,7 @@ public class DevicePolicyManager {
        try {
            return mService.isAuditLogEnabled(mContext.getPackageName());
        } catch (RemoteException re) {
            re.rethrowFromSystemServer();
            // unreachable
            return false;
            throw re.rethrowFromSystemServer();
        }
    }
@@ -14102,8 +14100,8 @@ public class DevicePolicyManager {
     * is enforced by the caller. Disabling the policy clears the callback. Each time a new callback
     * is set, it will first be invoked with all the audit log events available at the time.
     *
     * @param callback callback to invoke when new audit log events become available or {@code null}
     *                 to clear the callback.
     * @param callback The callback to invoke when new audit log events become available.
     * @param executor The executor through which the callback should be invoked.
     * @hide
     */
    @SystemApi
@@ -14111,11 +14109,10 @@ public class DevicePolicyManager {
    @RequiresPermission(permission.MANAGE_DEVICE_POLICY_AUDIT_LOGGING)
    public void setAuditLogEventCallback(
            @NonNull @CallbackExecutor Executor executor,
            @Nullable Consumer<List<SecurityEvent>> callback) {
            @NonNull Consumer<List<SecurityEvent>> callback) {
        throwIfParentInstance("setAuditLogEventCallback");
        final IAuditLogEventsCallback wrappedCallback = callback == null
                ? null
                : new IAuditLogEventsCallback.Stub() {
        final IAuditLogEventsCallback wrappedCallback =
                new IAuditLogEventsCallback.Stub() {
                    @Override
                    public void onNewAuditLogEvents(List<SecurityEvent> events) {
                        executor.execute(() -> callback.accept(events));
@@ -14124,7 +14121,25 @@ public class DevicePolicyManager {
        try {
            mService.setAuditLogEventsCallback(mContext.getPackageName(), wrappedCallback);
        } catch (RemoteException re) {
            re.rethrowFromSystemServer();
            throw re.rethrowFromSystemServer();
        }
    }
    /**
     * Clears audit log event callback. If a callback was set previously, it may still get invoked
     * after this call returns if it was already scheduled.
     *
     * @hide
     */
    @SystemApi
    @FlaggedApi(FLAG_SECURITY_LOG_V2_ENABLED)
    @RequiresPermission(permission.MANAGE_DEVICE_POLICY_AUDIT_LOGGING)
    public void clearAuditLogEventCallback() {
        throwIfParentInstance("clearAuditLogEventCallback");
        try {
            mService.setAuditLogEventsCallback(mContext.getPackageName(), null);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }