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

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

Merge "Handle simplified Slice deep link intent pattern."

parents c5143cee f837b899
Loading
Loading
Loading
Loading
+26 −52
Original line number Diff line number Diff line
@@ -25,31 +25,23 @@ import com.android.settings.bluetooth.BluetoothSliceBuilder;
import com.android.settings.notification.ZenModeSliceBuilder;
import com.android.settings.overlay.FeatureFactory;

import java.net.URISyntaxException;

public class SliceDeepLinkSpringBoard extends Activity {

    private static final String TAG = "DeeplinkSpringboard";
    public static final String INTENT = "intent";
    public static final String SETTINGS = "settings";
    public static final String ACTION_VIEW_SLICE = "com.android.settings.action.VIEW_SLICE";
    public static final String EXTRA_SLICE = "slice";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Uri uri = getIntent().getData();
        if (uri == null) {
        final Uri sliceUri = parse(getIntent().getData());
        if (sliceUri == null) {
            Log.e(TAG, "No data found");
            finish();
            return;
        }
        try {
            Intent intent = parse(uri, getPackageName());
            if (ACTION_VIEW_SLICE.equals(intent.getAction())) {
            // This shouldn't matter since the slice is shown instead of the device
            // index caring about the launch uri.
                final Uri sliceUri = Uri.parse(intent.getStringExtra(EXTRA_SLICE));
            Intent launchIntent;

            // TODO (b/80263568) Avoid duplicating this list of Slice Uris.
@@ -71,34 +63,16 @@ public class SliceDeepLinkSpringBoard extends Activity {
                        slicesDatabaseAccessor.getSliceDataFromUri(sliceUri);
                launchIntent = SliceBuilderUtils.getContentIntent(this, sliceData);
            }

            startActivity(launchIntent);
            } else {
                startActivity(intent);
            }
            finish();
        } catch (URISyntaxException e) {
            Log.e(TAG, "Error decoding uri", e);
            finish();
        } catch (IllegalStateException e) {
        } catch (Exception e) {
            Log.w(TAG, "Couldn't launch Slice intent", e);
            startActivity(new Intent(Settings.ACTION_SETTINGS));
            finish();
        }
    }

    public static Intent parse(Uri uri, String pkg) throws URISyntaxException {
        Intent intent = Intent.parseUri(uri.getQueryParameter(INTENT),
                Intent.URI_ANDROID_APP_SCHEME);
        // Start with some really strict constraints and loosen them if we need to.
        // Don't allow components.
        intent.setComponent(null);
        // Clear out the extras.
        if (intent.getExtras() != null) {
            intent.getExtras().clear();
        }
        // Make sure this points at Settings.
        intent.setPackage(pkg);
        return intent;
    private static Uri parse(Uri uri) {
        return Uri.parse(uri.getQueryParameter(EXTRA_SLICE));
    }
}