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

Commit 03e8e4fc authored by Chen Xu's avatar Chen Xu Committed by android-build-merger
Browse files

Merge "refactor radiopowerstate" am: a1e55d4b

am: a3bac4a8

Change-Id: I379be6442004e3a0cc4fa92ab47cff74e8b05a05
parents 39afbab4 a3bac4a8
Loading
Loading
Loading
Loading
+20 −15
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ import android.telephony.TelephonyManager;
public abstract class BaseCommands implements CommandsInterface {
    //***** Instance Variables
    protected Context mContext;
    protected RadioState mState = RadioState.RADIO_UNAVAILABLE;
    protected int mState = TelephonyManager.RADIO_POWER_UNAVAILABLE;
    protected Object mStateMonitor = new Object();

    protected RegistrantList mRadioStateChangedRegistrants = new RegistrantList();
@@ -117,7 +117,7 @@ public abstract class BaseCommands implements CommandsInterface {
    //***** CommandsInterface implementation

    @Override
    public RadioState getRadioState() {
    public @TelephonyManager.RadioPowerState int getRadioState() {
        return mState;
    }

@@ -154,7 +154,7 @@ public abstract class BaseCommands implements CommandsInterface {
        synchronized (mStateMonitor) {
            mOnRegistrants.add(r);

            if (mState.isOn()) {
            if (mState == TelephonyManager.RADIO_POWER_ON) {
                r.notifyRegistrant(new AsyncResult(null, null, null));
            }
        }
@@ -174,7 +174,7 @@ public abstract class BaseCommands implements CommandsInterface {
        synchronized (mStateMonitor) {
            mAvailRegistrants.add(r);

            if (mState.isAvailable()) {
            if (mState != TelephonyManager.RADIO_POWER_UNAVAILABLE) {
                r.notifyRegistrant(new AsyncResult(null, null, null));
            }
        }
@@ -194,7 +194,7 @@ public abstract class BaseCommands implements CommandsInterface {
        synchronized (mStateMonitor) {
            mNotAvailRegistrants.add(r);

            if (!mState.isAvailable()) {
            if (mState == TelephonyManager.RADIO_POWER_UNAVAILABLE) {
                r.notifyRegistrant(new AsyncResult(null, null, null));
            }
        }
@@ -214,7 +214,8 @@ public abstract class BaseCommands implements CommandsInterface {
        synchronized (mStateMonitor) {
            mOffOrNotAvailRegistrants.add(r);

            if (mState == RadioState.RADIO_OFF || !mState.isAvailable()) {
            if (mState == TelephonyManager.RADIO_POWER_OFF
                    || mState == TelephonyManager.RADIO_POWER_UNAVAILABLE) {
                r.notifyRegistrant(new AsyncResult(null, null, null));
            }
        }
@@ -791,12 +792,13 @@ public abstract class BaseCommands implements CommandsInterface {
     *
     * RadioState has 3 values : RADIO_OFF, RADIO_UNAVAILABLE, RADIO_ON.
     *
     * @param newState new RadioState decoded from RIL_UNSOL_RADIO_STATE_CHANGED
     * @param newState new radio power state decoded from RIL_UNSOL_RADIO_STATE_CHANGED
     * @param forceNotifyRegistrants boolean indicating if registrants should be notified even if
     * there is no change in state
     */
    protected void setRadioState(RadioState newState, boolean forceNotifyRegistrants) {
        RadioState oldState;
    protected void setRadioState(@TelephonyManager.RadioPowerState int newState,
                                 boolean forceNotifyRegistrants) {
        int oldState;

        synchronized (mStateMonitor) {
            oldState = mState;
@@ -809,21 +811,24 @@ public abstract class BaseCommands implements CommandsInterface {

            mRadioStateChangedRegistrants.notifyRegistrants();

            if (mState.isAvailable() && !oldState.isAvailable()) {
            if (mState != TelephonyManager.RADIO_POWER_UNAVAILABLE
                    && oldState == TelephonyManager.RADIO_POWER_UNAVAILABLE) {
                mAvailRegistrants.notifyRegistrants();
            }

            if (!mState.isAvailable() && oldState.isAvailable()) {
            if (mState == TelephonyManager.RADIO_POWER_UNAVAILABLE
                    && oldState != TelephonyManager.RADIO_POWER_UNAVAILABLE) {
                mNotAvailRegistrants.notifyRegistrants();
            }

            if (mState.isOn() && !oldState.isOn()) {
            if (mState == TelephonyManager.RADIO_POWER_ON
                    && oldState != TelephonyManager.RADIO_POWER_ON) {
                mOnRegistrants.notifyRegistrants();
            }

            if ((!mState.isOn() || !mState.isAvailable())
                && !((!oldState.isOn() || !oldState.isAvailable()))
            ) {
            if ((mState == TelephonyManager.RADIO_POWER_OFF
                    || mState == TelephonyManager.RADIO_POWER_UNAVAILABLE)
                    && (oldState == TelephonyManager.RADIO_POWER_ON)) {
                mOffOrNotAvailRegistrants.notifyRegistrants();
            }
        }
+7 −14
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.service.carrier.CarrierIdentifier;
import android.telephony.ClientRequestStats;
import android.telephony.ImsiEncryptionInfo;
import android.telephony.NetworkScanRequest;
import android.telephony.TelephonyManager;
import android.telephony.data.DataProfile;

import com.android.internal.telephony.cdma.CdmaSmsBroadcastConfigInfo;
@@ -37,19 +38,6 @@ import java.util.List;
 * {@hide}
 */
public interface CommandsInterface {
    enum RadioState {
        RADIO_OFF,         /* Radio explicitly powered off (eg CFUN=0) */
        RADIO_UNAVAILABLE, /* Radio unavailable (eg, resetting or not booted) */
        RADIO_ON;          /* Radio is on */

        public boolean isOn() /* and available...*/ {
            return this == RADIO_ON;
        }

        public boolean isAvailable() {
            return this != RADIO_UNAVAILABLE;
        }
    }

    //***** Constants

@@ -121,7 +109,12 @@ public interface CommandsInterface {
    static final int CDMA_SMS_FAIL_CAUSE_ENCODING_PROBLEM           = 96;

    //***** Methods
    RadioState getRadioState();

    /**
     * get latest radio power state from modem
     * @return
     */
    @TelephonyManager.RadioPowerState int getRadioState();

    /**
     * response.obj.result is an int[2]
+9 −0
Original line number Diff line number Diff line
@@ -353,6 +353,15 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
        }
    }

    @Override
    public void notifyRadioPowerStateChanged(@TelephonyManager.RadioPowerState int state) {
        try {
            mRegistry.notifyRadioPowerStateChanged(state);
        } catch (RemoteException ex) {
            // system process is dead
        }
    }

    /**
     * Convert the {@link Phone.DataActivityState} enum into the TelephonyManager.DATA_* constants
     * for the public API.
+1 −1
Original line number Diff line number Diff line
@@ -620,7 +620,7 @@ public class GsmCdmaCallTracker extends CallTracker {
        String disableCall = SystemProperties.get(
                TelephonyProperties.PROPERTY_DISABLE_CALL, "false");

        if (!mCi.getRadioState().isOn()) {
        if (mCi.getRadioState() != TelephonyManager.RADIO_POWER_ON) {
            throw new CallStateException(CallStateException.ERROR_POWER_OFF,
                    "Modem not powered");
        }
+17 −5
Original line number Diff line number Diff line
@@ -261,6 +261,7 @@ public class GsmCdmaPhone extends Phone {
        mCi.registerForAvailable(this, EVENT_RADIO_AVAILABLE, null);
        mCi.registerForOffOrNotAvailable(this, EVENT_RADIO_OFF_OR_NOT_AVAILABLE, null);
        mCi.registerForOn(this, EVENT_RADIO_ON, null);
        mCi.registerForRadioStateChanged(this, EVENT_RADIO_STATE_CHANGED, null);
        mCi.setOnSuppServiceNotification(this, EVENT_SSN, null);

        //GSM
@@ -396,14 +397,14 @@ public class GsmCdmaPhone extends Phone {
        onUpdateIccAvailability();
        mCT.updatePhoneType();

        CommandsInterface.RadioState radioState = mCi.getRadioState();
        if (radioState.isAvailable()) {
        int radioState = mCi.getRadioState();
        if (radioState != TelephonyManager.RADIO_POWER_UNAVAILABLE) {
            handleRadioAvailable();
            if (radioState.isOn()) {
            if (radioState == TelephonyManager.RADIO_POWER_ON) {
                handleRadioOn();
            }
        }
        if (!radioState.isAvailable() || !radioState.isOn()) {
        if (radioState != TelephonyManager.RADIO_POWER_ON) {
            handleRadioOffOrNotAvailable();
        }
    }
@@ -2221,6 +2222,11 @@ public class GsmCdmaPhone extends Phone {
        mRadioOffOrNotAvailableRegistrants.notifyRegistrants();
    }

    private void handleRadioPowerStateChange() {
        Rlog.d(LOG_TAG, "handleRadioPowerStateChange, state= " + mCi.getRadioState());
        mNotifier.notifyRadioPowerStateChanged(mCi.getRadioState());
    }

    @Override
    public void handleMessage(Message msg) {
        AsyncResult ar;
@@ -2474,6 +2480,12 @@ public class GsmCdmaPhone extends Phone {
                break;
            }

            case EVENT_RADIO_STATE_CHANGED: {
                logd("EVENT EVENT_RADIO_STATE_CHANGED");
                handleRadioPowerStateChange();
                break;
            }

            case EVENT_SSN:
                logd("Event EVENT_SSN Received");
                if (isPhoneTypeGsm()) {
@@ -3372,7 +3384,7 @@ public class GsmCdmaPhone extends Phone {

        boolean oldPowerState = false; // old power state to off
        if (mResetModemOnRadioTechnologyChange) {
            if (mCi.getRadioState().isOn()) {
            if (mCi.getRadioState() == TelephonyManager.RADIO_POWER_ON) {
                oldPowerState = true;
                logd("phoneObjectUpdater: Setting Radio Power to Off");
                mCi.setRadioPower(false, null);
Loading