Architecture review of Copyable Slice
Design doc: https://drive.google.com/open?id=1NJPd_282H4195HUGJH5cGJO_Jrcz1Vl6AAw_VQOtGq0 Fixes: 118398321 Test: manual Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.slice Change-Id: Ic6762e58698a994d16a5de1778b4035ae430a256
This commit is contained in:
@@ -41,6 +41,7 @@ import androidx.slice.widget.SliceLiveData;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.FakeCopyableController;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.FakeSliderController;
|
||||
import com.android.settings.testutils.FakeToggleController;
|
||||
@@ -67,6 +68,7 @@ public class SliceBuilderUtilsTest {
|
||||
private final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||
private final Class TOGGLE_CONTROLLER = FakeToggleController.class;
|
||||
private final Class SLIDER_CONTROLLER = FakeSliderController.class;
|
||||
private final Class COPYABLE_CONTROLLER = FakeCopyableController.class;
|
||||
private final Class CONTEXT_CONTROLLER = FakeContextOnlyPreferenceController.class;
|
||||
private final boolean IS_DYNAMIC_SUMMARY_ALLOWED = false;
|
||||
|
||||
@@ -116,7 +118,6 @@ public class SliceBuilderUtilsTest {
|
||||
public void buildSliderSlice_returnsMatchingSlice() {
|
||||
final SliceData data = getDummyData(SLIDER_CONTROLLER, SliceData.SliceType.SLIDER);
|
||||
|
||||
|
||||
final Slice slice = SliceBuilderUtils.buildSlice(mContext, data);
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(eq(mContext), eq(MetricsEvent.ACTION_SETTINGS_SLICE_REQUESTED),
|
||||
@@ -130,6 +131,23 @@ public class SliceBuilderUtilsTest {
|
||||
SliceTester.testSettingsSliderSlice(mContext, slice, data);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildCopyableSlice_returnsMatchingSlice() {
|
||||
final SliceData dummyData = getDummyData(COPYABLE_CONTROLLER, -1);
|
||||
|
||||
final Slice slice = SliceBuilderUtils.buildSlice(mContext, dummyData);
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(eq(mContext), eq(MetricsEvent.ACTION_SETTINGS_SLICE_REQUESTED),
|
||||
mLoggingArgumentCatpor.capture());
|
||||
final Pair<Integer, Object> capturedLoggingPair = mLoggingArgumentCatpor.getValue();
|
||||
|
||||
assertThat(capturedLoggingPair.first)
|
||||
.isEqualTo(MetricsEvent.FIELD_SETTINGS_PREFERENCE_CHANGE_NAME);
|
||||
assertThat(capturedLoggingPair.second)
|
||||
.isEqualTo(dummyData.getKey());
|
||||
SliceTester.testSettingsCopyableSlice(mContext, slice, dummyData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUriBuilder_oemAuthority_intentPath_returnsValidSliceUri() {
|
||||
final Uri expectedUri = new Uri.Builder()
|
||||
|
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.testutils;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.slices.CopyableSlice;
|
||||
|
||||
public class FakeCopyableController extends BasePreferenceController implements
|
||||
CopyableSlice {
|
||||
|
||||
public FakeCopyableController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
}
|
||||
}
|
@@ -168,6 +168,43 @@ public class SliceTester {
|
||||
assertKeywords(metadata, sliceData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the copyable slice, including:
|
||||
* - No intent
|
||||
* - Correct title
|
||||
* - Correct intent
|
||||
* - Correct keywords
|
||||
* - TTL
|
||||
* - Color
|
||||
*/
|
||||
public static void testSettingsCopyableSlice(Context context, Slice slice,
|
||||
SliceData sliceData) {
|
||||
final SliceMetadata metadata = SliceMetadata.from(context, slice);
|
||||
|
||||
final SliceItem colorItem = SliceQuery.findSubtype(slice, FORMAT_INT, SUBTYPE_COLOR);
|
||||
final int color = colorItem.getInt();
|
||||
assertThat(color).isEqualTo(Utils.getColorAccentDefaultColor(context));
|
||||
|
||||
final SliceAction primaryAction = metadata.getPrimaryAction();
|
||||
|
||||
final IconCompat expectedIcon = IconCompat.createWithResource(context,
|
||||
sliceData.getIconResource());
|
||||
assertThat(expectedIcon.toString()).isEqualTo(primaryAction.getIcon().toString());
|
||||
|
||||
final long sliceTTL = metadata.getExpiry();
|
||||
assertThat(sliceTTL).isEqualTo(ListBuilder.INFINITY);
|
||||
|
||||
// Check primary intent
|
||||
final PendingIntent primaryPendingIntent = primaryAction.getAction();
|
||||
assertThat(primaryPendingIntent).isEqualTo(
|
||||
SliceBuilderUtils.getContentPendingIntent(context, sliceData));
|
||||
|
||||
final List<SliceItem> sliceItems = slice.getItems();
|
||||
assertTitle(sliceItems, sliceData.getTitle());
|
||||
|
||||
assertKeywords(metadata, sliceData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the contents of an unavailable slice, including:
|
||||
* - No toggles
|
||||
@@ -229,4 +266,4 @@ public class SliceTester {
|
||||
expectedKeywords.add(data.getScreenTitle().toString());
|
||||
assertThat(keywords).containsExactlyElementsIn(expectedKeywords);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user