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