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

Commit 92fe51aa authored by Zhihai Xu's avatar Zhihai Xu
Browse files

BT connection notification in not updated in status bar for second user

It is due to the system UI is always running as the first user. It can't receive
broadcast intent ACTION_CONNECTION_STATE_CHANGED and ACTION_BOND_STATE_CHANGED
from bluetooth service when We switch to second user. Also the system UI also
is running as uid 10055, which will also call function isEnabled, getState,
getBondedDevices, getAdapterConnectionState and getBondState in bluetooth service.
I allow these functions to be called by all the users.
I forget remove check for getBondState in my first patch set

bug 7333382

Change-Id: I57f39a722e78d6d2453ebfecaab043637fef4d9c
parent 76ad10a1
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.Intent;
import android.os.ParcelUuid;
import android.os.UserHandle;
import android.util.Log;
import android.util.Pair;

@@ -299,7 +300,8 @@ class AdapterProperties {
                intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_CONNECTION_STATE,
                        convertToAdapterState(prevState));
                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
                mService.sendBroadcast(intent, mService.BLUETOOTH_PERM);
                mService.sendBroadcastAsUser(intent, UserHandle.ALL,
                        mService.BLUETOOTH_PERM);
                Log.d(TAG, "CONNECTION_STATE_CHANGE: " + device + ": "
                        + prevState + " -> " + state);
            }
+5 −27
Original line number Diff line number Diff line
@@ -483,24 +483,14 @@ public class AdapterService extends Service {
            return null;
        }
        public boolean isEnabled() {
            if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
                (!Utils.checkCaller())) {
                Log.w(TAG,"isEnabled(): not allowed for non-active user and non system user");
                return false;
	    }

            // don't check caller, may be called from system UI
            AdapterService service = getService();
            if (service == null) return false;
            return service.isEnabled();
        }

        public int getState() {
            if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
                (!Utils.checkCaller())) {
                Log.w(TAG,"getState(): not allowed for non-active user and non system user");
                return BluetoothAdapter.STATE_OFF;
            }

            // don't check caller, may be called from system UI
            AdapterService service = getService();
            if (service == null) return  BluetoothAdapter.STATE_OFF;
            return service.getState();
@@ -665,22 +655,14 @@ public class AdapterService extends Service {
        }

        public BluetoothDevice[] getBondedDevices() {
            if (!Utils.checkCaller()) {
                Log.w(TAG,"getBondedDevices: not allowed for non-active user");
                return new BluetoothDevice[0];
            }

            // don't check caller, may be called from system UI
            AdapterService service = getService();
            if (service == null) return new BluetoothDevice[0];
            return service.getBondedDevices();
        }

        public int getAdapterConnectionState() {
            if (!Utils.checkCaller()) {
                Log.w(TAG,"getAdapterConnectionState: not allowed for non-active user");
                return BluetoothAdapter.STATE_DISCONNECTED;
            }

            // don't check caller, may be called from system UI
            AdapterService service = getService();
            if (service == null) return BluetoothAdapter.STATE_DISCONNECTED;
            return service.getAdapterConnectionState();
@@ -731,11 +713,7 @@ public class AdapterService extends Service {
        }

        public int getBondState(BluetoothDevice device) {
            if (!Utils.checkCaller()) {
                Log.w(TAG,"getBondState(): not allowed for non-active user");
                return BluetoothDevice.BOND_NONE;
            }

            // don't check caller, may be called from system UI
            AdapterService service = getService();
            if (service == null) return BluetoothDevice.BOND_NONE;
            return service.getBondState(device);
+3 −1
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ import com.android.bluetooth.hfp.HeadsetService;
import android.content.Context;
import android.content.Intent;
import android.os.Message;
import android.os.UserHandle;
import android.util.Log;

import com.android.bluetooth.Utils;
@@ -252,7 +253,8 @@ final class BondStateMachine extends StateMachine {
        intent.putExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, oldState);
        if (newState == BluetoothDevice.BOND_NONE)
            intent.putExtra(BluetoothDevice.EXTRA_REASON, reason);
        mAdapterService.sendBroadcast(intent, AdapterService.BLUETOOTH_PERM);
        mAdapterService.sendBroadcastAsUser(intent, UserHandle.ALL,
                AdapterService.BLUETOOTH_PERM);
        infoLog("Bond State Change Intent:" + device + " OldState: " + oldState
                + " NewState: " + newState);
    }