• 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 public abstract class TunerService {
24 
25     public static final String ACTION_CLEAR = "com.android.systemui.action.CLEAR_TUNER";
26     private final Context mContext;
27 
clearAll()28     public abstract void clearAll();
destroy()29     public abstract void destroy();
30 
getValue(String setting)31     public abstract String getValue(String setting);
getValue(String setting, int def)32     public abstract int getValue(String setting, int def);
getValue(String setting, String def)33     public abstract String getValue(String setting, String def);
34 
setValue(String setting, String value)35     public abstract void setValue(String setting, String value);
setValue(String setting, int value)36     public abstract void setValue(String setting, int value);
37 
addTunable(Tunable tunable, String... keys)38     public abstract void addTunable(Tunable tunable, String... keys);
removeTunable(Tunable tunable)39     public abstract void removeTunable(Tunable tunable);
40 
41     /**
42      * Sets the state of the {@link TunerActivity} component for the current user
43      */
setTunerEnabled(boolean enabled)44     public abstract void setTunerEnabled(boolean enabled);
45 
46     /**
47      * Returns true if the tuner is enabled for the current user.
48      */
isTunerEnabled()49     public abstract boolean isTunerEnabled();
50 
51     public interface Tunable {
onTuningChanged(String key, String newValue)52         void onTuningChanged(String key, String newValue);
53     }
54 
TunerService(Context context)55     public TunerService(Context context) {
56         mContext = context;
57     }
58 
59     public static class ClearReceiver extends BroadcastReceiver {
60         @Override
onReceive(Context context, Intent intent)61         public void onReceive(Context context, Intent intent) {
62             if (ACTION_CLEAR.equals(intent.getAction())) {
63                 Dependency.get(TunerService.class).clearAll();
64             }
65         }
66     }
67 
68     /** */
showResetRequest(Runnable onDisabled)69     public abstract void showResetRequest(Runnable onDisabled);
70 
parseIntegerSwitch(String value, boolean defaultValue)71     public static boolean parseIntegerSwitch(String value, boolean defaultValue) {
72         try {
73             return value != null ? Integer.parseInt(value) != 0 : defaultValue;
74         } catch (NumberFormatException e) {
75             return defaultValue;
76         }
77     }
78 }
79