Wire top Windows button to Android Recents via RecentsService
This commit is contained in:
1 parent
babced838b
commit
72b0d7d896
8 files changed
+129
-12
No files matched your search
+53
-8
@@ -19,23 +19,68 @@ export CARGO_APK_RELEASE_KEYSTORE_PASSWORD="${CARGO_APK_RELEASE_KEYSTORE_PASSWOR
|
||||
|
||||
cargo apk build --release
|
||||
apk="target/release/apk/ultra-launcher-wasm.apk"
|
||||
manifest="target/release/apk/AndroidManifest.xml"
|
||||
|
||||
work="target/java-build"
|
||||
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" \
|
||||
-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" \
|
||||
$(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
|
||||
src, dex, dst = sys.argv[1], sys.argv[2], sys.argv[3]
|
||||
with zipfile.ZipFile(src, "r") as zin, zipfile.ZipFile(dst, "w") as zout:
|
||||
for info in zin.infolist():
|
||||
if info.filename.startswith("META-INF/") or info.filename == "classes.dex":
|
||||
src, res_apk, dex, dst = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]
|
||||
with zipfile.ZipFile(src, "r") as zsrc, \
|
||||
zipfile.ZipFile(res_apk, "r") as zres, \
|
||||
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
|
||||
zout.writestr(info, zin.read(info.filename))
|
||||
zout.writestr(info, zsrc.read(info.filename))
|
||||
zout.write(dex, "classes.dex", compress_type=zipfile.ZIP_DEFLATED)
|
||||
PY
|
||||
|
||||
|
||||
@@ -298,6 +298,24 @@ public class LauncherActivity extends NativeActivity {
|
||||
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() {
|
||||
main.post(() -> getWindow().getDecorView().performHapticFeedback(
|
||||
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() { }
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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" />
|
||||
@@ -202,6 +202,9 @@ impl ultra::launcher::android::Host for HostState {
|
||||
fn pick_wallpaper(&mut self) {
|
||||
self.call_void("pickWallpaper", "()V", &[]);
|
||||
}
|
||||
fn open_recents(&mut self) {
|
||||
self.call_void("openRecents", "()V", &[]);
|
||||
}
|
||||
fn haptic(&mut self) {
|
||||
self.call_void("haptic", "()V", &[]);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user