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