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

Commit 32eb9171 authored by Yincheng Zhao's avatar Yincheng Zhao Committed by Gerrit Code Review
Browse files

Merge "Adding API in TelephonyManger for updating Fplmns."

parents 871d5592 da2ec5cc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -45055,6 +45055,7 @@ package android.telephony {
    method @RequiresPermission(android.Manifest.permission.CALL_PHONE) public void sendUssdRequest(String, android.telephony.TelephonyManager.UssdResponseCallback, android.os.Handler);
    method public void sendVisualVoicemailSms(String, int, String, android.app.PendingIntent);
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataEnabled(boolean);
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int setForbiddenPlmns(@NonNull java.util.List<java.lang.String>);
    method public boolean setLine1NumberForDisplay(String, String);
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setNetworkSelectionModeAutomatic();
    method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setNetworkSelectionModeManual(String, boolean);
+24 −3
Original line number Diff line number Diff line
@@ -35,6 +35,15 @@ public abstract class CellIdentity implements Parcelable {
    /** @hide */
    public static final int INVALID_CHANNEL_NUMBER = -1;

    /**
     * parameters for validation
     * @hide
     */
    public static final int MCC_LENGTH = 3;

    private static final int MNC_MIN_LENGTH = 2;
    private static final int MNC_MAX_LENGTH = 3;

    // Log tag
    /** @hide */
    protected final String mTag;
@@ -207,6 +216,17 @@ public abstract class CellIdentity implements Parcelable {
        dest.writeString(mAlphaShort);
    }

    /** Used by phone interface manager to verify if a given string is valid MccMnc
     * @hide
     */
    public static boolean isValidPlmn(@NonNull String plmn) {
        if (plmn.length() < MCC_LENGTH + MNC_MIN_LENGTH
                || plmn.length() > MCC_LENGTH + MNC_MAX_LENGTH) {
            return false;
        }
        return (isMcc(plmn.substring(0, MCC_LENGTH)) && isMnc(plmn.substring(MCC_LENGTH)));
    }

    /**
     * Construct from Parcel
     * @hide
@@ -267,10 +287,10 @@ public abstract class CellIdentity implements Parcelable {
    /** @hide */
    private static boolean isMcc(@NonNull String mcc) {
        // ensure no out of bounds indexing
        if (mcc.length() != 3) return false;
        if (mcc.length() != MCC_LENGTH) return false;

        // Character.isDigit allows all unicode digits, not just [0-9]
        for (int i = 0; i < 3; i++) {
        for (int i = 0; i < MCC_LENGTH; i++) {
            if (mcc.charAt(i) < '0' || mcc.charAt(i) > '9') return false;
        }

@@ -280,7 +300,7 @@ public abstract class CellIdentity implements Parcelable {
    /** @hide */
    private static boolean isMnc(@NonNull String mnc) {
        // ensure no out of bounds indexing
        if (mnc.length() < 2 || mnc.length() > 3) return false;
        if (mnc.length() < MNC_MIN_LENGTH || mnc.length() > MNC_MAX_LENGTH) return false;

        // Character.isDigit allows all unicode digits, not just [0-9]
        for (int i = 0; i < mnc.length(); i++) {
@@ -289,4 +309,5 @@ public abstract class CellIdentity implements Parcelable {

        return true;
    }

}
+34 −0
Original line number Diff line number Diff line
@@ -6755,6 +6755,40 @@ public class TelephonyManager {
        }
    }

    /**
     * Replace the contents of the forbidden PLMN SIM file with the provided values.
     * Passing an empty list will clear the contents of the EFfplmn file.
     * If the provided list is shorter than the size of EFfplmn, then the list will be padded
     * up to the file size with 'FFFFFF'. (required by 3GPP TS 31.102 spec 4.2.16)
     * If the list is longer than the size of EFfplmn, then the file will be written from the
     * beginning of the list up to the file size.
     *
     * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
     * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}).
     *
     * @param fplmns a list of PLMNs to be forbidden.
     *
     * @return number of PLMNs that were successfully written to the SIM FPLMN list.
     * This may be less than the number of PLMNs passed in where the SIM file does not have enough
     * room for all of the values passed in. Return -1 in the event of an unexpected failure
     */
    @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
    public int setForbiddenPlmns(@NonNull List<String> fplmns) {
        try {
            ITelephony telephony = getITelephony();
            if (telephony == null) return 0;
            return telephony.setForbiddenPlmns(
                    getSubId(), APPTYPE_USIM, fplmns, getOpPackageName());
        } catch (RemoteException ex) {
            Rlog.e(TAG, "setForbiddenPlmns RemoteException: " + ex.getMessage());
        } catch (NullPointerException ex) {
            // This could happen before phone starts
            Rlog.e(TAG, "setForbiddenPlmns NullPointerException: " + ex.getMessage());
        }
        return 0;
    }

    /**
     * Get P-CSCF address from PCO after data connection is established or modified.
     * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN
+12 −0
Original line number Diff line number Diff line
@@ -1602,6 +1602,18 @@ interface ITelephony {
     */
    String[] getForbiddenPlmns(int subId, int appType, String callingPackage);

    /**
     * Set the forbidden PLMN list from the givven app type (ex APPTYPE_USIM) on a particular
     * subscription.
     *
     * @param subId subId the id of the subscription
     * @param appType appType the uicc app type, must be USIM or SIM.
     * @param fplmns plmns the Forbiden plmns list that needed to be written to the SIM.
     * @param content callingPackage the op Package name.
     * @return number of fplmns that is successfully written to the SIM
     */
    int setForbiddenPlmns(int subId, int appType, in List<String> fplmns, String callingPackage);

    /**
     * Check if phone is in emergency callback mode
     * @return true if phone is in emergency callback mode
+30 −0
Original line number Diff line number Diff line
@@ -22,9 +22,11 @@ import android.graphics.Bitmap;
import android.graphics.Color;
import android.telephony.Rlog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.GsmAlphabet;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * Various methods, useful for dealing with SIM data.
@@ -32,6 +34,11 @@ import java.io.UnsupportedEncodingException;
public class IccUtils {
    static final String LOG_TAG="IccUtils";

    // 3GPP specification constants
    // Spec reference TS 31.102 section 4.2.16
    @VisibleForTesting
    static final int FPLMN_BYTE_SIZE = 3;

    // A table mapping from a number to a hex character for fast encoding hex strings.
    private static final char[] HEX_CHARS = {
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
@@ -883,4 +890,27 @@ public class IccUtils {
        }
        return 0;
    }

    /**
     * Encode the Fplmns into byte array to write to EF.
     *
     * @param fplmns Array of fplmns to be serialized.
     * @param dataLength the size of the EF file.
     * @return the encoded byte array in the correct format for FPLMN file.
     */
    public static byte[] encodeFplmns(List<String> fplmns, int dataLength) {
        byte[] serializedFplmns = new byte[dataLength];
        int offset = 0;
        for (String fplmn : fplmns) {
            if (offset >= dataLength) break;
            stringToBcdPlmn(fplmn, serializedFplmns, offset);
            offset += FPLMN_BYTE_SIZE;
        }
        //pads to the length of the EF file.
        while (offset < dataLength) {
            // required by 3GPP TS 31.102 spec 4.2.16
            serializedFplmns[offset++] = (byte) 0xff;
        }
        return serializedFplmns;
    }
}