Fix Android sandbox onboarding and surface insets; checkpoint application cache
android-ci / android-arm64 (push) Successful in 18m47s

This commit is contained in:
bit9992 committed 2026-11-12 13:25:41 +03:00
1 parent 52d2c22ec0
commit fd41389d63
9 files changed
+365 -33

No files matched your search

@@ -22,6 +22,13 @@ public final class TeamsPeachActivity extends NativeActivity {
private SafGrant sharedGrant;
private android.net.Uri installerUri;
private int requestedPermission;
private SurfaceView renderSurface;
private final Rect insetWindow = new Rect(), visibleWindow = new Rect();
private final int[] decorLocation = new int[2], surfaceLocation = new int[2];
private final ViewTreeObserver.OnGlobalLayoutListener insetLayout = this::reportInsets;
private int insetTop, insetRight, insetBottom, insetLeft, insetKeyboard;
private float insetScale;
private long insetGeneration;
private static final int PICK = 501, PERMISSION = 502, SHARE = 503, INSTALL = 504, INSTALL_PERMISSION = 505;
@Override protected void onCreate(Bundle state) {
PlatformBridge.activity = new java.lang.ref.WeakReference<>(this);
@@ -31,22 +38,59 @@ public final class TeamsPeachActivity extends NativeActivity {
addContentView(accessibility, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
// Slint 1.18.1 already owns API34+ predictive-back and the decor's inset listener.
if (Build.VERSION.SDK_INT == 33) getOnBackInvokedDispatcher().registerOnBackInvokedCallback(android.window.OnBackInvokedDispatcher.PRIORITY_DEFAULT, () -> PlatformBridge.nativeBack(generation));
// Observe without replacing Slint's decor listener or IME animation callback.
accessibility.setOnApplyWindowInsetsListener((view, insets) -> {
float scale = getResources().getDisplayMetrics().density;
int top, right, bottom, left, keyboard = 0;
if (Build.VERSION.SDK_INT >= 30) {
android.graphics.Insets safe = getWindowManager().getCurrentWindowMetrics().getWindowInsets().getInsets(WindowInsets.Type.systemBars() | WindowInsets.Type.displayCutout());
top = safe.top; right = safe.right; bottom = safe.bottom; left = safe.left;
keyboard = insets.getInsets(WindowInsets.Type.ime()).bottom;
} else {
top = insets.getSystemWindowInsetTop(); right = insets.getSystemWindowInsetRight(); bottom = insets.getSystemWindowInsetBottom(); left = insets.getSystemWindowInsetLeft();
Rect visible = new Rect(); view.getWindowVisibleDisplayFrame(visible);
int difference = view.getRootView().getHeight() - visible.bottom;
if (difference > 100 * scale) keyboard = difference;
}
PlatformBridge.nativeInsets(generation, top / scale, right / scale, bottom / scale, left / scale, keyboard / scale);
reportInsets();
return insets;
});
getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(insetLayout);
}
private void reportInsets() {
if (generation == 0 || renderSurface == null || !renderSurface.isAttachedToWindow()
|| renderSurface.getWidth() == 0 || renderSurface.getHeight() == 0) return;
View decor = getWindow().getDecorView();
// A child receives consumed insets on some ROMs. The root retains the IME state.
WindowInsets insets = decor.getRootWindowInsets();
if (insets == null) return;
float scale = getResources().getDisplayMetrics().density;
decor.getLocationOnScreen(decorLocation);
insetWindow.set(decorLocation[0], decorLocation[1], decorLocation[0] + decor.getWidth(), decorLocation[1] + decor.getHeight());
int top, right, bottom, left, keyboard = 0;
if (Build.VERSION.SDK_INT >= 30) {
WindowMetrics metrics = getWindowManager().getCurrentWindowMetrics();
insetWindow.set(metrics.getBounds());
android.graphics.Insets safe = metrics.getWindowInsets().getInsets(WindowInsets.Type.systemBars() | WindowInsets.Type.displayCutout());
top = safe.top; right = safe.right; bottom = safe.bottom; left = safe.left;
keyboard = insets.getInsets(WindowInsets.Type.ime()).bottom;
} else {
// Stable bars exclude the keyboard on API26-29; legacy system insets can include it.
top = insets.getStableInsetTop(); right = insets.getStableInsetRight();
bottom = insets.getStableInsetBottom(); left = insets.getStableInsetLeft();
if (Build.VERSION.SDK_INT >= 28 && insets.getDisplayCutout() != null) {
DisplayCutout cutout = insets.getDisplayCutout();
top = Math.max(top, cutout.getSafeInsetTop()); right = Math.max(right, cutout.getSafeInsetRight());
bottom = Math.max(bottom, cutout.getSafeInsetBottom()); left = Math.max(left, cutout.getSafeInsetLeft());
}
decor.getWindowVisibleDisplayFrame(visibleWindow);
int obscured = Math.max(insets.getSystemWindowInsetBottom(), insetWindow.bottom - visibleWindow.bottom);
if (obscured > bottom + 100 * scale) keyboard = obscured;
}
renderSurface.getLocationOnScreen(surfaceLocation);
// adjustResize / non-edge-to-edge windows already exclude some bars or the IME.
// Send only the overlap with Slint's actual surface, never the full window inset twice.
int excludedTop = Math.max(0, surfaceLocation[1] - insetWindow.top);
int excludedLeft = Math.max(0, surfaceLocation[0] - insetWindow.left);
int excludedRight = Math.max(0, insetWindow.right - surfaceLocation[0] - renderSurface.getWidth());
int excludedBottom = Math.max(0, insetWindow.bottom - surfaceLocation[1] - renderSurface.getHeight());
top = Math.max(0, top - excludedTop); right = Math.max(0, right - excludedRight);
bottom = Math.max(0, bottom - excludedBottom); left = Math.max(0, left - excludedLeft);
keyboard = Math.max(0, keyboard - excludedBottom);
// Global layout also runs after unrelated UI updates; do not feed those back into Slint.
if (insetGeneration == generation && insetScale == scale && insetTop == top && insetRight == right
&& insetBottom == bottom && insetLeft == left && insetKeyboard == keyboard) return;
insetGeneration = generation; insetScale = scale;
insetTop = top; insetRight = right; insetBottom = bottom; insetLeft = left; insetKeyboard = keyboard;
PlatformBridge.nativeInsets(generation, top / scale, right / scale, bottom / scale, left / scale, keyboard / scale);
}
@Override protected void onResume() {
super.onResume(); resumed = true; PlatformBridge.activity = new java.lang.ref.WeakReference<>(this); CaptureBridge.bindActivity(this);
@@ -59,6 +103,7 @@ public final class TeamsPeachActivity extends NativeActivity {
}
@Override protected void onDestroy() {
CaptureBridge.unbindActivity(this);
getWindow().getDecorView().getViewTreeObserver().removeOnGlobalLayoutListener(insetLayout);
if (picker > 0) PlatformBridge.nativePick(picker, null, "activity_destroyed");
if (permissionRequest > 0) PlatformBridge.nativeText(permissionRequest, null, "activity_destroyed");
if (pipToken != 0) PlatformBridge.nativePip(pipToken, false, true);
@@ -81,8 +126,8 @@ public final class TeamsPeachActivity extends NativeActivity {
// Keep its invisible IME proxy out of TalkBack without changing its input connection.
java.util.ArrayDeque<View> views=new java.util.ArrayDeque<>();views.add(getWindow().getDecorView());
int visited=0;
while(!views.isEmpty() && visited++<256){View view=views.removeFirst();if("SlintInputView".equals(view.getClass().getSimpleName()))view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);if(view instanceof ViewGroup){ViewGroup group=(ViewGroup)view;for(int i=0;i<group.getChildCount();i++)views.addLast(group.getChildAt(i));}}
accessibility.bringToFront();accessibility.requestApplyInsets();
while(!views.isEmpty() && visited++<256){View view=views.removeFirst();if(view instanceof SurfaceView)renderSurface=(SurfaceView)view;if("SlintInputView".equals(view.getClass().getSimpleName()))view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);if(view instanceof ViewGroup){ViewGroup group=(ViewGroup)view;for(int i=0;i<group.getChildCount();i++)views.addLast(group.getChildAt(i));}}
accessibility.bringToFront();accessibility.requestApplyInsets();reportInsets();
}
@Override public void onConfigurationChanged(Configuration value) { super.onConfigurationChanged(value); reportConfiguration(); }
@Override public void onTrimMemory(int level) { super.onTrimMemory(level); if (level >= TRIM_MEMORY_RUNNING_LOW) PlatformBridge.nativeEvent(generation, 6, true); }