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

Commit f505e786 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix DreamManagerService dream validation in HSUM" into main

parents 20674d8f 75c7547b
Loading
Loading
Loading
Loading
+9 −8
Original line number Original line Diff line number Diff line
@@ -605,7 +605,7 @@ public final class DreamManagerService extends SystemService {
    private ComponentName chooseDreamForUser(boolean doze, int userId) {
    private ComponentName chooseDreamForUser(boolean doze, int userId) {
        if (doze) {
        if (doze) {
            ComponentName dozeComponent = getDozeComponent(userId);
            ComponentName dozeComponent = getDozeComponent(userId);
            return validateDream(dozeComponent) ? dozeComponent : null;
            return validateDream(dozeComponent, userId) ? dozeComponent : null;
        }
        }


        if (mSystemDreamComponent != null) {
        if (mSystemDreamComponent != null) {
@@ -616,11 +616,11 @@ public final class DreamManagerService extends SystemService {
        return dreams != null && dreams.length != 0 ? dreams[0] : null;
        return dreams != null && dreams.length != 0 ? dreams[0] : null;
    }
    }


    private boolean validateDream(ComponentName component) {
    private boolean validateDream(ComponentName component, int userId) {
        if (component == null) return false;
        if (component == null) return false;
        final ServiceInfo serviceInfo = getServiceInfo(component);
        final ServiceInfo serviceInfo = getServiceInfo(component, userId);
        if (serviceInfo == null) {
        if (serviceInfo == null) {
            Slog.w(TAG, "Dream " + component + " does not exist");
            Slog.w(TAG, "Dream " + component + " does not exist on user " + userId);
            return false;
            return false;
        } else if (serviceInfo.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP
        } else if (serviceInfo.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP
                && !BIND_DREAM_SERVICE.equals(serviceInfo.permission)) {
                && !BIND_DREAM_SERVICE.equals(serviceInfo.permission)) {
@@ -647,7 +647,7 @@ public final class DreamManagerService extends SystemService {
        List<ComponentName> validComponents = new ArrayList<>();
        List<ComponentName> validComponents = new ArrayList<>();
        if (components != null) {
        if (components != null) {
            for (ComponentName component : components) {
            for (ComponentName component : components) {
                if (validateDream(component)) {
                if (validateDream(component, userId)) {
                    validComponents.add(component);
                    validComponents.add(component);
                }
                }
            }
            }
@@ -718,9 +718,10 @@ public final class DreamManagerService extends SystemService {
        return userId == mainUserId;
        return userId == mainUserId;
    }
    }


    private ServiceInfo getServiceInfo(ComponentName name) {
    private ServiceInfo getServiceInfo(ComponentName name, int userId) {
        final Context userContext = mContext.createContextAsUser(UserHandle.of(userId), 0);
        try {
        try {
            return name != null ? mContext.getPackageManager().getServiceInfo(name,
            return name != null ? userContext.getPackageManager().getServiceInfo(name,
                    PackageManager.MATCH_DEBUG_TRIAGED_MISSING) : null;
                    PackageManager.MATCH_DEBUG_TRIAGED_MISSING) : null;
        } catch (NameNotFoundException e) {
        } catch (NameNotFoundException e) {
            return null;
            return null;
@@ -813,7 +814,7 @@ public final class DreamManagerService extends SystemService {


    private void writePulseGestureEnabled() {
    private void writePulseGestureEnabled() {
        ComponentName name = getDozeComponent();
        ComponentName name = getDozeComponent();
        boolean dozeEnabled = validateDream(name);
        boolean dozeEnabled = validateDream(name, ActivityManager.getCurrentUser());
        LocalServices.getService(InputManagerInternal.class).setPulseGestureEnabled(dozeEnabled);
        LocalServices.getService(InputManagerInternal.class).setPulseGestureEnabled(dozeEnabled);
    }
    }