Home | History | Annotate | Download | only in search
      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 
     21 import android.app.Activity;
     22 import android.content.Intent;
     23 import android.os.Bundle;
     24 
     25 import com.android.settings.SettingsActivity;
     26 import com.android.settings.SubSettings;
     27 import com.android.settings.overlay.FeatureFactory;
     28 
     29 /**
     30  * A trampoline activity that launches setting result page.
     31  */
     32 public class SearchResultTrampoline extends Activity {
     33 
     34     @Override
     35     protected void onCreate(Bundle savedInstanceState) {
     36         super.onCreate(savedInstanceState);
     37 
     38         // First make sure caller has privilege to launch a search result page.
     39         FeatureFactory.getFactory(this)
     40                 .getSearchFeatureProvider()
     41                 .verifyLaunchSearchResultPageCaller(this, getCallingActivity());
     42         // Didn't crash, proceed and launch the result as a subsetting.
     43         final Intent intent = getIntent();
     44 
     45         // Hack to take EXTRA_FRAGMENT_ARG_KEY from intent and set into
     46         // EXTRA_SHOW_FRAGMENT_ARGUMENTS. This is necessary because intent could be from external
     47         // caller and args may not persisted.
     48         final String settingKey = intent.getStringExtra(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY);
     49         final Bundle args = new Bundle();
     50         args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, settingKey);
     51         intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
     52 
     53         // Reroute request to SubSetting.
     54         intent.setClass(this /* context */, SubSettings.class)
     55                 .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
     56         startActivity(intent);
     57 
     58         // Done.
     59         finish();
     60     }
     61 
     62 }
     63