diff --git a/android/app/src/com/android/bluetooth/Utils.java b/android/app/src/com/android/bluetooth/Utils.java index fa07a5ff59aa78d9e2a2135016f9e4f855035e73..2f0fb5f088bf235b7c52164efa0a2e17e98401ac 100644 --- a/android/app/src/com/android/bluetooth/Utils.java +++ b/android/app/src/com/android/bluetooth/Utils.java @@ -1190,4 +1190,42 @@ public final class Utils { return string; } + + /** + * Check if BLE is supported by this platform + * @param context current device context + * @return true if BLE is supported, false otherwise + */ + public static boolean isBleSupported(Context context) { + return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE); + } + + /** + * Check if this is an automotive device + * @param context current device context + * @return true if this Android device is an automotive device, false otherwise + */ + public static boolean isAutomotive(Context context) { + return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE); + } + + /** + * Check if this is a watch device + * @param context current device context + * @return true if this Android device is a watch device, false otherwise + */ + public static boolean isWatch(Context context) { + return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH); + } + + /** + * Check if this is a TV device + * @param context current device context + * @return true if this Android device is a TV device, false otherwise + */ + public static boolean isTv(Context context) { + PackageManager pm = context.getPackageManager(); + return pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION) + || pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK); + } } diff --git a/android/app/src/com/android/bluetooth/btservice/Config.java b/android/app/src/com/android/bluetooth/btservice/Config.java index 4510002e09c6f1f7f0ae633723d70b4ce5899773..7eaa804af88dbe88a578f8780c08e6965d6f6b1f 100644 --- a/android/app/src/com/android/bluetooth/btservice/Config.java +++ b/android/app/src/com/android/bluetooth/btservice/Config.java @@ -18,12 +18,13 @@ package com.android.bluetooth.btservice; import android.bluetooth.BluetoothProfile; import android.content.Context; -import android.content.pm.PackageManager; import android.content.res.Resources; import android.os.SystemProperties; +import android.sysprop.BluetoothProperties; import android.util.Log; import com.android.bluetooth.R; +import com.android.bluetooth.Utils; import com.android.bluetooth.a2dp.A2dpService; import com.android.bluetooth.a2dpsink.A2dpSinkService; import com.android.bluetooth.avrcp.AvrcpTargetService; @@ -194,8 +195,18 @@ public class Config { } } - // Disable ASHA if BLE is not supported on this platform - if (!ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { + // Disable ASHA on Automotive, TV, and Watch devices if the system property is not set + // This means that the OS will not automatically enable ASHA on these platforms, but these + // platforms can choose to enable ASHA themselves + if (BluetoothProperties.isProfileAshaCentralEnabled().isEmpty()) { + if (Utils.isAutomotive(ctx) || Utils.isTv(ctx) || Utils.isWatch(ctx)) { + setProfileEnabled(HearingAidService.class, false); + } + } + + // Disable ASHA if BLE is not supported on this platform even if the platform enabled ASHA + // accidentally + if (!Utils.isBleSupported(ctx)) { setProfileEnabled(HearingAidService.class, false); } diff --git a/service/src/com/android/server/bluetooth/BluetoothManagerService.java b/service/src/com/android/server/bluetooth/BluetoothManagerService.java index 080b332f74ba070448c53d988a01b207c111107a..f237c53264b6a9fa9ea98caa144d9feecdad00ea 100644 --- a/service/src/com/android/server/bluetooth/BluetoothManagerService.java +++ b/service/src/com/android/server/bluetooth/BluetoothManagerService.java @@ -646,11 +646,19 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { mBluetoothNotificationManager = new BluetoothNotificationManager(mContext); - // Disable ASHA if BLE is not supported on this platform - mIsHearingAidProfileSupported = - BluetoothProperties.isProfileAshaCentralEnabled().orElse(true); - if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { + // Disable ASHA if BLE is not supported, overriding any system property + if (!isBleSupported(mContext)) { mIsHearingAidProfileSupported = false; + } else { + // ASHA default value is: + // * disabled on Automotive, TV, and Watch. + // * enabled for other form factor + // This default value can be overridden with a system property + final boolean isAshaEnabledByDefault = + !(isAutomotive(mContext) || isWatch(mContext) || isTv(mContext)); + mIsHearingAidProfileSupported = + BluetoothProperties.isProfileAshaCentralEnabled() + .orElse(isAshaEnabledByDefault); } String value = SystemProperties.get( @@ -3647,5 +3655,43 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { } return BluetoothAdapter.BT_SNOOP_LOG_MODE_DISABLED; } + + /** + * Check if BLE is supported by this platform + * @param context current device context + * @return true if BLE is supported, false otherwise + */ + private static boolean isBleSupported(Context context) { + return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE); + } + + /** + * Check if this is an automotive device + * @param context current device context + * @return true if this Android device is an automotive device, false otherwise + */ + private static boolean isAutomotive(Context context) { + return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE); + } + + /** + * Check if this is a watch device + * @param context current device context + * @return true if this Android device is a watch device, false otherwise + */ + private static boolean isWatch(Context context) { + return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH); + } + + /** + * Check if this is a TV device + * @param context current device context + * @return true if this Android device is a TV device, false otherwise + */ + private static boolean isTv(Context context) { + PackageManager pm = context.getPackageManager(); + return pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION) + || pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK); + } }