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

Commit 9aedfb18 authored by Steven Thomas's avatar Steven Thomas
Browse files

Fix missing service call when rebinding to VrCore

When rebinding to VrCore after a VrCore crash we weren't calling
onCurrentVrActivityChanged().

Bug: b/69839187

Test: Went through the repro steps in b/69839187 and confirmed we
successfully recover after VrCore dies and is rebound.

Change-Id: Idbd7acb438e8b7754743c5ccaaa68b4e0a686d33
(cherry picked from commit d03fa742c2f29330d138ba6e2241f13eb527b9b5)
parent b0538e6d
Loading
Loading
Loading
Loading
+26 −10
Original line number Diff line number Diff line
@@ -185,6 +185,14 @@ public class VrManagerService extends SystemService
            ComponentName component = null;
            synchronized (mLock) {
                component = ((mCurrentVrService == null) ? null : mCurrentVrService.getComponent());

                // If the VrCore main service was disconnected or the binding died we'll rebind
                // automatically. Call focusedActivityChanged() once we rebind.
                if (component != null && component.equals(event.component) &&
                        (event.event == LogEvent.EVENT_DISCONNECTED ||
                         event.event == LogEvent.EVENT_BINDING_DIED)) {
                    callFocusedActivityChangedLocked();
                }
            }

            // If not on an AIO device and we permanently stopped trying to connect to the
@@ -980,16 +988,7 @@ public class VrManagerService extends SystemService
                    oldVrServicePackage, oldUserId);

            if (mCurrentVrService != null && sendUpdatedCaller) {
                final ComponentName c = mCurrentVrModeComponent;
                final boolean b = running2dInVr;
                final int pid = processId;
                mCurrentVrService.sendEvent(new PendingEvent() {
                    @Override
                    public void runEvent(IInterface service) throws RemoteException {
                        IVrListener l = (IVrListener) service;
                        l.focusedActivityChanged(c, b, pid);
                    }
                });
                callFocusedActivityChangedLocked();
            }

            if (!nothingChanged) {
@@ -1002,6 +1001,23 @@ public class VrManagerService extends SystemService
        }
    }

    private void callFocusedActivityChangedLocked() {
        final ComponentName c = mCurrentVrModeComponent;
        final boolean b = mRunning2dInVr;
        final int pid = mVrAppProcessId;
        mCurrentVrService.sendEvent(new PendingEvent() {
            @Override
            public void runEvent(IInterface service) throws RemoteException {
                // Under specific (and unlikely) timing scenarios, when VrCore
                // crashes and is rebound, focusedActivityChanged() may be
                // called a 2nd time with the same arguments. IVrListeners
                // should make sure to handle that scenario gracefully.
                IVrListener l = (IVrListener) service;
                l.focusedActivityChanged(c, b, pid);
            }
        });
    }

    private boolean isDefaultAllowed(String packageName) {
        PackageManager pm = mContext.getPackageManager();