Skip to content
This repository was archived by the owner on Dec 18, 2022. It is now read-only.

Commit 77c2e31

Browse files
authored
Merge pull request #113 from 05nelsonm/development
Merge development branch for 2.1.0 release
2 parents 445deda + 1708bc8 commit 77c2e31

47 files changed

Lines changed: 1158 additions & 316 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ android.enableJetifier=true
2323
kotlin.code.style=official
2424

2525
GROUP=io.matthewnelson.topl-android
26-
VERSION_NAME=2.0.3-SNAPSHOT
26+
VERSION_NAME=2.0.3i-SNAPSHOT
2727

2828
# The trailing 2 digits are for `alpha##` releases. For example:
2929
# 4.4.1-alpha02 = 441102 where `102` stands for alpha02

gradle/dependencies.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ ext.versions = [
33
'compileSdk': 30,
44
'minSdk': 16,
55

6-
'coroutines': '1.4.0-M1',
6+
'coroutines': '1.4.2',
77
'lifecycle': '2.2.0',
8-
'kotlin': '1.4.10',
9-
'navigation': '2.3.1',
8+
'kotlin': '1.4.21-2',
9+
'navigation': '2.3.3',
1010
]
1111

1212
/**
@@ -44,13 +44,13 @@ ext.deps = [
4444
]
4545

4646
ext.plugin = [
47-
androidGradle: "com.android.tools.build:gradle:4.1.0",
48-
gradleVersions: "com.github.ben-manes:gradle-versions-plugin:0.33.0",
47+
androidGradle: "com.android.tools.build:gradle:4.1.2",
48+
gradleVersions: "com.github.ben-manes:gradle-versions-plugin:0.36.0",
4949
kotlin: [
5050
dokka: "org.jetbrains.dokka:dokka-gradle-plugin:0.10.1",
5151
gradle: "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}",
5252
],
53-
mavenPublish: "com.vanniktech:gradle-maven-publish-plugin:0.12.0",
53+
mavenPublish: "com.vanniktech:gradle-maven-publish-plugin:0.13.0",
5454
]
5555

5656
/**
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
# https://gradle.org/release-checksums/
4-
distributionSha256Sum=0080de8491f0918e4f529a6db6820fa0b9e818ee2386117f4394f95feb1d5583
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
4+
distributionSha256Sum=3db89524a3981819ff28c3f979236c1274a726e146ced0c8a2020417f9bc0782
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-all.zip
66
zipStoreBase=GRADLE_USER_HOME
77
zipStorePath=wrapper/dists

sampleapp/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
3-
apply plugin: 'kotlin-android-extensions'
43

54
android {
65
packagingOptions {
@@ -102,7 +101,7 @@ dependencies {
102101
implementation deps.kotlin.stdlib
103102

104103
implementation 'io.matthewnelson.encrypted-storage:encrypted-storage:2.0.1'
105-
implementation 'io.matthewnelson.topl-android:tor-binary:0.4.4.0'
104+
implementation 'io.matthewnelson.topl-android:tor-binary:0.4.5.4'
106105

107106
testImplementation testDeps.junit
108107
}

sampleapp/src/main/java/io/matthewnelson/sampleapp/App.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import android.content.Intent
7777
import android.os.Process
7878
import io.matthewnelson.encrypted_storage.Prefs
7979
import io.matthewnelson.sampleapp.topl_android.MyEventBroadcaster
80+
import io.matthewnelson.sampleapp.topl_android.MyServiceExecutionHooks
8081
import io.matthewnelson.sampleapp.topl_android.MyTorSettings
8182
import io.matthewnelson.sampleapp.ui.MainActivity
8283
import io.matthewnelson.sampleapp.ui.fragments.dashboard.DashMessage
@@ -186,6 +187,7 @@ class App: Application() {
186187
.disableStopServiceOnTaskRemoved(stopServiceOnTaskRemoved)
187188
.setBuildConfigDebug(buildConfigDebug)
188189
.setEventBroadcaster(eventBroadcaster = MyEventBroadcaster())
190+
.setServiceExecutionHooks(executionHooks = MyServiceExecutionHooks())
189191
}
190192
}
191193

sampleapp/src/main/java/io/matthewnelson/sampleapp/topl_android/CodeSamples.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ class CodeSamples {
178178
// TorServiceController.Companion?.appEventBroadcaster and cast what's returned
179179
// as MyEventBroadcaster
180180
.setEventBroadcaster(eventBroadcaster = MyEventBroadcaster())
181+
.setServiceExecutionHooks(executionHooks = MyServiceExecutionHooks())
181182

182183
// Only needed if you wish to customize the directories/files used by Tor if
183184
// the defaults aren't to your liking.

sampleapp/src/main/java/io/matthewnelson/sampleapp/topl_android/MyEventBroadcaster.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ class MyEventBroadcaster: TorServiceEventBroadcaster() {
9696
_liveTorPortInfo.value = torPortInfo
9797
}
9898

99+
override fun broadcastServiceLifecycleEvent(event: String, hashCode: Int) {
100+
broadcastLogMessage("NOTICE|TorService|LCE=$event - HashCode=$hashCode")
101+
}
102+
99103

100104
/////////////////
101105
/// Bandwidth ///
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
package io.matthewnelson.sampleapp.topl_android
2+
3+
import android.content.Context
4+
import io.matthewnelson.topl_core_base.BaseConsts.BroadcastType
5+
import io.matthewnelson.topl_service.TorServiceController
6+
import io.matthewnelson.topl_service_base.ServiceExecutionHooks
7+
import kotlinx.coroutines.Dispatchers
8+
import kotlinx.coroutines.delay
9+
import kotlinx.coroutines.withContext
10+
11+
class MyServiceExecutionHooks: ServiceExecutionHooks() {
12+
13+
override suspend fun executeOnCreateTorService(context: Context) {
14+
// Executed on Dispatchers.Default, so querying shared prefs has to switch
15+
// context to IO.
16+
withContext(Dispatchers.Main) {
17+
TorServiceController.getServiceTorSettings()
18+
}.let { settings ->
19+
withContext(Dispatchers.IO) {
20+
settings.hasDebugLogs
21+
}.let { debugLogs ->
22+
if (!debugLogs) {
23+
return
24+
}
25+
26+
withContext(Dispatchers.Main) {
27+
TorServiceController.appEventBroadcaster?.broadcastDebug(
28+
"${BroadcastType.DEBUG}|" +
29+
"${this@MyServiceExecutionHooks.javaClass.simpleName}|" +
30+
"onCreateTorService execution hook started"
31+
)
32+
33+
delay(20_000L)
34+
35+
TorServiceController.appEventBroadcaster?.broadcastDebug(
36+
"${BroadcastType.DEBUG}|" +
37+
"${this@MyServiceExecutionHooks.javaClass.simpleName}|" +
38+
"onCreateTorService execution hook completed"
39+
)
40+
}
41+
}
42+
}
43+
}
44+
45+
override suspend fun executeOnStartCommandBeforeStartTor(context: Context) {
46+
// Executed on Dispatchers.Default, so querying shared prefs has to switch
47+
// context to IO.
48+
withContext(Dispatchers.Main) {
49+
TorServiceController.getServiceTorSettings()
50+
}.let { settings ->
51+
withContext(Dispatchers.IO) {
52+
settings.hasDebugLogs
53+
}.let { debugLogs ->
54+
if (!debugLogs) {
55+
return
56+
}
57+
58+
withContext(Dispatchers.Main) {
59+
TorServiceController.appEventBroadcaster?.broadcastDebug(
60+
"${BroadcastType.DEBUG}|" +
61+
"${this@MyServiceExecutionHooks.javaClass.simpleName}|" +
62+
"OnStartCommandBeforeStartTor execution hook started"
63+
)
64+
65+
delay(1_000L)
66+
67+
TorServiceController.appEventBroadcaster?.broadcastDebug(
68+
"${BroadcastType.DEBUG}|" +
69+
"${this@MyServiceExecutionHooks.javaClass.simpleName}|" +
70+
"OnStartCommandBeforeStartTor execution hook completed"
71+
)
72+
}
73+
}
74+
}
75+
}
76+
77+
override suspend fun executeBeforeStartTor(context: Context) {
78+
// Executed on Dispatchers.IO
79+
withContext(Dispatchers.Main) {
80+
TorServiceController.getServiceTorSettings()
81+
}.let { settings ->
82+
if (!settings.hasDebugLogs) {
83+
return
84+
}
85+
86+
withContext(Dispatchers.Main) {
87+
TorServiceController.appEventBroadcaster?.broadcastDebug(
88+
"${BroadcastType.DEBUG}|" +
89+
"${this@MyServiceExecutionHooks.javaClass.simpleName}|" +
90+
"BeforeStartTor execution hook started"
91+
)
92+
93+
delay(500L)
94+
95+
TorServiceController.appEventBroadcaster?.broadcastDebug(
96+
"${BroadcastType.DEBUG}|" +
97+
"${this@MyServiceExecutionHooks.javaClass.simpleName}|" +
98+
"BeforeStartTor execution hook completed"
99+
)
100+
}
101+
}
102+
}
103+
104+
override suspend fun executeAfterStopTor(context: Context) {
105+
// Executed on Dispatchers.IO
106+
withContext(Dispatchers.Main) {
107+
TorServiceController.getServiceTorSettings()
108+
}.let { settings ->
109+
if (!settings.hasDebugLogs) {
110+
return
111+
}
112+
113+
withContext(Dispatchers.Main) {
114+
TorServiceController.appEventBroadcaster?.broadcastDebug(
115+
"${BroadcastType.DEBUG}|" +
116+
"${this@MyServiceExecutionHooks.javaClass.simpleName}|" +
117+
"AfterStopTor execution hook started"
118+
)
119+
120+
delay(500L)
121+
122+
TorServiceController.appEventBroadcaster?.broadcastDebug(
123+
"${BroadcastType.DEBUG}|" +
124+
"${this@MyServiceExecutionHooks.javaClass.simpleName}|" +
125+
"AfterStopTor execution hook completed"
126+
)
127+
}
128+
}
129+
}
130+
131+
override suspend fun executeBeforeStoppingService(context: Context) {
132+
// Executed on Dispatchers.IO
133+
withContext(Dispatchers.Main) {
134+
TorServiceController.getServiceTorSettings()
135+
}.let { settings ->
136+
if (!settings.hasDebugLogs) {
137+
return
138+
}
139+
140+
withContext(Dispatchers.Main) {
141+
TorServiceController.appEventBroadcaster?.broadcastDebug(
142+
"${BroadcastType.DEBUG}|" +
143+
"${this@MyServiceExecutionHooks.javaClass.simpleName}|" +
144+
"BeforeStoppingService execution hook started"
145+
)
146+
147+
delay(2_000L)
148+
149+
TorServiceController.appEventBroadcaster?.broadcastDebug(
150+
"${BroadcastType.DEBUG}|" +
151+
"${this@MyServiceExecutionHooks.javaClass.simpleName}|" +
152+
"BeforeStoppingService execution hook completed"
153+
)
154+
}
155+
}
156+
}
157+
}

topl-core-base/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
3-
apply plugin: 'kotlin-android-extensions'
43
apply from: rootProject.file('gradle/maven-publish.gradle')
54

65
android {

topl-core/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
3-
apply plugin: 'kotlin-android-extensions'
43
apply from: rootProject.file('gradle/maven-publish.gradle')
54

65
android {

0 commit comments

Comments
 (0)