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