Skip to content

Commit ad4f1c0

Browse files
adi23aroracpg
authored andcommitted
Remove Chuck Interceptor (#327)
* Comment the gradle dependecies * Remove code associated with Chuck Interceptor * Add directions to re-enable chuck Closes #322
1 parent 3cc275a commit ad4f1c0

File tree

4 files changed

+85
-19
lines changed

4 files changed

+85
-19
lines changed

DEBUG.md

+55-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,63 @@
11
# Debugging
22

3+
## Using a Custom Server
4+
35
Sometimes you may need to debug with some special purpose server. To do that, add a file like this
46

57
src/main/assets/customServers.json
68

79
with details of the custom server(s) you need, like this:
810

9-
```
10-
[
11-
{
12-
"name": "Test Server 1",
13-
"session_token": "12345678901234567",
14-
"local_address": "http://192.168.0.11:4563",
15-
"remote_address": "http://192.168.12.22:4563"
16-
},
17-
{
18-
"name": "Test Server 2",
19-
"session_token": "12345678901234567",
20-
"local_address": "http://192.168.0.11:4563",
21-
"remote_address": "http://192.168.12.22:4563"
22-
}
23-
]
24-
```
11+
```
12+
[
13+
{
14+
"name": "Test Server 1",
15+
"session_token": "12345678901234567",
16+
"local_address": "http://192.168.0.11:4563",
17+
"remote_address": "http://192.168.12.22:4563"
18+
},
19+
{
20+
"name": "Test Server 2",
21+
"session_token": "12345678901234567",
22+
"local_address": "http://192.168.0.11:4563",
23+
"remote_address": "http://192.168.12.22:4563"
24+
}
25+
]
26+
```
27+
28+
29+
## Enabling Chuck Interceptor
30+
31+
Some relevant information about Chuck Interceptor can be found [here](https://github.com/jgilfelt/chuck).
32+
33+
We have disabled Chuck Interceptor by default in Amahi App. But if you want to use it for debugging, you can enable it by following these steps :
34+
35+
1. Enable the dependencies in `build.gradle` by uncommenting the following code :
36+
37+
```
38+
debugImplementation 'com.readystatesoftware.chuck:library:1.1.0'
39+
releaseImplementation 'com.readystatesoftware.chuck:library-no-op:1.1.0'
40+
betaReleaseImplementation 'com.readystatesoftware.chuck:library-no-op:1.1.0'
41+
```
42+
43+
2. Now modify the `ApIModule.java` file to add the Chuck Interceptor :
44+
45+
* Creating an instance for Chuck Interceptor, by uncommenting following block of code:
46+
```
47+
@Provides
48+
@Singleton
49+
ChuckInterceptor provideChuckInterceptor(Context context) {
50+
return new ChuckInterceptor(context);
51+
}
52+
```
53+
54+
* Modify the function definition to pass Chuck Interceptor :
55+
```
56+
provideHttpClient(ApiHeaders headers, HttpLoggingInterceptor logging, ChuckInterceptor chuck)
57+
```
58+
59+
* Add the Chuck interceptor when building OkHttpClient, using:
60+
```
61+
clientBuilder.addInterceptor(chuck);
62+
```
63+

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,9 @@ This is something to keep **private** and you obtain it by asking in the [Amahi
5353
```
5454
$ ./gradlew clean assembleDebug generateDebugJavadoc
5555
```
56+
57+
## Debugging
58+
59+
* For debugging the APIs and logging requests and responses you can either use `Logcat` on Android Studio or enable `Chuck Interceptor` (UI based) from the steps given [here](DEBUG.md#enabling-chuck-interceptor).
60+
61+
* To debug with some special purpose server, you can find steps [here](DEBUG.md#using-a-custom-server).

build.gradle

+5
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,14 @@ dependencies {
145145
androidTestImplementation 'com.android.support:support-annotations:25.4.0'
146146
compileOnly 'com.squareup.dagger:dagger-compiler:1.2.5'
147147
implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever:1.0.14'
148+
149+
// Uncomment the dependencies below to enable Chuck Interceptor for logging
150+
/*
148151
debugImplementation 'com.readystatesoftware.chuck:library:1.1.0'
149152
releaseImplementation 'com.readystatesoftware.chuck:library-no-op:1.1.0'
150153
betaReleaseImplementation 'com.readystatesoftware.chuck:library-no-op:1.1.0'
154+
*/
155+
151156
}
152157

153158
task generateWrapper(type: Wrapper) {

src/main/java/org/amahi/anywhere/server/ApiModule.java

+19-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import com.google.gson.Gson;
2525
import com.google.gson.GsonBuilder;
26-
import com.readystatesoftware.chuck.ChuckInterceptor;
2726

2827
import org.amahi.anywhere.BuildConfig;
2928
import org.amahi.anywhere.util.Time;
@@ -41,18 +40,29 @@
4140
* API dependency injection module. Provides resources such as HTTP client and JSON converter
4241
* for possible consumers.
4342
*/
43+
4444
@Module(
4545
complete = false,
4646
library = true
4747
)
4848
public class ApiModule {
49+
50+
/**
51+
* After enabling the chuck dependencies modify the function definition below to pass ChuckInterceptor:
52+
* provideHttpClient(ApiHeaders headers, HttpLoggingInterceptor logging, ChuckInterceptor chuck)
53+
*
54+
* Add the Chuck interceptor when building OkHttpClient, using:
55+
* clientBuilder.addInterceptor(chuck);
56+
*/
57+
4958
@Provides
5059
@Singleton
51-
OkHttpClient provideHttpClient(ApiHeaders headers, HttpLoggingInterceptor logging, ChuckInterceptor chuck) {
60+
OkHttpClient provideHttpClient(ApiHeaders headers, HttpLoggingInterceptor logging) {
5261
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
62+
5363
clientBuilder.addInterceptor(headers);
5464
clientBuilder.addInterceptor(logging);
55-
clientBuilder.addInterceptor(chuck);
65+
5666
return clientBuilder.build();
5767
}
5868

@@ -62,11 +72,17 @@ ApiHeaders provideHeaders(Context context) {
6272
return new ApiHeaders(context);
6373
}
6474

75+
/**
76+
* Creating an instance for ChuckInterceptor and providing it with context
77+
* Uncomment the code below if using Chuck Interceptor for logging
78+
*/
79+
/*
6580
@Provides
6681
@Singleton
6782
ChuckInterceptor provideChuckInterceptor(Context context) {
6883
return new ChuckInterceptor(context);
6984
}
85+
*/
7086

7187
@Provides
7288
@Singleton

0 commit comments

Comments
 (0)