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.content.ComponentName; 20 import android.content.Context; 21 import android.content.pm.PackageManager; 22 import android.os.SystemProperties; 23 import android.service.quicksettings.Tile; 24 import android.service.quicksettings.TileService; 25 import android.view.ThreadedRenderer; 26 import android.view.View; 27 import com.android.settings.DevelopmentSettings; 28 29 public class DevelopmentTiles { 30 // List of components that need to be enabled when developer tools are turned on 31 static final Class[] TILE_CLASSES = new Class[] { 32 ShowLayout.class, 33 GPUProfiling.class, 34 }; setTilesEnabled(Context context, boolean enable)35 public static void setTilesEnabled(Context context, boolean enable) { 36 final PackageManager pm = context.getPackageManager(); 37 for (Class cls : TILE_CLASSES) { 38 pm.setComponentEnabledSetting(new ComponentName(context, cls), 39 enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED 40 : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 41 PackageManager.DONT_KILL_APP); 42 } 43 } 44 45 /** 46 * Tile to control the "Show layout bounds" developer setting 47 */ 48 public static class ShowLayout extends TileService { 49 @Override onStartListening()50 public void onStartListening() { 51 super.onStartListening(); 52 refresh(); 53 } 54 refresh()55 public void refresh() { 56 final boolean enabled = SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false); 57 getQsTile().setState(enabled ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); 58 getQsTile().updateTile(); 59 } 60 61 @Override onClick()62 public void onClick() { 63 SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY, 64 getQsTile().getState() == Tile.STATE_INACTIVE ? "true" : "false"); 65 new DevelopmentSettings.SystemPropPoker().execute(); // Settings app magic 66 refresh(); 67 } 68 } 69 70 /** 71 * Tile to control the "GPU profiling" developer setting 72 */ 73 public static class GPUProfiling extends TileService { 74 @Override onStartListening()75 public void onStartListening() { 76 super.onStartListening(); 77 refresh(); 78 } 79 refresh()80 public void refresh() { 81 final String value = SystemProperties.get(ThreadedRenderer.PROFILE_PROPERTY); 82 getQsTile().setState(value.equals("visual_bars") 83 ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); 84 getQsTile().updateTile(); 85 } 86 87 @Override onClick()88 public void onClick() { 89 SystemProperties.set(ThreadedRenderer.PROFILE_PROPERTY, 90 getQsTile().getState() == Tile.STATE_INACTIVE ? "visual_bars" : ""); 91 new DevelopmentSettings.SystemPropPoker().execute(); // Settings app magic 92 refresh(); 93 } 94 } 95 }