blob: a327b3819541e7baafdca521565917406b6294ec [file] [log] [blame]
cretin450328b872015-01-15 16:04:44 -08001/*
2 * Copyright (C) 2013 The CyanogenMod 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.cyanogenmod.setupwizard;
18
19
20import android.app.Application;
21import android.app.StatusBarManager;
22import android.content.Context;
d34d88aba002015-03-13 18:35:34 -070023import android.content.pm.PackageManager;
cretin45f654deb2015-04-14 17:28:37 -070024import android.os.Handler;
cretin45e001f972015-02-19 13:01:28 -080025import android.provider.Settings;
cretin450328b872015-01-15 16:04:44 -080026
cretin450d31b312015-03-09 14:49:31 -070027import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
28
Roman Birgfccccda2016-04-15 13:09:25 -070029import cyanogenmod.providers.CMSettings;
30
cretin450328b872015-01-15 16:04:44 -080031public class SetupWizardApp extends Application {
32
33 public static final String TAG = SetupWizardApp.class.getSimpleName();
34 // Leave this off for release
35 public static final boolean DEBUG = false;
36
cretin4548ca24e2015-01-19 14:29:43 -080037 public static final String ACTION_FINISHED = "com.cyanogenmod.setupwizard.SETUP_FINISHED";
38
cretin4577108552015-05-07 16:21:10 -070039 public static final String ACCOUNT_TYPE_CYANOGEN = "com.cyanogen";
cretin450328b872015-01-15 16:04:44 -080040 public static final String ACCOUNT_TYPE_GMS = "com.google";
41
42 public static final String ACTION_SETUP_WIFI = "com.android.net.wifi.SETUP_WIFI_NETWORK";
cretin45b076a552015-05-05 16:44:26 -070043 public static final String ACTION_VIEW_LEGAL = "cyanogenmod.intent.action.LEGALESE";
cretin450328b872015-01-15 16:04:44 -080044
d34d68d2ba72015-12-03 16:52:30 -080045 public static final String ACTION_SETUP_FINGERPRINT = "android.settings.FINGERPRINT_SETUP";
Ricardo Cerqueira83316022016-08-10 12:33:05 +010046 public static final String ACTION_SETUP_LOCKSCREEN = "com.android.settings.SETUP_LOCK_SCREEN";
d34db28f9c02015-07-07 17:30:20 -070047
cretin450328b872015-01-15 16:04:44 -080048 public static final String EXTRA_FIRST_RUN = "firstRun";
49 public static final String EXTRA_ALLOW_SKIP = "allowSkip";
50 public static final String EXTRA_AUTO_FINISH = "wifi_auto_finish_on_connect";
cretin4589137992015-01-22 14:17:05 -080051 public static final String EXTRA_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
cretin4530af3272015-01-23 10:14:07 -080052 public static final String EXTRA_USE_IMMERSIVE = "useImmersiveMode";
cretin453441abd2015-02-02 16:44:52 -080053 public static final String EXTRA_THEME = "theme";
54 public static final String EXTRA_MATERIAL_LIGHT = "material_light";
cretin4577108552015-05-07 16:21:10 -070055 public static final String EXTRA_CKSOP = "cksOp";
56 public static final String EXTRA_LOGIN_FOR_KILL_SWITCH = "authCks";
d34db28f9c02015-07-07 17:30:20 -070057 public static final String EXTRA_TITLE = "title";
58 public static final String EXTRA_DETAILS = "details";
Adnan Begovic74482792016-03-16 17:09:49 -070059 public static final String EXTRA_FRAGMENT = "fragment";
60 public static final String EXTRA_ACTION_ID = "actionId";
Adnan Begovicd114a092016-03-21 10:20:08 -070061 public static final String EXTRA_SUPRESS_D2D_SETUP = "suppress_device_to_device_setup";
cretin450328b872015-01-15 16:04:44 -080062
cretin45c5e926d2015-06-17 13:56:09 -070063 public static final String KEY_DETECT_CAPTIVE_PORTAL = "captive_portal_detection_enabled";
cretin45e001f972015-02-19 13:01:28 -080064
d34d88aba002015-03-13 18:35:34 -070065 private static final String[] THEME_PACKAGES = {
66 "org.cyanogenmod.theme.chooser",
67 "com.cyngn.theme.chooser",
68 "com.cyngn.themestore"
69 };
70
cretin450328b872015-01-15 16:04:44 -080071 public static final int REQUEST_CODE_SETUP_WIFI = 0;
cretin4530af3272015-01-23 10:14:07 -080072 public static final int REQUEST_CODE_SETUP_GMS= 1;
cretin453441abd2015-02-02 16:44:52 -080073 public static final int REQUEST_CODE_RESTORE_GMS= 2;
74 public static final int REQUEST_CODE_SETUP_CYANOGEN= 3;
cretin45e001f972015-02-19 13:01:28 -080075 public static final int REQUEST_CODE_SETUP_CAPTIVE_PORTAL= 4;
dhacker29218deb92015-04-23 22:54:36 -040076 public static final int REQUEST_CODE_SETUP_BLUETOOTH= 5;
cretin4577108552015-05-07 16:21:10 -070077 public static final int REQUEST_CODE_UNLOCK = 6;
d34db28f9c02015-07-07 17:30:20 -070078 public static final int REQUEST_CODE_SETUP_FINGERPRINT = 7;
cretin4581092772016-04-26 13:43:22 -070079 public static final int REQUEST_CODE_VENDOR_SETUP_GMS = 8;
Ricardo Cerqueira83316022016-08-10 12:33:05 +010080 public static final int REQUEST_CODE_SETUP_LOCKSCREEN = 9;
cretin450328b872015-01-15 16:04:44 -080081
cretin45f654deb2015-04-14 17:28:37 -070082 public static final int RADIO_READY_TIMEOUT = 10 * 1000;
83
84 private boolean mIsRadioReady = false;
85
cretin4577108552015-05-07 16:21:10 -070086 private boolean mIsAuthorized = false;
87
cretin450328b872015-01-15 16:04:44 -080088 private StatusBarManager mStatusBarManager;
89
cretin45f654deb2015-04-14 17:28:37 -070090 private final Handler mHandler = new Handler();
91
92 private final Runnable mRadioTimeoutRunnable = new Runnable() {
93 @Override
94 public void run() {
95 mIsRadioReady = true;
96 }
97 };
98
cretin450328b872015-01-15 16:04:44 -080099 @Override
100 public void onCreate() {
101 super.onCreate();
102 mStatusBarManager = (StatusBarManager)getSystemService(Context.STATUS_BAR_SERVICE);
cretin450d31b312015-03-09 14:49:31 -0700103 try {
104 // Since this is a new component, we need to disable here if the user
105 // has already been through setup on a previous version.
d34d88aba002015-03-13 18:35:34 -0700106 final boolean isOwner = SetupWizardUtils.isOwner();
107 if (!isOwner
cretin450d31b312015-03-09 14:49:31 -0700108 || Settings.Secure.getInt(getContentResolver(),
109 Settings.Secure.USER_SETUP_COMPLETE) == 1) {
cretin451b1b9912016-02-01 15:16:05 -0800110 Thread t = new Thread(){
111 @Override
112 public void run() {
113 Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
114 Settings.Secure.putInt(getContentResolver(),
115 Settings.Secure.USER_SETUP_COMPLETE, 1);
Roman Birgfccccda2016-04-15 13:09:25 -0700116 CMSettings.Secure.putInt(getContentResolver(),
117 CMSettings.Secure.CM_SETUP_WIZARD_COMPLETED, 1);
cretin451b1b9912016-02-01 15:16:05 -0800118 SetupWizardUtils.disableGMSSetupWizard(SetupWizardApp.this);
119 SetupWizardUtils.disableSetupWizard(SetupWizardApp.this);
120 if (!isOwner) {
121 disableThemeComponentsForSecondaryUser();
122 }
123 }
124 };
125 t.run();
cretin450d31b312015-03-09 14:49:31 -0700126 } else {
127 disableCaptivePortalDetection();
128 }
129 } catch (Settings.SettingNotFoundException e) {
130 // Continue with setup
131 disableCaptivePortalDetection();
132 }
cretin45f654deb2015-04-14 17:28:37 -0700133 mHandler.postDelayed(mRadioTimeoutRunnable, SetupWizardApp.RADIO_READY_TIMEOUT);
134 }
135
136 public boolean isRadioReady() {
137 return mIsRadioReady;
138 }
139
140 public void setRadioReady(boolean radioReady) {
141 if (!mIsRadioReady && radioReady) {
142 mHandler.removeCallbacks(mRadioTimeoutRunnable);
143 }
144 mIsRadioReady = radioReady;
cretin450328b872015-01-15 16:04:44 -0800145 }
146
cretin4577108552015-05-07 16:21:10 -0700147 public boolean isAuthorized() {
148 return mIsAuthorized;
149 }
150
151 public void setIsAuthorized(boolean isAuthorized) {
152 mIsAuthorized = isAuthorized;
153 }
154
cretin450328b872015-01-15 16:04:44 -0800155 public void disableStatusBar() {
cretin4581092772016-04-26 13:43:22 -0700156 mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND |
157 StatusBarManager.DISABLE_NOTIFICATION_ALERTS |
158 StatusBarManager.DISABLE_NOTIFICATION_ICONS |
159 StatusBarManager.DISABLE_NOTIFICATION_TICKER |
160 StatusBarManager.DISABLE_RECENT |
161 StatusBarManager.DISABLE_HOME |
162 StatusBarManager.DISABLE_SEARCH);
cretin450328b872015-01-15 16:04:44 -0800163 }
164
165 public void enableStatusBar() {
166 mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);
167 }
cretin45e001f972015-02-19 13:01:28 -0800168
169 public void disableCaptivePortalDetection() {
170 Settings.Global.putInt(getContentResolver(), KEY_DETECT_CAPTIVE_PORTAL, 0);
171 }
172
173 public void enableCaptivePortalDetection() {
174 Settings.Global.putInt(getContentResolver(), KEY_DETECT_CAPTIVE_PORTAL, 1);
175 }
d34d88aba002015-03-13 18:35:34 -0700176
177 private void disableThemeComponentsForSecondaryUser() {
178 PackageManager pm = getPackageManager();
179 for(String pkgName : THEME_PACKAGES) {
180 try {
181 pm.getApplicationInfo(pkgName, 0);
182 pm.setApplicationEnabledSetting(pkgName,
183 PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER, 0);
184 } catch (PackageManager.NameNotFoundException e) {
185 // don't care
186 }
187 }
188 }
cretin450328b872015-01-15 16:04:44 -0800189}