Merge "Only allow Settings app launch search result page"
This commit is contained in:
@@ -94,7 +94,7 @@ public class AmbientDisplayAlwaysOnPreferenceController extends
|
||||
|
||||
@Override
|
||||
public ResultPayload getResultPayload() {
|
||||
final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
|
||||
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
|
||||
AmbientDisplaySettings.class.getName(), KEY_ALWAYS_ON,
|
||||
mContext.getString(R.string.ambient_display_screen_title));
|
||||
|
||||
|
@@ -13,6 +13,9 @@
|
||||
*/
|
||||
package com.android.settings.display;
|
||||
|
||||
import static android.provider.Settings.Secure.DOZE_ENABLED;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_AMBIENT_DISPLAY;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.UserHandle;
|
||||
@@ -30,9 +33,6 @@ import com.android.settings.search.InlineSwitchPayload;
|
||||
import com.android.settings.search.ResultPayload;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import static android.provider.Settings.Secure.DOZE_ENABLED;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_AMBIENT_DISPLAY;
|
||||
|
||||
public class AmbientDisplayNotificationsPreferenceController extends
|
||||
AbstractPreferenceController implements PreferenceControllerMixin,
|
||||
Preference.OnPreferenceChangeListener {
|
||||
@@ -86,7 +86,7 @@ public class AmbientDisplayNotificationsPreferenceController extends
|
||||
|
||||
@Override
|
||||
public ResultPayload getResultPayload() {
|
||||
final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
|
||||
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
|
||||
AmbientDisplaySettings.class.getName(), KEY_AMBIENT_DISPLAY_NOTIFICATIONS,
|
||||
mContext.getString(R.string.ambient_display_screen_title));
|
||||
|
||||
|
@@ -73,7 +73,7 @@ public class AutoBrightnessPreferenceController extends AbstractPreferenceContro
|
||||
|
||||
@Override
|
||||
public ResultPayload getResultPayload() {
|
||||
final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
|
||||
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
|
||||
DisplaySettings.class.getName(), mAutoBrightnessKey,
|
||||
mContext.getString(R.string.display_settings));
|
||||
|
||||
|
@@ -162,7 +162,7 @@ public class AssistGestureSettingsPreferenceController extends GesturePreference
|
||||
|
||||
@Override
|
||||
public ResultPayload getResultPayload() {
|
||||
final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
|
||||
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
|
||||
AssistGestureSettings.class.getName(), mAssistGesturePrefKey,
|
||||
mContext.getString(R.string.display_settings));
|
||||
|
||||
|
@@ -89,7 +89,7 @@ public class DoubleTapPowerPreferenceController extends GesturePreferenceControl
|
||||
|
||||
@Override
|
||||
public ResultPayload getResultPayload() {
|
||||
final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
|
||||
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
|
||||
DoubleTapPowerSettings.class.getName(), mDoubleTapPowerKey,
|
||||
mContext.getString(R.string.display_settings));
|
||||
|
||||
|
@@ -89,7 +89,7 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro
|
||||
|
||||
@Override
|
||||
public ResultPayload getResultPayload() {
|
||||
final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
|
||||
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
|
||||
DoubleTapScreenSettings.class.getName(), mDoubleTapScreenPrefKey,
|
||||
mContext.getString(R.string.display_settings));
|
||||
|
||||
|
@@ -95,7 +95,7 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
|
||||
|
||||
@Override
|
||||
public ResultPayload getResultPayload() {
|
||||
final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
|
||||
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
|
||||
PickupGestureSettings.class.getName(), mPickUpPrefKey,
|
||||
mContext.getString(R.string.display_settings));
|
||||
|
||||
|
@@ -127,7 +127,7 @@ public class LocationPreferenceController extends AbstractPreferenceController
|
||||
|
||||
@Override
|
||||
public ResultPayload getResultPayload() {
|
||||
final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
|
||||
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
|
||||
LocationSettings.class.getName(), KEY_LOCATION,
|
||||
mContext.getString(R.string.location_settings_title));
|
||||
|
||||
|
@@ -133,7 +133,7 @@ public class BadgingNotificationPreferenceController extends AbstractPreferenceC
|
||||
|
||||
@Override
|
||||
public ResultPayload getResultPayload() {
|
||||
final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(mContext,
|
||||
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
|
||||
ConfigureNotificationSettings.class.getName(), KEY_NOTIFICATION_BADGING,
|
||||
mContext.getString(R.string.configure_notification_settings));
|
||||
|
||||
|
@@ -102,7 +102,7 @@ public class AccessibilityServiceResultLoader extends AsyncLoader<Set<? extends
|
||||
}
|
||||
final String componentName = new ComponentName(serviceInfo.packageName,
|
||||
serviceInfo.name).flattenToString();
|
||||
final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(context,
|
||||
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(context,
|
||||
AccessibilitySettings.class.getName(), componentName, screenTitle);
|
||||
|
||||
results.add(new SearchResult.Builder()
|
||||
|
@@ -46,21 +46,28 @@ public class DatabaseIndexingUtils {
|
||||
"SEARCH_INDEX_DATA_PROVIDER";
|
||||
|
||||
/**
|
||||
* Builds intent into a subsetting.
|
||||
* Builds intent that launches the search destination as a sub-setting.
|
||||
*/
|
||||
public static Intent buildSubsettingIntent(Context context, String className, String key,
|
||||
public static Intent buildSearchResultPageIntent(Context context, String className, String key,
|
||||
String screenTitle) {
|
||||
return buildSearchResultPageIntent(context, className, key, screenTitle,
|
||||
MetricsProto.MetricsEvent.DASHBOARD_SEARCH_RESULTS);
|
||||
}
|
||||
|
||||
public static Intent buildSearchResultPageIntent(Context context, String className, String key,
|
||||
String screenTitle, int sourceMetricsCategory) {
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key);
|
||||
return Utils.onBuildStartFragmentIntent(context,
|
||||
className, args, null, 0, screenTitle, false,
|
||||
MetricsProto.MetricsEvent.DASHBOARD_SEARCH_RESULTS);
|
||||
final Intent searchDestination = Utils.onBuildStartFragmentIntent(context,
|
||||
className, args, null, 0, screenTitle, false, sourceMetricsCategory);
|
||||
searchDestination.putExtra(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key);
|
||||
searchDestination.setClass(context, SearchResultTrampoline.class);
|
||||
return searchDestination;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param className which wil provide the map between from {@link Uri}s to
|
||||
* {@link PreferenceControllerMixin}
|
||||
* @param context
|
||||
* {@link PreferenceControllerMixin}
|
||||
* @return A map between {@link Uri}s and {@link PreferenceControllerMixin}s to get the payload
|
||||
* types for Settings.
|
||||
*/
|
||||
@@ -85,7 +92,7 @@ public class DatabaseIndexingUtils {
|
||||
List<AbstractPreferenceController> controllers =
|
||||
provider.getPreferenceControllers(context);
|
||||
|
||||
if (controllers == null ) {
|
||||
if (controllers == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -106,7 +113,7 @@ public class DatabaseIndexingUtils {
|
||||
/**
|
||||
* @param uriMap Map between the {@link PreferenceControllerMixin} keys
|
||||
* and the controllers themselves.
|
||||
* @param key The look-up key
|
||||
* @param key The look-up key
|
||||
* @return The Payload from the {@link PreferenceControllerMixin} specified by the key,
|
||||
* if it exists. Otherwise null.
|
||||
*/
|
||||
|
@@ -107,7 +107,7 @@ public class InputDeviceResultLoader extends AsyncLoader<Set<? extends SearchRes
|
||||
: context.getString(R.string.keyboard_layout_default_label);
|
||||
final String key = deviceName;
|
||||
|
||||
final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(context,
|
||||
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(context,
|
||||
PHYSICAL_KEYBOARD_FRAGMENT, key, screenTitle);
|
||||
results.add(new SearchResult.Builder()
|
||||
.setTitle(deviceName)
|
||||
@@ -140,7 +140,7 @@ public class InputDeviceResultLoader extends AsyncLoader<Set<? extends SearchRes
|
||||
final ServiceInfo serviceInfo = info.getServiceInfo();
|
||||
final String key = new ComponentName(serviceInfo.packageName, serviceInfo.name)
|
||||
.flattenToString();
|
||||
final Intent intent = DatabaseIndexingUtils.buildSubsettingIntent(context,
|
||||
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(context,
|
||||
VIRTUAL_KEYBOARD_FRAGMENT, key, screenTitle);
|
||||
results.add(new SearchResult.Builder()
|
||||
.setTitle(title)
|
||||
|
@@ -20,6 +20,7 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
@@ -34,6 +35,8 @@ import java.util.List;
|
||||
public class IntentSearchViewHolder extends SearchViewHolder {
|
||||
|
||||
private static final String TAG = "IntentSearchViewHolder";
|
||||
@VisibleForTesting
|
||||
static final int REQUEST_CODE_NO_OP = 0;
|
||||
|
||||
public IntentSearchViewHolder(View view) {
|
||||
super(view);
|
||||
@@ -60,7 +63,7 @@ public class IntentSearchViewHolder extends SearchViewHolder {
|
||||
final PackageManager pm = fragment.getActivity().getPackageManager();
|
||||
final List<ResolveInfo> info = pm.queryIntentActivities(intent, 0 /* flags */);
|
||||
if (info != null && !info.isEmpty()) {
|
||||
fragment.startActivity(intent);
|
||||
fragment.startActivityForResult(intent, REQUEST_CODE_NO_OP);
|
||||
} else {
|
||||
Log.e(TAG, "Cannot launch search result, title: "
|
||||
+ result.title + ", " + intent);
|
||||
|
@@ -16,6 +16,8 @@
|
||||
*/
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
@@ -32,6 +34,15 @@ public interface SearchFeatureProvider {
|
||||
*/
|
||||
boolean isEnabled(Context context);
|
||||
|
||||
/**
|
||||
* Ensures the caller has necessary privilege to launch search result page.
|
||||
*
|
||||
* @throws IllegalArgumentException when caller is null
|
||||
* @throws SecurityException when caller is not allowed to launch search result page
|
||||
*/
|
||||
void verifyLaunchSearchResultPageCaller(Context context, @NonNull ComponentName caller)
|
||||
throws SecurityException, IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Returns a new loader to search in index database.
|
||||
*/
|
||||
|
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@@ -42,6 +43,18 @@ public class SearchFeatureProviderImpl implements SearchFeatureProvider {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void verifyLaunchSearchResultPageCaller(Context context, ComponentName caller) {
|
||||
if (caller == null) {
|
||||
throw new IllegalArgumentException("ExternalSettingsTrampoline intents "
|
||||
+ "must be called with startActivityForResult");
|
||||
}
|
||||
final String packageName = caller.getPackageName();
|
||||
if (!TextUtils.equals(packageName, context.getPackageName())) {
|
||||
throw new SecurityException("Only Settings app can launch search result page");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseResultLoader getDatabaseSearchLoader(Context context, String query) {
|
||||
return new DatabaseResultLoader(context, cleanQuery(query), getSiteMapManager());
|
||||
|
62
src/com/android/settings/search/SearchResultTrampoline.java
Normal file
62
src/com/android/settings/search/SearchResultTrampoline.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.search;
|
||||
|
||||
import static com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SubSettings;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
/**
|
||||
* A trampoline activity that launches setting result page.
|
||||
*/
|
||||
public class SearchResultTrampoline extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// First make sure caller has privilege to launch a search result page.
|
||||
FeatureFactory.getFactory(this)
|
||||
.getSearchFeatureProvider()
|
||||
.verifyLaunchSearchResultPageCaller(this, getCallingActivity());
|
||||
// Didn't crash, proceed and launch the result as a subsetting.
|
||||
final Intent intent = getIntent();
|
||||
|
||||
// Hack to take EXTRA_FRAGMENT_ARG_KEY from intent and set into
|
||||
// EXTRA_SHOW_FRAGMENT_ARGUMENTS. This is necessary because intent could be from external
|
||||
// caller and args may not persisted.
|
||||
final String settingKey = intent.getStringExtra(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY);
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, settingKey);
|
||||
intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
|
||||
|
||||
// Reroute request to SubSetting.
|
||||
intent.setClass(this /* context */, SubSettings.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
|
||||
startActivity(intent);
|
||||
|
||||
// Done.
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
@@ -273,7 +273,7 @@ public class IndexData {
|
||||
|| TextUtils.equals(mIntentTargetPackage,
|
||||
SearchIndexableResources.SUBSETTING_TARGET_PACKAGE)) {
|
||||
// Action is null, we will launch it as a sub-setting
|
||||
intent = DatabaseIndexingUtils.buildSubsettingIntent(context, mClassName, mKey,
|
||||
intent = DatabaseIndexingUtils.buildSearchResultPageIntent(context, mClassName, mKey,
|
||||
mScreenTitle);
|
||||
} else {
|
||||
intent = new Intent(mIntentAction);
|
||||
|
Reference in New Issue
Block a user