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

Commit fb35ab5e authored by Heemin Seog's avatar Heemin Seog
Browse files

Fix constantly spinning hvac views

Also clean up some things w.r.t. CarFacetButtonController

Bug: 143610340
Test: manual, atest HvacControllerTest
Change-Id: Idca6f5731704da893fb530deefe2e695281c6f60
parent d59786b9
Loading
Loading
Loading
Loading
+0 −20
Original line number Diff line number Diff line
@@ -19,36 +19,16 @@ package com.android.systemui;
import android.content.Context;

import com.android.systemui.dagger.SystemUIRootComponent;
import com.android.systemui.navigationbar.car.CarFacetButtonController;

import javax.inject.Singleton;

import dagger.Component;

/**
 * Class factory to provide car specific SystemUI components.
 */
public class CarSystemUIFactory extends SystemUIFactory {

    private CarDependencyComponent mCarDependencyComponent;

    @Override
    protected SystemUIRootComponent buildSystemUIRootComponent(Context context) {
        mCarDependencyComponent = DaggerCarSystemUIFactory_CarDependencyComponent.builder()
                .contextHolder(new ContextHolder(context))
                .build();
        return DaggerCarSystemUIRootComponent.builder()
                .contextHolder(new ContextHolder(context))
                .build();
    }

    public CarDependencyComponent getCarDependencyComponent() {
        return mCarDependencyComponent;
    }

    @Singleton
    @Component(modules = ContextHolder.class)
    public interface CarDependencyComponent {
        CarFacetButtonController getCarFacetButtonController();
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.systemui.car;
import android.car.Car;
import android.content.Context;

import androidx.annotation.VisibleForTesting;

import java.util.ArrayList;
import java.util.List;

@@ -50,6 +52,12 @@ public class CarServiceProvider {
                });
    }

    @VisibleForTesting
    public CarServiceProvider(Context context, Car car) {
        mContext = context;
        mCar = car;
    }

    /**
     * Let's other components hook into the connection to the car service. If we're already
     * connected to the car service, the callback is immediately triggered.
+0 −6
Original line number Diff line number Diff line
@@ -29,9 +29,7 @@ import android.widget.ImageView;
import android.widget.LinearLayout;

import com.android.keyguard.AlphaOptimizedImageButton;
import com.android.systemui.CarSystemUIFactory;
import com.android.systemui.R;
import com.android.systemui.SystemUIFactory;

/**
 * CarFacetButton is a ui component designed to be used as a shortcut for an app of a defined
@@ -82,10 +80,6 @@ public class CarFacetButton extends LinearLayout {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CarFacetButton);
        setupIntents(typedArray);
        setupIcons(typedArray);
        CarSystemUIFactory factory = SystemUIFactory.getInstance();
        CarFacetButtonController carFacetButtonController = factory.getCarDependencyComponent()
                .getCarFacetButtonController();
        carFacetButtonController.addFacetButton(this);
    }

    /**
+10 −1
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ import javax.inject.Singleton;
@Singleton
public class CarFacetButtonController {

    private final Set<CarFacetButton> mRegisteredViews = new HashSet<>();

    protected ButtonMap mButtonsByCategory = new ButtonMap();
    protected ButtonMap mButtonsByPackage = new ButtonMap();
    protected ButtonMap mButtonsByComponentName = new ButtonMap();
@@ -60,7 +62,11 @@ public class CarFacetButtonController {
     * to get a reference to this controller via {@link com.android.systemui.Dependency}
     * and self add.
     */
    public void addFacetButton(CarFacetButton facetButton) {
    private void addFacetButton(CarFacetButton facetButton) {
        if (mRegisteredViews.contains(facetButton)) {
            return;
        }

        String[] categories = facetButton.getCategories();
        for (int i = 0; i < categories.length; i++) {
            mButtonsByCategory.add(categories[i], facetButton);
@@ -74,6 +80,8 @@ public class CarFacetButtonController {
        for (int i = 0; i < componentNames.length; i++) {
            mButtonsByComponentName.add(componentNames[i], facetButton);
        }

        mRegisteredViews.add(facetButton);
    }

    /** Removes all buttons from the button maps. */
@@ -82,6 +90,7 @@ public class CarFacetButtonController {
        mButtonsByPackage.clear();
        mButtonsByComponentName.clear();
        mSelectedFacetButtons.clear();
        mRegisteredViews.clear();
    }

    /**
+10 −1
Original line number Diff line number Diff line
@@ -32,10 +32,12 @@ import com.android.systemui.car.CarServiceProvider;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import javax.inject.Inject;
import javax.inject.Singleton;
@@ -49,6 +51,7 @@ public class HvacController {
    public static final String TAG = "HvacController";

    private final CarServiceProvider mCarServiceProvider;
    private final Set<TemperatureView> mRegisteredViews = new HashSet<>();

    private CarHvacManager mHvacManager;
    private HashMap<HvacKey, List<TemperatureView>> mTempComponents = new HashMap<>();
@@ -112,7 +115,10 @@ public class HvacController {
    /**
     * Add component to list and initialize it if the connection is up.
     */
    public void addHvacTextView(TemperatureView temperatureView) {
    private void addHvacTextView(TemperatureView temperatureView) {
        if (mRegisteredViews.contains(temperatureView)) {
            return;
        }

        HvacKey hvacKey = new HvacKey(temperatureView.getPropertyId(), temperatureView.getAreaId());
        if (!mTempComponents.containsKey(hvacKey)) {
@@ -120,6 +126,8 @@ public class HvacController {
        }
        mTempComponents.get(hvacKey).add(temperatureView);
        initComponent(temperatureView);

        mRegisteredViews.add(temperatureView);
    }

    private void initComponents() {
@@ -165,6 +173,7 @@ public class HvacController {
     */
    public void removeAllComponents() {
        mTempComponents.clear();
        mRegisteredViews.clear();
    }

    /**
Loading