Commit 8454975a authored by Mygod's avatar Mygod

Fix NAT notifications on Android 4.4

parent 69cb86a7
...@@ -49,7 +49,6 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str ...@@ -49,7 +49,6 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str
case _ => case _ =>
} }
private lazy val style = new BigTextStyle(builder) private lazy val style = new BigTextStyle(builder)
private val showOnUnlock = visible && Utils.isLollipopOrAbove
private var isVisible = true private var isVisible = true
update(if (service.getSystemService(Context.POWER_SERVICE).asInstanceOf[PowerManager].isScreenOn) update(if (service.getSystemService(Context.POWER_SERVICE).asInstanceOf[PowerManager].isScreenOn)
Intent.ACTION_SCREEN_ON else Intent.ACTION_SCREEN_OFF, true) Intent.ACTION_SCREEN_ON else Intent.ACTION_SCREEN_OFF, true)
...@@ -57,19 +56,19 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str ...@@ -57,19 +56,19 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str
val screenFilter = new IntentFilter() val screenFilter = new IntentFilter()
screenFilter.addAction(Intent.ACTION_SCREEN_ON) screenFilter.addAction(Intent.ACTION_SCREEN_ON)
screenFilter.addAction(Intent.ACTION_SCREEN_OFF) screenFilter.addAction(Intent.ACTION_SCREEN_OFF)
if (showOnUnlock) screenFilter.addAction(Intent.ACTION_USER_PRESENT) if (visible && Utils.isLollipopOrAbove) screenFilter.addAction(Intent.ACTION_USER_PRESENT)
service.registerReceiver(lockReceiver, screenFilter) service.registerReceiver(lockReceiver, screenFilter)
private def update(action: String, forceShow: Boolean = false) = private def update(action: String, forceShow: Boolean = false) =
if (forceShow || service.getState == State.CONNECTED) action match { if (forceShow || service.getState == State.CONNECTED) action match {
case Intent.ACTION_SCREEN_OFF => case Intent.ACTION_SCREEN_OFF =>
setVisible(false, forceShow) setVisible(visible && !Utils.isLollipopOrAbove, forceShow)
unregisterCallback // unregister callback to save battery unregisterCallback // unregister callback to save battery
case Intent.ACTION_SCREEN_ON => case Intent.ACTION_SCREEN_ON =>
setVisible(showOnUnlock && !keyGuard.inKeyguardRestrictedInputMode, forceShow) setVisible(visible && Utils.isLollipopOrAbove && !keyGuard.inKeyguardRestrictedInputMode, forceShow)
service.binder.registerCallback(callback) service.binder.registerCallback(callback)
callbackRegistered = true callbackRegistered = true
case Intent.ACTION_USER_PRESENT => setVisible(showOnUnlock, forceShow) case Intent.ACTION_USER_PRESENT => setVisible(true, forceShow)
} }
private def unregisterCallback = if (callbackRegistered) { private def unregisterCallback = if (callbackRegistered) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment