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

Commit b03d44d9 authored by Winson Chung's avatar Winson Chung
Browse files

Unregister wallpaper visibility listener when nav bar view is destroyed

- The wallpaper visibility listener is only registered but never
  unregistered, and the RemoteCallbackList isn't enough to manage this
  since all instances belong to the same instance of the SysUI process.

Fixes: 79181718
Test: Change configuration to recreate the nav bar and ensure the old
      nav bar transition wallpaper visibility listener is unregistered
      first

Change-Id: I08e1600a016f1ddff51fc2f67eb4ddced42963b6
parent 64c4523e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -67,6 +67,10 @@ public class BarTransitions {
        mView.setBackground(mBarBackground);
    }

    public void destroy() {
        // To be overridden
    }

    public int getMode() {
        return mMode;
    }
+4 −1
Original line number Diff line number Diff line
@@ -307,7 +307,10 @@ public class NavigationBarFragment extends Fragment implements Callbacks {
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (mNavigationBarView != null) {
            mNavigationBarView.getBarTransitions().destroy();
            mNavigationBarView.getLightTransitionsController().destroy(getContext());
        }
        mOverviewProxyService.removeCallback(mOverviewProxyListener);
        getContext().unregisterReceiver(mBroadcastReceiver);
    }
+22 −9
Original line number Diff line number Diff line
@@ -44,6 +44,17 @@ public final class NavigationBarTransitions extends BarTransitions {
    private boolean mAutoDim;
    private View mNavButtons;

    private final Handler mHandler = Handler.getMain();
    private final IWallpaperVisibilityListener mWallpaperVisibilityListener =
            new IWallpaperVisibilityListener.Stub() {
        @Override
        public void onWallpaperVisibilityChanged(boolean newVisibility,
        int displayId) throws RemoteException {
            mWallpaperVisible = newVisibility;
            mHandler.post(() -> applyLightsOut(true, false));
        }
    };

    public NavigationBarTransitions(NavigationBarView view) {
        super(view, R.drawable.nav_background);
        mView = view;
@@ -55,17 +66,9 @@ public final class NavigationBarTransitions extends BarTransitions {
                .getBoolean(R.bool.config_navigation_bar_enable_auto_dim_no_visible_wallpaper);

        IWindowManager windowManagerService = Dependency.get(IWindowManager.class);
        Handler handler = Handler.getMain();
        try {
            mWallpaperVisible = windowManagerService.registerWallpaperVisibilityListener(
                new IWallpaperVisibilityListener.Stub() {
                    @Override
                    public void onWallpaperVisibilityChanged(boolean newVisibility,
                            int displayId) throws RemoteException {
                        mWallpaperVisible = newVisibility;
                        handler.post(() -> applyLightsOut(true, false));
                    }
                }, Display.DEFAULT_DISPLAY);
                    mWallpaperVisibilityListener, Display.DEFAULT_DISPLAY);
        } catch (RemoteException e) {
        }
        mView.addOnLayoutChangeListener(
@@ -87,6 +90,16 @@ public final class NavigationBarTransitions extends BarTransitions {
        applyLightsOut(false /*animate*/, true /*force*/);
    }

    @Override
    public void destroy() {
        IWindowManager windowManagerService = Dependency.get(IWindowManager.class);
        try {
            windowManagerService.unregisterWallpaperVisibilityListener(mWallpaperVisibilityListener,
                    Display.DEFAULT_DISPLAY);
        } catch (RemoteException e) {
        }
    }

    @Override
    public void setAutoDim(boolean autoDim) {
        if (mAutoDim == autoDim) return;