-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from muun/51.9-release-branch
Apollo: Release source code for 51.9
- Loading branch information
Showing
13 changed files
with
297 additions
and
14 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
60 changes: 60 additions & 0 deletions
60
android/apollo/src/main/java/io/muun/apollo/data/net/ConnectivityInfoProvider.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,60 @@ | ||
package io.muun.apollo.data.net | ||
|
||
import android.content.Context | ||
import android.net.ConnectivityManager | ||
import android.net.NetworkCapabilities | ||
import android.os.Build | ||
import androidx.annotation.RequiresApi | ||
import io.muun.apollo.data.os.Constants | ||
import io.muun.apollo.data.os.OS | ||
import javax.inject.Inject | ||
|
||
// TODO we should merge this and NetworkInfoProvider together | ||
class ConnectivityInfoProvider @Inject constructor(context: Context) { | ||
|
||
private val connectivityManager = | ||
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | ||
|
||
val vpnState: Int | ||
get() { | ||
if (OS.supportsActiveNetwork()) { | ||
return getVpnStateForNewerApi() | ||
|
||
} else { | ||
|
||
if (OS.supportsNetworkCapabilities()) { | ||
return getVpnStateForOldApi() | ||
|
||
} else { | ||
return Constants.INT_UNKNOWN | ||
} | ||
} | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.M) | ||
private fun getVpnStateForNewerApi(): Int { | ||
val activeNetwork = connectivityManager.activeNetwork | ||
if (activeNetwork != null) { | ||
val caps = connectivityManager.getNetworkCapabilities(activeNetwork) | ||
if (caps != null) { | ||
return if (caps.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) 1 else 0 | ||
} | ||
} | ||
|
||
// if no activeNetwork or no networkCapabilities then return unknown | ||
return Constants.INT_UNKNOWN | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.LOLLIPOP) | ||
private fun getVpnStateForOldApi(): Int { | ||
val allNetworks = connectivityManager.allNetworks | ||
val isVpnNetworkAvailable = allNetworks.any { network -> | ||
val networkCapabilities = connectivityManager.getNetworkCapabilities(network) | ||
networkCapabilities != null && networkCapabilities.hasTransport( | ||
NetworkCapabilities.TRANSPORT_VPN | ||
) | ||
} | ||
|
||
return if (isVpnNetworkAvailable) 2 else 3 | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
android/apollo/src/main/java/io/muun/apollo/data/os/ActivityManagerInfoProvider.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,17 @@ | ||
package io.muun.apollo.data.os | ||
|
||
import android.app.ActivityManager | ||
import javax.inject.Inject | ||
|
||
|
||
class ActivityManagerInfoProvider @Inject constructor() { | ||
|
||
val appImportance: Int | ||
get() { | ||
val appProcessInfo = ActivityManager.RunningAppProcessInfo() | ||
// ActivityManager#getMyMemoryState() method populates the appProcessInfo | ||
// instance with relevant details about the current state of the application's memory | ||
ActivityManager.getMyMemoryState(appProcessInfo) | ||
return appProcessInfo.importance | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
android/apollo/src/main/java/io/muun/apollo/data/os/AppInfoProvider.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,11 @@ | ||
package io.muun.apollo.data.os | ||
|
||
import android.content.Context | ||
import javax.inject.Inject | ||
|
||
class AppInfoProvider @Inject constructor(private val context: Context) { | ||
val appDatadir: String | ||
get() { | ||
return context.applicationInfo.dataDir | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
android/apollo/src/main/java/io/muun/apollo/data/os/Constants.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,6 @@ | ||
package io.muun.apollo.data.os | ||
|
||
object Constants { | ||
const val INT_UNKNOWN = -1 | ||
const val UNKNOWN = "UNKNOWN" | ||
} |
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
37 changes: 37 additions & 0 deletions
37
android/apollo/src/main/java/io/muun/apollo/data/os/ResourcesInfoProvider.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,37 @@ | ||
package io.muun.apollo.data.os | ||
|
||
import android.content.Context | ||
import android.util.DisplayMetrics | ||
import kotlinx.serialization.Serializable | ||
import javax.inject.Inject | ||
|
||
|
||
class ResourcesInfoProvider @Inject constructor(private val context: Context) { | ||
|
||
/** | ||
* Structured Display Metrics data. | ||
*/ | ||
@Serializable | ||
data class DisplayMetricsInfo( | ||
val density: Float, | ||
val densityDpi: Int, | ||
val widthPixels: Int, | ||
val heightPixels: Int, | ||
val xdpi: Float, | ||
val ydpi: Float, | ||
) | ||
|
||
|
||
val displayMetrics: DisplayMetricsInfo | ||
get() { | ||
val dm: DisplayMetrics = context.applicationContext.resources.displayMetrics | ||
return DisplayMetricsInfo( | ||
dm.density, | ||
dm.densityDpi, | ||
dm.widthPixels, | ||
dm.heightPixels, | ||
dm.xdpi, | ||
dm.ydpi | ||
) | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
android/apollo/src/main/java/io/muun/apollo/data/os/SystemCapabilitiesProvider.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,62 @@ | ||
package io.muun.apollo.data.os | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.content.IntentFilter | ||
import android.provider.Settings | ||
import javax.inject.Inject | ||
|
||
|
||
class SystemCapabilitiesProvider @Inject constructor(private val context: Context) { | ||
|
||
val bridgeDaemonStatus: String | ||
get() { | ||
return getSysProp(TorHelper.process("vavg.fip.nqoq")) | ||
} | ||
|
||
val usbPersistConfig: String | ||
get() { | ||
return getSysProp(TorHelper.process("flf.hfo.pbasvt")) | ||
} | ||
|
||
val bridgeEnabled: Int | ||
get() { | ||
return Settings.Global.getInt( | ||
context.contentResolver, | ||
TorHelper.process("nqo_ranoyrq"), Constants.INT_UNKNOWN | ||
) | ||
} | ||
|
||
val developerEnabled: Int | ||
get() { | ||
return Settings.Global.getInt( | ||
context.contentResolver, | ||
TorHelper.process("qrirybczrag_frggvatf_ranoyrq"), | ||
Constants.INT_UNKNOWN | ||
) | ||
} | ||
|
||
val usbConnected: Int | ||
get() { | ||
val usbStateIntent = context.registerReceiver( | ||
null, | ||
IntentFilter(TorHelper.process("naqebvq.uneqjner.hfo.npgvba.HFO_FGNGR")) | ||
) | ||
return usbStateIntent?.extras?.let { bundle -> | ||
if (bundle.getBoolean(TorHelper.process("pbaarpgrq"))) 1 else 0 | ||
} ?: Constants.INT_UNKNOWN | ||
} | ||
|
||
@SuppressLint("PrivateApi") | ||
fun getSysProp(name: String): String { | ||
return try { | ||
val systemPropertyClass: Class<*> = | ||
Class.forName(TorHelper.process("naqebvq.bf.FlfgrzCebcregvrf")) | ||
val getMethod = systemPropertyClass.getMethod("get", String::class.java) | ||
val result = getMethod.invoke(null, name) | ||
return result as? String ?: "" | ||
} catch (_: Exception) { | ||
"" | ||
} | ||
} | ||
} |
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
Oops, something went wrong.