• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5  * except in compliance with the License. You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the
10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11  * KIND, either express or implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */
14 
15 package com.android.systemui.tuner;
16 
17 import android.content.BroadcastReceiver;
18 import android.content.Context;
19 import android.content.Intent;
20 
21 import com.android.systemui.Dependency;
22 
23 /**
24  * @deprecated Don't use this class to listen to Secure Settings. Use {@code SecureSettings} instead
25  * or {@code SettingsObserver} to be able to specify the handler.
26  */
27 @Deprecated
28 public abstract class TunerService {
29 
30     public static final String ACTION_CLEAR = "com.android.systemui.action.CLEAR_TUNER";
31     private final Context mContext;
32 
clearAll()33     public abstract void clearAll();
destroy()34     public abstract void destroy();
35 
getValue(String setting)36     public abstract String getValue(String setting);
getValue(String setting, int def)37     public abstract int getValue(String setting, int def);
getValue(String setting, String def)38     public abstract String getValue(String setting, String def);
39 
setValue(String setting, String value)40     public abstract void setValue(String setting, String value);
setValue(String setting, int value)41     public abstract void setValue(String setting, int value);
42 
addTunable(Tunable tunable, String... keys)43     public abstract void addTunable(Tunable tunable, String... keys);
removeTunable(Tunable tunable)44     public abstract void removeTunable(Tunable tunable);
45 
46     /**
47      * Sets the state of the {@link TunerActivity} component for the current user
48      */
setTunerEnabled(boolean enabled)49     public abstract void setTunerEnabled(boolean enabled);
50 
51     /**
52      * Returns true if the tuner is enabled for the current user.
53      */
isTunerEnabled()54     public abstract boolean isTunerEnabled();
55 
56     public interface Tunable {
onTuningChanged(String key, String newValue)57         void onTuningChanged(String key, String newValue);
58     }
59 
TunerService(Context context)60     public TunerService(Context context) {
61         mContext = context;
62     }
63 
64     public static class ClearReceiver extends BroadcastReceiver {
65         @Override
onReceive(Context context, Intent intent)66         public void onReceive(Context context, Intent intent) {
67             if (ACTION_CLEAR.equals(intent.getAction())) {
68                 Dependency.get(TunerService.class).clearAll();
69             }
70         }
71     }
72 
73     /** */
showResetRequest(Runnable onDisabled)74     public abstract void showResetRequest(Runnable onDisabled);
75 
parseIntegerSwitch(String value, boolean defaultValue)76     public static boolean parseIntegerSwitch(String value, boolean defaultValue) {
77         try {
78             return value != null ? Integer.parseInt(value) != 0 : defaultValue;
79         } catch (NumberFormatException e) {
80             return defaultValue;
81         }
82     }
83 }
84