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

Commit 519fcdd2 authored by Nazanin Bakhshi's avatar Nazanin Bakhshi
Browse files

create getModemEnabled function in PhoneConfigurationManager

Bug: 124402911
Test: build
Change-Id: I3eb53f8b0ecac57a015ad43e44c7bbfbe17eed8c
Merged-In: I3eb53f8b0ecac57a015ad43e44c7bbfbe17eed8c
(cherry picked from commit dfe58bf43a74cc36410a9a64cdf24dd181235f8d)
parent d1bee509
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -2266,6 +2266,13 @@ public interface CommandsInterface {
     */
    default void enableModem(boolean enable, Message result) {};

    /**
     * Query whether logical modem is enabled or disabled
     *
     * @param result a Message to return to the requester
     */
    default void getModemStatus(Message result) {};

    default List<ClientRequestStats> getClientRequestStats() {
        return null;
    }
+89 −1
Original line number Diff line number Diff line
@@ -22,11 +22,15 @@ import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.os.SystemProperties;
import android.os.storage.StorageManager;
import android.telephony.PhoneCapability;
import android.telephony.Rlog;
import android.telephony.TelephonyManager;
import android.util.Log;

import java.util.HashMap;
import java.util.Map;

/**
 * This class manages phone's configuration which defines the potential capability (static) of the
 * phone and its current activated capability (current).
@@ -40,6 +44,8 @@ public class PhoneConfigurationManager {
    public static final String SSSS = "";
    private static final String LOG_TAG = "PhoneCfgMgr";
    private static final int EVENT_SWITCH_DSDS_CONFIG_DONE = 100;
    private static final int EVENT_GET_MODEM_STATUS = 101;
    private static final int EVENT_GET_MODEM_STATUS_DONE = 102;

    private static PhoneConfigurationManager sInstance = null;
    private final Context mContext;
@@ -47,6 +53,8 @@ public class PhoneConfigurationManager {
    private PhoneCapability mCurrentCapability;
    private final RadioConfig mRadioConfig;
    private final MainThreadHandler mHandler;
    private final Phone[] mPhones;
    private final Map<Integer, Boolean> mPhoneStatusMap;

    /**
     * Init method to instantiate the object
@@ -75,8 +83,20 @@ public class PhoneConfigurationManager {
        mCurrentCapability = mStaticCapability;
        mRadioConfig = RadioConfig.getInstance(mContext);
        mHandler = new MainThreadHandler();
        mPhoneStatusMap = new HashMap<>();

        notifyCapabilityChanged();

        mPhones = PhoneFactory.getPhones();
        if (!StorageManager.inCryptKeeperBounce()) {
            for (Phone phone : mPhones) {
                phone.mCi.registerForAvailable(mHandler, Phone.EVENT_RADIO_AVAILABLE, phone);
            }
        } else {
            for (Phone phone : mPhones) {
                phone.mCi.registerForOn(mHandler, Phone.EVENT_RADIO_ON, phone);
            }
        }
    }

    /**
@@ -96,9 +116,24 @@ public class PhoneConfigurationManager {
    private final class MainThreadHandler extends Handler {
        @Override
        public void handleMessage(Message msg) {
            AsyncResult ar;
            Phone phone = null;
            switch (msg.what) {
                case Phone.EVENT_RADIO_AVAILABLE:
                case Phone.EVENT_RADIO_ON:
                    log("Received EVENT_RADIO_AVAILABLE/EVENT_RADIO_ON");
                    if (msg.obj instanceof Phone) {
                        phone = (Phone) msg.obj;
                    }
                    if (phone == null) {
                        log("Unable to add phoneStatus to cache. "
                                + "No phone object provided for event " + msg.what);
                    } else {
                        updatePhoneStatus(phone);
                    }
                    break;
                case EVENT_SWITCH_DSDS_CONFIG_DONE:
                    AsyncResult ar = (AsyncResult) msg.obj;
                    ar = (AsyncResult) msg.obj;
                    if (ar != null && ar.exception == null) {
                        int numOfLiveModems = msg.arg1;
                        setMultiSimProperties(numOfLiveModems);
@@ -106,6 +141,17 @@ public class PhoneConfigurationManager {
                        log(msg.what + " failure. Not switching multi-sim config." + ar.exception);
                    }
                    break;
                case EVENT_GET_MODEM_STATUS_DONE:
                    ar = (AsyncResult) msg.obj;
                    if (ar != null && ar.exception == null) {
                        int phoneId = msg.arg1;
                        boolean enabled = (boolean) ar.result;
                        //update the cache each time getModemStatus is requested
                        mPhoneStatusMap.put(phoneId, enabled);
                    } else {
                        log(msg.what + " failure. Not updating modem status." + ar.exception);
                    }
                    break;
            }
        }
    }
@@ -123,6 +169,48 @@ public class PhoneConfigurationManager {
            return;
        }
        phone.mCi.enableModem(enable, result);
        updatePhoneStatus(phone);
    }

    /**
     * Get phone status (enabled/disabled)
     *
     * @param phone which phone to operate on
     */
    public boolean getPhoneStatus(Phone phone) {
        if (phone == null) {
            log("getPhonetatus failed phone is null");
            return false;
        }

        int phoneId = phone.getPhoneId();

        //use cache if the status has already been updated/queried
        if (mPhoneStatusMap.containsKey(phoneId)) {
            return mPhoneStatusMap.get(phoneId);
        } else {
            //return false if modem status is not in cache
            updatePhoneStatus(phone);
            return false;
        }
    }

    /**
     * method to call RIL getM
     */
    private void updatePhoneStatus(Phone phone) {
        Message callback = Message.obtain(
                mHandler, EVENT_GET_MODEM_STATUS_DONE, phone.getPhoneId(), 0 /**dummy arg*/);
        phone.mCi.getModemStatus(callback);
    }

    /**
     * Add status of the phone to the status HashMap
     * @param phoneId
     * @param status
     */
    public void addToPhoneStatusCache(int phoneId, boolean status) {
        mPhoneStatusMap.put(phoneId, status);
    }

    /**
+2 −1
Original line number Diff line number Diff line
@@ -242,7 +242,8 @@ public class PhoneFactory {

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

                sPhoneConfigurationManager = PhoneConfigurationManager.init(sContext);
                sPhoneConfigurationManager = PhoneConfigurationManager.init(
                        sContext);

                sCellularNetworkValidator = CellularNetworkValidator.make(sContext);

+33 −0
Original line number Diff line number Diff line
@@ -902,6 +902,37 @@ public class RIL extends BaseCommands implements CommandsInterface {
        }
    }

    @Override
    public void getModemStatus(Message result) {
        IRadio radioProxy = getRadioProxy(result);
        if (mRadioVersion.less(RADIO_HAL_VERSION_1_3)) {
            if (RILJ_LOGV) riljLog("getModemStatus: not supported.");
            if (result != null) {
                AsyncResult.forMessage(result, null,
                        CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
                result.sendToTarget();
            }
            return;
        }

        android.hardware.radio.V1_3.IRadio radioProxy13 =
                (android.hardware.radio.V1_3.IRadio) radioProxy;
        if (radioProxy13 != null) {
            RILRequest rr = obtainRequest(RIL_REQUEST_GET_MODEM_STATUS, result,
                    mRILDefaultWorkSource);

            if (RILJ_LOGD) {
                riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
            }

            try {
                radioProxy13.getModemStackStatus(rr.mSerial);
            } catch (RemoteException | RuntimeException e) {
                handleRadioProxyExceptionForRR(rr, "getModemStatus", e);
            }
        }
    }

    @Override
    public void dial(String address, boolean isEmergencyCall, EmergencyNumber emergencyNumberInfo,
                     boolean hasKnownUserIntentEmergency, int clirMode, UUSInfo uusInfo,
@@ -5307,6 +5338,8 @@ public class RIL extends BaseCommands implements CommandsInterface {
                return "RIL_REQUEST_SET_LINK_CAPACITY_REPORTING_CRITERIA";
            case RIL_REQUEST_ENABLE_MODEM:
                return "RIL_REQUEST_ENABLE_MODEM";
            case RIL_REQUEST_GET_MODEM_STATUS:
                return "RIL_REQUEST_GET_MODEM_STATUS";
            default: return "<unknown request>";
        }
    }