Loading android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -704,7 +704,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) { } static bool initNative(JNIEnv* env, jobject obj, jboolean isGuest, jboolean isNiapMode, int configCompareResult, jboolean isCommonCriteriaMode, int configCompareResult, jobjectArray initFlags, jboolean isAtvDevice) { ALOGV("%s", __func__); Loading Loading @@ -734,7 +734,7 @@ static bool initNative(JNIEnv* env, jobject obj, jboolean isGuest, int ret = sBluetoothInterface->init( &sBluetoothCallbacks, isGuest == JNI_TRUE ? 1 : 0, isNiapMode == JNI_TRUE ? 1 : 0, configCompareResult, flags, isCommonCriteriaMode == JNI_TRUE ? 1 : 0, configCompareResult, flags, isAtvDevice == JNI_TRUE ? 1 : 0); for (int i = 0; i < flagCount; i++) { Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +6 −5 Original line number Diff line number Diff line Loading @@ -468,7 +468,7 @@ public class AdapterService extends Service { mAdapterProperties = new AdapterProperties(this); mAdapterStateMachine = AdapterState.make(this); mJniCallbacks = new JniCallbacks(this, mAdapterProperties); mBluetoothKeystoreService = new BluetoothKeystoreService(isNiapMode()); mBluetoothKeystoreService = new BluetoothKeystoreService(isCommonCriteriaMode()); mBluetoothKeystoreService.start(); mActivityAttributionService = new ActivityAttributionService(); mActivityAttributionService.start(); Loading @@ -477,7 +477,8 @@ public class AdapterService extends Service { // Android TV doesn't show consent dialogs for just works and encryption only le pairing boolean isAtvDevice = getApplicationContext().getPackageManager().hasSystemFeature( PackageManager.FEATURE_LEANBACK_ONLY); initNative(isGuest(), isNiapMode(), configCompareResult, getInitFlags(), isAtvDevice); initNative(isGuest(), isCommonCriteriaMode(), configCompareResult, getInitFlags(), isAtvDevice); mNativeAvailable = true; mCallbacks = new RemoteCallbackList<IBluetoothCallback>(); mAppOps = getSystemService(AppOpsManager.class); Loading Loading @@ -3238,7 +3239,7 @@ public class AdapterService extends Service { return UserManager.get(this).isGuestUser(); } private boolean isNiapMode() { private boolean isCommonCriteriaMode() { return ((DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE)) .isCommonCriteriaModeEnabled(null); } Loading Loading @@ -3387,8 +3388,8 @@ public class AdapterService extends Service { static native void classInitNative(); native boolean initNative(boolean startRestricted, boolean isNiapMode, int configCompareResult, String[] initFlags, boolean isAtvDevice); native boolean initNative(boolean startRestricted, boolean isCommonCriteriaMode, int configCompareResult, String[] initFlags, boolean isAtvDevice); native void cleanupNative(); Loading android/app/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreService.java +18 −18 Original line number Diff line number Diff line Loading @@ -69,7 +69,7 @@ public class BluetoothKeystoreService { private static BluetoothKeystoreService sBluetoothKeystoreService; private boolean mCleaningUp; private boolean mIsNiapMode; private boolean mIsCommonCriteriaMode; private static final String CIPHER_ALGORITHM = "AES/GCM/NoPadding"; private static final int GCM_TAG_LENGTH = 128; Loading Loading @@ -118,9 +118,9 @@ public class BluetoothKeystoreService { private Base64.Decoder mDecoder = Base64.getDecoder(); private Base64.Encoder mEncoder = Base64.getEncoder(); public BluetoothKeystoreService(boolean isNiapMode) { debugLog("new BluetoothKeystoreService isNiapMode: " + isNiapMode); mIsNiapMode = isNiapMode; public BluetoothKeystoreService(boolean isCommonCriteriaMode) { debugLog("new BluetoothKeystoreService isCommonCriteriaMode: " + isCommonCriteriaMode); mIsCommonCriteriaMode = isCommonCriteriaMode; mCompareResult = CONFIG_COMPARE_INIT; startThread(); } Loading @@ -139,7 +139,7 @@ public class BluetoothKeystoreService { keyStore = getKeyStore(); // Confirm whether to enable NIAP for the first time. // Confirm whether to enable Common Criteria mode for the first time. if (keyStore == null) { debugLog("cannot find the keystore."); return; Loading @@ -153,8 +153,8 @@ public class BluetoothKeystoreService { setBluetoothKeystoreService(this); try { if (!keyStore.containsAlias(KEYALIAS) && mIsNiapMode) { infoLog("Enable NIAP mode for the first time, pass hash check."); if (!keyStore.containsAlias(KEYALIAS) && mIsCommonCriteriaMode) { infoLog("Enable Common Criteria mode for the first time, pass hash check."); mCompareResult = 0b11; return; } Loading Loading @@ -200,18 +200,18 @@ public class BluetoothKeystoreService { mBluetoothKeystoreNativeInterface.cleanup(); mBluetoothKeystoreNativeInterface = null; if (mIsNiapMode) { cleanupForNiapModeEnable(); if (mIsCommonCriteriaMode) { cleanupForCommonCriteriaModeEnable(); } else { cleanupForNiapModeDisable(); cleanupForCommonCriteriaModeDisable(); } } /** * Clean up if NIAP mode is enabled. * Clean up if Common Criteria mode is enabled. */ @VisibleForTesting public void cleanupForNiapModeEnable() { public void cleanupForCommonCriteriaModeEnable() { try { setEncryptKeyOrRemoveKey(CONFIG_FILE_PREFIX, CONFIG_FILE_HASH); } catch (InterruptedException e) { Loading @@ -226,10 +226,10 @@ public class BluetoothKeystoreService { } /** * Clean up if NIAP mode is disabled. * Clean up if Common Criteria mode is disabled. */ @VisibleForTesting public void cleanupForNiapModeDisable() { public void cleanupForCommonCriteriaModeDisable() { mNameDecryptKey.clear(); mNameEncryptKey.clear(); } Loading Loading @@ -267,16 +267,16 @@ public class BluetoothKeystoreService { mNameEncryptKey.remove(CONFIG_FILE_PREFIX); loadEncryptionFile(CONFIG_BACKUP_ENCRYPTION_PATH, true); } else { // if the NIAP mode is disable, don't show the log. if (mIsNiapMode) { // if the Common Criteria mode is disable, don't show the log. if (mIsCommonCriteriaMode) { debugLog("Config file conf and bak checksum check fail."); } cleanupAll(); return; } } // keep memory data for get decrypted key if NIAP mode disable. if (!mIsNiapMode) { // keep memory data for get decrypted key if Common Criteria mode disable. if (!mIsCommonCriteriaMode) { stopThread(); cleanupFile(); } Loading android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ public class AdapterServiceTest { } Assert.assertNotNull(Looper.myLooper()); AdapterService adapterService = new AdapterService(); adapterService.initNative(false /* is_restricted */, false /* is_niap_mode */, adapterService.initNative(false /* is_restricted */, false /* is_common_criteria_mode */, 0 /* config_compare_result */, new String[0], false); adapterService.cleanupNative(); HashMap<String, HashMap<String, String>> adapterConfig = TestUtils.readAdapterConfig(); Loading android/app/tests/unit/src/com/android/bluetooth/btservice/ProfileServiceTest.java +3 −2 Original line number Diff line number Diff line Loading @@ -98,8 +98,9 @@ public class ProfileServiceTest { mProfiles = Config.getSupportedProfiles(); mMockAdapterService.initNative(false /* is_restricted */, false /* is_niap_mode */, 0 /* config_compare_result */, new String[0], false); mMockAdapterService.initNative(false /* is_restricted */, false /* is_common_criteria_mode */, 0 /* config_compare_result */, new String[0], false); TestUtils.setAdapterService(mMockAdapterService); doReturn(mDatabaseManager).when(mMockAdapterService).getDatabase(); Loading Loading
android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -704,7 +704,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) { } static bool initNative(JNIEnv* env, jobject obj, jboolean isGuest, jboolean isNiapMode, int configCompareResult, jboolean isCommonCriteriaMode, int configCompareResult, jobjectArray initFlags, jboolean isAtvDevice) { ALOGV("%s", __func__); Loading Loading @@ -734,7 +734,7 @@ static bool initNative(JNIEnv* env, jobject obj, jboolean isGuest, int ret = sBluetoothInterface->init( &sBluetoothCallbacks, isGuest == JNI_TRUE ? 1 : 0, isNiapMode == JNI_TRUE ? 1 : 0, configCompareResult, flags, isCommonCriteriaMode == JNI_TRUE ? 1 : 0, configCompareResult, flags, isAtvDevice == JNI_TRUE ? 1 : 0); for (int i = 0; i < flagCount; i++) { Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +6 −5 Original line number Diff line number Diff line Loading @@ -468,7 +468,7 @@ public class AdapterService extends Service { mAdapterProperties = new AdapterProperties(this); mAdapterStateMachine = AdapterState.make(this); mJniCallbacks = new JniCallbacks(this, mAdapterProperties); mBluetoothKeystoreService = new BluetoothKeystoreService(isNiapMode()); mBluetoothKeystoreService = new BluetoothKeystoreService(isCommonCriteriaMode()); mBluetoothKeystoreService.start(); mActivityAttributionService = new ActivityAttributionService(); mActivityAttributionService.start(); Loading @@ -477,7 +477,8 @@ public class AdapterService extends Service { // Android TV doesn't show consent dialogs for just works and encryption only le pairing boolean isAtvDevice = getApplicationContext().getPackageManager().hasSystemFeature( PackageManager.FEATURE_LEANBACK_ONLY); initNative(isGuest(), isNiapMode(), configCompareResult, getInitFlags(), isAtvDevice); initNative(isGuest(), isCommonCriteriaMode(), configCompareResult, getInitFlags(), isAtvDevice); mNativeAvailable = true; mCallbacks = new RemoteCallbackList<IBluetoothCallback>(); mAppOps = getSystemService(AppOpsManager.class); Loading Loading @@ -3238,7 +3239,7 @@ public class AdapterService extends Service { return UserManager.get(this).isGuestUser(); } private boolean isNiapMode() { private boolean isCommonCriteriaMode() { return ((DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE)) .isCommonCriteriaModeEnabled(null); } Loading Loading @@ -3387,8 +3388,8 @@ public class AdapterService extends Service { static native void classInitNative(); native boolean initNative(boolean startRestricted, boolean isNiapMode, int configCompareResult, String[] initFlags, boolean isAtvDevice); native boolean initNative(boolean startRestricted, boolean isCommonCriteriaMode, int configCompareResult, String[] initFlags, boolean isAtvDevice); native void cleanupNative(); Loading
android/app/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreService.java +18 −18 Original line number Diff line number Diff line Loading @@ -69,7 +69,7 @@ public class BluetoothKeystoreService { private static BluetoothKeystoreService sBluetoothKeystoreService; private boolean mCleaningUp; private boolean mIsNiapMode; private boolean mIsCommonCriteriaMode; private static final String CIPHER_ALGORITHM = "AES/GCM/NoPadding"; private static final int GCM_TAG_LENGTH = 128; Loading Loading @@ -118,9 +118,9 @@ public class BluetoothKeystoreService { private Base64.Decoder mDecoder = Base64.getDecoder(); private Base64.Encoder mEncoder = Base64.getEncoder(); public BluetoothKeystoreService(boolean isNiapMode) { debugLog("new BluetoothKeystoreService isNiapMode: " + isNiapMode); mIsNiapMode = isNiapMode; public BluetoothKeystoreService(boolean isCommonCriteriaMode) { debugLog("new BluetoothKeystoreService isCommonCriteriaMode: " + isCommonCriteriaMode); mIsCommonCriteriaMode = isCommonCriteriaMode; mCompareResult = CONFIG_COMPARE_INIT; startThread(); } Loading @@ -139,7 +139,7 @@ public class BluetoothKeystoreService { keyStore = getKeyStore(); // Confirm whether to enable NIAP for the first time. // Confirm whether to enable Common Criteria mode for the first time. if (keyStore == null) { debugLog("cannot find the keystore."); return; Loading @@ -153,8 +153,8 @@ public class BluetoothKeystoreService { setBluetoothKeystoreService(this); try { if (!keyStore.containsAlias(KEYALIAS) && mIsNiapMode) { infoLog("Enable NIAP mode for the first time, pass hash check."); if (!keyStore.containsAlias(KEYALIAS) && mIsCommonCriteriaMode) { infoLog("Enable Common Criteria mode for the first time, pass hash check."); mCompareResult = 0b11; return; } Loading Loading @@ -200,18 +200,18 @@ public class BluetoothKeystoreService { mBluetoothKeystoreNativeInterface.cleanup(); mBluetoothKeystoreNativeInterface = null; if (mIsNiapMode) { cleanupForNiapModeEnable(); if (mIsCommonCriteriaMode) { cleanupForCommonCriteriaModeEnable(); } else { cleanupForNiapModeDisable(); cleanupForCommonCriteriaModeDisable(); } } /** * Clean up if NIAP mode is enabled. * Clean up if Common Criteria mode is enabled. */ @VisibleForTesting public void cleanupForNiapModeEnable() { public void cleanupForCommonCriteriaModeEnable() { try { setEncryptKeyOrRemoveKey(CONFIG_FILE_PREFIX, CONFIG_FILE_HASH); } catch (InterruptedException e) { Loading @@ -226,10 +226,10 @@ public class BluetoothKeystoreService { } /** * Clean up if NIAP mode is disabled. * Clean up if Common Criteria mode is disabled. */ @VisibleForTesting public void cleanupForNiapModeDisable() { public void cleanupForCommonCriteriaModeDisable() { mNameDecryptKey.clear(); mNameEncryptKey.clear(); } Loading Loading @@ -267,16 +267,16 @@ public class BluetoothKeystoreService { mNameEncryptKey.remove(CONFIG_FILE_PREFIX); loadEncryptionFile(CONFIG_BACKUP_ENCRYPTION_PATH, true); } else { // if the NIAP mode is disable, don't show the log. if (mIsNiapMode) { // if the Common Criteria mode is disable, don't show the log. if (mIsCommonCriteriaMode) { debugLog("Config file conf and bak checksum check fail."); } cleanupAll(); return; } } // keep memory data for get decrypted key if NIAP mode disable. if (!mIsNiapMode) { // keep memory data for get decrypted key if Common Criteria mode disable. if (!mIsCommonCriteriaMode) { stopThread(); cleanupFile(); } Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ public class AdapterServiceTest { } Assert.assertNotNull(Looper.myLooper()); AdapterService adapterService = new AdapterService(); adapterService.initNative(false /* is_restricted */, false /* is_niap_mode */, adapterService.initNative(false /* is_restricted */, false /* is_common_criteria_mode */, 0 /* config_compare_result */, new String[0], false); adapterService.cleanupNative(); HashMap<String, HashMap<String, String>> adapterConfig = TestUtils.readAdapterConfig(); Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/ProfileServiceTest.java +3 −2 Original line number Diff line number Diff line Loading @@ -98,8 +98,9 @@ public class ProfileServiceTest { mProfiles = Config.getSupportedProfiles(); mMockAdapterService.initNative(false /* is_restricted */, false /* is_niap_mode */, 0 /* config_compare_result */, new String[0], false); mMockAdapterService.initNative(false /* is_restricted */, false /* is_common_criteria_mode */, 0 /* config_compare_result */, new String[0], false); TestUtils.setAdapterService(mMockAdapterService); doReturn(mDatabaseManager).when(mMockAdapterService).getDatabase(); Loading