blob: c3bb913b2231d589ca6a498edd2c0e657389d2a8 [file] [log] [blame]
cretin453593f032016-04-20 16:21:05 -07001/*
2 * Copyright (C) 2016 The CyanogenMod Project
Bruno Martins33636d12018-09-17 13:53:31 +01003 * Copyright (C) 2017-2018 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;
30import android.text.Spannable;
31import android.text.SpannableString;
32import android.text.SpannableStringBuilder;
33import android.text.Spanned;
34import android.text.method.LinkMovementMethod;
35import android.text.style.ClickableSpan;
36import android.util.Log;
37import android.view.IWindowManager;
38import android.view.View;
39import android.view.WindowManagerGlobal;
40import android.widget.CheckBox;
cretin453593f032016-04-20 16:21:05 -070041import android.widget.TextView;
42
43import com.android.setupwizardlib.util.WizardManagerHelper;
44
Michael Bestasc83309e2018-02-03 17:42:13 +020045import org.lineageos.setupwizard.R;
cretin453593f032016-04-20 16:21:05 -070046
Abhisek Devkotacc839c92018-01-29 12:41:42 -080047import lineageos.hardware.LineageHardwareManager;
48import lineageos.providers.LineageSettings;
cretin453593f032016-04-20 16:21:05 -070049
50public class LineageSettingsActivity extends BaseSetupWizardActivity {
51
52 public static final String TAG = LineageSettingsActivity.class.getSimpleName();
53
54 public static final String PRIVACY_POLICY_URI = "http://lineageos.org/legal";
55
56 private SetupWizardApp mSetupWizardApp;
57
cretin453593f032016-04-20 16:21:05 -070058 private CheckBox mMetrics;
cretin453593f032016-04-20 16:21:05 -070059 private CheckBox mNavKeys;
60 private CheckBox mPrivacyGuard;
61
Bruno Martins33636d12018-09-17 13:53:31 +010062 private boolean mSupportsKeyDisabler = false;
cretin453593f032016-04-20 16:21:05 -070063
Michael W2236d292018-07-15 15:09:20 +020064 private View.OnClickListener mMetricsClickListener = view -> {
65 boolean checked = !mMetrics.isChecked();
66 mMetrics.setChecked(checked);
67 mSetupWizardApp.getSettingsBundle().putBoolean(KEY_SEND_METRICS, checked);
cretin453593f032016-04-20 16:21:05 -070068 };
69
Michael W2236d292018-07-15 15:09:20 +020070 private View.OnClickListener mNavKeysClickListener = view -> {
71 boolean checked = !mNavKeys.isChecked();
72 mNavKeys.setChecked(checked);
73 mSetupWizardApp.getSettingsBundle().putBoolean(DISABLE_NAV_KEYS, checked);
cretin453593f032016-04-20 16:21:05 -070074 };
75
Michael W2236d292018-07-15 15:09:20 +020076 private View.OnClickListener mPrivacyGuardClickListener = view -> {
77 boolean checked = !mPrivacyGuard.isChecked();
78 mPrivacyGuard.setChecked(checked);
79 mSetupWizardApp.getSettingsBundle().putBoolean(KEY_PRIVACY_GUARD, checked);
cretin453593f032016-04-20 16:21:05 -070080 };
81
82 @Override
83 protected void onCreate(Bundle savedInstanceState) {
84 super.onCreate(savedInstanceState);
85 mSetupWizardApp = (SetupWizardApp) getApplication();
cretin453593f032016-04-20 16:21:05 -070086 setNextText(R.string.next);
87 String privacy_policy = getString(R.string.services_privacy_policy);
88 String policySummary = getString(R.string.services_explanation, privacy_policy);
89 SpannableString ss = new SpannableString(policySummary);
90 ClickableSpan clickableSpan = new ClickableSpan() {
91 @Override
92 public void onClick(View textView) {
93 // At this point of the setup, the device has already been unlocked (if frp
94 // had been enabled), so there should be no issues regarding security
95 final Intent intent = new Intent(Intent.ACTION_VIEW,
96 Uri.parse(PRIVACY_POLICY_URI));
97 try {
98 startActivity(intent);
99 } catch (Exception e) {
100 Log.e(TAG, "Unable to start activity " + intent.toString(), e);
101 }
102 }
103 };
104 ss.setSpan(clickableSpan,
105 policySummary.length() - privacy_policy.length() - 1,
106 policySummary.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
107 TextView privacyPolicy = (TextView) findViewById(R.id.privacy_policy);
108 privacyPolicy.setMovementMethod(LinkMovementMethod.getInstance());
109 privacyPolicy.setText(ss);
110
Michael W2236d292018-07-15 15:09:20 +0200111 View metricsRow = findViewById(R.id.metrics);
112 metricsRow.setOnClickListener(mMetricsClickListener);
Michael Bestasc83309e2018-02-03 17:42:13 +0200113 String metricsHelpImproveLineage =
cretin453593f032016-04-20 16:21:05 -0700114 getString(R.string.services_help_improve_cm, getString(R.string.os_name));
115 String metricsSummary = getString(R.string.services_metrics_label,
Michael Bestasc83309e2018-02-03 17:42:13 +0200116 metricsHelpImproveLineage, getString(R.string.os_name));
cretin453593f032016-04-20 16:21:05 -0700117 final SpannableStringBuilder metricsSpan = new SpannableStringBuilder(metricsSummary);
118 metricsSpan.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD),
Michael Bestasc83309e2018-02-03 17:42:13 +0200119 0, metricsHelpImproveLineage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
cretin453593f032016-04-20 16:21:05 -0700120 TextView metrics = (TextView) findViewById(R.id.enable_metrics_summary);
121 metrics.setText(metricsSpan);
122 mMetrics = (CheckBox) findViewById(R.id.enable_metrics_checkbox);
123
Michael W2236d292018-07-15 15:09:20 +0200124 View navKeysRow = findViewById(R.id.nav_keys);
125 navKeysRow.setOnClickListener(mNavKeysClickListener);
cretin453593f032016-04-20 16:21:05 -0700126 mNavKeys = (CheckBox) findViewById(R.id.nav_keys_checkbox);
Bruno Martins33636d12018-09-17 13:53:31 +0100127 mSupportsKeyDisabler = isKeyDisablerSupported(this);
128 if (mSupportsKeyDisabler) {
cretin453593f032016-04-20 16:21:05 -0700129 boolean navKeysDisabled = isKeyDisablerActive(this);
130 mNavKeys.setChecked(navKeysDisabled);
Bruno Martins33636d12018-09-17 13:53:31 +0100131 } else {
132 navKeysRow.setVisibility(View.GONE);
cretin453593f032016-04-20 16:21:05 -0700133 }
134
Michael W2236d292018-07-15 15:09:20 +0200135 View privacyGuardRow = findViewById(R.id.privacy_guard);
136 privacyGuardRow.setOnClickListener(mPrivacyGuardClickListener);
cretin453593f032016-04-20 16:21:05 -0700137 mPrivacyGuard = (CheckBox) findViewById(R.id.privacy_guard_checkbox);
Abhisek Devkotacc839c92018-01-29 12:41:42 -0800138 mPrivacyGuard.setChecked(LineageSettings.Secure.getInt(getContentResolver(),
139 LineageSettings.Secure.PRIVACY_GUARD_DEFAULT, 0) == 1);
cretin453593f032016-04-20 16:21:05 -0700140 }
141
142 @Override
143 public void onResume() {
144 super.onResume();
145 updateDisableNavkeysOption();
146 updateMetricsOption();
cretin453593f032016-04-20 16:21:05 -0700147 updatePrivacyGuardOption();
148 }
149
150 @Override
151 public void onNavigateBack() {
152 onBackPressed();
153 }
154
155 @Override
156 public void onNavigateNext() {
157 Intent intent = WizardManagerHelper.getNextIntent(getIntent(), Activity.RESULT_OK);
158 startActivityForResult(intent, 1);
159 }
160
cretin45d4cea552016-04-25 11:00:04 -0700161 @Override
162 protected int getTransition() {
163 return TRANSITION_ID_SLIDE;
164 }
165
166 @Override
167 protected int getLayoutResId() {
168 return R.layout.setup_lineage_settings;
169 }
170
171 @Override
172 protected int getTitleResId() {
173 return R.string.setup_services;
174 }
175
176 @Override
177 protected int getIconResId() {
178 return R.drawable.ic_features;
179 }
180
cretin453593f032016-04-20 16:21:05 -0700181 private void updateMetricsOption() {
182 final Bundle myPageBundle = mSetupWizardApp.getSettingsBundle();
183 boolean metricsChecked =
184 !myPageBundle.containsKey(KEY_SEND_METRICS) || myPageBundle
185 .getBoolean(KEY_SEND_METRICS);
186 mMetrics.setChecked(metricsChecked);
187 myPageBundle.putBoolean(KEY_SEND_METRICS, metricsChecked);
188 }
189
cretin453593f032016-04-20 16:21:05 -0700190 private void updateDisableNavkeysOption() {
Bruno Martins33636d12018-09-17 13:53:31 +0100191 if (mSupportsKeyDisabler) {
cretin453593f032016-04-20 16:21:05 -0700192 final Bundle myPageBundle = mSetupWizardApp.getSettingsBundle();
Michael Bestas9ca7cf42018-02-04 21:53:22 +0200193 boolean enabled = LineageSettings.Global.getInt(getContentResolver(),
194 LineageSettings.Global.DEV_FORCE_SHOW_NAVBAR, 0) != 0;
cretin453593f032016-04-20 16:21:05 -0700195 boolean checked = myPageBundle.containsKey(DISABLE_NAV_KEYS) ?
196 myPageBundle.getBoolean(DISABLE_NAV_KEYS) :
197 enabled;
198 mNavKeys.setChecked(checked);
199 myPageBundle.putBoolean(DISABLE_NAV_KEYS, checked);
200 }
201 }
202
203 private void updatePrivacyGuardOption() {
204 final Bundle bundle = mSetupWizardApp.getSettingsBundle();
Abhisek Devkotacc839c92018-01-29 12:41:42 -0800205 boolean enabled = LineageSettings.Secure.getInt(getContentResolver(),
206 LineageSettings.Secure.PRIVACY_GUARD_DEFAULT, 0) != 0;
cretin453593f032016-04-20 16:21:05 -0700207 boolean checked = bundle.containsKey(KEY_PRIVACY_GUARD) ?
208 bundle.getBoolean(KEY_PRIVACY_GUARD) :
209 enabled;
210 mPrivacyGuard.setChecked(checked);
211 bundle.putBoolean(KEY_PRIVACY_GUARD, checked);
212 }
213
Bruno Martins33636d12018-09-17 13:53:31 +0100214 private static boolean isKeyDisablerSupported(Context context) {
Abhisek Devkotacc839c92018-01-29 12:41:42 -0800215 final LineageHardwareManager hardware = LineageHardwareManager.getInstance(context);
Bruno Martins33636d12018-09-17 13:53:31 +0100216 return hardware.isSupported(LineageHardwareManager.FEATURE_KEY_DISABLE);
cretin453593f032016-04-20 16:21:05 -0700217 }
218
219 private static boolean isKeyDisablerActive(Context context) {
Abhisek Devkotacc839c92018-01-29 12:41:42 -0800220 final LineageHardwareManager hardware = LineageHardwareManager.getInstance(context);
221 return hardware.get(LineageHardwareManager.FEATURE_KEY_DISABLE);
cretin453593f032016-04-20 16:21:05 -0700222 }
cretin453593f032016-04-20 16:21:05 -0700223}