Skip to content

Commit

Permalink
feat(rootless): add auto-start support (requires new permissions)
Browse files Browse the repository at this point in the history
  • Loading branch information
timschneeb committed Mar 23, 2023
1 parent 9aa791e commit 961fc44
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import me.timschneeberger.rootlessjamesdsp.activity.OnboardingActivity.Companion
import me.timschneeberger.rootlessjamesdsp.databinding.OnboardingFragmentBinding
import me.timschneeberger.rootlessjamesdsp.flavor.RootShellImpl
import me.timschneeberger.rootlessjamesdsp.service.RootAudioProcessorService
import me.timschneeberger.rootlessjamesdsp.utils.SdkCheck
import me.timschneeberger.rootlessjamesdsp.utils.extensions.ContextExtensions.isPackageInstalled
import me.timschneeberger.rootlessjamesdsp.utils.extensions.ContextExtensions.launchApp
import me.timschneeberger.rootlessjamesdsp.utils.extensions.ContextExtensions.openPlayStoreApp
Expand All @@ -36,7 +37,6 @@ import me.timschneeberger.rootlessjamesdsp.utils.extensions.PermissionExtensions
import me.timschneeberger.rootlessjamesdsp.utils.extensions.PermissionExtensions.hasNotificationPermission
import me.timschneeberger.rootlessjamesdsp.utils.extensions.PermissionExtensions.hasRecordPermission
import me.timschneeberger.rootlessjamesdsp.utils.preferences.Preferences
import me.timschneeberger.rootlessjamesdsp.utils.SdkCheck
import me.timschneeberger.rootlessjamesdsp.utils.sdkAbove
import org.koin.android.ext.android.inject
import rikka.shizuku.Shizuku
Expand Down Expand Up @@ -450,8 +450,26 @@ class OnboardingFragment : Fragment() {
Timber
.d("Granting DUMP via Shizuku (uid ${Shizuku.getUid()}) for $pkg")

// Grant DUMP as system
ShizukuSystemServerApi.PermissionManager_grantRuntimePermission(pkg, Manifest.permission.DUMP, UserHandle.USER_SYSTEM)
// Grant DUMP as shell
ShizukuSystemServerApi.PermissionManager_grantRuntimePermission(
pkg,
Manifest.permission.DUMP,
UserHandle.USER_SYSTEM
)

// Grant SYSTEM_ALERT_WINDOW as shell
try {
ShizukuSystemServerApi.PermissionManager_grantRuntimePermission(
pkg,
Manifest.permission.SYSTEM_ALERT_WINDOW,
UserHandle.USER_SYSTEM
)
}
catch (ex: Exception) {
Timber.e(ex)
}

// Grant permanent PROJECT_MEDIA op as shell
try {
val result = ShizukuSystemServerApi.AppOpsService_setMode(
ShizukuSystemServerApi.APP_OPS_OP_PROJECT_MEDIA,
Expand Down Expand Up @@ -530,6 +548,7 @@ class OnboardingFragment : Fragment() {
page.step4.isVisible = selectedSetupMethod == SetupMethods.Adb
page.step5.isVisible = selectedSetupMethod == SetupMethods.Adb
page.step5bOptional.isVisible = selectedSetupMethod == SetupMethods.Adb && BuildConfig.ROOTLESS
page.step5cOptional.isVisible = selectedSetupMethod == SetupMethods.Adb && BuildConfig.ROOTLESS

if(selectedSetupMethod == SetupMethods.Shizuku) {
val installed = requireContext().isPackageInstalled(SHIZUKU_PKG)
Expand Down Expand Up @@ -574,6 +593,7 @@ class OnboardingFragment : Fragment() {
page.step4.bodyText = getString(R.string.onboarding_adb_manual_step4, requireContext().packageName)
page.step5.bodyText = getString(R.string.onboarding_adb_manual_step5)
page.step5bOptional.bodyText = getString(R.string.onboarding_adb_manual_step5b, requireContext().packageName)
page.step5cOptional.bodyText = getString(R.string.onboarding_adb_manual_step5c, requireContext().packageName)

page.title.text = getString(R.string.onboarding_adb_adb_title)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ package me.timschneeberger.rootlessjamesdsp.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.provider.Settings
import me.timschneeberger.rootlessjamesdsp.BuildConfig
import me.timschneeberger.rootlessjamesdsp.R
import me.timschneeberger.rootlessjamesdsp.activity.EngineLauncherActivity
import me.timschneeberger.rootlessjamesdsp.service.RootAudioProcessorService
import me.timschneeberger.rootlessjamesdsp.utils.preferences.Preferences
import me.timschneeberger.rootlessjamesdsp.utils.extensions.PermissionExtensions.hasProjectMediaAppOp
import me.timschneeberger.rootlessjamesdsp.utils.notifications.ServiceNotificationHelper
import me.timschneeberger.rootlessjamesdsp.utils.preferences.Preferences
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import timber.log.Timber


class BootCompletedReceiver : BroadcastReceiver(), KoinComponent {
Expand All @@ -23,6 +27,18 @@ class BootCompletedReceiver : BroadcastReceiver(), KoinComponent {
if (!preferences.get<Boolean>(R.string.key_autostart_prompt_at_boot))
return

if(Settings.canDrawOverlays(context) && context.hasProjectMediaAppOp()) {
Timber.i("Preconditions for a silent auto-start met")
context.startActivity(Intent(context, EngineLauncherActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_MULTIPLE_TASK or
Intent.FLAG_ACTIVITY_NO_USER_ACTION or
Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS or
Intent.FLAG_ACTIVITY_NO_ANIMATION
})
return
}

ServiceNotificationHelper.pushPermissionPromptNotification(context)
}
else {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/onboarding_page4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@
app:iconSrc="@drawable/ic_twotone_info_24dp"
app:iconTint="?attr/colorOnSurface" />


<me.timschneeberger.rootlessjamesdsp.view.Card
android:id="@+id/step5c_optional"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:cardMargin="8dp"
app:iconSrc="@drawable/ic_twotone_info_24dp"
app:iconTint="?attr/colorOnSurface" />

<me.timschneeberger.rootlessjamesdsp.view.Card
android:id="@+id/step5"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
<string name="onboarding_adb_manual_step4">Navigate to \'Interactive Shell\' and execute the following command in the shell: \'pm grant %s android.permission.DUMP\'</string>
<string name="onboarding_adb_manual_step5">Tap \'Next\' in this app to continue.</string>
<string name="onboarding_adb_manual_step5b">(Optional) You can permanently skip the audio capture permission prompts by executing this command: \'appops set %s PROJECT_MEDIA allow\'</string>
<string name="onboarding_adb_manual_step5c">(Optional) In addition to the previous step, you can also enable auto-start by executing the following command: \'pm grant %s android.permission.SYSTEM_ALERT_WINDOW\'</string>
<string name="onboarding_adb_manual_step1_button">Open development settings</string>

<string name="onboarding_perm_title">Other permissions</string>
Expand Down

0 comments on commit 961fc44

Please sign in to comment.