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

Commit 7d46698a authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Force AttributionSource after handler dispatch.

The Bluetooth stack often receives BluetoothDevice instances from
remote Binder calls, and previous work forced the AttributionSource
to match that remote caller.

However, in some instances these objects are passed to an internal
handler or state machine, and we need to switch back to our internal
AttributionSource, since any method calls will be performed as the
Bluetooth stack.

Longer term we should find a better way of transporting these
values in AIDL directly, but this is the safest mechanical change
to make at this late stage of the release.

Bug: 193194829, 188391719
Test: atest BluetoothInstrumentationTests
Change-Id: I19649edb72aabeb92d4987739a1c4cd7fa07bb21
parent 9bf2882a
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -21,12 +21,14 @@ import static android.Manifest.permission.BLUETOOTH_CONNECT;
import android.annotation.RequiresPermission;
import android.annotation.Nullable;
import android.app.Activity;
import android.app.ActivityThread;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProtoEnums;
import android.bluetooth.OobData;
import android.content.Attributable;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.os.Build;
@@ -135,6 +137,8 @@ final class BondStateMachine extends StateMachine {
        public synchronized boolean processMessage(Message msg) {

            BluetoothDevice dev = (BluetoothDevice) msg.obj;
            Attributable.setAttributionSource(dev,
                    ActivityThread.currentAttributionSource());

            switch (msg.what) {

@@ -183,12 +187,14 @@ final class BondStateMachine extends StateMachine {
        @Override
        public void enter() {
            infoLog("Entering PendingCommandState State");
            BluetoothDevice dev = (BluetoothDevice) getCurrentMessage().obj;
        }

        @Override
        public synchronized boolean processMessage(Message msg) {
            BluetoothDevice dev = (BluetoothDevice) msg.obj;
            Attributable.setAttributionSource(dev,
                    ActivityThread.currentAttributionSource());

            DeviceProperties devProp = mRemoteDevices.getDeviceProperties(dev);
            boolean result = false;
            if (mDevices.contains(dev) && msg.what != CANCEL_BOND
+4 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.bluetooth.btservice;

import android.annotation.RequiresPermission;
import android.app.ActivityThread;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
@@ -25,6 +26,7 @@ import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUuid;
import android.content.Attributable;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -216,6 +218,8 @@ class PhonePolicy {
                    // Called when we try connect some profiles in processConnectOtherProfiles but
                    // we send a delayed message to try connecting the remaining profiles
                    BluetoothDevice device = (BluetoothDevice) msg.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    processConnectOtherProfiles(device);
                    mConnectOtherProfilesDeviceSet.remove(device);
                    break;
+4 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.bluetooth.btservice;
import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static android.Manifest.permission.BLUETOOTH_SCAN;

import android.app.ActivityThread;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothAssignedNumbers;
import android.bluetooth.BluetoothClass;
@@ -26,6 +27,7 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.IBluetoothConnectionCallback;
import android.content.Attributable;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -86,6 +88,8 @@ final class RemoteDevices {
            switch (msg.what) {
                case MESSAGE_UUID_INTENT:
                    BluetoothDevice device = (BluetoothDevice) msg.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    if (device != null) {
                        DeviceProperties prop = getDeviceProperties(device);
                        sendUuidIntent(device, prop);
+4 −0
Original line number Diff line number Diff line
@@ -19,10 +19,12 @@ package com.android.bluetooth.btservice;
import static android.Manifest.permission.BLUETOOTH_CONNECT;

import android.annotation.RequiresPermission;
import android.app.ActivityThread;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothProfile;
import android.content.Attributable;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -127,6 +129,8 @@ public class SilenceDeviceManager {
            switch (msg.what) {
                case MSG_SILENCE_DEVICE_STATE_CHANGED: {
                    BluetoothDevice device = (BluetoothDevice) msg.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    boolean state = (msg.arg1 == ENABLE_SILENCE);
                    handleSilenceDeviceStateChanged(device, state);
                }
+34 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.bluetooth.hfp;
import static android.Manifest.permission.BLUETOOTH_CONNECT;

import android.annotation.RequiresPermission;
import android.app.ActivityThread;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothAssignedNumbers;
import android.bluetooth.BluetoothDevice;
@@ -26,6 +27,7 @@ import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProtoEnums;
import android.bluetooth.hfp.BluetoothHfpProtoEnums;
import android.content.Attributable;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Looper;
@@ -464,6 +466,8 @@ public class HeadsetStateMachine extends StateMachine {
            switch (message.what) {
                case CONNECT:
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    stateLogD("Connecting to " + device);
                    if (!mDevice.equals(device)) {
                        stateLogE(
@@ -582,6 +586,8 @@ public class HeadsetStateMachine extends StateMachine {
                case CONNECT_TIMEOUT: {
                    // We timed out trying to connect, transition to Disconnected state
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    if (!mDevice.equals(device)) {
                        stateLogE("Unknown device timeout " + device);
                        break;
@@ -740,6 +746,8 @@ public class HeadsetStateMachine extends StateMachine {
                    break;
                case CONNECT_TIMEOUT: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    if (!mDevice.equals(device)) {
                        stateLogE("Unknown device timeout " + device);
                        break;
@@ -825,6 +833,8 @@ public class HeadsetStateMachine extends StateMachine {
                            "Illegal message in generic handler: " + message);
                case VOICE_RECOGNITION_START: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    if (!mDevice.equals(device)) {
                        stateLogW("VOICE_RECOGNITION_START failed " + device
                                + " is not currentDevice");
@@ -838,6 +848,8 @@ public class HeadsetStateMachine extends StateMachine {
                }
                case VOICE_RECOGNITION_STOP: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    if (!mDevice.equals(device)) {
                        stateLogW("VOICE_RECOGNITION_STOP failed " + device
                                + " is not currentDevice");
@@ -865,6 +877,8 @@ public class HeadsetStateMachine extends StateMachine {
                    break;
                case CLCC_RSP_TIMEOUT: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    if (!mDevice.equals(device)) {
                        stateLogW("CLCC_RSP_TIMEOUT failed " + device + " is not currentDevice");
                        break;
@@ -881,6 +895,8 @@ public class HeadsetStateMachine extends StateMachine {
                    break;
                case VOICE_RECOGNITION_RESULT: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    if (!mDevice.equals(device)) {
                        stateLogW("VOICE_RECOGNITION_RESULT failed " + device
                                + " is not currentDevice");
@@ -893,6 +909,8 @@ public class HeadsetStateMachine extends StateMachine {
                }
                case DIALING_OUT_RESULT: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    if (!mDevice.equals(device)) {
                        stateLogW("DIALING_OUT_RESULT failed " + device + " is not currentDevice");
                        break;
@@ -1051,11 +1069,15 @@ public class HeadsetStateMachine extends StateMachine {
            switch (message.what) {
                case CONNECT: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    stateLogW("CONNECT, ignored, device=" + device + ", currentDevice" + mDevice);
                    break;
                }
                case DISCONNECT: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    stateLogD("DISCONNECT from device=" + device);
                    if (!mDevice.equals(device)) {
                        stateLogW("DISCONNECT, device " + device + " not connected");
@@ -1161,6 +1183,8 @@ public class HeadsetStateMachine extends StateMachine {
                    break;
                case CONNECT_TIMEOUT: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    if (!mDevice.equals(device)) {
                        stateLogW("CONNECT_TIMEOUT for unknown device " + device);
                        break;
@@ -1257,11 +1281,15 @@ public class HeadsetStateMachine extends StateMachine {
            switch (message.what) {
                case CONNECT: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    stateLogW("CONNECT, ignored, device=" + device + ", currentDevice" + mDevice);
                    break;
                }
                case DISCONNECT: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    stateLogD("DISCONNECT, device=" + device);
                    if (!mDevice.equals(device)) {
                        stateLogW("DISCONNECT, device " + device + " not connected");
@@ -1279,6 +1307,8 @@ public class HeadsetStateMachine extends StateMachine {
                }
                case CONNECT_AUDIO: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    if (!mDevice.equals(device)) {
                        stateLogW("CONNECT_AUDIO device is not connected " + device);
                        break;
@@ -1288,6 +1318,8 @@ public class HeadsetStateMachine extends StateMachine {
                }
                case DISCONNECT_AUDIO: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    if (!mDevice.equals(device)) {
                        stateLogW("DISCONNECT_AUDIO, failed, device=" + device + ", currentDevice="
                                + mDevice);
@@ -1381,6 +1413,8 @@ public class HeadsetStateMachine extends StateMachine {
                    break;
                case CONNECT_TIMEOUT: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    Attributable.setAttributionSource(device,
                            ActivityThread.currentAttributionSource());
                    if (!mDevice.equals(device)) {
                        stateLogW("CONNECT_TIMEOUT for unknown device " + device);
                        break;
Loading