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

Commit 56f7c7f3 authored by Yuliya Kamatkova's avatar Yuliya Kamatkova Committed by Android (Google) Code Review
Browse files

Merge "Add Activity#setLocusContext API. Plumb LocusID to the System Server....

Merge "Add Activity#setLocusContext API. Plumb LocusID to the System Server. Add locus update event to the Usage Stats. Test: Build and run on a test device with a test app. Bug: 147594233, 147100454"
parents 30295f54 48c38076
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3901,6 +3901,7 @@ package android.app {
    method public void setImmersive(boolean);
    method public void setInheritShowWhenLocked(boolean);
    method public void setIntent(android.content.Intent);
    method public void setLocusContext(@Nullable android.content.LocusId, @Nullable android.os.Bundle);
    method public final void setMediaController(android.media.session.MediaController);
    method public void setPictureInPictureParams(@NonNull android.app.PictureInPictureParams);
    method @Deprecated public final void setProgress(int);
+34 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.content.CursorLoader;
import android.content.IIntentSender;
import android.content.Intent;
import android.content.IntentSender;
import android.content.LocusId;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
@@ -1025,6 +1026,39 @@ public class Activity extends ContextThemeWrapper
        mIntent = newIntent;
    }

    /**
     * Sets the {@link android.content.LocusId} for this activity. The locus id
     * helps identify different instances of the same {@code Activity} class.
     * <p> For example, a locus id based on a specific conversation could be set on a
     * conversation app's chat {@code Activity}. The system can then use this locus id
     * along with app's contents to provide ranking signals in various UI surfaces
     * including sharing, notifications, shortcuts and so on.
     * <p> It is recommended to set the same locus id in the shortcut's locus id using
     * {@link android.content.pm.ShortcutInfo.Builder#setLocusId(android.content.LocusId)
     *      setLocusId}
     * so that the system can learn appropriate ranking signals linking the activity's
     * locus id with the matching shortcut.
     *
     * @param locusId  a unique, stable id that identifies this {@code Activity} instance from
     *      others. This can be linked to a shortcut using
     *      {@link android.content.pm.ShortcutInfo.Builder#setLocusId(android.content.LocusId)
     *      setLocusId} with the same locus id string.
     * @param bundle extras set or updated as part of this locus context. This may help provide
     *      additional metadata such as URLs, conversation participants specific to this
     *      {@code Activity}'s context.
     *
     * @see android.view.contentcapture.ContentCaptureManager
     * @see android.view.contentcapture.ContentCaptureContext
     */
    public void setLocusContext(@Nullable LocusId locusId, @Nullable Bundle bundle) {
        try {
            ActivityManager.getService().setActivityLocusContext(mComponent, locusId, mToken);
        } catch (RemoteException re) {
            re.rethrowFromSystemServer();
        }
        // TODO(b/147750355): Pass locusId and bundle to the Content Capture.
    }

    /** Return the application that owns this activity. */
    public final Application getApplication() {
        return mApplication;
+10 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import android.content.pm.ParceledListSlice;
import android.content.pm.ProviderInfo;
import android.content.pm.UserInfo;
import android.content.res.Configuration;
import android.content.LocusId;
import android.graphics.Bitmap;
import android.graphics.GraphicBuffer;
import android.graphics.Point;
@@ -637,4 +638,13 @@ interface IActivityManager {
     * and the given process is imperceptible.
     */
    void killProcessesWhenImperceptible(in int[] pids, String reason);

    /**
     * Set locus context for a given activity.
     * @param activity
     * @param locusId a unique, stable id that identifies this activity instance from others.
     * @param appToken ActivityRecord's appToken.
     */
    void setActivityLocusContext(in ComponentName activity, in LocusId locusId,
            in IBinder appToken);
}
+37 −1
Original line number Diff line number Diff line
@@ -289,11 +289,17 @@ public final class UsageEvents implements Parcelable {
         */
        public static final int USER_STOPPED = 29;

        /**
         * An event type denoting that new locusId has been set for a given activity.
         * @hide
         */
        public static final int LOCUS_ID_SET = 30;

        /**
         * Keep in sync with the greatest event type value.
         * @hide
         */
        public static final int MAX_EVENT_TYPE = 29;
        public static final int MAX_EVENT_TYPE = 30;

        /** @hide */
        public static final int FLAG_IS_PACKAGE_INSTANT_APP = 1 << 0;
@@ -436,6 +442,18 @@ public final class UsageEvents implements Parcelable {
         */
        public int mNotificationChannelIdToken = UNASSIGNED_TOKEN;

        /**
         * LocusId.
         * Currently LocusId only present for {@link #LOCUS_ID_SET} event types.
         * {@hide}
         */
        public String mLocusId;

        /**
         * {@hide}
         */
        public int mLocusIdToken = UNASSIGNED_TOKEN;

        /** @hide */
        @EventFlags
        public int mFlags;
@@ -609,6 +627,16 @@ public final class UsageEvents implements Parcelable {
            return ret;
        }

        /**
         * Returns the locusId for this event if the event is of type {@link #LOCUS_ID_SET},
         * otherwise it returns null.
         * @hide
         */
        @Nullable
        public String getLocusId() {
            return mLocusId;
        }

        private void copyFrom(Event orig) {
            mPackage = orig.mPackage;
            mClass = orig.mClass;
@@ -625,6 +653,7 @@ public final class UsageEvents implements Parcelable {
            mFlags = orig.mFlags;
            mBucketAndReason = orig.mBucketAndReason;
            mNotificationChannelId = orig.mNotificationChannelId;
            mLocusId = orig.mLocusId;
        }
    }

@@ -823,6 +852,9 @@ public final class UsageEvents implements Parcelable {
            case Event.NOTIFICATION_INTERRUPTION:
                p.writeString(event.mNotificationChannelId);
                break;
            case Event.LOCUS_ID_SET:
                p.writeString(event.mLocusId);
                break;
        }
        p.writeInt(event.mFlags);
    }
@@ -871,6 +903,7 @@ public final class UsageEvents implements Parcelable {
        eventOut.mContentType = null;
        eventOut.mContentAnnotations = null;
        eventOut.mNotificationChannelId = null;
        eventOut.mLocusId = null;

        switch (eventOut.mEventType) {
            case Event.CONFIGURATION_CHANGE:
@@ -891,6 +924,9 @@ public final class UsageEvents implements Parcelable {
            case Event.NOTIFICATION_INTERRUPTION:
                eventOut.mNotificationChannelId = p.readString();
                break;
            case Event.LOCUS_ID_SET:
                eventOut.mLocusId = p.readString();
                break;
        }
        eventOut.mFlags = p.readInt();
    }
+19 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2020, 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.content;

parcelable LocusId;
Loading