Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -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 | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 19 | import android.net.INetworkScoreCache; |
Jeremy Joslin | b2087a1 | 2016-12-13 16:11:51 -0800 | [diff] [blame] | 20 | import android.net.NetworkKey; |
Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 21 | import android.net.NetworkScorerAppData; |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 22 | import android.net.ScoredNetwork; |
| 23 | |
| 24 | /** |
| 25 | * A service for updating network scores from a network scorer application. |
| 26 | * @hide |
| 27 | */ |
| 28 | interface INetworkScoreService |
| 29 | { |
| 30 | /** |
| 31 | * Update scores. |
| 32 | * @return whether the update was successful. |
| 33 | * @throws SecurityException if the caller is not the current active scorer. |
| 34 | */ |
| 35 | boolean updateScores(in ScoredNetwork[] networks); |
| 36 | |
| 37 | /** |
| 38 | * Clear all scores. |
| 39 | * @return whether the clear was successful. |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 40 | * @throws SecurityException if the caller is neither the current active scorer nor the system. |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 41 | */ |
| 42 | boolean clearScores(); |
| 43 | |
| 44 | /** |
| 45 | * Set the active scorer and clear existing scores. |
| 46 | * @param packageName the package name of the new scorer to use. |
| 47 | * @return true if the operation succeeded, or false if the new package is not a valid scorer. |
Jeremy Joslin | a9f933e | 2017-04-28 13:08:17 -0700 | [diff] [blame] | 48 | * @throws SecurityException if the caller is not the system or a network scorer. |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 49 | */ |
| 50 | boolean setActiveScorer(in String packageName); |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
Jeff Davidson | 26fd143 | 2014-07-29 09:39:52 -0700 | [diff] [blame] | 53 | * Disable the current active scorer and clear existing scores. |
| 54 | * @throws SecurityException if the caller is not the current scorer or the system. |
| 55 | */ |
| 56 | void disableScoring(); |
| 57 | |
| 58 | /** |
Amin Shaikh | 972e236 | 2016-12-07 14:08:09 -0800 | [diff] [blame] | 59 | * Register a cache to receive scoring updates. |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 60 | * |
Jeremy Joslin | c5ac587 | 2016-11-30 15:05:40 -0800 | [diff] [blame] | 61 | * @param networkType the type of network this cache can handle. See {@link NetworkKey#type} |
| 62 | * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores |
| 63 | * @param filterType the {@link CacheUpdateFilter} to apply |
| 64 | * @throws SecurityException if the caller is not the system |
| 65 | * @throws IllegalArgumentException if a score cache is already registed for this type |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 66 | * @hide |
| 67 | */ |
Jeremy Joslin | c5ac587 | 2016-11-30 15:05:40 -0800 | [diff] [blame] | 68 | void registerNetworkScoreCache(int networkType, INetworkScoreCache scoreCache, int filterType); |
Jeff Davidson | 14f1ec0 | 2014-04-29 11:58:26 -0700 | [diff] [blame] | 69 | |
Jeremy Joslin | d1daf6d | 2016-11-28 17:47:35 -0800 | [diff] [blame] | 70 | /** |
Amin Shaikh | 972e236 | 2016-12-07 14:08:09 -0800 | [diff] [blame] | 71 | * Unregister a cache to receive scoring updates. |
| 72 | * |
| 73 | * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}. |
| 74 | * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores. |
| 75 | * @throws SecurityException if the caller is not the system. |
| 76 | * @hide |
| 77 | */ |
| 78 | void unregisterNetworkScoreCache(int networkType, INetworkScoreCache scoreCache); |
| 79 | |
| 80 | /** |
Jeremy Joslin | b2087a1 | 2016-12-13 16:11:51 -0800 | [diff] [blame] | 81 | * Request scoring for networks. |
| 82 | * |
| 83 | * Implementations should delegate to the registered network recommendation provider or |
| 84 | * fulfill the request locally if possible. |
| 85 | * |
| 86 | * @param networks an array of {@link NetworkKey}s to score |
| 87 | * @return true if the request was delegated or fulfilled locally, false otherwise |
| 88 | * @throws SecurityException if the caller is not the system |
| 89 | * @hide |
| 90 | */ |
| 91 | boolean requestScores(in NetworkKey[] networks); |
Jeremy Joslin | 134c9d3 | 2017-01-09 16:22:20 -0800 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * Determine whether the application with the given UID is the enabled scorer. |
| 95 | * |
| 96 | * @param callingUid the UID to check |
| 97 | * @return true if the provided UID is the active scorer, false otherwise. |
| 98 | * @hide |
| 99 | */ |
| 100 | boolean isCallerActiveScorer(int callingUid); |
Jeremy Joslin | 6c1ca28 | 2017-01-10 13:08:32 -0800 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Obtain the package name of the current active network scorer. |
| 104 | * |
| 105 | * @return the full package name of the current active scorer, or null if there is no active |
| 106 | * scorer. |
| 107 | */ |
| 108 | String getActiveScorerPackage(); |
Jeremy Joslin | a5172f6 | 2017-02-02 14:27:05 -0800 | [diff] [blame] | 109 | |
Jeremy Joslin | f95c865 | 2017-02-09 15:32:04 -0800 | [diff] [blame] | 110 | /** |
| 111 | * Returns metadata about the active scorer or <code>null</code> if there is no active scorer. |
| 112 | */ |
Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 113 | NetworkScorerAppData getActiveScorer(); |
Jeremy Joslin | f95c865 | 2017-02-09 15:32:04 -0800 | [diff] [blame] | 114 | |
| 115 | /** |
| 116 | * Returns the list of available scorer apps. The list will be empty if there are |
| 117 | * no valid scorers. |
| 118 | */ |
Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 119 | List<NetworkScorerAppData> getAllValidScorers(); |
Jeff Davidson | 6a4b220 | 2014-04-16 17:29:40 -0700 | [diff] [blame] | 120 | } |