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

Commit 5217cacb authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Make JobSchedulerService encryption aware.

When a user is started, but a persisted job component doesn't appear
in the normal resolution list, we avoid enqueuing the job.  Later
when the user is unlocked, we take another pass over the pending
jobs to see if they became available.

Load keyboard layouts from XML metadata regardless of crypto status,
since we don't need to spin up any remote code.

Add MATCH_SYSTEM_ONLY to make system logic easier to write when
looking for trusted components.

Sprinkle more annotations on ArrayUtils methods.

Bug: 26279465
Change-Id: Iec28e0bb46862b07d740b12a79f6360de68dab0f
parent 2a9e3f8e
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.content.pm;

import android.content.ComponentName;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
@@ -148,6 +149,11 @@ public class ComponentInfo extends PackageItemInfo {
        return banner != 0 ? banner : applicationInfo.banner;
    }

    /** {@hide} */
    public ComponentName getComponentName() {
        return new ComponentName(packageName, name);
    }

    protected void dumpFront(Printer pw, String prefix) {
        super.dumpFront(pw, prefix);
        if (processName != null && !packageName.equals(processName)) {
+9 −1
Original line number Diff line number Diff line
@@ -252,6 +252,14 @@ public abstract class PackageManager {
    public static final int MATCH_ENCRYPTION_AWARE_AND_UNAWARE = MATCH_ENCRYPTION_AWARE_ONLY
            | MATCH_ENCRYPTION_UNAWARE_ONLY;

    /**
     * {@link PackageInfo} flag: include only components from applications that
     * are marked with {@link ApplicationInfo#FLAG_SYSTEM}.
     *
     * @hide
     */
    public static final int MATCH_SYSTEM_ONLY = 0x00100000;

    /**
     * {@link PackageInfo} flag: use the default encryption matching behavior
     * based on user state. Internal flag used to indicate that a system
@@ -260,7 +268,7 @@ public abstract class PackageManager {
     *
     * @hide
     */
    public static final int MATCH_ENCRYPTION_DEFAULT = 0x00100000;
    public static final int MATCH_ENCRYPTION_DEFAULT = 0x10000000;

    /**
     * Flag for {@link addCrossProfileIntentFilter}: if this flag is set:
+21 −19
Original line number Diff line number Diff line
@@ -125,28 +125,28 @@ public class ArrayUtils {
    /**
     * Checks if given array is null or has zero elements.
     */
    public static <T> boolean isEmpty(T[] array) {
    public static <T> boolean isEmpty(@Nullable T[] array) {
        return array == null || array.length == 0;
    }

    /**
     * Checks if given array is null or has zero elements.
     */
    public static boolean isEmpty(int[] array) {
    public static boolean isEmpty(@Nullable int[] array) {
        return array == null || array.length == 0;
    }

    /**
     * Checks if given array is null or has zero elements.
     */
    public static boolean isEmpty(long[] array) {
    public static boolean isEmpty(@Nullable long[] array) {
        return array == null || array.length == 0;
    }

    /**
     * Checks if given array is null or has zero elements.
     */
    public static boolean isEmpty(byte[] array) {
    public static boolean isEmpty(@Nullable byte[] array) {
        return array == null || array.length == 0;
    }

@@ -156,7 +156,7 @@ public class ArrayUtils {
     * @param value the value to check for
     * @return true if the value is present in the array
     */
    public static <T> boolean contains(T[] array, T value) {
    public static <T> boolean contains(@Nullable T[] array, T value) {
        return indexOf(array, value) != -1;
    }

@@ -164,7 +164,7 @@ public class ArrayUtils {
     * Return first index of {@code value} in {@code array}, or {@code -1} if
     * not found.
     */
    public static <T> int indexOf(T[] array, T value) {
    public static <T> int indexOf(@Nullable T[] array, T value) {
        if (array == null) return -1;
        for (int i = 0; i < array.length; i++) {
            if (Objects.equals(array[i], value)) return i;
@@ -175,7 +175,7 @@ public class ArrayUtils {
    /**
     * Test if all {@code check} items are contained in {@code array}.
     */
    public static <T> boolean containsAll(T[] array, T[] check) {
    public static <T> boolean containsAll(@Nullable T[] array, T[] check) {
        if (check == null) return true;
        for (T checkItem : check) {
            if (!contains(array, checkItem)) {
@@ -185,7 +185,7 @@ public class ArrayUtils {
        return true;
    }

    public static boolean contains(int[] array, int value) {
    public static boolean contains(@Nullable int[] array, int value) {
        if (array == null) return false;
        for (int element : array) {
            if (element == value) {
@@ -195,7 +195,7 @@ public class ArrayUtils {
        return false;
    }

    public static boolean contains(long[] array, long value) {
    public static boolean contains(@Nullable long[] array, long value) {
        if (array == null) return false;
        for (long element : array) {
            if (element == value) {
@@ -205,11 +205,13 @@ public class ArrayUtils {
        return false;
    }

    public static long total(long[] array) {
    public static long total(@Nullable long[] array) {
        long total = 0;
        if (array != null) {
            for (long value : array) {
                total += value;
            }
        }
        return total;
    }

@@ -366,11 +368,11 @@ public class ArrayUtils {
        return cur;
    }

    public static long[] cloneOrNull(long[] array) {
    public static @Nullable long[] cloneOrNull(@Nullable long[] array) {
        return (array != null) ? array.clone() : null;
    }

    public static <T> ArraySet<T> add(ArraySet<T> cur, T val) {
    public static @NonNull <T> ArraySet<T> add(@Nullable ArraySet<T> cur, T val) {
        if (cur == null) {
            cur = new ArraySet<>();
        }
@@ -378,7 +380,7 @@ public class ArrayUtils {
        return cur;
    }

    public static <T> ArraySet<T> remove(ArraySet<T> cur, T val) {
    public static @Nullable <T> ArraySet<T> remove(@Nullable ArraySet<T> cur, T val) {
        if (cur == null) {
            return null;
        }
@@ -390,11 +392,11 @@ public class ArrayUtils {
        }
    }

    public static <T> boolean contains(ArraySet<T> cur, T val) {
    public static <T> boolean contains(@Nullable ArraySet<T> cur, T val) {
        return (cur != null) ? cur.contains(val) : false;
    }

    public static <T> ArrayList<T> add(ArrayList<T> cur, T val) {
    public static @NonNull <T> ArrayList<T> add(@Nullable ArrayList<T> cur, T val) {
        if (cur == null) {
            cur = new ArrayList<>();
        }
@@ -402,7 +404,7 @@ public class ArrayUtils {
        return cur;
    }

    public static <T> ArrayList<T> remove(ArrayList<T> cur, T val) {
    public static @Nullable <T> ArrayList<T> remove(@Nullable ArrayList<T> cur, T val) {
        if (cur == null) {
            return null;
        }
@@ -414,7 +416,7 @@ public class ArrayUtils {
        }
    }

    public static <T> boolean contains(ArrayList<T> cur, T val) {
    public static <T> boolean contains(@Nullable ArrayList<T> cur, T val) {
        return (cur != null) ? cur.contains(val) : false;
    }

+4 −3
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static com.android.internal.util.XmlUtils.writeBooleanAttribute;
import static com.android.internal.util.XmlUtils.writeIntAttribute;
import static com.android.internal.util.XmlUtils.writeLongAttribute;
import static com.android.internal.util.XmlUtils.writeStringAttribute;

import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
import static org.xmlpull.v1.XmlPullParser.START_TAG;

@@ -89,9 +90,6 @@ import android.util.Slog;
import android.util.TimeUtils;
import android.util.Xml;

import libcore.io.IoUtils;
import libcore.util.EmptyArray;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.app.IMediaContainerService;
import com.android.internal.os.SomeArgs;
@@ -106,6 +104,9 @@ import com.android.server.NativeDaemonConnector.Command;
import com.android.server.NativeDaemonConnector.SensitiveArg;
import com.android.server.pm.PackageManagerService;

import libcore.io.IoUtils;
import libcore.util.EmptyArray;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
+3 −2
Original line number Diff line number Diff line
@@ -978,7 +978,7 @@ public class InputManagerService extends IInputManager.Stub
        final PackageManager pm = mContext.getPackageManager();
        Intent intent = new Intent(InputManager.ACTION_QUERY_KEYBOARD_LAYOUTS);
        for (ResolveInfo resolveInfo : pm.queryBroadcastReceivers(intent,
                PackageManager.GET_META_DATA)) {
                PackageManager.GET_META_DATA | PackageManager.MATCH_ENCRYPTION_AWARE_AND_UNAWARE)) {
            final ActivityInfo activityInfo = resolveInfo.activityInfo;
            final int priority = resolveInfo.priority;
            visitKeyboardLayoutsInPackage(pm, activityInfo, null, priority, visitor);
@@ -993,7 +993,8 @@ public class InputManagerService extends IInputManager.Stub
            try {
                ActivityInfo receiver = pm.getReceiverInfo(
                        new ComponentName(d.packageName, d.receiverName),
                        PackageManager.GET_META_DATA);
                        PackageManager.GET_META_DATA
                                | PackageManager.MATCH_ENCRYPTION_AWARE_AND_UNAWARE);
                visitKeyboardLayoutsInPackage(pm, receiver, d.keyboardLayoutName, 0, visitor);
            } catch (NameNotFoundException ex) {
            }
Loading