blob: 33b32839302859bf1cf09d581aa85295e065e1e2 [file] [log] [blame]
Kang Libbced1c2017-04-05 12:30:55 -07001/*
2 * Copyright (C) 2017 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
17package android.service.resolver;
18
19import android.annotation.SystemApi;
20import android.os.Bundle;
21import android.os.Parcel;
22import android.os.Parcelable;
23import android.util.ArrayMap;
24
25import java.util.Map;
26
27/**
28 * A ResolverTarget contains features by which an app or option will be ranked, in
29 * {@link ResolverRankerService}.
30 * @hide
31 */
32@SystemApi
33public final class ResolverTarget implements Parcelable {
34 private static final String TAG = "ResolverTarget";
35
36 /**
37 * a float score for recency of last use.
38 */
39 private float mRecencyScore;
40
41 /**
42 * a float score for total time spent.
43 */
44 private float mTimeSpentScore;
45
46 /**
47 * a float score for number of launches.
48 */
49 private float mLaunchScore;
50
51 /**
52 * a float score for number of selected.
53 */
54 private float mChooserScore;
55
56 /**
57 * a float score for the probability to be selected.
58 */
59 private float mSelectProbability;
60
61 // constructor for the class.
62 public ResolverTarget() {}
63
64 ResolverTarget(Parcel in) {
65 mRecencyScore = in.readFloat();
66 mTimeSpentScore = in.readFloat();
67 mLaunchScore = in.readFloat();
68 mChooserScore = in.readFloat();
69 mSelectProbability = in.readFloat();
70 }
71
72 /**
73 * Gets the score for how recently the target was used in the foreground.
74 *
75 * @return a float score whose range is [0, 1]. The higher the score is, the more recently the
76 * target was used.
77 */
78 public float getRecencyScore() {
79 return mRecencyScore;
80 }
81
82 /**
83 * Sets the score for how recently the target was used in the foreground.
84 *
85 * @param recencyScore a float score whose range is [0, 1]. The higher the score is, the more
86 * recently the target was used.
87 */
88 public void setRecencyScore(float recencyScore) {
89 this.mRecencyScore = recencyScore;
90 }
91
92 /**
93 * Gets the score for how long the target has been used in the foreground.
94 *
95 * @return a float score whose range is [0, 1]. The higher the score is, the longer the target
96 * has been used for.
97 */
98 public float getTimeSpentScore() {
99 return mTimeSpentScore;
100 }
101
102 /**
103 * Sets the score for how long the target has been used in the foreground.
104 *
105 * @param timeSpentScore a float score whose range is [0, 1]. The higher the score is, the
106 * longer the target has been used for.
107 */
108 public void setTimeSpentScore(float timeSpentScore) {
109 this.mTimeSpentScore = timeSpentScore;
110 }
111
112 /**
113 * Gets the score for how many times the target has been launched to the foreground.
114 *
115 * @return a float score whose range is [0, 1]. The higher the score is, the more times the
116 * target has been launched.
117 */
118 public float getLaunchScore() {
119 return mLaunchScore;
120 }
121
122 /**
123 * Sets the score for how many times the target has been launched to the foreground.
124 *
125 * @param launchScore a float score whose range is [0, 1]. The higher the score is, the more
126 * times the target has been launched.
127 */
128 public void setLaunchScore(float launchScore) {
129 this.mLaunchScore = launchScore;
130 }
131
132 /**
133 * Gets the score for how many times the target has been selected by the user to share the same
134 * types of content.
135 *
136 * @return a float score whose range is [0, 1]. The higher the score is, the
137 * more times the target has been selected by the user to share the same types of content for.
138 */
139 public float getChooserScore() {
140 return mChooserScore;
141 }
142
143 /**
144 * Sets the score for how many times the target has been selected by the user to share the same
145 * types of content.
146 *
147 * @param chooserScore a float score whose range is [0, 1]. The higher the score is, the more
148 * times the target has been selected by the user to share the same types
149 * of content for.
150 */
151 public void setChooserScore(float chooserScore) {
152 this.mChooserScore = chooserScore;
153 }
154
155 /**
156 * Gets the probability of how likely this target will be selected by the user.
157 *
158 * @return a float score whose range is [0, 1]. The higher the score is, the more likely the
159 * user is going to select this target.
160 */
161 public float getSelectProbability() {
162 return mSelectProbability;
163 }
164
165 /**
166 * Sets the probability for how like this target will be selected by the user.
167 *
168 * @param selectProbability a float score whose range is [0, 1]. The higher the score is, the
169 * more likely tht user is going to select this target.
170 */
171 public void setSelectProbability(float selectProbability) {
172 this.mSelectProbability = selectProbability;
173 }
174
175 // serialize the class to a string.
176 @Override
177 public String toString() {
178 return "ResolverTarget{"
179 + mRecencyScore + ", "
180 + mTimeSpentScore + ", "
181 + mLaunchScore + ", "
182 + mChooserScore + ", "
183 + mSelectProbability + "}";
184 }
185
186 // describes the kinds of special objects contained in this Parcelable instance's marshaled
187 // representation.
188 @Override
189 public int describeContents() {
190 return 0;
191 }
192
193 // flattens this object in to a Parcel.
194 @Override
195 public void writeToParcel(Parcel dest, int flags) {
196 dest.writeFloat(mRecencyScore);
197 dest.writeFloat(mTimeSpentScore);
198 dest.writeFloat(mLaunchScore);
199 dest.writeFloat(mChooserScore);
200 dest.writeFloat(mSelectProbability);
201 }
202
203 // creator definition for the class.
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700204 public static final @android.annotation.NonNull Creator<ResolverTarget> CREATOR
Kang Libbced1c2017-04-05 12:30:55 -0700205 = new Creator<ResolverTarget>() {
206 @Override
207 public ResolverTarget createFromParcel(Parcel source) {
208 return new ResolverTarget(source);
209 }
210
211 @Override
212 public ResolverTarget[] newArray(int size) {
213 return new ResolverTarget[size];
214 }
215 };
216}