Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 21f66edd authored by Ted Wang's avatar Ted Wang
Browse files

BluetoothInCallService enabled state setting modification

This patch is to modify component enabled setting flow of
BluetoothInCallService. Instead of disabling BluetoothInCallService when
exiting ON state of Bluetooth adapter, disabling
BluetoothInCallService in its onDestroy callback to avoid component been
disabled without unbind.

Tag: #stability
Bug: 195882442
Test: HFP regression test; atest BluetoothInstrumentationTests
Change-Id: Id4719d5144dce15b77fab4293749ee9699e42830
parent 2925ef43
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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),
@@ -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) {
+6 −14
Original line number Diff line number Diff line
@@ -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;

@@ -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();
@@ -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();
        }

@@ -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();
        }
+10 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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();

@@ -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);
    }

@@ -556,6 +564,7 @@ public class BluetoothInCallService extends InCallService {
            unregisterReceiver(mBluetoothAdapterReceiver);
            mBluetoothAdapterReceiver = null;
        }
        sInstance = null;
        super.onDestroy();
    }