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

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

Reattempt to download the IMSIEncryption key when the device is unlocked.

Bug: 303780982
Test: atest tests/telephonytests/src/com/android/internal/telephony and
manually verified using test APK.

Change-Id: Ib315b41b2eed1c725cb9c95b88f26cd57cccc86f
parent ec2b2663
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -6,3 +6,9 @@ flag {
    description: "This flag controls eSIM Bootstrap provisioning feature support."
    bug:"298567545"
}
flag {
    name: "imsi_key_retry_download_on_phone_unlock"
    namespace: "telephony"
    description: "This flag controls to download the IMSI encryption keys after user unlocks the phone."
    bug:"303780982"
}
 No newline at end of file
+30 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;

import android.app.AlarmManager;
import android.app.DownloadManager;
import android.app.KeyguardManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -40,6 +41,7 @@ import android.util.Log;
import android.util.Pair;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.flags.FeatureFlags;

import org.json.JSONArray;
import org.json.JSONException;
@@ -108,6 +110,7 @@ public class CarrierKeyDownloadManager extends Handler {
    private String mURL;
    private boolean mAllowedOverMeteredNetwork = false;
    private boolean mDeleteOldKeyAfterDownload = false;
    private boolean mIsRequiredToHandleUnlock;
    private TelephonyManager mTelephonyManager;
    private UserManager mUserManager;

@@ -116,13 +119,16 @@ public class CarrierKeyDownloadManager extends Handler {
    public int mCarrierId;
    @VisibleForTesting
    public long mDownloadId;
    private final FeatureFlags mFeatureFlags;

    public CarrierKeyDownloadManager(Phone phone) {
    public CarrierKeyDownloadManager(Phone phone, FeatureFlags featureFlags) {
        mPhone = phone;
        mFeatureFlags = featureFlags;
        mContext = phone.getContext();
        IntentFilter filter = new IntentFilter();
        filter.addAction(INTENT_KEY_RENEWAL_ALARM_PREFIX);
        filter.addAction(TelephonyIntents.ACTION_CARRIER_CERTIFICATE_DOWNLOAD);
        filter.addAction(Intent.ACTION_USER_PRESENT);
        mContext.registerReceiver(mBroadcastReceiver, filter, null, phone);
        mDownloadManager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
        mTelephonyManager = mContext.getSystemService(TelephonyManager.class)
@@ -186,6 +192,16 @@ public class CarrierKeyDownloadManager extends Handler {
                    Log.d(LOG_TAG, "Handling reset intent: " + action);
                    sendEmptyMessage(EVENT_ALARM_OR_CONFIG_CHANGE);
                }
            }  else if (action.equals(Intent.ACTION_USER_PRESENT)) {
                // The Carrier key download fails when SIM is inserted while device is locked
                // hence adding a retry logic when device is unlocked.
                Log.d(LOG_TAG,
                        "device unlocked, isRequiredToHandleUnlock = " + mIsRequiredToHandleUnlock
                                + ", slotIndex = " + slotIndex);
                if (mIsRequiredToHandleUnlock) {
                    mIsRequiredToHandleUnlock = false;
                    sendEmptyMessage(EVENT_ALARM_OR_CONFIG_CHANGE);
                }
            }
        }
    };
@@ -224,6 +240,16 @@ public class CarrierKeyDownloadManager extends Handler {
                // keys, we'll still want to renew the alarms, and try downloading the key a day
                // later.
                if (!downloadStartedSuccessfully) {
                    // If download fails due to the device lock, we will reattempt once the device
                    // is unlocked.
                    if (mFeatureFlags.imsiKeyRetryDownloadOnPhoneUnlock()) {
                        KeyguardManager keyguardManager = mContext.getSystemService(
                                KeyguardManager.class);
                        if (keyguardManager.isKeyguardSecure()) {
                            Log.e(LOG_TAG, "Key download failed in device lock state");
                            mIsRequiredToHandleUnlock = true;
                        }
                    }
                    resetRenewalAlarm();
                }
            } else {
@@ -233,6 +259,7 @@ public class CarrierKeyDownloadManager extends Handler {
            // delete any existing alarms.
            cleanupRenewalAlarms();
            mPhone.deleteCarrierInfoForImsiEncryption(getSimCarrierId());

        }
    }

@@ -622,7 +649,8 @@ public class CarrierKeyDownloadManager extends Handler {
            mCarrierId = carrierId;
            mDownloadId = carrierKeyDownloadRequestId;
        } catch (Exception e) {
            Log.e(LOG_TAG, "exception trying to download key from url: " + mURL);
            Log.e(LOG_TAG, "exception trying to download key from url: " + mURL + ", Exception = "
                    + e.getMessage());
            return false;
        }
        return true;
+1 −1
Original line number Diff line number Diff line
@@ -511,7 +511,7 @@ public class GsmCdmaPhone extends Phone {
        mContext.registerReceiver(mBroadcastReceiver, filter,
                android.Manifest.permission.MODIFY_PHONE_STATE, null, Context.RECEIVER_EXPORTED);

        mCDM = new CarrierKeyDownloadManager(this);
        mCDM = new CarrierKeyDownloadManager(this, mFeatureFlags);
        mCIM = new CarrierInfoManager();

        initializeCarrierApps();
+6 −2
Original line number Diff line number Diff line
@@ -41,12 +41,15 @@ import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.util.Pair;

import com.android.internal.telephony.flags.FeatureFlags;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;

import java.security.PublicKey;
import java.text.SimpleDateFormat;
@@ -87,7 +90,7 @@ public class CarrierKeyDownloadMgrTest extends TelephonyTest {
                    + "\"public-key\": \"" + CERT + "\"}]}";

    private CarrierConfigManager.CarrierConfigChangeListener mCarrierConfigChangeListener;

    private FeatureFlags mFeatureFlags;
    @Before
    public void setUp() throws Exception {
        logd("CarrierActionAgentTest +Setup!");
@@ -98,7 +101,8 @@ public class CarrierKeyDownloadMgrTest extends TelephonyTest {
        // Capture listener to emulate the carrier config change notification used later
        ArgumentCaptor<CarrierConfigManager.CarrierConfigChangeListener> listenerArgumentCaptor =
                ArgumentCaptor.forClass(CarrierConfigManager.CarrierConfigChangeListener.class);
        mCarrierKeyDM = new CarrierKeyDownloadManager(mPhone);
        mFeatureFlags = Mockito.mock(FeatureFlags.class);
        mCarrierKeyDM = new CarrierKeyDownloadManager(mPhone, mFeatureFlags);
        verify(mCarrierConfigManager).registerCarrierConfigChangeListener(any(),
                listenerArgumentCaptor.capture());
        mCarrierConfigChangeListener = listenerArgumentCaptor.getAllValues().get(0);