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