Add logging for SettingsPanels

The 3 main categories are:
- Panel Opened
- Panel Closed
- Panel Slice interaction

There are 3 close events:
- See more button
- Done button
- Clicking outside the panel

Slice interactions will log the Uri of the Slice and the ActionType,
such as Toggle, Slider, Content (intent).

Change-Id: Iecad948f39f50dd12ae1bcb23a5d523e0df8bb98
Fixes: 117804231
Test: robotests
This commit is contained in:
Matthew Fritze
2019-02-08 14:09:35 -08:00
parent 545f8b1454
commit b197110f71
15 changed files with 291 additions and 42 deletions

View File

@@ -16,13 +16,25 @@
package com.android.settings.panel;
import static com.android.settings.panel.SettingsPanelActivity.KEY_PANEL_PACKAGE_NAME;
import static com.android.settings.panel.SettingsPanelActivity.KEY_MEDIA_PACKAGE_NAME;
import static com.android.settings.panel.SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT;
import static com.google.common.truth.Truth.assertThat;
import android.content.Intent;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.settings.SettingsEnums;
import android.content.Intent;
import android.view.MotionEvent;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
@@ -31,6 +43,22 @@ import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class SettingsPanelActivityTest {
private FakeFeatureFactory mFakeFeatureFactory;
private FakeSettingsPanelActivity mSettingsPanelActivity;
private PanelFeatureProvider mPanelFeatureProvider;
private FakePanelContent mFakePanelContent;
@Before
public void setUp() {
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
mSettingsPanelActivity = Robolectric.buildActivity(FakeSettingsPanelActivity.class)
.create().get();
mPanelFeatureProvider = spy(new PanelFeatureProviderImpl());
mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider;
mFakePanelContent = new FakePanelContent();
doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any(), any());
}
@Test
public void startMediaOutputSlice_withPackageName_bundleShouldHaveValue() {
final Intent intent = new Intent()
@@ -41,7 +69,7 @@ public class SettingsPanelActivityTest {
final SettingsPanelActivity activity =
Robolectric.buildActivity(SettingsPanelActivity.class, intent).create().get();
assertThat(activity.mBundle.getString(KEY_PANEL_PACKAGE_NAME))
assertThat(activity.mBundle.getString(KEY_MEDIA_PACKAGE_NAME))
.isEqualTo("com.google.android.music");
assertThat(activity.mBundle.getString(KEY_PANEL_TYPE_ARGUMENT))
.isEqualTo("com.android.settings.panel.action.MEDIA_OUTPUT");
@@ -55,7 +83,23 @@ public class SettingsPanelActivityTest {
final SettingsPanelActivity activity =
Robolectric.buildActivity(SettingsPanelActivity.class, intent).create().get();
assertThat(activity.mBundle.containsKey(KEY_PANEL_PACKAGE_NAME)).isFalse();
assertThat(activity.mBundle.containsKey(KEY_MEDIA_PACKAGE_NAME)).isFalse();
assertThat(activity.mBundle.containsKey(KEY_PANEL_TYPE_ARGUMENT)).isFalse();
}
@Test
public void onTouchEvent_outsideAction_logsPanelClosed() {
final MotionEvent event = mock(MotionEvent.class);
when(event.getAction()).thenReturn(MotionEvent.ACTION_OUTSIDE);
mSettingsPanelActivity.onTouchEvent(event);
verify(mFakeFeatureFactory.metricsFeatureProvider).action(
0,
SettingsEnums.PAGE_HIDE,
SettingsEnums.TESTING,
PanelLoggingContract.PanelClosedKeys.KEY_CLICKED_OUT,
0
);
}
}