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

Commit ac042501 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

ShortcutManager: Implement usage report API

Bug 28536054

Change-Id: I293e8eaad523e3b0d76d562fc381601633451ed3
parent f6be4c02
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6493,11 +6493,13 @@ package android.app.usage {
    method public android.content.res.Configuration getConfiguration();
    method public int getEventType();
    method public java.lang.String getPackageName();
    method public java.lang.String getShortcutId();
    method public long getTimeStamp();
    field public static final int CONFIGURATION_CHANGE = 5; // 0x5
    field public static final int MOVE_TO_BACKGROUND = 2; // 0x2
    field public static final int MOVE_TO_FOREGROUND = 1; // 0x1
    field public static final int NONE = 0; // 0x0
    field public static final int SHORTCUT_INVOCATION = 8; // 0x8
    field public static final int USER_INTERACTION = 7; // 0x7
  }
+2 −0
Original line number Diff line number Diff line
@@ -6774,11 +6774,13 @@ package android.app.usage {
    method public android.content.res.Configuration getConfiguration();
    method public int getEventType();
    method public java.lang.String getPackageName();
    method public java.lang.String getShortcutId();
    method public long getTimeStamp();
    field public static final int CONFIGURATION_CHANGE = 5; // 0x5
    field public static final int MOVE_TO_BACKGROUND = 2; // 0x2
    field public static final int MOVE_TO_FOREGROUND = 1; // 0x1
    field public static final int NONE = 0; // 0x0
    field public static final int SHORTCUT_INVOCATION = 8; // 0x8
    field public static final int USER_INTERACTION = 7; // 0x7
  }
+2 −0
Original line number Diff line number Diff line
@@ -6499,11 +6499,13 @@ package android.app.usage {
    method public android.content.res.Configuration getConfiguration();
    method public int getEventType();
    method public java.lang.String getPackageName();
    method public java.lang.String getShortcutId();
    method public long getTimeStamp();
    field public static final int CONFIGURATION_CHANGE = 5; // 0x5
    field public static final int MOVE_TO_BACKGROUND = 2; // 0x2
    field public static final int MOVE_TO_FOREGROUND = 1; // 0x1
    field public static final int NONE = 0; // 0x0
    field public static final int SHORTCUT_INVOCATION = 8; // 0x8
    field public static final int USER_INTERACTION = 7; // 0x7
  }
+43 −7
Original line number Diff line number Diff line
@@ -78,6 +78,13 @@ public final class UsageEvents implements Parcelable {
         */
        public static final int USER_INTERACTION = 7;

        /**
         * An event type denoting that an action equivalent to a ShortcutInfo is taken by the user.
         *
         * @see android.content.pm.ShortcutManager#reportShortcutUsed(String)
         */
        public static final int SHORTCUT_INVOCATION = 8;

        /**
         * {@hide}
         */
@@ -104,6 +111,13 @@ public final class UsageEvents implements Parcelable {
         */
        public Configuration mConfiguration;

        /**
         * ID of the shortcut.
         * Only present for {@link #SHORTCUT_INVOCATION} event types.
         * {@hide}
         */
        public String mShortcutId;

        /**
         * The package name of the source of this event.
         */
@@ -145,6 +159,16 @@ public final class UsageEvents implements Parcelable {
        public Configuration getConfiguration() {
            return mConfiguration;
        }

        /**
         * Returns the ID of a {@link android.content.pm.ShortcutInfo} for this event
         * if the event is of type {@link #SHORTCUT_INVOCATION}, otherwise it returns null.
         *
         * @see android.content.pm.ShortcutManager#reportShortcutUsed(String)
         */
        public String getShortcutId() {
            return mShortcutId;
        }
    }

    // Only used when creating the resulting events. Not used for reading/unparceling.
@@ -276,8 +300,13 @@ public final class UsageEvents implements Parcelable {
        p.writeInt(event.mEventType);
        p.writeLong(event.mTimeStamp);

        if (event.mEventType == Event.CONFIGURATION_CHANGE) {
        switch (event.mEventType) {
            case Event.CONFIGURATION_CHANGE:
                event.mConfiguration.writeToParcel(p, flags);
                break;
            case Event.SHORTCUT_INVOCATION:
                p.writeString(event.mShortcutId);
                break;
        }
    }

@@ -301,11 +330,18 @@ public final class UsageEvents implements Parcelable {
        eventOut.mEventType = p.readInt();
        eventOut.mTimeStamp = p.readLong();

        // Fill out the event-dependant fields.
        eventOut.mConfiguration = null;
        eventOut.mShortcutId = null;

        switch (eventOut.mEventType) {
            case Event.CONFIGURATION_CHANGE:
                // Extract the configuration for configuration change events.
        if (eventOut.mEventType == Event.CONFIGURATION_CHANGE) {
                eventOut.mConfiguration = Configuration.CREATOR.createFromParcel(p);
        } else {
            eventOut.mConfiguration = null;
                break;
            case Event.SHORTCUT_INVOCATION:
                eventOut.mShortcutId = p.readString();
                break;
        }
    }

+11 −0
Original line number Diff line number Diff line
@@ -55,6 +55,17 @@ public abstract class UsageStatsManagerInternal {
     */
    public abstract void reportConfigurationChange(Configuration config, int userId);

    /**
     * Reports that an action equivalent to a ShortcutInfo is taken by the user.
     *
     * @param packageName The package name of the shortcut publisher
     * @param shortcutId The ID of the shortcut in question
     * @param userId The user in which the content provider was accessed.
     *
     * @see android.content.pm.ShortcutManager#reportShortcutUsed(String)
     */
    public abstract void reportShortcutUsage(String packageName, String shortcutId, int userId);

    /**
     * Reports that a content provider has been accessed by a foreground app.
     * @param name The authority of the content provider
Loading