Start all help intents as startActivityForResult

So that the receiver may verify identity if they so desire...

Bug: 21849741
Change-Id: I2e2c3f674a8be88f22e051e2affb54df2f1c3eed
This commit is contained in:
Jason Monk
2015-06-16 10:31:38 -04:00
parent 744f2adb56
commit 6e61347242
3 changed files with 17 additions and 9 deletions

View File

@@ -588,7 +588,7 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable
final MenuItem help = menu.findItem(R.id.data_usage_menu_help); final MenuItem help = menu.findItem(R.id.data_usage_menu_help);
String helpUrl; String helpUrl;
if (!TextUtils.isEmpty(helpUrl = getResources().getString(R.string.help_url_data_usage))) { if (!TextUtils.isEmpty(helpUrl = getResources().getString(R.string.help_url_data_usage))) {
HelpUtils.prepareHelpMenuItem(context, help, helpUrl, getClass().getName()); HelpUtils.prepareHelpMenuItem(getActivity(), help, helpUrl, getClass().getName());
} else { } else {
help.setVisible(false); help.setVisible(false);
} }

View File

@@ -16,6 +16,7 @@
package com.android.settings; package com.android.settings;
import android.app.Activity;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@@ -28,6 +29,7 @@ import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Locale; import java.util.Locale;
@@ -65,16 +67,16 @@ public class HelpUtils {
/** Static helper that is not instantiable*/ /** Static helper that is not instantiable*/
private HelpUtils() { } private HelpUtils() { }
public static boolean prepareHelpMenuItem(Context context, Menu menu, String helpUri, public static boolean prepareHelpMenuItem(Activity activity, Menu menu, String helpUri,
String backupContext) { String backupContext) {
MenuItem helpItem = menu.add(0, MENU_HELP, 0, R.string.help_label); MenuItem helpItem = menu.add(0, MENU_HELP, 0, R.string.help_label);
return prepareHelpMenuItem(context, helpItem, helpUri, backupContext); return prepareHelpMenuItem(activity, helpItem, helpUri, backupContext);
} }
public static boolean prepareHelpMenuItem(Context context, Menu menu, int helpUriResource, public static boolean prepareHelpMenuItem(Activity activity, Menu menu, int helpUriResource,
String backupContext) { String backupContext) {
MenuItem helpItem = menu.add(0, MENU_HELP, 0, R.string.help_label); MenuItem helpItem = menu.add(0, MENU_HELP, 0, R.string.help_label);
return prepareHelpMenuItem(context, helpItem, context.getString(helpUriResource), return prepareHelpMenuItem(activity, helpItem, activity.getString(helpUriResource),
backupContext); backupContext);
} }
@@ -86,7 +88,7 @@ public class HelpUtils {
* *
* @return returns whether the help menu item has been made visible. * @return returns whether the help menu item has been made visible.
*/ */
public static boolean prepareHelpMenuItem(Context context, MenuItem helpMenuItem, public static boolean prepareHelpMenuItem(final Activity activity, MenuItem helpMenuItem,
String helpUriString, String backupContext) { String helpUriString, String backupContext) {
if (TextUtils.isEmpty(helpUriString)) { if (TextUtils.isEmpty(helpUriString)) {
// The help url string is empty or null, so set the help menu item to be invisible. // The help url string is empty or null, so set the help menu item to be invisible.
@@ -95,12 +97,18 @@ public class HelpUtils {
// return that the help menu item is not visible (i.e. false) // return that the help menu item is not visible (i.e. false)
return false; return false;
} else { } else {
Intent intent = getHelpIntent(context, helpUriString, backupContext); final Intent intent = getHelpIntent(activity, helpUriString, backupContext);
// Set the intent to the help menu item, show the help menu item in the overflow // Set the intent to the help menu item, show the help menu item in the overflow
// menu, and make it visible. // menu, and make it visible.
if (intent != null) { if (intent != null) {
helpMenuItem.setIntent(intent); helpMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
activity.startActivityForResult(intent, 0);
return true;
}
});
helpMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); helpMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
helpMenuItem.setVisible(true); helpMenuItem.setVisible(true);
} else { } else {

View File

@@ -576,7 +576,7 @@ public class FingerprintSettings extends SubSettings {
Context ctx = widget.getContext(); Context ctx = widget.getContext();
Intent intent = HelpUtils.getHelpIntent(ctx, getURL(), ctx.getClass().getName()); Intent intent = HelpUtils.getHelpIntent(ctx, getURL(), ctx.getClass().getName());
try { try {
ctx.startActivity(intent); ((Activity) ctx).startActivityForResult(intent, 0);
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
Log.w(FingerprintSettingsFragment.TAG, Log.w(FingerprintSettingsFragment.TAG,
"Actvity was not found for intent, " + intent.toString()); "Actvity was not found for intent, " + intent.toString());