Search in sources :

Example 1 with TelephonyNetworkFactory

use of com.android.internal.telephony.dataconnection.TelephonyNetworkFactory in project android_frameworks_opt_telephony by LineageOS.

the class PhoneFactory method onMultiSimConfigChanged.

/**
 * Upon single SIM to dual SIM switch or vice versa, we dynamically allocate or de-allocate
 * Phone and CommandInterface objects.
 * @param context
 * @param activeModemCount
 */
public static void onMultiSimConfigChanged(Context context, int activeModemCount) {
    synchronized (sLockProxyPhones) {
        int prevActiveModemCount = sPhones.length;
        if (prevActiveModemCount == activeModemCount)
            return;
        // user switches back.
        if (prevActiveModemCount > activeModemCount)
            return;
        sPhones = copyOf(sPhones, activeModemCount);
        sCommandsInterfaces = copyOf(sCommandsInterfaces, activeModemCount);
        sTelephonyNetworkFactories = copyOf(sTelephonyNetworkFactories, activeModemCount);
        int cdmaSubscription = CdmaSubscriptionSourceManager.getDefault(context);
        for (int i = prevActiveModemCount; i < activeModemCount; i++) {
            sCommandsInterfaces[i] = new RIL(context, RILConstants.PREFERRED_NETWORK_MODE, cdmaSubscription, i);
            sPhones[i] = createPhone(context, i);
            if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
                sPhones[i].createImsPhone();
            }
            sTelephonyNetworkFactories[i] = new TelephonyNetworkFactory(Looper.myLooper(), sPhones[i]);
        }
    }
}
Also used : TelephonyNetworkFactory(com.android.internal.telephony.dataconnection.TelephonyNetworkFactory)

Example 2 with TelephonyNetworkFactory

use of com.android.internal.telephony.dataconnection.TelephonyNetworkFactory in project android_frameworks_opt_telephony by LineageOS.

the class PhoneFactory method getNetworkFactory.

/**
 * Get the network factory associated with a given phone ID.
 * @param phoneId the phone id
 * @return a factory for this phone ID, or null if none.
 */
public static TelephonyNetworkFactory getNetworkFactory(int phoneId) {
    synchronized (sLockProxyPhones) {
        if (!sMadeDefaults) {
            throw new IllegalStateException("Default phones haven't been made yet!");
        }
        final String dbgInfo;
        if (phoneId == SubscriptionManager.DEFAULT_PHONE_INDEX) {
            dbgInfo = "getNetworkFactory with DEFAULT_PHONE_ID => factory for sPhone";
            phoneId = sPhone.getSubId();
        } else {
            dbgInfo = "getNetworkFactory with non-default, return factory for passed id";
        }
        // sTelephonyNetworkFactories is null in tests because in tests makeDefaultPhones()
        // is not called.
        final TelephonyNetworkFactory factory = (sTelephonyNetworkFactories != null && (phoneId >= 0 && phoneId < sTelephonyNetworkFactories.length)) ? sTelephonyNetworkFactories[phoneId] : null;
        if (DBG) {
            Rlog.d(LOG_TAG, "getNetworkFactory:-" + dbgInfo + " phoneId=" + phoneId + " factory=" + factory);
        }
        return factory;
    }
}
Also used : TelephonyNetworkFactory(com.android.internal.telephony.dataconnection.TelephonyNetworkFactory)

Example 3 with TelephonyNetworkFactory

use of com.android.internal.telephony.dataconnection.TelephonyNetworkFactory in project android_frameworks_opt_telephony by LineageOS.

the class PhoneFactory method makeDefaultPhone.

/**
 * FIXME replace this with some other way of making these
 * instances
 */
@UnsupportedAppUsage
public static void makeDefaultPhone(Context context) {
    synchronized (sLockProxyPhones) {
        if (!sMadeDefaults) {
            sContext = context;
            // create the telephony device controller.
            TelephonyDevController.create();
            TelephonyMetrics metrics = TelephonyMetrics.getInstance();
            metrics.setContext(context);
            int retryCount = 0;
            for (; ; ) {
                boolean hasException = false;
                retryCount++;
                try {
                    // use UNIX domain socket to
                    // prevent subsequent initialization
                    new LocalServerSocket("com.android.internal.telephony");
                } catch (java.io.IOException ex) {
                    hasException = true;
                }
                if (!hasException) {
                    break;
                } else if (retryCount > SOCKET_OPEN_MAX_RETRY) {
                    throw new RuntimeException("PhoneFactory probably already running");
                } else {
                    try {
                        Thread.sleep(SOCKET_OPEN_RETRY_MILLIS);
                    } catch (InterruptedException er) {
                    }
                }
            }
            // register statsd pullers.
            sMetricsCollector = new MetricsCollector(context);
            sPhoneNotifier = new DefaultPhoneNotifier(context);
            int cdmaSubscription = CdmaSubscriptionSourceManager.getDefault(context);
            Rlog.i(LOG_TAG, "Cdma Subscription set to " + cdmaSubscription);
            /* In case of multi SIM mode two instances of Phone, RIL are created,
                   where as in single SIM mode only instance. isMultiSimEnabled() function checks
                   whether it is single SIM or multi SIM mode */
            int numPhones = TelephonyManager.getDefault().getActiveModemCount();
            int[] networkModes = new int[numPhones];
            sPhones = new Phone[numPhones];
            sCommandsInterfaces = new RIL[numPhones];
            sTelephonyNetworkFactories = new TelephonyNetworkFactory[numPhones];
            for (int i = 0; i < numPhones; i++) {
                // reads the system properties and makes commandsinterface
                // Get preferred network type.
                networkModes[i] = RILConstants.PREFERRED_NETWORK_MODE;
                Rlog.i(LOG_TAG, "Network Mode set to " + Integer.toString(networkModes[i]));
                sCommandsInterfaces[i] = new RIL(context, networkModes[i], cdmaSubscription, i);
            }
            // Instantiate UiccController so that all other classes can just
            // call getInstance()
            sUiccController = UiccController.make(context);
            Rlog.i(LOG_TAG, "Creating SubscriptionController");
            TelephonyComponentFactory.getInstance().inject(SubscriptionController.class.getName()).initSubscriptionController(context);
            TelephonyComponentFactory.getInstance().inject(MultiSimSettingController.class.getName()).initMultiSimSettingController(context, SubscriptionController.getInstance());
            if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_EUICC)) {
                sEuiccController = EuiccController.init(context);
                sEuiccCardController = EuiccCardController.init(context);
            }
            for (int i = 0; i < numPhones; i++) {
                sPhones[i] = createPhone(context, i);
            }
            // FIXME: needs to be done in a more controlled manner in the future.
            if (numPhones > 0)
                sPhone = sPhones[0];
            // Ensure that we have a default SMS app. Requesting the app with
            // updateIfNeeded set to true is enough to configure a default SMS app.
            ComponentName componentName = SmsApplication.getDefaultSmsApplication(context, true);
            String packageName = "NONE";
            if (componentName != null) {
                packageName = componentName.getPackageName();
            }
            Rlog.i(LOG_TAG, "defaultSmsApplication: " + packageName);
            // Set up monitor to watch for changes to SMS packages
            SmsApplication.initSmsPackageMonitor(context);
            sMadeDefaults = true;
            Rlog.i(LOG_TAG, "Creating SubInfoRecordUpdater ");
            HandlerThread pfhandlerThread = new HandlerThread("PhoneFactoryHandlerThread");
            pfhandlerThread.start();
            sSubInfoRecordUpdater = TelephonyComponentFactory.getInstance().inject(SubscriptionInfoUpdater.class.getName()).makeSubscriptionInfoUpdater(pfhandlerThread.getLooper(), context, sCommandsInterfaces);
            // Only bring up IMS if the device supports having an IMS stack.
            if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS)) {
                // might need it when it is being opened.
                for (int i = 0; i < numPhones; i++) {
                    sPhones[i].createImsPhone();
                }
            } else {
                Rlog.i(LOG_TAG, "IMS is not supported on this device, skipping ImsResolver.");
            }
            sPhoneConfigurationManager = PhoneConfigurationManager.init(sContext);
            sCellularNetworkValidator = CellularNetworkValidator.make(sContext);
            int maxActivePhones = sPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
            sPhoneSwitcher = TelephonyComponentFactory.getInstance().inject(PhoneSwitcher.class.getName()).makePhoneSwitcher(maxActivePhones, sContext, Looper.myLooper());
            sProxyController = ProxyController.getInstance(context);
            sIntentBroadcaster = IntentBroadcaster.getInstance(context);
            sNotificationChannelController = new NotificationChannelController(context);
            for (int i = 0; i < numPhones; i++) {
                sTelephonyNetworkFactories[i] = new TelephonyNetworkFactory(Looper.myLooper(), sPhones[i]);
            }
        }
    }
}
Also used : MetricsCollector(com.android.internal.telephony.metrics.MetricsCollector) HandlerThread(android.os.HandlerThread) LocalServerSocket(android.net.LocalServerSocket) ComponentName(android.content.ComponentName) TelephonyMetrics(com.android.internal.telephony.metrics.TelephonyMetrics) TelephonyNetworkFactory(com.android.internal.telephony.dataconnection.TelephonyNetworkFactory) NotificationChannelController(com.android.internal.telephony.util.NotificationChannelController) UnsupportedAppUsage(android.compat.annotation.UnsupportedAppUsage)

Aggregations

TelephonyNetworkFactory (com.android.internal.telephony.dataconnection.TelephonyNetworkFactory)3 UnsupportedAppUsage (android.compat.annotation.UnsupportedAppUsage)1 ComponentName (android.content.ComponentName)1 LocalServerSocket (android.net.LocalServerSocket)1 HandlerThread (android.os.HandlerThread)1 MetricsCollector (com.android.internal.telephony.metrics.MetricsCollector)1 TelephonyMetrics (com.android.internal.telephony.metrics.TelephonyMetrics)1 NotificationChannelController (com.android.internal.telephony.util.NotificationChannelController)1