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.provider.DeviceConfig;
20 
21 /**
22  * Implementation of {@link ContactsIndexerConfig} using {@link DeviceConfig}.
23  *
24  * <p>It contains all the keys for flags related to Contacts Indexer.
25  *
26  * <p>This class is thread-safe.
27  *
28  * @hide
29  */
30 public class FrameworkContactsIndexerConfig implements ContactsIndexerConfig {
31     static final String KEY_CONTACTS_INDEXER_ENABLED = "contacts_indexer_enabled";
32     static final String KEY_CONTACTS_INSTANT_INDEXING_LIMIT = "contacts_instant_indexing_limit";
33     static final String KEY_CONTACTS_FULL_UPDATE_INTERVAL_MILLIS =
34             "contacts_full_update_interval_millis";
35     static final String KEY_CONTACTS_FULL_UPDATE_LIMIT = "contacts_indexer_full_update_limit";
36     static final String KEY_CONTACTS_DELTA_UPDATE_LIMIT = "contacts_indexer_delta_update_limit";
37     public static final String KEY_CONTACTS_INDEX_FIRST_MIDDLE_AND_LAST_NAMES =
38             "contacts_index_first_middle_and_last_names";
39     static final String KEY_CONTACTS_KEEP_UPDATING_ON_ERROR = "contacts_keep_updating_on_error";
40 
41     @Override
isContactsIndexerEnabled()42     public boolean isContactsIndexerEnabled() {
43         return DeviceConfig.getBoolean(
44                 DeviceConfig.NAMESPACE_APPSEARCH,
45                 KEY_CONTACTS_INDEXER_ENABLED,
46                 DEFAULT_CONTACTS_INDEXER_ENABLED);
47     }
48 
49     @Override
getContactsFirstRunIndexingLimit()50     public int getContactsFirstRunIndexingLimit() {
51         return DeviceConfig.getInt(
52                 DeviceConfig.NAMESPACE_APPSEARCH,
53                 KEY_CONTACTS_INSTANT_INDEXING_LIMIT,
54                 DEFAULT_CONTACTS_FIRST_RUN_INDEXING_LIMIT);
55     }
56 
57     @Override
getContactsFullUpdateIntervalMillis()58     public long getContactsFullUpdateIntervalMillis() {
59         return DeviceConfig.getLong(
60                 DeviceConfig.NAMESPACE_APPSEARCH,
61                 KEY_CONTACTS_FULL_UPDATE_INTERVAL_MILLIS,
62                 DEFAULT_CONTACTS_FULL_UPDATE_INTERVAL_MILLIS);
63     }
64 
65     @Override
getContactsFullUpdateLimit()66     public int getContactsFullUpdateLimit() {
67         return DeviceConfig.getInt(
68                 DeviceConfig.NAMESPACE_APPSEARCH,
69                 KEY_CONTACTS_FULL_UPDATE_LIMIT,
70                 DEFAULT_CONTACTS_FULL_UPDATE_INDEXING_LIMIT);
71     }
72 
73     @Override
getContactsDeltaUpdateLimit()74     public int getContactsDeltaUpdateLimit() {
75         // TODO(b/227419499) Based on the metrics, we can tweak this number. Right now it is same
76         //  as the instant indexing limit, which is 1,000. From our stats in GMSCore, 95th
77         //  percentile for number of contacts on the device is around 2000 contacts.
78         return DeviceConfig.getInt(
79                 DeviceConfig.NAMESPACE_APPSEARCH,
80                 KEY_CONTACTS_DELTA_UPDATE_LIMIT,
81                 DEFAULT_CONTACTS_DELTA_UPDATE_INDEXING_LIMIT);
82     }
83 
84     @Override
shouldIndexFirstMiddleAndLastNames()85     public boolean shouldIndexFirstMiddleAndLastNames() {
86         return DeviceConfig.getBoolean(
87                 DeviceConfig.NAMESPACE_APPSEARCH,
88                 KEY_CONTACTS_INDEX_FIRST_MIDDLE_AND_LAST_NAMES,
89                 DEFAULT_CONTACTS_INDEX_FIRST_MIDDLE_AND_LAST_NAMES);
90     }
91 
92     @Override
shouldKeepUpdatingOnError()93     public boolean shouldKeepUpdatingOnError() {
94         return DeviceConfig.getBoolean(
95                 DeviceConfig.NAMESPACE_APPSEARCH,
96                 KEY_CONTACTS_KEEP_UPDATING_ON_ERROR,
97                 DEFAULT_CONTACTS_KEEP_UPDATING_ON_ERROR);
98     }
99 }
100