| 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 | e001f97 | 2015-02-19 13:01:28 -0800 | [diff] [blame] | 24 | import android.provider.Settings; |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 25 | |
| cretin45 | 0d31b31 | 2015-03-09 14:49:31 -0700 | [diff] [blame] | 26 | import com.cyanogenmod.setupwizard.util.SetupWizardUtils; |
| 27 | |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 28 | public 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 | |
| cretin45 | 48ca24e | 2015-01-19 14:29:43 -0800 | [diff] [blame] | 34 | public static final String ACTION_FINISHED = "com.cyanogenmod.setupwizard.SETUP_FINISHED"; |
| 35 | |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 36 | 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"; |
| cretin45 | 8913799 | 2015-01-22 14:17:05 -0800 | [diff] [blame] | 43 | public static final String EXTRA_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar"; |
| cretin45 | 30af327 | 2015-01-23 10:14:07 -0800 | [diff] [blame] | 44 | public static final String EXTRA_USE_IMMERSIVE = "useImmersiveMode"; |
| cretin45 | 3441abd | 2015-02-02 16:44:52 -0800 | [diff] [blame] | 45 | public static final String EXTRA_THEME = "theme"; |
| 46 | public static final String EXTRA_MATERIAL_LIGHT = "material_light"; |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 47 | |
| cretin45 | e001f97 | 2015-02-19 13:01:28 -0800 | [diff] [blame] | 48 | private static final String KEY_DETECT_CAPTIVE_PORTAL = "captive_portal_detection_enabled"; |
| 49 | |
| d34d | 88aba00 | 2015-03-13 18:35:34 -0700 | [diff] [blame^] | 50 | private static final String[] THEME_PACKAGES = { |
| 51 | "org.cyanogenmod.theme.chooser", |
| 52 | "com.cyngn.theme.chooser", |
| 53 | "com.cyngn.themestore" |
| 54 | }; |
| 55 | |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 56 | public static final int REQUEST_CODE_SETUP_WIFI = 0; |
| cretin45 | 30af327 | 2015-01-23 10:14:07 -0800 | [diff] [blame] | 57 | public static final int REQUEST_CODE_SETUP_GMS= 1; |
| cretin45 | 3441abd | 2015-02-02 16:44:52 -0800 | [diff] [blame] | 58 | public static final int REQUEST_CODE_RESTORE_GMS= 2; |
| 59 | public static final int REQUEST_CODE_SETUP_CYANOGEN= 3; |
| cretin45 | e001f97 | 2015-02-19 13:01:28 -0800 | [diff] [blame] | 60 | public static final int REQUEST_CODE_SETUP_CAPTIVE_PORTAL= 4; |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 61 | |
| 62 | private StatusBarManager mStatusBarManager; |
| 63 | |
| 64 | @Override |
| 65 | public void onCreate() { |
| 66 | super.onCreate(); |
| 67 | mStatusBarManager = (StatusBarManager)getSystemService(Context.STATUS_BAR_SERVICE); |
| cretin45 | 0d31b31 | 2015-03-09 14:49:31 -0700 | [diff] [blame] | 68 | 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. |
| d34d | 88aba00 | 2015-03-13 18:35:34 -0700 | [diff] [blame^] | 71 | final boolean isOwner = SetupWizardUtils.isOwner(); |
| 72 | if (!isOwner |
| cretin45 | 0d31b31 | 2015-03-09 14:49:31 -0700 | [diff] [blame] | 73 | || Settings.Secure.getInt(getContentResolver(), |
| 74 | Settings.Secure.USER_SETUP_COMPLETE) == 1) { |
| cretin45 | 0ed67f5 | 2015-03-12 13:50:19 -0700 | [diff] [blame] | 75 | SetupWizardUtils.disableGMSSetupWizard(this); |
| cretin45 | 0d31b31 | 2015-03-09 14:49:31 -0700 | [diff] [blame] | 76 | SetupWizardUtils.disableSetupWizard(this); |
| d34d | 88aba00 | 2015-03-13 18:35:34 -0700 | [diff] [blame^] | 77 | if (!isOwner) { |
| 78 | disableThemeComponentsForSecondaryUser(); |
| 79 | } |
| cretin45 | 0d31b31 | 2015-03-09 14:49:31 -0700 | [diff] [blame] | 80 | } else { |
| 81 | disableCaptivePortalDetection(); |
| 82 | } |
| 83 | } catch (Settings.SettingNotFoundException e) { |
| 84 | // Continue with setup |
| 85 | disableCaptivePortalDetection(); |
| 86 | } |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 87 | } |
| 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 | } |
| cretin45 | e001f97 | 2015-02-19 13:01:28 -0800 | [diff] [blame] | 98 | |
| 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 | } |
| d34d | 88aba00 | 2015-03-13 18:35:34 -0700 | [diff] [blame^] | 106 | |
| 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 | } |
| cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 119 | } |