Make UsageAccess WarningDialog actually instatiatable.
The DialogFragment used for WarningDialog was not instatiatable by the fragment manager. Bug:17435234 Change-Id: I5f65dd1e0ec0b95d048934480bd5fafd8648ab7c
This commit is contained in:
@@ -24,6 +24,8 @@ import android.app.AlertDialog;
|
|||||||
import android.app.AppOpsManager;
|
import android.app.AppOpsManager;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.DialogFragment;
|
import android.app.DialogFragment;
|
||||||
|
import android.app.Fragment;
|
||||||
|
import android.app.FragmentTransaction;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.pm.IPackageManager;
|
import android.content.pm.IPackageManager;
|
||||||
@@ -316,9 +318,12 @@ public class UsageAccessSettings extends SettingsPreferenceFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Turning on the setting has a Warning.
|
// Turning on the setting has a Warning.
|
||||||
getFragmentManager().beginTransaction()
|
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
|
||||||
.add(new WarningDialog(pe), "warning")
|
Fragment prev = getChildFragmentManager().findFragmentByTag("warning");
|
||||||
.commit();
|
if (prev != null) {
|
||||||
|
ft.remove(prev);
|
||||||
|
}
|
||||||
|
WarningDialogFragment.newInstance(pe.packageName).show(ft, "warning");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -330,6 +335,17 @@ public class UsageAccessSettings extends SettingsPreferenceFragment implements
|
|||||||
pe.appOpMode = newMode;
|
pe.appOpMode = newMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void allowAccess(String packageName) {
|
||||||
|
final PackageEntry entry = mPackageEntryMap.get(packageName);
|
||||||
|
if (entry == null) {
|
||||||
|
Log.w(TAG, "Unable to give access to package " + packageName + ": it does not exist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setNewMode(entry, AppOpsManager.MODE_ALLOWED);
|
||||||
|
entry.preference.setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
private final PackageMonitor mPackageMonitor = new PackageMonitor() {
|
private final PackageMonitor mPackageMonitor = new PackageMonitor() {
|
||||||
@Override
|
@Override
|
||||||
public void onPackageAdded(String packageName, int uid) {
|
public void onPackageAdded(String packageName, int uid) {
|
||||||
@@ -342,12 +358,16 @@ public class UsageAccessSettings extends SettingsPreferenceFragment implements
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private class WarningDialog extends DialogFragment
|
public static class WarningDialogFragment extends DialogFragment
|
||||||
implements DialogInterface.OnClickListener {
|
implements DialogInterface.OnClickListener {
|
||||||
private final PackageEntry mEntry;
|
private static final String ARG_PACKAGE_NAME = "package";
|
||||||
|
|
||||||
public WarningDialog(PackageEntry pe) {
|
public static WarningDialogFragment newInstance(String packageName) {
|
||||||
mEntry = pe;
|
WarningDialogFragment dialog = new WarningDialogFragment();
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putString(ARG_PACKAGE_NAME, packageName);
|
||||||
|
dialog.setArguments(args);
|
||||||
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -364,8 +384,8 @@ public class UsageAccessSettings extends SettingsPreferenceFragment implements
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||||
setNewMode(mEntry, AppOpsManager.MODE_ALLOWED);
|
((UsageAccessSettings) getParentFragment()).allowAccess(
|
||||||
mEntry.preference.setChecked(true);
|
getArguments().getString(ARG_PACKAGE_NAME));
|
||||||
} else {
|
} else {
|
||||||
dialog.cancel();
|
dialog.cancel();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user