am fee56f1d: am c912a86c: am 00a871ca: am 4e2689b5: am d4fefc51: am 44e09b47: Merge "Add cts test for testing launcher version." into lmp-sprout-dev

* commit 'fee56f1dd004aa99e01393726cf2bf498143fc22':
  Add cts test for testing launcher version.
diff --git a/tests/tests/admin/src/android/admin/cts/DevicePolicyManagerTest.java b/tests/tests/admin/src/android/admin/cts/DevicePolicyManagerTest.java
index 04060e5..513b67e 100644
--- a/tests/tests/admin/src/android/admin/cts/DevicePolicyManagerTest.java
+++ b/tests/tests/admin/src/android/admin/cts/DevicePolicyManagerTest.java
@@ -21,7 +21,11 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ResolveInfo;
+import android.os.Build;
 import android.os.UserManager;
 import android.provider.Settings;
 import android.test.AndroidTestCase;
@@ -44,6 +48,8 @@
     private ComponentName mComponent;
     private ComponentName mSecondComponent;
     private boolean mDeviceAdmin;
+    private boolean mManagedProfiles;
+    private PackageManager mPackageManager;
 
     private static final String TEST_CA_STRING1 =
             "-----BEGIN CERTIFICATE-----\n" +
@@ -68,9 +74,11 @@
         mDevicePolicyManager = (DevicePolicyManager)
                 mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
         mComponent = DeviceAdminInfoTest.getReceiverComponent();
+        mPackageManager = mContext.getPackageManager();
         mSecondComponent = DeviceAdminInfoTest.getSecondReceiverComponent();
-        mDeviceAdmin =
-                mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN);
+        mDeviceAdmin = mPackageManager.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN);
+        mManagedProfiles = mDeviceAdmin
+                && mPackageManager.hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS);
         setBlankPassword();
     }
 
@@ -876,6 +884,32 @@
         }
     }
 
+    /**
+     * Test whether the version of the pre-installed launcher is at least L. This is needed for
+     * managed profile support.
+     */
+    public void testLauncherVersionAtLeastL() throws Exception {
+        if (!mManagedProfiles) {
+            return;
+        }
+
+        Intent intent = new Intent(Intent.ACTION_MAIN);
+        intent.addCategory(Intent.CATEGORY_HOME);
+        List<ResolveInfo> resolveInfos = mPackageManager.queryIntentActivities(intent,
+                0 /* default flags */);
+        assertFalse("No launcher present", resolveInfos.isEmpty());
+
+        for (ResolveInfo resolveInfo : resolveInfos) {
+            ApplicationInfo launcherAppInfo = mPackageManager.getApplicationInfo(
+                    resolveInfo.activityInfo.packageName, 0 /* default flags */);
+            if ((launcherAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 &&
+                    launcherAppInfo.targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP) {
+                return;
+            }
+        }
+        fail("No system launcher with version L+ present present on device.");
+    }
+
     private void assertDeviceOwnerMessage(String message) {
         assertTrue("message is: "+ message, message.contains("does not own the device")
                 || message.contains("can only be called by the device owner"));
diff --git a/tests/tests/admin/src/android/admin/cts/NfcProvisioningSetupWizardConfigTest.java b/tests/tests/admin/src/android/admin/cts/NfcProvisioningSetupWizardConfigTest.java
deleted file mode 100644
index 668c8c0..0000000
--- a/tests/tests/admin/src/android/admin/cts/NfcProvisioningSetupWizardConfigTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.admin.cts;
-
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.res.Resources;
-import android.test.AndroidTestCase;
-
-/**
- * Test whether the resources of com.android.nfc specify that managed provisioning intents can be
- * received in the setup wizard. See go/android-enterprise-oemchecklist.
- */
-public class NfcProvisioningSetupWizardConfigTest extends AndroidTestCase {
-
-    private static final String NFC_PACKAGE_NAME = "com.android.nfc";
-    private static final String MANAGED_PROVISIONING_PACKAGE_NAME =
-            "com.android.managedprovisioning";
-
-    private static final String PROVISIONING_MIME_TYPES = "provisioning_mime_types";
-    private static final String ENABLE_NFC_PROVISIONING = "enable_nfc_provisioning";
-
-    private static final String REQUIRED_MIME_TYPE = "application/com.android.managedprovisioning";
-
-    private boolean mHasFeature;
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        mHasFeature = isPackageInstalledOnSystemImage(NFC_PACKAGE_NAME)
-                && getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)
-                && isPackageInstalledOnSystemImage(MANAGED_PROVISIONING_PACKAGE_NAME)
-                && getContext().getPackageManager().hasSystemFeature(
-                        PackageManager.FEATURE_DEVICE_ADMIN);
-    }
-
-    public void testNfcEnabledDuringSetupWizard() throws Exception {
-        if (!mHasFeature) {
-            return;
-        }
-
-        assertTrue("Boolean " + ENABLE_NFC_PROVISIONING + " must be true in resources of "
-                + NFC_PACKAGE_NAME, getBooleanByName(ENABLE_NFC_PROVISIONING));
-    }
-
-    public void testManagedProvisioningMimeTypeAccepted() throws Exception {
-        if (!mHasFeature) {
-            return;
-        }
-
-        String[] provisioningMimeTypes = getStringArrayByName(PROVISIONING_MIME_TYPES);
-        for (String mimeType : provisioningMimeTypes) {
-            if (mimeType.equals(REQUIRED_MIME_TYPE)) {
-                return;
-            }
-        }
-
-        fail("Mime type " + REQUIRED_MIME_TYPE + " was not present in the list "
-                + PROVISIONING_MIME_TYPES + " in resources of " + NFC_PACKAGE_NAME);
-    }
-
-    private String[] getStringArrayByName(String name) throws Exception {
-        Resources resources = getNfcResources();
-        int arrayId = resources.getIdentifier(name, "array", NFC_PACKAGE_NAME);
-        return resources.getStringArray(arrayId);
-    }
-
-    private boolean getBooleanByName(String name) throws Exception {
-        Resources resources = getNfcResources();
-        int arrayId = resources.getIdentifier(name, "bool", NFC_PACKAGE_NAME);
-        return resources.getBoolean(arrayId);
-    }
-
-    private Resources getNfcResources() throws Exception {
-        return getContext().getPackageManager().getResourcesForApplication(NFC_PACKAGE_NAME);
-    }
-
-    private boolean isPackageInstalledOnSystemImage(String packagename) {
-        try {
-            ApplicationInfo info = getContext().getPackageManager().getApplicationInfo(packagename,
-                    0 /* default flags */);
-            return (info.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
-        } catch (NameNotFoundException e) {
-            return false;
-        }
-    }
-}