1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 
17 package com.android.settings.qstile;
18 
19 import android.os.RemoteException;
20 import android.os.SystemProperties;
21 import android.provider.Settings;
22 import android.service.quicksettings.Tile;
23 import android.service.quicksettings.TileService;
24 import android.view.IWindowManager;
25 import android.view.ThreadedRenderer;
26 import android.view.View;
27 import android.view.WindowManagerGlobal;
28 
29 import com.android.internal.app.LocalePicker;
30 import com.android.settings.development.DevelopmentSettings;
31 
32 public abstract class DevelopmentTiles extends TileService {
33 
isEnabled()34     protected abstract boolean isEnabled();
35 
setIsEnabled(boolean isEnabled)36     protected abstract void setIsEnabled(boolean isEnabled);
37 
38     @Override
onStartListening()39     public void onStartListening() {
40         super.onStartListening();
41         refresh();
42     }
43 
refresh()44     public void refresh() {
45         getQsTile().setState(isEnabled() ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
46         getQsTile().updateTile();
47     }
48 
49     @Override
onClick()50     public void onClick() {
51         setIsEnabled(getQsTile().getState() == Tile.STATE_INACTIVE);
52         new DevelopmentSettings.SystemPropPoker().execute(); // Settings app magic
53         refresh();
54     }
55 
56     /**
57      * Tile to control the "Show layout bounds" developer setting
58      */
59     public static class ShowLayout extends DevelopmentTiles {
60 
61         @Override
isEnabled()62         protected boolean isEnabled() {
63             return SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false);
64         }
65 
66         @Override
setIsEnabled(boolean isEnabled)67         protected void setIsEnabled(boolean isEnabled) {
68             SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY, isEnabled ? "true" : "false");
69         }
70     }
71 
72     /**
73      * Tile to control the "GPU profiling" developer setting
74      */
75     public static class GPUProfiling extends DevelopmentTiles {
76 
77         @Override
isEnabled()78         protected boolean isEnabled() {
79             final String value = SystemProperties.get(ThreadedRenderer.PROFILE_PROPERTY);
80             return value.equals("visual_bars");
81         }
82 
83         @Override
setIsEnabled(boolean isEnabled)84         protected void setIsEnabled(boolean isEnabled) {
85             SystemProperties.set(ThreadedRenderer.PROFILE_PROPERTY, isEnabled ? "visual_bars" : "");
86         }
87     }
88 
89     /**
90      * Tile to control the "Force RTL" developer setting
91      */
92     public static class ForceRTL extends DevelopmentTiles {
93 
94         @Override
isEnabled()95         protected boolean isEnabled() {
96             return Settings.Global.getInt(
97                     getContentResolver(), Settings.Global.DEVELOPMENT_FORCE_RTL, 0) != 0;
98         }
99 
100         @Override
setIsEnabled(boolean isEnabled)101         protected void setIsEnabled(boolean isEnabled) {
102             Settings.Global.putInt(
103                     getContentResolver(), Settings.Global.DEVELOPMENT_FORCE_RTL, isEnabled ? 1 : 0);
104             SystemProperties.set(Settings.Global.DEVELOPMENT_FORCE_RTL, isEnabled ? "1" : "0");
105             LocalePicker.updateLocales(getResources().getConfiguration().getLocales());
106         }
107     }
108 
109     /**
110      * Tile to control the "Animation speed" developer setting
111      */
112     public static class AnimationSpeed extends DevelopmentTiles {
113 
114         @Override
isEnabled()115         protected boolean isEnabled() {
116             IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
117             try {
118                 return wm.getAnimationScale(0) != 1;
119             } catch (RemoteException e) { }
120             return false;
121         }
122 
123         @Override
setIsEnabled(boolean isEnabled)124         protected void setIsEnabled(boolean isEnabled) {
125             IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
126             float scale = isEnabled ? 10 : 1;
127             try {
128                 wm.setAnimationScale(0, scale);
129                 wm.setAnimationScale(1, scale);
130                 wm.setAnimationScale(2, scale);
131             } catch (RemoteException e) { }
132         }
133     }
134 }