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:
@@ -25,31 +25,23 @@ import com.android.settings.bluetooth.BluetoothSliceBuilder;
|
|||||||
import com.android.settings.notification.ZenModeSliceBuilder;
|
import com.android.settings.notification.ZenModeSliceBuilder;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
|
|
||||||
public class SliceDeepLinkSpringBoard extends Activity {
|
public class SliceDeepLinkSpringBoard extends Activity {
|
||||||
|
|
||||||
private static final String TAG = "DeeplinkSpringboard";
|
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";
|
public static final String EXTRA_SLICE = "slice";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
Uri uri = getIntent().getData();
|
final Uri sliceUri = parse(getIntent().getData());
|
||||||
if (uri == null) {
|
if (sliceUri == null) {
|
||||||
Log.e(TAG, "No data found");
|
Log.e(TAG, "No data found");
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
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
|
// This shouldn't matter since the slice is shown instead of the device
|
||||||
// index caring about the launch uri.
|
// index caring about the launch uri.
|
||||||
final Uri sliceUri = Uri.parse(intent.getStringExtra(EXTRA_SLICE));
|
|
||||||
Intent launchIntent;
|
Intent launchIntent;
|
||||||
|
|
||||||
// TODO (b/80263568) Avoid duplicating this list of Slice Uris.
|
// TODO (b/80263568) Avoid duplicating this list of Slice Uris.
|
||||||
@@ -71,34 +63,16 @@ public class SliceDeepLinkSpringBoard extends Activity {
|
|||||||
slicesDatabaseAccessor.getSliceDataFromUri(sliceUri);
|
slicesDatabaseAccessor.getSliceDataFromUri(sliceUri);
|
||||||
launchIntent = SliceBuilderUtils.getContentIntent(this, sliceData);
|
launchIntent = SliceBuilderUtils.getContentIntent(this, sliceData);
|
||||||
}
|
}
|
||||||
|
|
||||||
startActivity(launchIntent);
|
startActivity(launchIntent);
|
||||||
} else {
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
finish();
|
finish();
|
||||||
} catch (URISyntaxException e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "Error decoding uri", e);
|
|
||||||
finish();
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
Log.w(TAG, "Couldn't launch Slice intent", e);
|
Log.w(TAG, "Couldn't launch Slice intent", e);
|
||||||
startActivity(new Intent(Settings.ACTION_SETTINGS));
|
startActivity(new Intent(Settings.ACTION_SETTINGS));
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Intent parse(Uri uri, String pkg) throws URISyntaxException {
|
private static Uri parse(Uri uri) {
|
||||||
Intent intent = Intent.parseUri(uri.getQueryParameter(INTENT),
|
return Uri.parse(uri.getQueryParameter(EXTRA_SLICE));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user