Search in sources :

Example 11 with SubscriptionInfo

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

the class NetworkControllerSignalTest method testSetCurrentSubscriptions.

public void testSetCurrentSubscriptions() {
    // We will not add one controller to make sure it gets created.
    int indexToSkipController = 0;
    // We will not add one subscription to make sure it's controller gets removed.
    int indexToSkipSubscription = 1;
    int[] testSubscriptions = new int[] { 1, 5, 3 };
    MobileSignalController[] mobileSignalControllers = new MobileSignalController[] { Mockito.mock(MobileSignalController.class), Mockito.mock(MobileSignalController.class), Mockito.mock(MobileSignalController.class) };
    mNetworkController.mMobileSignalControllers.clear();
    List<SubscriptionInfo> subscriptions = new ArrayList<>();
    for (int i = 0; i < testSubscriptions.length; i++) {
        if (i != indexToSkipController) {
            // Force the test controllers into NetworkController.
            mNetworkController.mMobileSignalControllers.put(testSubscriptions[i], mobileSignalControllers[i]);
        }
        if (i != indexToSkipSubscription) {
            // Generate a list of subscriptions we will tell the NetworkController to use.
            SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
            Mockito.when(mockSubInfo.getSubscriptionId()).thenReturn(testSubscriptions[i]);
            Mockito.when(mockSubInfo.getSimSlotIndex()).thenReturn(testSubscriptions[i]);
            subscriptions.add(mockSubInfo);
        }
    }
    // We can only test whether unregister gets called if it thinks its in a listening
    // state.
    mNetworkController.mListening = true;
    mNetworkController.setCurrentSubscriptions(subscriptions);
    for (int i = 0; i < testSubscriptions.length; i++) {
        if (i == indexToSkipController) {
            // Make sure a controller was created despite us not adding one.
            assertTrue(mNetworkController.mMobileSignalControllers.containsKey(testSubscriptions[i]));
        } else if (i == indexToSkipSubscription) {
            // Make sure the controller that did exist was removed
            assertFalse(mNetworkController.mMobileSignalControllers.containsKey(testSubscriptions[i]));
        } else {
            // If a MobileSignalController is around it needs to not be unregistered.
            Mockito.verify(mobileSignalControllers[i], Mockito.never()).unregisterListener();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SubscriptionInfo(android.telephony.SubscriptionInfo)

Example 12 with SubscriptionInfo

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

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;
            }
        }
    }
    setSimNeedsEmergencyAffordance(neededNow);
    return neededNow;
}
Also used : SubscriptionInfo(android.telephony.SubscriptionInfo)

Example 13 with SubscriptionInfo

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

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();
    } 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;
            }
            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("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.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 14 with SubscriptionInfo

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

the class NetworkControllerBaseTest method setSubscriptions.

protected void setSubscriptions(int... subIds) {
    List<SubscriptionInfo> subs = new ArrayList<SubscriptionInfo>();
    for (int subId : subIds) {
        SubscriptionInfo subscription = mock(SubscriptionInfo.class);
        when(subscription.getSubscriptionId()).thenReturn(subId);
        subs.add(subscription);
    }
    when(mMockSm.getActiveSubscriptionInfoList()).thenReturn(subs);
    mNetworkController.doUpdateMobileControllers();
}
Also used : ArrayList(java.util.ArrayList) SubscriptionInfo(android.telephony.SubscriptionInfo)

Example 15 with SubscriptionInfo

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

the class NetworkControllerSignalTest method testHasCorrectMobileControllers.

// Some tests of actual NetworkController code, just internals not display stuff
// TODO: Put this somewhere else, maybe in its own file.
public void testHasCorrectMobileControllers() {
    int[] testSubscriptions = new int[] { 1, 5, 3 };
    int notTestSubscription = 0;
    MobileSignalController mobileSignalController = Mockito.mock(MobileSignalController.class);
    mNetworkController.mMobileSignalControllers.clear();
    List<SubscriptionInfo> subscriptions = new ArrayList<>();
    for (int i = 0; i < testSubscriptions.length; i++) {
        // Force the test controllers into NetworkController.
        mNetworkController.mMobileSignalControllers.put(testSubscriptions[i], mobileSignalController);
        // Generate a list of subscriptions we will tell the NetworkController to use.
        SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
        Mockito.when(mockSubInfo.getSubscriptionId()).thenReturn(testSubscriptions[i]);
        subscriptions.add(mockSubInfo);
    }
    assertTrue(mNetworkController.hasCorrectMobileControllers(subscriptions));
    // Add a subscription that the NetworkController doesn't know about.
    SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
    Mockito.when(mockSubInfo.getSubscriptionId()).thenReturn(notTestSubscription);
    subscriptions.add(mockSubInfo);
    assertFalse(mNetworkController.hasCorrectMobileControllers(subscriptions));
}
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