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

Commit f5cefda0 authored by arunvoddu's avatar arunvoddu Committed by Arun kumar Voddu
Browse files

CarrierRestrictionStatus public API implementation

Bug:189884347
Test: Verified CTS and also verified using Test Application

Change-Id: Id630239b4d65dca1c07ebcfc4e0b8b0fbae82d38
parent 8ed2a596
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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<java.lang.Integer>);
    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
+22 −0
Original line number Diff line number Diff line
@@ -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<CarrierIdentifier>();
        mExcludedCarriers = new ArrayList<CarrierIdentifier>();
        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;
        }
    }
}
+75 −0
Original line number Diff line number Diff line
@@ -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.
     * <p>To fetch the carrier restriction status of the device the calling application needs to be
     * allowlisted to Android at <a href="https://android.googlesource.com/platform/packages/services/Telephony/+/master/assets/CarrierRestrictionOperatorDetails.json">here</a>.
     * The calling application also needs the READ_PHONE_STATE permission.
     * The return value of the API is as follows.
     * <ul>
     *      <li>return {@link #CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER} if the caller
     *      and the device locked by the network are same</li>
     *      <li>return {@link #CARRIER_RESTRICTION_STATUS_RESTRICTED} if the caller and the
     *      device locked by the network are different</li>
     *      <li>return {@link #CARRIER_RESTRICTION_STATUS_NOT_RESTRICTED} if the device is
     *      not locked</li>
     *      <li>return {@link #CARRIER_RESTRICTION_STATUS_UNKNOWN} if the device locking
     *      state is unavailable or radio does not supports the feature</li>
     * </ul>
     *
     * @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<Integer> 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
+5 −0
Original line number Diff line number Diff line
@@ -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);
}