John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 2014, The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.notification; |
| 18 | |
Julia Reynolds | 3ec9330 | 2019-07-11 15:27:31 -0400 | [diff] [blame] | 19 | import static android.app.NotificationManager.AUTOMATIC_RULE_STATUS_DISABLED; |
| 20 | import static android.app.NotificationManager.AUTOMATIC_RULE_STATUS_ENABLED; |
| 21 | import static android.app.NotificationManager.AUTOMATIC_RULE_STATUS_REMOVED; |
Julia Reynolds | 8f5dabd | 2020-02-19 08:42:07 -0500 | [diff] [blame] | 22 | import static android.app.NotificationManager.Policy.PRIORITY_SENDERS_ANY; |
Chris Wren | 9316569 | 2020-05-15 16:12:41 -0400 | [diff] [blame] | 23 | import static android.service.notification.DNDModeProto.ROOT_CONFIG; |
| 24 | |
| 25 | import static com.android.internal.util.FrameworkStatsLog.ANNOTATION_ID_IS_UID; |
| 26 | import static com.android.internal.util.FrameworkStatsLog.DND_MODE_RULE; |
Julia Reynolds | 3ec9330 | 2019-07-11 15:27:31 -0400 | [diff] [blame] | 27 | |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 28 | import android.app.AppOpsManager; |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 29 | import android.app.AutomaticZenRule; |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 30 | import android.app.Notification; |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 31 | import android.app.NotificationManager; |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 32 | import android.app.NotificationManager.Policy; |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 33 | import android.app.PendingIntent; |
John Spurlock | 312d1d0 | 2014-07-08 10:24:57 -0400 | [diff] [blame] | 34 | import android.content.ComponentName; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 35 | import android.content.ContentResolver; |
| 36 | import android.content.Context; |
Julia Reynolds | 0ae2b0b | 2016-01-14 09:58:03 -0500 | [diff] [blame] | 37 | import android.content.Intent; |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 38 | import android.content.pm.ActivityInfo; |
| 39 | import android.content.pm.PackageItemInfo; |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 40 | import android.content.pm.PackageManager; |
Julia Reynolds | 0ae2b0b | 2016-01-14 09:58:03 -0500 | [diff] [blame] | 41 | import android.content.pm.ResolveInfo; |
| 42 | import android.content.pm.ServiceInfo; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 43 | import android.content.res.Resources; |
| 44 | import android.content.res.XmlResourceParser; |
| 45 | import android.database.ContentObserver; |
Julia Reynolds | 9aa1c9e | 2018-04-09 11:31:15 -0400 | [diff] [blame] | 46 | import android.graphics.drawable.Icon; |
Jean-Michel Trivi | e743bda | 2016-09-09 11:56:48 -0700 | [diff] [blame] | 47 | import android.media.AudioAttributes; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 48 | import android.media.AudioManager; |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 49 | import android.media.AudioManagerInternal; |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 50 | import android.media.AudioSystem; |
John Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 51 | import android.media.VolumePolicy; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 52 | import android.net.Uri; |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 53 | import android.os.Binder; |
John Spurlock | 2b122f4 | 2014-08-27 16:29:47 -0400 | [diff] [blame] | 54 | import android.os.Bundle; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 55 | import android.os.Handler; |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 56 | import android.os.Looper; |
| 57 | import android.os.Message; |
Julia Reynolds | c8e54e8 | 2015-11-30 16:43:05 -0500 | [diff] [blame] | 58 | import android.os.Process; |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 59 | import android.os.SystemClock; |
John Spurlock | b5e767b | 2014-07-27 11:53:20 -0400 | [diff] [blame] | 60 | import android.os.UserHandle; |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 61 | import android.provider.Settings; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 62 | import android.provider.Settings.Global; |
Julia Reynolds | 520df6e | 2017-02-13 09:05:10 -0500 | [diff] [blame] | 63 | import android.service.notification.Condition; |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 64 | import android.service.notification.ConditionProviderService; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 65 | import android.service.notification.ZenModeConfig; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 66 | import android.service.notification.ZenModeConfig.ZenRule; |
Julia Reynolds | 520df6e | 2017-02-13 09:05:10 -0500 | [diff] [blame] | 67 | import android.service.notification.ZenModeProto; |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 68 | import android.service.notification.ZenPolicy; |
Julia Reynolds | 87c4277 | 2016-05-16 09:52:17 -0400 | [diff] [blame] | 69 | import android.util.AndroidRuntimeException; |
Beverly | 4e2f76c | 2018-03-16 15:43:49 -0400 | [diff] [blame] | 70 | import android.util.ArrayMap; |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 71 | import android.util.Log; |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 72 | import android.util.Slog; |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 73 | import android.util.SparseArray; |
Chris Wren | 9316569 | 2020-05-15 16:12:41 -0400 | [diff] [blame] | 74 | import android.util.StatsEvent; |
Julia Reynolds | 520df6e | 2017-02-13 09:05:10 -0500 | [diff] [blame] | 75 | import android.util.proto.ProtoOutputStream; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 76 | |
| 77 | import com.android.internal.R; |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 78 | import com.android.internal.annotations.VisibleForTesting; |
John Spurlock | 25d01ee | 2015-06-03 12:17:46 -0400 | [diff] [blame] | 79 | import com.android.internal.logging.MetricsLogger; |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 80 | import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; |
| 81 | import com.android.internal.notification.SystemNotificationChannels; |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 82 | import com.android.server.LocalServices; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 83 | |
| 84 | import libcore.io.IoUtils; |
| 85 | |
| 86 | import org.xmlpull.v1.XmlPullParser; |
| 87 | import org.xmlpull.v1.XmlPullParserException; |
| 88 | import org.xmlpull.v1.XmlSerializer; |
| 89 | |
| 90 | import java.io.IOException; |
| 91 | import java.io.PrintWriter; |
John Spurlock | 1c923a3 | 2014-04-27 16:42:29 -0400 | [diff] [blame] | 92 | import java.util.ArrayList; |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 93 | import java.util.List; |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 94 | import java.util.Objects; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * NotificationManagerService helper for functionality related to zen mode. |
| 98 | */ |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 99 | public class ZenModeHelper { |
| 100 | static final String TAG = "ZenModeHelper"; |
| 101 | static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 102 | |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 103 | // The amount of time rules instances can exist without their owning app being installed. |
| 104 | private static final int RULE_INSTANCE_GRACE_PERIOD = 1000 * 60 * 60 * 72; |
| 105 | |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 106 | private final Context mContext; |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 107 | private final H mHandler; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 108 | private final SettingsObserver mSettingsObserver; |
Julia Reynolds | e99db5a | 2019-04-16 12:50:04 -0400 | [diff] [blame] | 109 | private final AppOpsManager mAppOps; |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 110 | @VisibleForTesting protected final NotificationManager mNotificationManager; |
Chris Wren | 9316569 | 2020-05-15 16:12:41 -0400 | [diff] [blame] | 111 | private final SysUiStatsEvent.BuilderFactory mStatsEventBuilderFactory; |
Beverly | 49ba9a6 | 2018-11-02 13:19:31 -0400 | [diff] [blame] | 112 | @VisibleForTesting protected ZenModeConfig mDefaultConfig; |
John Spurlock | 1c923a3 | 2014-04-27 16:42:29 -0400 | [diff] [blame] | 113 | private final ArrayList<Callback> mCallbacks = new ArrayList<Callback>(); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 114 | private final ZenModeFiltering mFiltering; |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 115 | protected final RingerModeDelegate mRingerModeDelegate = new |
| 116 | RingerModeDelegate(); |
Beverly | 2f43b64 | 2018-08-14 09:43:11 -0400 | [diff] [blame] | 117 | @VisibleForTesting protected final ZenModeConditions mConditions; |
Annie Meng | 8b646fd | 2019-02-01 18:46:42 +0000 | [diff] [blame] | 118 | @VisibleForTesting final SparseArray<ZenModeConfig> mConfigs = new SparseArray<>(); |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 119 | private final Metrics mMetrics = new Metrics(); |
Julia Reynolds | 0ae2b0b | 2016-01-14 09:58:03 -0500 | [diff] [blame] | 120 | private final ConditionProviders.Config mServiceConfig; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 121 | |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 122 | @VisibleForTesting protected int mZenMode; |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 123 | @VisibleForTesting protected NotificationManager.Policy mConsolidatedPolicy; |
Xiaohui Chen | ddbe4ca | 2015-08-13 16:20:56 -0700 | [diff] [blame] | 124 | private int mUser = UserHandle.USER_SYSTEM; |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 125 | @VisibleForTesting protected ZenModeConfig mConfig; |
Beverly | 85f5241 | 2018-02-27 10:41:13 -0500 | [diff] [blame] | 126 | @VisibleForTesting protected AudioManagerInternal mAudioManager; |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 127 | protected PackageManager mPm; |
Bryce Lee | 7219ada | 2016-04-08 10:54:23 -0700 | [diff] [blame] | 128 | private long mSuppressedEffects; |
| 129 | |
| 130 | public static final long SUPPRESSED_EFFECT_NOTIFICATIONS = 1; |
| 131 | public static final long SUPPRESSED_EFFECT_CALLS = 1 << 1; |
| 132 | public static final long SUPPRESSED_EFFECT_ALL = SUPPRESSED_EFFECT_CALLS |
| 133 | | SUPPRESSED_EFFECT_NOTIFICATIONS; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 134 | |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 135 | @VisibleForTesting protected boolean mIsBootComplete; |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 136 | |
Julia Reynolds | e99db5a | 2019-04-16 12:50:04 -0400 | [diff] [blame] | 137 | private String[] mPriorityOnlyDndExemptPackages; |
| 138 | |
Chris Wren | 9316569 | 2020-05-15 16:12:41 -0400 | [diff] [blame] | 139 | public ZenModeHelper(Context context, Looper looper, ConditionProviders conditionProviders, |
| 140 | SysUiStatsEvent.BuilderFactory statsEventBuilderFactory) { |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 141 | mContext = context; |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 142 | mHandler = new H(looper); |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 143 | addCallback(mMetrics); |
Julia Reynolds | e99db5a | 2019-04-16 12:50:04 -0400 | [diff] [blame] | 144 | mAppOps = context.getSystemService(AppOpsManager.class); |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 145 | mNotificationManager = context.getSystemService(NotificationManager.class); |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 146 | |
Beverly | f3b92d2 | 2018-09-18 15:13:17 -0400 | [diff] [blame] | 147 | mDefaultConfig = readDefaultConfig(mContext.getResources()); |
| 148 | updateDefaultAutomaticRuleNames(); |
| 149 | mConfig = mDefaultConfig.copy(); |
Xiaohui Chen | ddbe4ca | 2015-08-13 16:20:56 -0700 | [diff] [blame] | 150 | mConfigs.put(UserHandle.USER_SYSTEM, mConfig); |
Beverly | 430b71a | 2020-03-16 14:17:31 -0400 | [diff] [blame] | 151 | mConsolidatedPolicy = mConfig.toNotificationPolicy(); |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 152 | |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 153 | mSettingsObserver = new SettingsObserver(mHandler); |
| 154 | mSettingsObserver.observe(); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 155 | mFiltering = new ZenModeFiltering(mContext); |
| 156 | mConditions = new ZenModeConditions(this, conditionProviders); |
Julia Reynolds | 0ae2b0b | 2016-01-14 09:58:03 -0500 | [diff] [blame] | 157 | mServiceConfig = conditionProviders.getConfig(); |
Chris Wren | 9316569 | 2020-05-15 16:12:41 -0400 | [diff] [blame] | 158 | mStatsEventBuilderFactory = statsEventBuilderFactory; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 159 | } |
| 160 | |
John Spurlock | 1b8b22b | 2015-05-20 09:47:13 -0400 | [diff] [blame] | 161 | public Looper getLooper() { |
| 162 | return mHandler.getLooper(); |
| 163 | } |
| 164 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 165 | @Override |
| 166 | public String toString() { |
| 167 | return TAG; |
| 168 | } |
| 169 | |
| 170 | public boolean matchesCallFilter(UserHandle userHandle, Bundle extras, |
| 171 | ValidateNotificationPeople validator, int contactsTimeoutMs, float timeoutAffinity) { |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 172 | synchronized (mConfig) { |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 173 | return ZenModeFiltering.matchesCallFilter(mContext, mZenMode, mConsolidatedPolicy, |
| 174 | userHandle, extras, validator, contactsTimeoutMs, timeoutAffinity); |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 175 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | public boolean isCall(NotificationRecord record) { |
| 179 | return mFiltering.isCall(record); |
| 180 | } |
| 181 | |
Julia Reynolds | c6b371b | 2016-06-14 08:31:03 -0400 | [diff] [blame] | 182 | public void recordCaller(NotificationRecord record) { |
| 183 | mFiltering.recordCall(record); |
| 184 | } |
| 185 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 186 | public boolean shouldIntercept(NotificationRecord record) { |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 187 | synchronized (mConfig) { |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 188 | return mFiltering.shouldIntercept(mZenMode, mConsolidatedPolicy, record); |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 189 | } |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 190 | } |
| 191 | |
John Spurlock | 1c923a3 | 2014-04-27 16:42:29 -0400 | [diff] [blame] | 192 | public void addCallback(Callback callback) { |
| 193 | mCallbacks.add(callback); |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 194 | } |
| 195 | |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 196 | public void removeCallback(Callback callback) { |
| 197 | mCallbacks.remove(callback); |
| 198 | } |
| 199 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 200 | public void initZenMode() { |
| 201 | if (DEBUG) Log.d(TAG, "initZenMode"); |
| 202 | evaluateZenMode("init", true /*setRingerMode*/); |
| 203 | } |
| 204 | |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 205 | public void onSystemReady() { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 206 | if (DEBUG) Log.d(TAG, "onSystemReady"); |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 207 | mAudioManager = LocalServices.getService(AudioManagerInternal.class); |
| 208 | if (mAudioManager != null) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 209 | mAudioManager.setRingerModeDelegate(mRingerModeDelegate); |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 210 | } |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 211 | mPm = mContext.getPackageManager(); |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 212 | mHandler.postMetricsTimer(); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 213 | cleanUpZenRules(); |
Julia Reynolds | 8ac6303 | 2015-08-31 15:19:43 -0400 | [diff] [blame] | 214 | evaluateZenMode("onSystemReady", true); |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 215 | mIsBootComplete = true; |
| 216 | showZenUpgradeNotification(mZenMode); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 217 | } |
| 218 | |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 219 | public void onUserSwitched(int user) { |
Julia Reynolds | a3dcaff | 2016-02-03 15:04:05 -0500 | [diff] [blame] | 220 | loadConfigForUser(user, "onUserSwitched"); |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | public void onUserRemoved(int user) { |
Xiaohui Chen | ddbe4ca | 2015-08-13 16:20:56 -0700 | [diff] [blame] | 224 | if (user < UserHandle.USER_SYSTEM) return; |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 225 | if (DEBUG) Log.d(TAG, "onUserRemoved u=" + user); |
| 226 | mConfigs.remove(user); |
| 227 | } |
| 228 | |
Julia Reynolds | a3dcaff | 2016-02-03 15:04:05 -0500 | [diff] [blame] | 229 | public void onUserUnlocked(int user) { |
| 230 | loadConfigForUser(user, "onUserUnlocked"); |
| 231 | } |
| 232 | |
Julia Reynolds | e99db5a | 2019-04-16 12:50:04 -0400 | [diff] [blame] | 233 | void setPriorityOnlyDndExemptPackages(String[] packages) { |
| 234 | mPriorityOnlyDndExemptPackages = packages; |
| 235 | } |
| 236 | |
Julia Reynolds | a3dcaff | 2016-02-03 15:04:05 -0500 | [diff] [blame] | 237 | private void loadConfigForUser(int user, String reason) { |
| 238 | if (mUser == user || user < UserHandle.USER_SYSTEM) return; |
| 239 | mUser = user; |
| 240 | if (DEBUG) Log.d(TAG, reason + " u=" + user); |
| 241 | ZenModeConfig config = mConfigs.get(user); |
| 242 | if (config == null) { |
| 243 | if (DEBUG) Log.d(TAG, reason + " generating default config for user " + user); |
| 244 | config = mDefaultConfig.copy(); |
| 245 | config.user = user; |
| 246 | } |
| 247 | synchronized (mConfig) { |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 248 | setConfigLocked(config, null, reason); |
Julia Reynolds | a3dcaff | 2016-02-03 15:04:05 -0500 | [diff] [blame] | 249 | } |
| 250 | cleanUpZenRules(); |
| 251 | } |
| 252 | |
Christoph Studer | 85a384b | 2014-08-27 20:16:15 +0200 | [diff] [blame] | 253 | public int getZenModeListenerInterruptionFilter() { |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 254 | return NotificationManager.zenModeToInterruptionFilter(mZenMode); |
John Spurlock | d8afe3c | 2014-08-01 14:04:07 -0400 | [diff] [blame] | 255 | } |
| 256 | |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 257 | public void requestFromListener(ComponentName name, int filter) { |
| 258 | final int newZen = NotificationManager.zenModeFromInterruptionFilter(filter, -1); |
John Spurlock | d8afe3c | 2014-08-01 14:04:07 -0400 | [diff] [blame] | 259 | if (newZen != -1) { |
Julia Reynolds | 44ad6ff | 2016-07-06 09:47:45 -0400 | [diff] [blame] | 260 | setManualZenMode(newZen, null, name != null ? name.getPackageName() : null, |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 261 | "listener:" + (name != null ? name.flattenToShortString() : null)); |
John Spurlock | d8afe3c | 2014-08-01 14:04:07 -0400 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
Bryce Lee | 7219ada | 2016-04-08 10:54:23 -0700 | [diff] [blame] | 265 | public void setSuppressedEffects(long suppressedEffects) { |
| 266 | if (mSuppressedEffects == suppressedEffects) return; |
| 267 | mSuppressedEffects = suppressedEffects; |
John Spurlock | 8403b75 | 2014-12-10 12:47:01 -0500 | [diff] [blame] | 268 | applyRestrictions(); |
| 269 | } |
| 270 | |
Bryce Lee | 7219ada | 2016-04-08 10:54:23 -0700 | [diff] [blame] | 271 | public long getSuppressedEffects() { |
| 272 | return mSuppressedEffects; |
| 273 | } |
| 274 | |
John Spurlock | 1c923a3 | 2014-04-27 16:42:29 -0400 | [diff] [blame] | 275 | public int getZenMode() { |
| 276 | return mZenMode; |
| 277 | } |
| 278 | |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 279 | public List<ZenRule> getZenRules() { |
| 280 | List<ZenRule> rules = new ArrayList<>(); |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 281 | synchronized (mConfig) { |
| 282 | if (mConfig == null) return rules; |
| 283 | for (ZenRule rule : mConfig.automaticRules.values()) { |
| 284 | if (canManageAutomaticZenRule(rule)) { |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 285 | rules.add(rule); |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 286 | } |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | return rules; |
| 290 | } |
| 291 | |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 292 | public AutomaticZenRule getAutomaticZenRule(String id) { |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 293 | ZenRule rule; |
| 294 | synchronized (mConfig) { |
| 295 | if (mConfig == null) return null; |
| 296 | rule = mConfig.automaticRules.get(id); |
| 297 | } |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 298 | if (rule == null) return null; |
| 299 | if (canManageAutomaticZenRule(rule)) { |
| 300 | return createAutomaticZenRule(rule); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 301 | } |
| 302 | return null; |
| 303 | } |
| 304 | |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 305 | public String addAutomaticZenRule(AutomaticZenRule automaticZenRule, String reason) { |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 306 | if (!isSystemRule(automaticZenRule)) { |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 307 | PackageItemInfo component = getServiceInfo(automaticZenRule.getOwner()); |
| 308 | if (component == null) { |
| 309 | component = getActivityInfo(automaticZenRule.getConfigurationActivity()); |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 310 | } |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 311 | if (component == null) { |
| 312 | throw new IllegalArgumentException("Lacking enabled CPS or config activity"); |
| 313 | } |
Julia Reynolds | 7f2f441 | 2016-03-01 12:33:48 -0500 | [diff] [blame] | 314 | int ruleInstanceLimit = -1; |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 315 | if (component.metaData != null) { |
| 316 | ruleInstanceLimit = component.metaData.getInt( |
Julia Reynolds | 7f2f441 | 2016-03-01 12:33:48 -0500 | [diff] [blame] | 317 | ConditionProviderService.META_DATA_RULE_INSTANCE_LIMIT, -1); |
| 318 | } |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 319 | int newRuleInstanceCount = getCurrentInstanceCount(automaticZenRule.getOwner()) |
| 320 | + getCurrentInstanceCount(automaticZenRule.getConfigurationActivity()) |
| 321 | + 1; |
| 322 | if (ruleInstanceLimit > 0 && ruleInstanceLimit < newRuleInstanceCount) { |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 323 | throw new IllegalArgumentException("Rule instance limit exceeded"); |
| 324 | } |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 325 | |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 326 | } |
| 327 | |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 328 | ZenModeConfig newConfig; |
| 329 | synchronized (mConfig) { |
Julia Reynolds | 87c4277 | 2016-05-16 09:52:17 -0400 | [diff] [blame] | 330 | if (mConfig == null) { |
| 331 | throw new AndroidRuntimeException("Could not create rule"); |
| 332 | } |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 333 | if (DEBUG) { |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 334 | Log.d(TAG, "addAutomaticZenRule rule= " + automaticZenRule + " reason=" + reason); |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 335 | } |
| 336 | newConfig = mConfig.copy(); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 337 | ZenRule rule = new ZenRule(); |
| 338 | populateZenRule(automaticZenRule, rule, true); |
Beverly | a0d07ab | 2018-11-28 16:49:23 -0500 | [diff] [blame] | 339 | newConfig.automaticRules.put(rule.id, rule); |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 340 | if (setConfigLocked(newConfig, reason, rule.component, true)) { |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 341 | return rule.id; |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 342 | } else { |
Julia Reynolds | 87c4277 | 2016-05-16 09:52:17 -0400 | [diff] [blame] | 343 | throw new AndroidRuntimeException("Could not create rule"); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 344 | } |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 348 | public boolean updateAutomaticZenRule(String ruleId, AutomaticZenRule automaticZenRule, |
| 349 | String reason) { |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 350 | ZenModeConfig newConfig; |
| 351 | synchronized (mConfig) { |
| 352 | if (mConfig == null) return false; |
| 353 | if (DEBUG) { |
| 354 | Log.d(TAG, "updateAutomaticZenRule zenRule=" + automaticZenRule |
| 355 | + " reason=" + reason); |
| 356 | } |
| 357 | newConfig = mConfig.copy(); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 358 | ZenModeConfig.ZenRule rule; |
| 359 | if (ruleId == null) { |
| 360 | throw new IllegalArgumentException("Rule doesn't exist"); |
| 361 | } else { |
| 362 | rule = newConfig.automaticRules.get(ruleId); |
| 363 | if (rule == null || !canManageAutomaticZenRule(rule)) { |
| 364 | throw new SecurityException( |
| 365 | "Cannot update rules not owned by your condition provider"); |
| 366 | } |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 367 | } |
Julia Reynolds | 3ec9330 | 2019-07-11 15:27:31 -0400 | [diff] [blame] | 368 | if (rule.enabled != automaticZenRule.isEnabled()) { |
| 369 | dispatchOnAutomaticRuleStatusChanged(mConfig.user, rule.pkg, ruleId, |
| 370 | automaticZenRule.isEnabled() |
| 371 | ? AUTOMATIC_RULE_STATUS_ENABLED : AUTOMATIC_RULE_STATUS_DISABLED); |
| 372 | } |
| 373 | |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 374 | populateZenRule(automaticZenRule, rule, false); |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 375 | return setConfigLocked(newConfig, reason, rule.component, true); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 376 | } |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 377 | } |
| 378 | |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 379 | public boolean removeAutomaticZenRule(String id, String reason) { |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 380 | ZenModeConfig newConfig; |
| 381 | synchronized (mConfig) { |
| 382 | if (mConfig == null) return false; |
| 383 | newConfig = mConfig.copy(); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 384 | ZenRule rule = newConfig.automaticRules.get(id); |
| 385 | if (rule == null) return false; |
| 386 | if (canManageAutomaticZenRule(rule)) { |
| 387 | newConfig.automaticRules.remove(id); |
| 388 | if (DEBUG) Log.d(TAG, "removeZenRule zenRule=" + id + " reason=" + reason); |
| 389 | } else { |
| 390 | throw new SecurityException( |
| 391 | "Cannot delete rules not owned by your condition provider"); |
| 392 | } |
Julia Reynolds | 3ec9330 | 2019-07-11 15:27:31 -0400 | [diff] [blame] | 393 | dispatchOnAutomaticRuleStatusChanged( |
| 394 | mConfig.user, rule.pkg, id, AUTOMATIC_RULE_STATUS_REMOVED); |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 395 | return setConfigLocked(newConfig, reason, null, true); |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 396 | } |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 397 | } |
| 398 | |
Julia Reynolds | c8e54e8 | 2015-11-30 16:43:05 -0500 | [diff] [blame] | 399 | public boolean removeAutomaticZenRules(String packageName, String reason) { |
| 400 | ZenModeConfig newConfig; |
| 401 | synchronized (mConfig) { |
| 402 | if (mConfig == null) return false; |
| 403 | newConfig = mConfig.copy(); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 404 | for (int i = newConfig.automaticRules.size() - 1; i >= 0; i--) { |
| 405 | ZenRule rule = newConfig.automaticRules.get(newConfig.automaticRules.keyAt(i)); |
Julia Reynolds | 10e663b | 2019-01-07 10:15:12 -0500 | [diff] [blame] | 406 | if (rule.pkg.equals(packageName) && canManageAutomaticZenRule(rule)) { |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 407 | newConfig.automaticRules.removeAt(i); |
| 408 | } |
Julia Reynolds | c8e54e8 | 2015-11-30 16:43:05 -0500 | [diff] [blame] | 409 | } |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 410 | return setConfigLocked(newConfig, reason, null, true); |
Julia Reynolds | c8e54e8 | 2015-11-30 16:43:05 -0500 | [diff] [blame] | 411 | } |
Julia Reynolds | c8e54e8 | 2015-11-30 16:43:05 -0500 | [diff] [blame] | 412 | } |
| 413 | |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 414 | public void setAutomaticZenRuleState(String id, Condition condition) { |
| 415 | ZenModeConfig newConfig; |
| 416 | synchronized (mConfig) { |
| 417 | if (mConfig == null) return; |
| 418 | |
| 419 | newConfig = mConfig.copy(); |
Julia Reynolds | 977a93e | 2019-04-10 16:18:13 -0400 | [diff] [blame] | 420 | setAutomaticZenRuleStateLocked(newConfig, newConfig.automaticRules.get(id), condition); |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 421 | } |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | public void setAutomaticZenRuleState(Uri ruleDefinition, Condition condition) { |
| 425 | ZenModeConfig newConfig; |
| 426 | synchronized (mConfig) { |
| 427 | if (mConfig == null) return; |
| 428 | newConfig = mConfig.copy(); |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 429 | |
Julia Reynolds | 977a93e | 2019-04-10 16:18:13 -0400 | [diff] [blame] | 430 | setAutomaticZenRuleStateLocked(newConfig, |
| 431 | findMatchingRule(newConfig, ruleDefinition, condition), |
| 432 | condition); |
| 433 | } |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 434 | } |
| 435 | |
Julia Reynolds | 977a93e | 2019-04-10 16:18:13 -0400 | [diff] [blame] | 436 | private void setAutomaticZenRuleStateLocked(ZenModeConfig config, ZenRule rule, |
| 437 | Condition condition) { |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 438 | if (rule == null) return; |
| 439 | |
| 440 | rule.condition = condition; |
| 441 | updateSnoozing(rule); |
| 442 | setConfigLocked(config, rule.component, "conditionChanged"); |
| 443 | } |
| 444 | |
| 445 | private ZenRule findMatchingRule(ZenModeConfig config, Uri id, Condition condition) { |
| 446 | if (ruleMatches(id, condition, config.manualRule)) { |
| 447 | return config.manualRule; |
| 448 | } else { |
| 449 | for (ZenRule automaticRule : config.automaticRules.values()) { |
| 450 | if (ruleMatches(id, condition, automaticRule)) { |
| 451 | return automaticRule; |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | return null; |
| 456 | } |
| 457 | |
| 458 | private boolean ruleMatches(Uri id, Condition condition, ZenRule rule) { |
| 459 | if (id == null || rule == null || rule.conditionId == null) return false; |
| 460 | if (!rule.conditionId.equals(id)) return false; |
| 461 | if (Objects.equals(condition, rule.condition)) return false; |
| 462 | return true; |
| 463 | } |
| 464 | |
| 465 | private boolean updateSnoozing(ZenRule rule) { |
| 466 | if (rule != null && rule.snoozing && !rule.isTrueOrUnknown()) { |
| 467 | rule.snoozing = false; |
| 468 | if (DEBUG) Log.d(TAG, "Snoozing reset for " + rule.conditionId); |
| 469 | return true; |
| 470 | } |
| 471 | return false; |
| 472 | } |
| 473 | |
| 474 | public int getCurrentInstanceCount(ComponentName cn) { |
| 475 | if (cn == null) { |
| 476 | return 0; |
| 477 | } |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 478 | int count = 0; |
| 479 | synchronized (mConfig) { |
| 480 | for (ZenRule rule : mConfig.automaticRules.values()) { |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 481 | if (cn.equals(rule.component) || cn.equals(rule.configurationActivity)) { |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 482 | count++; |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | return count; |
| 487 | } |
| 488 | |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 489 | public boolean canManageAutomaticZenRule(ZenRule rule) { |
Julia Reynolds | c8e54e8 | 2015-11-30 16:43:05 -0500 | [diff] [blame] | 490 | final int callingUid = Binder.getCallingUid(); |
| 491 | if (callingUid == 0 || callingUid == Process.SYSTEM_UID) { |
| 492 | return true; |
| 493 | } else if (mContext.checkCallingPermission(android.Manifest.permission.MANAGE_NOTIFICATIONS) |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 494 | == PackageManager.PERMISSION_GRANTED) { |
| 495 | return true; |
| 496 | } else { |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 497 | String[] packages = mPm.getPackagesForUid(Binder.getCallingUid()); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 498 | if (packages != null) { |
| 499 | final int packageCount = packages.length; |
| 500 | for (int i = 0; i < packageCount; i++) { |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 501 | if (packages[i].equals(rule.pkg)) { |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 502 | return true; |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | return false; |
| 507 | } |
| 508 | } |
| 509 | |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 510 | protected void updateDefaultZenRules() { |
Beverly | f3b92d2 | 2018-09-18 15:13:17 -0400 | [diff] [blame] | 511 | updateDefaultAutomaticRuleNames(); |
| 512 | for (ZenRule defaultRule : mDefaultConfig.automaticRules.values()) { |
| 513 | ZenRule currRule = mConfig.automaticRules.get(defaultRule.id); |
Beverly | 49ba9a6 | 2018-11-02 13:19:31 -0400 | [diff] [blame] | 514 | // if default rule wasn't user-modified nor enabled, use localized name |
| 515 | // instead of previous system name |
| 516 | if (currRule != null && !currRule.modified && !currRule.enabled |
| 517 | && !defaultRule.name.equals(currRule.name)) { |
| 518 | if (canManageAutomaticZenRule(currRule)) { |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 519 | if (DEBUG) Slog.d(TAG, "Locale change - updating default zen rule name " |
Beverly | f3b92d2 | 2018-09-18 15:13:17 -0400 | [diff] [blame] | 520 | + "from " + currRule.name + " to " + defaultRule.name); |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 521 | // update default rule (if locale changed, name of rule will change) |
Beverly | 49ba9a6 | 2018-11-02 13:19:31 -0400 | [diff] [blame] | 522 | currRule.name = defaultRule.name; |
| 523 | updateAutomaticZenRule(defaultRule.id, createAutomaticZenRule(currRule), |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 524 | "locale changed"); |
| 525 | } |
| 526 | } |
| 527 | } |
| 528 | } |
| 529 | |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 530 | private boolean isSystemRule(AutomaticZenRule rule) { |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 531 | return rule.getOwner() != null |
| 532 | && ZenModeConfig.SYSTEM_AUTHORITY.equals(rule.getOwner().getPackageName()); |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | private ServiceInfo getServiceInfo(ComponentName owner) { |
Julia Reynolds | 0ae2b0b | 2016-01-14 09:58:03 -0500 | [diff] [blame] | 536 | Intent queryIntent = new Intent(); |
| 537 | queryIntent.setComponent(owner); |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 538 | List<ResolveInfo> installedServices = mPm.queryIntentServicesAsUser( |
Julia Reynolds | 0ae2b0b | 2016-01-14 09:58:03 -0500 | [diff] [blame] | 539 | queryIntent, |
| 540 | PackageManager.GET_SERVICES | PackageManager.GET_META_DATA, |
| 541 | UserHandle.getCallingUserId()); |
| 542 | if (installedServices != null) { |
| 543 | for (int i = 0, count = installedServices.size(); i < count; i++) { |
| 544 | ResolveInfo resolveInfo = installedServices.get(i); |
| 545 | ServiceInfo info = resolveInfo.serviceInfo; |
| 546 | if (mServiceConfig.bindPermission.equals(info.permission)) { |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 547 | return info; |
Julia Reynolds | 0ae2b0b | 2016-01-14 09:58:03 -0500 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | } |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 551 | return null; |
Julia Reynolds | 0ae2b0b | 2016-01-14 09:58:03 -0500 | [diff] [blame] | 552 | } |
| 553 | |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 554 | private ActivityInfo getActivityInfo(ComponentName configActivity) { |
| 555 | Intent queryIntent = new Intent(); |
| 556 | queryIntent.setComponent(configActivity); |
| 557 | List<ResolveInfo> installedComponents = mPm.queryIntentActivitiesAsUser( |
| 558 | queryIntent, |
| 559 | PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA, |
| 560 | UserHandle.getCallingUserId()); |
| 561 | if (installedComponents != null) { |
| 562 | for (int i = 0, count = installedComponents.size(); i < count; i++) { |
| 563 | ResolveInfo resolveInfo = installedComponents.get(i); |
| 564 | return resolveInfo.activityInfo; |
| 565 | } |
| 566 | } |
| 567 | return null; |
| 568 | } |
| 569 | |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 570 | private void populateZenRule(AutomaticZenRule automaticZenRule, ZenRule rule, boolean isNew) { |
| 571 | if (isNew) { |
| 572 | rule.id = ZenModeConfig.newRuleId(); |
| 573 | rule.creationTime = System.currentTimeMillis(); |
| 574 | rule.component = automaticZenRule.getOwner(); |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 575 | rule.configurationActivity = automaticZenRule.getConfigurationActivity(); |
| 576 | rule.pkg = (rule.component != null) |
| 577 | ? rule.component.getPackageName() |
| 578 | : rule.configurationActivity.getPackageName(); |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | if (rule.enabled != automaticZenRule.isEnabled()) { |
| 582 | rule.snoozing = false; |
| 583 | } |
| 584 | rule.name = automaticZenRule.getName(); |
| 585 | rule.condition = null; |
| 586 | rule.conditionId = automaticZenRule.getConditionId(); |
| 587 | rule.enabled = automaticZenRule.isEnabled(); |
Beverly | 49ba9a6 | 2018-11-02 13:19:31 -0400 | [diff] [blame] | 588 | rule.modified = automaticZenRule.isModified(); |
Beverly | 1219670 | 2018-12-12 15:05:51 -0500 | [diff] [blame] | 589 | rule.zenPolicy = automaticZenRule.getZenPolicy(); |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 590 | rule.zenMode = NotificationManager.zenModeFromInterruptionFilter( |
| 591 | automaticZenRule.getInterruptionFilter(), Global.ZEN_MODE_OFF); |
| 592 | } |
| 593 | |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 594 | protected AutomaticZenRule createAutomaticZenRule(ZenRule rule) { |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 595 | return new AutomaticZenRule(rule.name, rule.component, rule.configurationActivity, |
| 596 | rule.conditionId, rule.zenPolicy, |
| 597 | NotificationManager.zenModeToInterruptionFilter(rule.zenMode), |
| 598 | rule.enabled, rule.creationTime); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 599 | } |
| 600 | |
Julia Reynolds | 44ad6ff | 2016-07-06 09:47:45 -0400 | [diff] [blame] | 601 | public void setManualZenMode(int zenMode, Uri conditionId, String caller, String reason) { |
| 602 | setManualZenMode(zenMode, conditionId, reason, caller, true /*setRingerMode*/); |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 603 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 604 | Settings.Secure.SHOW_ZEN_SETTINGS_SUGGESTION, 0); |
John Spurlock | e77bb36 | 2014-04-26 10:24:59 -0400 | [diff] [blame] | 605 | } |
| 606 | |
Julia Reynolds | 44ad6ff | 2016-07-06 09:47:45 -0400 | [diff] [blame] | 607 | private void setManualZenMode(int zenMode, Uri conditionId, String reason, String caller, |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 608 | boolean setRingerMode) { |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 609 | ZenModeConfig newConfig; |
| 610 | synchronized (mConfig) { |
| 611 | if (mConfig == null) return; |
| 612 | if (!Global.isValidZenMode(zenMode)) return; |
| 613 | if (DEBUG) Log.d(TAG, "setManualZenMode " + Global.zenModeToString(zenMode) |
| 614 | + " conditionId=" + conditionId + " reason=" + reason |
| 615 | + " setRingerMode=" + setRingerMode); |
| 616 | newConfig = mConfig.copy(); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 617 | if (zenMode == Global.ZEN_MODE_OFF) { |
| 618 | newConfig.manualRule = null; |
| 619 | for (ZenRule automaticRule : newConfig.automaticRules.values()) { |
| 620 | if (automaticRule.isAutomaticActive()) { |
| 621 | automaticRule.snoozing = true; |
| 622 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 623 | } |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 624 | } else { |
| 625 | final ZenRule newRule = new ZenRule(); |
| 626 | newRule.enabled = true; |
| 627 | newRule.zenMode = zenMode; |
| 628 | newRule.conditionId = conditionId; |
Julia Reynolds | 44ad6ff | 2016-07-06 09:47:45 -0400 | [diff] [blame] | 629 | newRule.enabler = caller; |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 630 | newConfig.manualRule = newRule; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 631 | } |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 632 | setConfigLocked(newConfig, reason, null, setRingerMode); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 633 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 634 | } |
| 635 | |
Julia Reynolds | 520df6e | 2017-02-13 09:05:10 -0500 | [diff] [blame] | 636 | void dump(ProtoOutputStream proto) { |
Julia Reynolds | 520df6e | 2017-02-13 09:05:10 -0500 | [diff] [blame] | 637 | proto.write(ZenModeProto.ZEN_MODE, mZenMode); |
| 638 | synchronized (mConfig) { |
| 639 | if (mConfig.manualRule != null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 640 | mConfig.manualRule.dumpDebug(proto, ZenModeProto.ENABLED_ACTIVE_CONDITIONS); |
Julia Reynolds | 520df6e | 2017-02-13 09:05:10 -0500 | [diff] [blame] | 641 | } |
| 642 | for (ZenRule rule : mConfig.automaticRules.values()) { |
| 643 | if (rule.enabled && rule.condition.state == Condition.STATE_TRUE |
| 644 | && !rule.snoozing) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 645 | rule.dumpDebug(proto, ZenModeProto.ENABLED_ACTIVE_CONDITIONS); |
Julia Reynolds | 520df6e | 2017-02-13 09:05:10 -0500 | [diff] [blame] | 646 | } |
| 647 | } |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 648 | mConfig.toNotificationPolicy().dumpDebug(proto, ZenModeProto.POLICY); |
Julia Reynolds | 520df6e | 2017-02-13 09:05:10 -0500 | [diff] [blame] | 649 | proto.write(ZenModeProto.SUPPRESSED_EFFECTS, mSuppressedEffects); |
| 650 | } |
| 651 | } |
| 652 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 653 | public void dump(PrintWriter pw, String prefix) { |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 654 | pw.print(prefix); |
| 655 | pw.print("mZenMode="); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 656 | pw.println(Global.zenModeToString(mZenMode)); |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 657 | pw.print(prefix); |
| 658 | pw.println("mConsolidatedPolicy=" + mConsolidatedPolicy.toString()); |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 659 | final int N = mConfigs.size(); |
| 660 | for (int i = 0; i < N; i++) { |
| 661 | dump(pw, prefix, "mConfigs[u=" + mConfigs.keyAt(i) + "]", mConfigs.valueAt(i)); |
| 662 | } |
| 663 | pw.print(prefix); pw.print("mUser="); pw.println(mUser); |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 664 | synchronized (mConfig) { |
| 665 | dump(pw, prefix, "mConfig", mConfig); |
| 666 | } |
Bryce Lee | 7219ada | 2016-04-08 10:54:23 -0700 | [diff] [blame] | 667 | |
| 668 | pw.print(prefix); pw.print("mSuppressedEffects="); pw.println(mSuppressedEffects); |
John Spurlock | 1d7d224 | 2015-04-10 08:10:22 -0400 | [diff] [blame] | 669 | mFiltering.dump(pw, prefix); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 670 | mConditions.dump(pw, prefix); |
| 671 | } |
| 672 | |
| 673 | private static void dump(PrintWriter pw, String prefix, String var, ZenModeConfig config) { |
| 674 | pw.print(prefix); pw.print(var); pw.print('='); |
| 675 | if (config == null) { |
| 676 | pw.println(config); |
| 677 | return; |
| 678 | } |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 679 | pw.printf("allow(alarms=%b,media=%b,system=%b,calls=%b,callsFrom=%s,repeatCallers=%b," |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 680 | + "messages=%b,messagesFrom=%s,conversations=%b,conversationsFrom=%s," |
| 681 | + "events=%b,reminders=%b)\n", |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 682 | config.allowAlarms, config.allowMedia, config.allowSystem, |
Julia Reynolds | 6ee2617 | 2015-09-28 11:34:48 -0400 | [diff] [blame] | 683 | config.allowCalls, ZenModeConfig.sourceToString(config.allowCallsFrom), |
| 684 | config.allowRepeatCallers, config.allowMessages, |
| 685 | ZenModeConfig.sourceToString(config.allowMessagesFrom), |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 686 | config.allowConversations, |
| 687 | ZenPolicy.conversationTypeToString(config.allowConversationsFrom), |
Julia Reynolds | 1f58057 | 2018-04-27 14:48:36 -0400 | [diff] [blame] | 688 | config.allowEvents, config.allowReminders); |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 689 | pw.print(prefix); |
| 690 | pw.printf(" disallow(visualEffects=%s)\n", config.suppressedVisualEffects); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 691 | pw.print(prefix); pw.print(" manualRule="); pw.println(config.manualRule); |
| 692 | if (config.automaticRules.isEmpty()) return; |
| 693 | final int N = config.automaticRules.size(); |
| 694 | for (int i = 0; i < N; i++) { |
| 695 | pw.print(prefix); pw.print(i == 0 ? " automaticRules=" : " "); |
| 696 | pw.println(config.automaticRules.valueAt(i)); |
| 697 | } |
| 698 | } |
| 699 | |
Annie Meng | 8b646fd | 2019-02-01 18:46:42 +0000 | [diff] [blame] | 700 | public void readXml(XmlPullParser parser, boolean forRestore, int userId) |
John Spurlock | 35ef0a6 | 2015-05-28 11:24:10 -0400 | [diff] [blame] | 701 | throws XmlPullParserException, IOException { |
Beverly | 4e2f76c | 2018-03-16 15:43:49 -0400 | [diff] [blame] | 702 | ZenModeConfig config = ZenModeConfig.readXml(parser); |
| 703 | String reason = "readXml"; |
| 704 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 705 | if (config != null) { |
John Spurlock | 35ef0a6 | 2015-05-28 11:24:10 -0400 | [diff] [blame] | 706 | if (forRestore) { |
Annie Meng | 8b646fd | 2019-02-01 18:46:42 +0000 | [diff] [blame] | 707 | config.user = userId; |
John Spurlock | 35ef0a6 | 2015-05-28 11:24:10 -0400 | [diff] [blame] | 708 | config.manualRule = null; // don't restore the manual rule |
Beverly | 4e2f76c | 2018-03-16 15:43:49 -0400 | [diff] [blame] | 709 | } |
| 710 | |
Beverly | ad3841a | 2018-07-31 11:23:35 -0400 | [diff] [blame] | 711 | // booleans to determine whether to reset the rules to the default rules |
| 712 | boolean allRulesDisabled = true; |
| 713 | boolean hasDefaultRules = config.automaticRules.containsAll( |
| 714 | ZenModeConfig.DEFAULT_RULE_IDS); |
| 715 | |
Beverly | 4e2f76c | 2018-03-16 15:43:49 -0400 | [diff] [blame] | 716 | long time = System.currentTimeMillis(); |
| 717 | if (config.automaticRules != null && config.automaticRules.size() > 0) { |
| 718 | for (ZenRule automaticRule : config.automaticRules.values()) { |
| 719 | if (forRestore) { |
John Spurlock | 995a749 | 2015-05-28 22:13:03 -0400 | [diff] [blame] | 720 | // don't restore transient state from restored automatic rules |
| 721 | automaticRule.snoozing = false; |
| 722 | automaticRule.condition = null; |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 723 | automaticRule.creationTime = time; |
John Spurlock | 995a749 | 2015-05-28 22:13:03 -0400 | [diff] [blame] | 724 | } |
Beverly | ad3841a | 2018-07-31 11:23:35 -0400 | [diff] [blame] | 725 | |
| 726 | allRulesDisabled &= !automaticRule.enabled; |
John Spurlock | 995a749 | 2015-05-28 22:13:03 -0400 | [diff] [blame] | 727 | } |
John Spurlock | 35ef0a6 | 2015-05-28 11:24:10 -0400 | [diff] [blame] | 728 | } |
Beverly | 4e2f76c | 2018-03-16 15:43:49 -0400 | [diff] [blame] | 729 | |
Beverly | ad3841a | 2018-07-31 11:23:35 -0400 | [diff] [blame] | 730 | if (!hasDefaultRules && allRulesDisabled |
| 731 | && (forRestore || config.version < ZenModeConfig.XML_VERSION)) { |
| 732 | // reset zen automatic rules to default on restore or upgrade if: |
| 733 | // - doesn't already have default rules and |
| 734 | // - all previous automatic rules were disabled |
| 735 | config.automaticRules = new ArrayMap<>(); |
Beverly | f3b92d2 | 2018-09-18 15:13:17 -0400 | [diff] [blame] | 736 | for (ZenRule rule : mDefaultConfig.automaticRules.values()) { |
| 737 | config.automaticRules.put(rule.id, rule); |
| 738 | } |
Beverly | ad3841a | 2018-07-31 11:23:35 -0400 | [diff] [blame] | 739 | reason += ", reset to default rules"; |
| 740 | } |
| 741 | |
Annie Meng | 8b646fd | 2019-02-01 18:46:42 +0000 | [diff] [blame] | 742 | // Resolve user id for settings. |
| 743 | userId = userId == UserHandle.USER_ALL ? UserHandle.USER_SYSTEM : userId; |
Beverly | ad3841a | 2018-07-31 11:23:35 -0400 | [diff] [blame] | 744 | if (config.version < ZenModeConfig.XML_VERSION) { |
Annie Meng | 8b646fd | 2019-02-01 18:46:42 +0000 | [diff] [blame] | 745 | Settings.Secure.putIntForUser(mContext.getContentResolver(), |
| 746 | Settings.Secure.SHOW_ZEN_UPGRADE_NOTIFICATION, 1, userId); |
Beverly | 301e92a | 2018-04-27 09:43:05 -0400 | [diff] [blame] | 747 | } else { |
| 748 | // devices not restoring/upgrading already have updated zen settings |
Annie Meng | 8b646fd | 2019-02-01 18:46:42 +0000 | [diff] [blame] | 749 | Settings.Secure.putIntForUser(mContext.getContentResolver(), |
| 750 | Settings.Secure.ZEN_SETTINGS_UPDATED, 1, userId); |
Beverly | 4e2f76c | 2018-03-16 15:43:49 -0400 | [diff] [blame] | 751 | } |
| 752 | if (DEBUG) Log.d(TAG, reason); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 753 | synchronized (mConfig) { |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 754 | setConfigLocked(config, null, reason); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 755 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | |
Annie Meng | 8b646fd | 2019-02-01 18:46:42 +0000 | [diff] [blame] | 759 | public void writeXml(XmlSerializer out, boolean forBackup, Integer version, int userId) |
| 760 | throws IOException { |
Beverly | 1ef2cce | 2019-04-29 11:08:05 -0400 | [diff] [blame] | 761 | synchronized (mConfigs) { |
| 762 | final int n = mConfigs.size(); |
| 763 | for (int i = 0; i < n; i++) { |
| 764 | if (forBackup && mConfigs.keyAt(i) != userId) { |
| 765 | continue; |
| 766 | } |
| 767 | mConfigs.valueAt(i).writeXml(out, version); |
John Spurlock | 35ef0a6 | 2015-05-28 11:24:10 -0400 | [diff] [blame] | 768 | } |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 769 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 770 | } |
| 771 | |
Beverly | 174d741 | 2018-08-22 16:34:41 -0400 | [diff] [blame] | 772 | /** |
| 773 | * @return user-specified default notification policy for priority only do not disturb |
| 774 | */ |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 775 | public Policy getNotificationPolicy() { |
| 776 | return getNotificationPolicy(mConfig); |
| 777 | } |
| 778 | |
| 779 | private static Policy getNotificationPolicy(ZenModeConfig config) { |
| 780 | return config == null ? null : config.toNotificationPolicy(); |
| 781 | } |
| 782 | |
Beverly | 174d741 | 2018-08-22 16:34:41 -0400 | [diff] [blame] | 783 | /** |
| 784 | * Sets the global notification policy used for priority only do not disturb |
| 785 | */ |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 786 | public void setNotificationPolicy(Policy policy) { |
| 787 | if (policy == null || mConfig == null) return; |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 788 | synchronized (mConfig) { |
| 789 | final ZenModeConfig newConfig = mConfig.copy(); |
| 790 | newConfig.applyNotificationPolicy(policy); |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 791 | setConfigLocked(newConfig, null, "setNotificationPolicy"); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 792 | } |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 793 | } |
| 794 | |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 795 | /** |
| 796 | * Removes old rule instances whose owner is not installed. |
| 797 | */ |
| 798 | private void cleanUpZenRules() { |
| 799 | long currentTime = System.currentTimeMillis(); |
| 800 | synchronized (mConfig) { |
| 801 | final ZenModeConfig newConfig = mConfig.copy(); |
| 802 | if (newConfig.automaticRules != null) { |
| 803 | for (int i = newConfig.automaticRules.size() - 1; i >= 0; i--) { |
| 804 | ZenRule rule = newConfig.automaticRules.get(newConfig.automaticRules.keyAt(i)); |
| 805 | if (RULE_INSTANCE_GRACE_PERIOD < (currentTime - rule.creationTime)) { |
| 806 | try { |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 807 | if (rule.pkg != null) { |
| 808 | mPm.getPackageInfo(rule.pkg, PackageManager.MATCH_ANY_USER); |
| 809 | } |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 810 | } catch (PackageManager.NameNotFoundException e) { |
| 811 | newConfig.automaticRules.removeAt(i); |
| 812 | } |
| 813 | } |
| 814 | } |
| 815 | } |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 816 | setConfigLocked(newConfig, null, "cleanUpZenRules"); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 817 | } |
| 818 | } |
| 819 | |
| 820 | /** |
| 821 | * @return a copy of the zen mode configuration |
| 822 | */ |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 823 | public ZenModeConfig getConfig() { |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 824 | synchronized (mConfig) { |
| 825 | return mConfig.copy(); |
| 826 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 827 | } |
| 828 | |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 829 | /** |
| 830 | * @return a copy of the zen mode consolidated policy |
| 831 | */ |
| 832 | public Policy getConsolidatedNotificationPolicy() { |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 833 | return mConsolidatedPolicy.copy(); |
| 834 | } |
| 835 | |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 836 | public boolean setConfigLocked(ZenModeConfig config, ComponentName triggeringComponent, |
| 837 | String reason) { |
| 838 | return setConfigLocked(config, reason, triggeringComponent, true /*setRingerMode*/); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 839 | } |
| 840 | |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 841 | public void setConfig(ZenModeConfig config, ComponentName triggeringComponent, String reason) { |
Julia Reynolds | 89aeab0 | 2016-09-15 11:07:50 -0400 | [diff] [blame] | 842 | synchronized (mConfig) { |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 843 | setConfigLocked(config, triggeringComponent, reason); |
Julia Reynolds | 89aeab0 | 2016-09-15 11:07:50 -0400 | [diff] [blame] | 844 | } |
Eric Laurent | e0ced4d | 2015-09-30 17:44:28 -0700 | [diff] [blame] | 845 | } |
| 846 | |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 847 | private boolean setConfigLocked(ZenModeConfig config, String reason, |
| 848 | ComponentName triggeringComponent, boolean setRingerMode) { |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 849 | final long identity = Binder.clearCallingIdentity(); |
| 850 | try { |
| 851 | if (config == null || !config.isValid()) { |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 852 | Log.w(TAG, "Invalid config in setConfigLocked; " + config); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 853 | return false; |
| 854 | } |
| 855 | if (config.user != mUser) { |
| 856 | // simply store away for background users |
| 857 | mConfigs.put(config.user, config); |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 858 | if (DEBUG) Log.d(TAG, "setConfigLocked: store config for user " + config.user); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 859 | return true; |
| 860 | } |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 861 | // handle CPS backed conditions - danger! may modify config |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 862 | mConditions.evaluateConfig(config, null, false /*processSubscriptions*/); |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 863 | |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 864 | mConfigs.put(config.user, config); |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 865 | if (DEBUG) Log.d(TAG, "setConfigLocked reason=" + reason, new Throwable()); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 866 | ZenLog.traceConfig(reason, mConfig, config); |
Julia Reynolds | 6806207 | 2018-08-06 15:38:21 -0400 | [diff] [blame] | 867 | |
| 868 | // send some broadcasts |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 869 | final boolean policyChanged = !Objects.equals(getNotificationPolicy(mConfig), |
| 870 | getNotificationPolicy(config)); |
Julia Reynolds | 9a25da1 | 2016-01-06 16:19:28 -0500 | [diff] [blame] | 871 | if (!config.equals(mConfig)) { |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 872 | dispatchOnConfigChanged(); |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 873 | updateConsolidatedPolicy(reason); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 874 | } |
| 875 | if (policyChanged) { |
| 876 | dispatchOnPolicyChanged(); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 877 | } |
Julia Reynolds | 9a25da1 | 2016-01-06 16:19:28 -0500 | [diff] [blame] | 878 | mConfig = config; |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 879 | mHandler.postApplyConfig(config, reason, triggeringComponent, setRingerMode); |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 880 | return true; |
Julia Reynolds | cb507b8 | 2017-09-07 13:53:40 -0400 | [diff] [blame] | 881 | } catch (SecurityException e) { |
| 882 | Log.wtf(TAG, "Invalid rule in config", e); |
| 883 | return false; |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 884 | } finally { |
| 885 | Binder.restoreCallingIdentity(identity); |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 886 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 887 | } |
| 888 | |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 889 | private void applyConfig(ZenModeConfig config, String reason, |
| 890 | ComponentName triggeringComponent, boolean setRingerMode) { |
Julia Reynolds | d82e981 | 2016-04-19 13:27:41 -0400 | [diff] [blame] | 891 | final String val = Integer.toString(config.hashCode()); |
| 892 | Global.putString(mContext.getContentResolver(), Global.ZEN_MODE_CONFIG_ETAG, val); |
Beverly | 174d741 | 2018-08-22 16:34:41 -0400 | [diff] [blame] | 893 | evaluateZenMode(reason, setRingerMode); |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 894 | mConditions.evaluateConfig(config, triggeringComponent, true /*processSubscriptions*/); |
Julia Reynolds | d82e981 | 2016-04-19 13:27:41 -0400 | [diff] [blame] | 895 | } |
| 896 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 897 | private int getZenModeSetting() { |
| 898 | return Global.getInt(mContext.getContentResolver(), Global.ZEN_MODE, Global.ZEN_MODE_OFF); |
| 899 | } |
| 900 | |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 901 | @VisibleForTesting |
| 902 | protected void setZenModeSetting(int zen) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 903 | Global.putInt(mContext.getContentResolver(), Global.ZEN_MODE, zen); |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 904 | showZenUpgradeNotification(zen); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 905 | } |
| 906 | |
Julia Reynolds | 9b11fdb | 2015-07-31 09:49:55 -0400 | [diff] [blame] | 907 | private int getPreviousRingerModeSetting() { |
| 908 | return Global.getInt(mContext.getContentResolver(), |
| 909 | Global.ZEN_MODE_RINGER_LEVEL, AudioManager.RINGER_MODE_NORMAL); |
| 910 | } |
| 911 | |
| 912 | private void setPreviousRingerModeSetting(Integer previousRingerLevel) { |
| 913 | Global.putString( |
| 914 | mContext.getContentResolver(), Global.ZEN_MODE_RINGER_LEVEL, |
| 915 | previousRingerLevel == null ? null : Integer.toString(previousRingerLevel)); |
| 916 | } |
| 917 | |
Beverly | e4ee1cc | 2018-03-06 17:21:08 -0500 | [diff] [blame] | 918 | @VisibleForTesting |
Beverly | 174d741 | 2018-08-22 16:34:41 -0400 | [diff] [blame] | 919 | protected void evaluateZenMode(String reason, boolean setRingerMode) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 920 | if (DEBUG) Log.d(TAG, "evaluateZenMode"); |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 921 | if (mConfig == null) return; |
| 922 | final int policyHashBefore = mConsolidatedPolicy == null ? 0 |
| 923 | : mConsolidatedPolicy.hashCode(); |
Jason Monk | a992732 | 2015-12-13 16:22:37 -0500 | [diff] [blame] | 924 | final int zenBefore = mZenMode; |
Julia Reynolds | 8ac6303 | 2015-08-31 15:19:43 -0400 | [diff] [blame] | 925 | final int zen = computeZenMode(); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 926 | ZenLog.traceSetZenMode(zen, reason); |
| 927 | mZenMode = zen; |
| 928 | setZenModeSetting(mZenMode); |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 929 | updateConsolidatedPolicy(reason); |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 930 | updateRingerModeAffectedStreams(); |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 931 | if (setRingerMode && (zen != zenBefore || (zen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS |
| 932 | && policyHashBefore != mConsolidatedPolicy.hashCode()))) { |
John Spurlock | 5762779 | 2014-12-11 11:29:54 -0500 | [diff] [blame] | 933 | applyZenToRingerMode(); |
| 934 | } |
| 935 | applyRestrictions(); |
Jason Monk | a992732 | 2015-12-13 16:22:37 -0500 | [diff] [blame] | 936 | if (zen != zenBefore) { |
Julia Reynolds | 8ac6303 | 2015-08-31 15:19:43 -0400 | [diff] [blame] | 937 | mHandler.postDispatchOnZenModeChanged(); |
| 938 | } |
John Spurlock | 5762779 | 2014-12-11 11:29:54 -0500 | [diff] [blame] | 939 | } |
| 940 | |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 941 | private void updateRingerModeAffectedStreams() { |
| 942 | if (mAudioManager != null) { |
| 943 | mAudioManager.updateRingerModeAffectedStreamsInternal(); |
| 944 | } |
| 945 | } |
| 946 | |
Julia Reynolds | 8ac6303 | 2015-08-31 15:19:43 -0400 | [diff] [blame] | 947 | private int computeZenMode() { |
Beverly | e4ee1cc | 2018-03-06 17:21:08 -0500 | [diff] [blame] | 948 | if (mConfig == null) return Global.ZEN_MODE_OFF; |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 949 | synchronized (mConfig) { |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 950 | if (mConfig.manualRule != null) return mConfig.manualRule.zenMode; |
| 951 | int zen = Global.ZEN_MODE_OFF; |
| 952 | for (ZenRule automaticRule : mConfig.automaticRules.values()) { |
| 953 | if (automaticRule.isAutomaticActive()) { |
| 954 | if (zenSeverity(automaticRule.zenMode) > zenSeverity(zen)) { |
Beverly | 301e92a | 2018-04-27 09:43:05 -0400 | [diff] [blame] | 955 | // automatic rule triggered dnd and user hasn't seen update dnd dialog |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 956 | if (Settings.Secure.getInt(mContext.getContentResolver(), |
| 957 | Settings.Secure.ZEN_SETTINGS_SUGGESTION_VIEWED, 1) == 0) { |
| 958 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 959 | Settings.Secure.SHOW_ZEN_SETTINGS_SUGGESTION, 1); |
Beverly | 301e92a | 2018-04-27 09:43:05 -0400 | [diff] [blame] | 960 | } |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 961 | zen = automaticRule.zenMode; |
| 962 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 963 | } |
| 964 | } |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 965 | return zen; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 966 | } |
John Spurlock | 8403b75 | 2014-12-10 12:47:01 -0500 | [diff] [blame] | 967 | } |
| 968 | |
Beverly | 1cc502f | 2019-04-15 11:21:25 -0400 | [diff] [blame] | 969 | private void applyCustomPolicy(ZenPolicy policy, ZenRule rule) { |
Beverly | 1f11492 | 2019-09-03 17:00:51 -0400 | [diff] [blame] | 970 | if (rule.zenMode == Global.ZEN_MODE_NO_INTERRUPTIONS) { |
Beverly | 1cc502f | 2019-04-15 11:21:25 -0400 | [diff] [blame] | 971 | policy.apply(new ZenPolicy.Builder() |
| 972 | .disallowAllSounds() |
| 973 | .build()); |
Beverly | 1f11492 | 2019-09-03 17:00:51 -0400 | [diff] [blame] | 974 | } else if (rule.zenMode == Global.ZEN_MODE_ALARMS) { |
Beverly | 1cc502f | 2019-04-15 11:21:25 -0400 | [diff] [blame] | 975 | policy.apply(new ZenPolicy.Builder() |
| 976 | .disallowAllSounds() |
| 977 | .allowAlarms(true) |
| 978 | .allowMedia(true) |
| 979 | .build()); |
| 980 | } else { |
| 981 | policy.apply(rule.zenPolicy); |
| 982 | } |
| 983 | } |
| 984 | |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 985 | private void updateConsolidatedPolicy(String reason) { |
| 986 | if (mConfig == null) return; |
| 987 | synchronized (mConfig) { |
| 988 | ZenPolicy policy = new ZenPolicy(); |
Beverly | 1cc502f | 2019-04-15 11:21:25 -0400 | [diff] [blame] | 989 | if (mConfig.manualRule != null) { |
| 990 | applyCustomPolicy(policy, mConfig.manualRule); |
| 991 | } |
| 992 | |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 993 | for (ZenRule automaticRule : mConfig.automaticRules.values()) { |
| 994 | if (automaticRule.isAutomaticActive()) { |
Beverly | 1cc502f | 2019-04-15 11:21:25 -0400 | [diff] [blame] | 995 | applyCustomPolicy(policy, automaticRule); |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 996 | } |
| 997 | } |
| 998 | Policy newPolicy = mConfig.toNotificationPolicy(policy); |
| 999 | if (!Objects.equals(mConsolidatedPolicy, newPolicy)) { |
| 1000 | mConsolidatedPolicy = newPolicy; |
| 1001 | dispatchOnConsolidatedPolicyChanged(); |
| 1002 | ZenLog.traceSetConsolidatedZenPolicy(mConsolidatedPolicy, reason); |
| 1003 | } |
| 1004 | } |
| 1005 | } |
| 1006 | |
Beverly | f3b92d2 | 2018-09-18 15:13:17 -0400 | [diff] [blame] | 1007 | private void updateDefaultAutomaticRuleNames() { |
| 1008 | for (ZenRule rule : mDefaultConfig.automaticRules.values()) { |
| 1009 | if (ZenModeConfig.EVENTS_DEFAULT_RULE_ID.equals(rule.id)) { |
| 1010 | rule.name = mContext.getResources() |
| 1011 | .getString(R.string.zen_mode_default_events_name); |
| 1012 | } else if (ZenModeConfig.EVERY_NIGHT_DEFAULT_RULE_ID.equals(rule.id)) { |
| 1013 | rule.name = mContext.getResources() |
| 1014 | .getString(R.string.zen_mode_default_every_night_name); |
| 1015 | } |
| 1016 | } |
Beverly | 30bfbca | 2017-10-17 14:38:20 -0400 | [diff] [blame] | 1017 | } |
| 1018 | |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 1019 | @VisibleForTesting |
| 1020 | protected void applyRestrictions() { |
Julia Reynolds | 8f5dabd | 2020-02-19 08:42:07 -0500 | [diff] [blame] | 1021 | final boolean zenOn = mZenMode != Global.ZEN_MODE_OFF; |
Beverly | d820bc2 | 2018-01-11 15:28:33 -0500 | [diff] [blame] | 1022 | final boolean zenPriorityOnly = mZenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; |
Beverly | 925cde8 | 2018-01-23 09:31:23 -0500 | [diff] [blame] | 1023 | final boolean zenSilence = mZenMode == Global.ZEN_MODE_NO_INTERRUPTIONS; |
Beverly | d820bc2 | 2018-01-11 15:28:33 -0500 | [diff] [blame] | 1024 | final boolean zenAlarmsOnly = mZenMode == Global.ZEN_MODE_ALARMS; |
Julia Reynolds | 8f5dabd | 2020-02-19 08:42:07 -0500 | [diff] [blame] | 1025 | final boolean allowCalls = mConsolidatedPolicy.allowCalls() |
| 1026 | && mConsolidatedPolicy.allowCallsFrom() == PRIORITY_SENDERS_ANY; |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 1027 | final boolean allowRepeatCallers = mConsolidatedPolicy.allowRepeatCallers(); |
| 1028 | final boolean allowSystem = mConsolidatedPolicy.allowSystem(); |
| 1029 | final boolean allowMedia = mConsolidatedPolicy.allowMedia(); |
| 1030 | final boolean allowAlarms = mConsolidatedPolicy.allowAlarms(); |
John Spurlock | 8403b75 | 2014-12-10 12:47:01 -0500 | [diff] [blame] | 1031 | |
| 1032 | // notification restrictions |
Julia Reynolds | 8f5dabd | 2020-02-19 08:42:07 -0500 | [diff] [blame] | 1033 | final boolean muteNotifications = zenOn |
| 1034 | || (mSuppressedEffects & SUPPRESSED_EFFECT_NOTIFICATIONS) != 0; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 1035 | // call restrictions |
Beverly | d820bc2 | 2018-01-11 15:28:33 -0500 | [diff] [blame] | 1036 | final boolean muteCalls = zenAlarmsOnly |
Julia Reynolds | 8f5dabd | 2020-02-19 08:42:07 -0500 | [diff] [blame] | 1037 | || (zenPriorityOnly && !(allowCalls || allowRepeatCallers)) |
Bryce Lee | 7219ada | 2016-04-08 10:54:23 -0700 | [diff] [blame] | 1038 | || (mSuppressedEffects & SUPPRESSED_EFFECT_CALLS) != 0; |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 1039 | // alarm restrictions |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 1040 | final boolean muteAlarms = zenPriorityOnly && !allowAlarms; |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 1041 | // media restrictions |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 1042 | final boolean muteMedia = zenPriorityOnly && !allowMedia; |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 1043 | // system restrictions |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 1044 | final boolean muteSystem = zenAlarmsOnly || (zenPriorityOnly && !allowSystem); |
Julia Reynolds | 3fe81be | 2016-02-03 09:10:06 -0500 | [diff] [blame] | 1045 | // total silence restrictions |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 1046 | final boolean muteEverything = zenSilence || (zenPriorityOnly |
| 1047 | && ZenModeConfig.areAllZenBehaviorSoundsMuted(mConsolidatedPolicy)); |
John Spurlock | 25d01ee | 2015-06-03 12:17:46 -0400 | [diff] [blame] | 1048 | |
Jean-Michel Trivi | e743bda | 2016-09-09 11:56:48 -0700 | [diff] [blame] | 1049 | for (int usage : AudioAttributes.SDK_USAGES) { |
| 1050 | final int suppressionBehavior = AudioAttributes.SUPPRESSIBLE_USAGES.get(usage); |
Jean-Michel Trivi | 7a84eae | 2017-06-20 14:58:18 -0700 | [diff] [blame] | 1051 | if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_NEVER) { |
Julia Reynolds | e99db5a | 2019-04-16 12:50:04 -0400 | [diff] [blame] | 1052 | applyRestrictions(zenPriorityOnly, false /*mute*/, usage); |
Jean-Michel Trivi | 7a84eae | 2017-06-20 14:58:18 -0700 | [diff] [blame] | 1053 | } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_NOTIFICATION) { |
Julia Reynolds | e99db5a | 2019-04-16 12:50:04 -0400 | [diff] [blame] | 1054 | applyRestrictions(zenPriorityOnly, muteNotifications || muteEverything, usage); |
Jean-Michel Trivi | e743bda | 2016-09-09 11:56:48 -0700 | [diff] [blame] | 1055 | } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_CALL) { |
Julia Reynolds | e99db5a | 2019-04-16 12:50:04 -0400 | [diff] [blame] | 1056 | applyRestrictions(zenPriorityOnly, muteCalls || muteEverything, usage); |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 1057 | } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_ALARM) { |
Julia Reynolds | e99db5a | 2019-04-16 12:50:04 -0400 | [diff] [blame] | 1058 | applyRestrictions(zenPriorityOnly, muteAlarms || muteEverything, usage); |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 1059 | } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_MEDIA) { |
Julia Reynolds | e99db5a | 2019-04-16 12:50:04 -0400 | [diff] [blame] | 1060 | applyRestrictions(zenPriorityOnly, muteMedia || muteEverything, usage); |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 1061 | } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_SYSTEM) { |
Beverly | 738bffd | 2018-03-12 10:46:17 -0400 | [diff] [blame] | 1062 | if (usage == AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) { |
| 1063 | // normally DND will only restrict touch sounds, not haptic feedback/vibrations |
Julia Reynolds | e99db5a | 2019-04-16 12:50:04 -0400 | [diff] [blame] | 1064 | applyRestrictions(zenPriorityOnly, muteSystem || muteEverything, usage, |
Beverly | 738bffd | 2018-03-12 10:46:17 -0400 | [diff] [blame] | 1065 | AppOpsManager.OP_PLAY_AUDIO); |
Julia Reynolds | e99db5a | 2019-04-16 12:50:04 -0400 | [diff] [blame] | 1066 | applyRestrictions(zenPriorityOnly, false, usage, AppOpsManager.OP_VIBRATE); |
Beverly | 738bffd | 2018-03-12 10:46:17 -0400 | [diff] [blame] | 1067 | } else { |
Julia Reynolds | e99db5a | 2019-04-16 12:50:04 -0400 | [diff] [blame] | 1068 | applyRestrictions(zenPriorityOnly, muteSystem || muteEverything, usage); |
Beverly | 738bffd | 2018-03-12 10:46:17 -0400 | [diff] [blame] | 1069 | } |
Julia Reynolds | 3fe81be | 2016-02-03 09:10:06 -0500 | [diff] [blame] | 1070 | } else { |
Julia Reynolds | e99db5a | 2019-04-16 12:50:04 -0400 | [diff] [blame] | 1071 | applyRestrictions(zenPriorityOnly, muteEverything, usage); |
Julia Reynolds | 3fe81be | 2016-02-03 09:10:06 -0500 | [diff] [blame] | 1072 | } |
| 1073 | } |
John Spurlock | 8403b75 | 2014-12-10 12:47:01 -0500 | [diff] [blame] | 1074 | } |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 1075 | |
Beverly | e2d9a23 | 2017-11-08 18:14:59 -0500 | [diff] [blame] | 1076 | |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 1077 | @VisibleForTesting |
Julia Reynolds | e99db5a | 2019-04-16 12:50:04 -0400 | [diff] [blame] | 1078 | protected void applyRestrictions(boolean zenPriorityOnly, boolean mute, int usage, int code) { |
| 1079 | final long ident = Binder.clearCallingIdentity(); |
| 1080 | try { |
| 1081 | mAppOps.setRestriction(code, usage, |
| 1082 | mute ? AppOpsManager.MODE_IGNORED : AppOpsManager.MODE_ALLOWED, |
| 1083 | zenPriorityOnly ? mPriorityOnlyDndExemptPackages : null); |
| 1084 | } finally { |
| 1085 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 1086 | } |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 1087 | } |
| 1088 | |
Beverly | 85f5241 | 2018-02-27 10:41:13 -0500 | [diff] [blame] | 1089 | @VisibleForTesting |
Julia Reynolds | e99db5a | 2019-04-16 12:50:04 -0400 | [diff] [blame] | 1090 | protected void applyRestrictions(boolean zenPriorityOnly, boolean mute, int usage) { |
| 1091 | applyRestrictions(zenPriorityOnly, mute, usage, AppOpsManager.OP_VIBRATE); |
| 1092 | applyRestrictions(zenPriorityOnly, mute, usage, AppOpsManager.OP_PLAY_AUDIO); |
Beverly | 738bffd | 2018-03-12 10:46:17 -0400 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | |
| 1096 | @VisibleForTesting |
Beverly | 85f5241 | 2018-02-27 10:41:13 -0500 | [diff] [blame] | 1097 | protected void applyZenToRingerMode() { |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1098 | if (mAudioManager == null) return; |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1099 | // force the ringer mode into compliance |
| 1100 | final int ringerModeInternal = mAudioManager.getRingerModeInternal(); |
| 1101 | int newRingerModeInternal = ringerModeInternal; |
John Spurlock | 5762779 | 2014-12-11 11:29:54 -0500 | [diff] [blame] | 1102 | switch (mZenMode) { |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1103 | case Global.ZEN_MODE_NO_INTERRUPTIONS: |
John Spurlock | 4f1163c | 2015-04-02 17:41:21 -0400 | [diff] [blame] | 1104 | case Global.ZEN_MODE_ALARMS: |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1105 | if (ringerModeInternal != AudioManager.RINGER_MODE_SILENT) { |
Julia Reynolds | 9b11fdb | 2015-07-31 09:49:55 -0400 | [diff] [blame] | 1106 | setPreviousRingerModeSetting(ringerModeInternal); |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1107 | newRingerModeInternal = AudioManager.RINGER_MODE_SILENT; |
John Spurlock | 8c01d88 | 2014-07-28 13:37:13 -0400 | [diff] [blame] | 1108 | } |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1109 | break; |
| 1110 | case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: |
Beverly | 9e4214d | 2018-03-26 11:10:10 -0400 | [diff] [blame] | 1111 | // do not apply zen to ringer, streams zen muted in AudioService |
Beverly | 925cde8 | 2018-01-23 09:31:23 -0500 | [diff] [blame] | 1112 | break; |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1113 | case Global.ZEN_MODE_OFF: |
| 1114 | if (ringerModeInternal == AudioManager.RINGER_MODE_SILENT) { |
Julia Reynolds | 9b11fdb | 2015-07-31 09:49:55 -0400 | [diff] [blame] | 1115 | newRingerModeInternal = getPreviousRingerModeSetting(); |
| 1116 | setPreviousRingerModeSetting(null); |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1117 | } |
| 1118 | break; |
John Spurlock | 8c01d88 | 2014-07-28 13:37:13 -0400 | [diff] [blame] | 1119 | } |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1120 | if (newRingerModeInternal != -1) { |
| 1121 | mAudioManager.setRingerModeInternal(newRingerModeInternal, TAG); |
| 1122 | } |
| 1123 | } |
| 1124 | |
John Spurlock | 1c923a3 | 2014-04-27 16:42:29 -0400 | [diff] [blame] | 1125 | private void dispatchOnConfigChanged() { |
| 1126 | for (Callback callback : mCallbacks) { |
| 1127 | callback.onConfigChanged(); |
| 1128 | } |
| 1129 | } |
| 1130 | |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1131 | private void dispatchOnPolicyChanged() { |
| 1132 | for (Callback callback : mCallbacks) { |
| 1133 | callback.onPolicyChanged(); |
| 1134 | } |
| 1135 | } |
| 1136 | |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 1137 | private void dispatchOnConsolidatedPolicyChanged() { |
| 1138 | for (Callback callback : mCallbacks) { |
| 1139 | callback.onConsolidatedPolicyChanged(); |
| 1140 | } |
| 1141 | } |
| 1142 | |
John Spurlock | 1c923a3 | 2014-04-27 16:42:29 -0400 | [diff] [blame] | 1143 | private void dispatchOnZenModeChanged() { |
| 1144 | for (Callback callback : mCallbacks) { |
| 1145 | callback.onZenModeChanged(); |
| 1146 | } |
| 1147 | } |
| 1148 | |
Julia Reynolds | 3ec9330 | 2019-07-11 15:27:31 -0400 | [diff] [blame] | 1149 | private void dispatchOnAutomaticRuleStatusChanged(int userId, String pkg, String id, |
| 1150 | int status) { |
| 1151 | for (Callback callback : mCallbacks) { |
| 1152 | callback.onAutomaticRuleStatusChanged(userId, pkg, id, status); |
| 1153 | } |
| 1154 | } |
| 1155 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1156 | private ZenModeConfig readDefaultConfig(Resources resources) { |
| 1157 | XmlResourceParser parser = null; |
| 1158 | try { |
| 1159 | parser = resources.getXml(R.xml.default_zen_mode_config); |
| 1160 | while (parser.next() != XmlPullParser.END_DOCUMENT) { |
Julia Reynolds | 206c7e9 | 2016-09-15 10:38:03 -0400 | [diff] [blame] | 1161 | final ZenModeConfig config = ZenModeConfig.readXml(parser); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1162 | if (config != null) return config; |
| 1163 | } |
| 1164 | } catch (Exception e) { |
| 1165 | Log.w(TAG, "Error reading default zen mode config from resource", e); |
| 1166 | } finally { |
| 1167 | IoUtils.closeQuietly(parser); |
| 1168 | } |
| 1169 | return new ZenModeConfig(); |
| 1170 | } |
| 1171 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1172 | private static int zenSeverity(int zen) { |
| 1173 | switch (zen) { |
| 1174 | case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: return 1; |
| 1175 | case Global.ZEN_MODE_ALARMS: return 2; |
| 1176 | case Global.ZEN_MODE_NO_INTERRUPTIONS: return 3; |
| 1177 | default: return 0; |
| 1178 | } |
| 1179 | } |
| 1180 | |
Chris Wren | 9316569 | 2020-05-15 16:12:41 -0400 | [diff] [blame] | 1181 | /** |
| 1182 | * Generate pulled atoms about do not disturb configurations. |
| 1183 | */ |
| 1184 | public void pullRules(List<StatsEvent> events) { |
| 1185 | synchronized (mConfig) { |
| 1186 | final int numConfigs = mConfigs.size(); |
| 1187 | int id = 0; |
| 1188 | for (int i = 0; i < numConfigs; i++) { |
| 1189 | final int user = mConfigs.keyAt(i); |
| 1190 | final ZenModeConfig config = mConfigs.valueAt(i); |
| 1191 | SysUiStatsEvent.Builder data = mStatsEventBuilderFactory.newBuilder() |
| 1192 | .setAtomId(DND_MODE_RULE) |
| 1193 | .writeInt(user) |
| 1194 | .writeBoolean(config.manualRule != null) // enabled |
| 1195 | .writeBoolean(config.areChannelsBypassingDnd) |
| 1196 | .writeInt(ROOT_CONFIG) |
| 1197 | .writeString("") // name, empty for root config |
| 1198 | .writeInt(Process.SYSTEM_UID) // system owns root config |
| 1199 | .addBooleanAnnotation(ANNOTATION_ID_IS_UID, true) |
| 1200 | .writeByteArray(config.toZenPolicy().toProto()); |
| 1201 | events.add(data.build()); |
| 1202 | if (config.manualRule != null && config.manualRule.enabler != null) { |
| 1203 | ruleToProto(user, config.manualRule, events); |
| 1204 | } |
| 1205 | for (ZenRule rule : config.automaticRules.values()) { |
| 1206 | ruleToProto(user, rule, events); |
| 1207 | } |
| 1208 | } |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | private void ruleToProto(int user, ZenRule rule, List<StatsEvent> events) { |
| 1213 | // Make the ID safe. |
| 1214 | String id = rule.id == null ? "" : rule.id; |
| 1215 | if (!ZenModeConfig.DEFAULT_RULE_IDS.contains(id)) { |
| 1216 | id = ""; |
| 1217 | } |
| 1218 | |
| 1219 | // Look for packages and enablers, enablers get priority. |
| 1220 | String pkg = rule.pkg == null ? "" : rule.pkg; |
| 1221 | if (rule.enabler != null) { |
| 1222 | pkg = rule.enabler; |
| 1223 | id = ZenModeConfig.MANUAL_RULE_ID; |
| 1224 | } |
| 1225 | |
| 1226 | // TODO: fetch the uid from the package manager |
| 1227 | int uid = "android".equals(pkg) ? Process.SYSTEM_UID : 0; |
| 1228 | |
| 1229 | SysUiStatsEvent.Builder data; |
| 1230 | data = mStatsEventBuilderFactory.newBuilder() |
| 1231 | .setAtomId(DND_MODE_RULE) |
| 1232 | .writeInt(user) |
| 1233 | .writeBoolean(rule.enabled) |
| 1234 | .writeBoolean(false) // channels_bypassing unused for rules |
| 1235 | .writeInt(rule.zenMode) |
| 1236 | .writeString(id) |
| 1237 | .writeInt(uid) |
| 1238 | .addBooleanAnnotation(ANNOTATION_ID_IS_UID, true); |
| 1239 | byte[] policyProto = new byte[]{}; |
| 1240 | if (rule.zenPolicy != null) { |
| 1241 | policyProto = rule.zenPolicy.toProto(); |
| 1242 | } |
| 1243 | data.writeByteArray(policyProto); |
| 1244 | events.add(data.build()); |
| 1245 | } |
| 1246 | |
Beverly | 85f5241 | 2018-02-27 10:41:13 -0500 | [diff] [blame] | 1247 | @VisibleForTesting |
| 1248 | protected final class RingerModeDelegate implements AudioManagerInternal.RingerModeDelegate { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1249 | @Override |
| 1250 | public String toString() { |
| 1251 | return TAG; |
| 1252 | } |
| 1253 | |
| 1254 | @Override |
| 1255 | public int onSetRingerModeInternal(int ringerModeOld, int ringerModeNew, String caller, |
| 1256 | int ringerModeExternal, VolumePolicy policy) { |
| 1257 | final boolean isChange = ringerModeOld != ringerModeNew; |
| 1258 | |
| 1259 | int ringerModeExternalOut = ringerModeNew; |
| 1260 | |
Beverly | e4ee1cc | 2018-03-06 17:21:08 -0500 | [diff] [blame] | 1261 | if (mZenMode == Global.ZEN_MODE_OFF |
| 1262 | || (mZenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS |
Beverly | 85dfc2e | 2019-09-20 11:26:34 -0400 | [diff] [blame] | 1263 | && !ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted(mConfig))) { |
Beverly | e4ee1cc | 2018-03-06 17:21:08 -0500 | [diff] [blame] | 1264 | // in priority only with ringer not muted, save ringer mode changes |
| 1265 | // in dnd off, save ringer mode changes |
| 1266 | setPreviousRingerModeSetting(ringerModeNew); |
| 1267 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1268 | int newZen = -1; |
| 1269 | switch (ringerModeNew) { |
| 1270 | case AudioManager.RINGER_MODE_SILENT: |
| 1271 | if (isChange && policy.doNotDisturbWhenSilent) { |
Beverly | 925cde8 | 2018-01-23 09:31:23 -0500 | [diff] [blame] | 1272 | if (mZenMode == Global.ZEN_MODE_OFF) { |
Julia Reynolds | f3252be | 2018-01-17 09:26:21 -0500 | [diff] [blame] | 1273 | newZen = Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1274 | } |
Julia Reynolds | 9b11fdb | 2015-07-31 09:49:55 -0400 | [diff] [blame] | 1275 | setPreviousRingerModeSetting(ringerModeOld); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1276 | } |
| 1277 | break; |
| 1278 | case AudioManager.RINGER_MODE_VIBRATE: |
| 1279 | case AudioManager.RINGER_MODE_NORMAL: |
| 1280 | if (isChange && ringerModeOld == AudioManager.RINGER_MODE_SILENT |
| 1281 | && (mZenMode == Global.ZEN_MODE_NO_INTERRUPTIONS |
Beverly | 925cde8 | 2018-01-23 09:31:23 -0500 | [diff] [blame] | 1282 | || mZenMode == Global.ZEN_MODE_ALARMS |
| 1283 | || (mZenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS |
Beverly | 85dfc2e | 2019-09-20 11:26:34 -0400 | [diff] [blame] | 1284 | && ZenModeConfig.areAllPriorityOnlyRingerSoundsMuted( |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 1285 | mConfig)))) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1286 | newZen = Global.ZEN_MODE_OFF; |
| 1287 | } else if (mZenMode != Global.ZEN_MODE_OFF) { |
| 1288 | ringerModeExternalOut = AudioManager.RINGER_MODE_SILENT; |
| 1289 | } |
| 1290 | break; |
| 1291 | } |
Beverly | 85f5241 | 2018-02-27 10:41:13 -0500 | [diff] [blame] | 1292 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1293 | if (newZen != -1) { |
Julia Reynolds | 44ad6ff | 2016-07-06 09:47:45 -0400 | [diff] [blame] | 1294 | setManualZenMode(newZen, null, "ringerModeInternal", null, |
| 1295 | false /*setRingerMode*/); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1296 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1297 | if (isChange || newZen != -1 || ringerModeExternal != ringerModeExternalOut) { |
| 1298 | ZenLog.traceSetRingerModeInternal(ringerModeOld, ringerModeNew, caller, |
| 1299 | ringerModeExternal, ringerModeExternalOut); |
| 1300 | } |
| 1301 | return ringerModeExternalOut; |
| 1302 | } |
| 1303 | |
| 1304 | @Override |
| 1305 | public int onSetRingerModeExternal(int ringerModeOld, int ringerModeNew, String caller, |
| 1306 | int ringerModeInternal, VolumePolicy policy) { |
| 1307 | int ringerModeInternalOut = ringerModeNew; |
| 1308 | final boolean isChange = ringerModeOld != ringerModeNew; |
| 1309 | final boolean isVibrate = ringerModeInternal == AudioManager.RINGER_MODE_VIBRATE; |
| 1310 | |
| 1311 | int newZen = -1; |
| 1312 | switch (ringerModeNew) { |
| 1313 | case AudioManager.RINGER_MODE_SILENT: |
| 1314 | if (isChange) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1315 | ringerModeInternalOut = isVibrate ? AudioManager.RINGER_MODE_VIBRATE |
John Spurlock | 05715ec | 2015-05-13 11:19:19 -0400 | [diff] [blame] | 1316 | : AudioManager.RINGER_MODE_SILENT; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1317 | } else { |
| 1318 | ringerModeInternalOut = ringerModeInternal; |
| 1319 | } |
| 1320 | break; |
| 1321 | case AudioManager.RINGER_MODE_VIBRATE: |
| 1322 | case AudioManager.RINGER_MODE_NORMAL: |
| 1323 | if (mZenMode != Global.ZEN_MODE_OFF) { |
| 1324 | newZen = Global.ZEN_MODE_OFF; |
| 1325 | } |
| 1326 | break; |
| 1327 | } |
| 1328 | if (newZen != -1) { |
Julia Reynolds | 44ad6ff | 2016-07-06 09:47:45 -0400 | [diff] [blame] | 1329 | setManualZenMode(newZen, null, "ringerModeExternal", caller, |
| 1330 | false /*setRingerMode*/); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | ZenLog.traceSetRingerModeExternal(ringerModeOld, ringerModeNew, caller, |
| 1334 | ringerModeInternal, ringerModeInternalOut); |
| 1335 | return ringerModeInternalOut; |
| 1336 | } |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 1337 | |
| 1338 | @Override |
| 1339 | public boolean canVolumeDownEnterSilent() { |
| 1340 | return mZenMode == Global.ZEN_MODE_OFF; |
| 1341 | } |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 1342 | |
| 1343 | @Override |
| 1344 | public int getRingerModeAffectedStreams(int streams) { |
Beverly | 85dfc2e | 2019-09-20 11:26:34 -0400 | [diff] [blame] | 1345 | // ringtone, notification and system streams are always affected by ringer mode |
| 1346 | // zen muting is handled in AudioService.java's mZenModeAffectedStreams |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 1347 | streams |= (1 << AudioSystem.STREAM_RING) | |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 1348 | (1 << AudioSystem.STREAM_NOTIFICATION) | |
| 1349 | (1 << AudioSystem.STREAM_SYSTEM); |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 1350 | |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 1351 | if (mZenMode == Global.ZEN_MODE_NO_INTERRUPTIONS) { |
Julia Reynolds | a6b653f | 2020-03-09 11:26:19 -0400 | [diff] [blame] | 1352 | // alarm and music and streams affected by ringer mode (cannot be adjusted) when in |
Beverly | 85dfc2e | 2019-09-20 11:26:34 -0400 | [diff] [blame] | 1353 | // total silence |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 1354 | streams |= (1 << AudioSystem.STREAM_ALARM) | |
Julia Reynolds | a6b653f | 2020-03-09 11:26:19 -0400 | [diff] [blame] | 1355 | (1 << AudioSystem.STREAM_MUSIC) | |
| 1356 | (1 << AudioSystem.STREAM_ASSISTANT); |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 1357 | } else { |
| 1358 | streams &= ~((1 << AudioSystem.STREAM_ALARM) | |
Julia Reynolds | a6b653f | 2020-03-09 11:26:19 -0400 | [diff] [blame] | 1359 | (1 << AudioSystem.STREAM_MUSIC) | |
| 1360 | (1 << AudioSystem.STREAM_ASSISTANT) |
| 1361 | ); |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 1362 | } |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 1363 | return streams; |
| 1364 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | private final class SettingsObserver extends ContentObserver { |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 1368 | private final Uri ZEN_MODE = Global.getUriFor(Global.ZEN_MODE); |
| 1369 | |
| 1370 | public SettingsObserver(Handler handler) { |
| 1371 | super(handler); |
| 1372 | } |
| 1373 | |
| 1374 | public void observe() { |
| 1375 | final ContentResolver resolver = mContext.getContentResolver(); |
| 1376 | resolver.registerContentObserver(ZEN_MODE, false /*notifyForDescendents*/, this); |
| 1377 | update(null); |
| 1378 | } |
| 1379 | |
| 1380 | @Override |
| 1381 | public void onChange(boolean selfChange, Uri uri) { |
| 1382 | update(uri); |
| 1383 | } |
| 1384 | |
| 1385 | public void update(Uri uri) { |
| 1386 | if (ZEN_MODE.equals(uri)) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1387 | if (mZenMode != getZenModeSetting()) { |
| 1388 | if (DEBUG) Log.d(TAG, "Fixing zen mode setting"); |
| 1389 | setZenModeSetting(mZenMode); |
| 1390 | } |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 1391 | } |
| 1392 | } |
| 1393 | } |
| 1394 | |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 1395 | private void showZenUpgradeNotification(int zen) { |
Nick | a485ec6 | 2018-07-03 11:32:39 -0700 | [diff] [blame] | 1396 | final boolean isWatch = mContext.getPackageManager().hasSystemFeature( |
| 1397 | PackageManager.FEATURE_WATCH); |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 1398 | final boolean showNotification = mIsBootComplete |
Julia Reynolds | 76bfa60 | 2018-04-23 09:38:47 -0400 | [diff] [blame] | 1399 | && zen != Global.ZEN_MODE_OFF |
Nick | a485ec6 | 2018-07-03 11:32:39 -0700 | [diff] [blame] | 1400 | && !isWatch |
Beverly | 9087cd1 | 2018-09-21 15:30:49 -0400 | [diff] [blame] | 1401 | && Settings.Secure.getInt(mContext.getContentResolver(), |
Beverly | 6c60b90 | 2018-08-17 10:10:46 -0400 | [diff] [blame] | 1402 | Settings.Secure.SHOW_ZEN_UPGRADE_NOTIFICATION, 0) != 0 |
Beverly | 9087cd1 | 2018-09-21 15:30:49 -0400 | [diff] [blame] | 1403 | && Settings.Secure.getInt(mContext.getContentResolver(), |
Beverly | 6c60b90 | 2018-08-17 10:10:46 -0400 | [diff] [blame] | 1404 | Settings.Secure.ZEN_SETTINGS_UPDATED, 0) != 1; |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 1405 | |
Nick | a485ec6 | 2018-07-03 11:32:39 -0700 | [diff] [blame] | 1406 | if (isWatch) { |
Beverly | 9087cd1 | 2018-09-21 15:30:49 -0400 | [diff] [blame] | 1407 | Settings.Secure.putInt(mContext.getContentResolver(), |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 1408 | Settings.Secure.SHOW_ZEN_UPGRADE_NOTIFICATION, 0); |
Nick | a485ec6 | 2018-07-03 11:32:39 -0700 | [diff] [blame] | 1409 | } |
| 1410 | |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 1411 | if (showNotification) { |
| 1412 | mNotificationManager.notify(TAG, SystemMessage.NOTE_ZEN_UPGRADE, |
| 1413 | createZenUpgradeNotification()); |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 1414 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 1415 | Settings.Secure.SHOW_ZEN_UPGRADE_NOTIFICATION, 0); |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | @VisibleForTesting |
| 1420 | protected Notification createZenUpgradeNotification() { |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 1421 | final Bundle extras = new Bundle(); |
| 1422 | extras.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME, |
| 1423 | mContext.getResources().getString(R.string.global_action_settings)); |
Julia Reynolds | 0b8455d | 2018-03-14 11:38:44 -0400 | [diff] [blame] | 1424 | int title = R.string.zen_upgrade_notification_title; |
| 1425 | int content = R.string.zen_upgrade_notification_content; |
Julia Reynolds | 76bfa60 | 2018-04-23 09:38:47 -0400 | [diff] [blame] | 1426 | int drawable = R.drawable.ic_zen_24dp; |
Julia Reynolds | 0b8455d | 2018-03-14 11:38:44 -0400 | [diff] [blame] | 1427 | if (NotificationManager.Policy.areAllVisualEffectsSuppressed( |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 1428 | getConsolidatedNotificationPolicy().suppressedVisualEffects)) { |
Julia Reynolds | 0b8455d | 2018-03-14 11:38:44 -0400 | [diff] [blame] | 1429 | title = R.string.zen_upgrade_notification_visd_title; |
| 1430 | content = R.string.zen_upgrade_notification_visd_content; |
Julia Reynolds | 76bfa60 | 2018-04-23 09:38:47 -0400 | [diff] [blame] | 1431 | drawable = R.drawable.ic_dnd_block_notifications; |
Julia Reynolds | 0b8455d | 2018-03-14 11:38:44 -0400 | [diff] [blame] | 1432 | } |
Julia Reynolds | 76bfa60 | 2018-04-23 09:38:47 -0400 | [diff] [blame] | 1433 | |
Julia Reynolds | 9aa1c9e | 2018-04-09 11:31:15 -0400 | [diff] [blame] | 1434 | Intent onboardingIntent = new Intent(Settings.ZEN_MODE_ONBOARDING); |
| 1435 | onboardingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
Julia Reynolds | 0b8455d | 2018-03-14 11:38:44 -0400 | [diff] [blame] | 1436 | return new Notification.Builder(mContext, SystemNotificationChannels.DO_NOT_DISTURB) |
Julia Reynolds | 9aa1c9e | 2018-04-09 11:31:15 -0400 | [diff] [blame] | 1437 | .setAutoCancel(true) |
Beverly | d8b15ee | 2018-02-13 14:37:38 -0500 | [diff] [blame] | 1438 | .setSmallIcon(R.drawable.ic_settings_24dp) |
Julia Reynolds | 76bfa60 | 2018-04-23 09:38:47 -0400 | [diff] [blame] | 1439 | .setLargeIcon(Icon.createWithResource(mContext, drawable)) |
Julia Reynolds | 0b8455d | 2018-03-14 11:38:44 -0400 | [diff] [blame] | 1440 | .setContentTitle(mContext.getResources().getString(title)) |
| 1441 | .setContentText(mContext.getResources().getString(content)) |
Julia Reynolds | 9aa1c9e | 2018-04-09 11:31:15 -0400 | [diff] [blame] | 1442 | .setContentIntent(PendingIntent.getActivity(mContext, 0, onboardingIntent, |
Julia Reynolds | d7f2b7d | 2020-05-08 14:14:25 -0400 | [diff] [blame] | 1443 | PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE)) |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 1444 | .setAutoCancel(true) |
| 1445 | .setLocalOnly(true) |
| 1446 | .addExtras(extras) |
Julia Reynolds | 0b8455d | 2018-03-14 11:38:44 -0400 | [diff] [blame] | 1447 | .setStyle(new Notification.BigTextStyle()) |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 1448 | .build(); |
| 1449 | } |
| 1450 | |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1451 | private final class Metrics extends Callback { |
Julia Reynolds | 3dfdde0 | 2018-10-08 09:17:56 -0400 | [diff] [blame] | 1452 | private static final String COUNTER_MODE_PREFIX = "dnd_mode_"; |
| 1453 | private static final String COUNTER_TYPE_PREFIX = "dnd_type_"; |
| 1454 | private static final int DND_OFF = 0; |
| 1455 | private static final int DND_ON_MANUAL = 1; |
| 1456 | private static final int DND_ON_AUTOMATIC = 2; |
| 1457 | private static final String COUNTER_RULE = "dnd_rule_count"; |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1458 | private static final long MINIMUM_LOG_PERIOD_MS = 60 * 1000; |
| 1459 | |
Julia Reynolds | 3dfdde0 | 2018-10-08 09:17:56 -0400 | [diff] [blame] | 1460 | // Total silence, alarms only, priority only |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1461 | private int mPreviousZenMode = -1; |
Julia Reynolds | 3dfdde0 | 2018-10-08 09:17:56 -0400 | [diff] [blame] | 1462 | private long mModeLogTimeMs = 0L; |
| 1463 | |
| 1464 | private int mNumZenRules = -1; |
| 1465 | private long mRuleCountLogTime = 0L; |
| 1466 | |
| 1467 | // automatic (1) vs manual (0) vs dnd off (2) |
| 1468 | private int mPreviousZenType = -1; |
| 1469 | private long mTypeLogTimeMs = 0L; |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1470 | |
| 1471 | @Override |
| 1472 | void onZenModeChanged() { |
| 1473 | emit(); |
| 1474 | } |
| 1475 | |
Julia Reynolds | 3dfdde0 | 2018-10-08 09:17:56 -0400 | [diff] [blame] | 1476 | @Override |
| 1477 | void onConfigChanged() { |
| 1478 | emit(); |
| 1479 | } |
| 1480 | |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1481 | private void emit() { |
| 1482 | mHandler.postMetricsTimer(); |
Julia Reynolds | 3dfdde0 | 2018-10-08 09:17:56 -0400 | [diff] [blame] | 1483 | emitZenMode(); |
| 1484 | emitRules(); |
| 1485 | emitDndType(); |
| 1486 | } |
| 1487 | |
| 1488 | private void emitZenMode() { |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1489 | final long now = SystemClock.elapsedRealtime(); |
Julia Reynolds | 3dfdde0 | 2018-10-08 09:17:56 -0400 | [diff] [blame] | 1490 | final long since = (now - mModeLogTimeMs); |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1491 | if (mPreviousZenMode != mZenMode || since > MINIMUM_LOG_PERIOD_MS) { |
| 1492 | if (mPreviousZenMode != -1) { |
Julia Reynolds | 3dfdde0 | 2018-10-08 09:17:56 -0400 | [diff] [blame] | 1493 | MetricsLogger.count( |
| 1494 | mContext, COUNTER_MODE_PREFIX + mPreviousZenMode, (int) since); |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1495 | } |
| 1496 | mPreviousZenMode = mZenMode; |
Julia Reynolds | 3dfdde0 | 2018-10-08 09:17:56 -0400 | [diff] [blame] | 1497 | mModeLogTimeMs = now; |
| 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | private void emitRules() { |
| 1502 | final long now = SystemClock.elapsedRealtime(); |
| 1503 | final long since = (now - mRuleCountLogTime); |
| 1504 | synchronized (mConfig) { |
| 1505 | int numZenRules = mConfig.automaticRules.size(); |
| 1506 | if (mNumZenRules != numZenRules |
| 1507 | || since > MINIMUM_LOG_PERIOD_MS) { |
| 1508 | if (mNumZenRules != -1) { |
| 1509 | MetricsLogger.count(mContext, COUNTER_RULE, |
| 1510 | numZenRules - mNumZenRules); |
| 1511 | } |
| 1512 | mNumZenRules = numZenRules; |
| 1513 | |
| 1514 | mRuleCountLogTime = since; |
| 1515 | } |
| 1516 | } |
| 1517 | } |
| 1518 | |
| 1519 | private void emitDndType() { |
| 1520 | final long now = SystemClock.elapsedRealtime(); |
| 1521 | final long since = (now - mTypeLogTimeMs); |
| 1522 | synchronized (mConfig) { |
| 1523 | boolean dndOn = mZenMode != Global.ZEN_MODE_OFF; |
| 1524 | int zenType = !dndOn ? DND_OFF |
| 1525 | : (mConfig.manualRule != null) ? DND_ON_MANUAL : DND_ON_AUTOMATIC; |
| 1526 | if (zenType != mPreviousZenType |
| 1527 | || since > MINIMUM_LOG_PERIOD_MS) { |
| 1528 | if (mPreviousZenType != -1) { |
| 1529 | MetricsLogger.count( |
| 1530 | mContext, COUNTER_TYPE_PREFIX + mPreviousZenType, (int) since); |
| 1531 | } |
| 1532 | mTypeLogTimeMs = now; |
| 1533 | mPreviousZenType = zenType; |
| 1534 | } |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1535 | } |
| 1536 | } |
| 1537 | } |
| 1538 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1539 | private final class H extends Handler { |
John Spurlock | 5762779 | 2014-12-11 11:29:54 -0500 | [diff] [blame] | 1540 | private static final int MSG_DISPATCH = 1; |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1541 | private static final int MSG_METRICS = 2; |
Julia Reynolds | d82e981 | 2016-04-19 13:27:41 -0400 | [diff] [blame] | 1542 | private static final int MSG_APPLY_CONFIG = 4; |
Eric Laurent | e0ced4d | 2015-09-30 17:44:28 -0700 | [diff] [blame] | 1543 | |
| 1544 | private final class ConfigMessageData { |
| 1545 | public final ZenModeConfig config; |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 1546 | public ComponentName triggeringComponent; |
Eric Laurent | e0ced4d | 2015-09-30 17:44:28 -0700 | [diff] [blame] | 1547 | public final String reason; |
Julia Reynolds | d82e981 | 2016-04-19 13:27:41 -0400 | [diff] [blame] | 1548 | public final boolean setRingerMode; |
Eric Laurent | e0ced4d | 2015-09-30 17:44:28 -0700 | [diff] [blame] | 1549 | |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 1550 | ConfigMessageData(ZenModeConfig config, String reason, |
| 1551 | ComponentName triggeringComponent, boolean setRingerMode) { |
Julia Reynolds | d82e981 | 2016-04-19 13:27:41 -0400 | [diff] [blame] | 1552 | this.config = config; |
| 1553 | this.reason = reason; |
| 1554 | this.setRingerMode = setRingerMode; |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 1555 | this.triggeringComponent = triggeringComponent; |
Eric Laurent | e0ced4d | 2015-09-30 17:44:28 -0700 | [diff] [blame] | 1556 | } |
| 1557 | } |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1558 | |
| 1559 | private static final long METRICS_PERIOD_MS = 6 * 60 * 60 * 1000; |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1560 | |
| 1561 | private H(Looper looper) { |
| 1562 | super(looper); |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 1563 | } |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1564 | |
John Spurlock | 5762779 | 2014-12-11 11:29:54 -0500 | [diff] [blame] | 1565 | private void postDispatchOnZenModeChanged() { |
| 1566 | removeMessages(MSG_DISPATCH); |
| 1567 | sendEmptyMessage(MSG_DISPATCH); |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1568 | } |
| 1569 | |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1570 | private void postMetricsTimer() { |
| 1571 | removeMessages(MSG_METRICS); |
| 1572 | sendEmptyMessageDelayed(MSG_METRICS, METRICS_PERIOD_MS); |
| 1573 | } |
| 1574 | |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 1575 | private void postApplyConfig(ZenModeConfig config, String reason, |
| 1576 | ComponentName triggeringComponent, boolean setRingerMode) { |
Julia Reynolds | d82e981 | 2016-04-19 13:27:41 -0400 | [diff] [blame] | 1577 | sendMessage(obtainMessage(MSG_APPLY_CONFIG, |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 1578 | new ConfigMessageData(config, reason, triggeringComponent, setRingerMode))); |
Julia Reynolds | d82e981 | 2016-04-19 13:27:41 -0400 | [diff] [blame] | 1579 | } |
| 1580 | |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1581 | @Override |
| 1582 | public void handleMessage(Message msg) { |
John Spurlock | 5762779 | 2014-12-11 11:29:54 -0500 | [diff] [blame] | 1583 | switch (msg.what) { |
| 1584 | case MSG_DISPATCH: |
| 1585 | dispatchOnZenModeChanged(); |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1586 | break; |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1587 | case MSG_METRICS: |
| 1588 | mMetrics.emit(); |
| 1589 | break; |
Julia Reynolds | d82e981 | 2016-04-19 13:27:41 -0400 | [diff] [blame] | 1590 | case MSG_APPLY_CONFIG: |
| 1591 | ConfigMessageData applyConfigData = (ConfigMessageData) msg.obj; |
| 1592 | applyConfig(applyConfigData.config, applyConfigData.reason, |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 1593 | applyConfigData.triggeringComponent, applyConfigData.setRingerMode); |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1594 | } |
| 1595 | } |
| 1596 | } |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 1597 | |
John Spurlock | 1c923a3 | 2014-04-27 16:42:29 -0400 | [diff] [blame] | 1598 | public static class Callback { |
| 1599 | void onConfigChanged() {} |
| 1600 | void onZenModeChanged() {} |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1601 | void onPolicyChanged() {} |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 1602 | void onConsolidatedPolicyChanged() {} |
Julia Reynolds | 3ec9330 | 2019-07-11 15:27:31 -0400 | [diff] [blame] | 1603 | void onAutomaticRuleStatusChanged(int userId, String pkg, String id, int status) {} |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 1604 | } |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 1605 | } |