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