summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/app/StatusBarManager.java6
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/QSPanel.java6
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java3
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelTest.java61
4 files changed, 68 insertions, 8 deletions
diff --git a/core/java/android/app/StatusBarManager.java b/core/java/android/app/StatusBarManager.java
index 2718bfacb618..bf3d885cd9c9 100644
--- a/core/java/android/app/StatusBarManager.java
+++ b/core/java/android/app/StatusBarManager.java
@@ -17,6 +17,7 @@
package android.app;
import android.annotation.IntDef;
+import android.annotation.Nullable;
import android.annotation.SystemService;
import android.annotation.UnsupportedAppUsage;
import android.content.Context;
@@ -208,10 +209,11 @@ public class StatusBarManager {
}
/**
- * Expand the settings panel and open a subPanel, pass null to just open the settings panel.
+ * Expand the settings panel and open a subPanel. If the subpanel is null or does not have a
+ * corresponding tile, the QS panel is simply expanded
*/
@UnsupportedAppUsage
- public void expandSettingsPanel(String subPanel) {
+ public void expandSettingsPanel(@Nullable String subPanel) {
try {
final IStatusBarService svc = getService();
if (svc != null) {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
index 7a57fdde6712..0006038c6067 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
@@ -199,7 +199,11 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
public void openDetails(String subPanel) {
QSTile tile = getTile(subPanel);
- showDetailAdapter(true, tile.getDetailAdapter(), new int[]{getWidth() / 2, 0});
+ // If there's no tile with that name (as defined in QSFactoryImpl or other QSFactory),
+ // QSFactory will not be able to create a tile and getTile will return null
+ if (tile != null) {
+ showDetailAdapter(true, tile.getDetailAdapter(), new int[]{getWidth() / 2, 0});
+ }
}
private QSTile getTile(String subPanel) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
index e1d86387cdfd..17e222100850 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -2156,7 +2156,7 @@ public class StatusBar extends SystemUI implements DemoMode,
}
@Override
- public void animateExpandSettingsPanel(String subPanel) {
+ public void animateExpandSettingsPanel(@Nullable String subPanel) {
if (SPEW) Log.d(TAG, "animateExpand: mExpandedVisible=" + mExpandedVisible);
if (!panelsEnabled()) {
return;
@@ -2165,7 +2165,6 @@ public class StatusBar extends SystemUI implements DemoMode,
// Settings are not available in setup
if (!mUserSetup) return;
-
if (subPanel != null) {
mQSPanel.openDetails(subPanel);
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelTest.java
index 85cdfcc2ce09..12a122a5c734 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelTest.java
@@ -14,8 +14,12 @@
package com.android.systemui.qs;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -23,15 +27,21 @@ import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
+import android.view.ViewGroup;
+import android.widget.FrameLayout;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.systemui.SysuiTestCase;
+import com.android.systemui.plugins.qs.QSTile;
+import com.android.systemui.plugins.qs.QSTileView;
import com.android.systemui.qs.customize.QSCustomizer;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import java.util.Collections;
@@ -41,19 +51,37 @@ import java.util.Collections;
public class QSPanelTest extends SysuiTestCase {
private MetricsLogger mMetricsLogger;
+ private TestableLooper mTestableLooper;
private QSPanel mQsPanel;
+ @Mock
private QSTileHost mHost;
+ @Mock
private QSCustomizer mCustomizer;
+ @Mock
+ private QSTile dndTile;
+ private ViewGroup mParentView;
+ @Mock
+ private QSDetail.Callback mCallback;
@Before
public void setup() throws Exception {
- TestableLooper.get(this).runWithLooper(() -> {
+ MockitoAnnotations.initMocks(this);
+
+ mTestableLooper = TestableLooper.get(this);
+ mTestableLooper.runWithLooper(() -> {
mMetricsLogger = mDependency.injectMockDependency(MetricsLogger.class);
mQsPanel = new QSPanel(mContext, null);
- mHost = mock(QSTileHost.class);
+ // Provides a parent with non-zero size for QSPanel
+ mParentView = new FrameLayout(mContext);
+ mParentView.addView(mQsPanel);
+
+ when(dndTile.getTileSpec()).thenReturn("dnd");
when(mHost.getTiles()).thenReturn(Collections.emptyList());
- mCustomizer = mock(QSCustomizer.class);
+ when(mHost.createTileView(any(), anyBoolean())).thenReturn(mock(QSTileView.class));
+
mQsPanel.setHost(mHost, mCustomizer);
+ mQsPanel.addTile(dndTile, true);
+ mQsPanel.setCallback(mCallback);
});
}
@@ -64,4 +92,31 @@ public class QSPanelTest extends SysuiTestCase {
mQsPanel.setExpanded(false);
verify(mMetricsLogger).visibility(eq(MetricsEvent.QS_PANEL), eq(false));
}
+
+ @Test
+ public void testOpenDetailsWithExistingTile_NoException() {
+ mTestableLooper.processAllMessages();
+ mQsPanel.openDetails("dnd");
+ mTestableLooper.processAllMessages();
+
+ verify(mCallback).onShowingDetail(any(), anyInt(), anyInt());
+ }
+
+/* @Test
+ public void testOpenDetailsWithNullParameter_NoException() {
+ mTestableLooper.processAllMessages();
+ mQsPanel.openDetails(null);
+ mTestableLooper.processAllMessages();
+
+ verify(mCallback, never()).onShowingDetail(any(), anyInt(), anyInt());
+ }*/
+
+ @Test
+ public void testOpenDetailsWithNonExistingTile_NoException() {
+ mTestableLooper.processAllMessages();
+ mQsPanel.openDetails("invalid-name");
+ mTestableLooper.processAllMessages();
+
+ verify(mCallback, never()).onShowingDetail(any(), anyInt(), anyInt());
+ }
}