Loading src/com/android/networkstack/NetworkStackNotifier.java +20 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.networkstack; import static android.app.NotificationManager.IMPORTANCE_NONE; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; Loading Loading @@ -142,7 +144,19 @@ public class NetworkStackNotifier { resources.getString(title), importance); channel.setDescription(resources.getString(description)); mNotificationManager.createNotificationChannel(channel); getNotificationManagerForChannels().createNotificationChannel(channel); } /** * Get the NotificationManager to use to query channels, as opposed to posting notifications. * * Although notifications are posted as USER_ALL, notification channels are always created * based on the UID calling NotificationManager, regardless of the context UserHandle. * When querying notification channels, using a USER_ALL context would return no channel: the * default context (as UserHandle 0 for NetworkStack) must be used. */ private NotificationManager getNotificationManagerForChannels() { return mContext.getSystemService(NotificationManager.class); } /** Loading Loading @@ -284,7 +298,11 @@ public class NetworkStackNotifier { } private boolean isVenueInfoNotificationEnabled() { return mNotificationManager.getNotificationChannel(CHANNEL_VENUE_INFO) != null; final NotificationChannel channel = getNotificationManagerForChannels() .getNotificationChannel(CHANNEL_VENUE_INFO); if (channel == null) return false; return channel.getImportance() != IMPORTANCE_NONE; } private static String getNotificationTag(@NonNull Network network) { Loading src/com/android/networkstack/metrics/DataStallDetectionStats.java +5 −3 Original line number Diff line number Diff line Loading @@ -261,11 +261,13 @@ public final class DataStallDetectionStats { if (info == null) return DataStallEventProto.AP_BAND_UNKNOWN; int freq = info.getFrequency(); // Refer to ScanResult.is5GHz() and ScanResult.is24GHz(). if (freq > 4900 && freq < 5900) { // Refer to ScanResult.is5GHz(), ScanResult.is24GHz() and ScanResult.is6GHz(). if (freq >= 5160 && freq <= 5865) { return DataStallEventProto.AP_BAND_5GHZ; } else if (freq > 2400 && freq < 2500) { } else if (freq >= 2412 && freq <= 2484) { return DataStallEventProto.AP_BAND_2GHZ; } else if (freq >= 5945 && freq <= 7105) { return DataStallEventProto.AP_BAND_6GHZ; } else { return DataStallEventProto.AP_BAND_UNKNOWN; } Loading src/com/android/server/connectivity/NetworkMonitor.java +1 −0 Original line number Diff line number Diff line Loading @@ -1731,6 +1731,7 @@ public class NetworkMonitor extends StateMachine { } try { final List<CellInfo> cells = mTelephonyManager.getAllCellInfo(); if (cells == null) return null; final Map<String, Integer> countryCodeMap = new HashMap<>(); int maxCount = 0; for (final CellInfo cell : cells) { Loading tests/unit/src/com/android/networkstack/NetworkStackNotifierTest.kt +8 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.app.Notification import android.app.NotificationChannel import android.app.NotificationManager import android.app.NotificationManager.IMPORTANCE_DEFAULT import android.app.NotificationManager.IMPORTANCE_NONE import android.app.PendingIntent import android.app.PendingIntent.FLAG_UPDATE_CURRENT import android.content.Context Loading Loading @@ -80,6 +81,8 @@ class NetworkStackNotifierTest { @Mock private lateinit var mNm: NotificationManager @Mock private lateinit var mNotificationChannelsNm: NotificationManager @Mock private lateinit var mCm: ConnectivityManager @Mock private lateinit var mResources: Resources Loading Loading @@ -141,10 +144,12 @@ class NetworkStackNotifierTest { realContext.packageName, 0, UserHandle.ALL) mAllUserContext.mockService(Context.NOTIFICATION_SERVICE, NotificationManager::class, mNm) mContext.mockService(Context.NOTIFICATION_SERVICE, NotificationManager::class, mNotificationChannelsNm) mContext.mockService(Context.CONNECTIVITY_SERVICE, ConnectivityManager::class, mCm) doReturn(NotificationChannel(CHANNEL_VENUE_INFO, "TestChannel", IMPORTANCE_DEFAULT)) .`when`(mNm).getNotificationChannel(CHANNEL_VENUE_INFO) .`when`(mNotificationChannelsNm).getNotificationChannel(CHANNEL_VENUE_INFO) doReturn(mPendingIntent).`when`(mDependencies).getActivityPendingIntent( any(), any(), anyInt()) Loading Loading @@ -247,7 +252,8 @@ class NetworkStackNotifierTest { fun testConnectedVenueInfoNotification_VenueInfoDisabled() { // Venue info (CaptivePortalData) is not available for API <= Q assumeTrue(NetworkInformationShimImpl.useApiAboveQ()) doReturn(null).`when`(mNm).getNotificationChannel(CHANNEL_VENUE_INFO) val channel = NotificationChannel(CHANNEL_VENUE_INFO, "test channel", IMPORTANCE_NONE) doReturn(channel).`when`(mNotificationChannelsNm).getNotificationChannel(CHANNEL_VENUE_INFO) mNotifier.notifyCaptivePortalValidationPending(TEST_NETWORK) onLinkPropertiesChanged(mTestCapportLp) onDefaultNetworkAvailable(TEST_NETWORK) Loading tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java +4 −1 Original line number Diff line number Diff line Loading @@ -866,12 +866,15 @@ public class NetworkMonitorTest { doReturn(PackageManager.PERMISSION_GRANTED).when(mContext).checkPermission( eq(android.Manifest.permission.ACCESS_FINE_LOCATION), anyInt(), anyInt()); doReturn(new ContextWrapper(mContext)).when(mContext).createConfigurationContext(any()); doReturn(null).when(mTelephony).getAllCellInfo(); assertNull(wnm.getLocationMcc()); // Prepare CellInfo and check if the vote mechanism is working or not. final List<CellInfo> cellList = new ArrayList<CellInfo>(); doReturn(cellList).when(mTelephony).getAllCellInfo(); assertNull(wnm.getLocationMcc()); cellList.add(makeTestCellInfoGsm("460")); cellList.add(makeTestCellInfoGsm("460")); cellList.add(makeTestCellInfoLte("466")); doReturn(cellList).when(mTelephony).getAllCellInfo(); // The count of 460 is 2 and the count of 466 is 1, so the getLocationMcc() should return // 460. assertEquals("460", wnm.getLocationMcc()); Loading Loading
src/com/android/networkstack/NetworkStackNotifier.java +20 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.networkstack; import static android.app.NotificationManager.IMPORTANCE_NONE; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; Loading Loading @@ -142,7 +144,19 @@ public class NetworkStackNotifier { resources.getString(title), importance); channel.setDescription(resources.getString(description)); mNotificationManager.createNotificationChannel(channel); getNotificationManagerForChannels().createNotificationChannel(channel); } /** * Get the NotificationManager to use to query channels, as opposed to posting notifications. * * Although notifications are posted as USER_ALL, notification channels are always created * based on the UID calling NotificationManager, regardless of the context UserHandle. * When querying notification channels, using a USER_ALL context would return no channel: the * default context (as UserHandle 0 for NetworkStack) must be used. */ private NotificationManager getNotificationManagerForChannels() { return mContext.getSystemService(NotificationManager.class); } /** Loading Loading @@ -284,7 +298,11 @@ public class NetworkStackNotifier { } private boolean isVenueInfoNotificationEnabled() { return mNotificationManager.getNotificationChannel(CHANNEL_VENUE_INFO) != null; final NotificationChannel channel = getNotificationManagerForChannels() .getNotificationChannel(CHANNEL_VENUE_INFO); if (channel == null) return false; return channel.getImportance() != IMPORTANCE_NONE; } private static String getNotificationTag(@NonNull Network network) { Loading
src/com/android/networkstack/metrics/DataStallDetectionStats.java +5 −3 Original line number Diff line number Diff line Loading @@ -261,11 +261,13 @@ public final class DataStallDetectionStats { if (info == null) return DataStallEventProto.AP_BAND_UNKNOWN; int freq = info.getFrequency(); // Refer to ScanResult.is5GHz() and ScanResult.is24GHz(). if (freq > 4900 && freq < 5900) { // Refer to ScanResult.is5GHz(), ScanResult.is24GHz() and ScanResult.is6GHz(). if (freq >= 5160 && freq <= 5865) { return DataStallEventProto.AP_BAND_5GHZ; } else if (freq > 2400 && freq < 2500) { } else if (freq >= 2412 && freq <= 2484) { return DataStallEventProto.AP_BAND_2GHZ; } else if (freq >= 5945 && freq <= 7105) { return DataStallEventProto.AP_BAND_6GHZ; } else { return DataStallEventProto.AP_BAND_UNKNOWN; } Loading
src/com/android/server/connectivity/NetworkMonitor.java +1 −0 Original line number Diff line number Diff line Loading @@ -1731,6 +1731,7 @@ public class NetworkMonitor extends StateMachine { } try { final List<CellInfo> cells = mTelephonyManager.getAllCellInfo(); if (cells == null) return null; final Map<String, Integer> countryCodeMap = new HashMap<>(); int maxCount = 0; for (final CellInfo cell : cells) { Loading
tests/unit/src/com/android/networkstack/NetworkStackNotifierTest.kt +8 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.app.Notification import android.app.NotificationChannel import android.app.NotificationManager import android.app.NotificationManager.IMPORTANCE_DEFAULT import android.app.NotificationManager.IMPORTANCE_NONE import android.app.PendingIntent import android.app.PendingIntent.FLAG_UPDATE_CURRENT import android.content.Context Loading Loading @@ -80,6 +81,8 @@ class NetworkStackNotifierTest { @Mock private lateinit var mNm: NotificationManager @Mock private lateinit var mNotificationChannelsNm: NotificationManager @Mock private lateinit var mCm: ConnectivityManager @Mock private lateinit var mResources: Resources Loading Loading @@ -141,10 +144,12 @@ class NetworkStackNotifierTest { realContext.packageName, 0, UserHandle.ALL) mAllUserContext.mockService(Context.NOTIFICATION_SERVICE, NotificationManager::class, mNm) mContext.mockService(Context.NOTIFICATION_SERVICE, NotificationManager::class, mNotificationChannelsNm) mContext.mockService(Context.CONNECTIVITY_SERVICE, ConnectivityManager::class, mCm) doReturn(NotificationChannel(CHANNEL_VENUE_INFO, "TestChannel", IMPORTANCE_DEFAULT)) .`when`(mNm).getNotificationChannel(CHANNEL_VENUE_INFO) .`when`(mNotificationChannelsNm).getNotificationChannel(CHANNEL_VENUE_INFO) doReturn(mPendingIntent).`when`(mDependencies).getActivityPendingIntent( any(), any(), anyInt()) Loading Loading @@ -247,7 +252,8 @@ class NetworkStackNotifierTest { fun testConnectedVenueInfoNotification_VenueInfoDisabled() { // Venue info (CaptivePortalData) is not available for API <= Q assumeTrue(NetworkInformationShimImpl.useApiAboveQ()) doReturn(null).`when`(mNm).getNotificationChannel(CHANNEL_VENUE_INFO) val channel = NotificationChannel(CHANNEL_VENUE_INFO, "test channel", IMPORTANCE_NONE) doReturn(channel).`when`(mNotificationChannelsNm).getNotificationChannel(CHANNEL_VENUE_INFO) mNotifier.notifyCaptivePortalValidationPending(TEST_NETWORK) onLinkPropertiesChanged(mTestCapportLp) onDefaultNetworkAvailable(TEST_NETWORK) Loading
tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java +4 −1 Original line number Diff line number Diff line Loading @@ -866,12 +866,15 @@ public class NetworkMonitorTest { doReturn(PackageManager.PERMISSION_GRANTED).when(mContext).checkPermission( eq(android.Manifest.permission.ACCESS_FINE_LOCATION), anyInt(), anyInt()); doReturn(new ContextWrapper(mContext)).when(mContext).createConfigurationContext(any()); doReturn(null).when(mTelephony).getAllCellInfo(); assertNull(wnm.getLocationMcc()); // Prepare CellInfo and check if the vote mechanism is working or not. final List<CellInfo> cellList = new ArrayList<CellInfo>(); doReturn(cellList).when(mTelephony).getAllCellInfo(); assertNull(wnm.getLocationMcc()); cellList.add(makeTestCellInfoGsm("460")); cellList.add(makeTestCellInfoGsm("460")); cellList.add(makeTestCellInfoLte("466")); doReturn(cellList).when(mTelephony).getAllCellInfo(); // The count of 460 is 2 and the count of 466 is 1, so the getLocationMcc() should return // 460. assertEquals("460", wnm.getLocationMcc()); Loading