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

Commit 0c13fd19 authored by SongFerngWang's avatar SongFerngWang
Browse files

Add getPhoneCapability function in TelephonyManager

- Add a resource for Device's Nr information.
- Expose below as systemApi
  - getDeviceNrCapabilityBitmask()
  - getMaxActiveInternetData()
  - getMaxActivePacketSwitchedVoiceCalls()
Bug: 175711587
Test: atest TelephonyManager#testGetPhoneCapability
atest PhoneCapabilityTest
atest PhoneConfigurationManagerTest
atest CellularNetworkValidatorTest
atest PhoneSwitcherTest
atest TelephonyRegistryTest
atest PhoneCapabilityTest

Change-Id: Ide25344787c15b3a57a9e6621766ad02a906f12e
Merged-In: Ide25344787c15b3a57a9e6621766ad02a906f12e
parent cdfdcdad
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -40287,12 +40287,6 @@ package android.telephony {
    field public static final int SCAN_TYPE_PERIODIC = 1; // 0x1
  }
  public final class PhoneCapability implements android.os.Parcelable {
    method public int describeContents();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.telephony.PhoneCapability> CREATOR;
  }
  public class PhoneNumberFormattingTextWatcher implements android.text.TextWatcher {
    ctor public PhoneNumberFormattingTextWatcher();
    ctor public PhoneNumberFormattingTextWatcher(String);
+13 −0
Original line number Diff line number Diff line
@@ -9753,6 +9753,18 @@ package android.telephony {
    field public static final int REASON_UNSPECIFIED = 0; // 0x0
  }
  public final class PhoneCapability implements android.os.Parcelable {
    method public int describeContents();
    method public int getDeviceNrCapabilityBitmask();
    method @IntRange(from=1) public int getMaxActiveInternetData();
    method @IntRange(from=1) public int getMaxActivePacketSwitchedVoiceCalls();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.telephony.PhoneCapability> CREATOR;
    field public static final int DEVICE_NR_CAPABILITY_NONE = 0; // 0x0
    field public static final int DEVICE_NR_CAPABILITY_NSA = 1; // 0x1
    field public static final int DEVICE_NR_CAPABILITY_SA = 2; // 0x2
  }
  public final class PhoneNumberRange implements android.os.Parcelable {
    ctor public PhoneNumberRange(@NonNull String, @NonNull String, @NonNull String, @NonNull String);
    method public int describeContents();
@@ -10272,6 +10284,7 @@ package android.telephony {
    method public int getMaxNumberOfSimultaneouslyActiveSims();
    method public static long getMaxNumberVerificationTimeoutMillis();
    method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String[] getMergedImsisFromGroup();
    method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public android.telephony.PhoneCapability getPhoneCapability();
    method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public long getPreferredNetworkTypeBitmask();
    method @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public int getRadioPowerState();
    method public int getSimApplicationState();
+5 −0
Original line number Diff line number Diff line
@@ -4426,4 +4426,9 @@

    <!-- Whether to allow the caching of the SIM PIN for verification after unattended reboot -->
    <bool name="config_allow_pin_storage_for_unattended_reboot">true</bool>

    <!-- Whether the device enable the standalone (SA) mode of 5G NR.-->
    <bool name="config_telephony5gStandalone">false</bool>
    <!-- Whether the device enable the non-standalone (NSA) mode of 5G NR.-->
    <bool name="config_telephony5gNonStandalone">false</bool>
</resources>
+3 −0
Original line number Diff line number Diff line
@@ -4075,4 +4075,7 @@
  <java-symbol type="array" name="config_keep_warming_services" />

  <java-symbol type="bool" name="config_voice_data_sms_auto_fallback" />

  <java-symbol type="bool" name="config_telephony5gStandalone" />
  <java-symbol type="bool" name="config_telephony5gNonStandalone" />
</resources>
+165 −43
Original line number Diff line number Diff line
@@ -16,19 +16,26 @@

package android.telephony;

import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * Define capability of a modem group. That is, the capabilities
 * are shared between those modems defined by list of modem IDs.
 * Phone capability which describes the data connection capability of modem.
 * It's used to evaluate possible phone config change, for example from single
 * SIM device to multi-SIM device.
 * @hide
 */
@SystemApi
public final class PhoneCapability implements Parcelable {
    // Hardcoded default DSDS capability.
    /** @hide */
@@ -37,6 +44,38 @@ public final class PhoneCapability implements Parcelable {
    /** @hide */
    public static final PhoneCapability DEFAULT_SSSS_CAPABILITY;

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = { "DEVICE_NR_CAPABILITY_" }, value = {
            DEVICE_NR_CAPABILITY_NONE,
            DEVICE_NR_CAPABILITY_NSA,
            DEVICE_NR_CAPABILITY_SA,
    })
    public @interface DeviceNrCapability {}

    /**
     * Indicates DEVICE_NR_CAPABILITY_NONE determine that the device does not enable 5G NR.
     * @hide
     */
    @SystemApi
    public static final int DEVICE_NR_CAPABILITY_NONE = 0;

    /**
     * Indicates DEVICE_NR_CAPABILITY_NSA determine that the device enable the non-standalone
     * (NSA) mode of 5G NR.
     * @hide
     */
    @SystemApi
    public static final int DEVICE_NR_CAPABILITY_NSA = 1 << 0;

    /**
     * Indicates DEVICE_NR_CAPABILITY_SA determine that the device enable the standalone (SA)
     * mode of 5G NR.
     * @hide
     */
    @SystemApi
    public static final int DEVICE_NR_CAPABILITY_SA = 1 << 1;

    static {
        ModemInfo modemInfo1 = new ModemInfo(0, 0, true, true);
        ModemInfo modemInfo2 = new ModemInfo(1, 0, true, true);
@@ -44,55 +83,85 @@ public final class PhoneCapability implements Parcelable {
        List<ModemInfo> logicalModemList = new ArrayList<>();
        logicalModemList.add(modemInfo1);
        logicalModemList.add(modemInfo2);
        DEFAULT_DSDS_CAPABILITY = new PhoneCapability(1, 1, 0, logicalModemList, false);
        DEFAULT_DSDS_CAPABILITY = new PhoneCapability(1, 1, logicalModemList, false,
                DEVICE_NR_CAPABILITY_NONE);

        logicalModemList = new ArrayList<>();
        logicalModemList.add(modemInfo1);
        DEFAULT_SSSS_CAPABILITY = new PhoneCapability(1, 1, 0, logicalModemList, false);
        DEFAULT_SSSS_CAPABILITY = new PhoneCapability(1, 1, logicalModemList, false,
                DEVICE_NR_CAPABILITY_NONE);
    }

    /**
     * MaxActivePsVoice defines the maximum number of active voice calls.  For a dual sim dual
     * standby (DSDS) modem it would be one, but for a dual sim dual active modem it would be 2.
     *
     * @hide
     */
    private final int mMaxActivePsVoice;

    /**
     * MaxActiveInternetData defines how many logical modems can have
     * PS attached simultaneously. For example, for L+L modem it
     * should be 2.
     *
     * @hide
     */
    private final int mMaxActiveInternetData;

    /**
     * Whether modem supports both internet PDN up so
     * that we can do ping test before tearing down the
     * other one.
     *
     * @hide
     */
    private final boolean mNetworkValidationBeforeSwitchSupported;

    /** @hide */
    public final int maxActiveVoiceCalls;
    /** @hide */
    public final int maxActiveData;
    /** @hide */
    public final int max5G;
    /** @hide */
    public final boolean validationBeforeSwitchSupported;
    /** @hide */
    public final List<ModemInfo> logicalModemList;
    private final List<ModemInfo> mLogicalModemList;

    /**
     * List of logical modem information.
     *
     * @hide
     */
    private final int mDeviceNrCapability;

    /** @hide */
    public PhoneCapability(int maxActiveVoiceCalls, int maxActiveData, int max5G,
            List<ModemInfo> logicalModemList, boolean validationBeforeSwitchSupported) {
        this.maxActiveVoiceCalls = maxActiveVoiceCalls;
        this.maxActiveData = maxActiveData;
        this.max5G = max5G;
    public PhoneCapability(int maxActivePsVoice, int maxActiveInternetData,
            List<ModemInfo> logicalModemList, boolean networkValidationBeforeSwitchSupported,
            int deviceNrCapability) {
        this.mMaxActivePsVoice = maxActivePsVoice;
        this.mMaxActiveInternetData = maxActiveInternetData;
        // Make sure it's not null.
        this.logicalModemList = logicalModemList == null ? new ArrayList<>() : logicalModemList;
        this.validationBeforeSwitchSupported = validationBeforeSwitchSupported;
        this.mLogicalModemList = logicalModemList == null ? new ArrayList<>() : logicalModemList;
        this.mNetworkValidationBeforeSwitchSupported = networkValidationBeforeSwitchSupported;
        this.mDeviceNrCapability = deviceNrCapability;
    }

    @Override
    public String toString() {
        return "maxActiveVoiceCalls=" + maxActiveVoiceCalls + " maxActiveData=" + maxActiveData
                + " max5G=" + max5G + "logicalModemList:"
                + Arrays.toString(logicalModemList.toArray());
        return "mMaxActivePsVoice=" + mMaxActivePsVoice
                + " mMaxActiveInternetData=" + mMaxActiveInternetData
                + " mNetworkValidationBeforeSwitchSupported="
                + mNetworkValidationBeforeSwitchSupported
                + " mDeviceNrCapability " + mDeviceNrCapability;
    }

    private PhoneCapability(Parcel in) {
        maxActiveVoiceCalls = in.readInt();
        maxActiveData = in.readInt();
        max5G = in.readInt();
        validationBeforeSwitchSupported = in.readBoolean();
        logicalModemList = new ArrayList<>();
        in.readList(logicalModemList, ModemInfo.class.getClassLoader());
        mMaxActivePsVoice = in.readInt();
        mMaxActiveInternetData = in.readInt();
        mNetworkValidationBeforeSwitchSupported = in.readBoolean();
        mLogicalModemList = new ArrayList<>();
        in.readList(mLogicalModemList, ModemInfo.class.getClassLoader());
        mDeviceNrCapability = in.readInt();
    }

    @Override
    public int hashCode() {
        return Objects.hash(maxActiveVoiceCalls, maxActiveData, max5G, logicalModemList,
                validationBeforeSwitchSupported);
        return Objects.hash(mMaxActivePsVoice, mMaxActiveInternetData, mLogicalModemList,
                mNetworkValidationBeforeSwitchSupported, mDeviceNrCapability);
    }

    @Override
@@ -107,11 +176,12 @@ public final class PhoneCapability implements Parcelable {

        PhoneCapability s = (PhoneCapability) o;

        return (maxActiveVoiceCalls == s.maxActiveVoiceCalls
                && maxActiveData == s.maxActiveData
                && max5G == s.max5G
                && validationBeforeSwitchSupported == s.validationBeforeSwitchSupported
                && logicalModemList.equals(s.logicalModemList));
        return (mMaxActivePsVoice == s.mMaxActivePsVoice
                && mMaxActiveInternetData == s.mMaxActiveInternetData
                && mNetworkValidationBeforeSwitchSupported
                == s.mNetworkValidationBeforeSwitchSupported
                && mLogicalModemList.equals(s.mLogicalModemList)
                && mDeviceNrCapability == s.mDeviceNrCapability);
    }

    /**
@@ -125,14 +195,15 @@ public final class PhoneCapability implements Parcelable {
     * {@link Parcelable#writeToParcel}
     */
    public void writeToParcel(@NonNull Parcel dest, @Parcelable.WriteFlags int flags) {
        dest.writeInt(maxActiveVoiceCalls);
        dest.writeInt(maxActiveData);
        dest.writeInt(max5G);
        dest.writeBoolean(validationBeforeSwitchSupported);
        dest.writeList(logicalModemList);
        dest.writeInt(mMaxActivePsVoice);
        dest.writeInt(mMaxActiveInternetData);
        dest.writeBoolean(mNetworkValidationBeforeSwitchSupported);
        dest.writeList(mLogicalModemList);
        dest.writeInt(mDeviceNrCapability);
    }

    public static final @android.annotation.NonNull Parcelable.Creator<PhoneCapability> CREATOR = new Parcelable.Creator() {
    public static final @android.annotation.NonNull Parcelable.Creator<PhoneCapability> CREATOR =
            new Parcelable.Creator() {
        public PhoneCapability createFromParcel(Parcel in) {
            return new PhoneCapability(in);
        }
@@ -141,4 +212,55 @@ public final class PhoneCapability implements Parcelable {
            return new PhoneCapability[size];
        }
    };

    /**
     * @return the maximum number of active packet-switched calls.  For a dual
     * sim dual standby (DSDS) modem it would be one, but for a dual sim dual active modem it
     * would be 2.
     * @hide
     */
    @SystemApi
    public @IntRange(from = 1) int getMaxActivePacketSwitchedVoiceCalls() {
        return mMaxActivePsVoice;
    }

    /**
     * @return MaxActiveInternetData defines how many logical modems can have PS attached
     * simultaneously.
     * For example, for L+L modem it should be 2.
     * @hide
     */
    @SystemApi
    public @IntRange(from = 1) int getMaxActiveInternetData() {
        return mMaxActiveInternetData;
    }

    /**
     * @return Check whether the Citizens Broadband Radio Service(CBRS) network validation before
     * CBRS switch is supported or not.
     *
     * @hide
     */
    public boolean isNetworkValidationBeforeSwitchSupported() {
        return mNetworkValidationBeforeSwitchSupported;
    }

    /**
     * @return The list of logical modem information.
     * @hide
     */
    public List<ModemInfo> getLogicalModemList() {
        return mLogicalModemList;
    }

    /**
     * Return the device's NR capability.
     *
     * @return {@link DeviceNrCapability} the device's NR capability.
     * @hide
     */
    @SystemApi
    public @DeviceNrCapability int getDeviceNrCapabilityBitmask() {
        return mDeviceNrCapability;
    }
}
Loading