1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15 package com.android.settings.slices; 16 17 import android.app.Activity; 18 import android.content.Intent; 19 import android.net.Uri; 20 import android.os.Bundle; 21 import android.provider.Settings; 22 import android.util.Log; 23 24 import com.android.settings.bluetooth.BluetoothSliceBuilder; 25 import com.android.settings.notification.ZenModeSliceBuilder; 26 27 public class SliceDeepLinkSpringBoard extends Activity { 28 29 private static final String TAG = "DeeplinkSpringboard"; 30 public static final String EXTRA_SLICE = "slice"; 31 32 @Override onCreate(Bundle savedInstanceState)33 protected void onCreate(Bundle savedInstanceState) { 34 super.onCreate(savedInstanceState); 35 final Uri sliceUri = parse(getIntent().getData()); 36 if (sliceUri == null) { 37 Log.e(TAG, "No data found"); 38 finish(); 39 return; 40 } 41 try { 42 // This shouldn't matter since the slice is shown instead of the device 43 // index caring about the launch uri. 44 Intent launchIntent; 45 46 // TODO (b/80263568) Avoid duplicating this list of Slice Uris. 47 if (CustomSliceRegistry.isValidUri(sliceUri)) { 48 final CustomSliceable sliceable = 49 CustomSliceable.createInstance(getApplicationContext(), 50 CustomSliceRegistry.getSliceClassByUri(sliceUri)); 51 launchIntent = sliceable.getIntent(); 52 } else if (CustomSliceRegistry.ZEN_MODE_SLICE_URI.equals(sliceUri)) { 53 launchIntent = ZenModeSliceBuilder.getIntent(this /* context */); 54 } else if (CustomSliceRegistry.BLUETOOTH_URI.equals(sliceUri)) { 55 launchIntent = BluetoothSliceBuilder.getIntent(this /* context */); 56 } else { 57 final SlicesDatabaseAccessor slicesDatabaseAccessor = 58 new SlicesDatabaseAccessor(this /* context */); 59 // Sadly have to block here because we don't know where to go. 60 final SliceData sliceData = 61 slicesDatabaseAccessor.getSliceDataFromUri(sliceUri); 62 launchIntent = SliceBuilderUtils.getContentIntent(this, sliceData); 63 } 64 startActivity(launchIntent); 65 finish(); 66 } catch (Exception e) { 67 Log.w(TAG, "Couldn't launch Slice intent", e); 68 startActivity(new Intent(Settings.ACTION_SETTINGS)); 69 finish(); 70 } 71 } 72 parse(Uri uri)73 private static Uri parse(Uri uri) { 74 return Uri.parse(uri.getQueryParameter(EXTRA_SLICE)); 75 } 76 } 77