blob: 33b005a758dbe95feb3c18074d7f3683a8920f4d [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
cretin450328b872015-01-15 16:04:44 -080029public class SetupWizardApp extends Application {
30
31 public static final String TAG = SetupWizardApp.class.getSimpleName();
32 // Leave this off for release
33 public static final boolean DEBUG = false;
34
cretin4548ca24e2015-01-19 14:29:43 -080035 public static final String ACTION_FINISHED = "com.cyanogenmod.setupwizard.SETUP_FINISHED";
36
cretin4577108552015-05-07 16:21:10 -070037 public static final String ACCOUNT_TYPE_CYANOGEN = "com.cyanogen";
cretin450328b872015-01-15 16:04:44 -080038 public static final String ACCOUNT_TYPE_GMS = "com.google";
39
40 public static final String ACTION_SETUP_WIFI = "com.android.net.wifi.SETUP_WIFI_NETWORK";
cretin45b076a552015-05-05 16:44:26 -070041 public static final String ACTION_VIEW_LEGAL = "cyanogenmod.intent.action.LEGALESE";
cretin450328b872015-01-15 16:04:44 -080042
43 public static final String EXTRA_FIRST_RUN = "firstRun";
44 public static final String EXTRA_ALLOW_SKIP = "allowSkip";
45 public static final String EXTRA_AUTO_FINISH = "wifi_auto_finish_on_connect";
cretin4589137992015-01-22 14:17:05 -080046 public static final String EXTRA_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
cretin4530af3272015-01-23 10:14:07 -080047 public static final String EXTRA_USE_IMMERSIVE = "useImmersiveMode";
cretin453441abd2015-02-02 16:44:52 -080048 public static final String EXTRA_THEME = "theme";
49 public static final String EXTRA_MATERIAL_LIGHT = "material_light";
cretin4577108552015-05-07 16:21:10 -070050 public static final String EXTRA_CKSOP = "cksOp";
51 public static final String EXTRA_LOGIN_FOR_KILL_SWITCH = "authCks";
cretin450328b872015-01-15 16:04:44 -080052
cretin45c5e926d2015-06-17 13:56:09 -070053 public static final String KEY_DETECT_CAPTIVE_PORTAL = "captive_portal_detection_enabled";
cretin45e001f972015-02-19 13:01:28 -080054
d34d88aba002015-03-13 18:35:34 -070055 private static final String[] THEME_PACKAGES = {
56 "org.cyanogenmod.theme.chooser",
57 "com.cyngn.theme.chooser",
58 "com.cyngn.themestore"
59 };
60
cretin450328b872015-01-15 16:04:44 -080061 public static final int REQUEST_CODE_SETUP_WIFI = 0;
cretin4530af3272015-01-23 10:14:07 -080062 public static final int REQUEST_CODE_SETUP_GMS= 1;
cretin453441abd2015-02-02 16:44:52 -080063 public static final int REQUEST_CODE_RESTORE_GMS= 2;
64 public static final int REQUEST_CODE_SETUP_CYANOGEN= 3;
cretin45e001f972015-02-19 13:01:28 -080065 public static final int REQUEST_CODE_SETUP_CAPTIVE_PORTAL= 4;
dhacker29218deb92015-04-23 22:54:36 -040066 public static final int REQUEST_CODE_SETUP_BLUETOOTH= 5;
cretin4577108552015-05-07 16:21:10 -070067 public static final int REQUEST_CODE_UNLOCK = 6;
cretin450328b872015-01-15 16:04:44 -080068
cretin45f654deb2015-04-14 17:28:37 -070069 public static final int RADIO_READY_TIMEOUT = 10 * 1000;
70
71 private boolean mIsRadioReady = false;
72
cretin4577108552015-05-07 16:21:10 -070073 private boolean mIsAuthorized = false;
74
cretin450328b872015-01-15 16:04:44 -080075 private StatusBarManager mStatusBarManager;
76
cretin45f654deb2015-04-14 17:28:37 -070077 private final Handler mHandler = new Handler();
78
79 private final Runnable mRadioTimeoutRunnable = new Runnable() {
80 @Override
81 public void run() {
82 mIsRadioReady = true;
83 }
84 };
85
cretin450328b872015-01-15 16:04:44 -080086 @Override
87 public void onCreate() {
88 super.onCreate();
89 mStatusBarManager = (StatusBarManager)getSystemService(Context.STATUS_BAR_SERVICE);
cretin450d31b312015-03-09 14:49:31 -070090 try {
91 // Since this is a new component, we need to disable here if the user
92 // has already been through setup on a previous version.
d34d88aba002015-03-13 18:35:34 -070093 final boolean isOwner = SetupWizardUtils.isOwner();
94 if (!isOwner
cretin450d31b312015-03-09 14:49:31 -070095 || Settings.Secure.getInt(getContentResolver(),
96 Settings.Secure.USER_SETUP_COMPLETE) == 1) {
cretin45b7c51822015-06-12 12:24:30 -070097 Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
98 Settings.Secure.putInt(getContentResolver(),
99 Settings.Secure.USER_SETUP_COMPLETE, 1);
cretin450ed67f52015-03-12 13:50:19 -0700100 SetupWizardUtils.disableGMSSetupWizard(this);
cretin450d31b312015-03-09 14:49:31 -0700101 SetupWizardUtils.disableSetupWizard(this);
d34d88aba002015-03-13 18:35:34 -0700102 if (!isOwner) {
103 disableThemeComponentsForSecondaryUser();
104 }
cretin450d31b312015-03-09 14:49:31 -0700105 } else {
106 disableCaptivePortalDetection();
107 }
108 } catch (Settings.SettingNotFoundException e) {
109 // Continue with setup
110 disableCaptivePortalDetection();
111 }
cretin45f654deb2015-04-14 17:28:37 -0700112 mHandler.postDelayed(mRadioTimeoutRunnable, SetupWizardApp.RADIO_READY_TIMEOUT);
113 }
114
115 public boolean isRadioReady() {
116 return mIsRadioReady;
117 }
118
119 public void setRadioReady(boolean radioReady) {
120 if (!mIsRadioReady && radioReady) {
121 mHandler.removeCallbacks(mRadioTimeoutRunnable);
122 }
123 mIsRadioReady = radioReady;
cretin450328b872015-01-15 16:04:44 -0800124 }
125
cretin4577108552015-05-07 16:21:10 -0700126 public boolean isAuthorized() {
127 return mIsAuthorized;
128 }
129
130 public void setIsAuthorized(boolean isAuthorized) {
131 mIsAuthorized = isAuthorized;
132 }
133
cretin450328b872015-01-15 16:04:44 -0800134 public void disableStatusBar() {
135 mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND | StatusBarManager.DISABLE_NOTIFICATION_ALERTS
136 | StatusBarManager.DISABLE_NOTIFICATION_TICKER | StatusBarManager.DISABLE_RECENT | StatusBarManager.DISABLE_HOME
137 | StatusBarManager.DISABLE_SEARCH);
138 }
139
140 public void enableStatusBar() {
141 mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);
142 }
cretin45e001f972015-02-19 13:01:28 -0800143
144 public void disableCaptivePortalDetection() {
145 Settings.Global.putInt(getContentResolver(), KEY_DETECT_CAPTIVE_PORTAL, 0);
146 }
147
148 public void enableCaptivePortalDetection() {
149 Settings.Global.putInt(getContentResolver(), KEY_DETECT_CAPTIVE_PORTAL, 1);
150 }
d34d88aba002015-03-13 18:35:34 -0700151
152 private void disableThemeComponentsForSecondaryUser() {
153 PackageManager pm = getPackageManager();
154 for(String pkgName : THEME_PACKAGES) {
155 try {
156 pm.getApplicationInfo(pkgName, 0);
157 pm.setApplicationEnabledSetting(pkgName,
158 PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER, 0);
159 } catch (PackageManager.NameNotFoundException e) {
160 // don't care
161 }
162 }
163 }
cretin450328b872015-01-15 16:04:44 -0800164}