Wire top Windows button to Android Recents via RecentsService

This commit is contained in:
nandi committed 2026-11-13 10:50:46 -08:00
1 parent babced838b
commit 72b0d7d896
8 files changed
+129 -12

No files matched your search

+53 -8
View File
@@ -19,23 +19,68 @@ export CARGO_APK_RELEASE_KEYSTORE_PASSWORD="${CARGO_APK_RELEASE_KEYSTORE_PASSWOR
cargo apk build --release cargo apk build --release
apk="target/release/apk/ultra-launcher-wasm.apk" apk="target/release/apk/ultra-launcher-wasm.apk"
manifest="target/release/apk/AndroidManifest.xml"
work="target/java-build" work="target/java-build"
rm -rf "$work" rm -rf "$work"
mkdir -p "$work/classes" "$work/dex" mkdir -p "$work/classes" "$work/dex" "$work/res"
python3 - "$manifest" "$work/AndroidManifest.xml" <<'PY'
import sys
src, dst = sys.argv[1], sys.argv[2]
xml = open(src, "r", encoding="utf-8").read()
service = """ <service
android:name="dev.ultra.launcher.wasm.RecentsService"
android:label="@string/recents_service_label"
android:exported="true"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/recents_service" />
</service>
"""
if "dev.ultra.launcher.wasm.RecentsService" not in xml:
xml = xml.replace("</application>", service + " </application>")
open(dst, "w", encoding="utf-8").write(xml)
PY
"$BUILD_TOOLS/aapt2" compile --dir res -o "$work/res.zip"
"$BUILD_TOOLS/aapt2" link \
--manifest "$work/AndroidManifest.xml" \
-I "$PLATFORM/android.jar" \
"$work/res.zip" \
-o "$work/res.apk" \
--auto-add-overlay
javac --release 11 -classpath "$PLATFORM/android.jar" \ javac --release 11 -classpath "$PLATFORM/android.jar" \
-d "$work/classes" java/dev/ultra/launcher/wasm/LauncherActivity.java -d "$work/classes" \
java/dev/ultra/launcher/wasm/LauncherActivity.java \
java/dev/ultra/launcher/wasm/RecentsService.java
"$BUILD_TOOLS/d8" --min-api 30 --output "$work/dex" \ "$BUILD_TOOLS/d8" --min-api 30 --output "$work/dex" \
$(find "$work/classes" -name '*.class') $(find "$work/classes" -name '*.class')
python3 - "$apk" "$work/dex/classes.dex" "$work/unaligned.apk" <<'PY' python3 - "$apk" "$work/res.apk" "$work/dex/classes.dex" "$work/unaligned.apk" <<'PY'
import sys, zipfile import sys, zipfile
src, dex, dst = sys.argv[1], sys.argv[2], sys.argv[3] src, res_apk, dex, dst = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]
with zipfile.ZipFile(src, "r") as zin, zipfile.ZipFile(dst, "w") as zout: with zipfile.ZipFile(src, "r") as zsrc, \
for info in zin.infolist(): zipfile.ZipFile(res_apk, "r") as zres, \
if info.filename.startswith("META-INF/") or info.filename == "classes.dex": zipfile.ZipFile(dst, "w") as zout:
for info in zres.infolist():
if info.filename == "resources.arsc":
zout.writestr(info, zres.read(info.filename), compress_type=zipfile.ZIP_STORED)
else:
zout.writestr(info, zres.read(info.filename))
for info in zsrc.infolist():
if (info.filename.startswith("META-INF/")
or info.filename == "classes.dex"
or info.filename == "AndroidManifest.xml"
or info.filename == "resources.arsc"
or info.filename.startswith("res/")):
continue continue
zout.writestr(info, zin.read(info.filename)) zout.writestr(info, zsrc.read(info.filename))
zout.write(dex, "classes.dex", compress_type=zipfile.ZIP_DEFLATED) zout.write(dex, "classes.dex", compress_type=zipfile.ZIP_DEFLATED)
PY PY
@@ -298,6 +298,24 @@ public class LauncherActivity extends NativeActivity {
new Intent(Intent.ACTION_SET_WALLPAPER), "Wallpaper").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))); new Intent(Intent.ACTION_SET_WALLPAPER), "Wallpaper").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)));
} }
public void openRecents() {
main.post(() -> {
if (RecentsService.showRecents()) return;
Toast.makeText(this, "Turn on \"ultra Wasm window list\" to show open windows", Toast.LENGTH_LONG).show();
String me = new ComponentName(this, RecentsService.class).flattenToString();
Bundle args = new Bundle();
args.putString(":settings:fragment_args_key", me);
try {
startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
.putExtra(":settings:fragment_args_key", me)
.putExtra(":settings:show_fragment_args", args)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "Not available on this device", Toast.LENGTH_SHORT).show();
}
});
}
public void haptic() { public void haptic() {
main.post(() -> getWindow().getDecorView().performHapticFeedback( main.post(() -> getWindow().getDecorView().performHapticFeedback(
HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING)); HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING));
@@ -0,0 +1,38 @@
package dev.ultra.launcher.wasm;
import android.accessibilityservice.AccessibilityService;
import android.content.Intent;
import android.view.accessibility.AccessibilityEvent;
/**
* Accessibility service that opens Recents (the system's list of open windows)
* for the home screen's Windows button.
*/
public class RecentsService extends AccessibilityService {
private static volatile RecentsService running;
public static boolean showRecents() {
RecentsService s = running;
return s != null && s.performGlobalAction(GLOBAL_ACTION_RECENTS);
}
@Override
protected void onServiceConnected() {
running = this;
}
@Override
public boolean onUnbind(Intent intent) {
running = null;
return super.onUnbind(intent);
}
@Override
public void onDestroy() {
running = null;
super.onDestroy();
}
@Override public void onAccessibilityEvent(AccessibilityEvent event) { }
@Override public void onInterrupt() { }
}
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="recents_service_label">ultra Wasm window list</string>
<string name="recents_service_summary">Lets the home screen\'s Windows button open Recents</string>
<string name="recents_service_description">Turn this on so the Windows button on the ultra Wasm Home screen can show your open windows (Recents). Android only lets accessibility services open Recents. This service reads nothing on screen and does nothing else.</string>
</resources>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityFlags="flagDefault"
android:canRetrieveWindowContent="false"
android:description="@string/recents_service_description"
android:summary="@string/recents_service_summary" />
+3
View File
@@ -202,6 +202,9 @@ impl ultra::launcher::android::Host for HostState {
fn pick_wallpaper(&mut self) { fn pick_wallpaper(&mut self) {
self.call_void("pickWallpaper", "()V", &[]); self.call_void("pickWallpaper", "()V", &[]);
} }
fn open_recents(&mut self) {
self.call_void("openRecents", "()V", &[]);
}
fn haptic(&mut self) { fn haptic(&mut self) {
self.call_void("haptic", "()V", &[]); self.call_void("haptic", "()V", &[]);
} }
+4 -4
View File
@@ -435,7 +435,7 @@ void LauncherWindow::drawIconAndLabel(QPainter &p, const QRectF &box, const QStr
} }
void LauncherWindow::drawHome(QPainter &p) { void LauncherWindow::drawHome(QPainter &p) {
// Top pill ("Apps") // Top pill ("Windows" -> opens system Recents / window list)
const QRectF pill = appsPillRect(); const QRectF pill = appsPillRect();
p.setPen(QPen(QColor(255, 255, 255, 55), 1.0)); p.setPen(QPen(QColor(255, 255, 255, 55), 1.0));
p.setBrush(QColor(24, 24, 30, 135)); p.setBrush(QColor(24, 24, 30, 135));
@@ -446,7 +446,7 @@ void LauncherWindow::drawHome(QPainter &p) {
f.setWeight(QFont::Medium); f.setWeight(QFont::Medium);
p.setFont(f); p.setFont(f);
p.setPen(Qt::white); p.setPen(Qt::white);
p.drawText(pill, Qt::AlignCenter, QStringLiteral("Apps")); p.drawText(pill, Qt::AlignCenter, QStringLiteral("Windows"));
if (m_home.isEmpty()) { if (m_home.isEmpty()) {
f.setPixelSize(14); f.setPixelSize(14);
@@ -455,7 +455,7 @@ void LauncherWindow::drawHome(QPainter &p) {
p.setPen(QColor(255, 255, 255, 190)); p.setPen(QColor(255, 255, 255, 190));
p.drawText(QRectF(gridX(), gridTop() + 40.0, gridW(), 60.0), p.drawText(QRectF(gridX(), gridTop() + 40.0, gridW(), 60.0),
Qt::AlignHCenter | Qt::AlignTop | Qt::TextWordWrap, Qt::AlignHCenter | Qt::AlignTop | Qt::TextWordWrap,
QStringLiteral("Swipe down or tap Apps • Long press for menu")); QStringLiteral("Swipe down for Apps • Long press for menu"));
return; return;
} }
@@ -705,7 +705,7 @@ void LauncherWindow::mouseReleaseEvent(QMouseEvent *event) {
} }
if (appsPillRect().contains(pos)) { if (appsPillRect().contains(pos)) {
openDrawer(); ultra_launcher_android_open_recents();
return; return;
} }
+1
View File
@@ -10,6 +10,7 @@ interface android {
uninstall: func(component: string); uninstall: func(component: string);
open-settings: func(); open-settings: func();
pick-wallpaper: func(); pick-wallpaper: func();
open-recents: func();
haptic: func(); haptic: func();
/// System bar insets in physical screen pixels: (top, bottom). /// System bar insets in physical screen pixels: (top, bottom).
insets: func() -> tuple<u32, u32>; insets: func() -> tuple<u32, u32>;