summaryrefslogtreecommitdiffstats
path: root/core/java/android
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/ddm/DdmHandleProfiling.java47
-rw-r--r--core/java/android/net/arp/ArpPeer.java174
-rw-r--r--core/java/android/text/MeasuredText.java2
-rw-r--r--core/java/android/webkit/ClientCertRequestHandler.java12
4 files changed, 24 insertions, 211 deletions
diff --git a/core/java/android/ddm/DdmHandleProfiling.java b/core/java/android/ddm/DdmHandleProfiling.java
index ec08393..537763d 100644
--- a/core/java/android/ddm/DdmHandleProfiling.java
+++ b/core/java/android/ddm/DdmHandleProfiling.java
@@ -37,6 +37,7 @@ public class DdmHandleProfiling extends ChunkHandler {
public static final int CHUNK_SPSS = type("SPSS");
public static final int CHUNK_SPSE = type("SPSE");
+ private static final boolean DEBUG = false;
private static DdmHandleProfiling mInstance = new DdmHandleProfiling();
@@ -72,7 +73,7 @@ public class DdmHandleProfiling extends ChunkHandler {
* Handle a chunk of data.
*/
public Chunk handleChunk(Chunk request) {
- if (false)
+ if (DEBUG)
Log.v("ddm-heap", "Handling " + name(request.type) + " chunk");
int type = request.type;
@@ -83,13 +84,13 @@ public class DdmHandleProfiling extends ChunkHandler {
} else if (type == CHUNK_MPSS) {
return handleMPSS(request);
} else if (type == CHUNK_MPSE) {
- return handleMPSE(request);
+ return handleMPSEOrSPSE(request, "Method");
} else if (type == CHUNK_MPRQ) {
return handleMPRQ(request);
} else if (type == CHUNK_SPSS) {
return handleSPSS(request);
} else if (type == CHUNK_SPSE) {
- return handleSPSE(request);
+ return handleMPSEOrSPSE(request, "Sample");
} else {
throw new RuntimeException("Unknown packet "
+ ChunkHandler.name(type));
@@ -106,7 +107,7 @@ public class DdmHandleProfiling extends ChunkHandler {
int flags = in.getInt();
int len = in.getInt();
String fileName = getString(in, len);
- if (false)
+ if (DEBUG)
Log.v("ddm-heap", "Method profiling start: filename='" + fileName
+ "', size=" + bufferSize + ", flags=" + flags);
@@ -146,7 +147,7 @@ public class DdmHandleProfiling extends ChunkHandler {
int bufferSize = in.getInt();
int flags = in.getInt();
- if (false) {
+ if (DEBUG) {
Log.v("ddm-heap", "Method prof stream start: size=" + bufferSize
+ ", flags=" + flags);
}
@@ -160,20 +161,18 @@ public class DdmHandleProfiling extends ChunkHandler {
}
/*
- * Handle a "Method Profiling w/Streaming End" request.
+ * Handle a "Method Profiling w/Streaming End" request or a
+ * "Sample Profiling w/Streaming End" request.
*/
- private Chunk handleMPSE(Chunk request) {
- byte result;
-
- if (false) {
- Log.v("ddm-heap", "Method prof stream end");
+ private Chunk handleMPSEOrSPSE(Chunk request, String type) {
+ if (DEBUG) {
+ Log.v("ddm-heap", type + " prof stream end");
}
try {
Debug.stopMethodTracing();
- result = 0;
} catch (RuntimeException re) {
- Log.w("ddm-heap", "Method prof stream end failed: "
+ Log.w("ddm-heap", type + " prof stream end failed: "
+ re.getMessage());
return createFailChunk(1, re.getMessage());
}
@@ -202,7 +201,7 @@ public class DdmHandleProfiling extends ChunkHandler {
int bufferSize = in.getInt();
int flags = in.getInt();
int interval = in.getInt();
- if (false) {
+ if (DEBUG) {
Log.v("ddm-heap", "Sample prof stream start: size=" + bufferSize
+ ", flags=" + flags + ", interval=" + interval);
}
@@ -214,25 +213,5 @@ public class DdmHandleProfiling extends ChunkHandler {
return createFailChunk(1, re.getMessage());
}
}
-
- /*
- * Handle a "Sample Profiling w/Streaming End" request.
- */
- private Chunk handleSPSE(Chunk request) {
- if (false) {
- Log.v("ddm-heap", "Sample prof stream end");
- }
-
- try {
- Debug.stopMethodTracing();
- } catch (RuntimeException re) {
- Log.w("ddm-heap", "Sample prof stream end failed: "
- + re.getMessage());
- return createFailChunk(1, re.getMessage());
- }
-
- /* VM sent the (perhaps very large) response directly */
- return null;
- }
}
diff --git a/core/java/android/net/arp/ArpPeer.java b/core/java/android/net/arp/ArpPeer.java
deleted file mode 100644
index 2013b11..0000000
--- a/core/java/android/net/arp/ArpPeer.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.net.arp;
-
-import android.net.LinkAddress;
-import android.net.LinkProperties;
-import android.net.RouteInfo;
-import android.os.SystemClock;
-import android.util.Log;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.Inet6Address;
-import java.net.SocketException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.Arrays;
-
-import libcore.net.RawSocket;
-
-/**
- * This class allows simple ARP exchanges over an uninitialized network
- * interface.
- *
- * @hide
- */
-public class ArpPeer {
- private static final boolean DBG = false;
- private static final String TAG = "ArpPeer";
- private String mInterfaceName;
- private final InetAddress mMyAddr;
- private final byte[] mMyMac = new byte[6];
- private final InetAddress mPeer;
- private final RawSocket mSocket;
- private final byte[] L2_BROADCAST; // TODO: refactor from DhcpClient.java
- private static final int MAX_LENGTH = 1500; // refactor from DhcpPacket.java
- private static final int ETHERNET_TYPE = 1;
- private static final int ARP_LENGTH = 28;
- private static final int MAC_ADDR_LENGTH = 6;
- private static final int IPV4_LENGTH = 4;
-
- public ArpPeer(String interfaceName, InetAddress myAddr, String mac,
- InetAddress peer) throws SocketException {
- mInterfaceName = interfaceName;
- mMyAddr = myAddr;
-
- if (mac != null) {
- for (int i = 0; i < MAC_ADDR_LENGTH; i++) {
- mMyMac[i] = (byte) Integer.parseInt(mac.substring(
- i*3, (i*3) + 2), 16);
- }
- }
-
- if (myAddr instanceof Inet6Address || peer instanceof Inet6Address) {
- throw new IllegalArgumentException("IPv6 unsupported");
- }
-
- mPeer = peer;
- L2_BROADCAST = new byte[MAC_ADDR_LENGTH];
- Arrays.fill(L2_BROADCAST, (byte) 0xFF);
-
- mSocket = new RawSocket(mInterfaceName, RawSocket.ETH_P_ARP);
- }
-
- /**
- * Returns the MAC address (or null if timeout) for the requested
- * peer.
- */
- public byte[] doArp(int timeoutMillis) {
- ByteBuffer buf = ByteBuffer.allocate(MAX_LENGTH);
- byte[] desiredIp = mPeer.getAddress();
- long timeout = SystemClock.elapsedRealtime() + timeoutMillis;
-
- // construct ARP request packet, using a ByteBuffer as a
- // convenient container
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
-
- buf.putShort((short) ETHERNET_TYPE); // Ethernet type, 16 bits
- buf.putShort(RawSocket.ETH_P_IP); // Protocol type IP, 16 bits
- buf.put((byte)MAC_ADDR_LENGTH); // MAC address length, 6 bytes
- buf.put((byte)IPV4_LENGTH); // IPv4 protocol size
- buf.putShort((short) 1); // ARP opcode 1: 'request'
- buf.put(mMyMac); // six bytes: sender MAC
- buf.put(mMyAddr.getAddress()); // four bytes: sender IP address
- buf.put(new byte[MAC_ADDR_LENGTH]); // target MAC address: unknown
- buf.put(desiredIp); // target IP address, 4 bytes
- buf.flip();
- mSocket.write(L2_BROADCAST, buf.array(), 0, buf.limit());
-
- byte[] recvBuf = new byte[MAX_LENGTH];
-
- while (SystemClock.elapsedRealtime() < timeout) {
- long duration = (long) timeout - SystemClock.elapsedRealtime();
- int readLen = mSocket.read(recvBuf, 0, recvBuf.length, -1,
- (int) duration);
-
- // Verify packet details. see RFC 826
- if ((readLen >= ARP_LENGTH) // trailing bytes at times
- && (recvBuf[0] == 0) && (recvBuf[1] == ETHERNET_TYPE) // type Ethernet
- && (recvBuf[2] == 8) && (recvBuf[3] == 0) // protocol IP
- && (recvBuf[4] == MAC_ADDR_LENGTH) // mac length
- && (recvBuf[5] == IPV4_LENGTH) // IPv4 protocol size
- && (recvBuf[6] == 0) && (recvBuf[7] == 2) // ARP reply
- // verify desired IP address
- && (recvBuf[14] == desiredIp[0]) && (recvBuf[15] == desiredIp[1])
- && (recvBuf[16] == desiredIp[2]) && (recvBuf[17] == desiredIp[3]))
- {
- // looks good. copy out the MAC
- byte[] result = new byte[MAC_ADDR_LENGTH];
- System.arraycopy(recvBuf, 8, result, 0, MAC_ADDR_LENGTH);
- return result;
- }
- }
-
- return null;
- }
-
- public static boolean doArp(String myMacAddress, LinkProperties linkProperties,
- int timeoutMillis, int numArpPings, int minArpResponses) {
- String interfaceName = linkProperties.getInterfaceName();
- InetAddress inetAddress = null;
- InetAddress gateway = null;
- boolean success;
-
- for (LinkAddress la : linkProperties.getLinkAddresses()) {
- inetAddress = la.getAddress();
- break;
- }
-
- for (RouteInfo route : linkProperties.getRoutes()) {
- gateway = route.getGateway();
- break;
- }
-
- try {
- ArpPeer peer = new ArpPeer(interfaceName, inetAddress, myMacAddress, gateway);
- int responses = 0;
- for (int i=0; i < numArpPings; i++) {
- if(peer.doArp(timeoutMillis) != null) responses++;
- }
- if (DBG) Log.d(TAG, "ARP test result: " + responses + "/" + numArpPings);
- success = (responses >= minArpResponses);
- peer.close();
- } catch (SocketException se) {
- //Consider an Arp socket creation issue as a successful Arp
- //test to avoid any wifi connectivity issues
- Log.e(TAG, "ARP test initiation failure: " + se);
- success = true;
- }
- return success;
- }
-
- public void close() {
- try {
- mSocket.close();
- } catch (IOException ex) {
- }
- }
-}
diff --git a/core/java/android/text/MeasuredText.java b/core/java/android/text/MeasuredText.java
index bd9310c..101d6a2 100644
--- a/core/java/android/text/MeasuredText.java
+++ b/core/java/android/text/MeasuredText.java
@@ -46,7 +46,7 @@ class MeasuredText {
}
private static final Object[] sLock = new Object[0];
- private static MeasuredText[] sCached = new MeasuredText[3];
+ private static final MeasuredText[] sCached = new MeasuredText[3];
static MeasuredText obtain() {
MeasuredText mt;
diff --git a/core/java/android/webkit/ClientCertRequestHandler.java b/core/java/android/webkit/ClientCertRequestHandler.java
index d7a6806..8cab9a6 100644
--- a/core/java/android/webkit/ClientCertRequestHandler.java
+++ b/core/java/android/webkit/ClientCertRequestHandler.java
@@ -20,7 +20,6 @@ import android.os.Handler;
import java.security.PrivateKey;
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;
-import com.android.org.conscrypt.NativeCrypto;
import com.android.org.conscrypt.OpenSSLKey;
import com.android.org.conscrypt.OpenSSLKeyHolder;
@@ -48,12 +47,21 @@ public final class ClientCertRequestHandler extends Handler {
mTable = table;
}
+ private static byte[][] encodeCertificates(X509Certificate[] certificates)
+ throws CertificateEncodingException {
+ byte[][] certificateBytes = new byte[certificates.length][];
+ for (int i = 0; i < certificates.length; i++) {
+ certificateBytes[i] = certificates[i].getEncoded();
+ }
+ return certificateBytes;
+ }
+
/**
* Proceed with the specified private key and client certificate chain.
*/
public void proceed(PrivateKey privateKey, X509Certificate[] chain) {
try {
- byte[][] chainBytes = NativeCrypto.encodeCertificates(chain);
+ byte[][] chainBytes = encodeCertificates(chain);
mTable.Allow(mHostAndPort, privateKey, chainBytes);
if (privateKey instanceof OpenSSLKeyHolder) {