Change Panels creation interface to take a bundle

Fixes: 124399577
Test: robolectric
adb shell am start -a android.settings.panel.action.WIFI
adb shell am start -a android.settings.panel.action.VOLUME

Change-Id: I9e13357444e4ebeee50fb8cc68fbc974ce5fffb6
This commit is contained in:
Raff Tsai
2019-10-18 12:51:28 +08:00
parent 4b4b7e76c4
commit dfba9a0f6d
7 changed files with 31 additions and 25 deletions

View File

@@ -17,12 +17,12 @@
package com.android.settings.panel; package com.android.settings.panel;
import android.content.Context; import android.content.Context;
import android.os.Bundle;
public interface PanelFeatureProvider { public interface PanelFeatureProvider {
/** /**
* Returns {@link PanelContent} as specified by the {@param panelType}, and * Returns {@link PanelContent} as specified by the {@param bundle}
* {@param mediaPackageName}.
*/ */
PanelContent getPanel(Context context, String panelType, String mediaPackageName); PanelContent getPanel(Context context, Bundle bundle);
} }

View File

@@ -19,16 +19,22 @@ package com.android.settings.panel;
import static com.android.settingslib.media.MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT; import static com.android.settingslib.media.MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT;
import android.content.Context; import android.content.Context;
import android.os.Bundle;
import android.provider.Settings; import android.provider.Settings;
public class PanelFeatureProviderImpl implements PanelFeatureProvider { public class PanelFeatureProviderImpl implements PanelFeatureProvider {
@Override @Override
public PanelContent getPanel(Context context, String panelType, String mediaPackageName) { public PanelContent getPanel(Context context, Bundle bundle) {
if (context == null) { if (context == null) {
return null; return null;
} }
final String panelType =
bundle.getString(SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT);
final String mediaPackageName =
bundle.getString(SettingsPanelActivity.KEY_MEDIA_PACKAGE_NAME);
switch (panelType) { switch (panelType) {
case Settings.Panel.ACTION_INTERNET_CONNECTIVITY: case Settings.Panel.ACTION_INTERNET_CONNECTIVITY:
return InternetConnectivityPanel.create(context); return InternetConnectivityPanel.create(context);

View File

@@ -161,17 +161,12 @@ public class PanelFragment extends Fragment {
mPanelSlices.setVisibility(View.GONE); mPanelSlices.setVisibility(View.GONE);
final Bundle arguments = getArguments(); final Bundle arguments = getArguments();
final String panelType =
arguments.getString(SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT);
final String callingPackageName = final String callingPackageName =
arguments.getString(SettingsPanelActivity.KEY_CALLING_PACKAGE_NAME); arguments.getString(SettingsPanelActivity.KEY_CALLING_PACKAGE_NAME);
final String mediaPackageName =
arguments.getString(SettingsPanelActivity.KEY_MEDIA_PACKAGE_NAME);
// TODO (b/124399577) transform interface to take a context and bundle.
mPanel = FeatureFactory.getFactory(activity) mPanel = FeatureFactory.getFactory(activity)
.getPanelFeatureProvider() .getPanelFeatureProvider()
.getPanel(activity, panelType, mediaPackageName); .getPanel(activity, arguments);
if (mPanel == null) { if (mPanel == null) {
activity.finish(); activity.finish();

View File

@@ -17,17 +17,19 @@
package com.android.settings.panel; package com.android.settings.panel;
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.android.settingslib.media.MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT; import static com.android.settingslib.media.MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import android.content.Context; import android.content.Context;
import android.os.Bundle;
import android.provider.Settings; import android.provider.Settings;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
@@ -38,33 +40,39 @@ public class PanelFeatureProviderImplTest {
private Context mContext; private Context mContext;
private PanelFeatureProviderImpl mProvider; private PanelFeatureProviderImpl mProvider;
private Bundle mBundle;
@Before @Before
public void setUp() { public void setUp() {
mContext = RuntimeEnvironment.application; mContext = RuntimeEnvironment.application;
mProvider = new PanelFeatureProviderImpl(); mProvider = new PanelFeatureProviderImpl();
mBundle = new Bundle();
mBundle.putString(KEY_MEDIA_PACKAGE_NAME, TEST_PACKAGENAME);
} }
@Test @Test
public void getPanel_internetConnectivityKey_returnsCorrectPanel() { public void getPanel_internetConnectivityKey_returnsCorrectPanel() {
final PanelContent panel = mProvider.getPanel(mContext, mBundle.putString(KEY_PANEL_TYPE_ARGUMENT, Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
Settings.Panel.ACTION_INTERNET_CONNECTIVITY, TEST_PACKAGENAME);
final PanelContent panel = mProvider.getPanel(mContext, mBundle);
assertThat(panel).isInstanceOf(InternetConnectivityPanel.class); assertThat(panel).isInstanceOf(InternetConnectivityPanel.class);
} }
@Test @Test
public void getPanel_volume_returnsCorrectPanel() { public void getPanel_volume_returnsCorrectPanel() {
final PanelContent panel = mProvider.getPanel(mContext, mBundle.putString(KEY_PANEL_TYPE_ARGUMENT, Settings.Panel.ACTION_VOLUME);
Settings.Panel.ACTION_VOLUME, TEST_PACKAGENAME);
final PanelContent panel = mProvider.getPanel(mContext, mBundle);
assertThat(panel).isInstanceOf(VolumePanel.class); assertThat(panel).isInstanceOf(VolumePanel.class);
} }
@Test @Test
public void getPanel_mediaOutputKey_returnsCorrectPanel() { public void getPanel_mediaOutputKey_returnsCorrectPanel() {
final PanelContent panel = mProvider.getPanel(mContext, mBundle.putString(KEY_PANEL_TYPE_ARGUMENT, ACTION_MEDIA_OUTPUT);
ACTION_MEDIA_OUTPUT, TEST_PACKAGENAME);
final PanelContent panel = mProvider.getPanel(mContext, mBundle);
assertThat(panel).isInstanceOf(MediaOutputPanel.class); assertThat(panel).isInstanceOf(MediaOutputPanel.class);
} }

View File

@@ -38,7 +38,6 @@ import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
@@ -63,7 +62,7 @@ public class PanelFragmentTest {
mFakeFeatureFactory = FakeFeatureFactory.setupForTest(); mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider; mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider;
mFakePanelContent = new FakePanelContent(); mFakePanelContent = new FakePanelContent();
doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any(), any()); doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any());
mActivity = spy(Robolectric.buildActivity(FakeSettingsPanelActivity.class).setup().get()); mActivity = spy(Robolectric.buildActivity(FakeSettingsPanelActivity.class).setup().get());
@@ -83,7 +82,7 @@ public class PanelFragmentTest {
new LinearLayout(mContext), null); new LinearLayout(mContext), null);
PanelSlicesLoaderCountdownLatch countdownLatch = PanelSlicesLoaderCountdownLatch countdownLatch =
mPanelFragment.mPanelSlicesLoaderCountdownLatch; mPanelFragment.mPanelSlicesLoaderCountdownLatch;
for (Uri sliecUri: mFakePanelContent.getSlices()) { for (Uri sliecUri : mFakePanelContent.getSlices()) {
countdownLatch.markSliceLoaded(sliecUri); countdownLatch.markSliceLoaded(sliecUri);
} }

View File

@@ -40,17 +40,15 @@ import com.android.settings.slices.CustomSliceRegistry;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before; import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.android.controller.ActivityController; import org.robolectric.android.controller.ActivityController;
import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@@ -74,7 +72,7 @@ public class PanelSlicesAdapterTest {
mFakeFeatureFactory = FakeFeatureFactory.setupForTest(); mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider; mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider;
mFakePanelContent = new FakePanelContent(); mFakePanelContent = new FakePanelContent();
doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any(), any()); doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any());
ActivityController<FakeSettingsPanelActivity> activityController = ActivityController<FakeSettingsPanelActivity> activityController =
Robolectric.buildActivity(FakeSettingsPanelActivity.class); Robolectric.buildActivity(FakeSettingsPanelActivity.class);

View File

@@ -65,7 +65,7 @@ public class SettingsPanelActivityTest {
mPanelFeatureProvider = spy(new PanelFeatureProviderImpl()); mPanelFeatureProvider = spy(new PanelFeatureProviderImpl());
mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider; mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider;
mFakePanelContent = new FakePanelContent(); mFakePanelContent = new FakePanelContent();
doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any(), any()); doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any());
} }
@Test @Test