Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +19 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import android.bluetooth.IBluetoothSocketManager; import android.bluetooth.OobData; import android.bluetooth.UidTraffic; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; Loading Loading @@ -176,6 +177,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 @@ -717,6 +722,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 android/app/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 android/app/src/com/android/bluetooth/telephony/BluetoothInCallService.java +10 −1 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ import android.util.Log; import androidx.annotation.VisibleForTesting; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.hfp.BluetoothHeadsetProxy; import java.util.ArrayList; Loading Loading @@ -115,7 +116,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 @@ -312,6 +313,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 @@ -556,6 +564,7 @@ public class BluetoothInCallService extends InCallService { unregisterReceiver(mBluetoothAdapterReceiver); mBluetoothAdapterReceiver = null; } sInstance = null; super.onDestroy(); } Loading Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +19 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import android.bluetooth.IBluetoothSocketManager; import android.bluetooth.OobData; import android.bluetooth.UidTraffic; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; Loading Loading @@ -176,6 +177,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 @@ -717,6 +722,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
android/app/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
android/app/src/com/android/bluetooth/telephony/BluetoothInCallService.java +10 −1 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ import android.util.Log; import androidx.annotation.VisibleForTesting; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.hfp.BluetoothHeadsetProxy; import java.util.ArrayList; Loading Loading @@ -115,7 +116,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 @@ -312,6 +313,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 @@ -556,6 +564,7 @@ public class BluetoothInCallService extends InCallService { unregisterReceiver(mBluetoothAdapterReceiver); mBluetoothAdapterReceiver = null; } sInstance = null; super.onDestroy(); } Loading