• 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.NonNull;
20 import android.os.PersistableBundle;
21 
22 import com.android.server.appsearch.indexer.IndexerSettings;
23 
24 import java.io.File;
25 import java.util.Objects;
26 
27 /**
28  * Contacts indexer settings backed by a PersistableBundle.
29  *
30  * <p>Holds settings such as:
31  *
32  * <ul>
33  *   <li>the last time a full update was performed
34  *   <li>the last time a delta update was performed
35  *   <li>the time of the last CP2 contact update
36  *   <li>the time of the last CP2 contact deletion
37  * </ul>
38  *
39  * <p>This class is NOT thread safe (similar to {@link PersistableBundle} which it wraps).
40  *
41  * @hide
42  */
43 public class ContactsIndexerSettings extends IndexerSettings {
44 
45     private static final String TAG = "ContactsIndexerSettings";
46 
47     static final String SETTINGS_FILE_NAME = "contacts_indexer_settings.pb";
48     static final String LAST_FULL_UPDATE_TIMESTAMP_KEY = "last_full_update_timestamp_millis";
49     static final String LAST_DELTA_UPDATE_TIMESTAMP_KEY = "last_delta_update_timestamp_key";
50     // TODO(b/296078517): rename the keys to match the constants but keep backwards compatibility
51     // Note this constant was renamed from LAST_DELTA_UPDATE_TIMESTAMP_KEY but the key itself has
52     // been kept the same for backwards compatibility
53     static final String LAST_CONTACT_UPDATE_TIMESTAMP_KEY = "last_delta_update_timestamp_millis";
54     // Note this constant was renamed from LAST_DELTA_DELETE_TIMESTAMP_KEY but the key itself has
55     // been kept the same for backwards compatibility
56     static final String LAST_CONTACT_DELETE_TIMESTAMP_KEY = "last_delta_delete_timestamp_millis";
57 
ContactsIndexerSettings(@onNull File baseDir)58     public ContactsIndexerSettings(@NonNull File baseDir) {
59         super(Objects.requireNonNull(baseDir));
60     }
61 
62     @Override
getSettingsFileName()63     protected String getSettingsFileName() {
64         return SETTINGS_FILE_NAME;
65     }
66 
67     /** Returns the timestamp of when the last full update occurred in milliseconds. */
getLastFullUpdateTimestampMillis()68     public long getLastFullUpdateTimestampMillis() {
69         return mBundle.getLong(LAST_FULL_UPDATE_TIMESTAMP_KEY);
70     }
71 
72     /** Sets the timestamp of when the last full update occurred in milliseconds. */
setLastFullUpdateTimestampMillis(long timestampMillis)73     public void setLastFullUpdateTimestampMillis(long timestampMillis) {
74         mBundle.putLong(LAST_FULL_UPDATE_TIMESTAMP_KEY, timestampMillis);
75     }
76 
77     /** Returns the timestamp of when the last delta update occurred in milliseconds. */
getLastDeltaUpdateTimestampMillis()78     public long getLastDeltaUpdateTimestampMillis() {
79         return mBundle.getLong(LAST_DELTA_UPDATE_TIMESTAMP_KEY);
80     }
81 
82     /** Sets the timestamp of when the last delta update occurred in milliseconds. */
setLastDeltaUpdateTimestampMillis(long timestampMillis)83     public void setLastDeltaUpdateTimestampMillis(long timestampMillis) {
84         mBundle.putLong(LAST_DELTA_UPDATE_TIMESTAMP_KEY, timestampMillis);
85     }
86 
87     /** Returns the timestamp of when the last contact in CP2 was updated in milliseconds. */
getLastContactUpdateTimestampMillis()88     public long getLastContactUpdateTimestampMillis() {
89         return mBundle.getLong(LAST_CONTACT_UPDATE_TIMESTAMP_KEY);
90     }
91 
92     /** Sets the timestamp of when the last contact in CP2 was updated in milliseconds. */
setLastContactUpdateTimestampMillis(long timestampMillis)93     public void setLastContactUpdateTimestampMillis(long timestampMillis) {
94         mBundle.putLong(LAST_CONTACT_UPDATE_TIMESTAMP_KEY, timestampMillis);
95     }
96 
97     /** Returns the timestamp of when the last contact in CP2 was deleted in milliseconds. */
getLastContactDeleteTimestampMillis()98     public long getLastContactDeleteTimestampMillis() {
99         return mBundle.getLong(LAST_CONTACT_DELETE_TIMESTAMP_KEY);
100     }
101 
102     /** Sets the timestamp of when the last contact in CP2 was deleted in milliseconds. */
setLastContactDeleteTimestampMillis(long timestampMillis)103     public void setLastContactDeleteTimestampMillis(long timestampMillis) {
104         mBundle.putLong(LAST_CONTACT_DELETE_TIMESTAMP_KEY, timestampMillis);
105     }
106 
107     /** Resets all the settings to default values. */
108     @Override
reset()109     public void reset() {
110         setLastFullUpdateTimestampMillis(0);
111         setLastDeltaUpdateTimestampMillis(0);
112         setLastContactUpdateTimestampMillis(0);
113         setLastContactDeleteTimestampMillis(0);
114     }
115 }
116