Skip to content

Commit 0632b35

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "Improve handling of built-in keyboard." into jb-dev
2 parents 5a00661 + daa3753 commit 0632b35

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
/**
@@ -516,8 +521,13 @@ public void init(Context context, IWindowManager windowManager,
516521
*
517522
* @param config The Configuration being computed, for you to change as
518523
* desired.
524+
* @param keyboardPresence Flags that indicate whether internal or external
525+
* keyboards are present.
526+
* @param navigationPresence Flags that indicate whether internal or external
527+
* navigation devices are present.
519528
*/
520-
public void adjustConfigurationLw(Configuration config);
529+
public void adjustConfigurationLw(Configuration config, int keyboardPresence,
530+
int navigationPresence);
521531

522532
/**
523533
* 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;
@@ -1265,46 +1267,42 @@ void readLidState() {
12651267
mLidState = mWindowManagerFuncs.getLidState();
12661268
}
12671269

1268-
private int determineHiddenState(int mode, int hiddenValue, int visibleValue) {
1269-
if (mLidState != LID_ABSENT) {
1270-
switch (mode) {
1271-
case 1:
1272-
return mLidState == LID_OPEN ? visibleValue : hiddenValue;
1273-
case 2:
1274-
return mLidState == LID_OPEN ? hiddenValue : visibleValue;
1275-
}
1270+
private boolean isHidden(int accessibilityMode) {
1271+
switch (accessibilityMode) {
1272+
case 1:
1273+
return mLidState == LID_CLOSED;
1274+
case 2:
1275+
return mLidState == LID_OPEN;
1276+
default:
1277+
return false;
12761278
}
1277-
return visibleValue;
12781279
}
12791280

1280-
private boolean isKeyboardVisible() {
1281-
return determineHiddenState(mLidKeyboardAccessibility, 0, 1) == 1
1282-
|| determineHiddenState(mLidNavigationAccessibility, 0, 1) == 1;
1281+
private boolean isBuiltInKeyboardVisible() {
1282+
return mHaveBuiltInKeyboard && !isHidden(mLidKeyboardAccessibility);
12831283
}
12841284

12851285
/** {@inheritDoc} */
1286-
public void adjustConfigurationLw(Configuration config) {
1286+
public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1287+
int navigationPresence) {
1288+
mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1289+
12871290
readLidState();
12881291
applyLidSwitchState();
12891292

1290-
if (config.keyboard == Configuration.KEYBOARD_NOKEYS) {
1293+
if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1294+
|| (keyboardPresence == PRESENCE_INTERNAL
1295+
&& isHidden(mLidKeyboardAccessibility))) {
12911296
config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
1292-
} else {
1293-
config.hardKeyboardHidden = determineHiddenState(mLidKeyboardAccessibility,
1294-
Configuration.HARDKEYBOARDHIDDEN_YES, Configuration.HARDKEYBOARDHIDDEN_NO);
1297+
if (!mHasSoftInput) {
1298+
config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1299+
}
12951300
}
12961301

1297-
if (config.navigation == Configuration.NAVIGATION_NONAV) {
1302+
if (config.navigation == Configuration.NAVIGATION_NONAV
1303+
|| (navigationPresence == PRESENCE_INTERNAL
1304+
&& isHidden(mLidNavigationAccessibility))) {
12981305
config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
1299-
} else {
1300-
config.navigationHidden = determineHiddenState(mLidNavigationAccessibility,
1301-
Configuration.NAVIGATIONHIDDEN_YES, Configuration.NAVIGATIONHIDDEN_NO);
1302-
}
1303-
1304-
if (mHasSoftInput || config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
1305-
config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1306-
} else {
1307-
config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
13081306
}
13091307
}
13101308

@@ -3932,7 +3930,8 @@ public void enableScreenAfterBoot() {
39323930
}
39333931

39343932
private void applyLidSwitchState() {
3935-
mPowerManager.setKeyboardVisibility(isKeyboardVisible());
3933+
mPowerManager.setKeyboardVisibility(isBuiltInKeyboardVisible());
3934+
39363935
if (mLidState == LID_CLOSED && mLidControlsSleep) {
39373936
mPowerManager.goToSleep(SystemClock.uptimeMillis());
39383937
}

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)