1 /*
2  * Copyright (C) 2021 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 package com.android.server.appsearch;
17 
18 import android.annotation.NonNull;
19 
20 import com.android.internal.annotations.VisibleForTesting;
21 import com.android.server.appsearch.external.localstorage.AppSearchImpl;
22 import com.android.server.appsearch.external.localstorage.visibilitystore.VisibilityChecker;
23 
24 import java.util.Objects;
25 
26 /**
27  * Container for AppSearch classes that should only be initialized once per device-user and make up
28  * the core of the AppSearch system.
29  */
30 public final class AppSearchUserInstance {
31     private volatile InternalAppSearchLogger mLogger;
32     private final AppSearchImpl mAppSearchImpl;
33     private final VisibilityChecker mVisibilityChecker;
34 
AppSearchUserInstance( @onNull InternalAppSearchLogger logger, @NonNull AppSearchImpl appSearchImpl, @NonNull VisibilityChecker visibilityChecker)35     AppSearchUserInstance(
36             @NonNull InternalAppSearchLogger logger,
37             @NonNull AppSearchImpl appSearchImpl,
38             @NonNull VisibilityChecker visibilityChecker) {
39         mLogger = Objects.requireNonNull(logger);
40         mAppSearchImpl = Objects.requireNonNull(appSearchImpl);
41         mVisibilityChecker = Objects.requireNonNull(visibilityChecker);
42     }
43 
44     @NonNull
getLogger()45     public InternalAppSearchLogger getLogger() {
46         return mLogger;
47     }
48 
49     @NonNull
getAppSearchImpl()50     public AppSearchImpl getAppSearchImpl() {
51         return mAppSearchImpl;
52     }
53 
54     @NonNull
getVisibilityChecker()55     public VisibilityChecker getVisibilityChecker() {
56         return mVisibilityChecker;
57     }
58 
59     @VisibleForTesting
setLoggerForTest(@onNull InternalAppSearchLogger logger)60     void setLoggerForTest(@NonNull InternalAppSearchLogger logger) {
61         mLogger = Objects.requireNonNull(logger);
62     }
63 }
64