Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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() =
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ class DaemonClient(private val serviceState: StateFlow<IManagerService?>) {
it.setStatusNotificationEnabled(enabled)
}

suspend fun getSettingsShortcutMode(): Result<Int> = runIpc { it.settingsShortcutMode }

suspend fun setSettingsShortcutEnabled(enabled: Boolean): Result<Boolean> = runIpc {
it.setSettingsShortcutEnabled(enabled)
}

suspend fun isVerboseLogEnabled(): Result<Boolean> = runIpc { it.isVerboseLogEnabled }

suspend fun setVerboseLogEnabled(enabled: Boolean): Result<Unit> = runIpc { it.setVerboseLogEnabled(enabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -209,6 +211,10 @@ class HomeViewModel(
private val _statusNotification = MutableStateFlow(true)
val statusNotification: StateFlow<Boolean> = _statusNotification.asStateFlow()

private val _settingsShortcut = MutableStateFlow<Boolean?>(null)
val settingsShortcut: StateFlow<Boolean?> = _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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions manager/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
<string name="info_not_injected">Not injected</string>
<string name="status_notification">Status notification</string>
<string name="status_notification_summary">A persistent notification showing that Vector is running.</string>
<string name="settings_shortcut">Settings launcher shortcut</string>
<string name="settings_shortcut_summary">Open Android Settings after changing this option. On supported launchers, touch and hold the Settings icon to open Vector.</string>
<string name="settings_shortcut_save_failed">Could not save the Settings shortcut preference.</string>
<string name="force_launcher_icons">Stop apps hiding their launcher icons</string>
<string name="force_launcher_icons_summary">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.</string>
<!-- Home: the community feed -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -73,4 +74,10 @@ interface IFrameworkService {
* every later hot reload answers UNSUPPORTED with "no hot reload entry point".</p>
*/
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();
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.</p>
*/
const int PROTOCOL_VERSION = 3;
const int PROTOCOL_VERSION = 4;

/**
* Which generation of this interface the daemon implements, never below 1.
Expand Down Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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()
}
Expand Down
Loading