From f5cefda066c8aaa9651388e359986047f3f1ee07 Mon Sep 17 00:00:00 2001 From: arunvoddu Date: Thu, 15 Dec 2022 15:56:06 +0000 Subject: [PATCH] CarrierRestrictionStatus public API implementation Bug:189884347 Test: Verified CTS and also verified using Test Application Change-Id: Id630239b4d65dca1c07ebcfc4e0b8b0fbae82d38 --- core/api/current.txt | 5 ++ .../telephony/CarrierRestrictionRules.java | 22 ++++++ .../android/telephony/TelephonyManager.java | 75 +++++++++++++++++++ .../internal/telephony/ITelephony.aidl | 5 ++ 4 files changed, 107 insertions(+) diff --git a/core/api/current.txt b/core/api/current.txt index 0ad7d80ea508d..6670c449ba584 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -44822,6 +44822,7 @@ package android.telephony { method public int getCardIdForDefaultEuicc(); method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) @WorkerThread public android.os.PersistableBundle getCarrierConfig(); method public int getCarrierIdFromSimMccMnc(); + method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public void getCarrierRestrictionStatus(@NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer); method @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public android.telephony.CellLocation getCellLocation(); method public int getDataActivity(); method @RequiresPermission(anyOf={android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.READ_BASIC_PHONE_STATE}) public int getDataNetworkType(); @@ -44981,6 +44982,10 @@ package android.telephony { field public static final int CALL_STATE_OFFHOOK = 2; // 0x2 field public static final int CALL_STATE_RINGING = 1; // 0x1 field public static final String CAPABILITY_SLICING_CONFIG_SUPPORTED = "CAPABILITY_SLICING_CONFIG_SUPPORTED"; + field public static final int CARRIER_RESTRICTION_STATUS_NOT_RESTRICTED = 1; // 0x1 + field public static final int CARRIER_RESTRICTION_STATUS_RESTRICTED = 2; // 0x2 + field public static final int CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER = 3; // 0x3 + field public static final int CARRIER_RESTRICTION_STATUS_UNKNOWN = 0; // 0x0 field public static final int CDMA_ROAMING_MODE_AFFILIATED = 1; // 0x1 field public static final int CDMA_ROAMING_MODE_ANY = 2; // 0x2 field public static final int CDMA_ROAMING_MODE_HOME = 0; // 0x0 diff --git a/telephony/java/android/telephony/CarrierRestrictionRules.java b/telephony/java/android/telephony/CarrierRestrictionRules.java index ceea94b5d82a8..eac4d1682aa91 100644 --- a/telephony/java/android/telephony/CarrierRestrictionRules.java +++ b/telephony/java/android/telephony/CarrierRestrictionRules.java @@ -104,12 +104,15 @@ public final class CarrierRestrictionRules implements Parcelable { private int mCarrierRestrictionDefault; @MultiSimPolicy private int mMultiSimPolicy; + @TelephonyManager.CarrierRestrictionStatus + private int mCarrierRestrictionStatus; private CarrierRestrictionRules() { mAllowedCarriers = new ArrayList(); mExcludedCarriers = new ArrayList(); mCarrierRestrictionDefault = CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED; mMultiSimPolicy = MULTISIM_POLICY_NONE; + mCarrierRestrictionStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; } private CarrierRestrictionRules(Parcel in) { @@ -120,6 +123,7 @@ public final class CarrierRestrictionRules implements Parcelable { in.readTypedList(mExcludedCarriers, CarrierIdentifier.CREATOR); mCarrierRestrictionDefault = in.readInt(); mMultiSimPolicy = in.readInt(); + mCarrierRestrictionStatus = in.readInt(); } /** @@ -289,6 +293,11 @@ public final class CarrierRestrictionRules implements Parcelable { return true; } + /** @hide */ + public int getCarrierRestrictionStatus() { + return mCarrierRestrictionStatus; + } + /** * {@link Parcelable#writeToParcel} */ @@ -298,6 +307,7 @@ public final class CarrierRestrictionRules implements Parcelable { out.writeTypedList(mExcludedCarriers); out.writeInt(mCarrierRestrictionDefault); out.writeInt(mMultiSimPolicy); + out.writeInt(mCarrierRestrictionStatus); } /** @@ -399,5 +409,17 @@ public final class CarrierRestrictionRules implements Parcelable { mRules.mMultiSimPolicy = multiSimPolicy; return this; } + + /** + * Set the device's carrier restriction status + * + * @param carrierRestrictionStatus device restriction status + * @hide + */ + public @NonNull + Builder setCarrierRestrictionStatus(int carrierRestrictionStatus) { + mRules.mCarrierRestrictionStatus = carrierRestrictionStatus; + return this; + } } } diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 0ad5ba0eaa472..89c823c13a265 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -13136,6 +13136,81 @@ public class TelephonyManager { return null; } + /** + * Carrier restriction status value is unknown, in case modem did not provide any + * information about carrier restriction status. + */ + public static final int CARRIER_RESTRICTION_STATUS_UNKNOWN = 0; + + /** The device is not restricted to a carrier */ + public static final int CARRIER_RESTRICTION_STATUS_NOT_RESTRICTED = 1; + + /** The device is restricted to a carrier. */ + public static final int CARRIER_RESTRICTION_STATUS_RESTRICTED = 2; + + /** The device is restricted to the carrier of the calling application. */ + public static final int CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER = 3; + + /** @hide */ + @IntDef(prefix = {"CARRIER_RESTRICTION_STATUS_"}, value = { + CARRIER_RESTRICTION_STATUS_UNKNOWN, + CARRIER_RESTRICTION_STATUS_NOT_RESTRICTED, + CARRIER_RESTRICTION_STATUS_RESTRICTED, + CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER + }) + + public @interface CarrierRestrictionStatus { + } + + /** + * Get the carrier restriction status of the device. + *

To fetch the carrier restriction status of the device the calling application needs to be + * allowlisted to Android at here. + * The calling application also needs the READ_PHONE_STATE permission. + * The return value of the API is as follows. + *

    + *
  • return {@link #CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER} if the caller + * and the device locked by the network are same
  • + *
  • return {@link #CARRIER_RESTRICTION_STATUS_RESTRICTED} if the caller and the + * device locked by the network are different
  • + *
  • return {@link #CARRIER_RESTRICTION_STATUS_NOT_RESTRICTED} if the device is + * not locked
  • + *
  • return {@link #CARRIER_RESTRICTION_STATUS_UNKNOWN} if the device locking + * state is unavailable or radio does not supports the feature
  • + *
+ * + * @param executor The executor on which the result listener will be called. + * @param resultListener {@link Consumer} that will be called with the result fetched + * from the radio of type {@link CarrierRestrictionStatus} + * @throws SecurityException if the caller does not have the required permission/privileges or + * if the caller is not pre-registered. + */ + @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) + @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) + public void getCarrierRestrictionStatus(@NonNull Executor executor, + @NonNull @CarrierRestrictionStatus + Consumer resultListener) { + Objects.requireNonNull(executor); + Objects.requireNonNull(resultListener); + + IIntegerConsumer internalCallback = new IIntegerConsumer.Stub() { + @Override + public void accept(@CarrierRestrictionStatus int result) { + executor.execute(() -> Binder.withCleanCallingIdentity( + () -> resultListener.accept(result))); + } + }; + try { + ITelephony service = getITelephony(); + if (service != null) { + service.getCarrierRestrictionStatus(internalCallback, getOpPackageName()); + } + } catch (RemoteException ex) { + Rlog.e(TAG, "getCarrierRestrictionStatus: RemoteException = " + ex); + throw ex.rethrowAsRuntimeException(); + } + } + /** * Used to enable or disable carrier data by the system based on carrier signalling or * carrier privileged apps. Different from {@link #setDataEnabled(boolean)} which is linked to diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index c7ed347b15bce..6099cb134e6ea 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -2687,4 +2687,9 @@ interface ITelephony { * @return {@code true} if the domain selection service is supported. */ boolean isDomainSelectionSupported(); + + /** + * Get the carrier restriction status of the device. + */ + void getCarrierRestrictionStatus(IIntegerConsumer internalCallback, String packageName); }