• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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 android.app.appsearch;
18 
19 import android.annotation.IntDef;
20 import android.content.Context;
21 import android.os.UserHandle;
22 
23 import org.jspecify.annotations.NonNull;
24 import org.jspecify.annotations.Nullable;
25 
26 import java.io.File;
27 import java.lang.annotation.Retention;
28 import java.lang.annotation.RetentionPolicy;
29 import java.util.concurrent.BlockingQueue;
30 import java.util.concurrent.ExecutorService;
31 import java.util.concurrent.TimeUnit;
32 
33 /**
34  * An interface which exposes environment specific methods for AppSearch.
35  *
36  * @hide
37  */
38 public interface AppSearchEnvironment {
39 
40     /** Returns the directory to initialize appsearch based on the environment. */
getAppSearchDir(@onNull Context context, @Nullable UserHandle userHandle)41     @NonNull File getAppSearchDir(@NonNull Context context, @Nullable UserHandle userHandle);
42 
43     /** Returns the correct context for the user based on the environment. */
createContextAsUser(@onNull Context context, @NonNull UserHandle userHandle)44     @NonNull Context createContextAsUser(@NonNull Context context, @NonNull UserHandle userHandle);
45 
46     /** Returns an ExecutorService based on given parameters. */
createExecutorService( int corePoolSize, int maxConcurrency, long keepAliveTime, @NonNull TimeUnit unit, @NonNull BlockingQueue<Runnable> workQueue, int priority)47     @NonNull ExecutorService createExecutorService(
48             int corePoolSize,
49             int maxConcurrency,
50             long keepAliveTime,
51             @NonNull TimeUnit unit,
52             @NonNull BlockingQueue<Runnable> workQueue,
53             int priority);
54 
55     /** Returns an ExecutorService with a single thread. */
createSingleThreadExecutor()56     @NonNull ExecutorService createSingleThreadExecutor();
57 
58     /** Creates and returns an Executor with cached thread pools. */
createCachedThreadPoolExecutor()59     @NonNull ExecutorService createCachedThreadPoolExecutor();
60 
61     /**
62      * Returns a cache directory for creating temporary files like in case of migrating documents.
63      */
getCacheDir(@onNull Context context)64     @Nullable File getCacheDir(@NonNull Context context);
65 
66     /** Returns if we can log INFO level logs. */
isInfoLoggingEnabled()67     boolean isInfoLoggingEnabled();
68 
69     /** The different environments that AppSearch code might be built in. */
70     @Retention(RetentionPolicy.SOURCE)
71     @IntDef(
72             value = {
73                 JETPACK_ENVIRONMENT,
74                 FRAMEWORK_ENVIRONMENT,
75                 PLAY_SERVICES_ENVIRONMENT,
76             })
77     @interface EnvironmentType {}
78 
79     /** This code is being built in the Jetpack Environment */
80     int JETPACK_ENVIRONMENT = 1;
81 
82     /** This code is being built in the Android Framework Environment */
83     int FRAMEWORK_ENVIRONMENT = 2;
84 
85     /** This code is being built in the internal environment for Play Services code. */
86     int PLAY_SERVICES_ENVIRONMENT = 3;
87 
88     /** Returns the {@code EnvironmentType} for this environment. */
89     @EnvironmentType
getEnvironment()90     int getEnvironment();
91 }
92