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
12 changes: 5 additions & 7 deletions .github/workflows/mobile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,20 @@ jobs:
echo "::error::Android emulator did not boot. $emulator_error"
exit 1
fi
if ! timeout 60 adb install --no-incremental "$CARGO_TARGET_DIR/x86_64-linux-android/OXMobile-debug.apk" ||
! timeout 30 adb shell am start -W -n dev.ox.mobile/dev.gpui.mobile.GpuiInputActivity; then
tail -60 "$emulator_log"
exit 1
fi
sleep 5
if ! timeout 5 adb shell pidof dev.ox.mobile; then
if ! bash desktop/ox-mobile/check-android-relaunch.sh \
"$CARGO_TARGET_DIR/x86_64-linux-android/OXMobile-debug.apk" \
"$RUNNER_TEMP/android-relaunch"; then
tail -60 "$emulator_log"
timeout 10 adb logcat -d -t 500 || true
timeout 10 adb logcat -b crash -d || true
exit 1
fi
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: always()
with:
name: mobile-android-debug
path: |
${{ runner.temp }}/android-relaunch
${{ runner.temp }}/ox-android-target/x86_64-linux-android/OXMobile-debug.apk
${{ runner.temp }}/mobile-emulator.log
- name: Build unsigned Android arm64 release
Expand Down
12 changes: 8 additions & 4 deletions desktop/ox-mobile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,14 @@ desktop/ox-mobile/build-android.sh x86_64-linux-android
For an ARM64 device use `aarch64-linux-android` in the target paths and
arguments. This is a debug APK for testing the native flow.

The Android 15 x86_64 emulator smoke test covered app launch, touch
scrolling, emoji rendering, and multiline typing with the software
keyboard. The composer stayed above the system bars and the keyboard
reopened on tap after dismissal. Live host testing on a phone is pending.
The Android 15 x86_64 emulator smoke test runs
[`check-android-relaunch.sh`](check-android-relaunch.sh): it launches the app,
presses ordinary Back at the unpaired root, and requires the first process to
end before relaunching as a different, resumed process with no app crash. The
smoke test also covered app launch, touch scrolling, emoji rendering, and
multiline typing with the software keyboard. The composer stayed above the
system bars and the keyboard reopened on tap after dismissal. Live host
testing on a phone is pending.

### Build and sign an Android APK for direct distribution

Expand Down
2 changes: 1 addition & 1 deletion desktop/ox-mobile/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
android:usesCleartextTraffic="false">
<activity
android:name="dev.gpui.mobile.GpuiInputActivity"
android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|keyboardHidden|keyboard|navigation|uiMode|density|fontScale"
android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|keyboardHidden|keyboard|navigation|uiMode|density|fontScale|locale|layoutDirection"
android:exported="true"
android:windowSoftInputMode="adjustResize">
<meta-data android:name="android.app.lib_name" android:value="ox_mobile" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<activity android:name="dev.gpui.mobile.GpuiInputActivity" tools:node="remove" />
<activity
android:name="dev.ox.mobile.OXAlertActivity"
android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|keyboardHidden|keyboard|navigation|uiMode|density|fontScale"
android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|keyboardHidden|keyboard|navigation|uiMode|density|fontScale|locale|layoutDirection"
android:exported="false"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize">
Expand Down
3 changes: 2 additions & 1 deletion desktop/ox-mobile/check-android-fcm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ PYMANIFEST
# The normal no-config build and the emulator check stay in place.
grep -Fq 'build-android.sh x86_64-linux-android' .github/workflows/mobile.yml || die "the Android CI build step is missing"
grep -Fq 'OXMobile-debug.apk' .github/workflows/mobile.yml || die "the Android emulator install step is missing"
grep -Fq 'pidof dev.ox.mobile' .github/workflows/mobile.yml || die "the Android launch check is missing"
grep -Fq 'desktop/ox-mobile/check-android-relaunch.sh' .github/workflows/mobile.yml || die "the Android relaunch check is missing"
bash -n "$mobile/check-android-relaunch.sh" || die "the Android relaunch check has invalid shell syntax"
grep -Fq 'check-android-fcm.sh' .github/workflows/mobile.yml || die "the Firebase static check is not in Android CI"
grep -Fq '"$tools/zipalign" -f -P 16 4' "$mobile/build-android.sh" || die "the normal APK lost 16 KiB zip alignment"
grep -Fq -- '--min-sdk-version 28' "$mobile/build-android.sh" || die "the normal APK lost minSdk 28"
Expand Down
163 changes: 163 additions & 0 deletions desktop/ox-mobile/check-android-relaunch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#!/usr/bin/env bash
# The GPUI Android platform belongs to one Activity's native thread. When that
# Activity ends, the process must exit so a later launcher intent starts a new
# platform instead of inheriting the spent one. Exercise that path the way a
# user does: launch, press ordinary Back at the unpaired root, and launch
# again. Never force-stop the package, which would hide the regression.
set -euo pipefail

apk="${1:?Provide the Android debug APK}"
artifacts="${2:?Provide a directory for relaunch diagnostics}"
mkdir -p "$artifacts"

package=dev.ox.mobile
component="$package/dev.gpui.mobile.GpuiInputActivity"
adb="${ADB:-adb}"
launch_timeout=45

package_pid() {
timeout 5 "$adb" shell pidof "$package" 2>/dev/null | tr -d '\r' || true
}

dumpsys_activities() {
timeout 5 "$adb" shell dumpsys activity activities 2>/dev/null || true
}

# The fields of the top ActivityRecord, from its "topResumedActivity=" line
# until the blank line that ends that task.
top_record() {
dumpsys_activities | awk '
/topResumedActivity=/ && !seen_top { in_top = 1; seen_top = 1 }
in_top { print }
in_top && /^[[:space:]]*$/ { in_top = 0 }
'
}

top_resumed_is_app() {
local record
record="$(top_record)"
[[ "$record" == *"$package"* ]]
}

app_ready() {
local pids record
pids="$(package_pid)"
[[ -n "$pids" ]] || return 1
record="$(top_record)"
[[ "$record" == *"$package"* ]] \
&& grep -q 'state=RESUMED' <<< "$record" \
&& grep -q 'reportedDrawn=true' <<< "$record" \
&& grep -q 'mVisible=true' <<< "$record"
}

wait_for() {
local description="$1" seconds="$2"
shift 2
local deadline=$((SECONDS + seconds))
while (( SECONDS < deadline )); do
if "$@"; then
printf 'OK: %s.\n' "$description"
return 0
fi
sleep 1
done
return 1
}

launch_app() {
timeout "$launch_timeout" "$adb" shell am start -W \
-a android.intent.action.MAIN -c android.intent.category.LAUNCHER \
-n "$component" 2>&1
}

diagnose() {
echo "::error::$*" >&2
{
echo "at=$(date -u +%FT%TZ)"
echo "pid=$(package_pid)"
dumpsys_activities
} > "$artifacts/failure-activities.txt" 2>&1 || true
timeout 20 "$adb" logcat -d -t 1000 > "$artifacts/failure-logcat.txt" 2>/dev/null || true
timeout 20 "$adb" logcat -b crash -d > "$artifacts/failure-crash.txt" 2>/dev/null || true
exit 1
}

timeout 60 "$adb" install -r --no-incremental "$apk" > "$artifacts/install.txt" 2>&1 \
|| diagnose "Installing the Android debug APK failed."
timeout 20 "$adb" logcat -c > /dev/null 2>&1 || true
timeout 20 "$adb" logcat -b crash -c > /dev/null 2>&1 || true

if ! first_launch="$(launch_app)"; then
printf '%s\n' "$first_launch" > "$artifacts/first-launch.txt"
diagnose "The first Android launch command failed."
fi
printf '%s\n' "$first_launch" > "$artifacts/first-launch.txt"
[[ "$first_launch" == *"Status: ok"* ]] \
|| diagnose "The first Android launch did not report Status: ok."
wait_for "the first launch to be resumed and drawn" 30 app_ready \
|| diagnose "OX Mobile never became a visible resumed Activity."
dumpsys_activities > "$artifacts/first-activities.txt"

old_pid="$(package_pid)"
[[ -n "$old_pid" ]] || diagnose "The first launch has no package process."
printf 'First launch PID %s.\n' "$old_pid"

timeout 20 "$adb" shell input keyevent KEYCODE_BACK > "$artifacts/back.txt" 2>&1 \
|| diagnose "Pressing Back failed."

old_process_gone() {
local pids
pids="$(package_pid)"
[[ " $pids " != *" $old_pid "* ]]
}

wait_for "the first process to end after Back" 30 old_process_gone \
|| diagnose "Back did not end the first OX Mobile process; the spent Activity may be reused."
top_resumed_is_app && diagnose "The first Activity is still resumed after Back."

activity_loop_ended() {
timeout 15 "$adb" logcat -d -s ox-mobile:I 2>/dev/null \
| grep -F 'OX Mobile Android activity loop ended; releasing the process' > /dev/null
}

wait_for "the Activity loop exit marker" 20 activity_loop_ended \
|| diagnose "The first process ended without the Activity loop exit marker."
dumpsys_activities > "$artifacts/after-back-activities.txt"

if ! second_launch="$(launch_app)"; then
printf '%s\n' "$second_launch" > "$artifacts/second-launch.txt"
diagnose "The second Android launch command failed."
fi
printf '%s\n' "$second_launch" > "$artifacts/second-launch.txt"
[[ "$second_launch" == *"Status: ok"* ]] \
|| diagnose "The second Android launch did not report Status: ok."
wait_for "the second launch to be resumed and drawn" 30 app_ready \
|| diagnose "The relaunched OX Mobile never became a visible resumed Activity."
dumpsys_activities > "$artifacts/second-activities.txt"

new_pid="$(package_pid)"
[[ -n "$new_pid" ]] || diagnose "The relaunch has no package process."
[[ "$new_pid" != "$old_pid" ]] \
|| diagnose "The relaunch reused the process that Back ended."

timeout 20 "$adb" logcat -d > "$artifacts/logcat.txt" 2>&1 \
|| diagnose "Collecting Android logs failed."
timeout 20 "$adb" logcat -b crash -d > "$artifacts/crash.txt" 2>&1 \
|| diagnose "Collecting the Android crash buffer failed."
if grep -Eq 'dev\.ox\.mobile|libox_mobile' "$artifacts/crash.txt"; then
diagnose "OX Mobile logged a crash during the relaunch regression."
fi
if grep -Eq \
'ox-mobile: PANIC|FATAL EXCEPTION.*dev\.ox\.mobile|Process: dev\.ox\.mobile|Fatal signal.*libox_mobile|duplicate init_platform|must construct App|destroyed mutex' \
"$artifacts/logcat.txt"; then
diagnose "OX Mobile logged a relevant failure during the relaunch regression."
fi

{
echo "first_pid=$old_pid"
echo "second_pid=$new_pid"
echo "lifecycle_marker=present"
echo "crash=absent"
} > "$artifacts/relaunch.txt"
printf 'OX Mobile ended PID %s with Back and relaunched as resumed PID %s with no crash.\n' \
"$old_pid" "$new_pid"
7 changes: 7 additions & 0 deletions desktop/ox-mobile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ fn android_main(app: android_activity::AndroidApp) {
gpui::Application::with_platform(platform.into_rc())
.with_assets(gpui_kit_assets::Assets)
.run(launch);
// The Android GPUI platform and its native activity are process-scoped.
// Once its event loop has shut down, let Android start a new process for
// the next activity, including an activity recreated after a locale change.
log::info!("OX Mobile Android activity loop ended; releasing the process");
// SAFETY: we own this process and the native event loop has unwound. Skip
// C exit handlers while platform-wide renderer and worker threads remain.
unsafe { libc::_exit(0) };
}

#[cfg(any(target_os = "ios", target_os = "android", test))]
Expand Down
3 changes: 3 additions & 0 deletions desktop/ox-mobile/src/mobile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,9 @@ impl Mobile {
app.sync_platform_appearance(cx);
app.recovery.activated();
cx.notify();
} else {
#[cfg(target_os = "android")]
app.flush_drafts();
}
});
app._subscriptions.push(appearance_changed);
Expand Down
Loading