diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/app/INotificationManager.aidl | 2 | ||||
-rw-r--r-- | core/java/android/app/INotificationManagerCallback.aidl | 24 | ||||
-rw-r--r-- | core/java/android/app/NotificationManager.java | 77 | ||||
-rw-r--r-- | core/java/android/provider/Settings.java | 18 | ||||
-rw-r--r-- | core/res/AndroidManifest.xml | 6 | ||||
-rw-r--r-- | core/res/res/values/strings.xml | 5 |
6 files changed, 53 insertions, 79 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index 63ff005..f78fb47 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -17,7 +17,6 @@ package android.app; -import android.app.INotificationManagerCallback; import android.app.ITransientNotification; import android.app.Notification; import android.app.NotificationManager; @@ -87,7 +86,6 @@ interface INotificationManager oneway void setZenMode(int mode, in Uri conditionId, String reason); oneway void notifyConditions(String pkg, in IConditionProvider provider, in Condition[] conditions); oneway void requestZenModeConditions(in IConditionListener callback, int relevance); - oneway void requestNotificationPolicyAccess(String pkg, in INotificationManagerCallback callback); boolean isNotificationPolicyAccessGranted(String pkg); NotificationManager.Policy getNotificationPolicy(String pkg); void setNotificationPolicy(String pkg, in NotificationManager.Policy policy); diff --git a/core/java/android/app/INotificationManagerCallback.aidl b/core/java/android/app/INotificationManagerCallback.aidl deleted file mode 100644 index 9929745..0000000 --- a/core/java/android/app/INotificationManagerCallback.aidl +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) 2015, The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.app; - -import android.app.NotificationManager; - -/** @hide */ -oneway interface INotificationManagerCallback { - void onPolicyRequestResult(boolean granted); -} diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java index 557964b..0904e21 100644 --- a/core/java/android/app/NotificationManager.java +++ b/core/java/android/app/NotificationManager.java @@ -101,6 +101,16 @@ public class NotificationManager = "android.os.action.ACTION_EFFECTS_SUPPRESSOR_CHANGED"; /** + * Intent that is broadcast when the state of {@link #isNotificationPolicyAccessGranted()} + * changes. + * + * This broadcast is only sent to registered receivers, and only to the apps that have changed. + */ + @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) + public static final String ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED + = "android.app.action.NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED"; + + /** * Intent that is broadcast when the state of getNotificationPolicy() changes. * This broadcast is only sent to registered receivers. */ @@ -403,55 +413,18 @@ public class NotificationManager } /** - * Requests the ability to read/modify notification policy for the calling package. - * - * @param callback required, used to receive the granted or the denied signal. - * @param handler The handler used when receiving the result. - * If null, the current thread is used. - */ - public void requestPolicyAccess(@NonNull final NotificationPolicyAccessRequestCallback callback, - @Nullable Handler handler) { - checkRequired("callback", callback); - final Handler h = handler != null ? handler : new Handler(); - INotificationManager service = getService(); - try { - service.requestNotificationPolicyAccess(mContext.getOpPackageName(), - new INotificationManagerCallback.Stub() { - @Override - public void onPolicyRequestResult(final boolean granted) throws RemoteException { - h.post(new Runnable() { - @Override - public void run() { - if (granted) { - callback.onAccessGranted(); - } else { - callback.onAccessDenied(); - } - } - }); - } - }); - } catch (RemoteException e) { - } - } - - /** Callback for receiving the result of a policy access request. */ - public static abstract class NotificationPolicyAccessRequestCallback { - /** - * Received if the request was granted for this package. - */ - public abstract void onAccessGranted(); - - /** - * Received if the request was denied for this package. - */ - public abstract void onAccessDenied(); - } - - /** * Checks the ability to read/modify notification 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}. + * + * <p> + * Use {@link #ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED} to listen for + * user grant or denial of this access. */ public boolean isNotificationPolicyAccessGranted() { INotificationManager service = getService(); @@ -476,7 +449,8 @@ public class NotificationManager * Gets the current notification policy. * * <p> - * Only available if policy access is granted. + * Only available if policy access is granted to this package. + * See {@link #isNotificationPolicyAccessGranted}. */ public Policy getNotificationPolicy() { INotificationManager service = getService(); @@ -491,7 +465,8 @@ public class NotificationManager * Sets the current notification policy. * * <p> - * Only available if policy access is granted. + * Only available if policy access is granted to this package. + * See {@link #isNotificationPolicyAccessGranted}. * * @param policy The new desired policy. */ @@ -716,7 +691,8 @@ public class NotificationManager * unavailable. * * <p> - * Only available if policy access is granted. + * Only available if policy access is granted to this package. + * See {@link #isNotificationPolicyAccessGranted}. */ public final int getCurrentInterruptionFilter() { final INotificationManager service = getService(); @@ -738,7 +714,8 @@ public class NotificationManager * unavailable. * * <p> - * Only available if policy access is granted. + * Only available if policy access is granted to this package. + * See {@link #isNotificationPolicyAccessGranted}. */ public final void setInterruptionFilter(int interruptionFilter) { final INotificationManager service = getService(); diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 37645b5..cac4a53 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -811,14 +811,17 @@ public final class Settings { /** * Activity Action: Show Do Not Disturb access settings. * <p> - * In some cases, a matching Activity may not exist, so ensure you safeguard against this. + * Users can grant and deny access to Do Not Disturb configuration from here. + * See {@link android.app.NotificationManager#isNotificationPolicyAccessGranted()} for more + * details. * <p> * Input: Nothing. * <p> * Output: Nothing. */ @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) - public static final String ACTION_ZEN_ACCESS_SETTINGS = "android.settings.ZEN_ACCESS_SETTINGS"; + public static final String ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS + = "android.settings.NOTIFICATION_POLICY_ACCESS_SETTINGS"; /** * @hide @@ -5425,7 +5428,7 @@ public final class Settings { public static final String ASSIST_STRUCTURE_ENABLED = "assist_structure_enabled"; /** - * Names of the packages that the current user has explicitly allowed to + * Names of the service components that the current user has explicitly allowed to * see all of the user's notifications, separated by ':'. * * @hide @@ -5433,6 +5436,15 @@ public final class Settings { public static final String ENABLED_NOTIFICATION_LISTENERS = "enabled_notification_listeners"; /** + * Names of the packages that the current user has explicitly allowed to + * manage notification policy configuration, separated by ':'. + * + * @hide + */ + public static final String ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES = + "enabled_notification_policy_access_packages"; + + /** * @hide */ public static final String ENABLED_CONDITION_PROVIDERS = "enabled_condition_providers"; diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 8accc0a..f32918d 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -2326,6 +2326,12 @@ <permission android:name="android.permission.ACCESS_NOTIFICATIONS" android:protectionLevel="signature|system" /> + <!-- Marker permission for applications that wish to access notification policy. --> + <permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" + android:description="@string/permdesc_access_notification_policy" + android:label="@string/permlab_access_notification_policy" + android:protectionLevel="normal" /> + <!-- Allows access to keyguard secure storage. Only allowed for system processes. @hide --> <permission android:name="android.permission.ACCESS_KEYGUARD_SECURE_STORAGE" diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index a2f8918..3f828e7 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -1435,6 +1435,11 @@ <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. --> <string name="permdesc_bindCarrierServices">Allows the holder to bind to carrier services. Should never be needed for normal apps.</string> + <!-- Title of an application permission, for applications that wish to access notification policy. --> + <string name="permlab_access_notification_policy">access Do Not Disturb</string> + <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. --> + <string name="permdesc_access_notification_policy">Allows the app to read and write Do Not Disturb configuration.</string> + <!-- Policy administration --> <!-- Title of policy access to limiting the user's password choices --> |