summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/net/SntpClient.java16
-rw-r--r--core/java/android/util/NtpTrustedTime.java19
-rw-r--r--core/tests/coretests/src/android/net/SntpClientTest.java52
-rw-r--r--telephony/java/android/telephony/CarrierConfigManager.java9
-rw-r--r--telephony/java/android/telephony/PhysicalChannelConfig.java25
-rw-r--r--telephony/java/android/telephony/UiccSlotInfo.java2
-rw-r--r--tests/BandwidthTests/src/com/android/tests/bandwidthenforcement/BandwidthEnforcementTestService.java12
7 files changed, 111 insertions, 24 deletions
diff --git a/core/java/android/net/SntpClient.java b/core/java/android/net/SntpClient.java
index ffc735c93aef..66cdc99150a5 100644
--- a/core/java/android/net/SntpClient.java
+++ b/core/java/android/net/SntpClient.java
@@ -80,25 +80,27 @@ public class SntpClient {
*
* @param host host name of the server.
* @param timeout network timeout in milliseconds.
+ * @param network network over which to send the request.
* @return true if the transaction was successful.
*/
- public boolean requestTime(String host, int timeout) {
+ public boolean requestTime(String host, int timeout, Network network) {
InetAddress address = null;
try {
- address = InetAddress.getByName(host);
+ address = network.getByName(host);
} catch (Exception e) {
EventLogTags.writeNtpFailure(host, e.toString());
if (DBG) Log.d(TAG, "request time failed: " + e);
return false;
}
- return requestTime(address, NTP_PORT, timeout);
+ return requestTime(address, NTP_PORT, timeout, network);
}
- public boolean requestTime(InetAddress address, int port, int timeout) {
+ public boolean requestTime(InetAddress address, int port, int timeout, Network network) {
DatagramSocket socket = null;
final int oldTag = TrafficStats.getAndSetThreadStatsTag(TrafficStats.TAG_SYSTEM_NTP);
try {
socket = new DatagramSocket();
+ network.bindSocket(socket);
socket.setSoTimeout(timeout);
byte[] buffer = new byte[NTP_PACKET_SIZE];
DatagramPacket request = new DatagramPacket(buffer, buffer.length, address, port);
@@ -168,6 +170,12 @@ public class SntpClient {
return true;
}
+ @Deprecated
+ public boolean requestTime(String host, int timeout) {
+ Log.w(TAG, "Shame on you for calling the hidden API requestTime()!");
+ return false;
+ }
+
/**
* Returns the time computed from the NTP transaction.
*
diff --git a/core/java/android/util/NtpTrustedTime.java b/core/java/android/util/NtpTrustedTime.java
index ed2d3c60fcd0..30d7b6c0786c 100644
--- a/core/java/android/util/NtpTrustedTime.java
+++ b/core/java/android/util/NtpTrustedTime.java
@@ -20,6 +20,7 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.net.ConnectivityManager;
+import android.net.Network;
import android.net.NetworkInfo;
import android.net.SntpClient;
import android.os.SystemClock;
@@ -80,6 +81,18 @@ public class NtpTrustedTime implements TrustedTime {
@Override
public boolean forceRefresh() {
+ // We can't do this at initialization time: ConnectivityService might not be running yet.
+ synchronized (this) {
+ if (mCM == null) {
+ mCM = sContext.getSystemService(ConnectivityManager.class);
+ }
+ }
+
+ final Network network = mCM == null ? null : mCM.getActiveNetwork();
+ return forceRefresh(network);
+ }
+
+ public boolean forceRefresh(Network network) {
if (TextUtils.isEmpty(mServer)) {
// missing server, so no trusted time available
return false;
@@ -88,11 +101,11 @@ public class NtpTrustedTime implements TrustedTime {
// We can't do this at initialization time: ConnectivityService might not be running yet.
synchronized (this) {
if (mCM == null) {
- mCM = (ConnectivityManager) sContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+ mCM = sContext.getSystemService(ConnectivityManager.class);
}
}
- final NetworkInfo ni = mCM == null ? null : mCM.getActiveNetworkInfo();
+ final NetworkInfo ni = mCM == null ? null : mCM.getNetworkInfo(network);
if (ni == null || !ni.isConnected()) {
if (LOGD) Log.d(TAG, "forceRefresh: no connectivity");
return false;
@@ -101,7 +114,7 @@ public class NtpTrustedTime implements TrustedTime {
if (LOGD) Log.d(TAG, "forceRefresh() from cache miss");
final SntpClient client = new SntpClient();
- if (client.requestTime(mServer, (int) mTimeout)) {
+ if (client.requestTime(mServer, (int) mTimeout, network)) {
mHasCache = true;
mCachedNtpTime = client.getNtpTime();
mCachedNtpElapsedRealtime = client.getNtpTimeReference();
diff --git a/core/tests/coretests/src/android/net/SntpClientTest.java b/core/tests/coretests/src/android/net/SntpClientTest.java
index 8b8cf671e723..d72738c6e32c 100644
--- a/core/tests/coretests/src/android/net/SntpClientTest.java
+++ b/core/tests/coretests/src/android/net/SntpClientTest.java
@@ -16,20 +16,28 @@
package android.net;
-import android.net.SntpClient;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import android.support.test.runner.AndroidJUnit4;
import android.util.Log;
+
import libcore.util.HexEncoding;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.util.Arrays;
-import junit.framework.TestCase;
-
-public class SntpClientTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public class SntpClientTest {
private static final String TAG = "SntpClientTest";
private static final int ORIGINATE_TIME_OFFSET = 24;
@@ -58,36 +66,50 @@ public class SntpClientTest extends TestCase {
"d9ca945194bd3fff" +
"d9ca945194bd4001";
- private final SntpTestServer mServer = new SntpTestServer();
- private final SntpClient mClient = new SntpClient();
+ private SntpTestServer mServer;
+ private SntpClient mClient;
+ private Network mNetwork;
+
+ @Before
+ public void setUp() throws Exception {
+ // NETID_UNSET allows the test to run, with a loopback server, even w/o external networking
+ mNetwork = new Network(ConnectivityManager.NETID_UNSET);
+ mServer = new SntpTestServer();
+ mClient = new SntpClient();
+ }
+ @Test
public void testBasicWorkingSntpClientQuery() throws Exception {
mServer.setServerReply(HexEncoding.decode(WORKING_VERSION4.toCharArray(), false));
- assertTrue(mClient.requestTime(mServer.getAddress(), mServer.getPort(), 500));
+ assertTrue(mClient.requestTime(mServer.getAddress(), mServer.getPort(), 500, mNetwork));
assertEquals(1, mServer.numRequestsReceived());
assertEquals(1, mServer.numRepliesSent());
}
+ @Test
public void testDnsResolutionFailure() throws Exception {
- assertFalse(mClient.requestTime("ntp.server.doesnotexist.example", 5000));
+ assertFalse(mClient.requestTime("ntp.server.doesnotexist.example", 5000, mNetwork));
}
+ @Test
public void testTimeoutFailure() throws Exception {
mServer.clearServerReply();
- assertFalse(mClient.requestTime(mServer.getAddress(), mServer.getPort(), 500));
+ assertFalse(mClient.requestTime(mServer.getAddress(), mServer.getPort(), 500, mNetwork));
assertEquals(1, mServer.numRequestsReceived());
assertEquals(0, mServer.numRepliesSent());
}
+ @Test
public void testIgnoreLeapNoSync() throws Exception {
final byte[] reply = HexEncoding.decode(WORKING_VERSION4.toCharArray(), false);
reply[0] |= (byte) 0xc0;
mServer.setServerReply(reply);
- assertFalse(mClient.requestTime(mServer.getAddress(), mServer.getPort(), 500));
+ assertFalse(mClient.requestTime(mServer.getAddress(), mServer.getPort(), 500, mNetwork));
assertEquals(1, mServer.numRequestsReceived());
assertEquals(1, mServer.numRepliesSent());
}
+ @Test
public void testAcceptOnlyServerAndBroadcastModes() throws Exception {
final byte[] reply = HexEncoding.decode(WORKING_VERSION4.toCharArray(), false);
for (int i = 0; i <= 7; i++) {
@@ -95,7 +117,8 @@ public class SntpClientTest extends TestCase {
reply[0] &= (byte) 0xf8;
reply[0] |= (byte) i;
mServer.setServerReply(reply);
- final boolean rval = mClient.requestTime(mServer.getAddress(), mServer.getPort(), 500);
+ final boolean rval = mClient.requestTime(mServer.getAddress(), mServer.getPort(), 500,
+ mNetwork);
switch (i) {
case NTP_MODE_SERVER:
case NTP_MODE_BROADCAST:
@@ -110,6 +133,7 @@ public class SntpClientTest extends TestCase {
}
}
+ @Test
public void testAcceptableStrataOnly() throws Exception {
final int STRATUM_MIN = 1;
final int STRATUM_MAX = 15;
@@ -119,7 +143,8 @@ public class SntpClientTest extends TestCase {
final String logMsg = "stratum: " + i;
reply[1] = (byte) i;
mServer.setServerReply(reply);
- final boolean rval = mClient.requestTime(mServer.getAddress(), mServer.getPort(), 500);
+ final boolean rval = mClient.requestTime(mServer.getAddress(), mServer.getPort(), 500,
+ mNetwork);
if (STRATUM_MIN <= i && i <= STRATUM_MAX) {
assertTrue(logMsg, rval);
} else {
@@ -130,11 +155,12 @@ public class SntpClientTest extends TestCase {
}
}
+ @Test
public void testZeroTransmitTime() throws Exception {
final byte[] reply = HexEncoding.decode(WORKING_VERSION4.toCharArray(), false);
Arrays.fill(reply, TRANSMIT_TIME_OFFSET, TRANSMIT_TIME_OFFSET + 8, (byte) 0x00);
mServer.setServerReply(reply);
- assertFalse(mClient.requestTime(mServer.getAddress(), mServer.getPort(), 500));
+ assertFalse(mClient.requestTime(mServer.getAddress(), mServer.getPort(), 500, mNetwork));
assertEquals(1, mServer.numRequestsReceived());
assertEquals(1, mServer.numRepliesSent());
}
diff --git a/telephony/java/android/telephony/CarrierConfigManager.java b/telephony/java/android/telephony/CarrierConfigManager.java
index b8a1c134764f..b672e690d45f 100644
--- a/telephony/java/android/telephony/CarrierConfigManager.java
+++ b/telephony/java/android/telephony/CarrierConfigManager.java
@@ -1895,6 +1895,15 @@ public class CarrierConfigManager {
public static final String KEY_WCDMA_DEFAULT_SIGNAL_STRENGTH_MEASUREMENT_STRING =
"wcdma_default_signal_strength_measurement_string";
+ /**
+ * When a partial sms / mms message stay in raw table for too long without being completed,
+ * we expire them and delete them from the raw table. This carrier config defines the
+ * expiration time.
+ * @hide
+ */
+ public static final String KEY_UNDELIVERED_SMS_MESSAGE_EXPIRATION_TIME =
+ "undelivered_sms_message_expiration_time";
+
/** The default value for every variable. */
private final static PersistableBundle sDefaults;
diff --git a/telephony/java/android/telephony/PhysicalChannelConfig.java b/telephony/java/android/telephony/PhysicalChannelConfig.java
index ce444dd00ce4..d2001ae6ea0e 100644
--- a/telephony/java/android/telephony/PhysicalChannelConfig.java
+++ b/telephony/java/android/telephony/PhysicalChannelConfig.java
@@ -99,6 +99,20 @@ public final class PhysicalChannelConfig implements Parcelable {
return mCellConnectionStatus;
}
+ /** @return String representation of the connection status */
+ private String getConnectionStatusString() {
+ switch(mCellConnectionStatus) {
+ case CONNECTION_PRIMARY_SERVING:
+ return "PrimaryServing";
+ case CONNECTION_SECONDARY_SERVING:
+ return "SecondaryServing";
+ case CONNECTION_UNKNOWN:
+ return "Unknown";
+ default:
+ return "Invalid(" + mCellConnectionStatus + ")";
+ }
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -129,4 +143,15 @@ public final class PhysicalChannelConfig implements Parcelable {
return new PhysicalChannelConfig[size];
}
};
+
+ @Override
+ public String toString() {
+ return new StringBuilder()
+ .append("{mConnectionStatus=")
+ .append(getConnectionStatusString())
+ .append(",mCellBandwidthDownlinkKhz=")
+ .append(mCellBandwidthDownlinkKhz)
+ .append("}")
+ .toString();
+ }
}
diff --git a/telephony/java/android/telephony/UiccSlotInfo.java b/telephony/java/android/telephony/UiccSlotInfo.java
index 125161d62373..a39992b17f8e 100644
--- a/telephony/java/android/telephony/UiccSlotInfo.java
+++ b/telephony/java/android/telephony/UiccSlotInfo.java
@@ -148,7 +148,7 @@ public class UiccSlotInfo implements Parcelable {
UiccSlotInfo that = (UiccSlotInfo) obj;
return (mIsActive == that.mIsActive)
&& (mIsEuicc == that.mIsEuicc)
- && (mCardId == that.mCardId)
+ && (Objects.equals(mCardId, that.mCardId))
&& (mCardStateInfo == that.mCardStateInfo)
&& (mLogicalSlotIdx == that.mLogicalSlotIdx)
&& (mIsExtendedApduSupported == that.mIsExtendedApduSupported);
diff --git a/tests/BandwidthTests/src/com/android/tests/bandwidthenforcement/BandwidthEnforcementTestService.java b/tests/BandwidthTests/src/com/android/tests/bandwidthenforcement/BandwidthEnforcementTestService.java
index a2427f514e17..35f1e585931b 100644
--- a/tests/BandwidthTests/src/com/android/tests/bandwidthenforcement/BandwidthEnforcementTestService.java
+++ b/tests/BandwidthTests/src/com/android/tests/bandwidthenforcement/BandwidthEnforcementTestService.java
@@ -16,7 +16,10 @@
package com.android.tests.bandwidthenforcement;
import android.app.IntentService;
+import android.content.Context;
import android.content.Intent;
+import android.net.ConnectivityManager;
+import android.net.Network;
import android.net.SntpClient;
import android.os.Environment;
import android.util.Log;
@@ -55,7 +58,7 @@ public class BandwidthEnforcementTestService extends IntentService {
String outputFile = intent.getStringExtra(OUTPUT_FILE);
dumpResult("testUrlConnection", testUrlConnection(), outputFile);
dumpResult("testUrlConnectionv6", testUrlConnectionv6(), outputFile);
- dumpResult("testSntp", testSntp(), outputFile);
+ dumpResult("testSntp", testSntp(getApplicationContext()), outputFile);
dumpResult("testDns", testDns(), outputFile);
}
@@ -138,9 +141,12 @@ public class BandwidthEnforcementTestService extends IntentService {
* Tests to connect via sntp.
* @return true if it was able to connect, false otherwise.
*/
- public static boolean testSntp() {
+ public static boolean testSntp(Context context) {
final SntpClient client = new SntpClient();
- if (client.requestTime("0.pool.ntp.org", 10000)) {
+ final ConnectivityManager mCM = context.getSystemService(ConnectivityManager.class);
+ final Network network = mCM.getActiveNetwork();
+
+ if (client.requestTime("0.pool.ntp.org", 10000, network)) {
return true;
}
return false;