Loading android/app/Android.bp +3 −0 Original line number Diff line number Diff line Loading @@ -165,6 +165,9 @@ cc_library_shared { ], min_sdk_version: "Tiramisu", ldflags: ["-Wl,--allow-multiple-definition"], // TODO(b/346919576) Workaround LTO build breakage. lto_O0: true, } cc_library { Loading android/app/jni/com_android_bluetooth_gatt.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -2468,10 +2468,11 @@ static void periodicScanCleanupNative(JNIEnv* env, jobject /* object */) { } static void scanInitializeNative(JNIEnv* env, jobject object) { std::unique_lock<std::shared_mutex> lock(callbacks_mutex); sScanner = bluetooth::shim::get_ble_scanner_instance(); sScanner->RegisterCallbacks(JniScanningCallbacks::GetInstance()); std::unique_lock<std::shared_mutex> lock(callbacks_mutex); if (mScanCallbacksObj != NULL) { log::warn("Cleaning up scan callback object"); env->DeleteGlobalRef(mScanCallbacksObj); Loading android/app/src/com/android/bluetooth/btservice/DataMigration.java +3 −3 Original line number Diff line number Diff line Loading @@ -89,16 +89,16 @@ final class DataMigration { static int run(Context ctx) { if (migrationStatus(ctx) == MIGRATION_STATUS_COMPLETED) { Log.d(TAG, "Legacy migration skiped: already completed"); Log.d(TAG, "Legacy migration skipped: already completed"); return MIGRATION_STATUS_COMPLETED; } if (!isMigrationApkInstalled(ctx)) { Log.d(TAG, "Legacy migration skiped: no migration app installed"); Log.d(TAG, "Legacy migration skipped: no migration app installed"); markMigrationStatus(ctx, MIGRATION_STATUS_MISSING_APK); return MIGRATION_STATUS_MISSING_APK; } if (!incrementeMigrationAttempt(ctx)) { Log.d(TAG, "Legacy migration skiped: still failing after too many attempt"); Log.d(TAG, "Legacy migration skipped: still failing after too many attempt"); markMigrationStatus(ctx, MIGRATION_STATUS_MAX_ATTEMPT); return MIGRATION_STATUS_MAX_ATTEMPT; } Loading android/app/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreService.java +2 −21 Original line number Diff line number Diff line Loading @@ -72,7 +72,6 @@ public class BluetoothKeystoreService { private static final int TRY_MAX = 3; private static final String CONFIG_FILE_PREFIX = "bt_config-origin"; private static final String CONFIG_BACKUP_PREFIX = "bt_config-backup"; private static final String CONFIG_FILE_HASH = "hash"; Loading @@ -80,17 +79,13 @@ public class BluetoothKeystoreService { "/data/misc/bluedroid/bt_config.checksum.encrypted"; private static final String CONFIG_FILE_ENCRYPTION_PATH = "/data/misc/bluedroid/bt_config.conf.encrypted"; private static final String CONFIG_BACKUP_ENCRYPTION_PATH = "/data/misc/bluedroid/bt_config.bak.encrypted"; private static final String CONFIG_FILE_PATH = "/data/misc/bluedroid/bt_config.conf"; private static final String CONFIG_BACKUP_PATH = "/data/misc/bluedroid/bt_config.bak"; private static final int BUFFER_SIZE = 400 * 10; private static final int CONFIG_COMPARE_INIT = 0b00; private static final int CONFIG_FILE_COMPARE_PASS = 0b01; private static final int CONFIG_BACKUP_COMPARE_PASS = 0b10; private int mCompareResult; private final BluetoothKeystoreNativeInterface mBluetoothKeystoreNativeInterface; Loading Loading @@ -225,21 +220,13 @@ public class BluetoothKeystoreService { debugLog("bt_config.conf checksum pass."); mCompareResult = mCompareResult | CONFIG_FILE_COMPARE_PASS; } if (compareFileHash(CONFIG_BACKUP_PATH)) { debugLog("bt_config.bak checksum pass."); mCompareResult = mCompareResult | CONFIG_BACKUP_COMPARE_PASS; } // Step4: choose which encryption file loads. if (doesComparePass(CONFIG_FILE_COMPARE_PASS)) { loadEncryptionFile(CONFIG_FILE_ENCRYPTION_PATH, true); } else if (doesComparePass(CONFIG_BACKUP_COMPARE_PASS)) { Files.deleteIfExists(Paths.get(CONFIG_FILE_ENCRYPTION_PATH)); mNameEncryptKey.remove(CONFIG_FILE_PREFIX); loadEncryptionFile(CONFIG_BACKUP_ENCRYPTION_PATH, true); } else { // if the Common Criteria mode is disable, don't show the log. if (mIsCommonCriteriaMode) { debugLog("Config file conf and bak checksum check fail."); debugLog("Config file conf checksum check fail."); } cleanupAll(); return; Loading Loading @@ -301,8 +288,6 @@ public class BluetoothKeystoreService { } else if (decryptedString.equals(CONFIG_FILE_HASH)) { readHashFile(CONFIG_FILE_PATH, CONFIG_FILE_PREFIX); mPendingEncryptKey.put(CONFIG_FILE_PREFIX); readHashFile(CONFIG_BACKUP_PATH, CONFIG_BACKUP_PREFIX); mPendingEncryptKey.put(CONFIG_BACKUP_PREFIX); saveEncryptedKey(); } return; Loading @@ -328,7 +313,6 @@ public class BluetoothKeystoreService { private void cleanupFile() throws IOException { Files.deleteIfExists(Paths.get(CONFIG_CHECKSUM_ENCRYPTION_PATH)); Files.deleteIfExists(Paths.get(CONFIG_FILE_ENCRYPTION_PATH)); Files.deleteIfExists(Paths.get(CONFIG_BACKUP_ENCRYPTION_PATH)); } /** Clean up memory. */ Loading Loading @@ -381,7 +365,7 @@ public class BluetoothKeystoreService { List<String> configEncryptedLines = new ArrayList<>(); List<String> keyEncryptedLines = new ArrayList<>(); for (String key : mNameEncryptKey.keySet()) { if (key.equals(CONFIG_FILE_PREFIX) || key.equals(CONFIG_BACKUP_PREFIX)) { if (key.equals(CONFIG_FILE_PREFIX)) { configEncryptedLines.add(getEncryptedKeyData(key)); } else { keyEncryptedLines.add(getEncryptedKeyData(key)); Loading @@ -395,7 +379,6 @@ public class BluetoothKeystoreService { } if (!keyEncryptedLines.isEmpty()) { Files.write(Paths.get(CONFIG_FILE_ENCRYPTION_PATH), keyEncryptedLines); Files.write(Paths.get(CONFIG_BACKUP_ENCRYPTION_PATH), keyEncryptedLines); } } catch (IOException e) { throw new RuntimeException("write encryption file fail"); Loading Loading @@ -441,8 +424,6 @@ public class BluetoothKeystoreService { String prefixString = null; if (CONFIG_FILE_PATH.equals(hashFilePathString)) { prefixString = CONFIG_FILE_PREFIX; } else if (CONFIG_BACKUP_PATH.equals(hashFilePathString)) { prefixString = CONFIG_BACKUP_PREFIX; } if (prefixString == null) { errorLog("compareFileHash: Unexpected hash file path: " + hashFilePathString); Loading android/app/tests/unit/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreServiceTest.java +0 −5 Original line number Diff line number Diff line Loading @@ -52,13 +52,10 @@ public final class BluetoothKeystoreServiceTest { // Please also check bt_stack string configuration if you want to change the content. private static final String CONFIG_FILE_PREFIX = "bt_config-origin"; private static final String CONFIG_BACKUP_PREFIX = "bt_config-backup"; private static final String CONFIG_FILE_HASH = "hash"; private static final String CONFIG_FILE_PATH = "/data/misc/bluedroid/bt_config.conf"; private static final String CONFIG_FILE_ENCRYPTION_PATH = "/data/misc/bluedroid/bt_config.conf.encrypted"; private static final String CONFIG_BACKUP_ENCRYPTION_PATH = "/data/misc/bluedroid/bt_config.bak.encrypted"; private static final String CONFIG_CHECKSUM_ENCRYPTION_PATH = "/data/misc/bluedroid/bt_config.checksum.encrypted"; Loading Loading @@ -271,11 +268,9 @@ public final class BluetoothKeystoreServiceTest { // check encryption file clean up. Assert.assertFalse(Files.exists(Paths.get(CONFIG_CHECKSUM_ENCRYPTION_PATH))); Assert.assertFalse(Files.exists(Paths.get(CONFIG_FILE_ENCRYPTION_PATH))); Assert.assertFalse(Files.exists(Paths.get(CONFIG_BACKUP_ENCRYPTION_PATH))); // remove hash data avoid interfering result. mBluetoothKeystoreService.getNameDecryptKey().remove(CONFIG_FILE_PREFIX); mBluetoothKeystoreService.getNameDecryptKey().remove(CONFIG_BACKUP_PREFIX); Assert.assertTrue( doCompareMap(mNameDecryptKeyResult, mBluetoothKeystoreService.getNameDecryptKey())); Loading Loading
android/app/Android.bp +3 −0 Original line number Diff line number Diff line Loading @@ -165,6 +165,9 @@ cc_library_shared { ], min_sdk_version: "Tiramisu", ldflags: ["-Wl,--allow-multiple-definition"], // TODO(b/346919576) Workaround LTO build breakage. lto_O0: true, } cc_library { Loading
android/app/jni/com_android_bluetooth_gatt.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -2468,10 +2468,11 @@ static void periodicScanCleanupNative(JNIEnv* env, jobject /* object */) { } static void scanInitializeNative(JNIEnv* env, jobject object) { std::unique_lock<std::shared_mutex> lock(callbacks_mutex); sScanner = bluetooth::shim::get_ble_scanner_instance(); sScanner->RegisterCallbacks(JniScanningCallbacks::GetInstance()); std::unique_lock<std::shared_mutex> lock(callbacks_mutex); if (mScanCallbacksObj != NULL) { log::warn("Cleaning up scan callback object"); env->DeleteGlobalRef(mScanCallbacksObj); Loading
android/app/src/com/android/bluetooth/btservice/DataMigration.java +3 −3 Original line number Diff line number Diff line Loading @@ -89,16 +89,16 @@ final class DataMigration { static int run(Context ctx) { if (migrationStatus(ctx) == MIGRATION_STATUS_COMPLETED) { Log.d(TAG, "Legacy migration skiped: already completed"); Log.d(TAG, "Legacy migration skipped: already completed"); return MIGRATION_STATUS_COMPLETED; } if (!isMigrationApkInstalled(ctx)) { Log.d(TAG, "Legacy migration skiped: no migration app installed"); Log.d(TAG, "Legacy migration skipped: no migration app installed"); markMigrationStatus(ctx, MIGRATION_STATUS_MISSING_APK); return MIGRATION_STATUS_MISSING_APK; } if (!incrementeMigrationAttempt(ctx)) { Log.d(TAG, "Legacy migration skiped: still failing after too many attempt"); Log.d(TAG, "Legacy migration skipped: still failing after too many attempt"); markMigrationStatus(ctx, MIGRATION_STATUS_MAX_ATTEMPT); return MIGRATION_STATUS_MAX_ATTEMPT; } Loading
android/app/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreService.java +2 −21 Original line number Diff line number Diff line Loading @@ -72,7 +72,6 @@ public class BluetoothKeystoreService { private static final int TRY_MAX = 3; private static final String CONFIG_FILE_PREFIX = "bt_config-origin"; private static final String CONFIG_BACKUP_PREFIX = "bt_config-backup"; private static final String CONFIG_FILE_HASH = "hash"; Loading @@ -80,17 +79,13 @@ public class BluetoothKeystoreService { "/data/misc/bluedroid/bt_config.checksum.encrypted"; private static final String CONFIG_FILE_ENCRYPTION_PATH = "/data/misc/bluedroid/bt_config.conf.encrypted"; private static final String CONFIG_BACKUP_ENCRYPTION_PATH = "/data/misc/bluedroid/bt_config.bak.encrypted"; private static final String CONFIG_FILE_PATH = "/data/misc/bluedroid/bt_config.conf"; private static final String CONFIG_BACKUP_PATH = "/data/misc/bluedroid/bt_config.bak"; private static final int BUFFER_SIZE = 400 * 10; private static final int CONFIG_COMPARE_INIT = 0b00; private static final int CONFIG_FILE_COMPARE_PASS = 0b01; private static final int CONFIG_BACKUP_COMPARE_PASS = 0b10; private int mCompareResult; private final BluetoothKeystoreNativeInterface mBluetoothKeystoreNativeInterface; Loading Loading @@ -225,21 +220,13 @@ public class BluetoothKeystoreService { debugLog("bt_config.conf checksum pass."); mCompareResult = mCompareResult | CONFIG_FILE_COMPARE_PASS; } if (compareFileHash(CONFIG_BACKUP_PATH)) { debugLog("bt_config.bak checksum pass."); mCompareResult = mCompareResult | CONFIG_BACKUP_COMPARE_PASS; } // Step4: choose which encryption file loads. if (doesComparePass(CONFIG_FILE_COMPARE_PASS)) { loadEncryptionFile(CONFIG_FILE_ENCRYPTION_PATH, true); } else if (doesComparePass(CONFIG_BACKUP_COMPARE_PASS)) { Files.deleteIfExists(Paths.get(CONFIG_FILE_ENCRYPTION_PATH)); mNameEncryptKey.remove(CONFIG_FILE_PREFIX); loadEncryptionFile(CONFIG_BACKUP_ENCRYPTION_PATH, true); } else { // if the Common Criteria mode is disable, don't show the log. if (mIsCommonCriteriaMode) { debugLog("Config file conf and bak checksum check fail."); debugLog("Config file conf checksum check fail."); } cleanupAll(); return; Loading Loading @@ -301,8 +288,6 @@ public class BluetoothKeystoreService { } else if (decryptedString.equals(CONFIG_FILE_HASH)) { readHashFile(CONFIG_FILE_PATH, CONFIG_FILE_PREFIX); mPendingEncryptKey.put(CONFIG_FILE_PREFIX); readHashFile(CONFIG_BACKUP_PATH, CONFIG_BACKUP_PREFIX); mPendingEncryptKey.put(CONFIG_BACKUP_PREFIX); saveEncryptedKey(); } return; Loading @@ -328,7 +313,6 @@ public class BluetoothKeystoreService { private void cleanupFile() throws IOException { Files.deleteIfExists(Paths.get(CONFIG_CHECKSUM_ENCRYPTION_PATH)); Files.deleteIfExists(Paths.get(CONFIG_FILE_ENCRYPTION_PATH)); Files.deleteIfExists(Paths.get(CONFIG_BACKUP_ENCRYPTION_PATH)); } /** Clean up memory. */ Loading Loading @@ -381,7 +365,7 @@ public class BluetoothKeystoreService { List<String> configEncryptedLines = new ArrayList<>(); List<String> keyEncryptedLines = new ArrayList<>(); for (String key : mNameEncryptKey.keySet()) { if (key.equals(CONFIG_FILE_PREFIX) || key.equals(CONFIG_BACKUP_PREFIX)) { if (key.equals(CONFIG_FILE_PREFIX)) { configEncryptedLines.add(getEncryptedKeyData(key)); } else { keyEncryptedLines.add(getEncryptedKeyData(key)); Loading @@ -395,7 +379,6 @@ public class BluetoothKeystoreService { } if (!keyEncryptedLines.isEmpty()) { Files.write(Paths.get(CONFIG_FILE_ENCRYPTION_PATH), keyEncryptedLines); Files.write(Paths.get(CONFIG_BACKUP_ENCRYPTION_PATH), keyEncryptedLines); } } catch (IOException e) { throw new RuntimeException("write encryption file fail"); Loading Loading @@ -441,8 +424,6 @@ public class BluetoothKeystoreService { String prefixString = null; if (CONFIG_FILE_PATH.equals(hashFilePathString)) { prefixString = CONFIG_FILE_PREFIX; } else if (CONFIG_BACKUP_PATH.equals(hashFilePathString)) { prefixString = CONFIG_BACKUP_PREFIX; } if (prefixString == null) { errorLog("compareFileHash: Unexpected hash file path: " + hashFilePathString); Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreServiceTest.java +0 −5 Original line number Diff line number Diff line Loading @@ -52,13 +52,10 @@ public final class BluetoothKeystoreServiceTest { // Please also check bt_stack string configuration if you want to change the content. private static final String CONFIG_FILE_PREFIX = "bt_config-origin"; private static final String CONFIG_BACKUP_PREFIX = "bt_config-backup"; private static final String CONFIG_FILE_HASH = "hash"; private static final String CONFIG_FILE_PATH = "/data/misc/bluedroid/bt_config.conf"; private static final String CONFIG_FILE_ENCRYPTION_PATH = "/data/misc/bluedroid/bt_config.conf.encrypted"; private static final String CONFIG_BACKUP_ENCRYPTION_PATH = "/data/misc/bluedroid/bt_config.bak.encrypted"; private static final String CONFIG_CHECKSUM_ENCRYPTION_PATH = "/data/misc/bluedroid/bt_config.checksum.encrypted"; Loading Loading @@ -271,11 +268,9 @@ public final class BluetoothKeystoreServiceTest { // check encryption file clean up. Assert.assertFalse(Files.exists(Paths.get(CONFIG_CHECKSUM_ENCRYPTION_PATH))); Assert.assertFalse(Files.exists(Paths.get(CONFIG_FILE_ENCRYPTION_PATH))); Assert.assertFalse(Files.exists(Paths.get(CONFIG_BACKUP_ENCRYPTION_PATH))); // remove hash data avoid interfering result. mBluetoothKeystoreService.getNameDecryptKey().remove(CONFIG_FILE_PREFIX); mBluetoothKeystoreService.getNameDecryptKey().remove(CONFIG_BACKUP_PREFIX); Assert.assertTrue( doCompareMap(mNameDecryptKeyResult, mBluetoothKeystoreService.getNameDecryptKey())); Loading