1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.search;
18 
19 import static com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS;
20 import static com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT_TAB;
21 
22 import android.app.Activity;
23 import android.content.Intent;
24 import android.os.Bundle;
25 
26 import com.android.settings.SettingsActivity;
27 import com.android.settings.SubSettings;
28 import com.android.settings.overlay.FeatureFactory;
29 
30 /**
31  * A trampoline activity that launches setting result page.
32  */
33 public class SearchResultTrampoline extends Activity {
34 
35     @Override
onCreate(Bundle savedInstanceState)36     protected void onCreate(Bundle savedInstanceState) {
37         super.onCreate(savedInstanceState);
38 
39         // First make sure caller has privilege to launch a search result page.
40         FeatureFactory.getFactory(this)
41                 .getSearchFeatureProvider()
42                 .verifyLaunchSearchResultPageCaller(this, getCallingActivity());
43         // Didn't crash, proceed and launch the result as a subsetting.
44         final Intent intent = getIntent();
45 
46         // Hack to take EXTRA_FRAGMENT_ARG_KEY from intent and set into
47         // EXTRA_SHOW_FRAGMENT_ARGUMENTS. This is necessary because intent could be from external
48         // caller and args may not persisted.
49         final String settingKey = intent.getStringExtra(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY);
50         final int tab = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TAB, 0);
51         final Bundle args = new Bundle();
52         args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, settingKey);
53         args.putInt(EXTRA_SHOW_FRAGMENT_TAB, tab);
54         intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
55 
56         // Reroute request to SubSetting.
57         intent.setClass(this /* context */, SubSettings.class)
58                 .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
59         startActivity(intent);
60 
61         // Done.
62         finish();
63     }
64 
65 }
66