blob: 015e368b8a20944038aa8ad785e65574457f06d6 [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;
cretin45e001f972015-02-19 13:01:28 -080024import android.provider.Settings;
cretin450328b872015-01-15 16:04:44 -080025
cretin450d31b312015-03-09 14:49:31 -070026import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
27
cretin450328b872015-01-15 16:04:44 -080028public class SetupWizardApp extends Application {
29
30 public static final String TAG = SetupWizardApp.class.getSimpleName();
31 // Leave this off for release
32 public static final boolean DEBUG = false;
33
cretin4548ca24e2015-01-19 14:29:43 -080034 public static final String ACTION_FINISHED = "com.cyanogenmod.setupwizard.SETUP_FINISHED";
35
cretin450328b872015-01-15 16:04:44 -080036 public static final String ACCOUNT_TYPE_GMS = "com.google";
37
38 public static final String ACTION_SETUP_WIFI = "com.android.net.wifi.SETUP_WIFI_NETWORK";
39
40 public static final String EXTRA_FIRST_RUN = "firstRun";
41 public static final String EXTRA_ALLOW_SKIP = "allowSkip";
42 public static final String EXTRA_AUTO_FINISH = "wifi_auto_finish_on_connect";
cretin4589137992015-01-22 14:17:05 -080043 public static final String EXTRA_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
cretin4530af3272015-01-23 10:14:07 -080044 public static final String EXTRA_USE_IMMERSIVE = "useImmersiveMode";
cretin453441abd2015-02-02 16:44:52 -080045 public static final String EXTRA_THEME = "theme";
46 public static final String EXTRA_MATERIAL_LIGHT = "material_light";
cretin450328b872015-01-15 16:04:44 -080047
cretin45e001f972015-02-19 13:01:28 -080048 private static final String KEY_DETECT_CAPTIVE_PORTAL = "captive_portal_detection_enabled";
49
d34d88aba002015-03-13 18:35:34 -070050 private static final String[] THEME_PACKAGES = {
51 "org.cyanogenmod.theme.chooser",
52 "com.cyngn.theme.chooser",
53 "com.cyngn.themestore"
54 };
55
cretin450328b872015-01-15 16:04:44 -080056 public static final int REQUEST_CODE_SETUP_WIFI = 0;
cretin4530af3272015-01-23 10:14:07 -080057 public static final int REQUEST_CODE_SETUP_GMS= 1;
cretin453441abd2015-02-02 16:44:52 -080058 public static final int REQUEST_CODE_RESTORE_GMS= 2;
59 public static final int REQUEST_CODE_SETUP_CYANOGEN= 3;
cretin45e001f972015-02-19 13:01:28 -080060 public static final int REQUEST_CODE_SETUP_CAPTIVE_PORTAL= 4;
cretin450328b872015-01-15 16:04:44 -080061
62 private StatusBarManager mStatusBarManager;
63
64 @Override
65 public void onCreate() {
66 super.onCreate();
67 mStatusBarManager = (StatusBarManager)getSystemService(Context.STATUS_BAR_SERVICE);
cretin450d31b312015-03-09 14:49:31 -070068 try {
69 // Since this is a new component, we need to disable here if the user
70 // has already been through setup on a previous version.
d34d88aba002015-03-13 18:35:34 -070071 final boolean isOwner = SetupWizardUtils.isOwner();
72 if (!isOwner
cretin450d31b312015-03-09 14:49:31 -070073 || Settings.Secure.getInt(getContentResolver(),
74 Settings.Secure.USER_SETUP_COMPLETE) == 1) {
cretin450ed67f52015-03-12 13:50:19 -070075 SetupWizardUtils.disableGMSSetupWizard(this);
cretin450d31b312015-03-09 14:49:31 -070076 SetupWizardUtils.disableSetupWizard(this);
d34d88aba002015-03-13 18:35:34 -070077 if (!isOwner) {
78 disableThemeComponentsForSecondaryUser();
79 }
cretin450d31b312015-03-09 14:49:31 -070080 } else {
81 disableCaptivePortalDetection();
82 }
83 } catch (Settings.SettingNotFoundException e) {
84 // Continue with setup
85 disableCaptivePortalDetection();
86 }
cretin450328b872015-01-15 16:04:44 -080087 }
88
89 public void disableStatusBar() {
90 mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND | StatusBarManager.DISABLE_NOTIFICATION_ALERTS
91 | StatusBarManager.DISABLE_NOTIFICATION_TICKER | StatusBarManager.DISABLE_RECENT | StatusBarManager.DISABLE_HOME
92 | StatusBarManager.DISABLE_SEARCH);
93 }
94
95 public void enableStatusBar() {
96 mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);
97 }
cretin45e001f972015-02-19 13:01:28 -080098
99 public void disableCaptivePortalDetection() {
100 Settings.Global.putInt(getContentResolver(), KEY_DETECT_CAPTIVE_PORTAL, 0);
101 }
102
103 public void enableCaptivePortalDetection() {
104 Settings.Global.putInt(getContentResolver(), KEY_DETECT_CAPTIVE_PORTAL, 1);
105 }
d34d88aba002015-03-13 18:35:34 -0700106
107 private void disableThemeComponentsForSecondaryUser() {
108 PackageManager pm = getPackageManager();
109 for(String pkgName : THEME_PACKAGES) {
110 try {
111 pm.getApplicationInfo(pkgName, 0);
112 pm.setApplicationEnabledSetting(pkgName,
113 PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER, 0);
114 } catch (PackageManager.NameNotFoundException e) {
115 // don't care
116 }
117 }
118 }
cretin450328b872015-01-15 16:04:44 -0800119}