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

Commit 3437c571 authored by TYM Tsai's avatar TYM Tsai
Browse files

Fix CtsAtomicInstallTestCases flaky

There is a timing issue when the session re-opens again after the
session is abandoned. Sometimes test cases will reopen the session
immediately when received callback, but at the time, the session does
not be removed from mSession. That's because the session is really
removed in a runnable that posts after notified callbacks.
To fix the issue, notify callbacks after the session is actually
removed from the mSession. This change doesn't apply to success cases
to avoid adding an unknown delay if somewhere wants to handle install
success.

Bug: 288319099
Test: atest CtsAtomicInstallTestCases --iterations 400
Change-Id: Iec7387eeac2beb19cda788363b6d31fa2399abdb
parent 25cd8799
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -1886,7 +1886,14 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
        }

        public void onSessionFinished(final PackageInstallerSession session, boolean success) {
            if (success) {
                // There is a timing issue here, if the callback opens the session again in
                // notifySessionFinished() immediately, the session may not be removed from
                // the mSession. But to avoid adding unknown latency, only notifying failures
                // are moved to the last of posted runnable, notifying success cases are
                // still kept here.
                mCallbacks.notifySessionFinished(session.sessionId, session.userId, success);
            }

            mInstallHandler.post(new Runnable() {
                @Override
@@ -1915,6 +1922,10 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements

                        mSettingsWriteRequest.runNow();
                    }
                    if (!success) {
                        mCallbacks.notifySessionFinished(
                                session.sessionId, session.userId, success);
                    }
                }
            });
        }