Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60d64cec authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use CustomSliceRegistry directly when possible."

parents 0ba4ca09 ad29500d
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -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));
    }
}
+6 −6
Original line number Diff line number Diff line
@@ -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);
        }
    }
}
 No newline at end of file
+2 −3
Original line number Diff line number Diff line
@@ -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;
        }
+2 −4
Original line number Diff line number Diff line
@@ -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 */);
+0 −5
Original line number Diff line number Diff line
@@ -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
Loading