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 static com.android.server.art.model.DexoptResult.PackageDexoptResult; 20 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.annotation.SystemApi; 24 25 import com.android.internal.annotations.Immutable; 26 27 import com.google.auto.value.AutoValue; 28 29 /** 30 * Represents the progress of an operation. Currently, this is only for batch dexopt. 31 * 32 * @hide 33 */ 34 @SystemApi(client = SystemApi.Client.SYSTEM_SERVER) 35 @Immutable 36 @AutoValue 37 public abstract class OperationProgress { 38 /** @hide */ OperationProgress()39 protected OperationProgress() {} 40 41 /** @hide */ create( int current, int total, @Nullable PackageDexoptResult packageDexoptResult)42 public static @NonNull OperationProgress create( 43 int current, int total, @Nullable PackageDexoptResult packageDexoptResult) { 44 return new AutoValue_OperationProgress(current, total, packageDexoptResult); 45 } 46 47 /** The overall progress, in the range of [0, 100]. */ getPercentage()48 public int getPercentage() { 49 return getTotal() == 0 ? 100 : 100 * getCurrent() / getTotal(); 50 } 51 52 /** 53 * The number of processed items. Can be 0, which means the operation was just started. 54 * 55 * Currently, this is the number of packages, for which dexopt has been done, regardless 56 * of the results (performed, failed, skipped, etc.). 57 * 58 * @hide 59 */ getCurrent()60 public abstract int getCurrent(); 61 62 /** 63 * The total number of items. Stays constant during the operation. 64 * 65 * Currently, this is the total number of packages to dexopt. 66 * 67 * @hide 68 */ getTotal()69 public abstract int getTotal(); 70 71 /** 72 * The last package dexopt result, or null if {@link #getCurrent} returns 0. Only applicable if 73 * this class represents batch dexopt progress. 74 * 75 * @hide 76 */ getLastPackageDexoptResult()77 public abstract @Nullable PackageDexoptResult getLastPackageDexoptResult(); 78 } 79