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

Commit 2bdf4c29 authored by Roman Birg's avatar Roman Birg Committed by Steve Kondik
Browse files

SystemUI: improve recreating statusbar



- Don't recreate controllers if they are already there
- Register receivers only the first time
- Set proper empty shade state after creation
- pause command queue a little earlier than right before creating new
  views
- collapse notifications panel so the views can be recreated properly

Change-Id: Id3fb285cd12e7e63564ff52886d7de5a97744a9c
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 38d4e08c
Loading
Loading
Loading
Loading
+104 −67
Original line number Diff line number Diff line
@@ -1086,7 +1086,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        mHandlerThread.start();

        // Other icons
        if (mLocationController == null) {
            mLocationController = new LocationControllerImpl(mContext); // will post a notification
        }
        if (mBatteryController == null) {
            mBatteryController = new BatteryController(mContext, mHandler);
            mBatteryController.addStateChangedCallback(new BatteryStateChangeCallback() {
                @Override
@@ -1096,26 +1099,46 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
                        mDozeServiceHost.firePowerSaveChanged(mBatteryController.isPowerSave());
                    }
                }

                @Override
                public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
                    // noop
                }

                @Override
                public void onBatteryStyleChanged(int style, int percentMode) {
                    // noop
                }
            });
        }
        if (mHotspotController == null) {
            mHotspotController = new HotspotControllerImpl(mContext);
        mBluetoothController = new BluetoothControllerImpl(mContext, mHandlerThread.getLooper());
        }
        if (mBluetoothController == null) {
            mBluetoothController = new BluetoothControllerImpl(mContext);
        }
        if (mSecurityController == null) {
            mSecurityController = new SecurityControllerImpl(mContext);
        if (mContext.getResources().getBoolean(R.bool.config_showRotationLock)) {
        }
        if (mContext.getResources().getBoolean(R.bool.config_showRotationLock)
                && mRotationLockController == null) {
            mRotationLockController = new RotationLockControllerImpl(mContext);
        }
        if (mUserInfoController == null) {
            mUserInfoController = new UserInfoController(mContext);
        }
        if (mVolumeComponent == null) {
            mVolumeComponent = getComponent(VolumeComponent.class);
        }
        if (mZenModeController == null) {
            mZenModeController = mVolumeComponent.getZenController();
        }
        if (mCastController == null) {
            mCastController = new CastControllerImpl(mContext);
        }
        if (mSuController == null) {
            mSuController = new SuControllerImpl(mContext);
        }

        if (isMSim()) {
            if (mMSimNetworkController == null) {
@@ -1206,12 +1229,22 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        }

        mKeyguardBottomArea.setPhoneStatusBar(this);
        if (mAccessibilityController == null) {
            mAccessibilityController = new AccessibilityController(mContext);
        }
        mKeyguardBottomArea.setAccessibilityController(mAccessibilityController);
        if (mNextAlarmController == null) {
            mNextAlarmController = new NextAlarmController(mContext);
        }
        if (mKeyguardMonitor == null) {
            mKeyguardMonitor = new KeyguardMonitor();
        }
        if (mUserSwitcherController == null) {
            mUserSwitcherController = new UserSwitcherController(mContext, mKeyguardMonitor);
        }
        if (mWeatherController == null) {
            mWeatherController = new WeatherControllerImpl(mContext);
        }

        mKeyguardUserSwitcher = new KeyguardUserSwitcher(mContext,
                (ViewStub) mStatusBarWindowContent.findViewById(R.id.keyguard_user_switcher),
@@ -1266,30 +1299,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        mBroadcastReceiver.onReceive(mContext,
                new Intent(pm.isScreenOn() ? Intent.ACTION_SCREEN_ON : Intent.ACTION_SCREEN_OFF));

        // receive broadcasts
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        filter.addAction(Intent.ACTION_SCREEN_OFF);
        filter.addAction(Intent.ACTION_SCREEN_ON);
        filter.addAction(Intent.ACTION_KEYGUARD_WALLPAPER_CHANGED);
        if (DEBUG_MEDIA_FAKE_ARTWORK) {
            filter.addAction("fake_artwork");
        }
        filter.addAction(ACTION_DEMO);
        context.registerReceiver(mBroadcastReceiver, filter);

        // receive broadcasts for packages
        IntentFilter packageFilter = new IntentFilter();
        packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
        packageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
        packageFilter.addAction(Intent.ACTION_PACKAGE_FULLY_REMOVED);
        packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        packageFilter.addDataScheme("package");
        context.registerReceiver(mPackageBroadcastReceiver, packageFilter);

        // listen for USER_SETUP_COMPLETE setting (per-user)
        resetUserSetupObserver();

        startGlyphRasterizeHack();
        return mStatusBarView;
    }
@@ -3528,6 +3537,30 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
    @Override
    public void createAndAddWindows() {
        addStatusBarWindow();

        // listen for USER_SETUP_COMPLETE setting (per-user)
        resetUserSetupObserver();

        // receive broadcasts
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        filter.addAction(Intent.ACTION_SCREEN_OFF);
        filter.addAction(Intent.ACTION_SCREEN_ON);
        filter.addAction(Intent.ACTION_KEYGUARD_WALLPAPER_CHANGED);
        if (DEBUG_MEDIA_FAKE_ARTWORK) {
            filter.addAction("fake_artwork");
        }
        filter.addAction(ACTION_DEMO);
        mContext.registerReceiver(mBroadcastReceiver, filter);

        // receive broadcasts for packages
        IntentFilter packageFilter = new IntentFilter();
        packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
        packageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
        packageFilter.addAction(Intent.ACTION_PACKAGE_FULLY_REMOVED);
        packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        packageFilter.addDataScheme("package");
        mContext.registerReceiver(mPackageBroadcastReceiver, packageFilter);
    }

    private void addStatusBarWindow() {
@@ -3772,6 +3805,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
    private void recreateStatusBar() {
        mRecreating = true;

        instantCollapseNotificationPanel();

        if (mMSimNetworkController != null) {
            mMSimNetworkController.removeAllSignalClusters();
        } else if (mNetworkController != null) {
@@ -3807,6 +3842,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        // this MUST happen before makeStatusBarView();
        haltTicker();

        // Stop the command queue until the new status bar container settles and has a layout pass
        mCommandQueue.pause();

        makeStatusBarView();
        repositionNavigationBar();
        addHeadsUpView();
@@ -3829,14 +3867,13 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        mNotificationData.filterAndSort();

        setAreThereNotifications();
        mNotificationPanel.setShadeEmpty(!hasActiveNotifications());

        mStatusBarWindow.addContent(mStatusBarWindowContent);

        updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
        checkBarModes();

        // Stop the command queue until the new status bar container settles and has a layout pass
        mCommandQueue.pause();
        mStatusBarWindow.requestLayout();
        mStatusBarWindow.getViewTreeObserver().addOnGlobalLayoutListener(
                new ViewTreeObserver.OnGlobalLayoutListener() {