pakstr 0.8.5 → 0.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android-template/app/src/main/java/com/pakstr/app/MainActivity.kt +2 -1
- package/android-template/app/src/main/java/com/pakstr/app/RuntimeConfig.kt +22 -25
- package/android-template/app/src/main/java/com/pakstr/app/WebViewController.kt +3 -1
- package/android-template/app/src/main/java/com/pakstr/app/debug/AppDebugLogger.kt +37 -40
- package/android-template/app/src/main/java/com/pakstr/app/debug/DebugReportExporter.kt +2 -26
- package/android-template/app/src/main/java/com/pakstr/app/debug/DeveloperToolsAccessManager.kt +0 -3
- package/android-template/app/src/main/java/com/pakstr/app/debug/DeveloperToolsActivity.kt +7 -1
- package/android-template/app/src/main/java/com/pakstr/app/debug/DeviceDeveloperState.kt +23 -0
- package/android-template/app/src/main/java/com/pakstr/app/debug/WebViewDebugManager.kt +33 -11
- package/android-template/app/src/main/java/com/pakstr/app/debug/logging/PakstrLogger.kt +8 -0
- package/android-template/app/src/test/java/com/pakstr/app/debug/DeviceDeveloperStateTest.kt +21 -0
- package/android-template/app/src/test/java/com/pakstr/app/debug/WebViewDebugManagerTest.kt +84 -0
- package/package.json +1 -1
|
@@ -190,7 +190,6 @@ class MainActivity : AppCompatActivity(), PermissionHandler {
|
|
|
190
190
|
|
|
191
191
|
val remainingDuration = SupportUnlock.remainingDuration(this)
|
|
192
192
|
if (!BuildConfig.DEBUG &&
|
|
193
|
-
!RuntimeConfig.debugEnabled(this) &&
|
|
194
193
|
remainingDuration > 0L
|
|
195
194
|
) {
|
|
196
195
|
diagnosticsHandler.postDelayed(
|
|
@@ -210,6 +209,7 @@ class MainActivity : AppCompatActivity(), PermissionHandler {
|
|
|
210
209
|
private fun setupSupportUnlockGesture() {
|
|
211
210
|
supportUnlockGestureLayout.onUnlock = {
|
|
212
211
|
SupportUnlock.unlock(this)
|
|
212
|
+
WebViewDebugManager.enable(this)
|
|
213
213
|
Toast.makeText(
|
|
214
214
|
this,
|
|
215
215
|
R.string.diagnostics_mode_enabled,
|
|
@@ -290,6 +290,7 @@ class MainActivity : AppCompatActivity(), PermissionHandler {
|
|
|
290
290
|
override fun onResume() {
|
|
291
291
|
super.onResume()
|
|
292
292
|
|
|
293
|
+
WebViewDebugManager.enable(this)
|
|
293
294
|
if (::fab.isInitialized) {
|
|
294
295
|
showDebugFab()
|
|
295
296
|
}
|
|
@@ -14,7 +14,7 @@ object RuntimeConfig {
|
|
|
14
14
|
fun load(context: Context): JSONObject {
|
|
15
15
|
|
|
16
16
|
config?.let {
|
|
17
|
-
|
|
17
|
+
debug("Returning cached config")
|
|
18
18
|
return it
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -33,8 +33,9 @@ object RuntimeConfig {
|
|
|
33
33
|
|
|
34
34
|
} catch (e: Exception) {
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
debugError(
|
|
37
|
+
"Failed loading runtime config",
|
|
38
|
+
e
|
|
38
39
|
)
|
|
39
40
|
|
|
40
41
|
JSONObject()
|
|
@@ -42,9 +43,7 @@ object RuntimeConfig {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
TAG, "FINAL CONFIG: $config"
|
|
47
|
-
)
|
|
46
|
+
debug("Runtime config loaded")
|
|
48
47
|
|
|
49
48
|
|
|
50
49
|
return config!!
|
|
@@ -66,9 +65,7 @@ object RuntimeConfig {
|
|
|
66
65
|
)
|
|
67
66
|
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
TAG, "apiBase=$value"
|
|
71
|
-
)
|
|
68
|
+
debug("apiBase=$value")
|
|
72
69
|
|
|
73
70
|
|
|
74
71
|
return value.takeIf {
|
|
@@ -86,9 +83,7 @@ object RuntimeConfig {
|
|
|
86
83
|
val enabled = !apiBase(context).isNullOrBlank()
|
|
87
84
|
|
|
88
85
|
|
|
89
|
-
|
|
90
|
-
TAG, "apiEnabled=$enabled"
|
|
91
|
-
)
|
|
86
|
+
debug("apiEnabled=$enabled")
|
|
92
87
|
|
|
93
88
|
|
|
94
89
|
return enabled
|
|
@@ -106,9 +101,7 @@ object RuntimeConfig {
|
|
|
106
101
|
)
|
|
107
102
|
|
|
108
103
|
|
|
109
|
-
|
|
110
|
-
TAG, "relayUrl=$relay"
|
|
111
|
-
)
|
|
104
|
+
debug("relayUrl=$relay")
|
|
112
105
|
|
|
113
106
|
|
|
114
107
|
return relay
|
|
@@ -142,13 +135,7 @@ object RuntimeConfig {
|
|
|
142
135
|
|
|
143
136
|
?: false
|
|
144
137
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
TAG,
|
|
148
|
-
|
|
149
|
-
"debugEnabled=$enabled"
|
|
150
|
-
|
|
151
|
-
)
|
|
138
|
+
debug("debugEnabled=$enabled")
|
|
152
139
|
|
|
153
140
|
return enabled
|
|
154
141
|
|
|
@@ -162,9 +149,19 @@ object RuntimeConfig {
|
|
|
162
149
|
|
|
163
150
|
config = null
|
|
164
151
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
152
|
+
debug("Config cache cleared")
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private fun debug(message: String) {
|
|
156
|
+
if (BuildConfig.DEBUG) {
|
|
157
|
+
Log.d(TAG, message)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private fun debugError(message: String, throwable: Throwable) {
|
|
162
|
+
if (BuildConfig.DEBUG) {
|
|
163
|
+
Log.e(TAG, message, throwable)
|
|
164
|
+
}
|
|
168
165
|
}
|
|
169
166
|
|
|
170
167
|
fun debugConfig(
|
|
@@ -33,16 +33,18 @@ object AppDebugLogger {
|
|
|
33
33
|
return
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
val sanitized = sanitize(message)
|
|
37
|
+
|
|
36
38
|
save(
|
|
37
39
|
context,
|
|
38
40
|
"DEBUG",
|
|
39
41
|
tag,
|
|
40
|
-
|
|
42
|
+
sanitized
|
|
41
43
|
)
|
|
42
44
|
|
|
43
45
|
Log.d(
|
|
44
46
|
TAG,
|
|
45
|
-
"[$tag] $
|
|
47
|
+
"[$tag] $sanitized"
|
|
46
48
|
)
|
|
47
49
|
}
|
|
48
50
|
|
|
@@ -61,20 +63,20 @@ object AppDebugLogger {
|
|
|
61
63
|
} else {
|
|
62
64
|
message
|
|
63
65
|
}
|
|
66
|
+
val sanitized = sanitize(fullMessage)
|
|
64
67
|
|
|
65
68
|
|
|
66
69
|
save(
|
|
67
70
|
context,
|
|
68
71
|
"ERROR",
|
|
69
72
|
tag,
|
|
70
|
-
|
|
73
|
+
sanitized
|
|
71
74
|
)
|
|
72
75
|
|
|
73
76
|
|
|
74
77
|
Log.e(
|
|
75
78
|
TAG,
|
|
76
|
-
"[$tag] $
|
|
77
|
-
throwable
|
|
79
|
+
"[$tag] $sanitized"
|
|
78
80
|
)
|
|
79
81
|
}
|
|
80
82
|
|
|
@@ -85,14 +87,11 @@ object AppDebugLogger {
|
|
|
85
87
|
message: String
|
|
86
88
|
) {
|
|
87
89
|
|
|
88
|
-
val sanitized =
|
|
89
|
-
sanitize(message)
|
|
90
|
-
|
|
91
90
|
val entry =
|
|
92
91
|
format(
|
|
93
92
|
level,
|
|
94
93
|
tag,
|
|
95
|
-
|
|
94
|
+
message
|
|
96
95
|
)
|
|
97
96
|
|
|
98
97
|
|
|
@@ -136,64 +135,62 @@ object AppDebugLogger {
|
|
|
136
135
|
|
|
137
136
|
}
|
|
138
137
|
|
|
139
|
-
|
|
138
|
+
internal fun sanitize(
|
|
140
139
|
message: String
|
|
141
140
|
): String {
|
|
142
141
|
|
|
143
|
-
// Debug build može vidjeti sve
|
|
144
142
|
if (BuildConfig.DEBUG) {
|
|
145
143
|
return message
|
|
146
144
|
}
|
|
147
145
|
|
|
148
|
-
// Release build uvijek sanitizira
|
|
149
146
|
return message
|
|
150
147
|
.replace(
|
|
151
148
|
Regex(
|
|
152
|
-
"\"plaintext\"\\s*:\\s*\"
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
"\"ciphertext\"\\s*:\\s*\".*?\""
|
|
159
|
-
),
|
|
160
|
-
"\"ciphertext\":\"***\""
|
|
161
|
-
)
|
|
149
|
+
"(?i)\"(plaintext|ciphertext|content|sig|signature|event|signing_?payload|private_?key|secret|seed|mnemonic|password|token|jwt|cookie|authorization)\"\\s*:\\s*\"(?:\\\\.|[^\"])*\""
|
|
150
|
+
)
|
|
151
|
+
) { match ->
|
|
152
|
+
val key = match.groupValues[1]
|
|
153
|
+
"\"$key\":\"***\""
|
|
154
|
+
}
|
|
162
155
|
.replace(
|
|
163
156
|
Regex(
|
|
164
|
-
"\"
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
|
|
157
|
+
"(?i)\"(event|signing_?payload)\"\\s*:\\s*(\\{[^\\r\\n]*}|\\[[^\\r\\n]*])"
|
|
158
|
+
)
|
|
159
|
+
) { match ->
|
|
160
|
+
val key = match.groupValues[1]
|
|
161
|
+
"\"$key\":\"***\""
|
|
162
|
+
}
|
|
168
163
|
.replace(
|
|
169
164
|
Regex(
|
|
170
|
-
"
|
|
171
|
-
)
|
|
172
|
-
|
|
173
|
-
|
|
165
|
+
"(?i)(authorization|proxy-authorization|cookie|set-cookie)\\s*:\\s*[^\\r\\n]+"
|
|
166
|
+
)
|
|
167
|
+
) { match ->
|
|
168
|
+
"${match.groupValues[1]}: ***"
|
|
169
|
+
}
|
|
174
170
|
.replace(
|
|
175
171
|
Regex(
|
|
176
|
-
"(?i)
|
|
172
|
+
"(?i)bearer\\s+[^\\s,;]+"
|
|
177
173
|
),
|
|
178
|
-
"
|
|
174
|
+
"Bearer ***"
|
|
179
175
|
)
|
|
180
176
|
.replace(
|
|
181
177
|
Regex(
|
|
182
|
-
"(?i)
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
|
|
178
|
+
"(?i)(token|auth_?token|jwt|password|private_?key|secret|seed|mnemonic|signature|sig|event|signing_?payload|plaintext|ciphertext|cookie)=([^\\s&]+)"
|
|
179
|
+
)
|
|
180
|
+
) { match ->
|
|
181
|
+
"${match.groupValues[1]}=***"
|
|
182
|
+
}
|
|
186
183
|
.replace(
|
|
187
184
|
Regex(
|
|
188
|
-
"(?i)
|
|
185
|
+
"(?i)\\b(nsec1)[023456789acdefghjklmnpqrstuvwxyz]+"
|
|
189
186
|
),
|
|
190
|
-
"
|
|
187
|
+
"nsec1***"
|
|
191
188
|
)
|
|
192
189
|
.replace(
|
|
193
190
|
Regex(
|
|
194
|
-
"
|
|
191
|
+
"\\beyJ[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\b"
|
|
195
192
|
),
|
|
196
|
-
"
|
|
193
|
+
"JWT***"
|
|
197
194
|
)
|
|
198
195
|
}
|
|
199
196
|
|
|
@@ -106,7 +106,7 @@ object DebugReportExporter {
|
|
|
106
106
|
${RuntimeConfig.apiEnabled(context)}
|
|
107
107
|
|
|
108
108
|
WebView Debug:
|
|
109
|
-
${
|
|
109
|
+
${WebViewDebugManager.isInspectionAllowed(context)}
|
|
110
110
|
|
|
111
111
|
Logs:
|
|
112
112
|
-------------------
|
|
@@ -120,30 +120,6 @@ object DebugReportExporter {
|
|
|
120
120
|
text: String
|
|
121
121
|
): String {
|
|
122
122
|
|
|
123
|
-
return text
|
|
124
|
-
.replace(
|
|
125
|
-
Regex("(?i)authorization:\\s*.*"),
|
|
126
|
-
"authorization: ***"
|
|
127
|
-
)
|
|
128
|
-
.replace(
|
|
129
|
-
Regex("(?i)bearer\\s+[a-zA-Z0-9._-]+"),
|
|
130
|
-
"Bearer ***"
|
|
131
|
-
)
|
|
132
|
-
.replace(
|
|
133
|
-
Regex("(?i)token=.*"),
|
|
134
|
-
"token=***"
|
|
135
|
-
)
|
|
136
|
-
.replace(
|
|
137
|
-
Regex("(?i)password=.*"),
|
|
138
|
-
"password=***"
|
|
139
|
-
)
|
|
140
|
-
.replace(
|
|
141
|
-
Regex("(?i)private.?key=.*"),
|
|
142
|
-
"privateKey=***"
|
|
143
|
-
)
|
|
144
|
-
.replace(
|
|
145
|
-
Regex("(?i)nsec[a-zA-Z0-9]+"),
|
|
146
|
-
"nsec***"
|
|
147
|
-
)
|
|
123
|
+
return AppDebugLogger.sanitize(text)
|
|
148
124
|
}
|
|
149
125
|
}
|
package/android-template/app/src/main/java/com/pakstr/app/debug/DeveloperToolsAccessManager.kt
CHANGED
|
@@ -2,13 +2,10 @@ package com.pakstr.app.debug
|
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import com.pakstr.app.BuildConfig
|
|
5
|
-
import com.pakstr.app.RuntimeConfig
|
|
6
|
-
|
|
7
5
|
object DeveloperToolsAccessManager {
|
|
8
6
|
|
|
9
7
|
fun canOpenDeveloperTools(context: Context): Boolean {
|
|
10
8
|
return BuildConfig.DEBUG ||
|
|
11
|
-
RuntimeConfig.debugEnabled(context) ||
|
|
12
9
|
SupportUnlock.isActive(context)
|
|
13
10
|
}
|
|
14
11
|
}
|
|
@@ -43,6 +43,12 @@ class DeveloperToolsActivity : AppCompatActivity() {
|
|
|
43
43
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
44
44
|
enableEdgeToEdge()
|
|
45
45
|
super.onCreate(savedInstanceState)
|
|
46
|
+
|
|
47
|
+
if (!DeveloperToolsAccessManager.canOpenDeveloperTools(this)) {
|
|
48
|
+
finish()
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
|
|
46
52
|
setContentView(R.layout.activity_developer_tools)
|
|
47
53
|
|
|
48
54
|
setupToolbar()
|
|
@@ -123,7 +129,7 @@ class DeveloperToolsActivity : AppCompatActivity() {
|
|
|
123
129
|
}
|
|
124
130
|
|
|
125
131
|
private fun isWebViewDebugEnabled(): Boolean {
|
|
126
|
-
return
|
|
132
|
+
return WebViewDebugManager.isInspectionAllowed(this)
|
|
127
133
|
}
|
|
128
134
|
|
|
129
135
|
private fun setupLogActions() {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package com.pakstr.app.debug
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.provider.Settings
|
|
5
|
+
|
|
6
|
+
object DeviceDeveloperState {
|
|
7
|
+
|
|
8
|
+
fun isAdbEnabled(context: Context): Boolean {
|
|
9
|
+
return isAdbEnabled {
|
|
10
|
+
Settings.Global.getInt(
|
|
11
|
+
context.contentResolver,
|
|
12
|
+
Settings.Global.ADB_ENABLED,
|
|
13
|
+
0
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
internal fun isAdbEnabled(
|
|
19
|
+
readSetting: () -> Int
|
|
20
|
+
): Boolean {
|
|
21
|
+
return readSetting() == 1
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,30 +1,52 @@
|
|
|
1
1
|
package com.pakstr.app.debug
|
|
2
2
|
|
|
3
|
-
import android.R.attr.enabled
|
|
4
3
|
import android.content.Context
|
|
5
4
|
import android.webkit.WebView
|
|
6
5
|
import com.pakstr.app.BuildConfig
|
|
7
|
-
import com.pakstr.app.RuntimeConfig
|
|
8
6
|
|
|
9
7
|
object WebViewDebugManager {
|
|
10
8
|
|
|
9
|
+
internal var debuggingStateApplier: (Boolean) -> Unit =
|
|
10
|
+
WebView::setWebContentsDebuggingEnabled
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
fun isInspectionAllowed(
|
|
14
|
+
context: Context
|
|
15
|
+
): Boolean {
|
|
16
|
+
return isInspectionAllowed(
|
|
17
|
+
isDebugBuild = BuildConfig.DEBUG,
|
|
18
|
+
isSupportUnlocked = SupportUnlock.isActive(context),
|
|
19
|
+
isAdbEnabled = DeviceDeveloperState.isAdbEnabled(context)
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
internal fun isInspectionAllowed(
|
|
24
|
+
isDebugBuild: Boolean,
|
|
25
|
+
isSupportUnlocked: Boolean,
|
|
26
|
+
isAdbEnabled: Boolean
|
|
27
|
+
): Boolean {
|
|
28
|
+
return isDebugBuild ||
|
|
29
|
+
(isSupportUnlocked && isAdbEnabled)
|
|
30
|
+
}
|
|
11
31
|
|
|
12
32
|
fun enable(
|
|
13
33
|
context: Context
|
|
14
34
|
) {
|
|
15
35
|
|
|
16
|
-
|
|
17
|
-
BuildConfig.DEBUG ||
|
|
18
|
-
RuntimeConfig.debugEnabled(context)
|
|
19
|
-
)
|
|
20
|
-
AppDebugLogger.log(
|
|
36
|
+
val enabled = isInspectionAllowed(context)
|
|
21
37
|
|
|
22
|
-
|
|
38
|
+
setWebContentsDebuggingEnabled(enabled)
|
|
23
39
|
|
|
40
|
+
AppDebugLogger.log(
|
|
41
|
+
context,
|
|
24
42
|
"WEBVIEW",
|
|
25
|
-
|
|
26
43
|
"WebView debugging enabled: $enabled"
|
|
27
|
-
|
|
28
44
|
)
|
|
29
45
|
}
|
|
30
|
-
|
|
46
|
+
|
|
47
|
+
internal fun setWebContentsDebuggingEnabled(
|
|
48
|
+
enabled: Boolean
|
|
49
|
+
) {
|
|
50
|
+
debuggingStateApplier(enabled)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package com.pakstr.app.debug.logging
|
|
2
2
|
|
|
3
3
|
import android.util.Log
|
|
4
|
+
import com.pakstr.app.BuildConfig
|
|
4
5
|
import com.pakstr.app.debug.logging.PakstrLog
|
|
5
6
|
import java.text.SimpleDateFormat
|
|
6
7
|
import java.util.Date
|
|
@@ -18,6 +19,8 @@ object PakstrLogger {
|
|
|
18
19
|
tag: String,
|
|
19
20
|
message: String
|
|
20
21
|
) {
|
|
22
|
+
if (!BuildConfig.DEBUG) return
|
|
23
|
+
|
|
21
24
|
add(
|
|
22
25
|
PakstrLog.Level.DEBUG,
|
|
23
26
|
tag,
|
|
@@ -35,6 +38,8 @@ object PakstrLogger {
|
|
|
35
38
|
tag: String,
|
|
36
39
|
message: String
|
|
37
40
|
) {
|
|
41
|
+
if (!BuildConfig.DEBUG) return
|
|
42
|
+
|
|
38
43
|
add(
|
|
39
44
|
PakstrLog.Level.INFO,
|
|
40
45
|
tag,
|
|
@@ -52,6 +57,8 @@ object PakstrLogger {
|
|
|
52
57
|
tag: String,
|
|
53
58
|
message: String
|
|
54
59
|
) {
|
|
60
|
+
if (!BuildConfig.DEBUG) return
|
|
61
|
+
|
|
55
62
|
add(
|
|
56
63
|
PakstrLog.Level.WARN,
|
|
57
64
|
tag,
|
|
@@ -70,6 +77,7 @@ object PakstrLogger {
|
|
|
70
77
|
message: String,
|
|
71
78
|
throwable: Throwable? = null
|
|
72
79
|
) {
|
|
80
|
+
if (!BuildConfig.DEBUG) return
|
|
73
81
|
|
|
74
82
|
add(
|
|
75
83
|
PakstrLog.Level.ERROR,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
package com.pakstr.app.debug
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.assertFalse
|
|
4
|
+
import org.junit.Assert.assertTrue
|
|
5
|
+
import org.junit.Test
|
|
6
|
+
|
|
7
|
+
class DeviceDeveloperStateTest {
|
|
8
|
+
|
|
9
|
+
@Test
|
|
10
|
+
fun adb_is_enabled_only_for_setting_value_one() {
|
|
11
|
+
assertTrue(
|
|
12
|
+
DeviceDeveloperState.isAdbEnabled { 1 }
|
|
13
|
+
)
|
|
14
|
+
assertFalse(
|
|
15
|
+
DeviceDeveloperState.isAdbEnabled { 0 }
|
|
16
|
+
)
|
|
17
|
+
assertFalse(
|
|
18
|
+
DeviceDeveloperState.isAdbEnabled { 2 }
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
package com.pakstr.app.debug
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.assertFalse
|
|
4
|
+
import org.junit.Assert.assertTrue
|
|
5
|
+
import org.junit.Test
|
|
6
|
+
|
|
7
|
+
class WebViewDebugManagerTest {
|
|
8
|
+
|
|
9
|
+
@Test
|
|
10
|
+
fun debug_build_allows_inspection_without_release_prerequisites() {
|
|
11
|
+
assertTrue(
|
|
12
|
+
WebViewDebugManager.isInspectionAllowed(
|
|
13
|
+
isDebugBuild = true,
|
|
14
|
+
isSupportUnlocked = false,
|
|
15
|
+
isAdbEnabled = false
|
|
16
|
+
)
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Test
|
|
21
|
+
fun release_allows_inspection_with_support_unlock_and_adb() {
|
|
22
|
+
assertTrue(
|
|
23
|
+
WebViewDebugManager.isInspectionAllowed(
|
|
24
|
+
isDebugBuild = false,
|
|
25
|
+
isSupportUnlocked = true,
|
|
26
|
+
isAdbEnabled = true
|
|
27
|
+
)
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Test
|
|
32
|
+
fun release_rejects_support_unlock_without_adb() {
|
|
33
|
+
assertFalse(
|
|
34
|
+
WebViewDebugManager.isInspectionAllowed(
|
|
35
|
+
isDebugBuild = false,
|
|
36
|
+
isSupportUnlocked = true,
|
|
37
|
+
isAdbEnabled = false
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Test
|
|
43
|
+
fun release_rejects_adb_without_support_unlock() {
|
|
44
|
+
assertFalse(
|
|
45
|
+
WebViewDebugManager.isInspectionAllowed(
|
|
46
|
+
isDebugBuild = false,
|
|
47
|
+
isSupportUnlocked = false,
|
|
48
|
+
isAdbEnabled = true
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@Test
|
|
54
|
+
fun release_rejects_inspection_without_either_prerequisite() {
|
|
55
|
+
assertFalse(
|
|
56
|
+
WebViewDebugManager.isInspectionAllowed(
|
|
57
|
+
isDebugBuild = false,
|
|
58
|
+
isSupportUnlocked = false,
|
|
59
|
+
isAdbEnabled = false
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Test
|
|
65
|
+
fun allowed_release_state_is_applied_to_webview_debugging() {
|
|
66
|
+
val appliedStates = mutableListOf<Boolean>()
|
|
67
|
+
val previous = WebViewDebugManager.debuggingStateApplier
|
|
68
|
+
WebViewDebugManager.debuggingStateApplier = appliedStates::add
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
val allowed =
|
|
72
|
+
WebViewDebugManager.isInspectionAllowed(
|
|
73
|
+
isDebugBuild = false,
|
|
74
|
+
isSupportUnlocked = true,
|
|
75
|
+
isAdbEnabled = true
|
|
76
|
+
)
|
|
77
|
+
WebViewDebugManager.setWebContentsDebuggingEnabled(allowed)
|
|
78
|
+
} finally {
|
|
79
|
+
WebViewDebugManager.debuggingStateApplier = previous
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
assertTrue(appliedStates.single())
|
|
83
|
+
}
|
|
84
|
+
}
|