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:
Fan Zhang
2019-03-13 15:58:18 -07:00
parent 6120d57cbc
commit ad29500d1d
6 changed files with 12 additions and 44 deletions

View File

@@ -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);
}
}
}