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

Commit 50dd6eb2 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 4413317 from 14a5c1c9 to pi-release

Change-Id: I92fe1cc6c426da4f8a0523d224b23a4e917a6caa
parents fc4b5b82 14a5c1c9
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -329,7 +329,7 @@
            android:name = ".hid.HidService"
            android:enabled="@bool/profile_supported_hid">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothInputDevice" />
                <action android:name="android.bluetooth.IBluetoothHidHost" />
            </intent-filter>
        </service>
        <service
@@ -391,7 +391,7 @@
            android:name = ".hid.HidDevService"
            android:enabled="@bool/profile_supported_hidd">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothInputHost" />
                <action android:name="android.bluetooth.IBluetoothHidDevice" />
            </intent-filter>
        </service>
    </application>
+43 −17
Original line number Diff line number Diff line
@@ -20,11 +20,12 @@ import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothA2dpSink;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothAvrcpController;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothInputDevice;
import android.bluetooth.BluetoothInputHost;
import android.bluetooth.BluetoothHidDevice;
import android.bluetooth.BluetoothHidHost;
import android.bluetooth.BluetoothMap;
import android.bluetooth.BluetoothMapClient;
import android.bluetooth.BluetoothPan;
@@ -57,7 +58,7 @@ class AdapterProperties {

    private volatile String mName;
    private volatile byte[] mAddress;
    private volatile int mBluetoothClass;
    private volatile BluetoothClass mBluetoothClass;
    private volatile int mScanMode;
    private volatile int mDiscoverableTimeout;
    private volatile ParcelUuid[] mUuids;
@@ -115,11 +116,11 @@ class AdapterProperties {
                case BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED:
                    sendConnectionStateChange(BluetoothProfile.A2DP_SINK, intent);
                    break;
                case BluetoothInputHost.ACTION_CONNECTION_STATE_CHANGED:
                    sendConnectionStateChange(BluetoothProfile.INPUT_HOST, intent);
                case BluetoothHidDevice.ACTION_CONNECTION_STATE_CHANGED:
                    sendConnectionStateChange(BluetoothProfile.HID_DEVICE, intent);
                    break;
                case BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED:
                    sendConnectionStateChange(BluetoothProfile.INPUT_DEVICE, intent);
                case BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED:
                    sendConnectionStateChange(BluetoothProfile.HID_HOST, intent);
                    break;
                case BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED:
                    sendConnectionStateChange(BluetoothProfile.AVRCP_CONTROLLER, intent);
@@ -168,8 +169,8 @@ class AdapterProperties {
        filter.addAction(BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothInputHost.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothHidDevice.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothPan.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothMap.ACTION_CONNECTION_STATE_CHANGED);
@@ -217,21 +218,38 @@ class AdapterProperties {
    /**
     * Set the Bluetooth Class of Device (CoD) of the adapter.
     *
     * @param bytes BluetoothClass of the device
     * <p>Bluetooth stack stores some adapter properties in native BT stack storage and some in the
     * Java Android stack. Bluetooth CoD is stored in the Android layer through
     * {@link android.provider.Settings.Global#BLUETOOTH_CLASS_OF_DEVICE}.
     *
     * <p>Due to this, the getAdapterPropertyNative and adapterPropertyChangedCallback methods don't
     * actually update mBluetoothClass. Hence, we update the field mBluetoothClass every time we
     * successfully update BluetoothClass.
     *
     * @param bluetoothClass BluetoothClass of the device
     */
    boolean setBluetoothClass(byte[] bytes) {
    boolean setBluetoothClass(BluetoothClass bluetoothClass) {
        synchronized (mObject) {
            return mService.setAdapterPropertyNative(AbstractionLayer.BT_PROPERTY_CLASS_OF_DEVICE,
                    bytes);
            boolean result =
                    mService.setAdapterPropertyNative(AbstractionLayer.BT_PROPERTY_CLASS_OF_DEVICE,
                            bluetoothClass.getClassOfDeviceBytes());

            if (result) {
                mBluetoothClass = bluetoothClass;
            }

            return result;
        }
    }

    /**
     * @return the mClass
     * @return the BluetoothClass of the Bluetooth adapter.
     */
    int getBluetoothClass() {
    BluetoothClass getBluetoothClass() {
        synchronized (mObject) {
            return mBluetoothClass;
        }
    }

    /**
     * @return the mScanMode
@@ -678,7 +696,15 @@ class AdapterProperties {
                                AdapterService.BLUETOOTH_PERM);
                        break;
                    case AbstractionLayer.BT_PROPERTY_CLASS_OF_DEVICE:
                        mBluetoothClass = Utils.byteArrayToInt(val, 0);
                        if (val == null || val.length != 3) {
                            debugLog("Invalid BT CoD value from stack.");
                            return;
                        }
                        int bluetoothClass =
                                ((int) val[0] << 16) + ((int) val[1] << 8) + (int) val[2];
                        if (bluetoothClass != 0) {
                            mBluetoothClass = new BluetoothClass(bluetoothClass);
                        }
                        debugLog("BT Class:" + mBluetoothClass);
                        break;
                    case AbstractionLayer.BT_PROPERTY_ADAPTER_SCAN_MODE:
+58 −1
Original line number Diff line number Diff line
@@ -406,6 +406,7 @@ public class AdapterService extends Service {
        //Load the name and address
        getAdapterPropertyNative(AbstractionLayer.BT_PROPERTY_BDADDR);
        getAdapterPropertyNative(AbstractionLayer.BT_PROPERTY_BDNAME);
        getAdapterPropertyNative(AbstractionLayer.BT_PROPERTY_CLASS_OF_DEVICE);
        mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
        mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
@@ -511,6 +512,32 @@ public class AdapterService extends Service {
        setGattProfileServiceState(supportedProfileServices, BluetoothAdapter.STATE_ON);
    }

    /**
     * Sets the Bluetooth CoD value of the local adapter if there exists a config value for it.
     */
    void setBluetoothClassFromConfig() {
        int bluetoothClassConfig = retrieveBluetoothClassConfig();
        if (bluetoothClassConfig != 0) {
            mAdapterProperties.setBluetoothClass(new BluetoothClass(bluetoothClassConfig));
        }
    }

    private int retrieveBluetoothClassConfig() {
        return Settings.Global.getInt(
                getContentResolver(), Settings.Global.BLUETOOTH_CLASS_OF_DEVICE, 0);
    }

    private boolean storeBluetoothClassConfig(int bluetoothClass) {
        boolean result = Settings.Global.putInt(
                getContentResolver(), Settings.Global.BLUETOOTH_CLASS_OF_DEVICE, bluetoothClass);

        if (!result) {
            Log.e(TAG, "Error storing BluetoothClass config - " + bluetoothClass);
        }

        return result;
    }

    void startCoreServices() {
        debugLog("startCoreServices()");
        Class[] supportedProfileServices = Config.getSupportedProfiles();
@@ -901,6 +928,17 @@ public class AdapterService extends Service {
            return service.setName(name);
        }

        public BluetoothClass getBluetoothClass() {
            if (!Utils.checkCaller()) {
                Log.w(TAG, "getBluetoothClass() - Not allowed for non-active user");
                return null;
            }

            AdapterService service = getService();
            if (service == null) return null;
            return service.getBluetoothClass();
        }

        public boolean setBluetoothClass(BluetoothClass bluetoothClass) {
            if (!Utils.checkCaller()) {
                Log.w(TAG, "setBluetoothClass() - Not allowed for non-active user");
@@ -1687,11 +1725,30 @@ public class AdapterService extends Service {
        return mAdapterProperties.setName(name);
    }

    BluetoothClass getBluetoothClass() {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission");

        return mAdapterProperties.getBluetoothClass();
    }

    /**
     * Sets the Bluetooth CoD on the local adapter and also modifies the storage config for it.
     *
     * <p>Once set, this value persists across reboots.
     */
    boolean setBluetoothClass(BluetoothClass bluetoothClass) {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH PRIVILEGED permission");

        return mAdapterProperties.setBluetoothClass(bluetoothClass.getClassOfDeviceBytes());
        boolean result = mAdapterProperties.setBluetoothClass(bluetoothClass);

        if (!result) {
            Log.e(TAG,
                    "Failed to set BluetoothClass (" + bluetoothClass
                            + ") on local Bluetooth adapter.");
        }

        return result && storeBluetoothClassConfig(bluetoothClass.getClassOfDevice());
    }

    int getScanMode() {
+1 −0
Original line number Diff line number Diff line
@@ -230,6 +230,7 @@ final class AdapterState extends StateMachine {
                return;
            }
            adapterService.updateUuids();
            adapterService.setBluetoothClassFromConfig();
        }

        @Override
+2 −2
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@ public class Config {
        } else if (profile == A2dpSinkService.class) {
            profileIndex = BluetoothProfile.A2DP_SINK;
        } else if (profile == HidService.class) {
            profileIndex = BluetoothProfile.INPUT_DEVICE;
            profileIndex = BluetoothProfile.HID_HOST;
        } else if (profile == HealthService.class) {
            profileIndex = BluetoothProfile.HEALTH;
        } else if (profile == PanService.class) {
@@ -176,7 +176,7 @@ public class Config {
        } else if (profile == MapClientService.class) {
            profileIndex = BluetoothProfile.MAP_CLIENT;
        } else if (profile == HidDevService.class) {
            profileIndex = BluetoothProfile.INPUT_HOST;
            profileIndex = BluetoothProfile.HID_DEVICE;
        }

        return profileIndex;
Loading