blob: e06684c328f71d3aadc000a1acf1ee6027a1e3c4 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
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
17package com.android.phone;
18
19import android.app.Notification;
20import android.app.NotificationManager;
21import android.app.PendingIntent;
22import android.app.StatusBarManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.content.Context;
25import android.content.Intent;
26import android.content.SharedPreferences;
Andrew Lee99d0ac22014-10-10 13:18:04 -070027import android.content.pm.UserInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.net.Uri;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.os.SystemProperties;
Andrew Lee99d0ac22014-10-10 13:18:04 -070030import android.os.UserHandle;
31import android.os.UserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.preference.PreferenceManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.provider.ContactsContract.PhoneLookup;
34import android.provider.Settings;
Tyler Gunn4d45d1c2014-09-12 22:17:53 -070035import android.telecom.PhoneAccount;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.telephony.PhoneNumberUtils;
37import android.telephony.ServiceState;
38import android.text.TextUtils;
39import android.util.Log;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.widget.Toast;
41
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import com.android.internal.telephony.Phone;
43import com.android.internal.telephony.PhoneBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import com.android.internal.telephony.TelephonyCapabilities;
45
Andrew Lee99d0ac22014-10-10 13:18:04 -070046import java.util.List;
47
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048/**
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 Cheng312b9c92013-09-16 15:40:53 -070057public class NotificationMgr {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058 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 Cordon7d4ddf62013-07-10 11:58:08 -070064 // notification types
Santos Cordonf68db2e2014-07-02 14:40:44 -070065 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 Cordon7d4ddf62013-07-10 11:58:08 -070071
72 /** The singleton NotificationMgr instance. */
73 private static NotificationMgr sInstance;
74
75 private PhoneGlobals mApp;
76 private Phone mPhone;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077
78 private Context mContext;
79 private NotificationManager mNotificationManager;
80 private StatusBarManager mStatusBarManager;
Andrew Lee99d0ac22014-10-10 13:18:04 -070081 private UserManager mUserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082 private Toast mToast;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083
84 public StatusBarHelper statusBarHelper;
85
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086 // 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 Cordon7d4ddf62013-07-10 11:58:08 -070094 /**
95 * Private constructor (this is a singleton).
Santos Cordonf68db2e2014-07-02 14:40:44 -070096 * @see #init(PhoneGlobals)
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097 */
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 Lee99d0ac22014-10-10 13:18:04 -0700105 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106 mPhone = app.phone; // TODO: better style to use mCM.getDefaultPhone() everywhere instead
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107 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 Cordon7d4ddf62013-07-10 11:58:08 -0700122 } 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 Chenb685f172013-09-25 18:32:59 -0700216 state |= StatusBarManager.DISABLE_SEARCH;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217 }
218
219 if (DBG) log("updateStatusBar: state = 0x" + Integer.toHexString(state));
220 mStatusBarManager.disable(state);
221 }
222 }
223
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224 /** 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 Cordon7d4ddf62013-07-10 11:58:08 -0700232 * 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 Shrauner137458b2014-09-05 14:27:25 -0700314 Uri.fromParts(PhoneAccount.SCHEME_VOICEMAIL, "", null));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315 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 Leeacb5f742014-08-19 09:08:42 -0700333 .setSound(ringtoneUri)
Andrew Lee99d0ac22014-10-10 13:18:04 -0700334 .setColor(mContext.getResources().getColor(R.color.dialer_theme_color))
335 .setOngoing(true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336
337 CallFeaturesSetting.migrateVoicemailVibrationSettingsIfNeeded(prefs);
338 final boolean vibrate = prefs.getBoolean(
339 CallFeaturesSetting.BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY, false);
340 if (vibrate) {
Andrew Lee99d0ac22014-10-10 13:18:04 -0700341 builder.setDefaults(Notification.DEFAULT_VIBRATE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342 }
Andrew Lee99d0ac22014-10-10 13:18:04 -0700343
344 final Notification notification = builder.build();
345 List<UserInfo> users = mUserManager.getUsers(true);
346 for (int i = 0; i < users.size(); i++) {
Yorke Lee047b1f92014-10-24 10:22:41 -0700347 final UserInfo user = users.get(i);
348 final UserHandle userHandle = user.getUserHandle();
Andrew Lee99d0ac22014-10-10 13:18:04 -0700349 if (!mUserManager.hasUserRestriction(
Yorke Lee047b1f92014-10-24 10:22:41 -0700350 UserManager.DISALLOW_OUTGOING_CALLS, userHandle)
351 && !user.isManagedProfile()) {
Andrew Lee99d0ac22014-10-10 13:18:04 -0700352 mNotificationManager.notifyAsUser(
353 null /* tag */, VOICEMAIL_NOTIFICATION, notification, userHandle);
354 }
355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 } else {
Andrew Lee99d0ac22014-10-10 13:18:04 -0700357 mNotificationManager.cancelAsUser(
358 null /* tag */, VOICEMAIL_NOTIFICATION, UserHandle.ALL);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 }
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 Lee99d0ac22014-10-10 13:18:04 -0700381 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 Cordon7d4ddf62013-07-10 11:58:08 -0700387
Andrew Lee99d0ac22014-10-10 13:18:04 -0700388 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 Lee3faa5942014-11-05 16:50:04 -0800395 final UserInfo user = users.get(i);
396 if (user.isManagedProfile()) {
397 continue;
398 }
399 UserHandle userHandle = user.getUserHandle();
Andrew Lee99d0ac22014-10-10 13:18:04 -0700400 builder.setContentIntent(userHandle.isOwner() ? contentIntent : null);
401 mNotificationManager.notifyAsUser(
402 null /* tag */, CALL_FORWARD_NOTIFICATION, builder.build(), userHandle);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404 } else {
Andrew Lee99d0ac22014-10-10 13:18:04 -0700405 mNotificationManager.cancelAsUser(
406 null /* tag */, CALL_FORWARD_NOTIFICATION, UserHandle.ALL);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407 }
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 Lee99d0ac22014-10-10 13:18:04 -0700420 PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421
422 final CharSequence contentText = mContext.getText(R.string.roaming_reenable_message);
423
Andrew Lee99d0ac22014-10-10 13:18:04 -0700424 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 Cordon7d4ddf62013-07-10 11:58:08 -0700429
Andrew Lee99d0ac22014-10-10 13:18:04 -0700430 List<UserInfo> users = mUserManager.getUsers(true);
431 for (int i = 0; i < users.size(); i++) {
Yorke Lee3faa5942014-11-05 16:50:04 -0800432 final UserInfo user = users.get(i);
433 if (user.isManagedProfile()) {
434 continue;
435 }
436 UserHandle userHandle = user.getUserHandle();
Andrew Lee99d0ac22014-10-10 13:18:04 -0700437 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 Cordon7d4ddf62013-07-10 11:58:08 -0700443 }
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 Lee99d0ac22014-10-10 13:18:04 -0700460 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 Cordon7d4ddf62013-07-10 11:58:08 -0700467
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 Lee99d0ac22014-10-10 13:18:04 -0700475 PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700476
Andrew Lee99d0ac22014-10-10 13:18:04 -0700477 List<UserInfo> users = mUserManager.getUsers(true);
478 for (int i = 0; i < users.size(); i++) {
Yorke Lee3faa5942014-11-05 16:50:04 -0800479 final UserInfo user = users.get(i);
480 if (user.isManagedProfile()) {
481 continue;
482 }
483 UserHandle userHandle = user.getUserHandle();
Andrew Lee99d0ac22014-10-10 13:18:04 -0700484 builder.setContentIntent(userHandle.isOwner() ? contentIntent : null);
485 mNotificationManager.notifyAsUser(
486 null /* tag */,
487 SELECTED_OPERATOR_FAIL_NOTIFICATION,
488 builder.build(),
489 userHandle);
490 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700491 }
492
493 /**
494 * Turn off the network selection "no service" notification
495 */
496 private void cancelNetworkSelection() {
497 if (DBG) log("cancelNetworkSelection()...");
Andrew Lee99d0ac22014-10-10 13:18:04 -0700498 mNotificationManager.cancelAsUser(
499 null /* tag */, SELECTED_OPERATOR_FAIL_NOTIFICATION, UserHandle.ALL);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700500 }
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}