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.location.LocationSliceBuilder; 26 import com.android.settings.notification.ZenModeSliceBuilder; 27 import com.android.settings.overlay.FeatureFactory; 28 import com.android.settings.wifi.WifiSliceBuilder; 29 import com.android.settings.wifi.calling.WifiCallingSliceHelper; 30 31 import java.net.URISyntaxException; 32 33 public class SliceDeepLinkSpringBoard extends Activity { 34 35 private static final String TAG = "DeeplinkSpringboard"; 36 public static final String INTENT = "intent"; 37 public static final String SETTINGS = "settings"; 38 public static final String ACTION_VIEW_SLICE = "com.android.settings.action.VIEW_SLICE"; 39 public static final String EXTRA_SLICE = "slice"; 40 41 @Override onCreate(Bundle savedInstanceState)42 protected void onCreate(Bundle savedInstanceState) { 43 super.onCreate(savedInstanceState); 44 Uri uri = getIntent().getData(); 45 if (uri == null) { 46 Log.e(TAG, "No data found"); 47 finish(); 48 return; 49 } 50 try { 51 Intent intent = parse(uri, getPackageName()); 52 if (ACTION_VIEW_SLICE.equals(intent.getAction())) { 53 // This shouldn't matter since the slice is shown instead of the device 54 // index caring about the launch uri. 55 final Uri slice = Uri.parse(intent.getStringExtra(EXTRA_SLICE)); 56 final Intent launchIntent; 57 58 // TODO (b/80263568) Avoid duplicating this list of Slice Uris. 59 if (WifiSliceBuilder.WIFI_URI.equals(slice)) { 60 launchIntent = WifiSliceBuilder.getIntent(this /* context */); 61 } else if (ZenModeSliceBuilder.ZEN_MODE_URI.equals(slice)) { 62 launchIntent = ZenModeSliceBuilder.getIntent(this /* context */); 63 } else if (BluetoothSliceBuilder.BLUETOOTH_URI.equals(slice)) { 64 launchIntent = BluetoothSliceBuilder.getIntent(this /* context */); 65 } else if (LocationSliceBuilder.LOCATION_URI.equals(slice)) { 66 launchIntent = LocationSliceBuilder.getIntent(this /* context */); 67 } else { 68 final SlicesDatabaseAccessor slicesDatabaseAccessor = 69 new SlicesDatabaseAccessor(this /* context */); 70 // Sadly have to block here because we don't know where to go. 71 final SliceData sliceData = slicesDatabaseAccessor.getSliceDataFromUri(slice); 72 launchIntent = SliceBuilderUtils.getContentIntent(this, sliceData); 73 } 74 75 startActivity(launchIntent); 76 } else { 77 startActivity(intent); 78 } 79 finish(); 80 } catch (URISyntaxException e) { 81 Log.e(TAG, "Error decoding uri", e); 82 finish(); 83 } catch (IllegalStateException e) { 84 Log.w(TAG, "Couldn't launch Slice intent", e); 85 startActivity(new Intent(Settings.ACTION_SETTINGS)); 86 finish(); 87 } 88 } 89 parse(Uri uri, String pkg)90 public static Intent parse(Uri uri, String pkg) throws URISyntaxException { 91 Intent intent = Intent.parseUri(uri.getQueryParameter(INTENT), 92 Intent.URI_ANDROID_APP_SCHEME); 93 // Start with some really strict constraints and loosen them if we need to. 94 // Don't allow components. 95 intent.setComponent(null); 96 // Clear out the extras. 97 if (intent.getExtras() != null) { 98 intent.getExtras().clear(); 99 } 100 // Make sure this points at Settings. 101 intent.setPackage(pkg); 102 return intent; 103 } 104 } 105