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

Commit 183ae0d1 authored by weichinweng's avatar weichinweng Committed by Weichin Weng
Browse files

NIAP: don't do unit test when the User is not primary.

Since the user can't switch user when NIAP is enabled. On the
premise, we don't need to do keystore unit test if the callingUser
is not primary. Will directly pass it.

Bug: 157685060
Test: atest BluetoothInstrumentationTests
Change-Id: I6cf31b67a7fc01ae3ba8bced6a0bff6349257c9d
parent 1f699e0a
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.bluetooth.btservice.bluetoothkeystore;

import android.os.Binder;
import android.os.Process;
import android.util.Log;

import java.io.IOException;
@@ -142,6 +144,10 @@ public final class BluetoothKeystoreServiceTest {
        mBluetoothKeystoreService = null;
    }

    private boolean isPrimaryUser() {
        return Binder.getCallingUid() == Process.BLUETOOTH_UID;
    }

    private void overwriteConfigFile(List<String> data) {
        try {
            Files.write(Paths.get(CONFIG_FILE_PATH), data);
@@ -210,6 +216,9 @@ public final class BluetoothKeystoreServiceTest {

    @Test
    public void testParserFile() {
        if (!isPrimaryUser()) {
            return;
        }
        // over write config
        overwriteConfigFile(mConfigTestData);
        // load config file.
@@ -221,6 +230,9 @@ public final class BluetoothKeystoreServiceTest {

    @Test
    public void testEncrypt() {
        if (!isPrimaryUser()) {
            return;
        }
        // load config file and put the unencrypted key in to queue.
        testParserFile();
        // Wait for encryption to complete
@@ -232,6 +244,9 @@ public final class BluetoothKeystoreServiceTest {

    @Test
    public void testDecrypt() {
        if (!isPrimaryUser()) {
            return;
        }
        // create an encrypted key list and save it.
        testEncrypt();
        mBluetoothKeystoreService.saveEncryptedKey();
@@ -248,6 +263,9 @@ public final class BluetoothKeystoreServiceTest {

    @Test
    public void testCompareHashFile() {
        if (!isPrimaryUser()) {
            return;
        }
        // save config checksum.
        Assert.assertTrue(setEncryptKeyOrRemoveKey(CONFIG_FILE_PREFIX, CONFIG_FILE_HASH));
        // clean up memory
@@ -260,6 +278,9 @@ public final class BluetoothKeystoreServiceTest {

    @Test
    public void testParserFileAfterDisableNiapMode() {
        if (!isPrimaryUser()) {
            return;
        }
        // preconfiguration.
        // need to creat encrypted file.
        testParserFile();
@@ -289,6 +310,9 @@ public final class BluetoothKeystoreServiceTest {

    @Test
    public void testParserFileAfterDisableNiapModeWhenEnableNiapMode() {
        if (!isPrimaryUser()) {
            return;
        }
        testParserFileAfterDisableNiapMode();
        mBluetoothKeystoreService.cleanupForNiapModeDisable();