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; |
Terry Wang | 12dc6c0 | 2021-03-31 19:26:16 -0700 | [diff] [blame] | 19 | import static android.os.UserHandle.USER_NULL; |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 20 | |
Xiaoyu Jin | f8cc201 | 2021-03-12 11:00:54 -0800 | [diff] [blame^] | 21 | import android.annotation.ElapsedRealtimeLong; |
sidchhabra | a7c8f8a | 2020-01-16 18:38:17 -0800 | [diff] [blame] | 22 | import android.annotation.NonNull; |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 23 | import android.annotation.UserIdInt; |
| 24 | import android.app.ActivityManager; |
Alexander Dorokhine | 1846584 | 2020-01-21 01:08:57 -0800 | [diff] [blame] | 25 | import android.app.appsearch.AppSearchBatchResult; |
Terry Wang | 623e3b0 | 2021-02-02 20:27:33 -0800 | [diff] [blame] | 26 | import android.app.appsearch.AppSearchMigrationHelper; |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 27 | import android.app.appsearch.AppSearchResult; |
Alexander Dorokhine | 92ce353 | 2020-10-06 01:39:36 -0700 | [diff] [blame] | 28 | import android.app.appsearch.AppSearchSchema; |
Alexander Dorokhine | c66d67c | 2020-10-08 13:44:04 -0700 | [diff] [blame] | 29 | import android.app.appsearch.GenericDocument; |
Alexander Dorokhine | 9795b51 | 2021-03-23 22:06:59 -0700 | [diff] [blame] | 30 | import android.app.appsearch.GetSchemaResponse; |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 31 | import android.app.appsearch.IAppSearchBatchResultCallback; |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 32 | import android.app.appsearch.IAppSearchManager; |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 33 | import android.app.appsearch.IAppSearchResultCallback; |
Alexander Dorokhine | ab78906 | 2021-01-11 21:00:00 -0800 | [diff] [blame] | 34 | import android.app.appsearch.PackageIdentifier; |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 35 | import android.app.appsearch.SearchResultPage; |
Alexander Dorokhine | c9fc960 | 2020-10-06 01:39:50 -0700 | [diff] [blame] | 36 | import android.app.appsearch.SearchSpec; |
Terry Wang | 623e3b0 | 2021-02-02 20:27:33 -0800 | [diff] [blame] | 37 | import android.app.appsearch.SetSchemaResponse; |
Cassie Wang | 8f0df49 | 2021-03-24 09:23:18 -0700 | [diff] [blame] | 38 | import android.app.appsearch.StorageInfo; |
Terry Wang | 12dc6c0 | 2021-03-31 19:26:16 -0700 | [diff] [blame] | 39 | import android.content.BroadcastReceiver; |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 40 | import android.content.Context; |
Terry Wang | 12dc6c0 | 2021-03-31 19:26:16 -0700 | [diff] [blame] | 41 | import android.content.Intent; |
| 42 | import android.content.IntentFilter; |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 43 | import android.content.pm.PackageManagerInternal; |
Alexander Dorokhine | 270d4f1 | 2020-01-15 17:24:35 -0800 | [diff] [blame] | 44 | import android.os.Binder; |
Alexander Dorokhine | 92ce353 | 2020-10-06 01:39:36 -0700 | [diff] [blame] | 45 | import android.os.Bundle; |
Terry Wang | 623e3b0 | 2021-02-02 20:27:33 -0800 | [diff] [blame] | 46 | import android.os.ParcelFileDescriptor; |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 47 | import android.os.ParcelableException; |
| 48 | import android.os.RemoteException; |
Xiaoyu Jin | f8cc201 | 2021-03-12 11:00:54 -0800 | [diff] [blame^] | 49 | import android.os.SystemClock; |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 50 | import android.os.UserHandle; |
Pinyao Ting | d5c2ed9 | 2021-03-18 14:51:54 -0700 | [diff] [blame] | 51 | import android.os.UserManager; |
Alexander Dorokhine | ab78906 | 2021-01-11 21:00:00 -0800 | [diff] [blame] | 52 | import android.util.ArrayMap; |
Cassie Wang | 9ba9ae1 | 2021-02-01 16:39:37 -0800 | [diff] [blame] | 53 | import android.util.ArraySet; |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 54 | import android.util.Log; |
Terry Wang | 12dc6c0 | 2021-03-31 19:26:16 -0700 | [diff] [blame] | 55 | import android.util.Slog; |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 56 | |
Cassie Wang | 15c8697 | 2021-02-09 13:43:25 -0800 | [diff] [blame] | 57 | import com.android.internal.annotations.GuardedBy; |
Alexander Dorokhine | 270d4f1 | 2020-01-15 17:24:35 -0800 | [diff] [blame] | 58 | import com.android.internal.util.Preconditions; |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 59 | import com.android.server.LocalServices; |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 60 | import com.android.server.SystemService; |
Alexander Dorokhine | f660d8f | 2020-10-29 22:37:00 -0700 | [diff] [blame] | 61 | import com.android.server.appsearch.external.localstorage.AppSearchImpl; |
Xiaoyu Jin | f8cc201 | 2021-03-12 11:00:54 -0800 | [diff] [blame^] | 62 | import com.android.server.appsearch.external.localstorage.stats.CallStats; |
| 63 | import com.android.server.appsearch.stats.LoggerInstanceManager; |
| 64 | import com.android.server.appsearch.stats.PlatformLogger; |
Alexander Dorokhine | fd07eba | 2020-01-13 20:22:20 -0800 | [diff] [blame] | 65 | |
Terry Wang | 623e3b0 | 2021-02-02 20:27:33 -0800 | [diff] [blame] | 66 | import java.io.DataInputStream; |
| 67 | import java.io.DataOutputStream; |
| 68 | import java.io.EOFException; |
| 69 | import java.io.FileInputStream; |
| 70 | import java.io.FileOutputStream; |
Alexander Dorokhine | 6a99f94 | 2020-12-04 02:57:22 -0800 | [diff] [blame] | 71 | import java.util.ArrayList; |
Alexander Dorokhine | 1846584 | 2020-01-21 01:08:57 -0800 | [diff] [blame] | 72 | import java.util.List; |
Alexander Dorokhine | ab78906 | 2021-01-11 21:00:00 -0800 | [diff] [blame] | 73 | import java.util.Map; |
Alexander Dorokhine | d18f884 | 2021-01-20 15:26:13 -0800 | [diff] [blame] | 74 | import java.util.Objects; |
Cassie Wang | 9ba9ae1 | 2021-02-01 16:39:37 -0800 | [diff] [blame] | 75 | import java.util.Set; |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 76 | import java.util.concurrent.Executor; |
| 77 | import java.util.concurrent.SynchronousQueue; |
| 78 | import java.util.concurrent.ThreadPoolExecutor; |
| 79 | import java.util.concurrent.TimeUnit; |
Alexander Dorokhine | 1846584 | 2020-01-21 01:08:57 -0800 | [diff] [blame] | 80 | |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 81 | /** TODO(b/142567528): add comments when implement this class */ |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 82 | public class AppSearchManagerService extends SystemService { |
Alexander Dorokhine | ebd3774 | 2020-09-22 15:02:26 -0700 | [diff] [blame] | 83 | private static final String TAG = "AppSearchManagerService"; |
Terry Wang | 12dc6c0 | 2021-03-31 19:26:16 -0700 | [diff] [blame] | 84 | private final Context mContext; |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 85 | private PackageManagerInternal mPackageManagerInternal; |
Cassie Wang | 21c2d6a | 2021-01-20 23:59:55 -0800 | [diff] [blame] | 86 | private ImplInstanceManager mImplInstanceManager; |
Pinyao Ting | d5c2ed9 | 2021-03-18 14:51:54 -0700 | [diff] [blame] | 87 | private UserManager mUserManager; |
Xiaoyu Jin | f8cc201 | 2021-03-12 11:00:54 -0800 | [diff] [blame^] | 88 | private LoggerInstanceManager mLoggerInstanceManager; |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 89 | |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 90 | // Never call shutdownNow(). It will cancel the futures it's returned. And since |
| 91 | // Executor#execute won't return anything, we will hang forever waiting for the execution. |
| 92 | // AppSearch multi-thread execution is guarded by Read & Write Lock in AppSearchImpl, all |
| 93 | // mutate requests will need to gain write lock and query requests need to gain read lock. |
| 94 | private static final Executor EXECUTOR = new ThreadPoolExecutor(/*corePoolSize=*/1, |
| 95 | Runtime.getRuntime().availableProcessors(), /*keepAliveTime*/ 60L, TimeUnit.SECONDS, |
| 96 | new SynchronousQueue<Runnable>()); |
| 97 | |
Cassie Wang | 15c8697 | 2021-02-09 13:43:25 -0800 | [diff] [blame] | 98 | // Cache of unlocked user ids so we don't have to query UserManager service each time. The |
| 99 | // "locked" suffix refers to the fact that access to the field should be locked; unrelated to |
| 100 | // the unlocked status of user ids. |
| 101 | @GuardedBy("mUnlockedUserIdsLocked") |
| 102 | private final Set<Integer> mUnlockedUserIdsLocked = new ArraySet<>(); |
Cassie Wang | 9ba9ae1 | 2021-02-01 16:39:37 -0800 | [diff] [blame] | 103 | |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 104 | public AppSearchManagerService(Context context) { |
| 105 | super(context); |
Terry Wang | 12dc6c0 | 2021-03-31 19:26:16 -0700 | [diff] [blame] | 106 | mContext = context; |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public void onStart() { |
| 111 | publishBinderService(Context.APP_SEARCH_SERVICE, new Stub()); |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 112 | mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class); |
Terry Wang | 12dc6c0 | 2021-03-31 19:26:16 -0700 | [diff] [blame] | 113 | mImplInstanceManager = ImplInstanceManager.getInstance(mContext); |
| 114 | mUserManager = mContext.getSystemService(UserManager.class); |
Xiaoyu Jin | f8cc201 | 2021-03-12 11:00:54 -0800 | [diff] [blame^] | 115 | mLoggerInstanceManager = LoggerInstanceManager.getInstance(); |
Terry Wang | 12dc6c0 | 2021-03-31 19:26:16 -0700 | [diff] [blame] | 116 | registerReceivers(); |
| 117 | } |
| 118 | |
| 119 | private void registerReceivers() { |
| 120 | mContext.registerReceiverAsUser(new UserActionReceiver(), UserHandle.ALL, |
| 121 | new IntentFilter(Intent.ACTION_USER_REMOVED), /*broadcastPermission=*/ null, |
| 122 | /*scheduler=*/ null); |
| 123 | } |
| 124 | |
| 125 | private class UserActionReceiver extends BroadcastReceiver { |
| 126 | @Override |
| 127 | public void onReceive(@NonNull Context context, @NonNull Intent intent) { |
| 128 | switch (intent.getAction()) { |
| 129 | case Intent.ACTION_USER_REMOVED: |
| 130 | final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL); |
| 131 | if (userId == USER_NULL) { |
| 132 | Slog.e(TAG, "userId is missing in the intent: " + intent); |
| 133 | return; |
| 134 | } |
| 135 | handleUserRemoved(userId); |
| 136 | break; |
| 137 | default: |
| 138 | Slog.e(TAG, "Received unknown intent: " + intent); |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Handles user removed action. |
| 145 | * |
| 146 | * <p>Only need to clear the AppSearchImpl instance. The data of AppSearch is saved in the |
| 147 | * "credential encrypted" system directory of each user. That directory will be auto-deleted |
| 148 | * when a user is removed. |
| 149 | * |
| 150 | * @param userId The multi-user userId of the user that need to be removed. |
| 151 | * |
| 152 | * @see android.os.Environment#getDataSystemCeDirectory |
| 153 | */ |
| 154 | private void handleUserRemoved(@UserIdInt int userId) { |
| 155 | try { |
| 156 | mImplInstanceManager.removeAppSearchImplForUser(userId); |
Xiaoyu Jin | f8cc201 | 2021-03-12 11:00:54 -0800 | [diff] [blame^] | 157 | mLoggerInstanceManager.removePlatformLoggerForUser(userId); |
Terry Wang | 12dc6c0 | 2021-03-31 19:26:16 -0700 | [diff] [blame] | 158 | Slog.i(TAG, "Removed AppSearchImpl instance for user: " + userId); |
| 159 | } catch (Throwable t) { |
| 160 | Slog.e(TAG, "Unable to remove data for user: " + userId, t); |
| 161 | } |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Cassie Wang | 9ba9ae1 | 2021-02-01 16:39:37 -0800 | [diff] [blame] | 164 | @Override |
Pinyao Ting | d5c2ed9 | 2021-03-18 14:51:54 -0700 | [diff] [blame] | 165 | public void onUserUnlocking(@NonNull TargetUser user) { |
Cassie Wang | 15c8697 | 2021-02-09 13:43:25 -0800 | [diff] [blame] | 166 | synchronized (mUnlockedUserIdsLocked) { |
| 167 | mUnlockedUserIdsLocked.add(user.getUserIdentifier()); |
| 168 | } |
Cassie Wang | 9ba9ae1 | 2021-02-01 16:39:37 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 171 | private class Stub extends IAppSearchManager.Stub { |
Alexander Dorokhine | fd07eba | 2020-01-13 20:22:20 -0800 | [diff] [blame] | 172 | @Override |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 173 | public void setSchema( |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 174 | @NonNull String packageName, |
Terry Wang | 6413aee | 2020-10-07 03:04:58 -0700 | [diff] [blame] | 175 | @NonNull String databaseName, |
Alexander Dorokhine | 92ce353 | 2020-10-06 01:39:36 -0700 | [diff] [blame] | 176 | @NonNull List<Bundle> schemaBundles, |
Alexander Dorokhine | 315cca6 | 2021-03-04 12:34:41 -0800 | [diff] [blame] | 177 | @NonNull List<String> schemasNotDisplayedBySystem, |
Alexander Dorokhine | ab78906 | 2021-01-11 21:00:00 -0800 | [diff] [blame] | 178 | @NonNull Map<String, List<Bundle>> schemasPackageAccessibleBundles, |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 179 | boolean forceOverride, |
Alexander Dorokhine | 9795b51 | 2021-03-23 22:06:59 -0700 | [diff] [blame] | 180 | int schemaVersion, |
Terry Wang | c10610d | 2021-03-21 13:21:24 -0700 | [diff] [blame] | 181 | @UserIdInt int userId, |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 182 | @NonNull IAppSearchResultCallback callback) { |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 183 | Preconditions.checkNotNull(packageName); |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 184 | Preconditions.checkNotNull(databaseName); |
Alexander Dorokhine | 92ce353 | 2020-10-06 01:39:36 -0700 | [diff] [blame] | 185 | Preconditions.checkNotNull(schemaBundles); |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 186 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 187 | int callingUid = Binder.getCallingUid(); |
| 188 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 189 | EXECUTOR.execute(() -> { |
| 190 | try { |
| 191 | verifyUserUnlocked(callingUserId); |
| 192 | verifyCallingPackage(callingUid, packageName); |
| 193 | List<AppSearchSchema> schemas = new ArrayList<>(schemaBundles.size()); |
| 194 | for (int i = 0; i < schemaBundles.size(); i++) { |
| 195 | schemas.add(new AppSearchSchema(schemaBundles.get(i))); |
Alexander Dorokhine | ab78906 | 2021-01-11 21:00:00 -0800 | [diff] [blame] | 196 | } |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 197 | Map<String, List<PackageIdentifier>> schemasPackageAccessible = |
| 198 | new ArrayMap<>(schemasPackageAccessibleBundles.size()); |
| 199 | for (Map.Entry<String, List<Bundle>> entry : |
| 200 | schemasPackageAccessibleBundles.entrySet()) { |
| 201 | List<PackageIdentifier> packageIdentifiers = |
| 202 | new ArrayList<>(entry.getValue().size()); |
| 203 | for (int i = 0; i < entry.getValue().size(); i++) { |
| 204 | packageIdentifiers.add( |
| 205 | new PackageIdentifier(entry.getValue().get(i))); |
| 206 | } |
| 207 | schemasPackageAccessible.put(entry.getKey(), packageIdentifiers); |
| 208 | } |
| 209 | AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(callingUserId); |
| 210 | SetSchemaResponse setSchemaResponse = impl.setSchema( |
| 211 | packageName, |
| 212 | databaseName, |
| 213 | schemas, |
| 214 | schemasNotDisplayedBySystem, |
| 215 | schemasPackageAccessible, |
| 216 | forceOverride, |
| 217 | schemaVersion); |
| 218 | invokeCallbackOnResult(callback, |
| 219 | AppSearchResult.newSuccessfulResult(setSchemaResponse.getBundle())); |
| 220 | } catch (Throwable t) { |
| 221 | invokeCallbackOnError(callback, t); |
Alexander Dorokhine | ab78906 | 2021-01-11 21:00:00 -0800 | [diff] [blame] | 222 | } |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 223 | }); |
Alexander Dorokhine | 179c8b8 | 2020-01-11 00:17:48 -0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | @Override |
Terry Wang | 83a2493 | 2020-12-09 21:00:18 -0800 | [diff] [blame] | 227 | public void getSchema( |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 228 | @NonNull String packageName, |
Terry Wang | 83a2493 | 2020-12-09 21:00:18 -0800 | [diff] [blame] | 229 | @NonNull String databaseName, |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 230 | @UserIdInt int userId, |
Terry Wang | 83a2493 | 2020-12-09 21:00:18 -0800 | [diff] [blame] | 231 | @NonNull IAppSearchResultCallback callback) { |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 232 | Preconditions.checkNotNull(packageName); |
Terry Wang | 83a2493 | 2020-12-09 21:00:18 -0800 | [diff] [blame] | 233 | Preconditions.checkNotNull(databaseName); |
| 234 | Preconditions.checkNotNull(callback); |
Cassie Wang | b0d6012 | 2021-03-30 12:38:46 -0700 | [diff] [blame] | 235 | int callingUid = Binder.getCallingUid(); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 236 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 237 | EXECUTOR.execute(() -> { |
| 238 | try { |
| 239 | verifyUserUnlocked(callingUserId); |
| 240 | verifyCallingPackage(callingUid, packageName); |
| 241 | AppSearchImpl impl = |
| 242 | mImplInstanceManager.getAppSearchImpl(callingUserId); |
| 243 | GetSchemaResponse response = impl.getSchema(packageName, databaseName); |
| 244 | invokeCallbackOnResult( |
| 245 | callback, |
| 246 | AppSearchResult.newSuccessfulResult(response.getBundle())); |
| 247 | } catch (Throwable t) { |
| 248 | invokeCallbackOnError(callback, t); |
| 249 | } |
| 250 | }); |
Alexander Dorokhine | 9795b51 | 2021-03-23 22:06:59 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public void getNamespaces( |
| 255 | @NonNull String packageName, |
| 256 | @NonNull String databaseName, |
| 257 | @UserIdInt int userId, |
| 258 | @NonNull IAppSearchResultCallback callback) { |
| 259 | Preconditions.checkNotNull(packageName); |
| 260 | Preconditions.checkNotNull(databaseName); |
| 261 | Preconditions.checkNotNull(callback); |
Cassie Wang | b0d6012 | 2021-03-30 12:38:46 -0700 | [diff] [blame] | 262 | int callingUid = Binder.getCallingUid(); |
Alexander Dorokhine | 9795b51 | 2021-03-23 22:06:59 -0700 | [diff] [blame] | 263 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 264 | EXECUTOR.execute(() -> { |
| 265 | try { |
| 266 | verifyUserUnlocked(callingUserId); |
| 267 | verifyCallingPackage(callingUid, packageName); |
| 268 | AppSearchImpl impl = |
| 269 | mImplInstanceManager.getAppSearchImpl(callingUserId); |
| 270 | List<String> namespaces = impl.getNamespaces(packageName, databaseName); |
| 271 | invokeCallbackOnResult(callback, |
| 272 | AppSearchResult.newSuccessfulResult(namespaces)); |
| 273 | } catch (Throwable t) { |
| 274 | invokeCallbackOnError(callback, t); |
| 275 | } |
| 276 | }); |
Terry Wang | 83a2493 | 2020-12-09 21:00:18 -0800 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | @Override |
Alexander Dorokhine | 1846584 | 2020-01-21 01:08:57 -0800 | [diff] [blame] | 280 | public void putDocuments( |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 281 | @NonNull String packageName, |
Terry Wang | 6413aee | 2020-10-07 03:04:58 -0700 | [diff] [blame] | 282 | @NonNull String databaseName, |
Alexander Dorokhine | c66d67c | 2020-10-08 13:44:04 -0700 | [diff] [blame] | 283 | @NonNull List<Bundle> documentBundles, |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 284 | @UserIdInt int userId, |
Xiaoyu Jin | f8cc201 | 2021-03-12 11:00:54 -0800 | [diff] [blame^] | 285 | @ElapsedRealtimeLong long binderCallStartTimeMillis, |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 286 | @NonNull IAppSearchBatchResultCallback callback) { |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 287 | Preconditions.checkNotNull(packageName); |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 288 | Preconditions.checkNotNull(databaseName); |
Alexander Dorokhine | c66d67c | 2020-10-08 13:44:04 -0700 | [diff] [blame] | 289 | Preconditions.checkNotNull(documentBundles); |
Alexander Dorokhine | cc22345 | 2020-01-19 03:00:28 -0800 | [diff] [blame] | 290 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 291 | int callingUid = Binder.getCallingUid(); |
| 292 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 293 | EXECUTOR.execute(() -> { |
Xiaoyu Jin | f8cc201 | 2021-03-12 11:00:54 -0800 | [diff] [blame^] | 294 | long totalLatencyStartTimeMillis = SystemClock.elapsedRealtime(); |
| 295 | @AppSearchResult.ResultCode int statusCode = AppSearchResult.RESULT_OK; |
| 296 | PlatformLogger logger = null; |
| 297 | int operationSuccessCount = 0; |
| 298 | int operationFailureCount = 0; |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 299 | try { |
| 300 | verifyUserUnlocked(callingUserId); |
| 301 | verifyCallingPackage(callingUid, packageName); |
| 302 | AppSearchBatchResult.Builder<String, Void> resultBuilder = |
| 303 | new AppSearchBatchResult.Builder<>(); |
| 304 | AppSearchImpl impl = |
| 305 | mImplInstanceManager.getAppSearchImpl(callingUserId); |
Xiaoyu Jin | f8cc201 | 2021-03-12 11:00:54 -0800 | [diff] [blame^] | 306 | logger = mLoggerInstanceManager.getPlatformLogger(callingUserId); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 307 | for (int i = 0; i < documentBundles.size(); i++) { |
| 308 | GenericDocument document = new GenericDocument(documentBundles.get(i)); |
| 309 | try { |
Xiaoyu Jin | f8cc201 | 2021-03-12 11:00:54 -0800 | [diff] [blame^] | 310 | impl.putDocument(packageName, databaseName, document, logger); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 311 | resultBuilder.setSuccess(document.getUri(), /*result=*/ null); |
Xiaoyu Jin | f8cc201 | 2021-03-12 11:00:54 -0800 | [diff] [blame^] | 312 | ++operationSuccessCount; |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 313 | } catch (Throwable t) { |
| 314 | resultBuilder.setResult(document.getUri(), |
| 315 | throwableToFailedResult(t)); |
Xiaoyu Jin | f8cc201 | 2021-03-12 11:00:54 -0800 | [diff] [blame^] | 316 | AppSearchResult<Void> result = throwableToFailedResult(t); |
| 317 | resultBuilder.setResult(document.getUri(), result); |
| 318 | // for failures, we would just log the one for last failure |
| 319 | statusCode = result.getResultCode(); |
| 320 | ++operationFailureCount; |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 321 | } |
Alexander Dorokhine | 1846584 | 2020-01-21 01:08:57 -0800 | [diff] [blame] | 322 | } |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 323 | invokeCallbackOnResult(callback, resultBuilder.build()); |
| 324 | } catch (Throwable t) { |
| 325 | invokeCallbackOnError(callback, t); |
Xiaoyu Jin | f8cc201 | 2021-03-12 11:00:54 -0800 | [diff] [blame^] | 326 | } finally { |
| 327 | if (logger != null) { |
| 328 | CallStats.Builder cBuilder = new CallStats.Builder(packageName, |
| 329 | databaseName) |
| 330 | .setCallType(CallStats.CALL_TYPE_PUT_DOCUMENTS) |
| 331 | // TODO(b/173532925) check the existing binder call latency chart |
| 332 | // is good enough for us: |
| 333 | // http://dashboards/view/_72c98f9a_91d9_41d4_ab9a_bc14f79742b4 |
| 334 | .setEstimatedBinderLatencyMillis( |
| 335 | 2 * (int) (totalLatencyStartTimeMillis |
| 336 | - binderCallStartTimeMillis)) |
| 337 | .setNumOperationsSucceeded(operationSuccessCount) |
| 338 | .setNumOperationsFailed(operationFailureCount); |
| 339 | cBuilder.getGeneralStatsBuilder() |
| 340 | .setStatusCode(statusCode) |
| 341 | .setTotalLatencyMillis( |
| 342 | (int) (SystemClock.elapsedRealtime() |
| 343 | - totalLatencyStartTimeMillis)); |
| 344 | logger.logStats(cBuilder.build()); |
| 345 | } |
Alexander Dorokhine | 1846584 | 2020-01-21 01:08:57 -0800 | [diff] [blame] | 346 | } |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 347 | }); |
Alexander Dorokhine | fd07eba | 2020-01-13 20:22:20 -0800 | [diff] [blame] | 348 | } |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 349 | |
Alexander Dorokhine | 69a8d9f | 2020-03-06 10:43:16 -0800 | [diff] [blame] | 350 | @Override |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 351 | public void getDocuments( |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 352 | @NonNull String packageName, |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 353 | @NonNull String databaseName, |
| 354 | @NonNull String namespace, |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 355 | @NonNull List<String> uris, |
Alexander Dorokhine | 87cdd15 | 2021-01-20 15:41:25 -0800 | [diff] [blame] | 356 | @NonNull Map<String, List<String>> typePropertyPaths, |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 357 | @UserIdInt int userId, |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 358 | @NonNull IAppSearchBatchResultCallback callback) { |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 359 | Preconditions.checkNotNull(packageName); |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 360 | Preconditions.checkNotNull(databaseName); |
| 361 | Preconditions.checkNotNull(namespace); |
Alexander Dorokhine | 69a8d9f | 2020-03-06 10:43:16 -0800 | [diff] [blame] | 362 | Preconditions.checkNotNull(uris); |
| 363 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 364 | int callingUid = Binder.getCallingUid(); |
| 365 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 366 | EXECUTOR.execute(() -> { |
| 367 | try { |
| 368 | verifyUserUnlocked(callingUserId); |
| 369 | verifyCallingPackage(callingUid, packageName); |
| 370 | AppSearchBatchResult.Builder<String, Bundle> resultBuilder = |
| 371 | new AppSearchBatchResult.Builder<>(); |
| 372 | AppSearchImpl impl = |
| 373 | mImplInstanceManager.getAppSearchImpl(callingUserId); |
| 374 | for (int i = 0; i < uris.size(); i++) { |
| 375 | String uri = uris.get(i); |
| 376 | try { |
| 377 | GenericDocument document = |
| 378 | impl.getDocument( |
| 379 | packageName, |
| 380 | databaseName, |
| 381 | namespace, |
| 382 | uri, |
| 383 | typePropertyPaths); |
| 384 | resultBuilder.setSuccess(uri, document.getBundle()); |
| 385 | } catch (Throwable t) { |
| 386 | resultBuilder.setResult(uri, throwableToFailedResult(t)); |
| 387 | } |
Alexander Dorokhine | a95f44f | 2020-03-06 13:53:14 -0800 | [diff] [blame] | 388 | } |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 389 | invokeCallbackOnResult(callback, resultBuilder.build()); |
| 390 | } catch (Throwable t) { |
| 391 | invokeCallbackOnError(callback, t); |
Alexander Dorokhine | 69a8d9f | 2020-03-06 10:43:16 -0800 | [diff] [blame] | 392 | } |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 393 | }); |
Alexander Dorokhine | 69a8d9f | 2020-03-06 10:43:16 -0800 | [diff] [blame] | 394 | } |
| 395 | |
sidchhabra | a7c8f8a | 2020-01-16 18:38:17 -0800 | [diff] [blame] | 396 | @Override |
Alexander Dorokhine | e708e18 | 2020-03-06 15:30:34 -0800 | [diff] [blame] | 397 | public void query( |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 398 | @NonNull String packageName, |
Terry Wang | 6413aee | 2020-10-07 03:04:58 -0700 | [diff] [blame] | 399 | @NonNull String databaseName, |
Alexander Dorokhine | c9fc960 | 2020-10-06 01:39:50 -0700 | [diff] [blame] | 400 | @NonNull String queryExpression, |
| 401 | @NonNull Bundle searchSpecBundle, |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 402 | @UserIdInt int userId, |
Alexander Dorokhine | d48f236 | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 403 | @NonNull IAppSearchResultCallback callback) { |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 404 | Preconditions.checkNotNull(packageName); |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 405 | Preconditions.checkNotNull(databaseName); |
Alexander Dorokhine | c9fc960 | 2020-10-06 01:39:50 -0700 | [diff] [blame] | 406 | Preconditions.checkNotNull(queryExpression); |
| 407 | Preconditions.checkNotNull(searchSpecBundle); |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 408 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 409 | int callingUid = Binder.getCallingUid(); |
| 410 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 411 | EXECUTOR.execute(() -> { |
| 412 | try { |
| 413 | verifyUserUnlocked(callingUserId); |
| 414 | verifyCallingPackage(callingUid, packageName); |
| 415 | AppSearchImpl impl = |
| 416 | mImplInstanceManager.getAppSearchImpl(callingUserId); |
| 417 | SearchResultPage searchResultPage = |
| 418 | impl.query( |
| 419 | packageName, |
| 420 | databaseName, |
| 421 | queryExpression, |
| 422 | new SearchSpec(searchSpecBundle)); |
| 423 | invokeCallbackOnResult( |
| 424 | callback, |
| 425 | AppSearchResult.newSuccessfulResult(searchResultPage.getBundle())); |
| 426 | } catch (Throwable t) { |
| 427 | invokeCallbackOnError(callback, t); |
| 428 | } |
| 429 | }); |
Alexander Dorokhine | d48f236 | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 432 | @Override |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 433 | public void globalQuery( |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 434 | @NonNull String packageName, |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 435 | @NonNull String queryExpression, |
| 436 | @NonNull Bundle searchSpecBundle, |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 437 | @UserIdInt int userId, |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 438 | @NonNull IAppSearchResultCallback callback) { |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 439 | Preconditions.checkNotNull(packageName); |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 440 | Preconditions.checkNotNull(queryExpression); |
| 441 | Preconditions.checkNotNull(searchSpecBundle); |
| 442 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 443 | int callingUid = Binder.getCallingUid(); |
| 444 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 445 | EXECUTOR.execute(() -> { |
| 446 | try { |
| 447 | verifyUserUnlocked(callingUserId); |
| 448 | verifyCallingPackage(callingUid, packageName); |
| 449 | AppSearchImpl impl = |
| 450 | mImplInstanceManager.getAppSearchImpl(callingUserId); |
| 451 | SearchResultPage searchResultPage = |
| 452 | impl.globalQuery( |
| 453 | queryExpression, |
| 454 | new SearchSpec(searchSpecBundle), |
| 455 | packageName, |
| 456 | callingUid); |
| 457 | invokeCallbackOnResult( |
| 458 | callback, |
| 459 | AppSearchResult.newSuccessfulResult(searchResultPage.getBundle())); |
| 460 | } catch (Throwable t) { |
| 461 | invokeCallbackOnError(callback, t); |
| 462 | } |
| 463 | }); |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 464 | } |
| 465 | |
Alexander Dorokhine | d48f236 | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 466 | @Override |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 467 | public void getNextPage( |
| 468 | long nextPageToken, |
| 469 | @UserIdInt int userId, |
Alexander Dorokhine | d48f236 | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 470 | @NonNull IAppSearchResultCallback callback) { |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 471 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 472 | int callingUid = Binder.getCallingUid(); |
| 473 | int callingUserId = handleIncomingUser(userId, callingUid); |
Alexander Dorokhine | d48f236 | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 474 | // TODO(b/162450968) check nextPageToken is being advanced by the same uid as originally |
| 475 | // opened it |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 476 | EXECUTOR.execute(() -> { |
| 477 | try { |
| 478 | verifyUserUnlocked(callingUserId); |
| 479 | AppSearchImpl impl = |
| 480 | mImplInstanceManager.getAppSearchImpl(callingUserId); |
| 481 | SearchResultPage searchResultPage = impl.getNextPage(nextPageToken); |
| 482 | invokeCallbackOnResult( |
| 483 | callback, |
| 484 | AppSearchResult.newSuccessfulResult(searchResultPage.getBundle())); |
| 485 | } catch (Throwable t) { |
| 486 | invokeCallbackOnError(callback, t); |
| 487 | } |
| 488 | }); |
Alexander Dorokhine | d48f236 | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | @Override |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 492 | public void invalidateNextPageToken(long nextPageToken, @UserIdInt int userId) { |
| 493 | int callingUid = Binder.getCallingUid(); |
| 494 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 495 | EXECUTOR.execute(() -> { |
| 496 | try { |
| 497 | verifyUserUnlocked(callingUserId); |
| 498 | AppSearchImpl impl = |
| 499 | mImplInstanceManager.getAppSearchImpl(callingUserId); |
| 500 | impl.invalidateNextPageToken(nextPageToken); |
| 501 | } catch (Throwable t) { |
| 502 | Log.e(TAG, "Unable to invalidate the query page token", t); |
| 503 | } |
| 504 | }); |
sidchhabra | a7c8f8a | 2020-01-16 18:38:17 -0800 | [diff] [blame] | 505 | } |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 506 | |
Alexander Dorokhine | f6c66ae | 2020-03-09 14:47:25 -0700 | [diff] [blame] | 507 | @Override |
Terry Wang | 623e3b0 | 2021-02-02 20:27:33 -0800 | [diff] [blame] | 508 | public void writeQueryResultsToFile( |
| 509 | @NonNull String packageName, |
| 510 | @NonNull String databaseName, |
| 511 | @NonNull ParcelFileDescriptor fileDescriptor, |
| 512 | @NonNull String queryExpression, |
| 513 | @NonNull Bundle searchSpecBundle, |
| 514 | @UserIdInt int userId, |
| 515 | @NonNull IAppSearchResultCallback callback) { |
| 516 | int callingUid = Binder.getCallingUid(); |
| 517 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 518 | EXECUTOR.execute(() -> { |
| 519 | try { |
| 520 | verifyCallingPackage(callingUid, packageName); |
| 521 | AppSearchImpl impl = |
| 522 | mImplInstanceManager.getAppSearchImpl(callingUserId); |
| 523 | // we don't need to append the file. The file is always brand new. |
| 524 | try (DataOutputStream outputStream = new DataOutputStream( |
| 525 | new FileOutputStream(fileDescriptor.getFileDescriptor()))) { |
| 526 | SearchResultPage searchResultPage = impl.query( |
| 527 | packageName, |
| 528 | databaseName, |
| 529 | queryExpression, |
| 530 | new SearchSpec(searchSpecBundle)); |
| 531 | while (!searchResultPage.getResults().isEmpty()) { |
| 532 | for (int i = 0; i < searchResultPage.getResults().size(); i++) { |
| 533 | AppSearchMigrationHelper.writeBundleToOutputStream( |
| 534 | outputStream, searchResultPage.getResults().get(i) |
| 535 | .getGenericDocument().getBundle()); |
| 536 | } |
| 537 | searchResultPage = impl.getNextPage( |
| 538 | searchResultPage.getNextPageToken()); |
Terry Wang | 623e3b0 | 2021-02-02 20:27:33 -0800 | [diff] [blame] | 539 | } |
Terry Wang | 623e3b0 | 2021-02-02 20:27:33 -0800 | [diff] [blame] | 540 | } |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 541 | invokeCallbackOnResult(callback, AppSearchResult.newSuccessfulResult(null)); |
| 542 | } catch (Throwable t) { |
| 543 | invokeCallbackOnError(callback, t); |
Terry Wang | 623e3b0 | 2021-02-02 20:27:33 -0800 | [diff] [blame] | 544 | } |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 545 | }); |
Terry Wang | 623e3b0 | 2021-02-02 20:27:33 -0800 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | @Override |
| 549 | public void putDocumentsFromFile( |
| 550 | @NonNull String packageName, |
| 551 | @NonNull String databaseName, |
| 552 | @NonNull ParcelFileDescriptor fileDescriptor, |
| 553 | @UserIdInt int userId, |
| 554 | @NonNull IAppSearchResultCallback callback) { |
| 555 | int callingUid = Binder.getCallingUid(); |
| 556 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 557 | EXECUTOR.execute(() -> { |
| 558 | try { |
| 559 | verifyCallingPackage(callingUid, packageName); |
| 560 | AppSearchImpl impl = |
| 561 | mImplInstanceManager.getAppSearchImpl(callingUserId); |
Terry Wang | 623e3b0 | 2021-02-02 20:27:33 -0800 | [diff] [blame] | 562 | |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 563 | GenericDocument document; |
| 564 | ArrayList<Bundle> migrationFailureBundles = new ArrayList<>(); |
| 565 | try (DataInputStream inputStream = new DataInputStream( |
| 566 | new FileInputStream(fileDescriptor.getFileDescriptor()))) { |
| 567 | while (true) { |
| 568 | try { |
| 569 | document = AppSearchMigrationHelper |
| 570 | .readDocumentFromInputStream(inputStream); |
| 571 | } catch (EOFException e) { |
| 572 | // nothing wrong, we just finish the reading. |
| 573 | break; |
| 574 | } |
| 575 | try { |
| 576 | impl.putDocument(packageName, databaseName, document, |
| 577 | /*logger=*/ null); |
| 578 | } catch (Throwable t) { |
| 579 | migrationFailureBundles.add( |
| 580 | new SetSchemaResponse.MigrationFailure.Builder() |
| 581 | .setNamespace(document.getNamespace()) |
| 582 | .setSchemaType(document.getSchemaType()) |
| 583 | .setUri(document.getUri()) |
| 584 | .setAppSearchResult(AppSearchResult |
| 585 | .throwableToFailedResult(t)) |
| 586 | .build().getBundle()); |
| 587 | } |
Terry Wang | 623e3b0 | 2021-02-02 20:27:33 -0800 | [diff] [blame] | 588 | } |
| 589 | } |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 590 | impl.persistToDisk(); |
| 591 | invokeCallbackOnResult(callback, |
| 592 | AppSearchResult.newSuccessfulResult(migrationFailureBundles)); |
| 593 | } catch (Throwable t) { |
| 594 | invokeCallbackOnError(callback, t); |
Terry Wang | 623e3b0 | 2021-02-02 20:27:33 -0800 | [diff] [blame] | 595 | } |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 596 | }); |
Terry Wang | 623e3b0 | 2021-02-02 20:27:33 -0800 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | @Override |
Alexander Dorokhine | d18f884 | 2021-01-20 15:26:13 -0800 | [diff] [blame] | 600 | public void reportUsage( |
| 601 | @NonNull String packageName, |
| 602 | @NonNull String databaseName, |
| 603 | @NonNull String namespace, |
| 604 | @NonNull String uri, |
| 605 | long usageTimeMillis, |
Alexander Dorokhine | 9795b51 | 2021-03-23 22:06:59 -0700 | [diff] [blame] | 606 | boolean systemUsage, |
Alexander Dorokhine | d18f884 | 2021-01-20 15:26:13 -0800 | [diff] [blame] | 607 | @UserIdInt int userId, |
| 608 | @NonNull IAppSearchResultCallback callback) { |
| 609 | Objects.requireNonNull(databaseName); |
| 610 | Objects.requireNonNull(namespace); |
| 611 | Objects.requireNonNull(uri); |
| 612 | Objects.requireNonNull(callback); |
| 613 | int callingUid = Binder.getCallingUid(); |
| 614 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 615 | EXECUTOR.execute(() -> { |
| 616 | try { |
| 617 | verifyUserUnlocked(callingUserId); |
Alexander Dorokhine | 9795b51 | 2021-03-23 22:06:59 -0700 | [diff] [blame] | 618 | |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 619 | if (systemUsage) { |
| 620 | // TODO(b/183031844): Validate that the call comes from the system |
| 621 | } |
| 622 | |
| 623 | AppSearchImpl impl = |
| 624 | mImplInstanceManager.getAppSearchImpl(callingUserId); |
| 625 | impl.reportUsage( |
| 626 | packageName, databaseName, namespace, uri, |
| 627 | usageTimeMillis, systemUsage); |
| 628 | invokeCallbackOnResult( |
| 629 | callback, AppSearchResult.newSuccessfulResult(/*result=*/ null)); |
| 630 | } catch (Throwable t) { |
| 631 | invokeCallbackOnError(callback, t); |
Alexander Dorokhine | 9795b51 | 2021-03-23 22:06:59 -0700 | [diff] [blame] | 632 | } |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 633 | }); |
Alexander Dorokhine | d18f884 | 2021-01-20 15:26:13 -0800 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | @Override |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 637 | public void removeByUri( |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 638 | @NonNull String packageName, |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 639 | @NonNull String databaseName, |
| 640 | @NonNull String namespace, |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 641 | @NonNull List<String> uris, |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 642 | @UserIdInt int userId, |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 643 | @NonNull IAppSearchBatchResultCallback callback) { |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 644 | Preconditions.checkNotNull(packageName); |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 645 | Preconditions.checkNotNull(databaseName); |
Alexander Dorokhine | ff82fba | 2020-03-09 16:35:24 -0700 | [diff] [blame] | 646 | Preconditions.checkNotNull(uris); |
| 647 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 648 | int callingUid = Binder.getCallingUid(); |
| 649 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 650 | EXECUTOR.execute(() -> { |
| 651 | try { |
| 652 | verifyUserUnlocked(callingUserId); |
| 653 | verifyCallingPackage(callingUid, packageName); |
| 654 | AppSearchBatchResult.Builder<String, Void> resultBuilder = |
| 655 | new AppSearchBatchResult.Builder<>(); |
| 656 | AppSearchImpl impl = |
| 657 | mImplInstanceManager.getAppSearchImpl(callingUserId); |
| 658 | for (int i = 0; i < uris.size(); i++) { |
| 659 | String uri = uris.get(i); |
| 660 | try { |
| 661 | impl.remove(packageName, databaseName, namespace, uri); |
| 662 | resultBuilder.setSuccess(uri, /*result= */ null); |
| 663 | } catch (Throwable t) { |
| 664 | resultBuilder.setResult(uri, throwableToFailedResult(t)); |
| 665 | } |
Alexander Dorokhine | ff82fba | 2020-03-09 16:35:24 -0700 | [diff] [blame] | 666 | } |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 667 | invokeCallbackOnResult(callback, resultBuilder.build()); |
| 668 | } catch (Throwable t) { |
| 669 | invokeCallbackOnError(callback, t); |
Alexander Dorokhine | ff82fba | 2020-03-09 16:35:24 -0700 | [diff] [blame] | 670 | } |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 671 | }); |
Alexander Dorokhine | ff82fba | 2020-03-09 16:35:24 -0700 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | @Override |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 675 | public void removeByQuery( |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 676 | @NonNull String packageName, |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 677 | @NonNull String databaseName, |
| 678 | @NonNull String queryExpression, |
| 679 | @NonNull Bundle searchSpecBundle, |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 680 | @UserIdInt int userId, |
Alexander Dorokhine | 178366b | 2020-10-20 17:40:49 -0700 | [diff] [blame] | 681 | @NonNull IAppSearchResultCallback callback) { |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 682 | Preconditions.checkNotNull(packageName); |
Terry Wang | 26b9e5c | 2020-10-23 02:05:01 -0700 | [diff] [blame] | 683 | Preconditions.checkNotNull(databaseName); |
| 684 | Preconditions.checkNotNull(queryExpression); |
| 685 | Preconditions.checkNotNull(searchSpecBundle); |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 686 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 687 | int callingUid = Binder.getCallingUid(); |
| 688 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 689 | EXECUTOR.execute(() -> { |
| 690 | try { |
| 691 | verifyUserUnlocked(callingUserId); |
| 692 | verifyCallingPackage(callingUid, packageName); |
| 693 | AppSearchImpl impl = |
| 694 | mImplInstanceManager.getAppSearchImpl(callingUserId); |
| 695 | impl.removeByQuery( |
| 696 | packageName, |
| 697 | databaseName, |
| 698 | queryExpression, |
| 699 | new SearchSpec(searchSpecBundle)); |
| 700 | invokeCallbackOnResult(callback, AppSearchResult.newSuccessfulResult(null)); |
| 701 | } catch (Throwable t) { |
| 702 | invokeCallbackOnError(callback, t); |
| 703 | } |
| 704 | }); |
Alexander Dorokhine | f6c66ae | 2020-03-09 14:47:25 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 707 | @Override |
Cassie Wang | 8f0df49 | 2021-03-24 09:23:18 -0700 | [diff] [blame] | 708 | public void getStorageInfo( |
| 709 | @NonNull String packageName, |
| 710 | @NonNull String databaseName, |
| 711 | @UserIdInt int userId, |
| 712 | @NonNull IAppSearchResultCallback callback) { |
| 713 | Preconditions.checkNotNull(packageName); |
| 714 | Preconditions.checkNotNull(databaseName); |
| 715 | Preconditions.checkNotNull(callback); |
| 716 | int callingUid = Binder.getCallingUid(); |
| 717 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 718 | EXECUTOR.execute(() -> { |
| 719 | try { |
| 720 | verifyUserUnlocked(callingUserId); |
| 721 | verifyCallingPackage(callingUid, packageName); |
| 722 | AppSearchImpl impl = |
| 723 | mImplInstanceManager.getAppSearchImpl(callingUserId); |
| 724 | StorageInfo storageInfo = impl.getStorageInfoForDatabase(packageName, |
| 725 | databaseName); |
| 726 | Bundle storageInfoBundle = storageInfo.getBundle(); |
| 727 | invokeCallbackOnResult( |
| 728 | callback, AppSearchResult.newSuccessfulResult(storageInfoBundle)); |
| 729 | } catch (Throwable t) { |
| 730 | invokeCallbackOnError(callback, t); |
| 731 | } |
| 732 | }); |
Cassie Wang | 8f0df49 | 2021-03-24 09:23:18 -0700 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | @Override |
Terry Wang | 2da1785 | 2020-12-16 19:59:08 -0800 | [diff] [blame] | 736 | public void persistToDisk(@UserIdInt int userId) { |
Cassie Wang | b0d6012 | 2021-03-30 12:38:46 -0700 | [diff] [blame] | 737 | int callingUid = Binder.getCallingUid(); |
Terry Wang | 2da1785 | 2020-12-16 19:59:08 -0800 | [diff] [blame] | 738 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 739 | EXECUTOR.execute(() -> { |
| 740 | try { |
| 741 | verifyUserUnlocked(callingUserId); |
| 742 | AppSearchImpl impl = |
| 743 | mImplInstanceManager.getAppSearchImpl(callingUserId); |
| 744 | impl.persistToDisk(); |
| 745 | } catch (Throwable t) { |
| 746 | Log.e(TAG, "Unable to persist the data to disk", t); |
| 747 | } |
| 748 | }); |
Terry Wang | 2da1785 | 2020-12-16 19:59:08 -0800 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | @Override |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 752 | public void initialize(@UserIdInt int userId, @NonNull IAppSearchResultCallback callback) { |
Terry Wang | bfbfcac | 2020-11-06 15:46:44 -0800 | [diff] [blame] | 753 | Preconditions.checkNotNull(callback); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 754 | int callingUid = Binder.getCallingUid(); |
| 755 | int callingUserId = handleIncomingUser(userId, callingUid); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 756 | EXECUTOR.execute(() -> { |
| 757 | try { |
| 758 | verifyUserUnlocked(callingUserId); |
| 759 | mImplInstanceManager.getOrCreateAppSearchImpl(mContext, callingUserId); |
Xiaoyu Jin | f8cc201 | 2021-03-12 11:00:54 -0800 | [diff] [blame^] | 760 | mLoggerInstanceManager.getOrCreatePlatformLogger(getContext(), callingUserId); |
Terry Wang | e04ceab | 2021-03-29 19:25:12 -0700 | [diff] [blame] | 761 | invokeCallbackOnResult(callback, AppSearchResult.newSuccessfulResult(null)); |
| 762 | } catch (Throwable t) { |
| 763 | invokeCallbackOnError(callback, t); |
| 764 | } |
| 765 | }); |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 766 | } |
| 767 | |
Cassie Wang | 9ba9ae1 | 2021-02-01 16:39:37 -0800 | [diff] [blame] | 768 | private void verifyUserUnlocked(int callingUserId) { |
Cassie Wang | 15c8697 | 2021-02-09 13:43:25 -0800 | [diff] [blame] | 769 | synchronized (mUnlockedUserIdsLocked) { |
Pinyao Ting | d5c2ed9 | 2021-03-18 14:51:54 -0700 | [diff] [blame] | 770 | // First, check the local copy. |
| 771 | if (mUnlockedUserIdsLocked.contains(callingUserId)) { |
| 772 | return; |
| 773 | } |
| 774 | // If the local copy says the user is locked, check with UM for the actual state, |
| 775 | // since the user might just have been unlocked. |
| 776 | if (!mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(callingUserId))) { |
Cassie Wang | 15c8697 | 2021-02-09 13:43:25 -0800 | [diff] [blame] | 777 | throw new IllegalStateException( |
| 778 | "User " + callingUserId + " is locked or not running."); |
| 779 | } |
Cassie Wang | 9ba9ae1 | 2021-02-01 16:39:37 -0800 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 783 | private void verifyCallingPackage(int callingUid, @NonNull String callingPackage) { |
| 784 | Preconditions.checkNotNull(callingPackage); |
| 785 | if (mPackageManagerInternal.getPackageUid( |
| 786 | callingPackage, /*flags=*/ 0, UserHandle.getUserId(callingUid)) |
| 787 | != callingUid) { |
| 788 | throw new SecurityException( |
| 789 | "Specified calling package [" |
| 790 | + callingPackage |
| 791 | + "] does not match the calling uid " |
| 792 | + callingUid); |
Alexander Dorokhine | ebd3774 | 2020-09-22 15:02:26 -0700 | [diff] [blame] | 793 | } |
Alexander Dorokhine | ebd3774 | 2020-09-22 15:02:26 -0700 | [diff] [blame] | 794 | } |
| 795 | |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 796 | /** Invokes the {@link IAppSearchResultCallback} with the result. */ |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 797 | private void invokeCallbackOnResult( |
| 798 | IAppSearchResultCallback callback, AppSearchResult<?> result) { |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 799 | try { |
| 800 | callback.onResult(result); |
| 801 | } catch (RemoteException e) { |
Terry Wang | 2da1785 | 2020-12-16 19:59:08 -0800 | [diff] [blame] | 802 | Log.e(TAG, "Unable to send result to the callback", e); |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 803 | } |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 804 | } |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 805 | |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 806 | /** Invokes the {@link IAppSearchBatchResultCallback} with the result. */ |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 807 | private void invokeCallbackOnResult( |
| 808 | IAppSearchBatchResultCallback callback, AppSearchBatchResult<?, ?> result) { |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 809 | try { |
| 810 | callback.onResult(result); |
| 811 | } catch (RemoteException e) { |
Terry Wang | 2da1785 | 2020-12-16 19:59:08 -0800 | [diff] [blame] | 812 | Log.e(TAG, "Unable to send result to the callback", e); |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 813 | } |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | /** |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 817 | * Invokes the {@link IAppSearchResultCallback} with an throwable. |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 818 | * |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 819 | * <p>The throwable is convert to a {@link AppSearchResult}; |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 820 | */ |
| 821 | private void invokeCallbackOnError(IAppSearchResultCallback callback, Throwable throwable) { |
| 822 | try { |
| 823 | callback.onResult(throwableToFailedResult(throwable)); |
| 824 | } catch (RemoteException e) { |
Terry Wang | 2da1785 | 2020-12-16 19:59:08 -0800 | [diff] [blame] | 825 | Log.e(TAG, "Unable to send result to the callback", e); |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
| 829 | /** |
Alexander Dorokhine | 8c5ba91 | 2020-12-14 22:58:12 -0800 | [diff] [blame] | 830 | * Invokes the {@link IAppSearchBatchResultCallback} with an unexpected internal throwable. |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 831 | * |
| 832 | * <p>The throwable is converted to {@link ParcelableException}. |
| 833 | */ |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 834 | private void invokeCallbackOnError( |
| 835 | IAppSearchBatchResultCallback callback, Throwable throwable) { |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 836 | try { |
Terry Wang | 9d8f427 | 2021-02-04 21:01:10 -0800 | [diff] [blame] | 837 | //TODO(b/175067650) verify ParcelableException could propagate throwable correctly. |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 838 | callback.onSystemError(new ParcelableException(throwable)); |
| 839 | } catch (RemoteException e) { |
Terry Wang | 2da1785 | 2020-12-16 19:59:08 -0800 | [diff] [blame] | 840 | Log.e(TAG, "Unable to send error to the callback", e); |
Terry Wang | dbd1dca | 2020-11-03 17:03:56 -0800 | [diff] [blame] | 841 | } |
Alexander Dorokhine | 969f446 | 2020-03-05 15:54:19 -0800 | [diff] [blame] | 842 | } |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 843 | } |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 844 | |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 845 | // TODO(b/173553485) verifying that the caller has permission to access target user's data |
| 846 | // TODO(b/173553485) Handle ACTION_USER_REMOVED broadcast |
| 847 | // TODO(b/173553485) Implement SystemService.onUserStopping() |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 848 | private static int handleIncomingUser(@UserIdInt int userId, int callingUid) { |
| 849 | int callingPid = Binder.getCallingPid(); |
Cassie Wang | 0c62d99 | 2021-01-15 14:39:30 -0800 | [diff] [blame] | 850 | return ActivityManager.handleIncomingUser( |
| 851 | callingPid, |
| 852 | callingUid, |
| 853 | userId, |
| 854 | /*allowAll=*/ false, |
| 855 | /*requireFull=*/ false, |
| 856 | /*name=*/ null, |
| 857 | /*callerPackage=*/ null); |
Terry Wang | f209307 | 2020-11-30 04:47:19 -0800 | [diff] [blame] | 858 | } |
Terry Wang | febbead | 2019-10-17 17:05:18 -0700 | [diff] [blame] | 859 | } |