Debian Codegraph @

core/java/android/app/prediction/AppPredictionContext.java

raw symbols SCIP
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.IntRange;
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.content.Context;
23 import android.os.Bundle;
24 import android.os.Parcel;
25 import android.os.Parcelable;
26
27 /**
28 * Class that provides contextual information about the environment in which the app prediction is
29 * used, such as package name, UI in which the app targets are shown, and number of targets.
30 *
31 * @hide
32 */
33 @SystemApi
34 public 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(@NonNull Parcel parcel) {
53 mUiSurface = parcel.readString();
54 mPredictedTargetCount = parcel.readInt();
55 mPackageName = parcel.readString();
56 mExtras = parcel.readBundle();
57 }
58
59 /**
60 * Returns the UI surface of the prediction context.
61 */
62 @NonNull
63 public String getUiSurface() {
64 return mUiSurface;
65 }
66
67 /**
68 * Returns the predicted target count
69 */
70 public @IntRange(from = 0) int getPredictedTargetCount() {
71 return mPredictedTargetCount;
72 }
73
74 /**
75 * Returns the package name of the prediction context.
76 */
77 @NonNull
78 public String getPackageName() {
79 return mPackageName;
80 }
81
82 /**
83 * Returns the extras of the prediction context.
84 */
85 @Nullable
86 public Bundle getExtras() {
87 return mExtras;
88 }
89
90 @Override
91 public boolean equals(@Nullable Object o) {
92 if (o == this) return true;
93 if (!getClass().equals(o != null ? o.getClass() : null)) return false;
94
95 AppPredictionContext other = (AppPredictionContext) o;
96 return mPredictedTargetCount == other.mPredictedTargetCount
97 && mUiSurface.equals(other.mUiSurface)
98 && mPackageName.equals(other.mPackageName);
99 }
100
101 @Override
102 public int describeContents() {
103 return 0;
104 }
105
106 @Override
107 public void writeToParcel(@NonNull Parcel dest, int flags) {
108 dest.writeString(mUiSurface);
109 dest.writeInt(mPredictedTargetCount);
110 dest.writeString(mPackageName);
111 dest.writeBundle(mExtras);
112 }
113
114 public static final @android.annotation.NonNull Parcelable.Creator<AppPredictionContext> CREATOR =
115 new Parcelable.Creator<AppPredictionContext>() {
116 public AppPredictionContext createFromParcel(Parcel parcel) {
117 return new AppPredictionContext(parcel);
118 }
119
120 public AppPredictionContext[] newArray(int size) {
121 return new AppPredictionContext[size];
122 }
123 };
124
125 /**
126 * A builder for app prediction contexts.
127 * @hide
128 */
129 @SystemApi
130 public static final class Builder {
131
132 @NonNull
133 private final String mPackageName;
134
135 private int mPredictedTargetCount;
136 @Nullable
137 private String mUiSurface;
138 @Nullable
139 private Bundle mExtras;
140
141 /**
142 * @param context The {@link Context} of the prediction client.
143 *
144 * @hide
145 */
146 @SystemApi
147 public Builder(@NonNull Context context) {
148 mPackageName = context.getPackageName();
149 }
150
151
152 /**
153 * Sets the number of prediction targets as a hint.
154 */
155 @NonNull
156 public Builder setPredictedTargetCount(@IntRange(from = 0) int predictedTargetCount) {
157 mPredictedTargetCount = predictedTargetCount;
158 return this;
159 }
160
161 /**
162 * Sets the UI surface.
163 */
164 @NonNull
165 public Builder setUiSurface(@NonNull String uiSurface) {
166 mUiSurface = uiSurface;
167 return this;
168 }
169
170 /**
171 * Sets the extras.
172 */
173 @NonNull
174 public Builder setExtras(@Nullable Bundle extras) {
175 mExtras = extras;
176 return this;
177 }
178
179 /**
180 * Builds a new context instance.
181 */
182 @NonNull
183 public AppPredictionContext build() {
184 return new AppPredictionContext(mUiSurface, mPredictedTargetCount, mPackageName,
185 mExtras);
186 }
187 }
188 }