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

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

Fix regression in SysUI boot time

- If we defer creating the fragment until the view is attached, that
  seems to throw off the flow of sysui startup (maybe because the actual
  nav bar fragment isn't set until later).  Instead, pull out the
  attached listener and clear the fragment ref after the view is attached
  so that we still release the fragment ref.

Bug: 162575036
Test: Kill sysui multiple times and check sysui boot times
Test: Switch navigation modes several times and verify there's still only
      one ref to nav bar fragment & view
Change-Id: I636837771e8011747de79c7609443ef562804eea
parent 736e4b06
Loading
Loading
Loading
Loading
+32 −20
Original line number Diff line number Diff line
@@ -375,6 +375,34 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
        }
    };

    private static class NavBarViewAttachedListener implements View.OnAttachStateChangeListener {
        private NavigationBarFragment mFragment;
        private FragmentListener mListener;

        NavBarViewAttachedListener(NavigationBarFragment fragment, FragmentListener listener) {
            mFragment = fragment;
            mListener = listener;
        }

        @Override
        public void onViewAttachedToWindow(View v) {
            final FragmentHostManager fragmentHost = FragmentHostManager.get(v);
            fragmentHost.getFragmentManager().beginTransaction()
                    .replace(R.id.navigation_bar_frame, mFragment, TAG)
                    .commit();
            fragmentHost.addTagListener(TAG, mListener);
            mFragment = null;
        }

        @Override
        public void onViewDetachedFromWindow(View v) {
            final FragmentHostManager fragmentHost = FragmentHostManager.get(v);
            fragmentHost.removeTagListener(TAG, mListener);
            FragmentHostManager.removeAndDestroy(v);
            v.removeOnAttachStateChangeListener(this);
        }
    }

    private final DeviceConfig.OnPropertiesChangedListener mOnPropertiesChangedListener =
            new DeviceConfig.OnPropertiesChangedListener() {
        @Override
@@ -1470,26 +1498,10 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
        if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + navigationBarView);
        if (navigationBarView == null) return null;

        navigationBarView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
            @Override
            public void onViewAttachedToWindow(View v) {
                final NavigationBarFragment fragment =
                        FragmentHostManager.get(v).create(NavigationBarFragment.class);
                final FragmentHostManager fragmentHost = FragmentHostManager.get(v);
                fragmentHost.getFragmentManager().beginTransaction()
                        .replace(R.id.navigation_bar_frame, fragment, TAG)
                        .commit();
                fragmentHost.addTagListener(TAG, listener);
            }

            @Override
            public void onViewDetachedFromWindow(View v) {
                final FragmentHostManager fragmentHost = FragmentHostManager.get(v);
                fragmentHost.removeTagListener(TAG, listener);
                FragmentHostManager.removeAndDestroy(v);
                navigationBarView.removeOnAttachStateChangeListener(this);
            }
        });
        NavigationBarFragment fragment = FragmentHostManager.get(navigationBarView)
                .create(NavigationBarFragment.class);
        navigationBarView.addOnAttachStateChangeListener(new NavBarViewAttachedListener(fragment,
                listener));
        context.getSystemService(WindowManager.class).addView(navigationBarView, lp);
        return navigationBarView;
    }