Loading android/app/aidl/android/bluetooth/IBluetooth.aidl +4 −4 Original line number Diff line number Diff line Loading @@ -52,8 +52,8 @@ interface IBluetooth @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)") oneway void offToBleOn(boolean quietMode, in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)") oneway void disable(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)") oneway void onToBleOn(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.LOCAL_MAC_ADDRESS})") String getAddress(in AttributionSource attributionSource); Loading Loading @@ -227,8 +227,8 @@ interface IBluetooth @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})") oneway void startBrEdr(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})") oneway void stopBle(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)") oneway void bleOnToOff(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED,android.Manifest.permission.MODIFY_PHONE_STATE})") int connectAllEnabledProfiles(in BluetoothDevice device, in AttributionSource attributionSource); Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +11 −12 Original line number Diff line number Diff line Loading @@ -2317,16 +2317,16 @@ public class AdapterService extends Service { } @Override public void disable(AttributionSource source) { public void onToBleOn(AttributionSource source) { AdapterService service = getService(); if (service == null || !callerIsSystemOrActiveOrManagedUser(service, TAG, "disable") || !Utils.checkConnectPermissionForDataDelivery( service, source, "AdapterService disable")) { || !callerIsSystemOrActiveOrManagedUser(service, TAG, "onToBleOn")) { return; } service.disable(); service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null); service.onToBleOn(); } @Override Loading Loading @@ -3814,17 +3814,16 @@ public class AdapterService extends Service { } @Override public void stopBle(AttributionSource source) { public void bleOnToOff(AttributionSource source) { AdapterService service = getService(); if (service == null || !callerIsSystemOrActiveOrManagedUser(service, TAG, "stopBle") || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) { || !callerIsSystemOrActiveOrManagedUser(service, TAG, "bleOnToOff")) { return; } service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null); service.stopBle(); service.bleOnToOff(); } @Override Loading Loading @@ -4628,8 +4627,8 @@ public class AdapterService extends Service { mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_ON); } void disable() { Log.d(TAG, "disable() called with mRunningProfiles.size() = " + mRunningProfiles.size()); void onToBleOn() { Log.d(TAG, "onToBleOn() called with mRunningProfiles.size() = " + mRunningProfiles.size()); mAdapterStateMachine.sendMessage(AdapterState.USER_TURN_OFF); } Loading Loading @@ -5767,7 +5766,7 @@ public class AdapterService extends Service { } @VisibleForTesting void stopBle() { void bleOnToOff() { mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_OFF); } Loading android/app/src/com/android/bluetooth/btservice/MetricsLogger.java +15 −0 Original line number Diff line number Diff line Loading @@ -546,6 +546,21 @@ public class MetricsLogger { BluetoothStatsLog.BLUETOOTH_HASHED_DEVICE_NAME_REPORTED, metricId, sha256); } public void logBluetoothEvent(BluetoothDevice device, int eventType, int state, int uid) { if (mAdapterService.getMetricId(device) == 0 || !mInitialized) { return; } BluetoothStatsLog.write( BluetoothStatsLog.BLUETOOTH_CROSS_LAYER_EVENT_REPORTED, eventType, state, uid, mAdapterService.getMetricId(device), getRemoteDeviceInfoProto(device)); } protected static String getSha256String(String name) { if (name.isEmpty()) { return ""; Loading android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java +7 −7 Original line number Diff line number Diff line Loading @@ -435,7 +435,7 @@ public class AdapterServiceTest { IBluetoothCallback callback, boolean onlyGatt, List<ProfileService> services) { adapter.disable(); adapter.onToBleOn(); TestUtils.syncHandler(looper, AdapterState.USER_TURN_OFF); verifyStateChange(callback, STATE_ON, STATE_TURNING_OFF); Loading Loading @@ -540,7 +540,7 @@ public class AdapterServiceTest { onToBleOn(looper, adapter, ctx, callback, onlyGatt, services); adapter.stopBle(); adapter.bleOnToOff(); TestUtils.syncHandler(looper, AdapterState.BLE_TURN_OFF); verifyStateChange(callback, STATE_BLE_ON, STATE_BLE_TURNING_OFF); Loading Loading @@ -661,7 +661,7 @@ public class AdapterServiceTest { false, listOfMockServices()); mAdapterService.stopBle(); mAdapterService.bleOnToOff(); syncHandler(AdapterState.BLE_TURN_OFF); verifyStateChange(STATE_BLE_ON, STATE_BLE_TURNING_OFF, CONTEXT_SWITCH_MS); assertThat(mAdapterService.getBluetoothGatt()).isNull(); Loading Loading @@ -723,7 +723,7 @@ public class AdapterServiceTest { assertThat(mAdapterService.getBluetoothScan()).isNotNull(); assertThat(mAdapterService.getBluetoothGatt()).isNull(); mAdapterService.stopBle(); mAdapterService.bleOnToOff(); syncHandler(AdapterState.BLE_TURN_OFF); verifyStateChange(callback, STATE_BLE_ON, STATE_BLE_TURNING_OFF); Loading Loading @@ -789,7 +789,7 @@ public class AdapterServiceTest { assertThat(mAdapterService.getState()).isEqualTo(STATE_ON); mAdapterService.disable(); mAdapterService.onToBleOn(); TestUtils.syncHandler(mLooper, AdapterState.USER_TURN_OFF); verifyStateChange(callback, STATE_ON, STATE_TURNING_OFF); Loading Loading @@ -858,7 +858,7 @@ public class AdapterServiceTest { public void testProfileStopTimeout() { doEnable(false); mAdapterService.disable(); mAdapterService.onToBleOn(); syncHandler(AdapterState.USER_TURN_OFF); verifyStateChange(STATE_ON, STATE_TURNING_OFF); assertThat(mAdapterService.mSetProfileServiceStateCounter).isEqualTo(4); Loading Loading @@ -910,7 +910,7 @@ public class AdapterServiceTest { false, listOfMockServices()); // Do not call stopBle(). The Adapter should turn itself off. // Do not call bleOnToOff(). The Adapter should turn itself off. syncHandler(AdapterState.BLE_TURN_OFF); verifyStateChange(STATE_BLE_ON, STATE_BLE_TURNING_OFF, CONTEXT_SWITCH_MS); Loading floss/hcidoc/src/main.rs +18 −28 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ mod parser; use crate::engine::RuleEngine; use crate::groups::{collisions, connections, controllers, informational}; use crate::parser::{LinuxSnoopOpcodes, LogParser, LogType, Packet}; use crate::parser::{LogParser, Packet, SnoopOpcodes}; fn main() { let matches = Command::new("hcidoc") Loading Loading @@ -63,7 +63,7 @@ fn main() { report_signals = true; } let mut parser = match LogParser::new(filename) { let parser = match LogParser::new(filename) { Ok(p) => p, Err(e) => { println!( Loading @@ -75,14 +75,6 @@ fn main() { } }; let log_type = match parser.read_log_type() { Ok(v) => v, Err(e) => { println!("Parsing {} failed: {}", filename, e); return; } }; // Create engine with default rule groups. let mut engine = RuleEngine::new(); engine.add_rule_group("Collisions".into(), collisions::get_collisions_group()); Loading @@ -93,14 +85,13 @@ fn main() { // Decide where to write output. let mut writer: Box<dyn Write> = Box::new(std::io::stdout()); if let LogType::LinuxSnoop(_header) = log_type { for (pos, v) in parser.get_snoop_iterator().expect("Not a linux snoop file").enumerate() { match Packet::try_from((pos, &v)) { for (pos, v) in parser.get_snoop_iterator().enumerate() { match Packet::try_from((pos, &*v)) { Ok(p) => engine.process(p), Err(e) => { if !ignore_unknown_opcode { match v.opcode() { LinuxSnoopOpcodes::Command | LinuxSnoopOpcodes::Event => { SnoopOpcodes::Command | SnoopOpcodes::Event => { eprintln!("#{}: {}", pos, e); } _ => (), Loading @@ -118,4 +109,3 @@ fn main() { engine.report_signals(&mut writer); } } } Loading
android/app/aidl/android/bluetooth/IBluetooth.aidl +4 −4 Original line number Diff line number Diff line Loading @@ -52,8 +52,8 @@ interface IBluetooth @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)") oneway void offToBleOn(boolean quietMode, in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)") oneway void disable(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)") oneway void onToBleOn(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.LOCAL_MAC_ADDRESS})") String getAddress(in AttributionSource attributionSource); Loading Loading @@ -227,8 +227,8 @@ interface IBluetooth @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})") oneway void startBrEdr(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})") oneway void stopBle(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)") oneway void bleOnToOff(in AttributionSource attributionSource); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED,android.Manifest.permission.MODIFY_PHONE_STATE})") int connectAllEnabledProfiles(in BluetoothDevice device, in AttributionSource attributionSource); Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +11 −12 Original line number Diff line number Diff line Loading @@ -2317,16 +2317,16 @@ public class AdapterService extends Service { } @Override public void disable(AttributionSource source) { public void onToBleOn(AttributionSource source) { AdapterService service = getService(); if (service == null || !callerIsSystemOrActiveOrManagedUser(service, TAG, "disable") || !Utils.checkConnectPermissionForDataDelivery( service, source, "AdapterService disable")) { || !callerIsSystemOrActiveOrManagedUser(service, TAG, "onToBleOn")) { return; } service.disable(); service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null); service.onToBleOn(); } @Override Loading Loading @@ -3814,17 +3814,16 @@ public class AdapterService extends Service { } @Override public void stopBle(AttributionSource source) { public void bleOnToOff(AttributionSource source) { AdapterService service = getService(); if (service == null || !callerIsSystemOrActiveOrManagedUser(service, TAG, "stopBle") || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) { || !callerIsSystemOrActiveOrManagedUser(service, TAG, "bleOnToOff")) { return; } service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null); service.stopBle(); service.bleOnToOff(); } @Override Loading Loading @@ -4628,8 +4627,8 @@ public class AdapterService extends Service { mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_ON); } void disable() { Log.d(TAG, "disable() called with mRunningProfiles.size() = " + mRunningProfiles.size()); void onToBleOn() { Log.d(TAG, "onToBleOn() called with mRunningProfiles.size() = " + mRunningProfiles.size()); mAdapterStateMachine.sendMessage(AdapterState.USER_TURN_OFF); } Loading Loading @@ -5767,7 +5766,7 @@ public class AdapterService extends Service { } @VisibleForTesting void stopBle() { void bleOnToOff() { mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_OFF); } Loading
android/app/src/com/android/bluetooth/btservice/MetricsLogger.java +15 −0 Original line number Diff line number Diff line Loading @@ -546,6 +546,21 @@ public class MetricsLogger { BluetoothStatsLog.BLUETOOTH_HASHED_DEVICE_NAME_REPORTED, metricId, sha256); } public void logBluetoothEvent(BluetoothDevice device, int eventType, int state, int uid) { if (mAdapterService.getMetricId(device) == 0 || !mInitialized) { return; } BluetoothStatsLog.write( BluetoothStatsLog.BLUETOOTH_CROSS_LAYER_EVENT_REPORTED, eventType, state, uid, mAdapterService.getMetricId(device), getRemoteDeviceInfoProto(device)); } protected static String getSha256String(String name) { if (name.isEmpty()) { return ""; Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java +7 −7 Original line number Diff line number Diff line Loading @@ -435,7 +435,7 @@ public class AdapterServiceTest { IBluetoothCallback callback, boolean onlyGatt, List<ProfileService> services) { adapter.disable(); adapter.onToBleOn(); TestUtils.syncHandler(looper, AdapterState.USER_TURN_OFF); verifyStateChange(callback, STATE_ON, STATE_TURNING_OFF); Loading Loading @@ -540,7 +540,7 @@ public class AdapterServiceTest { onToBleOn(looper, adapter, ctx, callback, onlyGatt, services); adapter.stopBle(); adapter.bleOnToOff(); TestUtils.syncHandler(looper, AdapterState.BLE_TURN_OFF); verifyStateChange(callback, STATE_BLE_ON, STATE_BLE_TURNING_OFF); Loading Loading @@ -661,7 +661,7 @@ public class AdapterServiceTest { false, listOfMockServices()); mAdapterService.stopBle(); mAdapterService.bleOnToOff(); syncHandler(AdapterState.BLE_TURN_OFF); verifyStateChange(STATE_BLE_ON, STATE_BLE_TURNING_OFF, CONTEXT_SWITCH_MS); assertThat(mAdapterService.getBluetoothGatt()).isNull(); Loading Loading @@ -723,7 +723,7 @@ public class AdapterServiceTest { assertThat(mAdapterService.getBluetoothScan()).isNotNull(); assertThat(mAdapterService.getBluetoothGatt()).isNull(); mAdapterService.stopBle(); mAdapterService.bleOnToOff(); syncHandler(AdapterState.BLE_TURN_OFF); verifyStateChange(callback, STATE_BLE_ON, STATE_BLE_TURNING_OFF); Loading Loading @@ -789,7 +789,7 @@ public class AdapterServiceTest { assertThat(mAdapterService.getState()).isEqualTo(STATE_ON); mAdapterService.disable(); mAdapterService.onToBleOn(); TestUtils.syncHandler(mLooper, AdapterState.USER_TURN_OFF); verifyStateChange(callback, STATE_ON, STATE_TURNING_OFF); Loading Loading @@ -858,7 +858,7 @@ public class AdapterServiceTest { public void testProfileStopTimeout() { doEnable(false); mAdapterService.disable(); mAdapterService.onToBleOn(); syncHandler(AdapterState.USER_TURN_OFF); verifyStateChange(STATE_ON, STATE_TURNING_OFF); assertThat(mAdapterService.mSetProfileServiceStateCounter).isEqualTo(4); Loading Loading @@ -910,7 +910,7 @@ public class AdapterServiceTest { false, listOfMockServices()); // Do not call stopBle(). The Adapter should turn itself off. // Do not call bleOnToOff(). The Adapter should turn itself off. syncHandler(AdapterState.BLE_TURN_OFF); verifyStateChange(STATE_BLE_ON, STATE_BLE_TURNING_OFF, CONTEXT_SWITCH_MS); Loading
floss/hcidoc/src/main.rs +18 −28 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ mod parser; use crate::engine::RuleEngine; use crate::groups::{collisions, connections, controllers, informational}; use crate::parser::{LinuxSnoopOpcodes, LogParser, LogType, Packet}; use crate::parser::{LogParser, Packet, SnoopOpcodes}; fn main() { let matches = Command::new("hcidoc") Loading Loading @@ -63,7 +63,7 @@ fn main() { report_signals = true; } let mut parser = match LogParser::new(filename) { let parser = match LogParser::new(filename) { Ok(p) => p, Err(e) => { println!( Loading @@ -75,14 +75,6 @@ fn main() { } }; let log_type = match parser.read_log_type() { Ok(v) => v, Err(e) => { println!("Parsing {} failed: {}", filename, e); return; } }; // Create engine with default rule groups. let mut engine = RuleEngine::new(); engine.add_rule_group("Collisions".into(), collisions::get_collisions_group()); Loading @@ -93,14 +85,13 @@ fn main() { // Decide where to write output. let mut writer: Box<dyn Write> = Box::new(std::io::stdout()); if let LogType::LinuxSnoop(_header) = log_type { for (pos, v) in parser.get_snoop_iterator().expect("Not a linux snoop file").enumerate() { match Packet::try_from((pos, &v)) { for (pos, v) in parser.get_snoop_iterator().enumerate() { match Packet::try_from((pos, &*v)) { Ok(p) => engine.process(p), Err(e) => { if !ignore_unknown_opcode { match v.opcode() { LinuxSnoopOpcodes::Command | LinuxSnoopOpcodes::Event => { SnoopOpcodes::Command | SnoopOpcodes::Event => { eprintln!("#{}: {}", pos, e); } _ => (), Loading @@ -118,4 +109,3 @@ fn main() { engine.report_signals(&mut writer); } } }