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

Commit 3b17c63f authored by Dmitry Dementyev's avatar Dmitry Dementyev
Browse files

Implement RecoverableKeyStoreLoader.setSnapshotCreatedPendingIntent

Bug: 66499222
Test: adb shell am instrument -w -e package \
com.android.server.locksettings.recoverablekeystore \
com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner

Change-Id: I45905a2594ae5b4a681f15e78a7f63293c8fb4d5
parent 897719ef
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ public class RecoverableKeyStoreManager {
    private final RecoverableKeyStoreDb mDatabase;
    private final RecoverySessionStorage mRecoverySessionStorage;
    private final ExecutorService mExecutorService;
    private final ListenersStorage mListenersStorage;

    /**
     * Returns a new or existing instance.
@@ -77,7 +78,8 @@ public class RecoverableKeyStoreManager {
                    mContext.getApplicationContext(),
                    db,
                    new RecoverySessionStorage(),
                    Executors.newSingleThreadExecutor());
                    Executors.newSingleThreadExecutor(),
                    ListenersStorage.getInstance());
        }
        return mInstance;
    }
@@ -87,11 +89,13 @@ public class RecoverableKeyStoreManager {
            Context context,
            RecoverableKeyStoreDb recoverableKeyStoreDb,
            RecoverySessionStorage recoverySessionStorage,
            ExecutorService executorService) {
            ExecutorService executorService,
            ListenersStorage listenersStorage) {
        mContext = context;
        mDatabase = recoverableKeyStoreDb;
        mRecoverySessionStorage = recoverySessionStorage;
        mExecutorService = executorService;
        mListenersStorage = listenersStorage;
    }

    public int initRecoveryService(
@@ -134,7 +138,8 @@ public class RecoverableKeyStoreManager {
    public void setSnapshotCreatedPendingIntent(@Nullable PendingIntent intent, int userId)
            throws RemoteException {
        checkRecoverKeyStorePermission();
        throw new UnsupportedOperationException();
        final int recoveryAgentUid = Binder.getCallingUid();
        mListenersStorage.setSnapshotListener(recoveryAgentUid, intent);
    }

    /**
+16 −1
Original line number Diff line number Diff line
@@ -27,7 +27,10 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.RemoteException;
import android.security.recoverablekeystore.KeyDerivationParameters;
import android.security.recoverablekeystore.KeyEntryRecoveryData;
@@ -89,6 +92,7 @@ public class RecoverableKeyStoreManagerTest {
    private static final String TEST_ALIAS = "nick";

    @Mock private Context mMockContext;
    @Mock private ListenersStorage mMockListenersStorage;

    private RecoverableKeyStoreDb mRecoverableKeyStoreDb;
    private File mDatabaseFile;
@@ -107,7 +111,8 @@ public class RecoverableKeyStoreManagerTest {
                mMockContext,
                mRecoverableKeyStoreDb,
                mRecoverySessionStorage,
                Executors.newSingleThreadExecutor());
                Executors.newSingleThreadExecutor(),
                mMockListenersStorage);
    }

    @After
@@ -301,6 +306,16 @@ public class RecoverableKeyStoreManagerTest {
                TEST_USER_ID);
    }

    @Test
    public void setSnapshotCreatedPendingIntent() throws Exception {
        int uid = Binder.getCallingUid();
        PendingIntent intent = PendingIntent.getBroadcast(
                InstrumentationRegistry.getTargetContext(), /*requestCode=*/1,
                new Intent(), /*flags=*/ 0);
        mRecoverableKeyStoreManager.setSnapshotCreatedPendingIntent(intent, /*userId=*/ 0);
        verify(mMockListenersStorage).setSnapshotListener(eq(uid), any(PendingIntent.class));
    }

    private static byte[] randomEncryptedApplicationKey(SecretKey recoveryKey) throws Exception {
        return KeySyncUtils.encryptKeysWithRecoveryKey(recoveryKey, ImmutableMap.of(
                "alias", new SecretKeySpec(randomBytes(32), "AES")