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 | |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 19 | import android.app.AppOpsManager; |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 20 | import android.app.AutomaticZenRule; |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 21 | import android.app.Notification; |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 22 | import android.app.NotificationManager; |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 23 | import android.app.NotificationManager.Policy; |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 24 | import android.app.PendingIntent; |
John Spurlock | 312d1d0 | 2014-07-08 10:24:57 -0400 | [diff] [blame] | 25 | import android.content.ComponentName; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 26 | import android.content.ContentResolver; |
| 27 | import android.content.Context; |
Julia Reynolds | 0ae2b0b | 2016-01-14 09:58:03 -0500 | [diff] [blame] | 28 | import android.content.Intent; |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 29 | import android.content.pm.PackageManager; |
Julia Reynolds | 0ae2b0b | 2016-01-14 09:58:03 -0500 | [diff] [blame] | 30 | import android.content.pm.ResolveInfo; |
| 31 | import android.content.pm.ServiceInfo; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 32 | import android.content.res.Resources; |
| 33 | import android.content.res.XmlResourceParser; |
| 34 | import android.database.ContentObserver; |
Julia Reynolds | 9aa1c9e | 2018-04-09 11:31:15 -0400 | [diff] [blame] | 35 | import android.graphics.drawable.Icon; |
Jean-Michel Trivi | e743bda | 2016-09-09 11:56:48 -0700 | [diff] [blame] | 36 | import android.media.AudioAttributes; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 37 | import android.media.AudioManager; |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 38 | import android.media.AudioManagerInternal; |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 39 | import android.media.AudioSystem; |
John Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 40 | import android.media.VolumePolicy; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 41 | import android.net.Uri; |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 42 | import android.os.Binder; |
John Spurlock | 2b122f4 | 2014-08-27 16:29:47 -0400 | [diff] [blame] | 43 | import android.os.Bundle; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 44 | import android.os.Handler; |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
Julia Reynolds | c8e54e8 | 2015-11-30 16:43:05 -0500 | [diff] [blame] | 47 | import android.os.Process; |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 48 | import android.os.SystemClock; |
John Spurlock | b5e767b | 2014-07-27 11:53:20 -0400 | [diff] [blame] | 49 | import android.os.UserHandle; |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 50 | import android.provider.Settings; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 51 | import android.provider.Settings.Global; |
Julia Reynolds | 520df6e | 2017-02-13 09:05:10 -0500 | [diff] [blame] | 52 | import android.service.notification.Condition; |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 53 | import android.service.notification.ConditionProviderService; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 54 | import android.service.notification.ZenModeConfig; |
John Spurlock | cb9aa20 | 2015-05-08 17:35:22 -0400 | [diff] [blame] | 55 | import android.service.notification.ZenModeConfig.EventInfo; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 56 | import android.service.notification.ZenModeConfig.ScheduleInfo; |
| 57 | import android.service.notification.ZenModeConfig.ZenRule; |
Julia Reynolds | 520df6e | 2017-02-13 09:05:10 -0500 | [diff] [blame] | 58 | import android.service.notification.ZenModeProto; |
Julia Reynolds | 87c4277 | 2016-05-16 09:52:17 -0400 | [diff] [blame] | 59 | import android.util.AndroidRuntimeException; |
Beverly | 4e2f76c | 2018-03-16 15:43:49 -0400 | [diff] [blame] | 60 | import android.util.ArrayMap; |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 61 | import android.util.Log; |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 62 | import android.util.Slog; |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 63 | import android.util.SparseArray; |
Julia Reynolds | 520df6e | 2017-02-13 09:05:10 -0500 | [diff] [blame] | 64 | import android.util.proto.ProtoOutputStream; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 65 | |
| 66 | import com.android.internal.R; |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 67 | import com.android.internal.annotations.VisibleForTesting; |
John Spurlock | 25d01ee | 2015-06-03 12:17:46 -0400 | [diff] [blame] | 68 | import com.android.internal.logging.MetricsLogger; |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 69 | import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; |
| 70 | import com.android.internal.notification.SystemNotificationChannels; |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 71 | import com.android.server.LocalServices; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 72 | |
| 73 | import libcore.io.IoUtils; |
| 74 | |
| 75 | import org.xmlpull.v1.XmlPullParser; |
| 76 | import org.xmlpull.v1.XmlPullParserException; |
| 77 | import org.xmlpull.v1.XmlSerializer; |
| 78 | |
| 79 | import java.io.IOException; |
| 80 | import java.io.PrintWriter; |
John Spurlock | 1c923a3 | 2014-04-27 16:42:29 -0400 | [diff] [blame] | 81 | import java.util.ArrayList; |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 82 | import java.util.List; |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 83 | import java.util.Objects; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * NotificationManagerService helper for functionality related to zen mode. |
| 87 | */ |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 88 | public class ZenModeHelper { |
| 89 | static final String TAG = "ZenModeHelper"; |
| 90 | static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 91 | |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 92 | // The amount of time rules instances can exist without their owning app being installed. |
| 93 | private static final int RULE_INSTANCE_GRACE_PERIOD = 1000 * 60 * 60 * 72; |
| 94 | |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 95 | private final Context mContext; |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 96 | private final H mHandler; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 97 | private final SettingsObserver mSettingsObserver; |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 98 | @VisibleForTesting protected final AppOpsManager mAppOps; |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 99 | @VisibleForTesting protected final NotificationManager mNotificationManager; |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 100 | protected ZenModeConfig mDefaultConfig; |
John Spurlock | 1c923a3 | 2014-04-27 16:42:29 -0400 | [diff] [blame] | 101 | private final ArrayList<Callback> mCallbacks = new ArrayList<Callback>(); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 102 | private final ZenModeFiltering mFiltering; |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 103 | protected final RingerModeDelegate mRingerModeDelegate = new |
| 104 | RingerModeDelegate(); |
Beverly | 2f43b64 | 2018-08-14 09:43:11 -0400 | [diff] [blame] | 105 | @VisibleForTesting protected final ZenModeConditions mConditions; |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 106 | private final SparseArray<ZenModeConfig> mConfigs = new SparseArray<>(); |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 107 | private final Metrics mMetrics = new Metrics(); |
Julia Reynolds | 0ae2b0b | 2016-01-14 09:58:03 -0500 | [diff] [blame] | 108 | private final ConditionProviders.Config mServiceConfig; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 109 | |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 110 | @VisibleForTesting protected int mZenMode; |
Xiaohui Chen | ddbe4ca | 2015-08-13 16:20:56 -0700 | [diff] [blame] | 111 | private int mUser = UserHandle.USER_SYSTEM; |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 112 | @VisibleForTesting protected ZenModeConfig mConfig; |
Beverly | 85f5241 | 2018-02-27 10:41:13 -0500 | [diff] [blame] | 113 | @VisibleForTesting protected AudioManagerInternal mAudioManager; |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 114 | protected PackageManager mPm; |
Bryce Lee | 7219ada | 2016-04-08 10:54:23 -0700 | [diff] [blame] | 115 | private long mSuppressedEffects; |
| 116 | |
| 117 | public static final long SUPPRESSED_EFFECT_NOTIFICATIONS = 1; |
| 118 | public static final long SUPPRESSED_EFFECT_CALLS = 1 << 1; |
| 119 | public static final long SUPPRESSED_EFFECT_ALL = SUPPRESSED_EFFECT_CALLS |
| 120 | | SUPPRESSED_EFFECT_NOTIFICATIONS; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 121 | |
Beverly | 26eba87 | 2017-12-04 16:30:11 -0500 | [diff] [blame] | 122 | protected String mDefaultRuleEveryNightName; |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 123 | protected String mDefaultRuleEventsName; |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 124 | @VisibleForTesting protected boolean mIsBootComplete; |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 125 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 126 | public ZenModeHelper(Context context, Looper looper, ConditionProviders conditionProviders) { |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 127 | mContext = context; |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 128 | mHandler = new H(looper); |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 129 | addCallback(mMetrics); |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 130 | mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 131 | mNotificationManager = context.getSystemService(NotificationManager.class); |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 132 | |
| 133 | mDefaultConfig = new ZenModeConfig(); |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 134 | setDefaultZenRules(mContext); |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 135 | mConfig = mDefaultConfig; |
Xiaohui Chen | ddbe4ca | 2015-08-13 16:20:56 -0700 | [diff] [blame] | 136 | mConfigs.put(UserHandle.USER_SYSTEM, mConfig); |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 137 | |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 138 | mSettingsObserver = new SettingsObserver(mHandler); |
| 139 | mSettingsObserver.observe(); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 140 | mFiltering = new ZenModeFiltering(mContext); |
| 141 | mConditions = new ZenModeConditions(this, conditionProviders); |
Julia Reynolds | 0ae2b0b | 2016-01-14 09:58:03 -0500 | [diff] [blame] | 142 | mServiceConfig = conditionProviders.getConfig(); |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 143 | } |
| 144 | |
John Spurlock | 1b8b22b | 2015-05-20 09:47:13 -0400 | [diff] [blame] | 145 | public Looper getLooper() { |
| 146 | return mHandler.getLooper(); |
| 147 | } |
| 148 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 149 | @Override |
| 150 | public String toString() { |
| 151 | return TAG; |
| 152 | } |
| 153 | |
| 154 | public boolean matchesCallFilter(UserHandle userHandle, Bundle extras, |
| 155 | ValidateNotificationPeople validator, int contactsTimeoutMs, float timeoutAffinity) { |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 156 | synchronized (mConfig) { |
| 157 | return ZenModeFiltering.matchesCallFilter(mContext, mZenMode, mConfig, userHandle, |
Julia Reynolds | c6b371b | 2016-06-14 08:31:03 -0400 | [diff] [blame] | 158 | extras, validator, contactsTimeoutMs, timeoutAffinity); |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 159 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | public boolean isCall(NotificationRecord record) { |
| 163 | return mFiltering.isCall(record); |
| 164 | } |
| 165 | |
Julia Reynolds | c6b371b | 2016-06-14 08:31:03 -0400 | [diff] [blame] | 166 | public void recordCaller(NotificationRecord record) { |
| 167 | mFiltering.recordCall(record); |
| 168 | } |
| 169 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 170 | public boolean shouldIntercept(NotificationRecord record) { |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 171 | synchronized (mConfig) { |
| 172 | return mFiltering.shouldIntercept(mZenMode, mConfig, record); |
| 173 | } |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 174 | } |
| 175 | |
John Spurlock | 1c923a3 | 2014-04-27 16:42:29 -0400 | [diff] [blame] | 176 | public void addCallback(Callback callback) { |
| 177 | mCallbacks.add(callback); |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 178 | } |
| 179 | |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 180 | public void removeCallback(Callback callback) { |
| 181 | mCallbacks.remove(callback); |
| 182 | } |
| 183 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 184 | public void initZenMode() { |
| 185 | if (DEBUG) Log.d(TAG, "initZenMode"); |
| 186 | evaluateZenMode("init", true /*setRingerMode*/); |
| 187 | } |
| 188 | |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 189 | public void onSystemReady() { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 190 | if (DEBUG) Log.d(TAG, "onSystemReady"); |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 191 | mAudioManager = LocalServices.getService(AudioManagerInternal.class); |
| 192 | if (mAudioManager != null) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 193 | mAudioManager.setRingerModeDelegate(mRingerModeDelegate); |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 194 | } |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 195 | mPm = mContext.getPackageManager(); |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 196 | mHandler.postMetricsTimer(); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 197 | cleanUpZenRules(); |
Julia Reynolds | 8ac6303 | 2015-08-31 15:19:43 -0400 | [diff] [blame] | 198 | evaluateZenMode("onSystemReady", true); |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 199 | mIsBootComplete = true; |
| 200 | showZenUpgradeNotification(mZenMode); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 201 | } |
| 202 | |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 203 | public void onUserSwitched(int user) { |
Julia Reynolds | a3dcaff | 2016-02-03 15:04:05 -0500 | [diff] [blame] | 204 | loadConfigForUser(user, "onUserSwitched"); |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | public void onUserRemoved(int user) { |
Xiaohui Chen | ddbe4ca | 2015-08-13 16:20:56 -0700 | [diff] [blame] | 208 | if (user < UserHandle.USER_SYSTEM) return; |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 209 | if (DEBUG) Log.d(TAG, "onUserRemoved u=" + user); |
| 210 | mConfigs.remove(user); |
| 211 | } |
| 212 | |
Julia Reynolds | a3dcaff | 2016-02-03 15:04:05 -0500 | [diff] [blame] | 213 | public void onUserUnlocked(int user) { |
| 214 | loadConfigForUser(user, "onUserUnlocked"); |
| 215 | } |
| 216 | |
| 217 | private void loadConfigForUser(int user, String reason) { |
| 218 | if (mUser == user || user < UserHandle.USER_SYSTEM) return; |
| 219 | mUser = user; |
| 220 | if (DEBUG) Log.d(TAG, reason + " u=" + user); |
| 221 | ZenModeConfig config = mConfigs.get(user); |
| 222 | if (config == null) { |
| 223 | if (DEBUG) Log.d(TAG, reason + " generating default config for user " + user); |
| 224 | config = mDefaultConfig.copy(); |
| 225 | config.user = user; |
| 226 | } |
| 227 | synchronized (mConfig) { |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 228 | setConfigLocked(config, null, reason); |
Julia Reynolds | a3dcaff | 2016-02-03 15:04:05 -0500 | [diff] [blame] | 229 | } |
| 230 | cleanUpZenRules(); |
| 231 | } |
| 232 | |
Christoph Studer | 85a384b | 2014-08-27 20:16:15 +0200 | [diff] [blame] | 233 | public int getZenModeListenerInterruptionFilter() { |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 234 | return NotificationManager.zenModeToInterruptionFilter(mZenMode); |
John Spurlock | d8afe3c | 2014-08-01 14:04:07 -0400 | [diff] [blame] | 235 | } |
| 236 | |
John Spurlock | 8077493 | 2015-05-07 17:38:50 -0400 | [diff] [blame] | 237 | public void requestFromListener(ComponentName name, int filter) { |
| 238 | final int newZen = NotificationManager.zenModeFromInterruptionFilter(filter, -1); |
John Spurlock | d8afe3c | 2014-08-01 14:04:07 -0400 | [diff] [blame] | 239 | if (newZen != -1) { |
Julia Reynolds | 44ad6ff | 2016-07-06 09:47:45 -0400 | [diff] [blame] | 240 | setManualZenMode(newZen, null, name != null ? name.getPackageName() : null, |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 241 | "listener:" + (name != null ? name.flattenToShortString() : null)); |
John Spurlock | d8afe3c | 2014-08-01 14:04:07 -0400 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
Bryce Lee | 7219ada | 2016-04-08 10:54:23 -0700 | [diff] [blame] | 245 | public void setSuppressedEffects(long suppressedEffects) { |
| 246 | if (mSuppressedEffects == suppressedEffects) return; |
| 247 | mSuppressedEffects = suppressedEffects; |
John Spurlock | 8403b75 | 2014-12-10 12:47:01 -0500 | [diff] [blame] | 248 | applyRestrictions(); |
| 249 | } |
| 250 | |
Bryce Lee | 7219ada | 2016-04-08 10:54:23 -0700 | [diff] [blame] | 251 | public long getSuppressedEffects() { |
| 252 | return mSuppressedEffects; |
| 253 | } |
| 254 | |
John Spurlock | 1c923a3 | 2014-04-27 16:42:29 -0400 | [diff] [blame] | 255 | public int getZenMode() { |
| 256 | return mZenMode; |
| 257 | } |
| 258 | |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 259 | public List<ZenRule> getZenRules() { |
| 260 | List<ZenRule> rules = new ArrayList<>(); |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 261 | synchronized (mConfig) { |
| 262 | if (mConfig == null) return rules; |
| 263 | for (ZenRule rule : mConfig.automaticRules.values()) { |
| 264 | if (canManageAutomaticZenRule(rule)) { |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 265 | rules.add(rule); |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 266 | } |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | return rules; |
| 270 | } |
| 271 | |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 272 | public AutomaticZenRule getAutomaticZenRule(String id) { |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 273 | ZenRule rule; |
| 274 | synchronized (mConfig) { |
| 275 | if (mConfig == null) return null; |
| 276 | rule = mConfig.automaticRules.get(id); |
| 277 | } |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 278 | if (rule == null) return null; |
| 279 | if (canManageAutomaticZenRule(rule)) { |
| 280 | return createAutomaticZenRule(rule); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 281 | } |
| 282 | return null; |
| 283 | } |
| 284 | |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 285 | public String addAutomaticZenRule(AutomaticZenRule automaticZenRule, String reason) { |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 286 | if (!isSystemRule(automaticZenRule)) { |
| 287 | ServiceInfo owner = getServiceInfo(automaticZenRule.getOwner()); |
| 288 | if (owner == null) { |
| 289 | throw new IllegalArgumentException("Owner is not a condition provider service"); |
| 290 | } |
| 291 | |
Julia Reynolds | 7f2f441 | 2016-03-01 12:33:48 -0500 | [diff] [blame] | 292 | int ruleInstanceLimit = -1; |
| 293 | if (owner.metaData != null) { |
| 294 | ruleInstanceLimit = owner.metaData.getInt( |
| 295 | ConditionProviderService.META_DATA_RULE_INSTANCE_LIMIT, -1); |
| 296 | } |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 297 | if (ruleInstanceLimit > 0 && ruleInstanceLimit |
| 298 | < (getCurrentInstanceCount(automaticZenRule.getOwner()) + 1)) { |
| 299 | throw new IllegalArgumentException("Rule instance limit exceeded"); |
| 300 | } |
| 301 | } |
| 302 | |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 303 | ZenModeConfig newConfig; |
| 304 | synchronized (mConfig) { |
Julia Reynolds | 87c4277 | 2016-05-16 09:52:17 -0400 | [diff] [blame] | 305 | if (mConfig == null) { |
| 306 | throw new AndroidRuntimeException("Could not create rule"); |
| 307 | } |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 308 | if (DEBUG) { |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 309 | Log.d(TAG, "addAutomaticZenRule rule= " + automaticZenRule + " reason=" + reason); |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 310 | } |
| 311 | newConfig = mConfig.copy(); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 312 | ZenRule rule = new ZenRule(); |
| 313 | populateZenRule(automaticZenRule, rule, true); |
| 314 | newConfig.automaticRules.put(rule.id, rule); |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 315 | if (setConfigLocked(newConfig, reason, rule.component, true)) { |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 316 | return rule.id; |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 317 | } else { |
Julia Reynolds | 87c4277 | 2016-05-16 09:52:17 -0400 | [diff] [blame] | 318 | throw new AndroidRuntimeException("Could not create rule"); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 319 | } |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 323 | public boolean updateAutomaticZenRule(String ruleId, AutomaticZenRule automaticZenRule, |
| 324 | String reason) { |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 325 | ZenModeConfig newConfig; |
| 326 | synchronized (mConfig) { |
| 327 | if (mConfig == null) return false; |
| 328 | if (DEBUG) { |
| 329 | Log.d(TAG, "updateAutomaticZenRule zenRule=" + automaticZenRule |
| 330 | + " reason=" + reason); |
| 331 | } |
| 332 | newConfig = mConfig.copy(); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 333 | ZenModeConfig.ZenRule rule; |
| 334 | if (ruleId == null) { |
| 335 | throw new IllegalArgumentException("Rule doesn't exist"); |
| 336 | } else { |
| 337 | rule = newConfig.automaticRules.get(ruleId); |
| 338 | if (rule == null || !canManageAutomaticZenRule(rule)) { |
| 339 | throw new SecurityException( |
| 340 | "Cannot update rules not owned by your condition provider"); |
| 341 | } |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 342 | } |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 343 | populateZenRule(automaticZenRule, rule, false); |
| 344 | newConfig.automaticRules.put(ruleId, rule); |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 345 | return setConfigLocked(newConfig, reason, rule.component, true); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 346 | } |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 347 | } |
| 348 | |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 349 | public boolean removeAutomaticZenRule(String id, 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 | newConfig = mConfig.copy(); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 354 | ZenRule rule = newConfig.automaticRules.get(id); |
| 355 | if (rule == null) return false; |
| 356 | if (canManageAutomaticZenRule(rule)) { |
| 357 | newConfig.automaticRules.remove(id); |
| 358 | if (DEBUG) Log.d(TAG, "removeZenRule zenRule=" + id + " reason=" + reason); |
| 359 | } else { |
| 360 | throw new SecurityException( |
| 361 | "Cannot delete rules not owned by your condition provider"); |
| 362 | } |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 363 | return setConfigLocked(newConfig, reason, null, true); |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 364 | } |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 365 | } |
| 366 | |
Julia Reynolds | c8e54e8 | 2015-11-30 16:43:05 -0500 | [diff] [blame] | 367 | public boolean removeAutomaticZenRules(String packageName, String reason) { |
| 368 | ZenModeConfig newConfig; |
| 369 | synchronized (mConfig) { |
| 370 | if (mConfig == null) return false; |
| 371 | newConfig = mConfig.copy(); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 372 | for (int i = newConfig.automaticRules.size() - 1; i >= 0; i--) { |
| 373 | ZenRule rule = newConfig.automaticRules.get(newConfig.automaticRules.keyAt(i)); |
| 374 | if (rule.component.getPackageName().equals(packageName) |
| 375 | && canManageAutomaticZenRule(rule)) { |
| 376 | newConfig.automaticRules.removeAt(i); |
| 377 | } |
Julia Reynolds | c8e54e8 | 2015-11-30 16:43:05 -0500 | [diff] [blame] | 378 | } |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 379 | return setConfigLocked(newConfig, reason, null, true); |
Julia Reynolds | c8e54e8 | 2015-11-30 16:43:05 -0500 | [diff] [blame] | 380 | } |
Julia Reynolds | c8e54e8 | 2015-11-30 16:43:05 -0500 | [diff] [blame] | 381 | } |
| 382 | |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 383 | public int getCurrentInstanceCount(ComponentName owner) { |
| 384 | int count = 0; |
| 385 | synchronized (mConfig) { |
| 386 | for (ZenRule rule : mConfig.automaticRules.values()) { |
| 387 | if (rule.component != null && rule.component.equals(owner)) { |
| 388 | count++; |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | return count; |
| 393 | } |
| 394 | |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 395 | public boolean canManageAutomaticZenRule(ZenRule rule) { |
Julia Reynolds | c8e54e8 | 2015-11-30 16:43:05 -0500 | [diff] [blame] | 396 | final int callingUid = Binder.getCallingUid(); |
| 397 | if (callingUid == 0 || callingUid == Process.SYSTEM_UID) { |
| 398 | return true; |
| 399 | } else if (mContext.checkCallingPermission(android.Manifest.permission.MANAGE_NOTIFICATIONS) |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 400 | == PackageManager.PERMISSION_GRANTED) { |
| 401 | return true; |
| 402 | } else { |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 403 | String[] packages = mPm.getPackagesForUid(Binder.getCallingUid()); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 404 | if (packages != null) { |
| 405 | final int packageCount = packages.length; |
| 406 | for (int i = 0; i < packageCount; i++) { |
| 407 | if (packages[i].equals(rule.component.getPackageName())) { |
| 408 | return true; |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | return false; |
| 413 | } |
| 414 | } |
| 415 | |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 416 | public void setDefaultZenRules(Context context) { |
| 417 | mDefaultConfig = readDefaultConfig(context.getResources()); |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 418 | appendDefaultRules(mDefaultConfig); |
| 419 | } |
| 420 | |
| 421 | private void appendDefaultRules (ZenModeConfig config) { |
Beverly | 30bfbca | 2017-10-17 14:38:20 -0400 | [diff] [blame] | 422 | getDefaultRuleNames(); |
Beverly | 26eba87 | 2017-12-04 16:30:11 -0500 | [diff] [blame] | 423 | appendDefaultEveryNightRule(config); |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 424 | appendDefaultEventRules(config); |
| 425 | } |
| 426 | |
| 427 | // Checks zen rule properties are the same (doesn't check creation time, name nor enabled) |
| 428 | // used to check if default rules were customized or not |
| 429 | private boolean ruleValuesEqual(AutomaticZenRule rule, ZenRule defaultRule) { |
| 430 | if (rule == null || defaultRule == null) { |
| 431 | return false; |
| 432 | } |
| 433 | return rule.getInterruptionFilter() == |
| 434 | NotificationManager.zenModeToInterruptionFilter(defaultRule.zenMode) |
| 435 | && rule.getConditionId().equals(defaultRule.conditionId) |
| 436 | && rule.getOwner().equals(defaultRule.component); |
| 437 | } |
| 438 | |
| 439 | protected void updateDefaultZenRules() { |
| 440 | ZenModeConfig configDefaultRules = new ZenModeConfig(); |
| 441 | appendDefaultRules(configDefaultRules); // "new" localized default rules |
Beverly | 26eba87 | 2017-12-04 16:30:11 -0500 | [diff] [blame] | 442 | for (String ruleId : ZenModeConfig.DEFAULT_RULE_IDS) { |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 443 | AutomaticZenRule currRule = getAutomaticZenRule(ruleId); |
| 444 | ZenRule defaultRule = configDefaultRules.automaticRules.get(ruleId); |
| 445 | // if default rule wasn't customized, use localized name instead of previous |
| 446 | if (ruleValuesEqual(currRule, defaultRule) && |
| 447 | !defaultRule.name.equals(currRule.getName())) { |
| 448 | if (canManageAutomaticZenRule(defaultRule)) { |
| 449 | if (DEBUG) Slog.d(TAG, "Locale change - updating default zen rule name " |
| 450 | + "from " + currRule.getName() + " to " + defaultRule.name); |
| 451 | // update default rule (if locale changed, name of rule will change) |
| 452 | AutomaticZenRule defaultAutoRule = createAutomaticZenRule(defaultRule); |
Beverly | 8363944 | 2017-09-06 10:36:04 -0400 | [diff] [blame] | 453 | // ensure enabled state is carried over from current rule |
| 454 | defaultAutoRule.setEnabled(currRule.isEnabled()); |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 455 | updateAutomaticZenRule(ruleId, defaultAutoRule, |
| 456 | "locale changed"); |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 462 | private boolean isSystemRule(AutomaticZenRule rule) { |
| 463 | return ZenModeConfig.SYSTEM_AUTHORITY.equals(rule.getOwner().getPackageName()); |
| 464 | } |
| 465 | |
| 466 | private ServiceInfo getServiceInfo(ComponentName owner) { |
Julia Reynolds | 0ae2b0b | 2016-01-14 09:58:03 -0500 | [diff] [blame] | 467 | Intent queryIntent = new Intent(); |
| 468 | queryIntent.setComponent(owner); |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 469 | List<ResolveInfo> installedServices = mPm.queryIntentServicesAsUser( |
Julia Reynolds | 0ae2b0b | 2016-01-14 09:58:03 -0500 | [diff] [blame] | 470 | queryIntent, |
| 471 | PackageManager.GET_SERVICES | PackageManager.GET_META_DATA, |
| 472 | UserHandle.getCallingUserId()); |
| 473 | if (installedServices != null) { |
| 474 | for (int i = 0, count = installedServices.size(); i < count; i++) { |
| 475 | ResolveInfo resolveInfo = installedServices.get(i); |
| 476 | ServiceInfo info = resolveInfo.serviceInfo; |
| 477 | if (mServiceConfig.bindPermission.equals(info.permission)) { |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 478 | return info; |
Julia Reynolds | 0ae2b0b | 2016-01-14 09:58:03 -0500 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | } |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 482 | return null; |
Julia Reynolds | 0ae2b0b | 2016-01-14 09:58:03 -0500 | [diff] [blame] | 483 | } |
| 484 | |
Julia Reynolds | 4fe98d6 | 2015-10-06 16:23:41 -0400 | [diff] [blame] | 485 | private void populateZenRule(AutomaticZenRule automaticZenRule, ZenRule rule, boolean isNew) { |
| 486 | if (isNew) { |
| 487 | rule.id = ZenModeConfig.newRuleId(); |
| 488 | rule.creationTime = System.currentTimeMillis(); |
| 489 | rule.component = automaticZenRule.getOwner(); |
| 490 | } |
| 491 | |
| 492 | if (rule.enabled != automaticZenRule.isEnabled()) { |
| 493 | rule.snoozing = false; |
| 494 | } |
| 495 | rule.name = automaticZenRule.getName(); |
| 496 | rule.condition = null; |
| 497 | rule.conditionId = automaticZenRule.getConditionId(); |
| 498 | rule.enabled = automaticZenRule.isEnabled(); |
| 499 | rule.zenMode = NotificationManager.zenModeFromInterruptionFilter( |
| 500 | automaticZenRule.getInterruptionFilter(), Global.ZEN_MODE_OFF); |
| 501 | } |
| 502 | |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 503 | protected AutomaticZenRule createAutomaticZenRule(ZenRule rule) { |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 504 | return new AutomaticZenRule(rule.name, rule.component, rule.conditionId, |
Julia Reynolds | 56106ff | 2015-09-30 14:42:53 -0400 | [diff] [blame] | 505 | NotificationManager.zenModeToInterruptionFilter(rule.zenMode), rule.enabled, |
Julia Reynolds | 361e82d3 | 2016-02-26 18:19:49 -0500 | [diff] [blame] | 506 | rule.creationTime); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 507 | } |
| 508 | |
Julia Reynolds | 44ad6ff | 2016-07-06 09:47:45 -0400 | [diff] [blame] | 509 | public void setManualZenMode(int zenMode, Uri conditionId, String caller, String reason) { |
| 510 | setManualZenMode(zenMode, conditionId, reason, caller, true /*setRingerMode*/); |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 511 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 512 | Settings.Secure.SHOW_ZEN_SETTINGS_SUGGESTION, 0); |
John Spurlock | e77bb36 | 2014-04-26 10:24:59 -0400 | [diff] [blame] | 513 | } |
| 514 | |
Julia Reynolds | 44ad6ff | 2016-07-06 09:47:45 -0400 | [diff] [blame] | 515 | private void setManualZenMode(int zenMode, Uri conditionId, String reason, String caller, |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 516 | boolean setRingerMode) { |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 517 | ZenModeConfig newConfig; |
| 518 | synchronized (mConfig) { |
| 519 | if (mConfig == null) return; |
| 520 | if (!Global.isValidZenMode(zenMode)) return; |
| 521 | if (DEBUG) Log.d(TAG, "setManualZenMode " + Global.zenModeToString(zenMode) |
| 522 | + " conditionId=" + conditionId + " reason=" + reason |
| 523 | + " setRingerMode=" + setRingerMode); |
| 524 | newConfig = mConfig.copy(); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 525 | if (zenMode == Global.ZEN_MODE_OFF) { |
| 526 | newConfig.manualRule = null; |
| 527 | for (ZenRule automaticRule : newConfig.automaticRules.values()) { |
| 528 | if (automaticRule.isAutomaticActive()) { |
| 529 | automaticRule.snoozing = true; |
| 530 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 531 | } |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 532 | } else { |
| 533 | final ZenRule newRule = new ZenRule(); |
| 534 | newRule.enabled = true; |
| 535 | newRule.zenMode = zenMode; |
| 536 | newRule.conditionId = conditionId; |
Julia Reynolds | 44ad6ff | 2016-07-06 09:47:45 -0400 | [diff] [blame] | 537 | newRule.enabler = caller; |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 538 | newConfig.manualRule = newRule; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 539 | } |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 540 | setConfigLocked(newConfig, reason, null, setRingerMode); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 541 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 542 | } |
| 543 | |
Julia Reynolds | 520df6e | 2017-02-13 09:05:10 -0500 | [diff] [blame] | 544 | void dump(ProtoOutputStream proto) { |
Julia Reynolds | 520df6e | 2017-02-13 09:05:10 -0500 | [diff] [blame] | 545 | proto.write(ZenModeProto.ZEN_MODE, mZenMode); |
| 546 | synchronized (mConfig) { |
| 547 | if (mConfig.manualRule != null) { |
Kweku Adams | 9954633 | 2018-01-24 17:03:50 -0800 | [diff] [blame] | 548 | mConfig.manualRule.writeToProto(proto, ZenModeProto.ENABLED_ACTIVE_CONDITIONS); |
Julia Reynolds | 520df6e | 2017-02-13 09:05:10 -0500 | [diff] [blame] | 549 | } |
| 550 | for (ZenRule rule : mConfig.automaticRules.values()) { |
| 551 | if (rule.enabled && rule.condition.state == Condition.STATE_TRUE |
| 552 | && !rule.snoozing) { |
Kweku Adams | 9954633 | 2018-01-24 17:03:50 -0800 | [diff] [blame] | 553 | rule.writeToProto(proto, ZenModeProto.ENABLED_ACTIVE_CONDITIONS); |
Julia Reynolds | 520df6e | 2017-02-13 09:05:10 -0500 | [diff] [blame] | 554 | } |
| 555 | } |
Kweku Adams | bc84aec | 2018-01-23 13:33:12 -0800 | [diff] [blame] | 556 | mConfig.toNotificationPolicy().writeToProto(proto, ZenModeProto.POLICY); |
Julia Reynolds | 520df6e | 2017-02-13 09:05:10 -0500 | [diff] [blame] | 557 | proto.write(ZenModeProto.SUPPRESSED_EFFECTS, mSuppressedEffects); |
| 558 | } |
| 559 | } |
| 560 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 561 | public void dump(PrintWriter pw, String prefix) { |
| 562 | pw.print(prefix); pw.print("mZenMode="); |
| 563 | pw.println(Global.zenModeToString(mZenMode)); |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 564 | final int N = mConfigs.size(); |
| 565 | for (int i = 0; i < N; i++) { |
| 566 | dump(pw, prefix, "mConfigs[u=" + mConfigs.keyAt(i) + "]", mConfigs.valueAt(i)); |
| 567 | } |
| 568 | pw.print(prefix); pw.print("mUser="); pw.println(mUser); |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 569 | synchronized (mConfig) { |
| 570 | dump(pw, prefix, "mConfig", mConfig); |
| 571 | } |
Bryce Lee | 7219ada | 2016-04-08 10:54:23 -0700 | [diff] [blame] | 572 | |
| 573 | pw.print(prefix); pw.print("mSuppressedEffects="); pw.println(mSuppressedEffects); |
John Spurlock | 1d7d224 | 2015-04-10 08:10:22 -0400 | [diff] [blame] | 574 | mFiltering.dump(pw, prefix); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 575 | mConditions.dump(pw, prefix); |
| 576 | } |
| 577 | |
| 578 | private static void dump(PrintWriter pw, String prefix, String var, ZenModeConfig config) { |
| 579 | pw.print(prefix); pw.print(var); pw.print('='); |
| 580 | if (config == null) { |
| 581 | pw.println(config); |
| 582 | return; |
| 583 | } |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 584 | pw.printf("allow(alarms=%b,media=%b,system=%b,calls=%b,callsFrom=%s,repeatCallers=%b," |
Julia Reynolds | 1f58057 | 2018-04-27 14:48:36 -0400 | [diff] [blame] | 585 | + "messages=%b,messagesFrom=%s,events=%b,reminders=%b)\n", |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 586 | config.allowAlarms, config.allowMedia, config.allowSystem, |
Julia Reynolds | 6ee2617 | 2015-09-28 11:34:48 -0400 | [diff] [blame] | 587 | config.allowCalls, ZenModeConfig.sourceToString(config.allowCallsFrom), |
| 588 | config.allowRepeatCallers, config.allowMessages, |
| 589 | ZenModeConfig.sourceToString(config.allowMessagesFrom), |
Julia Reynolds | 1f58057 | 2018-04-27 14:48:36 -0400 | [diff] [blame] | 590 | config.allowEvents, config.allowReminders); |
Julia Reynolds | ccc6ae6 | 2018-03-01 16:24:49 -0500 | [diff] [blame] | 591 | pw.printf(" disallow(visualEffects=%s)\n", config.suppressedVisualEffects); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 592 | pw.print(prefix); pw.print(" manualRule="); pw.println(config.manualRule); |
| 593 | if (config.automaticRules.isEmpty()) return; |
| 594 | final int N = config.automaticRules.size(); |
| 595 | for (int i = 0; i < N; i++) { |
| 596 | pw.print(prefix); pw.print(i == 0 ? " automaticRules=" : " "); |
| 597 | pw.println(config.automaticRules.valueAt(i)); |
| 598 | } |
| 599 | } |
| 600 | |
John Spurlock | 35ef0a6 | 2015-05-28 11:24:10 -0400 | [diff] [blame] | 601 | public void readXml(XmlPullParser parser, boolean forRestore) |
| 602 | throws XmlPullParserException, IOException { |
Beverly | 4e2f76c | 2018-03-16 15:43:49 -0400 | [diff] [blame] | 603 | ZenModeConfig config = ZenModeConfig.readXml(parser); |
| 604 | String reason = "readXml"; |
| 605 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 606 | if (config != null) { |
John Spurlock | 35ef0a6 | 2015-05-28 11:24:10 -0400 | [diff] [blame] | 607 | if (forRestore) { |
Xiaohui Chen | ddbe4ca | 2015-08-13 16:20:56 -0700 | [diff] [blame] | 608 | //TODO: http://b/22388012 |
| 609 | if (config.user != UserHandle.USER_SYSTEM) { |
John Spurlock | 35ef0a6 | 2015-05-28 11:24:10 -0400 | [diff] [blame] | 610 | return; |
| 611 | } |
| 612 | config.manualRule = null; // don't restore the manual rule |
Beverly | 4e2f76c | 2018-03-16 15:43:49 -0400 | [diff] [blame] | 613 | } |
| 614 | |
Beverly | ad3841a | 2018-07-31 11:23:35 -0400 | [diff] [blame] | 615 | // booleans to determine whether to reset the rules to the default rules |
| 616 | boolean allRulesDisabled = true; |
| 617 | boolean hasDefaultRules = config.automaticRules.containsAll( |
| 618 | ZenModeConfig.DEFAULT_RULE_IDS); |
| 619 | |
Beverly | 4e2f76c | 2018-03-16 15:43:49 -0400 | [diff] [blame] | 620 | long time = System.currentTimeMillis(); |
| 621 | if (config.automaticRules != null && config.automaticRules.size() > 0) { |
| 622 | for (ZenRule automaticRule : config.automaticRules.values()) { |
| 623 | if (forRestore) { |
John Spurlock | 995a749 | 2015-05-28 22:13:03 -0400 | [diff] [blame] | 624 | // don't restore transient state from restored automatic rules |
| 625 | automaticRule.snoozing = false; |
| 626 | automaticRule.condition = null; |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 627 | automaticRule.creationTime = time; |
John Spurlock | 995a749 | 2015-05-28 22:13:03 -0400 | [diff] [blame] | 628 | } |
Beverly | ad3841a | 2018-07-31 11:23:35 -0400 | [diff] [blame] | 629 | |
| 630 | allRulesDisabled &= !automaticRule.enabled; |
John Spurlock | 995a749 | 2015-05-28 22:13:03 -0400 | [diff] [blame] | 631 | } |
John Spurlock | 35ef0a6 | 2015-05-28 11:24:10 -0400 | [diff] [blame] | 632 | } |
Beverly | 4e2f76c | 2018-03-16 15:43:49 -0400 | [diff] [blame] | 633 | |
Beverly | ad3841a | 2018-07-31 11:23:35 -0400 | [diff] [blame] | 634 | if (!hasDefaultRules && allRulesDisabled |
| 635 | && (forRestore || config.version < ZenModeConfig.XML_VERSION)) { |
| 636 | // reset zen automatic rules to default on restore or upgrade if: |
| 637 | // - doesn't already have default rules and |
| 638 | // - all previous automatic rules were disabled |
| 639 | config.automaticRules = new ArrayMap<>(); |
| 640 | appendDefaultRules(config); |
| 641 | reason += ", reset to default rules"; |
| 642 | } |
| 643 | |
| 644 | if (config.version < ZenModeConfig.XML_VERSION) { |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 645 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 646 | Settings.Secure.SHOW_ZEN_UPGRADE_NOTIFICATION, 1); |
Beverly | 301e92a | 2018-04-27 09:43:05 -0400 | [diff] [blame] | 647 | } else { |
| 648 | // devices not restoring/upgrading already have updated zen settings |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 649 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 650 | Settings.Secure.ZEN_SETTINGS_UPDATED, 1); |
Beverly | 4e2f76c | 2018-03-16 15:43:49 -0400 | [diff] [blame] | 651 | } |
| 652 | if (DEBUG) Log.d(TAG, reason); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 653 | synchronized (mConfig) { |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 654 | setConfigLocked(config, null, reason); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 655 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | |
Beverly | 4e2f76c | 2018-03-16 15:43:49 -0400 | [diff] [blame] | 659 | public void writeXml(XmlSerializer out, boolean forBackup, Integer version) throws IOException { |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 660 | final int N = mConfigs.size(); |
| 661 | for (int i = 0; i < N; i++) { |
Xiaohui Chen | ddbe4ca | 2015-08-13 16:20:56 -0700 | [diff] [blame] | 662 | //TODO: http://b/22388012 |
| 663 | if (forBackup && mConfigs.keyAt(i) != UserHandle.USER_SYSTEM) { |
John Spurlock | 35ef0a6 | 2015-05-28 11:24:10 -0400 | [diff] [blame] | 664 | continue; |
| 665 | } |
Beverly | 4e2f76c | 2018-03-16 15:43:49 -0400 | [diff] [blame] | 666 | mConfigs.valueAt(i).writeXml(out, version); |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 667 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 668 | } |
| 669 | |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 670 | public Policy getNotificationPolicy() { |
| 671 | return getNotificationPolicy(mConfig); |
| 672 | } |
| 673 | |
| 674 | private static Policy getNotificationPolicy(ZenModeConfig config) { |
| 675 | return config == null ? null : config.toNotificationPolicy(); |
| 676 | } |
| 677 | |
| 678 | public void setNotificationPolicy(Policy policy) { |
| 679 | if (policy == null || mConfig == null) return; |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 680 | synchronized (mConfig) { |
| 681 | final ZenModeConfig newConfig = mConfig.copy(); |
| 682 | newConfig.applyNotificationPolicy(policy); |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 683 | setConfigLocked(newConfig, null, "setNotificationPolicy"); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 684 | } |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 685 | } |
| 686 | |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 687 | /** |
| 688 | * Removes old rule instances whose owner is not installed. |
| 689 | */ |
| 690 | private void cleanUpZenRules() { |
| 691 | long currentTime = System.currentTimeMillis(); |
| 692 | synchronized (mConfig) { |
| 693 | final ZenModeConfig newConfig = mConfig.copy(); |
| 694 | if (newConfig.automaticRules != null) { |
| 695 | for (int i = newConfig.automaticRules.size() - 1; i >= 0; i--) { |
| 696 | ZenRule rule = newConfig.automaticRules.get(newConfig.automaticRules.keyAt(i)); |
| 697 | if (RULE_INSTANCE_GRACE_PERIOD < (currentTime - rule.creationTime)) { |
| 698 | try { |
Jeff Sharkey | c7bacab | 2016-02-09 15:56:11 -0700 | [diff] [blame] | 699 | mPm.getPackageInfo(rule.component.getPackageName(), |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 700 | PackageManager.MATCH_ANY_USER); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 701 | } catch (PackageManager.NameNotFoundException e) { |
| 702 | newConfig.automaticRules.removeAt(i); |
| 703 | } |
| 704 | } |
| 705 | } |
| 706 | } |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 707 | setConfigLocked(newConfig, null, "cleanUpZenRules"); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 708 | } |
| 709 | } |
| 710 | |
| 711 | /** |
| 712 | * @return a copy of the zen mode configuration |
| 713 | */ |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 714 | public ZenModeConfig getConfig() { |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 715 | synchronized (mConfig) { |
| 716 | return mConfig.copy(); |
| 717 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 718 | } |
| 719 | |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 720 | public boolean setConfigLocked(ZenModeConfig config, ComponentName triggeringComponent, |
| 721 | String reason) { |
| 722 | return setConfigLocked(config, reason, triggeringComponent, true /*setRingerMode*/); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 723 | } |
| 724 | |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 725 | public void setConfig(ZenModeConfig config, ComponentName triggeringComponent, String reason) { |
Julia Reynolds | 89aeab0 | 2016-09-15 11:07:50 -0400 | [diff] [blame] | 726 | synchronized (mConfig) { |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 727 | setConfigLocked(config, triggeringComponent, reason); |
Julia Reynolds | 89aeab0 | 2016-09-15 11:07:50 -0400 | [diff] [blame] | 728 | } |
Eric Laurent | e0ced4d | 2015-09-30 17:44:28 -0700 | [diff] [blame] | 729 | } |
| 730 | |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 731 | private boolean setConfigLocked(ZenModeConfig config, String reason, |
| 732 | ComponentName triggeringComponent, boolean setRingerMode) { |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 733 | final long identity = Binder.clearCallingIdentity(); |
| 734 | try { |
| 735 | if (config == null || !config.isValid()) { |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 736 | Log.w(TAG, "Invalid config in setConfigLocked; " + config); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 737 | return false; |
| 738 | } |
| 739 | if (config.user != mUser) { |
| 740 | // simply store away for background users |
| 741 | mConfigs.put(config.user, config); |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 742 | if (DEBUG) Log.d(TAG, "setConfigLocked: store config for user " + config.user); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 743 | return true; |
| 744 | } |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 745 | // may modify config |
| 746 | mConditions.evaluateConfig(config, null, false /*processSubscriptions*/); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 747 | mConfigs.put(config.user, config); |
Julia Reynolds | 43b70cd | 2016-01-14 15:05:34 -0500 | [diff] [blame] | 748 | if (DEBUG) Log.d(TAG, "setConfigLocked reason=" + reason, new Throwable()); |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 749 | ZenLog.traceConfig(reason, mConfig, config); |
| 750 | final boolean policyChanged = !Objects.equals(getNotificationPolicy(mConfig), |
| 751 | getNotificationPolicy(config)); |
Julia Reynolds | 9a25da1 | 2016-01-06 16:19:28 -0500 | [diff] [blame] | 752 | if (!config.equals(mConfig)) { |
Julia Reynolds | 5a43aaa | 2015-12-15 13:54:41 -0500 | [diff] [blame] | 753 | dispatchOnConfigChanged(); |
| 754 | } |
| 755 | if (policyChanged) { |
| 756 | dispatchOnPolicyChanged(); |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 757 | } |
Julia Reynolds | 9a25da1 | 2016-01-06 16:19:28 -0500 | [diff] [blame] | 758 | mConfig = config; |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 759 | mHandler.postApplyConfig(config, reason, triggeringComponent, setRingerMode); |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 760 | return true; |
Julia Reynolds | cb507b8 | 2017-09-07 13:53:40 -0400 | [diff] [blame] | 761 | } catch (SecurityException e) { |
| 762 | Log.wtf(TAG, "Invalid rule in config", e); |
| 763 | return false; |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 764 | } finally { |
| 765 | Binder.restoreCallingIdentity(identity); |
John Spurlock | 21258a3 | 2015-05-27 18:22:55 -0400 | [diff] [blame] | 766 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 767 | } |
| 768 | |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 769 | private void applyConfig(ZenModeConfig config, String reason, |
| 770 | ComponentName triggeringComponent, boolean setRingerMode) { |
Julia Reynolds | d82e981 | 2016-04-19 13:27:41 -0400 | [diff] [blame] | 771 | final String val = Integer.toString(config.hashCode()); |
| 772 | Global.putString(mContext.getContentResolver(), Global.ZEN_MODE_CONFIG_ETAG, val); |
| 773 | if (!evaluateZenMode(reason, setRingerMode)) { |
| 774 | applyRestrictions(); // evaluateZenMode will also apply restrictions if changed |
| 775 | } |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 776 | mConditions.evaluateConfig(config, triggeringComponent, true /*processSubscriptions*/); |
Julia Reynolds | d82e981 | 2016-04-19 13:27:41 -0400 | [diff] [blame] | 777 | } |
| 778 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 779 | private int getZenModeSetting() { |
| 780 | return Global.getInt(mContext.getContentResolver(), Global.ZEN_MODE, Global.ZEN_MODE_OFF); |
| 781 | } |
| 782 | |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 783 | @VisibleForTesting |
| 784 | protected void setZenModeSetting(int zen) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 785 | Global.putInt(mContext.getContentResolver(), Global.ZEN_MODE, zen); |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 786 | showZenUpgradeNotification(zen); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 787 | } |
| 788 | |
Julia Reynolds | 9b11fdb | 2015-07-31 09:49:55 -0400 | [diff] [blame] | 789 | private int getPreviousRingerModeSetting() { |
| 790 | return Global.getInt(mContext.getContentResolver(), |
| 791 | Global.ZEN_MODE_RINGER_LEVEL, AudioManager.RINGER_MODE_NORMAL); |
| 792 | } |
| 793 | |
| 794 | private void setPreviousRingerModeSetting(Integer previousRingerLevel) { |
| 795 | Global.putString( |
| 796 | mContext.getContentResolver(), Global.ZEN_MODE_RINGER_LEVEL, |
| 797 | previousRingerLevel == null ? null : Integer.toString(previousRingerLevel)); |
| 798 | } |
| 799 | |
Beverly | e4ee1cc | 2018-03-06 17:21:08 -0500 | [diff] [blame] | 800 | @VisibleForTesting |
| 801 | protected boolean evaluateZenMode(String reason, boolean setRingerMode) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 802 | if (DEBUG) Log.d(TAG, "evaluateZenMode"); |
Jason Monk | a992732 | 2015-12-13 16:22:37 -0500 | [diff] [blame] | 803 | final int zenBefore = mZenMode; |
Julia Reynolds | 8ac6303 | 2015-08-31 15:19:43 -0400 | [diff] [blame] | 804 | final int zen = computeZenMode(); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 805 | ZenLog.traceSetZenMode(zen, reason); |
| 806 | mZenMode = zen; |
| 807 | setZenModeSetting(mZenMode); |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 808 | updateRingerModeAffectedStreams(); |
Beverly | e4ee1cc | 2018-03-06 17:21:08 -0500 | [diff] [blame] | 809 | if (setRingerMode && zen != zenBefore) { |
John Spurlock | 5762779 | 2014-12-11 11:29:54 -0500 | [diff] [blame] | 810 | applyZenToRingerMode(); |
| 811 | } |
| 812 | applyRestrictions(); |
Jason Monk | a992732 | 2015-12-13 16:22:37 -0500 | [diff] [blame] | 813 | if (zen != zenBefore) { |
Julia Reynolds | 8ac6303 | 2015-08-31 15:19:43 -0400 | [diff] [blame] | 814 | mHandler.postDispatchOnZenModeChanged(); |
| 815 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 816 | return true; |
John Spurlock | 5762779 | 2014-12-11 11:29:54 -0500 | [diff] [blame] | 817 | } |
| 818 | |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 819 | private void updateRingerModeAffectedStreams() { |
| 820 | if (mAudioManager != null) { |
| 821 | mAudioManager.updateRingerModeAffectedStreamsInternal(); |
| 822 | } |
| 823 | } |
| 824 | |
Julia Reynolds | 8ac6303 | 2015-08-31 15:19:43 -0400 | [diff] [blame] | 825 | private int computeZenMode() { |
Beverly | e4ee1cc | 2018-03-06 17:21:08 -0500 | [diff] [blame] | 826 | if (mConfig == null) return Global.ZEN_MODE_OFF; |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 827 | synchronized (mConfig) { |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 828 | if (mConfig.manualRule != null) return mConfig.manualRule.zenMode; |
| 829 | int zen = Global.ZEN_MODE_OFF; |
| 830 | for (ZenRule automaticRule : mConfig.automaticRules.values()) { |
| 831 | if (automaticRule.isAutomaticActive()) { |
| 832 | if (zenSeverity(automaticRule.zenMode) > zenSeverity(zen)) { |
Beverly | 301e92a | 2018-04-27 09:43:05 -0400 | [diff] [blame] | 833 | // automatic rule triggered dnd and user hasn't seen update dnd dialog |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 834 | if (Settings.Secure.getInt(mContext.getContentResolver(), |
| 835 | Settings.Secure.ZEN_SETTINGS_SUGGESTION_VIEWED, 1) == 0) { |
| 836 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 837 | Settings.Secure.SHOW_ZEN_SETTINGS_SUGGESTION, 1); |
Beverly | 301e92a | 2018-04-27 09:43:05 -0400 | [diff] [blame] | 838 | } |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 839 | zen = automaticRule.zenMode; |
| 840 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 841 | } |
| 842 | } |
Julia Reynolds | aaf191c | 2015-10-26 15:53:28 -0400 | [diff] [blame] | 843 | return zen; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 844 | } |
John Spurlock | 8403b75 | 2014-12-10 12:47:01 -0500 | [diff] [blame] | 845 | } |
| 846 | |
Beverly | 30bfbca | 2017-10-17 14:38:20 -0400 | [diff] [blame] | 847 | private void getDefaultRuleNames() { |
| 848 | // on locale-change, these values differ |
Beverly | 26eba87 | 2017-12-04 16:30:11 -0500 | [diff] [blame] | 849 | mDefaultRuleEveryNightName = mContext.getResources() |
| 850 | .getString(R.string.zen_mode_default_every_night_name); |
Beverly | 30bfbca | 2017-10-17 14:38:20 -0400 | [diff] [blame] | 851 | mDefaultRuleEventsName = mContext.getResources() |
| 852 | .getString(R.string.zen_mode_default_events_name); |
| 853 | } |
| 854 | |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 855 | @VisibleForTesting |
| 856 | protected void applyRestrictions() { |
Beverly | d820bc2 | 2018-01-11 15:28:33 -0500 | [diff] [blame] | 857 | final boolean zenPriorityOnly = mZenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; |
Beverly | 925cde8 | 2018-01-23 09:31:23 -0500 | [diff] [blame] | 858 | final boolean zenSilence = mZenMode == Global.ZEN_MODE_NO_INTERRUPTIONS; |
Beverly | d820bc2 | 2018-01-11 15:28:33 -0500 | [diff] [blame] | 859 | final boolean zenAlarmsOnly = mZenMode == Global.ZEN_MODE_ALARMS; |
John Spurlock | 8403b75 | 2014-12-10 12:47:01 -0500 | [diff] [blame] | 860 | |
| 861 | // notification restrictions |
Bryce Lee | 7219ada | 2016-04-08 10:54:23 -0700 | [diff] [blame] | 862 | final boolean muteNotifications = |
| 863 | (mSuppressedEffects & SUPPRESSED_EFFECT_NOTIFICATIONS) != 0; |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 864 | // call restrictions |
Beverly | d820bc2 | 2018-01-11 15:28:33 -0500 | [diff] [blame] | 865 | final boolean muteCalls = zenAlarmsOnly |
| 866 | || (zenPriorityOnly && !mConfig.allowCalls && !mConfig.allowRepeatCallers) |
Bryce Lee | 7219ada | 2016-04-08 10:54:23 -0700 | [diff] [blame] | 867 | || (mSuppressedEffects & SUPPRESSED_EFFECT_CALLS) != 0; |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 868 | // alarm restrictions |
Beverly | d820bc2 | 2018-01-11 15:28:33 -0500 | [diff] [blame] | 869 | final boolean muteAlarms = zenPriorityOnly && !mConfig.allowAlarms; |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 870 | // media restrictions |
| 871 | final boolean muteMedia = zenPriorityOnly && !mConfig.allowMedia; |
| 872 | // system restrictions |
| 873 | final boolean muteSystem = zenAlarmsOnly || (zenPriorityOnly && !mConfig.allowSystem); |
Julia Reynolds | 3fe81be | 2016-02-03 09:10:06 -0500 | [diff] [blame] | 874 | // total silence restrictions |
Beverly | d820bc2 | 2018-01-11 15:28:33 -0500 | [diff] [blame] | 875 | final boolean muteEverything = zenSilence |
Beverly | 925cde8 | 2018-01-23 09:31:23 -0500 | [diff] [blame] | 876 | || (zenPriorityOnly && ZenModeConfig.areAllZenBehaviorSoundsMuted(mConfig)); |
John Spurlock | 25d01ee | 2015-06-03 12:17:46 -0400 | [diff] [blame] | 877 | |
Jean-Michel Trivi | e743bda | 2016-09-09 11:56:48 -0700 | [diff] [blame] | 878 | for (int usage : AudioAttributes.SDK_USAGES) { |
| 879 | final int suppressionBehavior = AudioAttributes.SUPPRESSIBLE_USAGES.get(usage); |
Jean-Michel Trivi | 7a84eae | 2017-06-20 14:58:18 -0700 | [diff] [blame] | 880 | if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_NEVER) { |
| 881 | applyRestrictions(false /*mute*/, usage); |
| 882 | } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_NOTIFICATION) { |
Jean-Michel Trivi | e743bda | 2016-09-09 11:56:48 -0700 | [diff] [blame] | 883 | applyRestrictions(muteNotifications || muteEverything, usage); |
| 884 | } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_CALL) { |
| 885 | applyRestrictions(muteCalls || muteEverything, usage); |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 886 | } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_ALARM) { |
| 887 | applyRestrictions(muteAlarms || muteEverything, usage); |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 888 | } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_MEDIA) { |
| 889 | applyRestrictions(muteMedia || muteEverything, usage); |
| 890 | } else if (suppressionBehavior == AudioAttributes.SUPPRESSIBLE_SYSTEM) { |
Beverly | 738bffd | 2018-03-12 10:46:17 -0400 | [diff] [blame] | 891 | if (usage == AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) { |
| 892 | // normally DND will only restrict touch sounds, not haptic feedback/vibrations |
| 893 | applyRestrictions(muteSystem || muteEverything, usage, |
| 894 | AppOpsManager.OP_PLAY_AUDIO); |
| 895 | applyRestrictions(false, usage, AppOpsManager.OP_VIBRATE); |
| 896 | } else { |
| 897 | applyRestrictions(muteSystem || muteEverything, usage); |
| 898 | } |
Julia Reynolds | 3fe81be | 2016-02-03 09:10:06 -0500 | [diff] [blame] | 899 | } else { |
Jean-Michel Trivi | e743bda | 2016-09-09 11:56:48 -0700 | [diff] [blame] | 900 | applyRestrictions(muteEverything, usage); |
Julia Reynolds | 3fe81be | 2016-02-03 09:10:06 -0500 | [diff] [blame] | 901 | } |
| 902 | } |
John Spurlock | 8403b75 | 2014-12-10 12:47:01 -0500 | [diff] [blame] | 903 | } |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 904 | |
Beverly | e2d9a23 | 2017-11-08 18:14:59 -0500 | [diff] [blame] | 905 | |
Beverly | 0421687 | 2017-09-28 10:55:32 -0400 | [diff] [blame] | 906 | @VisibleForTesting |
Beverly | 738bffd | 2018-03-12 10:46:17 -0400 | [diff] [blame] | 907 | protected void applyRestrictions(boolean mute, int usage, int code) { |
John Spurlock | 8403b75 | 2014-12-10 12:47:01 -0500 | [diff] [blame] | 908 | final String[] exceptionPackages = null; // none (for now) |
Beverly | e2d9a23 | 2017-11-08 18:14:59 -0500 | [diff] [blame] | 909 | |
Dianne Hackborn | bf1b57d | 2018-03-07 12:42:47 -0800 | [diff] [blame] | 910 | // Only do this if we are executing within the system process... otherwise |
| 911 | // we are running as test code, so don't have access to the protected call. |
| 912 | if (Process.myUid() == Process.SYSTEM_UID) { |
| 913 | final long ident = Binder.clearCallingIdentity(); |
| 914 | try { |
| 915 | mAppOps.setRestriction(code, usage, |
| 916 | mute ? AppOpsManager.MODE_IGNORED : AppOpsManager.MODE_ALLOWED, |
| 917 | exceptionPackages); |
| 918 | } finally { |
| 919 | Binder.restoreCallingIdentity(ident); |
| 920 | } |
| 921 | } |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 922 | } |
| 923 | |
Beverly | 85f5241 | 2018-02-27 10:41:13 -0500 | [diff] [blame] | 924 | @VisibleForTesting |
Beverly | 738bffd | 2018-03-12 10:46:17 -0400 | [diff] [blame] | 925 | protected void applyRestrictions(boolean mute, int usage) { |
| 926 | applyRestrictions(mute, usage, AppOpsManager.OP_VIBRATE); |
| 927 | applyRestrictions(mute, usage, AppOpsManager.OP_PLAY_AUDIO); |
| 928 | } |
| 929 | |
| 930 | |
| 931 | @VisibleForTesting |
Beverly | 85f5241 | 2018-02-27 10:41:13 -0500 | [diff] [blame] | 932 | protected void applyZenToRingerMode() { |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 933 | if (mAudioManager == null) return; |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 934 | // force the ringer mode into compliance |
| 935 | final int ringerModeInternal = mAudioManager.getRingerModeInternal(); |
| 936 | int newRingerModeInternal = ringerModeInternal; |
John Spurlock | 5762779 | 2014-12-11 11:29:54 -0500 | [diff] [blame] | 937 | switch (mZenMode) { |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 938 | case Global.ZEN_MODE_NO_INTERRUPTIONS: |
John Spurlock | 4f1163c | 2015-04-02 17:41:21 -0400 | [diff] [blame] | 939 | case Global.ZEN_MODE_ALARMS: |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 940 | if (ringerModeInternal != AudioManager.RINGER_MODE_SILENT) { |
Julia Reynolds | 9b11fdb | 2015-07-31 09:49:55 -0400 | [diff] [blame] | 941 | setPreviousRingerModeSetting(ringerModeInternal); |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 942 | newRingerModeInternal = AudioManager.RINGER_MODE_SILENT; |
John Spurlock | 8c01d88 | 2014-07-28 13:37:13 -0400 | [diff] [blame] | 943 | } |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 944 | break; |
| 945 | case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: |
Beverly | 9e4214d | 2018-03-26 11:10:10 -0400 | [diff] [blame] | 946 | // do not apply zen to ringer, streams zen muted in AudioService |
Beverly | 925cde8 | 2018-01-23 09:31:23 -0500 | [diff] [blame] | 947 | break; |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 948 | case Global.ZEN_MODE_OFF: |
| 949 | if (ringerModeInternal == AudioManager.RINGER_MODE_SILENT) { |
Julia Reynolds | 9b11fdb | 2015-07-31 09:49:55 -0400 | [diff] [blame] | 950 | newRingerModeInternal = getPreviousRingerModeSetting(); |
| 951 | setPreviousRingerModeSetting(null); |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 952 | } |
| 953 | break; |
John Spurlock | 8c01d88 | 2014-07-28 13:37:13 -0400 | [diff] [blame] | 954 | } |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 955 | if (newRingerModeInternal != -1) { |
| 956 | mAudioManager.setRingerModeInternal(newRingerModeInternal, TAG); |
| 957 | } |
| 958 | } |
| 959 | |
John Spurlock | 1c923a3 | 2014-04-27 16:42:29 -0400 | [diff] [blame] | 960 | private void dispatchOnConfigChanged() { |
| 961 | for (Callback callback : mCallbacks) { |
| 962 | callback.onConfigChanged(); |
| 963 | } |
| 964 | } |
| 965 | |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 966 | private void dispatchOnPolicyChanged() { |
| 967 | for (Callback callback : mCallbacks) { |
| 968 | callback.onPolicyChanged(); |
| 969 | } |
| 970 | } |
| 971 | |
John Spurlock | 1c923a3 | 2014-04-27 16:42:29 -0400 | [diff] [blame] | 972 | private void dispatchOnZenModeChanged() { |
| 973 | for (Callback callback : mCallbacks) { |
| 974 | callback.onZenModeChanged(); |
| 975 | } |
| 976 | } |
| 977 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 978 | private ZenModeConfig readDefaultConfig(Resources resources) { |
| 979 | XmlResourceParser parser = null; |
| 980 | try { |
| 981 | parser = resources.getXml(R.xml.default_zen_mode_config); |
| 982 | while (parser.next() != XmlPullParser.END_DOCUMENT) { |
Julia Reynolds | 206c7e9 | 2016-09-15 10:38:03 -0400 | [diff] [blame] | 983 | final ZenModeConfig config = ZenModeConfig.readXml(parser); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 984 | if (config != null) return config; |
| 985 | } |
| 986 | } catch (Exception e) { |
| 987 | Log.w(TAG, "Error reading default zen mode config from resource", e); |
| 988 | } finally { |
| 989 | IoUtils.closeQuietly(parser); |
| 990 | } |
| 991 | return new ZenModeConfig(); |
| 992 | } |
| 993 | |
Beverly | 26eba87 | 2017-12-04 16:30:11 -0500 | [diff] [blame] | 994 | private void appendDefaultEveryNightRule(ZenModeConfig config) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 995 | if (config == null) return; |
| 996 | |
| 997 | final ScheduleInfo weeknights = new ScheduleInfo(); |
Beverly | 26eba87 | 2017-12-04 16:30:11 -0500 | [diff] [blame] | 998 | weeknights.days = ZenModeConfig.ALL_DAYS; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 999 | weeknights.startHour = 22; |
| 1000 | weeknights.endHour = 7; |
Beverly | 30bfbca | 2017-10-17 14:38:20 -0400 | [diff] [blame] | 1001 | weeknights.exitAtAlarm = true; |
Beverly | 26eba87 | 2017-12-04 16:30:11 -0500 | [diff] [blame] | 1002 | final ZenRule rule = new ZenRule(); |
| 1003 | rule.enabled = false; |
| 1004 | rule.name = mDefaultRuleEveryNightName; |
| 1005 | rule.conditionId = ZenModeConfig.toScheduleConditionId(weeknights); |
| 1006 | rule.zenMode = Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; |
| 1007 | rule.component = ScheduleConditionProvider.COMPONENT; |
| 1008 | rule.id = ZenModeConfig.EVERY_NIGHT_DEFAULT_RULE_ID; |
| 1009 | rule.creationTime = System.currentTimeMillis(); |
| 1010 | config.automaticRules.put(rule.id, rule); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1011 | } |
| 1012 | |
John Spurlock | cb9aa20 | 2015-05-08 17:35:22 -0400 | [diff] [blame] | 1013 | private void appendDefaultEventRules(ZenModeConfig config) { |
| 1014 | if (config == null) return; |
| 1015 | |
| 1016 | final EventInfo events = new EventInfo(); |
John Spurlock | 995a749 | 2015-05-28 22:13:03 -0400 | [diff] [blame] | 1017 | events.calendar = null; // any calendar |
John Spurlock | cb9aa20 | 2015-05-08 17:35:22 -0400 | [diff] [blame] | 1018 | events.reply = EventInfo.REPLY_YES_OR_MAYBE; |
| 1019 | final ZenRule rule = new ZenRule(); |
| 1020 | rule.enabled = false; |
Beverly | d4f9649 | 2017-08-02 13:36:11 -0400 | [diff] [blame] | 1021 | rule.name = mDefaultRuleEventsName; |
John Spurlock | cb9aa20 | 2015-05-08 17:35:22 -0400 | [diff] [blame] | 1022 | rule.conditionId = ZenModeConfig.toEventConditionId(events); |
Beverly | bf16c14 | 2017-11-27 16:21:34 -0500 | [diff] [blame] | 1023 | rule.zenMode = Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; |
Julia Reynolds | a47a27f | 2015-08-24 08:31:47 -0400 | [diff] [blame] | 1024 | rule.component = EventConditionProvider.COMPONENT; |
Beverly | 26eba87 | 2017-12-04 16:30:11 -0500 | [diff] [blame] | 1025 | rule.id = ZenModeConfig.EVENTS_DEFAULT_RULE_ID; |
Julia Reynolds | 56106ff | 2015-09-30 14:42:53 -0400 | [diff] [blame] | 1026 | rule.creationTime = System.currentTimeMillis(); |
| 1027 | config.automaticRules.put(rule.id, rule); |
John Spurlock | cb9aa20 | 2015-05-08 17:35:22 -0400 | [diff] [blame] | 1028 | } |
| 1029 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1030 | private static int zenSeverity(int zen) { |
| 1031 | switch (zen) { |
| 1032 | case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: return 1; |
| 1033 | case Global.ZEN_MODE_ALARMS: return 2; |
| 1034 | case Global.ZEN_MODE_NO_INTERRUPTIONS: return 3; |
| 1035 | default: return 0; |
| 1036 | } |
| 1037 | } |
| 1038 | |
Beverly | 85f5241 | 2018-02-27 10:41:13 -0500 | [diff] [blame] | 1039 | @VisibleForTesting |
| 1040 | protected final class RingerModeDelegate implements AudioManagerInternal.RingerModeDelegate { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1041 | @Override |
| 1042 | public String toString() { |
| 1043 | return TAG; |
| 1044 | } |
| 1045 | |
| 1046 | @Override |
| 1047 | public int onSetRingerModeInternal(int ringerModeOld, int ringerModeNew, String caller, |
| 1048 | int ringerModeExternal, VolumePolicy policy) { |
| 1049 | final boolean isChange = ringerModeOld != ringerModeNew; |
| 1050 | |
| 1051 | int ringerModeExternalOut = ringerModeNew; |
| 1052 | |
Beverly | e4ee1cc | 2018-03-06 17:21:08 -0500 | [diff] [blame] | 1053 | if (mZenMode == Global.ZEN_MODE_OFF |
| 1054 | || (mZenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS |
| 1055 | && !ZenModeConfig.areAllPriorityOnlyNotificationZenSoundsMuted(mConfig))) { |
| 1056 | // in priority only with ringer not muted, save ringer mode changes |
| 1057 | // in dnd off, save ringer mode changes |
| 1058 | setPreviousRingerModeSetting(ringerModeNew); |
| 1059 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1060 | int newZen = -1; |
| 1061 | switch (ringerModeNew) { |
| 1062 | case AudioManager.RINGER_MODE_SILENT: |
| 1063 | if (isChange && policy.doNotDisturbWhenSilent) { |
Beverly | 925cde8 | 2018-01-23 09:31:23 -0500 | [diff] [blame] | 1064 | if (mZenMode == Global.ZEN_MODE_OFF) { |
Julia Reynolds | f3252be | 2018-01-17 09:26:21 -0500 | [diff] [blame] | 1065 | newZen = Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1066 | } |
Julia Reynolds | 9b11fdb | 2015-07-31 09:49:55 -0400 | [diff] [blame] | 1067 | setPreviousRingerModeSetting(ringerModeOld); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1068 | } |
| 1069 | break; |
| 1070 | case AudioManager.RINGER_MODE_VIBRATE: |
| 1071 | case AudioManager.RINGER_MODE_NORMAL: |
| 1072 | if (isChange && ringerModeOld == AudioManager.RINGER_MODE_SILENT |
| 1073 | && (mZenMode == Global.ZEN_MODE_NO_INTERRUPTIONS |
Beverly | 925cde8 | 2018-01-23 09:31:23 -0500 | [diff] [blame] | 1074 | || mZenMode == Global.ZEN_MODE_ALARMS |
| 1075 | || (mZenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS |
| 1076 | && ZenModeConfig.areAllPriorityOnlyNotificationZenSoundsMuted( |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 1077 | mConfig)))) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1078 | newZen = Global.ZEN_MODE_OFF; |
| 1079 | } else if (mZenMode != Global.ZEN_MODE_OFF) { |
| 1080 | ringerModeExternalOut = AudioManager.RINGER_MODE_SILENT; |
| 1081 | } |
| 1082 | break; |
| 1083 | } |
Beverly | 85f5241 | 2018-02-27 10:41:13 -0500 | [diff] [blame] | 1084 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1085 | if (newZen != -1) { |
Julia Reynolds | 44ad6ff | 2016-07-06 09:47:45 -0400 | [diff] [blame] | 1086 | setManualZenMode(newZen, null, "ringerModeInternal", null, |
| 1087 | false /*setRingerMode*/); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1088 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1089 | if (isChange || newZen != -1 || ringerModeExternal != ringerModeExternalOut) { |
| 1090 | ZenLog.traceSetRingerModeInternal(ringerModeOld, ringerModeNew, caller, |
| 1091 | ringerModeExternal, ringerModeExternalOut); |
| 1092 | } |
| 1093 | return ringerModeExternalOut; |
| 1094 | } |
| 1095 | |
| 1096 | @Override |
| 1097 | public int onSetRingerModeExternal(int ringerModeOld, int ringerModeNew, String caller, |
| 1098 | int ringerModeInternal, VolumePolicy policy) { |
| 1099 | int ringerModeInternalOut = ringerModeNew; |
| 1100 | final boolean isChange = ringerModeOld != ringerModeNew; |
| 1101 | final boolean isVibrate = ringerModeInternal == AudioManager.RINGER_MODE_VIBRATE; |
| 1102 | |
| 1103 | int newZen = -1; |
| 1104 | switch (ringerModeNew) { |
| 1105 | case AudioManager.RINGER_MODE_SILENT: |
| 1106 | if (isChange) { |
| 1107 | if (mZenMode == Global.ZEN_MODE_OFF) { |
Julia Reynolds | f3252be | 2018-01-17 09:26:21 -0500 | [diff] [blame] | 1108 | newZen = Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1109 | } |
| 1110 | ringerModeInternalOut = isVibrate ? AudioManager.RINGER_MODE_VIBRATE |
John Spurlock | 05715ec | 2015-05-13 11:19:19 -0400 | [diff] [blame] | 1111 | : AudioManager.RINGER_MODE_SILENT; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1112 | } else { |
| 1113 | ringerModeInternalOut = ringerModeInternal; |
| 1114 | } |
| 1115 | break; |
| 1116 | case AudioManager.RINGER_MODE_VIBRATE: |
| 1117 | case AudioManager.RINGER_MODE_NORMAL: |
| 1118 | if (mZenMode != Global.ZEN_MODE_OFF) { |
| 1119 | newZen = Global.ZEN_MODE_OFF; |
| 1120 | } |
| 1121 | break; |
| 1122 | } |
| 1123 | if (newZen != -1) { |
Julia Reynolds | 44ad6ff | 2016-07-06 09:47:45 -0400 | [diff] [blame] | 1124 | setManualZenMode(newZen, null, "ringerModeExternal", caller, |
| 1125 | false /*setRingerMode*/); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | ZenLog.traceSetRingerModeExternal(ringerModeOld, ringerModeNew, caller, |
| 1129 | ringerModeInternal, ringerModeInternalOut); |
| 1130 | return ringerModeInternalOut; |
| 1131 | } |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 1132 | |
| 1133 | @Override |
| 1134 | public boolean canVolumeDownEnterSilent() { |
| 1135 | return mZenMode == Global.ZEN_MODE_OFF; |
| 1136 | } |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 1137 | |
| 1138 | @Override |
| 1139 | public int getRingerModeAffectedStreams(int streams) { |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 1140 | // ringtone and notification streams are always affected by ringer mode |
| 1141 | // system stream is affected by ringer mode when not in priority-only |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 1142 | streams |= (1 << AudioSystem.STREAM_RING) | |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 1143 | (1 << AudioSystem.STREAM_NOTIFICATION) | |
| 1144 | (1 << AudioSystem.STREAM_SYSTEM); |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 1145 | |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 1146 | if (mZenMode == Global.ZEN_MODE_NO_INTERRUPTIONS) { |
Beverly | 925cde8 | 2018-01-23 09:31:23 -0500 | [diff] [blame] | 1147 | // alarm and music streams affected by ringer mode when in total silence |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 1148 | streams |= (1 << AudioSystem.STREAM_ALARM) | |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 1149 | (1 << AudioSystem.STREAM_MUSIC); |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 1150 | } else { |
| 1151 | streams &= ~((1 << AudioSystem.STREAM_ALARM) | |
Beverly | d696476 | 2018-02-16 14:07:03 -0500 | [diff] [blame] | 1152 | (1 << AudioSystem.STREAM_MUSIC)); |
| 1153 | } |
| 1154 | |
| 1155 | if (mZenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS |
| 1156 | && ZenModeConfig.areAllPriorityOnlyNotificationZenSoundsMuted(mConfig)) { |
| 1157 | // system stream is not affected by ringer mode in priority only when the ringer |
| 1158 | // is zen muted (all other notification categories are muted) |
| 1159 | streams &= ~(1 << AudioSystem.STREAM_SYSTEM); |
| 1160 | } else { |
| 1161 | streams |= (1 << AudioSystem.STREAM_SYSTEM); |
John Spurlock | 50ced3f | 2015-05-11 16:00:09 -0400 | [diff] [blame] | 1162 | } |
| 1163 | return streams; |
| 1164 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | private final class SettingsObserver extends ContentObserver { |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 1168 | private final Uri ZEN_MODE = Global.getUriFor(Global.ZEN_MODE); |
| 1169 | |
| 1170 | public SettingsObserver(Handler handler) { |
| 1171 | super(handler); |
| 1172 | } |
| 1173 | |
| 1174 | public void observe() { |
| 1175 | final ContentResolver resolver = mContext.getContentResolver(); |
| 1176 | resolver.registerContentObserver(ZEN_MODE, false /*notifyForDescendents*/, this); |
| 1177 | update(null); |
| 1178 | } |
| 1179 | |
| 1180 | @Override |
| 1181 | public void onChange(boolean selfChange, Uri uri) { |
| 1182 | update(uri); |
| 1183 | } |
| 1184 | |
| 1185 | public void update(Uri uri) { |
| 1186 | if (ZEN_MODE.equals(uri)) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1187 | if (mZenMode != getZenModeSetting()) { |
| 1188 | if (DEBUG) Log.d(TAG, "Fixing zen mode setting"); |
| 1189 | setZenModeSetting(mZenMode); |
| 1190 | } |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | } |
| 1194 | |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 1195 | private void showZenUpgradeNotification(int zen) { |
Nick | a485ec6 | 2018-07-03 11:32:39 -0700 | [diff] [blame] | 1196 | final boolean isWatch = mContext.getPackageManager().hasSystemFeature( |
| 1197 | PackageManager.FEATURE_WATCH); |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 1198 | final boolean showNotification = mIsBootComplete |
Julia Reynolds | 76bfa60 | 2018-04-23 09:38:47 -0400 | [diff] [blame] | 1199 | && zen != Global.ZEN_MODE_OFF |
Nick | a485ec6 | 2018-07-03 11:32:39 -0700 | [diff] [blame] | 1200 | && !isWatch |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 1201 | && Settings.Global.getInt(mContext.getContentResolver(), |
Beverly | 6c60b90 | 2018-08-17 10:10:46 -0400 | [diff] [blame] | 1202 | Settings.Secure.SHOW_ZEN_UPGRADE_NOTIFICATION, 0) != 0 |
| 1203 | && Settings.Global.getInt(mContext.getContentResolver(), |
| 1204 | Settings.Secure.ZEN_SETTINGS_UPDATED, 0) != 1; |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 1205 | |
Nick | a485ec6 | 2018-07-03 11:32:39 -0700 | [diff] [blame] | 1206 | if (isWatch) { |
| 1207 | Settings.Global.putInt(mContext.getContentResolver(), |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 1208 | Settings.Secure.SHOW_ZEN_UPGRADE_NOTIFICATION, 0); |
Nick | a485ec6 | 2018-07-03 11:32:39 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 1211 | if (showNotification) { |
| 1212 | mNotificationManager.notify(TAG, SystemMessage.NOTE_ZEN_UPGRADE, |
| 1213 | createZenUpgradeNotification()); |
Beverly | 91d0a63 | 2018-07-02 16:45:00 -0400 | [diff] [blame] | 1214 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 1215 | Settings.Secure.SHOW_ZEN_UPGRADE_NOTIFICATION, 0); |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | @VisibleForTesting |
| 1220 | protected Notification createZenUpgradeNotification() { |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 1221 | final Bundle extras = new Bundle(); |
| 1222 | extras.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME, |
| 1223 | mContext.getResources().getString(R.string.global_action_settings)); |
Julia Reynolds | 0b8455d | 2018-03-14 11:38:44 -0400 | [diff] [blame] | 1224 | int title = R.string.zen_upgrade_notification_title; |
| 1225 | int content = R.string.zen_upgrade_notification_content; |
Julia Reynolds | 76bfa60 | 2018-04-23 09:38:47 -0400 | [diff] [blame] | 1226 | int drawable = R.drawable.ic_zen_24dp; |
Julia Reynolds | 0b8455d | 2018-03-14 11:38:44 -0400 | [diff] [blame] | 1227 | if (NotificationManager.Policy.areAllVisualEffectsSuppressed( |
| 1228 | getNotificationPolicy().suppressedVisualEffects)) { |
| 1229 | title = R.string.zen_upgrade_notification_visd_title; |
| 1230 | content = R.string.zen_upgrade_notification_visd_content; |
Julia Reynolds | 76bfa60 | 2018-04-23 09:38:47 -0400 | [diff] [blame] | 1231 | drawable = R.drawable.ic_dnd_block_notifications; |
Julia Reynolds | 0b8455d | 2018-03-14 11:38:44 -0400 | [diff] [blame] | 1232 | } |
Julia Reynolds | 76bfa60 | 2018-04-23 09:38:47 -0400 | [diff] [blame] | 1233 | |
Julia Reynolds | 9aa1c9e | 2018-04-09 11:31:15 -0400 | [diff] [blame] | 1234 | Intent onboardingIntent = new Intent(Settings.ZEN_MODE_ONBOARDING); |
| 1235 | onboardingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
Julia Reynolds | 0b8455d | 2018-03-14 11:38:44 -0400 | [diff] [blame] | 1236 | return new Notification.Builder(mContext, SystemNotificationChannels.DO_NOT_DISTURB) |
Julia Reynolds | 9aa1c9e | 2018-04-09 11:31:15 -0400 | [diff] [blame] | 1237 | .setAutoCancel(true) |
Beverly | d8b15ee | 2018-02-13 14:37:38 -0500 | [diff] [blame] | 1238 | .setSmallIcon(R.drawable.ic_settings_24dp) |
Julia Reynolds | 76bfa60 | 2018-04-23 09:38:47 -0400 | [diff] [blame] | 1239 | .setLargeIcon(Icon.createWithResource(mContext, drawable)) |
Julia Reynolds | 0b8455d | 2018-03-14 11:38:44 -0400 | [diff] [blame] | 1240 | .setContentTitle(mContext.getResources().getString(title)) |
| 1241 | .setContentText(mContext.getResources().getString(content)) |
Julia Reynolds | 9aa1c9e | 2018-04-09 11:31:15 -0400 | [diff] [blame] | 1242 | .setContentIntent(PendingIntent.getActivity(mContext, 0, onboardingIntent, |
| 1243 | PendingIntent.FLAG_UPDATE_CURRENT)) |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 1244 | .setAutoCancel(true) |
| 1245 | .setLocalOnly(true) |
| 1246 | .addExtras(extras) |
Julia Reynolds | 0b8455d | 2018-03-14 11:38:44 -0400 | [diff] [blame] | 1247 | .setStyle(new Notification.BigTextStyle()) |
Beverly | 3bae4e5 | 2018-02-07 12:32:02 -0500 | [diff] [blame] | 1248 | .build(); |
| 1249 | } |
| 1250 | |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1251 | private final class Metrics extends Callback { |
| 1252 | private static final String COUNTER_PREFIX = "dnd_mode_"; |
| 1253 | private static final long MINIMUM_LOG_PERIOD_MS = 60 * 1000; |
| 1254 | |
| 1255 | private int mPreviousZenMode = -1; |
| 1256 | private long mBeginningMs = 0L; |
| 1257 | |
| 1258 | @Override |
| 1259 | void onZenModeChanged() { |
| 1260 | emit(); |
| 1261 | } |
| 1262 | |
| 1263 | private void emit() { |
| 1264 | mHandler.postMetricsTimer(); |
| 1265 | final long now = SystemClock.elapsedRealtime(); |
| 1266 | final long since = (now - mBeginningMs); |
| 1267 | if (mPreviousZenMode != mZenMode || since > MINIMUM_LOG_PERIOD_MS) { |
| 1268 | if (mPreviousZenMode != -1) { |
| 1269 | MetricsLogger.count(mContext, COUNTER_PREFIX + mPreviousZenMode, (int) since); |
| 1270 | } |
| 1271 | mPreviousZenMode = mZenMode; |
| 1272 | mBeginningMs = now; |
| 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1277 | private final class H extends Handler { |
John Spurlock | 5762779 | 2014-12-11 11:29:54 -0500 | [diff] [blame] | 1278 | private static final int MSG_DISPATCH = 1; |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1279 | private static final int MSG_METRICS = 2; |
Julia Reynolds | d82e981 | 2016-04-19 13:27:41 -0400 | [diff] [blame] | 1280 | private static final int MSG_APPLY_CONFIG = 4; |
Eric Laurent | e0ced4d | 2015-09-30 17:44:28 -0700 | [diff] [blame] | 1281 | |
| 1282 | private final class ConfigMessageData { |
| 1283 | public final ZenModeConfig config; |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 1284 | public ComponentName triggeringComponent; |
Eric Laurent | e0ced4d | 2015-09-30 17:44:28 -0700 | [diff] [blame] | 1285 | public final String reason; |
Julia Reynolds | d82e981 | 2016-04-19 13:27:41 -0400 | [diff] [blame] | 1286 | public final boolean setRingerMode; |
Eric Laurent | e0ced4d | 2015-09-30 17:44:28 -0700 | [diff] [blame] | 1287 | |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 1288 | ConfigMessageData(ZenModeConfig config, String reason, |
| 1289 | ComponentName triggeringComponent, boolean setRingerMode) { |
Julia Reynolds | d82e981 | 2016-04-19 13:27:41 -0400 | [diff] [blame] | 1290 | this.config = config; |
| 1291 | this.reason = reason; |
| 1292 | this.setRingerMode = setRingerMode; |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 1293 | this.triggeringComponent = triggeringComponent; |
Eric Laurent | e0ced4d | 2015-09-30 17:44:28 -0700 | [diff] [blame] | 1294 | } |
| 1295 | } |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1296 | |
| 1297 | private static final long METRICS_PERIOD_MS = 6 * 60 * 60 * 1000; |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1298 | |
| 1299 | private H(Looper looper) { |
| 1300 | super(looper); |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 1301 | } |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1302 | |
John Spurlock | 5762779 | 2014-12-11 11:29:54 -0500 | [diff] [blame] | 1303 | private void postDispatchOnZenModeChanged() { |
| 1304 | removeMessages(MSG_DISPATCH); |
| 1305 | sendEmptyMessage(MSG_DISPATCH); |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1306 | } |
| 1307 | |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1308 | private void postMetricsTimer() { |
| 1309 | removeMessages(MSG_METRICS); |
| 1310 | sendEmptyMessageDelayed(MSG_METRICS, METRICS_PERIOD_MS); |
| 1311 | } |
| 1312 | |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 1313 | private void postApplyConfig(ZenModeConfig config, String reason, |
| 1314 | ComponentName triggeringComponent, boolean setRingerMode) { |
Julia Reynolds | d82e981 | 2016-04-19 13:27:41 -0400 | [diff] [blame] | 1315 | sendMessage(obtainMessage(MSG_APPLY_CONFIG, |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 1316 | new ConfigMessageData(config, reason, triggeringComponent, setRingerMode))); |
Julia Reynolds | d82e981 | 2016-04-19 13:27:41 -0400 | [diff] [blame] | 1317 | } |
| 1318 | |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1319 | @Override |
| 1320 | public void handleMessage(Message msg) { |
John Spurlock | 5762779 | 2014-12-11 11:29:54 -0500 | [diff] [blame] | 1321 | switch (msg.what) { |
| 1322 | case MSG_DISPATCH: |
| 1323 | dispatchOnZenModeChanged(); |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1324 | break; |
Chris Wren | 98d235b | 2015-05-27 18:25:17 -0400 | [diff] [blame] | 1325 | case MSG_METRICS: |
| 1326 | mMetrics.emit(); |
| 1327 | break; |
Julia Reynolds | d82e981 | 2016-04-19 13:27:41 -0400 | [diff] [blame] | 1328 | case MSG_APPLY_CONFIG: |
| 1329 | ConfigMessageData applyConfigData = (ConfigMessageData) msg.obj; |
| 1330 | applyConfig(applyConfigData.config, applyConfigData.reason, |
Julia Reynolds | 8f05600 | 2018-07-13 15:12:29 -0400 | [diff] [blame] | 1331 | applyConfigData.triggeringComponent, applyConfigData.setRingerMode); |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 1332 | } |
| 1333 | } |
| 1334 | } |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 1335 | |
John Spurlock | 1c923a3 | 2014-04-27 16:42:29 -0400 | [diff] [blame] | 1336 | public static class Callback { |
| 1337 | void onConfigChanged() {} |
| 1338 | void onZenModeChanged() {} |
John Spurlock | 1fc476d | 2015-04-14 16:05:20 -0400 | [diff] [blame] | 1339 | void onPolicyChanged() {} |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 1340 | } |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 1341 | |
John Spurlock | 056c519 | 2014-04-20 21:52:01 -0400 | [diff] [blame] | 1342 | } |