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

Commit cc43d6a8 authored by Evan Laird's avatar Evan Laird
Browse files

Support new pipeline demo mode in the old view presenter

Adds support for the new mobile pipeline's demo mode to the old front
end. Note that this is kind of hacky because we actually don't have to
do anything to support demo mode, since it's implemented entirely at the
level of the repository. However, due to the fact that the old
implementation of demo mode added a special view, `DemoStatusIcons`,
that overlays the regular icons, we have to suport the new pipeline in
_that_ icon container.

Test: manual
Bug: 249790009
Change-Id: Ib02a1eb6f6abaec113a15045f9bd0b151d2a773f
parent a2c6879a
Loading
Loading
Loading
Loading
+46 −2
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ import com.android.systemui.statusbar.StatusIconDisplayable;
import com.android.systemui.statusbar.connectivity.ui.MobileContextProvider;
import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.MobileIconState;
import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.WifiIconState;
import com.android.systemui.statusbar.pipeline.mobile.ui.view.ModernStatusBarMobileView;
import com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel.MobileIconsViewModel;

import java.util.ArrayList;
import java.util.List;
@@ -50,20 +52,25 @@ public class DemoStatusIcons extends StatusIconContainer implements DemoMode, Da

    private final LinearLayout mStatusIcons;
    private final ArrayList<StatusBarMobileView> mMobileViews = new ArrayList<>();
    private final ArrayList<ModernStatusBarMobileView> mModernMobileViews = new ArrayList<>();
    private final int mIconSize;

    private StatusBarWifiView mWifiView;
    private boolean mDemoMode;
    private int mColor;

    private final MobileIconsViewModel mMobileIconsViewModel;

    public DemoStatusIcons(
            LinearLayout statusIcons,
            MobileIconsViewModel mobileIconsViewModel,
            int iconSize
    ) {
        super(statusIcons.getContext());
        mStatusIcons = statusIcons;
        mIconSize = iconSize;
        mColor = DarkIconDispatcher.DEFAULT_ICON_TINT;
        mMobileIconsViewModel = mobileIconsViewModel;

        if (statusIcons instanceof StatusIconContainer) {
            setShouldRestrictIcons(((StatusIconContainer) statusIcons).isRestrictingIcons());
@@ -115,6 +122,8 @@ public class DemoStatusIcons extends StatusIconContainer implements DemoMode, Da
    public void onDemoModeFinished() {
        mDemoMode = false;
        mStatusIcons.setVisibility(View.VISIBLE);
        mModernMobileViews.clear();
        mMobileViews.clear();
        setVisibility(View.GONE);
    }

@@ -268,6 +277,24 @@ public class DemoStatusIcons extends StatusIconContainer implements DemoMode, Da
        addView(view, getChildCount(), createLayoutParams());
    }

    /**
     * Add a {@link ModernStatusBarMobileView}
     * @param mobileContext possibly mcc/mnc overridden mobile context
     * @param subId the subscriptionId for this mobile view
     */
    public void addModernMobileView(Context mobileContext, int subId) {
        Log.d(TAG, "addModernMobileView (subId=" + subId + ")");
        ModernStatusBarMobileView view = ModernStatusBarMobileView.constructAndBind(
                mobileContext,
                "mobile",
                mMobileIconsViewModel.viewModelForSub(subId)
        );

        // mobile always goes at the end
        mModernMobileViews.add(view);
        addView(view, getChildCount(), createLayoutParams());
    }

    /**
     * Apply an update to a mobile icon view for the given {@link MobileIconState}. For
     * compatibility with {@link MobileContextProvider}, we have to recreate the view every time we
@@ -292,12 +319,19 @@ public class DemoStatusIcons extends StatusIconContainer implements DemoMode, Da
        if (view.getSlot().equals("wifi")) {
            removeView(mWifiView);
            mWifiView = null;
        } else {
        } else if (view instanceof StatusBarMobileView) {
            StatusBarMobileView mobileView = matchingMobileView(view);
            if (mobileView != null) {
                removeView(mobileView);
                mMobileViews.remove(mobileView);
            }
        } else if (view instanceof ModernStatusBarMobileView) {
            ModernStatusBarMobileView mobileView = matchingModernMobileView(
                    (ModernStatusBarMobileView) view);
            if (mobileView != null) {
                removeView(mobileView);
                mModernMobileViews.remove(mobileView);
            }
        }
    }

@@ -316,6 +350,16 @@ public class DemoStatusIcons extends StatusIconContainer implements DemoMode, Da
        return null;
    }

    private ModernStatusBarMobileView matchingModernMobileView(ModernStatusBarMobileView other) {
        for (ModernStatusBarMobileView v : mModernMobileViews) {
            if (v.getSubId() == other.getSubId()) {
                return v;
            }
        }

        return null;
    }

    private LayoutParams createLayoutParams() {
        return new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, mIconSize);
    }
+6 −5
Original line number Diff line number Diff line
@@ -536,8 +536,7 @@ public interface StatusBarIconController {
            mGroup.addView(view, index, onCreateLayoutParams());

            if (mIsInDemoMode) {
                // TODO (b/249790009): demo mode should be handled at the data layer in the
                //  new pipeline
                mDemoStatusIcons.addModernMobileView(mContext, subId);
            }

            return view;
@@ -565,11 +564,13 @@ public interface StatusBarIconController {

        private ModernStatusBarMobileView onCreateModernStatusBarMobileView(
                String slot, int subId) {
            Context mobileContext = mMobileContextProvider.getMobileContextForSub(subId, mContext);
            return ModernStatusBarMobileView
                    .constructAndBind(
                            mContext,
                            mobileContext,
                            slot,
                            mMobileIconsViewModel.viewModelForSub(subId));
                            mMobileIconsViewModel.viewModelForSub(subId)
                        );
        }

        protected LinearLayout.LayoutParams onCreateLayoutParams() {
@@ -704,7 +705,7 @@ public interface StatusBarIconController {
        }

        protected DemoStatusIcons createDemoStatusIcons() {
            return new DemoStatusIcons((LinearLayout) mGroup, mIconSize);
            return new DemoStatusIcons((LinearLayout) mGroup, mMobileIconsViewModel, mIconSize);
        }
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -276,6 +276,11 @@ public class StatusBarIconControllerImpl implements Tunable,
        String slotName = mContext.getString(com.android.internal.R.string.status_bar_mobile);
        Slot mobileSlot = mStatusBarIconList.getSlot(slotName);

        // Because of the way we cache the icon holders, we need to remove everything any time
        // we get a new set of subscriptions. This might change in the future, but is required
        // to support demo mode for now
        removeAllIconsForSlot(slotName);

        Collections.reverse(subIds);

        for (Integer subId : subIds) {
+2 −0
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ import kotlinx.coroutines.flow.StateFlow
 * eventually becomes a single icon in the status bar.
 */
interface MobileConnectionRepository {
    /** The subscriptionId that this connection represents */
    val subId: Int
    /**
     * A flow that aggregates all necessary callbacks from [TelephonyCallback] into a single
     * listener + model.
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ import kotlinx.coroutines.flow.StateFlow
 */
interface MobileConnectionsRepository {
    /** Observable list of current mobile subscriptions */
    val subscriptionsFlow: Flow<List<SubscriptionInfo>>
    val subscriptionsFlow: StateFlow<List<SubscriptionInfo>>

    /** Observable for the subscriptionId of the current mobile data connection */
    val activeMobileDataSubscriptionId: StateFlow<Int>
Loading