blob: eaea742b890a86521c676f74e762c5338a63fbbd [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
Maarten Derkse901e0c2017-05-22 11:15:44 +020017package com.fairphone.setupwizard;
cretin450328b872015-01-15 16:04:44 -080018
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
Maarten Derkse901e0c2017-05-22 11:15:44 +020027import com.fairphone.setupwizard.util.SetupWizardUtils;
Roman Birgfccccda2016-04-15 13:09:25 -070028
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
Maarten Derkse901e0c2017-05-22 11:15:44 +020035 public static final String ACTION_FINISHED = "com.fairphone.fairphone.SETUP_FINISHED";
cretin450328b872015-01-15 16:04:44 -080036
37 public static final String ACTION_SETUP_WIFI = "com.android.net.wifi.SETUP_WIFI_NETWORK";
38
d34d68d2ba72015-12-03 16:52:30 -080039 public static final String ACTION_SETUP_FINGERPRINT = "android.settings.FINGERPRINT_SETUP";
Ricardo Cerqueira83316022016-08-10 12:33:05 +010040 public static final String ACTION_SETUP_LOCKSCREEN = "com.android.settings.SETUP_LOCK_SCREEN";
d34db28f9c02015-07-07 17:30:20 -070041
cretin450328b872015-01-15 16:04:44 -080042 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";
cretin4577108552015-05-07 16:21:10 -070049 public static final String EXTRA_LOGIN_FOR_KILL_SWITCH = "authCks";
d34db28f9c02015-07-07 17:30:20 -070050 public static final String EXTRA_TITLE = "title";
51 public static final String EXTRA_DETAILS = "details";
Adnan Begovic74482792016-03-16 17:09:49 -070052 public static final String EXTRA_FRAGMENT = "fragment";
53 public static final String EXTRA_ACTION_ID = "actionId";
Adnan Begovicd114a092016-03-21 10:20:08 -070054 public static final String EXTRA_SUPRESS_D2D_SETUP = "suppress_device_to_device_setup";
cretin450328b872015-01-15 16:04:44 -080055
cretin45c5e926d2015-06-17 13:56:09 -070056 public static final String KEY_DETECT_CAPTIVE_PORTAL = "captive_portal_detection_enabled";
cretin45e001f972015-02-19 13:01:28 -080057
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;
cretin45e001f972015-02-19 13:01:28 -080061 public static final int REQUEST_CODE_SETUP_CAPTIVE_PORTAL= 4;
dhacker29218deb92015-04-23 22:54:36 -040062 public static final int REQUEST_CODE_SETUP_BLUETOOTH= 5;
cretin4577108552015-05-07 16:21:10 -070063 public static final int REQUEST_CODE_UNLOCK = 6;
d34db28f9c02015-07-07 17:30:20 -070064 public static final int REQUEST_CODE_SETUP_FINGERPRINT = 7;
cretin4581092772016-04-26 13:43:22 -070065 public static final int REQUEST_CODE_VENDOR_SETUP_GMS = 8;
Ricardo Cerqueira83316022016-08-10 12:33:05 +010066 public static final int REQUEST_CODE_SETUP_LOCKSCREEN = 9;
cretin450328b872015-01-15 16:04:44 -080067
cretin45f654deb2015-04-14 17:28:37 -070068 public static final int RADIO_READY_TIMEOUT = 10 * 1000;
69
70 private boolean mIsRadioReady = false;
71
cretin4577108552015-05-07 16:21:10 -070072 private boolean mIsAuthorized = false;
73
cretin450328b872015-01-15 16:04:44 -080074 private StatusBarManager mStatusBarManager;
75
cretin45f654deb2015-04-14 17:28:37 -070076 private final Handler mHandler = new Handler();
77
78 private final Runnable mRadioTimeoutRunnable = new Runnable() {
79 @Override
80 public void run() {
81 mIsRadioReady = true;
82 }
83 };
84
cretin450328b872015-01-15 16:04:44 -080085 @Override
86 public void onCreate() {
87 super.onCreate();
88 mStatusBarManager = (StatusBarManager)getSystemService(Context.STATUS_BAR_SERVICE);
cretin450d31b312015-03-09 14:49:31 -070089 try {
90 // Since this is a new component, we need to disable here if the user
91 // has already been through setup on a previous version.
d34d88aba002015-03-13 18:35:34 -070092 final boolean isOwner = SetupWizardUtils.isOwner();
93 if (!isOwner
cretin450d31b312015-03-09 14:49:31 -070094 || Settings.Secure.getInt(getContentResolver(),
95 Settings.Secure.USER_SETUP_COMPLETE) == 1) {
cretin451b1b9912016-02-01 15:16:05 -080096 Thread t = new Thread(){
97 @Override
98 public void run() {
Dirk Vogtba25e092016-08-17 12:22:47 +020099 Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
100 Settings.Secure.putInt(getContentResolver(),
101 Settings.Secure.USER_SETUP_COMPLETE, 1);
102 SetupWizardUtils.disableSetupWizard(SetupWizardApp.this);
cretin451b1b9912016-02-01 15:16:05 -0800103 }
104 };
105 t.run();
cretin450d31b312015-03-09 14:49:31 -0700106 } else {
107 disableCaptivePortalDetection();
108 }
109 } catch (Settings.SettingNotFoundException e) {
110 // Continue with setup
111 disableCaptivePortalDetection();
112 }
cretin45f654deb2015-04-14 17:28:37 -0700113 mHandler.postDelayed(mRadioTimeoutRunnable, SetupWizardApp.RADIO_READY_TIMEOUT);
114 }
115
116 public boolean isRadioReady() {
117 return mIsRadioReady;
118 }
119
120 public void setRadioReady(boolean radioReady) {
121 if (!mIsRadioReady && radioReady) {
122 mHandler.removeCallbacks(mRadioTimeoutRunnable);
123 }
124 mIsRadioReady = radioReady;
cretin450328b872015-01-15 16:04:44 -0800125 }
126
cretin4577108552015-05-07 16:21:10 -0700127 public boolean isAuthorized() {
128 return mIsAuthorized;
129 }
130
131 public void setIsAuthorized(boolean isAuthorized) {
132 mIsAuthorized = isAuthorized;
133 }
134
cretin450328b872015-01-15 16:04:44 -0800135 public void disableStatusBar() {
cretin4581092772016-04-26 13:43:22 -0700136 mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND |
137 StatusBarManager.DISABLE_NOTIFICATION_ALERTS |
138 StatusBarManager.DISABLE_NOTIFICATION_ICONS |
139 StatusBarManager.DISABLE_NOTIFICATION_TICKER |
140 StatusBarManager.DISABLE_RECENT |
141 StatusBarManager.DISABLE_HOME |
142 StatusBarManager.DISABLE_SEARCH);
cretin450328b872015-01-15 16:04:44 -0800143 }
144
145 public void enableStatusBar() {
146 mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);
147 }
cretin45e001f972015-02-19 13:01:28 -0800148
149 public void disableCaptivePortalDetection() {
150 Settings.Global.putInt(getContentResolver(), KEY_DETECT_CAPTIVE_PORTAL, 0);
151 }
152
153 public void enableCaptivePortalDetection() {
154 Settings.Global.putInt(getContentResolver(), KEY_DETECT_CAPTIVE_PORTAL, 1);
155 }
cretin450328b872015-01-15 16:04:44 -0800156}