blob: 54e1899e9a00455a2c77320dfd754d41c64a2947 [file] [log] [blame]
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07001/*
2 * Copyright (C) 2014 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.net;
18
Jeremy Joslina9f933e2017-04-28 13:08:17 -070019import android.Manifest.permission;
Jeremy Joslinc5ac5872016-11-30 15:05:40 -080020import android.annotation.IntDef;
Jeremy Joslina4807952017-01-18 14:21:56 -080021import android.annotation.Nullable;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060022import android.annotation.RequiresPermission;
Jeff Davidsonb51e0a62014-04-09 12:38:15 -070023import android.annotation.SdkConstant;
24import android.annotation.SdkConstant.SdkConstantType;
Jeff Davidson7be8e972014-07-16 17:24:46 -070025import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060026import android.annotation.SystemService;
Jeff Davidsonb51e0a62014-04-09 12:38:15 -070027import android.content.Context;
Jeff Davidson6a4b2202014-04-16 17:29:40 -070028import android.os.RemoteException;
29import android.os.ServiceManager;
Jeff Sharkey49ca5292016-05-10 12:54:45 -060030import android.os.ServiceManager.ServiceNotFoundException;
Jeff Davidsonb51e0a62014-04-09 12:38:15 -070031
Jeremy Joslinc5ac5872016-11-30 15:05:40 -080032import java.lang.annotation.Retention;
33import java.lang.annotation.RetentionPolicy;
Jeremy Joslinf95c8652017-02-09 15:32:04 -080034import java.util.List;
Jeremy Joslinc5ac5872016-11-30 15:05:40 -080035
Jeff Davidsonb51e0a62014-04-09 12:38:15 -070036/**
37 * Class that manages communication between network subsystems and a network scorer.
38 *
Jeff Davidsonb51e0a62014-04-09 12:38:15 -070039 * <p>A network scorer is any application which:
40 * <ul>
Jeremy Joslin59502eb2017-07-14 15:00:53 -070041 * <li>Is granted the {@link permission#SCORE_NETWORKS} permission.
42 * <li>Is granted the {@link permission#ACCESS_COARSE_LOCATION} permission.
Jeremy Joslin5519d7c2017-01-06 14:36:54 -080043 * <li>Include a Service for the {@link #ACTION_RECOMMEND_NETWORKS} action
Jeremy Joslina9f933e2017-04-28 13:08:17 -070044 * protected by the {@link permission#BIND_NETWORK_RECOMMENDATION_SERVICE}
Jeremy Joslin5519d7c2017-01-06 14:36:54 -080045 * permission.
Jeff Davidsonb51e0a62014-04-09 12:38:15 -070046 * </ul>
47 *
Jeff Davidsonb51e0a62014-04-09 12:38:15 -070048 * @hide
49 */
Jeff Davidson7be8e972014-07-16 17:24:46 -070050@SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060051@SystemService(Context.NETWORK_SCORE_SERVICE)
Jeff Davidsonb51e0a62014-04-09 12:38:15 -070052public class NetworkScoreManager {
53 /**
Jeff Davidsonee2a1212014-04-17 12:19:23 -070054 * Activity action: ask the user to change the active network scorer. This will show a dialog
55 * that asks the user whether they want to replace the current active scorer with the one
Jeff Davidsonb51e0a62014-04-09 12:38:15 -070056 * specified in {@link #EXTRA_PACKAGE_NAME}. The activity will finish with RESULT_OK if the
Jeff Davidsonee2a1212014-04-17 12:19:23 -070057 * active scorer was changed or RESULT_CANCELED if it failed for any reason.
Jeff Davidsonb51e0a62014-04-09 12:38:15 -070058 */
59 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
Jeff Davidsonee2a1212014-04-17 12:19:23 -070060 public static final String ACTION_CHANGE_ACTIVE = "android.net.scoring.CHANGE_ACTIVE";
Jeff Davidsonb51e0a62014-04-09 12:38:15 -070061
62 /**
Jeff Davidsonee2a1212014-04-17 12:19:23 -070063 * Extra used with {@link #ACTION_CHANGE_ACTIVE} to specify the new scorer package. Set with
Jeff Davidsonb51e0a62014-04-09 12:38:15 -070064 * {@link android.content.Intent#putExtra(String, String)}.
65 */
66 public static final String EXTRA_PACKAGE_NAME = "packageName";
67
68 /**
69 * Broadcast action: new network scores are being requested. This intent will only be delivered
Jeff Davidsonee2a1212014-04-17 12:19:23 -070070 * to the current active scorer app. That app is responsible for scoring the networks and
Jeff Davidsonb51e0a62014-04-09 12:38:15 -070071 * calling {@link #updateScores} when complete. The networks to score are specified in
72 * {@link #EXTRA_NETWORKS_TO_SCORE}, and will generally consist of all networks which have been
73 * configured by the user as well as any open networks.
74 *
75 * <p class="note">This is a protected intent that can only be sent by the system.
76 */
77 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
78 public static final String ACTION_SCORE_NETWORKS = "android.net.scoring.SCORE_NETWORKS";
79
80 /**
Jeff Davidsonb096bdc2014-07-01 12:29:11 -070081 * Extra used with {@link #ACTION_SCORE_NETWORKS} to specify the networks to be scored, as an
82 * array of {@link NetworkKey}s. Can be obtained with
83 * {@link android.content.Intent#getParcelableArrayExtra(String)}}.
84 */
85 public static final String EXTRA_NETWORKS_TO_SCORE = "networksToScore";
86
87 /**
Amin Shaikhbc9a8e62017-02-02 15:39:12 -080088 * Activity action: launch an activity for configuring a provider for the feature that connects
89 * and secures open wifi networks available before enabling it. Applications that enable this
90 * feature must provide an activity for this action. The framework will launch this activity
91 * which must return RESULT_OK if the feature should be enabled.
Jeff Davidsonb6646a82014-06-27 16:24:42 -070092 */
93 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
94 public static final String ACTION_CUSTOM_ENABLE = "android.net.scoring.CUSTOM_ENABLE";
95
96 /**
Stephen Chen8b1339a2017-02-28 18:11:34 -080097 * Meta-data specified on a {@link NetworkRecommendationProvider} that provides a user-visible
98 * label of the recommendation service.
99 * @hide
100 */
101 public static final String RECOMMENDATION_SERVICE_LABEL_META_DATA =
102 "android.net.scoring.recommendation_service_label";
103
104 /**
Amin Shaikhbc9a8e62017-02-02 15:39:12 -0800105 * Meta-data specified on a {@link NetworkRecommendationProvider} that specified the package
106 * name of the application that connects and secures open wifi networks automatically. The
107 * specified package must provide an Activity for {@link #ACTION_CUSTOM_ENABLE}.
108 * @hide
109 */
110 public static final String USE_OPEN_WIFI_PACKAGE_META_DATA =
111 "android.net.wifi.use_open_wifi_package";
112
113 /**
Amin Shaikhd6013602017-03-24 15:52:32 -0700114 * Meta-data specified on a {@link NetworkRecommendationProvider} that specifies the
115 * {@link android.app.NotificationChannel} ID used to post open network notifications.
116 * @hide
117 */
118 public static final String NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID_META_DATA =
119 "android.net.wifi.notification_channel_id_network_available";
120
121 /**
Jeff Davidsonb096bdc2014-07-01 12:29:11 -0700122 * Broadcast action: the active scorer has been changed. Scorer apps may listen to this to
123 * perform initialization once selected as the active scorer, or clean up unneeded resources
Jeremy Joslinda11f5c2016-02-10 07:31:33 -0800124 * if another scorer has been selected. This is an explicit broadcast only sent to the
125 * previous scorer and new scorer. Note that it is unnecessary to clear existing scores as
Jeff Davidsonb096bdc2014-07-01 12:29:11 -0700126 * this is handled by the system.
127 *
128 * <p>The new scorer will be specified in {@link #EXTRA_NEW_SCORER}.
129 *
130 * <p class="note">This is a protected intent that can only be sent by the system.
Jeff Davidsonb51e0a62014-04-09 12:38:15 -0700131 */
Jeff Davidsonb096bdc2014-07-01 12:29:11 -0700132 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
133 public static final String ACTION_SCORER_CHANGED = "android.net.scoring.SCORER_CHANGED";
134
135 /**
Jeremy Joslin13978372016-11-28 17:47:35 -0800136 * Service action: Used to discover and bind to a network recommendation provider.
137 * Implementations should return {@link NetworkRecommendationProvider#getBinder()} from
138 * their <code>onBind()</code> method.
139 */
140 @SdkConstant(SdkConstantType.SERVICE_ACTION)
141 public static final String ACTION_RECOMMEND_NETWORKS = "android.net.action.RECOMMEND_NETWORKS";
142
143 /**
Jeff Davidsonb096bdc2014-07-01 12:29:11 -0700144 * Extra used with {@link #ACTION_SCORER_CHANGED} to specify the newly selected scorer's package
145 * name. Will be null if scoring was disabled. Can be obtained with
146 * {@link android.content.Intent#getStringExtra(String)}.
147 */
148 public static final String EXTRA_NEW_SCORER = "newScorer";
Jeff Davidsonb51e0a62014-04-09 12:38:15 -0700149
Jeremy Joslinc5ac5872016-11-30 15:05:40 -0800150 /** @hide */
151 @IntDef({CACHE_FILTER_NONE, CACHE_FILTER_CURRENT_NETWORK, CACHE_FILTER_SCAN_RESULTS})
152 @Retention(RetentionPolicy.SOURCE)
153 public @interface CacheUpdateFilter {}
154
155 /**
156 * Do not filter updates sent to the cache.
157 * @hide
158 */
159 public static final int CACHE_FILTER_NONE = 0;
160
161 /**
162 * Only send cache updates when the network matches the connected network.
163 * @hide
164 */
165 public static final int CACHE_FILTER_CURRENT_NETWORK = 1;
166
167 /**
168 * Only send cache updates when the network is part of the current scan result set.
169 * @hide
170 */
171 public static final int CACHE_FILTER_SCAN_RESULTS = 2;
172
Jeremy Joslin9925c6a2017-03-06 10:39:35 -0800173 /** @hide */
174 @IntDef({RECOMMENDATIONS_ENABLED_FORCED_OFF, RECOMMENDATIONS_ENABLED_OFF,
175 RECOMMENDATIONS_ENABLED_ON})
176 @Retention(RetentionPolicy.SOURCE)
177 public @interface RecommendationsEnabledSetting {}
178
179 /**
180 * Recommendations have been forced off.
181 * <p>
182 * This value is never set by any of the NetworkScore classes, it must be set via other means.
183 * This state is also "sticky" and we won't transition out of this state once entered. To move
184 * to a different state this value has to be explicitly set to a different value via
185 * other means.
186 * @hide
187 */
188 public static final int RECOMMENDATIONS_ENABLED_FORCED_OFF = -1;
189
190 /**
191 * Recommendations are not enabled.
192 * <p>
193 * This is a transient state that can be entered when the default recommendation app is enabled
194 * but no longer valid. This state will transition to RECOMMENDATIONS_ENABLED_ON when a valid
195 * recommendation app is enabled.
196 * @hide
197 */
198 public static final int RECOMMENDATIONS_ENABLED_OFF = 0;
199
200 /**
201 * Recommendations are enabled.
202 * <p>
203 * This is a transient state that means a valid recommendation app is active. This state will
204 * transition to RECOMMENDATIONS_ENABLED_OFF if the current and default recommendation apps
205 * become invalid.
206 * @hide
207 */
208 public static final int RECOMMENDATIONS_ENABLED_ON = 1;
209
Jeff Davidsonb51e0a62014-04-09 12:38:15 -0700210 private final Context mContext;
Jeff Davidson6a4b2202014-04-16 17:29:40 -0700211 private final INetworkScoreService mService;
Jeff Davidsonb51e0a62014-04-09 12:38:15 -0700212
213 /** @hide */
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600214 public NetworkScoreManager(Context context) throws ServiceNotFoundException {
Jeff Davidsonb51e0a62014-04-09 12:38:15 -0700215 mContext = context;
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600216 mService = INetworkScoreService.Stub
217 .asInterface(ServiceManager.getServiceOrThrow(Context.NETWORK_SCORE_SERVICE));
Jeff Davidsonb51e0a62014-04-09 12:38:15 -0700218 }
219
220 /**
Jeff Davidson6a4b2202014-04-16 17:29:40 -0700221 * Obtain the package name of the current active network scorer.
Jeff Davidsonb51e0a62014-04-09 12:38:15 -0700222 *
Jeff Davidson6a4b2202014-04-16 17:29:40 -0700223 * <p>At any time, only one scorer application will receive {@link #ACTION_SCORE_NETWORKS}
Jeff Davidsonb51e0a62014-04-09 12:38:15 -0700224 * broadcasts and be allowed to call {@link #updateScores}. Applications may use this method to
225 * determine the current scorer and offer the user the ability to select a different scorer via
Jeff Davidsonee2a1212014-04-17 12:19:23 -0700226 * the {@link #ACTION_CHANGE_ACTIVE} intent.
Jeff Davidson6a4b2202014-04-16 17:29:40 -0700227 * @return the full package name of the current active scorer, or null if there is no active
Jeff Davidson14f1ec02014-04-29 11:58:26 -0700228 * scorer.
Jeff Davidsonb51e0a62014-04-09 12:38:15 -0700229 */
Jeremy Joslin2d55b182017-07-11 15:54:14 -0700230 @RequiresPermission(anyOf = {android.Manifest.permission.SCORE_NETWORKS,
231 android.Manifest.permission.REQUEST_NETWORK_SCORES})
Jeff Davidson6a4b2202014-04-16 17:29:40 -0700232 public String getActiveScorerPackage() {
Jeremy Joslin6c1ca282017-01-10 13:08:32 -0800233 try {
234 return mService.getActiveScorerPackage();
235 } catch (RemoteException e) {
236 throw e.rethrowFromSystemServer();
Jeff Davidsonc7415532014-06-23 18:15:34 -0700237 }
Jeff Davidsonb51e0a62014-04-09 12:38:15 -0700238 }
239
240 /**
Jeremy Joslina5172f62017-02-02 14:27:05 -0800241 * Returns metadata about the active scorer or <code>null</code> if there is no active scorer.
242 *
243 * @hide
244 */
245 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -0600246 @RequiresPermission(android.Manifest.permission.REQUEST_NETWORK_SCORES)
Jeremy Joslina5172f62017-02-02 14:27:05 -0800247 public NetworkScorerAppData getActiveScorer() {
248 try {
249 return mService.getActiveScorer();
250 } catch (RemoteException e) {
251 throw e.rethrowFromSystemServer();
252 }
253 }
254
255 /**
Jeremy Joslinf95c8652017-02-09 15:32:04 -0800256 * Returns the list of available scorer apps. The list will be empty if there are
257 * no valid scorers.
258 *
259 * @hide
260 */
261 public List<NetworkScorerAppData> getAllValidScorers() {
262 try {
263 return mService.getAllValidScorers();
264 } catch (RemoteException e) {
265 throw e.rethrowFromSystemServer();
266 }
267 }
268
269 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -0700270 * Update network scores.
271 *
Jeff Davidson6a4b2202014-04-16 17:29:40 -0700272 * <p>This may be called at any time to re-score active networks. Scores will generally be
273 * updated quickly, but if this method is called too frequently, the scores may be held and
274 * applied at a later time.
Jeff Davidsonb51e0a62014-04-09 12:38:15 -0700275 *
276 * @param networks the networks which have been scored by the scorer.
Jeff Davidson6a4b2202014-04-16 17:29:40 -0700277 * @return whether the update was successful.
278 * @throws SecurityException if the caller is not the active scorer.
Jeff Davidsonb51e0a62014-04-09 12:38:15 -0700279 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -0600280 @RequiresPermission(android.Manifest.permission.SCORE_NETWORKS)
Jeff Davidson6a4b2202014-04-16 17:29:40 -0700281 public boolean updateScores(ScoredNetwork[] networks) throws SecurityException {
282 try {
283 return mService.updateScores(networks);
284 } catch (RemoteException e) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700285 throw e.rethrowFromSystemServer();
Jeff Davidson6a4b2202014-04-16 17:29:40 -0700286 }
287 }
288
289 /**
290 * Clear network scores.
291 *
292 * <p>Should be called when all scores need to be invalidated, i.e. because the scoring
293 * algorithm has changed and old scores can no longer be compared to future scores.
294 *
295 * <p>Note that scores will be cleared automatically when the active scorer changes, as scores
296 * from one scorer cannot be compared to those from another scorer.
297 *
298 * @return whether the clear was successful.
299 * @throws SecurityException if the caller is not the active scorer or privileged.
300 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -0600301 @RequiresPermission(android.Manifest.permission.REQUEST_NETWORK_SCORES)
Jeff Davidson6a4b2202014-04-16 17:29:40 -0700302 public boolean clearScores() throws SecurityException {
303 try {
304 return mService.clearScores();
305 } catch (RemoteException e) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700306 throw e.rethrowFromSystemServer();
Jeff Davidson6a4b2202014-04-16 17:29:40 -0700307 }
308 }
309
310 /**
311 * Set the active scorer to a new package and clear existing scores.
312 *
Jeff Davidsone56f2bb2014-11-05 11:14:19 -0800313 * <p>Should never be called directly without obtaining user consent. This can be done by using
314 * the {@link #ACTION_CHANGE_ACTIVE} broadcast, or using a custom configuration activity.
315 *
Jeff Davidson6a4b2202014-04-16 17:29:40 -0700316 * @return true if the operation succeeded, or false if the new package is not a valid scorer.
Jeremy Josline9052a32017-02-27 15:47:54 -0800317 * @throws SecurityException if the caller is not a system process or does not hold the
Jeremy Joslina9f933e2017-04-28 13:08:17 -0700318 * {@link permission#SCORE_NETWORKS} permission
Jeff Davidson6a4b2202014-04-16 17:29:40 -0700319 * @hide
320 */
Jeff Davidsone56f2bb2014-11-05 11:14:19 -0800321 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -0600322 @RequiresPermission(android.Manifest.permission.SCORE_NETWORKS)
Jeff Davidson6a4b2202014-04-16 17:29:40 -0700323 public boolean setActiveScorer(String packageName) throws SecurityException {
324 try {
325 return mService.setActiveScorer(packageName);
326 } catch (RemoteException e) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700327 throw e.rethrowFromSystemServer();
Jeff Davidson6a4b2202014-04-16 17:29:40 -0700328 }
Jeff Davidsonb51e0a62014-04-09 12:38:15 -0700329 }
Jeff Davidson14f1ec02014-04-29 11:58:26 -0700330
331 /**
Jeff Davidson26fd1432014-07-29 09:39:52 -0700332 * Turn off network scoring.
333 *
334 * <p>May only be called by the current scorer app, or the system.
335 *
336 * @throws SecurityException if the caller is neither the active scorer nor the system.
337 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -0600338 @RequiresPermission(android.Manifest.permission.REQUEST_NETWORK_SCORES)
Jeff Davidson26fd1432014-07-29 09:39:52 -0700339 public void disableScoring() throws SecurityException {
340 try {
341 mService.disableScoring();
342 } catch (RemoteException e) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700343 throw e.rethrowFromSystemServer();
Jeff Davidson26fd1432014-07-29 09:39:52 -0700344 }
345 }
346
347 /**
Jeff Davidson14f1ec02014-04-29 11:58:26 -0700348 * Request scoring for networks.
349 *
Jeff Davidson14f1ec02014-04-29 11:58:26 -0700350 * @return true if the broadcast was sent, or false if there is no active scorer.
351 * @throws SecurityException if the caller does not hold the
Jeremy Joslina9f933e2017-04-28 13:08:17 -0700352 * {@link permission#REQUEST_NETWORK_SCORES} permission.
Jeff Davidson14f1ec02014-04-29 11:58:26 -0700353 * @hide
354 */
355 public boolean requestScores(NetworkKey[] networks) throws SecurityException {
Jeremy Joslin145c3432016-12-09 13:11:51 -0800356 try {
357 return mService.requestScores(networks);
358 } catch (RemoteException e) {
359 throw e.rethrowFromSystemServer();
Jeff Davidson14f1ec02014-04-29 11:58:26 -0700360 }
Jeff Davidson14f1ec02014-04-29 11:58:26 -0700361 }
362
363 /**
364 * Register a network score cache.
365 *
366 * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}.
367 * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores.
368 * @throws SecurityException if the caller does not hold the
Jeremy Joslina9f933e2017-04-28 13:08:17 -0700369 * {@link permission#REQUEST_NETWORK_SCORES} permission.
Jeff Davidson14f1ec02014-04-29 11:58:26 -0700370 * @throws IllegalArgumentException if a score cache is already registered for this type.
Jeremy Joslinc5ac5872016-11-30 15:05:40 -0800371 * @deprecated equivalent to registering for cache updates with CACHE_FILTER_NONE.
Jeff Davidson14f1ec02014-04-29 11:58:26 -0700372 * @hide
373 */
Jeremy Joslinc5ac5872016-11-30 15:05:40 -0800374 @Deprecated // migrate to registerNetworkScoreCache(int, INetworkScoreCache, int)
Jeff Davidson14f1ec02014-04-29 11:58:26 -0700375 public void registerNetworkScoreCache(int networkType, INetworkScoreCache scoreCache) {
Jeremy Joslinc5ac5872016-11-30 15:05:40 -0800376 registerNetworkScoreCache(networkType, scoreCache, CACHE_FILTER_NONE);
377 }
378
379 /**
380 * Register a network score cache.
381 *
382 * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}
383 * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores
384 * @param filterType the {@link CacheUpdateFilter} to apply
385 * @throws SecurityException if the caller does not hold the
Jeremy Joslina9f933e2017-04-28 13:08:17 -0700386 * {@link permission#REQUEST_NETWORK_SCORES} permission.
Jeremy Joslinc5ac5872016-11-30 15:05:40 -0800387 * @throws IllegalArgumentException if a score cache is already registered for this type.
388 * @hide
389 */
390 public void registerNetworkScoreCache(int networkType, INetworkScoreCache scoreCache,
391 @CacheUpdateFilter int filterType) {
Jeff Davidson14f1ec02014-04-29 11:58:26 -0700392 try {
Jeremy Joslinc5ac5872016-11-30 15:05:40 -0800393 mService.registerNetworkScoreCache(networkType, scoreCache, filterType);
Jeff Davidson14f1ec02014-04-29 11:58:26 -0700394 } catch (RemoteException e) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700395 throw e.rethrowFromSystemServer();
Jeff Davidson14f1ec02014-04-29 11:58:26 -0700396 }
397 }
Jeremy Joslin13978372016-11-28 17:47:35 -0800398
399 /**
Amin Shaikh972e2362016-12-07 14:08:09 -0800400 * Unregister a network score cache.
401 *
402 * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}.
403 * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores.
404 * @throws SecurityException if the caller does not hold the
Jeremy Joslina9f933e2017-04-28 13:08:17 -0700405 * {@link permission#REQUEST_NETWORK_SCORES} permission.
Amin Shaikh972e2362016-12-07 14:08:09 -0800406 * @throws IllegalArgumentException if a score cache is already registered for this type.
407 * @hide
408 */
409 public void unregisterNetworkScoreCache(int networkType, INetworkScoreCache scoreCache) {
410 try {
411 mService.unregisterNetworkScoreCache(networkType, scoreCache);
412 } catch (RemoteException e) {
413 throw e.rethrowFromSystemServer();
414 }
415 }
416
417 /**
Jeremy Joslin134c9d32017-01-09 16:22:20 -0800418 * Determine whether the application with the given UID is the enabled scorer.
419 *
420 * @param callingUid the UID to check
421 * @return true if the provided UID is the active scorer, false otherwise.
422 * @hide
423 */
424 public boolean isCallerActiveScorer(int callingUid) {
425 try {
426 return mService.isCallerActiveScorer(callingUid);
427 } catch (RemoteException e) {
428 throw e.rethrowFromSystemServer();
429 }
430 }
Jeff Davidsonb51e0a62014-04-09 12:38:15 -0700431}