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 | |
Maarten Derks | e901e0c | 2017-05-22 11:15:44 +0200 | [diff] [blame] | 17 | package com.fairphone.setupwizard; |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 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 | |
Maarten Derks | e901e0c | 2017-05-22 11:15:44 +0200 | [diff] [blame] | 27 | import com.fairphone.setupwizard.util.SetupWizardUtils; |
Roman Birg | fccccda | 2016-04-15 13:09:25 -0700 | [diff] [blame] | 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 | |
Maarten Derks | e901e0c | 2017-05-22 11:15:44 +0200 | [diff] [blame] | 35 | public static final String ACTION_FINISHED = "com.fairphone.fairphone.SETUP_FINISHED"; |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 36 | |
Bharath | 90d4451 | 2021-01-14 18:39:05 +0530 | [diff] [blame] | 37 | public static final String ACTION_SETUP_WIFI = "android.net.wifi.PICK_WIFI_NETWORK"; |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 38 | |
d34d | 68d2ba7 | 2015-12-03 16:52:30 -0800 | [diff] [blame] | 39 | public static final String ACTION_SETUP_FINGERPRINT = "android.settings.FINGERPRINT_SETUP"; |
Ricardo Cerqueira | 8331602 | 2016-08-10 12:33:05 +0100 | [diff] [blame] | 40 | public static final String ACTION_SETUP_LOCKSCREEN = "com.android.settings.SETUP_LOCK_SCREEN"; |
d34d | b28f9c0 | 2015-07-07 17:30:20 -0700 | [diff] [blame] | 41 | |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 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"; |
cretin45 | 8913799 | 2015-01-22 14:17:05 -0800 | [diff] [blame] | 45 | public static final String EXTRA_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar"; |
cretin45 | 30af327 | 2015-01-23 10:14:07 -0800 | [diff] [blame] | 46 | public static final String EXTRA_USE_IMMERSIVE = "useImmersiveMode"; |
cretin45 | 3441abd | 2015-02-02 16:44:52 -0800 | [diff] [blame] | 47 | public static final String EXTRA_THEME = "theme"; |
| 48 | public static final String EXTRA_MATERIAL_LIGHT = "material_light"; |
cretin45 | 7710855 | 2015-05-07 16:21:10 -0700 | [diff] [blame] | 49 | public static final String EXTRA_LOGIN_FOR_KILL_SWITCH = "authCks"; |
d34d | b28f9c0 | 2015-07-07 17:30:20 -0700 | [diff] [blame] | 50 | public static final String EXTRA_TITLE = "title"; |
| 51 | public static final String EXTRA_DETAILS = "details"; |
Adnan Begovic | 7448279 | 2016-03-16 17:09:49 -0700 | [diff] [blame] | 52 | public static final String EXTRA_FRAGMENT = "fragment"; |
| 53 | public static final String EXTRA_ACTION_ID = "actionId"; |
Adnan Begovic | d114a09 | 2016-03-21 10:20:08 -0700 | [diff] [blame] | 54 | public static final String EXTRA_SUPRESS_D2D_SETUP = "suppress_device_to_device_setup"; |
Bharath | 90d4451 | 2021-01-14 18:39:05 +0530 | [diff] [blame] | 55 | public static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar"; |
| 56 | public static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text"; |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 57 | |
cretin45 | c5e926d | 2015-06-17 13:56:09 -0700 | [diff] [blame] | 58 | public static final String KEY_DETECT_CAPTIVE_PORTAL = "captive_portal_detection_enabled"; |
cretin45 | e001f97 | 2015-02-19 13:01:28 -0800 | [diff] [blame] | 59 | |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 60 | public static final int REQUEST_CODE_SETUP_WIFI = 0; |
cretin45 | 30af327 | 2015-01-23 10:14:07 -0800 | [diff] [blame] | 61 | public static final int REQUEST_CODE_SETUP_GMS= 1; |
cretin45 | 3441abd | 2015-02-02 16:44:52 -0800 | [diff] [blame] | 62 | public static final int REQUEST_CODE_RESTORE_GMS= 2; |
cretin45 | e001f97 | 2015-02-19 13:01:28 -0800 | [diff] [blame] | 63 | public static final int REQUEST_CODE_SETUP_CAPTIVE_PORTAL= 4; |
dhacker29 | 218deb9 | 2015-04-23 22:54:36 -0400 | [diff] [blame] | 64 | public static final int REQUEST_CODE_SETUP_BLUETOOTH= 5; |
cretin45 | 7710855 | 2015-05-07 16:21:10 -0700 | [diff] [blame] | 65 | public static final int REQUEST_CODE_UNLOCK = 6; |
d34d | b28f9c0 | 2015-07-07 17:30:20 -0700 | [diff] [blame] | 66 | public static final int REQUEST_CODE_SETUP_FINGERPRINT = 7; |
cretin45 | 8109277 | 2016-04-26 13:43:22 -0700 | [diff] [blame] | 67 | public static final int REQUEST_CODE_VENDOR_SETUP_GMS = 8; |
Ricardo Cerqueira | 8331602 | 2016-08-10 12:33:05 +0100 | [diff] [blame] | 68 | public static final int REQUEST_CODE_SETUP_LOCKSCREEN = 9; |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 69 | |
cretin45 | f654deb | 2015-04-14 17:28:37 -0700 | [diff] [blame] | 70 | public static final int RADIO_READY_TIMEOUT = 10 * 1000; |
| 71 | |
| 72 | private boolean mIsRadioReady = false; |
| 73 | |
cretin45 | 7710855 | 2015-05-07 16:21:10 -0700 | [diff] [blame] | 74 | private boolean mIsAuthorized = false; |
| 75 | |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 76 | private StatusBarManager mStatusBarManager; |
| 77 | |
cretin45 | f654deb | 2015-04-14 17:28:37 -0700 | [diff] [blame] | 78 | private final Handler mHandler = new Handler(); |
| 79 | |
| 80 | private final Runnable mRadioTimeoutRunnable = new Runnable() { |
| 81 | @Override |
| 82 | public void run() { |
| 83 | mIsRadioReady = true; |
| 84 | } |
| 85 | }; |
| 86 | |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 87 | @Override |
| 88 | public void onCreate() { |
| 89 | super.onCreate(); |
| 90 | mStatusBarManager = (StatusBarManager)getSystemService(Context.STATUS_BAR_SERVICE); |
cretin45 | 0d31b31 | 2015-03-09 14:49:31 -0700 | [diff] [blame] | 91 | try { |
| 92 | // Since this is a new component, we need to disable here if the user |
| 93 | // has already been through setup on a previous version. |
d34d | 88aba00 | 2015-03-13 18:35:34 -0700 | [diff] [blame] | 94 | final boolean isOwner = SetupWizardUtils.isOwner(); |
| 95 | if (!isOwner |
cretin45 | 0d31b31 | 2015-03-09 14:49:31 -0700 | [diff] [blame] | 96 | || Settings.Secure.getInt(getContentResolver(), |
| 97 | Settings.Secure.USER_SETUP_COMPLETE) == 1) { |
cretin45 | 1b1b991 | 2016-02-01 15:16:05 -0800 | [diff] [blame] | 98 | Thread t = new Thread(){ |
| 99 | @Override |
| 100 | public void run() { |
Dirk Vogt | ba25e09 | 2016-08-17 12:22:47 +0200 | [diff] [blame] | 101 | Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1); |
| 102 | Settings.Secure.putInt(getContentResolver(), |
| 103 | Settings.Secure.USER_SETUP_COMPLETE, 1); |
| 104 | SetupWizardUtils.disableSetupWizard(SetupWizardApp.this); |
cretin45 | 1b1b991 | 2016-02-01 15:16:05 -0800 | [diff] [blame] | 105 | } |
| 106 | }; |
| 107 | t.run(); |
cretin45 | 0d31b31 | 2015-03-09 14:49:31 -0700 | [diff] [blame] | 108 | } else { |
| 109 | disableCaptivePortalDetection(); |
| 110 | } |
| 111 | } catch (Settings.SettingNotFoundException e) { |
| 112 | // Continue with setup |
| 113 | disableCaptivePortalDetection(); |
| 114 | } |
cretin45 | f654deb | 2015-04-14 17:28:37 -0700 | [diff] [blame] | 115 | mHandler.postDelayed(mRadioTimeoutRunnable, SetupWizardApp.RADIO_READY_TIMEOUT); |
| 116 | } |
| 117 | |
| 118 | public boolean isRadioReady() { |
| 119 | return mIsRadioReady; |
| 120 | } |
| 121 | |
| 122 | public void setRadioReady(boolean radioReady) { |
| 123 | if (!mIsRadioReady && radioReady) { |
| 124 | mHandler.removeCallbacks(mRadioTimeoutRunnable); |
| 125 | } |
| 126 | mIsRadioReady = radioReady; |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 127 | } |
| 128 | |
cretin45 | 7710855 | 2015-05-07 16:21:10 -0700 | [diff] [blame] | 129 | public boolean isAuthorized() { |
| 130 | return mIsAuthorized; |
| 131 | } |
| 132 | |
| 133 | public void setIsAuthorized(boolean isAuthorized) { |
| 134 | mIsAuthorized = isAuthorized; |
| 135 | } |
| 136 | |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 137 | public void disableStatusBar() { |
cretin45 | 8109277 | 2016-04-26 13:43:22 -0700 | [diff] [blame] | 138 | mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND | |
| 139 | StatusBarManager.DISABLE_NOTIFICATION_ALERTS | |
| 140 | StatusBarManager.DISABLE_NOTIFICATION_ICONS | |
| 141 | StatusBarManager.DISABLE_NOTIFICATION_TICKER | |
| 142 | StatusBarManager.DISABLE_RECENT | |
| 143 | StatusBarManager.DISABLE_HOME | |
| 144 | StatusBarManager.DISABLE_SEARCH); |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | public void enableStatusBar() { |
| 148 | mStatusBarManager.disable(StatusBarManager.DISABLE_NONE); |
| 149 | } |
cretin45 | e001f97 | 2015-02-19 13:01:28 -0800 | [diff] [blame] | 150 | |
| 151 | public void disableCaptivePortalDetection() { |
| 152 | Settings.Global.putInt(getContentResolver(), KEY_DETECT_CAPTIVE_PORTAL, 0); |
| 153 | } |
| 154 | |
| 155 | public void enableCaptivePortalDetection() { |
| 156 | Settings.Global.putInt(getContentResolver(), KEY_DETECT_CAPTIVE_PORTAL, 1); |
| 157 | } |
cretin45 | 0328b87 | 2015-01-15 16:04:44 -0800 | [diff] [blame] | 158 | } |