• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.appsearch.contactsindexer;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.app.appsearch.AppSearchResult;
22 import android.util.ArraySet;
23 
24 import com.android.server.appsearch.stats.AppSearchStatsLog;
25 
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 import java.util.Set;
29 
30 /**
31  * The class to hold stats for DeltaUpdate or FullUpdate.
32  *
33  * <p>This will be used to populate
34  * {@link AppSearchStatsLog#CONTACTS_INDEXER_UPDATE_STATS_REPORTED}.
35  *
36  * <p>This class is not thread-safe.
37  *
38  * @hide
39  */
40 public class ContactsUpdateStats {
41     @IntDef(
42             value = {
43                     UNKNOWN_UPDATE_TYPE,
44                     DELTA_UPDATE,
45                     FULL_UPDATE,
46             })
47     @Retention(RetentionPolicy.SOURCE)
48     public @interface UpdateType {
49     }
50 
51     public static final int UNKNOWN_UPDATE_TYPE =
52             AppSearchStatsLog.CONTACTS_INDEXER_UPDATE_STATS_REPORTED__UPDATE_TYPE__UNKNOWN;
53     /** Incremental update reacting to CP2 change notifications. */
54     public static final int DELTA_UPDATE =
55             AppSearchStatsLog.CONTACTS_INDEXER_UPDATE_STATS_REPORTED__UPDATE_TYPE__DELTA;
56     /** Complete update to bring AppSearch in sync with CP2. */
57     public static final int FULL_UPDATE =
58             AppSearchStatsLog.CONTACTS_INDEXER_UPDATE_STATS_REPORTED__UPDATE_TYPE__FULL;
59 
60     @UpdateType
61     int mUpdateType = UNKNOWN_UPDATE_TYPE;
62     // Status for updates.
63     // In case of success, we will just have one success status stored.
64     // In case of Error,  we store the unique error codes during the update.
65     @AppSearchResult.ResultCode
66     Set<Integer> mUpdateStatuses = new ArraySet<>();
67     // Status for deletions.
68     // In case of success, we will just have one success status stored.
69     // In case of Error,  we store the unique error codes during the deletion.
70     @AppSearchResult.ResultCode
71     Set<Integer> mDeleteStatuses = new ArraySet<>();
72 
73     // Start time in millis for update and delete.
74     long mUpdateAndDeleteStartTimeMillis;
75 
76 
77     //
78     // Update for both old and new contacts(a.k.a insertion).
79     //
80     // # of old and new contacts failed to be updated.
81     int mContactsUpdateFailedCount;
82     // # of old and new contacts succeeds to be updated.
83     int mContactsUpdateSucceededCount;
84     // # of contacts update skipped due to NO significant change during the update.
85     int mContactsUpdateSkippedCount;
86     // Total # of old and new contacts to be updated.
87     // It should equal to
88     // mContactsUpdateFailedCount + mContactsUpdateSucceededCount + mContactsUpdateSkippedCount
89     int mTotalContactsToBeUpdated;
90     // Among the succeeded and failed contacts updates, how many of them are for the new contacts
91     // currently NOT available in AppSearch.
92     int mNewContactsToBeUpdated;
93 
94     //
95     // Deletion for old documents.
96     //
97     // # of old contacts failed to be deleted.
98     int mContactsDeleteFailedCount;
99     // # of old contacts succeeds to be deleted.
100     int mContactsDeleteSucceededCount;
101     // Total # of old contacts to be deleted. It should equal to
102     // mContactsDeleteFailedCount + mContactsDeleteSucceededCount
103     int mTotalContactsToBeDeleted;
104 
clear()105     public void clear() {
106         mUpdateType = UNKNOWN_UPDATE_TYPE;
107         mUpdateStatuses.clear();
108         mDeleteStatuses.clear();
109         mUpdateAndDeleteStartTimeMillis = 0;
110         // Update for old and new contacts
111         mContactsUpdateFailedCount = 0;
112         mContactsUpdateSucceededCount = 0;
113         mContactsUpdateSkippedCount = 0;
114         mNewContactsToBeUpdated = 0;
115         mTotalContactsToBeUpdated = 0;
116         // delete for old contacts
117         mContactsDeleteFailedCount = 0;
118         mContactsDeleteSucceededCount = 0;
119         mTotalContactsToBeDeleted = 0;
120     }
121 
122     @NonNull
toString()123     public String toString() {
124         return "UpdateType: " + mUpdateType
125                 + ", UpdateStatus: " + mUpdateStatuses.toString()
126                 + ", DeleteStatus: " + mDeleteStatuses.toString()
127                 + ", UpdateAndDeleteStartTimeMillis: " + mUpdateAndDeleteStartTimeMillis
128                 + ", ContactsUpdateFailedCount: " + mContactsUpdateFailedCount
129                 + ", ContactsUpdateSucceededCount: " + mContactsUpdateSucceededCount
130                 + ", NewContactsToBeUpdated: " + mNewContactsToBeUpdated
131                 + ", ContactsUpdateSkippedCount: " + mContactsUpdateSkippedCount
132                 + ", TotalContactsToBeUpdated: " + mTotalContactsToBeUpdated
133                 + ", ContactsDeleteFailedCount: " + mContactsDeleteFailedCount
134                 + ", ContactsDeleteSucceededCount: " + mContactsDeleteSucceededCount
135                 + ", TotalContactsToBeDeleted: " + mTotalContactsToBeDeleted;
136     }
137 }