blob: 2da46719cd79bd6bdc56720b9f4129a814be4a3d [file] [log] [blame]
Sunny Goyal54e91342018-11-14 11:59:02 -08001/*
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 */
16package android.app.prediction;
17
18import android.annotation.NonNull;
19import android.annotation.Nullable;
20import android.annotation.SystemApi;
Winson Chung5208cbe2019-01-11 20:51:46 -080021import android.annotation.TestApi;
Sunny Goyal54e91342018-11-14 11:59:02 -080022import android.content.Context;
23import android.os.Bundle;
24import android.os.Parcel;
25import android.os.Parcelable;
26
27/**
28 * TODO(b/111701043): Add java docs
29 *
30 * @hide
31 */
32@SystemApi
Winson Chung5208cbe2019-01-11 20:51:46 -080033@TestApi
Sunny Goyal54e91342018-11-14 11:59:02 -080034public final class AppPredictionContext implements Parcelable {
35
36 private final int mPredictedTargetCount;
37 @NonNull
38 private final String mUiSurface;
39 @NonNull
40 private final String mPackageName;
41 @Nullable
42 private final Bundle mExtras;
43
44 private AppPredictionContext(@NonNull String uiSurface, int numPredictedTargets,
45 @NonNull String packageName, @Nullable Bundle extras) {
46 mUiSurface = uiSurface;
47 mPredictedTargetCount = numPredictedTargets;
48 mPackageName = packageName;
49 mExtras = extras;
50 }
51
52 private AppPredictionContext(Parcel parcel) {
53 mUiSurface = parcel.readString();
54 mPredictedTargetCount = parcel.readInt();
55 mPackageName = parcel.readString();
56 mExtras = parcel.readBundle();
57 }
58
59 public String getUiSurface() {
60 return mUiSurface;
61 }
62
63 public int getPredictedTargetCount() {
64 return mPredictedTargetCount;
65 }
66
67 @NonNull
68 public String getPackageName() {
69 return mPackageName;
70 }
71
72 @Nullable
73 public Bundle getExtras() {
74 return mExtras;
75 }
76
77 @Override
Winson Chung5208cbe2019-01-11 20:51:46 -080078 public boolean equals(Object o) {
79 if (o == this) return true;
80 if (!getClass().equals(o != null ? o.getClass() : null)) return false;
81
82 AppPredictionContext other = (AppPredictionContext) o;
83 return mPredictedTargetCount == other.mPredictedTargetCount
84 && mUiSurface.equals(other.mUiSurface)
85 && mPackageName.equals(other.mPackageName);
86 }
87
88 @Override
Sunny Goyal54e91342018-11-14 11:59:02 -080089 public int describeContents() {
90 return 0;
91 }
92
93 @Override
94 public void writeToParcel(Parcel dest, int flags) {
95 dest.writeString(mUiSurface);
96 dest.writeInt(mPredictedTargetCount);
97 dest.writeString(mPackageName);
98 dest.writeBundle(mExtras);
99 }
100
101 /**
102 * @see Parcelable.Creator
103 */
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700104 public static final @android.annotation.NonNull Parcelable.Creator<AppPredictionContext> CREATOR =
Sunny Goyal54e91342018-11-14 11:59:02 -0800105 new Parcelable.Creator<AppPredictionContext>() {
106 public AppPredictionContext createFromParcel(Parcel parcel) {
107 return new AppPredictionContext(parcel);
108 }
109
110 public AppPredictionContext[] newArray(int size) {
111 return new AppPredictionContext[size];
112 }
113 };
114
115 /**
116 * A builder for app prediction contexts.
117 * @hide
118 */
119 @SystemApi
Winson Chung5208cbe2019-01-11 20:51:46 -0800120 @TestApi
Sunny Goyal54e91342018-11-14 11:59:02 -0800121 public static final class Builder {
122
123 @NonNull
124 private final String mPackageName;
125
126 private int mPredictedTargetCount;
127 @Nullable
128 private String mUiSurface;
129 @Nullable
130 private Bundle mExtras;
131
132 /**
Winson Chung5208cbe2019-01-11 20:51:46 -0800133 * TODO(b/123591863): Add java docs
134 *
Sunny Goyal54e91342018-11-14 11:59:02 -0800135 * @hide
136 */
Winson Chung5208cbe2019-01-11 20:51:46 -0800137 @SystemApi
138 @TestApi
Sunny Goyal54e91342018-11-14 11:59:02 -0800139 public Builder(@NonNull Context context) {
140 mPackageName = context.getPackageName();
141 }
142
143
144 /**
145 * Sets the number of prediction targets as a hint.
146 */
147 public Builder setPredictedTargetCount(int predictedTargetCount) {
148 mPredictedTargetCount = predictedTargetCount;
149 return this;
150 }
151
152 /**
153 * Sets the UI surface.
154 */
155 public Builder setUiSurface(@Nullable String uiSurface) {
156 mUiSurface = uiSurface;
157 return this;
158 }
159
160 /**
161 * Sets the extras.
162 */
163 public Builder setExtras(@Nullable Bundle extras) {
164 mExtras = extras;
165 return this;
166 }
167
168 /**
169 * Builds a new context instance.
170 */
171 public AppPredictionContext build() {
172 return new AppPredictionContext(mUiSurface, mPredictedTargetCount, mPackageName,
173 mExtras);
174 }
175 }
176}