1 /* 2 * Copyright (C) 2017 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 17 package com.android.settings.development; 18 19 import android.content.Context; 20 import android.os.SystemProperties; 21 import android.text.TextUtils; 22 import android.view.ThreadedRenderer; 23 24 import androidx.preference.ListPreference; 25 import androidx.preference.Preference; 26 27 import com.android.settings.core.PreferenceControllerMixin; 28 import com.android.settingslib.development.DeveloperOptionsPreferenceController; 29 import com.android.settingslib.development.SystemPropPoker; 30 31 public class DebugGpuOverdrawPreferenceController extends 32 DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener, 33 PreferenceControllerMixin { 34 35 private static final String DEBUG_HW_OVERDRAW_KEY = "debug_hw_overdraw"; 36 37 private final String[] mListValues; 38 private final String[] mListSummaries; 39 DebugGpuOverdrawPreferenceController(Context context)40 public DebugGpuOverdrawPreferenceController(Context context) { 41 super(context); 42 43 mListValues = context.getResources().getStringArray( 44 com.android.settingslib.R.array.debug_hw_overdraw_values); 45 mListSummaries = context.getResources().getStringArray( 46 com.android.settingslib.R.array.debug_hw_overdraw_entries); 47 } 48 49 @Override getPreferenceKey()50 public String getPreferenceKey() { 51 return DEBUG_HW_OVERDRAW_KEY; 52 } 53 54 @Override onPreferenceChange(Preference preference, Object newValue)55 public boolean onPreferenceChange(Preference preference, Object newValue) { 56 writeDebugHwOverdrawOptions(newValue); 57 updateDebugHwOverdrawOptions(); 58 return true; 59 } 60 61 @Override updateState(Preference preference)62 public void updateState(Preference preference) { 63 updateDebugHwOverdrawOptions(); 64 } 65 writeDebugHwOverdrawOptions(Object newValue)66 private void writeDebugHwOverdrawOptions(Object newValue) { 67 SystemProperties.set(ThreadedRenderer.DEBUG_OVERDRAW_PROPERTY, 68 newValue == null ? "" : newValue.toString()); 69 SystemPropPoker.getInstance().poke(); 70 } 71 updateDebugHwOverdrawOptions()72 private void updateDebugHwOverdrawOptions() { 73 final String value = SystemProperties.get( 74 ThreadedRenderer.DEBUG_OVERDRAW_PROPERTY, "" /* default */); 75 76 int index = 0; // default 77 for (int i = 0; i < mListValues.length; i++) { 78 if (TextUtils.equals(value, mListValues[i])) { 79 index = i; 80 break; 81 } 82 } 83 final ListPreference listPreference = (ListPreference) mPreference; 84 listPreference.setValue(mListValues[index]); 85 listPreference.setSummary(mListSummaries[index]); 86 } 87 } 88