diff options
| author | 2014-09-19 19:52:53 +0000 | |
|---|---|---|
| committer | 2014-09-19 19:52:54 +0000 | |
| commit | 4bc92b064b1f23c67b06a8ed34d11335dd9a8b4f (patch) | |
| tree | ab5bf441d5b6d10ea67f5f33bf50f05ee7199d06 | |
| parent | f6edc55e6a2efdf14daf1b95cc9e3a9a6b4a213b (diff) | |
| parent | 8ebac231966e27364e5d463b63540a0527d40c4b (diff) | |
Merge "Respect intent-filter priority for system keyboard layouts." into lmp-dev
| -rw-r--r-- | core/java/android/hardware/input/KeyboardLayout.java | 15 | ||||
| -rw-r--r-- | services/core/java/com/android/server/input/InputManagerService.java | 41 |
2 files changed, 37 insertions, 19 deletions
diff --git a/core/java/android/hardware/input/KeyboardLayout.java b/core/java/android/hardware/input/KeyboardLayout.java index 5402e75a42c7..ed51402bdac8 100644 --- a/core/java/android/hardware/input/KeyboardLayout.java +++ b/core/java/android/hardware/input/KeyboardLayout.java @@ -29,6 +29,7 @@ public final class KeyboardLayout implements Parcelable, 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 final class KeyboardLayout implements Parcelable, } }; - 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 @@ public final class KeyboardLayout implements Parcelable, 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 @@ public final class KeyboardLayout implements Parcelable, } 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 81b579d9174f..7f89947420a9 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.Context; 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 @@ public class InputManagerService extends IInputManager.Stub 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 @@ public class InputManagerService extends IInputManager.Stub 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 @@ public class InputManagerService extends IInputManager.Stub 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 @@ public class InputManagerService extends IInputManager.Stub 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 @@ public class InputManagerService extends IInputManager.Stub 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 @@ public class InputManagerService extends IInputManager.Stub 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 @@ public class InputManagerService extends IInputManager.Stub 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 @@ public class InputManagerService extends IInputManager.Stub 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 @@ public class InputManagerService extends IInputManager.Stub } 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 { |