1 /* 2 * Copyright (C) 2022 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.server.art.model; 18 19 import android.annotation.NonNull; 20 import android.annotation.SystemApi; 21 import android.os.Build; 22 23 import androidx.annotation.RequiresApi; 24 25 import com.android.internal.annotations.Immutable; 26 import com.android.server.art.proto.BatchDexoptParamsProto; 27 28 import com.google.auto.value.AutoValue; 29 30 import java.util.ArrayList; 31 import java.util.Collections; 32 import java.util.List; 33 34 /** @hide */ 35 @SystemApi(client = SystemApi.Client.SYSTEM_SERVER) 36 @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) 37 @Immutable 38 @AutoValue 39 public abstract class BatchDexoptParams { 40 /** @hide */ 41 @SystemApi(client = SystemApi.Client.SYSTEM_SERVER) 42 public static final class Builder { 43 private @NonNull List<String> mPackageNames; // This is assumed immutable. 44 private @NonNull DexoptParams mDexoptParams; 45 46 /** @hide */ Builder( @onNull List<String> defaultPackages, @NonNull DexoptParams defaultDexoptParams)47 public Builder( 48 @NonNull List<String> defaultPackages, @NonNull DexoptParams defaultDexoptParams) { 49 mPackageNames = defaultPackages; // The argument is assumed immutable. 50 mDexoptParams = defaultDexoptParams; 51 } 52 53 /** 54 * Sets the list of packages to dexopt. The dexopt will be scheduled in the given 55 * order. 56 * 57 * If not called, the default list will be used. 58 */ 59 @NonNull setPackages(@onNull List<String> packageNames)60 public Builder setPackages(@NonNull List<String> packageNames) { 61 mPackageNames = Collections.unmodifiableList(new ArrayList<>(packageNames)); 62 return this; 63 } 64 65 /** 66 * Sets the params for dexopting each package. 67 * 68 * If not called, the default params built from {@link DexoptParams#Builder(String)} will 69 * be used. 70 */ 71 @NonNull setDexoptParams(@onNull DexoptParams dexoptParams)72 public Builder setDexoptParams(@NonNull DexoptParams dexoptParams) { 73 mDexoptParams = dexoptParams; 74 return this; 75 } 76 77 /** Returns the built object. */ 78 @NonNull build()79 public BatchDexoptParams build() { 80 return new AutoValue_BatchDexoptParams(mPackageNames, mDexoptParams); 81 } 82 } 83 84 /** @hide */ BatchDexoptParams()85 protected BatchDexoptParams() {} 86 87 /** The ordered list of packages to dexopt. */ getPackages()88 public abstract @NonNull List<String> getPackages(); 89 90 /** The params for dexopting each package. */ getDexoptParams()91 public abstract @NonNull DexoptParams getDexoptParams(); 92 93 /** @hide */ fromProto(@onNull BatchDexoptParamsProto proto)94 public static @NonNull BatchDexoptParams fromProto(@NonNull BatchDexoptParamsProto proto) { 95 return new BatchDexoptParams 96 .Builder(proto.getPackageList(), DexoptParams.fromProto(proto.getDexoptParams())) 97 .build(); 98 } 99 100 /** @hide */ toProto()101 public @NonNull BatchDexoptParamsProto toProto() { 102 return BatchDexoptParamsProto.newBuilder() 103 .addAllPackage(getPackages()) 104 .setDexoptParams(getDexoptParams().toProto()) 105 .build(); 106 } 107 } 108