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.traceur; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 import java.util.Set; 23 24 public class TraceConfig implements Parcelable { 25 26 private final int bufferSizeKb; 27 private final boolean winscope; 28 private final boolean apps; 29 private final boolean longTrace; 30 private final boolean attachToBugreport; 31 private final int maxLongTraceSizeMb; 32 private final int maxLongTraceDurationMinutes; 33 private final Set<String> tags; 34 TraceConfig(int bufferSizeKb, boolean winscope, boolean apps, boolean longTrace, boolean attachToBugreport, int maxLongTraceSizeMb, int maxLongTraceDurationMinutes, Set<String> tags)35 public TraceConfig(int bufferSizeKb, boolean winscope, boolean apps, boolean longTrace, 36 boolean attachToBugreport, int maxLongTraceSizeMb, int maxLongTraceDurationMinutes, 37 Set<String> tags) { 38 this.bufferSizeKb = bufferSizeKb; 39 this.winscope = winscope; 40 this.apps = apps; 41 this.longTrace = longTrace; 42 this.attachToBugreport = attachToBugreport; 43 this.maxLongTraceSizeMb = maxLongTraceSizeMb; 44 this.maxLongTraceDurationMinutes = maxLongTraceDurationMinutes; 45 this.tags = tags; 46 } 47 TraceConfig(PresetTraceConfigs.TraceOptions options, Set<String> tags)48 public TraceConfig(PresetTraceConfigs.TraceOptions options, Set<String> tags) { 49 this( 50 options.bufferSizeKb, 51 options.winscope, 52 options.apps, 53 options.longTrace, 54 options.attachToBugreport, 55 options.maxLongTraceSizeMb, 56 options.maxLongTraceDurationMinutes, 57 tags 58 ); 59 } 60 getOptions()61 public PresetTraceConfigs.TraceOptions getOptions() { 62 return new PresetTraceConfigs.TraceOptions( 63 bufferSizeKb, 64 winscope, 65 apps, 66 longTrace, 67 attachToBugreport, 68 maxLongTraceSizeMb, 69 maxLongTraceDurationMinutes 70 ); 71 } 72 getBufferSizeKb()73 public int getBufferSizeKb() { 74 return bufferSizeKb; 75 } 76 getWinscope()77 public boolean getWinscope() { 78 return winscope; 79 } 80 getApps()81 public boolean getApps() { 82 return apps; 83 } 84 getLongTrace()85 public boolean getLongTrace() { 86 return longTrace; 87 } 88 getAttachToBugreport()89 public boolean getAttachToBugreport() { 90 return attachToBugreport; 91 } 92 getMaxLongTraceSizeMb()93 public int getMaxLongTraceSizeMb() { 94 return maxLongTraceSizeMb; 95 } 96 getMaxLongTraceDurationMinutes()97 public int getMaxLongTraceDurationMinutes() { 98 return maxLongTraceDurationMinutes; 99 } 100 getTags()101 public Set<String> getTags() { 102 return tags; 103 } 104 105 @Override describeContents()106 public int describeContents() { 107 return 0; 108 } 109 110 @Override writeToParcel(Parcel parcel, int i)111 public void writeToParcel(Parcel parcel, int i) { 112 parcel.writeInt(bufferSizeKb); 113 parcel.writeBoolean(winscope); 114 parcel.writeBoolean(apps); 115 parcel.writeBoolean(longTrace); 116 parcel.writeBoolean(attachToBugreport); 117 parcel.writeInt(maxLongTraceSizeMb); 118 parcel.writeInt(maxLongTraceDurationMinutes); 119 parcel.writeStringArray(tags.toArray(String[]::new)); 120 } 121 122 public static final Parcelable.Creator<TraceConfig> CREATOR = new Creator<>() { 123 @Override 124 public TraceConfig createFromParcel(Parcel parcel) { 125 return new TraceConfig( 126 parcel.readInt(), 127 parcel.readBoolean(), 128 parcel.readBoolean(), 129 parcel.readBoolean(), 130 parcel.readBoolean(), 131 parcel.readInt(), 132 parcel.readInt(), 133 Set.of(parcel.readStringArray()) 134 ); 135 } 136 137 @Override 138 public TraceConfig[] newArray(int i) { 139 return new TraceConfig[i]; 140 } 141 }; 142 143 public static class Builder { 144 public int bufferSizeKb; 145 public boolean winscope; 146 public boolean apps; 147 public boolean longTrace; 148 public boolean attachToBugreport; 149 public int maxLongTraceSizeMb; 150 public int maxLongTraceDurationMinutes; 151 public Set<String> tags; 152 Builder(TraceConfig traceConfig)153 public Builder(TraceConfig traceConfig) { 154 this( 155 traceConfig.getBufferSizeKb(), 156 traceConfig.getWinscope(), 157 traceConfig.getApps(), 158 traceConfig.getLongTrace(), 159 traceConfig.getAttachToBugreport(), 160 traceConfig.getMaxLongTraceSizeMb(), 161 traceConfig.getMaxLongTraceDurationMinutes(), 162 traceConfig.getTags() 163 ); 164 } 165 Builder(int bufferSizeKb, boolean winscope, boolean apps, boolean longTrace, boolean attachToBugreport, int maxLongTraceSizeMb, int maxLongTraceDurationMinutes, Set<String> tags)166 private Builder(int bufferSizeKb, boolean winscope, boolean apps, boolean longTrace, 167 boolean attachToBugreport, int maxLongTraceSizeMb, int maxLongTraceDurationMinutes, 168 Set<String> tags) { 169 this.bufferSizeKb = bufferSizeKb; 170 this.winscope = winscope; 171 this.apps = apps; 172 this.longTrace = longTrace; 173 this.attachToBugreport = attachToBugreport; 174 this.maxLongTraceSizeMb = maxLongTraceSizeMb; 175 this.maxLongTraceDurationMinutes = maxLongTraceDurationMinutes; 176 this.tags = tags; 177 } 178 build()179 public TraceConfig build() { 180 return new TraceConfig(bufferSizeKb, winscope, apps, longTrace, attachToBugreport, 181 maxLongTraceSizeMb, maxLongTraceDurationMinutes, tags); 182 } 183 } 184 } 185