Merge changes from topic "media_slice"
* changes: Implement MediaOutputSlice Add entry point to launch media output slice
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.settings.media;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
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.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.android.settingslib.media.MediaDevice;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class MediaDeviceUpdateWorkerTest {
|
||||
|
||||
private static final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||
private static final String TEST_DEVICE_1_ID = "test_device_1_id";
|
||||
private static final String TEST_DEVICE_2_ID = "test_device_2_id";
|
||||
private static final String TEST_DEVICE_3_ID = "test_device_3_id";
|
||||
|
||||
private final List<MediaDevice> mMediaDevices = new ArrayList<>();
|
||||
|
||||
private MediaDeviceUpdateWorker mMediaDeviceUpdateWorker;
|
||||
private ContentResolver mResolver;
|
||||
private Context mContext;
|
||||
private MediaDevice mMediaDevice1;
|
||||
private MediaDevice mMediaDevice2;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mMediaDeviceUpdateWorker = new MediaDeviceUpdateWorker(mContext, URI);
|
||||
mResolver = mock(ContentResolver.class);
|
||||
|
||||
mMediaDevice1 = mock(MediaDevice.class);
|
||||
when(mMediaDevice1.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
mMediaDevice2 = mock(MediaDevice.class);
|
||||
when(mMediaDevice2.getId()).thenReturn(TEST_DEVICE_2_ID);
|
||||
mMediaDevices.add(mMediaDevice1);
|
||||
mMediaDevices.add(mMediaDevice2);
|
||||
|
||||
doReturn(mResolver).when(mContext).getContentResolver();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeviceListUpdate_shouldNotifyChange() {
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mMediaDevices);
|
||||
|
||||
verify(mResolver).notifyChange(URI, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSelectedDeviceStateChanged_shouldNotifyChange() {
|
||||
mMediaDeviceUpdateWorker.onSelectedDeviceStateChanged(null, 0);
|
||||
|
||||
verify(mResolver).notifyChange(URI, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeviceListUpdate_sameDeviceList_shouldBeEqual() {
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mMediaDevices);
|
||||
|
||||
final List<MediaDevice> newDevices = new ArrayList<>();
|
||||
newDevices.add(mMediaDevice1);
|
||||
newDevices.add(mMediaDevice2);
|
||||
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(newDevices);
|
||||
final List<MediaDevice> devices = mMediaDeviceUpdateWorker.getMediaDevices();
|
||||
|
||||
assertThat(devices.get(0).getId()).isEqualTo(newDevices.get(0).getId());
|
||||
assertThat(devices.get(1).getId()).isEqualTo(newDevices.get(1).getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeviceListUpdate_add1DeviceToDeviceList_shouldBeEqual() {
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mMediaDevices);
|
||||
|
||||
final List<MediaDevice> newDevices = new ArrayList<>();
|
||||
final MediaDevice device3 = mock(MediaDevice.class);
|
||||
when(mMediaDevice2.getId()).thenReturn(TEST_DEVICE_3_ID);
|
||||
newDevices.add(mMediaDevice1);
|
||||
newDevices.add(mMediaDevice2);
|
||||
newDevices.add(device3);
|
||||
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(newDevices);
|
||||
final List<MediaDevice> devices = mMediaDeviceUpdateWorker.getMediaDevices();
|
||||
|
||||
assertThat(devices.size()).isEqualTo(newDevices.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeviceListUpdate_less1DeviceToDeviceList_shouldBeEqual() {
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mMediaDevices);
|
||||
|
||||
final List<MediaDevice> newDevices = new ArrayList<>();
|
||||
newDevices.add(mMediaDevice1);
|
||||
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(newDevices);
|
||||
final List<MediaDevice> devices = mMediaDeviceUpdateWorker.getMediaDevices();
|
||||
|
||||
assertThat(devices.size()).isEqualTo(newDevices.size());
|
||||
}
|
||||
}
|
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.settings.media;
|
||||
|
||||
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
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.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.UserHandle;
|
||||
import android.util.IconDrawableFactory;
|
||||
|
||||
import androidx.slice.Slice;
|
||||
import androidx.slice.SliceMetadata;
|
||||
import androidx.slice.SliceProvider;
|
||||
import androidx.slice.core.SliceAction;
|
||||
import androidx.slice.widget.SliceLiveData;
|
||||
|
||||
import com.android.settingslib.media.LocalMediaManager;
|
||||
import com.android.settingslib.media.MediaDevice;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class MediaOutputSliceTest {
|
||||
|
||||
private static final String TEST_PACKAGE_NAME = "com.fake.android.music";
|
||||
private static final String TEST_LABEL = "Test app";
|
||||
private static final String TEST_DEVICE_1_ID = "test_device_1_id";
|
||||
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private ApplicationInfo mApplicationInfo;
|
||||
@Mock
|
||||
private ApplicationInfo mApplicationInfo2;
|
||||
@Mock
|
||||
private LocalMediaManager mLocalMediaManager;
|
||||
@Mock
|
||||
private IconDrawableFactory mIconDrawableFactory;
|
||||
@Mock
|
||||
private Drawable mTestDrawable;
|
||||
|
||||
private final List<MediaDevice> mDevices = new ArrayList<>();
|
||||
|
||||
private Context mContext;
|
||||
private MediaOutputSlice mMediaOutputSlice;
|
||||
private MediaDeviceUpdateWorker mMediaDeviceUpdateWorker;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPackageManager.getApplicationInfo(eq(TEST_PACKAGE_NAME), anyInt()))
|
||||
.thenReturn(mApplicationInfo);
|
||||
when(mPackageManager.getApplicationInfoAsUser(eq(TEST_PACKAGE_NAME), anyInt(), anyInt()))
|
||||
.thenReturn(mApplicationInfo2);
|
||||
when(mApplicationInfo.loadLabel(mPackageManager)).thenReturn(TEST_LABEL);
|
||||
when(mIconDrawableFactory.getBadgedIcon(mApplicationInfo2, UserHandle.myUserId()))
|
||||
.thenReturn(mTestDrawable);
|
||||
when(mTestDrawable.getIntrinsicWidth()).thenReturn(100);
|
||||
when(mTestDrawable.getIntrinsicHeight()).thenReturn(100);
|
||||
|
||||
// Set-up specs for SliceMetadata.
|
||||
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
|
||||
|
||||
mMediaOutputSlice = new MediaOutputSlice(mContext);
|
||||
mMediaDeviceUpdateWorker = new MediaDeviceUpdateWorker(mContext, MEDIA_OUTPUT_SLICE_URI);
|
||||
mMediaDeviceUpdateWorker.setPackageName(TEST_PACKAGE_NAME);
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
mMediaDeviceUpdateWorker.mLocalMediaManager = mLocalMediaManager;
|
||||
mMediaOutputSlice.init(TEST_PACKAGE_NAME, mMediaDeviceUpdateWorker, mIconDrawableFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_shouldHaveAppTitle() {
|
||||
final Slice mediaSlice = mMediaOutputSlice.getSlice();
|
||||
final SliceMetadata metadata = SliceMetadata.from(mContext, mediaSlice);
|
||||
|
||||
final SliceAction primaryAction = metadata.getPrimaryAction();
|
||||
assertThat(primaryAction.getTitle().toString()).isEqualTo(TEST_LABEL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNotifyChange_foundMediaDevice_connect() {
|
||||
mDevices.clear();
|
||||
final MediaDevice device = mock(MediaDevice.class);
|
||||
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
when(mLocalMediaManager.getMediaDeviceById(mDevices, TEST_DEVICE_1_ID)).thenReturn(device);
|
||||
mDevices.add(device);
|
||||
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra("media_device_id", TEST_DEVICE_1_ID);
|
||||
|
||||
mMediaOutputSlice.onNotifyChange(intent);
|
||||
|
||||
verify(mLocalMediaManager).connectDevice(device);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNotifyChange_notFoundMediaDevice_doNothing() {
|
||||
mDevices.clear();
|
||||
final MediaDevice device = mock(MediaDevice.class);
|
||||
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
when(mLocalMediaManager.getMediaDeviceById(mDevices, TEST_DEVICE_1_ID)).thenReturn(device);
|
||||
mDevices.add(device);
|
||||
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra("media_device_id", "fake_123");
|
||||
|
||||
mMediaOutputSlice.onNotifyChange(intent);
|
||||
|
||||
verify(mLocalMediaManager, never()).connectDevice(device);
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.settings.panel;
|
||||
|
||||
import static com.android.settings.media.MediaOutputSlice.MEDIA_PACKAGE_NAME;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import com.android.settings.slices.CustomSliceRegistry;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class MediaOutputPanelTest {
|
||||
|
||||
private static final String TEST_PACKAGENAME = "com.test.packagename";
|
||||
|
||||
private MediaOutputPanel mPanel;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mPanel = MediaOutputPanel.create(RuntimeEnvironment.application, TEST_PACKAGENAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlices_containsNecessarySlices() {
|
||||
final List<Uri> uris = mPanel.getSlices();
|
||||
|
||||
assertThat(uris).containsExactly(CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlices_verifyPackageName_isEqual() {
|
||||
final List<Uri> uris = mPanel.getSlices();
|
||||
|
||||
assertThat(uris.get(0).getQueryParameter(MEDIA_PACKAGE_NAME)).isEqualTo(TEST_PACKAGENAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSeeMoreIntent_isNull() {
|
||||
assertThat(mPanel.getSeeMoreIntent()).isNull();
|
||||
}
|
||||
}
|
@@ -17,6 +17,8 @@
|
||||
|
||||
package com.android.settings.panel;
|
||||
|
||||
import static com.android.settingslib.media.MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -32,6 +34,8 @@ import org.robolectric.RuntimeEnvironment;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class PanelFeatureProviderImplTest {
|
||||
|
||||
private static final String TEST_PACKAGENAME = "com.test.packagename";
|
||||
|
||||
private Context mContext;
|
||||
private PanelFeatureProviderImpl mProvider;
|
||||
|
||||
@@ -44,7 +48,7 @@ public class PanelFeatureProviderImplTest {
|
||||
@Test
|
||||
public void getPanel_internetConnectivityKey_returnsCorrectPanel() {
|
||||
final PanelContent panel = mProvider.getPanel(mContext,
|
||||
Settings.Panel.ACTION_INTERNET_CONNECTIVITY);
|
||||
Settings.Panel.ACTION_INTERNET_CONNECTIVITY, TEST_PACKAGENAME);
|
||||
|
||||
assertThat(panel).isInstanceOf(InternetConnectivityPanel.class);
|
||||
}
|
||||
@@ -52,8 +56,16 @@ public class PanelFeatureProviderImplTest {
|
||||
@Test
|
||||
public void getPanel_volume_returnsCorrectPanel() {
|
||||
final PanelContent panel = mProvider.getPanel(mContext,
|
||||
Settings.Panel.ACTION_VOLUME);
|
||||
Settings.Panel.ACTION_VOLUME, TEST_PACKAGENAME);
|
||||
|
||||
assertThat(panel).isInstanceOf(VolumePanel.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPanel_mediaOutputKey_returnsCorrectPanel() {
|
||||
final PanelContent panel = mProvider.getPanel(mContext,
|
||||
ACTION_MEDIA_OUTPUT, TEST_PACKAGENAME);
|
||||
|
||||
assertThat(panel).isInstanceOf(MediaOutputPanel.class);
|
||||
}
|
||||
}
|
||||
|
@@ -59,7 +59,7 @@ public class PanelFragmentTest {
|
||||
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider;
|
||||
mFakePanelContent = new FakePanelContent();
|
||||
doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any());
|
||||
doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any(), any());
|
||||
|
||||
ActivityController<FakeSettingsPanelActivity> activityController =
|
||||
Robolectric.buildActivity(FakeSettingsPanelActivity.class);
|
||||
|
@@ -58,7 +58,7 @@ public class PanelSlicesAdapterTest {
|
||||
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mFakeFeatureFactory.panelFeatureProvider = mPanelFeatureProvider;
|
||||
mFakePanelContent = new FakePanelContent();
|
||||
doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any());
|
||||
doReturn(mFakePanelContent).when(mPanelFeatureProvider).getPanel(any(), any(), any());
|
||||
|
||||
ActivityController<FakeSettingsPanelActivity> activityController =
|
||||
Robolectric.buildActivity(FakeSettingsPanelActivity.class);
|
||||
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.settings.panel;
|
||||
|
||||
import static com.android.settings.panel.SettingsPanelActivity.KEY_PANEL_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 org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SettingsPanelActivityTest {
|
||||
|
||||
@Test
|
||||
public void startMediaOutputSlice_withPackageName_bundleShouldHaveValue() {
|
||||
final Intent intent = new Intent()
|
||||
.setAction("com.android.settings.panel.action.MEDIA_OUTPUT")
|
||||
.putExtra("com.android.settings.panel.extra.PACKAGE_NAME",
|
||||
"com.google.android.music");
|
||||
|
||||
final SettingsPanelActivity activity =
|
||||
Robolectric.buildActivity(SettingsPanelActivity.class, intent).create().get();
|
||||
|
||||
assertThat(activity.mBundle.getString(KEY_PANEL_PACKAGE_NAME))
|
||||
.isEqualTo("com.google.android.music");
|
||||
assertThat(activity.mBundle.getString(KEY_PANEL_TYPE_ARGUMENT))
|
||||
.isEqualTo("com.android.settings.panel.action.MEDIA_OUTPUT");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startMediaOutputSlice_withoutPackageName_bundleShouldNotHaveValue() {
|
||||
final Intent intent = new Intent()
|
||||
.setAction("com.android.settings.panel.action.MEDIA_OUTPUT");
|
||||
|
||||
final SettingsPanelActivity activity =
|
||||
Robolectric.buildActivity(SettingsPanelActivity.class, intent).create().get();
|
||||
|
||||
assertThat(activity.mBundle.containsKey(KEY_PANEL_PACKAGE_NAME)).isFalse();
|
||||
assertThat(activity.mBundle.containsKey(KEY_PANEL_TYPE_ARGUMENT)).isFalse();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user