• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static com.android.server.appsearch.appsindexer.AppIndexerVersions.APP_INDEXER_VERSION_UNKNOWN;
20 
21 import android.annotation.NonNull;
22 
23 import com.android.server.appsearch.indexer.IndexerSettings;
24 
25 import java.io.File;
26 
27 /**
28  * Apps indexer settings backed by a PersistableBundle.
29  *
30  * <p>Holds settings such as:
31  *
32  * <ul>
33  *   <li>the timestamp of the last full update
34  *   <li>the timestamp of the last apps update
35  * </ul>
36  */
37 public class AppsIndexerSettings extends IndexerSettings {
38     static final String SETTINGS_FILE_NAME = "apps_indexer_settings.pb";
39     static final String LAST_APP_UPDATE_TIMESTAMP_KEY = "last_app_update_timestamp_millis";
40 
41     static final String PREVIOUS_APP_INDEXER_VERSION_CODE = "previous_app_indexer_version_code";
42 
AppsIndexerSettings(@onNull File baseDir)43     public AppsIndexerSettings(@NonNull File baseDir) {
44         super(baseDir);
45     }
46 
47     @Override
getSettingsFileName()48     protected String getSettingsFileName() {
49         return SETTINGS_FILE_NAME;
50     }
51 
52     /** Returns the timestamp of when the last app was updated in milliseconds. */
getLastAppUpdateTimestampMillis()53     public long getLastAppUpdateTimestampMillis() {
54         return mBundle.getLong(LAST_APP_UPDATE_TIMESTAMP_KEY);
55     }
56 
57     /** Sets the timestamp of when the last app was updated in milliseconds. */
setLastAppUpdateTimestampMillis(long timestampMillis)58     public void setLastAppUpdateTimestampMillis(long timestampMillis) {
59         mBundle.putLong(LAST_APP_UPDATE_TIMESTAMP_KEY, timestampMillis);
60     }
61 
62     /** Returns the version code of AppSearch module that previously indexed the apps. */
63     @AppIndexerVersions.AppIndexerVersion
getPreviousIndexerVersionCode()64     public int getPreviousIndexerVersionCode() {
65         return mBundle.getInt(PREVIOUS_APP_INDEXER_VERSION_CODE, APP_INDEXER_VERSION_UNKNOWN);
66     }
67 
68     /** Sets the version code of App Indexer that previously indexed the apps. */
setPreviousIndexerVersionCode( @ppIndexerVersions.AppIndexerVersion int versionCode)69     public void setPreviousIndexerVersionCode(
70             @AppIndexerVersions.AppIndexerVersion int versionCode) {
71         mBundle.putInt(PREVIOUS_APP_INDEXER_VERSION_CODE, versionCode);
72     }
73 
74     /** Resets all settings to default values except {@link #getPreviousIndexerVersionCode()}. */
75     @Override
reset()76     public void reset() {
77         super.reset();
78         setLastAppUpdateTimestampMillis(0);
79         setPreviousIndexerVersionCode(APP_INDEXER_VERSION_UNKNOWN);
80     }
81 }
82