mirror of
https://github.com/MatsuriDayo/NekoBoxForAndroid.git
synced 2025-12-18 22:20:06 +08:00
fix: fix reciver in SDK 34
This commit is contained in:
parent
c7ef42d9f1
commit
6f7b4a125f
@ -13,6 +13,7 @@
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
@ -254,11 +255,17 @@
|
||||
<service
|
||||
android:name="io.nekohasekai.sagernet.bg.ProxyService"
|
||||
android:exported="false"
|
||||
android:process=":bg" />
|
||||
android:foregroundServiceType="specialUse"
|
||||
android:process=":bg">
|
||||
<property
|
||||
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
|
||||
android:value="proxy" />
|
||||
</service>
|
||||
|
||||
<service
|
||||
android:name="io.nekohasekai.sagernet.bg.VpnService"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="specialUse"
|
||||
android:label="@string/app_name"
|
||||
android:permission="android.permission.BIND_VPN_SERVICE"
|
||||
android:process=":bg">
|
||||
@ -266,6 +273,9 @@
|
||||
<intent-filter>
|
||||
<action android:name="android.net.VpnService" />
|
||||
</intent-filter>
|
||||
<property
|
||||
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
|
||||
android:value="vpn" />
|
||||
</service>
|
||||
|
||||
<service
|
||||
|
||||
@ -328,7 +328,7 @@ class BaseService {
|
||||
data.proxy = proxy
|
||||
BootReceiver.enabled = DataStore.persistAcrossReboot
|
||||
if (!data.closeReceiverRegistered) {
|
||||
registerReceiver(data.receiver, IntentFilter().apply {
|
||||
val filter = IntentFilter().apply {
|
||||
addAction(Action.RELOAD)
|
||||
addAction(Intent.ACTION_SHUTDOWN)
|
||||
addAction(Action.CLOSE)
|
||||
@ -337,7 +337,23 @@ class BaseService {
|
||||
addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED)
|
||||
}
|
||||
addAction(Action.RESET_UPSTREAM_CONNECTIONS)
|
||||
}, "$packageName.SERVICE", null)
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
registerReceiver(
|
||||
data.receiver,
|
||||
filter,
|
||||
"$packageName.SERVICE",
|
||||
null,
|
||||
Context.RECEIVER_NOT_EXPORTED
|
||||
)
|
||||
} else {
|
||||
registerReceiver(
|
||||
data.receiver,
|
||||
filter,
|
||||
"$packageName.SERVICE",
|
||||
null
|
||||
)
|
||||
}
|
||||
data.closeReceiverRegistered = true
|
||||
}
|
||||
|
||||
|
||||
@ -191,7 +191,11 @@ class ServiceNotification(
|
||||
|
||||
fun destroy() {
|
||||
listenPostSpeed = false
|
||||
(service as Service).stopForeground(true)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
(service as Service).stopForeground(Service.STOP_FOREGROUND_REMOVE)
|
||||
} else {
|
||||
(service as Service).stopForeground(true)
|
||||
}
|
||||
service.unregisterReceiver(this)
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.net.VpnService
|
||||
import android.os.Build.VERSION.SDK_INT
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContract
|
||||
@ -26,7 +27,15 @@ class VpnRequestActivity : AppCompatActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (getSystemService<KeyguardManager>()!!.isKeyguardLocked) {
|
||||
receiver = broadcastReceiver { _, _ -> connect.launch(null) }
|
||||
registerReceiver(receiver, IntentFilter(Intent.ACTION_USER_PRESENT))
|
||||
if (SDK_INT >= 33) {
|
||||
registerReceiver(
|
||||
receiver,
|
||||
IntentFilter(Intent.ACTION_USER_PRESENT),
|
||||
Context.RECEIVER_NOT_EXPORTED
|
||||
)
|
||||
} else {
|
||||
registerReceiver(receiver, IntentFilter(Intent.ACTION_USER_PRESENT))
|
||||
}
|
||||
} else connect.launch(null)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user