Respect intent-filter priority for system keyboard layouts.
Bug: 17573945
Change-Id: Id357e199b37ef771c4362c2a5c4ae762071f0042
diff --git a/core/java/android/hardware/input/KeyboardLayout.java b/core/java/android/hardware/input/KeyboardLayout.java
index 5402e75..ed51402 100644
--- a/core/java/android/hardware/input/KeyboardLayout.java
+++ b/core/java/android/hardware/input/KeyboardLayout.java
@@ -29,6 +29,7 @@
private final String mDescriptor;
private final String mLabel;
private final String mCollection;
+ private final int mPriority;
public static final Parcelable.Creator<KeyboardLayout> CREATOR =
new Parcelable.Creator<KeyboardLayout>() {
@@ -40,16 +41,18 @@
}
};
- public KeyboardLayout(String descriptor, String label, String collection) {
+ public KeyboardLayout(String descriptor, String label, String collection, int priority) {
mDescriptor = descriptor;
mLabel = label;
mCollection = collection;
+ mPriority = priority;
}
private KeyboardLayout(Parcel source) {
mDescriptor = source.readString();
mLabel = source.readString();
mCollection = source.readString();
+ mPriority = source.readInt();
}
/**
@@ -90,11 +93,17 @@
dest.writeString(mDescriptor);
dest.writeString(mLabel);
dest.writeString(mCollection);
+ dest.writeInt(mPriority);
}
@Override
public int compareTo(KeyboardLayout another) {
- int result = mLabel.compareToIgnoreCase(another.mLabel);
+ // Note that these arguments are intentionally flipped since you want higher priority
+ // keyboards to be listed before lower priority keyboards.
+ int result = Integer.compare(another.mPriority, mPriority);
+ if (result == 0) {
+ result = mLabel.compareToIgnoreCase(another.mLabel);
+ }
if (result == 0) {
result = mCollection.compareToIgnoreCase(another.mCollection);
}
@@ -108,4 +117,4 @@
}
return mLabel + " - " + mCollection;
}
-}
\ No newline at end of file
+}
diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java
index 81b579d..7f89947 100644
--- a/services/core/java/com/android/server/input/InputManagerService.java
+++ b/services/core/java/com/android/server/input/InputManagerService.java
@@ -37,6 +37,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.PackageManager.NameNotFoundException;
@@ -806,8 +807,8 @@
final HashSet<String> availableKeyboardLayouts = new HashSet<String>();
visitAllKeyboardLayouts(new KeyboardLayoutVisitor() {
@Override
- public void visitKeyboardLayout(Resources resources,
- String descriptor, String label, String collection, int keyboardLayoutResId) {
+ public void visitKeyboardLayout(Resources resources, String descriptor, String label,
+ String collection, int keyboardLayoutResId, int priority) {
availableKeyboardLayouts.add(descriptor);
}
});
@@ -840,9 +841,9 @@
final ArrayList<KeyboardLayout> list = new ArrayList<KeyboardLayout>();
visitAllKeyboardLayouts(new KeyboardLayoutVisitor() {
@Override
- public void visitKeyboardLayout(Resources resources,
- String descriptor, String label, String collection, int keyboardLayoutResId) {
- list.add(new KeyboardLayout(descriptor, label, collection));
+ public void visitKeyboardLayout(Resources resources, String descriptor, String label,
+ String collection, int keyboardLayoutResId, int priority) {
+ list.add(new KeyboardLayout(descriptor, label, collection, priority));
}
});
return list.toArray(new KeyboardLayout[list.size()]);
@@ -857,9 +858,9 @@
final KeyboardLayout[] result = new KeyboardLayout[1];
visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {
@Override
- public void visitKeyboardLayout(Resources resources,
- String descriptor, String label, String collection, int keyboardLayoutResId) {
- result[0] = new KeyboardLayout(descriptor, label, collection);
+ public void visitKeyboardLayout(Resources resources, String descriptor,
+ String label, String collection, int keyboardLayoutResId, int priority) {
+ result[0] = new KeyboardLayout(descriptor, label, collection, priority);
}
});
if (result[0] == null) {
@@ -874,7 +875,9 @@
Intent intent = new Intent(InputManager.ACTION_QUERY_KEYBOARD_LAYOUTS);
for (ResolveInfo resolveInfo : pm.queryBroadcastReceivers(intent,
PackageManager.GET_META_DATA)) {
- visitKeyboardLayoutsInPackage(pm, resolveInfo.activityInfo, null, visitor);
+ final ActivityInfo activityInfo = resolveInfo.activityInfo;
+ final int priority = resolveInfo.priority;
+ visitKeyboardLayoutsInPackage(pm, activityInfo, null, priority, visitor);
}
}
@@ -887,14 +890,14 @@
ActivityInfo receiver = pm.getReceiverInfo(
new ComponentName(d.packageName, d.receiverName),
PackageManager.GET_META_DATA);
- visitKeyboardLayoutsInPackage(pm, receiver, d.keyboardLayoutName, visitor);
+ visitKeyboardLayoutsInPackage(pm, receiver, d.keyboardLayoutName, 0, visitor);
} catch (NameNotFoundException ex) {
}
}
}
private void visitKeyboardLayoutsInPackage(PackageManager pm, ActivityInfo receiver,
- String keyboardName, KeyboardLayoutVisitor visitor) {
+ String keyboardName, int requestedPriority, KeyboardLayoutVisitor visitor) {
Bundle metaData = receiver.metaData;
if (metaData == null) {
return;
@@ -909,6 +912,12 @@
CharSequence receiverLabel = receiver.loadLabel(pm);
String collection = receiverLabel != null ? receiverLabel.toString() : "";
+ int priority;
+ if ((receiver.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
+ priority = requestedPriority;
+ } else {
+ priority = 0;
+ }
try {
Resources resources = pm.getResourcesForApplication(receiver.applicationInfo);
@@ -943,7 +952,7 @@
receiver.packageName, receiver.name, name);
if (keyboardName == null || name.equals(keyboardName)) {
visitor.visitKeyboardLayout(resources, descriptor,
- label, collection, keyboardLayoutResId);
+ label, collection, keyboardLayoutResId, priority);
}
}
} finally {
@@ -1550,8 +1559,8 @@
final String[] result = new String[2];
visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {
@Override
- public void visitKeyboardLayout(Resources resources,
- String descriptor, String label, String collection, int keyboardLayoutResId) {
+ public void visitKeyboardLayout(Resources resources, String descriptor, String label,
+ String collection, int keyboardLayoutResId, int priority) {
try {
result[0] = descriptor;
result[1] = Streams.readFully(new InputStreamReader(
@@ -1699,8 +1708,8 @@
}
private interface KeyboardLayoutVisitor {
- void visitKeyboardLayout(Resources resources,
- String descriptor, String label, String collection, int keyboardLayoutResId);
+ void visitKeyboardLayout(Resources resources, String descriptor, String label,
+ String collection, int keyboardLayoutResId, int priority);
}
private final class InputDevicesChangedListenerRecord implements DeathRecipient {