Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Nov 6, 2024
1 parent 7bbdda2 commit 28a90ba
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,19 @@ class QSTileService : TileService() {

override fun onStartListening() {
super.onStartListening()

setState(Tile.STATE_INACTIVE)
mMsgReceive = ReceiveMessageHandler(this)
val mFilter = IntentFilter(AppConfig.BROADCAST_ACTION_ACTIVITY)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
ContextCompat.registerReceiver(applicationContext, mMsgReceive, mFilter, ContextCompat.RECEIVER_EXPORTED)
} else {
ContextCompat.registerReceiver(applicationContext, mMsgReceive, mFilter, ContextCompat.RECEIVER_NOT_EXPORTED)
}

ContextCompat.registerReceiver(applicationContext, mMsgReceive, mFilter, Utils.receiverFlags())
MessageUtil.sendMsg2Service(this, AppConfig.MSG_REGISTER_CLIENT, "")
}

override fun onStopListening() {
super.onStopListening()

try {
unregisterReceiver(mMsgReceive)
applicationContext.unregisterReceiver(mMsgReceive)
mMsgReceive = null
} catch (e: Exception) {
e.printStackTrace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,7 @@ object V2RayServiceManager {
mFilter.addAction(Intent.ACTION_SCREEN_ON)
mFilter.addAction(Intent.ACTION_SCREEN_OFF)
mFilter.addAction(Intent.ACTION_USER_PRESENT)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
ContextCompat.registerReceiver(
service, mMsgReceive, mFilter,
ContextCompat.RECEIVER_EXPORTED
)
} else {
ContextCompat.registerReceiver(
service, mMsgReceive, mFilter,
ContextCompat.RECEIVER_NOT_EXPORTED
)
}
ContextCompat.registerReceiver(service, mMsgReceive, mFilter, Utils.receiverFlags())
} catch (e: Exception) {
Log.d(ANG_PACKAGE, e.toString())
}
Expand Down
7 changes: 7 additions & 0 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import android.util.Log
import android.util.Patterns
import android.webkit.URLUtil
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.ContextCompat
import com.v2ray.ang.AppConfig
import com.v2ray.ang.AppConfig.ANG_PACKAGE
import com.v2ray.ang.AppConfig.LOOPBACK
Expand Down Expand Up @@ -482,5 +483,11 @@ object Utils {
return false
}

fun receiverFlags(): Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
ContextCompat.RECEIVER_EXPORTED
} else {
ContextCompat.RECEIVER_NOT_EXPORTED
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.v2ray.ang.handler.MmkvManager
import com.v2ray.ang.handler.SettingsManager
import com.v2ray.ang.util.MessageUtil
import com.v2ray.ang.util.SpeedtestUtil
import com.v2ray.ang.util.Utils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -53,18 +54,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
fun startListenBroadcast() {
isRunning.value = false
val mFilter = IntentFilter(AppConfig.BROADCAST_ACTION_ACTIVITY)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
ContextCompat.registerReceiver(
getApplication(), mMsgReceiver, mFilter,
ContextCompat.RECEIVER_EXPORTED
)
} else {
ContextCompat.registerReceiver(
getApplication(), mMsgReceiver, mFilter,
ContextCompat.RECEIVER_NOT_EXPORTED
)
}
ContextCompat.registerReceiver(getApplication(), mMsgReceiver, mFilter, Utils.receiverFlags())
MessageUtil.sendMsg2Service(getApplication(), AppConfig.MSG_REGISTER_CLIENT, "")
}

Expand Down

0 comments on commit 28a90ba

Please sign in to comment.