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

Commit 0129e884 authored by Yvonne Jiang's avatar Yvonne Jiang Committed by Android (Google) Code Review
Browse files

Merge "Clear and restore binder calling identity within...

Merge "Clear and restore binder calling identity within SupervisionService#setSupervisionEnabledForUser." into main
parents d3d362dd db38f820
Loading
Loading
Loading
Loading
+38 −30
Original line number Diff line number Diff line
@@ -128,36 +128,6 @@ public class SupervisionService extends ISupervisionManager.Stub {
            enforcePermission(INTERACT_ACROSS_USERS);
        }
        setSupervisionEnabledForUserInternal(userId, enabled, getSystemSupervisionPackage());
        updateWebContentFilters(userId);

        if (Flags.enableSupervisionAppService()) {
            List<AppServiceConnection> connections = getSupervisionAppServiceConnections(userId);
            for (AppServiceConnection conn : connections) {
                String targetPackage = conn.getFinder().getTargetPackage(userId);
                ISupervisionAppService binder = (ISupervisionAppService) conn.getServiceBinder();
                if (binder == null) {
                    Slog.d(
                            LOG_TAG,
                            TextUtils.formatSimple(
                                    "Unable to toggle supervision for package %s. Binder is null.",
                                    targetPackage));
                    continue;
                }
                try {
                    if (enabled) {
                        binder.onEnabled();
                    } else {
                        binder.onDisabled();
                    }
                } catch (RemoteException e) {
                    Slog.d(
                            LOG_TAG,
                            TextUtils.formatSimple(
                                    "Unable to toggle supervision for package %s. e = %s",
                                    targetPackage, e));
                }
            }
        }
    }

    private List<AppServiceConnection> getSupervisionAppServiceConnections(@UserIdInt int userId) {
@@ -335,6 +305,44 @@ public class SupervisionService extends ISupervisionManager.Stub {
            data.supervisionEnabled = enabled;
            data.supervisionAppPackage = enabled ? supervisionAppPackage : null;
        }
        final long token = Binder.clearCallingIdentity();
        try {
            updateWebContentFilters(userId);

            if (Flags.enableSupervisionAppService()) {
                List<AppServiceConnection> connections =
                        getSupervisionAppServiceConnections(userId);
                for (AppServiceConnection conn : connections) {
                    String targetPackage = conn.getFinder().getTargetPackage(userId);
                    ISupervisionAppService binder =
                            (ISupervisionAppService) conn.getServiceBinder();
                    if (binder == null) {
                        Slog.d(
                                LOG_TAG,
                                TextUtils.formatSimple(
                                        "Unable to toggle supervision for package %s. Binder is"
                                                + " null.",
                                        targetPackage));
                        continue;
                    }
                    try {
                        if (enabled) {
                            binder.onEnabled();
                        } else {
                            binder.onDisabled();
                        }
                    } catch (RemoteException e) {
                        Slog.d(
                                LOG_TAG,
                                TextUtils.formatSimple(
                                        "Unable to toggle supervision for package %s. e = %s",
                                        targetPackage, e));
                    }
                }
            }
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }

    /** Updates Web Content Filters when supervision status is updated. */