Better named encryption flags, start triaging.

Create distinct flags for encryption aware, unaware, and both, and
name them like the other MATCH_ flags.

Start adding logic to help triage all system internal callers to
verify that they've done their homework and thought about how to
handle apps while locked.  Call sites in the system should either
ask for explicit matching behavior, or explicitly use the DEFAULT
match flag to indicate that they've been triaged to use the
default state-based matching.

Bug: 26250295
Change-Id: I86214e5c4f71a6dc72f06930800388713aecd107
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 9973faf..0f3ca10 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -4168,6 +4168,14 @@
     public static final int FLAG_GRANT_PREFIX_URI_PERMISSION = 0x00000080;
 
     /**
+     * Internal flag used to indicate that a system component has done their
+     * homework and verified their encryption-aware behavior.
+     *
+     * @hide
+     */
+    public static final int FLAG_DEBUG_ENCRYPTION_TRIAGED = 0x00000100;
+
+    /**
      * If set, the new activity is not kept in the history stack.  As soon as
      * the user navigates away from it, the activity is finished.  This may also
      * be set with the {@link android.R.styleable#AndroidManifestActivity_noHistory
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 3235bcf..1882f8d 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -47,10 +47,8 @@
 import android.os.RemoteException;
 import android.os.UserHandle;
 import android.os.storage.VolumeInfo;
-import android.provider.Settings;
 import android.util.AndroidException;
 
-import android.util.Log;
 import com.android.internal.util.ArrayUtils;
 
 import java.io.File;
@@ -236,21 +234,33 @@
     public static final int MATCH_ALL = 0x00020000;
 
     /**
-     * {@link PackageInfo} flag: include components which aren't encryption
-     * aware in the returned info, regardless of the current user state.
+     * {@link PackageInfo} flag: include only components which are encryption
+     * unaware in the returned info, regardless of the current user state.
      */
-    public static final int GET_ENCRYPTION_UNAWARE_COMPONENTS = 0x00040000;
+    public static final int MATCH_ENCRYPTION_UNAWARE_ONLY = 0x00040000;
 
     /**
-     * {@link PackageInfo} flag: return components that are marked as
-     * {@link ComponentInfo#encryptionAware}, unless
-     * {@link #GET_ENCRYPTION_UNAWARE_COMPONENTS} is also specified.
-     * <p>
-     * This flag is for internal use only.
+     * {@link PackageInfo} flag: include only components which are encryption
+     * aware in the returned info, regardless of the current user state.
+     */
+    public static final int MATCH_ENCRYPTION_AWARE_ONLY = 0x00080000;
+
+    /**
+     * {@link PackageInfo} flag: include both encryption aware and unaware
+     * components in the returned info, regardless of the current user state.
+     */
+    public static final int MATCH_ENCRYPTION_AWARE_AND_UNAWARE = MATCH_ENCRYPTION_AWARE_ONLY
+            | MATCH_ENCRYPTION_UNAWARE_ONLY;
+
+    /**
+     * {@link PackageInfo} flag: use the default encryption matching behavior
+     * based on user state. Internal flag used to indicate that a system
+     * component has done their homework and verified their encryption-aware
+     * behavior.
      *
      * @hide
      */
-    public static final int MATCH_ENCRYPTION_AWARE_ONLY = 0x00080000;
+    public static final int MATCH_ENCRYPTION_DEFAULT = 0x00100000;
 
     /**
      * Flag for {@link addCrossProfileIntentFilter}: if this flag is set:
diff --git a/core/java/android/content/pm/RegisteredServicesCache.java b/core/java/android/content/pm/RegisteredServicesCache.java
index a413f36..bb28bde 100644
--- a/core/java/android/content/pm/RegisteredServicesCache.java
+++ b/core/java/android/content/pm/RegisteredServicesCache.java
@@ -365,7 +365,7 @@
     protected List<ResolveInfo> queryIntentServices(int userId) {
         final PackageManager pm = mContext.getPackageManager();
         return pm.queryIntentServicesAsUser(new Intent(mInterfaceName),
-                PackageManager.GET_META_DATA | PackageManager.GET_ENCRYPTION_UNAWARE_COMPONENTS,
+                PackageManager.GET_META_DATA | PackageManager.MATCH_ENCRYPTION_AWARE_AND_UNAWARE,
                 userId);
     }