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

Commit b852e566 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Migrate managed services from setting to policy xml

Change-Id: Ie20f91dbdd0ba6b57b5909cbf0152a32754fe02d
Fixes: 62263757
Test: runtest systemui-notification, cts AudioManagerTest,
cts-verifier DND tests, verify bug reports after toggling
access for various types of managed services, verified
default approved services aren't renabled on boot; verified that
they are reenabled after a device reset, verified that
settings are migrated after a restore from OC backup.
parent 1c75b9c9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5592,6 +5592,7 @@ package android.app {
    method public java.util.List<android.app.NotificationChannelGroup> getNotificationChannelGroups();
    method public java.util.List<android.app.NotificationChannel> getNotificationChannels();
    method public android.app.NotificationManager.Policy getNotificationPolicy();
    method public boolean isNotificationListenerAccessGranted(android.content.ComponentName);
    method public boolean isNotificationPolicyAccessGranted();
    method public void notify(int, android.app.Notification);
    method public void notify(java.lang.String, int, android.app.Notification);
+1 −0
Original line number Diff line number Diff line
@@ -5798,6 +5798,7 @@ package android.app {
    method public java.util.List<android.app.NotificationChannelGroup> getNotificationChannelGroups();
    method public java.util.List<android.app.NotificationChannel> getNotificationChannels();
    method public android.app.NotificationManager.Policy getNotificationPolicy();
    method public boolean isNotificationListenerAccessGranted(android.content.ComponentName);
    method public boolean isNotificationPolicyAccessGranted();
    method public void notify(int, android.app.Notification);
    method public void notify(java.lang.String, int, android.app.Notification);
+2 −1
Original line number Diff line number Diff line
@@ -5606,6 +5606,7 @@ package android.app {
    method public java.util.List<android.app.NotificationChannelGroup> getNotificationChannelGroups();
    method public java.util.List<android.app.NotificationChannel> getNotificationChannels();
    method public android.app.NotificationManager.Policy getNotificationPolicy();
    method public boolean isNotificationListenerAccessGranted(android.content.ComponentName);
    method public boolean isNotificationPolicyAccessGranted();
    method public void notify(int, android.app.Notification);
    method public void notify(java.lang.String, int, android.app.Notification);
@@ -35028,7 +35029,7 @@ package android.provider {
    field public static final java.lang.String DISABLED_PRINT_SERVICES = "disabled_print_services";
    field public static final java.lang.String ENABLED_ACCESSIBILITY_SERVICES = "enabled_accessibility_services";
    field public static final java.lang.String ENABLED_INPUT_METHODS = "enabled_input_methods";
    field public static final java.lang.String ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES = "enabled_notification_policy_access_packages";
    field public static final deprecated java.lang.String ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES = "enabled_notification_policy_access_packages";
    field public static final deprecated java.lang.String HTTP_PROXY = "http_proxy";
    field public static final java.lang.String INPUT_METHOD_SELECTOR_VISIBILITY = "input_method_selector_visibility";
    field public static final deprecated java.lang.String INSTALL_NON_MARKET_APPS = "install_non_market_apps";
+10 −1
Original line number Diff line number Diff line
@@ -116,6 +116,16 @@ interface INotificationManager
    boolean matchesCallFilter(in Bundle extras);
    boolean isSystemConditionProviderEnabled(String path);

    boolean isNotificationListenerAccessGranted(in ComponentName listener);
    boolean isNotificationListenerAccessGrantedForUser(in ComponentName listener, int userId);
    boolean isNotificationAssistantAccessGranted(in ComponentName assistant);
    void setNotificationListenerAccessGranted(in ComponentName listener, boolean enabled);
    void setNotificationAssistantAccessGranted(in ComponentName assistant, boolean enabled);
    void setNotificationListenerAccessGrantedForUser(in ComponentName listener, int userId, boolean enabled);
    void setNotificationAssistantAccessGrantedForUser(in ComponentName assistant, int userId, boolean enabled);
    List<String> getEnabledNotificationListenerPackages();
    List<ComponentName> getEnabledNotificationListeners(int userId);

    int getZenMode();
    ZenModeConfig getZenModeConfig();
    oneway void setZenMode(int mode, in Uri conditionId, String reason);
@@ -123,7 +133,6 @@ interface INotificationManager
    boolean isNotificationPolicyAccessGranted(String pkg);
    NotificationManager.Policy getNotificationPolicy(String pkg);
    void setNotificationPolicy(String pkg, in NotificationManager.Policy policy);
    String[] getPackagesRequestingNotificationPolicyAccess();
    boolean isNotificationPolicyAccessGrantedForPackage(String pkg);
    void setNotificationPolicyAccessGranted(String pkg, boolean granted);
    AutomaticZenRule getAutomaticZenRule(String id);
+71 −18
Original line number Diff line number Diff line
@@ -18,14 +18,12 @@ package android.app;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.app.Notification.Builder;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ParceledListSlice;
import android.graphics.drawable.Icon;
import android.net.Uri;
@@ -33,7 +31,6 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
@@ -41,10 +38,8 @@ import android.os.ServiceManager;
import android.os.StrictMode;
import android.os.UserHandle;
import android.provider.Settings.Global;
import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.StatusBarNotification;
import android.service.notification.ZenModeConfig;
import android.util.ArraySet;
import android.util.Log;

import java.lang.annotation.Retention;
@@ -747,14 +742,14 @@ public class NotificationManager {
    }

    /**
     * Checks the ability to read/modify notification policy for the calling package.
     * Checks the ability to read/modify notification do not disturb policy for the calling package.
     *
     * <p>
     * Returns true if the calling package can read/modify notification policy.
     *
     * <p>
     * Request policy access by sending the user to the activity that matches the system intent
     * action {@link android.provider.Settings#ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS}.
     * Apps can request policy access by sending the user to the activity that matches the system
     * intent action {@link android.provider.Settings#ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS}.
     *
     * <p>
     * Use {@link #ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED} to listen for
@@ -769,6 +764,39 @@ public class NotificationManager {
        }
    }

    /**
     * Checks whether the user has approved a given
     * {@link android.service.notification.NotificationListenerService}.
     *
     * <p>
     * The listener service must belong to the calling app.
     *
     * <p>
     * Apps can request notification listener access by sending the user to the activity that
     * matches the system intent action
     * {@link android.provider.Settings#ACTION_NOTIFICATION_LISTENER_SETTINGS}.
     */
    public boolean isNotificationListenerAccessGranted(ComponentName listener) {
        INotificationManager service = getService();
        try {
            return service.isNotificationListenerAccessGranted(listener);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * @hide
     */
    public boolean isNotificationAssistantAccessGranted(ComponentName assistant) {
        INotificationManager service = getService();
        try {
            return service.isNotificationAssistantAccessGranted(assistant);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** @hide */
    public boolean isNotificationPolicyAccessGrantedForPackage(String pkg) {
        INotificationManager service = getService();
@@ -779,6 +807,18 @@ public class NotificationManager {
        }
    }

    /**
     * @hide
     */
    public List<String> getEnabledNotificationListenerPackages() {
        INotificationManager service = getService();
        try {
            return service.getEnabledNotificationListenerPackages();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Gets the current notification policy.
     *
@@ -825,21 +865,34 @@ public class NotificationManager {
    }

    /** @hide */
    public ArraySet<String> getPackagesRequestingNotificationPolicyAccess() {
    public void setNotificationListenerAccessGranted(ComponentName listener, boolean granted) {
        INotificationManager service = getService();
        try {
            final String[] pkgs = service.getPackagesRequestingNotificationPolicyAccess();
            if (pkgs != null && pkgs.length > 0) {
                final ArraySet<String> rt = new ArraySet<>(pkgs.length);
                for (int i = 0; i < pkgs.length; i++) {
                    rt.add(pkgs[i]);
            service.setNotificationListenerAccessGranted(listener, granted);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
                return rt;
    }

    /** @hide */
    public void setNotificationListenerAccessGrantedForUser(ComponentName listener, int userId,
            boolean granted) {
        INotificationManager service = getService();
        try {
            service.setNotificationListenerAccessGrantedForUser(listener, userId, granted);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** @hide */
    public List<ComponentName> getEnabledNotificationListeners(int userId) {
        INotificationManager service = getService();
        try {
            return service.getEnabledNotificationListeners(userId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        return new ArraySet<>();
    }

    private Context mContext;
Loading