catalyst-core 0.0.3-canary.9 → 0.1.0-beta.2

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.
Files changed (182) hide show
  1. package/README.md +4 -5
  2. package/bin/catalyst.js +28 -15
  3. package/changelog.md +139 -30
  4. package/dist/native/androidProject/app/build.gradle.kts +125 -15
  5. package/dist/native/androidProject/app/proguard-rules.pro +85 -14
  6. package/dist/native/androidProject/app/src/debug/res/xml/network_security_config.xml +8 -0
  7. package/dist/native/androidProject/app/src/main/AndroidManifest.xml +10 -3
  8. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/BridgeMessageValidator.kt +552 -0
  9. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/CatalystConstants.kt +109 -0
  10. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/CustomWebview.kt +605 -124
  11. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MainActivity.kt +405 -47
  12. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MetricsMonitor.kt +341 -0
  13. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/NativeBridge.kt +954 -71
  14. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/SplashActivity.kt +111 -0
  15. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/URLWhitelistManager.kt +231 -0
  16. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/Utils.kt +49 -55
  17. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/WebCacheManager.kt +81 -8
  18. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/design/DesignTokens.kt +307 -0
  19. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/EmulatorDetector.kt +203 -0
  20. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/FridaDetector.kt +187 -0
  21. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityAlertHandler.kt +170 -0
  22. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityAlertUI.kt +366 -0
  23. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityBottomSheet.kt +138 -0
  24. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityCheckManager.kt +511 -0
  25. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityCheckScheduler.kt +68 -0
  26. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/BridgeUtils.kt +47 -11
  27. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/DeviceInfoUtils.kt +38 -13
  28. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/DownloadUtils.kt +36 -14
  29. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/FileUtils.kt +3 -2
  30. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/FrameworkServerUtils.kt +57 -8
  31. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/IntentUtils.kt +31 -6
  32. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/KeyboardUtil.kt +82 -0
  33. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/NetworkUtils.kt +105 -0
  34. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/NotificationConstants.kt +28 -0
  35. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/NotificationUtils.kt +639 -0
  36. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/SafeAreaUtils.kt +62 -0
  37. package/dist/native/androidProject/app/src/main/res/drawable/splashscreen_fallback.png +0 -0
  38. package/dist/native/androidProject/app/src/main/res/layout/activity_main.xml +1 -0
  39. package/dist/native/androidProject/app/src/main/res/layout/activity_splash.xml +20 -0
  40. package/dist/native/androidProject/app/src/main/res/values/themes.xml +23 -0
  41. package/dist/native/androidProject/app/src/main/res/values-night/themes.xml +11 -0
  42. package/dist/native/androidProject/app/src/main/res/xml/network_security_config.xml +12 -0
  43. package/dist/native/androidProject/app/src/noFcm/java/io/yourname/androidproject/utils/NotificationManager.kt +166 -0
  44. package/dist/native/androidProject/app/src/noFcm/java/io/yourname/androidproject/utils/PushNotificationUtils.kt +94 -0
  45. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/BridgeMessageValidatorTest.kt +267 -0
  46. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/BridgeUtilsTest.kt +286 -0
  47. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/CameraUtilsTest.kt +296 -0
  48. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/ConfigMappingTest.kt +594 -0
  49. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/CustomWebviewTest.kt +466 -0
  50. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/DeviceInfoUtilsTest.kt +187 -0
  51. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/FileUtilsTest.kt +304 -0
  52. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/NativeBridgeTest.kt +424 -0
  53. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/NotificationUtilsTest.kt +469 -0
  54. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/SecurityBridgeTest.kt +199 -0
  55. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/URLWhitelistManagerTest.kt +462 -0
  56. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/WebCacheManagerTest.kt +391 -0
  57. package/dist/native/androidProject/app/src/withFcm/java/io/yourname/androidproject/utils/NotificationManager.kt +224 -0
  58. package/dist/native/androidProject/app/src/withFcm/java/io/yourname/androidproject/utils/PushNotificationUtils.kt +399 -0
  59. package/dist/native/androidProject/build.gradle.kts +6 -0
  60. package/dist/native/androidProject/gradle/libs.versions.toml +8 -2
  61. package/dist/native/androidSetup.js +4 -3
  62. package/dist/native/assets/catalyst.png +0 -0
  63. package/dist/native/bridge/WebBridge.js +16 -3
  64. package/dist/native/bridge/constants/NativeInterfaces.js +28 -10
  65. package/dist/native/bridge/errors.js +1 -1
  66. package/dist/native/bridge/hooks.js +76 -16
  67. package/dist/native/bridge/safeArea.js +5 -0
  68. package/dist/native/bridge/standardizedHooks.js +23 -5
  69. package/dist/native/bridge/useBaseHook.js +7 -9
  70. package/dist/native/bridge/utils/CameraUtils.js +58 -0
  71. package/dist/native/bridge/utils/FileObjectConverter.js +40 -0
  72. package/dist/native/bridge/utils/NativeBridge.js +57 -8
  73. package/dist/native/buildAppAndroid.js +115 -43
  74. package/dist/native/buildAppIos.js +291 -26
  75. package/dist/native/iosnativeWebView/Configurations/Debug.xcconfig +21 -0
  76. package/dist/native/iosnativeWebView/Configurations/Release.xcconfig +24 -0
  77. package/dist/native/iosnativeWebView/Configurations/Shared.xcconfig +50 -0
  78. package/dist/native/iosnativeWebView/Package.resolved +32 -0
  79. package/dist/native/iosnativeWebView/Package.swift +37 -0
  80. package/dist/native/iosnativeWebView/Sources/CatalystNotifications/LocalNotificationHandler.swift +293 -0
  81. package/dist/native/iosnativeWebView/Sources/CatalystNotifications/NotificationManager.swift +299 -0
  82. package/dist/native/iosnativeWebView/Sources/CatalystNotifications/PushNotificationHandler.swift +199 -0
  83. package/dist/native/iosnativeWebView/Sources/Core/Constants/CatalystConstants.swift +125 -0
  84. package/dist/native/iosnativeWebView/Sources/Core/Constants/ConfigConstants.swift +70 -0
  85. package/dist/native/iosnativeWebView/Sources/Core/Notifications/NotificationModels.swift +156 -0
  86. package/dist/native/iosnativeWebView/Sources/Core/Protocols/NotificationHandlerProtocol.swift +35 -0
  87. package/dist/native/iosnativeWebView/Sources/Core/Utils/BootTimingUtility.swift +26 -0
  88. package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/CacheManager.swift +69 -36
  89. package/dist/native/iosnativeWebView/Sources/Core/Utils/CameraTransportUtils.swift +363 -0
  90. package/dist/native/iosnativeWebView/Sources/Core/Utils/DeviceInfoUtils.swift +67 -0
  91. package/dist/native/iosnativeWebView/Sources/Core/Utils/FilePickerHandler.swift +1053 -0
  92. package/dist/native/iosnativeWebView/Sources/Core/Utils/FrameworkServerUtils.swift +901 -0
  93. package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/ImageHandler.swift +206 -20
  94. package/dist/native/iosnativeWebView/Sources/Core/Utils/NetworkMonitor.swift +112 -0
  95. package/dist/native/iosnativeWebView/Sources/Core/Utils/NotificationHandlerProvider.swift +20 -0
  96. package/dist/native/iosnativeWebView/Sources/Core/Utils/NullNotificationHandler.swift +85 -0
  97. package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/ResourceURLProtocol.swift +60 -25
  98. package/dist/native/iosnativeWebView/Sources/Core/Utils/SafeAreaUtils.swift +132 -0
  99. package/dist/native/iosnativeWebView/Sources/Core/Utils/ScreenSecureManager.swift +131 -0
  100. package/dist/native/iosnativeWebView/Sources/Core/Utils/URLWhitelistManager.swift +224 -0
  101. package/dist/native/iosnativeWebView/Sources/Core/Utils/WebKitConfig.swift +43 -0
  102. package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeCommandHandler.swift +991 -0
  103. package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeDelegateHandler.swift +166 -0
  104. package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeFileHandler.swift +340 -0
  105. package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeJavaScriptInterface.swift +149 -0
  106. package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeMessageValidator.swift +611 -0
  107. package/dist/native/iosnativeWebView/Sources/Core/WebView/NativeBridge.swift +334 -0
  108. package/dist/native/iosnativeWebView/Sources/Core/WebView/SplashView.swift +95 -0
  109. package/dist/native/iosnativeWebView/Sources/Core/WebView/SplashViewModel.swift +86 -0
  110. package/dist/native/iosnativeWebView/Sources/Core/WebView/WebView.swift +181 -0
  111. package/dist/native/iosnativeWebView/Sources/Core/WebView/WebViewModel.swift +182 -0
  112. package/dist/native/iosnativeWebView/Sources/Core/WebView/WebViewNavigationDelegate.swift +395 -0
  113. package/dist/native/iosnativeWebView/iosnativeWebView/AppDelegate.swift +84 -0
  114. package/dist/native/iosnativeWebView/iosnativeWebView/Assets.xcassets/AccentColor.colorset/Contents.json +8 -8
  115. package/dist/native/iosnativeWebView/iosnativeWebView/Assets.xcassets/AppIcon.appiconset/Contents.json +10 -10
  116. package/dist/native/iosnativeWebView/iosnativeWebView/Assets.xcassets/Contents.json +4 -4
  117. package/dist/native/iosnativeWebView/iosnativeWebView/ContentView.swift +65 -10
  118. package/dist/native/iosnativeWebView/iosnativeWebView/Info-Release.plist +21 -0
  119. package/dist/native/iosnativeWebView/iosnativeWebView/Info.plist +13 -0
  120. package/dist/native/iosnativeWebView/iosnativeWebView/Preview Content/Preview Assets.xcassets/Contents.json +4 -4
  121. package/dist/native/iosnativeWebView/iosnativeWebView/iosnativeWebView.entitlements +12 -0
  122. package/dist/native/iosnativeWebView/iosnativeWebView/iosnativeWebViewApp.swift +80 -0
  123. package/dist/native/iosnativeWebView/iosnativeWebView/localhost.p12 +0 -0
  124. package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.pbxproj +118 -100
  125. package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +69 -0
  126. package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/xcshareddata/xcschemes/iosnativeWebView.xcscheme +9 -4
  127. package/dist/native/iosnativeWebView/iosnativeWebView.xctestplan +47 -0
  128. package/dist/native/iosnativeWebView/iosnativeWebViewTests/BootTimingUtilityTests.swift +236 -0
  129. package/dist/native/iosnativeWebView/iosnativeWebViewTests/BridgeCommandHandlerSecurityTests.swift +212 -0
  130. package/dist/native/iosnativeWebView/iosnativeWebViewTests/BridgeMessageValidatorTests.swift +418 -0
  131. package/dist/native/iosnativeWebView/iosnativeWebViewTests/CacheManagerTests.swift +390 -0
  132. package/dist/native/iosnativeWebView/iosnativeWebViewTests/ConfigMappingTests.swift +299 -0
  133. package/dist/native/iosnativeWebView/iosnativeWebViewTests/FilePickerHandlerTests.swift +383 -0
  134. package/dist/native/iosnativeWebView/iosnativeWebViewTests/FrameworkServerUtilsTests.swift +391 -0
  135. package/dist/native/iosnativeWebView/iosnativeWebViewTests/NativeBridgeTests.swift +581 -0
  136. package/dist/native/iosnativeWebView/iosnativeWebViewTests/NotificationHandlerTests.swift +430 -0
  137. package/dist/native/iosnativeWebView/iosnativeWebViewTests/ScreenSecureManagerTests.swift +121 -0
  138. package/dist/native/iosnativeWebView/iosnativeWebViewTests/URLWhitelistManagerTests.swift +367 -0
  139. package/dist/native/iosnativeWebView/iosnativeWebViewTests/WebViewTests.swift +440 -0
  140. package/dist/native/renameAndroidProject.js +80 -70
  141. package/dist/native/setupEmulatorIos.js +22 -5
  142. package/dist/native/setupServer.js +11 -10
  143. package/dist/native/terminalProgress.js +10 -10
  144. package/dist/native/utils.js +4 -5
  145. package/dist/otel.js +4 -0
  146. package/dist/scripts/build.js +2 -2
  147. package/dist/scripts/devBuild.js +2 -2
  148. package/dist/scripts/loadEnvironmentVariables.js +3 -1
  149. package/dist/scripts/scriptUtils.js +2 -2
  150. package/dist/sentry.js +4 -1
  151. package/dist/server/renderer/document/Body.js +4 -4
  152. package/dist/server/renderer/handler.js +7 -5
  153. package/dist/webpack/development.client.babel.js +1 -1
  154. package/mcp_v2/conversion-tasks.json +326 -0
  155. package/mcp_v2/knowledge-base.json +1068 -0
  156. package/mcp_v2/lib/helpers.js +165 -0
  157. package/mcp_v2/mcp.js +563 -0
  158. package/mcp_v2/package.json +13 -0
  159. package/mcp_v2/schema.sql +88 -0
  160. package/mcp_v2/setup.js +278 -0
  161. package/mcp_v2/tools/build.js +686 -0
  162. package/mcp_v2/tools/config.js +453 -0
  163. package/mcp_v2/tools/conversion.js +799 -0
  164. package/mcp_v2/tools/debug.js +113 -0
  165. package/mcp_v2/tools/knowledge.js +219 -0
  166. package/mcp_v2/tools/sync.js +23 -0
  167. package/mcp_v2/tools/tasks.js +945 -0
  168. package/package.json +11 -15
  169. package/dist/native/androidProject/.idea/.name +0 -1
  170. package/dist/native/androidProject/.idea/AndroidProjectSystem.xml +0 -6
  171. package/dist/native/androidProject/.idea/compiler.xml +0 -6
  172. package/dist/native/androidProject/.idea/deploymentTargetSelector.xml +0 -10
  173. package/dist/native/androidProject/.idea/gradle.xml +0 -18
  174. package/dist/native/androidProject/.idea/migrations.xml +0 -10
  175. package/dist/native/androidProject/.idea/misc.xml +0 -10
  176. package/dist/native/androidProject/.idea/runConfigurations.xml +0 -17
  177. package/dist/native/androidProject/.idea/vcs.xml +0 -6
  178. package/dist/native/iosnativeWebView/iosnativeWebView/NativeBridge.swift +0 -217
  179. package/dist/native/iosnativeWebView/iosnativeWebView/WebView.swift +0 -96
  180. package/dist/native/iosnativeWebView/iosnativeWebView/WebViewModel.swift +0 -47
  181. package/dist/native/iosnativeWebView/iosnativeWebView/WebViewNavigationDelegate.swift +0 -140
  182. package/license +0 -10
@@ -0,0 +1,170 @@
1
+ package io.yourname.androidproject.security
2
+
3
+ import android.app.Activity
4
+ import android.util.Log
5
+ import android.view.View
6
+ import io.yourname.androidproject.MainActivity
7
+ import io.yourname.androidproject.R
8
+ import org.json.JSONObject
9
+
10
+ /**
11
+ * SecurityAlertHandler handles the display of security alerts when device compromise is detected.
12
+ * Uses a Material Design BottomSheet with smooth animations.
13
+ * This utility class keeps MainActivity clean and focused on its primary responsibilities.
14
+ */
15
+ object SecurityAlertHandler {
16
+
17
+ private const val TAG = "SecurityAlertHandler"
18
+ private var currentBottomSheet: SecurityBottomSheet? = null
19
+
20
+ /**
21
+ * Handle security check results and show alert if device is compromised.
22
+ * This method parses the security check results and displays a bottom sheet alert
23
+ * if any threats are detected.
24
+ *
25
+ * @param activity The activity context to display the alert
26
+ * @param results JSONObject containing security check results
27
+ */
28
+ fun handleSecurityCheckResults(activity: Activity, results: JSONObject) {
29
+ try {
30
+ val securityMode = SecurityCheckManager.getSecurityMode(activity)
31
+ val isCompromised = results.optBoolean("isCompromised", false)
32
+
33
+ Log.d(TAG, "Security mode: $securityMode, isCompromised: $isCompromised")
34
+
35
+ // custom mode: no UI, data is already saved via SecurityCheckManager for getDeviceInfo()
36
+ if (securityMode == "custom") {
37
+ Log.d(TAG, "Security mode is custom - skipping bottom sheet, data available via getDeviceInfo()")
38
+ return
39
+ }
40
+
41
+ // default mode: show bottom sheet if compromised
42
+ if (isCompromised) {
43
+ val isRooted = results.optBoolean("isRooted", false)
44
+ val isEmulator = results.optBoolean("isEmulator", false)
45
+ val isFridaDetected = results.optBoolean("isFridaDetected", false)
46
+
47
+ val threats = mutableListOf<String>()
48
+ if (isRooted) threats.add("Root access detected")
49
+ if (isEmulator) threats.add("Running on emulator")
50
+ if (isFridaDetected) threats.add("Frida framework detected")
51
+
52
+ activity.runOnUiThread {
53
+ showSecurityBottomSheet(activity, threats)
54
+ }
55
+ }
56
+ } catch (e: Exception) {
57
+ Log.e(TAG, "Error handling security check results: ${e.message}", e)
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Show security alert as a bottom sheet when device is compromised.
63
+ * The bottom sheet slides up from the bottom with animation and hides the WebView.
64
+ *
65
+ * @param activity The activity context to display the alert
66
+ * @param threats List of detected security threats
67
+ */
68
+ private fun showSecurityBottomSheet(activity: Activity, threats: List<String>) {
69
+ if (activity.isFinishing || activity.isDestroyed) {
70
+ Log.w(TAG, "Cannot show security alert - activity is finishing or destroyed")
71
+ return
72
+ }
73
+
74
+ // Dismiss any existing bottom sheet
75
+ currentBottomSheet?.dismiss()
76
+
77
+ // Hide WebView if this is MainActivity
78
+ hideWebView(activity)
79
+
80
+ // Create the UI view for the bottom sheet
81
+ val alertView = SecurityAlertUI.createSecurityAlertView(
82
+ context = activity,
83
+ threats = threats,
84
+ onExitClick = {
85
+ currentBottomSheet?.dismiss()
86
+ activity.finish()
87
+ }
88
+ )
89
+
90
+ // Create and show the bottom sheet
91
+ currentBottomSheet = SecurityBottomSheet(
92
+ activity = activity,
93
+ customView = alertView,
94
+ onDismiss = {
95
+ // Clean up reference when dismissed
96
+ currentBottomSheet = null
97
+ }
98
+ )
99
+
100
+ currentBottomSheet?.show(animated = true)
101
+
102
+ Log.d(TAG, "Security bottom sheet displayed with ${threats.size} threats")
103
+ }
104
+
105
+ /**
106
+ * Hide the WebView with smooth fade-out animation when security alert is shown.
107
+ * Uses Material Design animation timing for professional transitions.
108
+ *
109
+ * @param activity The activity context
110
+ */
111
+ private fun hideWebView(activity: Activity) {
112
+ if (activity is MainActivity) {
113
+ try {
114
+ val webViewContainer = activity.findViewById<View>(R.id.webview)
115
+ if (webViewContainer != null && webViewContainer.visibility == View.VISIBLE) {
116
+ // Fade out animation (300ms - Material Design standard)
117
+ webViewContainer.animate()
118
+ .alpha(0f)
119
+ .setDuration(300L)
120
+ .withEndAction {
121
+ webViewContainer.visibility = View.GONE
122
+ Log.d(TAG, "WebView hidden with fade animation")
123
+ }
124
+ .start()
125
+ } else {
126
+ Log.w(TAG, "WebView container not found or already hidden")
127
+ }
128
+ } catch (e: Exception) {
129
+ Log.e(TAG, "Error hiding WebView: ${e.message}", e)
130
+ }
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Show the WebView with smooth fade-in animation.
136
+ * Can be used to restore WebView if security alert is dismissed (though typically we exit app).
137
+ *
138
+ * @param activity The activity context
139
+ */
140
+ fun showWebView(activity: Activity) {
141
+ if (activity is MainActivity) {
142
+ try {
143
+ val webViewContainer = activity.findViewById<View>(R.id.webview)
144
+ if (webViewContainer != null && webViewContainer.visibility != View.VISIBLE) {
145
+ webViewContainer.visibility = View.VISIBLE
146
+ webViewContainer.alpha = 0f
147
+ // Fade in animation (300ms - Material Design standard)
148
+ webViewContainer.animate()
149
+ .alpha(1f)
150
+ .setDuration(300L)
151
+ .withEndAction {
152
+ Log.d(TAG, "WebView shown with fade animation")
153
+ }
154
+ .start()
155
+ }
156
+ } catch (e: Exception) {
157
+ Log.e(TAG, "Error showing WebView: ${e.message}", e)
158
+ }
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Dismiss the current security bottom sheet if showing.
164
+ */
165
+ fun dismissCurrentBottomSheet() {
166
+ currentBottomSheet?.dismiss()
167
+ currentBottomSheet = null
168
+ }
169
+ }
170
+
@@ -0,0 +1,366 @@
1
+ package io.yourname.androidproject.security
2
+
3
+ import android.content.Context
4
+ import android.graphics.drawable.GradientDrawable
5
+ import android.view.Gravity
6
+ import android.view.View
7
+ import android.view.ViewGroup
8
+ import android.widget.Button
9
+ import android.widget.FrameLayout
10
+ import android.widget.ImageView
11
+ import android.widget.LinearLayout
12
+ import android.widget.ScrollView
13
+ import android.widget.TextView
14
+ import io.yourname.androidproject.design.DesignTokens
15
+
16
+ /**
17
+ * UI builder for security alert bottom sheets.
18
+ * Follows Material Design 3 principles with adaptive theming.
19
+ */
20
+ object SecurityAlertUI {
21
+
22
+ /**
23
+ * Create a modern security alert view for bottom sheet display.
24
+ *
25
+ * Design features:
26
+ * - Large hero icon at top
27
+ * - Scrollable content area
28
+ * - Persistent footer button
29
+ * - Dark/light mode support
30
+ * - Material Design 3 styling
31
+ *
32
+ * @param context Android context
33
+ * @param threats List of detected security threats
34
+ * @param onExitClick Callback for when exit button is clicked
35
+ * @return View to be displayed in the bottom sheet
36
+ */
37
+ fun createSecurityAlertView(
38
+ context: Context,
39
+ threats: List<String>,
40
+ onExitClick: () -> Unit
41
+ ): View {
42
+
43
+ // Root container with rounded corners
44
+ val rootContainer = FrameLayout(context).apply {
45
+ layoutParams = ViewGroup.LayoutParams(
46
+ ViewGroup.LayoutParams.MATCH_PARENT,
47
+ ViewGroup.LayoutParams.WRAP_CONTENT
48
+ )
49
+ // Apply rounded corners to the container itself
50
+ val roundedBackground = GradientDrawable().apply {
51
+ shape = GradientDrawable.RECTANGLE
52
+ cornerRadii = floatArrayOf(
53
+ DesignTokens.dpToPx(context, DesignTokens.Dimensions.CORNER_RADIUS_LG).toFloat(), // top-left
54
+ DesignTokens.dpToPx(context, DesignTokens.Dimensions.CORNER_RADIUS_LG).toFloat(),
55
+ DesignTokens.dpToPx(context, DesignTokens.Dimensions.CORNER_RADIUS_LG).toFloat(), // top-right
56
+ DesignTokens.dpToPx(context, DesignTokens.Dimensions.CORNER_RADIUS_LG).toFloat(),
57
+ 0f, 0f, // bottom-right (no rounding)
58
+ 0f, 0f // bottom-left (no rounding)
59
+ )
60
+ setColor(DesignTokens.getSurfaceColor(context))
61
+ }
62
+ background = roundedBackground
63
+ }
64
+
65
+ // Main content wrapper (vertically stacked)
66
+ val mainWrapper = LinearLayout(context).apply {
67
+ orientation = LinearLayout.VERTICAL
68
+ layoutParams = FrameLayout.LayoutParams(
69
+ ViewGroup.LayoutParams.MATCH_PARENT,
70
+ ViewGroup.LayoutParams.WRAP_CONTENT
71
+ )
72
+ }
73
+
74
+ // Top section with icon and header (non-scrollable)
75
+ val headerSection = createHeaderSection(context)
76
+ mainWrapper.addView(headerSection)
77
+
78
+ // Scrollable content section
79
+ val scrollView = ScrollView(context).apply {
80
+ layoutParams = LinearLayout.LayoutParams(
81
+ ViewGroup.LayoutParams.MATCH_PARENT,
82
+ ViewGroup.LayoutParams.WRAP_CONTENT
83
+ )
84
+ isVerticalScrollBarEnabled = false
85
+ overScrollMode = View.OVER_SCROLL_IF_CONTENT_SCROLLS
86
+ }
87
+
88
+ val scrollContent = createScrollableContent(context, threats)
89
+ scrollView.addView(scrollContent)
90
+ mainWrapper.addView(scrollView)
91
+
92
+ // Persistent footer with button
93
+ val footer = createFooter(context, onExitClick)
94
+ mainWrapper.addView(footer)
95
+
96
+ rootContainer.addView(mainWrapper)
97
+ return rootContainer
98
+ }
99
+
100
+ /**
101
+ * Create the header section with hero icon and title.
102
+ */
103
+ private fun createHeaderSection(context: Context): View {
104
+ val header = LinearLayout(context).apply {
105
+ orientation = LinearLayout.VERTICAL
106
+ gravity = Gravity.CENTER_HORIZONTAL
107
+ layoutParams = LinearLayout.LayoutParams(
108
+ ViewGroup.LayoutParams.MATCH_PARENT,
109
+ ViewGroup.LayoutParams.WRAP_CONTENT
110
+ )
111
+ val paddingHorizontal = DesignTokens.dpToPx(context, DesignTokens.Spacing.SPACE_LG)
112
+ val paddingTop = DesignTokens.dpToPx(context, DesignTokens.Spacing.SPACE_XL)
113
+ val paddingBottom = DesignTokens.dpToPx(context, DesignTokens.Spacing.SPACE_MD)
114
+ setPadding(paddingHorizontal, paddingTop, paddingHorizontal, paddingBottom)
115
+ }
116
+
117
+ // Hero icon (shield with warning)
118
+ val iconContainer = FrameLayout(context).apply {
119
+ layoutParams = LinearLayout.LayoutParams(
120
+ DesignTokens.dpToPx(context, DesignTokens.Dimensions.ICON_SIZE_LG),
121
+ DesignTokens.dpToPx(context, DesignTokens.Dimensions.ICON_SIZE_LG)
122
+ ).apply {
123
+ bottomMargin = DesignTokens.dpToPx(context, DesignTokens.Spacing.SPACE_MD)
124
+ }
125
+ }
126
+
127
+ // Icon background with error color
128
+ val iconBackground = View(context).apply {
129
+ layoutParams = FrameLayout.LayoutParams(
130
+ ViewGroup.LayoutParams.MATCH_PARENT,
131
+ ViewGroup.LayoutParams.MATCH_PARENT
132
+ )
133
+ val drawable = GradientDrawable().apply {
134
+ shape = GradientDrawable.OVAL
135
+ setColor(DesignTokens.getErrorContainerColor(context))
136
+ }
137
+ background = drawable
138
+ alpha = 0.2f
139
+ }
140
+ iconContainer.addView(iconBackground)
141
+
142
+ // Icon (using Unicode shield character)
143
+ val icon = TextView(context).apply {
144
+ text = "🛡️"
145
+ textSize = 32f
146
+ gravity = Gravity.CENTER
147
+ layoutParams = FrameLayout.LayoutParams(
148
+ ViewGroup.LayoutParams.MATCH_PARENT,
149
+ ViewGroup.LayoutParams.MATCH_PARENT
150
+ )
151
+ }
152
+ iconContainer.addView(icon)
153
+ header.addView(iconContainer)
154
+
155
+ // Title
156
+ val title = TextView(context).apply {
157
+ text = "Security Alert"
158
+ textSize = DesignTokens.Typography.TEXT_SIZE_HEADLINE
159
+ setTextColor(DesignTokens.getErrorColor(context))
160
+ setTypeface(null, DesignTokens.Typography.FONT_WEIGHT_BOLD)
161
+ gravity = Gravity.CENTER_HORIZONTAL
162
+ layoutParams = LinearLayout.LayoutParams(
163
+ ViewGroup.LayoutParams.MATCH_PARENT,
164
+ ViewGroup.LayoutParams.WRAP_CONTENT
165
+ ).apply {
166
+ bottomMargin = DesignTokens.dpToPx(context, DesignTokens.Spacing.SPACE_XS)
167
+ }
168
+ }
169
+ header.addView(title)
170
+
171
+ return header
172
+ }
173
+
174
+ /**
175
+ * Create the scrollable content section with message and threats.
176
+ */
177
+ private fun createScrollableContent(
178
+ context: Context,
179
+ threats: List<String>
180
+ ): View {
181
+ val content = LinearLayout(context).apply {
182
+ orientation = LinearLayout.VERTICAL
183
+ layoutParams = ViewGroup.LayoutParams(
184
+ ViewGroup.LayoutParams.MATCH_PARENT,
185
+ ViewGroup.LayoutParams.WRAP_CONTENT
186
+ )
187
+ val paddingHorizontal = DesignTokens.dpToPx(context, DesignTokens.Spacing.SPACE_LG)
188
+ setPadding(paddingHorizontal, 0, paddingHorizontal, 0)
189
+ }
190
+
191
+ // Main message
192
+ val message = TextView(context).apply {
193
+ text = "This device has failed security checks and cannot run this app."
194
+ textSize = DesignTokens.Typography.TEXT_SIZE_BODY_LG
195
+ setTextColor(DesignTokens.getOnSurfaceColor(context))
196
+ setLineSpacing(0f, DesignTokens.Typography.LINE_HEIGHT_NORMAL)
197
+ layoutParams = LinearLayout.LayoutParams(
198
+ ViewGroup.LayoutParams.MATCH_PARENT,
199
+ ViewGroup.LayoutParams.WRAP_CONTENT
200
+ ).apply {
201
+ bottomMargin = DesignTokens.dpToPx(context, DesignTokens.Spacing.SPACE_LG)
202
+ }
203
+ }
204
+ content.addView(message)
205
+
206
+ // Threats section header
207
+ val threatsHeader = TextView(context).apply {
208
+ text = "Detected Issues:"
209
+ textSize = DesignTokens.Typography.TEXT_SIZE_BODY
210
+ setTextColor(DesignTokens.getOnSurfaceVariantColor(context))
211
+ setTypeface(null, DesignTokens.Typography.FONT_WEIGHT_BOLD)
212
+ layoutParams = LinearLayout.LayoutParams(
213
+ ViewGroup.LayoutParams.MATCH_PARENT,
214
+ ViewGroup.LayoutParams.WRAP_CONTENT
215
+ ).apply {
216
+ bottomMargin = DesignTokens.dpToPx(context, DesignTokens.Spacing.SPACE_SM)
217
+ }
218
+ }
219
+ content.addView(threatsHeader)
220
+
221
+ // Threats list with cards
222
+ threats.forEach { threat ->
223
+ val threatCard = createThreatCard(context, threat)
224
+ content.addView(threatCard)
225
+ }
226
+
227
+ // Footer warning message
228
+ val warningText = TextView(context).apply {
229
+ text = "For your security, this app cannot continue. These checks protect your data and ensure a safe experience."
230
+ textSize = DesignTokens.Typography.TEXT_SIZE_BODY
231
+ setTextColor(DesignTokens.getOnSurfaceVariantColor(context))
232
+ setLineSpacing(0f, DesignTokens.Typography.LINE_HEIGHT_NORMAL)
233
+ alpha = DesignTokens.Opacity.MEDIUM
234
+ layoutParams = LinearLayout.LayoutParams(
235
+ ViewGroup.LayoutParams.MATCH_PARENT,
236
+ ViewGroup.LayoutParams.WRAP_CONTENT
237
+ ).apply {
238
+ topMargin = DesignTokens.dpToPx(context, DesignTokens.Spacing.SPACE_LG)
239
+ }
240
+ }
241
+ content.addView(warningText)
242
+
243
+ return content
244
+ }
245
+
246
+ /**
247
+ * Create a threat card with icon and text.
248
+ */
249
+ private fun createThreatCard(
250
+ context: Context,
251
+ threat: String
252
+ ): View {
253
+ val card = LinearLayout(context).apply {
254
+ orientation = LinearLayout.HORIZONTAL
255
+ gravity = Gravity.CENTER_VERTICAL
256
+ layoutParams = LinearLayout.LayoutParams(
257
+ ViewGroup.LayoutParams.MATCH_PARENT,
258
+ ViewGroup.LayoutParams.WRAP_CONTENT
259
+ ).apply {
260
+ bottomMargin = DesignTokens.dpToPx(context, DesignTokens.Spacing.SPACE_SM)
261
+ }
262
+ val padding = DesignTokens.dpToPx(context, DesignTokens.Spacing.SPACE_MD)
263
+ setPadding(padding, padding, padding, padding)
264
+
265
+ // Card background with proper opacity applied to color, not view
266
+ val errorContainerColor = DesignTokens.getErrorContainerColor(context)
267
+ val drawable = GradientDrawable().apply {
268
+ shape = GradientDrawable.RECTANGLE
269
+ cornerRadius = DesignTokens.dpToPx(context, DesignTokens.Dimensions.CORNER_RADIUS_SM).toFloat()
270
+ // Apply alpha to color directly for better readability
271
+ val alpha = (0.15 * 255).toInt() // 15% opacity for subtle background
272
+ val alphaColor = (alpha shl 24) or (errorContainerColor and 0x00FFFFFF)
273
+ setColor(alphaColor)
274
+ }
275
+ background = drawable
276
+ }
277
+
278
+ // Warning icon
279
+ val icon = TextView(context).apply {
280
+ text = "⚠️"
281
+ textSize = DesignTokens.Typography.TEXT_SIZE_BODY_LG
282
+ layoutParams = LinearLayout.LayoutParams(
283
+ ViewGroup.LayoutParams.WRAP_CONTENT,
284
+ ViewGroup.LayoutParams.WRAP_CONTENT
285
+ ).apply {
286
+ rightMargin = DesignTokens.dpToPx(context, DesignTokens.Spacing.SPACE_SM)
287
+ }
288
+ }
289
+ card.addView(icon)
290
+
291
+ // Threat text
292
+ val text = TextView(context).apply {
293
+ text = threat
294
+ textSize = DesignTokens.Typography.TEXT_SIZE_BODY
295
+ setTextColor(DesignTokens.getOnErrorContainerColor(context))
296
+ setLineSpacing(0f, DesignTokens.Typography.LINE_HEIGHT_NORMAL)
297
+ layoutParams = LinearLayout.LayoutParams(
298
+ 0,
299
+ ViewGroup.LayoutParams.WRAP_CONTENT,
300
+ 1f // Weight for flexible width
301
+ )
302
+ }
303
+ card.addView(text)
304
+
305
+ return card
306
+ }
307
+
308
+ /**
309
+ * Create the persistent footer with exit button.
310
+ */
311
+ private fun createFooter(
312
+ context: Context,
313
+ onExitClick: () -> Unit
314
+ ): View {
315
+ val footer = LinearLayout(context).apply {
316
+ orientation = LinearLayout.VERTICAL
317
+ layoutParams = LinearLayout.LayoutParams(
318
+ ViewGroup.LayoutParams.MATCH_PARENT,
319
+ ViewGroup.LayoutParams.WRAP_CONTENT
320
+ )
321
+ val padding = DesignTokens.dpToPx(context, DesignTokens.Spacing.SPACE_LG)
322
+ setPadding(padding, padding, padding, padding)
323
+
324
+ // Top divider
325
+ val divider = View(context).apply {
326
+ layoutParams = LinearLayout.LayoutParams(
327
+ ViewGroup.LayoutParams.MATCH_PARENT,
328
+ DesignTokens.dpToPx(context, 1)
329
+ ).apply {
330
+ bottomMargin = DesignTokens.dpToPx(context, DesignTokens.Spacing.SPACE_MD)
331
+ }
332
+ setBackgroundColor(DesignTokens.getOutlineColor(context))
333
+ alpha = 0.12f
334
+ }
335
+ addView(divider)
336
+ }
337
+
338
+ // Exit button (Material Design filled button)
339
+ val exitButton = Button(context).apply {
340
+ text = "Exit App"
341
+ textSize = DesignTokens.Typography.TEXT_SIZE_BODY_LG
342
+ setTextColor(DesignTokens.getOnErrorColor(context))
343
+ setTypeface(null, DesignTokens.Typography.FONT_WEIGHT_BOLD)
344
+ isAllCaps = false // Material Design 3 uses sentence case
345
+ layoutParams = LinearLayout.LayoutParams(
346
+ ViewGroup.LayoutParams.MATCH_PARENT,
347
+ DesignTokens.dpToPx(context, DesignTokens.Dimensions.MIN_TOUCH_TARGET)
348
+ )
349
+
350
+ // Button background with rounded corners
351
+ val drawable = GradientDrawable().apply {
352
+ shape = GradientDrawable.RECTANGLE
353
+ cornerRadius = DesignTokens.dpToPx(context, DesignTokens.Dimensions.CORNER_RADIUS_MD).toFloat()
354
+ setColor(DesignTokens.getErrorColor(context))
355
+ }
356
+ background = drawable
357
+
358
+ elevation = DesignTokens.Dimensions.ELEVATION_SM
359
+ stateListAnimator = null // Remove default state animator
360
+ setOnClickListener { onExitClick() }
361
+ }
362
+ footer.addView(exitButton)
363
+
364
+ return footer
365
+ }
366
+ }
@@ -0,0 +1,138 @@
1
+ package io.yourname.androidproject.security
2
+
3
+ import android.app.Activity
4
+ import android.graphics.drawable.GradientDrawable
5
+ import android.util.Log
6
+ import android.view.View
7
+ import android.view.animation.DecelerateInterpolator
8
+ import com.google.android.material.bottomsheet.BottomSheetBehavior
9
+ import com.google.android.material.bottomsheet.BottomSheetDialog
10
+ import io.yourname.androidproject.design.DesignTokens
11
+
12
+ /**
13
+ * Reusable BottomSheet component for displaying modal content.
14
+ * Features Material Design 3 styling with smooth animations.
15
+ *
16
+ * Design features:
17
+ * - Rounded top corners (24dp)
18
+ * - Smooth slide-up animation with DecelerateInterpolator
19
+ * - Non-dismissible (security critical)
20
+ * - Adaptive theming (dark/light mode)
21
+ */
22
+ class SecurityBottomSheet(
23
+ private val activity: Activity,
24
+ private val customView: View,
25
+ private val onDismiss: (() -> Unit)? = null
26
+ ) {
27
+
28
+ private val TAG = "SecurityBottomSheet"
29
+ private val bottomSheetDialog: BottomSheetDialog
30
+
31
+ init {
32
+ // Use custom transparent theme to prevent dark background layer
33
+ bottomSheetDialog = BottomSheetDialog(
34
+ activity,
35
+ io.yourname.androidproject.R.style.TransparentBottomSheetDialog
36
+ ).apply {
37
+ setCancelable(false)
38
+ setCanceledOnTouchOutside(false)
39
+ setContentView(customView)
40
+
41
+ // Configure bottom sheet behavior
42
+ behavior.apply {
43
+ state = BottomSheetBehavior.STATE_EXPANDED
44
+ isDraggable = false // Prevent dismissal by dragging
45
+ skipCollapsed = true // Skip half-expanded state
46
+ isHideable = false // Prevent hiding
47
+ peekHeight = 0 // No peek height
48
+ }
49
+
50
+ // Match window background to app surface color to prevent dark layer during animation
51
+ window?.apply {
52
+ val surfaceColor = DesignTokens.getSurfaceColor(activity)
53
+ setBackgroundDrawableResource(android.R.color.transparent)
54
+ decorView.setBackgroundColor(surfaceColor) // Matches light/dark theme
55
+ setDimAmount(0.4f) // Semi-transparent scrim (40% dark overlay) for visual separation
56
+ }
57
+
58
+ // Add dismiss listener if callback provided
59
+ onDismiss?.let { callback ->
60
+ setOnDismissListener { callback() }
61
+ }
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Show the bottom sheet with smooth slide-up animation.
67
+ * Uses DecelerateInterpolator for natural deceleration (Material Design).
68
+ *
69
+ * Animation tuning: Adjust ANIMATION_DURATION_MS to control entrance speed
70
+ * - Default: 1200ms (slow, dramatic entrance)
71
+ * - Past options: 300ms (fast), 500ms (smooth)
72
+ *
73
+ * @param animated Whether to animate the bottom sheet appearance
74
+ */
75
+ fun show(animated: Boolean = true) {
76
+ if (activity.isFinishing || activity.isDestroyed) {
77
+ Log.w(TAG, "Cannot show bottom sheet - activity is finishing or destroyed")
78
+ return
79
+ }
80
+
81
+ // Show dialog first so layout pass runs
82
+ bottomSheetDialog.show()
83
+
84
+ // Wait for layout to complete, then position off-screen and animate in
85
+ customView.post {
86
+ // Force transparent background on all container layers AFTER layout
87
+ bottomSheetDialog.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)?.apply {
88
+ setBackgroundResource(android.R.color.transparent)
89
+ }
90
+ bottomSheetDialog.findViewById<View>(com.google.android.material.R.id.coordinator)?.apply {
91
+ setBackgroundResource(android.R.color.transparent)
92
+ }
93
+
94
+ if (animated) {
95
+ // Position off-screen using real measured height (available after layout)
96
+ customView.translationY = customView.height.toFloat()
97
+ customView.animate()
98
+ .translationY(0f)
99
+ .setDuration(ANIMATION_DURATION_MS)
100
+ .setInterpolator(DecelerateInterpolator())
101
+ .start()
102
+ }
103
+ }
104
+
105
+ Log.d(TAG, "Bottom sheet shown with animation=$animated")
106
+ }
107
+
108
+ companion object {
109
+ /**
110
+ * TUNING VARIABLE: Bottom sheet entrance animation duration in milliseconds.
111
+ *
112
+ * Adjust this value to control how quickly the bottom sheet slides up:
113
+ * - 300ms = Fast, snappy entrance
114
+ * - 500ms = Smooth, balanced entrance
115
+ * - 1200ms = Slow, dramatic entrance (Current Default)
116
+ */
117
+ const val ANIMATION_DURATION_MS = 1200L
118
+ }
119
+
120
+ /**
121
+ * Dismiss the bottom sheet.
122
+ */
123
+ fun dismiss() {
124
+ // Ensure dismissal happens on UI thread to prevent crashes
125
+ activity.runOnUiThread {
126
+ if (!activity.isFinishing && !activity.isDestroyed) {
127
+ bottomSheetDialog.dismiss()
128
+ }
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Check if the bottom sheet is currently showing.
134
+ *
135
+ * @return true if bottom sheet is showing
136
+ */
137
+ fun isShowing(): Boolean = bottomSheetDialog.isShowing
138
+ }