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