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 */);
|
||||
|
Reference in New Issue
Block a user