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

Commit 69cdf8e2 authored by Jiashen Wang's avatar Jiashen Wang
Browse files

Add isEuiccSupportedCountry system API to EuiccManager

Currently LPA passed supported/unsupported countries to Settings by
writing the value into properties which is not ideal. Instead, we need to
provide an API in EuiccManager to determine whether eUICC is supported
in a country.
Bug: 147674689
Test: 1) Manually tested by flashing the change to the device
2) Change LPA to override onGetIsEuiccSupportedCountry
3) Make sure LPA can get the request

Change-Id: I01c7df59a6257eb908bc179c5491ca371daa154d
parent 214cee0d
Loading
Loading
Loading
Loading
+90 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.internal.telephony.euicc;


import android.Manifest;
import android.Manifest;
import android.Manifest.permission;
import android.Manifest.permission;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.app.AppOpsManager;
import android.app.AppOpsManager;
import android.app.PendingIntent;
import android.app.PendingIntent;
@@ -53,6 +54,7 @@ import com.android.internal.telephony.euicc.EuiccConnector.OtaStatusChangedCallb


import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.List;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReference;
@@ -83,6 +85,11 @@ public class EuiccController extends IEuiccController.Stub {
    private final AppOpsManager mAppOpsManager;
    private final AppOpsManager mAppOpsManager;
    private final PackageManager mPackageManager;
    private final PackageManager mPackageManager;


    // These values should be set or updated upon 1) system boot, 2) EuiccService/LPA is bound to
    // the phone process, 3) values are updated remotely by server flags.
    private List<String> mSupportedCountries;
    private List<String> mUnsupportedCountries;

    /** Initialize the instance. Should only be called once. */
    /** Initialize the instance. Should only be called once. */
    public static EuiccController init(Context context) {
    public static EuiccController init(Context context) {
        synchronized (EuiccController.class) {
        synchronized (EuiccController.class) {
@@ -242,6 +249,89 @@ public class EuiccController extends IEuiccController.Stub {
                subscription, false /* forceDeactivateSim */, callingPackage, callbackIntent);
                subscription, false /* forceDeactivateSim */, callingPackage, callbackIntent);
    }
    }


    /**
     * Sets the supported or unsupported countries for eUICC.
     *
     * <p>If {@code isSupported} is true, the supported country list will be replaced by
     * {@code countriesList}. Otherwise, unsupported country list will be replaced by
     * {@code countriesList}. For how we determine whether a country is supported by checking
     * supported and unsupported country list please check {@link EuiccManager#isSupportedCountry}.
     *
     * @param isSupported should be true if caller wants to set supported country list. If
     * isSupported is false, un-supported country list will be updated.
     * @param countriesList is a list of strings contains country ISO codes in uppercase.
     */
    @Override
    public void setSupportedCountries(boolean isSupported, @NonNull List<String> countriesList) {
        if (isSupported) {
            mSupportedCountries = countriesList;
        } else {
            mUnsupportedCountries = countriesList;
        }
    }

    /**
     * Gets the supported or unsupported countries for eUICC.
     *
     * <p>If {@code isSupported} is true, the supported country list will be returned. Otherwise,
     * unsupported country list will be returned.
     *
     * @param isSupported should be true if caller wants to get supported country list. If
     * isSupported is false, unsupported country list will be returned.
     * @return a list of strings contains country ISO codes in uppercase.
     */
    @Override
    @NonNull
    public List<String> getSupportedCountries(boolean isSupported) {
        if (isSupported && mSupportedCountries != null) {
            return mSupportedCountries;
        } else if (!isSupported && mUnsupportedCountries != null) {
            return mUnsupportedCountries;
        }
        return Collections.emptyList();
    }

    /**
     * Returns whether the given country supports eUICC.
     *
     * <p>Supported country list has a higher prority than unsupported country list. If the
     * supported country list is not empty, {@code countryIso} will be considered as supported when
     * it exists in the supported country list. Otherwise {@code countryIso} is not supported. If
     * the supported country list is empty, {@code countryIso} will be considered as supported if it
     * does not exist in the unsupported country list. Otherwise {@code countryIso} is not
     * supported. If both supported and unsupported country lists are empty, then all countries are
     * consider be supported. For how to set supported and unsupported country list, please check
     * {@link #setSupportedCountries}.
     *
     * @param countryIso should be the ISO-3166 country code is provided in uppercase 2 character
     * format.
     * @return whether the given country supports eUICC or not.
     */
    @Override
    public boolean isSupportedCountry(@NonNull String countryIso) {
        if (mSupportedCountries == null || mSupportedCountries.isEmpty()) {
            Log.i(TAG, "Using blacklist unsupportedCountries=" + mUnsupportedCountries);
            return !isEsimUnsupportedCountry(countryIso);
        } else {
            Log.i(TAG, "Using whitelist supportedCountries=" + mSupportedCountries);
            return isEsimSupportedCountry(countryIso);
        }
    }

    private boolean isEsimSupportedCountry(String countryIso) {
        if (mSupportedCountries == null || TextUtils.isEmpty(countryIso)) {
            return true;
        }
        return mSupportedCountries.contains(countryIso);
    }

    private boolean isEsimUnsupportedCountry(String countryIso) {
        if (mUnsupportedCountries == null || TextUtils.isEmpty(countryIso)) {
            return false;
        }
        return mUnsupportedCountries.contains(countryIso);
    }

    void getDownloadableSubscriptionMetadata(int cardId, DownloadableSubscription subscription,
    void getDownloadableSubscriptionMetadata(int cardId, DownloadableSubscription subscription,
            boolean forceDeactivateSim, String callingPackage, PendingIntent callbackIntent) {
            boolean forceDeactivateSim, String callingPackage, PendingIntent callbackIntent) {
        if (!callerCanWriteEmbeddedSubscriptions()) {
        if (!callerCanWriteEmbeddedSubscriptions()) {