| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The CyanogenMod Project |
| Bruno Martins | 33636d1 | 2018-09-17 13:53:31 +0100 | [diff] [blame^] | 3 | * Copyright (C) 2017-2018 The LineageOS Project |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 4 | * |
| 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 Bestas | c83309e | 2018-02-03 17:42:13 +0200 | [diff] [blame] | 18 | package org.lineageos.setupwizard; |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 19 | |
| Michael Bestas | c83309e | 2018-02-03 17:42:13 +0200 | [diff] [blame] | 20 | import static org.lineageos.setupwizard.SetupWizardApp.DISABLE_NAV_KEYS; |
| 21 | import static org.lineageos.setupwizard.SetupWizardApp.KEY_PRIVACY_GUARD; |
| 22 | import static org.lineageos.setupwizard.SetupWizardApp.KEY_SEND_METRICS; |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 23 | |
| 24 | import android.app.Activity; |
| 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 27 | import android.net.Uri; |
| 28 | import android.os.Bundle; |
| 29 | import android.os.RemoteException; |
| 30 | import android.text.Spannable; |
| 31 | import android.text.SpannableString; |
| 32 | import android.text.SpannableStringBuilder; |
| 33 | import android.text.Spanned; |
| 34 | import android.text.method.LinkMovementMethod; |
| 35 | import android.text.style.ClickableSpan; |
| 36 | import android.util.Log; |
| 37 | import android.view.IWindowManager; |
| 38 | import android.view.View; |
| 39 | import android.view.WindowManagerGlobal; |
| 40 | import android.widget.CheckBox; |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 41 | import android.widget.TextView; |
| 42 | |
| 43 | import com.android.setupwizardlib.util.WizardManagerHelper; |
| 44 | |
| Michael Bestas | c83309e | 2018-02-03 17:42:13 +0200 | [diff] [blame] | 45 | import org.lineageos.setupwizard.R; |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 46 | |
| Abhisek Devkota | cc839c9 | 2018-01-29 12:41:42 -0800 | [diff] [blame] | 47 | import lineageos.hardware.LineageHardwareManager; |
| 48 | import lineageos.providers.LineageSettings; |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 49 | |
| 50 | public 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 | |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 58 | private CheckBox mMetrics; |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 59 | private CheckBox mNavKeys; |
| 60 | private CheckBox mPrivacyGuard; |
| 61 | |
| Bruno Martins | 33636d1 | 2018-09-17 13:53:31 +0100 | [diff] [blame^] | 62 | private boolean mSupportsKeyDisabler = false; |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 63 | |
| Michael W | 2236d29 | 2018-07-15 15:09:20 +0200 | [diff] [blame] | 64 | private View.OnClickListener mMetricsClickListener = view -> { |
| 65 | boolean checked = !mMetrics.isChecked(); |
| 66 | mMetrics.setChecked(checked); |
| 67 | mSetupWizardApp.getSettingsBundle().putBoolean(KEY_SEND_METRICS, checked); |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
| Michael W | 2236d29 | 2018-07-15 15:09:20 +0200 | [diff] [blame] | 70 | private View.OnClickListener mNavKeysClickListener = view -> { |
| 71 | boolean checked = !mNavKeys.isChecked(); |
| 72 | mNavKeys.setChecked(checked); |
| 73 | mSetupWizardApp.getSettingsBundle().putBoolean(DISABLE_NAV_KEYS, checked); |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| Michael W | 2236d29 | 2018-07-15 15:09:20 +0200 | [diff] [blame] | 76 | private View.OnClickListener mPrivacyGuardClickListener = view -> { |
| 77 | boolean checked = !mPrivacyGuard.isChecked(); |
| 78 | mPrivacyGuard.setChecked(checked); |
| 79 | mSetupWizardApp.getSettingsBundle().putBoolean(KEY_PRIVACY_GUARD, checked); |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | @Override |
| 83 | protected void onCreate(Bundle savedInstanceState) { |
| 84 | super.onCreate(savedInstanceState); |
| 85 | mSetupWizardApp = (SetupWizardApp) getApplication(); |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 86 | 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 W | 2236d29 | 2018-07-15 15:09:20 +0200 | [diff] [blame] | 111 | View metricsRow = findViewById(R.id.metrics); |
| 112 | metricsRow.setOnClickListener(mMetricsClickListener); |
| Michael Bestas | c83309e | 2018-02-03 17:42:13 +0200 | [diff] [blame] | 113 | String metricsHelpImproveLineage = |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 114 | getString(R.string.services_help_improve_cm, getString(R.string.os_name)); |
| 115 | String metricsSummary = getString(R.string.services_metrics_label, |
| Michael Bestas | c83309e | 2018-02-03 17:42:13 +0200 | [diff] [blame] | 116 | metricsHelpImproveLineage, getString(R.string.os_name)); |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 117 | final SpannableStringBuilder metricsSpan = new SpannableStringBuilder(metricsSummary); |
| 118 | metricsSpan.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD), |
| Michael Bestas | c83309e | 2018-02-03 17:42:13 +0200 | [diff] [blame] | 119 | 0, metricsHelpImproveLineage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 120 | TextView metrics = (TextView) findViewById(R.id.enable_metrics_summary); |
| 121 | metrics.setText(metricsSpan); |
| 122 | mMetrics = (CheckBox) findViewById(R.id.enable_metrics_checkbox); |
| 123 | |
| Michael W | 2236d29 | 2018-07-15 15:09:20 +0200 | [diff] [blame] | 124 | View navKeysRow = findViewById(R.id.nav_keys); |
| 125 | navKeysRow.setOnClickListener(mNavKeysClickListener); |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 126 | mNavKeys = (CheckBox) findViewById(R.id.nav_keys_checkbox); |
| Bruno Martins | 33636d1 | 2018-09-17 13:53:31 +0100 | [diff] [blame^] | 127 | mSupportsKeyDisabler = isKeyDisablerSupported(this); |
| 128 | if (mSupportsKeyDisabler) { |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 129 | boolean navKeysDisabled = isKeyDisablerActive(this); |
| 130 | mNavKeys.setChecked(navKeysDisabled); |
| Bruno Martins | 33636d1 | 2018-09-17 13:53:31 +0100 | [diff] [blame^] | 131 | } else { |
| 132 | navKeysRow.setVisibility(View.GONE); |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| Michael W | 2236d29 | 2018-07-15 15:09:20 +0200 | [diff] [blame] | 135 | View privacyGuardRow = findViewById(R.id.privacy_guard); |
| 136 | privacyGuardRow.setOnClickListener(mPrivacyGuardClickListener); |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 137 | mPrivacyGuard = (CheckBox) findViewById(R.id.privacy_guard_checkbox); |
| Abhisek Devkota | cc839c9 | 2018-01-29 12:41:42 -0800 | [diff] [blame] | 138 | mPrivacyGuard.setChecked(LineageSettings.Secure.getInt(getContentResolver(), |
| 139 | LineageSettings.Secure.PRIVACY_GUARD_DEFAULT, 0) == 1); |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | @Override |
| 143 | public void onResume() { |
| 144 | super.onResume(); |
| 145 | updateDisableNavkeysOption(); |
| 146 | updateMetricsOption(); |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 147 | 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 | |
| cretin45 | d4cea55 | 2016-04-25 11:00:04 -0700 | [diff] [blame] | 161 | @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 | |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 181 | 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 | |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 190 | private void updateDisableNavkeysOption() { |
| Bruno Martins | 33636d1 | 2018-09-17 13:53:31 +0100 | [diff] [blame^] | 191 | if (mSupportsKeyDisabler) { |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 192 | final Bundle myPageBundle = mSetupWizardApp.getSettingsBundle(); |
| Michael Bestas | 9ca7cf4 | 2018-02-04 21:53:22 +0200 | [diff] [blame] | 193 | boolean enabled = LineageSettings.Global.getInt(getContentResolver(), |
| 194 | LineageSettings.Global.DEV_FORCE_SHOW_NAVBAR, 0) != 0; |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 195 | 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 Devkota | cc839c9 | 2018-01-29 12:41:42 -0800 | [diff] [blame] | 205 | boolean enabled = LineageSettings.Secure.getInt(getContentResolver(), |
| 206 | LineageSettings.Secure.PRIVACY_GUARD_DEFAULT, 0) != 0; |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 207 | 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 Martins | 33636d1 | 2018-09-17 13:53:31 +0100 | [diff] [blame^] | 214 | private static boolean isKeyDisablerSupported(Context context) { |
| Abhisek Devkota | cc839c9 | 2018-01-29 12:41:42 -0800 | [diff] [blame] | 215 | final LineageHardwareManager hardware = LineageHardwareManager.getInstance(context); |
| Bruno Martins | 33636d1 | 2018-09-17 13:53:31 +0100 | [diff] [blame^] | 216 | return hardware.isSupported(LineageHardwareManager.FEATURE_KEY_DISABLE); |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | private static boolean isKeyDisablerActive(Context context) { |
| Abhisek Devkota | cc839c9 | 2018-01-29 12:41:42 -0800 | [diff] [blame] | 220 | final LineageHardwareManager hardware = LineageHardwareManager.getInstance(context); |
| 221 | return hardware.get(LineageHardwareManager.FEATURE_KEY_DISABLE); |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 222 | } |
| cretin45 | 3593f03 | 2016-04-20 16:21:05 -0700 | [diff] [blame] | 223 | } |