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

Commit 6d8e76f0 authored by Pengquan Meng's avatar Pengquan Meng
Browse files

Add get/set PreferredNetworkTypeBitmap

Bug: 111453000
Test: build
Change-Id: Icbd3b2108ce8eb75e863dcf38fb8249c1e37ea91
parent 2da29013
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6097,6 +6097,7 @@ package android.telephony {
    method public boolean getEmergencyCallbackMode();
    method public java.lang.String getIsimDomain();
    method public int getPreferredNetworkType(int);
    method public int getPreferredNetworkTypeBitmap();
    method public int getRadioPowerState();
    method public int getSimApplicationState();
    method public int getSimCardState();
@@ -6125,6 +6126,7 @@ package android.telephony {
    method public void setDataActivationState(int);
    method public deprecated void setDataEnabled(int, boolean);
    method public void setDataRoamingEnabled(boolean);
    method public boolean setPreferredNetworkTypeBitmap(int);
    method public boolean setRadio(boolean);
    method public boolean setRadioPower(boolean);
    method public void setSimPowerState(int);
+64 −1
Original line number Diff line number Diff line
@@ -6382,8 +6382,9 @@ public class TelephonyManager {
    public @PrefNetworkMode int getPreferredNetworkType(int subId) {
        try {
            ITelephony telephony = getITelephony();
            if (telephony != null)
            if (telephony != null) {
                return telephony.getPreferredNetworkType(subId);
            }
        } catch (RemoteException ex) {
            Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex);
        } catch (NullPointerException ex) {
@@ -6392,6 +6393,37 @@ public class TelephonyManager {
        return -1;
    }

    /**
     * Get the preferred network type bitmap.
     *
     * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the
     * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()}
     *
     * <p>Requires Permission:
     * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE}
     * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}).
     *
     * @return a 32-bit bitmap.
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
    @SystemApi
    public @NetworkTypeBitMask int getPreferredNetworkTypeBitmap() {
        try {
            ITelephony telephony = getITelephony();
            if (telephony != null) {
                return RadioAccessFamily.getRafFromNetworkType(
                        telephony.getPreferredNetworkType(getSubId()));
            }
        } catch (RemoteException ex) {
            Rlog.e(TAG, "getPreferredNetworkTypeBitmap RemoteException", ex);
        } catch (NullPointerException ex) {
            Rlog.e(TAG, "getPreferredNetworkTypeBitmap NPE", ex);
        }
        return 0;
    }

    /**
     * Sets the network selection mode to automatic.
     *
@@ -6606,6 +6638,37 @@ public class TelephonyManager {
        return false;
    }

    /**
     * Set the preferred network type bitmap.
     *
     * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the
     * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()}
     *
     * <p>Requires Permission:
     * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling
     * app has carrier privileges (see {@link #hasCarrierPrivileges}).
     *
     * @param networkTypeBitmap a 32-bit bitmap.
     * @return true on success; false on any failure.
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
    @SystemApi
    public boolean setPreferredNetworkTypeBitmap(@NetworkTypeBitMask int networkTypeBitmap) {
        try {
            ITelephony telephony = getITelephony();
            if (telephony != null) {
                return telephony.setPreferredNetworkType(
                        getSubId(), RadioAccessFamily.getNetworkTypeFromRaf(networkTypeBitmap));
            }
        } catch (RemoteException ex) {
            Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex);
        } catch (NullPointerException ex) {
            Rlog.e(TAG, "setPreferredNetworkType NPE", ex);
        }
        return false;
    }

    /**
     * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA.
     *