Skip to content

Commit daa3753

Browse files
author
Jeff Brown
committed
Improve handling of built-in keyboard.
The window manager policy made some incorrect assumptions about the meaning of the Configuration.keyboard field. We need to be more careful about distinguishing between built-in and external keyboards. Most of this change is to move the determination of the parts of the Configuration related to input devices into the WindowManagerService leveraging new features of the InputManagerService to good effect. Then we plumb through the flag that indicates whether a device is internal or external so that we can be more particular about how the lid switch effects changes to the Configuration. Bug: 6424373 Change-Id: I36a1c22ade35e578955465a25940a33f227b9763
1 parent 32c8113 commit daa3753

File tree

14 files changed

+117
-260
lines changed

14 files changed

+117
-260
lines changed

core/java/android/view/InputDevice.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public final class InputDevice implements Parcelable {
4646
private final int mGeneration;
4747
private final String mName;
4848
private final String mDescriptor;
49+
private final boolean mIsExternal;
4950
private final int mSources;
5051
private final int mKeyboardType;
5152
private final KeyCharacterMap mKeyCharacterMap;
@@ -322,12 +323,14 @@ public InputDevice[] newArray(int size) {
322323
};
323324

324325
// Called by native code.
325-
private InputDevice(int id, int generation, String name, String descriptor, int sources,
326+
private InputDevice(int id, int generation, String name, String descriptor,
327+
boolean isExternal, int sources,
326328
int keyboardType, KeyCharacterMap keyCharacterMap, boolean hasVibrator) {
327329
mId = id;
328330
mGeneration = generation;
329331
mName = name;
330332
mDescriptor = descriptor;
333+
mIsExternal = isExternal;
331334
mSources = sources;
332335
mKeyboardType = keyboardType;
333336
mKeyCharacterMap = keyCharacterMap;
@@ -339,6 +342,7 @@ private InputDevice(Parcel in) {
339342
mGeneration = in.readInt();
340343
mName = in.readString();
341344
mDescriptor = in.readString();
345+
mIsExternal = in.readInt() != 0;
342346
mSources = in.readInt();
343347
mKeyboardType = in.readInt();
344348
mKeyCharacterMap = KeyCharacterMap.CREATOR.createFromParcel(in);
@@ -414,7 +418,7 @@ public int getGeneration() {
414418
* has a trackpad. Alternately, it may be that the input devices are simply
415419
* indistinguishable, such as two keyboards made by the same manufacturer.
416420
* </p><p>
417-
* The input device descriptor returned by {@link #getDescriptor} should only bt
421+
* The input device descriptor returned by {@link #getDescriptor} should only be
418422
* used when an application needs to remember settings associated with a particular
419423
* input device. For all other purposes when referring to a logical
420424
* {@link InputDevice} instance at runtime use the id returned by {@link #getId()}.
@@ -442,6 +446,18 @@ public boolean isVirtual() {
442446
return mId < 0;
443447
}
444448

449+
/**
450+
* Returns true if the device is external (connected to USB or Bluetooth or some other
451+
* peripheral bus), otherwise it is built-in.
452+
*
453+
* @return True if the device is external.
454+
*
455+
* @hide
456+
*/
457+
public boolean isExternal() {
458+
return mIsExternal;
459+
}
460+
445461
/**
446462
* Gets the name of this input device.
447463
* @return The input device name.
@@ -660,6 +676,7 @@ public void writeToParcel(Parcel out, int flags) {
660676
out.writeInt(mGeneration);
661677
out.writeString(mName);
662678
out.writeString(mDescriptor);
679+
out.writeInt(mIsExternal ? 1 : 0);
663680
out.writeInt(mSources);
664681
out.writeInt(mKeyboardType);
665682
mKeyCharacterMap.writeToParcel(out, flags);
@@ -689,6 +706,7 @@ public String toString() {
689706
description.append("Input Device ").append(mId).append(": ").append(mName).append("\n");
690707
description.append(" Descriptor: ").append(mDescriptor).append("\n");
691708
description.append(" Generation: ").append(mGeneration).append("\n");
709+
description.append(" Location: ").append(mIsExternal ? "external" : "built-in").append("\n");
692710

693711
description.append(" Keyboard Type: ");
694712
switch (mKeyboardType) {

core/java/android/view/WindowManagerPolicy.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ public interface WindowManagerPolicy {
9191
public final static int FLAG_BRIGHT_HERE = 0x20000000;
9292
public final static int FLAG_PASS_TO_USER = 0x40000000;
9393

94+
// Flags used for indicating whether the internal and/or external input devices
95+
// of some type are available.
96+
public final static int PRESENCE_INTERNAL = 1 << 0;
97+
public final static int PRESENCE_EXTERNAL = 1 << 1;
98+
9499
public final static boolean WATCH_POINTER = false;
95100

96101
/**
@@ -500,8 +505,13 @@ public void init(Context context, IWindowManager windowManager,
500505
*
501506
* @param config The Configuration being computed, for you to change as
502507
* desired.
508+
* @param keyboardPresence Flags that indicate whether internal or external
509+
* keyboards are present.
510+
* @param navigationPresence Flags that indicate whether internal or external
511+
* navigation devices are present.
503512
*/
504-
public void adjustConfigurationLw(Configuration config);
513+
public void adjustConfigurationLw(Configuration config, int keyboardPresence,
514+
int navigationPresence);
505515

506516
/**
507517
* Assign a window type to a layer. Allows you to control how different

core/jni/android_view_InputDevice.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi
5555

5656
ScopedLocalRef<jobject> inputDeviceObj(env, env->NewObject(gInputDeviceClassInfo.clazz,
5757
gInputDeviceClassInfo.ctor, deviceInfo.getId(), deviceInfo.getGeneration(),
58-
nameObj.get(), descriptorObj.get(),
58+
nameObj.get(), descriptorObj.get(), deviceInfo.isExternal(),
5959
deviceInfo.getSources(), deviceInfo.getKeyboardType(),
6060
kcmObj.get(), deviceInfo.hasVibrator()));
6161

@@ -87,7 +87,7 @@ int register_android_view_InputDevice(JNIEnv* env)
8787
gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
8888

8989
GET_METHOD_ID(gInputDeviceClassInfo.ctor, gInputDeviceClassInfo.clazz,
90-
"<init>", "(IILjava/lang/String;Ljava/lang/String;IILandroid/view/KeyCharacterMap;Z)V");
90+
"<init>", "(IILjava/lang/String;Ljava/lang/String;ZIILandroid/view/KeyCharacterMap;Z)V");
9191

9292
GET_METHOD_ID(gInputDeviceClassInfo.addMotionRange, gInputDeviceClassInfo.clazz,
9393
"addMotionRange", "(IIFFFF)V");

include/androidfw/Input.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -156,37 +156,6 @@ enum {
156156
POLICY_FLAG_PASS_TO_USER = 0x40000000,
157157
};
158158

159-
/*
160-
* Describes the basic configuration of input devices that are present.
161-
*/
162-
struct InputConfiguration {
163-
enum {
164-
TOUCHSCREEN_UNDEFINED = 0,
165-
TOUCHSCREEN_NOTOUCH = 1,
166-
TOUCHSCREEN_STYLUS = 2,
167-
TOUCHSCREEN_FINGER = 3
168-
};
169-
170-
enum {
171-
KEYBOARD_UNDEFINED = 0,
172-
KEYBOARD_NOKEYS = 1,
173-
KEYBOARD_QWERTY = 2,
174-
KEYBOARD_12KEY = 3
175-
};
176-
177-
enum {
178-
NAVIGATION_UNDEFINED = 0,
179-
NAVIGATION_NONAV = 1,
180-
NAVIGATION_DPAD = 2,
181-
NAVIGATION_TRACKBALL = 3,
182-
NAVIGATION_WHEEL = 4
183-
};
184-
185-
int32_t touchScreen;
186-
int32_t keyboard;
187-
int32_t navigation;
188-
};
189-
190159
/*
191160
* Pointer coordinate data.
192161
*/

include/androidfw/InputDevice.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class InputDeviceInfo {
6767
};
6868

6969
void initialize(int32_t id, int32_t generation, const InputDeviceIdentifier& identifier,
70-
const String8& alias);
70+
const String8& alias, bool isExternal);
7171

7272
inline int32_t getId() const { return mId; }
7373
inline int32_t getGeneration() const { return mGeneration; }
@@ -76,6 +76,7 @@ class InputDeviceInfo {
7676
inline const String8& getDisplayName() const {
7777
return mAlias.isEmpty() ? mIdentifier.name : mAlias;
7878
}
79+
inline bool isExternal() const { return mIsExternal; }
7980
inline uint32_t getSources() const { return mSources; }
8081

8182
const MotionRange* getMotionRange(int32_t axis, uint32_t source) const;
@@ -108,6 +109,7 @@ class InputDeviceInfo {
108109
int32_t mGeneration;
109110
InputDeviceIdentifier mIdentifier;
110111
String8 mAlias;
112+
bool mIsExternal;
111113
uint32_t mSources;
112114
int32_t mKeyboardType;
113115
sp<KeyCharacterMap> mKeyCharacterMap;

libs/androidfw/InputDevice.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ String8 getInputDeviceConfigurationFilePathByName(
127127
// --- InputDeviceInfo ---
128128

129129
InputDeviceInfo::InputDeviceInfo() {
130-
initialize(-1, -1, InputDeviceIdentifier(), String8());
130+
initialize(-1, -1, InputDeviceIdentifier(), String8(), false);
131131
}
132132

133133
InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) :
134134
mId(other.mId), mGeneration(other.mGeneration), mIdentifier(other.mIdentifier),
135-
mAlias(other.mAlias), mSources(other.mSources),
135+
mAlias(other.mAlias), mIsExternal(other.mIsExternal), mSources(other.mSources),
136136
mKeyboardType(other.mKeyboardType),
137137
mKeyCharacterMap(other.mKeyCharacterMap),
138138
mHasVibrator(other.mHasVibrator),
@@ -143,11 +143,12 @@ InputDeviceInfo::~InputDeviceInfo() {
143143
}
144144

145145
void InputDeviceInfo::initialize(int32_t id, int32_t generation,
146-
const InputDeviceIdentifier& identifier, const String8& alias) {
146+
const InputDeviceIdentifier& identifier, const String8& alias, bool isExternal) {
147147
mId = id;
148148
mGeneration = generation;
149149
mIdentifier = identifier;
150150
mAlias = alias;
151+
mIsExternal = isExternal;
151152
mSources = 0;
152153
mKeyboardType = AINPUT_KEYBOARD_TYPE_NONE;
153154
mHasVibrator = false;

policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import android.graphics.PixelFormat;
3939
import android.graphics.Rect;
4040
import android.graphics.RectF;
41+
import android.hardware.input.InputManager;
4142
import android.media.AudioManager;
4243
import android.media.IAudioService;
4344
import android.os.BatteryManager;
@@ -332,6 +333,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
332333
int mRecentAppsDialogHeldModifiers;
333334

334335
int mLidState = LID_ABSENT;
336+
boolean mHaveBuiltInKeyboard;
335337

336338
boolean mSystemReady;
337339
boolean mSystemBooted;
@@ -1259,46 +1261,42 @@ void readLidState() {
12591261
mLidState = mWindowManagerFuncs.getLidState();
12601262
}
12611263

1262-
private int determineHiddenState(int mode, int hiddenValue, int visibleValue) {
1263-
if (mLidState != LID_ABSENT) {
1264-
switch (mode) {
1265-
case 1:
1266-
return mLidState == LID_OPEN ? visibleValue : hiddenValue;
1267-
case 2:
1268-
return mLidState == LID_OPEN ? hiddenValue : visibleValue;
1269-
}
1264+
private boolean isHidden(int accessibilityMode) {
1265+
switch (accessibilityMode) {
1266+
case 1:
1267+
return mLidState == LID_CLOSED;
1268+
case 2:
1269+
return mLidState == LID_OPEN;
1270+
default:
1271+
return false;
12701272
}
1271-
return visibleValue;
12721273
}
12731274

1274-
private boolean isKeyboardVisible() {
1275-
return determineHiddenState(mLidKeyboardAccessibility, 0, 1) == 1
1276-
|| determineHiddenState(mLidNavigationAccessibility, 0, 1) == 1;
1275+
private boolean isBuiltInKeyboardVisible() {
1276+
return mHaveBuiltInKeyboard && !isHidden(mLidKeyboardAccessibility);
12771277
}
12781278

12791279
/** {@inheritDoc} */
1280-
public void adjustConfigurationLw(Configuration config) {
1280+
public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1281+
int navigationPresence) {
1282+
mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1283+
12811284
readLidState();
12821285
applyLidSwitchState();
12831286

1284-
if (config.keyboard == Configuration.KEYBOARD_NOKEYS) {
1287+
if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1288+
|| (keyboardPresence == PRESENCE_INTERNAL
1289+
&& isHidden(mLidKeyboardAccessibility))) {
12851290
config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
1286-
} else {
1287-
config.hardKeyboardHidden = determineHiddenState(mLidKeyboardAccessibility,
1288-
Configuration.HARDKEYBOARDHIDDEN_YES, Configuration.HARDKEYBOARDHIDDEN_NO);
1291+
if (!mHasSoftInput) {
1292+
config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1293+
}
12891294
}
12901295

1291-
if (config.navigation == Configuration.NAVIGATION_NONAV) {
1296+
if (config.navigation == Configuration.NAVIGATION_NONAV
1297+
|| (navigationPresence == PRESENCE_INTERNAL
1298+
&& isHidden(mLidNavigationAccessibility))) {
12921299
config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
1293-
} else {
1294-
config.navigationHidden = determineHiddenState(mLidNavigationAccessibility,
1295-
Configuration.NAVIGATIONHIDDEN_YES, Configuration.NAVIGATIONHIDDEN_NO);
1296-
}
1297-
1298-
if (mHasSoftInput || config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
1299-
config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1300-
} else {
1301-
config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
13021300
}
13031301
}
13041302

@@ -3890,7 +3888,8 @@ public void enableScreenAfterBoot() {
38903888
}
38913889

38923890
private void applyLidSwitchState() {
3893-
mPowerManager.setKeyboardVisibility(isKeyboardVisible());
3891+
mPowerManager.setKeyboardVisibility(isBuiltInKeyboardVisible());
3892+
38943893
if (mLidState == LID_CLOSED && mLidControlsSleep) {
38953894
mPowerManager.goToSleep(SystemClock.uptimeMillis());
38963895
}

services/input/InputReader.cpp

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ InputReader::InputReader(const sp<EventHubInterface>& eventHub,
250250

251251
refreshConfigurationLocked(0);
252252
updateGlobalMetaStateLocked();
253-
updateInputConfigurationLocked();
254253
} // release lock
255254
}
256255

@@ -502,9 +501,6 @@ void InputReader::handleConfigurationChangedLocked(nsecs_t when) {
502501
// Reset global meta state because it depends on the list of all configured devices.
503502
updateGlobalMetaStateLocked();
504503

505-
// Update input configuration.
506-
updateInputConfigurationLocked();
507-
508504
// Enqueue configuration changed.
509505
NotifyConfigurationChangedArgs args(when);
510506
mQueuedListener->notifyConfigurationChanged(&args);
@@ -542,36 +538,6 @@ int32_t InputReader::getGlobalMetaStateLocked() {
542538
return mGlobalMetaState;
543539
}
544540

545-
void InputReader::updateInputConfigurationLocked() {
546-
int32_t touchScreenConfig = InputConfiguration::TOUCHSCREEN_NOTOUCH;
547-
int32_t keyboardConfig = InputConfiguration::KEYBOARD_NOKEYS;
548-
int32_t navigationConfig = InputConfiguration::NAVIGATION_NONAV;
549-
InputDeviceInfo deviceInfo;
550-
for (size_t i = 0; i < mDevices.size(); i++) {
551-
InputDevice* device = mDevices.valueAt(i);
552-
if (!(device->getClasses() & INPUT_DEVICE_CLASS_VIRTUAL)) {
553-
device->getDeviceInfo(& deviceInfo);
554-
uint32_t sources = deviceInfo.getSources();
555-
556-
if ((sources & AINPUT_SOURCE_TOUCHSCREEN) == AINPUT_SOURCE_TOUCHSCREEN) {
557-
touchScreenConfig = InputConfiguration::TOUCHSCREEN_FINGER;
558-
}
559-
if ((sources & AINPUT_SOURCE_TRACKBALL) == AINPUT_SOURCE_TRACKBALL) {
560-
navigationConfig = InputConfiguration::NAVIGATION_TRACKBALL;
561-
} else if ((sources & AINPUT_SOURCE_DPAD) == AINPUT_SOURCE_DPAD) {
562-
navigationConfig = InputConfiguration::NAVIGATION_DPAD;
563-
}
564-
if (deviceInfo.getKeyboardType() == AINPUT_KEYBOARD_TYPE_ALPHABETIC) {
565-
keyboardConfig = InputConfiguration::KEYBOARD_QWERTY;
566-
}
567-
}
568-
}
569-
570-
mInputConfiguration.touchScreen = touchScreenConfig;
571-
mInputConfiguration.keyboard = keyboardConfig;
572-
mInputConfiguration.navigation = navigationConfig;
573-
}
574-
575541
void InputReader::disableVirtualKeysUntilLocked(nsecs_t time) {
576542
mDisableVirtualKeysTimeout = time;
577543
}
@@ -608,12 +574,6 @@ int32_t InputReader::bumpGenerationLocked() {
608574
return ++mGeneration;
609575
}
610576

611-
void InputReader::getInputConfiguration(InputConfiguration* outConfiguration) {
612-
AutoMutex _l(mLock);
613-
614-
*outConfiguration = mInputConfiguration;
615-
}
616-
617577
void InputReader::getInputDevices(Vector<InputDeviceInfo>& outInputDevices) {
618578
AutoMutex _l(mLock);
619579
getInputDevicesLocked(outInputDevices);
@@ -1049,7 +1009,7 @@ void InputDevice::timeoutExpired(nsecs_t when) {
10491009
}
10501010

10511011
void InputDevice::getDeviceInfo(InputDeviceInfo* outDeviceInfo) {
1052-
outDeviceInfo->initialize(mId, mGeneration, mIdentifier, mAlias);
1012+
outDeviceInfo->initialize(mId, mGeneration, mIdentifier, mAlias, mIsExternal);
10531013

10541014
size_t numMappers = mMappers.size();
10551015
for (size_t i = 0; i < numMappers; i++) {

0 commit comments

Comments
 (0)