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

Commit 195d5e1b authored by Thomas Nguyen's avatar Thomas Nguyen Committed by Android (Google) Code Review
Browse files

Merge "Add internal implementation to support the new APIs used by owner...

Merge "Add internal implementation to support the new APIs used by owner groups to vote on radio power state"
parents 4daa604e 1c3e7936
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -1817,7 +1818,7 @@ public class GsmCdmaPhone extends Phone {
    public void setRadioPower(boolean power, boolean forEmergencyCall,
            boolean isSelectedPhoneForEmergencyCall, boolean forceApply) {
        setRadioPowerForReason(power, forEmergencyCall, isSelectedPhoneForEmergencyCall, forceApply,
                Phone.RADIO_POWER_REASON_USER);
                TelephonyManager.RADIO_POWER_REASON_USER);
    }

    @Override
@@ -1827,6 +1828,11 @@ public class GsmCdmaPhone extends Phone {
                forceApply, reason);
    }

    @Override
    public Set<Integer> getRadioPowerOffReasons() {
        return mSST.getRadioPowerOffReasons();
    }

    private void storeVoiceMailNumber(String number) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
        SharedPreferences.Editor editor = sp.edit();
+1 −1
Original line number Diff line number Diff line
@@ -1932,7 +1932,7 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    public boolean isRadioOffForThermalMitigation() {
        ServiceStateTracker sst = getServiceStateTracker();
        return sst != null && sst.getRadioPowerOffReasons()
                .contains(Phone.RADIO_POWER_REASON_THERMAL);
                .contains(TelephonyManager.RADIO_POWER_REASON_THERMAL);
    }

    /**
+19 −20
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.internal.telephony;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Build;
@@ -36,9 +35,9 @@ import android.telephony.emergency.EmergencyNumber;

import com.android.internal.telephony.PhoneConstants.DataState;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;

/**
@@ -211,16 +210,6 @@ public interface PhoneInternalInterface {
    static final String REASON_DATA_UNTHROTTLED = "dataUnthrottled";
    static final String REASON_TRAFFIC_DESCRIPTORS_UPDATED = "trafficDescriptorsUpdated";

    // Reasons for Radio being powered off
    int RADIO_POWER_REASON_USER = 0;
    int RADIO_POWER_REASON_THERMAL = 1;
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = {"RADIO_POWER_REASON_"},
        value = {
            RADIO_POWER_REASON_USER,
            RADIO_POWER_REASON_THERMAL})
    public @interface RadioPowerReason {}

    // Used for band mode selection methods
    static final int BM_UNSPECIFIED = RILConstants.BAND_MODE_UNSPECIFIED; // automatic
    static final int BM_EURO_BAND   = RILConstants.BAND_MODE_EURO;
@@ -593,8 +582,9 @@ public interface PhoneInternalInterface {
     * getServiceState().getState() will not change immediately after this call.
     * registerForServiceStateChanged() to find out when the
     * request is complete. This will set the reason for radio power state as {@link
     * #RADIO_POWER_REASON_USER}. This will not guarantee that the requested radio power state will
     * actually be set. See {@link #setRadioPowerForReason(boolean, boolean, boolean, boolean, int)}
     * android.telephony.TelephonyManager#RADIO_POWER_REASON_USER}. This will not guarantee that the
     * requested radio power state will actually be set.
     * See {@link #setRadioPowerForReason(boolean, boolean, boolean, boolean, int)}
     * for details.
     *
     * @param power true means "on", false means "off".
@@ -620,8 +610,9 @@ public interface PhoneInternalInterface {
     * getServiceState().getState() will not change immediately after this call.
     * registerForServiceStateChanged() to find out when the
     * request is complete. This will set the reason for radio power state as {@link
     * #RADIO_POWER_REASON_USER}. This will not guarantee that the requested radio power state will
     * actually be set. See {@link #setRadioPowerForReason(boolean, boolean, boolean, boolean, int)}
     * android.telephony.TelephonyManager#RADIO_POWER_REASON_USER}. This will not guarantee that the
     * requested radio power state will actually be set.
     * See {@link #setRadioPowerForReason(boolean, boolean, boolean, boolean, int)}
     * for details.
     *
     * @param power true means "on", false means "off".
@@ -638,7 +629,7 @@ public interface PhoneInternalInterface {
    default void setRadioPower(boolean power, boolean forEmergencyCall,
            boolean isSelectedPhoneForEmergencyCall, boolean forceApply) {
        setRadioPowerForReason(power, forEmergencyCall, isSelectedPhoneForEmergencyCall, forceApply,
                RADIO_POWER_REASON_USER);
                TelephonyManager.RADIO_POWER_REASON_USER);
    }

    /**
@@ -656,10 +647,18 @@ public interface PhoneInternalInterface {
     * @param power true means "on", false means "off".
     * @param reason RadioPowerReason constant defining the reason why the radio power was set.
     */
    default void setRadioPowerForReason(boolean power, @RadioPowerReason int reason) {
    default void setRadioPowerForReason(boolean power,
            @TelephonyManager.RadioPowerReason int reason) {
        setRadioPowerForReason(power, false, false, false, reason);
    }

    /**
     * @return reasons for powering off radio.
     */
    default Set<Integer> getRadioPowerOffReasons() {
        return new HashSet<>();
    }

    /**
     * Sets the radio power on/off state with option to specify whether it's for emergency call
     * (off is sometimes called "airplane mode") and option to set the reason for setting the power
@@ -686,7 +685,7 @@ public interface PhoneInternalInterface {
     */
    default void setRadioPowerForReason(boolean power, boolean forEmergencyCall,
            boolean isSelectedPhoneForEmergencyCall, boolean forceApply,
            @RadioPowerReason int reason) {}
            @TelephonyManager.RadioPowerReason int reason) {}

    /**
     * Get the line 1 phone number (MSISDN). For CDMA phones, the MDN is returned
+18 −33
Original line number Diff line number Diff line
@@ -323,8 +323,6 @@ public class ServiceStateTracker extends Handler {
    private CarrierDisplayNameResolver mCdnr;

    private boolean mImsRegistrationOnOff = false;
    /** Radio is disabled by carrier. Radio power will not be override if this field is set */
    private boolean mRadioDisabledByCarrier = false;
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    private boolean mDeviceShuttingDown = false;
    /** Keep track of SPN display rules, so we only broadcast intent if something changes. */
@@ -686,7 +684,7 @@ public class ServiceStateTracker extends Handler {
                Settings.Global.ENABLE_CELLULAR_ON_BOOT, 1);
        mDesiredPowerState = (enableCellularOnBoot > 0) && ! (airplaneMode > 0);
        if (!mDesiredPowerState) {
            mRadioPowerOffReasons.add(Phone.RADIO_POWER_REASON_USER);
            mRadioPowerOffReasons.add(TelephonyManager.RADIO_POWER_REASON_USER);
        }
        mRadioPowerLog.log("init : airplane mode = " + airplaneMode + " enableCellularOnBoot = " +
                enableCellularOnBoot);
@@ -872,7 +870,10 @@ public class ServiceStateTracker extends Handler {
    public boolean getDesiredPowerState() {
        return mDesiredPowerState;
    }
    public boolean getPowerStateFromCarrier() { return !mRadioDisabledByCarrier; }

    public boolean getPowerStateFromCarrier() {
        return !mRadioPowerOffReasons.contains(TelephonyManager.RADIO_POWER_REASON_CARRIER);
    }

    public List<PhysicalChannelConfig> getPhysicalChannelConfigList() {
        return mLastPhysicalChannelConfigList;
@@ -1062,7 +1063,7 @@ public class ServiceStateTracker extends Handler {
     * @return the current reasons for which the radio is off.
     */
    public Set<Integer> getRadioPowerOffReasons() {
        return mRadioPowerOffReasons;
        return Set.copyOf(mRadioPowerOffReasons);
    }

    /**
@@ -1088,7 +1089,7 @@ public class ServiceStateTracker extends Handler {
    public void setRadioPower(boolean power, boolean forEmergencyCall,
            boolean isSelectedPhoneForEmergencyCall, boolean forceApply) {
        setRadioPowerForReason(power, forEmergencyCall, isSelectedPhoneForEmergencyCall, forceApply,
                Phone.RADIO_POWER_REASON_USER);
                TelephonyManager.RADIO_POWER_REASON_USER);
    }

    /**
@@ -1128,23 +1129,6 @@ public class ServiceStateTracker extends Handler {
        setPowerStateToDesired(forEmergencyCall, isSelectedPhoneForEmergencyCall, forceApply);
    }

    /**
     * Radio power set from carrier action. if set to false means carrier desire to turn radio off
     * and radio wont be re-enabled unless carrier explicitly turn it back on.
     * @param enable indicate if radio power is enabled or disabled from carrier action.
     */
    public void setRadioPowerFromCarrier(boolean enable) {
        boolean disableByCarrier = !enable;
        if (mRadioDisabledByCarrier == disableByCarrier) {
            log("setRadioPowerFromCarrier mRadioDisabledByCarrier is already "
                    + disableByCarrier + " Do nothing.");
            return;
        }

        mRadioDisabledByCarrier = disableByCarrier;
        setPowerStateToDesired();
    }

    /**
     * These two flags manage the behavior of the cell lock -- the
     * lock should be held if either flag is true.  The intention is
@@ -1670,7 +1654,8 @@ public class ServiceStateTracker extends Handler {
                if (ar.exception == null) {
                    boolean enable = (boolean) ar.result;
                    if (DBG) log("EVENT_RADIO_POWER_FROM_CARRIER: " + enable);
                    setRadioPowerFromCarrier(enable);
                    setRadioPowerForReason(enable, false, false, false,
                            TelephonyManager.RADIO_POWER_REASON_CARRIER);
                }
                break;

@@ -3113,12 +3098,12 @@ public class ServiceStateTracker extends Handler {
    protected void setPowerStateToDesired(boolean forEmergencyCall,
            boolean isSelectedPhoneForEmergencyCall, boolean forceApply) {
        if (DBG) {
            String tmpLog = "setPowerStateToDesired: mDeviceShuttingDown=" + mDeviceShuttingDown +
                    ", mDesiredPowerState=" + mDesiredPowerState +
                    ", getRadioState=" + mCi.getRadioState() +
                    ", mRadioDisabledByCarrier=" + mRadioDisabledByCarrier +
                    ", IMS reg state=" + mImsRegistrationOnOff +
                    ", pending radio off=" + hasMessages(EVENT_POWER_OFF_RADIO_IMS_DEREG_TIMEOUT);
            String tmpLog = "setPowerStateToDesired: mDeviceShuttingDown=" + mDeviceShuttingDown
                    + ", mDesiredPowerState=" + mDesiredPowerState
                    + ", getRadioState=" + mCi.getRadioState()
                    + ", mRadioPowerOffReasons=" + mRadioPowerOffReasons
                    + ", IMS reg state=" + mImsRegistrationOnOff
                    + ", pending radio off=" + hasMessages(EVENT_POWER_OFF_RADIO_IMS_DEREG_TIMEOUT);
            log(tmpLog);
            mRadioPowerLog.log(tmpLog);
        }
@@ -3130,10 +3115,10 @@ public class ServiceStateTracker extends Handler {
        }

        // If we want it on and it's off, turn it on
        if (mDesiredPowerState && !mRadioDisabledByCarrier
        if (mDesiredPowerState && mRadioPowerOffReasons.isEmpty()
                && (forceApply || mCi.getRadioState() == TelephonyManager.RADIO_POWER_OFF)) {
            mCi.setRadioPower(true, forEmergencyCall, isSelectedPhoneForEmergencyCall, null);
        } else if ((!mDesiredPowerState || mRadioDisabledByCarrier) && mCi.getRadioState()
        } else if ((!mDesiredPowerState || !mRadioPowerOffReasons.isEmpty()) && mCi.getRadioState()
                == TelephonyManager.RADIO_POWER_ON) {
            // If it's on and available and we want it off gracefully
            if (!mPhone.isUsingNewDataStack() && mImsRegistrationOnOff
@@ -5410,7 +5395,7 @@ public class ServiceStateTracker extends Handler {
        pw.println(" mImsRegistrationOnOff=" + mImsRegistrationOnOff);
        pw.println(" pending radio off event="
                + hasMessages(EVENT_POWER_OFF_RADIO_IMS_DEREG_TIMEOUT));
        pw.println(" mRadioDisabledByCarrier" + mRadioDisabledByCarrier);
        pw.println(" mRadioPowerOffReasons=" + mRadioPowerOffReasons);
        pw.println(" mDeviceShuttingDown=" + mDeviceShuttingDown);
        pw.println(" mSpnUpdatePending=" + mSpnUpdatePending);
        pw.println(" mCellInfoMinIntervalMs=" + mCellInfoMinIntervalMs);
+5 −4
Original line number Diff line number Diff line
@@ -1297,11 +1297,12 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
    public void testSetRadioPower() throws Exception {
        mPhoneUT.setRadioPower(false);
        verify(mSST).setRadioPowerForReason(false, false, false, false,
                Phone.RADIO_POWER_REASON_USER);
                TelephonyManager.RADIO_POWER_REASON_USER);

        // Turn on radio for emergency call.
        mPhoneUT.setRadioPower(true, true, false, true);
        verify(mSST).setRadioPowerForReason(true, true, false, true, Phone.RADIO_POWER_REASON_USER);
        verify(mSST).setRadioPowerForReason(true, true, false, true,
                TelephonyManager.RADIO_POWER_REASON_USER);
    }

    @Test
@@ -1309,12 +1310,12 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
    public void testSetRadioPowerOnForTestEmergencyCall() {
        mPhoneUT.setRadioPower(false);
        verify(mSST).setRadioPowerForReason(false, false, false, false,
                Phone.RADIO_POWER_REASON_USER);
                TelephonyManager.RADIO_POWER_REASON_USER);

        mPhoneUT.setRadioPowerOnForTestEmergencyCall(false);
        verify(mSST).clearAllRadioOffReasons();
        verify(mSST).setRadioPowerForReason(eq(true), eq(false), anyBoolean(), eq(false),
                eq(Phone.RADIO_POWER_REASON_USER));
                eq(TelephonyManager.RADIO_POWER_REASON_USER));
    }

    @Test
Loading