blob: a1e8fe4c9ffba918fe5f907d556865dfb2d1d57c [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
Bharath90d44512021-01-14 18:39:05 +053037 public static final String ACTION_SETUP_WIFI = "android.net.wifi.PICK_WIFI_NETWORK";
cretin450328b872015-01-15 16:04:44 -080038
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";
Bharath90d44512021-01-14 18:39:05 +053055 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";
cretin450328b872015-01-15 16:04:44 -080057
cretin45c5e926d2015-06-17 13:56:09 -070058 public static final String KEY_DETECT_CAPTIVE_PORTAL = "captive_portal_detection_enabled";
cretin45e001f972015-02-19 13:01:28 -080059
cretin450328b872015-01-15 16:04:44 -080060 public static final int REQUEST_CODE_SETUP_WIFI = 0;
cretin4530af3272015-01-23 10:14:07 -080061 public static final int REQUEST_CODE_SETUP_GMS= 1;
cretin453441abd2015-02-02 16:44:52 -080062 public static final int REQUEST_CODE_RESTORE_GMS= 2;
cretin45e001f972015-02-19 13:01:28 -080063 public static final int REQUEST_CODE_SETUP_CAPTIVE_PORTAL= 4;
dhacker29218deb92015-04-23 22:54:36 -040064 public static final int REQUEST_CODE_SETUP_BLUETOOTH= 5;
cretin4577108552015-05-07 16:21:10 -070065 public static final int REQUEST_CODE_UNLOCK = 6;
d34db28f9c02015-07-07 17:30:20 -070066 public static final int REQUEST_CODE_SETUP_FINGERPRINT = 7;
cretin4581092772016-04-26 13:43:22 -070067 public static final int REQUEST_CODE_VENDOR_SETUP_GMS = 8;
Ricardo Cerqueira83316022016-08-10 12:33:05 +010068 public static final int REQUEST_CODE_SETUP_LOCKSCREEN = 9;
cretin450328b872015-01-15 16:04:44 -080069
cretin45f654deb2015-04-14 17:28:37 -070070 public static final int RADIO_READY_TIMEOUT = 10 * 1000;
71
72 private boolean mIsRadioReady = false;
73
cretin4577108552015-05-07 16:21:10 -070074 private boolean mIsAuthorized = false;
75
cretin450328b872015-01-15 16:04:44 -080076 private StatusBarManager mStatusBarManager;
77
cretin45f654deb2015-04-14 17:28:37 -070078 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
cretin450328b872015-01-15 16:04:44 -080087 @Override
88 public void onCreate() {
89 super.onCreate();
90 mStatusBarManager = (StatusBarManager)getSystemService(Context.STATUS_BAR_SERVICE);
cretin450d31b312015-03-09 14:49:31 -070091 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.
d34d88aba002015-03-13 18:35:34 -070094 final boolean isOwner = SetupWizardUtils.isOwner();
95 if (!isOwner
cretin450d31b312015-03-09 14:49:31 -070096 || Settings.Secure.getInt(getContentResolver(),
97 Settings.Secure.USER_SETUP_COMPLETE) == 1) {
cretin451b1b9912016-02-01 15:16:05 -080098 Thread t = new Thread(){
99 @Override
100 public void run() {
Dirk Vogtba25e092016-08-17 12:22:47 +0200101 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);
cretin451b1b9912016-02-01 15:16:05 -0800105 }
106 };
107 t.run();
cretin450d31b312015-03-09 14:49:31 -0700108 } else {
109 disableCaptivePortalDetection();
110 }
111 } catch (Settings.SettingNotFoundException e) {
112 // Continue with setup
113 disableCaptivePortalDetection();
114 }
cretin45f654deb2015-04-14 17:28:37 -0700115 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;
cretin450328b872015-01-15 16:04:44 -0800127 }
128
cretin4577108552015-05-07 16:21:10 -0700129 public boolean isAuthorized() {
130 return mIsAuthorized;
131 }
132
133 public void setIsAuthorized(boolean isAuthorized) {
134 mIsAuthorized = isAuthorized;
135 }
136
cretin450328b872015-01-15 16:04:44 -0800137 public void disableStatusBar() {
cretin4581092772016-04-26 13:43:22 -0700138 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);
cretin450328b872015-01-15 16:04:44 -0800145 }
146
147 public void enableStatusBar() {
148 mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);
149 }
cretin45e001f972015-02-19 13:01:28 -0800150
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 }
cretin450328b872015-01-15 16:04:44 -0800158}