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.server.appsearch.appsindexer; 18 19 import android.annotation.IntDef; 20 import android.util.ArraySet; 21 22 import com.android.server.appsearch.stats.AppSearchStatsLog; 23 24 import java.lang.annotation.Retention; 25 import java.lang.annotation.RetentionPolicy; 26 import java.util.Set; 27 28 public class AppsUpdateStats { 29 30 @IntDef( 31 value = { 32 UNKNOWN_UPDATE_TYPE, 33 FULL_UPDATE, 34 // TODO(b/275592563): Add package event update types 35 }) 36 @Retention(RetentionPolicy.SOURCE) 37 public @interface UpdateType {} 38 39 public static final int UNKNOWN_UPDATE_TYPE = 40 AppSearchStatsLog.APP_SEARCH_APPS_INDEXER_STATS_REPORTED__UPDATE_TYPE__UNKNOWN; 41 42 /** Complete update to bring AppSearch in sync with PackageManager. */ 43 public static final int FULL_UPDATE = 44 AppSearchStatsLog.APP_SEARCH_APPS_INDEXER_STATS_REPORTED__UPDATE_TYPE__FULL; 45 46 @UpdateType int mUpdateType = UNKNOWN_UPDATE_TYPE; 47 48 // Ok by default, will be set to something else if there is a failure while updating. 49 Set<Integer> mUpdateStatusCodes = new ArraySet<>(); 50 int mNumberOfAppsAdded; 51 int mNumberOfAppsRemoved; 52 int mNumberOfAppsUpdated; 53 int mNumberOfAppsUnchanged; 54 long mTotalLatencyMillis; 55 long mPackageManagerLatencyMillis; 56 long mAppSearchGetLatencyMillis; 57 long mAppSearchSetSchemaLatencyMillis; 58 long mAppSearchPutLatencyMillis; 59 60 // Same as in settings 61 long mUpdateStartTimestampMillis; 62 long mLastAppUpdateTimestampMillis; 63 64 int mNumberOfFunctionsAdded; 65 // For apps that get deleted, we don't check what functions were indexed into AppSearch, and 66 // delete the entire database corresponding to the packages functions. We use a setSchema call 67 // with override set to true, so it's not clear how many functions were deleted from AppSearch 68 // for deleted packages. 69 int mApproximateNumberOfFunctionsRemoved; 70 // As of now, added and unchanged and updated functions are all logged as updated 71 // TODO(b/357551503): Log indexed function counts more accurately 72 int mNumberOfFunctionsUpdated; 73 // For apps that don't get updated, we don't check functions at all. So it's not clear how many 74 // functions have remained unchanged in packages that were unchanged. 75 int mApproximateNumberOfFunctionsUnchanged; 76 77 long mAppSearchRemoveLatencyMillis; 78 79 /** Resets the Apps Indexer update stats. */ clear()80 public void clear() { 81 mUpdateType = UNKNOWN_UPDATE_TYPE; 82 mUpdateStatusCodes = new ArraySet<>(); 83 84 mPackageManagerLatencyMillis = 0; 85 mAppSearchGetLatencyMillis = 0; 86 mAppSearchSetSchemaLatencyMillis = 0; 87 mAppSearchPutLatencyMillis = 0; 88 mTotalLatencyMillis = 0; 89 90 mNumberOfAppsRemoved = 0; 91 mNumberOfAppsAdded = 0; 92 mNumberOfAppsUpdated = 0; 93 mNumberOfAppsUnchanged = 0; 94 95 mLastAppUpdateTimestampMillis = 0; 96 mUpdateStartTimestampMillis = 0; 97 98 mNumberOfFunctionsAdded = 0; 99 mApproximateNumberOfFunctionsRemoved = 0; 100 mApproximateNumberOfFunctionsUnchanged = 0; 101 mNumberOfFunctionsUpdated = 0; 102 103 mAppSearchRemoveLatencyMillis = 0; 104 } 105 } 106