Clears out diagnostic code.

main
Vavassor 8 years ago
parent 48c9b71f92
commit b9ea3bf185
  1. 15
      app/src/main/java/com/keylesspalace/tusky/Log.java
  2. 6
      app/src/main/java/com/keylesspalace/tusky/LoginActivity.java
  3. 38
      app/src/main/java/com/keylesspalace/tusky/OkHttpUtils.java
  4. 23
      app/src/main/res/layout/activity_login.xml

@ -18,15 +18,10 @@ package com.keylesspalace.tusky;
/**A wrapper for android.util.Log that allows for disabling logging, such as for release builds.*/
public class Log {
private static final boolean LOGGING_ENABLED = BuildConfig.DEBUG;
private static String longBoy;
private static String watchedTag;
public static void i(String tag, String string) {
if (LOGGING_ENABLED) {
android.util.Log.i(tag, string);
if (tag.equals(watchedTag)) {
longBoy += string + '\n';
}
}
}
@ -53,14 +48,4 @@ public class Log {
android.util.Log.w(tag, string);
}
}
static void watchTag(String tag) {
longBoy = "";
watchedTag = tag;
}
static String getWatchedMessages() {
watchedTag = null;
return longBoy;
}
}

@ -59,7 +59,6 @@ public class LoginActivity extends AppCompatActivity {
@BindView(R.id.edit_text_domain) EditText editText;
@BindView(R.id.button_login) Button button;
@BindView(R.id.whats_an_instance) TextView whatsAnInstance;
@BindView(R.id.debug_log_display) TextView debugLogDisplay;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -190,14 +189,11 @@ public class LoginActivity extends AppCompatActivity {
clientSecret = prefClientSecret;
redirectUserToAuthorizeAndLogin(editText);
} else {
Log.watchTag(OkHttpUtils.TAG);
Callback<AppCredentials> callback = new Callback<AppCredentials>() {
@Override
public void onResponse(Call<AppCredentials> call,
Response<AppCredentials> response) {
if (!response.isSuccessful()) {
debugLogDisplay.setText(Log.getWatchedMessages());
editText.setError(getString(R.string.error_failed_app_registration));
Log.e(TAG, "App authentication failed. " + response.message());
return;
@ -209,13 +205,11 @@ public class LoginActivity extends AppCompatActivity {
editor.putString(domain + "/client_id", clientId);
editor.putString(domain + "/client_secret", clientSecret);
editor.apply();
Log.watchTag(null);
redirectUserToAuthorizeAndLogin(editText);
}
@Override
public void onFailure(Call<AppCredentials> call, Throwable t) {
debugLogDisplay.setText(Log.getWatchedMessages());
editText.setError(getString(R.string.error_failed_app_registration));
t.printStackTrace();
}

@ -29,8 +29,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.net.ssl.HandshakeCompletedEvent;
import javax.net.ssl.HandshakeCompletedListener;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
@ -77,7 +75,7 @@ class OkHttpUtils {
}
private static OkHttpClient.Builder enableHigherTlsOnPreLollipop(OkHttpClient.Builder builder) {
// if (Build.VERSION.SDK_INT >= 16 && Build.VERSION.SDK_INT < 22) {
if (Build.VERSION.SDK_INT >= 16 && Build.VERSION.SDK_INT < 22) {
try {
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
@ -99,7 +97,7 @@ class OkHttpUtils {
} catch (NoSuchAlgorithmException|KeyStoreException|KeyManagementException e) {
Log.e(TAG, "Failed enabling TLS 1.1 & 1.2. " + e.getMessage());
}
// }
}
return builder;
}
@ -160,44 +158,12 @@ class OkHttpUtils {
return a.toArray(new String[0]);
}
@NonNull
private static List<String> getDifferences(String[] wanted, String[] have) {
List<String> a = new ArrayList<>(Arrays.asList(wanted));
List<String> b = Arrays.asList(have);
a.removeAll(b);
return a;
}
private Socket patch(Socket socket) {
if (socket instanceof SSLSocket) {
SSLSocket sslSocket = (SSLSocket) socket;
String[] protocols = getMatches(DESIRED_TLS_VERSIONS,
sslSocket.getSupportedProtocols());
sslSocket.setEnabledProtocols(protocols);
// Add a debug listener.
String[] enabledProtocols = sslSocket.getEnabledProtocols();
List<String> disabledProtocols = getDifferences(sslSocket.getSupportedProtocols(),
enabledProtocols);
String[] enabledSuites = sslSocket.getEnabledCipherSuites();
List<String> disabledSuites = getDifferences(sslSocket.getSupportedCipherSuites(),
enabledSuites);
Log.i(TAG, "Socket Created-----");
Log.i(TAG, "enabled protocols: " + Arrays.toString(enabledProtocols));
Log.i(TAG, "disabled protocols: " + disabledProtocols.toString());
Log.i(TAG, "enabled cipher suites: " + Arrays.toString(enabledSuites));
Log.i(TAG, "disabled cipher suites: " + disabledSuites.toString());
sslSocket.addHandshakeCompletedListener(new HandshakeCompletedListener() {
@Override
public void handshakeCompleted(HandshakeCompletedEvent event) {
String host = event.getSession().getPeerHost();
String protocol = event.getSession().getProtocol();
String cipherSuite = event.getCipherSuite();
Log.i(TAG, String.format("Handshake: %s %s %s", host, protocol,
cipherSuite));
}
});
}
return socket;
}

@ -13,34 +13,11 @@
android:gravity="center"
android:layout_height="wrap_content">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="300dp">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#000000"
android:layout_marginBottom="25dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/debug_log_display"
android:textIsSelectable="true"
android:textColor="#ffffff" />
</ScrollView>
</HorizontalScrollView>
<!--
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:src="@drawable/elephant_friend"/>
-->
<android.support.design.widget.TextInputLayout
android:layout_height="wrap_content"

Loading…
Cancel
Save