Use CustomSliceRegistry directly when possible.
This is one step closer to (un)make CustomSliceManager an singleton. Bug: 123937830 Test: manual Change-Id: I844d0fb798c73e2af1945ecb667ba73fac9edf72
This commit is contained in:
@@ -57,15 +57,4 @@ public class CustomSliceManager {
|
||||
mSliceableCache.put(newUri, sliceable);
|
||||
return sliceable;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a {@link CustomSliceable} associated to the Action.
|
||||
* <p>
|
||||
* Do not change this method signature to accommodate for a special-case sliceable - a context
|
||||
* is the only thing that should be needed to create the object.
|
||||
*/
|
||||
public CustomSliceable getSliceableFromIntentAction(String action) {
|
||||
return getSliceableFromUri(Uri.parse(action));
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,6 @@ package com.android.settings.slices;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.Uri;
|
||||
|
||||
import androidx.slice.Slice;
|
||||
@@ -106,16 +105,17 @@ public interface CustomSliceable extends Sliceable {
|
||||
/**
|
||||
* Build an instance of a {@link CustomSliceable} which has a {@link Context}-only constructor.
|
||||
*/
|
||||
static CustomSliceable createInstance(Context context, Class<CustomSliceable> sliceableClass) {
|
||||
static CustomSliceable createInstance(Context context,
|
||||
Class<? extends CustomSliceable> sliceable) {
|
||||
try {
|
||||
final Constructor<CustomSliceable> sliceable =
|
||||
sliceableClass.getConstructor(Context.class);
|
||||
final Constructor<? extends CustomSliceable> constructor =
|
||||
sliceable.getConstructor(Context.class);
|
||||
final Object[] params = new Object[]{context};
|
||||
return sliceable.newInstance(params);
|
||||
return constructor.newInstance(params);
|
||||
} catch (NoSuchMethodException | InstantiationException |
|
||||
IllegalArgumentException | InvocationTargetException | IllegalAccessException e) {
|
||||
throw new IllegalStateException(
|
||||
"Invalid sliceable class: " + sliceableClass, e);
|
||||
"Invalid sliceable class: " + sliceable, e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -61,11 +61,10 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
final boolean isPlatformSlice = intent.getBooleanExtra(EXTRA_SLICE_PLATFORM_DEFINED,
|
||||
false /* default */);
|
||||
|
||||
final CustomSliceManager mCustomSliceManager = FeatureFactory.getFactory(
|
||||
context).getSlicesFeatureProvider().getCustomSliceManager(context);
|
||||
if (CustomSliceRegistry.isValidAction(action)) {
|
||||
final CustomSliceable sliceable =
|
||||
mCustomSliceManager.getSliceableFromIntentAction(action);
|
||||
CustomSliceable.createInstance(context,
|
||||
CustomSliceRegistry.getSliceClassByUri(Uri.parse(action)));
|
||||
sliceable.onNotifyChange(intent);
|
||||
return;
|
||||
}
|
||||
|
@@ -23,7 +23,6 @@ import android.util.Log;
|
||||
|
||||
import com.android.settings.bluetooth.BluetoothSliceBuilder;
|
||||
import com.android.settings.notification.ZenModeSliceBuilder;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
public class SliceDeepLinkSpringBoard extends Activity {
|
||||
|
||||
@@ -45,11 +44,10 @@ public class SliceDeepLinkSpringBoard extends Activity {
|
||||
Intent launchIntent;
|
||||
|
||||
// TODO (b/80263568) Avoid duplicating this list of Slice Uris.
|
||||
final CustomSliceManager customSliceManager = FeatureFactory.getFactory(this)
|
||||
.getSlicesFeatureProvider().getCustomSliceManager(this);
|
||||
if (CustomSliceRegistry.isValidUri(sliceUri)) {
|
||||
final CustomSliceable sliceable =
|
||||
customSliceManager.getSliceableFromUri(sliceUri);
|
||||
CustomSliceable.createInstance(getApplicationContext(),
|
||||
CustomSliceRegistry.getSliceClassByUri(sliceUri));
|
||||
launchIntent = sliceable.getIntent();
|
||||
} else if (CustomSliceRegistry.ZEN_MODE_SLICE_URI.equals(sliceUri)) {
|
||||
launchIntent = ZenModeSliceBuilder.getIntent(this /* context */);
|
||||
|
@@ -19,14 +19,12 @@ package com.android.settings.slices;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
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.app.settings.SettingsEnums;
|
||||
import android.app.slice.Slice;
|
||||
@@ -82,9 +80,6 @@ public class SliceBroadcastReceiverTest {
|
||||
mSearchFeatureProvider = new SearchFeatureProviderImpl();
|
||||
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mFakeFeatureFactory.searchFeatureProvider = mSearchFeatureProvider;
|
||||
CustomSliceManager manager = new CustomSliceManager(mContext);
|
||||
when(mFakeFeatureFactory.slicesFeatureProvider.getCustomSliceManager(any()))
|
||||
.thenReturn(manager);
|
||||
}
|
||||
|
||||
@After
|
||||
|
@@ -19,8 +19,6 @@ package com.android.settings.slices;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -41,28 +39,17 @@ public class SpecialCaseSliceManagerTest {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private CustomSliceManager mCustomSliceManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mCustomSliceManager = spy(new CustomSliceManager(mContext));
|
||||
CustomSliceRegistry.sUriToSlice.clear();
|
||||
CustomSliceRegistry.sUriToSlice.put(FakeSliceable.URI, FakeSliceable.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSliceableFromUri_returnsCorrectObject() {
|
||||
final CustomSliceable sliceable = mCustomSliceManager.getSliceableFromUri(
|
||||
FakeSliceable.URI);
|
||||
|
||||
assertThat(sliceable).isInstanceOf(FakeSliceable.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSliceableFromIntentAction_returnsCorrectObject() {
|
||||
final CustomSliceable sliceable =
|
||||
mCustomSliceManager.getSliceableFromIntentAction(FakeSliceable.URI.toString());
|
||||
final CustomSliceable sliceable = CustomSliceable.createInstance(
|
||||
mContext, CustomSliceRegistry.getSliceClassByUri(FakeSliceable.URI));
|
||||
|
||||
assertThat(sliceable).isInstanceOf(FakeSliceable.class);
|
||||
}
|
||||
|
Reference in New Issue
Block a user