Jason Monk | f6edc7c | 2017-11-22 10:04:38 -0500 | [diff] [blame] | 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; |
Matthew Fritze | a559103 | 2018-05-24 16:09:05 -0700 | [diff] [blame] | 21 | import android.provider.Settings; |
Yanting Yang | a299fc5 | 2019-07-25 20:56:22 +0800 | [diff] [blame] | 22 | import android.text.TextUtils; |
Tsung-Mao Fang | 8c4aacd | 2020-02-11 17:16:20 +0800 | [diff] [blame] | 23 | import android.util.EventLog; |
Jason Monk | f6edc7c | 2017-11-22 10:04:38 -0500 | [diff] [blame] | 24 | import android.util.Log; |
| 25 | |
Matthew Fritze | a559103 | 2018-05-24 16:09:05 -0700 | [diff] [blame] | 26 | import com.android.settings.bluetooth.BluetoothSliceBuilder; |
Julia Reynolds | aceccce | 2019-11-26 16:14:03 -0500 | [diff] [blame] | 27 | import com.android.settings.notification.zen.ZenModeSliceBuilder; |
Matthew Fritze | a559103 | 2018-05-24 16:09:05 -0700 | [diff] [blame] | 28 | |
Jason Monk | f6edc7c | 2017-11-22 10:04:38 -0500 | [diff] [blame] | 29 | public class SliceDeepLinkSpringBoard extends Activity { |
| 30 | |
| 31 | private static final String TAG = "DeeplinkSpringboard"; |
Jason Monk | fcd5f0f | 2018-04-20 14:08:57 -0400 | [diff] [blame] | 32 | public static final String EXTRA_SLICE = "slice"; |
Jason Monk | f6edc7c | 2017-11-22 10:04:38 -0500 | [diff] [blame] | 33 | |
| 34 | @Override |
| 35 | protected void onCreate(Bundle savedInstanceState) { |
| 36 | super.onCreate(savedInstanceState); |
Fan Zhang | f837b89 | 2019-02-11 15:51:20 -0800 | [diff] [blame] | 37 | final Uri sliceUri = parse(getIntent().getData()); |
| 38 | if (sliceUri == null) { |
Jason Monk | f6edc7c | 2017-11-22 10:04:38 -0500 | [diff] [blame] | 39 | Log.e(TAG, "No data found"); |
| 40 | finish(); |
| 41 | return; |
| 42 | } |
| 43 | try { |
Fan Zhang | f837b89 | 2019-02-11 15:51:20 -0800 | [diff] [blame] | 44 | // This shouldn't matter since the slice is shown instead of the device |
| 45 | // index caring about the launch uri. |
| 46 | Intent launchIntent; |
Matthew Fritze | a559103 | 2018-05-24 16:09:05 -0700 | [diff] [blame] | 47 | |
Fan Zhang | f837b89 | 2019-02-11 15:51:20 -0800 | [diff] [blame] | 48 | // TODO (b/80263568) Avoid duplicating this list of Slice Uris. |
Fan Zhang | 2fe7e9f | 2019-03-12 15:46:12 -0700 | [diff] [blame] | 49 | if (CustomSliceRegistry.isValidUri(sliceUri)) { |
Fan Zhang | f837b89 | 2019-02-11 15:51:20 -0800 | [diff] [blame] | 50 | final CustomSliceable sliceable = |
Fan Zhang | ad29500 | 2019-03-13 15:58:18 -0700 | [diff] [blame] | 51 | CustomSliceable.createInstance(getApplicationContext(), |
| 52 | CustomSliceRegistry.getSliceClassByUri(sliceUri)); |
Fan Zhang | f837b89 | 2019-02-11 15:51:20 -0800 | [diff] [blame] | 53 | launchIntent = sliceable.getIntent(); |
| 54 | } else if (CustomSliceRegistry.ZEN_MODE_SLICE_URI.equals(sliceUri)) { |
| 55 | launchIntent = ZenModeSliceBuilder.getIntent(this /* context */); |
| 56 | } else if (CustomSliceRegistry.BLUETOOTH_URI.equals(sliceUri)) { |
| 57 | launchIntent = BluetoothSliceBuilder.getIntent(this /* context */); |
Jason Monk | fcd5f0f | 2018-04-20 14:08:57 -0400 | [diff] [blame] | 58 | } else { |
Fan Zhang | f837b89 | 2019-02-11 15:51:20 -0800 | [diff] [blame] | 59 | final SlicesDatabaseAccessor slicesDatabaseAccessor = |
| 60 | new SlicesDatabaseAccessor(this /* context */); |
| 61 | // Sadly have to block here because we don't know where to go. |
| 62 | final SliceData sliceData = |
| 63 | slicesDatabaseAccessor.getSliceDataFromUri(sliceUri); |
| 64 | launchIntent = SliceBuilderUtils.getContentIntent(this, sliceData); |
Jason Monk | fcd5f0f | 2018-04-20 14:08:57 -0400 | [diff] [blame] | 65 | } |
Fan Zhang | f837b89 | 2019-02-11 15:51:20 -0800 | [diff] [blame] | 66 | startActivity(launchIntent); |
Jason Monk | f6edc7c | 2017-11-22 10:04:38 -0500 | [diff] [blame] | 67 | finish(); |
Fan Zhang | f837b89 | 2019-02-11 15:51:20 -0800 | [diff] [blame] | 68 | } catch (Exception e) { |
Matthew Fritze | a559103 | 2018-05-24 16:09:05 -0700 | [diff] [blame] | 69 | Log.w(TAG, "Couldn't launch Slice intent", e); |
| 70 | startActivity(new Intent(Settings.ACTION_SETTINGS)); |
| 71 | finish(); |
Jason Monk | f6edc7c | 2017-11-22 10:04:38 -0500 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
Fan Zhang | f837b89 | 2019-02-11 15:51:20 -0800 | [diff] [blame] | 75 | private static Uri parse(Uri uri) { |
Yanting Yang | a299fc5 | 2019-07-25 20:56:22 +0800 | [diff] [blame] | 76 | final String sliceParameter = uri.getQueryParameter(EXTRA_SLICE); |
Tsung-Mao Fang | 8c4aacd | 2020-02-11 17:16:20 +0800 | [diff] [blame] | 77 | if (TextUtils.isEmpty(sliceParameter)) { |
| 78 | EventLog.writeEvent(0x534e4554, "122836081", -1, ""); |
| 79 | return null; |
| 80 | } else { |
| 81 | return Uri.parse(sliceParameter); |
| 82 | } |
Jason Monk | f6edc7c | 2017-11-22 10:04:38 -0500 | [diff] [blame] | 83 | } |
| 84 | } |