17d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon/*
27d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * Copyright (C) 2006 The Android Open Source Project
37d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon *
47d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * Licensed under the Apache License, Version 2.0 (the "License");
57d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * you may not use this file except in compliance with the License.
67d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * You may obtain a copy of the License at
77d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon *
87d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon *      http://www.apache.org/licenses/LICENSE-2.0
97d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon *
107d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * Unless required by applicable law or agreed to in writing, software
117d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * distributed under the License is distributed on an "AS IS" BASIS,
127d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * See the License for the specific language governing permissions and
147d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * limitations under the License.
157d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon */
167d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
177d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonpackage com.android.phone;
187d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
197d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.app.Notification;
207d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.app.NotificationManager;
217d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.app.PendingIntent;
227d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.app.StatusBarManager;
237d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.content.ComponentName;
247d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.content.Context;
257d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.content.Intent;
267d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.content.SharedPreferences;
2799d0ac2c693849e959601a275128a739569d2efbAndrew Leeimport android.content.pm.UserInfo;
28b4a9270ef0cd337732e6e88d9cf4ff5f72fb94d2Nancy Chenimport android.content.res.Resources;
297d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.net.Uri;
30c31f1f32963534763aaf82ae2544f3a94f13edcaJonathan Basseriimport android.os.PersistableBundle;
317d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.os.SystemProperties;
3299d0ac2c693849e959601a275128a739569d2efbAndrew Leeimport android.os.UserHandle;
3399d0ac2c693849e959601a275128a739569d2efbAndrew Leeimport android.os.UserManager;
347d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.preference.PreferenceManager;
357d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.provider.ContactsContract.PhoneLookup;
364d45d1cf58a2003378fd35912d6d73a00001bf06Tyler Gunnimport android.telecom.PhoneAccount;
37d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Leeimport android.telecom.PhoneAccountHandle;
38d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Leeimport android.telecom.TelecomManager;
393649bdb5813200904d4e887306dfebb1a0beffa8Jonathan Basseriimport android.telephony.CarrierConfigManager;
407d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.telephony.PhoneNumberUtils;
417d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.telephony.ServiceState;
422fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Leeimport android.telephony.SubscriptionInfo;
43a82b820e69f41585c3a2b76678040b93fdf54886Andrew Leeimport android.telephony.SubscriptionManager;
44d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Leeimport android.telephony.TelephonyManager;
457d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.text.TextUtils;
469c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunnimport android.util.ArrayMap;
477d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.util.Log;
487d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.widget.Toast;
497d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
507d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport com.android.internal.telephony.Phone;
517d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport com.android.internal.telephony.TelephonyCapabilities;
52bf07f76dd57457da159b5d5504e391afbb4a3592Andrew Leeimport com.android.phone.settings.VoicemailSettingsActivity;
532cf7f2935c71b0ddbdda86fa6bc18b33db2dbf99Nancy Chenimport com.android.phone.vvm.omtp.sync.VoicemailStatusQueryHelper;
548d66d81ad89e66ccaf688e896286e2a06307a554Andrew Leeimport com.android.phone.settings.VoicemailNotificationSettingsUtil;
557d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
569c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunnimport java.util.Iterator;
5799d0ac2c693849e959601a275128a739569d2efbAndrew Leeimport java.util.List;
589c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunnimport java.util.Set;
5999d0ac2c693849e959601a275128a739569d2efbAndrew Lee
607d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon/**
617d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * NotificationManager-related utility code for the Phone app.
627d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon *
637d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * This is a singleton object which acts as the interface to the
647d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * framework's NotificationManager, and is used to display status bar
657d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * icons and control other status bar-related behavior.
667d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon *
677d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * @see PhoneGlobals.notificationMgr
687d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon */
69312b9c9112948c8ca7f74ea91b5e2585a66482c9Chiao Chengpublic class NotificationMgr {
70a82b820e69f41585c3a2b76678040b93fdf54886Andrew Lee    private static final String LOG_TAG = NotificationMgr.class.getSimpleName();
717d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    private static final boolean DBG =
727d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
737d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    // Do not check in with VDBG = true, since that may write PII to the system log.
747d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    private static final boolean VDBG = false;
757d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
767d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    // notification types
77f68db2ef27f3bdf14f0053c46d73df910bd394f2Santos Cordon    static final int MMI_NOTIFICATION = 1;
78f68db2ef27f3bdf14f0053c46d73df910bd394f2Santos Cordon    static final int NETWORK_SELECTION_NOTIFICATION = 2;
79f68db2ef27f3bdf14f0053c46d73df910bd394f2Santos Cordon    static final int VOICEMAIL_NOTIFICATION = 3;
80f68db2ef27f3bdf14f0053c46d73df910bd394f2Santos Cordon    static final int CALL_FORWARD_NOTIFICATION = 4;
81f68db2ef27f3bdf14f0053c46d73df910bd394f2Santos Cordon    static final int DATA_DISCONNECTED_ROAMING_NOTIFICATION = 5;
82f68db2ef27f3bdf14f0053c46d73df910bd394f2Santos Cordon    static final int SELECTED_OPERATOR_FAIL_NOTIFICATION = 6;
837d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
847d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    /** The singleton NotificationMgr instance. */
857d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    private static NotificationMgr sInstance;
867d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
877d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    private PhoneGlobals mApp;
887d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    private Phone mPhone;
897d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
907d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    private Context mContext;
917d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    private NotificationManager mNotificationManager;
925dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee    private final ComponentName mNotificationComponent;
937d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    private StatusBarManager mStatusBarManager;
9499d0ac2c693849e959601a275128a739569d2efbAndrew Lee    private UserManager mUserManager;
957d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    private Toast mToast;
962fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee    private SubscriptionManager mSubscriptionManager;
97d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee    private TelecomManager mTelecomManager;
98d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee    private TelephonyManager mTelephonyManager;
997d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
1007d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    // used to track the notification of selected network unavailable
1017d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    private boolean mSelectedUnavailableNotify = false;
1027d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
1039c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn    // used to track whether the message waiting indicator is visible, per subscription id.
1049c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn    private ArrayMap<Integer, Boolean> mMwiVisible = new ArrayMap<Integer, Boolean>();
1059c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn
1067d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    /**
1077d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * Private constructor (this is a singleton).
108f68db2ef27f3bdf14f0053c46d73df910bd394f2Santos Cordon     * @see #init(PhoneGlobals)
1097d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     */
1107d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    private NotificationMgr(PhoneGlobals app) {
1117d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        mApp = app;
1127d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        mContext = app;
1137d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        mNotificationManager =
1147d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon                (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
1157d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        mStatusBarManager =
1167d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon                (StatusBarManager) app.getSystemService(Context.STATUS_BAR_SERVICE);
11799d0ac2c693849e959601a275128a739569d2efbAndrew Lee        mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
118dcf40a9cc562d95f826123d8d670262c8d15e7bdStuart Scott        mPhone = app.mCM.getDefaultPhone();
1192fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee        mSubscriptionManager = SubscriptionManager.from(mContext);
120d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee        mTelecomManager = TelecomManager.from(mContext);
121d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee        mTelephonyManager = (TelephonyManager) app.getSystemService(Context.TELEPHONY_SERVICE);
1225dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee
1235dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee        final String notificationComponent = mContext.getString(
1245dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                R.string.config_customVoicemailComponent);
1255dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee
1265dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee        mNotificationComponent = notificationComponent != null
1275dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                ? ComponentName.unflattenFromString(notificationComponent) : null;
1287d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    }
1297d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
1307d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    /**
1317d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * Initialize the singleton NotificationMgr instance.
1327d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     *
1337d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * This is only done once, at startup, from PhoneApp.onCreate().
1347d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * From then on, the NotificationMgr instance is available via the
1357d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * PhoneApp's public "notificationMgr" field, which is why there's no
1367d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * getInstance() method here.
1377d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     */
1387d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    /* package */ static NotificationMgr init(PhoneGlobals app) {
1397d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        synchronized (NotificationMgr.class) {
1407d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            if (sInstance == null) {
1417d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon                sInstance = new NotificationMgr(app);
1427d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            } else {
1437d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon                Log.wtf(LOG_TAG, "init() called multiple times!  sInstance = " + sInstance);
1447d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            }
1457d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            return sInstance;
1467d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        }
1477d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    }
1487d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
1497d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    /** The projection to use when querying the phones table */
1507d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    static final String[] PHONES_PROJECTION = new String[] {
1517d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        PhoneLookup.NUMBER,
1527d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        PhoneLookup.DISPLAY_NAME,
1537d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        PhoneLookup._ID
1547d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    };
1557d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
1567d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    /**
1579c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn     * Re-creates the message waiting indicator (voicemail) notification if it is showing.  Used to
1589c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn     * refresh the voicemail intent on the indicator when the user changes it via the voicemail
1599c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn     * settings screen.  The voicemail notification sound is suppressed.
1609c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn     *
1619c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn     * @param subId The subscription Id.
1629c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn     */
1639c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn    /* package */ void refreshMwi(int subId) {
1649c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn        // In a single-sim device, subId can be -1 which means "no sub id".  In this case we will
1659c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn        // reference the single subid stored in the mMwiVisible map.
1669c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn        if (subId == SubscriptionInfoHelper.NO_SUB_ID) {
1679c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn            if (mMwiVisible.keySet().size() == 1) {
1689c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                Set<Integer> keySet = mMwiVisible.keySet();
1699c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                Iterator<Integer> keyIt = keySet.iterator();
1709c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                if (!keyIt.hasNext()) {
1719c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                    return;
1729c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                }
1739c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                subId = keyIt.next();
1749c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn            }
1759c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn        }
1769c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn        if (mMwiVisible.containsKey(subId)) {
1779c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn            boolean mwiVisible = mMwiVisible.get(subId);
1789c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn            if (mwiVisible) {
1799c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                updateMwi(subId, mwiVisible, false /* enableNotificationSound */);
1809c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn            }
1819c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn        }
1829c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn    }
1839c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn
1849c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn    /**
1857d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * Updates the message waiting indicator (voicemail) notification.
1867d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     *
1877d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * @param visible true if there are messages waiting
1887d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     */
1892fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee    /* package */ void updateMwi(int subId, boolean visible) {
1909c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn        updateMwi(subId, visible, true /* enableNotificationSound */);
1919c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn    }
1929c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn
1939c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn    /**
1949c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn     * Updates the message waiting indicator (voicemail) notification.
1959c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn     *
1969c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn     * @param subId the subId to update.
1979c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn     * @param visible true if there are messages waiting
1989c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn     * @param enableNotificationSound {@code true} if the notification sound should be played.
1999c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn     */
2009c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn    void updateMwi(int subId, boolean visible, boolean enableNotificationSound) {
201a82b820e69f41585c3a2b76678040b93fdf54886Andrew Lee        if (!PhoneGlobals.sVoiceCapable) {
202a82b820e69f41585c3a2b76678040b93fdf54886Andrew Lee            // Do not show the message waiting indicator on devices which are not voice capable.
203a82b820e69f41585c3a2b76678040b93fdf54886Andrew Lee            // These events *should* be blocked at the telephony layer for such devices.
204a82b820e69f41585c3a2b76678040b93fdf54886Andrew Lee            Log.w(LOG_TAG, "Called updateMwi() on non-voice-capable device! Ignoring...");
205a82b820e69f41585c3a2b76678040b93fdf54886Andrew Lee            return;
206a82b820e69f41585c3a2b76678040b93fdf54886Andrew Lee        }
207a82b820e69f41585c3a2b76678040b93fdf54886Andrew Lee
2082cf7f2935c71b0ddbdda86fa6bc18b33db2dbf99Nancy Chen        Phone phone = PhoneGlobals.getPhone(subId);
2092cf7f2935c71b0ddbdda86fa6bc18b33db2dbf99Nancy Chen        if (visible && phone != null) {
2102cf7f2935c71b0ddbdda86fa6bc18b33db2dbf99Nancy Chen            VoicemailStatusQueryHelper queryHelper = new VoicemailStatusQueryHelper(mContext);
2112cf7f2935c71b0ddbdda86fa6bc18b33db2dbf99Nancy Chen            PhoneAccountHandle phoneAccount = PhoneUtils.makePstnPhoneAccountHandle(phone);
2122cf7f2935c71b0ddbdda86fa6bc18b33db2dbf99Nancy Chen            if (queryHelper.isNotificationsChannelActive(phoneAccount)) {
2132cf7f2935c71b0ddbdda86fa6bc18b33db2dbf99Nancy Chen                Log.v(LOG_TAG, "Notifications channel active for visual voicemail, hiding mwi.");
2142cf7f2935c71b0ddbdda86fa6bc18b33db2dbf99Nancy Chen                visible = false;
2152cf7f2935c71b0ddbdda86fa6bc18b33db2dbf99Nancy Chen            }
2162cf7f2935c71b0ddbdda86fa6bc18b33db2dbf99Nancy Chen        }
2172cf7f2935c71b0ddbdda86fa6bc18b33db2dbf99Nancy Chen
21867a62a2dd4941b983ed92f53b330a7c902408c5dYorke Lee        Log.i(LOG_TAG, "updateMwi(): subId " + subId + " update to " + visible);
219f8ad78f133fc0841d2cd6947f5be3aa94cf2252eAndrew Lee        mMwiVisible.put(subId, visible);
220f8ad78f133fc0841d2cd6947f5be3aa94cf2252eAndrew Lee
2217d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        if (visible) {
2222fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee            if (phone == null) {
223d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee                Log.w(LOG_TAG, "Found null phone for: " + subId);
224d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee                return;
225d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee            }
226d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee
227d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee            SubscriptionInfo subInfo = mSubscriptionManager.getActiveSubscriptionInfo(subId);
228d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee            if (subInfo == null) {
229d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee                Log.w(LOG_TAG, "Found null subscription info for: " + subId);
2302fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee                return;
2312fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee            }
2322fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee
2337d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            int resId = android.R.drawable.stat_notify_voicemail;
2347d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
2357d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            // This Notification can get a lot fancier once we have more
2367d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            // information about the current voicemail messages.
2377d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            // (For example, the current voicemail system can't tell
2387d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            // us the caller-id or timestamp of a message, or tell us the
2397d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            // message count.)
2407d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
2417d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            // But for now, the UI is ultra-simple: if the MWI indication
2427d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            // is supposed to be visible, just show a single generic
2437d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            // notification.
2447d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
2457d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            String notificationTitle = mContext.getString(R.string.notification_voicemail_title);
2462fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee            String vmNumber = phone.getVoiceMailNumber();
2477d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            if (DBG) log("- got vm number: '" + vmNumber + "'");
2487d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
249a82b820e69f41585c3a2b76678040b93fdf54886Andrew Lee            // The voicemail number may be null because:
250a82b820e69f41585c3a2b76678040b93fdf54886Andrew Lee            //   (1) This phone has no voicemail number.
251a82b820e69f41585c3a2b76678040b93fdf54886Andrew Lee            //   (2) This phone has a voicemail number, but the SIM isn't ready yet. This may
252a82b820e69f41585c3a2b76678040b93fdf54886Andrew Lee            //       happen when the device first boots if we get a MWI notification when we
253a82b820e69f41585c3a2b76678040b93fdf54886Andrew Lee            //       register on the network before the SIM has loaded. In this case, the
2542fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee            //       SubscriptionListener in CallNotifier will update this once the SIM is loaded.
2552fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee            if ((vmNumber == null) && !phone.getIccRecordsLoaded()) {
2567d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon                if (DBG) log("- Null vm number: SIM records not loaded (yet)...");
257a82b820e69f41585c3a2b76678040b93fdf54886Andrew Lee                return;
2587d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            }
2597d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
2605dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            Integer vmCount = null;
2615dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee
2622fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee            if (TelephonyCapabilities.supportsVoiceMessageCount(phone)) {
2635dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                vmCount = phone.getVoiceMessageCount();
2647d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon                String titleFormat = mContext.getString(R.string.notification_voicemail_title_count);
2657d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon                notificationTitle = String.format(titleFormat, vmCount);
2667d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            }
2677d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
2689c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn            // This pathway only applies to PSTN accounts; only SIMS have subscription ids.
2699c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn            PhoneAccountHandle phoneAccountHandle = PhoneUtils.makePstnPhoneAccountHandle(phone);
2709c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn
2719c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn            Intent intent;
2727d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            String notificationText;
2735dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            boolean isSettingsIntent = TextUtils.isEmpty(vmNumber);
2745dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee
2755dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            if (isSettingsIntent) {
2769c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                notificationText = mContext.getString(
2779c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                        R.string.notification_voicemail_no_vm_number);
2789c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn
2799c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                // If the voicemail number if unknown, instead of calling voicemail, take the user
2809c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                // to the voicemail settings.
2819c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                notificationText = mContext.getString(
2829c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                        R.string.notification_voicemail_no_vm_number);
283bf07f76dd57457da159b5d5504e391afbb4a3592Andrew Lee                intent = new Intent(VoicemailSettingsActivity.ACTION_ADD_VOICEMAIL);
2849c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                intent.putExtra(SubscriptionInfoHelper.SUB_ID_EXTRA, subId);
285bf07f76dd57457da159b5d5504e391afbb4a3592Andrew Lee                intent.setClass(mContext, VoicemailSettingsActivity.class);
2867d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            } else {
2879c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                if (mTelephonyManager.getPhoneCount() > 1) {
2889c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                    notificationText = subInfo.getDisplayName().toString();
289d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee                } else {
290d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee                    notificationText = String.format(
291d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee                            mContext.getString(R.string.notification_voicemail_text_format),
292d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee                            PhoneNumberUtils.formatNumber(vmNumber));
293d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee                }
2949c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                intent = new Intent(
2959c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                        Intent.ACTION_CALL, Uri.fromParts(PhoneAccount.SCHEME_VOICEMAIL, "",
2963649bdb5813200904d4e887306dfebb1a0beffa8Jonathan Basseri                                null));
2979c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);
2987d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            }
2997d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
3002fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee            PendingIntent pendingIntent =
3012fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee                    PendingIntent.getActivity(mContext, subId /* requestCode */, intent, 0);
3029c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn            Uri ringtoneUri = null;
3039c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn
3049c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn            if (enableNotificationSound) {
3059c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn                ringtoneUri = VoicemailNotificationSettingsUtil.getRingtoneUri(mPhone);
3069c1071fdb42947afd215b0f4f3e81f871b1ff581Tyler Gunn            }
3077d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
308b4a9270ef0cd337732e6e88d9cf4ff5f72fb94d2Nancy Chen            Resources res = mContext.getResources();
309c31f1f32963534763aaf82ae2544f3a94f13edcaJonathan Basseri            PersistableBundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(
3103649bdb5813200904d4e887306dfebb1a0beffa8Jonathan Basseri                    mPhone.getSubId());
3117d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            Notification.Builder builder = new Notification.Builder(mContext);
3127d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            builder.setSmallIcon(resId)
3137d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon                    .setWhen(System.currentTimeMillis())
314d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee                    .setColor(subInfo.getIconTint())
3157d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon                    .setContentTitle(notificationTitle)
3167d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon                    .setContentText(notificationText)
3177d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon                    .setContentIntent(pendingIntent)
318acb5f74aff9bd9e15ec21f421e79bc555faaff20Yorke Lee                    .setSound(ringtoneUri)
319b4a9270ef0cd337732e6e88d9cf4ff5f72fb94d2Nancy Chen                    .setColor(res.getColor(R.color.dialer_theme_color))
3203649bdb5813200904d4e887306dfebb1a0beffa8Jonathan Basseri                    .setOngoing(carrierConfig.getBoolean(
3219504c6b5c5c7072f72d8a9e6df59dbda8a6ccbe4Jonathan Basseri                            CarrierConfigManager.KEY_VOICEMAIL_NOTIFICATION_PERSISTENT_BOOL));
3227d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
3232fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee            if (VoicemailNotificationSettingsUtil.isVibrationEnabled(phone)) {
32499d0ac2c693849e959601a275128a739569d2efbAndrew Lee                builder.setDefaults(Notification.DEFAULT_VIBRATE);
32599d0ac2c693849e959601a275128a739569d2efbAndrew Lee            }
32699d0ac2c693849e959601a275128a739569d2efbAndrew Lee
32799d0ac2c693849e959601a275128a739569d2efbAndrew Lee            final Notification notification = builder.build();
32899d0ac2c693849e959601a275128a739569d2efbAndrew Lee            List<UserInfo> users = mUserManager.getUsers(true);
32999d0ac2c693849e959601a275128a739569d2efbAndrew Lee            for (int i = 0; i < users.size(); i++) {
330047b1f9f0af3c9a0a285eb944b409a785040707cYorke Lee                final UserInfo user = users.get(i);
331047b1f9f0af3c9a0a285eb944b409a785040707cYorke Lee                final UserHandle userHandle = user.getUserHandle();
33299d0ac2c693849e959601a275128a739569d2efbAndrew Lee                if (!mUserManager.hasUserRestriction(
333047b1f9f0af3c9a0a285eb944b409a785040707cYorke Lee                        UserManager.DISALLOW_OUTGOING_CALLS, userHandle)
3343649bdb5813200904d4e887306dfebb1a0beffa8Jonathan Basseri                        && !user.isManagedProfile()) {
3355dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                    if (!sendNotificationCustomComponent(vmCount, vmNumber, pendingIntent,
3365dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                            isSettingsIntent)) {
3375dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                        mNotificationManager.notifyAsUser(
3385dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                                Integer.toString(subId) /* tag */,
3395dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                                VOICEMAIL_NOTIFICATION,
3405dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                                notification,
3415dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                                userHandle);
3425dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                    }
34399d0ac2c693849e959601a275128a739569d2efbAndrew Lee                }
3447d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            }
3457d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        } else {
3465dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            if (!sendNotificationCustomComponent(0, null, null, false)) {
3475dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                mNotificationManager.cancelAsUser(
3485dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                        Integer.toString(subId) /* tag */,
3495dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                        VOICEMAIL_NOTIFICATION,
3505dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                        UserHandle.ALL);
3515dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            }
3525dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee        }
3535dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee    }
3545dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee
3555dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee    /**
3565dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee     * Sends a broadcast with the voicemail notification information to a custom component to
3575dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee     * handle. This method is also used to indicate to the custom component when to clear the
3585dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee     * notification. A pending intent can be passed to the custom component to indicate an action to
3595dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee     * be taken as it would by a notification produced in this class.
3605dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee     * @param count The number of pending voicemail messages to indicate on the notification. A
3615dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee     *              Value of 0 is passed here to indicate that the notification should be cleared.
3625dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee     * @param number The voicemail phone number if specified.
3635dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee     * @param pendingIntent The intent that should be passed as the action to be taken.
3645dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee     * @param isSettingsIntent {@code true} to indicate the pending intent is to launch settings.
3655dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee     *                         otherwise, {@code false} to indicate the intent launches voicemail.
3665dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee     * @return {@code true} if a custom component was notified of the notification.
3675dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee     */
3685dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee    private boolean sendNotificationCustomComponent(Integer count, String number,
3695dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            PendingIntent pendingIntent, boolean isSettingsIntent) {
3705dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee        if (mNotificationComponent != null) {
3715dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            Intent intent = new Intent();
3725dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            intent.setFlags(Intent.FLAG_RECEIVER_FOREGROUND);
3735dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            intent.setComponent(mNotificationComponent);
3745dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            intent.setAction(TelephonyManager.ACTION_SHOW_VOICEMAIL_NOTIFICATION);
3755dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee
3765dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            if (count != null) {
3775dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                intent.putExtra(TelephonyManager.EXTRA_NOTIFICATION_COUNT, count);
3785dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            }
3795dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee
3805dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            // Additional information about the voicemail notification beyond the count is only
3815dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            // present when the count not specified or greater than 0. The value of 0 represents
3825dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            // clearing the notification, which does not require additional information.
3835dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            if (count == null || count > 0) {
3845dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                if (!TextUtils.isEmpty(number)) {
3855dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                    intent.putExtra(TelephonyManager.EXTRA_VOICEMAIL_NUMBER, number);
3865dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                }
3875dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee
3885dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                if (pendingIntent != null) {
3895dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                    intent.putExtra(isSettingsIntent
3905dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                            ? TelephonyManager.EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT
3915dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                            : TelephonyManager.EXTRA_CALL_VOICEMAIL_INTENT,
3925dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                            pendingIntent);
3935dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee                }
3945dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            }
3955dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee
3965dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            mContext.sendBroadcast(intent);
3975dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee            return true;
3987d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        }
3995dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee
4005dc90848c184a5fd35ad5b7c0e9aa1d50911934bBryce Lee        return false;
4017d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    }
4027d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
4037d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    /**
4047d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * Updates the message call forwarding indicator notification.
4057d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     *
4067d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * @param visible true if there are messages waiting
4077d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     */
4082fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee    /* package */ void updateCfi(int subId, boolean visible) {
4097d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        if (DBG) log("updateCfi(): " + visible);
4107d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        if (visible) {
4117d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            // If Unconditional Call Forwarding (forward all calls) for VOICE
4127d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            // is enabled, just show a notification.  We'll default to expanded
4137d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            // view for now, so the there is less confusion about the icon.  If
4147d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            // it is deemed too weird to have CF indications as expanded views,
4157d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            // then we'll flip the flag back.
4167d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
4177d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            // TODO: We may want to take a look to see if the notification can
4187d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            // display the target to forward calls to.  This will require some
4197d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            // effort though, since there are multiple layers of messages that
4207d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            // will need to propagate that information.
4217d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
422d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee            SubscriptionInfo subInfo = mSubscriptionManager.getActiveSubscriptionInfo(subId);
423d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee            if (subInfo == null) {
424d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee                Log.w(LOG_TAG, "Found null subscription info for: " + subId);
425d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee                return;
426d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee            }
427d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee
428d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee            String notificationTitle;
429d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee            if (mTelephonyManager.getPhoneCount() > 1) {
430d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee                notificationTitle = subInfo.getDisplayName().toString();
431d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee            } else {
432d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee                notificationTitle = mContext.getString(R.string.labelCF);
433d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee            }
434d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee
43599d0ac2c693849e959601a275128a739569d2efbAndrew Lee            Notification.Builder builder = new Notification.Builder(mContext)
43699d0ac2c693849e959601a275128a739569d2efbAndrew Lee                    .setSmallIcon(R.drawable.stat_sys_phone_call_forward)
437d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee                    .setColor(subInfo.getIconTint())
438d5165b05c851ecd47d330b600ed2768e0db8b9d1Andrew Lee                    .setContentTitle(notificationTitle)
43999d0ac2c693849e959601a275128a739569d2efbAndrew Lee                    .setContentText(mContext.getString(R.string.sum_cfu_enabled_indicator))
44099d0ac2c693849e959601a275128a739569d2efbAndrew Lee                    .setShowWhen(false)
44199d0ac2c693849e959601a275128a739569d2efbAndrew Lee                    .setOngoing(true);
44299d0ac2c693849e959601a275128a739569d2efbAndrew Lee
44399d0ac2c693849e959601a275128a739569d2efbAndrew Lee            Intent intent = new Intent(Intent.ACTION_MAIN);
4442fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
44599d0ac2c693849e959601a275128a739569d2efbAndrew Lee            intent.setClassName("com.android.phone", "com.android.phone.CallFeaturesSetting");
4462fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee            SubscriptionInfoHelper.addExtrasToIntent(
4472fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee                    intent, mSubscriptionManager.getActiveSubscriptionInfo(subId));
4482fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee            PendingIntent contentIntent =
4492fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee                    PendingIntent.getActivity(mContext, subId /* requestCode */, intent, 0);
45099d0ac2c693849e959601a275128a739569d2efbAndrew Lee
45199d0ac2c693849e959601a275128a739569d2efbAndrew Lee            List<UserInfo> users = mUserManager.getUsers(true);
45299d0ac2c693849e959601a275128a739569d2efbAndrew Lee            for (int i = 0; i < users.size(); i++) {
4533faa594099e79c7fa7ac6e4c974e435d2cf4d471Yorke Lee                final UserInfo user = users.get(i);
4543faa594099e79c7fa7ac6e4c974e435d2cf4d471Yorke Lee                if (user.isManagedProfile()) {
4553faa594099e79c7fa7ac6e4c974e435d2cf4d471Yorke Lee                    continue;
4563faa594099e79c7fa7ac6e4c974e435d2cf4d471Yorke Lee                }
4573faa594099e79c7fa7ac6e4c974e435d2cf4d471Yorke Lee                UserHandle userHandle = user.getUserHandle();
4583105e9a01b1cf782e11fd1a6cb3bcefc5633ef67Xiaohui Chen                builder.setContentIntent(user.isAdmin() ? contentIntent : null);
4592fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee                mNotificationManager.notifyAsUser(
4602fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee                        Integer.toString(subId) /* tag */,
4612fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee                        CALL_FORWARD_NOTIFICATION,
4622fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee                        builder.build(),
4632fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee                        userHandle);
4647d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            }
4657d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        } else {
46699d0ac2c693849e959601a275128a739569d2efbAndrew Lee            mNotificationManager.cancelAsUser(
4672fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee                    Integer.toString(subId) /* tag */,
4682fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee                    CALL_FORWARD_NOTIFICATION,
4692fcb6c372c76a48b7af8f9b0dc7fd518698bbf77Andrew Lee                    UserHandle.ALL);
4707d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        }
4717d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    }
4727d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
4737d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    /**
4747d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * Shows the "data disconnected due to roaming" notification, which
4757d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * appears when you lose data connectivity because you're roaming and
4767d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * you have the "data roaming" feature turned off.
4777d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     */
4787d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    /* package */ void showDataDisconnectedRoaming() {
4797d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        if (DBG) log("showDataDisconnectedRoaming()...");
4807d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
4817d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        // "Mobile network settings" screen / dialog
4827d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        Intent intent = new Intent(mContext, com.android.phone.MobileNetworkSettings.class);
48399d0ac2c693849e959601a275128a739569d2efbAndrew Lee        PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
4847d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
4857d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        final CharSequence contentText = mContext.getText(R.string.roaming_reenable_message);
4867d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
48799d0ac2c693849e959601a275128a739569d2efbAndrew Lee        final Notification.Builder builder = new Notification.Builder(mContext)
48899d0ac2c693849e959601a275128a739569d2efbAndrew Lee                .setSmallIcon(android.R.drawable.stat_sys_warning)
48999d0ac2c693849e959601a275128a739569d2efbAndrew Lee                .setContentTitle(mContext.getText(R.string.roaming))
49099d0ac2c693849e959601a275128a739569d2efbAndrew Lee                .setColor(mContext.getResources().getColor(R.color.dialer_theme_color))
49199d0ac2c693849e959601a275128a739569d2efbAndrew Lee                .setContentText(contentText);
49299d0ac2c693849e959601a275128a739569d2efbAndrew Lee
49399d0ac2c693849e959601a275128a739569d2efbAndrew Lee        List<UserInfo> users = mUserManager.getUsers(true);
49499d0ac2c693849e959601a275128a739569d2efbAndrew Lee        for (int i = 0; i < users.size(); i++) {
4953faa594099e79c7fa7ac6e4c974e435d2cf4d471Yorke Lee            final UserInfo user = users.get(i);
4963faa594099e79c7fa7ac6e4c974e435d2cf4d471Yorke Lee            if (user.isManagedProfile()) {
4973faa594099e79c7fa7ac6e4c974e435d2cf4d471Yorke Lee                continue;
4983faa594099e79c7fa7ac6e4c974e435d2cf4d471Yorke Lee            }
4993faa594099e79c7fa7ac6e4c974e435d2cf4d471Yorke Lee            UserHandle userHandle = user.getUserHandle();
5003105e9a01b1cf782e11fd1a6cb3bcefc5633ef67Xiaohui Chen            builder.setContentIntent(user.isAdmin() ? contentIntent : null);
50199d0ac2c693849e959601a275128a739569d2efbAndrew Lee            final Notification notif =
50299d0ac2c693849e959601a275128a739569d2efbAndrew Lee                    new Notification.BigTextStyle(builder).bigText(contentText).build();
50399d0ac2c693849e959601a275128a739569d2efbAndrew Lee            mNotificationManager.notifyAsUser(
50499d0ac2c693849e959601a275128a739569d2efbAndrew Lee                    null /* tag */, DATA_DISCONNECTED_ROAMING_NOTIFICATION, notif, userHandle);
50599d0ac2c693849e959601a275128a739569d2efbAndrew Lee        }
5067d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    }
5077d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
5087d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    /**
5097d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * Turns off the "data disconnected due to roaming" notification.
5107d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     */
5117d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    /* package */ void hideDataDisconnectedRoaming() {
5127d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        if (DBG) log("hideDataDisconnectedRoaming()...");
5137d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        mNotificationManager.cancel(DATA_DISCONNECTED_ROAMING_NOTIFICATION);
5147d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    }
5157d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
5167d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    /**
5177d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * Display the network selection "no service" notification
5187d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * @param operator is the numeric operator number
5197d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     */
5207d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    private void showNetworkSelection(String operator) {
5217d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        if (DBG) log("showNetworkSelection(" + operator + ")...");
5227d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
52399d0ac2c693849e959601a275128a739569d2efbAndrew Lee        Notification.Builder builder = new Notification.Builder(mContext)
52499d0ac2c693849e959601a275128a739569d2efbAndrew Lee                .setSmallIcon(android.R.drawable.stat_sys_warning)
52599d0ac2c693849e959601a275128a739569d2efbAndrew Lee                .setContentTitle(mContext.getString(R.string.notification_network_selection_title))
52699d0ac2c693849e959601a275128a739569d2efbAndrew Lee                .setContentText(
52799d0ac2c693849e959601a275128a739569d2efbAndrew Lee                        mContext.getString(R.string.notification_network_selection_text, operator))
52899d0ac2c693849e959601a275128a739569d2efbAndrew Lee                .setShowWhen(false)
52999d0ac2c693849e959601a275128a739569d2efbAndrew Lee                .setOngoing(true);
5307d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
5317d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        // create the target network operators settings intent
5327d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        Intent intent = new Intent(Intent.ACTION_MAIN);
5337d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
5347d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon                Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
5357d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        // Use NetworkSetting to handle the selection intent
536be964583a634a57199417e50b36edb10223f7d3eWei Liu        intent.setComponent(new ComponentName(
537be964583a634a57199417e50b36edb10223f7d3eWei Liu                mContext.getString(R.string.network_operator_settings_package),
538be964583a634a57199417e50b36edb10223f7d3eWei Liu                mContext.getString(R.string.network_operator_settings_class)));
5393e1073d1607d41c87e97cf49ff942afde772725bSanket Padawe        intent.putExtra(GsmUmtsOptions.EXTRA_SUB_ID, mPhone.getSubId());
54099d0ac2c693849e959601a275128a739569d2efbAndrew Lee        PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
54199d0ac2c693849e959601a275128a739569d2efbAndrew Lee
54299d0ac2c693849e959601a275128a739569d2efbAndrew Lee        List<UserInfo> users = mUserManager.getUsers(true);
54399d0ac2c693849e959601a275128a739569d2efbAndrew Lee        for (int i = 0; i < users.size(); i++) {
5443faa594099e79c7fa7ac6e4c974e435d2cf4d471Yorke Lee            final UserInfo user = users.get(i);
5453faa594099e79c7fa7ac6e4c974e435d2cf4d471Yorke Lee            if (user.isManagedProfile()) {
5463faa594099e79c7fa7ac6e4c974e435d2cf4d471Yorke Lee                continue;
5473faa594099e79c7fa7ac6e4c974e435d2cf4d471Yorke Lee            }
5483faa594099e79c7fa7ac6e4c974e435d2cf4d471Yorke Lee            UserHandle userHandle = user.getUserHandle();
5493105e9a01b1cf782e11fd1a6cb3bcefc5633ef67Xiaohui Chen            builder.setContentIntent(user.isAdmin() ? contentIntent : null);
55099d0ac2c693849e959601a275128a739569d2efbAndrew Lee            mNotificationManager.notifyAsUser(
55199d0ac2c693849e959601a275128a739569d2efbAndrew Lee                    null /* tag */,
55299d0ac2c693849e959601a275128a739569d2efbAndrew Lee                    SELECTED_OPERATOR_FAIL_NOTIFICATION,
55399d0ac2c693849e959601a275128a739569d2efbAndrew Lee                    builder.build(),
55499d0ac2c693849e959601a275128a739569d2efbAndrew Lee                    userHandle);
55599d0ac2c693849e959601a275128a739569d2efbAndrew Lee        }
5567d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    }
5577d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
5587d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    /**
5597d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * Turn off the network selection "no service" notification
5607d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     */
5617d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    private void cancelNetworkSelection() {
5627d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        if (DBG) log("cancelNetworkSelection()...");
56399d0ac2c693849e959601a275128a739569d2efbAndrew Lee        mNotificationManager.cancelAsUser(
56499d0ac2c693849e959601a275128a739569d2efbAndrew Lee                null /* tag */, SELECTED_OPERATOR_FAIL_NOTIFICATION, UserHandle.ALL);
5657d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    }
5667d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
5677d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    /**
5687d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * Update notification about no service of user selected operator
5697d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     *
5707d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     * @param serviceState Phone service state
5717d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon     */
5727d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    void updateNetworkSelection(int serviceState) {
5737d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        if (TelephonyCapabilities.supportsNetworkSelection(mPhone)) {
574a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan            int subId = mPhone.getSubId();
575a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan            if (SubscriptionManager.isValidSubscriptionId(subId)) {
576a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                // get the shared preference of network_selection.
577a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                // empty is auto mode, otherwise it is the operator alpha name
578a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                // in case there is no operator name, check the operator numeric
579a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                SharedPreferences sp =
580a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                        PreferenceManager.getDefaultSharedPreferences(mContext);
581a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                String networkSelection =
582c5201f417b58f95c5f1b54de1c101b3a35ad544fAmit Mahajan                        sp.getString(Phone.NETWORK_SELECTION_NAME_KEY + subId, "");
583a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                if (TextUtils.isEmpty(networkSelection)) {
584a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                    networkSelection =
585c5201f417b58f95c5f1b54de1c101b3a35ad544fAmit Mahajan                            sp.getString(Phone.NETWORK_SELECTION_KEY + subId, "");
586a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                }
5877d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
588a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                if (DBG) log("updateNetworkSelection()..." + "state = " +
589a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                        serviceState + " new network " + networkSelection);
5907d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
591a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                if (serviceState == ServiceState.STATE_OUT_OF_SERVICE
592a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                        && !TextUtils.isEmpty(networkSelection)) {
5932b846c78ff3b4102e416c81c4a17b976d327ed38Hall Liu                    showNetworkSelection(networkSelection);
5942b846c78ff3b4102e416c81c4a17b976d327ed38Hall Liu                    mSelectedUnavailableNotify = true;
595a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                } else {
596a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                    if (mSelectedUnavailableNotify) {
597a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                        cancelNetworkSelection();
598a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                        mSelectedUnavailableNotify = false;
599a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                    }
6007d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon                }
6017d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            } else {
602a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                if (DBG) log("updateNetworkSelection()..." + "state = " +
603a60be872ccf4fc96584bf99b11129ffa2cbb7c4eAmit Mahajan                        serviceState + " not updating network due to invalid subId " + subId);
6047d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            }
6057d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        }
6067d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    }
6077d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
6087d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    /* package */ void postTransientNotification(int notifyId, CharSequence msg) {
6097d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        if (mToast != null) {
6107d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            mToast.cancel();
6117d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        }
6127d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
6137d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        mToast = Toast.makeText(mContext, msg, Toast.LENGTH_LONG);
6147d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        mToast.show();
6157d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    }
6167d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
6177d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    private void log(String msg) {
6187d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        Log.d(LOG_TAG, msg);
6197d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    }
6207d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon}
621