Loading core/java/android/net/NetworkScoreManager.java +8 −0 Original line number Diff line number Diff line Loading @@ -119,6 +119,14 @@ public class NetworkScoreManager { public static final String USE_OPEN_WIFI_PACKAGE_META_DATA = "android.net.wifi.use_open_wifi_package"; /** * Meta-data specified on a {@link NetworkRecommendationProvider} that specifies the * {@link android.app.NotificationChannel} ID used to post open network notifications. * @hide */ public static final String NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID_META_DATA = "android.net.wifi.notification_channel_id_network_available"; /** * Broadcast action: the active scorer has been changed. Scorer apps may listen to this to * perform initialization once selected as the active scorer, or clean up unneeded resources Loading core/java/android/net/NetworkScorerAppData.java +21 −3 Original line number Diff line number Diff line Loading @@ -23,13 +23,20 @@ public final class NetworkScorerAppData implements Parcelable { * wifi networks automatically" feature. */ private final ComponentName mEnableUseOpenWifiActivity; /** * The {@link android.app.NotificationChannel} ID used by {@link #mRecommendationService} to * post open network notifications. */ private final String mNetworkAvailableNotificationChannelId; public NetworkScorerAppData(int packageUid, ComponentName recommendationServiceComp, String recommendationServiceLabel, ComponentName enableUseOpenWifiActivity) { String recommendationServiceLabel, ComponentName enableUseOpenWifiActivity, String networkAvailableNotificationChannelId) { this.packageUid = packageUid; this.mRecommendationService = recommendationServiceComp; this.mRecommendationServiceLabel = recommendationServiceLabel; this.mEnableUseOpenWifiActivity = enableUseOpenWifiActivity; this.mNetworkAvailableNotificationChannelId = networkAvailableNotificationChannelId; } protected NetworkScorerAppData(Parcel in) { Loading @@ -37,6 +44,7 @@ public final class NetworkScorerAppData implements Parcelable { mRecommendationService = ComponentName.readFromParcel(in); mRecommendationServiceLabel = in.readString(); mEnableUseOpenWifiActivity = ComponentName.readFromParcel(in); mNetworkAvailableNotificationChannelId = in.readString(); } @Override Loading @@ -45,6 +53,7 @@ public final class NetworkScorerAppData implements Parcelable { ComponentName.writeToParcel(mRecommendationService, dest); dest.writeString(mRecommendationServiceLabel); ComponentName.writeToParcel(mEnableUseOpenWifiActivity, dest); dest.writeString(mNetworkAvailableNotificationChannelId); } @Override Loading Loading @@ -83,6 +92,11 @@ public final class NetworkScorerAppData implements Parcelable { return mRecommendationServiceLabel; } @Nullable public String getNetworkAvailableNotificationChannelId() { return mNetworkAvailableNotificationChannelId; } @Override public String toString() { return "NetworkScorerAppData{" + Loading @@ -90,6 +104,8 @@ public final class NetworkScorerAppData implements Parcelable { ", mRecommendationService=" + mRecommendationService + ", mRecommendationServiceLabel=" + mRecommendationServiceLabel + ", mEnableUseOpenWifiActivity=" + mEnableUseOpenWifiActivity + ", mNetworkAvailableNotificationChannelId=" + mNetworkAvailableNotificationChannelId + '}'; } Loading @@ -101,12 +117,14 @@ public final class NetworkScorerAppData implements Parcelable { return packageUid == that.packageUid && Objects.equals(mRecommendationService, that.mRecommendationService) && Objects.equals(mRecommendationServiceLabel, that.mRecommendationServiceLabel) && Objects.equals(mEnableUseOpenWifiActivity, that.mEnableUseOpenWifiActivity); Objects.equals(mEnableUseOpenWifiActivity, that.mEnableUseOpenWifiActivity) && Objects.equals(mNetworkAvailableNotificationChannelId, that.mNetworkAvailableNotificationChannelId); } @Override public int hashCode() { return Objects.hash(packageUid, mRecommendationService, mRecommendationServiceLabel, mEnableUseOpenWifiActivity); mEnableUseOpenWifiActivity, mNetworkAvailableNotificationChannelId); } } services/core/java/com/android/server/NetworkScorerAppManager.java +18 −1 Original line number Diff line number Diff line Loading @@ -88,9 +88,12 @@ public class NetworkScorerAppManager { final String serviceLabel = getRecommendationServiceLabel(serviceInfo, pm); final ComponentName useOpenWifiNetworksActivity = findUseOpenWifiNetworksActivity(serviceInfo); final String networkAvailableNotificationChannelId = getNetworkAvailableNotificationChannelId(serviceInfo); appDataList.add( new NetworkScorerAppData(serviceInfo.applicationInfo.uid, serviceComponentName, serviceLabel, useOpenWifiNetworksActivity)); serviceComponentName, serviceLabel, useOpenWifiNetworksActivity, networkAvailableNotificationChannelId)); } else { if (VERBOSE) Log.v(TAG, serviceInfo.packageName + " is NOT a valid scorer/recommender."); Loading Loading @@ -145,6 +148,20 @@ public class NetworkScorerAppManager { return null; } @Nullable private static String getNetworkAvailableNotificationChannelId(ServiceInfo serviceInfo) { if (serviceInfo.metaData == null) { if (DEBUG) { Log.d(TAG, "No metadata found on " + serviceInfo.getComponentName()); } return null; } return serviceInfo.metaData.getString( NetworkScoreManager.NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID_META_DATA); } /** * Get the application to use for scoring networks. * Loading services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java +5 −3 Original line number Diff line number Diff line Loading @@ -128,9 +128,11 @@ public class NetworkScoreServiceTest { private static final ScoredNetwork SCORED_NETWORK_2 = new ScoredNetwork(new NetworkKey(new WifiKey(quote(SSID_2), "00:00:00:00:00:00")), null /* rssiCurve*/); private static final String NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID = "networkAvailableNotificationChannelId"; private static final NetworkScorerAppData NEW_SCORER = new NetworkScorerAppData( 1, RECOMMENDATION_SERVICE_COMP, RECOMMENDATION_SERVICE_LABEL, USE_WIFI_ENABLE_ACTIVITY_COMP); USE_WIFI_ENABLE_ACTIVITY_COMP, NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID); @Mock private NetworkScorerAppManager mNetworkScorerAppManager; @Mock private Context mContext; Loading Loading @@ -965,7 +967,7 @@ public class NetworkScoreServiceTest { .thenReturn(PackageManager.PERMISSION_GRANTED); NetworkScorerAppData expectedAppData = new NetworkScorerAppData(Binder.getCallingUid(), RECOMMENDATION_SERVICE_COMP, RECOMMENDATION_SERVICE_LABEL, USE_WIFI_ENABLE_ACTIVITY_COMP); USE_WIFI_ENABLE_ACTIVITY_COMP, NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID); bindToScorer(expectedAppData); assertEquals(expectedAppData, mNetworkScoreService.getActiveScorer()); } Loading Loading @@ -1007,7 +1009,7 @@ public class NetworkScoreServiceTest { final int callingUid = callerIsScorer ? Binder.getCallingUid() : Binder.getCallingUid() + 1; NetworkScorerAppData appData = new NetworkScorerAppData(callingUid, RECOMMENDATION_SERVICE_COMP, RECOMMENDATION_SERVICE_LABEL, USE_WIFI_ENABLE_ACTIVITY_COMP); USE_WIFI_ENABLE_ACTIVITY_COMP, NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID); bindToScorer(appData); } Loading services/tests/servicestests/src/com/android/server/NetworkScorerAppManagerTest.java +35 −1 Original line number Diff line number Diff line Loading @@ -62,6 +62,8 @@ import java.util.List; public class NetworkScorerAppManagerTest { private static String MOCK_SERVICE_LABEL = "Mock Service"; private static String MOCK_OVERRIDEN_SERVICE_LABEL = "Mock Service Label Override"; private static String MOCK_NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID = "Mock Network Available Notification Channel Id"; @Mock private Context mMockContext; @Mock private PackageManager mMockPm; Loading Loading @@ -168,13 +170,30 @@ public class NetworkScorerAppManagerTest { mockScoreNetworksGranted(recoComponent.getPackageName()); mockRecommendationServiceAvailable(recoComponent, 924 /* packageUid */, enableUseOpenWifiComponent.getPackageName()); mockEnableUseOpenWifiActivity(enableUseOpenWifiComponent); final NetworkScorerAppData activeScorer = mNetworkScorerAppManager.getActiveScorer(); assertNotNull(activeScorer); assertEquals(recoComponent, activeScorer.getRecommendationServiceComponent()); assertEquals(924, activeScorer.packageUid); assertEquals(enableUseOpenWifiComponent, activeScorer.getEnableUseOpenWifiActivity()); assertNull(activeScorer.getNetworkAvailableNotificationChannelId()); } @Test public void testGetActiveScorer_providerAvailable_networkAvailableNotificationChannelIdSet() { final ComponentName recoComponent = new ComponentName("package1", "class1"); setNetworkRecoPackageSetting(recoComponent.getPackageName()); mockScoreNetworksGranted(recoComponent.getPackageName()); mockRecommendationServiceAvailable(recoComponent, 924 /* packageUid */, null /* enableUseOpenWifiActivityPackage */, false /* serviceLabelOverride */, true /* setNotificationChannelId */); final NetworkScorerAppData activeScorer = mNetworkScorerAppManager.getActiveScorer(); assertNotNull(activeScorer); assertEquals(recoComponent, activeScorer.getRecommendationServiceComponent()); assertEquals(924, activeScorer.packageUid); assertEquals(MOCK_NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID, activeScorer.getNetworkAvailableNotificationChannelId()); } @Test Loading Loading @@ -368,6 +387,13 @@ public class NetworkScorerAppManagerTest { private void mockRecommendationServiceAvailable(final ComponentName compName, int packageUid, String enableUseOpenWifiActivityPackage, boolean serviceLabelOverride) { mockRecommendationServiceAvailable(compName, packageUid, enableUseOpenWifiActivityPackage, serviceLabelOverride, false); } private void mockRecommendationServiceAvailable(final ComponentName compName, int packageUid, String enableUseOpenWifiActivityPackage, boolean serviceLabelOverride, boolean setNotificationChannel) { final ResolveInfo serviceInfo = new ResolveInfo(); serviceInfo.serviceInfo = new ServiceInfo(); serviceInfo.serviceInfo.name = compName.getClassName(); Loading @@ -390,6 +416,14 @@ public class NetworkScorerAppManagerTest { } else { serviceInfo.serviceInfo.nonLocalizedLabel = MOCK_SERVICE_LABEL; } if (setNotificationChannel) { if (serviceInfo.serviceInfo.metaData == null) { serviceInfo.serviceInfo.metaData = new Bundle(); } serviceInfo.serviceInfo.metaData.putString( NetworkScoreManager.NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID_META_DATA, MOCK_NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID); } final int flags = PackageManager.GET_META_DATA; when(mMockPm.resolveService( Loading Loading
core/java/android/net/NetworkScoreManager.java +8 −0 Original line number Diff line number Diff line Loading @@ -119,6 +119,14 @@ public class NetworkScoreManager { public static final String USE_OPEN_WIFI_PACKAGE_META_DATA = "android.net.wifi.use_open_wifi_package"; /** * Meta-data specified on a {@link NetworkRecommendationProvider} that specifies the * {@link android.app.NotificationChannel} ID used to post open network notifications. * @hide */ public static final String NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID_META_DATA = "android.net.wifi.notification_channel_id_network_available"; /** * Broadcast action: the active scorer has been changed. Scorer apps may listen to this to * perform initialization once selected as the active scorer, or clean up unneeded resources Loading
core/java/android/net/NetworkScorerAppData.java +21 −3 Original line number Diff line number Diff line Loading @@ -23,13 +23,20 @@ public final class NetworkScorerAppData implements Parcelable { * wifi networks automatically" feature. */ private final ComponentName mEnableUseOpenWifiActivity; /** * The {@link android.app.NotificationChannel} ID used by {@link #mRecommendationService} to * post open network notifications. */ private final String mNetworkAvailableNotificationChannelId; public NetworkScorerAppData(int packageUid, ComponentName recommendationServiceComp, String recommendationServiceLabel, ComponentName enableUseOpenWifiActivity) { String recommendationServiceLabel, ComponentName enableUseOpenWifiActivity, String networkAvailableNotificationChannelId) { this.packageUid = packageUid; this.mRecommendationService = recommendationServiceComp; this.mRecommendationServiceLabel = recommendationServiceLabel; this.mEnableUseOpenWifiActivity = enableUseOpenWifiActivity; this.mNetworkAvailableNotificationChannelId = networkAvailableNotificationChannelId; } protected NetworkScorerAppData(Parcel in) { Loading @@ -37,6 +44,7 @@ public final class NetworkScorerAppData implements Parcelable { mRecommendationService = ComponentName.readFromParcel(in); mRecommendationServiceLabel = in.readString(); mEnableUseOpenWifiActivity = ComponentName.readFromParcel(in); mNetworkAvailableNotificationChannelId = in.readString(); } @Override Loading @@ -45,6 +53,7 @@ public final class NetworkScorerAppData implements Parcelable { ComponentName.writeToParcel(mRecommendationService, dest); dest.writeString(mRecommendationServiceLabel); ComponentName.writeToParcel(mEnableUseOpenWifiActivity, dest); dest.writeString(mNetworkAvailableNotificationChannelId); } @Override Loading Loading @@ -83,6 +92,11 @@ public final class NetworkScorerAppData implements Parcelable { return mRecommendationServiceLabel; } @Nullable public String getNetworkAvailableNotificationChannelId() { return mNetworkAvailableNotificationChannelId; } @Override public String toString() { return "NetworkScorerAppData{" + Loading @@ -90,6 +104,8 @@ public final class NetworkScorerAppData implements Parcelable { ", mRecommendationService=" + mRecommendationService + ", mRecommendationServiceLabel=" + mRecommendationServiceLabel + ", mEnableUseOpenWifiActivity=" + mEnableUseOpenWifiActivity + ", mNetworkAvailableNotificationChannelId=" + mNetworkAvailableNotificationChannelId + '}'; } Loading @@ -101,12 +117,14 @@ public final class NetworkScorerAppData implements Parcelable { return packageUid == that.packageUid && Objects.equals(mRecommendationService, that.mRecommendationService) && Objects.equals(mRecommendationServiceLabel, that.mRecommendationServiceLabel) && Objects.equals(mEnableUseOpenWifiActivity, that.mEnableUseOpenWifiActivity); Objects.equals(mEnableUseOpenWifiActivity, that.mEnableUseOpenWifiActivity) && Objects.equals(mNetworkAvailableNotificationChannelId, that.mNetworkAvailableNotificationChannelId); } @Override public int hashCode() { return Objects.hash(packageUid, mRecommendationService, mRecommendationServiceLabel, mEnableUseOpenWifiActivity); mEnableUseOpenWifiActivity, mNetworkAvailableNotificationChannelId); } }
services/core/java/com/android/server/NetworkScorerAppManager.java +18 −1 Original line number Diff line number Diff line Loading @@ -88,9 +88,12 @@ public class NetworkScorerAppManager { final String serviceLabel = getRecommendationServiceLabel(serviceInfo, pm); final ComponentName useOpenWifiNetworksActivity = findUseOpenWifiNetworksActivity(serviceInfo); final String networkAvailableNotificationChannelId = getNetworkAvailableNotificationChannelId(serviceInfo); appDataList.add( new NetworkScorerAppData(serviceInfo.applicationInfo.uid, serviceComponentName, serviceLabel, useOpenWifiNetworksActivity)); serviceComponentName, serviceLabel, useOpenWifiNetworksActivity, networkAvailableNotificationChannelId)); } else { if (VERBOSE) Log.v(TAG, serviceInfo.packageName + " is NOT a valid scorer/recommender."); Loading Loading @@ -145,6 +148,20 @@ public class NetworkScorerAppManager { return null; } @Nullable private static String getNetworkAvailableNotificationChannelId(ServiceInfo serviceInfo) { if (serviceInfo.metaData == null) { if (DEBUG) { Log.d(TAG, "No metadata found on " + serviceInfo.getComponentName()); } return null; } return serviceInfo.metaData.getString( NetworkScoreManager.NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID_META_DATA); } /** * Get the application to use for scoring networks. * Loading
services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java +5 −3 Original line number Diff line number Diff line Loading @@ -128,9 +128,11 @@ public class NetworkScoreServiceTest { private static final ScoredNetwork SCORED_NETWORK_2 = new ScoredNetwork(new NetworkKey(new WifiKey(quote(SSID_2), "00:00:00:00:00:00")), null /* rssiCurve*/); private static final String NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID = "networkAvailableNotificationChannelId"; private static final NetworkScorerAppData NEW_SCORER = new NetworkScorerAppData( 1, RECOMMENDATION_SERVICE_COMP, RECOMMENDATION_SERVICE_LABEL, USE_WIFI_ENABLE_ACTIVITY_COMP); USE_WIFI_ENABLE_ACTIVITY_COMP, NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID); @Mock private NetworkScorerAppManager mNetworkScorerAppManager; @Mock private Context mContext; Loading Loading @@ -965,7 +967,7 @@ public class NetworkScoreServiceTest { .thenReturn(PackageManager.PERMISSION_GRANTED); NetworkScorerAppData expectedAppData = new NetworkScorerAppData(Binder.getCallingUid(), RECOMMENDATION_SERVICE_COMP, RECOMMENDATION_SERVICE_LABEL, USE_WIFI_ENABLE_ACTIVITY_COMP); USE_WIFI_ENABLE_ACTIVITY_COMP, NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID); bindToScorer(expectedAppData); assertEquals(expectedAppData, mNetworkScoreService.getActiveScorer()); } Loading Loading @@ -1007,7 +1009,7 @@ public class NetworkScoreServiceTest { final int callingUid = callerIsScorer ? Binder.getCallingUid() : Binder.getCallingUid() + 1; NetworkScorerAppData appData = new NetworkScorerAppData(callingUid, RECOMMENDATION_SERVICE_COMP, RECOMMENDATION_SERVICE_LABEL, USE_WIFI_ENABLE_ACTIVITY_COMP); USE_WIFI_ENABLE_ACTIVITY_COMP, NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID); bindToScorer(appData); } Loading
services/tests/servicestests/src/com/android/server/NetworkScorerAppManagerTest.java +35 −1 Original line number Diff line number Diff line Loading @@ -62,6 +62,8 @@ import java.util.List; public class NetworkScorerAppManagerTest { private static String MOCK_SERVICE_LABEL = "Mock Service"; private static String MOCK_OVERRIDEN_SERVICE_LABEL = "Mock Service Label Override"; private static String MOCK_NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID = "Mock Network Available Notification Channel Id"; @Mock private Context mMockContext; @Mock private PackageManager mMockPm; Loading Loading @@ -168,13 +170,30 @@ public class NetworkScorerAppManagerTest { mockScoreNetworksGranted(recoComponent.getPackageName()); mockRecommendationServiceAvailable(recoComponent, 924 /* packageUid */, enableUseOpenWifiComponent.getPackageName()); mockEnableUseOpenWifiActivity(enableUseOpenWifiComponent); final NetworkScorerAppData activeScorer = mNetworkScorerAppManager.getActiveScorer(); assertNotNull(activeScorer); assertEquals(recoComponent, activeScorer.getRecommendationServiceComponent()); assertEquals(924, activeScorer.packageUid); assertEquals(enableUseOpenWifiComponent, activeScorer.getEnableUseOpenWifiActivity()); assertNull(activeScorer.getNetworkAvailableNotificationChannelId()); } @Test public void testGetActiveScorer_providerAvailable_networkAvailableNotificationChannelIdSet() { final ComponentName recoComponent = new ComponentName("package1", "class1"); setNetworkRecoPackageSetting(recoComponent.getPackageName()); mockScoreNetworksGranted(recoComponent.getPackageName()); mockRecommendationServiceAvailable(recoComponent, 924 /* packageUid */, null /* enableUseOpenWifiActivityPackage */, false /* serviceLabelOverride */, true /* setNotificationChannelId */); final NetworkScorerAppData activeScorer = mNetworkScorerAppManager.getActiveScorer(); assertNotNull(activeScorer); assertEquals(recoComponent, activeScorer.getRecommendationServiceComponent()); assertEquals(924, activeScorer.packageUid); assertEquals(MOCK_NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID, activeScorer.getNetworkAvailableNotificationChannelId()); } @Test Loading Loading @@ -368,6 +387,13 @@ public class NetworkScorerAppManagerTest { private void mockRecommendationServiceAvailable(final ComponentName compName, int packageUid, String enableUseOpenWifiActivityPackage, boolean serviceLabelOverride) { mockRecommendationServiceAvailable(compName, packageUid, enableUseOpenWifiActivityPackage, serviceLabelOverride, false); } private void mockRecommendationServiceAvailable(final ComponentName compName, int packageUid, String enableUseOpenWifiActivityPackage, boolean serviceLabelOverride, boolean setNotificationChannel) { final ResolveInfo serviceInfo = new ResolveInfo(); serviceInfo.serviceInfo = new ServiceInfo(); serviceInfo.serviceInfo.name = compName.getClassName(); Loading @@ -390,6 +416,14 @@ public class NetworkScorerAppManagerTest { } else { serviceInfo.serviceInfo.nonLocalizedLabel = MOCK_SERVICE_LABEL; } if (setNotificationChannel) { if (serviceInfo.serviceInfo.metaData == null) { serviceInfo.serviceInfo.metaData = new Bundle(); } serviceInfo.serviceInfo.metaData.putString( NetworkScoreManager.NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID_META_DATA, MOCK_NETWORK_AVAILABLE_NOTIFICATION_CHANNEL_ID); } final int flags = PackageManager.GET_META_DATA; when(mMockPm.resolveService( Loading