This repository has been archived by the owner on Feb 11, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert to standard broadcast receiver for Tasker integration
Some devices are finicky with services and end up breaking the feature altogether. Fixes #148 Revert "Application: Restart tasker service from background below Oreo" This reverts commit 209e87b. Revert "Application: Don't try to start service from background" This reverts commit d533be7. Revert "Persist service state across application restarts" This reverts commit 3a41fd3. Revert "Convert Tasker receiver to a service" This reverts commit f159fad. Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
- Loading branch information
Showing
5 changed files
with
81 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
app/src/main/java/com/wireguard/android/services/TaskerIntegrationReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright © 2017-2019 WireGuard LLC. | ||
* Copyright © 2018-2019 Harsh Shandilya <msfjarvis@gmail.com>. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package com.wireguard.android.services | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import com.wireguard.android.BuildConfig | ||
import com.wireguard.android.di.ext.getPrefs | ||
import com.wireguard.android.di.ext.getTunnelManager | ||
import com.wireguard.android.model.Tunnel | ||
import com.wireguard.android.model.TunnelManager | ||
import org.koin.core.KoinComponent | ||
import timber.log.Timber | ||
|
||
class TaskerIntegrationReceiver : BroadcastReceiver(), KoinComponent { | ||
val manager = getTunnelManager() | ||
val prefs = getPrefs() | ||
|
||
override fun onReceive(context: Context?, intent: Intent?) { | ||
if (intent == null || intent.action == null) | ||
return | ||
|
||
val isSelfPackage = intent.`package` == BuildConfig.APPLICATION_ID | ||
val taskerEnabled = !prefs.allowTaskerIntegration || prefs.taskerIntegrationSecret.isEmpty() | ||
val tunnelName: String? = intent.getStringExtra(TunnelManager.TUNNEL_NAME_INTENT_EXTRA) | ||
val integrationSecret: String? = intent.getStringExtra(TunnelManager.INTENT_INTEGRATION_SECRET_EXTRA) | ||
|
||
var state: Tunnel.State? = null | ||
Timber.tag("IntentReceiver") | ||
when (intent.action) { | ||
"${BuildConfig.APPLICATION_ID}.SET_TUNNEL_UP" -> { | ||
state = Tunnel.State.UP | ||
} | ||
"${BuildConfig.APPLICATION_ID}.SET_TUNNEL_DOWN" -> { | ||
state = Tunnel.State.DOWN | ||
} | ||
else -> Timber.d("Invalid intent action: ${intent.action}") | ||
} | ||
|
||
if (taskerEnabled && !isSelfPackage) { | ||
Timber.e("Tasker integration is disabled! Not allowing tunnel state change to pass through.") | ||
return | ||
} | ||
|
||
if (tunnelName != null && state != null) { | ||
if (isSelfPackage) { | ||
toggleTunnelState(tunnelName, state, manager) | ||
return | ||
} | ||
when (integrationSecret) { | ||
prefs.taskerIntegrationSecret -> toggleTunnelState(tunnelName, state, manager) | ||
else -> Timber.e("Intent integration secret mis-match! Exiting...") | ||
} | ||
} else if (tunnelName == null) { | ||
Timber.d("Intent parameter ${TunnelManager.TUNNEL_NAME_INTENT_EXTRA} not set!") | ||
} | ||
} | ||
|
||
private fun toggleTunnelState(tunnelName: String, state: Tunnel.State, manager: TunnelManager) { | ||
Timber.d("Setting $tunnelName's state to $state") | ||
manager.getTunnels().thenAccept { tunnels -> | ||
val tunnel = tunnels[tunnelName] | ||
tunnel?.let { | ||
manager.setTunnelState(it, state) | ||
} | ||
} | ||
} | ||
} |
104 changes: 0 additions & 104 deletions
104
app/src/main/java/com/wireguard/android/services/TaskerIntegrationService.kt
This file was deleted.
Oops, something went wrong.