Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
| 19 | import android.app.Notification; |
| 20 | import android.app.NotificationManager; |
| 21 | import android.app.PendingIntent; |
| 22 | import android.app.StatusBarManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 23 | import android.content.ComponentName; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 24 | import android.content.Context; |
| 25 | import android.content.Intent; |
| 26 | import android.content.SharedPreferences; |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 27 | import android.content.pm.UserInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 28 | import android.net.Uri; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 29 | import android.os.SystemProperties; |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 30 | import android.os.UserHandle; |
| 31 | import android.os.UserManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.preference.PreferenceManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 33 | import android.provider.ContactsContract.PhoneLookup; |
| 34 | import android.provider.Settings; |
Tyler Gunn | 4d45d1c | 2014-09-12 22:17:53 -0700 | [diff] [blame] | 35 | import android.telecom.PhoneAccount; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 36 | import android.telephony.PhoneNumberUtils; |
| 37 | import android.telephony.ServiceState; |
| 38 | import android.text.TextUtils; |
| 39 | import android.util.Log; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 40 | import android.widget.Toast; |
| 41 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import com.android.internal.telephony.Phone; |
| 43 | import com.android.internal.telephony.PhoneBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import com.android.internal.telephony.TelephonyCapabilities; |
| 45 | |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 46 | import java.util.List; |
| 47 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | /** |
| 49 | * NotificationManager-related utility code for the Phone app. |
| 50 | * |
| 51 | * This is a singleton object which acts as the interface to the |
| 52 | * framework's NotificationManager, and is used to display status bar |
| 53 | * icons and control other status bar-related behavior. |
| 54 | * |
| 55 | * @see PhoneGlobals.notificationMgr |
| 56 | */ |
Chiao Cheng | 312b9c9 | 2013-09-16 15:40:53 -0700 | [diff] [blame] | 57 | public class NotificationMgr { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | private static final String LOG_TAG = "NotificationMgr"; |
| 59 | private static final boolean DBG = |
| 60 | (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1); |
| 61 | // Do not check in with VDBG = true, since that may write PII to the system log. |
| 62 | private static final boolean VDBG = false; |
| 63 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | // notification types |
Santos Cordon | f68db2e | 2014-07-02 14:40:44 -0700 | [diff] [blame] | 65 | static final int MMI_NOTIFICATION = 1; |
| 66 | static final int NETWORK_SELECTION_NOTIFICATION = 2; |
| 67 | static final int VOICEMAIL_NOTIFICATION = 3; |
| 68 | static final int CALL_FORWARD_NOTIFICATION = 4; |
| 69 | static final int DATA_DISCONNECTED_ROAMING_NOTIFICATION = 5; |
| 70 | static final int SELECTED_OPERATOR_FAIL_NOTIFICATION = 6; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 71 | |
| 72 | /** The singleton NotificationMgr instance. */ |
| 73 | private static NotificationMgr sInstance; |
| 74 | |
| 75 | private PhoneGlobals mApp; |
| 76 | private Phone mPhone; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 77 | |
| 78 | private Context mContext; |
| 79 | private NotificationManager mNotificationManager; |
| 80 | private StatusBarManager mStatusBarManager; |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 81 | private UserManager mUserManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 82 | private Toast mToast; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 83 | |
| 84 | public StatusBarHelper statusBarHelper; |
| 85 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 86 | // used to track the notification of selected network unavailable |
| 87 | private boolean mSelectedUnavailableNotify = false; |
| 88 | |
| 89 | // Retry params for the getVoiceMailNumber() call; see updateMwi(). |
| 90 | private static final int MAX_VM_NUMBER_RETRIES = 5; |
| 91 | private static final int VM_NUMBER_RETRY_DELAY_MILLIS = 10000; |
| 92 | private int mVmNumberRetriesRemaining = MAX_VM_NUMBER_RETRIES; |
| 93 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 94 | /** |
| 95 | * Private constructor (this is a singleton). |
Santos Cordon | f68db2e | 2014-07-02 14:40:44 -0700 | [diff] [blame] | 96 | * @see #init(PhoneGlobals) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 97 | */ |
| 98 | private NotificationMgr(PhoneGlobals app) { |
| 99 | mApp = app; |
| 100 | mContext = app; |
| 101 | mNotificationManager = |
| 102 | (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE); |
| 103 | mStatusBarManager = |
| 104 | (StatusBarManager) app.getSystemService(Context.STATUS_BAR_SERVICE); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 105 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 106 | mPhone = app.phone; // TODO: better style to use mCM.getDefaultPhone() everywhere instead |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 107 | statusBarHelper = new StatusBarHelper(); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Initialize the singleton NotificationMgr instance. |
| 112 | * |
| 113 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 114 | * From then on, the NotificationMgr instance is available via the |
| 115 | * PhoneApp's public "notificationMgr" field, which is why there's no |
| 116 | * getInstance() method here. |
| 117 | */ |
| 118 | /* package */ static NotificationMgr init(PhoneGlobals app) { |
| 119 | synchronized (NotificationMgr.class) { |
| 120 | if (sInstance == null) { |
| 121 | sInstance = new NotificationMgr(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 122 | } else { |
| 123 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 124 | } |
| 125 | return sInstance; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Helper class that's a wrapper around the framework's |
| 131 | * StatusBarManager.disable() API. |
| 132 | * |
| 133 | * This class is used to control features like: |
| 134 | * |
| 135 | * - Disabling the status bar "notification windowshade" |
| 136 | * while the in-call UI is up |
| 137 | * |
| 138 | * - Disabling notification alerts (audible or vibrating) |
| 139 | * while a phone call is active |
| 140 | * |
| 141 | * - Disabling navigation via the system bar (the "soft buttons" at |
| 142 | * the bottom of the screen on devices with no hard buttons) |
| 143 | * |
| 144 | * We control these features through a single point of control to make |
| 145 | * sure that the various StatusBarManager.disable() calls don't |
| 146 | * interfere with each other. |
| 147 | */ |
| 148 | public class StatusBarHelper { |
| 149 | // Current desired state of status bar / system bar behavior |
| 150 | private boolean mIsNotificationEnabled = true; |
| 151 | private boolean mIsExpandedViewEnabled = true; |
| 152 | private boolean mIsSystemBarNavigationEnabled = true; |
| 153 | |
| 154 | private StatusBarHelper () { |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Enables or disables auditory / vibrational alerts. |
| 159 | * |
| 160 | * (We disable these any time a voice call is active, regardless |
| 161 | * of whether or not the in-call UI is visible.) |
| 162 | */ |
| 163 | public void enableNotificationAlerts(boolean enable) { |
| 164 | if (mIsNotificationEnabled != enable) { |
| 165 | mIsNotificationEnabled = enable; |
| 166 | updateStatusBar(); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Enables or disables the expanded view of the status bar |
| 172 | * (i.e. the ability to pull down the "notification windowshade"). |
| 173 | * |
| 174 | * (This feature is disabled by the InCallScreen while the in-call |
| 175 | * UI is active.) |
| 176 | */ |
| 177 | public void enableExpandedView(boolean enable) { |
| 178 | if (mIsExpandedViewEnabled != enable) { |
| 179 | mIsExpandedViewEnabled = enable; |
| 180 | updateStatusBar(); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Enables or disables the navigation via the system bar (the |
| 186 | * "soft buttons" at the bottom of the screen) |
| 187 | * |
| 188 | * (This feature is disabled while an incoming call is ringing, |
| 189 | * because it's easy to accidentally touch the system bar while |
| 190 | * pulling the phone out of your pocket.) |
| 191 | */ |
| 192 | public void enableSystemBarNavigation(boolean enable) { |
| 193 | if (mIsSystemBarNavigationEnabled != enable) { |
| 194 | mIsSystemBarNavigationEnabled = enable; |
| 195 | updateStatusBar(); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Updates the status bar to reflect the current desired state. |
| 201 | */ |
| 202 | private void updateStatusBar() { |
| 203 | int state = StatusBarManager.DISABLE_NONE; |
| 204 | |
| 205 | if (!mIsExpandedViewEnabled) { |
| 206 | state |= StatusBarManager.DISABLE_EXPAND; |
| 207 | } |
| 208 | if (!mIsNotificationEnabled) { |
| 209 | state |= StatusBarManager.DISABLE_NOTIFICATION_ALERTS; |
| 210 | } |
| 211 | if (!mIsSystemBarNavigationEnabled) { |
| 212 | // Disable *all* possible navigation via the system bar. |
| 213 | state |= StatusBarManager.DISABLE_HOME; |
| 214 | state |= StatusBarManager.DISABLE_RECENT; |
| 215 | state |= StatusBarManager.DISABLE_BACK; |
Christine Chen | b685f17 | 2013-09-25 18:32:59 -0700 | [diff] [blame] | 216 | state |= StatusBarManager.DISABLE_SEARCH; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | if (DBG) log("updateStatusBar: state = 0x" + Integer.toHexString(state)); |
| 220 | mStatusBarManager.disable(state); |
| 221 | } |
| 222 | } |
| 223 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 224 | /** The projection to use when querying the phones table */ |
| 225 | static final String[] PHONES_PROJECTION = new String[] { |
| 226 | PhoneLookup.NUMBER, |
| 227 | PhoneLookup.DISPLAY_NAME, |
| 228 | PhoneLookup._ID |
| 229 | }; |
| 230 | |
| 231 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 232 | * Updates the message waiting indicator (voicemail) notification. |
| 233 | * |
| 234 | * @param visible true if there are messages waiting |
| 235 | */ |
| 236 | /* package */ void updateMwi(boolean visible) { |
| 237 | if (DBG) log("updateMwi(): " + visible); |
| 238 | |
| 239 | if (visible) { |
| 240 | int resId = android.R.drawable.stat_notify_voicemail; |
| 241 | |
| 242 | // This Notification can get a lot fancier once we have more |
| 243 | // information about the current voicemail messages. |
| 244 | // (For example, the current voicemail system can't tell |
| 245 | // us the caller-id or timestamp of a message, or tell us the |
| 246 | // message count.) |
| 247 | |
| 248 | // But for now, the UI is ultra-simple: if the MWI indication |
| 249 | // is supposed to be visible, just show a single generic |
| 250 | // notification. |
| 251 | |
| 252 | String notificationTitle = mContext.getString(R.string.notification_voicemail_title); |
| 253 | String vmNumber = mPhone.getVoiceMailNumber(); |
| 254 | if (DBG) log("- got vm number: '" + vmNumber + "'"); |
| 255 | |
| 256 | // Watch out: vmNumber may be null, for two possible reasons: |
| 257 | // |
| 258 | // (1) This phone really has no voicemail number |
| 259 | // |
| 260 | // (2) This phone *does* have a voicemail number, but |
| 261 | // the SIM isn't ready yet. |
| 262 | // |
| 263 | // Case (2) *does* happen in practice if you have voicemail |
| 264 | // messages when the device first boots: we get an MWI |
| 265 | // notification as soon as we register on the network, but the |
| 266 | // SIM hasn't finished loading yet. |
| 267 | // |
| 268 | // So handle case (2) by retrying the lookup after a short |
| 269 | // delay. |
| 270 | |
| 271 | if ((vmNumber == null) && !mPhone.getIccRecordsLoaded()) { |
| 272 | if (DBG) log("- Null vm number: SIM records not loaded (yet)..."); |
| 273 | |
| 274 | // TODO: rather than retrying after an arbitrary delay, it |
| 275 | // would be cleaner to instead just wait for a |
| 276 | // SIM_RECORDS_LOADED notification. |
| 277 | // (Unfortunately right now there's no convenient way to |
| 278 | // get that notification in phone app code. We'd first |
| 279 | // want to add a call like registerForSimRecordsLoaded() |
| 280 | // to Phone.java and GSMPhone.java, and *then* we could |
| 281 | // listen for that in the CallNotifier class.) |
| 282 | |
| 283 | // Limit the number of retries (in case the SIM is broken |
| 284 | // or missing and can *never* load successfully.) |
| 285 | if (mVmNumberRetriesRemaining-- > 0) { |
| 286 | if (DBG) log(" - Retrying in " + VM_NUMBER_RETRY_DELAY_MILLIS + " msec..."); |
| 287 | mApp.notifier.sendMwiChangedDelayed(VM_NUMBER_RETRY_DELAY_MILLIS); |
| 288 | return; |
| 289 | } else { |
| 290 | Log.w(LOG_TAG, "NotificationMgr.updateMwi: getVoiceMailNumber() failed after " |
| 291 | + MAX_VM_NUMBER_RETRIES + " retries; giving up."); |
| 292 | // ...and continue with vmNumber==null, just as if the |
| 293 | // phone had no VM number set up in the first place. |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | if (TelephonyCapabilities.supportsVoiceMessageCount(mPhone)) { |
| 298 | int vmCount = mPhone.getVoiceMessageCount(); |
| 299 | String titleFormat = mContext.getString(R.string.notification_voicemail_title_count); |
| 300 | notificationTitle = String.format(titleFormat, vmCount); |
| 301 | } |
| 302 | |
| 303 | String notificationText; |
| 304 | if (TextUtils.isEmpty(vmNumber)) { |
| 305 | notificationText = mContext.getString( |
| 306 | R.string.notification_voicemail_no_vm_number); |
| 307 | } else { |
| 308 | notificationText = String.format( |
| 309 | mContext.getString(R.string.notification_voicemail_text_format), |
| 310 | PhoneNumberUtils.formatNumber(vmNumber)); |
| 311 | } |
| 312 | |
| 313 | Intent intent = new Intent(Intent.ACTION_CALL, |
Jay Shrauner | 137458b | 2014-09-05 14:27:25 -0700 | [diff] [blame] | 314 | Uri.fromParts(PhoneAccount.SCHEME_VOICEMAIL, "", null)); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 315 | PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0); |
| 316 | |
| 317 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); |
| 318 | Uri ringtoneUri; |
| 319 | String uriString = prefs.getString( |
| 320 | CallFeaturesSetting.BUTTON_VOICEMAIL_NOTIFICATION_RINGTONE_KEY, null); |
| 321 | if (!TextUtils.isEmpty(uriString)) { |
| 322 | ringtoneUri = Uri.parse(uriString); |
| 323 | } else { |
| 324 | ringtoneUri = Settings.System.DEFAULT_NOTIFICATION_URI; |
| 325 | } |
| 326 | |
| 327 | Notification.Builder builder = new Notification.Builder(mContext); |
| 328 | builder.setSmallIcon(resId) |
| 329 | .setWhen(System.currentTimeMillis()) |
| 330 | .setContentTitle(notificationTitle) |
| 331 | .setContentText(notificationText) |
| 332 | .setContentIntent(pendingIntent) |
Yorke Lee | acb5f74 | 2014-08-19 09:08:42 -0700 | [diff] [blame] | 333 | .setSound(ringtoneUri) |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 334 | .setColor(mContext.getResources().getColor(R.color.dialer_theme_color)) |
| 335 | .setOngoing(true); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 336 | |
| 337 | CallFeaturesSetting.migrateVoicemailVibrationSettingsIfNeeded(prefs); |
| 338 | final boolean vibrate = prefs.getBoolean( |
| 339 | CallFeaturesSetting.BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY, false); |
| 340 | if (vibrate) { |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 341 | builder.setDefaults(Notification.DEFAULT_VIBRATE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 342 | } |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 343 | |
| 344 | final Notification notification = builder.build(); |
| 345 | List<UserInfo> users = mUserManager.getUsers(true); |
| 346 | for (int i = 0; i < users.size(); i++) { |
Yorke Lee | 047b1f9 | 2014-10-24 10:22:41 -0700 | [diff] [blame] | 347 | final UserInfo user = users.get(i); |
| 348 | final UserHandle userHandle = user.getUserHandle(); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 349 | if (!mUserManager.hasUserRestriction( |
Yorke Lee | 047b1f9 | 2014-10-24 10:22:41 -0700 | [diff] [blame] | 350 | UserManager.DISALLOW_OUTGOING_CALLS, userHandle) |
| 351 | && !user.isManagedProfile()) { |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 352 | mNotificationManager.notifyAsUser( |
| 353 | null /* tag */, VOICEMAIL_NOTIFICATION, notification, userHandle); |
| 354 | } |
| 355 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 356 | } else { |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 357 | mNotificationManager.cancelAsUser( |
| 358 | null /* tag */, VOICEMAIL_NOTIFICATION, UserHandle.ALL); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * Updates the message call forwarding indicator notification. |
| 364 | * |
| 365 | * @param visible true if there are messages waiting |
| 366 | */ |
| 367 | /* package */ void updateCfi(boolean visible) { |
| 368 | if (DBG) log("updateCfi(): " + visible); |
| 369 | if (visible) { |
| 370 | // If Unconditional Call Forwarding (forward all calls) for VOICE |
| 371 | // is enabled, just show a notification. We'll default to expanded |
| 372 | // view for now, so the there is less confusion about the icon. If |
| 373 | // it is deemed too weird to have CF indications as expanded views, |
| 374 | // then we'll flip the flag back. |
| 375 | |
| 376 | // TODO: We may want to take a look to see if the notification can |
| 377 | // display the target to forward calls to. This will require some |
| 378 | // effort though, since there are multiple layers of messages that |
| 379 | // will need to propagate that information. |
| 380 | |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 381 | Notification.Builder builder = new Notification.Builder(mContext) |
| 382 | .setSmallIcon(R.drawable.stat_sys_phone_call_forward) |
| 383 | .setContentTitle(mContext.getString(R.string.labelCF)) |
| 384 | .setContentText(mContext.getString(R.string.sum_cfu_enabled_indicator)) |
| 385 | .setShowWhen(false) |
| 386 | .setOngoing(true); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 387 | |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 388 | Intent intent = new Intent(Intent.ACTION_MAIN); |
| 389 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 390 | intent.setClassName("com.android.phone", "com.android.phone.CallFeaturesSetting"); |
| 391 | PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0); |
| 392 | |
| 393 | List<UserInfo> users = mUserManager.getUsers(true); |
| 394 | for (int i = 0; i < users.size(); i++) { |
Yorke Lee | 3faa594 | 2014-11-05 16:50:04 -0800 | [diff] [blame^] | 395 | final UserInfo user = users.get(i); |
| 396 | if (user.isManagedProfile()) { |
| 397 | continue; |
| 398 | } |
| 399 | UserHandle userHandle = user.getUserHandle(); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 400 | builder.setContentIntent(userHandle.isOwner() ? contentIntent : null); |
| 401 | mNotificationManager.notifyAsUser( |
| 402 | null /* tag */, CALL_FORWARD_NOTIFICATION, builder.build(), userHandle); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 403 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 404 | } else { |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 405 | mNotificationManager.cancelAsUser( |
| 406 | null /* tag */, CALL_FORWARD_NOTIFICATION, UserHandle.ALL); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Shows the "data disconnected due to roaming" notification, which |
| 412 | * appears when you lose data connectivity because you're roaming and |
| 413 | * you have the "data roaming" feature turned off. |
| 414 | */ |
| 415 | /* package */ void showDataDisconnectedRoaming() { |
| 416 | if (DBG) log("showDataDisconnectedRoaming()..."); |
| 417 | |
| 418 | // "Mobile network settings" screen / dialog |
| 419 | Intent intent = new Intent(mContext, com.android.phone.MobileNetworkSettings.class); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 420 | PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 421 | |
| 422 | final CharSequence contentText = mContext.getText(R.string.roaming_reenable_message); |
| 423 | |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 424 | final Notification.Builder builder = new Notification.Builder(mContext) |
| 425 | .setSmallIcon(android.R.drawable.stat_sys_warning) |
| 426 | .setContentTitle(mContext.getText(R.string.roaming)) |
| 427 | .setColor(mContext.getResources().getColor(R.color.dialer_theme_color)) |
| 428 | .setContentText(contentText); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 429 | |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 430 | List<UserInfo> users = mUserManager.getUsers(true); |
| 431 | for (int i = 0; i < users.size(); i++) { |
Yorke Lee | 3faa594 | 2014-11-05 16:50:04 -0800 | [diff] [blame^] | 432 | final UserInfo user = users.get(i); |
| 433 | if (user.isManagedProfile()) { |
| 434 | continue; |
| 435 | } |
| 436 | UserHandle userHandle = user.getUserHandle(); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 437 | builder.setContentIntent(userHandle.isOwner() ? contentIntent : null); |
| 438 | final Notification notif = |
| 439 | new Notification.BigTextStyle(builder).bigText(contentText).build(); |
| 440 | mNotificationManager.notifyAsUser( |
| 441 | null /* tag */, DATA_DISCONNECTED_ROAMING_NOTIFICATION, notif, userHandle); |
| 442 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | /** |
| 446 | * Turns off the "data disconnected due to roaming" notification. |
| 447 | */ |
| 448 | /* package */ void hideDataDisconnectedRoaming() { |
| 449 | if (DBG) log("hideDataDisconnectedRoaming()..."); |
| 450 | mNotificationManager.cancel(DATA_DISCONNECTED_ROAMING_NOTIFICATION); |
| 451 | } |
| 452 | |
| 453 | /** |
| 454 | * Display the network selection "no service" notification |
| 455 | * @param operator is the numeric operator number |
| 456 | */ |
| 457 | private void showNetworkSelection(String operator) { |
| 458 | if (DBG) log("showNetworkSelection(" + operator + ")..."); |
| 459 | |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 460 | Notification.Builder builder = new Notification.Builder(mContext) |
| 461 | .setSmallIcon(android.R.drawable.stat_sys_warning) |
| 462 | .setContentTitle(mContext.getString(R.string.notification_network_selection_title)) |
| 463 | .setContentText( |
| 464 | mContext.getString(R.string.notification_network_selection_text, operator)) |
| 465 | .setShowWhen(false) |
| 466 | .setOngoing(true); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 467 | |
| 468 | // create the target network operators settings intent |
| 469 | Intent intent = new Intent(Intent.ACTION_MAIN); |
| 470 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| 471 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 472 | // Use NetworkSetting to handle the selection intent |
| 473 | intent.setComponent(new ComponentName("com.android.phone", |
| 474 | "com.android.phone.NetworkSetting")); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 475 | PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 476 | |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 477 | List<UserInfo> users = mUserManager.getUsers(true); |
| 478 | for (int i = 0; i < users.size(); i++) { |
Yorke Lee | 3faa594 | 2014-11-05 16:50:04 -0800 | [diff] [blame^] | 479 | final UserInfo user = users.get(i); |
| 480 | if (user.isManagedProfile()) { |
| 481 | continue; |
| 482 | } |
| 483 | UserHandle userHandle = user.getUserHandle(); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 484 | builder.setContentIntent(userHandle.isOwner() ? contentIntent : null); |
| 485 | mNotificationManager.notifyAsUser( |
| 486 | null /* tag */, |
| 487 | SELECTED_OPERATOR_FAIL_NOTIFICATION, |
| 488 | builder.build(), |
| 489 | userHandle); |
| 490 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | /** |
| 494 | * Turn off the network selection "no service" notification |
| 495 | */ |
| 496 | private void cancelNetworkSelection() { |
| 497 | if (DBG) log("cancelNetworkSelection()..."); |
Andrew Lee | 99d0ac2 | 2014-10-10 13:18:04 -0700 | [diff] [blame] | 498 | mNotificationManager.cancelAsUser( |
| 499 | null /* tag */, SELECTED_OPERATOR_FAIL_NOTIFICATION, UserHandle.ALL); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | /** |
| 503 | * Update notification about no service of user selected operator |
| 504 | * |
| 505 | * @param serviceState Phone service state |
| 506 | */ |
| 507 | void updateNetworkSelection(int serviceState) { |
| 508 | if (TelephonyCapabilities.supportsNetworkSelection(mPhone)) { |
| 509 | // get the shared preference of network_selection. |
| 510 | // empty is auto mode, otherwise it is the operator alpha name |
| 511 | // in case there is no operator name, check the operator numeric |
| 512 | SharedPreferences sp = |
| 513 | PreferenceManager.getDefaultSharedPreferences(mContext); |
| 514 | String networkSelection = |
| 515 | sp.getString(PhoneBase.NETWORK_SELECTION_NAME_KEY, ""); |
| 516 | if (TextUtils.isEmpty(networkSelection)) { |
| 517 | networkSelection = |
| 518 | sp.getString(PhoneBase.NETWORK_SELECTION_KEY, ""); |
| 519 | } |
| 520 | |
| 521 | if (DBG) log("updateNetworkSelection()..." + "state = " + |
| 522 | serviceState + " new network " + networkSelection); |
| 523 | |
| 524 | if (serviceState == ServiceState.STATE_OUT_OF_SERVICE |
| 525 | && !TextUtils.isEmpty(networkSelection)) { |
| 526 | if (!mSelectedUnavailableNotify) { |
| 527 | showNetworkSelection(networkSelection); |
| 528 | mSelectedUnavailableNotify = true; |
| 529 | } |
| 530 | } else { |
| 531 | if (mSelectedUnavailableNotify) { |
| 532 | cancelNetworkSelection(); |
| 533 | mSelectedUnavailableNotify = false; |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | /* package */ void postTransientNotification(int notifyId, CharSequence msg) { |
| 540 | if (mToast != null) { |
| 541 | mToast.cancel(); |
| 542 | } |
| 543 | |
| 544 | mToast = Toast.makeText(mContext, msg, Toast.LENGTH_LONG); |
| 545 | mToast.show(); |
| 546 | } |
| 547 | |
| 548 | private void log(String msg) { |
| 549 | Log.d(LOG_TAG, msg); |
| 550 | } |
| 551 | } |