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

Commit db38f820 authored by Yvonne Jiang's avatar Yvonne Jiang
Browse files

Clear and restore binder calling identity within SupervisionService#setSupervisionEnabledForUser.

Bug: 413146336
Flag: android.app.supervision.flags.supervision_manager_apis
Change-Id: I8810f251e6ee083f8fda76767049e3bfa31a2a99
parent 9c73c416
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) {
@@ -328,6 +298,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. */