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

Commit 34578717 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Kick Bluetooth stack after user is unlocked." into nyc-dev

parents 0e9e642b aacb89e9
Loading
Loading
Loading
Loading
+33 −12
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
    private static final int MESSAGE_TIMEOUT_BIND = 100;
    private static final int MESSAGE_TIMEOUT_UNBIND = 101;
    private static final int MESSAGE_USER_SWITCHED = 300;
    private static final int MESSAGE_USER_UNLOCKED = 301;
    private static final int MESSAGE_ADD_PROXY_DELAYED = 400;
    private static final int MESSAGE_BIND_PROFILE_SERVICE = 401;
    private static final int MAX_SAVE_RETRIES = 3;
@@ -767,8 +768,16 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
     * Called when switching to a different foreground user.
     */
    public void handleOnSwitchUser(int userHandle) {
        if (DBG) Slog.d(TAG, "Bluetooth user switched");
        mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_USER_SWITCHED, userHandle, 0));
        if (DBG) Slog.d(TAG, "User " + userHandle + " switched");
        mHandler.obtainMessage(MESSAGE_USER_SWITCHED, userHandle, 0).sendToTarget();
    }

    /**
     * Called when user is unlocked.
     */
    public void handleOnUnlockUser(int userHandle) {
        if (DBG) Slog.d(TAG, "User " + userHandle + " unlocked");
        mHandler.obtainMessage(MESSAGE_USER_UNLOCKED, userHandle, 0).sendToTarget();
    }

    /**
@@ -1308,12 +1317,10 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                    break;
                }

                case MESSAGE_USER_SWITCHED:
                {
                    if (DBG) {
                        Slog.d(TAG, "MESSAGE_USER_SWITCHED");
                    }
                case MESSAGE_USER_SWITCHED: {
                    if (DBG) Slog.d(TAG, "MESSAGE_USER_SWITCHED");
                    mHandler.removeMessages(MESSAGE_USER_SWITCHED);

                    /* disable and enable BT when detect a user switch */
                    if (mEnable && mBluetooth != null) {
                        synchronized (mConnection) {
@@ -1381,6 +1388,20 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                    }
                    break;
                }
                case MESSAGE_USER_UNLOCKED: {
                    if (DBG) Slog.d(TAG, "MESSAGE_USER_UNLOCKED");
                    mHandler.removeMessages(MESSAGE_USER_SWITCHED);

                    synchronized (mConnection) {
                        if (mEnable && !mBinding && (mBluetooth == null)) {
                            // We should be connected, but we gave up for some
                            // reason; maybe the Bluetooth service wasn't encryption
                            // aware, so try binding again.
                            if (DBG) Slog.d(TAG, "Enabled but not bound; retrying after unlock");
                            handleEnable(mQuietEnable);
                        }
                    }
                }
            }
        }
    }
+7 −6
Original line number Diff line number Diff line
@@ -18,10 +18,8 @@ package com.android.server;

import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.util.Log;

class BluetoothService extends SystemService {
    private static final String TAG = "BluetoothService";
    private BluetoothManagerService mBluetoothManagerService;

    public BluetoothService(Context context) {
@@ -36,17 +34,20 @@ class BluetoothService extends SystemService {
    @Override
    public void onBootPhase(int phase) {
        if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
            Log.d(TAG, "onBootPhase: PHASE_SYSTEM_SERVICES_READY");
            publishBinderService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, mBluetoothManagerService);
            publishBinderService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE,
                    mBluetoothManagerService);
        } else if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) {
            Log.d(TAG, "onBootPhase: PHASE_ACTIVITY_MANAGER_READY");
            mBluetoothManagerService.handleOnBootPhase();
        }
    }

    @Override
    public void onSwitchUser(int userHandle) {
        Log.d(TAG, "onSwitchUser: switching to user " + userHandle);
        mBluetoothManagerService.handleOnSwitchUser(userHandle);
    }

    @Override
    public void onUnlockUser(int userHandle) {
        mBluetoothManagerService.handleOnUnlockUser(userHandle);
    }
}