summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaurice Lam <yukl@google.com>2015-03-30 16:06:18 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-03-30 16:06:18 +0000
commita183f1a46eec94c32a4da8fb7eaba63dca81646b (patch)
treec4a2922e982503c0fbc499e583d4aaa089bb9d81
parentd2abf66846d1fcea1345f0b7d5383c3366721e8c (diff)
parent2cd3a5058ef157486d7d3c0f391f89dff808e81d (diff)
downloadandroid_frameworks_opt_setupwizard-a183f1a46eec94c32a4da8fb7eaba63dca81646b.tar.gz
android_frameworks_opt_setupwizard-a183f1a46eec94c32a4da8fb7eaba63dca81646b.tar.bz2
android_frameworks_opt_setupwizard-a183f1a46eec94c32a4da8fb7eaba63dca81646b.zip
am 2cd3a505: Merge "[SetupWizardLib] Add isSetupWizard" into ub-setupwizard-alatar
* commit '2cd3a5058ef157486d7d3c0f391f89dff808e81d': [SetupWizardLib] Add isSetupWizard
-rw-r--r--library/main/src/com/android/setupwizardlib/util/WizardManagerHelper.java58
-rw-r--r--library/test/src/com/android/setupwizardlib/test/WizardManagerHelperTest.java70
2 files changed, 128 insertions, 0 deletions
diff --git a/library/main/src/com/android/setupwizardlib/util/WizardManagerHelper.java b/library/main/src/com/android/setupwizardlib/util/WizardManagerHelper.java
index 563e97d..69d3848 100644
--- a/library/main/src/com/android/setupwizardlib/util/WizardManagerHelper.java
+++ b/library/main/src/com/android/setupwizardlib/util/WizardManagerHelper.java
@@ -16,7 +16,11 @@
package com.android.setupwizardlib.util;
+import android.content.Context;
import android.content.Intent;
+import android.os.Build.VERSION;
+import android.os.Build.VERSION_CODES;
+import android.provider.Settings;
public class WizardManagerHelper {
@@ -25,10 +29,14 @@ public class WizardManagerHelper {
private static final String EXTRA_SCRIPT_URI = "scriptUri";
private static final String EXTRA_ACTION_ID = "actionId";
private static final String EXTRA_RESULT_CODE = "com.android.setupwizard.ResultCode";
+ private static final String EXTRA_IS_FIRST_RUN = "firstRun";
public static final String EXTRA_THEME = "theme";
public static final String EXTRA_USE_IMMERSIVE_MODE = "useImmersiveMode";
+ public static final String SETTINGS_GLOBAL_DEVICE_PROVISIONED = "device_provisioned";
+ public static final String SETTINGS_SECURE_USER_SETUP_COMPLETE = "user_setup_complete";
+
public static final String THEME_MATERIAL = "material";
public static final String THEME_MATERIAL_LIGHT = "material_light";
@@ -66,4 +74,54 @@ public class WizardManagerHelper {
intent.putExtra(EXTRA_THEME, originalIntent.getStringExtra(EXTRA_THEME));
return intent;
}
+
+ /**
+ * Check whether an intent is intended to be used within the setup wizard flow.
+ *
+ * @param intent The intent to be checked, usually from Activity.getIntent().
+ * @return true if the intent passed in was intended to be used with setup wizard.
+ */
+ public static boolean isSetupWizardIntent(Intent intent) {
+ return intent.getBooleanExtra(EXTRA_IS_FIRST_RUN, false);
+ }
+
+ /**
+ * Checks whether the current user has completed Setup Wizard. This is true if the current user
+ * has gone through Setup Wizard. The current user may or may not be the device owner and the
+ * device owner may have already completed setup wizard.
+ *
+ * @param context The context to retrieve the settings.
+ * @return true if the current user has completed Setup Wizard.
+ * @see #isDeviceProvisioned(android.content.Context)
+ */
+ public static boolean isUserSetupComplete(Context context) {
+ if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
+ return Settings.Secure.getInt(context.getContentResolver(),
+ SETTINGS_SECURE_USER_SETUP_COMPLETE, 0) == 1;
+ } else {
+ // For versions below JB MR1, there are no user profiles. Just return the global device
+ // provisioned state.
+ return Settings.Secure.getInt(context.getContentResolver(),
+ SETTINGS_GLOBAL_DEVICE_PROVISIONED, 0) == 1;
+ }
+ }
+
+ /**
+ * Checks whether the device is provisioned. This means that the device has gone through Setup
+ * Wizard at least once. Note that the user can still be in Setup Wizard even if this is true,
+ * for a secondary user profile triggered through Settings > Add account.
+ *
+ * @param context The context to retrieve the settings.
+ * @return true if the device is provisioned.
+ * @see #isUserSetupComplete(android.content.Context)
+ */
+ public static boolean isDeviceProvisioned(Context context) {
+ if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
+ return Settings.Global.getInt(context.getContentResolver(),
+ SETTINGS_GLOBAL_DEVICE_PROVISIONED, 0) == 1;
+ } else {
+ return Settings.Secure.getInt(context.getContentResolver(),
+ SETTINGS_GLOBAL_DEVICE_PROVISIONED, 0) == 1;
+ }
+ }
}
diff --git a/library/test/src/com/android/setupwizardlib/test/WizardManagerHelperTest.java b/library/test/src/com/android/setupwizardlib/test/WizardManagerHelperTest.java
new file mode 100644
index 0000000..b8dd7a0
--- /dev/null
+++ b/library/test/src/com/android/setupwizardlib/test/WizardManagerHelperTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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 com.android.setupwizardlib.test;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.android.setupwizardlib.util.WizardManagerHelper;
+
+public class WizardManagerHelperTest extends AndroidTestCase {
+
+ @SmallTest
+ public void testGetNextIntent() {
+ final Intent intent = new Intent("test.intent.ACTION");
+ intent.putExtra("scriptUri", "android-resource://test-script");
+ intent.putExtra("actionId", "test_action_id");
+ intent.putExtra("theme", "test_theme");
+ intent.putExtra("ignoreExtra", "poof"); // extra is ignored because it's not known
+
+ final Intent data = new Intent();
+ data.putExtra("extraData", "shazam");
+
+ final Intent nextIntent = WizardManagerHelper.getNextIntent(intent, Activity.RESULT_OK, data);
+ assertEquals("Next intent action should be NEXT", "com.android.wizard.NEXT",
+ nextIntent.getAction());
+ assertEquals("Script URI should be the same as original intent",
+ "android-resource://test-script", nextIntent.getStringExtra("scriptUri"));
+ assertEquals("Action ID should be the same as original intent", "test_action_id",
+ nextIntent.getStringExtra("actionId"));
+ assertEquals("Theme extra should be the same as original intent", "test_theme",
+ nextIntent.getStringExtra("theme"));
+ assertFalse("ignoreExtra should not be in nextIntent", nextIntent.hasExtra("ignoreExtra"));
+ assertEquals("Result code extra should be RESULT_OK", Activity.RESULT_OK,
+ nextIntent.getIntExtra("com.android.setupwizard.ResultCode", 0));
+ assertEquals("Extra data should surface as extra in nextIntent", "shazam",
+ nextIntent.getStringExtra("extraData"));
+ }
+
+ @SmallTest
+ public void testIsSetupWizardTrue() {
+ final Intent intent = new Intent();
+ intent.putExtra("firstRun", true);
+ assertTrue("Is setup wizard should be true",
+ WizardManagerHelper.isSetupWizardIntent(intent));
+ }
+
+ @SmallTest
+ public void testIsSetupWizardFalse() {
+ final Intent intent = new Intent();
+ intent.putExtra("firstRun", false);
+ assertFalse("Is setup wizard should be true",
+ WizardManagerHelper.isSetupWizardIntent(intent));
+ }
+}