• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.CallbackExecutor;
20 import android.annotation.FlaggedApi;
21 import android.annotation.NonNull;
22 import android.app.appsearch.aidl.AppSearchAttributionSource;
23 import android.app.appsearch.aidl.IAppSearchManager;
24 import android.os.UserHandle;
25 
26 import com.android.appsearch.flags.Flags;
27 
28 import java.util.concurrent.Executor;
29 import java.util.function.Consumer;
30 
31 /**
32  * Provides a connection to all enterprise (work profile) AppSearch databases the querying
33  * application has been granted access to.
34  *
35  * <p>This session can be created from any user profile but will only properly return results when
36  * created from the main profile. If the user is not the main profile or an associated work profile
37  * does not exist, queries will still successfully complete but with empty results.
38  *
39  * <p>Schemas must be explicitly tagged enterprise and may require additional permissions to be
40  * visible from an enterprise session. Retrieved documents may also have certain fields restricted
41  * or modified unlike if they were retrieved directly from {@link GlobalSearchSession} on the work
42  * profile.
43  *
44  * <p>This class is thread safe.
45  *
46  * @see GlobalSearchSession
47  */
48 @FlaggedApi(Flags.FLAG_ENABLE_ENTERPRISE_GLOBAL_SEARCH_SESSION)
49 public class EnterpriseGlobalSearchSession extends ReadOnlyGlobalSearchSession {
50 
51     /**
52      * Creates an enterprise search session for the client, defined by the {@code userHandle} and
53      * {@code packageName}.
54      */
createEnterpriseGlobalSearchSession( @onNull IAppSearchManager service, @NonNull UserHandle userHandle, @NonNull AppSearchAttributionSource attributionSource, @NonNull @CallbackExecutor Executor executor, @NonNull Consumer<AppSearchResult<EnterpriseGlobalSearchSession>> callback)55     static void createEnterpriseGlobalSearchSession(
56             @NonNull IAppSearchManager service,
57             @NonNull UserHandle userHandle,
58             @NonNull AppSearchAttributionSource attributionSource,
59             @NonNull @CallbackExecutor Executor executor,
60             @NonNull Consumer<AppSearchResult<EnterpriseGlobalSearchSession>> callback) {
61         EnterpriseGlobalSearchSession enterpriseGlobalSearchSession =
62                 new EnterpriseGlobalSearchSession(service, userHandle, attributionSource);
63         enterpriseGlobalSearchSession.initialize(
64                 executor,
65                 result -> {
66                     if (result.isSuccess()) {
67                         callback.accept(
68                                 AppSearchResult.newSuccessfulResult(enterpriseGlobalSearchSession));
69                     } else {
70                         callback.accept(AppSearchResult.newFailedResult(result));
71                     }
72                 });
73     }
74 
EnterpriseGlobalSearchSession( @onNull IAppSearchManager service, @NonNull UserHandle userHandle, @NonNull AppSearchAttributionSource callerAttributionSource)75     private EnterpriseGlobalSearchSession(
76             @NonNull IAppSearchManager service,
77             @NonNull UserHandle userHandle,
78             @NonNull AppSearchAttributionSource callerAttributionSource) {
79         super(service, userHandle, callerAttributionSource, /* isForEnterprise= */ true);
80     }
81 }
82