| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.cyanogenmod.setupwizard; |
| 18 | |
| 19 | |
| 20 | import android.app.Application; |
| 21 | import android.app.StatusBarManager; |
| 22 | import android.content.Context; |
| d34d | 88aba00 | 2015-03-13 18:35:34 -0700 | [diff] [blame] | 23 | import android.content.pm.PackageManager; |
| cretin45 | f654deb | 2015-04-14 17:28:37 -0700 | [diff] [blame] | 24 | import android.os.Handler; |
| cretin45 | e001f97 | 2015-02-19 13:01:28 -0800 | [diff] [blame] | 25 | import android.provider.Settings; |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 26 | |
| cretin45 | 0d31b31 | 2015-03-09 14:49:31 -0700 | [diff] [blame] | 27 | import com.cyanogenmod.setupwizard.util.SetupWizardUtils; |
| 28 | |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 29 | public 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 | |
| cretin45 | 48ca24e | 2015-01-19 14:29:43 -0800 | [diff] [blame] | 35 | public static final String ACTION_FINISHED = "com.cyanogenmod.setupwizard.SETUP_FINISHED"; |
| 36 | |
| cretin45 | 7710855 | 2015-05-07 16:21:10 -0700 | [diff] [blame] | 37 | public static final String ACCOUNT_TYPE_CYANOGEN = "com.cyanogen"; |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 38 | 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"; |
| cretin45 | b076a55 | 2015-05-05 16:44:26 -0700 | [diff] [blame] | 41 | public static final String ACTION_VIEW_LEGAL = "cyanogenmod.intent.action.LEGALESE"; |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 42 | |
| 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"; |
| cretin45 | 8913799 | 2015-01-22 14:17:05 -0800 | [diff] [blame] | 46 | public static final String EXTRA_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar"; |
| cretin45 | 30af327 | 2015-01-23 10:14:07 -0800 | [diff] [blame] | 47 | public static final String EXTRA_USE_IMMERSIVE = "useImmersiveMode"; |
| cretin45 | 3441abd | 2015-02-02 16:44:52 -0800 | [diff] [blame] | 48 | public static final String EXTRA_THEME = "theme"; |
| 49 | public static final String EXTRA_MATERIAL_LIGHT = "material_light"; |
| cretin45 | 7710855 | 2015-05-07 16:21:10 -0700 | [diff] [blame] | 50 | public static final String EXTRA_CKSOP = "cksOp"; |
| 51 | public static final String EXTRA_LOGIN_FOR_KILL_SWITCH = "authCks"; |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 52 | |
| cretin45 | c5e926d | 2015-06-17 13:56:09 -0700 | [diff] [blame^] | 53 | public static final String KEY_DETECT_CAPTIVE_PORTAL = "captive_portal_detection_enabled"; |
| cretin45 | e001f97 | 2015-02-19 13:01:28 -0800 | [diff] [blame] | 54 | |
| d34d | 88aba00 | 2015-03-13 18:35:34 -0700 | [diff] [blame] | 55 | private static final String[] THEME_PACKAGES = { |
| 56 | "org.cyanogenmod.theme.chooser", |
| 57 | "com.cyngn.theme.chooser", |
| 58 | "com.cyngn.themestore" |
| 59 | }; |
| 60 | |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 61 | public static final int REQUEST_CODE_SETUP_WIFI = 0; |
| cretin45 | 30af327 | 2015-01-23 10:14:07 -0800 | [diff] [blame] | 62 | public static final int REQUEST_CODE_SETUP_GMS= 1; |
| cretin45 | 3441abd | 2015-02-02 16:44:52 -0800 | [diff] [blame] | 63 | public static final int REQUEST_CODE_RESTORE_GMS= 2; |
| 64 | public static final int REQUEST_CODE_SETUP_CYANOGEN= 3; |
| cretin45 | e001f97 | 2015-02-19 13:01:28 -0800 | [diff] [blame] | 65 | public static final int REQUEST_CODE_SETUP_CAPTIVE_PORTAL= 4; |
| dhacker29 | 218deb9 | 2015-04-23 22:54:36 -0400 | [diff] [blame] | 66 | public static final int REQUEST_CODE_SETUP_BLUETOOTH= 5; |
| cretin45 | 7710855 | 2015-05-07 16:21:10 -0700 | [diff] [blame] | 67 | public static final int REQUEST_CODE_UNLOCK = 6; |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 68 | |
| cretin45 | f654deb | 2015-04-14 17:28:37 -0700 | [diff] [blame] | 69 | public static final int RADIO_READY_TIMEOUT = 10 * 1000; |
| 70 | |
| 71 | private boolean mIsRadioReady = false; |
| 72 | |
| cretin45 | 7710855 | 2015-05-07 16:21:10 -0700 | [diff] [blame] | 73 | private boolean mIsAuthorized = false; |
| 74 | |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 75 | private StatusBarManager mStatusBarManager; |
| 76 | |
| cretin45 | f654deb | 2015-04-14 17:28:37 -0700 | [diff] [blame] | 77 | 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 | |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 86 | @Override |
| 87 | public void onCreate() { |
| 88 | super.onCreate(); |
| 89 | mStatusBarManager = (StatusBarManager)getSystemService(Context.STATUS_BAR_SERVICE); |
| cretin45 | 0d31b31 | 2015-03-09 14:49:31 -0700 | [diff] [blame] | 90 | 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. |
| d34d | 88aba00 | 2015-03-13 18:35:34 -0700 | [diff] [blame] | 93 | final boolean isOwner = SetupWizardUtils.isOwner(); |
| 94 | if (!isOwner |
| cretin45 | 0d31b31 | 2015-03-09 14:49:31 -0700 | [diff] [blame] | 95 | || Settings.Secure.getInt(getContentResolver(), |
| 96 | Settings.Secure.USER_SETUP_COMPLETE) == 1) { |
| cretin45 | b7c5182 | 2015-06-12 12:24:30 -0700 | [diff] [blame] | 97 | Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1); |
| 98 | Settings.Secure.putInt(getContentResolver(), |
| 99 | Settings.Secure.USER_SETUP_COMPLETE, 1); |
| cretin45 | 0ed67f5 | 2015-03-12 13:50:19 -0700 | [diff] [blame] | 100 | SetupWizardUtils.disableGMSSetupWizard(this); |
| cretin45 | 0d31b31 | 2015-03-09 14:49:31 -0700 | [diff] [blame] | 101 | SetupWizardUtils.disableSetupWizard(this); |
| d34d | 88aba00 | 2015-03-13 18:35:34 -0700 | [diff] [blame] | 102 | if (!isOwner) { |
| 103 | disableThemeComponentsForSecondaryUser(); |
| 104 | } |
| cretin45 | 0d31b31 | 2015-03-09 14:49:31 -0700 | [diff] [blame] | 105 | } else { |
| 106 | disableCaptivePortalDetection(); |
| 107 | } |
| 108 | } catch (Settings.SettingNotFoundException e) { |
| 109 | // Continue with setup |
| 110 | disableCaptivePortalDetection(); |
| 111 | } |
| cretin45 | f654deb | 2015-04-14 17:28:37 -0700 | [diff] [blame] | 112 | 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; |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| cretin45 | 7710855 | 2015-05-07 16:21:10 -0700 | [diff] [blame] | 126 | public boolean isAuthorized() { |
| 127 | return mIsAuthorized; |
| 128 | } |
| 129 | |
| 130 | public void setIsAuthorized(boolean isAuthorized) { |
| 131 | mIsAuthorized = isAuthorized; |
| 132 | } |
| 133 | |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 134 | 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 | } |
| cretin45 | e001f97 | 2015-02-19 13:01:28 -0800 | [diff] [blame] | 143 | |
| 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 | } |
| d34d | 88aba00 | 2015-03-13 18:35:34 -0700 | [diff] [blame] | 151 | |
| 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 | } |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 164 | } |