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

Commit fb182aeb authored by Alexander Dorokhine's avatar Alexander Dorokhine Committed by Android (Google) Code Review
Browse files

Merge "Update framework from Jetpack"

parents 7b848d34 4306d3f8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -233,7 +233,7 @@ public class AppSearchManager {
            mService.setSchema(
                    DEFAULT_DATABASE_NAME,
                    schemaBundles,
                    new ArrayList<>(request.getSchemasNotPlatformSurfaceable()),
                    new ArrayList<>(request.getSchemasNotVisibleToSystemUi()),
                    request.isForceOverride(),
                    mContext.getUserId(),
                    new IAppSearchResultCallback.Stub() {
+1 −1
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ public final class AppSearchSession {
            mService.setSchema(
                    mDatabaseName,
                    schemaBundles,
                    new ArrayList<>(request.getSchemasNotPlatformSurfaceable()),
                    new ArrayList<>(request.getSchemasNotVisibleToSystemUi()),
                    request.isForceOverride(),
                    mUserId,
                    new IAppSearchResultCallback.Stub() {
+21 −10
Original line number Diff line number Diff line
@@ -18,27 +18,38 @@ package android.app.appsearch;

import android.annotation.NonNull;

import com.android.internal.util.Preconditions;

import java.util.Arrays;
import java.util.Objects;

/**
 * This class represents a uniquely identifiable package.
 *
 * @hide
 */
public class PackageIdentifier {
    public final String packageName;
    public final byte[] certificate;
    private final String mPackageName;
    private final byte[] mSha256Certificate;

    /**
     * Creates a unique identifier for a package.
     *
     * @param packageName Name of the package.
     * @param certificate SHA256 certificate digest of the package.
     * @param sha256Certificate SHA256 certificate digest of the package.
     */
    public PackageIdentifier(@NonNull String packageName, @NonNull byte[] certificate) {
        this.packageName = packageName;
        this.certificate = certificate;
    public PackageIdentifier(@NonNull String packageName, @NonNull byte[] sha256Certificate) {
        mPackageName = Preconditions.checkNotNull(packageName);
        mSha256Certificate = Preconditions.checkNotNull(sha256Certificate);
    }

    @NonNull
    public String getPackageName() {
        return mPackageName;
    }

    @NonNull
    public byte[] getSha256Certificate() {
        return mSha256Certificate;
    }

    @Override
@@ -50,12 +61,12 @@ public class PackageIdentifier {
            return false;
        }
        final PackageIdentifier other = (PackageIdentifier) obj;
        return this.packageName.equals(other.packageName)
                && Arrays.equals(this.certificate, other.certificate);
        return this.mPackageName.equals(other.mPackageName)
                && Arrays.equals(this.mSha256Certificate, other.mSha256Certificate);
    }

    @Override
    public int hashCode() {
        return Objects.hash(packageName, Arrays.hashCode(certificate));
        return Objects.hash(mPackageName, Arrays.hashCode(mSha256Certificate));
    }
}
+29 −30
Original line number Diff line number Diff line
@@ -18,17 +18,14 @@ package android.app.appsearch;

import android.annotation.NonNull;
import android.annotation.SuppressLint;
import android.app.appsearch.exceptions.AppSearchException;
import android.util.ArrayMap;
import android.util.ArraySet;

import com.android.internal.util.Preconditions;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

@@ -39,18 +36,18 @@ import java.util.Set;
 */
public final class SetSchemaRequest {
    private final Set<AppSearchSchema> mSchemas;
    private final Set<String> mSchemasNotPlatformSurfaceable;
    private final Map<String, Set<PackageIdentifier>> mSchemasPackageAccessible;
    private final Set<String> mSchemasNotVisibleToSystemUi;
    private final Map<String, Set<PackageIdentifier>> mSchemasVisibleToPackages;
    private final boolean mForceOverride;

    SetSchemaRequest(
            @NonNull Set<AppSearchSchema> schemas,
            @NonNull Set<String> schemasNotPlatformSurfaceable,
            @NonNull Map<String, Set<PackageIdentifier>> schemasPackageAccessible,
            @NonNull Set<String> schemasNotVisibleToSystemUi,
            @NonNull Map<String, Set<PackageIdentifier>> schemasVisibleToPackages,
            boolean forceOverride) {
        mSchemas = Preconditions.checkNotNull(schemas);
        mSchemasNotPlatformSurfaceable = Preconditions.checkNotNull(schemasNotPlatformSurfaceable);
        mSchemasPackageAccessible = Preconditions.checkNotNull(schemasPackageAccessible);
        mSchemasNotVisibleToSystemUi = Preconditions.checkNotNull(schemasNotVisibleToSystemUi);
        mSchemasVisibleToPackages = Preconditions.checkNotNull(schemasVisibleToPackages);
        mForceOverride = forceOverride;
    }

@@ -62,12 +59,11 @@ public final class SetSchemaRequest {

    /**
     * Returns the set of schema types that have opted out of being visible on system UI surfaces.
     *
     * @hide
     */
    @NonNull
    public Set<String> getSchemasNotPlatformSurfaceable() {
        return Collections.unmodifiableSet(mSchemasNotPlatformSurfaceable);
    public Set<String> getSchemasNotVisibleToSystemUi() {
        return Collections.unmodifiableSet(mSchemasNotVisibleToSystemUi);
    }

    /**
@@ -76,14 +72,13 @@ public final class SetSchemaRequest {
     * certificate.
     *
     * <p>This method is inefficient to call repeatedly.
     *
     * @hide
     */
    @NonNull
    public Map<String, Set<PackageIdentifier>> getSchemasPackageAccessible() {
    public Map<String, Set<PackageIdentifier>> getSchemasVisibleToPackages() {
        Map<String, Set<PackageIdentifier>> copy = new ArrayMap<>();
        for (String key : mSchemasPackageAccessible.keySet()) {
            copy.put(key, new ArraySet<>(mSchemasPackageAccessible.get(key)));
        for (String key : mSchemasVisibleToPackages.keySet()) {
            copy.put(key, new ArraySet<>(mSchemasVisibleToPackages.get(key)));
        }
        return copy;
    }
@@ -93,14 +88,14 @@ public final class SetSchemaRequest {
     * type. Each package is represented by a {@link PackageIdentifier}. name and byte[]
     * certificate.
     *
     * <p>A more efficient version of {@code #getSchemasPackageAccessible}, but it returns a
     * <p>A more efficient version of {@link #getSchemasVisibleToPackages}, but it returns a
     * modifiable map. This is not meant to be unhidden and should only be used by internal classes.
     *
     * @hide
     */
    @NonNull
    public Map<String, Set<PackageIdentifier>> getSchemasPackageAccessibleInternal() {
        return mSchemasPackageAccessible;
    public Map<String, Set<PackageIdentifier>> getSchemasVisibleToPackagesInternal() {
        return mSchemasVisibleToPackages;
    }

    /** Returns whether this request will force the schema to be overridden. */
@@ -111,8 +106,8 @@ public final class SetSchemaRequest {
    /** Builder for {@link SetSchemaRequest} objects. */
    public static final class Builder {
        private final Set<AppSearchSchema> mSchemas = new ArraySet<>();
        private final Set<String> mSchemasNotPlatformSurfaceable = new ArraySet<>();
        private final Map<String, Set<PackageIdentifier>> mSchemasPackageAccessible =
        private final Set<String> mSchemasNotVisibleToSystemUi = new ArraySet<>();
        private final Map<String, Set<PackageIdentifier>> mSchemasVisibleToPackages =
                new ArrayMap<>();
        private boolean mForceOverride = false;
        private boolean mBuilt = false;
@@ -148,6 +143,8 @@ public final class SetSchemaRequest {
         * @param visible Whether the {@code schemaType} will be visible or not.
         * @hide
         */
        // Merged list available from getSchemasNotVisibleToSystemUi
        @SuppressLint("MissingGetterMatchingBuilder")
        @NonNull
        public Builder setSchemaTypeVisibilityForSystemUi(
                @NonNull String schemaType, boolean visible) {
@@ -155,9 +152,9 @@ public final class SetSchemaRequest {
            Preconditions.checkState(!mBuilt, "Builder has already been used");

            if (visible) {
                mSchemasNotPlatformSurfaceable.remove(schemaType);
                mSchemasNotVisibleToSystemUi.remove(schemaType);
            } else {
                mSchemasNotPlatformSurfaceable.add(schemaType);
                mSchemasNotVisibleToSystemUi.add(schemaType);
            }
            return this;
        }
@@ -170,6 +167,8 @@ public final class SetSchemaRequest {
         * @param packageIdentifier Represents the package that will be granted visibility.
         * @hide
         */
        // Merged list available from getSchemasVisibleToPackages
        @SuppressLint("MissingGetterMatchingBuilder")
        @NonNull
        public Builder setSchemaTypeVisibilityForPackage(
                @NonNull String schemaType,
@@ -179,13 +178,13 @@ public final class SetSchemaRequest {
            Preconditions.checkNotNull(packageIdentifier);
            Preconditions.checkState(!mBuilt, "Builder has already been used");

            Set<PackageIdentifier> packageIdentifiers = mSchemasPackageAccessible.get(schemaType);
            Set<PackageIdentifier> packageIdentifiers = mSchemasVisibleToPackages.get(schemaType);
            if (visible) {
                if (packageIdentifiers == null) {
                    packageIdentifiers = new ArraySet<>();
                }
                packageIdentifiers.add(packageIdentifier);
                mSchemasPackageAccessible.put(schemaType, packageIdentifiers);
                mSchemasVisibleToPackages.put(schemaType, packageIdentifiers);
            } else {
                if (packageIdentifiers == null) {
                    // Return early since there was nothing set to begin with.
@@ -194,7 +193,7 @@ public final class SetSchemaRequest {
                packageIdentifiers.remove(packageIdentifier);
                if (packageIdentifiers.isEmpty()) {
                    // Remove the entire key so that we don't have empty sets as values.
                    mSchemasPackageAccessible.remove(schemaType);
                    mSchemasVisibleToPackages.remove(schemaType);
                }
            }

@@ -229,8 +228,8 @@ public final class SetSchemaRequest {

            // Verify that any schema types with visibility settings refer to a real schema.
            // Create a copy because we're going to remove from the set for verification purposes.
            Set<String> referencedSchemas = new ArraySet<>(mSchemasNotPlatformSurfaceable);
            referencedSchemas.addAll(mSchemasPackageAccessible.keySet());
            Set<String> referencedSchemas = new ArraySet<>(mSchemasNotVisibleToSystemUi);
            referencedSchemas.addAll(mSchemasVisibleToPackages.keySet());

            for (AppSearchSchema schema : mSchemas) {
                referencedSchemas.remove(schema.getSchemaType());
@@ -244,8 +243,8 @@ public final class SetSchemaRequest {

            return new SetSchemaRequest(
                    mSchemas,
                    mSchemasNotPlatformSurfaceable,
                    mSchemasPackageAccessible,
                    mSchemasNotVisibleToSystemUi,
                    mSchemasVisibleToPackages,
                    mForceOverride);
        }
    }
+9 −8
Original line number Diff line number Diff line
@@ -156,7 +156,6 @@ public final class AppSearchImpl {
    }

    private AppSearchImpl(@NonNull File icingDir) throws AppSearchException {
        boolean isReset = false;
        mReadWriteLock.writeLock().lock();

        try {
@@ -168,9 +167,11 @@ public final class AppSearchImpl {
                            .build();
            mIcingSearchEngineLocked = new IcingSearchEngine(options);

            mVisibilityStoreLocked = new VisibilityStore(this);

            InitializeResultProto initializeResultProto = mIcingSearchEngineLocked.initialize();
            SchemaProto schemaProto = null;
            GetAllNamespacesResultProto getAllNamespacesResultProto = null;
            SchemaProto schemaProto;
            GetAllNamespacesResultProto getAllNamespacesResultProto;
            try {
                checkSuccess(initializeResultProto.getStatus());
                schemaProto = getSchemaProtoLocked();
@@ -180,7 +181,7 @@ public final class AppSearchImpl {
                Log.w(TAG, "Error initializing, resetting IcingSearchEngine.", e);
                // Some error. Reset and see if it fixes it.
                reset();
                isReset = true;
                return;
            }

            // Populate schema map
@@ -196,11 +197,8 @@ public final class AppSearchImpl {

            // TODO(b/155939114): It's possible to optimize after init, which would reduce the time
            //   to when we're able to serve queries. Consider moving this optimize call out.
            if (!isReset) {
            checkForOptimizeLocked(/* force= */ true);
            }

            mVisibilityStoreLocked = new VisibilityStore(this);
        } finally {
            mReadWriteLock.writeLock().unlock();
        }
@@ -635,6 +633,9 @@ public final class AppSearchImpl {
    /**
     * Clears documents and schema across all packages and databaseNames.
     *
     * <p>This method also clear all data in {@link VisibilityStore}, an {@link
     * #initializeVisibilityStore()} must be called after this.
     *
     * <p>This method belongs to mutate group.
     *
     * @throws AppSearchException on IcingSearchEngine error.
Loading