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

Commit e546540a authored by Michael Wright's avatar Michael Wright Committed by Android Git Automerger
Browse files

am 2b5563f1: am 66bbf591: Merge "Respect intent-filter priority for system...

am 2b5563f1: am 66bbf591: Merge "Respect intent-filter priority for system keyboard layouts." into lmp-dev

* commit '2b5563f1bf52724b1158d895dffa8fcbd643e3c8':
  Respect intent-filter priority for system keyboard layouts.
parents 417ea7d3 299947f5
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -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);
        }
+25 −16
Original line number Diff line number Diff line
@@ -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 {