Search in sources :

Example 6 with SubscriptionInfo

use of android.telephony.SubscriptionInfo in project platform_frameworks_base by android.

the class EmergencyAffordanceService method handleUpdateSimSubscriptionInfo.

private boolean handleUpdateSimSubscriptionInfo() {
    boolean neededBefore = simNeededAffordanceBefore();
    boolean neededNow = neededBefore;
    List<SubscriptionInfo> activeSubscriptionInfoList = mSubscriptionManager.getActiveSubscriptionInfoList();
    if (activeSubscriptionInfoList == null) {
        return neededNow;
    }
    for (SubscriptionInfo info : activeSubscriptionInfoList) {
        int mcc = info.getMcc();
        if (mccRequiresEmergencyAffordance(mcc)) {
            neededNow = true;
            break;
        } else if (mcc != 0 && mcc != Integer.MAX_VALUE) {
            // a Sim with a different mcc code was found
            neededNow = false;
        }
        String simOperator = mTelephonyManager.getSimOperator(info.getSubscriptionId());
        mcc = 0;
        if (simOperator != null && simOperator.length() >= 3) {
            mcc = Integer.parseInt(simOperator.substring(0, 3));
        }
        if (mcc != 0) {
            if (mccRequiresEmergencyAffordance(mcc)) {
                neededNow = true;
                break;
            } else {
                // a Sim with a different mcc code was found
                neededNow = false;
            }
        }
    }
    if (neededNow != neededBefore) {
        setSimNeedsEmergencyAffordance(neededNow);
    }
    return neededNow;
}
Also used : SubscriptionInfo(android.telephony.SubscriptionInfo)

Example 7 with SubscriptionInfo

use of android.telephony.SubscriptionInfo in project android_frameworks_base by DirtyUnicorns.

the class NetworkControllerImpl method dispatchDemoCommand.

@Override
public void dispatchDemoCommand(String command, Bundle args) {
    if (!mDemoMode && command.equals(COMMAND_ENTER)) {
        if (DEBUG)
            Log.d(TAG, "Entering demo mode");
        unregisterListeners();
        mDemoMode = true;
        mDemoInetCondition = mInetCondition;
        mDemoWifiState = mWifiSignalController.getState();
        mDemoWifiState.ssid = "DemoMode";
    } else if (mDemoMode && command.equals(COMMAND_EXIT)) {
        if (DEBUG)
            Log.d(TAG, "Exiting demo mode");
        mDemoMode = false;
        // Update what MobileSignalControllers, because they may change
        // to set the number of sim slots.
        updateMobileControllers();
        for (MobileSignalController controller : mMobileSignalControllers.values()) {
            controller.resetLastState();
        }
        mWifiSignalController.resetLastState();
        mReceiverHandler.post(mRegisterListeners);
        notifyAllListeners();
    } else if (mDemoMode && command.equals(COMMAND_NETWORK)) {
        String airplane = args.getString("airplane");
        if (airplane != null) {
            boolean show = airplane.equals("show");
            mCallbackHandler.setIsAirplaneMode(new IconState(show, TelephonyIcons.FLIGHT_MODE_ICON, R.string.accessibility_airplane_mode, mContext));
        }
        String fully = args.getString("fully");
        if (fully != null) {
            mDemoInetCondition = Boolean.parseBoolean(fully);
            BitSet connected = new BitSet();
            if (mDemoInetCondition) {
                connected.set(mWifiSignalController.mTransportType);
            }
            mWifiSignalController.updateConnectivity(connected, connected);
            for (MobileSignalController controller : mMobileSignalControllers.values()) {
                if (mDemoInetCondition) {
                    connected.set(controller.mTransportType);
                }
                controller.updateConnectivity(connected, connected);
            }
        }
        String wifi = args.getString("wifi");
        if (wifi != null) {
            boolean show = wifi.equals("show");
            String level = args.getString("level");
            if (level != null) {
                mDemoWifiState.level = level.equals("null") ? -1 : Math.min(Integer.parseInt(level), WifiIcons.WIFI_LEVEL_COUNT - 1);
                mDemoWifiState.connected = mDemoWifiState.level >= 0;
            }
            String activity = args.getString("activity");
            if (activity != null) {
                switch(activity) {
                    case "inout":
                        mWifiSignalController.setActivity(WifiManager.DATA_ACTIVITY_INOUT);
                        break;
                    case "in":
                        mWifiSignalController.setActivity(WifiManager.DATA_ACTIVITY_IN);
                        break;
                    case "out":
                        mWifiSignalController.setActivity(WifiManager.DATA_ACTIVITY_OUT);
                        break;
                    default:
                        mWifiSignalController.setActivity(WifiManager.DATA_ACTIVITY_NONE);
                        break;
                }
            } else {
                mWifiSignalController.setActivity(WifiManager.DATA_ACTIVITY_NONE);
            }
            mDemoWifiState.enabled = show;
            mWifiSignalController.notifyListeners();
        }
        String sims = args.getString("sims");
        if (sims != null) {
            int num = MathUtils.constrain(Integer.parseInt(sims), 1, 8);
            List<SubscriptionInfo> subs = new ArrayList<>();
            if (num != mMobileSignalControllers.size()) {
                mMobileSignalControllers.clear();
                int start = mSubscriptionManager.getActiveSubscriptionInfoCountMax();
                for (int i = start; /* get out of normal index range */
                i < start + num; i++) {
                    subs.add(addSignalController(i, i));
                }
                mCallbackHandler.setSubs(subs);
            }
        }
        String nosim = args.getString("nosim");
        if (nosim != null) {
            mHasNoSims = nosim.equals("show");
            mCallbackHandler.setNoSims(mHasNoSims);
        }
        String mobile = args.getString("mobile");
        if (mobile != null) {
            boolean show = mobile.equals("show");
            String datatype = args.getString("datatype");
            String slotString = args.getString("slot");
            int slot = TextUtils.isEmpty(slotString) ? 0 : Integer.parseInt(slotString);
            slot = MathUtils.constrain(slot, 0, 8);
            // Ensure we have enough sim slots
            List<SubscriptionInfo> subs = new ArrayList<>();
            while (mMobileSignalControllers.size() <= slot) {
                int nextSlot = mMobileSignalControllers.size();
                subs.add(addSignalController(nextSlot, nextSlot));
            }
            if (!subs.isEmpty()) {
                mCallbackHandler.setSubs(subs);
            }
            // Hack to index linearly for easy use.
            MobileSignalController controller = mMobileSignalControllers.values().toArray(new MobileSignalController[0])[slot];
            controller.getState().dataSim = datatype != null;
            if (datatype != null) {
                controller.getState().iconGroup = datatype.equals("1x") ? TelephonyIcons.ONE_X : datatype.equals("3g") ? TelephonyIcons.THREE_G : datatype.equals("4g") ? TelephonyIcons.FOUR_G : datatype.equals("4g+") ? TelephonyIcons.FOUR_G_PLUS : datatype.equals("e") ? TelephonyIcons.E : datatype.equals("g") ? TelephonyIcons.G : datatype.equals("h") ? TelephonyIcons.H : datatype.equals("hp") ? TelephonyIcons.HP : datatype.equals("lte") ? TelephonyIcons.LTE : datatype.equals("lte+") ? TelephonyIcons.LTE_PLUS : TelephonyIcons.UNKNOWN;
            }
            if (args.containsKey("roam")) {
                controller.getState().roaming = "show".equals(args.getString("roam"));
            }
            int[][] icons = TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH;
            String level = args.getString("level");
            if (level != null) {
                controller.getState().level = level.equals("null") ? -1 : Math.min(Integer.parseInt(level), icons[0].length - 1);
                controller.getState().connected = controller.getState().level >= 0;
            }
            String activity = args.getString("activity");
            if (activity != null) {
                controller.getState().dataConnected = true;
                switch(activity) {
                    case "inout":
                        controller.setActivity(TelephonyManager.DATA_ACTIVITY_INOUT);
                        break;
                    case "in":
                        controller.setActivity(TelephonyManager.DATA_ACTIVITY_IN);
                        break;
                    case "out":
                        controller.setActivity(TelephonyManager.DATA_ACTIVITY_OUT);
                        break;
                    default:
                        controller.setActivity(TelephonyManager.DATA_ACTIVITY_NONE);
                        break;
                }
            } else {
                controller.setActivity(TelephonyManager.DATA_ACTIVITY_NONE);
            }
            if (activity != null) {
                controller.setActivity(Integer.parseInt(activity));
            }
            controller.getState().enabled = show;
            controller.notifyListeners();
        }
        String carrierNetworkChange = args.getString("carriernetworkchange");
        if (carrierNetworkChange != null) {
            boolean show = carrierNetworkChange.equals("show");
            for (MobileSignalController controller : mMobileSignalControllers.values()) {
                controller.setCarrierNetworkChangeMode(show);
            }
        }
    }
}
Also used : BitSet(java.util.BitSet) ArrayList(java.util.ArrayList) SubscriptionInfo(android.telephony.SubscriptionInfo)

Example 8 with SubscriptionInfo

use of android.telephony.SubscriptionInfo in project android_frameworks_base by DirtyUnicorns.

the class EmergencyCryptkeeperText method update.

public void update() {
    boolean hasMobile = ConnectivityManager.from(mContext).isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
    boolean airplaneMode = (Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) == 1);
    if (!hasMobile || airplaneMode) {
        setText(null);
        setVisibility(GONE);
        return;
    }
    boolean allSimsMissing = true;
    CharSequence displayText = null;
    List<SubscriptionInfo> subs = mKeyguardUpdateMonitor.getSubscriptionInfo(false);
    final int N = subs.size();
    for (int i = 0; i < N; i++) {
        int subId = subs.get(i).getSubscriptionId();
        IccCardConstants.State simState = mKeyguardUpdateMonitor.getSimState(subId);
        CharSequence carrierName = subs.get(i).getCarrierName();
        if (simState.iccCardExist() && !TextUtils.isEmpty(carrierName)) {
            allSimsMissing = false;
            displayText = carrierName;
        }
    }
    if (allSimsMissing) {
        if (N != 0) {
            // Shows "Emergency calls only" on devices that are voice-capable.
            // This depends on mPlmn containing the text "Emergency calls only" when the radio
            // has some connectivity. Otherwise it should show "No service"
            // Grab the first subscription, because they all should contain the emergency text,
            // described above.
            displayText = subs.get(0).getCarrierName();
        } else {
            // We don't have a SubscriptionInfo to get the emergency calls only from.
            // Grab it from the old sticky broadcast if possible instead. We can use it
            // here because no subscriptions are active, so we don't have
            // to worry about MSIM clashing.
            displayText = getContext().getText(com.android.internal.R.string.emergency_calls_only);
            Intent i = getContext().registerReceiver(null, new IntentFilter(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION));
            if (i != null) {
                displayText = i.getStringExtra(TelephonyIntents.EXTRA_PLMN);
            }
        }
    }
    setText(displayText);
    setVisibility(TextUtils.isEmpty(displayText) ? GONE : VISIBLE);
}
Also used : IntentFilter(android.content.IntentFilter) IccCardConstants(com.android.internal.telephony.IccCardConstants) SubscriptionInfo(android.telephony.SubscriptionInfo) Intent(android.content.Intent)

Example 9 with SubscriptionInfo

use of android.telephony.SubscriptionInfo in project android_frameworks_base by DirtyUnicorns.

the class CarrierText method updateCarrierText.

protected void updateCarrierText() {
    boolean allSimsMissing = true;
    boolean anySimReadyAndInService = false;
    CharSequence displayText = null;
    List<SubscriptionInfo> subs = mKeyguardUpdateMonitor.getSubscriptionInfo(false);
    final int N = subs.size();
    if (DEBUG)
        Log.d(TAG, "updateCarrierText(): " + N);
    for (int i = 0; i < N; i++) {
        int subId = subs.get(i).getSubscriptionId();
        State simState = mKeyguardUpdateMonitor.getSimState(subId);
        CharSequence carrierName = subs.get(i).getCarrierName();
        CharSequence carrierTextForSimState = getCarrierTextForSimState(simState, carrierName);
        if (DEBUG) {
            Log.d(TAG, "Handling (subId=" + subId + "): " + simState + " " + carrierName);
        }
        if (carrierTextForSimState != null) {
            allSimsMissing = false;
            displayText = concatenate(displayText, carrierTextForSimState);
        }
        if (simState == IccCardConstants.State.READY) {
            ServiceState ss = mKeyguardUpdateMonitor.mServiceStates.get(subId);
            if (ss != null && ss.getDataRegState() == ServiceState.STATE_IN_SERVICE) {
                // Wi-Fi is disassociated or disabled
                if (ss.getRilDataRadioTechnology() != ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN || (mWifiManager.isWifiEnabled() && mWifiManager.getConnectionInfo() != null && mWifiManager.getConnectionInfo().getBSSID() != null)) {
                    if (DEBUG) {
                        Log.d(TAG, "SIM ready and in service: subId=" + subId + ", ss=" + ss);
                    }
                    anySimReadyAndInService = true;
                }
            }
        }
    }
    if (allSimsMissing) {
        if (N != 0) {
            // Shows "No SIM card | Emergency calls only" on devices that are voice-capable.
            // This depends on mPlmn containing the text "Emergency calls only" when the radio
            // has some connectivity. Otherwise, it should be null or empty and just show
            // "No SIM card"
            // Grab the first subscripton, because they all should contain the emergency text,
            // described above.
            displayText = null;
        } else {
            // We don't have a SubscriptionInfo to get the emergency calls only from.
            // Grab it from the old sticky broadcast if possible instead. We can use it
            // here because no subscriptions are active, so we don't have
            // to worry about MSIM clashing.
            CharSequence text = getContext().getText(com.android.internal.R.string.emergency_calls_only);
            Intent i = getContext().registerReceiver(null, new IntentFilter(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION));
            if (i != null) {
                String spn = "";
                String plmn = "";
                if (i.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_SPN, false)) {
                    spn = i.getStringExtra(TelephonyIntents.EXTRA_SPN);
                }
                if (i.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_PLMN, false)) {
                    plmn = i.getStringExtra(TelephonyIntents.EXTRA_PLMN);
                }
                if (DEBUG)
                    Log.d(TAG, "Getting plmn/spn sticky brdcst " + plmn + "/" + spn);
                if (Objects.equals(plmn, spn)) {
                    text = plmn;
                } else {
                    text = concatenate(plmn, spn);
                }
            }
            displayText = null;
        }
    }
    // (e.g. WFC = Wi-Fi calling) which may operate in APM.
    if (!anySimReadyAndInService && WirelessUtils.isAirplaneModeOn(mContext)) {
        displayText = getContext().getString(R.string.airplane_mode);
    }
    setText(displayText);
}
Also used : IntentFilter(android.content.IntentFilter) ServiceState(android.telephony.ServiceState) ServiceState(android.telephony.ServiceState) State(com.android.internal.telephony.IccCardConstants.State) SubscriptionInfo(android.telephony.SubscriptionInfo) Intent(android.content.Intent)

Example 10 with SubscriptionInfo

use of android.telephony.SubscriptionInfo in project android_frameworks_base by DirtyUnicorns.

the class KeyguardUpdateMonitor method handleSimSubscriptionInfoChanged.

protected void handleSimSubscriptionInfoChanged() {
    if (DEBUG_SIM_STATES) {
        Log.v(TAG, "onSubscriptionInfoChanged()");
        List<SubscriptionInfo> sil = mSubscriptionManager.getActiveSubscriptionInfoList();
        if (sil != null) {
            for (SubscriptionInfo subInfo : sil) {
                Log.v(TAG, "SubInfo:" + subInfo);
            }
        } else {
            Log.v(TAG, "onSubscriptionInfoChanged: list is null");
        }
    }
    List<SubscriptionInfo> subscriptionInfos = getSubscriptionInfo(true);
    // Hack level over 9000: Because the subscription id is not yet valid when we see the
    // first update in handleSimStateChange, we need to force refresh all all SIM states
    // so the subscription id for them is consistent.
    ArrayList<SubscriptionInfo> changedSubscriptions = new ArrayList<>();
    for (int i = 0; i < subscriptionInfos.size(); i++) {
        SubscriptionInfo info = subscriptionInfos.get(i);
        boolean changed = refreshSimState(info.getSubscriptionId(), info.getSimSlotIndex());
        if (changed) {
            changedSubscriptions.add(info);
        }
    }
    for (int i = 0; i < changedSubscriptions.size(); i++) {
        SimData data = mSimDatas.get(changedSubscriptions.get(i).getSubscriptionId());
        for (int j = 0; j < mCallbacks.size(); j++) {
            KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get();
            if (cb != null) {
                cb.onSimStateChanged(data.subId, data.slotId, data.simState);
            }
        }
    }
    for (int j = 0; j < mCallbacks.size(); j++) {
        KeyguardUpdateMonitorCallback cb = mCallbacks.get(j).get();
        if (cb != null) {
            cb.onRefreshCarrierInfo();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SubscriptionInfo(android.telephony.SubscriptionInfo)

Aggregations

SubscriptionInfo (android.telephony.SubscriptionInfo)89 ArrayList (java.util.ArrayList)27 Intent (android.content.Intent)14 SubscriptionManager (android.telephony.SubscriptionManager)13 IntentFilter (android.content.IntentFilter)12 Resources (android.content.res.Resources)9 TelephonyManager (android.telephony.TelephonyManager)9 ServiceState (android.telephony.ServiceState)7 BitSet (java.util.BitSet)7 RemoteException (android.os.RemoteException)5 Preference (android.support.v7.preference.Preference)5 IccCardConstants (com.android.internal.telephony.IccCardConstants)5 State (com.android.internal.telephony.IccCardConstants.State)5 ContentResolver (android.content.ContentResolver)4 PersistentDataBlockManager (android.service.persistentdata.PersistentDataBlockManager)4 SwitchPreference (android.support.v14.preference.SwitchPreference)4 PhoneAccountHandle (android.telecom.PhoneAccountHandle)4 TelecomManager (android.telecom.TelecomManager)3 TargetApi (android.annotation.TargetApi)2 AlertDialog (android.app.AlertDialog)2