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

Commit 2a9131f7 authored by jovanak's avatar jovanak
Browse files

Makes bluetooth profile services bind to current (foreground) user.

If profile services are created from a singleton process
(like SystemUI), they need to be re-bind to a new foreground user
when we switch to a secondary user.
This is achieved by binding to UserHandle.CURRENT_OR_SELF.

If the process doesn't have adequate permissions to bind to current,
it will bind to self (which is the same as the previous behavior).

Change-Id: Ib1134a1a62887d6f5b2c97301dccd3223ade9ed2
Fixes: 117517812
Test: ran the existing core bluetooth tests; manual testing on a mojave, verifying that the service correctly rebinds from sys ui after user switch.
parent 0d541559
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.ServiceConnection;
import android.os.Binder;
import android.os.Binder;
import android.os.IBinder;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;
import android.util.Log;


import java.util.ArrayList;
import java.util.ArrayList;
@@ -183,7 +184,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
        ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
        ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
        intent.setComponent(comp);
        intent.setComponent(comp);
        if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
        if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
                mContext.getUser())) {
                UserHandle.CURRENT_OR_SELF)) {
            Log.e(TAG, "Could not bind to Bluetooth A2DP Service with " + intent);
            Log.e(TAG, "Could not bind to Bluetooth A2DP Service with " + intent);
            return false;
            return false;
        }
        }
+2 −1
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.ServiceConnection;
import android.os.Binder;
import android.os.Binder;
import android.os.IBinder;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;
import android.util.Log;


import java.util.ArrayList;
import java.util.ArrayList;
@@ -138,7 +139,7 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
        ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
        ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
        intent.setComponent(comp);
        intent.setComponent(comp);
        if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
        if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
                mContext.getUser())) {
                UserHandle.CURRENT_OR_SELF)) {
            Log.e(TAG, "Could not bind to Bluetooth AVRCP Controller Service with " + intent);
            Log.e(TAG, "Could not bind to Bluetooth AVRCP Controller Service with " + intent);
            return false;
            return false;
        }
        }
+2 −1
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@ import android.os.Binder;
import android.os.Bundle;
import android.os.Bundle;
import android.os.IBinder;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;
import android.util.Log;


import java.util.ArrayList;
import java.util.ArrayList;
@@ -428,7 +429,7 @@ public final class BluetoothHeadsetClient implements BluetoothProfile {
        ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
        ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
        intent.setComponent(comp);
        intent.setComponent(comp);
        if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
        if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
                mContext.getUser())) {
                UserHandle.CURRENT_OR_SELF)) {
            Log.e(TAG, "Could not bind to Bluetooth Headset Client Service with " + intent);
            Log.e(TAG, "Could not bind to Bluetooth Headset Client Service with " + intent);
            return false;
            return false;
        }
        }
+2 −1
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ import android.os.Binder;
import android.os.IBinder;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;
import android.util.Log;


import java.util.ArrayList;
import java.util.ArrayList;
@@ -491,7 +492,7 @@ public final class BluetoothHealth implements BluetoothProfile {
        ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
        ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
        intent.setComponent(comp);
        intent.setComponent(comp);
        if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
        if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
                mContext.getUser())) {
                UserHandle.CURRENT_OR_SELF)) {
            Log.e(TAG, "Could not bind to Bluetooth Health Service with " + intent);
            Log.e(TAG, "Could not bind to Bluetooth Health Service with " + intent);
            return false;
            return false;
        }
        }
+2 −1
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import android.content.ServiceConnection;
import android.os.Binder;
import android.os.Binder;
import android.os.IBinder;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;
import android.util.Log;


import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;
@@ -205,7 +206,7 @@ public final class BluetoothHearingAid implements BluetoothProfile {
        ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
        ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
        intent.setComponent(comp);
        intent.setComponent(comp);
        if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
        if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
                android.os.Process.myUserHandle())) {
                UserHandle.CURRENT_OR_SELF)) {
            Log.e(TAG, "Could not bind to Bluetooth Hearing Aid Service with " + intent);
            Log.e(TAG, "Could not bind to Bluetooth Hearing Aid Service with " + intent);
            return;
            return;
        }
        }
Loading