diff --git a/app/src/main/java/com/sdex/activityrunner/app/ActivityLauncher.kt b/app/src/main/java/com/sdex/activityrunner/app/ActivityLauncher.kt
index c4ce72e6..d87a6030 100644
--- a/app/src/main/java/com/sdex/activityrunner/app/ActivityLauncher.kt
+++ b/app/src/main/java/com/sdex/activityrunner/app/ActivityLauncher.kt
@@ -34,17 +34,17 @@ fun Activity.launchActivity(
fun Activity.launchActivity(
componentName: ComponentName,
- isExported: Boolean,
+ useRoot: Boolean,
) {
- if (isExported) {
+ if (useRoot) {
+ launchActivityWithRoot(this, componentName)
+ } else {
IntentUtils.launchActivity(
this,
componentName,
componentName.className.split(".").last(),
false
)
- } else {
- launchActivityWithRoot(this, componentName)
}
}
diff --git a/app/src/main/java/com/sdex/activityrunner/shortcut/AddShortcutDialogActivity.kt b/app/src/main/java/com/sdex/activityrunner/shortcut/AddShortcutDialogActivity.kt
index f6d01272..57ea9c81 100644
--- a/app/src/main/java/com/sdex/activityrunner/shortcut/AddShortcutDialogActivity.kt
+++ b/app/src/main/java/com/sdex/activityrunner/shortcut/AddShortcutDialogActivity.kt
@@ -14,6 +14,7 @@ import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia
import androidx.appcompat.app.AppCompatActivity
import androidx.core.graphics.drawable.toBitmap
+import androidx.core.view.isVisible
import androidx.core.widget.doOnTextChanged
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.CustomTarget
@@ -99,6 +100,8 @@ class AddShortcutDialogActivity : AppCompatActivity(), IconDialog.Callback {
override fun onLoadCleared(placeholder: Drawable?) {
}
})
+ binding.useRoot.isVisible = true
+ binding.useRoot.isChecked = !activityModel.exported
}
if (historyModel != null) {
@@ -124,11 +127,19 @@ class AddShortcutDialogActivity : AppCompatActivity(), IconDialog.Callback {
activityModel?.let {
val model = it.copy(name = shortcutName)
- IntentUtils.createLauncherIcon(this, model, bitmap)
+ IntentUtils.createLauncherIcon(
+ this,
+ model,
+ bitmap,
+ binding.useRoot.isChecked
+ )
}
historyModel?.let {
- createHistoryModelShortcut(historyModel, shortcutName)
+ createHistoryModelShortcut(
+ historyModel,
+ shortcutName
+ )
}
finish()
diff --git a/app/src/main/java/com/sdex/activityrunner/shortcut/ShortcutHandlerActivity.kt b/app/src/main/java/com/sdex/activityrunner/shortcut/ShortcutHandlerActivity.kt
index 0c183dad..eca4a594 100644
--- a/app/src/main/java/com/sdex/activityrunner/shortcut/ShortcutHandlerActivity.kt
+++ b/app/src/main/java/com/sdex/activityrunner/shortcut/ShortcutHandlerActivity.kt
@@ -4,6 +4,7 @@ import android.app.Activity
import android.content.ComponentName
import android.os.Bundle
import com.sdex.activityrunner.app.launchActivity
+import timber.log.Timber
class ShortcutHandlerActivity : Activity() {
@@ -11,10 +12,17 @@ class ShortcutHandlerActivity : Activity() {
super.onCreate(savedInstanceState)
val packageName = intent.getStringExtra(ARG_PACKAGE_NAME)
val className = intent.getStringExtra(ARG_CLASS_NAME)
- val isExported = intent.getBooleanExtra(ARG_EXPORTED, false)
+ Timber.d("Shortcut: packageName=$packageName, className=$className")
if (packageName != null && className != null) {
val componentName = ComponentName(packageName, className)
- launchActivity(componentName, isExported)
+ // keep it to support shortcuts created before #56
+ if (intent.hasExtra(ARG_EXPORTED)) {
+ val isExported = intent.getBooleanExtra(ARG_EXPORTED, false)
+ launchActivity(componentName, useRoot = !isExported)
+ } else {
+ val useRoot = intent.getBooleanExtra(ARG_USE_ROOT, false)
+ launchActivity(componentName, useRoot = useRoot)
+ }
}
finishAffinity()
}
@@ -24,5 +32,6 @@ class ShortcutHandlerActivity : Activity() {
const val ARG_PACKAGE_NAME = "arg_package_name"
const val ARG_CLASS_NAME = "arg_class_name"
const val ARG_EXPORTED = "arg_exported"
+ const val ARG_USE_ROOT = "arg_use_root"
}
}
diff --git a/app/src/main/java/com/sdex/activityrunner/util/IntentUtils.kt b/app/src/main/java/com/sdex/activityrunner/util/IntentUtils.kt
index be651276..d54be245 100644
--- a/app/src/main/java/com/sdex/activityrunner/util/IntentUtils.kt
+++ b/app/src/main/java/com/sdex/activityrunner/util/IntentUtils.kt
@@ -36,9 +36,16 @@ object IntentUtils {
}
}
- fun createLauncherIcon(context: Context, activityModel: ActivityModel, bitmap: Bitmap?) {
+ fun createLauncherIcon(
+ context: Context,
+ activityModel: ActivityModel,
+ bitmap: Bitmap?,
+ useRoot: Boolean = false,
+ ) {
if (bitmap != null) {
- val intent = activityModel.toIntent(context)
+ val intent = activityModel.toIntent(context).apply {
+ putExtra(ShortcutHandlerActivity.ARG_USE_ROOT, useRoot)
+ }
val iconCompat = try {
IconCompat.createWithBitmap(bitmap)
} catch (e: Exception) { // android.os.TransactionTooLargeException
@@ -60,7 +67,6 @@ object IntentUtils {
val intent = getActivityIntent(Intent.ACTION_VIEW, component)
intent.putExtra(ShortcutHandlerActivity.ARG_PACKAGE_NAME, this.packageName)
intent.putExtra(ShortcutHandlerActivity.ARG_CLASS_NAME, this.className)
- intent.putExtra(ShortcutHandlerActivity.ARG_EXPORTED, this.exported)
return intent
}
diff --git a/app/src/main/res/layout/activity_add_shortcut.xml b/app/src/main/res/layout/activity_add_shortcut.xml
index 1f53b0c7..e07fd507 100644
--- a/app/src/main/res/layout/activity_add_shortcut.xml
+++ b/app/src/main/res/layout/activity_add_shortcut.xml
@@ -51,6 +51,17 @@
+
+
+ app:layout_constraintTop_toBottomOf="@+id/use_root" />