Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.net; |
| 18 | |
Jeff Davidson | ac7285d | 2014-08-08 15:12:47 -0700 | [diff] [blame] | 19 | import android.Manifest; |
Jeremy Joslin | 823db05 | 2016-11-30 15:05:40 -0800 | [diff] [blame] | 20 | import android.annotation.IntDef; |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 21 | import android.annotation.SdkConstant; |
| 22 | import android.annotation.SdkConstant.SdkConstantType; |
Jeff Davidson | 7be8e97 | 2014-07-16 17:24:46 -0700 | [diff] [blame] | 23 | import android.annotation.SystemApi; |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 24 | import android.content.Context; |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 25 | import android.content.Intent; |
Jeff Davidson | c741553 | 2014-06-23 18:15:34 -0700 | [diff] [blame] | 26 | import android.net.NetworkScorerAppManager.NetworkScorerAppData; |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 27 | import android.os.IBinder; |
| 28 | import android.os.RemoteException; |
| 29 | import android.os.ServiceManager; |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 30 | |
Jeremy Joslin | 823db05 | 2016-11-30 15:05:40 -0800 | [diff] [blame] | 31 | import java.lang.annotation.Retention; |
| 32 | import java.lang.annotation.RetentionPolicy; |
| 33 | |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 34 | /** |
| 35 | * Class that manages communication between network subsystems and a network scorer. |
| 36 | * |
| 37 | * <p>You can get an instance of this class by calling |
| 38 | * {@link android.content.Context#getSystemService(String)}: |
| 39 | * |
| 40 | * <pre>NetworkScoreManager manager = |
| 41 | * (NetworkScoreManager) getSystemService(Context.NETWORK_SCORE_SERVICE)</pre> |
| 42 | * |
| 43 | * <p>A network scorer is any application which: |
| 44 | * <ul> |
| 45 | * <li>Declares the {@link android.Manifest.permission#SCORE_NETWORKS} permission. |
Jeremy Joslin | 186f333 | 2017-01-06 14:36:54 -0800 | [diff] [blame] | 46 | * <li>Include a Service for the {@link #ACTION_RECOMMEND_NETWORKS} action |
| 47 | * protected by the {@link android.Manifest.permission#BIND_NETWORK_RECOMMENDATION_SERVICE} |
| 48 | * permission. |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 49 | * </ul> |
| 50 | * |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 51 | * @hide |
| 52 | */ |
Jeff Davidson | 7be8e97 | 2014-07-16 17:24:46 -0700 | [diff] [blame] | 53 | @SystemApi |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 54 | public class NetworkScoreManager { |
| 55 | /** |
Jeff Davidson | ee2a121 | 2014-04-17 12:19:23 -0700 | [diff] [blame] | 56 | * Activity action: ask the user to change the active network scorer. This will show a dialog |
| 57 | * that asks the user whether they want to replace the current active scorer with the one |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 58 | * specified in {@link #EXTRA_PACKAGE_NAME}. The activity will finish with RESULT_OK if the |
Jeff Davidson | ee2a121 | 2014-04-17 12:19:23 -0700 | [diff] [blame] | 59 | * active scorer was changed or RESULT_CANCELED if it failed for any reason. |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 60 | */ |
| 61 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
Jeff Davidson | ee2a121 | 2014-04-17 12:19:23 -0700 | [diff] [blame] | 62 | public static final String ACTION_CHANGE_ACTIVE = "android.net.scoring.CHANGE_ACTIVE"; |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 63 | |
| 64 | /** |
Jeff Davidson | ee2a121 | 2014-04-17 12:19:23 -0700 | [diff] [blame] | 65 | * Extra used with {@link #ACTION_CHANGE_ACTIVE} to specify the new scorer package. Set with |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 66 | * {@link android.content.Intent#putExtra(String, String)}. |
| 67 | */ |
| 68 | public static final String EXTRA_PACKAGE_NAME = "packageName"; |
| 69 | |
| 70 | /** |
| 71 | * Broadcast action: new network scores are being requested. This intent will only be delivered |
Jeff Davidson | ee2a121 | 2014-04-17 12:19:23 -0700 | [diff] [blame] | 72 | * to the current active scorer app. That app is responsible for scoring the networks and |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 73 | * calling {@link #updateScores} when complete. The networks to score are specified in |
| 74 | * {@link #EXTRA_NETWORKS_TO_SCORE}, and will generally consist of all networks which have been |
| 75 | * configured by the user as well as any open networks. |
| 76 | * |
| 77 | * <p class="note">This is a protected intent that can only be sent by the system. |
| 78 | */ |
| 79 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 80 | public static final String ACTION_SCORE_NETWORKS = "android.net.scoring.SCORE_NETWORKS"; |
| 81 | |
| 82 | /** |
Jeff Davidson | b096bdc | 2014-07-01 12:29:11 -0700 | [diff] [blame] | 83 | * Extra used with {@link #ACTION_SCORE_NETWORKS} to specify the networks to be scored, as an |
| 84 | * array of {@link NetworkKey}s. Can be obtained with |
| 85 | * {@link android.content.Intent#getParcelableArrayExtra(String)}}. |
| 86 | */ |
| 87 | public static final String EXTRA_NETWORKS_TO_SCORE = "networksToScore"; |
| 88 | |
| 89 | /** |
Jeff Davidson | b6646a8 | 2014-06-27 16:24:42 -0700 | [diff] [blame] | 90 | * Activity action: launch a custom activity for configuring a scorer before enabling it. |
| 91 | * Scorer applications may choose to specify an activity for this action, in which case the |
| 92 | * framework will launch that activity which should return RESULT_OK if scoring was enabled. |
| 93 | * |
| 94 | * <p>If no activity is included in a scorer which implements this action, the system dialog for |
| 95 | * selecting a scorer will be shown instead. |
| 96 | */ |
| 97 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
| 98 | public static final String ACTION_CUSTOM_ENABLE = "android.net.scoring.CUSTOM_ENABLE"; |
| 99 | |
| 100 | /** |
Jeff Davidson | b096bdc | 2014-07-01 12:29:11 -0700 | [diff] [blame] | 101 | * Broadcast action: the active scorer has been changed. Scorer apps may listen to this to |
| 102 | * perform initialization once selected as the active scorer, or clean up unneeded resources |
Jeremy Joslin | da11f5c | 2016-02-10 07:31:33 -0800 | [diff] [blame] | 103 | * if another scorer has been selected. This is an explicit broadcast only sent to the |
| 104 | * previous scorer and new scorer. Note that it is unnecessary to clear existing scores as |
Jeff Davidson | b096bdc | 2014-07-01 12:29:11 -0700 | [diff] [blame] | 105 | * this is handled by the system. |
| 106 | * |
| 107 | * <p>The new scorer will be specified in {@link #EXTRA_NEW_SCORER}. |
| 108 | * |
| 109 | * <p class="note">This is a protected intent that can only be sent by the system. |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 110 | */ |
Jeff Davidson | b096bdc | 2014-07-01 12:29:11 -0700 | [diff] [blame] | 111 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 112 | public static final String ACTION_SCORER_CHANGED = "android.net.scoring.SCORER_CHANGED"; |
| 113 | |
| 114 | /** |
Jeremy Joslin | d1daf6d | 2016-11-28 17:47:35 -0800 | [diff] [blame] | 115 | * Service action: Used to discover and bind to a network recommendation provider. |
| 116 | * Implementations should return {@link NetworkRecommendationProvider#getBinder()} from |
| 117 | * their <code>onBind()</code> method. |
| 118 | */ |
| 119 | @SdkConstant(SdkConstantType.SERVICE_ACTION) |
| 120 | public static final String ACTION_RECOMMEND_NETWORKS = "android.net.action.RECOMMEND_NETWORKS"; |
| 121 | |
| 122 | /** |
Jeff Davidson | b096bdc | 2014-07-01 12:29:11 -0700 | [diff] [blame] | 123 | * Extra used with {@link #ACTION_SCORER_CHANGED} to specify the newly selected scorer's package |
| 124 | * name. Will be null if scoring was disabled. Can be obtained with |
| 125 | * {@link android.content.Intent#getStringExtra(String)}. |
| 126 | */ |
| 127 | public static final String EXTRA_NEW_SCORER = "newScorer"; |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 128 | |
Jeremy Joslin | 823db05 | 2016-11-30 15:05:40 -0800 | [diff] [blame] | 129 | /** @hide */ |
| 130 | @IntDef({CACHE_FILTER_NONE, CACHE_FILTER_CURRENT_NETWORK, CACHE_FILTER_SCAN_RESULTS}) |
| 131 | @Retention(RetentionPolicy.SOURCE) |
| 132 | public @interface CacheUpdateFilter {} |
| 133 | |
| 134 | /** |
| 135 | * Do not filter updates sent to the cache. |
| 136 | * @hide |
| 137 | */ |
| 138 | public static final int CACHE_FILTER_NONE = 0; |
| 139 | |
| 140 | /** |
| 141 | * Only send cache updates when the network matches the connected network. |
| 142 | * @hide |
| 143 | */ |
| 144 | public static final int CACHE_FILTER_CURRENT_NETWORK = 1; |
| 145 | |
| 146 | /** |
| 147 | * Only send cache updates when the network is part of the current scan result set. |
| 148 | * @hide |
| 149 | */ |
| 150 | public static final int CACHE_FILTER_SCAN_RESULTS = 2; |
| 151 | |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 152 | private final Context mContext; |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 153 | private final INetworkScoreService mService; |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 154 | |
| 155 | /** @hide */ |
| 156 | public NetworkScoreManager(Context context) { |
| 157 | mContext = context; |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 158 | IBinder iBinder = ServiceManager.getService(Context.NETWORK_SCORE_SERVICE); |
| 159 | mService = INetworkScoreService.Stub.asInterface(iBinder); |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | /** |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 163 | * Obtain the package name of the current active network scorer. |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 164 | * |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 165 | * <p>At any time, only one scorer application will receive {@link #ACTION_SCORE_NETWORKS} |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 166 | * broadcasts and be allowed to call {@link #updateScores}. Applications may use this method to |
| 167 | * determine the current scorer and offer the user the ability to select a different scorer via |
Jeff Davidson | ee2a121 | 2014-04-17 12:19:23 -0700 | [diff] [blame] | 168 | * the {@link #ACTION_CHANGE_ACTIVE} intent. |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 169 | * @return the full package name of the current active scorer, or null if there is no active |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 170 | * scorer. |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 171 | */ |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 172 | public String getActiveScorerPackage() { |
Jeremy Joslin | d7670f6 | 2017-01-10 13:08:32 -0800 | [diff] [blame] | 173 | try { |
| 174 | return mService.getActiveScorerPackage(); |
| 175 | } catch (RemoteException e) { |
| 176 | throw e.rethrowFromSystemServer(); |
Jeff Davidson | c741553 | 2014-06-23 18:15:34 -0700 | [diff] [blame] | 177 | } |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Update network scores. |
| 182 | * |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 183 | * <p>This may be called at any time to re-score active networks. Scores will generally be |
| 184 | * updated quickly, but if this method is called too frequently, the scores may be held and |
| 185 | * applied at a later time. |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 186 | * |
| 187 | * @param networks the networks which have been scored by the scorer. |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 188 | * @return whether the update was successful. |
| 189 | * @throws SecurityException if the caller is not the active scorer. |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 190 | */ |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 191 | public boolean updateScores(ScoredNetwork[] networks) throws SecurityException { |
| 192 | try { |
| 193 | return mService.updateScores(networks); |
| 194 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 195 | throw e.rethrowFromSystemServer(); |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Clear network scores. |
| 201 | * |
| 202 | * <p>Should be called when all scores need to be invalidated, i.e. because the scoring |
| 203 | * algorithm has changed and old scores can no longer be compared to future scores. |
| 204 | * |
| 205 | * <p>Note that scores will be cleared automatically when the active scorer changes, as scores |
| 206 | * from one scorer cannot be compared to those from another scorer. |
| 207 | * |
| 208 | * @return whether the clear was successful. |
| 209 | * @throws SecurityException if the caller is not the active scorer or privileged. |
| 210 | */ |
| 211 | public boolean clearScores() throws SecurityException { |
| 212 | try { |
| 213 | return mService.clearScores(); |
| 214 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 215 | throw e.rethrowFromSystemServer(); |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Set the active scorer to a new package and clear existing scores. |
| 221 | * |
Jeff Davidson | e56f2bb | 2014-11-05 11:14:19 -0800 | [diff] [blame] | 222 | * <p>Should never be called directly without obtaining user consent. This can be done by using |
| 223 | * the {@link #ACTION_CHANGE_ACTIVE} broadcast, or using a custom configuration activity. |
| 224 | * |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 225 | * @return true if the operation succeeded, or false if the new package is not a valid scorer. |
| 226 | * @throws SecurityException if the caller does not hold the |
Jeff Davidson | e56f2bb | 2014-11-05 11:14:19 -0800 | [diff] [blame] | 227 | * {@link android.Manifest.permission#SCORE_NETWORKS} permission. |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 228 | * @hide |
| 229 | */ |
Jeff Davidson | e56f2bb | 2014-11-05 11:14:19 -0800 | [diff] [blame] | 230 | @SystemApi |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 231 | public boolean setActiveScorer(String packageName) throws SecurityException { |
| 232 | try { |
| 233 | return mService.setActiveScorer(packageName); |
| 234 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 235 | throw e.rethrowFromSystemServer(); |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 236 | } |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 237 | } |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 238 | |
| 239 | /** |
Jeff Davidson | 26fd143 | 2014-07-29 09:39:52 -0700 | [diff] [blame] | 240 | * Turn off network scoring. |
| 241 | * |
| 242 | * <p>May only be called by the current scorer app, or the system. |
| 243 | * |
| 244 | * @throws SecurityException if the caller is neither the active scorer nor the system. |
| 245 | */ |
| 246 | public void disableScoring() throws SecurityException { |
| 247 | try { |
| 248 | mService.disableScoring(); |
| 249 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 250 | throw e.rethrowFromSystemServer(); |
Jeff Davidson | 26fd143 | 2014-07-29 09:39:52 -0700 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
| 254 | /** |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 255 | * Request scoring for networks. |
| 256 | * |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 257 | * @return true if the broadcast was sent, or false if there is no active scorer. |
| 258 | * @throws SecurityException if the caller does not hold the |
Jeremy Joslin | 186f333 | 2017-01-06 14:36:54 -0800 | [diff] [blame] | 259 | * {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission. |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 260 | * @hide |
| 261 | */ |
| 262 | public boolean requestScores(NetworkKey[] networks) throws SecurityException { |
Jeremy Joslin | 36d4c48 | 2016-12-09 13:11:51 -0800 | [diff] [blame] | 263 | try { |
| 264 | return mService.requestScores(networks); |
| 265 | } catch (RemoteException e) { |
| 266 | throw e.rethrowFromSystemServer(); |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 267 | } |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Register a network score cache. |
| 272 | * |
| 273 | * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}. |
| 274 | * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores. |
| 275 | * @throws SecurityException if the caller does not hold the |
Jeremy Joslin | 186f333 | 2017-01-06 14:36:54 -0800 | [diff] [blame] | 276 | * {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission. |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 277 | * @throws IllegalArgumentException if a score cache is already registered for this type. |
Jeremy Joslin | 823db05 | 2016-11-30 15:05:40 -0800 | [diff] [blame] | 278 | * @deprecated equivalent to registering for cache updates with CACHE_FILTER_NONE. |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 279 | * @hide |
| 280 | */ |
Jeremy Joslin | 823db05 | 2016-11-30 15:05:40 -0800 | [diff] [blame] | 281 | @Deprecated // migrate to registerNetworkScoreCache(int, INetworkScoreCache, int) |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 282 | public void registerNetworkScoreCache(int networkType, INetworkScoreCache scoreCache) { |
Jeremy Joslin | 823db05 | 2016-11-30 15:05:40 -0800 | [diff] [blame] | 283 | registerNetworkScoreCache(networkType, scoreCache, CACHE_FILTER_NONE); |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * Register a network score cache. |
| 288 | * |
| 289 | * @param networkType the type of network this cache can handle. See {@link NetworkKey#type} |
| 290 | * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores |
| 291 | * @param filterType the {@link CacheUpdateFilter} to apply |
| 292 | * @throws SecurityException if the caller does not hold the |
Jeremy Joslin | 186f333 | 2017-01-06 14:36:54 -0800 | [diff] [blame] | 293 | * {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission. |
Jeremy Joslin | 823db05 | 2016-11-30 15:05:40 -0800 | [diff] [blame] | 294 | * @throws IllegalArgumentException if a score cache is already registered for this type. |
| 295 | * @hide |
| 296 | */ |
| 297 | public void registerNetworkScoreCache(int networkType, INetworkScoreCache scoreCache, |
| 298 | @CacheUpdateFilter int filterType) { |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 299 | try { |
Jeremy Joslin | 823db05 | 2016-11-30 15:05:40 -0800 | [diff] [blame] | 300 | mService.registerNetworkScoreCache(networkType, scoreCache, filterType); |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 301 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 302 | throw e.rethrowFromSystemServer(); |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 303 | } |
| 304 | } |
Jeremy Joslin | d1daf6d | 2016-11-28 17:47:35 -0800 | [diff] [blame] | 305 | |
| 306 | /** |
Amin Shaikh | 972e236 | 2016-12-07 14:08:09 -0800 | [diff] [blame] | 307 | * Unregister a network score cache. |
| 308 | * |
| 309 | * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}. |
| 310 | * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores. |
| 311 | * @throws SecurityException if the caller does not hold the |
Jeremy Joslin | 186f333 | 2017-01-06 14:36:54 -0800 | [diff] [blame] | 312 | * {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission. |
Amin Shaikh | 972e236 | 2016-12-07 14:08:09 -0800 | [diff] [blame] | 313 | * @throws IllegalArgumentException if a score cache is already registered for this type. |
| 314 | * @hide |
| 315 | */ |
| 316 | public void unregisterNetworkScoreCache(int networkType, INetworkScoreCache scoreCache) { |
| 317 | try { |
| 318 | mService.unregisterNetworkScoreCache(networkType, scoreCache); |
| 319 | } catch (RemoteException e) { |
| 320 | throw e.rethrowFromSystemServer(); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | /** |
Jeremy Joslin | d1daf6d | 2016-11-28 17:47:35 -0800 | [diff] [blame] | 325 | * Request a recommendation for which network to connect to. |
| 326 | * |
Jeremy Joslin | 36d4c48 | 2016-12-09 13:11:51 -0800 | [diff] [blame] | 327 | * <p>It is not safe to call this method from the main thread. |
| 328 | * |
Jeremy Joslin | d1daf6d | 2016-11-28 17:47:35 -0800 | [diff] [blame] | 329 | * @param request a {@link RecommendationRequest} instance containing additional |
| 330 | * request details |
| 331 | * @return a {@link RecommendationResult} instance containing the recommended network |
| 332 | * to connect to |
Jeremy Joslin | 186f333 | 2017-01-06 14:36:54 -0800 | [diff] [blame] | 333 | * @throws SecurityException if the caller does not hold the |
| 334 | * {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission. |
Jeremy Joslin | d1daf6d | 2016-11-28 17:47:35 -0800 | [diff] [blame] | 335 | */ |
| 336 | public RecommendationResult requestRecommendation(RecommendationRequest request) |
| 337 | throws SecurityException { |
| 338 | try { |
| 339 | return mService.requestRecommendation(request); |
| 340 | } catch (RemoteException e) { |
| 341 | throw e.rethrowFromSystemServer(); |
| 342 | } |
| 343 | } |
Jeremy Joslin | 9b442fa | 2017-01-09 16:22:20 -0800 | [diff] [blame] | 344 | |
| 345 | /** |
| 346 | * Determine whether the application with the given UID is the enabled scorer. |
| 347 | * |
| 348 | * @param callingUid the UID to check |
| 349 | * @return true if the provided UID is the active scorer, false otherwise. |
| 350 | * @hide |
| 351 | */ |
| 352 | public boolean isCallerActiveScorer(int callingUid) { |
| 353 | try { |
| 354 | return mService.isCallerActiveScorer(callingUid); |
| 355 | } catch (RemoteException e) { |
| 356 | throw e.rethrowFromSystemServer(); |
| 357 | } |
| 358 | } |
Jeff Davidson | b51e0a6 | 2014-04-09 12:38:15 -0700 | [diff] [blame] | 359 | } |