Declare location permission used by foreground properly

Fix #132.
This commit is contained in:
Mygod
2019-10-24 12:15:36 +08:00
parent 13c43f9b0e
commit e790e513e1
3 changed files with 13 additions and 6 deletions

View File

@@ -73,13 +73,16 @@
<service <service
android:name=".LocalOnlyHotspotService" android:name=".LocalOnlyHotspotService"
android:directBootAware="true"/> android:directBootAware="true"
android:foregroundServiceType="location|connectedDevice"/>
<service <service
android:name=".RepeaterService" android:name=".RepeaterService"
android:directBootAware="true"/> android:directBootAware="true"
android:foregroundServiceType="location|connectedDevice"/>
<service <service
android:name=".TetheringService" android:name=".TetheringService"
android:directBootAware="true"/> android:directBootAware="true"
android:foregroundServiceType="connectedDevice"/>
<service <service
android:name=".manage.RepeaterTileService" android:name=".manage.RepeaterTileService"

View File

@@ -46,6 +46,8 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
*/ */
private const val PLACEHOLDER_NETWORK_NAME = "DIRECT-00-VPNHotspot" private const val PLACEHOLDER_NETWORK_NAME = "DIRECT-00-VPNHotspot"
const val EXTRA_POSSIBLY_BACKGROUND = "possiblyBackground"
/** /**
* This is only a "ServiceConnection" to system service and its impact on system is minimal. * This is only a "ServiceConnection" to system service and its impact on system is minimal.
*/ */
@@ -255,7 +257,9 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
val channel = channel ?: return START_NOT_STICKY.also { stopSelf() } val channel = channel ?: return START_NOT_STICKY.also { stopSelf() }
status = Status.STARTING status = Status.STARTING
// show invisible foreground notification on television to avoid being killed // show invisible foreground notification on television to avoid being killed
if (Build.VERSION.SDK_INT >= 26 && app.uiMode.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION) { if (Build.VERSION.SDK_INT >= 26 && app.uiMode.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION ||
// or bump self to foreground location service to use foreground location permission
Build.VERSION.SDK_INT >= 29 && intent?.getBooleanExtra(EXTRA_POSSIBLY_BACKGROUND, false) == true) {
showNotification() showNotification()
} }
launch { launch {

View File

@@ -35,8 +35,8 @@ class RepeaterTileService : KillableTileService() {
val binder = binder val binder = binder
if (binder == null) tapPending = true else when (binder.service.status) { if (binder == null) tapPending = true else when (binder.service.status) {
RepeaterService.Status.ACTIVE -> binder.shutdown() RepeaterService.Status.ACTIVE -> binder.shutdown()
RepeaterService.Status.IDLE -> RepeaterService.Status.IDLE -> ContextCompat.startForegroundService(this,
ContextCompat.startForegroundService(this, Intent(this, RepeaterService::class.java)) Intent(this, RepeaterService::class.java).putExtra(RepeaterService.EXTRA_POSSIBLY_BACKGROUND, true))
else -> { } else -> { }
} }
} }