Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package com.android.systemui.tuner; |
| 17 | |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 18 | import android.app.AlertDialog; |
Jason Monk | 72def0d | 2015-11-10 16:03:06 -0500 | [diff] [blame] | 19 | import android.app.Dialog; |
| 20 | import android.app.DialogFragment; |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 21 | import android.content.DialogInterface; |
Jason Monk | 2ad83b9 | 2017-05-09 14:19:57 -0400 | [diff] [blame^] | 22 | import android.os.Build; |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 23 | import android.os.Bundle; |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 24 | import android.provider.Settings; |
Jason Monk | 87ccd55 | 2015-12-11 21:39:54 -0500 | [diff] [blame] | 25 | import android.support.v14.preference.PreferenceFragment; |
Jason Monk | 2ad83b9 | 2017-05-09 14:19:57 -0400 | [diff] [blame^] | 26 | import android.support.v7.preference.Preference; |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 27 | import android.view.Menu; |
| 28 | import android.view.MenuInflater; |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 29 | import android.view.MenuItem; |
Jason Monk | 87ccd55 | 2015-12-11 21:39:54 -0500 | [diff] [blame] | 30 | |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 31 | import com.android.internal.hardware.AmbientDisplayConfiguration; |
Jason Monk | a403159 | 2015-07-16 14:15:50 -0400 | [diff] [blame] | 32 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 33 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 34 | import com.android.systemui.R; |
Jason Monk | ef0d34d | 2016-08-23 14:41:05 -0400 | [diff] [blame] | 35 | import com.android.systemui.plugins.PluginPrefs; |
Jason Monk | fe7c91b | 2015-08-13 15:42:28 -0400 | [diff] [blame] | 36 | |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 37 | public class TunerFragment extends PreferenceFragment { |
| 38 | |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 39 | private static final String TAG = "TunerFragment"; |
| 40 | |
John Spurlock | f40d08f | 2015-05-29 10:48:22 -0400 | [diff] [blame] | 41 | private static final String KEY_BATTERY_PCT = "battery_pct"; |
Jason Monk | ef0d34d | 2016-08-23 14:41:05 -0400 | [diff] [blame] | 42 | private static final String KEY_PLUGINS = "plugins"; |
Adrian Roos | 5cd29e4 | 2017-02-22 16:02:02 +0100 | [diff] [blame] | 43 | private static final CharSequence KEY_DOZE = "doze"; |
John Spurlock | f40d08f | 2015-05-29 10:48:22 -0400 | [diff] [blame] | 44 | |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 45 | public static final String SETTING_SEEN_TUNER_WARNING = "seen_tuner_warning"; |
| 46 | |
Jason Monk | 72def0d | 2015-11-10 16:03:06 -0500 | [diff] [blame] | 47 | private static final String WARNING_TAG = "tuner_warning"; |
Jason Monk | 2ad83b9 | 2017-05-09 14:19:57 -0400 | [diff] [blame^] | 48 | private static final String[] DEBUG_ONLY = new String[] { |
| 49 | "nav_bar", |
| 50 | "lockscreen", |
| 51 | "picture_in_picture", |
| 52 | }; |
Jason Monk | 72def0d | 2015-11-10 16:03:06 -0500 | [diff] [blame] | 53 | |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 54 | private static final int MENU_REMOVE = Menu.FIRST + 1; |
| 55 | |
Jason Monk | 87ccd55 | 2015-12-11 21:39:54 -0500 | [diff] [blame] | 56 | @Override |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 57 | public void onCreate(Bundle savedInstanceState) { |
| 58 | super.onCreate(savedInstanceState); |
| 59 | |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 60 | setHasOptionsMenu(true); |
Jason Monk | 87ccd55 | 2015-12-11 21:39:54 -0500 | [diff] [blame] | 61 | } |
Jason Monk | 11a7744 | 2015-05-12 19:29:02 -0400 | [diff] [blame] | 62 | |
Jason Monk | 87ccd55 | 2015-12-11 21:39:54 -0500 | [diff] [blame] | 63 | @Override |
Jason Monk | a9f1288 | 2016-01-24 12:03:19 -0500 | [diff] [blame] | 64 | public void onActivityCreated(Bundle savedInstanceState) { |
| 65 | super.onActivityCreated(savedInstanceState); |
| 66 | getActivity().getActionBar().setDisplayHomeAsUpEnabled(true); |
| 67 | } |
| 68 | |
| 69 | @Override |
Jason Monk | 87ccd55 | 2015-12-11 21:39:54 -0500 | [diff] [blame] | 70 | public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { |
| 71 | addPreferencesFromResource(R.xml.tuner_prefs); |
Jason Monk | ef0d34d | 2016-08-23 14:41:05 -0400 | [diff] [blame] | 72 | if (!PluginPrefs.hasPlugins(getContext())) { |
| 73 | getPreferenceScreen().removePreference(findPreference(KEY_PLUGINS)); |
| 74 | } |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 75 | if (!alwaysOnAvailable()) { |
Adrian Roos | 5cd29e4 | 2017-02-22 16:02:02 +0100 | [diff] [blame] | 76 | getPreferenceScreen().removePreference(findPreference(KEY_DOZE)); |
| 77 | } |
Jason Monk | 2ad83b9 | 2017-05-09 14:19:57 -0400 | [diff] [blame^] | 78 | if (!Build.IS_DEBUGGABLE) { |
| 79 | for (int i = 0; i < DEBUG_ONLY.length; i++) { |
| 80 | Preference preference = findPreference(DEBUG_ONLY[i]); |
| 81 | if (preference != null) getPreferenceScreen().removePreference(preference); |
| 82 | } |
| 83 | } |
Jason Monk | 87ccd55 | 2015-12-11 21:39:54 -0500 | [diff] [blame] | 84 | |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 85 | if (Settings.Secure.getInt(getContext().getContentResolver(), SETTING_SEEN_TUNER_WARNING, |
| 86 | 0) == 0) { |
Jason Monk | 72def0d | 2015-11-10 16:03:06 -0500 | [diff] [blame] | 87 | if (getFragmentManager().findFragmentByTag(WARNING_TAG) == null) { |
| 88 | new TunerWarningFragment().show(getFragmentManager(), WARNING_TAG); |
| 89 | } |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 90 | } |
John Spurlock | f40d08f | 2015-05-29 10:48:22 -0400 | [diff] [blame] | 91 | } |
| 92 | |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 93 | private boolean alwaysOnAvailable() { |
| 94 | return new AmbientDisplayConfiguration(getContext()).alwaysOnAvailable(); |
| 95 | } |
| 96 | |
John Spurlock | f40d08f | 2015-05-29 10:48:22 -0400 | [diff] [blame] | 97 | @Override |
| 98 | public void onResume() { |
| 99 | super.onResume(); |
Jason Monk | f0c6f64 | 2016-01-20 22:24:50 -0500 | [diff] [blame] | 100 | getActivity().setTitle(R.string.system_ui_tuner); |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 101 | |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 102 | MetricsLogger.visibility(getContext(), MetricsEvent.TUNER, true); |
John Spurlock | f40d08f | 2015-05-29 10:48:22 -0400 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public void onPause() { |
| 107 | super.onPause(); |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 108 | |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 109 | MetricsLogger.visibility(getContext(), MetricsEvent.TUNER, false); |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 110 | } |
| 111 | |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 112 | @Override |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 113 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { |
| 114 | menu.add(Menu.NONE, MENU_REMOVE, Menu.NONE, R.string.remove_from_settings); |
| 115 | } |
| 116 | |
| 117 | @Override |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 118 | public boolean onOptionsItemSelected(MenuItem item) { |
| 119 | switch (item.getItemId()) { |
| 120 | case android.R.id.home: |
| 121 | getActivity().finish(); |
| 122 | return true; |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 123 | case MENU_REMOVE: |
| 124 | TunerService.showResetRequest(getContext(), new Runnable() { |
| 125 | @Override |
| 126 | public void run() { |
Akira Oshimi | 8fbcb76 | 2016-09-29 12:17:24 +0900 | [diff] [blame] | 127 | if (getActivity() != null) { |
| 128 | getActivity().finish(); |
| 129 | } |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 130 | } |
| 131 | }); |
| 132 | return true; |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 133 | } |
| 134 | return super.onOptionsItemSelected(item); |
| 135 | } |
| 136 | |
Jason Monk | 72def0d | 2015-11-10 16:03:06 -0500 | [diff] [blame] | 137 | public static class TunerWarningFragment extends DialogFragment { |
| 138 | @Override |
| 139 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 140 | return new AlertDialog.Builder(getContext()) |
| 141 | .setTitle(R.string.tuner_warning_title) |
| 142 | .setMessage(R.string.tuner_warning) |
| 143 | .setPositiveButton(R.string.got_it, new DialogInterface.OnClickListener() { |
| 144 | @Override |
| 145 | public void onClick(DialogInterface dialog, int which) { |
| 146 | Settings.Secure.putInt(getContext().getContentResolver(), |
| 147 | SETTING_SEEN_TUNER_WARNING, 1); |
| 148 | } |
| 149 | }).show(); |
| 150 | } |
| 151 | } |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 152 | } |