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 Original line Diff line number Diff line
@@ -21,12 +21,14 @@ import static android.Manifest.permission.BLUETOOTH_CONNECT;
import android.annotation.RequiresPermission;
import android.annotation.RequiresPermission;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.app.Activity;
import android.app.Activity;
import android.app.ActivityThread;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProtoEnums;
import android.bluetooth.BluetoothProtoEnums;
import android.bluetooth.OobData;
import android.bluetooth.OobData;
import android.content.Attributable;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.Intent;
import android.os.Build;
import android.os.Build;
@@ -135,6 +137,8 @@ final class BondStateMachine extends StateMachine {
        public synchronized boolean processMessage(Message msg) {
        public synchronized boolean processMessage(Message msg) {


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


            switch (msg.what) {
            switch (msg.what) {


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


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

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


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


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


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


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