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