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.NonNull;
20 import android.annotation.Nullable;
21 import android.content.Context;
22 import android.os.UserHandle;
23 
24 import java.io.File;
25 import java.util.concurrent.BlockingQueue;
26 import java.util.concurrent.ExecutorService;
27 import java.util.concurrent.TimeUnit;
28 
29 /**
30  * An interface which exposes environment specific methods for AppSearch.
31  *
32  * @hide
33  */
34 public interface AppSearchEnvironment {
35 
36     /** Returns the directory to initialize appsearch based on the environment. */
37     @NonNull
getAppSearchDir(@onNull Context context, @Nullable UserHandle userHandle)38     File getAppSearchDir(@NonNull Context context, @Nullable UserHandle userHandle);
39 
40     /** Returns the correct context for the user based on the environment. */
41     @NonNull
createContextAsUser(@onNull Context context, @NonNull UserHandle userHandle)42     Context createContextAsUser(@NonNull Context context, @NonNull UserHandle userHandle);
43 
44     /** Returns an ExecutorService based on given parameters. */
45     @NonNull
createExecutorService( int corePoolSize, int maxConcurrency, long keepAliveTime, @NonNull TimeUnit unit, @NonNull BlockingQueue<Runnable> workQueue, int priority)46     ExecutorService createExecutorService(
47             int corePoolSize,
48             int maxConcurrency,
49             long keepAliveTime,
50             @NonNull TimeUnit unit,
51             @NonNull BlockingQueue<Runnable> workQueue,
52             int priority);
53 
54     /** Returns an ExecutorService with a single thread. */
55     @NonNull
createSingleThreadExecutor()56     ExecutorService createSingleThreadExecutor();
57 
58     /** Creates and returns an Executor with cached thread pools. */
59     @NonNull
createCachedThreadPoolExecutor()60     ExecutorService createCachedThreadPoolExecutor();
61 
62     /**
63      * Returns a cache directory for creating temporary files like in case of migrating documents.
64      */
65     @Nullable
getCacheDir(@onNull Context context)66     File getCacheDir(@NonNull Context context);
67 
68     /** Returns if we can log INFO level logs. */
isInfoLoggingEnabled()69     boolean isInfoLoggingEnabled();
70 }
71