WizardManagerHelper.java revision bc60ae4e0ee0116facc9bdc21d6da8a470303ce3
1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.setupwizardlib.util; 18 19import android.content.Context; 20import android.content.Intent; 21import android.os.Build.VERSION; 22import android.os.Build.VERSION_CODES; 23import android.provider.Settings; 24 25public class WizardManagerHelper { 26 27 private static final String ACTION_NEXT = "com.android.wizard.NEXT"; 28 29 private static final String EXTRA_SCRIPT_URI = "scriptUri"; 30 private static final String EXTRA_ACTION_ID = "actionId"; 31 private static final String EXTRA_RESULT_CODE = "com.android.setupwizard.ResultCode"; 32 private static final String EXTRA_IS_FIRST_RUN = "firstRun"; 33 34 public static final String EXTRA_THEME = "theme"; 35 public static final String EXTRA_USE_IMMERSIVE_MODE = "useImmersiveMode"; 36 37 public static final String SETTINGS_GLOBAL_DEVICE_PROVISIONED = "device_provisioned"; 38 public static final String SETTINGS_SECURE_USER_SETUP_COMPLETE = "user_setup_complete"; 39 40 public static final String THEME_MATERIAL = "material"; 41 public static final String THEME_MATERIAL_LIGHT = "material_light"; 42 43 /** 44 * Get an intent that will invoke the next step of setup wizard. 45 * 46 * @param originalIntent The original intent that was used to start the step, usually via 47 * Activity.getIntent(). 48 * @param resultCode The result code of the step. See {@link ResultCodes}. 49 * @return A new intent that can be used with startActivityForResult() to start the next step of 50 * the setup flow. 51 */ 52 public static Intent getNextIntent(Intent originalIntent, int resultCode) { 53 return getNextIntent(originalIntent, resultCode, null); 54 } 55 56 /** 57 * Get an intent that will invoke the next step of setup wizard. 58 * 59 * @param originalIntent The original intent that was used to start the step, usually via 60 * Activity.getIntent(). 61 * @param resultCode The result code of the step. See {@link ResultCodes}. 62 * @param data An intent containing extra result data. 63 * @return A new intent that can be used with startActivityForResult() to start the next step of 64 * the setup flow. 65 */ 66 public static Intent getNextIntent(Intent originalIntent, int resultCode, Intent data) { 67 Intent intent = new Intent(ACTION_NEXT); 68 intent.putExtra(EXTRA_SCRIPT_URI, originalIntent.getStringExtra(EXTRA_SCRIPT_URI)); 69 intent.putExtra(EXTRA_ACTION_ID, originalIntent.getStringExtra(EXTRA_ACTION_ID)); 70 intent.putExtra(EXTRA_RESULT_CODE, resultCode); 71 if (data != null && data.getExtras() != null) { 72 intent.putExtras(data.getExtras()); 73 } 74 intent.putExtra(EXTRA_THEME, originalIntent.getStringExtra(EXTRA_THEME)); 75 return intent; 76 } 77 78 /** 79 * Check whether an intent is intended to be used within the setup wizard flow. 80 * 81 * @param intent The intent to be checked, usually from Activity.getIntent(). 82 * @return true if the intent passed in was intended to be used with setup wizard. 83 */ 84 public static boolean isSetupWizardIntent(Intent intent) { 85 return intent.getBooleanExtra(EXTRA_IS_FIRST_RUN, false); 86 } 87 88 /** 89 * Checks whether the current user has completed Setup Wizard. This is true if the current user 90 * has gone through Setup Wizard. The current user may or may not be the device owner and the 91 * device owner may have already completed setup wizard. 92 * 93 * @param context The context to retrieve the settings. 94 * @return true if the current user has completed Setup Wizard. 95 * @see #isDeviceProvisioned(android.content.Context) 96 */ 97 public static boolean isUserSetupComplete(Context context) { 98 if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) { 99 return Settings.Secure.getInt(context.getContentResolver(), 100 SETTINGS_SECURE_USER_SETUP_COMPLETE, 0) == 1; 101 } else { 102 // For versions below JB MR1, there are no user profiles. Just return the global device 103 // provisioned state. 104 return Settings.Secure.getInt(context.getContentResolver(), 105 SETTINGS_GLOBAL_DEVICE_PROVISIONED, 0) == 1; 106 } 107 } 108 109 /** 110 * Checks whether the device is provisioned. This means that the device has gone through Setup 111 * Wizard at least once. Note that the user can still be in Setup Wizard even if this is true, 112 * for a secondary user profile triggered through Settings > Add account. 113 * 114 * @param context The context to retrieve the settings. 115 * @return true if the device is provisioned. 116 * @see #isUserSetupComplete(android.content.Context) 117 */ 118 public static boolean isDeviceProvisioned(Context context) { 119 if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) { 120 return Settings.Global.getInt(context.getContentResolver(), 121 SETTINGS_GLOBAL_DEVICE_PROVISIONED, 0) == 1; 122 } else { 123 return Settings.Secure.getInt(context.getContentResolver(), 124 SETTINGS_GLOBAL_DEVICE_PROVISIONED, 0) == 1; 125 } 126 } 127} 128