Handle simplified Slice deep link intent pattern.

Old intent:
settings://com.android.settings.slices?intent=android-app%3A%2F%2Fcom.android.settings%23Intent%3Baction%3Dcom.android.settings.action.VIEW_SLICE%3BS.slice%3Dcontent%253A%252F%252Fcom.android.settings.slices%252Faction%252Fscreen_magnification_navbar_preference_screen%3B

New intent:
settings://com.android.settings.slices?slice%3Dcontent%253A%252F%252Fcom.android.settings.slices%252Faction%252Fscreen_magnification_navbar_preference_screen%3B

Change-Id: Ia786812c68b5a2b1858203f62494c0d5f5a4a5ba
Fixes: 110156445
Test: manual
This commit is contained in:
Fan Zhang
2019-02-11 15:51:20 -08:00
parent 671a39f905
commit f837b899fb

View File

@@ -25,80 +25,54 @@ 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;
// This shouldn't matter since the slice is shown instead of the device
// index caring about the launch uri.
Intent launchIntent;
// TODO (b/80263568) Avoid duplicating this list of Slice Uris.
final CustomSliceManager customSliceManager = FeatureFactory.getFactory(this)
.getSlicesFeatureProvider().getCustomSliceManager(this);
if (customSliceManager.isValidUri(sliceUri)) {
final CustomSliceable sliceable =
customSliceManager.getSliceableFromUri(sliceUri);
launchIntent = sliceable.getIntent();
} else if (CustomSliceRegistry.ZEN_MODE_SLICE_URI.equals(sliceUri)) {
launchIntent = ZenModeSliceBuilder.getIntent(this /* context */);
} else if (CustomSliceRegistry.BLUETOOTH_URI.equals(sliceUri)) {
launchIntent = BluetoothSliceBuilder.getIntent(this /* context */);
} else {
final SlicesDatabaseAccessor slicesDatabaseAccessor =
new SlicesDatabaseAccessor(this /* context */);
// Sadly have to block here because we don't know where to go.
final SliceData sliceData =
slicesDatabaseAccessor.getSliceDataFromUri(sliceUri);
launchIntent = SliceBuilderUtils.getContentIntent(this, sliceData);
}
startActivity(launchIntent);
// TODO (b/80263568) Avoid duplicating this list of Slice Uris.
final CustomSliceManager customSliceManager = FeatureFactory.getFactory(this)
.getSlicesFeatureProvider().getCustomSliceManager(this);
if (customSliceManager.isValidUri(sliceUri)) {
final CustomSliceable sliceable =
customSliceManager.getSliceableFromUri(sliceUri);
launchIntent = sliceable.getIntent();
} else if (CustomSliceRegistry.ZEN_MODE_SLICE_URI.equals(sliceUri)) {
launchIntent = ZenModeSliceBuilder.getIntent(this /* context */);
} else if (CustomSliceRegistry.BLUETOOTH_URI.equals(sliceUri)) {
launchIntent = BluetoothSliceBuilder.getIntent(this /* context */);
} else {
startActivity(intent);
final SlicesDatabaseAccessor slicesDatabaseAccessor =
new SlicesDatabaseAccessor(this /* context */);
// Sadly have to block here because we don't know where to go.
final SliceData sliceData =
slicesDatabaseAccessor.getSliceDataFromUri(sliceUri);
launchIntent = SliceBuilderUtils.getContentIntent(this, sliceData);
}
startActivity(launchIntent);
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));
}
}