Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mobile: Clean up Java and Kotlin code #32773

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
class AndroidProxyMonitor extends BroadcastReceiver {
static volatile AndroidProxyMonitor instance = null;
private ConnectivityManager connectivityManager;
private EnvoyEngine envoyEngine;
private final ConnectivityManager connectivityManager;
private final EnvoyEngine envoyEngine;

static void load(Context context, EnvoyEngine envoyEngine) {
if (instance != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum TrustChainVerification {
// Connections where the certificate fails verification will be permitted.
// For HTTP connections, the result of certificate verification can be used in route matching.
// Used for testing.
ACCEPT_UNTRUSTED;
ACCEPT_UNTRUSTED
}

public final Integer connectTimeoutSeconds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ public interface EnvoyEngine {
/*
* These are the available log levels for Envoy Mobile.
*/
public enum LogLevel { TRACE, DEBUG, INFO, WARN, ERR, CRITICAL, OFF }
enum LogLevel { TRACE, DEBUG, INFO, WARN, ERR, CRITICAL, OFF }

/**
* Set the log level for Envoy mobile
*
* @param log_level the verbosity of logging Envoy should use.
*/
public void setLogLevel(LogLevel log_level);
void setLogLevel(LogLevel log_level);
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ public void setPreferredNetwork(EnvoyNetworkType network) {
return;
default:
JniLibrary.setPreferredNetwork(engineHandle, ENVOY_NET_GENERIC);
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
import io.envoyproxy.envoymobile.engine.types.EnvoyFinalStreamIntel;

class EnvoyFinalStreamIntelImpl implements EnvoyFinalStreamIntel {
private long streamStartMs;
private long dnsStartMs;
private long dnsEndMs;
private long connectStartMs;
private long connectEndMs;
private long sslStartMs;
private long sslEndMs;
private long sendingStartMs;
private long sendingEndMs;
private long responseStartMs;
private long streamEndMs;
private boolean socketReused;
private long sentByteCount;
private long receivedByteCount;
private long responseFlags;
private long upstreamProtocol;
private final long streamStartMs;
private final long dnsStartMs;
private final long dnsEndMs;
private final long connectStartMs;
private final long connectEndMs;
private final long sslStartMs;
private final long sslEndMs;
private final long sendingStartMs;
private final long sendingEndMs;
private final long responseStartMs;
private final long streamEndMs;
private final boolean socketReused;
private final long sentByteCount;
private final long receivedByteCount;
private final long responseFlags;
private final long upstreamProtocol;

EnvoyFinalStreamIntelImpl(long[] values) {
streamStartMs = values[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public enum EnvoyNativeResourceRegistry {
SINGLETON();

// References are automatically enqueued when the gc flags them as unreachable.
private ReferenceQueue<EnvoyNativeResourceWrapper> refQueue;
private final ReferenceQueue<EnvoyNativeResourceWrapper> refQueue;
// Maintains references in the object graph while we wait for them to be enqueued.
private Set refMaintainer;
private final Set refMaintainer;
// Blocks on the reference queue and calls the releaser of queued references.
private RefQueueThread refQueueThread;
private final RefQueueThread refQueueThread;

private class RefQueueThread extends Thread {
public void run() {
Expand Down Expand Up @@ -52,7 +52,7 @@ private class EnvoyPhantomRef extends PhantomReference<EnvoyNativeResourceWrappe
void releaseResource() { releaser.release(nativeHandle); }
}

private EnvoyNativeResourceRegistry() {
EnvoyNativeResourceRegistry() {
refQueue = new ReferenceQueue<>();
refQueueThread = new RefQueueThread();
refMaintainer = new ConcurrentHashMap().newKeySet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public interface EnvoyNativeResourceReleaser {
*
* @param @nativeHandle, JNI identifier for the native resource.
*/
public void release(long nativeHandle);
void release(long nativeHandle);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import io.envoyproxy.envoymobile.engine.types.EnvoyStreamIntel;

class EnvoyStreamIntelImpl implements EnvoyStreamIntel {
private long streamId;
private long connectionId;
private long attemptCount;
private long consumedBytesFromResponse;
private final long streamId;
private final long connectionId;
private final long attemptCount;
private final long consumedBytesFromResponse;

EnvoyStreamIntelImpl(long[] values) {
streamId = values[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public enum Type {
// Indicates the match value is a regular expression.
SAFE_REGEX
}
;

// The name of the matcher.
public final String name;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.envoyproxy.envoymobile.engine;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -34,12 +35,8 @@ void passHeader(byte[] key, byte[] value, boolean start) {
String headerKey;
String headerValue;

try {
headerKey = new String(key, "UTF-8");
headerValue = new String(value, "UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
headerKey = new String(key, StandardCharsets.UTF_8);
headerValue = new String(value, StandardCharsets.UTF_8);

// Ensure list is present in dictionary value
List<String> values = headerAccumulator.get(headerKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,71 @@ public interface EnvoyFinalStreamIntel {
/*
* The time the stream started (a.k.a request started), in ms since the epoch.
*/
public long getStreamStartMs();
long getStreamStartMs();
/*
* The time the DNS resolution for this request started, in ms since the epoch.
*/
public long getDnsStartMs();
long getDnsStartMs();
/*
* The time the DNS resolution for this request completed, in ms since the epoch.
*/
public long getDnsEndMs();
long getDnsEndMs();
/*
* The time the upstream connection started, in ms since the epoch.
* This may not be set if socket_reused is false.
*/
public long getConnectStartMs();
long getConnectStartMs();
/*
* The time the upstream connection completed, in ms since the epoch.
* This may not be set if socket_reused is false.
*/
public long getConnectEndMs();
long getConnectEndMs();
/*
* The time the SSL handshake started, in ms since the epoch.
* This may not be set if socket_reused is false.
*/
public long getSslStartMs();
long getSslStartMs();
/*
* The time the SSL handshake completed, in ms since the epoch.
* This may not be set if socket_reused is false.
*/
public long getSslEndMs();
long getSslEndMs();
/*
* The time the first byte of the request was sent upstream, in ms since the epoch.
*/
public long getSendingStartMs();
long getSendingStartMs();
/*
* The time the last byte of the request was sent upstream, in ms since the epoch.
*/
public long getSendingEndMs();
long getSendingEndMs();
/*
* The time the first byte of the response was received, in ms since the epoch.
*/
public long getResponseStartMs();
long getResponseStartMs();
/*
* The time when the stream reached a final state (Error, Cancel, Success), in ms since the epoch.
*/
public long getStreamEndMs();
long getStreamEndMs();
/*
* True if the upstream socket had been used previously.
*/
public boolean getSocketReused();
boolean getSocketReused();
/*
* The number of bytes sent upstream.
*/
public long getSentByteCount();
long getSentByteCount();
/*
* The number of bytes received from upstream.
*/
public long getReceivedByteCount();
long getReceivedByteCount();
/*
* The response flags for the stream. See
* https://github.com/envoyproxy/envoy/blob/main/envoy/stream_info/stream_info.h#L39
* for values.
*/
public long getResponseFlags();
long getResponseFlags();

/* The protocol for the upstream stream, if one was established, else -1 See
* https://github.com/envoyproxy/envoy/blob/main/envoy/http/protocol.h#L39 for values. */
public long getUpstreamProtocol();
long getUpstreamProtocol();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public enum EnvoyNetworkType {
// WLAN
ENVOY_NETWORK_TYPE_WLAN,
// GENERIC
ENVOY_NETWORK_TYPE_GENERIC;
ENVOY_NETWORK_TYPE_GENERIC
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ public interface EnvoyStreamIntel {
/**
* An internal identifier for the stream.
*/
public long getStreamId();
long getStreamId();

/**
* An internal identifier for the connection carrying the stream.
*/
public long getConnectionId();
long getConnectionId();

/**
* The number of internal attempts to carry out a request/operation.
*/
public long getAttemptCount();
long getAttemptCount();

/**
* The number of bytes consumed by the non terminal callbacks, from the response.
Expand All @@ -28,5 +28,5 @@ public interface EnvoyStreamIntel {
* number of bytes received before decompression. getConsumedBytesFromResponse() omits the number
* number of bytes related to the Status Line, and is after decompression.
*/
public long getConsumedBytesFromResponse();
long getConsumedBytesFromResponse();
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public AndroidCertVerifyResult(int status, boolean isIssuedByKnownRoot,
public AndroidCertVerifyResult(int status) {
mStatus = status;
mIsIssuedByKnownRoot = false;
mCertificateChain = Collections.<X509Certificate>emptyList();
mCertificateChain = Collections.emptyList();
}

// TODO(stefanoduo): Hook envoy-mobile JNI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ public static void addTestRootCertificate(byte[] rootCertBytes)
ensureInitialized();
X509Certificate rootCert = createCertificateFromBytes(rootCertBytes);
synchronized (sLock) {
sTestKeyStore.setCertificateEntry("root_cert_" + Integer.toString(sTestKeyStore.size()),
rootCert);
sTestKeyStore.setCertificateEntry("root_cert_" + sTestKeyStore.size(), rootCert);
reloadTestTrustManager();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -255,7 +256,6 @@ public void run() {
case NextAction.TAKE_NO_MORE_ACTIONS:
// Very unlikely: just before this switch statement and after the previous one, an EM
// onError callback occurred, or there was a USER_CANCEL event.
return;
}
}
} catch (Exception e) {
Expand Down Expand Up @@ -765,8 +765,8 @@ private void postTaskToExecutor(Runnable task) {
}
// proxy and caching are not supported.
CronvoyUrlResponseInfoImpl responseInfo =
new CronvoyUrlResponseInfoImpl(Arrays.asList(mInitialUrl), httpStatusCode, "", headers,
false, negotiatedProtocol, null, receivedByteCount);
new CronvoyUrlResponseInfoImpl(Collections.singletonList(mInitialUrl), httpStatusCode, "",
headers, false, negotiatedProtocol, null, receivedByteCount);
return responseInfo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public CronvoyQuicExceptionImpl(String message, int errorCode, int netErrorCode,

@Override
public String getMessage() {
StringBuilder b = new StringBuilder(mNetworkException.getMessage());
b.append(", QuicDetailedErrorCode=").append(mQuicDetailedErrorCode);
return b.toString();
return mNetworkException.getMessage() + ", QuicDetailedErrorCode=" + mQuicDetailedErrorCode;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static String from(Context context) {
builder.append(" (Linux; U; Android ");
builder.append(Build.VERSION.RELEASE);
builder.append("; ");
builder.append(Locale.getDefault().toString());
builder.append(Locale.getDefault());

String model = Build.MODEL;
if (model.length() > 0) {
Expand Down
Loading
Loading