Make notification listeners screen not crash

Change-Id: I2ac94fdcaeb3c5acaab8b4ac6e6ebae1b9a7b529
This commit is contained in:
Jason Monk
2016-08-11 10:13:13 -04:00
parent 28e7bc9235
commit efe4c4e4e0

View File

@@ -20,6 +20,7 @@ import android.annotation.Nullable;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.Fragment;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
@@ -33,6 +34,7 @@ import android.support.v7.preference.Preference.OnPreferenceChangeListener;
import android.support.v7.preference.PreferenceScreen;
import android.view.View;
import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.notification.EmptyTextSettings;
@@ -122,21 +124,23 @@ public abstract class ManagedServiceSettings extends EmptyTextSettings {
}
// show a scary dialog
new ScaryWarningDialogFragment()
.setServiceInfo(service, title)
.setServiceInfo(service, title, this)
.show(getFragmentManager(), "dialog");
return false;
}
}
public class ScaryWarningDialogFragment extends DialogFragment {
public static class ScaryWarningDialogFragment extends DialogFragment {
static final String KEY_COMPONENT = "c";
static final String KEY_LABEL = "l";
public ScaryWarningDialogFragment setServiceInfo(ComponentName cn, String label) {
public ScaryWarningDialogFragment setServiceInfo(ComponentName cn, String label,
Fragment target) {
Bundle args = new Bundle();
args.putString(KEY_COMPONENT, cn.flattenToString());
args.putString(KEY_LABEL, label);
setArguments(args);
setTargetFragment(target, 0);
return this;
}
@@ -147,17 +151,19 @@ public abstract class ManagedServiceSettings extends EmptyTextSettings {
final String label = args.getString(KEY_LABEL);
final ComponentName cn = ComponentName.unflattenFromString(args
.getString(KEY_COMPONENT));
ManagedServiceSettings parent = (ManagedServiceSettings) getTargetFragment();
final String title = getResources().getString(mConfig.warningDialogTitle, label);
final String summary = getResources().getString(mConfig.warningDialogSummary, label);
return new AlertDialog.Builder(mContext)
final String title = getResources().getString(parent.mConfig.warningDialogTitle, label);
final String summary = getResources().getString(parent.mConfig.warningDialogSummary,
label);
return new AlertDialog.Builder(getContext())
.setMessage(summary)
.setTitle(title)
.setCancelable(true)
.setPositiveButton(R.string.allow,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mServiceListing.setEnabled(cn, true);
parent.mServiceListing.setEnabled(cn, true);
}
})
.setNegativeButton(R.string.deny,