Migrate HID host/device enable/disable to sysprops
Tag: #refactor
Bug: 217448211
Test: atest BluetoothInstrumentationTests
Merged-In: I0d81eb91a6576818e0f83df7ac3a6bf0ac6c8b97
Change-Id: I0d81eb91a6576818e0f83df7ac3a6bf0ac6c8b97
diff --git a/android/app/AndroidManifest.xml b/android/app/AndroidManifest.xml
index bdeed89..fad9d06 100644
--- a/android/app/AndroidManifest.xml
+++ b/android/app/AndroidManifest.xml
@@ -221,6 +221,26 @@
</intent-filter>
</service>
+ <!-- Human Interface Device (HID) host Profile Service -->
+ <service android:process="@string/process"
+ android:name="com.android.bluetooth.hid.HidHostService"
+ android:enabled="true"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="android.bluetooth.IBluetoothHidHost"/>
+ </intent-filter>
+ </service>
+
+ <!-- Human Interface Device (HID) device Profile Service -->
+ <service android:process="@string/process"
+ android:name="com.android.bluetooth.hid.HidDeviceService"
+ android:enabled="true"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="android.bluetooth.IBluetoothHidDevice"/>
+ </intent-filter>
+ </service>
+
<!-- Media Control Profile (MCP) server Profile Service -->
<service android:process="@string/process"
android:name="com.android.bluetooth.mcp.McpService"
@@ -451,22 +471,6 @@
<action android:name="android.bluetooth.IBluetoothHeadset"/>
</intent-filter>
</service>
- <service android:process="@string/process"
- android:name=".hid.HidHostService"
- android:enabled="@bool/profile_supported_hid_host"
- android:exported="true">
- <intent-filter>
- <action android:name="android.bluetooth.IBluetoothHidHost"/>
- </intent-filter>
- </service>
- <service android:process="@string/process"
- android:name=".hid.HidDeviceService"
- android:enabled="@bool/profile_supported_hid_device"
- android:exported="true">
- <intent-filter>
- <action android:name="android.bluetooth.IBluetoothHidDevice"/>
- </intent-filter>
- </service>
<service
android:process="@string/process"
android:name=".pan.PanService"
diff --git a/android/app/res/values/config.xml b/android/app/res/values/config.xml
index 704357f..a84fecb 100644
--- a/android/app/res/values/config.xml
+++ b/android/app/res/values/config.xml
@@ -16,7 +16,6 @@
<bool name="profile_supported_hs_hfp">true</bool>
<bool name="profile_supported_hfpclient">false</bool>
<bool name="profile_supported_hfp_incallservice">true</bool>
- <bool name="profile_supported_hid_host">true</bool>
<bool name="profile_supported_opp">true</bool>
<bool name="profile_supported_pan">true</bool>
<bool name="profile_supported_pbap">true</bool>
@@ -26,7 +25,6 @@
<bool name="profile_supported_sap">false</bool>
<bool name="profile_supported_pbapclient">false</bool>
<bool name="profile_supported_mapmce">false</bool>
- <bool name="profile_supported_hid_device">true</bool>
<!-- If true, we will require location to be enabled on the device to
fire Bluetooth LE scan result callbacks in addition to having one
diff --git a/android/app/src/com/android/bluetooth/hid/HidDeviceService.java b/android/app/src/com/android/bluetooth/hid/HidDeviceService.java
index cff9876..c95856a 100644
--- a/android/app/src/com/android/bluetooth/hid/HidDeviceService.java
+++ b/android/app/src/com/android/bluetooth/hid/HidDeviceService.java
@@ -35,6 +35,7 @@
import android.os.Message;
import android.os.Process;
import android.os.RemoteException;
+import android.sysprop.BluetoothProperties;
import android.util.Log;
import com.android.bluetooth.BluetoothMetricsProto;
@@ -85,6 +86,10 @@
private HidDeviceServiceHandler mHandler;
+ public static boolean isEnabled() {
+ return BluetoothProperties.isProfileHidDeviceEnabled().orElse(false);
+ }
+
private class HidDeviceServiceHandler extends Handler {
@Override
public void handleMessage(Message msg) {
diff --git a/android/app/src/com/android/bluetooth/hid/HidHostService.java b/android/app/src/com/android/bluetooth/hid/HidHostService.java
index f2baa1a..0c2c127 100644
--- a/android/app/src/com/android/bluetooth/hid/HidHostService.java
+++ b/android/app/src/com/android/bluetooth/hid/HidHostService.java
@@ -31,6 +31,7 @@
import android.os.Handler;
import android.os.Message;
import android.os.UserHandle;
+import android.sysprop.BluetoothProperties;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
@@ -87,6 +88,10 @@
classInitNative();
}
+ public static boolean isEnabled() {
+ return BluetoothProperties.isProfileHidHostEnabled().orElse(false);
+ }
+
@Override
public IProfileServiceBinder initBinder() {
return new BluetoothHidHostBinder(this);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hid/HidDeviceTest.java b/android/app/tests/unit/src/com/android/bluetooth/hid/HidDeviceTest.java
index ad67968..0e1743e 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hid/HidDeviceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hid/HidDeviceTest.java
@@ -101,7 +101,7 @@
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
Assume.assumeTrue("Ignore test when HidDeviceService is not enabled",
- mTargetContext.getResources().getBoolean(R.bool.profile_supported_hid_device));
+ HidDeviceService.isEnabled());
if (Looper.myLooper() == null) {
Looper.prepare();
}
@@ -145,7 +145,7 @@
@After
public void tearDown() throws Exception {
- if (!mTargetContext.getResources().getBoolean(R.bool.profile_supported_hid_device)) {
+ if (!HidDeviceService.isEnabled()) {
return;
}
TestUtils.stopService(mServiceRule, HidDeviceService.class);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceTest.java
index 72bd648..4122c33 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceTest.java
@@ -59,7 +59,7 @@
public void setUp() throws Exception {
mTargetContext = InstrumentationRegistry.getTargetContext();
Assume.assumeTrue("Ignore test when HidHostService is not enabled",
- mTargetContext.getResources().getBoolean(R.bool.profile_supported_hid_host));
+ HidHostService.isEnabled());
MockitoAnnotations.initMocks(this);
TestUtils.setAdapterService(mAdapterService);
when(mAdapterService.getDatabase()).thenReturn(mDatabaseManager);
@@ -77,7 +77,7 @@
@After
public void tearDown() throws Exception {
- if (!mTargetContext.getResources().getBoolean(R.bool.profile_supported_hid_host)) {
+ if (!HidHostService.isEnabled()) {
return;
}
when(mAdapterService.isStartedProfile(anyString())).thenReturn(false);