1 /* 2 * Copyright (C) 2024 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.systemui.recordissue 18 19 import android.content.SharedPreferences 20 import com.android.traceur.PresetTraceConfigs.TraceOptions 21 import com.android.traceur.PresetTraceConfigs.getDefaultConfig 22 import com.android.traceur.TraceConfig 23 24 /** 25 * This class encapsulates the values that go into a customized record issue trace config, part of 26 * the RecordIssueTile feature. This class stores the last configuration chosen by power users. 27 */ 28 class CustomTraceState(private val prefs: SharedPreferences) { 29 30 private var enabledTags: Set<String>? 31 get() = prefs.getStringSet(KEY_TAGS, getDefaultConfig().tags) ?: getDefaultConfig().tags 32 set(value) = prefs.edit().putStringSet(KEY_TAGS, value).apply() 33 34 var traceConfig: TraceConfig 35 get() = TraceConfig(options, enabledTags) 36 set(value) { 37 enabledTags = value.tags 38 options = value.options 39 } 40 41 private var options: TraceOptions 42 get() = 43 TraceOptions( 44 prefs.getInt(KEY_CUSTOM_BUFFER_SIZE_KB, getDefaultConfig().bufferSizeKb), 45 prefs.getBoolean(KEY_WINSCOPE, getDefaultConfig().winscope), 46 prefs.getBoolean(KEY_APPS, getDefaultConfig().apps), 47 prefs.getBoolean(KEY_LONG_TRACE, getDefaultConfig().longTrace), 48 prefs.getBoolean(KEY_ATTACH_TO_BUGREPORT, getDefaultConfig().attachToBugreport), 49 prefs.getInt(KEY_LONG_TRACE_SIZE_MB, getDefaultConfig().maxLongTraceSizeMb), 50 prefs.getInt( 51 KEY_LONG_TRACE_DURATION_MINUTES, 52 getDefaultConfig().maxLongTraceDurationMinutes 53 ), 54 ) 55 set(value) { 56 prefs 57 .edit() 58 .putInt(KEY_CUSTOM_BUFFER_SIZE_KB, value.bufferSizeKb) 59 .putBoolean(KEY_WINSCOPE, value.winscope) 60 .putBoolean(KEY_APPS, value.apps) 61 .putBoolean(KEY_LONG_TRACE, value.longTrace) 62 .putBoolean(KEY_ATTACH_TO_BUGREPORT, value.attachToBugreport) 63 .putInt(KEY_LONG_TRACE_SIZE_MB, value.maxLongTraceSizeMb) 64 .putInt(KEY_LONG_TRACE_DURATION_MINUTES, value.maxLongTraceDurationMinutes) 65 .apply() 66 } 67 68 companion object { 69 private const val KEY_CUSTOM_BUFFER_SIZE_KB = "key_bufferSizeKb" 70 private const val KEY_WINSCOPE = "key_winscope" 71 private const val KEY_APPS = "key_apps" 72 private const val KEY_LONG_TRACE = "key_longTrace" 73 private const val KEY_ATTACH_TO_BUGREPORT = "key_attachToBugReport" 74 private const val KEY_LONG_TRACE_SIZE_MB = "key_maxLongTraceSizeMb" 75 private const val KEY_LONG_TRACE_DURATION_MINUTES = "key_maxLongTraceDurationInMinutes" 76 private const val KEY_TAGS = "key_tags" 77 } 78 } 79