Loading src/com/android/bluetooth/btservice/AdapterService.java +19 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ import android.companion.CompanionDeviceManager; import android.content.Attributable; import android.content.AttributionSource; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; Loading Loading @@ -191,6 +192,10 @@ public class AdapterService extends Service { private static final int CONTROLLER_ENERGY_UPDATE_TIMEOUT_MILLIS = 30; private static final ComponentName BLUETOOTH_INCALLSERVICE_COMPONENT = new ComponentName("com.android.bluetooth", BluetoothInCallService.class.getCanonicalName()); // Report ID definition public enum BqrQualityReportId { QUALITY_REPORT_ID_MONITOR_MODE(0x01), Loading Loading @@ -809,6 +814,20 @@ public class AdapterService extends Service { } } /** * Enable/disable BluetoothInCallService * * @param enable to enable/disable BluetoothInCallService. */ public void enableBluetoothInCallService(boolean enable) { debugLog("enableBluetoothInCallService() - Enable = " + enable); getPackageManager().setComponentEnabledSetting( BLUETOOTH_INCALLSERVICE_COMPONENT, enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } void cleanup() { debugLog("cleanup()"); if (mCleaningUp) { Loading src/com/android/bluetooth/btservice/AdapterState.java +6 −14 Original line number Diff line number Diff line Loading @@ -17,8 +17,6 @@ package com.android.bluetooth.btservice; import android.bluetooth.BluetoothAdapter; import android.content.ComponentName; import android.content.pm.PackageManager; import android.os.Message; import android.util.Log; Loading Loading @@ -79,10 +77,6 @@ final class AdapterState extends StateMachine { static final int BREDR_START_TIMEOUT_DELAY = 4000; static final int BREDR_STOP_TIMEOUT_DELAY = 4000; static final ComponentName BLUETOOTH_INCALLSERVICE_COMPONENT = new ComponentName(R.class.getPackage().getName(), BluetoothInCallService.class.getCanonicalName()); private AdapterService mAdapterService; private TurningOnState mTurningOnState = new TurningOnState(); private TurningBleOnState mTurningBleOnState = new TurningBleOnState(); Loading Loading @@ -233,18 +227,15 @@ final class AdapterState extends StateMachine { @Override public void enter() { super.enter(); mAdapterService.getPackageManager().setComponentEnabledSetting( BLUETOOTH_INCALLSERVICE_COMPONENT, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); mAdapterService.enableBluetoothInCallService(true); } @Override public void exit() { mAdapterService.getPackageManager().setComponentEnabledSetting( BLUETOOTH_INCALLSERVICE_COMPONENT, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); BluetoothInCallService bluetoothInCallService = BluetoothInCallService.getInstance(); if (bluetoothInCallService == null) { mAdapterService.enableBluetoothInCallService(false); } super.exit(); } Loading Loading @@ -393,6 +384,7 @@ final class AdapterState extends StateMachine { @Override public void enter() { super.enter(); mAdapterService.enableBluetoothInCallService(false); sendMessageDelayed(BLE_STOP_TIMEOUT, BLE_STOP_TIMEOUT_DELAY); mAdapterService.bringDownBle(); } Loading src/com/android/bluetooth/telephony/BluetoothInCallService.java +10 −1 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.hfp.BluetoothHeadsetProxy; import com.android.bluetooth.hfp.HeadsetService; Loading Loading @@ -117,7 +118,7 @@ public class BluetoothInCallService extends InCallService { // A map from Calls to indexes used to identify calls for CLCC (C* List Current Calls). private final Map<BluetoothCall, Integer> mClccIndexMap = new HashMap<>(); private static BluetoothInCallService sInstance; private static BluetoothInCallService sInstance = null; public CallInfo mCallInfo = new CallInfo(); Loading Loading @@ -314,6 +315,13 @@ public class BluetoothInCallService extends InCallService { @Override public boolean onUnbind(Intent intent) { Log.i(TAG, "onUnbind. Intent: " + intent); BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { Log.i(TAG, "Bluetooth is off when unbind, disable BluetoothInCallService"); AdapterService adapterService = AdapterService.getAdapterService(); adapterService.enableBluetoothInCallService(false); } return super.onUnbind(intent); } Loading Loading @@ -563,6 +571,7 @@ public class BluetoothInCallService extends InCallService { unregisterReceiver(mBluetoothAdapterReceiver); mBluetoothAdapterReceiver = null; } sInstance = null; super.onDestroy(); } Loading Loading
src/com/android/bluetooth/btservice/AdapterService.java +19 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ import android.companion.CompanionDeviceManager; import android.content.Attributable; import android.content.AttributionSource; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; Loading Loading @@ -191,6 +192,10 @@ public class AdapterService extends Service { private static final int CONTROLLER_ENERGY_UPDATE_TIMEOUT_MILLIS = 30; private static final ComponentName BLUETOOTH_INCALLSERVICE_COMPONENT = new ComponentName("com.android.bluetooth", BluetoothInCallService.class.getCanonicalName()); // Report ID definition public enum BqrQualityReportId { QUALITY_REPORT_ID_MONITOR_MODE(0x01), Loading Loading @@ -809,6 +814,20 @@ public class AdapterService extends Service { } } /** * Enable/disable BluetoothInCallService * * @param enable to enable/disable BluetoothInCallService. */ public void enableBluetoothInCallService(boolean enable) { debugLog("enableBluetoothInCallService() - Enable = " + enable); getPackageManager().setComponentEnabledSetting( BLUETOOTH_INCALLSERVICE_COMPONENT, enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } void cleanup() { debugLog("cleanup()"); if (mCleaningUp) { Loading
src/com/android/bluetooth/btservice/AdapterState.java +6 −14 Original line number Diff line number Diff line Loading @@ -17,8 +17,6 @@ package com.android.bluetooth.btservice; import android.bluetooth.BluetoothAdapter; import android.content.ComponentName; import android.content.pm.PackageManager; import android.os.Message; import android.util.Log; Loading Loading @@ -79,10 +77,6 @@ final class AdapterState extends StateMachine { static final int BREDR_START_TIMEOUT_DELAY = 4000; static final int BREDR_STOP_TIMEOUT_DELAY = 4000; static final ComponentName BLUETOOTH_INCALLSERVICE_COMPONENT = new ComponentName(R.class.getPackage().getName(), BluetoothInCallService.class.getCanonicalName()); private AdapterService mAdapterService; private TurningOnState mTurningOnState = new TurningOnState(); private TurningBleOnState mTurningBleOnState = new TurningBleOnState(); Loading Loading @@ -233,18 +227,15 @@ final class AdapterState extends StateMachine { @Override public void enter() { super.enter(); mAdapterService.getPackageManager().setComponentEnabledSetting( BLUETOOTH_INCALLSERVICE_COMPONENT, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); mAdapterService.enableBluetoothInCallService(true); } @Override public void exit() { mAdapterService.getPackageManager().setComponentEnabledSetting( BLUETOOTH_INCALLSERVICE_COMPONENT, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); BluetoothInCallService bluetoothInCallService = BluetoothInCallService.getInstance(); if (bluetoothInCallService == null) { mAdapterService.enableBluetoothInCallService(false); } super.exit(); } Loading Loading @@ -393,6 +384,7 @@ final class AdapterState extends StateMachine { @Override public void enter() { super.enter(); mAdapterService.enableBluetoothInCallService(false); sendMessageDelayed(BLE_STOP_TIMEOUT, BLE_STOP_TIMEOUT_DELAY); mAdapterService.bringDownBle(); } Loading
src/com/android/bluetooth/telephony/BluetoothInCallService.java +10 −1 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.hfp.BluetoothHeadsetProxy; import com.android.bluetooth.hfp.HeadsetService; Loading Loading @@ -117,7 +118,7 @@ public class BluetoothInCallService extends InCallService { // A map from Calls to indexes used to identify calls for CLCC (C* List Current Calls). private final Map<BluetoothCall, Integer> mClccIndexMap = new HashMap<>(); private static BluetoothInCallService sInstance; private static BluetoothInCallService sInstance = null; public CallInfo mCallInfo = new CallInfo(); Loading Loading @@ -314,6 +315,13 @@ public class BluetoothInCallService extends InCallService { @Override public boolean onUnbind(Intent intent) { Log.i(TAG, "onUnbind. Intent: " + intent); BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { Log.i(TAG, "Bluetooth is off when unbind, disable BluetoothInCallService"); AdapterService adapterService = AdapterService.getAdapterService(); adapterService.enableBluetoothInCallService(false); } return super.onUnbind(intent); } Loading Loading @@ -563,6 +571,7 @@ public class BluetoothInCallService extends InCallService { unregisterReceiver(mBluetoothAdapterReceiver); mBluetoothAdapterReceiver = null; } sInstance = null; super.onDestroy(); } Loading