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