Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bc4504e5 authored by Cassie Wang's avatar Cassie Wang Committed by Android (Google) Code Review
Browse files

Merge "Implement getStorageInfo." into sc-dev

parents 5a162f80 751415fb
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -587,8 +587,28 @@ public final class AppSearchSession implements Closeable {
        Objects.requireNonNull(executor);
        Objects.requireNonNull(callback);
        Preconditions.checkState(!mIsClosed, "AppSearchSession has already been closed");
        // TODO(b/182909475): Implement getStorageInfo
        throw new UnsupportedOperationException();
        try {
            mService.getStorageInfo(
                    mPackageName,
                    mDatabaseName,
                    mUserId,
                    new IAppSearchResultCallback.Stub() {
                        public void onResult(AppSearchResult result) {
                            executor.execute(() -> {
                                if (result.isSuccess()) {
                                    Bundle responseBundle = (Bundle) result.getResultValue();
                                    StorageInfo response =
                                            new StorageInfo(responseBundle);
                                    callback.accept(AppSearchResult.newSuccessfulResult(response));
                                } else {
                                    callback.accept(result);
                                }
                            });
                        }
                    });
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
+16 −0
Original line number Diff line number Diff line
@@ -306,6 +306,22 @@ interface IAppSearchManager {
        in int userId,
        in IAppSearchResultCallback callback);

    /**
     * Gets the storage info.
     *
     * @param packageName The name of the package to get the storage info for.
     * @param databaseName The databaseName to get the storage info for.
     * @param userId Id of the calling user
     * @param callback {@link IAppSearchResultCallback#onResult} will be called with an
     *     {@link AppSearchResult}<{@link Bundle}>, where the value is a
     *     {@link StorageInfo}.
     */
    void getStorageInfo(
        in String packageName,
        in String databaseName,
        in int userId,
        in IAppSearchResultCallback callback);

    /**
     * Persists all update/delete requests to the disk.
     *
+29 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.app.appsearch.PackageIdentifier;
import android.app.appsearch.SearchResultPage;
import android.app.appsearch.SearchSpec;
import android.app.appsearch.SetSchemaResponse;
import android.app.appsearch.StorageInfo;
import android.content.Context;
import android.content.pm.PackageManagerInternal;
import android.os.Binder;
@@ -609,6 +610,34 @@ public class AppSearchManagerService extends SystemService {
            }
        }

        @Override
        public void getStorageInfo(
                @NonNull String packageName,
                @NonNull String databaseName,
                @UserIdInt int userId,
                @NonNull IAppSearchResultCallback callback) {
            Preconditions.checkNotNull(packageName);
            Preconditions.checkNotNull(databaseName);
            Preconditions.checkNotNull(callback);
            int callingUid = Binder.getCallingUid();
            int callingUserId = handleIncomingUser(userId, callingUid);
            final long callingIdentity = Binder.clearCallingIdentity();
            try {
                verifyUserUnlocked(callingUserId);
                verifyCallingPackage(callingUid, packageName);
                AppSearchImpl impl =
                        mImplInstanceManager.getAppSearchImpl(callingUserId);
                StorageInfo storageInfo = impl.getStorageInfoForDatabase(packageName, databaseName);
                Bundle storageInfoBundle = storageInfo.getBundle();
                invokeCallbackOnResult(
                        callback, AppSearchResult.newSuccessfulResult(storageInfoBundle));
            } catch (Throwable t) {
                invokeCallbackOnError(callback, t);
            } finally {
                Binder.restoreCallingIdentity(callingIdentity);
            }
        }

        @Override
        public void persistToDisk(@UserIdInt int userId) {
            int callingUid = Binder.getCallingUidOrThrow();
+6 −0
Original line number Diff line number Diff line
@@ -849,6 +849,12 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
            callback.onResult(AppSearchResult.newSuccessfulResult(null));
        }

        @Override
        public void getStorageInfo(String packageName, String databaseName, int userId,
                IAppSearchResultCallback callback) throws RemoteException {
            ignore(callback);
        }

        @Override
        public void persistToDisk(int userId) throws RemoteException {