@@ -73,32 +73,67 @@ class GuardedContext(
7373 private val isStrictlyBlocked: Boolean
7474 get() = providerName != null && (policy.blockAllUnknown || AllowlistStore .blockedProviders().contains(providerName))
7575
76+ private fun detectCallerProvider (): String? {
77+ val trace = Thread .currentThread().stackTrace
78+ for (element in trace) {
79+ val className = element.className
80+ if (className.startsWith(" com.csguard" )) continue
81+ if (className.startsWith(" com.lagradost" )) continue
82+ if (className.startsWith(" android." )) continue
83+ if (className.startsWith(" java." )) continue
84+ if (className.startsWith(" kotlin." )) continue
85+ if (className.startsWith(" dalvik." )) continue
86+
87+ try {
88+ val providers = com.lagradost.cloudstream3.APIHolder .allProviders
89+ for (provider in providers) {
90+ val pkg = provider.javaClass.`package`?.name ? : continue
91+ if (className.startsWith(pkg)) {
92+ return provider.name
93+ }
94+ }
95+ } catch (_: Throwable ) {}
96+ }
97+ return null
98+ }
99+
100+ private fun isCallerBlocked (): Boolean {
101+ if (isStrictlyBlocked) return true
102+ if (providerName == null ) {
103+ val caller = detectCallerProvider()
104+ if (caller != null && (policy.blockAllUnknown || AllowlistStore .blockedProviders().contains(caller))) {
105+ return true
106+ }
107+ }
108+ return false
109+ }
110+
76111 override fun getSystemService (name : String ): Any? {
77- if (isStrictlyBlocked ) {
78- when (name) {
79- Context .WINDOW_SERVICE ,
80- Context .CLIPBOARD_SERVICE ,
81- Context .NOTIFICATION_SERVICE ,
82- Context .VIBRATOR_SERVICE ,
83- Context .LOCATION_SERVICE ,
84- Context . AUDIO_SERVICE -> return null
112+ when (name ) {
113+ Context . WINDOW_SERVICE ,
114+ Context .CLIPBOARD_SERVICE ,
115+ Context .NOTIFICATION_SERVICE ,
116+ Context .VIBRATOR_SERVICE ,
117+ Context .LOCATION_SERVICE ,
118+ Context .AUDIO_SERVICE -> {
119+ if (isCallerBlocked()) return null
85120 }
86121 }
87122 return super .getSystemService(name)
88123 }
89124
90125 override fun sendBroadcast (intent : Intent ? ) {
91- if (isStrictlyBlocked ) return
126+ if (isCallerBlocked() ) return
92127 super .sendBroadcast(intent)
93128 }
94129
95130 override fun startService (service : Intent ? ): android.content.ComponentName ? {
96- if (isStrictlyBlocked ) return null
131+ if (isCallerBlocked() ) return null
97132 return super .startService(service)
98133 }
99134
100135 override fun bindService (service : Intent , conn : android.content.ServiceConnection , flags : Int ): Boolean {
101- if (isStrictlyBlocked ) return false
136+ if (isCallerBlocked() ) return false
102137 return super .bindService(service, conn, flags)
103138 }
104139}
0 commit comments