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.support.v7.preference.ListPreference; 22 import android.support.v7.preference.Preference; 23 import android.text.TextUtils; 24 import android.view.ThreadedRenderer; 25 26 import com.android.settings.R; 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 ProfileGpuRenderingPreferenceController extends DeveloperOptionsPreferenceController 32 implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin { 33 34 private static final String TRACK_FRAME_TIME_KEY = "track_frame_time"; 35 36 private final String[] mListValues; 37 private final String[] mListSummaries; 38 39 public ProfileGpuRenderingPreferenceController(Context context) { 40 super(context); 41 42 mListValues = context.getResources().getStringArray(R.array.track_frame_time_values); 43 mListSummaries = context.getResources().getStringArray(R.array.track_frame_time_entries); 44 } 45 46 @Override 47 public String getPreferenceKey() { 48 return TRACK_FRAME_TIME_KEY; 49 } 50 51 @Override 52 public boolean onPreferenceChange(Preference preference, Object newValue) { 53 writeTrackFrameTimeOptions(newValue); 54 updateTrackFrameTimeOptions(); 55 return true; 56 } 57 58 @Override 59 public void updateState(Preference preference) { 60 updateTrackFrameTimeOptions(); 61 } 62 63 private void writeTrackFrameTimeOptions(Object newValue) { 64 SystemProperties.set(ThreadedRenderer.PROFILE_PROPERTY, 65 newValue == null ? "" : newValue.toString()); 66 SystemPropPoker.getInstance().poke(); 67 } 68 69 private void updateTrackFrameTimeOptions() { 70 final String value = SystemProperties.get( 71 ThreadedRenderer.PROFILE_PROPERTY, "" /* default */); 72 int index = 0; // default 73 for (int i = 0; i < mListValues.length; i++) { 74 if (TextUtils.equals(value, mListValues[i])) { 75 index = i; 76 break; 77 } 78 } 79 final ListPreference listPreference = (ListPreference) mPreference; 80 listPreference.setValue(mListValues[index]); 81 listPreference.setSummary(mListSummaries[index]); 82 } 83 } 84