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

Commit 67e9426e authored by Felipe Leme's avatar Felipe Leme Committed by Android (Google) Code Review
Browse files

Merge "Implemented ContentCaptureConditions APIs."

parents 9c4a902b a8d33c24
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -136,13 +136,18 @@ public final class ContentCaptureOptions implements Parcelable {
    @Override
    public String toString() {
        if (lite) {
            return "ContentCaptureOptions [(lite) loggingLevel=" + loggingLevel + "]";
            return "ContentCaptureOptions [loggingLevel=" + loggingLevel + " (lite)]";
        }
        final StringBuilder string = new StringBuilder("ContentCaptureOptions [");
        string.append("loggingLevel=").append(loggingLevel)
            .append(", maxBufferSize=").append(maxBufferSize)
            .append(", idleFlushingFrequencyMs=").append(idleFlushingFrequencyMs)
            .append(", textChangeFlushingFrequencyMs=").append(textChangeFlushingFrequencyMs)
            .append(", logHistorySize=").append(logHistorySize);
        if (whitelistedComponents != null) {
            string.append(", whitelisted=").append(whitelistedComponents);
        }
        return "ContentCaptureOptions [loggingLevel=" + loggingLevel + ", maxBufferSize="
                + maxBufferSize + ", idleFlushingFrequencyMs=" + idleFlushingFrequencyMs
                + ", textChangeFlushingFrequencyMs=" + textChangeFlushingFrequencyMs
                + ", logHistorySize=" + logHistorySize + ", whitelistedComponents="
                + whitelistedComponents + "]";
        return string.append(']').toString();
    }

    /** @hide */
+11 −5
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package android.service.contentcapture;

import static android.view.contentcapture.ContentCaptureHelper.sDebug;
import static android.view.contentcapture.ContentCaptureHelper.sVerbose;
import static android.view.contentcapture.ContentCaptureHelper.toList;
import static android.view.contentcapture.ContentCaptureSession.NO_SESSION_ID;

import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;
@@ -54,7 +55,6 @@ import com.android.internal.os.IResultReceiver;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@@ -241,11 +241,17 @@ public abstract class ContentCaptureService extends Service {
     */
    public final void setContentCaptureConditions(@NonNull String packageName,
            @Nullable Set<ContentCaptureCondition> conditions) {
        // TODO(b/129267994): implement
        final IContentCaptureServiceCallback callback = mCallback;
        if (callback == null) {
            Log.w(TAG, "setContentCaptureConditions(): no server callback");
            return;
        }

    private <T> ArrayList<T> toList(@Nullable Set<T> set) {
        return set == null ? null : new ArrayList<T>(set);
        try {
            callback.setContentCaptureConditions(packageName, toList(conditions));
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
    }

    /**
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.service.contentcapture;

import android.content.ComponentName;
import android.view.contentcapture.ContentCaptureCondition;

import java.util.List;

@@ -27,5 +28,6 @@ import java.util.List;
 */
oneway interface IContentCaptureServiceCallback {
    void setContentCaptureWhitelist(in List<String> packages, in List<ComponentName> activities);
    void setContentCaptureConditions(String packageName, in List<ContentCaptureCondition> conditions);
    void disableSelf();
 }
+19 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2019, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view.contentcapture;

parcelable ContentCaptureCondition;
+37 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.content.LocusId;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.DebugUtils;

import com.android.internal.util.Preconditions;

@@ -58,7 +59,6 @@ public final class ContentCaptureCondition implements Parcelable {
    public ContentCaptureCondition(@NonNull LocusId locusId, @Flags int flags) {
        this.mLocusId = Preconditions.checkNotNull(locusId);
        this.mFlags = flags;
        // TODO(b/129267994): check flags, add test case for null and invalid flags
    }

    /**
@@ -78,6 +78,42 @@ public final class ContentCaptureCondition implements Parcelable {
        return mFlags;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + mFlags;
        result = prime * result + ((mLocusId == null) ? 0 : mLocusId.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        if (getClass() != obj.getClass()) return false;
        final ContentCaptureCondition other = (ContentCaptureCondition) obj;
        if (mFlags != other.mFlags) return false;
        if (mLocusId == null) {
            if (other.mLocusId != null) return false;
        } else {
            if (!mLocusId.equals(other.mLocusId)) return false;
        }
        return true;
    }

    @Override
    public String toString() {
        final StringBuilder string = new StringBuilder(mLocusId.toString()); // LocusID is PII safe
        if (mFlags != 0) {
            string
                .append(" (")
                .append(DebugUtils.flagsToString(ContentCaptureCondition.class, "FLAG_", mFlags))
                .append(')');
        }
        return string.toString();
    }

    @Override
    public int describeContents() {
        return 0;
Loading