From 9dbae5cf83c93f29cd84f85030f42a230756f72c Mon Sep 17 00:00:00 2001 From: Lorenzo Garrone Date: Sun, 15 Nov 2026 23:54:59 +0100 Subject: [PATCH] Add an opt-in Settings launcher shortcut Let the registered primary-user Settings process reconcile a Vector-owned shortcut when it opens. Keep publication separate from the saved preference and preserve existing launch routes. --- README.md | 5 + .../org/matrix/vector/daemon/VectorService.kt | 2 + .../vector/daemon/data/PreferenceStore.kt | 6 + .../vector/daemon/ipc/FrameworkService.kt | 9 ++ .../vector/daemon/ipc/ManagerService.kt | 18 +++ .../vector/daemon/ipc/SettingsShortcut.kt | 46 +++++++ .../vector/manager/demo/FakeManagerService.kt | 6 + .../matrix/vector/manager/ipc/DaemonClient.kt | 6 + .../manager/ui/screens/home/HomeViewModel.kt | 24 ++++ .../ui/screens/home/SystemStatusScreen.kt | 19 +++ manager/src/main/res/values/strings.xml | 3 + .../matrix/vector/ipc/IFrameworkService.aidl | 7 + .../vector/ipc/SettingsShortcutInfo.aidl | 10 ++ .../matrix/vector/ipc/IManagerService.aidl | 10 +- .../vector/impl/core/VectorServiceClient.kt | 4 + .../org/matrix/vector/SettingsShortcut.kt | 128 ++++++++++++++++++ .../kotlin/org/matrix/vector/core/Main.kt | 2 + 17 files changed, 304 insertions(+), 1 deletion(-) create mode 100644 daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/SettingsShortcut.kt create mode 100644 services/daemon-service/src/main/aidl/org/matrix/vector/ipc/SettingsShortcutInfo.aidl create mode 100644 zygisk/src/main/kotlin/org/matrix/vector/SettingsShortcut.kt diff --git a/README.md b/README.md index 4db56b2809..c15dd3546f 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,11 @@ Vector supports devices running **Android 8.1 through Android 17 Beta**. 4. Reboot the device. 5. Access management settings via the system notification. +On supported launchers, the primary user can also enable **Settings launcher shortcut** in +Vector's **System status**. Open Android Settings once to apply the change, then touch and hold +the Settings icon and select **Vector**. To remove the shortcut, turn the option off and open +Android Settings again before disabling or uninstalling Vector. + --- ### Downloads diff --git a/daemon/src/main/kotlin/org/matrix/vector/daemon/VectorService.kt b/daemon/src/main/kotlin/org/matrix/vector/daemon/VectorService.kt index aa22bc6a19..cb6c5de2d4 100644 --- a/daemon/src/main/kotlin/org/matrix/vector/daemon/VectorService.kt +++ b/daemon/src/main/kotlin/org/matrix/vector/daemon/VectorService.kt @@ -25,6 +25,7 @@ import org.matrix.vector.daemon.data.ProcessScope import org.matrix.vector.daemon.ipc.FrameworkService import org.matrix.vector.daemon.ipc.ManagerService import org.matrix.vector.daemon.ipc.ModuleAppService +import org.matrix.vector.daemon.ipc.SettingsShortcut import org.matrix.vector.daemon.system.* private const val TAG = "VectorService" @@ -79,6 +80,7 @@ object VectorService : IVectorDaemon.Stub() { val scope = ProcessScope(processName, uid) if (!ManagerService.tryRegisterManagerProcess(pid, uid, processName) && + !SettingsShortcut.isPublisher(uid, processName) && ConfigCache.shouldSkipProcess(scope)) { Log.d(TAG, "Skipped $processName/$uid") return null diff --git a/daemon/src/main/kotlin/org/matrix/vector/daemon/data/PreferenceStore.kt b/daemon/src/main/kotlin/org/matrix/vector/daemon/data/PreferenceStore.kt index bf1f4905f5..c87e3b6d7a 100644 --- a/daemon/src/main/kotlin/org/matrix/vector/daemon/data/PreferenceStore.kt +++ b/daemon/src/main/kotlin/org/matrix/vector/daemon/data/PreferenceStore.kt @@ -91,6 +91,12 @@ object PreferenceStore { fun setStatusNotification(enabled: Boolean) = updateModulePref("lspd", 0, "config", "enable_status_notification", enabled) + fun isSettingsShortcutEnabled(): Boolean = + getModulePrefs("lspd", 0, "config")["enable_settings_shortcut"] as? Boolean ?: false + + fun setSettingsShortcutEnabled(enabled: Boolean) = + updateModulePref("lspd", 0, "config", "enable_settings_shortcut", enabled) + fun isVerboseLogEnabled(): Boolean = getModulePrefs("lspd", 0, "config")["enable_verbose_log"] as? Boolean ?: true diff --git a/daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/FrameworkService.kt b/daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/FrameworkService.kt index 44ed1c6507..88500b707c 100644 --- a/daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/FrameworkService.kt +++ b/daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/FrameworkService.kt @@ -13,6 +13,7 @@ import java.util.concurrent.atomic.AtomicLong import org.matrix.vector.ipc.LoadedModule import org.matrix.vector.ipc.IProcessChannel import org.matrix.vector.ipc.IFrameworkService +import org.matrix.vector.ipc.SettingsShortcutInfo import org.matrix.vector.daemon.data.ConfigCache import org.matrix.vector.daemon.data.FileSystem import org.matrix.vector.daemon.system.FIRST_APPLICATION_UID @@ -276,6 +277,14 @@ object FrameworkService : IFrameworkService.Stub() { return ConfigCache.getModulesForProcess(info.processName, info.key.uid) } + override fun getSettingsShortcut(): SettingsShortcutInfo { + val info = ensureRegistered() + if (!SettingsShortcut.isPublisher(info.key.uid, info.processName)) { + throw SecurityException("Only Android Settings may read the launcher shortcut") + } + return SettingsShortcut.get() + } + override fun getModules() = getAllModules().filter { !it.code.legacy }.also { recordHotReloadTargets(ensureRegistered(), it) } diff --git a/daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/ManagerService.kt b/daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/ManagerService.kt index dc7437b05d..357bdf21ba 100644 --- a/daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/ManagerService.kt +++ b/daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/ManagerService.kt @@ -12,6 +12,7 @@ import android.content.pm.ResolveInfo import android.content.pm.VersionedPackage import android.net.Uri import android.os.Build +import android.os.Binder import android.os.Bundle import android.provider.Settings import android.os.IBinder @@ -180,6 +181,8 @@ object ManagerService : IManagerService.Stub() { return managerIntent } + internal fun managerShortcutIntent(): Intent? = getManagerIntent()?.let(::Intent) + fun openManager(withData: Uri?) { val intent = getManagerIntent() ?: return val launchIntent = Intent(intent).apply { data = withData } @@ -582,6 +585,21 @@ object ManagerService : IManagerService.Stub() { } } + override fun getSettingsShortcutMode(): Int = + when { + Binder.getCallingUid() >= PER_USER_RANGE -> IManagerService.SETTINGS_SHORTCUT_UNAVAILABLE + PreferenceStore.isSettingsShortcutEnabled() -> IManagerService.SETTINGS_SHORTCUT_ENABLED + else -> IManagerService.SETTINGS_SHORTCUT_DISABLED + } + + override fun setSettingsShortcutEnabled(enabled: Boolean): Boolean { + if (Binder.getCallingUid() >= PER_USER_RANGE) { + throw SecurityException("The Settings shortcut is only available to user 0") + } + PreferenceStore.setSettingsShortcutEnabled(enabled) + return PreferenceStore.isSettingsShortcutEnabled() == enabled + } + override fun optimizePackage(packageName: String) = PackageOptimizer.optimize(packageName) override fun getDex2OatWrapperState() = diff --git a/daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/SettingsShortcut.kt b/daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/SettingsShortcut.kt new file mode 100644 index 0000000000..89e6c83cae --- /dev/null +++ b/daemon/src/main/kotlin/org/matrix/vector/daemon/ipc/SettingsShortcut.kt @@ -0,0 +1,46 @@ +package org.matrix.vector.daemon.ipc + +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Color +import android.os.Process +import java.io.ByteArrayOutputStream +import org.matrix.vector.daemon.R +import org.matrix.vector.daemon.data.FileSystem +import org.matrix.vector.daemon.data.PreferenceStore +import org.matrix.vector.ipc.SettingsShortcutInfo + +internal object SettingsShortcut { + fun isPublisher(uid: Int, process: String): Boolean = + uid == Process.SYSTEM_UID && process == "com.android.settings" + + // Keep the icon inline. A Bitmap parcel can carry an FD that Settings cannot receive. + private val iconPng: ByteArray by lazy { + val icon = FileSystem.resources.getDrawable(R.drawable.ic_statue_monochrome, null) + val size = 96 + val inset = size / 4 + val bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888) + try { + bitmap.eraseColor(Color.rgb(18, 18, 18)) + icon.setBounds(inset, inset, size - inset, size - inset) + icon.draw(Canvas(bitmap)) + ByteArrayOutputStream().use { out -> + check(bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)) + out.toByteArray() + } + } finally { + bitmap.recycle() + } + } + + fun get(): SettingsShortcutInfo { + if (!PreferenceStore.isSettingsShortcutEnabled()) return SettingsShortcutInfo() + val intent = + checkNotNull(ManagerService.managerShortcutIntent()) { "Manager intent unavailable" } + return SettingsShortcutInfo().apply { + enabled = true + launchIntent = intent + iconPng = this@SettingsShortcut.iconPng + } + } +} diff --git a/manager/src/debug/kotlin/org/matrix/vector/manager/demo/FakeManagerService.kt b/manager/src/debug/kotlin/org/matrix/vector/manager/demo/FakeManagerService.kt index e41aaaeb7f..51092bcb86 100644 --- a/manager/src/debug/kotlin/org/matrix/vector/manager/demo/FakeManagerService.kt +++ b/manager/src/debug/kotlin/org/matrix/vector/manager/demo/FakeManagerService.kt @@ -309,6 +309,12 @@ class FakeManagerService( real?.setStatusNotificationEnabled(enabled) } + override fun getSettingsShortcutMode(): Int = + real?.settingsShortcutMode ?: IManagerService.SETTINGS_SHORTCUT_UNAVAILABLE + + override fun setSettingsShortcutEnabled(enabled: Boolean): Boolean = + real?.setSettingsShortcutEnabled(enabled) == true + override fun getIncludeNewApps(packageName: String?, userId: Int): Boolean = real?.getIncludeNewApps(packageName, userId) ?: false diff --git a/manager/src/main/kotlin/org/matrix/vector/manager/ipc/DaemonClient.kt b/manager/src/main/kotlin/org/matrix/vector/manager/ipc/DaemonClient.kt index 9000b99373..701cbd01b9 100644 --- a/manager/src/main/kotlin/org/matrix/vector/manager/ipc/DaemonClient.kt +++ b/manager/src/main/kotlin/org/matrix/vector/manager/ipc/DaemonClient.kt @@ -215,6 +215,12 @@ class DaemonClient(private val serviceState: StateFlow) { it.setStatusNotificationEnabled(enabled) } + suspend fun getSettingsShortcutMode(): Result = runIpc { it.settingsShortcutMode } + + suspend fun setSettingsShortcutEnabled(enabled: Boolean): Result = runIpc { + it.setSettingsShortcutEnabled(enabled) + } + suspend fun isVerboseLogEnabled(): Result = runIpc { it.isVerboseLogEnabled } suspend fun setVerboseLogEnabled(enabled: Boolean): Result = runIpc { it.setVerboseLogEnabled(enabled) diff --git a/manager/src/main/kotlin/org/matrix/vector/manager/ui/screens/home/HomeViewModel.kt b/manager/src/main/kotlin/org/matrix/vector/manager/ui/screens/home/HomeViewModel.kt index 725ff534dc..94f8e943bd 100644 --- a/manager/src/main/kotlin/org/matrix/vector/manager/ui/screens/home/HomeViewModel.kt +++ b/manager/src/main/kotlin/org/matrix/vector/manager/ui/screens/home/HomeViewModel.kt @@ -20,6 +20,8 @@ import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.update import kotlin.random.Random import kotlinx.coroutines.launch +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock import org.matrix.vector.ipc.IManagerService import org.matrix.vector.manager.data.github.CommunityFeed import org.matrix.vector.manager.data.github.GitHubRepository @@ -209,6 +211,10 @@ class HomeViewModel( private val _statusNotification = MutableStateFlow(true) val statusNotification: StateFlow = _statusNotification.asStateFlow() + private val _settingsShortcut = MutableStateFlow(null) + val settingsShortcut: StateFlow = _settingsShortcut.asStateFlow() + private val settingsShortcutMutex = Mutex() + // True is the platform's own default for `show_hidden_icon_apps_enabled`, so the switch shows // what the system is doing on a device where nobody has touched it rather than reading "off" // until the daemon answers. @@ -552,8 +558,26 @@ class HomeViewModel( .isForcedLauncherIcons() .onSuccess { _hiddenIcon.value = it } .onFailure { e -> logW("status: launcher-icon toggle unread", e) } + settingsShortcutMutex.withLock { + _settingsShortcut.value = + when (daemon.getSettingsShortcutMode().getOrNull()) { + IManagerService.SETTINGS_SHORTCUT_DISABLED -> false + IManagerService.SETTINGS_SHORTCUT_ENABLED -> true + else -> null + } + } } + suspend fun setSettingsShortcut(enabled: Boolean): Boolean = + settingsShortcutMutex.withLock { + val saved = + daemon.setSettingsShortcutEnabled(enabled) + .onFailure { e -> logE("Could not change the Settings shortcut preference", e) } + .getOrDefault(false) + if (saved) _settingsShortcut.value = enabled + saved + } + fun setStatusNotification(enabled: Boolean) { viewModelScope.launch { daemon diff --git a/manager/src/main/kotlin/org/matrix/vector/manager/ui/screens/home/SystemStatusScreen.kt b/manager/src/main/kotlin/org/matrix/vector/manager/ui/screens/home/SystemStatusScreen.kt index f63f0dd9c9..d6fc699e6c 100644 --- a/manager/src/main/kotlin/org/matrix/vector/manager/ui/screens/home/SystemStatusScreen.kt +++ b/manager/src/main/kotlin/org/matrix/vector/manager/ui/screens/home/SystemStatusScreen.kt @@ -96,6 +96,8 @@ fun SystemStatusScreen( val device = viewModel.device val context = LocalContext.current val statusNotification by viewModel.statusNotification.collectAsStateWithLifecycle() + val settingsShortcut by viewModel.settingsShortcut.collectAsStateWithLifecycle() + val settingsShortcutFailed = stringResource(R.string.settings_shortcut_save_failed) val hiddenIcon by viewModel.hiddenIcon.collectAsStateWithLifecycle() val presence by viewModel.presence.collectAsStateWithLifecycle() val managerInstall by viewModel.managerInstall.collectAsStateWithLifecycle() @@ -228,6 +230,23 @@ fun SystemStatusScreen( onCheckedChange = viewModel::setForcedLauncherIcons, ) } + settingsShortcut?.let { enabled -> + item { + FrameworkToggle( + title = stringResource(R.string.settings_shortcut), + subtitle = stringResource(R.string.settings_shortcut_summary), + checked = enabled, + enabled = daemonAlive, + onCheckedChange = { requested -> + scope.launch { + if (!viewModel.setSettingsShortcut(requested)) { + snackbars.show(settingsShortcutFailed, SnackbarTone.Failure) + } + } + }, + ) + } + } // How to get back in. Only parasitically: installed, the manager has a launcher icon // like any other app and none of this means anything. diff --git a/manager/src/main/res/values/strings.xml b/manager/src/main/res/values/strings.xml index 4ae291426e..dd9b1b6e3e 100644 --- a/manager/src/main/res/values/strings.xml +++ b/manager/src/main/res/values/strings.xml @@ -90,6 +90,9 @@ Not injected Status notification A persistent notification showing that Vector is running. + Settings launcher shortcut + Open Android Settings after changing this option. On supported launchers, touch and hold the Settings icon to open Vector. + Could not save the Settings shortcut preference. Stop apps hiding their launcher icons Since Android 10, an app that hides its own launcher icon gets one back that opens its app info page. Turn this off to let it stay hidden — your launcher may not catch up until it restarts. Apps that never had a launcher icon, including most modules, are unaffected. diff --git a/services/daemon-service/src/main/aidl/org/matrix/vector/ipc/IFrameworkService.aidl b/services/daemon-service/src/main/aidl/org/matrix/vector/ipc/IFrameworkService.aidl index 2d74b199eb..8eff74fe63 100644 --- a/services/daemon-service/src/main/aidl/org/matrix/vector/ipc/IFrameworkService.aidl +++ b/services/daemon-service/src/main/aidl/org/matrix/vector/ipc/IFrameworkService.aidl @@ -2,6 +2,7 @@ package org.matrix.vector.ipc; import org.matrix.vector.ipc.LoadedModule; import org.matrix.vector.ipc.IProcessChannel; +import org.matrix.vector.ipc.SettingsShortcutInfo; /** * What an injected process asks the framework for, once the zygisk handshake has given it one. @@ -73,4 +74,10 @@ interface IFrameworkService { * every later hot reload answers UNSUPPORTED with "no hot reload entry point".

*/ void attachProcessChannel(IProcessChannel channel); + + /** + * Returns the configured shortcut state. Only the registered Settings process for user 0 + * may call this. A missing reply does not give permission to remove a shortcut. + */ + @nullable SettingsShortcutInfo getSettingsShortcut(); } diff --git a/services/daemon-service/src/main/aidl/org/matrix/vector/ipc/SettingsShortcutInfo.aidl b/services/daemon-service/src/main/aidl/org/matrix/vector/ipc/SettingsShortcutInfo.aidl new file mode 100644 index 0000000000..dced247e70 --- /dev/null +++ b/services/daemon-service/src/main/aidl/org/matrix/vector/ipc/SettingsShortcutInfo.aidl @@ -0,0 +1,10 @@ +package org.matrix.vector.ipc; + +import android.content.Intent; + +/** Launch data for the shortcut owned by the Android Settings app. */ +parcelable SettingsShortcutInfo { + boolean enabled; + @nullable Intent launchIntent; + @nullable byte[] iconPng; +} diff --git a/services/manager-service/src/main/aidl/org/matrix/vector/ipc/IManagerService.aidl b/services/manager-service/src/main/aidl/org/matrix/vector/ipc/IManagerService.aidl index 78cfb9eddb..fbafc06c2f 100644 --- a/services/manager-service/src/main/aidl/org/matrix/vector/ipc/IManagerService.aidl +++ b/services/manager-service/src/main/aidl/org/matrix/vector/ipc/IManagerService.aidl @@ -73,7 +73,7 @@ interface IManagerService { * transaction ids follow declaration order, this number is the only thing standing between a * mismatched pair and a call that lands on the wrong method.

*/ - const int PROTOCOL_VERSION = 3; + const int PROTOCOL_VERSION = 4; /** * Which generation of this interface the daemon implements, never below 1. @@ -799,4 +799,12 @@ interface IManagerService { /** APatch. */ const int ROOT_APATCH = 5; + + const int SETTINGS_SHORTCUT_UNAVAILABLE = 0; + const int SETTINGS_SHORTCUT_DISABLED = 1; + const int SETTINGS_SHORTCUT_ENABLED = 2; + + int getSettingsShortcutMode(); + /** Returns true once the preference is stored. Settings applies it when next opened. */ + boolean setSettingsShortcutEnabled(boolean enabled); } diff --git a/xposed/src/main/kotlin/org/matrix/vector/impl/core/VectorServiceClient.kt b/xposed/src/main/kotlin/org/matrix/vector/impl/core/VectorServiceClient.kt index 33710418ec..faee965ff3 100644 --- a/xposed/src/main/kotlin/org/matrix/vector/impl/core/VectorServiceClient.kt +++ b/xposed/src/main/kotlin/org/matrix/vector/impl/core/VectorServiceClient.kt @@ -5,6 +5,7 @@ import android.os.ParcelFileDescriptor import org.matrix.vector.ipc.LoadedModule import org.matrix.vector.ipc.IProcessChannel import org.matrix.vector.ipc.IFrameworkService +import org.matrix.vector.ipc.SettingsShortcutInfo import org.matrix.vector.util.Log /** @@ -78,6 +79,9 @@ object VectorServiceClient : IFrameworkService, IBinder.DeathRecipient { return runCatching { service?.requestManagerService() }.getOrNull() } + override fun getSettingsShortcut(): SettingsShortcutInfo? = + checkNotNull(service) { "Daemon unavailable" }.settingsShortcut + override fun asBinder(): IBinder? { return service?.asBinder() } diff --git a/zygisk/src/main/kotlin/org/matrix/vector/SettingsShortcut.kt b/zygisk/src/main/kotlin/org/matrix/vector/SettingsShortcut.kt new file mode 100644 index 0000000000..c5bc0db9e6 --- /dev/null +++ b/zygisk/src/main/kotlin/org/matrix/vector/SettingsShortcut.kt @@ -0,0 +1,128 @@ +package org.matrix.vector + +import android.app.Activity +import android.app.ActivityThread +import android.app.Application +import android.content.Intent +import android.content.pm.ShortcutInfo +import android.content.pm.ShortcutManager +import android.graphics.BitmapFactory +import android.graphics.drawable.Icon +import android.os.Bundle +import android.os.Process +import android.os.UserManager +import java.util.concurrent.LinkedBlockingQueue +import java.util.concurrent.ThreadPoolExecutor +import java.util.concurrent.TimeUnit +import java.util.concurrent.atomic.AtomicBoolean +import org.matrix.vector.impl.core.VectorServiceClient +import org.matrix.vector.impl.hooks.VectorHookBuilder +import org.matrix.vector.util.Utils + +/** Publishes in the process that owns the Settings launcher icon. */ +internal object SettingsShortcut { + private const val SETTINGS_PACKAGE = "com.android.settings" + private const val ID = "org.matrix.vector.settings.shortcut" + private var publisher: Publisher? = null + + fun install(processName: String) { + if (processName != SETTINGS_PACKAGE || Process.myUid() != Process.SYSTEM_UID) return + runCatching { + val application = ActivityThread.currentApplication() + if (application != null) { + start(application) + } else { + val bindData = Class.forName("android.app.ActivityThread\$AppBindData") + val bind = + ActivityThread::class.java.getDeclaredMethod("handleBindApplication", bindData) + VectorHookBuilder(bind).intercept { chain -> + chain.proceed().also { + runCatching { ActivityThread.currentApplication()?.let(::start) } + .onFailure { + Utils.logW("Could not observe Settings activity launches", it) + } + } + } + } + } + .onFailure { Utils.logW("Could not register the Settings shortcut publisher", it) } + } + + private fun start(application: Application) { + if (application.packageName != SETTINGS_PACKAGE || publisher != null) return + val entry = Publisher(application) + application.registerActivityLifecycleCallbacks(entry) + publisher = entry + entry.schedule() + } + + private class Publisher(private val application: Application) : + Application.ActivityLifecycleCallbacks { + private val worker = + ThreadPoolExecutor(0, 1, 15, TimeUnit.SECONDS, LinkedBlockingQueue()) { + Thread(it, "vector-settings-shortcut") + } + private val queued = AtomicBoolean() + + // Accessed only on the worker. + private var publishedIntent: Intent? = null + + fun schedule() { + if (!queued.compareAndSet(false, true)) return + worker.execute { + queued.set(false) + runCatching { updateShortcut() } + .onFailure { + Utils.logW("Could not update the Vector shortcut in Settings", it) + } + } + } + + private fun updateShortcut() { + if (application.getSystemService(UserManager::class.java)?.isUserUnlocked != true) + return + val shortcutManager = + application.getSystemService(ShortcutManager::class.java) ?: return + val data = VectorServiceClient.settingsShortcut ?: return + val existing = shortcutManager.dynamicShortcuts.any { it.id == ID && it.isEnabled } + if (!data.enabled) { + val pinned = shortcutManager.pinnedShortcuts.any { it.id == ID && it.isEnabled } + if (existing || pinned) shortcutManager.disableShortcuts(listOf(ID)) + publishedIntent = null + return + } + + val intent = checkNotNull(data.launchIntent) { "Manager intent unavailable" } + if (existing && intent.filterEquals(publishedIntent)) return + val png = checkNotNull(data.iconPng) { "Manager icon unavailable" } + check(png.size in 1..(64 * 1024)) { "Invalid Settings shortcut icon size" } + val bitmap = + BitmapFactory.decodeByteArray(png, 0, png.size) + ?: error("Invalid Settings shortcut icon") + val shortcut = + ShortcutInfo.Builder(application, ID) + .setShortLabel("Vector") + .setIcon(Icon.createWithAdaptiveBitmap(bitmap)) + .setIntent(intent) + .build() + // Merge this ID into Settings' shortcuts without replacing any other publisher's ID. + if (shortcutManager.addDynamicShortcuts(listOf(shortcut))) { + publishedIntent = intent + } + } + + override fun onActivityResumed(activity: Activity) = schedule() + + override fun onActivityCreated(activity: Activity, state: Bundle?) = Unit + + override fun onActivityStarted(activity: Activity) = Unit + + override fun onActivityPaused(activity: Activity) = Unit + + override fun onActivityStopped(activity: Activity) = Unit + + override fun onActivitySaveInstanceState(activity: Activity, state: Bundle) = Unit + + override fun onActivityDestroyed(activity: Activity) = Unit + } +} diff --git a/zygisk/src/main/kotlin/org/matrix/vector/core/Main.kt b/zygisk/src/main/kotlin/org/matrix/vector/core/Main.kt index 69629a7bff..e6269f73bc 100644 --- a/zygisk/src/main/kotlin/org/matrix/vector/core/Main.kt +++ b/zygisk/src/main/kotlin/org/matrix/vector/core/Main.kt @@ -9,6 +9,7 @@ import org.matrix.vector.BuildConfig import org.matrix.vector.GrapheneDclHooker import org.matrix.vector.ParasiticManagerHooker import org.matrix.vector.ParasiticManagerSystemHooker +import org.matrix.vector.SettingsShortcut import org.matrix.vector.Startup import org.matrix.vector.impl.core.VectorServiceClient @@ -44,6 +45,7 @@ object Main { // Initialize Xposed bridge components val appService = IFrameworkService.Stub.asInterface(binder) Startup.initXposed(isSystem, niceName, appDir, appService) + if (!isSystem) SettingsShortcut.install(niceName) // Configure logging levels from the service client runCatching { Log.muted = VectorServiceClient.isLogMuted }