File tree Expand file tree Collapse file tree 4 files changed +14
-3
lines changed
app/src/main/java/com/ismartcoding/plain Expand file tree Collapse file tree 4 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import com.ismartcoding.plain.helpers.NotificationHelper
2424import com.ismartcoding.plain.helpers.UrlHelper
2525import com.ismartcoding.plain.web.HttpServerManager
2626import com.ismartcoding.plain.web.NsdHelper
27+ import com.ismartcoding.plain.features.Permission
2728import io.ktor.client.request.get
2829import io.ktor.http.HttpStatusCode
2930import kotlinx.coroutines.delay
@@ -116,6 +117,7 @@ class HttpServerService : LifecycleService() {
116117 HttpServerManager .portsInUse.clear()
117118 NsdHelper .registerService(this , TempData .httpPort)
118119 sendEvent(HttpServerStateChangedEvent (HttpServerState .ON ))
120+ PNotificationListenerService .toggle(this , Permission .NOTIFICATION_LISTENER .isEnabledAsync(this ))
119121 } else {
120122 if (! checkResult.http) {
121123 if (PortHelper .isPortInUse(TempData .httpPort)) {
@@ -142,6 +144,7 @@ class HttpServerService : LifecycleService() {
142144 }
143145
144146 sendEvent(HttpServerStateChangedEvent (HttpServerState .ERROR ))
147+ PNotificationListenerService .toggle(this , false )
145148 }
146149 }
147150
@@ -167,5 +170,6 @@ class HttpServerService : LifecycleService() {
167170 LogCat .e(ex.toString())
168171 ex.printStackTrace()
169172 }
173+ PNotificationListenerService .toggle(this , false )
170174 }
171175}
Original file line number Diff line number Diff line change @@ -279,7 +279,9 @@ class MainActivity : AppCompatActivity() {
279279
280280 private suspend fun doWhenReadyAsync () {
281281 // PackageHelper.cacheAppLabels()
282- PNotificationListenerService .toggle(this @MainActivity, Permission .NOTIFICATION_LISTENER .isEnabledAsync(this @MainActivity))
282+ val webEnabled = WebPreference .getAsync(this @MainActivity)
283+ val permissionEnabled = Permission .NOTIFICATION_LISTENER .isEnabledAsync(this @MainActivity)
284+ PNotificationListenerService .toggle(this @MainActivity, webEnabled && permissionEnabled)
283285 }
284286
285287 override fun onDestroy () {
Original file line number Diff line number Diff line change @@ -99,7 +99,8 @@ fun WebSettingsPage(
9999 permissionList = Permissions .getWebList(context)
100100 systemAlertWindow = Permission .SYSTEM_ALERT_WINDOW .can(context)
101101 if (event.map[Permission .NOTIFICATION_LISTENER .toSysPermission()] == true ) {
102- PNotificationListenerService .toggle(context, true )
102+ // Only enable listener if web is enabled
103+ PNotificationListenerService .toggle(context, WebPreference .getAsync(context))
103104 }
104105 }
105106
@@ -125,7 +126,9 @@ fun WebSettingsPage(
125126 scope.launch {
126127 withIO { ApiPermissionsPreference .putAsync(context, m.permission, enable) }
127128 if (m.permission == Permission .NOTIFICATION_LISTENER ) {
128- PNotificationListenerService .toggle(context, enable)
129+ // Enable only when web is enabled; otherwise disable
130+ val webEnabled = WebPreference .getAsync(context)
131+ PNotificationListenerService .toggle(context, enable && webEnabled)
129132 }
130133 if (enable) {
131134 val ps = m.permissions.filter { ! it.can(context) }
Original file line number Diff line number Diff line change @@ -91,6 +91,8 @@ object HttpServerManager {
9191 ex.printStackTrace()
9292 }
9393 context.stopService(Intent (context, HttpServerService ::class .java))
94+ // Ensure notification listener is disabled when server is stopped explicitly
95+ com.ismartcoding.plain.services.PNotificationListenerService .toggle(context, false )
9496 httpServerError = " "
9597 portsInUse.clear()
9698 sendEvent(HttpServerStateChangedEvent (HttpServerState .OFF ))
You can’t perform that action at this time.
0 commit comments