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.SystemApi;
20 import android.os.Bundle;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 import android.util.ArrayMap;
24 
25 import 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
33 public 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.
ResolverTarget()62     public ResolverTarget() {}
63 
ResolverTarget(Parcel in)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      */
getRecencyScore()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      */
setRecencyScore(float recencyScore)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      */
getTimeSpentScore()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      */
setTimeSpentScore(float timeSpentScore)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      */
getLaunchScore()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      */
setLaunchScore(float launchScore)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      */
getChooserScore()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      */
setChooserScore(float chooserScore)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      */
getSelectProbability()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      */
setSelectProbability(float selectProbability)171     public void setSelectProbability(float selectProbability) {
172         this.mSelectProbability = selectProbability;
173     }
174 
175     // serialize the class to a string.
176     @Override
toString()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
describeContents()189     public int describeContents() {
190         return 0;
191     }
192 
193     // flattens this object in to a Parcel.
194     @Override
writeToParcel(Parcel dest, int flags)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.
204     public static final Creator<ResolverTarget> CREATOR
205             = 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 }
217