Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 1 | /* |
sidchhabra | a7c8f8a | 2020-01-16 18:38:17 -0800 | [diff] [blame] | 2 | * Copyright (C) 2020 The Android Open Source Project |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 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 | |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 18 | import static android.app.appsearch.AppSearchResult.throwableToFailedResult; |
| 19 | |
sidchhabra | a7c8f8a | 2020-01-16 18:38:17 -0800 | [diff] [blame] | 20 | import android.annotation.NonNull; |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 21 | import android.annotation.UserIdInt; |
| 22 | import android.app.ActivityManager; |
Alexander Dorokhine | 1846584 | 2020-01-21 01:08:57 -0800 | [diff] [blame] | 23 | import android.app.appsearch.AppSearchBatchResult; |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 24 | import android.app.appsearch.AppSearchResult; |
Alexander Dorokhine | 92ce353 | 2020-10-06 01:39:36 -0700 | [diff] [blame] | 25 | import android.app.appsearch.AppSearchSchema; |
Alexander Dorokhine | c66d67c | 2020-10-08 13:44:04 -0700 | [diff] [blame] | 26 | import android.app.appsearch.GenericDocument; |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 27 | import android.app.appsearch.IAppSearchBatchResultCallback; |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 28 | import android.app.appsearch.IAppSearchManager; |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 29 | import android.app.appsearch.IAppSearchResultCallback; |
Alexander Dorokhine | ab78906 | 2021-01-11 21:00:00 -0800 | [diff] [blame^] | 30 | import android.app.appsearch.PackageIdentifier; |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 31 | import android.app.appsearch.SearchResultPage; |
Alexander Dorokhine | c9fc960 | 2020-10-06 01:39:50 -0700 | [diff] [blame] | 32 | import android.app.appsearch.SearchSpec; |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 33 | import android.content.Context; |
Alexander Dorokhine | 270d4f1 | 2020-01-15 17:24:35 -0800 | [diff] [blame] | 34 | import android.os.Binder; |
Alexander Dorokhine | 92ce353 | 2020-10-06 01:39:36 -0700 | [diff] [blame] | 35 | import android.os.Bundle; |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 36 | import android.os.ParcelableException; |
| 37 | import android.os.RemoteException; |
Alexander Dorokhine | ab78906 | 2021-01-11 21:00:00 -0800 | [diff] [blame^] | 38 | import android.util.ArrayMap; |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 39 | import android.util.Log; |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 40 | |
Alexander Dorokhine | 270d4f1 | 2020-01-15 17:24:35 -0800 | [diff] [blame] | 41 | import com.android.internal.util.Preconditions; |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 42 | import com.android.server.SystemService; |
Alexander Dorokhine | f660d8f | 2020-10-29 22:37:00 -0700 | [diff] [blame] | 43 | import com.android.server.appsearch.external.localstorage.AppSearchImpl; |
Alexander Dorokhine | fd07eba | 2020-01-13 20:22:20 -0800 | [diff] [blame] | 44 | |
Alexander Dorokhine | 6a99f94 | 2020-12-04 02:57:22 -0800 | [diff] [blame] | 45 | import java.util.ArrayList; |
Alexander Dorokhine | 1846584 | 2020-01-21 01:08:57 -0800 | [diff] [blame] | 46 | import java.util.List; |
Alexander Dorokhine | ab78906 | 2021-01-11 21:00:00 -0800 | [diff] [blame^] | 47 | import java.util.Map; |
Alexander Dorokhine | 1846584 | 2020-01-21 01:08:57 -0800 | [diff] [blame] | 48 | |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 49 | /** |
| 50 | * TODO(b/142567528): add comments when implement this class |
| 51 | */ |
| 52 | public class AppSearchManagerService extends SystemService { |
Alexander Dorokhine | ebd3774 | 2020-09-22 15:02:26 -0700 | [diff] [blame] | 53 | private static final String TAG = "AppSearchManagerService"; |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 54 | |
| 55 | public AppSearchManagerService(Context context) { |
| 56 | super(context); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public void onStart() { |
| 61 | publishBinderService(Context.APP_SEARCH_SERVICE, new Stub()); |
| 62 | } |
| 63 | |
| 64 | private class Stub extends IAppSearchManager.Stub { |
Alexander Dorokhine | fd07eba | 2020-01-13 20:22:20 -0800 | [diff] [blame] | 65 | @Override |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 66 | public void setSchema( |
Terry Wang | 6413aee | 2020-10-07 03:04:58 -0700 | [diff] [blame] | 67 | @NonNull String databaseName, |
Alexander Dorokhine | 92ce353 | 2020-10-06 01:39:36 -0700 | [diff] [blame] | 68 | @NonNull List<Bundle> schemaBundles, |
Alexander Dorokhine | 6a99f94 | 2020-12-04 02:57:22 -0800 | [diff] [blame] | 69 | @NonNull List<String> schemasNotPlatformSurfaceable, |
Alexander Dorokhine | ab78906 | 2021-01-11 21:00:00 -0800 | [diff] [blame^] | 70 | @NonNull Map<String, List<Bundle>> schemasPackageAccessibleBundles, |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 71 | boolean forceOverride, |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 72 | @UserIdInt int userId, |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 73 | @NonNull IAppSearchResultCallback callback) { |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 74 | Preconditions.checkNotNull(databaseName); |
Alexander Dorokhine | 92ce353 | 2020-10-06 01:39:36 -0700 | [diff] [blame] | 75 | Preconditions.checkNotNull(schemaBundles); |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 76 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 77 | int callingUid = Binder.getCallingUid(); |
| 78 | int callingUserId = handleIncomingUser(userId, callingUid); |
Jeff Sharkey | ea5328c | 2020-10-06 11:18:09 -0600 | [diff] [blame] | 79 | final long callingIdentity = Binder.clearCallingIdentity(); |
Alexander Dorokhine | fd07eba | 2020-01-13 20:22:20 -0800 | [diff] [blame] | 80 | try { |
Alexander Dorokhine | 6a99f94 | 2020-12-04 02:57:22 -0800 | [diff] [blame] | 81 | List<AppSearchSchema> schemas = new ArrayList<>(schemaBundles.size()); |
Alexander Dorokhine | 92ce353 | 2020-10-06 01:39:36 -0700 | [diff] [blame] | 82 | for (int i = 0; i < schemaBundles.size(); i++) { |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 83 | schemas.add(new AppSearchSchema(schemaBundles.get(i))); |
Alexander Dorokhine | 92ce353 | 2020-10-06 01:39:36 -0700 | [diff] [blame] | 84 | } |
Alexander Dorokhine | ab78906 | 2021-01-11 21:00:00 -0800 | [diff] [blame^] | 85 | Map<String, List<PackageIdentifier>> schemasPackageAccessible = |
| 86 | new ArrayMap<>(schemasPackageAccessibleBundles.size()); |
| 87 | for (Map.Entry<String, List<Bundle>> entry : |
| 88 | schemasPackageAccessibleBundles.entrySet()) { |
| 89 | List<PackageIdentifier> packageIdentifiers = |
| 90 | new ArrayList<>(entry.getValue().size()); |
| 91 | for (int i = 0; i < packageIdentifiers.size(); i++) { |
| 92 | packageIdentifiers.add(new PackageIdentifier(entry.getValue().get(i))); |
| 93 | } |
| 94 | schemasPackageAccessible.put(entry.getKey(), packageIdentifiers); |
| 95 | } |
Terry Wang | 0d39387 | 2020-12-11 22:17:09 +0000 | [diff] [blame] | 96 | AppSearchImpl impl = ImplInstanceManager.getInstance(getContext(), callingUserId); |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 97 | String packageName = convertUidToPackageName(callingUid); |
Alexander Dorokhine | ab78906 | 2021-01-11 21:00:00 -0800 | [diff] [blame^] | 98 | impl.setSchema( |
| 99 | packageName, |
| 100 | databaseName, |
| 101 | schemas, |
| 102 | schemasNotPlatformSurfaceable, |
| 103 | schemasPackageAccessible, |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 104 | forceOverride); |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 105 | invokeCallbackOnResult(callback, |
| 106 | AppSearchResult.newSuccessfulResult(/*result=*/ null)); |
Alexander Dorokhine | 179c8b8 | 2020-01-11 00:17:48 -0800 | [diff] [blame] | 107 | } catch (Throwable t) { |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 108 | invokeCallbackOnError(callback, t); |
Alexander Dorokhine | 270d4f1 | 2020-01-15 17:24:35 -0800 | [diff] [blame] | 109 | } finally { |
| 110 | Binder.restoreCallingIdentity(callingIdentity); |
Alexander Dorokhine | 179c8b8 | 2020-01-11 00:17:48 -0800 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | |
| 114 | @Override |
Terry Wang | 83a2493 | 2020-12-09 21:00:18 -0800 | [diff] [blame] | 115 | public void getSchema( |
| 116 | @NonNull String databaseName, |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 117 | @UserIdInt int userId, |
Terry Wang | 83a2493 | 2020-12-09 21:00:18 -0800 | [diff] [blame] | 118 | @NonNull IAppSearchResultCallback callback) { |
| 119 | Preconditions.checkNotNull(databaseName); |
| 120 | Preconditions.checkNotNull(callback); |
| 121 | int callingUid = Binder.getCallingUidOrThrow(); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 122 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | 83a2493 | 2020-12-09 21:00:18 -0800 | [diff] [blame] | 123 | final long callingIdentity = Binder.clearCallingIdentity(); |
| 124 | try { |
| 125 | AppSearchImpl impl = ImplInstanceManager.getInstance(getContext(), callingUserId); |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 126 | String packageName = convertUidToPackageName(callingUid); |
| 127 | List<AppSearchSchema> schemas = impl.getSchema(packageName, databaseName); |
Terry Wang | 83a2493 | 2020-12-09 21:00:18 -0800 | [diff] [blame] | 128 | List<Bundle> schemaBundles = new ArrayList<>(schemas.size()); |
| 129 | for (int i = 0; i < schemas.size(); i++) { |
| 130 | schemaBundles.add(schemas.get(i).getBundle()); |
| 131 | } |
| 132 | invokeCallbackOnResult(callback, |
| 133 | AppSearchResult.newSuccessfulResult(schemaBundles)); |
| 134 | } catch (Throwable t) { |
| 135 | invokeCallbackOnError(callback, t); |
| 136 | } finally { |
| 137 | Binder.restoreCallingIdentity(callingIdentity); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | @Override |
Alexander Dorokhine | 1846584 | 2020-01-21 01:08:57 -0800 | [diff] [blame] | 142 | public void putDocuments( |
Terry Wang | 6413aee | 2020-10-07 03:04:58 -0700 | [diff] [blame] | 143 | @NonNull String databaseName, |
Alexander Dorokhine | c66d67c | 2020-10-08 13:44:04 -0700 | [diff] [blame] | 144 | @NonNull List<Bundle> documentBundles, |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 145 | @UserIdInt int userId, |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 146 | @NonNull IAppSearchBatchResultCallback callback) { |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 147 | Preconditions.checkNotNull(databaseName); |
Alexander Dorokhine | c66d67c | 2020-10-08 13:44:04 -0700 | [diff] [blame] | 148 | Preconditions.checkNotNull(documentBundles); |
Alexander Dorokhine | cc22345 | 2020-01-19 03:00:28 -0800 | [diff] [blame] | 149 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 150 | int callingUid = Binder.getCallingUid(); |
| 151 | int callingUserId = handleIncomingUser(userId, callingUid); |
Jeff Sharkey | ea5328c | 2020-10-06 11:18:09 -0600 | [diff] [blame] | 152 | final long callingIdentity = Binder.clearCallingIdentity(); |
Alexander Dorokhine | 179c8b8 | 2020-01-11 00:17:48 -0800 | [diff] [blame] | 153 | try { |
Alexander Dorokhine | 1846584 | 2020-01-21 01:08:57 -0800 | [diff] [blame] | 154 | AppSearchBatchResult.Builder<String, Void> resultBuilder = |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 155 | new AppSearchBatchResult.Builder<>(); |
Terry Wang | 0d39387 | 2020-12-11 22:17:09 +0000 | [diff] [blame] | 156 | AppSearchImpl impl = ImplInstanceManager.getInstance(getContext(), callingUserId); |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 157 | String packageName = convertUidToPackageName(callingUid); |
Alexander Dorokhine | c66d67c | 2020-10-08 13:44:04 -0700 | [diff] [blame] | 158 | for (int i = 0; i < documentBundles.size(); i++) { |
| 159 | GenericDocument document = new GenericDocument(documentBundles.get(i)); |
Alexander Dorokhine | 1846584 | 2020-01-21 01:08:57 -0800 | [diff] [blame] | 160 | try { |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 161 | // TODO(b/173451571): reduce burden of binder thread by enqueue request onto |
| 162 | // a separate thread. |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 163 | impl.putDocument(packageName, databaseName, document); |
Alexander Dorokhine | c66d67c | 2020-10-08 13:44:04 -0700 | [diff] [blame] | 164 | resultBuilder.setSuccess(document.getUri(), /*result=*/ null); |
Alexander Dorokhine | 1846584 | 2020-01-21 01:08:57 -0800 | [diff] [blame] | 165 | } catch (Throwable t) { |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 166 | resultBuilder.setResult(document.getUri(), throwableToFailedResult(t)); |
Alexander Dorokhine | 1846584 | 2020-01-21 01:08:57 -0800 | [diff] [blame] | 167 | } |
| 168 | } |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 169 | invokeCallbackOnResult(callback, resultBuilder.build()); |
Alexander Dorokhine | fd07eba | 2020-01-13 20:22:20 -0800 | [diff] [blame] | 170 | } catch (Throwable t) { |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 171 | invokeCallbackOnError(callback, t); |
Alexander Dorokhine | cc22345 | 2020-01-19 03:00:28 -0800 | [diff] [blame] | 172 | } finally { |
| 173 | Binder.restoreCallingIdentity(callingIdentity); |
Alexander Dorokhine | fd07eba | 2020-01-13 20:22:20 -0800 | [diff] [blame] | 174 | } |
| 175 | } |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 176 | |
Alexander Dorokhine | 69a8d9f | 2020-03-06 10:43:16 -0800 | [diff] [blame] | 177 | @Override |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 178 | public void getDocuments( |
| 179 | @NonNull String databaseName, |
| 180 | @NonNull String namespace, |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 181 | @NonNull List<String> uris, |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 182 | @UserIdInt int userId, |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 183 | @NonNull IAppSearchBatchResultCallback callback) { |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 184 | Preconditions.checkNotNull(databaseName); |
| 185 | Preconditions.checkNotNull(namespace); |
Alexander Dorokhine | 69a8d9f | 2020-03-06 10:43:16 -0800 | [diff] [blame] | 186 | Preconditions.checkNotNull(uris); |
| 187 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 188 | int callingUid = Binder.getCallingUid(); |
| 189 | int callingUserId = handleIncomingUser(userId, callingUid); |
Jeff Sharkey | ea5328c | 2020-10-06 11:18:09 -0600 | [diff] [blame] | 190 | final long callingIdentity = Binder.clearCallingIdentity(); |
Alexander Dorokhine | 69a8d9f | 2020-03-06 10:43:16 -0800 | [diff] [blame] | 191 | try { |
Alexander Dorokhine | c66d67c | 2020-10-08 13:44:04 -0700 | [diff] [blame] | 192 | AppSearchBatchResult.Builder<String, Bundle> resultBuilder = |
Alexander Dorokhine | a95f44f | 2020-03-06 13:53:14 -0800 | [diff] [blame] | 193 | new AppSearchBatchResult.Builder<>(); |
Terry Wang | 0d39387 | 2020-12-11 22:17:09 +0000 | [diff] [blame] | 194 | AppSearchImpl impl = ImplInstanceManager.getInstance(getContext(), callingUserId); |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 195 | String packageName = convertUidToPackageName(callingUid); |
Alexander Dorokhine | a95f44f | 2020-03-06 13:53:14 -0800 | [diff] [blame] | 196 | for (int i = 0; i < uris.size(); i++) { |
| 197 | String uri = uris.get(i); |
| 198 | try { |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 199 | GenericDocument document = impl.getDocument(packageName, databaseName, |
| 200 | namespace, uri); |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 201 | resultBuilder.setSuccess(uri, document.getBundle()); |
Alexander Dorokhine | a95f44f | 2020-03-06 13:53:14 -0800 | [diff] [blame] | 202 | } catch (Throwable t) { |
| 203 | resultBuilder.setResult(uri, throwableToFailedResult(t)); |
| 204 | } |
Alexander Dorokhine | 69a8d9f | 2020-03-06 10:43:16 -0800 | [diff] [blame] | 205 | } |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 206 | invokeCallbackOnResult(callback, resultBuilder.build()); |
Alexander Dorokhine | 69a8d9f | 2020-03-06 10:43:16 -0800 | [diff] [blame] | 207 | } catch (Throwable t) { |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 208 | invokeCallbackOnError(callback, t); |
Alexander Dorokhine | 69a8d9f | 2020-03-06 10:43:16 -0800 | [diff] [blame] | 209 | } finally { |
| 210 | Binder.restoreCallingIdentity(callingIdentity); |
| 211 | } |
| 212 | } |
| 213 | |
sidchhabra | a7c8f8a | 2020-01-16 18:38:17 -0800 | [diff] [blame] | 214 | // TODO(sidchhabra): Do this in a threadpool. |
| 215 | @Override |
Alexander Dorokhine | e708e18 | 2020-03-06 15:30:34 -0800 | [diff] [blame] | 216 | public void query( |
Terry Wang | 6413aee | 2020-10-07 03:04:58 -0700 | [diff] [blame] | 217 | @NonNull String databaseName, |
Alexander Dorokhine | c9fc960 | 2020-10-06 01:39:50 -0700 | [diff] [blame] | 218 | @NonNull String queryExpression, |
| 219 | @NonNull Bundle searchSpecBundle, |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 220 | @UserIdInt int userId, |
Alexander Dorokhine | d48f236 | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 221 | @NonNull IAppSearchResultCallback callback) { |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 222 | Preconditions.checkNotNull(databaseName); |
Alexander Dorokhine | c9fc960 | 2020-10-06 01:39:50 -0700 | [diff] [blame] | 223 | Preconditions.checkNotNull(queryExpression); |
| 224 | Preconditions.checkNotNull(searchSpecBundle); |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 225 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 226 | int callingUid = Binder.getCallingUid(); |
| 227 | int callingUserId = handleIncomingUser(userId, callingUid); |
Jeff Sharkey | ea5328c | 2020-10-06 11:18:09 -0600 | [diff] [blame] | 228 | final long callingIdentity = Binder.clearCallingIdentity(); |
sidchhabra | a7c8f8a | 2020-01-16 18:38:17 -0800 | [diff] [blame] | 229 | try { |
Terry Wang | 0d39387 | 2020-12-11 22:17:09 +0000 | [diff] [blame] | 230 | AppSearchImpl impl = ImplInstanceManager.getInstance(getContext(), callingUserId); |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 231 | String packageName = convertUidToPackageName(callingUid); |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 232 | SearchResultPage searchResultPage = impl.query( |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 233 | packageName, |
Alexander Dorokhine | c9fc960 | 2020-10-06 01:39:50 -0700 | [diff] [blame] | 234 | databaseName, |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 235 | queryExpression, |
| 236 | new SearchSpec(searchSpecBundle)); |
Alexander Dorokhine | d48f236 | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 237 | invokeCallbackOnResult(callback, |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 238 | AppSearchResult.newSuccessfulResult(searchResultPage.getBundle())); |
Alexander Dorokhine | e708e18 | 2020-03-06 15:30:34 -0800 | [diff] [blame] | 239 | } catch (Throwable t) { |
Alexander Dorokhine | d48f236 | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 240 | invokeCallbackOnError(callback, t); |
| 241 | } finally { |
| 242 | Binder.restoreCallingIdentity(callingIdentity); |
| 243 | } |
| 244 | } |
| 245 | |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 246 | @Override |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 247 | public void globalQuery( |
| 248 | @NonNull String queryExpression, |
| 249 | @NonNull Bundle searchSpecBundle, |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 250 | @UserIdInt int userId, |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 251 | @NonNull IAppSearchResultCallback callback) { |
| 252 | Preconditions.checkNotNull(queryExpression); |
| 253 | Preconditions.checkNotNull(searchSpecBundle); |
| 254 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 255 | int callingUid = Binder.getCallingUid(); |
| 256 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 257 | final long callingIdentity = Binder.clearCallingIdentity(); |
| 258 | try { |
Terry Wang | 0d39387 | 2020-12-11 22:17:09 +0000 | [diff] [blame] | 259 | AppSearchImpl impl = ImplInstanceManager.getInstance(getContext(), callingUserId); |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 260 | SearchResultPage searchResultPage = impl.globalQuery( |
| 261 | queryExpression, |
| 262 | new SearchSpec(searchSpecBundle)); |
| 263 | invokeCallbackOnResult(callback, |
| 264 | AppSearchResult.newSuccessfulResult(searchResultPage.getBundle())); |
| 265 | } catch (Throwable t) { |
| 266 | invokeCallbackOnError(callback, t); |
| 267 | } finally { |
| 268 | Binder.restoreCallingIdentity(callingIdentity); |
| 269 | } |
| 270 | } |
| 271 | |
Alexander Dorokhine | d48f236 | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 272 | @Override |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 273 | public void getNextPage(long nextPageToken, @UserIdInt int userId, |
Alexander Dorokhine | d48f236 | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 274 | @NonNull IAppSearchResultCallback callback) { |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 275 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 276 | int callingUid = Binder.getCallingUid(); |
| 277 | int callingUserId = handleIncomingUser(userId, callingUid); |
Alexander Dorokhine | d48f236 | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 278 | final long callingIdentity = Binder.clearCallingIdentity(); |
| 279 | // TODO(b/162450968) check nextPageToken is being advanced by the same uid as originally |
| 280 | // opened it |
| 281 | try { |
Terry Wang | 0d39387 | 2020-12-11 22:17:09 +0000 | [diff] [blame] | 282 | AppSearchImpl impl = ImplInstanceManager.getInstance(getContext(), callingUserId); |
Alexander Dorokhine | d48f236 | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 283 | SearchResultPage searchResultPage = impl.getNextPage(nextPageToken); |
| 284 | invokeCallbackOnResult(callback, |
| 285 | AppSearchResult.newSuccessfulResult(searchResultPage.getBundle())); |
| 286 | } catch (Throwable t) { |
| 287 | invokeCallbackOnError(callback, t); |
| 288 | } finally { |
| 289 | Binder.restoreCallingIdentity(callingIdentity); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | @Override |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 294 | public void invalidateNextPageToken(long nextPageToken, @UserIdInt int userId) { |
| 295 | int callingUid = Binder.getCallingUid(); |
| 296 | int callingUserId = handleIncomingUser(userId, callingUid); |
Alexander Dorokhine | d48f236 | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 297 | final long callingIdentity = Binder.clearCallingIdentity(); |
| 298 | try { |
Terry Wang | 0d39387 | 2020-12-11 22:17:09 +0000 | [diff] [blame] | 299 | AppSearchImpl impl = ImplInstanceManager.getInstance(getContext(), callingUserId); |
Alexander Dorokhine | d48f236 | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 300 | impl.invalidateNextPageToken(nextPageToken); |
| 301 | } catch (Throwable t) { |
Terry Wang | 2da1785 | 2020-12-16 19:59:08 -0800 | [diff] [blame] | 302 | Log.e(TAG, "Unable to invalidate the query page token", t); |
Alexander Dorokhine | e708e18 | 2020-03-06 15:30:34 -0800 | [diff] [blame] | 303 | } finally { |
| 304 | Binder.restoreCallingIdentity(callingIdentity); |
sidchhabra | a7c8f8a | 2020-01-16 18:38:17 -0800 | [diff] [blame] | 305 | } |
sidchhabra | a7c8f8a | 2020-01-16 18:38:17 -0800 | [diff] [blame] | 306 | } |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 307 | |
Alexander Dorokhine | f6c66ae | 2020-03-09 14:47:25 -0700 | [diff] [blame] | 308 | @Override |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 309 | public void removeByUri( |
| 310 | @NonNull String databaseName, |
| 311 | @NonNull String namespace, |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 312 | @NonNull List<String> uris, |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 313 | @UserIdInt int userId, |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 314 | @NonNull IAppSearchBatchResultCallback callback) { |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 315 | Preconditions.checkNotNull(databaseName); |
Alexander Dorokhine | ff82fba | 2020-03-09 16:35:24 -0700 | [diff] [blame] | 316 | Preconditions.checkNotNull(uris); |
| 317 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 318 | int callingUid = Binder.getCallingUid(); |
| 319 | int callingUserId = handleIncomingUser(userId, callingUid); |
Jeff Sharkey | ea5328c | 2020-10-06 11:18:09 -0600 | [diff] [blame] | 320 | final long callingIdentity = Binder.clearCallingIdentity(); |
Alexander Dorokhine | ff82fba | 2020-03-09 16:35:24 -0700 | [diff] [blame] | 321 | try { |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 322 | AppSearchBatchResult.Builder<String, Void> resultBuilder = |
| 323 | new AppSearchBatchResult.Builder<>(); |
Terry Wang | 0d39387 | 2020-12-11 22:17:09 +0000 | [diff] [blame] | 324 | AppSearchImpl impl = ImplInstanceManager.getInstance(getContext(), callingUserId); |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 325 | String packageName = convertUidToPackageName(callingUid); |
Alexander Dorokhine | ff82fba | 2020-03-09 16:35:24 -0700 | [diff] [blame] | 326 | for (int i = 0; i < uris.size(); i++) { |
| 327 | String uri = uris.get(i); |
| 328 | try { |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 329 | impl.remove(packageName, databaseName, namespace, uri); |
Alexander Dorokhine | c66d67c | 2020-10-08 13:44:04 -0700 | [diff] [blame] | 330 | resultBuilder.setSuccess(uri, /*result= */null); |
Alexander Dorokhine | ff82fba | 2020-03-09 16:35:24 -0700 | [diff] [blame] | 331 | } catch (Throwable t) { |
| 332 | resultBuilder.setResult(uri, throwableToFailedResult(t)); |
| 333 | } |
| 334 | } |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 335 | invokeCallbackOnResult(callback, resultBuilder.build()); |
Alexander Dorokhine | ff82fba | 2020-03-09 16:35:24 -0700 | [diff] [blame] | 336 | } catch (Throwable t) { |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 337 | invokeCallbackOnError(callback, t); |
Alexander Dorokhine | ff82fba | 2020-03-09 16:35:24 -0700 | [diff] [blame] | 338 | } finally { |
| 339 | Binder.restoreCallingIdentity(callingIdentity); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | @Override |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 344 | public void removeByQuery( |
| 345 | @NonNull String databaseName, |
| 346 | @NonNull String queryExpression, |
| 347 | @NonNull Bundle searchSpecBundle, |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 348 | @UserIdInt int userId, |
Alexander Dorokhine | 178366b | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 349 | @NonNull IAppSearchResultCallback callback) { |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 350 | Preconditions.checkNotNull(databaseName); |
| 351 | Preconditions.checkNotNull(queryExpression); |
| 352 | Preconditions.checkNotNull(searchSpecBundle); |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 353 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 354 | int callingUid = Binder.getCallingUid(); |
| 355 | int callingUserId = handleIncomingUser(userId, callingUid); |
Jeff Sharkey | ea5328c | 2020-10-06 11:18:09 -0600 | [diff] [blame] | 356 | final long callingIdentity = Binder.clearCallingIdentity(); |
Alexander Dorokhine | f6c66ae | 2020-03-09 14:47:25 -0700 | [diff] [blame] | 357 | try { |
Terry Wang | 0d39387 | 2020-12-11 22:17:09 +0000 | [diff] [blame] | 358 | AppSearchImpl impl = ImplInstanceManager.getInstance(getContext(), callingUserId); |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 359 | String packageName = convertUidToPackageName(callingUid); |
| 360 | impl.removeByQuery(packageName, databaseName, queryExpression, |
Alexander Dorokhine | 178366b | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 361 | new SearchSpec(searchSpecBundle)); |
| 362 | invokeCallbackOnResult(callback, AppSearchResult.newSuccessfulResult(null)); |
Alexander Dorokhine | f6c66ae | 2020-03-09 14:47:25 -0700 | [diff] [blame] | 363 | } catch (Throwable t) { |
Alexander Dorokhine | 178366b | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 364 | invokeCallbackOnError(callback, t); |
Alexander Dorokhine | f6c66ae | 2020-03-09 14:47:25 -0700 | [diff] [blame] | 365 | } finally { |
| 366 | Binder.restoreCallingIdentity(callingIdentity); |
| 367 | } |
| 368 | } |
| 369 | |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 370 | @Override |
Terry Wang | 2da1785 | 2020-12-16 19:59:08 -0800 | [diff] [blame] | 371 | public void persistToDisk(@UserIdInt int userId) { |
| 372 | int callingUid = Binder.getCallingUidOrThrow(); |
| 373 | int callingUserId = handleIncomingUser(userId, callingUid); |
| 374 | final long callingIdentity = Binder.clearCallingIdentity(); |
| 375 | try { |
| 376 | AppSearchImpl impl = ImplInstanceManager.getInstance(getContext(), callingUserId); |
| 377 | impl.persistToDisk(); |
| 378 | } catch (Throwable t) { |
| 379 | Log.e(TAG, "Unable to persist the data to disk", t); |
| 380 | } finally { |
| 381 | Binder.restoreCallingIdentity(callingIdentity); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | @Override |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 386 | public void initialize(@UserIdInt int userId, @NonNull IAppSearchResultCallback callback) { |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 387 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 388 | int callingUid = Binder.getCallingUid(); |
| 389 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 390 | final long callingIdentity = Binder.clearCallingIdentity(); |
| 391 | try { |
Terry Wang | 0d39387 | 2020-12-11 22:17:09 +0000 | [diff] [blame] | 392 | ImplInstanceManager.getInstance(getContext(), callingUserId); |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 393 | invokeCallbackOnResult(callback, AppSearchResult.newSuccessfulResult(null)); |
| 394 | } catch (Throwable t) { |
| 395 | invokeCallbackOnError(callback, t); |
| 396 | } finally { |
| 397 | Binder.restoreCallingIdentity(callingIdentity); |
| 398 | } |
| 399 | } |
| 400 | |
Alexander Dorokhine | ebd3774 | 2020-09-22 15:02:26 -0700 | [diff] [blame] | 401 | /** |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 402 | * Returns a package name for the given uid. |
Alexander Dorokhine | ebd3774 | 2020-09-22 15:02:26 -0700 | [diff] [blame] | 403 | * |
| 404 | * <p>The current implementation returns the package name of the app with this uid in a |
| 405 | * format like {@code com.example.package} or {@code com.example.sharedname:5678}. |
| 406 | */ |
| 407 | @NonNull |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 408 | private String convertUidToPackageName(int callingUid) { |
Alexander Dorokhine | ebd3774 | 2020-09-22 15:02:26 -0700 | [diff] [blame] | 409 | // For regular apps, this call will return the package name. If callingUid is an |
| 410 | // android:sharedUserId, this value may be another type of name and have a :uid suffix. |
| 411 | String callingUidName = getContext().getPackageManager().getNameForUid(callingUid); |
| 412 | if (callingUidName == null) { |
| 413 | // Not sure how this is possible --- maybe app was uninstalled? |
| 414 | throw new IllegalStateException( |
| 415 | "Failed to look up package name for uid " + callingUid); |
| 416 | } |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 417 | return callingUidName; |
Alexander Dorokhine | ebd3774 | 2020-09-22 15:02:26 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 420 | /** Invokes the {@link IAppSearchResultCallback} with the result. */ |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 421 | private void invokeCallbackOnResult(IAppSearchResultCallback callback, |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 422 | AppSearchResult<?> result) { |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 423 | try { |
| 424 | callback.onResult(result); |
| 425 | } catch (RemoteException e) { |
Terry Wang | 2da1785 | 2020-12-16 19:59:08 -0800 | [diff] [blame] | 426 | Log.e(TAG, "Unable to send result to the callback", e); |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 427 | } |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 428 | } |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 429 | |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 430 | /** Invokes the {@link IAppSearchBatchResultCallback} with the result. */ |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 431 | private void invokeCallbackOnResult(IAppSearchBatchResultCallback callback, |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 432 | AppSearchBatchResult<?, ?> result) { |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 433 | try { |
| 434 | callback.onResult(result); |
| 435 | } catch (RemoteException e) { |
Terry Wang | 2da1785 | 2020-12-16 19:59:08 -0800 | [diff] [blame] | 436 | Log.e(TAG, "Unable to send result to the callback", e); |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 437 | } |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | /** |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 441 | * Invokes the {@link IAppSearchResultCallback} with an throwable. |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 442 | * |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 443 | * <p>The throwable is convert to a {@link AppSearchResult}; |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 444 | */ |
| 445 | private void invokeCallbackOnError(IAppSearchResultCallback callback, Throwable throwable) { |
| 446 | try { |
| 447 | callback.onResult(throwableToFailedResult(throwable)); |
| 448 | } catch (RemoteException e) { |
Terry Wang | 2da1785 | 2020-12-16 19:59:08 -0800 | [diff] [blame] | 449 | Log.e(TAG, "Unable to send result to the callback", e); |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | |
| 453 | /** |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 454 | * Invokes the {@link IAppSearchBatchResultCallback} with an unexpected internal throwable. |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 455 | * |
| 456 | * <p>The throwable is converted to {@link ParcelableException}. |
| 457 | */ |
| 458 | private void invokeCallbackOnError(IAppSearchBatchResultCallback callback, |
| 459 | Throwable throwable) { |
| 460 | try { |
| 461 | callback.onSystemError(new ParcelableException(throwable)); |
| 462 | } catch (RemoteException e) { |
Terry Wang | 2da1785 | 2020-12-16 19:59:08 -0800 | [diff] [blame] | 463 | Log.e(TAG, "Unable to send error to the callback", e); |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 464 | } |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 465 | } |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 466 | } |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 467 | |
| 468 | //TODO(b/173553485) verifying that the caller has permission to access target user's data |
| 469 | //TODO(b/173553485) Handle ACTION_USER_REMOVED broadcast |
| 470 | //TODO(b/173553485) Implement SystemService.onUserStopping() |
| 471 | private static int handleIncomingUser(@UserIdInt int userId, int callingUid) { |
| 472 | int callingPid = Binder.getCallingPid(); |
| 473 | return ActivityManager.handleIncomingUser(callingPid, callingUid, userId, |
| 474 | /*allowAll=*/ false, /*requireFull=*/ false, |
| 475 | /*name=*/ null, /*callerPackage=*/ null); |
| 476 | } |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 477 | } |