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

Commit 7091b5a8 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix facetbuttons selection It didn't work when apps where in a virtual...

Merge "Fix facetbuttons selection It didn't work when apps where in a virtual or secondary dispaly" into pi-dev
parents 11d203ea a5e714ca
Loading
Loading
Loading
Loading
+45 −24
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.util.Log;
import android.view.Display;

import java.util.HashMap;
import java.util.List;
@@ -49,6 +49,9 @@ public class CarFacetButtonController {
        for (int i = 0; i < componentNames.length; i++) {
            mButtonsByComponentName.put(componentNames[i], facetButton);
        }
        // Using the following as a default button for display id info it's not
        // attached to a screen at this point so it can't be extracted here.
        mSelectedFacetButton = facetButton;
    }

    public void removeAll() {
@@ -61,36 +64,54 @@ public class CarFacetButtonController {
    /**
     * This will unselect the currently selected CarFacetButton and determine which one should be
     * selected next. It does this by reading the properties on the CarFacetButton and seeing if
     * they are a match with the supplied taskInfo.
     * Order of selection detection ComponentName, PackageName, Category
     * they are a match with the supplied StackInfo list.
     * The order of selection detection is ComponentName, PackageName then Category
     * They will then be compared with the supplied StackInfo list.
     * The StackInfo is expected to be supplied in order of recency and StackInfo will only be used
     * for consideration if it has the same displayId as the CarFacetButtons.
     * @param taskInfo of the currently running application
     */
    public void taskChanged(ActivityManager.RunningTaskInfo taskInfo) {
        if (taskInfo == null || taskInfo.baseActivity == null) {
            return;
    public void taskChanged(List<ActivityManager.StackInfo> stackInfoList) {
        int displayId = getDisplayId();
        for (ActivityManager.StackInfo stackInfo :stackInfoList) {
            // if the display id is known and does not match the stack we skip
            if (displayId != -1 && displayId != stackInfo.displayId) {
                continue;
            }
        String packageName = taskInfo.baseActivity.getPackageName();

        // If the package name belongs to a filter, then highlight appropriate button in
        // the navigation bar.
            if (mSelectedFacetButton != null) {
                mSelectedFacetButton.setSelected(false);
            }
        CarFacetButton facetButton = findFacetButtongByComponentName(taskInfo.topActivity);

            String packageName = stackInfo.topActivity.getPackageName();
            CarFacetButton facetButton = findFacetButtongByComponentName(stackInfo.topActivity);
            if (facetButton == null) {
                facetButton = mButtonsByPackage.get(packageName);
            }
        if (facetButton != null) {
            facetButton.setSelected(true);
            mSelectedFacetButton = facetButton;
        } else {

            if (facetButton == null) {
                String category = getPackageCategory(packageName);
                if (category != null) {
                    facetButton = mButtonsByCategory.get(category);
                }
            }

            if (facetButton != null) {
                facetButton.setSelected(true);
                mSelectedFacetButton = facetButton;
                return;
            }
        }
    }

    private int getDisplayId() {
        if (mSelectedFacetButton != null) {
            Display display = mSelectedFacetButton.getDisplay();
            if (display != null) {
                return display.getDisplayId();
            }
        }
        return -1;
    }

    private CarFacetButton findFacetButtongByComponentName(ComponentName componentName) {
+6 −5
Original line number Diff line number Diff line
@@ -25,9 +25,7 @@ import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewStub;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.BatteryMeterView;
@@ -406,9 +404,12 @@ public class CarStatusBar extends StatusBar implements
    private class TaskStackListenerImpl extends SysUiTaskStackChangeListener {
        @Override
        public void onTaskStackChanged() {
            ActivityManager.RunningTaskInfo runningTaskInfo =
                    ActivityManagerWrapper.getInstance().getRunningTask();
            mCarFacetButtonController.taskChanged(runningTaskInfo);
            try {
                mCarFacetButtonController.taskChanged(
                        ActivityManager.getService().getAllStackInfos());
            } catch (Exception e) {
                Log.e(TAG, "Getting StackInfo from activity manager failed", e);
            }
        }
    }