blob: a1d644bb462c301b5ed86429958a9ba23d4d39de [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
cretin450328b872015-01-15 16:04:44 -080037 public static final String ACCOUNT_TYPE_GMS = "com.google";
38
39 public static final String ACTION_SETUP_WIFI = "com.android.net.wifi.SETUP_WIFI_NETWORK";
cretin45b076a552015-05-05 16:44:26 -070040 public static final String ACTION_VIEW_LEGAL = "cyanogenmod.intent.action.LEGALESE";
cretin450328b872015-01-15 16:04:44 -080041
42 public static final String EXTRA_FIRST_RUN = "firstRun";
43 public static final String EXTRA_ALLOW_SKIP = "allowSkip";
44 public static final String EXTRA_AUTO_FINISH = "wifi_auto_finish_on_connect";
cretin4589137992015-01-22 14:17:05 -080045 public static final String EXTRA_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
cretin4530af3272015-01-23 10:14:07 -080046 public static final String EXTRA_USE_IMMERSIVE = "useImmersiveMode";
cretin453441abd2015-02-02 16:44:52 -080047 public static final String EXTRA_THEME = "theme";
48 public static final String EXTRA_MATERIAL_LIGHT = "material_light";
cretin450328b872015-01-15 16:04:44 -080049
cretin45e001f972015-02-19 13:01:28 -080050 private static final String KEY_DETECT_CAPTIVE_PORTAL = "captive_portal_detection_enabled";
51
d34d88aba002015-03-13 18:35:34 -070052 private static final String[] THEME_PACKAGES = {
53 "org.cyanogenmod.theme.chooser",
54 "com.cyngn.theme.chooser",
55 "com.cyngn.themestore"
56 };
57
cretin450328b872015-01-15 16:04:44 -080058 public static final int REQUEST_CODE_SETUP_WIFI = 0;
cretin4530af3272015-01-23 10:14:07 -080059 public static final int REQUEST_CODE_SETUP_GMS= 1;
cretin453441abd2015-02-02 16:44:52 -080060 public static final int REQUEST_CODE_RESTORE_GMS= 2;
61 public static final int REQUEST_CODE_SETUP_CYANOGEN= 3;
cretin45e001f972015-02-19 13:01:28 -080062 public static final int REQUEST_CODE_SETUP_CAPTIVE_PORTAL= 4;
dhacker29218deb92015-04-23 22:54:36 -040063 public static final int REQUEST_CODE_SETUP_BLUETOOTH= 5;
cretin450328b872015-01-15 16:04:44 -080064
cretin45f654deb2015-04-14 17:28:37 -070065 public static final int RADIO_READY_TIMEOUT = 10 * 1000;
66
67 private boolean mIsRadioReady = false;
68
cretin450328b872015-01-15 16:04:44 -080069 private StatusBarManager mStatusBarManager;
70
cretin45f654deb2015-04-14 17:28:37 -070071 private final Handler mHandler = new Handler();
72
73 private final Runnable mRadioTimeoutRunnable = new Runnable() {
74 @Override
75 public void run() {
76 mIsRadioReady = true;
77 }
78 };
79
cretin450328b872015-01-15 16:04:44 -080080 @Override
81 public void onCreate() {
82 super.onCreate();
83 mStatusBarManager = (StatusBarManager)getSystemService(Context.STATUS_BAR_SERVICE);
cretin450d31b312015-03-09 14:49:31 -070084 try {
85 // Since this is a new component, we need to disable here if the user
86 // has already been through setup on a previous version.
d34d88aba002015-03-13 18:35:34 -070087 final boolean isOwner = SetupWizardUtils.isOwner();
88 if (!isOwner
cretin450d31b312015-03-09 14:49:31 -070089 || Settings.Secure.getInt(getContentResolver(),
90 Settings.Secure.USER_SETUP_COMPLETE) == 1) {
cretin450ed67f52015-03-12 13:50:19 -070091 SetupWizardUtils.disableGMSSetupWizard(this);
cretin450d31b312015-03-09 14:49:31 -070092 SetupWizardUtils.disableSetupWizard(this);
d34d88aba002015-03-13 18:35:34 -070093 if (!isOwner) {
94 disableThemeComponentsForSecondaryUser();
95 }
cretin450d31b312015-03-09 14:49:31 -070096 } else {
97 disableCaptivePortalDetection();
98 }
99 } catch (Settings.SettingNotFoundException e) {
100 // Continue with setup
101 disableCaptivePortalDetection();
102 }
cretin45f654deb2015-04-14 17:28:37 -0700103 mHandler.postDelayed(mRadioTimeoutRunnable, SetupWizardApp.RADIO_READY_TIMEOUT);
104 }
105
106 public boolean isRadioReady() {
107 return mIsRadioReady;
108 }
109
110 public void setRadioReady(boolean radioReady) {
111 if (!mIsRadioReady && radioReady) {
112 mHandler.removeCallbacks(mRadioTimeoutRunnable);
113 }
114 mIsRadioReady = radioReady;
cretin450328b872015-01-15 16:04:44 -0800115 }
116
117 public void disableStatusBar() {
118 mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND | StatusBarManager.DISABLE_NOTIFICATION_ALERTS
119 | StatusBarManager.DISABLE_NOTIFICATION_TICKER | StatusBarManager.DISABLE_RECENT | StatusBarManager.DISABLE_HOME
120 | StatusBarManager.DISABLE_SEARCH);
121 }
122
123 public void enableStatusBar() {
124 mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);
125 }
cretin45e001f972015-02-19 13:01:28 -0800126
127 public void disableCaptivePortalDetection() {
128 Settings.Global.putInt(getContentResolver(), KEY_DETECT_CAPTIVE_PORTAL, 0);
129 }
130
131 public void enableCaptivePortalDetection() {
132 Settings.Global.putInt(getContentResolver(), KEY_DETECT_CAPTIVE_PORTAL, 1);
133 }
d34d88aba002015-03-13 18:35:34 -0700134
135 private void disableThemeComponentsForSecondaryUser() {
136 PackageManager pm = getPackageManager();
137 for(String pkgName : THEME_PACKAGES) {
138 try {
139 pm.getApplicationInfo(pkgName, 0);
140 pm.setApplicationEnabledSetting(pkgName,
141 PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER, 0);
142 } catch (PackageManager.NameNotFoundException e) {
143 // don't care
144 }
145 }
146 }
cretin450328b872015-01-15 16:04:44 -0800147}