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

Improve energy efficiency by applying Cache Energy Pattern #111

Merged
merged 1 commit into from
Jul 25, 2020
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
14 changes: 8 additions & 6 deletions app/src/main/java/com/perflyst/twire/service/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.net.NetworkInfo;
import android.net.TrafficStats;
import android.os.Build;
import android.os.Process;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
Expand Down Expand Up @@ -78,11 +79,7 @@
import java.util.Scanner;
import java.util.TreeMap;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.net.ssl.*;

/**
* Created by Sebastian Rask on 12-02-2015.
Expand Down Expand Up @@ -714,6 +711,11 @@ public X509Certificate[] getAcceptedIssuers() {
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new SecureRandom());
SSLSessionContext sslSessionContext = sc.getServerSessionContext();
int sessionCacheSize = sslSessionContext.getSessionCacheSize();
if (sessionCacheSize > 0) {
sslSessionContext.setSessionCacheSize(0);
}
HttpsURLConnection
.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
Expand Down Expand Up @@ -993,7 +995,7 @@ public static Bitmap makeTransparent(Bitmap bit, int transparentColor) {
}

public static double getDataReceived() {
return (double) TrafficStats.getUidRxBytes(android.os.Process
return (double) TrafficStats.getUidRxBytes(Process
.myUid()) / (1024 * 1024);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
import java.net.Socket;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.*;


/**
Expand All @@ -30,14 +27,23 @@ public class TLSSocketFactoryCompat extends SSLSocketFactory {
public TLSSocketFactoryCompat() throws KeyManagementException, NoSuchAlgorithmException {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, null, null);
SSLSessionContext sslSessionContext = context.getServerSessionContext();
int sessionCacheSize = sslSessionContext.getSessionCacheSize();
if (sessionCacheSize > 0) {
sslSessionContext.setSessionCacheSize(0);
}
internalSSLSocketFactory = context.getSocketFactory();
}


public TLSSocketFactoryCompat(final TrustManager[] tm)
throws KeyManagementException, NoSuchAlgorithmException {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, tm, new java.security.SecureRandom());
context.init(null, tm, new SecureRandom());
SSLSessionContext sslSessionContext = context.getServerSessionContext();
int sessionCacheSize = sslSessionContext.getSessionCacheSize();
if (sessionCacheSize > 0) {
sslSessionContext.setSessionCacheSize(0);
}
internalSSLSocketFactory = context.getSocketFactory();
}

Expand Down