Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite dependency injection to use Dagger #214

Merged
merged 26 commits into from Dec 29, 2019
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
da8cade
Add Dagger dependencies
msfjarvis Dec 18, 2019
52f2d07
Add AppComponent and InjectorProvider
msfjarvis Dec 28, 2019
5612393
AppComponent: Remove JvmStatic annotation
msfjarvis Dec 19, 2019
8d297f5
Annotate class constructors with Inject@
msfjarvis Dec 28, 2019
b077c80
Remove provided definitions that are unneeded
msfjarvis Dec 28, 2019
ca5dfdc
Remove useless qualifier
msfjarvis Dec 28, 2019
1050e2c
Annotate classes with Reusable
msfjarvis Dec 28, 2019
7af43ef
Start using Dagger for some injection
msfjarvis Dec 29, 2019
9eb5325
Cleanup injection in Tunnel and TunnelManager
msfjarvis Dec 29, 2019
3108ecd
Migrate fragments to Dagger
msfjarvis Dec 29, 2019
b8d4db3
Migrate activities to Dagger
msfjarvis Dec 29, 2019
35c6a2a
Migrate preferences to Dagger
msfjarvis Dec 29, 2019
b78b8e5
Migrate contentproviders to Dagger
msfjarvis Dec 29, 2019
f04e5e1
Update Detekt baseline
msfjarvis Dec 29, 2019
8cec1a8
Update detekt
msfjarvis Dec 29, 2019
b08f384
Migrate services and broadcastreceivers to Dagger
msfjarvis Dec 29, 2019
e23f878
Migrate TunnelRestoreWorker to Dagger
msfjarvis Dec 29, 2019
9b7e809
Remove all unused Koin extensions
msfjarvis Dec 29, 2019
3ac858d
Unpair config package from android dependencies
msfjarvis Dec 29, 2019
daabc64
Remove Koin from ConfigTest
msfjarvis Dec 29, 2019
9d576ea
Wire exclusions directly into WgQuickBackend
msfjarvis Dec 29, 2019
a463f9f
Fix and use Backend factory in AppComponent
msfjarvis Dec 29, 2019
40b0d15
Remove Koin from ConfigStoreTest
msfjarvis Dec 29, 2019
fc54ec6
Cleanup Koin remanants
msfjarvis Dec 29, 2019
c34e0f9
Remove Koin dependencies
msfjarvis Dec 29, 2019
ce4f753
Remove leftover KoinComponent
msfjarvis Dec 29, 2019
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Cleanup injection in Tunnel and TunnelManager

Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
  • Loading branch information
msfjarvis committed Dec 29, 2019
commit 9eb532521f51d0f7bb66a2a78aa1fc5688128a22
@@ -27,7 +27,7 @@ val appModule = module {
single { RootShell(androidContext()) }
single { PreferenceManager.getDefaultSharedPreferences(androidContext()) }
single { ApplicationPreferences(get()) }
single { TunnelManager(androidContext(), get(), get()) }
single { TunnelManager(get(), get(), androidContext(), get(), get()) }
single { BackendFactory.getBackend(androidContext(), get(), get(), get()) }
single { CompletableBackendFactory.getBackendAsync(get()) }
single { ToolsInstaller(androidContext(), get()) }
@@ -47,12 +47,11 @@ class Tunnel internal constructor(
}

val stateAsync: CompletionStage<State>
get() = TunnelManager.getTunnelState(this)
get() = manager.getTunnelState(this)

// FIXME: Check age of statistics.
val statisticsAsync: CompletionStage<Statistics>
get() = if (statistics == null || statistics!!.isStale()) {
TunnelManager.getTunnelStatistics(this)
manager.getTunnelStatistics(this)
} else {
CompletableFuture.completedFuture(statistics)
}
@@ -72,7 +71,7 @@ class Tunnel internal constructor(
@Bindable
fun getStatistics(): Statistics? {
if (statistics == null || statistics!!.isStale()) {
TunnelManager.getTunnelStatistics(this).whenComplete(ExceptionLoggers.E)
manager.getTunnelStatistics(this).whenComplete(ExceptionLoggers.E)
}
return statistics
}
@@ -14,12 +14,12 @@ import androidx.databinding.Bindable
import com.wireguard.android.BR
import com.wireguard.android.BuildConfig
import com.wireguard.android.R
import com.wireguard.android.backend.Backend
import com.wireguard.android.configStore.ConfigStore
import com.wireguard.android.di.ext.getTunnelManager
import com.wireguard.android.di.ext.injectAsyncWorker
import com.wireguard.android.di.ext.injectBackend
import com.wireguard.android.model.Tunnel.Statistics
import com.wireguard.android.util.ApplicationPreferences
import com.wireguard.android.util.AsyncWorker
import com.wireguard.android.util.ExceptionLoggers
import com.wireguard.android.util.KotlinCompanions
import com.wireguard.android.util.ObservableSortedKeyedArrayList
@@ -35,10 +35,12 @@ import timber.log.Timber

@Reusable
class TunnelManager @Inject constructor(
This conversation was marked as resolved by msfjarvis

This comment has been minimized.

Copy link
@msasikanth

msasikanth Dec 28, 2019

Contributor

You can make the class @Reusable

private val asyncWorker: AsyncWorker,
private val backend: Backend,
private val context: Context,
private val configStore: ConfigStore,
private val prefs: ApplicationPreferences
) : BaseObservable(), KoinComponent {
) : BaseObservable() {

private val completableTunnels = CompletableFuture<ObservableSortedKeyedList<String, Tunnel>>()
private val tunnels = ObservableSortedKeyedArrayList<String, Tunnel>(COMPARATOR)
@@ -276,7 +278,17 @@ class TunnelManager @Inject constructor(
}
}

class IntentReceiver : BroadcastReceiver() {
internal fun getTunnelState(tunnel: Tunnel): CompletionStage<Tunnel.State> {
return asyncWorker.supplyAsync { backend.getState(tunnel) }
.thenApply(tunnel::onStateChanged)
}

fun getTunnelStatistics(tunnel: Tunnel): CompletionStage<Statistics> {
return asyncWorker.supplyAsync { backend.getStatistics(tunnel) }
.thenApply(tunnel::onStatisticsChanged)
}

class IntentReceiver : BroadcastReceiver(), KoinComponent {
private val tunnelManager = getTunnelManager()

override fun onReceive(context: Context?, intent: Intent?) {
@@ -293,27 +305,12 @@ class TunnelManager @Inject constructor(
}
}

companion object : KoinComponent {
companion object {
const val NOTIFICATION_CHANNEL_ID = "wg-quick_tunnels"
const val TUNNEL_NAME_INTENT_EXTRA = "tunnel_name"
const val INTENT_INTEGRATION_SECRET_EXTRA = "integration_secret"
const val TUNNEL_STATE_INTENT_EXTRA = "tunnel_state"
private val asyncWorker by injectAsyncWorker()
private val backend by injectBackend()

private val COMPARATOR = Comparators.thenComparing(
String.CASE_INSENSITIVE_ORDER, Comparators.naturalOrder()
)
private val COMPARATOR = Comparators.thenComparing(String.CASE_INSENSITIVE_ORDER, Comparators.naturalOrder())
private var lastUsedTunnel: Tunnel? = null

internal fun getTunnelState(tunnel: Tunnel): CompletionStage<Tunnel.State> {
return asyncWorker.supplyAsync { backend.getState(tunnel) }
.thenApply(tunnel::onStateChanged)
}

fun getTunnelStatistics(tunnel: Tunnel): CompletionStage<Statistics> {
return asyncWorker.supplyAsync { backend.getStatistics(tunnel) }
.thenApply(tunnel::onStatisticsChanged)
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.