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 system/blueberry/tests/gd/cert/gd_device.py +75 −98 Original line number Diff line number Diff line Loading @@ -194,29 +194,25 @@ class GdDeviceBase(ABC): """ # Start backing process logging.debug("[%s] Running %s %s" % (self.type_identifier, self.label, " ".join(self.cmd))) self.backing_process = subprocess.Popen( self.cmd, self.backing_process = subprocess.Popen(self.cmd, cwd=get_gd_root(), env=self.environment, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) self.backing_process_logger = AsyncSubprocessLogger( self.backing_process, [self.backing_process_log_path], self.backing_process_logger = AsyncSubprocessLogger(self.backing_process, [self.backing_process_log_path], log_to_stdout=self.verbose_mode, tag=self.label, color=self.terminal_color) asserts.assert_true( self.backing_process, msg="[%s] failed to open backing process for %s" % (self.type_identifier, self.label)) asserts.assert_true(self.backing_process, msg="[%s] failed to open backing process for %s" % (self.type_identifier, self.label)) self.is_backing_process_alive = is_subprocess_alive(self.backing_process) asserts.assert_true( self.is_backing_process_alive, asserts.assert_true(self.is_backing_process_alive, msg="[%s] backing process for %s died after starting" % (self.type_identifier, self.label)) # If gRPC root server port is not specified, we can skip settings up the root server if self.grpc_root_server_port != -1: # Setup gRPC management channels Loading @@ -228,14 +224,14 @@ class GdDeviceBase(ABC): logging.info("[%s] Waiting to connect to gRPC root server for %s, timeout is %d seconds" % (self.type_identifier, self.label, GRPC_START_TIMEOUT_SEC)) grpc.channel_ready_future(self.grpc_root_server_channel).result(timeout=GRPC_START_TIMEOUT_SEC) logging.info( "[%s] Successfully connected to gRPC root server for %s" % (self.type_identifier, self.label)) logging.info("[%s] Successfully connected to gRPC root server for %s" % (self.type_identifier, self.label)) self.grpc_root_server_ready = True except grpc.FutureTimeoutError: logging.error("[%s] Failed to connect to gRPC root server for %s" % (self.type_identifier, self.label)) asserts.assert_true( self.grpc_root_server_ready, msg="gRPC root server did not start after running " + " ".join(self.cmd)) asserts.assert_true(self.grpc_root_server_ready, msg="gRPC root server did not start after running " + " ".join(self.cmd)) self.grpc_channel = grpc.insecure_channel("localhost:%d" % self.grpc_port) Loading Loading @@ -338,10 +334,10 @@ class GdHostOnlyDevice(GdDeviceBase): # Only check on host only test, for Android devices, these ports will # be opened on Android device and host machine ports will be occupied # by sshd or adb forwarding ports_needed = [self.grpc_port, self.grpc_root_server_port] if self.grpc_root_server_port != -1 else [self.grpc_port] asserts.assert_true( make_ports_available(ports_needed), "[%s] Failed to make backing process ports available" % self.label) ports_needed = [self.grpc_port, self.grpc_root_server_port ] if self.grpc_root_server_port != -1 else [self.grpc_port] asserts.assert_true(make_ports_available(ports_needed), "[%s] Failed to make backing process ports available" % self.label) super().setup() def teardown(self): Loading @@ -362,8 +358,8 @@ class GdHostOnlyDevice(GdDeviceBase): } def get_coverage_profdata_path_for_host(self, test_runner_base_path, type_identifier, label) -> pathlib.Path: return pathlib.Path(test_runner_base_path).parent.parent.joinpath( "%s_%s_backing_process_coverage.profdata" % (type_identifier, label)) return pathlib.Path(test_runner_base_path).parent.parent.joinpath("%s_%s_backing_process_coverage.profdata" % (type_identifier, label)) def merge_coverage_profdata_for_host(self, backing_process_profraw_path, profdata_path: pathlib.Path, label): if not backing_process_profraw_path.is_file(): Loading Loading @@ -421,8 +417,7 @@ class GdHostOnlyDevice(GdDeviceBase): str(stack_bin) ] logging.debug("Running llvm_cov export: %s" % " ".join(llvm_cov_export_cmd)) result = subprocess.run( llvm_cov_export_cmd, result = subprocess.run(llvm_cov_export_cmd, stderr=subprocess.PIPE, stdout=coverage_result_file, cwd=os.path.join(get_gd_root())) Loading @@ -440,8 +435,7 @@ class GdHostOnlyDevice(GdDeviceBase): str(stack_bin) ] logging.debug("Running llvm_cov report: %s" % " ".join(llvm_cov_report_cmd)) result = subprocess.run( llvm_cov_report_cmd, result = subprocess.run(llvm_cov_report_cmd, stderr=subprocess.PIPE, stdout=coverage_summary_file, cwd=os.path.join(get_gd_root())) Loading Loading @@ -479,8 +473,7 @@ class GdAndroidDevice(GdDeviceBase): logging.info("Confirmed that verity is disabled on device %s %s" % (self.label, self.serial_number)) # Try freeing ports and ignore results asserts.assert_true( make_ports_available((self.grpc_port, self.grpc_root_server_port, self.signal_port)), asserts.assert_true(make_ports_available((self.grpc_port, self.grpc_root_server_port, self.signal_port)), "[%s] Failed to make backing process ports available" % self.label) self.cleanup_port_forwarding() self.sync_device_time() Loading @@ -501,17 +494,15 @@ class GdAndroidDevice(GdDeviceBase): # Do not override exist libraries shared by other binaries on the Android device to avoid corrupting the Android device self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_BIN_DIR, "bluetooth_stack_with_facade")) self.push_or_die( *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "android.hardware.bluetooth@1.0.so"), self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "android.hardware.bluetooth@1.0.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "android.hardware.bluetooth@1.1.so"), overwrite_existing=False) self.push_or_die( *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "android.hardware.bluetooth@1.1.so"), self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libandroid_runtime_lazy.so"), overwrite_existing=False) self.push_or_die( *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libandroid_runtime_lazy.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libbase.so"), overwrite_existing=False) self.push_or_die( *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libbinder_ndk.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libbinder_ndk.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libbinder.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libc++.so"), overwrite_existing=False) # libclang_rt.asan-aarch64-android.so is only needed for ASAN build and is automatically included on device Loading @@ -520,8 +511,8 @@ class GdAndroidDevice(GdDeviceBase): # overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libcrypto.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libcutils.so"), overwrite_existing=False) self.push_or_die( *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libgrpc_wrap.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libgrpc_wrap.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libgrpc++.so")) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libhidlbase.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "liblog.so"), overwrite_existing=False) Loading @@ -529,8 +520,8 @@ class GdAndroidDevice(GdDeviceBase): self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libprotobuf-cpp-full.so")) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libssl.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libgrpc++.so")) self.push_or_die( *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libunwindstack.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libunwindstack.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libutils.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libgrpc++.so")) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libz.so"), overwrite_existing=False) Loading @@ -555,11 +546,6 @@ class GdAndroidDevice(GdDeviceBase): if ADB_FILE_NOT_EXIST_ERROR not in str(error): logging.error("Error during setup: " + str(error)) try: self.adb.shell("rm /data/misc/bluedroid/bt_config.bak") except AdbError as error: if ADB_FILE_NOT_EXIST_ERROR not in str(error): logging.error("Error during setup: " + str(error)) logging.info("Old logs removed from device %s %s" % (self.label, self.serial_number)) # Ensure Bluetooth is disabled Loading @@ -575,14 +561,14 @@ class GdAndroidDevice(GdDeviceBase): self.log_path_base, '%s_%s_%s_logcat_logs.txt' % (self.type_identifier, self.label, self.serial_number)) self.logcat_cmd = ["adb", "-s", self.serial_number, "logcat", "-T", "1", "-v", "year", "-v", "uid"] logging.debug("Running %s", " ".join(self.logcat_cmd)) self.logcat_process = subprocess.Popen( self.logcat_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) self.logcat_process = subprocess.Popen(self.logcat_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) asserts.assert_true(self.logcat_process, msg="Cannot start logcat_process at " + " ".join(self.logcat_cmd)) asserts.assert_true( is_subprocess_alive(self.logcat_process), asserts.assert_true(is_subprocess_alive(self.logcat_process), msg="logcat_process stopped immediately after running " + " ".join(self.logcat_cmd)) self.logcat_logger = AsyncSubprocessLogger( self.logcat_process, [self.logcat_output_path], self.logcat_logger = AsyncSubprocessLogger(self.logcat_process, [self.logcat_output_path], log_to_stdout=self.verbose_mode, tag="%s_%s" % (self.label, self.serial_number), color=self.terminal_color) Loading Loading @@ -631,14 +617,6 @@ class GdAndroidDevice(GdDeviceBase): # Some tests have no config file, and that's OK if ADB_FILE_NOT_EXIST_ERROR not in str(error): logging.error(PULL_LOG_FILE_ERROR_MSG_PREFIX + str(error)) try: self.adb.pull( ["/data/misc/bluedroid/bt_config.bak", str(os.path.join(base_dir, "%s_bt_config.bak" % self.label))]) except AdbError as error: # Some tests have no config.bak file, and that's OK if ADB_FILE_NOT_EXIST_ERROR not in str(error): logging.error(PULL_LOG_FILE_ERROR_MSG_PREFIX + str(error)) def cleanup_port_forwarding(self): try: Loading Loading @@ -674,8 +652,8 @@ class GdAndroidDevice(GdDeviceBase): """ Ensure a command has not output """ asserts.assert_true( result is None or len(result) == 0, msg="command returned something when it shouldn't: %s" % result) asserts.assert_true(result is None or len(result) == 0, msg="command returned something when it shouldn't: %s" % result) def sync_device_time(self): self.adb.shell("settings put global auto_time 0") Loading Loading @@ -706,8 +684,7 @@ class GdAndroidDevice(GdDeviceBase): # Include ADB delay that might be longer in SSH environment max_delta_seconds = 3 host_time = datetime.now(tz=device_time.tzinfo) asserts.assert_almost_equal( (device_time - host_time).total_seconds(), asserts.assert_almost_equal((device_time - host_time).total_seconds(), 0, msg="Device time %s and host time %s off by >%dms after sync" % (device_time.isoformat(), host_time.isoformat(), int(max_delta_seconds * 1000)), Loading Loading @@ -744,14 +721,14 @@ class GdAndroidDevice(GdDeviceBase): if num_retry > 0: # If requested, reboot an retry num_retry -= 1 logging.warning( "[%s] Failed to TCP forward host port %d to " "device port %d, num_retries left is %d" % (self.label, host_port, device_port, num_retry)) logging.warning("[%s] Failed to TCP forward host port %d to " "device port %d, num_retries left is %d" % (self.label, host_port, device_port, num_retry)) self.reboot() self.adb.remount() return self.tcp_forward_or_die(host_port, device_port, num_retry=num_retry) asserts.fail( 'Unable to forward host port %d to device port %d, error %s' % (host_port, device_port, error_or_port)) asserts.fail('Unable to forward host port %d to device port %d, error %s' % (host_port, device_port, error_or_port)) return error_or_port def tcp_reverse_or_die(self, device_port, host_port, num_retry=1): Loading @@ -772,14 +749,14 @@ class GdAndroidDevice(GdDeviceBase): if num_retry > 0: # If requested, reboot an retry num_retry -= 1 logging.warning( "[%s] Failed to TCP reverse device port %d to " "host port %d, num_retries left is %d" % (self.label, device_port, host_port, num_retry)) logging.warning("[%s] Failed to TCP reverse device port %d to " "host port %d, num_retries left is %d" % (self.label, device_port, host_port, num_retry)) self.reboot() self.adb.remount() return self.tcp_reverse_or_die(device_port, host_port, num_retry=num_retry) asserts.fail( 'Unable to reverse device port %d to host port %d, error %s' % (device_port, host_port, error_or_port)) asserts.fail('Unable to reverse device port %d to host port %d, error %s' % (device_port, host_port, error_or_port)) return error_or_port def ensure_verity_disabled(self): Loading system/blueberry/tests/gd_sl4a/lib/gd_sl4a_base_test.py +0 −4 Original line number Diff line number Diff line Loading @@ -123,10 +123,6 @@ class GdSl4aBaseTestClass(BaseTestClass): "/data/misc/bluedroid/bt_config.conf", os.path.join(base_dir, "DUT_%s_bt_config.conf" % self.dut.serial) ]) self.dut.adb.pull([ "/data/misc/bluedroid/bt_config.bak", os.path.join(base_dir, "DUT_%s_bt_config.bak" % self.dut.serial) ]) except AdbError as error: logging.warning("Failed to pull logs from DUT: " + str(error)) Loading 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
system/blueberry/tests/gd/cert/gd_device.py +75 −98 Original line number Diff line number Diff line Loading @@ -194,29 +194,25 @@ class GdDeviceBase(ABC): """ # Start backing process logging.debug("[%s] Running %s %s" % (self.type_identifier, self.label, " ".join(self.cmd))) self.backing_process = subprocess.Popen( self.cmd, self.backing_process = subprocess.Popen(self.cmd, cwd=get_gd_root(), env=self.environment, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) self.backing_process_logger = AsyncSubprocessLogger( self.backing_process, [self.backing_process_log_path], self.backing_process_logger = AsyncSubprocessLogger(self.backing_process, [self.backing_process_log_path], log_to_stdout=self.verbose_mode, tag=self.label, color=self.terminal_color) asserts.assert_true( self.backing_process, msg="[%s] failed to open backing process for %s" % (self.type_identifier, self.label)) asserts.assert_true(self.backing_process, msg="[%s] failed to open backing process for %s" % (self.type_identifier, self.label)) self.is_backing_process_alive = is_subprocess_alive(self.backing_process) asserts.assert_true( self.is_backing_process_alive, asserts.assert_true(self.is_backing_process_alive, msg="[%s] backing process for %s died after starting" % (self.type_identifier, self.label)) # If gRPC root server port is not specified, we can skip settings up the root server if self.grpc_root_server_port != -1: # Setup gRPC management channels Loading @@ -228,14 +224,14 @@ class GdDeviceBase(ABC): logging.info("[%s] Waiting to connect to gRPC root server for %s, timeout is %d seconds" % (self.type_identifier, self.label, GRPC_START_TIMEOUT_SEC)) grpc.channel_ready_future(self.grpc_root_server_channel).result(timeout=GRPC_START_TIMEOUT_SEC) logging.info( "[%s] Successfully connected to gRPC root server for %s" % (self.type_identifier, self.label)) logging.info("[%s] Successfully connected to gRPC root server for %s" % (self.type_identifier, self.label)) self.grpc_root_server_ready = True except grpc.FutureTimeoutError: logging.error("[%s] Failed to connect to gRPC root server for %s" % (self.type_identifier, self.label)) asserts.assert_true( self.grpc_root_server_ready, msg="gRPC root server did not start after running " + " ".join(self.cmd)) asserts.assert_true(self.grpc_root_server_ready, msg="gRPC root server did not start after running " + " ".join(self.cmd)) self.grpc_channel = grpc.insecure_channel("localhost:%d" % self.grpc_port) Loading Loading @@ -338,10 +334,10 @@ class GdHostOnlyDevice(GdDeviceBase): # Only check on host only test, for Android devices, these ports will # be opened on Android device and host machine ports will be occupied # by sshd or adb forwarding ports_needed = [self.grpc_port, self.grpc_root_server_port] if self.grpc_root_server_port != -1 else [self.grpc_port] asserts.assert_true( make_ports_available(ports_needed), "[%s] Failed to make backing process ports available" % self.label) ports_needed = [self.grpc_port, self.grpc_root_server_port ] if self.grpc_root_server_port != -1 else [self.grpc_port] asserts.assert_true(make_ports_available(ports_needed), "[%s] Failed to make backing process ports available" % self.label) super().setup() def teardown(self): Loading @@ -362,8 +358,8 @@ class GdHostOnlyDevice(GdDeviceBase): } def get_coverage_profdata_path_for_host(self, test_runner_base_path, type_identifier, label) -> pathlib.Path: return pathlib.Path(test_runner_base_path).parent.parent.joinpath( "%s_%s_backing_process_coverage.profdata" % (type_identifier, label)) return pathlib.Path(test_runner_base_path).parent.parent.joinpath("%s_%s_backing_process_coverage.profdata" % (type_identifier, label)) def merge_coverage_profdata_for_host(self, backing_process_profraw_path, profdata_path: pathlib.Path, label): if not backing_process_profraw_path.is_file(): Loading Loading @@ -421,8 +417,7 @@ class GdHostOnlyDevice(GdDeviceBase): str(stack_bin) ] logging.debug("Running llvm_cov export: %s" % " ".join(llvm_cov_export_cmd)) result = subprocess.run( llvm_cov_export_cmd, result = subprocess.run(llvm_cov_export_cmd, stderr=subprocess.PIPE, stdout=coverage_result_file, cwd=os.path.join(get_gd_root())) Loading @@ -440,8 +435,7 @@ class GdHostOnlyDevice(GdDeviceBase): str(stack_bin) ] logging.debug("Running llvm_cov report: %s" % " ".join(llvm_cov_report_cmd)) result = subprocess.run( llvm_cov_report_cmd, result = subprocess.run(llvm_cov_report_cmd, stderr=subprocess.PIPE, stdout=coverage_summary_file, cwd=os.path.join(get_gd_root())) Loading Loading @@ -479,8 +473,7 @@ class GdAndroidDevice(GdDeviceBase): logging.info("Confirmed that verity is disabled on device %s %s" % (self.label, self.serial_number)) # Try freeing ports and ignore results asserts.assert_true( make_ports_available((self.grpc_port, self.grpc_root_server_port, self.signal_port)), asserts.assert_true(make_ports_available((self.grpc_port, self.grpc_root_server_port, self.signal_port)), "[%s] Failed to make backing process ports available" % self.label) self.cleanup_port_forwarding() self.sync_device_time() Loading @@ -501,17 +494,15 @@ class GdAndroidDevice(GdDeviceBase): # Do not override exist libraries shared by other binaries on the Android device to avoid corrupting the Android device self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_BIN_DIR, "bluetooth_stack_with_facade")) self.push_or_die( *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "android.hardware.bluetooth@1.0.so"), self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "android.hardware.bluetooth@1.0.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "android.hardware.bluetooth@1.1.so"), overwrite_existing=False) self.push_or_die( *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "android.hardware.bluetooth@1.1.so"), self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libandroid_runtime_lazy.so"), overwrite_existing=False) self.push_or_die( *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libandroid_runtime_lazy.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libbase.so"), overwrite_existing=False) self.push_or_die( *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libbinder_ndk.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libbinder_ndk.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libbinder.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libc++.so"), overwrite_existing=False) # libclang_rt.asan-aarch64-android.so is only needed for ASAN build and is automatically included on device Loading @@ -520,8 +511,8 @@ class GdAndroidDevice(GdDeviceBase): # overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libcrypto.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libcutils.so"), overwrite_existing=False) self.push_or_die( *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libgrpc_wrap.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libgrpc_wrap.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libgrpc++.so")) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libhidlbase.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "liblog.so"), overwrite_existing=False) Loading @@ -529,8 +520,8 @@ class GdAndroidDevice(GdDeviceBase): self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libprotobuf-cpp-full.so")) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libssl.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libgrpc++.so")) self.push_or_die( *generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libunwindstack.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libunwindstack.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libutils.so"), overwrite_existing=False) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libgrpc++.so")) self.push_or_die(*generate_dir_pair(local_dir, self.DEVICE_LIB_DIR, "libz.so"), overwrite_existing=False) Loading @@ -555,11 +546,6 @@ class GdAndroidDevice(GdDeviceBase): if ADB_FILE_NOT_EXIST_ERROR not in str(error): logging.error("Error during setup: " + str(error)) try: self.adb.shell("rm /data/misc/bluedroid/bt_config.bak") except AdbError as error: if ADB_FILE_NOT_EXIST_ERROR not in str(error): logging.error("Error during setup: " + str(error)) logging.info("Old logs removed from device %s %s" % (self.label, self.serial_number)) # Ensure Bluetooth is disabled Loading @@ -575,14 +561,14 @@ class GdAndroidDevice(GdDeviceBase): self.log_path_base, '%s_%s_%s_logcat_logs.txt' % (self.type_identifier, self.label, self.serial_number)) self.logcat_cmd = ["adb", "-s", self.serial_number, "logcat", "-T", "1", "-v", "year", "-v", "uid"] logging.debug("Running %s", " ".join(self.logcat_cmd)) self.logcat_process = subprocess.Popen( self.logcat_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) self.logcat_process = subprocess.Popen(self.logcat_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) asserts.assert_true(self.logcat_process, msg="Cannot start logcat_process at " + " ".join(self.logcat_cmd)) asserts.assert_true( is_subprocess_alive(self.logcat_process), asserts.assert_true(is_subprocess_alive(self.logcat_process), msg="logcat_process stopped immediately after running " + " ".join(self.logcat_cmd)) self.logcat_logger = AsyncSubprocessLogger( self.logcat_process, [self.logcat_output_path], self.logcat_logger = AsyncSubprocessLogger(self.logcat_process, [self.logcat_output_path], log_to_stdout=self.verbose_mode, tag="%s_%s" % (self.label, self.serial_number), color=self.terminal_color) Loading Loading @@ -631,14 +617,6 @@ class GdAndroidDevice(GdDeviceBase): # Some tests have no config file, and that's OK if ADB_FILE_NOT_EXIST_ERROR not in str(error): logging.error(PULL_LOG_FILE_ERROR_MSG_PREFIX + str(error)) try: self.adb.pull( ["/data/misc/bluedroid/bt_config.bak", str(os.path.join(base_dir, "%s_bt_config.bak" % self.label))]) except AdbError as error: # Some tests have no config.bak file, and that's OK if ADB_FILE_NOT_EXIST_ERROR not in str(error): logging.error(PULL_LOG_FILE_ERROR_MSG_PREFIX + str(error)) def cleanup_port_forwarding(self): try: Loading Loading @@ -674,8 +652,8 @@ class GdAndroidDevice(GdDeviceBase): """ Ensure a command has not output """ asserts.assert_true( result is None or len(result) == 0, msg="command returned something when it shouldn't: %s" % result) asserts.assert_true(result is None or len(result) == 0, msg="command returned something when it shouldn't: %s" % result) def sync_device_time(self): self.adb.shell("settings put global auto_time 0") Loading Loading @@ -706,8 +684,7 @@ class GdAndroidDevice(GdDeviceBase): # Include ADB delay that might be longer in SSH environment max_delta_seconds = 3 host_time = datetime.now(tz=device_time.tzinfo) asserts.assert_almost_equal( (device_time - host_time).total_seconds(), asserts.assert_almost_equal((device_time - host_time).total_seconds(), 0, msg="Device time %s and host time %s off by >%dms after sync" % (device_time.isoformat(), host_time.isoformat(), int(max_delta_seconds * 1000)), Loading Loading @@ -744,14 +721,14 @@ class GdAndroidDevice(GdDeviceBase): if num_retry > 0: # If requested, reboot an retry num_retry -= 1 logging.warning( "[%s] Failed to TCP forward host port %d to " "device port %d, num_retries left is %d" % (self.label, host_port, device_port, num_retry)) logging.warning("[%s] Failed to TCP forward host port %d to " "device port %d, num_retries left is %d" % (self.label, host_port, device_port, num_retry)) self.reboot() self.adb.remount() return self.tcp_forward_or_die(host_port, device_port, num_retry=num_retry) asserts.fail( 'Unable to forward host port %d to device port %d, error %s' % (host_port, device_port, error_or_port)) asserts.fail('Unable to forward host port %d to device port %d, error %s' % (host_port, device_port, error_or_port)) return error_or_port def tcp_reverse_or_die(self, device_port, host_port, num_retry=1): Loading @@ -772,14 +749,14 @@ class GdAndroidDevice(GdDeviceBase): if num_retry > 0: # If requested, reboot an retry num_retry -= 1 logging.warning( "[%s] Failed to TCP reverse device port %d to " "host port %d, num_retries left is %d" % (self.label, device_port, host_port, num_retry)) logging.warning("[%s] Failed to TCP reverse device port %d to " "host port %d, num_retries left is %d" % (self.label, device_port, host_port, num_retry)) self.reboot() self.adb.remount() return self.tcp_reverse_or_die(device_port, host_port, num_retry=num_retry) asserts.fail( 'Unable to reverse device port %d to host port %d, error %s' % (device_port, host_port, error_or_port)) asserts.fail('Unable to reverse device port %d to host port %d, error %s' % (device_port, host_port, error_or_port)) return error_or_port def ensure_verity_disabled(self): Loading
system/blueberry/tests/gd_sl4a/lib/gd_sl4a_base_test.py +0 −4 Original line number Diff line number Diff line Loading @@ -123,10 +123,6 @@ class GdSl4aBaseTestClass(BaseTestClass): "/data/misc/bluedroid/bt_config.conf", os.path.join(base_dir, "DUT_%s_bt_config.conf" % self.dut.serial) ]) self.dut.adb.pull([ "/data/misc/bluedroid/bt_config.bak", os.path.join(base_dir, "DUT_%s_bt_config.bak" % self.dut.serial) ]) except AdbError as error: logging.warning("Failed to pull logs from DUT: " + str(error)) Loading