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

Commit 5bbd4b4f authored by Jeff Brown's avatar Jeff Brown
Browse files

Get alias for Bluetooth devices.

Bluetooth devices can be renamed by the user.  Make the
input system aware of the user-specified name and transparently
pass it down to applications.  This enables the keyboard
layout picker Settings UI to use device names that are
consistent with what the user set in the Bluetooth UI.

Bug: 6363157
Change-Id: I8eea26ce2c69c2a3f09c8de02e9e847610e0419c
parent 9e6d4b03
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -159,6 +159,18 @@ public final class BluetoothDevice implements Parcelable {
    public static final String ACTION_NAME_CHANGED =
            "android.bluetooth.device.action.NAME_CHANGED";

    /**
     * Broadcast Action: Indicates the alias of a remote device has been
     * changed.
     * <p>Always contains the extra field {@link #EXTRA_DEVICE}.
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
     *
     * @hide
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_ALIAS_CHANGED =
            "android.bluetooth.device.action.ALIAS_CHANGED";

    /**
     * Broadcast Action: Indicates a change in the bond state of a remote
     * device. For example, if a device is bonded (paired).
+4 −0
Original line number Diff line number Diff line
@@ -405,6 +405,10 @@ class BluetoothEventLoop {
            mContext.sendBroadcast(intent, BLUETOOTH_PERM);
        } else if (name.equals("Alias")) {
            mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]);
            Intent intent = new Intent(BluetoothDevice.ACTION_ALIAS_CHANGED);
            intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
            mContext.sendBroadcast(intent, BLUETOOTH_PERM);
        } else if (name.equals("Class")) {
            mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]);
            Intent intent = new Intent(BluetoothDevice.ACTION_CLASS_CHANGED);
+2 −2
Original line number Diff line number Diff line
@@ -35,13 +35,13 @@ static struct {
} gInputDeviceClassInfo;

jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& deviceInfo) {
    ScopedLocalRef<jstring> nameObj(env, env->NewStringUTF(deviceInfo.getName().string()));
    ScopedLocalRef<jstring> nameObj(env, env->NewStringUTF(deviceInfo.getDisplayName().string()));
    if (!nameObj.get()) {
        return NULL;
    }

    ScopedLocalRef<jstring> descriptorObj(env,
            env->NewStringUTF(deviceInfo.getDescriptor().string()));
            env->NewStringUTF(deviceInfo.getIdentifier().descriptor.string()));
    if (!descriptorObj.get()) {
        return NULL;
    }
+9 −6
Original line number Diff line number Diff line
@@ -66,13 +66,16 @@ public:
        float fuzz;
    };

    void initialize(int32_t id, int32_t generation,
            const String8& name, const String8& descriptor);
    void initialize(int32_t id, int32_t generation, const InputDeviceIdentifier& identifier,
            const String8& alias);

    inline int32_t getId() const { return mId; }
    inline int32_t getGeneration() const { return mGeneration; }
    inline const String8 getName() const { return mName; }
    inline const String8 getDescriptor() const { return mDescriptor; }
    inline const InputDeviceIdentifier& getIdentifier() const { return mIdentifier; }
    inline const String8& getAlias() const { return mAlias; }
    inline const String8& getDisplayName() const {
        return mAlias.isEmpty() ? mIdentifier.name : mAlias;
    }
    inline uint32_t getSources() const { return mSources; }

    const MotionRange* getMotionRange(int32_t axis, uint32_t source) const;
@@ -103,8 +106,8 @@ public:
private:
    int32_t mId;
    int32_t mGeneration;
    String8 mName;
    String8 mDescriptor;
    InputDeviceIdentifier mIdentifier;
    String8 mAlias;
    uint32_t mSources;
    int32_t mKeyboardType;
    sp<KeyCharacterMap> mKeyCharacterMap;
+5 −6
Original line number Diff line number Diff line
@@ -127,12 +127,11 @@ String8 getInputDeviceConfigurationFilePathByName(
// --- InputDeviceInfo ---

InputDeviceInfo::InputDeviceInfo() {
    initialize(-1, -1, String8("uninitialized device info"), String8("unknown"));
    initialize(-1, -1, InputDeviceIdentifier(), String8());
}

InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) :
        mId(other.mId), mGeneration(other.mGeneration),
        mName(other.mName), mDescriptor(other.mDescriptor),
        mId(other.mId), mGeneration(other.mGeneration), mIdentifier(other.mIdentifier),
        mSources(other.mSources),
        mKeyboardType(other.mKeyboardType),
        mKeyCharacterMap(other.mKeyCharacterMap),
@@ -144,11 +143,11 @@ InputDeviceInfo::~InputDeviceInfo() {
}

void InputDeviceInfo::initialize(int32_t id, int32_t generation,
        const String8& name, const String8& descriptor) {
        const InputDeviceIdentifier& identifier, const String8& alias) {
    mId = id;
    mGeneration = generation;
    mName = name;
    mDescriptor = descriptor;
    mIdentifier = identifier;
    mAlias = alias;
    mSources = 0;
    mKeyboardType = AINPUT_KEYBOARD_TYPE_NONE;
    mHasVibrator = false;
Loading