Merge changes I1eaab5ea,I42928da8

* changes:
  DO NOT MERGE Captive portal systel log improvements
  DO NOT MERGE Fix flaky IpPrefixTest.
This commit is contained in:
Treehugger Robot
2017-01-11 01:02:05 +00:00
committed by Gerrit Code Review
3 changed files with 35 additions and 17 deletions

View File

@@ -18,14 +18,14 @@ package android.net;
import android.net.IpPrefix; import android.net.IpPrefix;
import android.os.Parcel; import android.os.Parcel;
import static android.test.MoreAsserts.assertNotEqual;
import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.SmallTest;
import static org.junit.Assert.assertArrayEquals;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.Random; import java.util.Random;
import junit.framework.TestCase; import junit.framework.TestCase;
import static android.test.MoreAsserts.assertNotEqual;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
public class IpPrefixTest extends TestCase { public class IpPrefixTest extends TestCase {
@@ -242,25 +242,42 @@ public class IpPrefixTest extends TestCase {
@SmallTest @SmallTest
public void testHashCode() { public void testHashCode() {
IpPrefix p; IpPrefix p = new IpPrefix(new byte[4], 0);
int oldCode = -1;
Random random = new Random(); Random random = new Random();
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
final IpPrefix oldP = p;
if (random.nextBoolean()) { if (random.nextBoolean()) {
// IPv4. // IPv4.
byte[] b = new byte[4]; byte[] b = new byte[4];
random.nextBytes(b); random.nextBytes(b);
p = new IpPrefix(b, random.nextInt(33)); p = new IpPrefix(b, random.nextInt(33));
assertNotEqual(oldCode, p.hashCode());
oldCode = p.hashCode();
} else { } else {
// IPv6. // IPv6.
byte[] b = new byte[16]; byte[] b = new byte[16];
random.nextBytes(b); random.nextBytes(b);
p = new IpPrefix(b, random.nextInt(129)); p = new IpPrefix(b, random.nextInt(129));
assertNotEqual(oldCode, p.hashCode());
oldCode = p.hashCode();
} }
if (p.equals(oldP)) {
assertEquals(p.hashCode(), oldP.hashCode());
}
if (p.hashCode() != oldP.hashCode()) {
assertNotEqual(p, oldP);
}
}
}
@SmallTest
public void testHashCodeIsNotConstant() {
IpPrefix[] prefixes = {
new IpPrefix("2001:db8:f00::ace:d00d/127"),
new IpPrefix("192.0.2.0/23"),
new IpPrefix("::/0"),
new IpPrefix("0.0.0.0/0"),
};
for (int i = 0; i < prefixes.length; i++) {
for (int j = i + 1; j < prefixes.length; j++) {
assertNotEqual(prefixes[i].hashCode(), prefixes[j].hashCode());
}
} }
} }

View File

@@ -80,7 +80,8 @@ import java.util.concurrent.TimeUnit;
*/ */
public class NetworkMonitor extends StateMachine { public class NetworkMonitor extends StateMachine {
private static final String TAG = NetworkMonitor.class.getSimpleName(); private static final String TAG = NetworkMonitor.class.getSimpleName();
private static final boolean DBG = false; private static final boolean DBG = true;
private static final boolean VDBG = false;
// Default configuration values for captive portal detection probes. // Default configuration values for captive portal detection probes.
// TODO: append a random length parameter to the default HTTPS url. // TODO: append a random length parameter to the default HTTPS url.
@@ -954,7 +955,7 @@ public class NetworkMonitor extends StateMachine {
latencyBroadcast.putExtra(EXTRA_SSID, currentWifiInfo.getSSID()); latencyBroadcast.putExtra(EXTRA_SSID, currentWifiInfo.getSSID());
latencyBroadcast.putExtra(EXTRA_BSSID, currentWifiInfo.getBSSID()); latencyBroadcast.putExtra(EXTRA_BSSID, currentWifiInfo.getBSSID());
} else { } else {
if (DBG) logw("network info is TYPE_WIFI but no ConnectionInfo found"); if (VDBG) logw("network info is TYPE_WIFI but no ConnectionInfo found");
return; return;
} }
break; break;
@@ -967,8 +968,8 @@ public class NetworkMonitor extends StateMachine {
if (cellInfo.isRegistered()) { if (cellInfo.isRegistered()) {
numRegisteredCellInfo++; numRegisteredCellInfo++;
if (numRegisteredCellInfo > 1) { if (numRegisteredCellInfo > 1) {
log("more than one registered CellInfo. Can't " + if (VDBG) logw("more than one registered CellInfo." +
"tell which is active. Bailing."); " Can't tell which is active. Bailing.");
return; return;
} }
if (cellInfo instanceof CellInfoCdma) { if (cellInfo instanceof CellInfoCdma) {
@@ -984,7 +985,7 @@ public class NetworkMonitor extends StateMachine {
CellIdentityWcdma cellId = ((CellInfoWcdma) cellInfo).getCellIdentity(); CellIdentityWcdma cellId = ((CellInfoWcdma) cellInfo).getCellIdentity();
latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId); latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
} else { } else {
if (DBG) logw("Registered cellinfo is unrecognized"); if (VDBG) logw("Registered cellinfo is unrecognized");
return; return;
} }
} }

View File

@@ -114,7 +114,7 @@ public class NetworkNotificationManager {
} }
if (DBG) { if (DBG) {
Slog.d(TAG, "showNotification " + notifyType Slog.d(TAG, "showNotification id=" + id + " " + notifyType
+ " transportType=" + getTransportName(transportType) + " transportType=" + getTransportName(transportType)
+ " extraInfo=" + extraInfo + " highPriority=" + highPriority); + " extraInfo=" + extraInfo + " highPriority=" + highPriority);
} }
@@ -187,7 +187,7 @@ public class NetworkNotificationManager {
try { try {
mNotificationManager.notifyAsUser(NOTIFICATION_ID, id, notification, UserHandle.ALL); mNotificationManager.notifyAsUser(NOTIFICATION_ID, id, notification, UserHandle.ALL);
} catch (NullPointerException npe) { } catch (NullPointerException npe) {
Slog.d(TAG, "setNotificationVisible: visible notificationManager npe=" + npe); Slog.d(TAG, "setNotificationVisible: visible notificationManager error", npe);
} }
} }
@@ -198,7 +198,7 @@ public class NetworkNotificationManager {
try { try {
mNotificationManager.cancelAsUser(NOTIFICATION_ID, id, UserHandle.ALL); mNotificationManager.cancelAsUser(NOTIFICATION_ID, id, UserHandle.ALL);
} catch (NullPointerException npe) { } catch (NullPointerException npe) {
Slog.d(TAG, "setNotificationVisible: cancel notificationManager npe=" + npe); Slog.d(TAG, "setNotificationVisible: cancel notificationManager error", npe);
} }
} }