pakstr 0.8.6 → 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 -0
- package/android-template/app/src/main/java/com/pakstr/app/debug/DebugReportExporter.kt +1 -1
- package/android-template/app/src/main/java/com/pakstr/app/debug/DeveloperToolsActivity.kt +1 -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 +31 -4
- 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
|
@@ -209,6 +209,7 @@ class MainActivity : AppCompatActivity(), PermissionHandler {
|
|
|
209
209
|
private fun setupSupportUnlockGesture() {
|
|
210
210
|
supportUnlockGestureLayout.onUnlock = {
|
|
211
211
|
SupportUnlock.unlock(this)
|
|
212
|
+
WebViewDebugManager.enable(this)
|
|
212
213
|
Toast.makeText(
|
|
213
214
|
this,
|
|
214
215
|
R.string.diagnostics_mode_enabled,
|
|
@@ -289,6 +290,7 @@ class MainActivity : AppCompatActivity(), PermissionHandler {
|
|
|
289
290
|
override fun onResume() {
|
|
290
291
|
super.onResume()
|
|
291
292
|
|
|
293
|
+
WebViewDebugManager.enable(this)
|
|
292
294
|
if (::fab.isInitialized) {
|
|
293
295
|
showDebugFab()
|
|
294
296
|
}
|
|
@@ -129,7 +129,7 @@ class DeveloperToolsActivity : AppCompatActivity() {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
private fun isWebViewDebugEnabled(): Boolean {
|
|
132
|
-
return
|
|
132
|
+
return WebViewDebugManager.isInspectionAllowed(this)
|
|
133
133
|
}
|
|
134
134
|
|
|
135
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
|
+
}
|
|
@@ -6,15 +6,36 @@ import com.pakstr.app.BuildConfig
|
|
|
6
6
|
|
|
7
7
|
object WebViewDebugManager {
|
|
8
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
|
+
}
|
|
9
31
|
|
|
10
32
|
fun enable(
|
|
11
33
|
context: Context
|
|
12
34
|
) {
|
|
13
35
|
|
|
14
|
-
val enabled =
|
|
15
|
-
SupportUnlock.isActive(context)
|
|
36
|
+
val enabled = isInspectionAllowed(context)
|
|
16
37
|
|
|
17
|
-
|
|
38
|
+
setWebContentsDebuggingEnabled(enabled)
|
|
18
39
|
|
|
19
40
|
AppDebugLogger.log(
|
|
20
41
|
context,
|
|
@@ -22,4 +43,10 @@ object WebViewDebugManager {
|
|
|
22
43
|
"WebView debugging enabled: $enabled"
|
|
23
44
|
)
|
|
24
45
|
}
|
|
25
|
-
|
|
46
|
+
|
|
47
|
+
internal fun setWebContentsDebuggingEnabled(
|
|
48
|
+
enabled: Boolean
|
|
49
|
+
) {
|
|
50
|
+
debuggingStateApplier(enabled)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -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
|
+
}
|