Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1e51da0 authored by Ahmad Khalil's avatar Ahmad Khalil
Browse files

Fix Activity leak via ViewRootImpl

The leak was caused by the ViewRootImpl reusing a cached Vibrator. We now clear the system vibrator in PhoneWindow to avoid this problem.

Bug: 393190314
Flag: com.android.window.flags.clear_system_vibrator
Test: Manual testing
Change-Id: If6e58e6184473e60111e873a77fb23b493df7a10
parent 934dd3a2
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -9377,6 +9377,16 @@ public final class ViewRootImpl implements ViewParent,
        return mVibrator;
    }
    /**
     * Clears the system vibrator.
     *
     * <p>This method releases the reference to the system vibrator. It's crucial to call this
     * method when the vibrator is no longer needed to prevent any potential memory leaks.
     */
    public void clearSystemVibrator() {
        mVibrator = null;
    }
    private @Nullable AutofillManager getAutofillManager() {
        if (mView instanceof ViewGroup) {
            ViewGroup decorView = (ViewGroup) mView;
+11 −0
Original line number Diff line number Diff line
@@ -461,3 +461,14 @@ flag {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "clear_system_vibrator"
    namespace: "windowing_frontend"
    description: "Clears the system vibrator before attaching new window, to avoid leaks."
    bug: "393190314"
    is_fixed_read_only: true
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
 No newline at end of file
+3 −0
Original line number Diff line number Diff line
@@ -436,6 +436,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            if (viewRoot != null) {
                // Clear the old callbacks and attach to the new window.
                viewRoot.getOnBackInvokedDispatcher().clear();
                if (Flags.clearSystemVibrator()) {
                    viewRoot.clearSystemVibrator();
                }
                onViewRootImplSet(viewRoot);
            }
        }