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