blob: 985037db61caa29631e3c03902e50adc080e9df1 [file] [log] [blame]
cretin453593f032016-04-20 16:21:05 -07001/*
2 * Copyright (C) 2016 The CyanogenMod Project
Bruno Martins0277e732019-01-18 10:42:41 +00003 * Copyright (C) 2017-2019 The LineageOS Project
cretin453593f032016-04-20 16:21:05 -07004 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Michael Bestasc83309e2018-02-03 17:42:13 +020018package org.lineageos.setupwizard;
cretin453593f032016-04-20 16:21:05 -070019
Michael Bestasc83309e2018-02-03 17:42:13 +020020import static org.lineageos.setupwizard.SetupWizardApp.DISABLE_NAV_KEYS;
21import static org.lineageos.setupwizard.SetupWizardApp.KEY_PRIVACY_GUARD;
22import static org.lineageos.setupwizard.SetupWizardApp.KEY_SEND_METRICS;
cretin453593f032016-04-20 16:21:05 -070023
24import android.app.Activity;
25import android.content.Context;
26import android.content.Intent;
cretin453593f032016-04-20 16:21:05 -070027import android.net.Uri;
28import android.os.Bundle;
29import android.os.RemoteException;
Bruno Martinsa8e278d2018-09-28 08:50:50 +010030import android.os.UserHandle;
cretin453593f032016-04-20 16:21:05 -070031import android.text.Spannable;
32import android.text.SpannableString;
33import android.text.SpannableStringBuilder;
34import android.text.Spanned;
35import android.text.method.LinkMovementMethod;
36import android.text.style.ClickableSpan;
37import android.util.Log;
38import android.view.IWindowManager;
39import android.view.View;
40import android.view.WindowManagerGlobal;
41import android.widget.CheckBox;
cretin453593f032016-04-20 16:21:05 -070042import android.widget.TextView;
43
44import com.android.setupwizardlib.util.WizardManagerHelper;
45
Michael Bestasc83309e2018-02-03 17:42:13 +020046import org.lineageos.setupwizard.R;
cretin453593f032016-04-20 16:21:05 -070047
Abhisek Devkotacc839c92018-01-29 12:41:42 -080048import lineageos.hardware.LineageHardwareManager;
49import lineageos.providers.LineageSettings;
cretin453593f032016-04-20 16:21:05 -070050
51public class LineageSettingsActivity extends BaseSetupWizardActivity {
52
53 public static final String TAG = LineageSettingsActivity.class.getSimpleName();
54
55 public static final String PRIVACY_POLICY_URI = "http://lineageos.org/legal";
56
57 private SetupWizardApp mSetupWizardApp;
58
cretin453593f032016-04-20 16:21:05 -070059 private CheckBox mMetrics;
cretin453593f032016-04-20 16:21:05 -070060 private CheckBox mNavKeys;
61 private CheckBox mPrivacyGuard;
62
Bruno Martins33636d12018-09-17 13:53:31 +010063 private boolean mSupportsKeyDisabler = false;
cretin453593f032016-04-20 16:21:05 -070064
Michael W2236d292018-07-15 15:09:20 +020065 private View.OnClickListener mMetricsClickListener = view -> {
66 boolean checked = !mMetrics.isChecked();
67 mMetrics.setChecked(checked);
68 mSetupWizardApp.getSettingsBundle().putBoolean(KEY_SEND_METRICS, checked);
cretin453593f032016-04-20 16:21:05 -070069 };
70
Michael W2236d292018-07-15 15:09:20 +020071 private View.OnClickListener mNavKeysClickListener = view -> {
72 boolean checked = !mNavKeys.isChecked();
73 mNavKeys.setChecked(checked);
74 mSetupWizardApp.getSettingsBundle().putBoolean(DISABLE_NAV_KEYS, checked);
cretin453593f032016-04-20 16:21:05 -070075 };
76
Michael W2236d292018-07-15 15:09:20 +020077 private View.OnClickListener mPrivacyGuardClickListener = view -> {
78 boolean checked = !mPrivacyGuard.isChecked();
79 mPrivacyGuard.setChecked(checked);
80 mSetupWizardApp.getSettingsBundle().putBoolean(KEY_PRIVACY_GUARD, checked);
cretin453593f032016-04-20 16:21:05 -070081 };
82
83 @Override
84 protected void onCreate(Bundle savedInstanceState) {
85 super.onCreate(savedInstanceState);
86 mSetupWizardApp = (SetupWizardApp) getApplication();
cretin453593f032016-04-20 16:21:05 -070087 setNextText(R.string.next);
88 String privacy_policy = getString(R.string.services_privacy_policy);
89 String policySummary = getString(R.string.services_explanation, privacy_policy);
90 SpannableString ss = new SpannableString(policySummary);
91 ClickableSpan clickableSpan = new ClickableSpan() {
92 @Override
93 public void onClick(View textView) {
94 // At this point of the setup, the device has already been unlocked (if frp
95 // had been enabled), so there should be no issues regarding security
96 final Intent intent = new Intent(Intent.ACTION_VIEW,
97 Uri.parse(PRIVACY_POLICY_URI));
98 try {
99 startActivity(intent);
100 } catch (Exception e) {
101 Log.e(TAG, "Unable to start activity " + intent.toString(), e);
102 }
103 }
104 };
105 ss.setSpan(clickableSpan,
106 policySummary.length() - privacy_policy.length() - 1,
107 policySummary.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
108 TextView privacyPolicy = (TextView) findViewById(R.id.privacy_policy);
109 privacyPolicy.setMovementMethod(LinkMovementMethod.getInstance());
110 privacyPolicy.setText(ss);
111
Michael W2236d292018-07-15 15:09:20 +0200112 View metricsRow = findViewById(R.id.metrics);
113 metricsRow.setOnClickListener(mMetricsClickListener);
Michael Bestasc83309e2018-02-03 17:42:13 +0200114 String metricsHelpImproveLineage =
cretin453593f032016-04-20 16:21:05 -0700115 getString(R.string.services_help_improve_cm, getString(R.string.os_name));
116 String metricsSummary = getString(R.string.services_metrics_label,
Michael Bestasc83309e2018-02-03 17:42:13 +0200117 metricsHelpImproveLineage, getString(R.string.os_name));
cretin453593f032016-04-20 16:21:05 -0700118 final SpannableStringBuilder metricsSpan = new SpannableStringBuilder(metricsSummary);
119 metricsSpan.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD),
Michael Bestasc83309e2018-02-03 17:42:13 +0200120 0, metricsHelpImproveLineage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
cretin453593f032016-04-20 16:21:05 -0700121 TextView metrics = (TextView) findViewById(R.id.enable_metrics_summary);
122 metrics.setText(metricsSpan);
123 mMetrics = (CheckBox) findViewById(R.id.enable_metrics_checkbox);
124
Michael W2236d292018-07-15 15:09:20 +0200125 View navKeysRow = findViewById(R.id.nav_keys);
126 navKeysRow.setOnClickListener(mNavKeysClickListener);
cretin453593f032016-04-20 16:21:05 -0700127 mNavKeys = (CheckBox) findViewById(R.id.nav_keys_checkbox);
Bruno Martins33636d12018-09-17 13:53:31 +0100128 mSupportsKeyDisabler = isKeyDisablerSupported(this);
129 if (mSupportsKeyDisabler) {
Bruno Martins0277e732019-01-18 10:42:41 +0000130 mNavKeys.setChecked(LineageSettings.System.getIntForUser(getContentResolver(),
131 LineageSettings.System.FORCE_SHOW_NAVBAR, 0, UserHandle.USER_CURRENT) != 0);
Bruno Martins33636d12018-09-17 13:53:31 +0100132 } else {
133 navKeysRow.setVisibility(View.GONE);
cretin453593f032016-04-20 16:21:05 -0700134 }
135
Michael W2236d292018-07-15 15:09:20 +0200136 View privacyGuardRow = findViewById(R.id.privacy_guard);
137 privacyGuardRow.setOnClickListener(mPrivacyGuardClickListener);
cretin453593f032016-04-20 16:21:05 -0700138 mPrivacyGuard = (CheckBox) findViewById(R.id.privacy_guard_checkbox);
Abhisek Devkotacc839c92018-01-29 12:41:42 -0800139 mPrivacyGuard.setChecked(LineageSettings.Secure.getInt(getContentResolver(),
140 LineageSettings.Secure.PRIVACY_GUARD_DEFAULT, 0) == 1);
cretin453593f032016-04-20 16:21:05 -0700141 }
142
143 @Override
144 public void onResume() {
145 super.onResume();
146 updateDisableNavkeysOption();
147 updateMetricsOption();
cretin453593f032016-04-20 16:21:05 -0700148 updatePrivacyGuardOption();
149 }
150
151 @Override
152 public void onNavigateBack() {
153 onBackPressed();
154 }
155
156 @Override
157 public void onNavigateNext() {
158 Intent intent = WizardManagerHelper.getNextIntent(getIntent(), Activity.RESULT_OK);
159 startActivityForResult(intent, 1);
160 }
161
cretin45d4cea552016-04-25 11:00:04 -0700162 @Override
163 protected int getTransition() {
164 return TRANSITION_ID_SLIDE;
165 }
166
167 @Override
168 protected int getLayoutResId() {
169 return R.layout.setup_lineage_settings;
170 }
171
172 @Override
173 protected int getTitleResId() {
174 return R.string.setup_services;
175 }
176
177 @Override
178 protected int getIconResId() {
179 return R.drawable.ic_features;
180 }
181
cretin453593f032016-04-20 16:21:05 -0700182 private void updateMetricsOption() {
183 final Bundle myPageBundle = mSetupWizardApp.getSettingsBundle();
184 boolean metricsChecked =
185 !myPageBundle.containsKey(KEY_SEND_METRICS) || myPageBundle
186 .getBoolean(KEY_SEND_METRICS);
187 mMetrics.setChecked(metricsChecked);
188 myPageBundle.putBoolean(KEY_SEND_METRICS, metricsChecked);
189 }
190
cretin453593f032016-04-20 16:21:05 -0700191 private void updateDisableNavkeysOption() {
Bruno Martins33636d12018-09-17 13:53:31 +0100192 if (mSupportsKeyDisabler) {
cretin453593f032016-04-20 16:21:05 -0700193 final Bundle myPageBundle = mSetupWizardApp.getSettingsBundle();
Bruno Martinsa8e278d2018-09-28 08:50:50 +0100194 boolean enabled = LineageSettings.System.getIntForUser(getContentResolver(),
195 LineageSettings.System.FORCE_SHOW_NAVBAR, 0, UserHandle.USER_CURRENT) != 0;
cretin453593f032016-04-20 16:21:05 -0700196 boolean checked = myPageBundle.containsKey(DISABLE_NAV_KEYS) ?
197 myPageBundle.getBoolean(DISABLE_NAV_KEYS) :
198 enabled;
199 mNavKeys.setChecked(checked);
200 myPageBundle.putBoolean(DISABLE_NAV_KEYS, checked);
201 }
202 }
203
204 private void updatePrivacyGuardOption() {
205 final Bundle bundle = mSetupWizardApp.getSettingsBundle();
Abhisek Devkotacc839c92018-01-29 12:41:42 -0800206 boolean enabled = LineageSettings.Secure.getInt(getContentResolver(),
207 LineageSettings.Secure.PRIVACY_GUARD_DEFAULT, 0) != 0;
cretin453593f032016-04-20 16:21:05 -0700208 boolean checked = bundle.containsKey(KEY_PRIVACY_GUARD) ?
209 bundle.getBoolean(KEY_PRIVACY_GUARD) :
210 enabled;
211 mPrivacyGuard.setChecked(checked);
212 bundle.putBoolean(KEY_PRIVACY_GUARD, checked);
213 }
214
Bruno Martins33636d12018-09-17 13:53:31 +0100215 private static boolean isKeyDisablerSupported(Context context) {
Abhisek Devkotacc839c92018-01-29 12:41:42 -0800216 final LineageHardwareManager hardware = LineageHardwareManager.getInstance(context);
Bruno Martins33636d12018-09-17 13:53:31 +0100217 return hardware.isSupported(LineageHardwareManager.FEATURE_KEY_DISABLE);
cretin453593f032016-04-20 16:21:05 -0700218 }
cretin453593f032016-04-20 16:21:05 -0700219}