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

Commit cffde72f authored by arunvoddu's avatar arunvoddu
Browse files

Refactor the ImsiEncryption key download scenarios.

1. Retry the download in fail scenarios like device screen is locked or Internet is not avilable.
2. Do not delete the Key from the DB when a sim is disabled/removed where same operetor sim is active in another slot.
3. Optimize the logic not to execute on every carrierConfig change call.

Bug: 320955199
Test: Verified manually also atest tests/telephonytests/src/com/android/internal/telephony/CarrierKeyDownloadMgrTest.java
Change-Id: Ic77c8f923cda1728e81db9e64a15ca86b73d2069
parent fb9fa4b8
Loading
Loading
Loading
Loading
+26 −4
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;

import com.android.internal.telephony.flags.Flags;
import com.android.internal.telephony.metrics.TelephonyMetrics;

import java.security.PublicKey;
@@ -297,7 +298,12 @@ public class CarrierInfoManager {
        final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class)
                .createForSubscriptionId(subId);
        int carrierId = telephonyManager.getSimCarrierId();
        if (Flags.imsiKeyRetryDownloadOnPhoneUnlock()) {
            String simOperator = telephonyManager.getSimOperator();
            deleteCarrierInfoForImsiEncryption(context, subId, carrierId, simOperator);
        } else {
            deleteCarrierInfoForImsiEncryption(context, subId, carrierId);
        }
        Intent resetIntent = new Intent(TelephonyIntents.ACTION_CARRIER_CERTIFICATE_DOWNLOAD);
        SubscriptionManager.putPhoneIdAndSubIdExtra(resetIntent, mPhoneId);
        context.sendBroadcastAsUser(resetIntent, UserHandle.ALL);
@@ -312,13 +318,29 @@ public class CarrierInfoManager {
     */
    public static void deleteCarrierInfoForImsiEncryption(Context context, int subId,
            int carrierId) {
        deleteCarrierInfoForImsiEncryption(context, subId, carrierId, null);
    }

    /**
     * Deletes all the keys for a given Carrier from the device keystore.
     * @param context Context
     * @param subId SubscriptionId
     * @param carrierId delete the key which matches the carrierId
     * @param simOperator delete the key which matches the MCCMNC
     *
     */
    public static void deleteCarrierInfoForImsiEncryption(Context context, int subId,
            int carrierId, String simOperator) {
        Log.i(LOG_TAG, "deleting carrier key from db for subId=" + subId);
        String mcc = "";
        String mnc = "";

        final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class)
        if (TextUtils.isEmpty(simOperator)) {
            final TelephonyManager telephonyManager = context.getSystemService(
                            TelephonyManager.class)
                    .createForSubscriptionId(subId);
        String simOperator = telephonyManager.getSimOperator();
            simOperator = telephonyManager.getSimOperator();
        }
        if (!TextUtils.isEmpty(simOperator)) {
            mcc = simOperator.substring(0, 3);
            mnc = simOperator.substring(3);