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

Commit d81332fe authored by Sanket Agarwal's avatar Sanket Agarwal Committed by android-build-merger
Browse files

Merge "Separate Phone Policy from mechanism" am: 10615e73 am: d86d1561 am: 9b40c9b0

am: ada867d8

Change-Id: I24979d2312918559081634904def891f4215b5ae
parents eaaed131 ada867d8
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -170,7 +170,7 @@ public class A2dpService extends ProfileService {
        return mStateMachine.getDevicesMatchingConnectionStates(states);
        return mStateMachine.getDevicesMatchingConnectionStates(states);
    }
    }


    int getConnectionState(BluetoothDevice device) {
    public int getConnectionState(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        return mStateMachine.getConnectionState(device);
        return mStateMachine.getConnectionState(device);
    }
    }
+0 −13
Original line number Original line Diff line number Diff line
@@ -235,12 +235,6 @@ final class A2dpStateMachine extends StateMachine {
                    //reject the connection and stay in Disconnected state itself
                    //reject the connection and stay in Disconnected state itself
                    logi("Incoming A2DP rejected");
                    logi("Incoming A2DP rejected");
                    disconnectA2dpNative(getByteAddress(device));
                    disconnectA2dpNative(getByteAddress(device));
                    // the other profile connection should be initiated
                    AdapterService adapterService = AdapterService.getAdapterService();
                    if (adapterService != null) {
                        adapterService.connectOtherProfile(device,
                                                           AdapterService.PROFILE_CONN_REJECTED);
                    }
                }
                }
                break;
                break;
            case CONNECTION_STATE_CONNECTED:
            case CONNECTION_STATE_CONNECTED:
@@ -257,12 +251,6 @@ final class A2dpStateMachine extends StateMachine {
                    //reject the connection and stay in Disconnected state itself
                    //reject the connection and stay in Disconnected state itself
                    logi("Incoming A2DP rejected");
                    logi("Incoming A2DP rejected");
                    disconnectA2dpNative(getByteAddress(device));
                    disconnectA2dpNative(getByteAddress(device));
                    // the other profile connection should be initiated
                    AdapterService adapterService = AdapterService.getAdapterService();
                    if (adapterService != null) {
                        adapterService.connectOtherProfile(device,
                                                           AdapterService.PROFILE_CONN_REJECTED);
                    }
                }
                }
                break;
                break;
            case CONNECTION_STATE_DISCONNECTING:
            case CONNECTION_STATE_DISCONNECTING:
@@ -820,7 +808,6 @@ final class A2dpStateMachine extends StateMachine {
            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
            mContext.sendBroadcast(intent, ProfileService.BLUETOOTH_PERM);
            mContext.sendBroadcast(intent, ProfileService.BLUETOOTH_PERM);
            log("Connection state " + device + ": " + prevState + "->" + state);
            log("Connection state " + device + ": " + prevState + "->" + state);
            mService.notifyProfileConnectionStateChanged(device, BluetoothProfile.A2DP, state, prevState);
        }
        }


        @Override
        @Override
+0 −14
Original line number Original line Diff line number Diff line
@@ -266,12 +266,6 @@ final class A2dpSinkStateMachine extends StateMachine {
                    //reject the connection and stay in Disconnected state itself
                    //reject the connection and stay in Disconnected state itself
                    logi("Incoming A2DP rejected");
                    logi("Incoming A2DP rejected");
                    disconnectA2dpNative(getByteAddress(device));
                    disconnectA2dpNative(getByteAddress(device));
                    // the other profile connection should be initiated
                    AdapterService adapterService = AdapterService.getAdapterService();
                    if (adapterService != null) {
                        adapterService.connectOtherProfile(device,
                                                           AdapterService.PROFILE_CONN_REJECTED);
                    }
                }
                }
                break;
                break;
            case CONNECTION_STATE_CONNECTED:
            case CONNECTION_STATE_CONNECTED:
@@ -288,12 +282,6 @@ final class A2dpSinkStateMachine extends StateMachine {
                    //reject the connection and stay in Disconnected state itself
                    //reject the connection and stay in Disconnected state itself
                    logi("Incoming A2DP rejected");
                    logi("Incoming A2DP rejected");
                    disconnectA2dpNative(getByteAddress(device));
                    disconnectA2dpNative(getByteAddress(device));
                    // the other profile connection should be initiated
                    AdapterService adapterService = AdapterService.getAdapterService();
                    if (adapterService != null) {
                        adapterService.connectOtherProfile(device,
                                                           AdapterService.PROFILE_CONN_REJECTED);
                    }
                }
                }
                break;
                break;
            case CONNECTION_STATE_DISCONNECTING:
            case CONNECTION_STATE_DISCONNECTING:
@@ -840,8 +828,6 @@ final class A2dpSinkStateMachine extends StateMachine {
//FIXME            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
//FIXME            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
            mContext.sendBroadcast(intent, ProfileService.BLUETOOTH_PERM);
            mContext.sendBroadcast(intent, ProfileService.BLUETOOTH_PERM);
            log("Connection state " + device + ": " + prevState + "->" + state);
            log("Connection state " + device + ": " + prevState + "->" + state);
            mService.notifyProfileConnectionStateChanged(device, BluetoothProfile.A2DP_SINK,
                    state, prevState);
        }
        }


        @Override
        @Override
+40 −0
Original line number Original line Diff line number Diff line
@@ -16,10 +16,17 @@


package com.android.bluetooth.btservice;
package com.android.bluetooth.btservice;


import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothA2dpSink;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.ParcelUuid;
import android.os.ParcelUuid;
import android.os.UserHandle;
import android.os.UserHandle;
import android.util.Log;
import android.util.Log;
@@ -68,6 +75,24 @@ class AdapterProperties {
    private boolean mIsDebugLogSupported;
    private boolean mIsDebugLogSupported;
    private boolean mIsActivityAndEnergyReporting;
    private boolean mIsActivityAndEnergyReporting;


    private BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(TAG, "Received intent " + intent);
            if (BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction())) {
                sendConnectionStateChange(BluetoothProfile.HEADSET, intent);
            } else if (BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction())) {
                sendConnectionStateChange(BluetoothProfile.A2DP, intent);
            } else if (BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED.equals(
                               intent.getAction())) {
                sendConnectionStateChange(BluetoothProfile.HEADSET_CLIENT, intent);
            } else if (BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED.equals(
                               intent.getAction())) {
                sendConnectionStateChange(BluetoothProfile.A2DP_SINK, intent);
            }
        }
    };

    // Lock for all getters and setters.
    // Lock for all getters and setters.
    // If finer grained locking is needer, more locks
    // If finer grained locking is needer, more locks
    // can be added here.
    // can be added here.
@@ -84,6 +109,14 @@ class AdapterProperties {
            mProfileConnectionState.clear();
            mProfileConnectionState.clear();
        }
        }
        mRemoteDevices = remoteDevices;
        mRemoteDevices = remoteDevices;

        IntentFilter filter = new IntentFilter();
        filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothDevice.ACTION_UUID);
        mService.registerReceiver(mReceiver, filter);
    }
    }


    public void cleanup() {
    public void cleanup() {
@@ -92,6 +125,7 @@ class AdapterProperties {
            mProfileConnectionState.clear();
            mProfileConnectionState.clear();
            mProfileConnectionState = null;
            mProfileConnectionState = null;
        }
        }
        mService.unregisterReceiver(mReceiver);
        mService = null;
        mService = null;
        mBondedDevices.clear();
        mBondedDevices.clear();
    }
    }
@@ -319,6 +353,12 @@ class AdapterProperties {
        return mDiscovering;
        return mDiscovering;
    }
    }


    private void sendConnectionStateChange(int profile, Intent connIntent) {
        BluetoothDevice device = connIntent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        int prevState = connIntent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, -1);
        int state = connIntent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1);
        sendConnectionStateChange(device, profile, state, prevState);
    }
    void sendConnectionStateChange(BluetoothDevice device, int profile, int state, int prevState) {
    void sendConnectionStateChange(BluetoothDevice device, int profile, int state, int prevState) {
        if (!validateProfileConnectionState(state) ||
        if (!validateProfileConnectionState(state) ||
                !validateProfileConnectionState(prevState)) {
                !validateProfileConnectionState(prevState)) {
+92 −549

File changed.

Preview size limit exceeded, changes collapsed.

Loading