Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package android.app.prediction; |
| 17 | |
| 18 | import android.annotation.IntDef; |
| 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
| 21 | import android.annotation.SystemApi; |
Winson Chung | 5208cbe | 2019-01-11 20:51:46 -0800 | [diff] [blame] | 22 | import android.annotation.TestApi; |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 23 | import android.os.Parcel; |
| 24 | import android.os.Parcelable; |
| 25 | |
| 26 | import java.lang.annotation.Retention; |
| 27 | import java.lang.annotation.RetentionPolicy; |
| 28 | |
| 29 | /** |
| 30 | * A representation of an app target event. |
Mehdi Alizadeh | 2f4b64a | 2019-03-13 21:58:58 -0700 | [diff] [blame] | 31 | * |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 32 | * @hide |
| 33 | */ |
| 34 | @SystemApi |
Winson Chung | 5208cbe | 2019-01-11 20:51:46 -0800 | [diff] [blame] | 35 | @TestApi |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 36 | public final class AppTargetEvent implements Parcelable { |
| 37 | |
| 38 | /** |
| 39 | * @hide |
| 40 | */ |
Shashwat Razdan | 842d4ee | 2019-11-22 15:42:29 -0800 | [diff] [blame] | 41 | @IntDef({ACTION_LAUNCH, ACTION_DISMISS, ACTION_PIN, ACTION_UNPIN}) |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 42 | @Retention(RetentionPolicy.SOURCE) |
| 43 | public @interface ActionType {} |
| 44 | |
| 45 | /** |
| 46 | * Event type constant indicating an app target has been launched. |
| 47 | */ |
| 48 | public static final int ACTION_LAUNCH = 1; |
| 49 | |
| 50 | /** |
| 51 | * Event type constant indicating an app target has been dismissed. |
| 52 | */ |
| 53 | public static final int ACTION_DISMISS = 2; |
| 54 | |
| 55 | /** |
| 56 | * Event type constant indicating an app target has been pinned. |
| 57 | */ |
| 58 | public static final int ACTION_PIN = 3; |
| 59 | |
Shashwat Razdan | 842d4ee | 2019-11-22 15:42:29 -0800 | [diff] [blame] | 60 | /** |
| 61 | * Event type constant indicating an app target has been un-pinned. |
| 62 | */ |
| 63 | public static final int ACTION_UNPIN = 4; |
| 64 | |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 65 | private final AppTarget mTarget; |
| 66 | private final String mLocation; |
| 67 | private final int mAction; |
| 68 | |
| 69 | private AppTargetEvent(@Nullable AppTarget target, @Nullable String location, |
| 70 | @ActionType int actionType) { |
| 71 | mTarget = target; |
| 72 | mLocation = location; |
| 73 | mAction = actionType; |
| 74 | } |
| 75 | |
| 76 | private AppTargetEvent(Parcel parcel) { |
| 77 | mTarget = parcel.readParcelable(null); |
| 78 | mLocation = parcel.readString(); |
| 79 | mAction = parcel.readInt(); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Returns the app target. |
| 84 | */ |
| 85 | @Nullable |
| 86 | public AppTarget getTarget() { |
| 87 | return mTarget; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Returns the launch location. |
| 92 | */ |
Mehdi Alizadeh | 387c7cb | 2019-03-05 16:36:08 -0800 | [diff] [blame] | 93 | @Nullable |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 94 | public String getLaunchLocation() { |
| 95 | return mLocation; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Returns the action type. |
| 100 | */ |
Mehdi Alizadeh | 387c7cb | 2019-03-05 16:36:08 -0800 | [diff] [blame] | 101 | public @ActionType int getAction() { |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 102 | return mAction; |
| 103 | } |
| 104 | |
| 105 | @Override |
Aurimas Liutikas | 4d1699d | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 106 | public boolean equals(@Nullable Object o) { |
Winson Chung | 5208cbe | 2019-01-11 20:51:46 -0800 | [diff] [blame] | 107 | if (!getClass().equals(o != null ? o.getClass() : null)) return false; |
| 108 | |
| 109 | AppTargetEvent other = (AppTargetEvent) o; |
| 110 | return mTarget.equals(other.mTarget) |
| 111 | && mLocation.equals(other.mLocation) |
| 112 | && mAction == other.mAction; |
| 113 | } |
| 114 | |
| 115 | @Override |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 116 | public int describeContents() { |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public void writeToParcel(Parcel dest, int flags) { |
| 122 | dest.writeParcelable(mTarget, 0); |
| 123 | dest.writeString(mLocation); |
| 124 | dest.writeInt(mAction); |
| 125 | } |
| 126 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 127 | public static final @android.annotation.NonNull Creator<AppTargetEvent> CREATOR = |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 128 | new Creator<AppTargetEvent>() { |
| 129 | public AppTargetEvent createFromParcel(Parcel parcel) { |
| 130 | return new AppTargetEvent(parcel); |
| 131 | } |
| 132 | |
| 133 | public AppTargetEvent[] newArray(int size) { |
| 134 | return new AppTargetEvent[size]; |
| 135 | } |
| 136 | }; |
| 137 | |
| 138 | /** |
| 139 | * A builder for app target events. |
Mehdi Alizadeh | 2f4b64a | 2019-03-13 21:58:58 -0700 | [diff] [blame] | 140 | * |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 141 | * @hide |
| 142 | */ |
| 143 | @SystemApi |
Winson Chung | 5208cbe | 2019-01-11 20:51:46 -0800 | [diff] [blame] | 144 | @TestApi |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 145 | public static final class Builder { |
| 146 | private AppTarget mTarget; |
| 147 | private String mLocation; |
| 148 | private @ActionType int mAction; |
| 149 | |
Mehdi Alizadeh | 2f4b64a | 2019-03-13 21:58:58 -0700 | [diff] [blame] | 150 | /** |
| 151 | * @param target The app target that is associated with this event. |
| 152 | * @param actionType The event type, which is one of the values in {@link ActionType}. |
| 153 | */ |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 154 | public Builder(@Nullable AppTarget target, @ActionType int actionType) { |
| 155 | mTarget = target; |
| 156 | mAction = actionType; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Sets the launch location. |
| 161 | */ |
Mehdi Alizadeh | 387c7cb | 2019-03-05 16:36:08 -0800 | [diff] [blame] | 162 | @NonNull |
| 163 | public Builder setLaunchLocation(@Nullable String location) { |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 164 | mLocation = location; |
| 165 | return this; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Builds a new event instance. |
| 170 | */ |
Mehdi Alizadeh | 387c7cb | 2019-03-05 16:36:08 -0800 | [diff] [blame] | 171 | @NonNull |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 172 | public AppTargetEvent build() { |
| 173 | return new AppTargetEvent(mTarget, mLocation, mAction); |
| 174 | } |
| 175 | } |
| 176 | } |