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 | |
Malcolm Chen | 39aa791 | 2017-06-05 19:02:16 -0700 | [diff] [blame] | 19 | import static android.Manifest.permission.READ_PHONE_STATE; |
| 20 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 21 | import android.app.Notification; |
| 22 | import android.app.NotificationManager; |
| 23 | import android.app.PendingIntent; |
| 24 | import android.app.StatusBarManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 25 | import android.content.ComponentName; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 26 | import android.content.Context; |
| 27 | import android.content.Intent; |
| 28 | import android.content.SharedPreferences; |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 29 | import android.content.pm.ResolveInfo; |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 30 | import android.content.pm.UserInfo; |
Nancy Chen | b4a9270 | 2014-12-04 15:57:29 -0800 | [diff] [blame] | 31 | import android.content.res.Resources; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.net.Uri; |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 33 | import android.os.PersistableBundle; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 34 | import android.os.SystemProperties; |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 35 | import android.os.UserHandle; |
| 36 | import android.os.UserManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.preference.PreferenceManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.provider.ContactsContract.PhoneLookup; |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 39 | import android.telecom.DefaultDialerManager; |
Tyler Gunn | 4d45d1c | 2014-09-12 22:17:53 -0700 | [diff] [blame] | 40 | import android.telecom.PhoneAccount; |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 41 | import android.telecom.PhoneAccountHandle; |
| 42 | import android.telecom.TelecomManager; |
Jonathan Basseri | 3649bdb | 2015-04-30 22:39:11 -0700 | [diff] [blame] | 43 | import android.telephony.CarrierConfigManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.telephony.PhoneNumberUtils; |
| 45 | import android.telephony.ServiceState; |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 46 | import android.telephony.SubscriptionInfo; |
Andrew Lee | a82b820 | 2014-11-21 16:18:28 -0800 | [diff] [blame] | 47 | import android.telephony.SubscriptionManager; |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 48 | import android.telephony.TelephonyManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.text.TextUtils; |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 50 | import android.util.ArrayMap; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.util.Log; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import android.widget.Toast; |
Ta-wei Yen | b29425b | 2016-09-21 17:28:14 -0700 | [diff] [blame] | 53 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import com.android.internal.telephony.Phone; |
Jayachandran C | 2ef9a48 | 2017-05-12 22:07:47 -0700 | [diff] [blame] | 55 | import com.android.internal.telephony.PhoneFactory; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import com.android.internal.telephony.TelephonyCapabilities; |
fionaxu | 8b7620d | 2017-05-01 16:22:17 -0700 | [diff] [blame] | 57 | import com.android.internal.telephony.util.NotificationChannelController; |
Andrew Lee | bf07f76 | 2015-04-07 19:05:50 -0700 | [diff] [blame] | 58 | import com.android.phone.settings.VoicemailSettingsActivity; |
Ta-wei Yen | b29425b | 2016-09-21 17:28:14 -0700 | [diff] [blame] | 59 | |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 60 | import java.util.Iterator; |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 61 | import java.util.List; |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 62 | import java.util.Set; |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 63 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | /** |
| 65 | * NotificationManager-related utility code for the Phone app. |
| 66 | * |
| 67 | * This is a singleton object which acts as the interface to the |
| 68 | * framework's NotificationManager, and is used to display status bar |
| 69 | * icons and control other status bar-related behavior. |
| 70 | * |
| 71 | * @see PhoneGlobals.notificationMgr |
| 72 | */ |
Chiao Cheng | 312b9c9 | 2013-09-16 15:40:53 -0700 | [diff] [blame] | 73 | public class NotificationMgr { |
Andrew Lee | a82b820 | 2014-11-21 16:18:28 -0800 | [diff] [blame] | 74 | private static final String LOG_TAG = NotificationMgr.class.getSimpleName(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | private static final boolean DBG = |
| 76 | (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1); |
| 77 | // Do not check in with VDBG = true, since that may write PII to the system log. |
| 78 | private static final boolean VDBG = false; |
| 79 | |
Ta-wei Yen | b29425b | 2016-09-21 17:28:14 -0700 | [diff] [blame] | 80 | private static final String MWI_SHOULD_CHECK_VVM_CONFIGURATION_KEY_PREFIX = |
| 81 | "mwi_should_check_vvm_configuration_state_"; |
| 82 | |
Ta-wei Yen | 282a970 | 2017-05-30 17:32:29 -0700 | [diff] [blame] | 83 | /** |
| 84 | * Boolean value representing whether the {@link |
| 85 | * TelephonyManager#ACTION_SHOW_VOICEMAIL_NOTIFICATION} is new or a refresh of an existing |
| 86 | * notification. |
| 87 | * |
| 88 | * TODO(b/62202833): make public |
| 89 | */ |
| 90 | private static final String EXTRA_IS_REFRESH = "is_refresh"; |
| 91 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 92 | // notification types |
Santos Cordon | f68db2e | 2014-07-02 14:40:44 -0700 | [diff] [blame] | 93 | static final int MMI_NOTIFICATION = 1; |
| 94 | static final int NETWORK_SELECTION_NOTIFICATION = 2; |
| 95 | static final int VOICEMAIL_NOTIFICATION = 3; |
| 96 | static final int CALL_FORWARD_NOTIFICATION = 4; |
| 97 | static final int DATA_DISCONNECTED_ROAMING_NOTIFICATION = 5; |
| 98 | static final int SELECTED_OPERATOR_FAIL_NOTIFICATION = 6; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 99 | |
| 100 | /** The singleton NotificationMgr instance. */ |
| 101 | private static NotificationMgr sInstance; |
| 102 | |
| 103 | private PhoneGlobals mApp; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 104 | |
| 105 | private Context mContext; |
| 106 | private NotificationManager mNotificationManager; |
| 107 | private StatusBarManager mStatusBarManager; |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 108 | private UserManager mUserManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 109 | private Toast mToast; |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 110 | private SubscriptionManager mSubscriptionManager; |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 111 | private TelecomManager mTelecomManager; |
| 112 | private TelephonyManager mTelephonyManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 113 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 114 | // used to track the notification of selected network unavailable |
| 115 | private boolean mSelectedUnavailableNotify = false; |
| 116 | |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 117 | // used to track whether the message waiting indicator is visible, per subscription id. |
| 118 | private ArrayMap<Integer, Boolean> mMwiVisible = new ArrayMap<Integer, Boolean>(); |
| 119 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 120 | /** |
| 121 | * Private constructor (this is a singleton). |
Santos Cordon | f68db2e | 2014-07-02 14:40:44 -0700 | [diff] [blame] | 122 | * @see #init(PhoneGlobals) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 123 | */ |
| 124 | private NotificationMgr(PhoneGlobals app) { |
| 125 | mApp = app; |
| 126 | mContext = app; |
| 127 | mNotificationManager = |
| 128 | (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE); |
| 129 | mStatusBarManager = |
| 130 | (StatusBarManager) app.getSystemService(Context.STATUS_BAR_SERVICE); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 131 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 132 | mSubscriptionManager = SubscriptionManager.from(mContext); |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 133 | mTelecomManager = TelecomManager.from(mContext); |
| 134 | mTelephonyManager = (TelephonyManager) app.getSystemService(Context.TELEPHONY_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Initialize the singleton NotificationMgr instance. |
| 139 | * |
| 140 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 141 | * From then on, the NotificationMgr instance is available via the |
| 142 | * PhoneApp's public "notificationMgr" field, which is why there's no |
| 143 | * getInstance() method here. |
| 144 | */ |
| 145 | /* package */ static NotificationMgr init(PhoneGlobals app) { |
| 146 | synchronized (NotificationMgr.class) { |
| 147 | if (sInstance == null) { |
| 148 | sInstance = new NotificationMgr(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 149 | } else { |
| 150 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 151 | } |
| 152 | return sInstance; |
| 153 | } |
| 154 | } |
| 155 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 156 | /** The projection to use when querying the phones table */ |
| 157 | static final String[] PHONES_PROJECTION = new String[] { |
| 158 | PhoneLookup.NUMBER, |
| 159 | PhoneLookup.DISPLAY_NAME, |
| 160 | PhoneLookup._ID |
| 161 | }; |
| 162 | |
| 163 | /** |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 164 | * Re-creates the message waiting indicator (voicemail) notification if it is showing. Used to |
| 165 | * refresh the voicemail intent on the indicator when the user changes it via the voicemail |
| 166 | * settings screen. The voicemail notification sound is suppressed. |
| 167 | * |
| 168 | * @param subId The subscription Id. |
| 169 | */ |
| 170 | /* package */ void refreshMwi(int subId) { |
| 171 | // In a single-sim device, subId can be -1 which means "no sub id". In this case we will |
| 172 | // reference the single subid stored in the mMwiVisible map. |
Ta-wei Yen | a1390d4 | 2017-12-04 15:11:33 -0800 | [diff] [blame^] | 173 | if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 174 | if (mMwiVisible.keySet().size() == 1) { |
| 175 | Set<Integer> keySet = mMwiVisible.keySet(); |
| 176 | Iterator<Integer> keyIt = keySet.iterator(); |
| 177 | if (!keyIt.hasNext()) { |
| 178 | return; |
| 179 | } |
| 180 | subId = keyIt.next(); |
| 181 | } |
| 182 | } |
| 183 | if (mMwiVisible.containsKey(subId)) { |
| 184 | boolean mwiVisible = mMwiVisible.get(subId); |
| 185 | if (mwiVisible) { |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 186 | mApp.notifier.updatePhoneStateListeners(true); |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
Ta-wei Yen | b29425b | 2016-09-21 17:28:14 -0700 | [diff] [blame] | 191 | public void setShouldCheckVisualVoicemailConfigurationForMwi(int subId, boolean enabled) { |
| 192 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 193 | Log.e(LOG_TAG, "setShouldCheckVisualVoicemailConfigurationForMwi: invalid subId" |
| 194 | + subId); |
| 195 | return; |
| 196 | } |
| 197 | |
| 198 | PreferenceManager.getDefaultSharedPreferences(mContext).edit() |
| 199 | .putBoolean(MWI_SHOULD_CHECK_VVM_CONFIGURATION_KEY_PREFIX + subId, enabled) |
| 200 | .apply(); |
| 201 | } |
| 202 | |
| 203 | private boolean shouldCheckVisualVoicemailConfigurationForMwi(int subId) { |
| 204 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 205 | Log.e(LOG_TAG, "shouldCheckVisualVoicemailConfigurationForMwi: invalid subId" + subId); |
| 206 | return true; |
| 207 | } |
| 208 | return PreferenceManager |
| 209 | .getDefaultSharedPreferences(mContext) |
| 210 | .getBoolean(MWI_SHOULD_CHECK_VVM_CONFIGURATION_KEY_PREFIX + subId, true); |
| 211 | } |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 212 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 213 | * Updates the message waiting indicator (voicemail) notification. |
| 214 | * |
| 215 | * @param visible true if there are messages waiting |
| 216 | */ |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 217 | /* package */ void updateMwi(int subId, boolean visible) { |
Ta-wei Yen | 282a970 | 2017-05-30 17:32:29 -0700 | [diff] [blame] | 218 | updateMwi(subId, visible, false /* isRefresh */); |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Updates the message waiting indicator (voicemail) notification. |
| 223 | * |
| 224 | * @param subId the subId to update. |
| 225 | * @param visible true if there are messages waiting |
Ta-wei Yen | 282a970 | 2017-05-30 17:32:29 -0700 | [diff] [blame] | 226 | * @param isRefresh {@code true} if the notification is a refresh and the user should not be |
| 227 | * notified again. |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 228 | */ |
Ta-wei Yen | 282a970 | 2017-05-30 17:32:29 -0700 | [diff] [blame] | 229 | void updateMwi(int subId, boolean visible, boolean isRefresh) { |
Andrew Lee | a82b820 | 2014-11-21 16:18:28 -0800 | [diff] [blame] | 230 | if (!PhoneGlobals.sVoiceCapable) { |
| 231 | // Do not show the message waiting indicator on devices which are not voice capable. |
| 232 | // These events *should* be blocked at the telephony layer for such devices. |
| 233 | Log.w(LOG_TAG, "Called updateMwi() on non-voice-capable device! Ignoring..."); |
| 234 | return; |
| 235 | } |
| 236 | |
Nancy Chen | 2cf7f29 | 2015-05-15 11:00:10 -0700 | [diff] [blame] | 237 | Phone phone = PhoneGlobals.getPhone(subId); |
Yorke Lee | 67a62a2 | 2014-12-15 18:46:17 -0800 | [diff] [blame] | 238 | Log.i(LOG_TAG, "updateMwi(): subId " + subId + " update to " + visible); |
Andrew Lee | f8ad78f | 2014-12-15 16:17:29 -0800 | [diff] [blame] | 239 | mMwiVisible.put(subId, visible); |
| 240 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 241 | if (visible) { |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 242 | if (phone == null) { |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 243 | Log.w(LOG_TAG, "Found null phone for: " + subId); |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | SubscriptionInfo subInfo = mSubscriptionManager.getActiveSubscriptionInfo(subId); |
| 248 | if (subInfo == null) { |
| 249 | Log.w(LOG_TAG, "Found null subscription info for: " + subId); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 250 | return; |
| 251 | } |
| 252 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 253 | int resId = android.R.drawable.stat_notify_voicemail; |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 254 | if (mTelephonyManager.getPhoneCount() > 1) { |
| 255 | resId = (phone.getPhoneId() == 0) ? R.drawable.stat_notify_voicemail_sub1 |
| 256 | : R.drawable.stat_notify_voicemail_sub2; |
| 257 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 258 | |
| 259 | // This Notification can get a lot fancier once we have more |
| 260 | // information about the current voicemail messages. |
| 261 | // (For example, the current voicemail system can't tell |
| 262 | // us the caller-id or timestamp of a message, or tell us the |
| 263 | // message count.) |
| 264 | |
| 265 | // But for now, the UI is ultra-simple: if the MWI indication |
| 266 | // is supposed to be visible, just show a single generic |
| 267 | // notification. |
| 268 | |
| 269 | String notificationTitle = mContext.getString(R.string.notification_voicemail_title); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 270 | String vmNumber = phone.getVoiceMailNumber(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 271 | if (DBG) log("- got vm number: '" + vmNumber + "'"); |
| 272 | |
Andrew Lee | a82b820 | 2014-11-21 16:18:28 -0800 | [diff] [blame] | 273 | // The voicemail number may be null because: |
| 274 | // (1) This phone has no voicemail number. |
| 275 | // (2) This phone has a voicemail number, but the SIM isn't ready yet. This may |
| 276 | // happen when the device first boots if we get a MWI notification when we |
| 277 | // 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] | 278 | // SubscriptionListener in CallNotifier will update this once the SIM is loaded. |
| 279 | if ((vmNumber == null) && !phone.getIccRecordsLoaded()) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 280 | if (DBG) log("- Null vm number: SIM records not loaded (yet)..."); |
Andrew Lee | a82b820 | 2014-11-21 16:18:28 -0800 | [diff] [blame] | 281 | return; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 284 | Integer vmCount = null; |
| 285 | |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 286 | if (TelephonyCapabilities.supportsVoiceMessageCount(phone)) { |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 287 | vmCount = phone.getVoiceMessageCount(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 288 | String titleFormat = mContext.getString(R.string.notification_voicemail_title_count); |
| 289 | notificationTitle = String.format(titleFormat, vmCount); |
| 290 | } |
| 291 | |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 292 | // This pathway only applies to PSTN accounts; only SIMS have subscription ids. |
| 293 | PhoneAccountHandle phoneAccountHandle = PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 294 | |
| 295 | Intent intent; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 296 | String notificationText; |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 297 | boolean isSettingsIntent = TextUtils.isEmpty(vmNumber); |
| 298 | |
| 299 | if (isSettingsIntent) { |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 300 | notificationText = mContext.getString( |
| 301 | R.string.notification_voicemail_no_vm_number); |
| 302 | |
| 303 | // If the voicemail number if unknown, instead of calling voicemail, take the user |
| 304 | // to the voicemail settings. |
| 305 | notificationText = mContext.getString( |
| 306 | R.string.notification_voicemail_no_vm_number); |
Andrew Lee | bf07f76 | 2015-04-07 19:05:50 -0700 | [diff] [blame] | 307 | intent = new Intent(VoicemailSettingsActivity.ACTION_ADD_VOICEMAIL); |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 308 | intent.putExtra(SubscriptionInfoHelper.SUB_ID_EXTRA, subId); |
Andrew Lee | bf07f76 | 2015-04-07 19:05:50 -0700 | [diff] [blame] | 309 | intent.setClass(mContext, VoicemailSettingsActivity.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 310 | } else { |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 311 | if (mTelephonyManager.getPhoneCount() > 1) { |
| 312 | notificationText = subInfo.getDisplayName().toString(); |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 313 | } else { |
| 314 | notificationText = String.format( |
| 315 | mContext.getString(R.string.notification_voicemail_text_format), |
| 316 | PhoneNumberUtils.formatNumber(vmNumber)); |
| 317 | } |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 318 | intent = new Intent( |
| 319 | Intent.ACTION_CALL, Uri.fromParts(PhoneAccount.SCHEME_VOICEMAIL, "", |
Jonathan Basseri | 3649bdb | 2015-04-30 22:39:11 -0700 | [diff] [blame] | 320 | null)); |
Tyler Gunn | 9c1071f | 2014-12-09 10:07:54 -0800 | [diff] [blame] | 321 | intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 324 | PendingIntent pendingIntent = |
| 325 | PendingIntent.getActivity(mContext, subId /* requestCode */, intent, 0); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 326 | |
Nancy Chen | b4a9270 | 2014-12-04 15:57:29 -0800 | [diff] [blame] | 327 | Resources res = mContext.getResources(); |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 328 | PersistableBundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId( |
Ta-wei Yen | 9b37a87 | 2016-05-27 12:16:58 -0700 | [diff] [blame] | 329 | subId); |
fionaxu | 8b7620d | 2017-05-01 16:22:17 -0700 | [diff] [blame] | 330 | Notification.Builder builder = new Notification.Builder(mContext); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 331 | builder.setSmallIcon(resId) |
| 332 | .setWhen(System.currentTimeMillis()) |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 333 | .setColor(subInfo.getIconTint()) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 334 | .setContentTitle(notificationTitle) |
| 335 | .setContentText(notificationText) |
| 336 | .setContentIntent(pendingIntent) |
Nancy Chen | b4a9270 | 2014-12-04 15:57:29 -0800 | [diff] [blame] | 337 | .setColor(res.getColor(R.color.dialer_theme_color)) |
Jonathan Basseri | 3649bdb | 2015-04-30 22:39:11 -0700 | [diff] [blame] | 338 | .setOngoing(carrierConfig.getBoolean( |
fionaxu | 75b66a7 | 2017-04-19 19:01:56 -0700 | [diff] [blame] | 339 | CarrierConfigManager.KEY_VOICEMAIL_NOTIFICATION_PERSISTENT_BOOL)) |
Ta-wei Yen | 282a970 | 2017-05-30 17:32:29 -0700 | [diff] [blame] | 340 | .setChannel(NotificationChannelController.CHANNEL_ID_VOICE_MAIL) |
| 341 | .setOnlyAlertOnce(isRefresh); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 342 | |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 343 | final Notification notification = builder.build(); |
| 344 | List<UserInfo> users = mUserManager.getUsers(true); |
| 345 | for (int i = 0; i < users.size(); i++) { |
Yorke Lee | 047b1f9 | 2014-10-24 10:22:41 -0700 | [diff] [blame] | 346 | final UserInfo user = users.get(i); |
| 347 | final UserHandle userHandle = user.getUserHandle(); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 348 | if (!mUserManager.hasUserRestriction( |
Yorke Lee | 047b1f9 | 2014-10-24 10:22:41 -0700 | [diff] [blame] | 349 | UserManager.DISALLOW_OUTGOING_CALLS, userHandle) |
Jonathan Basseri | 3649bdb | 2015-04-30 22:39:11 -0700 | [diff] [blame] | 350 | && !user.isManagedProfile()) { |
Ta-wei Yen | a71a38b | 2017-02-24 18:19:27 -0800 | [diff] [blame] | 351 | if (!maybeSendVoicemailNotificationUsingDefaultDialer(phone, vmCount, vmNumber, |
Ta-wei Yen | 282a970 | 2017-05-30 17:32:29 -0700 | [diff] [blame] | 352 | pendingIntent, isSettingsIntent, userHandle, isRefresh)) { |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 353 | mNotificationManager.notifyAsUser( |
| 354 | Integer.toString(subId) /* tag */, |
| 355 | VOICEMAIL_NOTIFICATION, |
| 356 | notification, |
| 357 | userHandle); |
| 358 | } |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 359 | } |
| 360 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 361 | } else { |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 362 | List<UserInfo> users = mUserManager.getUsers(true /* excludeDying */); |
| 363 | for (int i = 0; i < users.size(); i++) { |
| 364 | final UserInfo user = users.get(i); |
| 365 | final UserHandle userHandle = user.getUserHandle(); |
| 366 | if (!mUserManager.hasUserRestriction( |
| 367 | UserManager.DISALLOW_OUTGOING_CALLS, userHandle) |
| 368 | && !user.isManagedProfile()) { |
Ta-wei Yen | a71a38b | 2017-02-24 18:19:27 -0800 | [diff] [blame] | 369 | if (!maybeSendVoicemailNotificationUsingDefaultDialer(phone, 0, null, null, |
Ta-wei Yen | 282a970 | 2017-05-30 17:32:29 -0700 | [diff] [blame] | 370 | false, userHandle, isRefresh)) { |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 371 | mNotificationManager.cancelAsUser( |
| 372 | Integer.toString(subId) /* tag */, |
| 373 | VOICEMAIL_NOTIFICATION, |
| 374 | userHandle); |
| 375 | } |
| 376 | } |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 377 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | |
| 381 | /** |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 382 | * Sends a broadcast with the voicemail notification information to the default dialer. This |
| 383 | * method is also used to indicate to the default dialer when to clear the |
| 384 | * 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] | 385 | * 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] | 386 | * @param phone The phone the notification is sent from |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 387 | * @param count The number of pending voicemail messages to indicate on the notification. A |
| 388 | * Value of 0 is passed here to indicate that the notification should be cleared. |
| 389 | * @param number The voicemail phone number if specified. |
| 390 | * @param pendingIntent The intent that should be passed as the action to be taken. |
| 391 | * @param isSettingsIntent {@code true} to indicate the pending intent is to launch settings. |
| 392 | * otherwise, {@code false} to indicate the intent launches voicemail. |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 393 | * @param userHandle The user to receive the notification. Each user can have their own default |
| 394 | * dialer. |
| 395 | * @return {@code true} if the default was notified of the notification. |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 396 | */ |
Ta-wei Yen | a71a38b | 2017-02-24 18:19:27 -0800 | [diff] [blame] | 397 | private boolean maybeSendVoicemailNotificationUsingDefaultDialer(Phone phone, Integer count, |
| 398 | String number, PendingIntent pendingIntent, boolean isSettingsIntent, |
Ta-wei Yen | 282a970 | 2017-05-30 17:32:29 -0700 | [diff] [blame] | 399 | UserHandle userHandle, boolean isRefresh) { |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 400 | |
| 401 | if (shouldManageNotificationThroughDefaultDialer(userHandle)) { |
| 402 | Intent intent = getShowVoicemailIntentForDefaultDialer(userHandle); |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 403 | intent.setFlags(Intent.FLAG_RECEIVER_FOREGROUND); |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 404 | intent.setAction(TelephonyManager.ACTION_SHOW_VOICEMAIL_NOTIFICATION); |
Ta-wei Yen | a71a38b | 2017-02-24 18:19:27 -0800 | [diff] [blame] | 405 | intent.putExtra(TelephonyManager.EXTRA_PHONE_ACCOUNT_HANDLE, |
| 406 | PhoneUtils.makePstnPhoneAccountHandle(phone)); |
Ta-wei Yen | 282a970 | 2017-05-30 17:32:29 -0700 | [diff] [blame] | 407 | intent.putExtra(EXTRA_IS_REFRESH, isRefresh); |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 408 | if (count != null) { |
| 409 | intent.putExtra(TelephonyManager.EXTRA_NOTIFICATION_COUNT, count); |
| 410 | } |
| 411 | |
| 412 | // Additional information about the voicemail notification beyond the count is only |
| 413 | // present when the count not specified or greater than 0. The value of 0 represents |
| 414 | // clearing the notification, which does not require additional information. |
| 415 | if (count == null || count > 0) { |
| 416 | if (!TextUtils.isEmpty(number)) { |
| 417 | intent.putExtra(TelephonyManager.EXTRA_VOICEMAIL_NUMBER, number); |
| 418 | } |
| 419 | |
| 420 | if (pendingIntent != null) { |
| 421 | intent.putExtra(isSettingsIntent |
| 422 | ? TelephonyManager.EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT |
| 423 | : TelephonyManager.EXTRA_CALL_VOICEMAIL_INTENT, |
| 424 | pendingIntent); |
| 425 | } |
| 426 | } |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 427 | mContext.sendBroadcastAsUser(intent, userHandle, READ_PHONE_STATE); |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 428 | return true; |
| 429 | } |
| 430 | |
| 431 | return false; |
| 432 | } |
| 433 | |
Ta-wei Yen | 5bb1956 | 2016-11-16 11:05:37 -0800 | [diff] [blame] | 434 | private Intent getShowVoicemailIntentForDefaultDialer(UserHandle userHandle) { |
| 435 | String dialerPackage = DefaultDialerManager |
| 436 | .getDefaultDialerApplication(mContext, userHandle.getIdentifier()); |
| 437 | return new Intent(TelephonyManager.ACTION_SHOW_VOICEMAIL_NOTIFICATION) |
| 438 | .setPackage(dialerPackage); |
| 439 | } |
| 440 | |
| 441 | private boolean shouldManageNotificationThroughDefaultDialer(UserHandle userHandle) { |
| 442 | Intent intent = getShowVoicemailIntentForDefaultDialer(userHandle); |
| 443 | if (intent == null) { |
| 444 | return false; |
| 445 | } |
| 446 | |
| 447 | List<ResolveInfo> receivers = mContext.getPackageManager() |
| 448 | .queryBroadcastReceivers(intent, 0); |
| 449 | return receivers.size() > 0; |
| 450 | } |
| 451 | |
Bryce Lee | 5dc9084 | 2015-08-11 07:57:14 -0700 | [diff] [blame] | 452 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 453 | * Updates the message call forwarding indicator notification. |
| 454 | * |
Srikanth Chintala | 4baf0b9 | 2017-11-14 15:52:47 +0530 | [diff] [blame] | 455 | * @param visible true if call forwarding enabled |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 456 | */ |
Srikanth Chintala | 4baf0b9 | 2017-11-14 15:52:47 +0530 | [diff] [blame] | 457 | |
| 458 | /* package */ void updateCfi(int subId, boolean visible) { |
| 459 | updateCfi(subId, visible, false /* isRefresh */); |
| 460 | } |
| 461 | |
| 462 | /** |
| 463 | * Updates the message call forwarding indicator notification. |
| 464 | * |
| 465 | * @param visible true if call forwarding enabled |
| 466 | */ |
| 467 | /* package */ void updateCfi(int subId, boolean visible, boolean isRefresh) { |
Tyler Gunn | 17bffd0 | 2017-09-19 11:40:12 -0700 | [diff] [blame] | 468 | logi("updateCfi: subId= " + subId + ", visible=" + (visible ? "Y" : "N")); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 469 | if (visible) { |
| 470 | // If Unconditional Call Forwarding (forward all calls) for VOICE |
| 471 | // is enabled, just show a notification. We'll default to expanded |
| 472 | // view for now, so the there is less confusion about the icon. If |
| 473 | // it is deemed too weird to have CF indications as expanded views, |
| 474 | // then we'll flip the flag back. |
| 475 | |
| 476 | // TODO: We may want to take a look to see if the notification can |
| 477 | // display the target to forward calls to. This will require some |
| 478 | // effort though, since there are multiple layers of messages that |
| 479 | // will need to propagate that information. |
| 480 | |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 481 | SubscriptionInfo subInfo = mSubscriptionManager.getActiveSubscriptionInfo(subId); |
| 482 | if (subInfo == null) { |
| 483 | Log.w(LOG_TAG, "Found null subscription info for: " + subId); |
| 484 | return; |
| 485 | } |
| 486 | |
| 487 | String notificationTitle; |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 488 | int resId = R.drawable.stat_sys_phone_call_forward; |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 489 | if (mTelephonyManager.getPhoneCount() > 1) { |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 490 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 491 | resId = (slotId == 0) ? R.drawable.stat_sys_phone_call_forward_sub1 |
| 492 | : R.drawable.stat_sys_phone_call_forward_sub2; |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 493 | notificationTitle = subInfo.getDisplayName().toString(); |
| 494 | } else { |
| 495 | notificationTitle = mContext.getString(R.string.labelCF); |
| 496 | } |
| 497 | |
fionaxu | 8b7620d | 2017-05-01 16:22:17 -0700 | [diff] [blame] | 498 | Notification.Builder builder = new Notification.Builder(mContext) |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 499 | .setSmallIcon(resId) |
Andrew Lee | d5165b0 | 2014-12-05 15:53:58 -0800 | [diff] [blame] | 500 | .setColor(subInfo.getIconTint()) |
| 501 | .setContentTitle(notificationTitle) |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 502 | .setContentText(mContext.getString(R.string.sum_cfu_enabled_indicator)) |
| 503 | .setShowWhen(false) |
fionaxu | 75b66a7 | 2017-04-19 19:01:56 -0700 | [diff] [blame] | 504 | .setOngoing(true) |
Srikanth Chintala | 4baf0b9 | 2017-11-14 15:52:47 +0530 | [diff] [blame] | 505 | .setChannel(NotificationChannelController.CHANNEL_ID_CALL_FORWARD) |
| 506 | .setOnlyAlertOnce(isRefresh); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 507 | |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 508 | Intent intent = new Intent(Intent.ACTION_MAIN); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 509 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 510 | intent.setClassName("com.android.phone", "com.android.phone.CallFeaturesSetting"); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 511 | SubscriptionInfoHelper.addExtrasToIntent( |
| 512 | intent, mSubscriptionManager.getActiveSubscriptionInfo(subId)); |
| 513 | PendingIntent contentIntent = |
| 514 | PendingIntent.getActivity(mContext, subId /* requestCode */, intent, 0); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 515 | |
| 516 | List<UserInfo> users = mUserManager.getUsers(true); |
| 517 | for (int i = 0; i < users.size(); i++) { |
Yorke Lee | 3faa594 | 2014-11-05 16:50:04 -0800 | [diff] [blame] | 518 | final UserInfo user = users.get(i); |
| 519 | if (user.isManagedProfile()) { |
| 520 | continue; |
| 521 | } |
| 522 | UserHandle userHandle = user.getUserHandle(); |
Xiaohui Chen | 3105e9a | 2015-10-21 12:27:17 -0700 | [diff] [blame] | 523 | builder.setContentIntent(user.isAdmin() ? contentIntent : null); |
Andrew Lee | 2fcb6c3 | 2014-12-04 14:52:35 -0800 | [diff] [blame] | 524 | mNotificationManager.notifyAsUser( |
| 525 | Integer.toString(subId) /* tag */, |
| 526 | CALL_FORWARD_NOTIFICATION, |
| 527 | builder.build(), |
| 528 | userHandle); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 529 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 530 | } else { |
Kazuya Ohshiro | 263737d | 2017-10-06 19:42:03 +0900 | [diff] [blame] | 531 | List<UserInfo> users = mUserManager.getUsers(true); |
| 532 | for (UserInfo user : users) { |
| 533 | if (user.isManagedProfile()) { |
| 534 | continue; |
| 535 | } |
| 536 | UserHandle userHandle = user.getUserHandle(); |
| 537 | mNotificationManager.cancelAsUser( |
| 538 | Integer.toString(subId) /* tag */, |
| 539 | CALL_FORWARD_NOTIFICATION, |
| 540 | userHandle); |
| 541 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | |
| 545 | /** |
| 546 | * Shows the "data disconnected due to roaming" notification, which |
| 547 | * appears when you lose data connectivity because you're roaming and |
| 548 | * you have the "data roaming" feature turned off. |
| 549 | */ |
Sanket Padawe | 336ef36 | 2017-07-12 12:12:37 -0700 | [diff] [blame] | 550 | void showDataDisconnectedRoaming() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 551 | if (DBG) log("showDataDisconnectedRoaming()..."); |
| 552 | |
| 553 | // "Mobile network settings" screen / dialog |
| 554 | Intent intent = new Intent(mContext, com.android.phone.MobileNetworkSettings.class); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 555 | PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 556 | |
| 557 | final CharSequence contentText = mContext.getText(R.string.roaming_reenable_message); |
| 558 | |
fionaxu | 8b7620d | 2017-05-01 16:22:17 -0700 | [diff] [blame] | 559 | final Notification.Builder builder = new Notification.Builder(mContext) |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 560 | .setSmallIcon(android.R.drawable.stat_sys_warning) |
| 561 | .setContentTitle(mContext.getText(R.string.roaming)) |
| 562 | .setColor(mContext.getResources().getColor(R.color.dialer_theme_color)) |
fionaxu | 75b66a7 | 2017-04-19 19:01:56 -0700 | [diff] [blame] | 563 | .setContentText(contentText) |
fionaxu | 8b7620d | 2017-05-01 16:22:17 -0700 | [diff] [blame] | 564 | .setChannel(NotificationChannelController.CHANNEL_ID_MOBILE_DATA_ALERT); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 565 | |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 566 | List<UserInfo> users = mUserManager.getUsers(true); |
| 567 | for (int i = 0; i < users.size(); i++) { |
Yorke Lee | 3faa594 | 2014-11-05 16:50:04 -0800 | [diff] [blame] | 568 | final UserInfo user = users.get(i); |
| 569 | if (user.isManagedProfile()) { |
| 570 | continue; |
| 571 | } |
| 572 | UserHandle userHandle = user.getUserHandle(); |
Xiaohui Chen | 3105e9a | 2015-10-21 12:27:17 -0700 | [diff] [blame] | 573 | builder.setContentIntent(user.isAdmin() ? contentIntent : null); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 574 | final Notification notif = |
| 575 | new Notification.BigTextStyle(builder).bigText(contentText).build(); |
| 576 | mNotificationManager.notifyAsUser( |
| 577 | null /* tag */, DATA_DISCONNECTED_ROAMING_NOTIFICATION, notif, userHandle); |
| 578 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | /** |
| 582 | * Turns off the "data disconnected due to roaming" notification. |
| 583 | */ |
| 584 | /* package */ void hideDataDisconnectedRoaming() { |
| 585 | if (DBG) log("hideDataDisconnectedRoaming()..."); |
| 586 | mNotificationManager.cancel(DATA_DISCONNECTED_ROAMING_NOTIFICATION); |
| 587 | } |
| 588 | |
| 589 | /** |
| 590 | * Display the network selection "no service" notification |
| 591 | * @param operator is the numeric operator number |
Jayachandran C | 2ef9a48 | 2017-05-12 22:07:47 -0700 | [diff] [blame] | 592 | * @param subId is the subscription ID |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 593 | */ |
Jayachandran C | 2ef9a48 | 2017-05-12 22:07:47 -0700 | [diff] [blame] | 594 | private void showNetworkSelection(String operator, int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 595 | if (DBG) log("showNetworkSelection(" + operator + ")..."); |
| 596 | |
fionaxu | 8b7620d | 2017-05-01 16:22:17 -0700 | [diff] [blame] | 597 | Notification.Builder builder = new Notification.Builder(mContext) |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 598 | .setSmallIcon(android.R.drawable.stat_sys_warning) |
| 599 | .setContentTitle(mContext.getString(R.string.notification_network_selection_title)) |
| 600 | .setContentText( |
| 601 | mContext.getString(R.string.notification_network_selection_text, operator)) |
| 602 | .setShowWhen(false) |
fionaxu | 75b66a7 | 2017-04-19 19:01:56 -0700 | [diff] [blame] | 603 | .setOngoing(true) |
fionaxu | 8b7620d | 2017-05-01 16:22:17 -0700 | [diff] [blame] | 604 | .setChannel(NotificationChannelController.CHANNEL_ID_ALERT); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 605 | |
| 606 | // create the target network operators settings intent |
| 607 | Intent intent = new Intent(Intent.ACTION_MAIN); |
| 608 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 609 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Malcolm Chen | 39aa791 | 2017-06-05 19:02:16 -0700 | [diff] [blame] | 610 | // Use MobileNetworkSettings to handle the selection intent |
Wei Liu | be96458 | 2015-08-21 11:57:00 -0700 | [diff] [blame] | 611 | intent.setComponent(new ComponentName( |
Malcolm Chen | 39aa791 | 2017-06-05 19:02:16 -0700 | [diff] [blame] | 612 | mContext.getString(R.string.mobile_network_settings_package), |
| 613 | mContext.getString(R.string.mobile_network_settings_class))); |
Jayachandran C | 2ef9a48 | 2017-05-12 22:07:47 -0700 | [diff] [blame] | 614 | intent.putExtra(GsmUmtsOptions.EXTRA_SUB_ID, subId); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 615 | PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 616 | |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 617 | List<UserInfo> users = mUserManager.getUsers(true); |
| 618 | for (int i = 0; i < users.size(); i++) { |
Yorke Lee | 3faa594 | 2014-11-05 16:50:04 -0800 | [diff] [blame] | 619 | final UserInfo user = users.get(i); |
| 620 | if (user.isManagedProfile()) { |
| 621 | continue; |
| 622 | } |
| 623 | UserHandle userHandle = user.getUserHandle(); |
Xiaohui Chen | 3105e9a | 2015-10-21 12:27:17 -0700 | [diff] [blame] | 624 | builder.setContentIntent(user.isAdmin() ? contentIntent : null); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 625 | mNotificationManager.notifyAsUser( |
| 626 | null /* tag */, |
| 627 | SELECTED_OPERATOR_FAIL_NOTIFICATION, |
| 628 | builder.build(), |
| 629 | userHandle); |
| 630 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Turn off the network selection "no service" notification |
| 635 | */ |
| 636 | private void cancelNetworkSelection() { |
| 637 | if (DBG) log("cancelNetworkSelection()..."); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 638 | mNotificationManager.cancelAsUser( |
| 639 | null /* tag */, SELECTED_OPERATOR_FAIL_NOTIFICATION, UserHandle.ALL); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | /** |
| 643 | * Update notification about no service of user selected operator |
| 644 | * |
| 645 | * @param serviceState Phone service state |
Jayachandran C | 2ef9a48 | 2017-05-12 22:07:47 -0700 | [diff] [blame] | 646 | * @param subId The subscription ID |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 647 | */ |
Jayachandran C | 2ef9a48 | 2017-05-12 22:07:47 -0700 | [diff] [blame] | 648 | void updateNetworkSelection(int serviceState, int subId) { |
| 649 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 650 | Phone phone = SubscriptionManager.isValidPhoneId(phoneId) ? |
| 651 | PhoneFactory.getPhone(phoneId) : PhoneFactory.getDefaultPhone(); |
| 652 | if (TelephonyCapabilities.supportsNetworkSelection(phone)) { |
Amit Mahajan | a60be87 | 2015-01-15 16:05:08 -0800 | [diff] [blame] | 653 | if (SubscriptionManager.isValidSubscriptionId(subId)) { |
| 654 | // get the shared preference of network_selection. |
| 655 | // empty is auto mode, otherwise it is the operator alpha name |
| 656 | // in case there is no operator name, check the operator numeric |
| 657 | SharedPreferences sp = |
| 658 | PreferenceManager.getDefaultSharedPreferences(mContext); |
| 659 | String networkSelection = |
Amit Mahajan | c5201f4 | 2015-11-24 15:38:12 -0800 | [diff] [blame] | 660 | sp.getString(Phone.NETWORK_SELECTION_NAME_KEY + subId, ""); |
Amit Mahajan | a60be87 | 2015-01-15 16:05:08 -0800 | [diff] [blame] | 661 | if (TextUtils.isEmpty(networkSelection)) { |
| 662 | networkSelection = |
Amit Mahajan | c5201f4 | 2015-11-24 15:38:12 -0800 | [diff] [blame] | 663 | sp.getString(Phone.NETWORK_SELECTION_KEY + subId, ""); |
Amit Mahajan | a60be87 | 2015-01-15 16:05:08 -0800 | [diff] [blame] | 664 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 665 | |
Amit Mahajan | a60be87 | 2015-01-15 16:05:08 -0800 | [diff] [blame] | 666 | if (DBG) log("updateNetworkSelection()..." + "state = " + |
| 667 | serviceState + " new network " + networkSelection); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 668 | |
Amit Mahajan | a60be87 | 2015-01-15 16:05:08 -0800 | [diff] [blame] | 669 | if (serviceState == ServiceState.STATE_OUT_OF_SERVICE |
| 670 | && !TextUtils.isEmpty(networkSelection)) { |
Jayachandran C | 2ef9a48 | 2017-05-12 22:07:47 -0700 | [diff] [blame] | 671 | showNetworkSelection(networkSelection, subId); |
Hall Liu | 2b846c7 | 2016-02-09 18:21:24 -0800 | [diff] [blame] | 672 | mSelectedUnavailableNotify = true; |
Amit Mahajan | a60be87 | 2015-01-15 16:05:08 -0800 | [diff] [blame] | 673 | } else { |
| 674 | if (mSelectedUnavailableNotify) { |
| 675 | cancelNetworkSelection(); |
| 676 | mSelectedUnavailableNotify = false; |
| 677 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 678 | } |
| 679 | } else { |
Amit Mahajan | a60be87 | 2015-01-15 16:05:08 -0800 | [diff] [blame] | 680 | if (DBG) log("updateNetworkSelection()..." + "state = " + |
| 681 | serviceState + " not updating network due to invalid subId " + subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | /* package */ void postTransientNotification(int notifyId, CharSequence msg) { |
| 687 | if (mToast != null) { |
| 688 | mToast.cancel(); |
| 689 | } |
| 690 | |
| 691 | mToast = Toast.makeText(mContext, msg, Toast.LENGTH_LONG); |
| 692 | mToast.show(); |
| 693 | } |
| 694 | |
| 695 | private void log(String msg) { |
| 696 | Log.d(LOG_TAG, msg); |
| 697 | } |
Tyler Gunn | 17bffd0 | 2017-09-19 11:40:12 -0700 | [diff] [blame] | 698 | |
| 699 | private void logi(String msg) { |
| 700 | Log.i(LOG_TAG, msg); |
| 701 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 702 | } |