Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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.phone; |
| 18 | |
Ta-wei Yen | afca2d6 | 2017-07-18 17:20:59 -0700 | [diff] [blame] | 19 | import static android.Manifest.permission.READ_PHONE_STATE; |
| 20 | |
chen xu | baf9fe5 | 2019-07-02 17:28:24 -0700 | [diff] [blame] | 21 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 22 | import android.app.Notification; |
| 23 | import android.app.NotificationManager; |
| 24 | import android.app.PendingIntent; |
| 25 | import android.app.StatusBarManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 26 | import android.content.ComponentName; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
| 29 | import android.content.SharedPreferences; |
Jordan Liu | 9ddde02 | 2019-08-05 13:49:08 -0700 | [diff] [blame] | 30 | import android.content.pm.PackageManager; |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 31 | import android.content.pm.ResolveInfo; |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 32 | import android.content.pm.UserInfo; |
Nancy Chen | b4a9270 | 2014-12-04 15:57:29 -0800 | [diff] [blame] | 33 | import android.content.res.Resources; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 34 | import android.net.Uri; |
irisykyang | 2520246 | 2018-11-13 14:49:54 +0800 | [diff] [blame] | 35 | import android.os.Handler; |
| 36 | import android.os.Message; |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 37 | import android.os.PersistableBundle; |
irisykyang | 2520246 | 2018-11-13 14:49:54 +0800 | [diff] [blame] | 38 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 39 | import android.os.SystemProperties; |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 40 | import android.os.UserHandle; |
| 41 | import android.os.UserManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.preference.PreferenceManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 43 | import android.provider.ContactsContract.PhoneLookup; |
Jeff Davidson | 6d9bf52 | 2017-11-03 14:51:13 -0700 | [diff] [blame] | 44 | import android.provider.Settings; |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 45 | import android.telecom.DefaultDialerManager; |
Tyler Gunn | 4d45d1c | 2014-09-12 22:17:53 -0700 | [diff] [blame] | 46 | import android.telecom.PhoneAccount; |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 47 | import android.telecom.PhoneAccountHandle; |
| 48 | import android.telecom.TelecomManager; |
Jonathan Basseri | 3649bdb | 2015-04-30 22:39:11 -0700 | [diff] [blame] | 49 | import android.telephony.CarrierConfigManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.telephony.PhoneNumberUtils; |
| 51 | import android.telephony.ServiceState; |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 52 | import android.telephony.SubscriptionInfo; |
Andrew Lee | a82b820 | 2014-11-21 16:18:28 -0800 | [diff] [blame] | 53 | import android.telephony.SubscriptionManager; |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 54 | import android.telephony.TelephonyManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.text.TextUtils; |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 56 | import android.util.ArrayMap; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | import android.util.Log; |
irisykyang | 2520246 | 2018-11-13 14:49:54 +0800 | [diff] [blame] | 58 | import android.util.SparseArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 59 | import android.widget.Toast; |
Ta-wei Yen | b29425b | 2016-09-21 17:28:14 -0700 | [diff] [blame] | 60 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 61 | import com.android.internal.telephony.Phone; |
Jayachandran C | 2ef9a48 | 2017-05-12 22:07:47 -0700 | [diff] [blame] | 62 | import com.android.internal.telephony.PhoneFactory; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 63 | import com.android.internal.telephony.TelephonyCapabilities; |
fionaxu | 8b7620d | 2017-05-01 16:22:17 -0700 | [diff] [blame] | 64 | import com.android.internal.telephony.util.NotificationChannelController; |
Andrew Lee | bf07f76 | 2015-04-07 19:05:50 -0700 | [diff] [blame] | 65 | import com.android.phone.settings.VoicemailSettingsActivity; |
Ta-wei Yen | b29425b | 2016-09-21 17:28:14 -0700 | [diff] [blame] | 66 | |
chen xu | baf9fe5 | 2019-07-02 17:28:24 -0700 | [diff] [blame] | 67 | import java.util.HashSet; |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 68 | import java.util.Iterator; |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 69 | import java.util.List; |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 70 | import java.util.Set; |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 71 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 72 | /** |
| 73 | * NotificationManager-related utility code for the Phone app. |
| 74 | * |
| 75 | * This is a singleton object which acts as the interface to the |
| 76 | * framework's NotificationManager, and is used to display status bar |
| 77 | * icons and control other status bar-related behavior. |
| 78 | * |
| 79 | * @see PhoneGlobals.notificationMgr |
| 80 | */ |
Chiao Cheng | 312b9c9 | 2013-09-16 15:40:53 -0700 | [diff] [blame] | 81 | public class NotificationMgr { |
Andrew Lee | a82b820 | 2014-11-21 16:18:28 -0800 | [diff] [blame] | 82 | private static final String LOG_TAG = NotificationMgr.class.getSimpleName(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 83 | private static final boolean DBG = |
| 84 | (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1); |
| 85 | // Do not check in with VDBG = true, since that may write PII to the system log. |
| 86 | private static final boolean VDBG = false; |
| 87 | |
Ta-wei Yen | b29425b | 2016-09-21 17:28:14 -0700 | [diff] [blame] | 88 | private static final String MWI_SHOULD_CHECK_VVM_CONFIGURATION_KEY_PREFIX = |
| 89 | "mwi_should_check_vvm_configuration_state_"; |
| 90 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 91 | // notification types |
Santos Cordon | f68db2e | 2014-07-02 14:40:44 -0700 | [diff] [blame] | 92 | static final int MMI_NOTIFICATION = 1; |
| 93 | static final int NETWORK_SELECTION_NOTIFICATION = 2; |
| 94 | static final int VOICEMAIL_NOTIFICATION = 3; |
| 95 | static final int CALL_FORWARD_NOTIFICATION = 4; |
Jordan Liu | c353b16 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 96 | static final int DATA_ROAMING_NOTIFICATION = 5; |
Santos Cordon | f68db2e | 2014-07-02 14:40:44 -0700 | [diff] [blame] | 97 | static final int SELECTED_OPERATOR_FAIL_NOTIFICATION = 6; |
chen xu | baf9fe5 | 2019-07-02 17:28:24 -0700 | [diff] [blame] | 98 | static final int LIMITED_SIM_FUNCTION_NOTIFICATION = 7; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 99 | |
irisykyang | 2520246 | 2018-11-13 14:49:54 +0800 | [diff] [blame] | 100 | // Event for network selection notification. |
| 101 | private static final int EVENT_PENDING_NETWORK_SELECTION_NOTIFICATION = 1; |
| 102 | |
| 103 | private static final long NETWORK_SELECTION_NOTIFICATION_MAX_PENDING_TIME_IN_MS = 10000L; |
| 104 | private static final int NETWORK_SELECTION_NOTIFICATION_MAX_PENDING_TIMES = 10; |
| 105 | |
| 106 | private static final int STATE_UNKNOWN_SERVICE = -1; |
| 107 | |
chen xu | baf9fe5 | 2019-07-02 17:28:24 -0700 | [diff] [blame] | 108 | private static final String ACTION_MOBILE_NETWORK_LIST = "android.settings.MOBILE_NETWORK_LIST"; |
| 109 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 110 | /** The singleton NotificationMgr instance. */ |
| 111 | private static NotificationMgr sInstance; |
| 112 | |
| 113 | private PhoneGlobals mApp; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 114 | |
| 115 | private Context mContext; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | private StatusBarManager mStatusBarManager; |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 117 | private UserManager mUserManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 118 | private Toast mToast; |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 119 | private SubscriptionManager mSubscriptionManager; |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 120 | private TelecomManager mTelecomManager; |
| 121 | private TelephonyManager mTelephonyManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 122 | |
irisykyang | 2520246 | 2018-11-13 14:49:54 +0800 | [diff] [blame] | 123 | // used to track the notification of selected network unavailable, per subscription id. |
| 124 | private SparseArray<Boolean> mSelectedUnavailableNotify = new SparseArray<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 125 | |
chen xu | baf9fe5 | 2019-07-02 17:28:24 -0700 | [diff] [blame] | 126 | // used to track the notification of limited sim function under dual sim, per subscription id. |
| 127 | private Set<Integer> mLimitedSimFunctionNotify = new HashSet<>(); |
| 128 | |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 129 | // used to track whether the message waiting indicator is visible, per subscription id. |
| 130 | private ArrayMap<Integer, Boolean> mMwiVisible = new ArrayMap<Integer, Boolean>(); |
| 131 | |
irisykyang | 2520246 | 2018-11-13 14:49:54 +0800 | [diff] [blame] | 132 | // those flags are used to track whether to show network selection notification or not. |
| 133 | private SparseArray<Integer> mPreviousServiceState = new SparseArray<>(); |
| 134 | private SparseArray<Long> mOOSTimestamp = new SparseArray<>(); |
| 135 | private SparseArray<Integer> mPendingEventCounter = new SparseArray<>(); |
| 136 | // maps each subId to selected network operator name. |
| 137 | private SparseArray<String> mSelectedNetworkOperatorName = new SparseArray<>(); |
| 138 | |
| 139 | private final Handler mHandler = new Handler() { |
| 140 | @Override |
| 141 | public void handleMessage(Message msg) { |
| 142 | switch (msg.what) { |
| 143 | case EVENT_PENDING_NETWORK_SELECTION_NOTIFICATION: |
| 144 | int subId = (int) msg.obj; |
| 145 | TelephonyManager telephonyManager = |
| 146 | mTelephonyManager.createForSubscriptionId(subId); |
| 147 | if (telephonyManager.getServiceState() != null) { |
| 148 | shouldShowNotification(telephonyManager.getServiceState().getState(), |
| 149 | subId); |
| 150 | } |
| 151 | break; |
| 152 | } |
| 153 | } |
| 154 | }; |
| 155 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 156 | /** |
| 157 | * Private constructor (this is a singleton). |
Santos Cordon | f68db2e | 2014-07-02 14:40:44 -0700 | [diff] [blame] | 158 | * @see #init(PhoneGlobals) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 159 | */ |
| 160 | private NotificationMgr(PhoneGlobals app) { |
| 161 | mApp = app; |
| 162 | mContext = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 163 | mStatusBarManager = |
| 164 | (StatusBarManager) app.getSystemService(Context.STATUS_BAR_SERVICE); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 165 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 166 | mSubscriptionManager = SubscriptionManager.from(mContext); |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 167 | mTelecomManager = TelecomManager.from(mContext); |
| 168 | mTelephonyManager = (TelephonyManager) app.getSystemService(Context.TELEPHONY_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Initialize the singleton NotificationMgr instance. |
| 173 | * |
| 174 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 175 | * From then on, the NotificationMgr instance is available via the |
| 176 | * PhoneApp's public "notificationMgr" field, which is why there's no |
| 177 | * getInstance() method here. |
| 178 | */ |
| 179 | /* package */ static NotificationMgr init(PhoneGlobals app) { |
| 180 | synchronized (NotificationMgr.class) { |
| 181 | if (sInstance == null) { |
| 182 | sInstance = new NotificationMgr(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 183 | } else { |
| 184 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 185 | } |
| 186 | return sInstance; |
| 187 | } |
| 188 | } |
| 189 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 190 | /** The projection to use when querying the phones table */ |
| 191 | static final String[] PHONES_PROJECTION = new String[] { |
| 192 | PhoneLookup.NUMBER, |
| 193 | PhoneLookup.DISPLAY_NAME, |
| 194 | PhoneLookup._ID |
| 195 | }; |
| 196 | |
| 197 | /** |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 198 | * Re-creates the message waiting indicator (voicemail) notification if it is showing. Used to |
| 199 | * refresh the voicemail intent on the indicator when the user changes it via the voicemail |
| 200 | * settings screen. The voicemail notification sound is suppressed. |
| 201 | * |
| 202 | * @param subId The subscription Id. |
| 203 | */ |
| 204 | /* package */ void refreshMwi(int subId) { |
| 205 | // In a single-sim device, subId can be -1 which means "no sub id". In this case we will |
| 206 | // reference the single subid stored in the mMwiVisible map. |
Ta-wei Yen | a1390d4 | 2017-12-04 15:11:33 -0800 | [diff] [blame] | 207 | if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 208 | if (mMwiVisible.keySet().size() == 1) { |
| 209 | Set<Integer> keySet = mMwiVisible.keySet(); |
| 210 | Iterator<Integer> keyIt = keySet.iterator(); |
| 211 | if (!keyIt.hasNext()) { |
| 212 | return; |
| 213 | } |
| 214 | subId = keyIt.next(); |
| 215 | } |
| 216 | } |
| 217 | if (mMwiVisible.containsKey(subId)) { |
| 218 | boolean mwiVisible = mMwiVisible.get(subId); |
| 219 | if (mwiVisible) { |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 220 | mApp.notifier.updatePhoneStateListeners(true); |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
Ta-wei Yen | b29425b | 2016-09-21 17:28:14 -0700 | [diff] [blame] | 225 | public void setShouldCheckVisualVoicemailConfigurationForMwi(int subId, boolean enabled) { |
| 226 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 227 | Log.e(LOG_TAG, "setShouldCheckVisualVoicemailConfigurationForMwi: invalid subId" |
| 228 | + subId); |
| 229 | return; |
| 230 | } |
| 231 | |
| 232 | PreferenceManager.getDefaultSharedPreferences(mContext).edit() |
| 233 | .putBoolean(MWI_SHOULD_CHECK_VVM_CONFIGURATION_KEY_PREFIX + subId, enabled) |
| 234 | .apply(); |
| 235 | } |
| 236 | |
| 237 | private boolean shouldCheckVisualVoicemailConfigurationForMwi(int subId) { |
| 238 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 239 | Log.e(LOG_TAG, "shouldCheckVisualVoicemailConfigurationForMwi: invalid subId" + subId); |
| 240 | return true; |
| 241 | } |
| 242 | return PreferenceManager |
| 243 | .getDefaultSharedPreferences(mContext) |
| 244 | .getBoolean(MWI_SHOULD_CHECK_VVM_CONFIGURATION_KEY_PREFIX + subId, true); |
| 245 | } |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 246 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 247 | * Updates the message waiting indicator (voicemail) notification. |
| 248 | * |
| 249 | * @param visible true if there are messages waiting |
| 250 | */ |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 251 | /* package */ void updateMwi(int subId, boolean visible) { |
Ta-wei Yen | 282a970 | 2017-05-30 17:32:29 -0700 | [diff] [blame] | 252 | updateMwi(subId, visible, false /* isRefresh */); |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Updates the message waiting indicator (voicemail) notification. |
| 257 | * |
| 258 | * @param subId the subId to update. |
| 259 | * @param visible true if there are messages waiting |
Ta-wei Yen | 282a970 | 2017-05-30 17:32:29 -0700 | [diff] [blame] | 260 | * @param isRefresh {@code true} if the notification is a refresh and the user should not be |
| 261 | * notified again. |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 262 | */ |
Ta-wei Yen | 282a970 | 2017-05-30 17:32:29 -0700 | [diff] [blame] | 263 | void updateMwi(int subId, boolean visible, boolean isRefresh) { |
Andrew Lee | a82b820 | 2014-11-21 16:18:28 -0800 | [diff] [blame] | 264 | if (!PhoneGlobals.sVoiceCapable) { |
| 265 | // Do not show the message waiting indicator on devices which are not voice capable. |
| 266 | // These events *should* be blocked at the telephony layer for such devices. |
| 267 | Log.w(LOG_TAG, "Called updateMwi() on non-voice-capable device! Ignoring..."); |
| 268 | return; |
| 269 | } |
| 270 | |
Nancy Chen | 2cf7f29 | 2015-05-15 11:00:10 -0700 | [diff] [blame] | 271 | Phone phone = PhoneGlobals.getPhone(subId); |
Yorke Lee | 67a62a2 | 2014-12-15 18:46:17 -0800 | [diff] [blame] | 272 | Log.i(LOG_TAG, "updateMwi(): subId " + subId + " update to " + visible); |
Andrew Lee | f8ad78f | 2014-12-15 16:17:29 -0800 | [diff] [blame] | 273 | mMwiVisible.put(subId, visible); |
| 274 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 275 | if (visible) { |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 276 | if (phone == null) { |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 277 | Log.w(LOG_TAG, "Found null phone for: " + subId); |
| 278 | return; |
| 279 | } |
| 280 | |
| 281 | SubscriptionInfo subInfo = mSubscriptionManager.getActiveSubscriptionInfo(subId); |
| 282 | if (subInfo == null) { |
| 283 | Log.w(LOG_TAG, "Found null subscription info for: " + subId); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 284 | return; |
| 285 | } |
| 286 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 287 | int resId = android.R.drawable.stat_notify_voicemail; |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 288 | if (mTelephonyManager.getPhoneCount() > 1) { |
| 289 | resId = (phone.getPhoneId() == 0) ? R.drawable.stat_notify_voicemail_sub1 |
| 290 | : R.drawable.stat_notify_voicemail_sub2; |
| 291 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 292 | |
| 293 | // This Notification can get a lot fancier once we have more |
| 294 | // information about the current voicemail messages. |
| 295 | // (For example, the current voicemail system can't tell |
| 296 | // us the caller-id or timestamp of a message, or tell us the |
| 297 | // message count.) |
| 298 | |
| 299 | // But for now, the UI is ultra-simple: if the MWI indication |
| 300 | // is supposed to be visible, just show a single generic |
| 301 | // notification. |
| 302 | |
| 303 | String notificationTitle = mContext.getString(R.string.notification_voicemail_title); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 304 | String vmNumber = phone.getVoiceMailNumber(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 305 | if (DBG) log("- got vm number: '" + vmNumber + "'"); |
| 306 | |
Andrew Lee | a82b820 | 2014-11-21 16:18:28 -0800 | [diff] [blame] | 307 | // The voicemail number may be null because: |
| 308 | // (1) This phone has no voicemail number. |
| 309 | // (2) This phone has a voicemail number, but the SIM isn't ready yet. This may |
| 310 | // happen when the device first boots if we get a MWI notification when we |
| 311 | // register on the network before the SIM has loaded. In this case, the |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 312 | // SubscriptionListener in CallNotifier will update this once the SIM is loaded. |
| 313 | if ((vmNumber == null) && !phone.getIccRecordsLoaded()) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 314 | if (DBG) log("- Null vm number: SIM records not loaded (yet)..."); |
Andrew Lee | a82b820 | 2014-11-21 16:18:28 -0800 | [diff] [blame] | 315 | return; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 318 | Integer vmCount = null; |
| 319 | |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 320 | if (TelephonyCapabilities.supportsVoiceMessageCount(phone)) { |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 321 | vmCount = phone.getVoiceMessageCount(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 322 | String titleFormat = mContext.getString(R.string.notification_voicemail_title_count); |
| 323 | notificationTitle = String.format(titleFormat, vmCount); |
| 324 | } |
| 325 | |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 326 | // This pathway only applies to PSTN accounts; only SIMS have subscription ids. |
| 327 | PhoneAccountHandle phoneAccountHandle = PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 328 | |
| 329 | Intent intent; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 330 | String notificationText; |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 331 | boolean isSettingsIntent = TextUtils.isEmpty(vmNumber); |
| 332 | |
| 333 | if (isSettingsIntent) { |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 334 | notificationText = mContext.getString( |
| 335 | R.string.notification_voicemail_no_vm_number); |
| 336 | |
| 337 | // If the voicemail number if unknown, instead of calling voicemail, take the user |
| 338 | // to the voicemail settings. |
| 339 | notificationText = mContext.getString( |
| 340 | R.string.notification_voicemail_no_vm_number); |
Andrew Lee | bf07f76 | 2015-04-07 19:05:50 -0700 | [diff] [blame] | 341 | intent = new Intent(VoicemailSettingsActivity.ACTION_ADD_VOICEMAIL); |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 342 | intent.putExtra(SubscriptionInfoHelper.SUB_ID_EXTRA, subId); |
Andrew Lee | bf07f76 | 2015-04-07 19:05:50 -0700 | [diff] [blame] | 343 | intent.setClass(mContext, VoicemailSettingsActivity.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 344 | } else { |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 345 | if (mTelephonyManager.getPhoneCount() > 1) { |
| 346 | notificationText = subInfo.getDisplayName().toString(); |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 347 | } else { |
| 348 | notificationText = String.format( |
| 349 | mContext.getString(R.string.notification_voicemail_text_format), |
| 350 | PhoneNumberUtils.formatNumber(vmNumber)); |
| 351 | } |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 352 | intent = new Intent( |
| 353 | Intent.ACTION_CALL, Uri.fromParts(PhoneAccount.SCHEME_VOICEMAIL, "", |
Jonathan Basseri | 3649bdb | 2015-04-30 22:39:11 -0700 | [diff] [blame] | 354 | null)); |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 355 | intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 358 | PendingIntent pendingIntent = |
| 359 | PendingIntent.getActivity(mContext, subId /* requestCode */, intent, 0); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 360 | |
Nancy Chen | b4a9270 | 2014-12-04 15:57:29 -0800 | [diff] [blame] | 361 | Resources res = mContext.getResources(); |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 362 | PersistableBundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId( |
Ta-wei Yen | 9b37a87 | 2016-05-27 12:16:58 -0700 | [diff] [blame] | 363 | subId); |
fionaxu | 8b7620d | 2017-05-01 16:22:17 -0700 | [diff] [blame] | 364 | Notification.Builder builder = new Notification.Builder(mContext); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 365 | builder.setSmallIcon(resId) |
| 366 | .setWhen(System.currentTimeMillis()) |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 367 | .setColor(subInfo.getIconTint()) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 368 | .setContentTitle(notificationTitle) |
| 369 | .setContentText(notificationText) |
| 370 | .setContentIntent(pendingIntent) |
Nancy Chen | b4a9270 | 2014-12-04 15:57:29 -0800 | [diff] [blame] | 371 | .setColor(res.getColor(R.color.dialer_theme_color)) |
Jonathan Basseri | 3649bdb | 2015-04-30 22:39:11 -0700 | [diff] [blame] | 372 | .setOngoing(carrierConfig.getBoolean( |
fionaxu | 75b66a7 | 2017-04-19 19:01:56 -0700 | [diff] [blame] | 373 | CarrierConfigManager.KEY_VOICEMAIL_NOTIFICATION_PERSISTENT_BOOL)) |
Jordan Liu | 575c0d0 | 2019-07-09 16:29:48 -0700 | [diff] [blame] | 374 | .setChannelId(NotificationChannelController.CHANNEL_ID_VOICE_MAIL) |
Ta-wei Yen | 282a970 | 2017-05-30 17:32:29 -0700 | [diff] [blame] | 375 | .setOnlyAlertOnce(isRefresh); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 376 | |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 377 | final Notification notification = builder.build(); |
| 378 | List<UserInfo> users = mUserManager.getUsers(true); |
Jordan Liu | a55aaaa | 2019-08-28 15:33:05 -0700 | [diff] [blame] | 379 | for (UserInfo user : users) { |
Yorke Lee | 047b1f9 | 2014-10-24 10:22:41 -0700 | [diff] [blame] | 380 | final UserHandle userHandle = user.getUserHandle(); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 381 | if (!mUserManager.hasUserRestriction( |
Yorke Lee | 047b1f9 | 2014-10-24 10:22:41 -0700 | [diff] [blame] | 382 | UserManager.DISALLOW_OUTGOING_CALLS, userHandle) |
Jordan Liu | a55aaaa | 2019-08-28 15:33:05 -0700 | [diff] [blame] | 383 | && !mUserManager.isManagedProfile(userHandle.getIdentifier())) { |
Ta-wei Yen | a71a38b | 2017-02-24 18:19:27 -0800 | [diff] [blame] | 384 | if (!maybeSendVoicemailNotificationUsingDefaultDialer(phone, vmCount, vmNumber, |
Ta-wei Yen | 282a970 | 2017-05-30 17:32:29 -0700 | [diff] [blame] | 385 | pendingIntent, isSettingsIntent, userHandle, isRefresh)) { |
Jordan Liu | 9ddde02 | 2019-08-05 13:49:08 -0700 | [diff] [blame] | 386 | notifyAsUser( |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 387 | Integer.toString(subId) /* tag */, |
| 388 | VOICEMAIL_NOTIFICATION, |
| 389 | notification, |
| 390 | userHandle); |
| 391 | } |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 392 | } |
| 393 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 394 | } else { |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 395 | List<UserInfo> users = mUserManager.getUsers(true /* excludeDying */); |
Jordan Liu | a55aaaa | 2019-08-28 15:33:05 -0700 | [diff] [blame] | 396 | for (UserInfo user : users) { |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 397 | final UserHandle userHandle = user.getUserHandle(); |
| 398 | if (!mUserManager.hasUserRestriction( |
| 399 | UserManager.DISALLOW_OUTGOING_CALLS, userHandle) |
Jordan Liu | a55aaaa | 2019-08-28 15:33:05 -0700 | [diff] [blame] | 400 | && !mUserManager.isManagedProfile(userHandle.getIdentifier())) { |
Ta-wei Yen | a71a38b | 2017-02-24 18:19:27 -0800 | [diff] [blame] | 401 | if (!maybeSendVoicemailNotificationUsingDefaultDialer(phone, 0, null, null, |
Ta-wei Yen | 282a970 | 2017-05-30 17:32:29 -0700 | [diff] [blame] | 402 | false, userHandle, isRefresh)) { |
Jordan Liu | 9ddde02 | 2019-08-05 13:49:08 -0700 | [diff] [blame] | 403 | cancelAsUser( |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 404 | Integer.toString(subId) /* tag */, |
| 405 | VOICEMAIL_NOTIFICATION, |
| 406 | userHandle); |
| 407 | } |
| 408 | } |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 409 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
| 413 | /** |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 414 | * Sends a broadcast with the voicemail notification information to the default dialer. This |
| 415 | * method is also used to indicate to the default dialer when to clear the |
| 416 | * notification. A pending intent can be passed to the default dialer to indicate an action to |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 417 | * be taken as it would by a notification produced in this class. |
Ta-wei Yen | a71a38b | 2017-02-24 18:19:27 -0800 | [diff] [blame] | 418 | * @param phone The phone the notification is sent from |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 419 | * @param count The number of pending voicemail messages to indicate on the notification. A |
| 420 | * Value of 0 is passed here to indicate that the notification should be cleared. |
| 421 | * @param number The voicemail phone number if specified. |
| 422 | * @param pendingIntent The intent that should be passed as the action to be taken. |
| 423 | * @param isSettingsIntent {@code true} to indicate the pending intent is to launch settings. |
| 424 | * otherwise, {@code false} to indicate the intent launches voicemail. |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 425 | * @param userHandle The user to receive the notification. Each user can have their own default |
| 426 | * dialer. |
| 427 | * @return {@code true} if the default was notified of the notification. |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 428 | */ |
Ta-wei Yen | a71a38b | 2017-02-24 18:19:27 -0800 | [diff] [blame] | 429 | private boolean maybeSendVoicemailNotificationUsingDefaultDialer(Phone phone, Integer count, |
| 430 | String number, PendingIntent pendingIntent, boolean isSettingsIntent, |
Ta-wei Yen | 282a970 | 2017-05-30 17:32:29 -0700 | [diff] [blame] | 431 | UserHandle userHandle, boolean isRefresh) { |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 432 | |
| 433 | if (shouldManageNotificationThroughDefaultDialer(userHandle)) { |
| 434 | Intent intent = getShowVoicemailIntentForDefaultDialer(userHandle); |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 435 | intent.setFlags(Intent.FLAG_RECEIVER_FOREGROUND); |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 436 | intent.setAction(TelephonyManager.ACTION_SHOW_VOICEMAIL_NOTIFICATION); |
Ta-wei Yen | a71a38b | 2017-02-24 18:19:27 -0800 | [diff] [blame] | 437 | intent.putExtra(TelephonyManager.EXTRA_PHONE_ACCOUNT_HANDLE, |
| 438 | PhoneUtils.makePstnPhoneAccountHandle(phone)); |
Ta-wei Yen | afca2d6 | 2017-07-18 17:20:59 -0700 | [diff] [blame] | 439 | intent.putExtra(TelephonyManager.EXTRA_IS_REFRESH, isRefresh); |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 440 | if (count != null) { |
| 441 | intent.putExtra(TelephonyManager.EXTRA_NOTIFICATION_COUNT, count); |
| 442 | } |
| 443 | |
| 444 | // Additional information about the voicemail notification beyond the count is only |
| 445 | // present when the count not specified or greater than 0. The value of 0 represents |
| 446 | // clearing the notification, which does not require additional information. |
| 447 | if (count == null || count > 0) { |
| 448 | if (!TextUtils.isEmpty(number)) { |
| 449 | intent.putExtra(TelephonyManager.EXTRA_VOICEMAIL_NUMBER, number); |
| 450 | } |
| 451 | |
| 452 | if (pendingIntent != null) { |
| 453 | intent.putExtra(isSettingsIntent |
| 454 | ? TelephonyManager.EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT |
| 455 | : TelephonyManager.EXTRA_CALL_VOICEMAIL_INTENT, |
| 456 | pendingIntent); |
| 457 | } |
| 458 | } |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 459 | mContext.sendBroadcastAsUser(intent, userHandle, READ_PHONE_STATE); |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 460 | return true; |
| 461 | } |
| 462 | |
| 463 | return false; |
| 464 | } |
| 465 | |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 466 | private Intent getShowVoicemailIntentForDefaultDialer(UserHandle userHandle) { |
| 467 | String dialerPackage = DefaultDialerManager |
| 468 | .getDefaultDialerApplication(mContext, userHandle.getIdentifier()); |
| 469 | return new Intent(TelephonyManager.ACTION_SHOW_VOICEMAIL_NOTIFICATION) |
| 470 | .setPackage(dialerPackage); |
| 471 | } |
| 472 | |
| 473 | private boolean shouldManageNotificationThroughDefaultDialer(UserHandle userHandle) { |
| 474 | Intent intent = getShowVoicemailIntentForDefaultDialer(userHandle); |
| 475 | if (intent == null) { |
| 476 | return false; |
| 477 | } |
| 478 | |
| 479 | List<ResolveInfo> receivers = mContext.getPackageManager() |
| 480 | .queryBroadcastReceivers(intent, 0); |
| 481 | return receivers.size() > 0; |
| 482 | } |
| 483 | |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 484 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 485 | * Updates the message call forwarding indicator notification. |
| 486 | * |
Srikanth Chintala | 4baf0b9 | 2017-11-14 15:52:47 +0530 | [diff] [blame] | 487 | * @param visible true if call forwarding enabled |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 488 | */ |
Srikanth Chintala | 4baf0b9 | 2017-11-14 15:52:47 +0530 | [diff] [blame] | 489 | |
| 490 | /* package */ void updateCfi(int subId, boolean visible) { |
| 491 | updateCfi(subId, visible, false /* isRefresh */); |
| 492 | } |
| 493 | |
| 494 | /** |
| 495 | * Updates the message call forwarding indicator notification. |
| 496 | * |
| 497 | * @param visible true if call forwarding enabled |
| 498 | */ |
| 499 | /* package */ void updateCfi(int subId, boolean visible, boolean isRefresh) { |
Tyler Gunn | a584e2c | 2017-09-19 11:40:12 -0700 | [diff] [blame] | 500 | logi("updateCfi: subId= " + subId + ", visible=" + (visible ? "Y" : "N")); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 501 | if (visible) { |
| 502 | // If Unconditional Call Forwarding (forward all calls) for VOICE |
| 503 | // is enabled, just show a notification. We'll default to expanded |
| 504 | // view for now, so the there is less confusion about the icon. If |
| 505 | // it is deemed too weird to have CF indications as expanded views, |
| 506 | // then we'll flip the flag back. |
| 507 | |
| 508 | // TODO: We may want to take a look to see if the notification can |
| 509 | // display the target to forward calls to. This will require some |
| 510 | // effort though, since there are multiple layers of messages that |
| 511 | // will need to propagate that information. |
| 512 | |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 513 | SubscriptionInfo subInfo = mSubscriptionManager.getActiveSubscriptionInfo(subId); |
| 514 | if (subInfo == null) { |
| 515 | Log.w(LOG_TAG, "Found null subscription info for: " + subId); |
| 516 | return; |
| 517 | } |
| 518 | |
| 519 | String notificationTitle; |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 520 | int resId = R.drawable.stat_sys_phone_call_forward; |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 521 | if (mTelephonyManager.getPhoneCount() > 1) { |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 522 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 523 | resId = (slotId == 0) ? R.drawable.stat_sys_phone_call_forward_sub1 |
| 524 | : R.drawable.stat_sys_phone_call_forward_sub2; |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 525 | notificationTitle = subInfo.getDisplayName().toString(); |
| 526 | } else { |
| 527 | notificationTitle = mContext.getString(R.string.labelCF); |
| 528 | } |
| 529 | |
fionaxu | 8b7620d | 2017-05-01 16:22:17 -0700 | [diff] [blame] | 530 | Notification.Builder builder = new Notification.Builder(mContext) |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 531 | .setSmallIcon(resId) |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 532 | .setColor(subInfo.getIconTint()) |
| 533 | .setContentTitle(notificationTitle) |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 534 | .setContentText(mContext.getString(R.string.sum_cfu_enabled_indicator)) |
| 535 | .setShowWhen(false) |
fionaxu | 75b66a7 | 2017-04-19 19:01:56 -0700 | [diff] [blame] | 536 | .setOngoing(true) |
Jordan Liu | 575c0d0 | 2019-07-09 16:29:48 -0700 | [diff] [blame] | 537 | .setChannelId(NotificationChannelController.CHANNEL_ID_CALL_FORWARD) |
Srikanth Chintala | 4baf0b9 | 2017-11-14 15:52:47 +0530 | [diff] [blame] | 538 | .setOnlyAlertOnce(isRefresh); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 539 | |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 540 | Intent intent = new Intent(Intent.ACTION_MAIN); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 541 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 542 | intent.setClassName("com.android.phone", "com.android.phone.CallFeaturesSetting"); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 543 | SubscriptionInfoHelper.addExtrasToIntent( |
| 544 | intent, mSubscriptionManager.getActiveSubscriptionInfo(subId)); |
fionaxu | 96ceebd | 2017-08-24 12:12:32 -0700 | [diff] [blame] | 545 | builder.setContentIntent(PendingIntent.getActivity(mContext, subId /* requestCode */, |
| 546 | intent, 0)); |
Jordan Liu | 9ddde02 | 2019-08-05 13:49:08 -0700 | [diff] [blame] | 547 | notifyAsUser( |
fionaxu | 96ceebd | 2017-08-24 12:12:32 -0700 | [diff] [blame] | 548 | Integer.toString(subId) /* tag */, |
| 549 | CALL_FORWARD_NOTIFICATION, |
| 550 | builder.build(), |
| 551 | UserHandle.ALL); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 552 | } else { |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 553 | List<UserInfo> users = mUserManager.getUsers(true); |
| 554 | for (UserInfo user : users) { |
Jordan Liu | a55aaaa | 2019-08-28 15:33:05 -0700 | [diff] [blame] | 555 | if (mUserManager.isManagedProfile(user.getUserHandle().getIdentifier())) { |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 556 | continue; |
| 557 | } |
| 558 | UserHandle userHandle = user.getUserHandle(); |
Jordan Liu | 9ddde02 | 2019-08-05 13:49:08 -0700 | [diff] [blame] | 559 | cancelAsUser( |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 560 | Integer.toString(subId) /* tag */, |
| 561 | CALL_FORWARD_NOTIFICATION, |
| 562 | userHandle); |
| 563 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 564 | } |
| 565 | } |
| 566 | |
| 567 | /** |
Jordan Liu | c353b16 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 568 | * Shows either: |
| 569 | * 1) the "Data roaming is on" notification, which |
| 570 | * appears when you're roaming and you have the "data roaming" feature turned on for the |
| 571 | * given {@code subId}. |
| 572 | * or |
| 573 | * 2) the "data disconnected due to roaming" notification, which |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 574 | * appears when you lose data connectivity because you're roaming and |
Pengquan Meng | 8783d93 | 2017-10-16 14:57:40 -0700 | [diff] [blame] | 575 | * you have the "data roaming" feature turned off for the given {@code subId}. |
Jordan Liu | c353b16 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 576 | * @param subId which subscription it's notifying about. |
| 577 | * @param roamingOn whether currently roaming is on or off. If true, we show notification |
| 578 | * 1) above; else we show notification 2). |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 579 | */ |
Jordan Liu | c353b16 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 580 | /* package */ void showDataRoamingNotification(int subId, boolean roamingOn) { |
| 581 | if (DBG) { |
| 582 | log("showDataRoamingNotification() roaming " + (roamingOn ? "on" : "off") |
| 583 | + " on subId " + subId); |
| 584 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 585 | |
| 586 | // "Mobile network settings" screen / dialog |
Nazanin Bakhshi | 682c77d | 2019-05-02 17:22:27 -0700 | [diff] [blame] | 587 | Intent intent = new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS); |
Jeff Davidson | 6d9bf52 | 2017-11-03 14:51:13 -0700 | [diff] [blame] | 588 | intent.putExtra(Settings.EXTRA_SUB_ID, subId); |
Pengquan Meng | 8783d93 | 2017-10-16 14:57:40 -0700 | [diff] [blame] | 589 | PendingIntent contentIntent = PendingIntent.getActivity(mContext, subId, intent, 0); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 590 | |
Jordan Liu | c353b16 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 591 | CharSequence contentTitle = mContext.getText(roamingOn |
| 592 | ? R.string.roaming_on_notification_title |
| 593 | : R.string.roaming_notification_title); |
| 594 | CharSequence contentText = mContext.getText(roamingOn |
| 595 | ? R.string.roaming_enabled_message |
| 596 | : R.string.roaming_reenable_message); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 597 | |
fionaxu | 8b7620d | 2017-05-01 16:22:17 -0700 | [diff] [blame] | 598 | final Notification.Builder builder = new Notification.Builder(mContext) |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 599 | .setSmallIcon(android.R.drawable.stat_sys_warning) |
Jordan Liu | c353b16 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 600 | .setContentTitle(contentTitle) |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 601 | .setColor(mContext.getResources().getColor(R.color.dialer_theme_color)) |
fionaxu | 75b66a7 | 2017-04-19 19:01:56 -0700 | [diff] [blame] | 602 | .setContentText(contentText) |
Jordan Liu | 575c0d0 | 2019-07-09 16:29:48 -0700 | [diff] [blame] | 603 | .setChannelId(NotificationChannelController.CHANNEL_ID_MOBILE_DATA_STATUS) |
fionaxu | 96ceebd | 2017-08-24 12:12:32 -0700 | [diff] [blame] | 604 | .setContentIntent(contentIntent); |
| 605 | final Notification notif = |
| 606 | new Notification.BigTextStyle(builder).bigText(contentText).build(); |
Jordan Liu | 9ddde02 | 2019-08-05 13:49:08 -0700 | [diff] [blame] | 607 | notifyAsUser(null /* tag */, DATA_ROAMING_NOTIFICATION, notif, UserHandle.ALL); |
| 608 | } |
| 609 | |
| 610 | private void notifyAsUser(String tag, int id, Notification notification, UserHandle user) { |
| 611 | try { |
| 612 | Context contextForUser = |
| 613 | mContext.createPackageContextAsUser(mContext.getPackageName(), 0, user); |
| 614 | NotificationManager notificationManager = |
| 615 | (NotificationManager) contextForUser.getSystemService( |
| 616 | Context.NOTIFICATION_SERVICE); |
| 617 | notificationManager.notify(tag, id, notification); |
| 618 | } catch (PackageManager.NameNotFoundException e) { |
| 619 | Log.e(LOG_TAG, "unable to notify for user " + user); |
| 620 | e.printStackTrace(); |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | private void cancelAsUser(String tag, int id, UserHandle user) { |
| 625 | try { |
| 626 | Context contextForUser = |
| 627 | mContext.createPackageContextAsUser(mContext.getPackageName(), 0, user); |
| 628 | NotificationManager notificationManager = |
| 629 | (NotificationManager) contextForUser.getSystemService( |
| 630 | Context.NOTIFICATION_SERVICE); |
| 631 | notificationManager.cancel(tag, id); |
| 632 | } catch (PackageManager.NameNotFoundException e) { |
| 633 | Log.e(LOG_TAG, "unable to cancel for user " + user); |
| 634 | e.printStackTrace(); |
| 635 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | /** |
Jordan Liu | c353b16 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 639 | * Turns off the "data disconnected due to roaming" or "Data roaming is on" notification. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 640 | */ |
Jordan Liu | c353b16 | 2019-07-23 15:54:41 -0700 | [diff] [blame] | 641 | /* package */ void hideDataRoamingNotification() { |
| 642 | if (DBG) log("hideDataRoamingNotification()..."); |
Jordan Liu | 9ddde02 | 2019-08-05 13:49:08 -0700 | [diff] [blame] | 643 | cancelAsUser(null, DATA_ROAMING_NOTIFICATION, UserHandle.ALL); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | /** |
chen xu | baf9fe5 | 2019-07-02 17:28:24 -0700 | [diff] [blame] | 647 | * Shows the "Limited SIM functionality" warning notification, which appears when using a |
| 648 | * special carrier under dual sim. limited function applies for DSDS in general when two SIM |
| 649 | * cards share a single radio, thus the voice & data maybe impaired under certain scenarios. |
| 650 | */ |
| 651 | public void showLimitedSimFunctionWarningNotification(int subId, @Nullable String carrierName) { |
| 652 | if (DBG) log("showLimitedSimFunctionWarningNotification carrier: " + carrierName |
| 653 | + " subId: " + subId); |
| 654 | if (mLimitedSimFunctionNotify.contains(subId)) { |
| 655 | // handle the case that user swipe the notification but condition triggers |
| 656 | // frequently which cause the same notification consistently displayed. |
| 657 | if (DBG) log("showLimitedSimFunctionWarningNotification, " |
| 658 | + "not display again if already displayed"); |
| 659 | return; |
| 660 | } |
| 661 | // Navigate to "Network Selection Settings" which list all subscriptions. |
| 662 | PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, |
| 663 | new Intent(ACTION_MOBILE_NETWORK_LIST), 0); |
| 664 | String line1Num = mTelephonyManager.getLine1Number(subId); |
| 665 | |
| 666 | final CharSequence contentText = TextUtils.isEmpty(line1Num) ? |
| 667 | String.format(mContext.getText( |
| 668 | R.string.limited_sim_function_notification_message).toString(), |
| 669 | carrierName, line1Num) : |
| 670 | String.format(mContext.getText( |
| 671 | R.string.limited_sim_function_with_phone_num_notification_message).toString(), |
| 672 | carrierName); |
| 673 | final Notification.Builder builder = new Notification.Builder(mContext) |
| 674 | .setSmallIcon(R.drawable.ic_sim_card) |
| 675 | .setContentTitle(mContext.getText( |
| 676 | R.string.limited_sim_function_notification_title)) |
| 677 | .setContentText(contentText) |
| 678 | .setOnlyAlertOnce(true) |
| 679 | .setOngoing(true) |
Jordan Liu | a55aaaa | 2019-08-28 15:33:05 -0700 | [diff] [blame] | 680 | .setChannelId(NotificationChannelController.CHANNEL_ID_SIM_HIGH_PRIORITY) |
chen xu | baf9fe5 | 2019-07-02 17:28:24 -0700 | [diff] [blame] | 681 | .setContentIntent(contentIntent); |
| 682 | final Notification notification = new Notification.BigTextStyle(builder).bigText( |
| 683 | contentText).build(); |
| 684 | |
Jordan Liu | 9ddde02 | 2019-08-05 13:49:08 -0700 | [diff] [blame] | 685 | notifyAsUser(Integer.toString(subId), |
chen xu | baf9fe5 | 2019-07-02 17:28:24 -0700 | [diff] [blame] | 686 | LIMITED_SIM_FUNCTION_NOTIFICATION, |
| 687 | notification, UserHandle.ALL); |
| 688 | mLimitedSimFunctionNotify.add(subId); |
| 689 | } |
| 690 | |
| 691 | /** |
| 692 | * Dismiss the "Limited SIM functionality" warning notification for the given subId. |
| 693 | */ |
| 694 | public void dismissLimitedSimFunctionWarningNotification(int subId) { |
| 695 | if (DBG) log("dismissLimitedSimFunctionWarningNotification subId: " + subId); |
| 696 | if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 697 | // dismiss all notifications |
| 698 | for (int id : mLimitedSimFunctionNotify) { |
Jordan Liu | 9ddde02 | 2019-08-05 13:49:08 -0700 | [diff] [blame] | 699 | cancelAsUser(Integer.toString(id), |
chen xu | baf9fe5 | 2019-07-02 17:28:24 -0700 | [diff] [blame] | 700 | LIMITED_SIM_FUNCTION_NOTIFICATION, UserHandle.ALL); |
| 701 | } |
| 702 | mLimitedSimFunctionNotify.clear(); |
| 703 | } else if (mLimitedSimFunctionNotify.contains(subId)) { |
Jordan Liu | 9ddde02 | 2019-08-05 13:49:08 -0700 | [diff] [blame] | 704 | cancelAsUser(Integer.toString(subId), |
chen xu | baf9fe5 | 2019-07-02 17:28:24 -0700 | [diff] [blame] | 705 | LIMITED_SIM_FUNCTION_NOTIFICATION, UserHandle.ALL); |
| 706 | mLimitedSimFunctionNotify.remove(subId); |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | /** |
| 711 | * Dismiss the "Limited SIM functionality" warning notification for all inactive subscriptions. |
| 712 | */ |
| 713 | public void dismissLimitedSimFunctionWarningNotificationForInactiveSubs() { |
| 714 | if (DBG) log("dismissLimitedSimFunctionWarningNotificationForInactiveSubs"); |
| 715 | // dismiss notification for inactive subscriptions. |
| 716 | // handle the corner case that SIM change by SIM refresh doesn't clear the notification |
| 717 | // from the old SIM if both old & new SIM configured to display the notification. |
| 718 | mLimitedSimFunctionNotify.removeIf(id -> { |
| 719 | if (!mSubscriptionManager.isActiveSubId(id)) { |
Jordan Liu | 9ddde02 | 2019-08-05 13:49:08 -0700 | [diff] [blame] | 720 | cancelAsUser(Integer.toString(id), |
chen xu | baf9fe5 | 2019-07-02 17:28:24 -0700 | [diff] [blame] | 721 | LIMITED_SIM_FUNCTION_NOTIFICATION, UserHandle.ALL); |
| 722 | return true; |
| 723 | } |
| 724 | return false; |
| 725 | }); |
| 726 | } |
| 727 | |
| 728 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 729 | * Display the network selection "no service" notification |
| 730 | * @param operator is the numeric operator number |
Jayachandran C | 2ef9a48 | 2017-05-12 22:07:47 -0700 | [diff] [blame] | 731 | * @param subId is the subscription ID |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 732 | */ |
Jayachandran C | 2ef9a48 | 2017-05-12 22:07:47 -0700 | [diff] [blame] | 733 | private void showNetworkSelection(String operator, int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 734 | if (DBG) log("showNetworkSelection(" + operator + ")..."); |
| 735 | |
Youming Ye | 0509b53 | 2018-09-14 16:21:17 -0700 | [diff] [blame] | 736 | if (!TextUtils.isEmpty(operator)) { |
| 737 | operator = String.format(" (%s)", operator); |
| 738 | } |
fionaxu | 8b7620d | 2017-05-01 16:22:17 -0700 | [diff] [blame] | 739 | Notification.Builder builder = new Notification.Builder(mContext) |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 740 | .setSmallIcon(android.R.drawable.stat_sys_warning) |
| 741 | .setContentTitle(mContext.getString(R.string.notification_network_selection_title)) |
| 742 | .setContentText( |
| 743 | mContext.getString(R.string.notification_network_selection_text, operator)) |
| 744 | .setShowWhen(false) |
fionaxu | 75b66a7 | 2017-04-19 19:01:56 -0700 | [diff] [blame] | 745 | .setOngoing(true) |
Jordan Liu | 575c0d0 | 2019-07-09 16:29:48 -0700 | [diff] [blame] | 746 | .setChannelId(NotificationChannelController.CHANNEL_ID_ALERT); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 747 | |
| 748 | // create the target network operators settings intent |
| 749 | Intent intent = new Intent(Intent.ACTION_MAIN); |
| 750 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 751 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Malcolm Chen | 34d4fa5 | 2017-06-05 19:02:16 -0700 | [diff] [blame] | 752 | // Use MobileNetworkSettings to handle the selection intent |
Wei Liu | be96458 | 2015-08-21 11:57:00 -0700 | [diff] [blame] | 753 | intent.setComponent(new ComponentName( |
Malcolm Chen | 34d4fa5 | 2017-06-05 19:02:16 -0700 | [diff] [blame] | 754 | mContext.getString(R.string.mobile_network_settings_package), |
| 755 | mContext.getString(R.string.mobile_network_settings_class))); |
Pengquan Meng | 984ba42 | 2019-09-05 18:00:06 -0700 | [diff] [blame^] | 756 | intent.putExtra(Settings.EXTRA_SUB_ID, subId); |
fionaxu | 96ceebd | 2017-08-24 12:12:32 -0700 | [diff] [blame] | 757 | builder.setContentIntent(PendingIntent.getActivity(mContext, 0, intent, 0)); |
Jordan Liu | 9ddde02 | 2019-08-05 13:49:08 -0700 | [diff] [blame] | 758 | notifyAsUser( |
irisykyang | 2520246 | 2018-11-13 14:49:54 +0800 | [diff] [blame] | 759 | Integer.toString(subId) /* tag */, |
fionaxu | 96ceebd | 2017-08-24 12:12:32 -0700 | [diff] [blame] | 760 | SELECTED_OPERATOR_FAIL_NOTIFICATION, |
| 761 | builder.build(), |
| 762 | UserHandle.ALL); |
irisykyang | 2520246 | 2018-11-13 14:49:54 +0800 | [diff] [blame] | 763 | mSelectedUnavailableNotify.put(subId, true); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | /** |
| 767 | * Turn off the network selection "no service" notification |
| 768 | */ |
irisykyang | 2520246 | 2018-11-13 14:49:54 +0800 | [diff] [blame] | 769 | private void cancelNetworkSelection(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 770 | if (DBG) log("cancelNetworkSelection()..."); |
Jordan Liu | 9ddde02 | 2019-08-05 13:49:08 -0700 | [diff] [blame] | 771 | cancelAsUser( |
irisykyang | 2520246 | 2018-11-13 14:49:54 +0800 | [diff] [blame] | 772 | Integer.toString(subId) /* tag */, SELECTED_OPERATOR_FAIL_NOTIFICATION, |
| 773 | UserHandle.ALL); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | /** |
| 777 | * Update notification about no service of user selected operator |
| 778 | * |
| 779 | * @param serviceState Phone service state |
Jayachandran C | 2ef9a48 | 2017-05-12 22:07:47 -0700 | [diff] [blame] | 780 | * @param subId The subscription ID |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 781 | */ |
Jayachandran C | 2ef9a48 | 2017-05-12 22:07:47 -0700 | [diff] [blame] | 782 | void updateNetworkSelection(int serviceState, int subId) { |
| 783 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 784 | Phone phone = SubscriptionManager.isValidPhoneId(phoneId) ? |
| 785 | PhoneFactory.getPhone(phoneId) : PhoneFactory.getDefaultPhone(); |
| 786 | if (TelephonyCapabilities.supportsNetworkSelection(phone)) { |
Amit Mahajan | a60be87 | 2015-01-15 16:05:08 -0800 | [diff] [blame] | 787 | if (SubscriptionManager.isValidSubscriptionId(subId)) { |
fionaxu | 996a1c3 | 2018-04-13 15:00:37 -0700 | [diff] [blame] | 788 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); |
| 789 | String selectedNetworkOperatorName = |
| 790 | sp.getString(Phone.NETWORK_SELECTION_NAME_KEY + subId, ""); |
| 791 | // get the shared preference of network_selection. |
| 792 | // empty is auto mode, otherwise it is the operator alpha name |
| 793 | // in case there is no operator name, check the operator numeric |
| 794 | if (TextUtils.isEmpty(selectedNetworkOperatorName)) { |
| 795 | selectedNetworkOperatorName = |
| 796 | sp.getString(Phone.NETWORK_SELECTION_KEY + subId, ""); |
| 797 | } |
| 798 | boolean isManualSelection; |
fionaxu | d6aac66 | 2018-03-14 16:44:29 -0700 | [diff] [blame] | 799 | // if restoring manual selection is controlled by framework, then get network |
| 800 | // selection from shared preference, otherwise get from real network indicators. |
| 801 | boolean restoreSelection = !mContext.getResources().getBoolean( |
| 802 | com.android.internal.R.bool.skip_restoring_network_selection); |
fionaxu | d6aac66 | 2018-03-14 16:44:29 -0700 | [diff] [blame] | 803 | if (restoreSelection) { |
fionaxu | d6aac66 | 2018-03-14 16:44:29 -0700 | [diff] [blame] | 804 | isManualSelection = !TextUtils.isEmpty(selectedNetworkOperatorName); |
| 805 | } else { |
fionaxu | d6aac66 | 2018-03-14 16:44:29 -0700 | [diff] [blame] | 806 | isManualSelection = phone.getServiceStateTracker().mSS.getIsManualSelection(); |
Amit Mahajan | a60be87 | 2015-01-15 16:05:08 -0800 | [diff] [blame] | 807 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 808 | |
fionaxu | d6aac66 | 2018-03-14 16:44:29 -0700 | [diff] [blame] | 809 | if (DBG) { |
| 810 | log("updateNetworkSelection()..." + "state = " + serviceState + " new network " |
| 811 | + (isManualSelection ? selectedNetworkOperatorName : "")); |
| 812 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 813 | |
irisykyang | 2520246 | 2018-11-13 14:49:54 +0800 | [diff] [blame] | 814 | if (isManualSelection) { |
| 815 | mSelectedNetworkOperatorName.put(subId, selectedNetworkOperatorName); |
| 816 | shouldShowNotification(serviceState, subId); |
Amit Mahajan | a60be87 | 2015-01-15 16:05:08 -0800 | [diff] [blame] | 817 | } else { |
irisykyang | 2520246 | 2018-11-13 14:49:54 +0800 | [diff] [blame] | 818 | dismissNetworkSelectionNotification(subId); |
| 819 | clearUpNetworkSelectionNotificationParam(subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 820 | } |
| 821 | } else { |
Amit Mahajan | a60be87 | 2015-01-15 16:05:08 -0800 | [diff] [blame] | 822 | if (DBG) log("updateNetworkSelection()..." + "state = " + |
| 823 | serviceState + " not updating network due to invalid subId " + subId); |
irisykyang | 2520246 | 2018-11-13 14:49:54 +0800 | [diff] [blame] | 824 | dismissNetworkSelectionNotificationForInactiveSubId(); |
| 825 | } |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | private void dismissNetworkSelectionNotification(int subId) { |
| 830 | if (mSelectedUnavailableNotify.get(subId, false)) { |
| 831 | cancelNetworkSelection(subId); |
| 832 | mSelectedUnavailableNotify.remove(subId); |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | private void dismissNetworkSelectionNotificationForInactiveSubId() { |
| 837 | for (int i = 0; i < mSelectedUnavailableNotify.size(); i++) { |
| 838 | int subId = mSelectedUnavailableNotify.keyAt(i); |
| 839 | if (!mSubscriptionManager.isActiveSubId(subId)) { |
| 840 | dismissNetworkSelectionNotification(subId); |
| 841 | clearUpNetworkSelectionNotificationParam(subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 842 | } |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | /* package */ void postTransientNotification(int notifyId, CharSequence msg) { |
| 847 | if (mToast != null) { |
| 848 | mToast.cancel(); |
| 849 | } |
| 850 | |
| 851 | mToast = Toast.makeText(mContext, msg, Toast.LENGTH_LONG); |
| 852 | mToast.show(); |
| 853 | } |
| 854 | |
| 855 | private void log(String msg) { |
| 856 | Log.d(LOG_TAG, msg); |
| 857 | } |
Tyler Gunn | a584e2c | 2017-09-19 11:40:12 -0700 | [diff] [blame] | 858 | |
| 859 | private void logi(String msg) { |
| 860 | Log.i(LOG_TAG, msg); |
| 861 | } |
irisykyang | 2520246 | 2018-11-13 14:49:54 +0800 | [diff] [blame] | 862 | |
| 863 | /** |
| 864 | * In case network selection notification shows up repeatedly under |
| 865 | * unstable network condition. The logic is to check whether or not |
| 866 | * the service state keeps in no service condition for at least |
| 867 | * {@link #NETWORK_SELECTION_NOTIFICATION_MAX_PENDING_TIME_IN_MS}. |
| 868 | * And checking {@link #NETWORK_SELECTION_NOTIFICATION_MAX_PENDING_TIMES} times. |
| 869 | * To avoid the notification showing up for the momentary state. |
| 870 | */ |
| 871 | private void shouldShowNotification(int serviceState, int subId) { |
| 872 | if (serviceState == ServiceState.STATE_OUT_OF_SERVICE) { |
| 873 | if (mPreviousServiceState.get(subId, STATE_UNKNOWN_SERVICE) |
| 874 | != ServiceState.STATE_OUT_OF_SERVICE) { |
| 875 | mOOSTimestamp.put(subId, getTimeStamp()); |
| 876 | } |
| 877 | if ((getTimeStamp() - mOOSTimestamp.get(subId, 0L) |
| 878 | >= NETWORK_SELECTION_NOTIFICATION_MAX_PENDING_TIME_IN_MS) |
| 879 | || mPendingEventCounter.get(subId, 0) |
| 880 | > NETWORK_SELECTION_NOTIFICATION_MAX_PENDING_TIMES) { |
| 881 | showNetworkSelection(mSelectedNetworkOperatorName.get(subId), subId); |
| 882 | clearUpNetworkSelectionNotificationParam(subId); |
| 883 | } else { |
| 884 | startPendingNetworkSelectionNotification(subId); |
| 885 | } |
| 886 | } else { |
| 887 | dismissNetworkSelectionNotification(subId); |
| 888 | } |
| 889 | mPreviousServiceState.put(subId, serviceState); |
| 890 | if (DBG) { |
| 891 | log("shouldShowNotification()..." + " subId = " + subId |
| 892 | + " serviceState = " + serviceState |
| 893 | + " mOOSTimestamp = " + mOOSTimestamp |
| 894 | + " mPendingEventCounter = " + mPendingEventCounter); |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | private void startPendingNetworkSelectionNotification(int subId) { |
| 899 | if (!mHandler.hasMessages(EVENT_PENDING_NETWORK_SELECTION_NOTIFICATION, subId)) { |
| 900 | if (DBG) { |
| 901 | log("startPendingNetworkSelectionNotification: subId = " + subId); |
| 902 | } |
| 903 | mHandler.sendMessageDelayed( |
| 904 | mHandler.obtainMessage(EVENT_PENDING_NETWORK_SELECTION_NOTIFICATION, subId), |
| 905 | NETWORK_SELECTION_NOTIFICATION_MAX_PENDING_TIME_IN_MS); |
| 906 | mPendingEventCounter.put(subId, mPendingEventCounter.get(subId, 0) + 1); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | private void clearUpNetworkSelectionNotificationParam(int subId) { |
| 911 | if (mHandler.hasMessages(EVENT_PENDING_NETWORK_SELECTION_NOTIFICATION, subId)) { |
| 912 | mHandler.removeMessages(EVENT_PENDING_NETWORK_SELECTION_NOTIFICATION, subId); |
| 913 | } |
| 914 | mPreviousServiceState.remove(subId); |
| 915 | mOOSTimestamp.remove(subId); |
| 916 | mPendingEventCounter.remove(subId); |
| 917 | mSelectedNetworkOperatorName.remove(subId); |
| 918 | } |
| 919 | |
| 920 | private static long getTimeStamp() { |
| 921 | return SystemClock.elapsedRealtime(); |
| 922 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 923 | } |