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

Commit aea67d4b authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "BluetoothInCallService enabled state setting modification" am: afff12f0

Original change: https://android-review.googlesource.com/c/platform/packages/apps/Bluetooth/+/1821315

Change-Id: If2370ce34b05dd5e8ded0afaba3bf09b2bbcba92
parents c38c8ab4 afff12f0
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -62,6 +62,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;
@@ -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),
@@ -747,6 +752,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
@@ -46,6 +46,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;
@@ -116,7 +117,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();

@@ -313,6 +314,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);
    }

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