Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 18d7a5b1 authored by Malcolm Chen's avatar Malcolm Chen Committed by android-build-merger
Browse files

Merge "Add PhoneConfigurationManager and define its APIs" am: 655e192c

am: 1742da75

Change-Id: I540262c5cddd99322b94e813c32b656abd8474ef
parents 114154c0 1742da75
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.telephony.CellInfo;
import android.telephony.PhoneCapability;
import android.telephony.PhysicalChannelConfig;
import android.telephony.PreciseCallState;
import android.telephony.Rlog;
@@ -342,6 +343,15 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
        }
    }

    @Override
    public void notifyPhoneCapabilityChanged(PhoneCapability capability) {
        try {
            mRegistry.notifyPhoneCapabilityChanged(capability);
        } catch (RemoteException ex) {
            // system process is dead
        }
    }

    /**
     * Convert the {@link Phone.DataActivityState} enum into the TelephonyManager.DATA_* constants
     * for the public API.
+141 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony;

import android.content.Context;
import android.telephony.PhoneCapability;
import android.telephony.Rlog;
import android.telephony.TelephonyManager;
import android.util.Log;

/**
 * This class manages phone's configuration which defines the potential capability (static) of the
 * phone and its current activated capability (current).
 * It gets and monitors static and current phone capability from the modem; send broadcast
 * if they change, and and sends commands to modem to enable or disable phones.
 */
public class PhoneConfigurationManager {
    private static final String LOG_TAG = "PhoneCfgMgr";

    private static PhoneConfigurationManager sInstance = null;
    private final Context mContext;
    private PhoneCapability mStaticCapability;
    private PhoneCapability mCurrentCapability;

    /**
     * Init method to instantiate the object
     * Should only be called once.
     */
    public static PhoneConfigurationManager init(Context context) {
        synchronized (PhoneConfigurationManager.class) {
            if (sInstance == null) {
                sInstance = new PhoneConfigurationManager(context);
            } else {
                Log.wtf(LOG_TAG, "init() called multiple times!  sInstance = " + sInstance);
            }
            return sInstance;
        }
    }

    /**
     * Constructor.
     * @param context context needed to send broadcast.
     */
    private PhoneConfigurationManager(Context context) {
        mContext = context;
        // TODO: send commands to modem once interface is ready.
        TelephonyManager telephonyManager = new TelephonyManager(context);
        mStaticCapability = telephonyManager.getPhoneCount() == 1
                ? PhoneConfigurationModels.SSSS_CAPABILITY
                : PhoneConfigurationModels.DSDS_CAPABILITY;
        mCurrentCapability = mStaticCapability;

        notifyCapabilityChanged();
    }

    /**
     * Static method to get instance.
     */
    public static PhoneConfigurationManager getInstance() {
        if (sInstance == null) {
            Log.wtf(LOG_TAG, "getInstance null");
        }

        return sInstance;
    }


    /**
     * Enable or disable phone
     *
     * @param phoneId which phone to operate on
     * @param enable true or false
     *
     */
    public void enablePhone(int phoneId, boolean enable) {
        // TODO: send command to modem once interface is ready.
    }

    /**
     * Enable or disable phone
     *
     * @param phoneId which phone to operate on
     * @param enable true or false
     *
     */
    public void enablePhone(int[] phoneId, boolean[] enable) {
        // TODO: send command to modem once interface is ready.
    }

    /**
     * Returns how many phone objects the device supports.
     */
    public int getPhoneCount() {
        TelephonyManager tm = new TelephonyManager(mContext);
        return tm.getPhoneCount();
    }

    /**
     * get static overall phone capabilities for all phones.
     *
     */
    public PhoneCapability getStaticPhoneCapability() {
        return mStaticCapability;
    }

    /**
     * get configuration related status of each phone.
     *
     */
    public PhoneCapability getCurrentPhoneCapability() {
        return mCurrentCapability;
    }

    public int getNumberOfModemsWithSimultaneousDataConnections() {
        return mCurrentCapability.maxActiveData;
    }

    private void notifyCapabilityChanged() {
        PhoneNotifier notifier = new DefaultPhoneNotifier();

        notifier.notifyPhoneCapabilityChanged(mCurrentCapability);
    }

    private static void log(String s) {
        Rlog.d(LOG_TAG, s);
    }
}
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony;

import android.telephony.ModemInfo;
import android.telephony.PhoneCapability;

import java.util.ArrayList;
import java.util.List;

/**
 * This class is temporary created for CBRS phase 1 demo purpose.
 * It has two hardcoded phone capability: ssss and dsds.
 * This file should be removed once modem interface to return capabilities are ready.
 */
class PhoneConfigurationModels {
    // Hardcoded DSDS capability.
    public static final PhoneCapability DSDS_CAPABILITY;
    // Hardcoded Single SIM single standby capability.
    public static final PhoneCapability SSSS_CAPABILITY;

    static {
        ModemInfo modemInfo1 = new ModemInfo(0, 0, true, true);
        ModemInfo modemInfo2 = new ModemInfo(1, 0, false, true);

        List<ModemInfo> logicalModemList = new ArrayList<>();
        logicalModemList.add(modemInfo1);
        logicalModemList.add(modemInfo2);
        DSDS_CAPABILITY = new PhoneCapability(1, 2, 0, logicalModemList);

        logicalModemList = new ArrayList<>();
        logicalModemList.add(modemInfo1);
        SSSS_CAPABILITY = new PhoneCapability(1, 1, 0, logicalModemList);
    }
}
+7 −4
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ public class PhoneFactory {
    static private boolean sMadeDefaults = false;
    static private PhoneNotifier sPhoneNotifier;
    static private Context sContext;
    static private PhoneConfigurationManager sPhoneConfigurationManager;
    static private PhoneSwitcher sPhoneSwitcher;
    static private SubscriptionMonitor sSubscriptionMonitor;
    static private TelephonyNetworkFactory[] sTelephonyNetworkFactories;
@@ -90,9 +91,6 @@ public class PhoneFactory {

    static private final HashMap<String, LocalLog>sLocalLogs = new HashMap<String, LocalLog>();

    // TODO - make this a dynamic property read from the modem
    public static final int MAX_ACTIVE_PHONES = 1;

    //***** Class Methods

    public static void makeDefaultPhones(Context context) {
@@ -243,7 +241,12 @@ public class PhoneFactory {

                sSubscriptionMonitor = new SubscriptionMonitor(tr, sContext, sc, numPhones);

                sPhoneSwitcher = new PhoneSwitcher(MAX_ACTIVE_PHONES, numPhones,
                sPhoneConfigurationManager = PhoneConfigurationManager.init(sContext);

                int maxActivePhones = sPhoneConfigurationManager
                        .getNumberOfModemsWithSimultaneousDataConnections();

                sPhoneSwitcher = new PhoneSwitcher(maxActivePhones, numPhones,
                        sContext, sc, Looper.myLooper(), tr, sCommandsInterfaces,
                        sPhones);

+3 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.telephony;

import android.telephony.CellInfo;
import android.telephony.PhoneCapability;
import android.telephony.PhysicalChannelConfig;
import android.telephony.VoLteServiceState;

@@ -70,4 +71,6 @@ public interface PhoneNotifier {
    public void notifyUserMobileDataStateChanged(Phone sender, boolean state);

    public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData);

    public void notifyPhoneCapabilityChanged(PhoneCapability capability);
}
Loading