Skip to content

Commit

Permalink
feat(root): add libjamesdsp version check
Browse files Browse the repository at this point in the history
  • Loading branch information
timschneeb committed Jul 13, 2023
1 parent 8fe9344 commit 3c4a818
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,17 @@ class MainActivity : BaseActivity() {
requestCapturePermission()
}
}
else if (!BuildConfig.ROOTLESS && JamesDspRemoteEngine.isPluginInstalled()) {
binding.powerToggle.isToggled = !binding.powerToggle.isToggled
prefsApp.set(R.string.key_powered_on, binding.powerToggle.isToggled)
else if (!BuildConfig.ROOTLESS) {
when(JamesDspRemoteEngine.isPluginInstalled() ) {
JamesDspRemoteEngine.PluginState.Available -> {
binding.powerToggle.isToggled = !binding.powerToggle.isToggled
prefsApp.set(R.string.key_powered_on, binding.powerToggle.isToggled)
}
JamesDspRemoteEngine.PluginState.Unsupported -> {
toast(getString(R.string.version_mismatch_root_toast))
}
else -> {}
}
}
}
})
Expand All @@ -294,8 +302,22 @@ class MainActivity : BaseActivity() {
}

// Root: show error if plugin unavailable
if(!BuildConfig.ROOTLESS && !JamesDspRemoteEngine.isPluginInstalled()) {
showLibraryLoadError()
if(!BuildConfig.ROOTLESS) {
when(JamesDspRemoteEngine.isPluginInstalled()) {
JamesDspRemoteEngine.PluginState.Unavailable -> showLibraryLoadError()
JamesDspRemoteEngine.PluginState.Unsupported -> {
prefsApp.set(R.string.key_powered_on, false)
showYesNoAlert(
getString(R.string.version_mismatch_root),
getString(R.string.version_mismatch_root_description)
) {
if(it) {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://zackptg5.com/android.php")))
}
}
}
else -> {}
}
}

/* Root: require battery optimizations turned off when legacy mode is disabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,21 +251,35 @@ class JamesDspRemoteEngine(
val allocatedBlockLength: Int
get() = effect.getParameterInt(20000) ?: -1

enum class PluginState {
Unavailable,
Available,
Unsupported
}

companion object {
private val EFFECT_TYPE_CUSTOM = UUID.fromString("f98765f4-c321-5de6-9a45-123459495ab2")
private val EFFECT_JAMESDSP = UUID.fromString("f27317f4-c984-4de6-9a90-545759495bf2")

fun isPluginInstalled(): Boolean {
fun isPluginInstalled(): PluginState {
return try {
AudioEffect
.queryEffects()
.orEmpty()
.filter { it.uuid == EFFECT_JAMESDSP }
.firstOrNull { it.name.contains("JamesDSP") } != null
.firstOrNull { it.name.contains("JamesDSP") }
.let {
if(it == null)
PluginState.Unavailable
else if(it.name.contains("v3"))
PluginState.Unsupported
else
PluginState.Available
}
} catch (e: Exception) {
Timber.e("isPluginInstalled: exception raised")
Timber.e(e)
false
PluginState.Unavailable
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import me.timschneeberger.rootlessjamesdsp.BuildConfig
import me.timschneeberger.rootlessjamesdsp.MainApplication
import me.timschneeberger.rootlessjamesdsp.utils.notifications.Notifications
import me.timschneeberger.rootlessjamesdsp.R
import me.timschneeberger.rootlessjamesdsp.interop.JamesDspRemoteEngine
import me.timschneeberger.rootlessjamesdsp.model.IEffectSession
Expand All @@ -29,8 +28,9 @@ import me.timschneeberger.rootlessjamesdsp.session.root.OnRootSessionChangeListe
import me.timschneeberger.rootlessjamesdsp.session.root.RootSessionDumpManager
import me.timschneeberger.rootlessjamesdsp.utils.Constants
import me.timschneeberger.rootlessjamesdsp.utils.extensions.ContextExtensions.sendLocalBroadcast
import me.timschneeberger.rootlessjamesdsp.utils.preferences.Preferences
import me.timschneeberger.rootlessjamesdsp.utils.notifications.Notifications
import me.timschneeberger.rootlessjamesdsp.utils.notifications.ServiceNotificationHelper
import me.timschneeberger.rootlessjamesdsp.utils.preferences.Preferences
import me.timschneeberger.rootlessjamesdsp.utils.sdkAbove
import org.koin.android.ext.android.inject
import org.koin.core.component.KoinComponent
Expand Down Expand Up @@ -118,7 +118,7 @@ class RootAudioProcessorService : BaseAudioProcessorService(), KoinComponent,
if (intent == null)
return START_STICKY

if(!JamesDspRemoteEngine.isPluginInstalled()) {
if(JamesDspRemoteEngine.isPluginInstalled() == JamesDspRemoteEngine.PluginState.Unavailable) {
Timber.e("onStartCommand: Ignoring command because plugin is not installed")
stopSelf()
return START_NOT_STICKY
Expand Down Expand Up @@ -235,7 +235,7 @@ class RootAudioProcessorService : BaseAudioProcessorService(), KoinComponent,
Timber.d("startService: intent=$intent")

// Prevent launch if plugin missing
if(!JamesDspRemoteEngine.isPluginInstalled()) {
if(JamesDspRemoteEngine.isPluginInstalled() == JamesDspRemoteEngine.PluginState.Unavailable) {
Timber.e("Service launch cancelled. Plugin not installed.")
return
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -638,4 +638,9 @@
<string name="device_profile_manage_copy_select">Select profile to copy</string>
<string name="device_profile_manage_paste_select">Select profiles to overwrite</string>

<!-- Root version check -->
<string name="version_mismatch_root">JamesDSP magisk package requires an update</string>
<string name="version_mismatch_root_description">The JamesDSP magisk package installed on your device is outdated and not supported by this app anymore.\n\nPlease retrieve the latest JamesDSP magisk package ZIP and install it via Magisk.\nNote that the magisk package may replace this app with the official JamesDSP app.\n\nDo you want to visit the download website for the Magisk packages now?</string>
<string name="version_mismatch_root_toast">Failed to start. The installed JamesDSP magisk package is too old and not supported by this app anymore.</string>

</resources>

0 comments on commit 3c4a818

Please sign in to comment.