Skip to content
Open
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
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.facebook.stetho:stetho-js-rhino:1.4.2'
implementation 'com.facebook.stetho:stetho-okhttp:1.5.0'
implementation 'com.facebook.stetho:stetho-okhttp3:1.3.1'
}
41 changes: 41 additions & 0 deletions app/src/main/java/saarland/cispa/artist/codelib/CodeLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@
package saarland.cispa.artist.codelib;

import android.content.Context;
import android.util.ArraySet;
import android.util.Log;

import com.facebook.stetho.Stetho;
import com.facebook.stetho.okhttp.StethoInterceptor;

import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

import okhttp3.OkHttpClient.Builder;
import com.squareup.okhttp.OkHttpClient;

public class CodeLib {

@interface Inject {
Expand Down Expand Up @@ -74,4 +80,39 @@ public void initStetho(Object obj) {
}

}

private final Set<Object> okhttp2blacklist = new ArraySet<>();

@Inject
@SuppressWarnings("unused")
public void okhttp2interceptor(Object obj) {
// blacklist required to prevent infinite loop as the method is injected into OkHttpClient.networkInterceptors()
if (obj != null && obj instanceof OkHttpClient) {
synchronized (okhttp2blacklist) {
if (!okhttp2blacklist.contains(obj)) {
try {
okhttp2blacklist.add(obj);
((OkHttpClient) obj).networkInterceptors().add(new StethoInterceptor());
Log.w(TAG, "Injected OkHttp2 interceptor");
} catch (RuntimeException e) {
okhttp2blacklist.remove(obj);
Log.w(TAG, e);
}
}
}
}
}

@Inject
@SuppressWarnings("unused")
public void okhttp3interceptor(Object obj){
try {
((Builder) obj).addNetworkInterceptor(new com.facebook.stetho.okhttp3.StethoInterceptor());
Log.w(TAG, "Injected OkHttp3 Interceptor");
} catch (RuntimeException e) {
Log.w(TAG, e);
}
}


}