-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSetupWizardApp.java
185 lines (159 loc) · 7.98 KB
/
SetupWizardApp.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* Copyright (C) 2013 The CyanogenMod Project
* Copyright (C) 2017-2022 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.lineageos.setupwizard;
import static android.os.UserHandle.USER_CURRENT;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY;
import android.app.AppOpsManager;
import android.app.Application;
import android.app.StatusBarManager;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.content.ComponentName;
import android.content.Context;
import android.content.om.IOverlayManager;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.service.oemlock.OemLockManager;
import android.util.Log;
import org.lineageos.setupwizard.util.NetworkMonitor;
import org.lineageos.setupwizard.util.PhoneMonitor;
import org.lineageos.setupwizard.util.SetupWizardUtils;
public class SetupWizardApp extends Application {
public static final String TAG = SetupWizardApp.class.getSimpleName();
// Verbose logging
public static final boolean LOGV = Log.isLoggable(TAG, Log.VERBOSE);
public static final String ACTION_ACCESSIBILITY_SETTINGS =
"android.settings.ACCESSIBILITY_SETTINGS_FOR_SUW";
public static final String ACTION_SETUP_COMPLETE =
"org.lineageos.setupwizard.LINEAGE_SETUP_COMPLETE";
public static final String ACTION_FINISHED = "org.lineageos.setupwizard.SETUP_FINISHED";
public static final String ACTION_SETUP_NETWORK = "android.settings.NETWORK_PROVIDER_SETUP";
public static final String ACTION_APPS_INSTALLED =
"org.lineageos.setupwizard.LINEAGE_APPS_INSTALLED";
public static final String ACTION_SETUP_BIOMETRIC = "android.settings.BIOMETRIC_ENROLL";
public static final String ACTION_SETUP_LOCKSCREEN = "com.android.settings.SETUP_LOCK_SCREEN";
public static final String ACTION_SETUP_INSTALL = "org.calyxos.lupin.INSTALL";
public static final String ACTION_RESTORE_FROM_BACKUP =
"com.stevesoltys.seedvault.RESTORE_BACKUP";
public static final String ACTION_EMERGENCY_DIAL = "com.android.phone.EmergencyDialer.DIAL";
public static final String ACTION_NEXT = "com.android.wizard.NEXT";
public static final String ACTION_LOAD = "com.android.wizard.LOAD";
public static final String EXTRA_HAS_MULTIPLE_USERS = "hasMultipleUsers";
public static final String EXTRA_TITLE = "title";
public static final String EXTRA_DETAILS = "details";
public static final String EXTRA_SCRIPT_URI = "scriptUri";
public static final String EXTRA_ACTION_ID = "actionId";
public static final String EXTRA_RESULT_CODE = "com.android.setupwizard.ResultCode";
public static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
public static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
public static final String EXTRA_PREFS_SHOW_SKIP_TV = "extra_show_skip_network";
public static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
public static final String EXTRA_ENABLE_NEXT_ON_CONNECT = "wifi_enable_next_on_connect";
public static final String KEY_DETECT_CAPTIVE_PORTAL = "captive_portal_detection_enabled";
public static final String AURORA_SERVICES_PACKAGE = "com.aurora.services";
public static final String FDROID_PACKAGE = "org.fdroid.fdroid";
public static final String FDROID_CATEGORY_DEFAULT = "Default";
public static final String FDROID_CATEGORY_DEFAULT_BACKEND = "DefaultBackend";
public static final String FDROID_UPDATEJOBSERVICE_CLASS = ".UpdateJobService";
// Must match F-Droid's UpdateService JOB_ID
public static final int FDROID_UPDATE_JOB_ID = 0xfedcba;
public static final String PACKAGENAMES = "packageNames";
public static final String NAVIGATION_OPTION_KEY = "navigation_option";
public static final int REQUEST_CODE_SETUP_NETWORK = 0;
public static final int REQUEST_CODE_SETUP_CAPTIVE_PORTAL = 4;
public static final int REQUEST_CODE_SETUP_BLUETOOTH = 5;
public static final int REQUEST_CODE_SETUP_BIOMETRIC = 7;
public static final int REQUEST_CODE_SETUP_LOCKSCREEN = 9;
public static final int REQUEST_CODE_SETUP_INSTALL = 10;
public static final int REQUEST_CODE_RESTORE = 11;
public static final int REQUEST_CODE_SETUP_EUICC = 12;
public static final int RADIO_READY_TIMEOUT = 10 * 1000;
private static StatusBarManager sStatusBarManager;
private boolean mIsRadioReady = false;
private boolean mIgnoreSimLocale = false;
private final Bundle mSettingsBundle = new Bundle();
private final Handler mHandler = new Handler();
private final Runnable mRadioTimeoutRunnable = () -> mIsRadioReady = true;
@Override
public void onCreate() {
super.onCreate();
if (LOGV) {
Log.v(TAG, "onCreate()");
}
NetworkMonitor.initInstance(this);
PhoneMonitor.initInstance(this);
SetupWizardUtils.disableComponentsForMissingFeatures(this);
if (SetupWizardUtils.isOwner()) {
SetupWizardUtils.setMobileDataEnabled(this, false);
}
sStatusBarManager = SetupWizardUtils.disableStatusBar(this);
if (SetupWizardUtils.isPackageInstalled(this, NAV_BAR_MODE_GESTURAL_OVERLAY)) {
IOverlayManager overlayManager = IOverlayManager.Stub.asInterface(
ServiceManager.getService(Context.OVERLAY_SERVICE));
try {
overlayManager.setEnabledExclusiveInCategory(NAV_BAR_MODE_GESTURAL_OVERLAY,
USER_CURRENT);
} catch (Exception e) {}
}
mHandler.postDelayed(mRadioTimeoutRunnable, SetupWizardApp.RADIO_READY_TIMEOUT);
scheduleIndexUpdateJob();
// If the bootloader is locked, and OEM unlocking is allowed, turn it off
if (SetupWizardUtils.isOwner()
&& !SetupWizardUtils.isBootloaderUnlocked(this)
&& SetupWizardUtils.isOemunlockAllowed(this)) {
getSystemService(OemLockManager.class).setOemUnlockAllowedByUser(false);
}
try {
getSystemService(AppOpsManager.class).setMode(AppOpsManager.OP_REQUEST_INSTALL_PACKAGES,
getPackageManager().getPackageUid(AURORA_SERVICES_PACKAGE, 0),
AURORA_SERVICES_PACKAGE,
AppOpsManager.MODE_ALLOWED);
} catch (PackageManager.NameNotFoundException e) {
}
}
public static StatusBarManager getStatusBarManager() {
return sStatusBarManager;
}
public boolean isRadioReady() {
return mIsRadioReady;
}
public void setRadioReady(boolean radioReady) {
if (!mIsRadioReady && radioReady) {
mHandler.removeCallbacks(mRadioTimeoutRunnable);
}
mIsRadioReady = radioReady;
}
public boolean ignoreSimLocale() {
return mIgnoreSimLocale;
}
public void setIgnoreSimLocale(boolean ignoreSimLocale) {
mIgnoreSimLocale = ignoreSimLocale;
}
public Bundle getSettingsBundle() {
return mSettingsBundle;
}
public int scheduleIndexUpdateJob() {
return getSystemService(JobScheduler.class).scheduleAsPackage(new JobInfo.Builder(
FDROID_UPDATE_JOB_ID,
new ComponentName(FDROID_PACKAGE, FDROID_PACKAGE + FDROID_UPDATEJOBSERVICE_CLASS))
.setOverrideDeadline(0)
.build(), FDROID_PACKAGE, UserHandle.myUserId(), TAG);
}
}