blob: badca74573ecd026002fe4e6f39233bb0a1bb445 [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;
Andrew Leea82b8202014-11-21 16:18:28 -080038import android.telephony.SubscriptionManager;
39import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.text.TextUtils;
41import android.util.Log;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.widget.Toast;
43
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import com.android.internal.telephony.Phone;
45import com.android.internal.telephony.PhoneBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import com.android.internal.telephony.TelephonyCapabilities;
Andrew Lee8d66d812014-11-24 14:54:02 -080047import com.android.phone.settings.VoicemailNotificationSettingsUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048
Andrew Lee99d0ac22014-10-10 13:18:04 -070049import java.util.List;
50
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051/**
52 * NotificationManager-related utility code for the Phone app.
53 *
54 * This is a singleton object which acts as the interface to the
55 * framework's NotificationManager, and is used to display status bar
56 * icons and control other status bar-related behavior.
57 *
58 * @see PhoneGlobals.notificationMgr
59 */
Chiao Cheng312b9c92013-09-16 15:40:53 -070060public class NotificationMgr {
Andrew Leea82b8202014-11-21 16:18:28 -080061 private static final String LOG_TAG = NotificationMgr.class.getSimpleName();
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062 private static final boolean DBG =
63 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
64 // Do not check in with VDBG = true, since that may write PII to the system log.
65 private static final boolean VDBG = false;
66
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067 // notification types
Santos Cordonf68db2e2014-07-02 14:40:44 -070068 static final int MMI_NOTIFICATION = 1;
69 static final int NETWORK_SELECTION_NOTIFICATION = 2;
70 static final int VOICEMAIL_NOTIFICATION = 3;
71 static final int CALL_FORWARD_NOTIFICATION = 4;
72 static final int DATA_DISCONNECTED_ROAMING_NOTIFICATION = 5;
73 static final int SELECTED_OPERATOR_FAIL_NOTIFICATION = 6;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074
75 /** The singleton NotificationMgr instance. */
76 private static NotificationMgr sInstance;
77
78 private PhoneGlobals mApp;
79 private Phone mPhone;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080
81 private Context mContext;
82 private NotificationManager mNotificationManager;
83 private StatusBarManager mStatusBarManager;
Andrew Lee99d0ac22014-10-10 13:18:04 -070084 private UserManager mUserManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085 private Toast mToast;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086
87 public StatusBarHelper statusBarHelper;
88
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089 // used to track the notification of selected network unavailable
90 private boolean mSelectedUnavailableNotify = false;
91
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092 /**
93 * Private constructor (this is a singleton).
Santos Cordonf68db2e2014-07-02 14:40:44 -070094 * @see #init(PhoneGlobals)
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095 */
96 private NotificationMgr(PhoneGlobals app) {
97 mApp = app;
98 mContext = app;
99 mNotificationManager =
100 (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
101 mStatusBarManager =
102 (StatusBarManager) app.getSystemService(Context.STATUS_BAR_SERVICE);
Andrew Lee99d0ac22014-10-10 13:18:04 -0700103 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104 mPhone = app.phone; // TODO: better style to use mCM.getDefaultPhone() everywhere instead
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105 statusBarHelper = new StatusBarHelper();
Andrew Leea82b8202014-11-21 16:18:28 -0800106
107 SubscriptionManager.from(mContext).registerOnSubscriptionsChangedListener(
108 new OnSubscriptionsChangedListener() {
109 @Override
110 public void onSubscriptionsChanged() {
111 // Update the message waiting indicator if the SIM is changed.
112 updateMwi(mPhone.getMessageWaitingIndicator());
113 }
114 });
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115 }
116
117 /**
118 * Initialize the singleton NotificationMgr instance.
119 *
120 * This is only done once, at startup, from PhoneApp.onCreate().
121 * From then on, the NotificationMgr instance is available via the
122 * PhoneApp's public "notificationMgr" field, which is why there's no
123 * getInstance() method here.
124 */
125 /* package */ static NotificationMgr init(PhoneGlobals app) {
126 synchronized (NotificationMgr.class) {
127 if (sInstance == null) {
128 sInstance = new NotificationMgr(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129 } else {
130 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
131 }
132 return sInstance;
133 }
134 }
135
136 /**
137 * Helper class that's a wrapper around the framework's
138 * StatusBarManager.disable() API.
139 *
140 * This class is used to control features like:
141 *
142 * - Disabling the status bar "notification windowshade"
143 * while the in-call UI is up
144 *
145 * - Disabling notification alerts (audible or vibrating)
146 * while a phone call is active
147 *
148 * - Disabling navigation via the system bar (the "soft buttons" at
149 * the bottom of the screen on devices with no hard buttons)
150 *
151 * We control these features through a single point of control to make
152 * sure that the various StatusBarManager.disable() calls don't
153 * interfere with each other.
154 */
155 public class StatusBarHelper {
156 // Current desired state of status bar / system bar behavior
157 private boolean mIsNotificationEnabled = true;
158 private boolean mIsExpandedViewEnabled = true;
159 private boolean mIsSystemBarNavigationEnabled = true;
160
161 private StatusBarHelper () {
162 }
163
164 /**
165 * Enables or disables auditory / vibrational alerts.
166 *
167 * (We disable these any time a voice call is active, regardless
168 * of whether or not the in-call UI is visible.)
169 */
170 public void enableNotificationAlerts(boolean enable) {
171 if (mIsNotificationEnabled != enable) {
172 mIsNotificationEnabled = enable;
173 updateStatusBar();
174 }
175 }
176
177 /**
178 * Enables or disables the expanded view of the status bar
179 * (i.e. the ability to pull down the "notification windowshade").
180 *
181 * (This feature is disabled by the InCallScreen while the in-call
182 * UI is active.)
183 */
184 public void enableExpandedView(boolean enable) {
185 if (mIsExpandedViewEnabled != enable) {
186 mIsExpandedViewEnabled = enable;
187 updateStatusBar();
188 }
189 }
190
191 /**
192 * Enables or disables the navigation via the system bar (the
193 * "soft buttons" at the bottom of the screen)
194 *
195 * (This feature is disabled while an incoming call is ringing,
196 * because it's easy to accidentally touch the system bar while
197 * pulling the phone out of your pocket.)
198 */
199 public void enableSystemBarNavigation(boolean enable) {
200 if (mIsSystemBarNavigationEnabled != enable) {
201 mIsSystemBarNavigationEnabled = enable;
202 updateStatusBar();
203 }
204 }
205
206 /**
207 * Updates the status bar to reflect the current desired state.
208 */
209 private void updateStatusBar() {
210 int state = StatusBarManager.DISABLE_NONE;
211
212 if (!mIsExpandedViewEnabled) {
213 state |= StatusBarManager.DISABLE_EXPAND;
214 }
215 if (!mIsNotificationEnabled) {
216 state |= StatusBarManager.DISABLE_NOTIFICATION_ALERTS;
217 }
218 if (!mIsSystemBarNavigationEnabled) {
219 // Disable *all* possible navigation via the system bar.
220 state |= StatusBarManager.DISABLE_HOME;
221 state |= StatusBarManager.DISABLE_RECENT;
222 state |= StatusBarManager.DISABLE_BACK;
Christine Chenb685f172013-09-25 18:32:59 -0700223 state |= StatusBarManager.DISABLE_SEARCH;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224 }
225
226 if (DBG) log("updateStatusBar: state = 0x" + Integer.toHexString(state));
227 mStatusBarManager.disable(state);
228 }
229 }
230
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700231 /** The projection to use when querying the phones table */
232 static final String[] PHONES_PROJECTION = new String[] {
233 PhoneLookup.NUMBER,
234 PhoneLookup.DISPLAY_NAME,
235 PhoneLookup._ID
236 };
237
238 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239 * Updates the message waiting indicator (voicemail) notification.
240 *
241 * @param visible true if there are messages waiting
242 */
243 /* package */ void updateMwi(boolean visible) {
244 if (DBG) log("updateMwi(): " + visible);
245
Andrew Leea82b8202014-11-21 16:18:28 -0800246 if (!PhoneGlobals.sVoiceCapable) {
247 // Do not show the message waiting indicator on devices which are not voice capable.
248 // These events *should* be blocked at the telephony layer for such devices.
249 Log.w(LOG_TAG, "Called updateMwi() on non-voice-capable device! Ignoring...");
250 return;
251 }
252
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253 if (visible) {
254 int resId = android.R.drawable.stat_notify_voicemail;
255
256 // This Notification can get a lot fancier once we have more
257 // information about the current voicemail messages.
258 // (For example, the current voicemail system can't tell
259 // us the caller-id or timestamp of a message, or tell us the
260 // message count.)
261
262 // But for now, the UI is ultra-simple: if the MWI indication
263 // is supposed to be visible, just show a single generic
264 // notification.
265
266 String notificationTitle = mContext.getString(R.string.notification_voicemail_title);
267 String vmNumber = mPhone.getVoiceMailNumber();
268 if (DBG) log("- got vm number: '" + vmNumber + "'");
269
Andrew Leea82b8202014-11-21 16:18:28 -0800270 // The voicemail number may be null because:
271 // (1) This phone has no voicemail number.
272 // (2) This phone has a voicemail number, but the SIM isn't ready yet. This may
273 // happen when the device first boots if we get a MWI notification when we
274 // register on the network before the SIM has loaded. In this case, the
275 // SubscriptionListener this class registers on the SubscriptionManager will
276 // call this method again once the SIM is loaded.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277 if ((vmNumber == null) && !mPhone.getIccRecordsLoaded()) {
278 if (DBG) log("- Null vm number: SIM records not loaded (yet)...");
Andrew Leea82b8202014-11-21 16:18:28 -0800279 return;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280 }
281
282 if (TelephonyCapabilities.supportsVoiceMessageCount(mPhone)) {
283 int vmCount = mPhone.getVoiceMessageCount();
284 String titleFormat = mContext.getString(R.string.notification_voicemail_title_count);
285 notificationTitle = String.format(titleFormat, vmCount);
286 }
287
288 String notificationText;
289 if (TextUtils.isEmpty(vmNumber)) {
290 notificationText = mContext.getString(
291 R.string.notification_voicemail_no_vm_number);
292 } else {
293 notificationText = String.format(
294 mContext.getString(R.string.notification_voicemail_text_format),
295 PhoneNumberUtils.formatNumber(vmNumber));
296 }
297
298 Intent intent = new Intent(Intent.ACTION_CALL,
Jay Shrauner137458b2014-09-05 14:27:25 -0700299 Uri.fromParts(PhoneAccount.SCHEME_VOICEMAIL, "", null));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300 PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
Andrew Lee8d66d812014-11-24 14:54:02 -0800301 Uri ringtoneUri = VoicemailNotificationSettingsUtil.getRingtoneUri(mContext);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700302
303 Notification.Builder builder = new Notification.Builder(mContext);
304 builder.setSmallIcon(resId)
305 .setWhen(System.currentTimeMillis())
306 .setContentTitle(notificationTitle)
307 .setContentText(notificationText)
308 .setContentIntent(pendingIntent)
Yorke Leeacb5f742014-08-19 09:08:42 -0700309 .setSound(ringtoneUri)
Andrew Lee99d0ac22014-10-10 13:18:04 -0700310 .setColor(mContext.getResources().getColor(R.color.dialer_theme_color))
311 .setOngoing(true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312
Andrew Lee8d66d812014-11-24 14:54:02 -0800313 if (VoicemailNotificationSettingsUtil.isVibrationEnabled(mContext)) {
Andrew Lee99d0ac22014-10-10 13:18:04 -0700314 builder.setDefaults(Notification.DEFAULT_VIBRATE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315 }
Andrew Lee99d0ac22014-10-10 13:18:04 -0700316
317 final Notification notification = builder.build();
318 List<UserInfo> users = mUserManager.getUsers(true);
319 for (int i = 0; i < users.size(); i++) {
Yorke Lee047b1f92014-10-24 10:22:41 -0700320 final UserInfo user = users.get(i);
321 final UserHandle userHandle = user.getUserHandle();
Andrew Lee99d0ac22014-10-10 13:18:04 -0700322 if (!mUserManager.hasUserRestriction(
Yorke Lee047b1f92014-10-24 10:22:41 -0700323 UserManager.DISALLOW_OUTGOING_CALLS, userHandle)
324 && !user.isManagedProfile()) {
Andrew Lee99d0ac22014-10-10 13:18:04 -0700325 mNotificationManager.notifyAsUser(
326 null /* tag */, VOICEMAIL_NOTIFICATION, notification, userHandle);
327 }
328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329 } else {
Andrew Lee99d0ac22014-10-10 13:18:04 -0700330 mNotificationManager.cancelAsUser(
331 null /* tag */, VOICEMAIL_NOTIFICATION, UserHandle.ALL);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 }
333 }
334
335 /**
336 * Updates the message call forwarding indicator notification.
337 *
338 * @param visible true if there are messages waiting
339 */
340 /* package */ void updateCfi(boolean visible) {
341 if (DBG) log("updateCfi(): " + visible);
342 if (visible) {
343 // If Unconditional Call Forwarding (forward all calls) for VOICE
344 // is enabled, just show a notification. We'll default to expanded
345 // view for now, so the there is less confusion about the icon. If
346 // it is deemed too weird to have CF indications as expanded views,
347 // then we'll flip the flag back.
348
349 // TODO: We may want to take a look to see if the notification can
350 // display the target to forward calls to. This will require some
351 // effort though, since there are multiple layers of messages that
352 // will need to propagate that information.
353
Andrew Lee99d0ac22014-10-10 13:18:04 -0700354 Notification.Builder builder = new Notification.Builder(mContext)
355 .setSmallIcon(R.drawable.stat_sys_phone_call_forward)
356 .setContentTitle(mContext.getString(R.string.labelCF))
357 .setContentText(mContext.getString(R.string.sum_cfu_enabled_indicator))
358 .setShowWhen(false)
359 .setOngoing(true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360
Andrew Lee99d0ac22014-10-10 13:18:04 -0700361 Intent intent = new Intent(Intent.ACTION_MAIN);
362 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
363 intent.setClassName("com.android.phone", "com.android.phone.CallFeaturesSetting");
364 PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
365
366 List<UserInfo> users = mUserManager.getUsers(true);
367 for (int i = 0; i < users.size(); i++) {
Yorke Lee3faa5942014-11-05 16:50:04 -0800368 final UserInfo user = users.get(i);
369 if (user.isManagedProfile()) {
370 continue;
371 }
372 UserHandle userHandle = user.getUserHandle();
Andrew Lee99d0ac22014-10-10 13:18:04 -0700373 builder.setContentIntent(userHandle.isOwner() ? contentIntent : null);
374 mNotificationManager.notifyAsUser(
375 null /* tag */, CALL_FORWARD_NOTIFICATION, builder.build(), userHandle);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377 } else {
Andrew Lee99d0ac22014-10-10 13:18:04 -0700378 mNotificationManager.cancelAsUser(
379 null /* tag */, CALL_FORWARD_NOTIFICATION, UserHandle.ALL);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 }
381 }
382
383 /**
384 * Shows the "data disconnected due to roaming" notification, which
385 * appears when you lose data connectivity because you're roaming and
386 * you have the "data roaming" feature turned off.
387 */
388 /* package */ void showDataDisconnectedRoaming() {
389 if (DBG) log("showDataDisconnectedRoaming()...");
390
391 // "Mobile network settings" screen / dialog
392 Intent intent = new Intent(mContext, com.android.phone.MobileNetworkSettings.class);
Andrew Lee99d0ac22014-10-10 13:18:04 -0700393 PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394
395 final CharSequence contentText = mContext.getText(R.string.roaming_reenable_message);
396
Andrew Lee99d0ac22014-10-10 13:18:04 -0700397 final Notification.Builder builder = new Notification.Builder(mContext)
398 .setSmallIcon(android.R.drawable.stat_sys_warning)
399 .setContentTitle(mContext.getText(R.string.roaming))
400 .setColor(mContext.getResources().getColor(R.color.dialer_theme_color))
401 .setContentText(contentText);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402
Andrew Lee99d0ac22014-10-10 13:18:04 -0700403 List<UserInfo> users = mUserManager.getUsers(true);
404 for (int i = 0; i < users.size(); i++) {
Yorke Lee3faa5942014-11-05 16:50:04 -0800405 final UserInfo user = users.get(i);
406 if (user.isManagedProfile()) {
407 continue;
408 }
409 UserHandle userHandle = user.getUserHandle();
Andrew Lee99d0ac22014-10-10 13:18:04 -0700410 builder.setContentIntent(userHandle.isOwner() ? contentIntent : null);
411 final Notification notif =
412 new Notification.BigTextStyle(builder).bigText(contentText).build();
413 mNotificationManager.notifyAsUser(
414 null /* tag */, DATA_DISCONNECTED_ROAMING_NOTIFICATION, notif, userHandle);
415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 }
417
418 /**
419 * Turns off the "data disconnected due to roaming" notification.
420 */
421 /* package */ void hideDataDisconnectedRoaming() {
422 if (DBG) log("hideDataDisconnectedRoaming()...");
423 mNotificationManager.cancel(DATA_DISCONNECTED_ROAMING_NOTIFICATION);
424 }
425
426 /**
427 * Display the network selection "no service" notification
428 * @param operator is the numeric operator number
429 */
430 private void showNetworkSelection(String operator) {
431 if (DBG) log("showNetworkSelection(" + operator + ")...");
432
Andrew Lee99d0ac22014-10-10 13:18:04 -0700433 Notification.Builder builder = new Notification.Builder(mContext)
434 .setSmallIcon(android.R.drawable.stat_sys_warning)
435 .setContentTitle(mContext.getString(R.string.notification_network_selection_title))
436 .setContentText(
437 mContext.getString(R.string.notification_network_selection_text, operator))
438 .setShowWhen(false)
439 .setOngoing(true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440
441 // create the target network operators settings intent
442 Intent intent = new Intent(Intent.ACTION_MAIN);
443 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
444 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
445 // Use NetworkSetting to handle the selection intent
446 intent.setComponent(new ComponentName("com.android.phone",
447 "com.android.phone.NetworkSetting"));
Andrew Lee99d0ac22014-10-10 13:18:04 -0700448 PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449
Andrew Lee99d0ac22014-10-10 13:18:04 -0700450 List<UserInfo> users = mUserManager.getUsers(true);
451 for (int i = 0; i < users.size(); i++) {
Yorke Lee3faa5942014-11-05 16:50:04 -0800452 final UserInfo user = users.get(i);
453 if (user.isManagedProfile()) {
454 continue;
455 }
456 UserHandle userHandle = user.getUserHandle();
Andrew Lee99d0ac22014-10-10 13:18:04 -0700457 builder.setContentIntent(userHandle.isOwner() ? contentIntent : null);
458 mNotificationManager.notifyAsUser(
459 null /* tag */,
460 SELECTED_OPERATOR_FAIL_NOTIFICATION,
461 builder.build(),
462 userHandle);
463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700464 }
465
466 /**
467 * Turn off the network selection "no service" notification
468 */
469 private void cancelNetworkSelection() {
470 if (DBG) log("cancelNetworkSelection()...");
Andrew Lee99d0ac22014-10-10 13:18:04 -0700471 mNotificationManager.cancelAsUser(
472 null /* tag */, SELECTED_OPERATOR_FAIL_NOTIFICATION, UserHandle.ALL);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 }
474
475 /**
476 * Update notification about no service of user selected operator
477 *
478 * @param serviceState Phone service state
479 */
480 void updateNetworkSelection(int serviceState) {
481 if (TelephonyCapabilities.supportsNetworkSelection(mPhone)) {
482 // get the shared preference of network_selection.
483 // empty is auto mode, otherwise it is the operator alpha name
484 // in case there is no operator name, check the operator numeric
485 SharedPreferences sp =
486 PreferenceManager.getDefaultSharedPreferences(mContext);
487 String networkSelection =
488 sp.getString(PhoneBase.NETWORK_SELECTION_NAME_KEY, "");
489 if (TextUtils.isEmpty(networkSelection)) {
490 networkSelection =
491 sp.getString(PhoneBase.NETWORK_SELECTION_KEY, "");
492 }
493
494 if (DBG) log("updateNetworkSelection()..." + "state = " +
495 serviceState + " new network " + networkSelection);
496
497 if (serviceState == ServiceState.STATE_OUT_OF_SERVICE
498 && !TextUtils.isEmpty(networkSelection)) {
499 if (!mSelectedUnavailableNotify) {
500 showNetworkSelection(networkSelection);
501 mSelectedUnavailableNotify = true;
502 }
503 } else {
504 if (mSelectedUnavailableNotify) {
505 cancelNetworkSelection();
506 mSelectedUnavailableNotify = false;
507 }
508 }
509 }
510 }
511
512 /* package */ void postTransientNotification(int notifyId, CharSequence msg) {
513 if (mToast != null) {
514 mToast.cancel();
515 }
516
517 mToast = Toast.makeText(mContext, msg, Toast.LENGTH_LONG);
518 mToast.show();
519 }
520
521 private void log(String msg) {
522 Log.d(LOG_TAG, msg);
523 }
524}