Show invisible foreground notification on television to avoid being killed
This commit is contained in:
@@ -2,6 +2,7 @@ package be.mygod.vpnhotspot
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import android.app.UiModeManager
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.Configuration
|
||||
import android.net.ConnectivityManager
|
||||
@@ -49,6 +50,7 @@ class App : Application() {
|
||||
val handler = Handler()
|
||||
val pref: SharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(deviceStorage) }
|
||||
val connectivity by lazy { getSystemService<ConnectivityManager>()!! }
|
||||
val uiMode by lazy { getSystemService<UiModeManager>()!! }
|
||||
val wifi by lazy { getSystemService<WifiManager>()!! }
|
||||
|
||||
val operatingChannel: Int get() {
|
||||
|
||||
@@ -2,7 +2,9 @@ package be.mygod.vpnhotspot
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.res.Configuration
|
||||
import android.net.wifi.WifiManager
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import be.mygod.vpnhotspot.net.TetheringManager
|
||||
@@ -65,6 +67,8 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService() {
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
binder.iface = ""
|
||||
// show invisible foreground notification on television to avoid being killed
|
||||
if (app.uiMode.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION) updateNotification()
|
||||
// throws IllegalStateException if the caller attempts to start the LocalOnlyHotspot while they
|
||||
// have an outstanding request.
|
||||
// https://android.googlesource.com/platform/frameworks/opt/net/wifi/+/53e0284/service/java/com/android/server/wifi/WifiServiceImpl.java#1192
|
||||
|
||||
@@ -3,6 +3,7 @@ package be.mygod.vpnhotspot
|
||||
import android.app.Service
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.Configuration
|
||||
import android.net.NetworkInfo
|
||||
import android.net.wifi.WpsInfo
|
||||
import android.net.wifi.p2p.WifiP2pDevice
|
||||
@@ -216,6 +217,10 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
if (status != Status.IDLE) return START_NOT_STICKY
|
||||
status = Status.STARTING
|
||||
// show invisible foreground notification on television to avoid being killed
|
||||
if (Build.VERSION.SDK_INT >= 26 && app.uiMode.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION) {
|
||||
showNotification()
|
||||
}
|
||||
unregisterReceiver()
|
||||
registerReceiver(receiver, intentFilter(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION,
|
||||
WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION))
|
||||
|
||||
Reference in New Issue
Block a user