Merge "Make assistant button display the icon of the role holder application" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-05-26 17:38:55 +00:00
committed by Android (Google) Code Review
20 changed files with 596 additions and 108 deletions

View File

@@ -25,6 +25,11 @@
<uses-permission android:name="android.car.permission.CAR_ENROLL_TRUST"/>
<!-- This permission is required to get bluetooth broadcast. -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<!-- These permissions are required to implement icons based on role holders. -->
<uses-permission android:name="android.permission.OBSERVE_ROLE_HOLDERS"/>
<uses-permission android:name="android.permission.MANAGE_ROLE_HOLDERS"/>
<!-- This permission is required to access app information from other users. -->
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/>
<!-- This permission is required to check the foreground user id. -->
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
</manifest>

View File

@@ -125,6 +125,7 @@
android:id="@+id/assist"
style="@style/NavigationBarButton"
systemui:icon="@drawable/ic_mic_white"
systemui:useDefaultAppIconForRole="true"
/>
</LinearLayout>

View File

@@ -29,12 +29,14 @@
<com.android.keyguard.AlphaOptimizedImageButton
android:id="@+id/car_nav_button_icon_image"
android:layout_height="wrap_content"
android:layout_height="@dimen/car_navigation_button_icon_height"
android:layout_width="match_parent"
android:layout_gravity="center"
android:animateLayoutChanges="true"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:tintMode="src_in"
android:tint="@color/car_nav_icon_fill_color"
android:clickable="false"
/>
@@ -48,6 +50,7 @@
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:clickable="false"
android:visibility="gone"
/>
<ImageView

View File

@@ -65,6 +65,10 @@
<attr name="showMoreWhenSelected" format="boolean" />
<!-- whether to highlight the button when selected. Defaults false -->
<attr name="highlightWhenSelected" format="boolean" />
<!-- whether to show the icon of the app currently associated this button's role. Only
relevant for buttons associated to specific roles (e.g.: AssistantButton).
Defaults false -->
<attr name="useDefaultAppIconForRole" format="boolean"/>
</declare-styleable>
<!-- Custom attributes to configure hvac values -->

View File

@@ -21,7 +21,7 @@
<color name="car_user_switcher_name_text_color">@*android:color/car_body1_light</color>
<color name="car_user_switcher_add_user_background_color">#131313</color>
<color name="car_user_switcher_add_user_add_sign_color">@*android:color/car_body1_light</color>
<color name="car_nav_icon_fill_color">#8Fffffff</color>
<color name="car_nav_icon_fill_color">#8F8F8F</color>
<color name="car_nav_icon_fill_color_selected">#ffffff</color>
<!-- colors for seekbar -->
<color name="car_seekbar_track_background">#131315</color>

View File

@@ -175,6 +175,7 @@
<dimen name="car_user_switcher_margin_top">@*android:dimen/car_padding_4</dimen>
<dimen name="car_navigation_button_width">64dp</dimen>
<dimen name="car_navigation_button_icon_height">44dp</dimen>
<dimen name="car_navigation_bar_width">760dp</dimen>
<dimen name="car_left_navigation_bar_width">96dp</dimen>
<dimen name="car_right_navigation_bar_width">96dp</dimen>

View File

@@ -18,6 +18,7 @@ package com.android.systemui.car.navigationbar;
import static android.service.voice.VoiceInteractionSession.SHOW_SOURCE_ASSIST_GESTURE;
import android.app.role.RoleManager;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
@@ -31,7 +32,6 @@ import com.android.internal.app.IVoiceInteractionSessionShowCallback;
* AssitantButton is a ui component that will trigger the Voice Interaction Service.
*/
public class AssitantButton extends CarNavigationButton {
private static final String TAG = "AssistantButton";
private final AssistUtils mAssistUtils;
private IVoiceInteractionSessionShowCallback mShowCallback =
@@ -50,9 +50,7 @@ public class AssitantButton extends CarNavigationButton {
public AssitantButton(Context context, AttributeSet attrs) {
super(context, attrs);
mAssistUtils = new AssistUtils(context);
setOnClickListener(v -> {
showAssistant();
});
setOnClickListener(v -> showAssistant());
}
private void showAssistant() {
@@ -65,4 +63,9 @@ public class AssitantButton extends CarNavigationButton {
protected void setUpIntents(TypedArray typedArray) {
// left blank because for the assistant button Intent will not be passed from the layout.
}
@Override
protected String getRoleName() {
return RoleManager.ROLE_ASSISTANT;
}
}

View File

@@ -0,0 +1,142 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.car.navigationbar;
import android.annotation.Nullable;
import android.app.role.OnRoleHoldersChangedListener;
import android.app.role.RoleManager;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.UserHandle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.car.CarDeviceProvisionedController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
/**
* Some CarNavigationButtons can be associated to a {@link RoleManager} role. When they are, it is
* possible to have them display the icon of the default application (role holder) for the given
* role.
*
* This class monitors the current role holders for each role type and updates the button icon for
* this buttons with have this feature enabled.
*/
@Singleton
public class ButtonRoleHolderController {
private static final String TAG = "ButtonRoleHolderController";
private final Context mContext;
private final PackageManager mPackageManager;
private final RoleManager mRoleManager;
private final CarDeviceProvisionedController mDeviceController;
private final Map<String, CarNavigationButton> mButtonMap = new HashMap<>();
private final OnRoleHoldersChangedListener mListener = this::onRoleChanged;
private boolean mRegistered;
@Inject
public ButtonRoleHolderController(Context context, PackageManager packageManager,
RoleManager roleManager, CarDeviceProvisionedController deviceController) {
mContext = context;
mPackageManager = packageManager;
mRoleManager = roleManager;
mDeviceController = deviceController;
}
/**
* Iterate through a view looking for CarNavigationButton and add it to this controller if it
* opted to be associated with a {@link RoleManager} role type.
*
* @param v the View that may contain CarFacetButtons
*/
void addAllButtonsWithRoleName(View v) {
if (v instanceof CarNavigationButton) {
CarNavigationButton button = (CarNavigationButton) v;
String roleName = button.getRoleName();
if (roleName != null && button.isDefaultAppIconForRoleEnabled()) {
addButtonWithRoleName(button, roleName);
}
} else if (v instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) v;
for (int i = 0; i < viewGroup.getChildCount(); i++) {
addAllButtonsWithRoleName(viewGroup.getChildAt(i));
}
}
}
private void addButtonWithRoleName(CarNavigationButton button, String roleName) {
mButtonMap.put(roleName, button);
updateIcon(roleName);
if (!mRegistered) {
mRoleManager.addOnRoleHoldersChangedListenerAsUser(mContext.getMainExecutor(),
mListener, UserHandle.ALL);
mRegistered = true;
}
}
void removeAll() {
mButtonMap.clear();
if (mRegistered) {
mRoleManager.removeOnRoleHoldersChangedListenerAsUser(mListener, UserHandle.ALL);
mRegistered = false;
}
}
@VisibleForTesting
void onRoleChanged(String roleName, UserHandle user) {
if (RoleManager.ROLE_ASSISTANT.equals(roleName)
&& user.getIdentifier() == mDeviceController.getCurrentUser()) {
updateIcon(roleName);
}
}
private void updateIcon(String roleName) {
CarNavigationButton button = mButtonMap.get(roleName);
if (button == null) {
return;
}
List<String> holders = mRoleManager.getRoleHoldersAsUser(button.getRoleName(),
UserHandle.of(mDeviceController.getCurrentUser()));
if (holders == null || holders.isEmpty()) {
button.setAppIcon(null);
} else {
button.setAppIcon(loadIcon(holders.get(0)));
}
}
@Nullable
private Drawable loadIcon(String packageName) {
try {
ApplicationInfo appInfo = mPackageManager.getApplicationInfo(packageName,
PackageManager.MATCH_ANY_USER);
return appInfo.loadIcon(mPackageManager);
} catch (PackageManager.NameNotFoundException e) {
Log.e(ButtonRoleHolderController.TAG, "Package not found: " + packageName, e);
return null;
}
}
}

View File

@@ -87,7 +87,6 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
private final Executor mUiBgExecutor;
private final IStatusBarService mBarService;
private final Lazy<KeyguardStateController> mKeyguardStateControllerLazy;
private final ButtonSelectionStateController mButtonSelectionStateController;
private final Lazy<PhoneStatusBarPolicy> mIconPolicyLazy;
private final Lazy<StatusBarIconController> mIconControllerLazy;
@@ -139,7 +138,6 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
@UiBackground Executor uiBgExecutor,
IStatusBarService barService,
Lazy<KeyguardStateController> keyguardStateControllerLazy,
ButtonSelectionStateController buttonSelectionStateController,
Lazy<PhoneStatusBarPolicy> iconPolicyLazy,
Lazy<StatusBarIconController> iconControllerLazy
) {
@@ -156,7 +154,6 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
mUiBgExecutor = uiBgExecutor;
mBarService = barService;
mKeyguardStateControllerLazy = keyguardStateControllerLazy;
mButtonSelectionStateController = buttonSelectionStateController;
mIconPolicyLazy = iconPolicyLazy;
mIconControllerLazy = iconControllerLazy;
@@ -280,10 +277,9 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
* before and after the device is provisioned. . Also for change of density and font size.
*/
private void restartNavBars() {
// remove and reattach all hvac components such that we don't keep a reference to unused
// ui elements
mCarNavigationBarController.removeAllFromHvac();
mButtonSelectionStateController.removeAll();
// remove and reattach all components such that we don't keep a reference to unused ui
// elements
mCarNavigationBarController.removeAll();
if (mTopNavigationBarWindow != null) {
mTopNavigationBarWindow.removeAllViews();

View File

@@ -37,6 +37,7 @@ public class CarNavigationBarController {
private final Context mContext;
private final NavigationBarViewFactory mNavigationBarViewFactory;
private final ButtonSelectionStateController mButtonSelectionStateController;
private final ButtonRoleHolderController mButtonRoleHolderController;
private final Lazy<HvacController> mHvacControllerLazy;
private boolean mShowTop;
@@ -59,11 +60,13 @@ public class CarNavigationBarController {
public CarNavigationBarController(Context context,
NavigationBarViewFactory navigationBarViewFactory,
ButtonSelectionStateController buttonSelectionStateController,
Lazy<HvacController> hvacControllerLazy) {
Lazy<HvacController> hvacControllerLazy,
ButtonRoleHolderController buttonRoleHolderController) {
mContext = context;
mNavigationBarViewFactory = navigationBarViewFactory;
mButtonSelectionStateController = buttonSelectionStateController;
mHvacControllerLazy = hvacControllerLazy;
mButtonRoleHolderController = buttonRoleHolderController;
// Read configuration.
mShowTop = mContext.getResources().getBoolean(R.bool.config_enableTopNavigationBar);
@@ -101,9 +104,11 @@ public class CarNavigationBarController {
mHvacControllerLazy.get().connectToCarService();
}
/** Clean up hvac. */
public void removeAllFromHvac() {
/** Clean up */
public void removeAll() {
mHvacControllerLazy.get().removeAllComponents();
mButtonSelectionStateController.removeAll();
mButtonRoleHolderController.removeAll();
}
/** Gets the top window if configured to do so. */
@@ -211,6 +216,7 @@ public class CarNavigationBarController {
view.setStatusBarWindowTouchListener(statusBarTouchListener);
view.setNotificationsPanelController(notifShadeController);
mButtonSelectionStateController.addAllButtonsWithSelectionState(view);
mButtonRoleHolderController.addAllButtonsWithRoleName(view);
mHvacControllerLazy.get().addTemperatureViewToController(view);
}

View File

@@ -17,9 +17,11 @@
package com.android.systemui.car.navigationbar;
import android.app.ActivityOptions;
import android.app.role.RoleManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.UserHandle;
import android.util.AttributeSet;
@@ -29,6 +31,7 @@ import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.android.internal.annotations.VisibleForTesting;
import com.android.keyguard.AlphaOptimizedImageButton;
import com.android.systemui.R;
@@ -62,6 +65,8 @@ public class CarNavigationButton extends LinearLayout {
private float mUnselectedAlpha;
private int mSelectedIconResourceId;
private int mIconResourceId;
private Drawable mAppIcon;
private boolean mIsDefaultAppIconForRoleEnabled;
private String[] mComponentNames;
/** App categories that are to be used with this widget */
private String[] mButtonCategories;
@@ -92,7 +97,9 @@ public class CarNavigationButton extends LinearLayout {
super.setSelected(selected);
mSelected = selected;
if (mHighlightWhenSelected) {
setAlpha(mSelected ? mSelectedAlpha : mUnselectedAlpha);
// Always apply selected alpha if the button does not toggle alpha based on selection
// state.
setAlpha(!mHighlightWhenSelected || mSelected ? mSelectedAlpha : mUnselectedAlpha);
}
if (mShowMoreWhenSelected && mMoreIcon != null) {
mMoreIcon.setVisibility(selected ? VISIBLE : GONE);
@@ -108,6 +115,20 @@ public class CarNavigationButton extends LinearLayout {
updateImage();
}
/**
* Sets the current icon of the default application associated with this button.
*/
public void setAppIcon(Drawable appIcon) {
mAppIcon = appIcon;
updateImage();
}
/** Gets the icon of the app currently associated to the role of this button. */
@VisibleForTesting
protected Drawable getAppIcon() {
return mAppIcon;
}
/** Gets whether the icon is in an unseen state. */
public boolean getUnseen() {
return mHasUnseen;
@@ -143,6 +164,22 @@ public class CarNavigationButton extends LinearLayout {
return mComponentNames;
}
/**
* Subclasses should override this method to return the {@link RoleManager} role associated
* with this button.
*/
protected String getRoleName() {
return null;
}
/**
* @return true if this button should show the icon of the default application for the
* role returned by {@link #getRoleName()}.
*/
protected boolean isDefaultAppIconForRoleEnabled() {
return mIsDefaultAppIconForRoleEnabled;
}
/**
* @return The id of the display the button is on or Display.INVALID_DISPLAY if it's not yet on
* a display.
@@ -240,7 +277,6 @@ public class CarNavigationButton extends LinearLayout {
};
}
/**
* Initializes view-related aspects of the button.
*/
@@ -256,28 +292,27 @@ public class CarNavigationButton extends LinearLayout {
R.styleable.CarNavigationButton_showMoreWhenSelected,
mShowMoreWhenSelected);
mSelectedIconResourceId = typedArray.getResourceId(
R.styleable.CarNavigationButton_selectedIcon, mIconResourceId);
mIconResourceId = typedArray.getResourceId(
R.styleable.CarNavigationButton_icon, 0);
mSelectedIconResourceId = typedArray.getResourceId(
R.styleable.CarNavigationButton_selectedIcon, mIconResourceId);
mIsDefaultAppIconForRoleEnabled = typedArray.getBoolean(
R.styleable.CarNavigationButton_useDefaultAppIconForRole, false);
mIcon = findViewById(R.id.car_nav_button_icon_image);
mIcon.setScaleType(ImageView.ScaleType.CENTER);
// Always apply selected alpha if the button does not toggle alpha based on selection state.
mIcon.setAlpha(mHighlightWhenSelected ? mUnselectedAlpha : mSelectedAlpha);
mIcon.setImageResource(mIconResourceId);
mMoreIcon = findViewById(R.id.car_nav_button_more_icon);
mMoreIcon.setAlpha(mSelectedAlpha);
mMoreIcon.setVisibility(GONE);
mUnseenIcon = findViewById(R.id.car_nav_button_unseen_icon);
mUnseenIcon.setVisibility(mHasUnseen ? VISIBLE : GONE);
updateImage();
}
private void updateImage() {
mIcon.setImageResource(mSelected ? mSelectedIconResourceId : mIconResourceId);
if (mIsDefaultAppIconForRoleEnabled && mAppIcon != null) {
mIcon.setImageDrawable(mAppIcon);
} else {
mIcon.setImageResource(mSelected ? mSelectedIconResourceId : mIconResourceId);
}
mUnseenIcon.setVisibility(mHasUnseen ? VISIBLE : GONE);
}

View File

@@ -0,0 +1,41 @@
<!--
~ Copyright (C) 2020 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:systemui="http://schemas.android.com/apk/res-auto"
android:id="@id/nav_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:gravity="center">
<com.android.systemui.car.navigationbar.AssitantButton
android:id="@+id/assistant_role_button"
style="@style/NavigationBarButton"
systemui:icon="@drawable/car_ic_overview"
systemui:useDefaultAppIconForRole="true"
/>
<com.android.systemui.car.navigationbar.AssitantButton
android:id="@+id/assistant_role_disabled_button"
style="@style/NavigationBarButton"
systemui:icon="@drawable/car_ic_overview"
/>
</LinearLayout>

View File

@@ -25,7 +25,7 @@
android:paddingEnd="20dp"
android:gravity="center">
<com.android.systemui.navigationbar.car.CarNavigationButton
<com.android.systemui.car.navigationbar.CarNavigationButton
android:id="@+id/detectable_by_component_name"
style="@style/NavigationBarButton"
systemui:componentNames="com.android.car.carlauncher/.CarLauncher"
@@ -34,7 +34,7 @@
systemui:highlightWhenSelected="true"
/>
<com.android.systemui.navigationbar.car.CarNavigationButton
<com.android.systemui.car.navigationbar.CarNavigationButton
android:id="@+id/detectable_by_category"
style="@style/NavigationBarButton"
systemui:categories="android.intent.category.APP_MAPS"
@@ -43,7 +43,7 @@
systemui:highlightWhenSelected="true"
/>
<com.android.systemui.navigationbar.car.CarNavigationButton
<com.android.systemui.car.navigationbar.CarNavigationButton
android:id="@+id/detectable_by_package"
style="@style/NavigationBarButton"
systemui:icon="@drawable/car_ic_phone"

View File

@@ -14,7 +14,7 @@
~ limitations under the License.
-->
<com.android.systemui.navigationbar.car.CarNavigationBarView
<com.android.systemui.car.navigationbar.CarNavigationBarView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:systemui="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
@@ -32,7 +32,7 @@
android:paddingEnd="20dp"
android:gravity="center">
<com.android.systemui.navigationbar.car.CarNavigationButton
<com.android.systemui.car.navigationbar.CarNavigationButton
android:id="@+id/home"
style="@style/NavigationBarButton"
systemui:componentNames="com.android.car.carlauncher/.CarLauncher"
@@ -55,4 +55,4 @@
android:visibility="gone"
/>
</com.android.systemui.navigationbar.car.CarNavigationBarView>
</com.android.systemui.car.navigationbar.CarNavigationBarView>

View File

@@ -25,7 +25,7 @@
android:paddingEnd="20dp"
android:gravity="center">
<com.android.systemui.navigationbar.car.CarNavigationButton
<com.android.systemui.car.navigationbar.CarNavigationButton
android:id="@+id/default_no_selection_state"
style="@style/NavigationBarButton"
systemui:componentNames="com.android.car.carlauncher/.CarLauncher"
@@ -34,7 +34,7 @@
systemui:selectedIcon="@drawable/car_ic_overview_selected"
/>
<com.android.systemui.navigationbar.car.CarNavigationButton
<com.android.systemui.car.navigationbar.CarNavigationButton
android:id="@+id/app_grid_activity"
style="@style/NavigationBarButton"
systemui:componentNames="com.android.car.carlauncher/.AppGridActivity"
@@ -44,7 +44,7 @@
systemui:highlightWhenSelected="true"
/>
<com.android.systemui.navigationbar.car.CarNavigationButton
<com.android.systemui.car.navigationbar.CarNavigationButton
android:id="@+id/long_click_app_grid_activity"
style="@style/NavigationBarButton"
systemui:componentNames="com.android.car.carlauncher/.AppGridActivity"
@@ -54,7 +54,7 @@
systemui:highlightWhenSelected="true"
/>
<com.android.systemui.navigationbar.car.CarNavigationButton
<com.android.systemui.car.navigationbar.CarNavigationButton
android:id="@+id/broadcast"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -63,7 +63,7 @@
systemui:intent="intent:#Intent;action=android.car.intent.action.TOGGLE_HVAC_CONTROLS;end"
/>
<com.android.systemui.navigationbar.car.CarNavigationButton
<com.android.systemui.car.navigationbar.CarNavigationButton
android:id="@+id/selected_icon_undefined"
style="@style/NavigationBarButton"
systemui:componentNames="com.android.car.carlauncher/.CarLauncher"
@@ -71,7 +71,7 @@
systemui:intent="intent:#Intent;action=android.intent.action.MAIN;category=android.intent.category.HOME;launchFlags=0x14000000;end"
/>
<com.android.systemui.navigationbar.car.CarNavigationButton
<com.android.systemui.car.navigationbar.CarNavigationButton
android:id="@+id/highlightable_no_more_button"
style="@style/NavigationBarButton"
systemui:componentNames="com.android.car.carlauncher/.CarLauncher"
@@ -81,7 +81,7 @@
systemui:highlightWhenSelected="true"
/>
<com.android.systemui.navigationbar.car.CarNavigationButton
<com.android.systemui.car.navigationbar.CarNavigationButton
android:id="@+id/not_highlightable_more_button"
style="@style/NavigationBarButton"
systemui:componentNames="com.android.car.carlauncher/.CarLauncher"
@@ -91,7 +91,7 @@
systemui:showMoreWhenSelected="true"
/>
<com.android.systemui.navigationbar.car.CarNavigationButton
<com.android.systemui.car.navigationbar.CarNavigationButton
android:id="@+id/highlightable_more_button"
style="@style/NavigationBarButton"
systemui:componentNames="com.android.car.carlauncher/.CarLauncher"
@@ -102,7 +102,7 @@
systemui:showMoreWhenSelected="true"
/>
<com.android.systemui.navigationbar.car.CarNavigationButton
<com.android.systemui.car.navigationbar.CarNavigationButton
android:id="@+id/broadcast"
style="@style/NavigationBarButton"
systemui:componentNames="com.android.car.carlauncher/.CarLauncher"
@@ -112,4 +112,13 @@
systemui:broadcast="true"
/>
<com.android.systemui.car.navigationbar.AssitantButton
android:id="@+id/role_based_button"
style="@style/NavigationBarButton"
systemui:icon="@drawable/car_ic_overview"
systemui:selectedIcon="@drawable/car_ic_overview_selected"
systemui:useDefaultAppIconForRole="true"
systemui:highlightWhenSelected="true"
/>
</LinearLayout>

View File

@@ -0,0 +1,187 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.car.navigationbar;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;
import android.app.role.RoleManager;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.UserHandle;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import androidx.test.filters.SmallTest;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.car.CarDeviceProvisionedController;
import com.android.systemui.tests.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.List;
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
@SmallTest
public class ButtonRoleHolderControllerTest extends SysuiTestCase {
private static final String TEST_VALID_PACKAGE_NAME = "foo";
private static final String TEST_INVALID_PACKAGE_NAME = "bar";
private static final UserHandle TEST_CURRENT_USER = UserHandle.of(100);
private static final UserHandle TEST_NON_CURRENT_USER = UserHandle.of(101);
private LinearLayout mTestView;
private CarNavigationButton mNavButtonDefaultAppIconForRoleWithEnabled;
private CarNavigationButton mNavButtonDefaultAppIconForRoleWithDisabled;
private ButtonRoleHolderController mControllerUnderTest;
private Drawable mAppIcon;
@Mock
private RoleManager mRoleManager;
@Mock
private CarDeviceProvisionedController mDeviceProvisionedController;
@Mock
private PackageManager mPackageManager;
@Mock
private ApplicationInfo mApplicationInfo;
@Before
public void setUp() throws PackageManager.NameNotFoundException {
MockitoAnnotations.initMocks(this);
mTestView = (LinearLayout) LayoutInflater.from(mContext).inflate(
R.layout.button_role_holder_controller_test, /* root= */ null);
mNavButtonDefaultAppIconForRoleWithEnabled = mTestView
.findViewById(R.id.assistant_role_button);
mNavButtonDefaultAppIconForRoleWithDisabled = mTestView
.findViewById(R.id.assistant_role_disabled_button);
mAppIcon = mContext.getDrawable(R.drawable.car_ic_apps);
when(mApplicationInfo.loadIcon(any())).thenReturn(mAppIcon);
doThrow(new PackageManager.NameNotFoundException()).when(mPackageManager)
.getApplicationInfo(any(), anyInt());
doReturn(mApplicationInfo).when(mPackageManager)
.getApplicationInfo(eq(TEST_VALID_PACKAGE_NAME), anyInt());
when(mDeviceProvisionedController
.getCurrentUser())
.thenReturn(TEST_CURRENT_USER.getIdentifier());
mControllerUnderTest = new ButtonRoleHolderController(mContext,
mPackageManager, mRoleManager, mDeviceProvisionedController);
}
@Test
public void addAllButtonsWithRoleName_roleAssigned_appIconEnabled_useAssignedAppIcon() {
when(mRoleManager.getRoleHoldersAsUser(eq(RoleManager.ROLE_ASSISTANT), any()))
.thenReturn(List.of(TEST_VALID_PACKAGE_NAME));
mControllerUnderTest.addAllButtonsWithRoleName(mTestView);
assertThat(mNavButtonDefaultAppIconForRoleWithEnabled.getAppIcon()).isEqualTo(mAppIcon);
}
@Test
public void addAllButtonsWithRoleName_roleUnassigned_appIconEnabled_useDefaultIcon() {
when(mRoleManager.getRoleHoldersAsUser(eq(RoleManager.ROLE_ASSISTANT), any()))
.thenReturn(null);
mControllerUnderTest.addAllButtonsWithRoleName(mTestView);
assertThat(mNavButtonDefaultAppIconForRoleWithEnabled.getAppIcon()).isNull();
}
@Test
public void onRoleChanged_currentUser_appIconEnabled_useAssignedAppIcon() {
when(mRoleManager.getRoleHoldersAsUser(eq(RoleManager.ROLE_ASSISTANT), any()))
.thenReturn(null);
mControllerUnderTest.addAllButtonsWithRoleName(mTestView);
when(mRoleManager
.getRoleHoldersAsUser(eq(RoleManager.ROLE_ASSISTANT), any()))
.thenReturn(List.of(TEST_VALID_PACKAGE_NAME));
mControllerUnderTest.onRoleChanged(RoleManager.ROLE_ASSISTANT, TEST_CURRENT_USER);
assertThat(mNavButtonDefaultAppIconForRoleWithEnabled.getAppIcon()).isEqualTo(mAppIcon);
}
@Test
public void onRoleChanged_nonCurrentUser_appIconEnabled_iconIsNotUpdated() {
when(mRoleManager
.getRoleHoldersAsUser(eq(RoleManager.ROLE_ASSISTANT), any()))
.thenReturn(null);
mControllerUnderTest.addAllButtonsWithRoleName(mTestView);
Drawable beforeIcon = mNavButtonDefaultAppIconForRoleWithEnabled.getAppIcon();
when(mRoleManager
.getRoleHoldersAsUser(eq(RoleManager.ROLE_ASSISTANT), any()))
.thenReturn(List.of(TEST_VALID_PACKAGE_NAME));
mControllerUnderTest.onRoleChanged(RoleManager.ROLE_ASSISTANT, TEST_NON_CURRENT_USER);
Drawable afterIcon = mNavButtonDefaultAppIconForRoleWithEnabled.getAppIcon();
assertThat(afterIcon).isEqualTo(beforeIcon);
}
@Test
public void onRoleChanged_invalidPackage_useDefaultIcon() {
when(mRoleManager
.getRoleHoldersAsUser(eq(RoleManager.ROLE_ASSISTANT), any()))
.thenReturn(List.of(TEST_INVALID_PACKAGE_NAME));
mControllerUnderTest.addAllButtonsWithRoleName(mTestView);
assertThat(mNavButtonDefaultAppIconForRoleWithEnabled.getAppIcon()).isNull();
}
@Test
public void addAllButtonsWithRoleName_appIconDisabled_useDefaultIcon() {
when(mRoleManager
.getRoleHoldersAsUser(eq(RoleManager.ROLE_ASSISTANT), any()))
.thenReturn(List.of(TEST_VALID_PACKAGE_NAME));
mControllerUnderTest.addAllButtonsWithRoleName(mTestView);
assertThat(mNavButtonDefaultAppIconForRoleWithDisabled.getAppIcon()).isNull();
}
@Test
public void onRoleChanged_roleAssigned_appIconDisabled_useDefaultIcon() {
when(mRoleManager
.getRoleHoldersAsUser(eq(RoleManager.ROLE_ASSISTANT), any()))
.thenReturn(null);
mControllerUnderTest.addAllButtonsWithRoleName(mTestView);
assertThat(mNavButtonDefaultAppIconForRoleWithDisabled.getAppIcon()).isNull();
when(mRoleManager
.getRoleHoldersAsUser(eq(RoleManager.ROLE_ASSISTANT), any()))
.thenReturn(List.of(TEST_VALID_PACKAGE_NAME));
mControllerUnderTest.onRoleChanged(RoleManager.ROLE_ASSISTANT, TEST_CURRENT_USER);
assertThat(mNavButtonDefaultAppIconForRoleWithDisabled.getAppIcon()).isNull();
}
}

View File

@@ -53,6 +53,8 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Mock
private ButtonSelectionStateController mButtonSelectionStateController;
@Mock
private ButtonRoleHolderController mButtonRoleHolderController;
@Mock
private HvacController mHvacController;
@Before
@@ -66,10 +68,15 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
mDependency.injectMockDependency(StatusBarIconController.class);
}
private CarNavigationBarController createNavigationBarController() {
return new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController,
mButtonRoleHolderController);
}
@Test
public void testConnectToHvac_callsConnect() {
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
mCarNavigationBar.connectToHvac();
@@ -77,20 +84,37 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
}
@Test
public void testRemoveAllFromHvac_callsRemoveAll() {
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
public void testRemoveAll_callsHvacControllerRemoveAllComponents() {
mCarNavigationBar = createNavigationBarController();
mCarNavigationBar.removeAllFromHvac();
mCarNavigationBar.removeAll();
verify(mHvacController).removeAllComponents();
}
@Test
public void testRemoveAll_callsButtonRoleHolderControllerRemoveAll() {
mCarNavigationBar = createNavigationBarController();
mCarNavigationBar.removeAll();
verify(mButtonRoleHolderController).removeAll();
}
@Test
public void testRemoveAll_callsButtonSelectionStateControllerRemoveAll() {
mCarNavigationBar = createNavigationBarController();
mCarNavigationBar.removeAll();
verify(mButtonSelectionStateController).removeAll();
}
@Test
public void testGetTopWindow_topDisabled_returnsNull() {
mTestableResources.addOverride(R.bool.config_enableTopNavigationBar, false);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window = mCarNavigationBar.getTopWindow();
@@ -100,8 +124,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testGetTopWindow_topEnabled_returnsWindow() {
mTestableResources.addOverride(R.bool.config_enableTopNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window = mCarNavigationBar.getTopWindow();
@@ -111,8 +134,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testGetTopWindow_topEnabled_calledTwice_returnsSameWindow() {
mTestableResources.addOverride(R.bool.config_enableTopNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window1 = mCarNavigationBar.getTopWindow();
ViewGroup window2 = mCarNavigationBar.getTopWindow();
@@ -123,8 +145,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testGetBottomWindow_bottomDisabled_returnsNull() {
mTestableResources.addOverride(R.bool.config_enableBottomNavigationBar, false);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window = mCarNavigationBar.getBottomWindow();
@@ -134,8 +155,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testGetBottomWindow_bottomEnabled_returnsWindow() {
mTestableResources.addOverride(R.bool.config_enableBottomNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window = mCarNavigationBar.getBottomWindow();
@@ -145,8 +165,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testGetBottomWindow_bottomEnabled_calledTwice_returnsSameWindow() {
mTestableResources.addOverride(R.bool.config_enableBottomNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window1 = mCarNavigationBar.getBottomWindow();
ViewGroup window2 = mCarNavigationBar.getBottomWindow();
@@ -157,8 +176,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testGetLeftWindow_leftDisabled_returnsNull() {
mTestableResources.addOverride(R.bool.config_enableLeftNavigationBar, false);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window = mCarNavigationBar.getLeftWindow();
assertThat(window).isNull();
}
@@ -166,8 +184,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testGetLeftWindow_leftEnabled_returnsWindow() {
mTestableResources.addOverride(R.bool.config_enableLeftNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window = mCarNavigationBar.getLeftWindow();
@@ -177,8 +194,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testGetLeftWindow_leftEnabled_calledTwice_returnsSameWindow() {
mTestableResources.addOverride(R.bool.config_enableLeftNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window1 = mCarNavigationBar.getLeftWindow();
ViewGroup window2 = mCarNavigationBar.getLeftWindow();
@@ -189,8 +205,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testGetRightWindow_rightDisabled_returnsNull() {
mTestableResources.addOverride(R.bool.config_enableRightNavigationBar, false);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window = mCarNavigationBar.getRightWindow();
@@ -200,8 +215,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testGetRightWindow_rightEnabled_returnsWindow() {
mTestableResources.addOverride(R.bool.config_enableRightNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window = mCarNavigationBar.getRightWindow();
@@ -211,8 +225,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testGetRightWindow_rightEnabled_calledTwice_returnsSameWindow() {
mTestableResources.addOverride(R.bool.config_enableRightNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window1 = mCarNavigationBar.getRightWindow();
ViewGroup window2 = mCarNavigationBar.getRightWindow();
@@ -223,8 +236,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testSetBottomWindowVisibility_setTrue_isVisible() {
mTestableResources.addOverride(R.bool.config_enableBottomNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window = mCarNavigationBar.getBottomWindow();
mCarNavigationBar.setBottomWindowVisibility(View.VISIBLE);
@@ -235,8 +247,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testSetBottomWindowVisibility_setFalse_isGone() {
mTestableResources.addOverride(R.bool.config_enableBottomNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window = mCarNavigationBar.getBottomWindow();
mCarNavigationBar.setBottomWindowVisibility(View.GONE);
@@ -247,8 +258,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testSetLeftWindowVisibility_setTrue_isVisible() {
mTestableResources.addOverride(R.bool.config_enableLeftNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window = mCarNavigationBar.getLeftWindow();
mCarNavigationBar.setLeftWindowVisibility(View.VISIBLE);
@@ -259,8 +269,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testSetLeftWindowVisibility_setFalse_isGone() {
mTestableResources.addOverride(R.bool.config_enableLeftNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window = mCarNavigationBar.getLeftWindow();
mCarNavigationBar.setLeftWindowVisibility(View.GONE);
@@ -271,8 +280,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testSetRightWindowVisibility_setTrue_isVisible() {
mTestableResources.addOverride(R.bool.config_enableRightNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window = mCarNavigationBar.getRightWindow();
mCarNavigationBar.setRightWindowVisibility(View.VISIBLE);
@@ -283,8 +291,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testSetRightWindowVisibility_setFalse_isGone() {
mTestableResources.addOverride(R.bool.config_enableRightNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
ViewGroup window = mCarNavigationBar.getRightWindow();
mCarNavigationBar.setRightWindowVisibility(View.GONE);
@@ -295,8 +302,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testRegisterBottomBarTouchListener_createViewFirst_registrationSuccessful() {
mTestableResources.addOverride(R.bool.config_enableBottomNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
CarNavigationBarView bottomBar = mCarNavigationBar.getBottomBar(/* isSetUp= */ true);
View.OnTouchListener controller = bottomBar.getStatusBarWindowTouchListener();
@@ -310,8 +316,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testRegisterBottomBarTouchListener_registerFirst_registrationSuccessful() {
mTestableResources.addOverride(R.bool.config_enableBottomNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
mCarNavigationBar.registerBottomBarTouchListener(mock(View.OnTouchListener.class));
CarNavigationBarView bottomBar = mCarNavigationBar.getBottomBar(/* isSetUp= */ true);
@@ -323,8 +328,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testRegisterNotificationController_createViewFirst_registrationSuccessful() {
mTestableResources.addOverride(R.bool.config_enableBottomNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
CarNavigationBarView bottomBar = mCarNavigationBar.getBottomBar(/* isSetUp= */ true);
CarNavigationBarController.NotificationsShadeController controller =
@@ -340,8 +344,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testRegisterNotificationController_registerFirst_registrationSuccessful() {
mTestableResources.addOverride(R.bool.config_enableBottomNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
mCarNavigationBar.registerNotificationController(
mock(CarNavigationBarController.NotificationsShadeController.class));
@@ -355,8 +358,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testShowAllKeyguardButtons_bottomEnabled_bottomKeyguardButtonsVisible() {
mTestableResources.addOverride(R.bool.config_enableBottomNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
CarNavigationBarView bottomBar = mCarNavigationBar.getBottomBar(/* isSetUp= */ true);
View bottomKeyguardButtons = bottomBar.findViewById(R.id.lock_screen_nav_buttons);
@@ -368,8 +370,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testShowAllKeyguardButtons_bottomEnabled_bottomNavButtonsGone() {
mTestableResources.addOverride(R.bool.config_enableBottomNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
CarNavigationBarView bottomBar = mCarNavigationBar.getBottomBar(/* isSetUp= */ true);
View bottomButtons = bottomBar.findViewById(R.id.nav_buttons);
@@ -381,8 +382,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testHideAllKeyguardButtons_bottomEnabled_bottomKeyguardButtonsGone() {
mTestableResources.addOverride(R.bool.config_enableBottomNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
CarNavigationBarView bottomBar = mCarNavigationBar.getBottomBar(/* isSetUp= */ true);
View bottomKeyguardButtons = bottomBar.findViewById(R.id.lock_screen_nav_buttons);
@@ -396,8 +396,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testHideAllKeyguardButtons_bottomEnabled_bottomNavButtonsVisible() {
mTestableResources.addOverride(R.bool.config_enableBottomNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
CarNavigationBarView bottomBar = mCarNavigationBar.getBottomBar(/* isSetUp= */ true);
View bottomButtons = bottomBar.findViewById(R.id.nav_buttons);
@@ -411,8 +410,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testToggleAllNotificationsUnseenIndicator_bottomEnabled_hasUnseen_setCorrectly() {
mTestableResources.addOverride(R.bool.config_enableBottomNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
CarNavigationBarView bottomBar = mCarNavigationBar.getBottomBar(/* isSetUp= */ true);
CarNavigationButton notifications = bottomBar.findViewById(R.id.notifications);
@@ -426,8 +424,7 @@ public class CarNavigationBarControllerTest extends SysuiTestCase {
@Test
public void testToggleAllNotificationsUnseenIndicator_bottomEnabled_noUnseen_setCorrectly() {
mTestableResources.addOverride(R.bool.config_enableBottomNavigationBar, true);
mCarNavigationBar = new CarNavigationBarController(mContext, mNavigationBarViewFactory,
mButtonSelectionStateController, () -> mHvacController);
mCarNavigationBar = createNavigationBarController();
CarNavigationBarView bottomBar = mCarNavigationBar.getBottomBar(/* isSetUp= */ true);
CarNavigationButton notifications = bottomBar.findViewById(R.id.notifications);

View File

@@ -89,6 +89,8 @@ public class CarNavigationBarTest extends SysuiTestCase {
@Mock
private ButtonSelectionStateListener mButtonSelectionStateListener;
@Mock
private ButtonRoleHolderController mButtonRoleHolderController;
@Mock
private IStatusBarService mBarService;
@Mock
private KeyguardStateController mKeyguardStateController;
@@ -137,8 +139,8 @@ public class CarNavigationBarTest extends SysuiTestCase {
mCarNavigationBarController, mLightBarController, mStatusBarIconController,
mWindowManager, mDeviceProvisionedController, new CommandQueue(mContext),
mAutoHideController, mButtonSelectionStateListener, mHandler, mUiBgExecutor,
mBarService, () -> mKeyguardStateController, mButtonSelectionStateController,
() -> mIconPolicy, () -> mIconController);
mBarService, () -> mKeyguardStateController, () -> mIconPolicy,
() -> mIconController);
}
@Test

View File

@@ -179,6 +179,56 @@ public class CarNavigationButtonTest extends SysuiTestCase {
assertThat(moreIcon.getVisibility()).isEqualTo(View.GONE);
}
@Test
public void onUnselected_withAppIcon_showsAppIcon() {
CarNavigationButton roleBasedButton = mTestView.findViewById(R.id.role_based_button);
Drawable appIcon = getContext().getDrawable(R.drawable.ic_android);
roleBasedButton.setSelected(false);
roleBasedButton.setAppIcon(appIcon);
Drawable currentDrawable = ((AlphaOptimizedImageButton) roleBasedButton.findViewById(
R.id.car_nav_button_icon_image)).getDrawable();
assertThat(currentDrawable).isEqualTo(appIcon);
}
@Test
public void onUnselected_withAppIcon_applyUnselectedAlpha() {
CarNavigationButton roleBasedButton = mTestView.findViewById(R.id.role_based_button);
roleBasedButton.setSelected(false);
roleBasedButton.setAppIcon(getContext().getDrawable(R.drawable.ic_android));
assertThat(roleBasedButton.getAlpha()).isEqualTo(
CarNavigationButton.DEFAULT_UNSELECTED_ALPHA);
}
@Test
public void onSelected_withAppIcon_showsAppIconWithSelectedAlpha() {
CarNavigationButton roleBasedButton = mTestView.findViewById(R.id.role_based_button);
Drawable appIcon = getContext().getDrawable(R.drawable.ic_android);
roleBasedButton.setSelected(true);
roleBasedButton.setAppIcon(appIcon);
Drawable currentDrawable = ((AlphaOptimizedImageButton) roleBasedButton.findViewById(
R.id.car_nav_button_icon_image)).getDrawable();
assertThat(currentDrawable).isEqualTo(appIcon);
}
@Test
public void onSelected_withAppIcon_applySelectedAlpha() {
CarNavigationButton roleBasedButton = mTestView.findViewById(R.id.role_based_button);
roleBasedButton.setSelected(true);
roleBasedButton.setAppIcon(getContext().getDrawable(R.drawable.ic_android));
assertThat(roleBasedButton.getAlpha()).isEqualTo(
CarNavigationButton.DEFAULT_SELECTED_ALPHA);
}
@Test
public void onClick_launchesIntentActivity() {
mDefaultButton.performClick();

View File

@@ -28,6 +28,7 @@ import android.app.KeyguardManager;
import android.app.NotificationManager;
import android.app.WallpaperManager;
import android.app.admin.DevicePolicyManager;
import android.app.role.RoleManager;
import android.app.trust.TrustManager;
import android.content.ContentResolver;
import android.content.Context;
@@ -314,4 +315,9 @@ public class SystemServicesModule {
return context.getSystemService(WindowManager.class);
}
@Provides
@Singleton
static RoleManager provideRoleManager(Context context) {
return context.getSystemService(RoleManager.class);
}
}