blob: 852f286186000339fb249eeb5d43ead001700bd9 [file] [log] [blame]
Jason Monkf6edc7c2017-11-22 10:04:38 -05001/*
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
15package com.android.settings.slices;
16
17import android.app.Activity;
18import android.content.Intent;
19import android.net.Uri;
20import android.os.Bundle;
Matthew Fritzea5591032018-05-24 16:09:05 -070021import android.provider.Settings;
Yanting Yanga299fc52019-07-25 20:56:22 +080022import android.text.TextUtils;
Tsung-Mao Fang8c4aacd2020-02-11 17:16:20 +080023import android.util.EventLog;
Jason Monkf6edc7c2017-11-22 10:04:38 -050024import android.util.Log;
25
Matthew Fritzea5591032018-05-24 16:09:05 -070026import com.android.settings.bluetooth.BluetoothSliceBuilder;
Julia Reynoldsaceccce2019-11-26 16:14:03 -050027import com.android.settings.notification.zen.ZenModeSliceBuilder;
Matthew Fritzea5591032018-05-24 16:09:05 -070028
Jason Monkf6edc7c2017-11-22 10:04:38 -050029public class SliceDeepLinkSpringBoard extends Activity {
30
31 private static final String TAG = "DeeplinkSpringboard";
Jason Monkfcd5f0f2018-04-20 14:08:57 -040032 public static final String EXTRA_SLICE = "slice";
Jason Monkf6edc7c2017-11-22 10:04:38 -050033
34 @Override
35 protected void onCreate(Bundle savedInstanceState) {
36 super.onCreate(savedInstanceState);
Fan Zhangf837b892019-02-11 15:51:20 -080037 final Uri sliceUri = parse(getIntent().getData());
38 if (sliceUri == null) {
Jason Monkf6edc7c2017-11-22 10:04:38 -050039 Log.e(TAG, "No data found");
40 finish();
41 return;
42 }
43 try {
Fan Zhangf837b892019-02-11 15:51:20 -080044 // This shouldn't matter since the slice is shown instead of the device
45 // index caring about the launch uri.
46 Intent launchIntent;
Matthew Fritzea5591032018-05-24 16:09:05 -070047
Fan Zhangf837b892019-02-11 15:51:20 -080048 // TODO (b/80263568) Avoid duplicating this list of Slice Uris.
Fan Zhang2fe7e9f2019-03-12 15:46:12 -070049 if (CustomSliceRegistry.isValidUri(sliceUri)) {
Fan Zhangf837b892019-02-11 15:51:20 -080050 final CustomSliceable sliceable =
Fan Zhangad295002019-03-13 15:58:18 -070051 CustomSliceable.createInstance(getApplicationContext(),
52 CustomSliceRegistry.getSliceClassByUri(sliceUri));
Fan Zhangf837b892019-02-11 15:51:20 -080053 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 Monkfcd5f0f2018-04-20 14:08:57 -040058 } else {
Fan Zhangf837b892019-02-11 15:51:20 -080059 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 Monkfcd5f0f2018-04-20 14:08:57 -040065 }
Fan Zhangf837b892019-02-11 15:51:20 -080066 startActivity(launchIntent);
Jason Monkf6edc7c2017-11-22 10:04:38 -050067 finish();
Fan Zhangf837b892019-02-11 15:51:20 -080068 } catch (Exception e) {
Matthew Fritzea5591032018-05-24 16:09:05 -070069 Log.w(TAG, "Couldn't launch Slice intent", e);
70 startActivity(new Intent(Settings.ACTION_SETTINGS));
71 finish();
Jason Monkf6edc7c2017-11-22 10:04:38 -050072 }
73 }
74
Fan Zhangf837b892019-02-11 15:51:20 -080075 private static Uri parse(Uri uri) {
Yanting Yanga299fc52019-07-25 20:56:22 +080076 final String sliceParameter = uri.getQueryParameter(EXTRA_SLICE);
Tsung-Mao Fang8c4aacd2020-02-11 17:16:20 +080077 if (TextUtils.isEmpty(sliceParameter)) {
78 EventLog.writeEvent(0x534e4554, "122836081", -1, "");
79 return null;
80 } else {
81 return Uri.parse(sliceParameter);
82 }
Jason Monkf6edc7c2017-11-22 10:04:38 -050083 }
84}