blob: 6ed9cbceb017a1dcf920c9d7aa5d03d01f296e28 [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++) {
347 UserHandle userHandle = users.get(i).getUserHandle();
348 if (!mUserManager.hasUserRestriction(
349 UserManager.DISALLOW_OUTGOING_CALLS, userHandle)) {
350 mNotificationManager.notifyAsUser(
351 null /* tag */, VOICEMAIL_NOTIFICATION, notification, userHandle);
352 }
353 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 } else {
Andrew Lee99d0ac22014-10-10 13:18:04 -0700355 mNotificationManager.cancelAsUser(
356 null /* tag */, VOICEMAIL_NOTIFICATION, UserHandle.ALL);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357 }
358 }
359
360 /**
361 * Updates the message call forwarding indicator notification.
362 *
363 * @param visible true if there are messages waiting
364 */
365 /* package */ void updateCfi(boolean visible) {
366 if (DBG) log("updateCfi(): " + visible);
367 if (visible) {
368 // If Unconditional Call Forwarding (forward all calls) for VOICE
369 // is enabled, just show a notification. We'll default to expanded
370 // view for now, so the there is less confusion about the icon. If
371 // it is deemed too weird to have CF indications as expanded views,
372 // then we'll flip the flag back.
373
374 // TODO: We may want to take a look to see if the notification can
375 // display the target to forward calls to. This will require some
376 // effort though, since there are multiple layers of messages that
377 // will need to propagate that information.
378
Andrew Lee99d0ac22014-10-10 13:18:04 -0700379 Notification.Builder builder = new Notification.Builder(mContext)
380 .setSmallIcon(R.drawable.stat_sys_phone_call_forward)
381 .setContentTitle(mContext.getString(R.string.labelCF))
382 .setContentText(mContext.getString(R.string.sum_cfu_enabled_indicator))
383 .setShowWhen(false)
384 .setOngoing(true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385
Andrew Lee99d0ac22014-10-10 13:18:04 -0700386 Intent intent = new Intent(Intent.ACTION_MAIN);
387 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
388 intent.setClassName("com.android.phone", "com.android.phone.CallFeaturesSetting");
389 PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
390
391 List<UserInfo> users = mUserManager.getUsers(true);
392 for (int i = 0; i < users.size(); i++) {
393 UserHandle userHandle = users.get(i).getUserHandle();
394 builder.setContentIntent(userHandle.isOwner() ? contentIntent : null);
395 mNotificationManager.notifyAsUser(
396 null /* tag */, CALL_FORWARD_NOTIFICATION, builder.build(), userHandle);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 } else {
Andrew Lee99d0ac22014-10-10 13:18:04 -0700399 mNotificationManager.cancelAsUser(
400 null /* tag */, CALL_FORWARD_NOTIFICATION, UserHandle.ALL);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 }
402 }
403
404 /**
405 * Shows the "data disconnected due to roaming" notification, which
406 * appears when you lose data connectivity because you're roaming and
407 * you have the "data roaming" feature turned off.
408 */
409 /* package */ void showDataDisconnectedRoaming() {
410 if (DBG) log("showDataDisconnectedRoaming()...");
411
412 // "Mobile network settings" screen / dialog
413 Intent intent = new Intent(mContext, com.android.phone.MobileNetworkSettings.class);
Andrew Lee99d0ac22014-10-10 13:18:04 -0700414 PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415
416 final CharSequence contentText = mContext.getText(R.string.roaming_reenable_message);
417
Andrew Lee99d0ac22014-10-10 13:18:04 -0700418 final Notification.Builder builder = new Notification.Builder(mContext)
419 .setSmallIcon(android.R.drawable.stat_sys_warning)
420 .setContentTitle(mContext.getText(R.string.roaming))
421 .setColor(mContext.getResources().getColor(R.color.dialer_theme_color))
422 .setContentText(contentText);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423
Andrew Lee99d0ac22014-10-10 13:18:04 -0700424 List<UserInfo> users = mUserManager.getUsers(true);
425 for (int i = 0; i < users.size(); i++) {
426 UserHandle userHandle = users.get(i).getUserHandle();
427 builder.setContentIntent(userHandle.isOwner() ? contentIntent : null);
428 final Notification notif =
429 new Notification.BigTextStyle(builder).bigText(contentText).build();
430 mNotificationManager.notifyAsUser(
431 null /* tag */, DATA_DISCONNECTED_ROAMING_NOTIFICATION, notif, userHandle);
432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433 }
434
435 /**
436 * Turns off the "data disconnected due to roaming" notification.
437 */
438 /* package */ void hideDataDisconnectedRoaming() {
439 if (DBG) log("hideDataDisconnectedRoaming()...");
440 mNotificationManager.cancel(DATA_DISCONNECTED_ROAMING_NOTIFICATION);
441 }
442
443 /**
444 * Display the network selection "no service" notification
445 * @param operator is the numeric operator number
446 */
447 private void showNetworkSelection(String operator) {
448 if (DBG) log("showNetworkSelection(" + operator + ")...");
449
Andrew Lee99d0ac22014-10-10 13:18:04 -0700450 Notification.Builder builder = new Notification.Builder(mContext)
451 .setSmallIcon(android.R.drawable.stat_sys_warning)
452 .setContentTitle(mContext.getString(R.string.notification_network_selection_title))
453 .setContentText(
454 mContext.getString(R.string.notification_network_selection_text, operator))
455 .setShowWhen(false)
456 .setOngoing(true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457
458 // create the target network operators settings intent
459 Intent intent = new Intent(Intent.ACTION_MAIN);
460 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
461 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
462 // Use NetworkSetting to handle the selection intent
463 intent.setComponent(new ComponentName("com.android.phone",
464 "com.android.phone.NetworkSetting"));
Andrew Lee99d0ac22014-10-10 13:18:04 -0700465 PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700466
Andrew Lee99d0ac22014-10-10 13:18:04 -0700467 List<UserInfo> users = mUserManager.getUsers(true);
468 for (int i = 0; i < users.size(); i++) {
469 UserHandle userHandle = users.get(i).getUserHandle();
470 builder.setContentIntent(userHandle.isOwner() ? contentIntent : null);
471 mNotificationManager.notifyAsUser(
472 null /* tag */,
473 SELECTED_OPERATOR_FAIL_NOTIFICATION,
474 builder.build(),
475 userHandle);
476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 }
478
479 /**
480 * Turn off the network selection "no service" notification
481 */
482 private void cancelNetworkSelection() {
483 if (DBG) log("cancelNetworkSelection()...");
Andrew Lee99d0ac22014-10-10 13:18:04 -0700484 mNotificationManager.cancelAsUser(
485 null /* tag */, SELECTED_OPERATOR_FAIL_NOTIFICATION, UserHandle.ALL);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 }
487
488 /**
489 * Update notification about no service of user selected operator
490 *
491 * @param serviceState Phone service state
492 */
493 void updateNetworkSelection(int serviceState) {
494 if (TelephonyCapabilities.supportsNetworkSelection(mPhone)) {
495 // get the shared preference of network_selection.
496 // empty is auto mode, otherwise it is the operator alpha name
497 // in case there is no operator name, check the operator numeric
498 SharedPreferences sp =
499 PreferenceManager.getDefaultSharedPreferences(mContext);
500 String networkSelection =
501 sp.getString(PhoneBase.NETWORK_SELECTION_NAME_KEY, "");
502 if (TextUtils.isEmpty(networkSelection)) {
503 networkSelection =
504 sp.getString(PhoneBase.NETWORK_SELECTION_KEY, "");
505 }
506
507 if (DBG) log("updateNetworkSelection()..." + "state = " +
508 serviceState + " new network " + networkSelection);
509
510 if (serviceState == ServiceState.STATE_OUT_OF_SERVICE
511 && !TextUtils.isEmpty(networkSelection)) {
512 if (!mSelectedUnavailableNotify) {
513 showNetworkSelection(networkSelection);
514 mSelectedUnavailableNotify = true;
515 }
516 } else {
517 if (mSelectedUnavailableNotify) {
518 cancelNetworkSelection();
519 mSelectedUnavailableNotify = false;
520 }
521 }
522 }
523 }
524
525 /* package */ void postTransientNotification(int notifyId, CharSequence msg) {
526 if (mToast != null) {
527 mToast.cancel();
528 }
529
530 mToast = Toast.makeText(mContext, msg, Toast.LENGTH_LONG);
531 mToast.show();
532 }
533
534 private void log(String msg) {
535 Log.d(LOG_TAG, msg);
536 }
537}