Introducing manifest flag requiredAccountType

This can be used by apps that won't work without an account of that
type in the limited user environment. This way we can avoid letting
users select these apps when setting up a limited user.

Bug: 8600261
Change-Id: Iaa0dd5ff88e89fa7a1d8a4e70317290268411bdb
diff --git a/api/current.txt b/api/current.txt
index ceccfb7..caaec21 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -852,6 +852,7 @@
     field public static final int reqNavigation = 16843306; // 0x101022a
     field public static final int reqTouchScreen = 16843303; // 0x1010227
     field public static final int required = 16843406; // 0x101028e
+    field public static final int requiredAccountType = 16843734; // 0x10103d6
     field public static final int requiredForAllUsers = 16843728; // 0x10103d0
     field public static final int requiresFadingEdge = 16843685; // 0x10103a5
     field public static final int requiresSmallestWidthDp = 16843620; // 0x1010364
diff --git a/core/java/android/content/pm/PackageInfo.java b/core/java/android/content/pm/PackageInfo.java
index 33a6757..af1a6d5 100644
--- a/core/java/android/content/pm/PackageInfo.java
+++ b/core/java/android/content/pm/PackageInfo.java
@@ -224,6 +224,9 @@
     /** @hide */
     public String restrictedAccountType;
 
+    /** @hide */
+    public String requiredAccountType;
+
     public PackageInfo() {
     }
 
@@ -266,6 +269,7 @@
         dest.writeInt(installLocation);
         dest.writeInt(requiredForAllUsers ? 1 : 0);
         dest.writeString(restrictedAccountType);
+        dest.writeString(requiredAccountType);
     }
 
     public static final Parcelable.Creator<PackageInfo> CREATOR
@@ -306,5 +310,6 @@
         installLocation = source.readInt();
         requiredForAllUsers = source.readInt() != 0;
         restrictedAccountType = source.readString();
+        requiredAccountType = source.readString();
     }
 }
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index 5a50ec2..3586573 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -289,6 +289,7 @@
         pi.installLocation = p.installLocation;
         pi.requiredForAllUsers = p.mRequiredForAllUsers;
         pi.restrictedAccountType = p.mRestrictedAccountType;
+        pi.requiredAccountType = p.mRequiredAccountType;
         pi.firstInstallTime = firstInstallTime;
         pi.lastUpdateTime = lastUpdateTime;
         if ((flags&PackageManager.GET_GIDS) != 0) {
@@ -1816,13 +1817,19 @@
                     false)) {
                 owner.mRequiredForAllUsers = true;
             }
-            String accountType = sa.getString(com.android.internal.R.styleable
+            String restrictedAccountType = sa.getString(com.android.internal.R.styleable
                     .AndroidManifestApplication_restrictedAccountType);
-            if (accountType != null && accountType.length() > 0) {
-                owner.mRestrictedAccountType = accountType;
+            if (restrictedAccountType != null && restrictedAccountType.length() > 0) {
+                owner.mRestrictedAccountType = restrictedAccountType;
             }
         }
 
+        String requiredAccountType = sa.getString(com.android.internal.R.styleable
+                .AndroidManifestApplication_requiredAccountType);
+        if (requiredAccountType != null && requiredAccountType.length() > 0) {
+            owner.mRequiredAccountType = requiredAccountType;
+        }
+
         if (sa.getBoolean(
                 com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
                 false)) {
@@ -3339,6 +3346,9 @@
         /* The restricted account authenticator type that is used by this application */
         public String mRestrictedAccountType;
 
+        /* The required account type without which this application will not function */
+        public String mRequiredAccountType;
+
         /**
          * Digest suitable for comparing whether this package's manifest is the
          * same as another.
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index 7f5a3dc..8821a01d 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -909,8 +909,13 @@
         <!-- Declare that this application requires access to restricted accounts of a certain
              type. The default value is null and restricted accounts won\'t be visible to this
              application. The type should correspond to the account authenticator type, such as
-             "com.google" -->
+             "com.google". Only usable by system apps. -->
         <attr name="restrictedAccountType" format="string"/>
+        <!-- Declare that this application requires an account of a certain
+             type. The default value is null and indicates that the application can work without
+             any accounts. The type should correspond to the account authenticator type, such as
+             "com.google". -->
+        <attr name="requiredAccountType" format="string"/>
     </declare-styleable>
     
     <!-- The <code>permission</code> tag declares a security permission that can be
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 42d692f..074d91f 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -2042,6 +2042,7 @@
   <public type="attr" name="childIndicatorStart" />
   <public type="attr" name="childIndicatorEnd" />
   <public type="attr" name="restrictedAccountType" />
+  <public type="attr" name="requiredAccountType" />
 
   <public type="style" name="Theme.NoTitleBar.Overscan" />
   <public type="style" name="Theme.Light.NoTitleBar.Overscan" />