Merge "Stop depending on empty Settings"

This commit is contained in:
Julia Reynolds
2020-12-07 18:31:26 +00:00
committed by Android (Google) Code Review
5 changed files with 21 additions and 12 deletions

View File

@@ -22,6 +22,7 @@ import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
@@ -39,10 +40,12 @@ public class FriendlyWarningDialogFragment extends InstrumentedDialogFragment {
return SettingsEnums.DIALOG_ZEN_ACCESS_REVOKE; return SettingsEnums.DIALOG_ZEN_ACCESS_REVOKE;
} }
public FriendlyWarningDialogFragment setPkgInfo(String pkg, CharSequence label) { public FriendlyWarningDialogFragment setPkgInfo(String pkg, CharSequence label,
Fragment target) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(KEY_PKG, pkg); args.putString(KEY_PKG, pkg);
args.putString(KEY_LABEL, TextUtils.isEmpty(label) ? pkg : label.toString()); args.putString(KEY_LABEL, TextUtils.isEmpty(label) ? pkg : label.toString());
setTargetFragment(target, 0);
setArguments(args); setArguments(args);
return this; return this;
} }
@@ -58,6 +61,8 @@ public class FriendlyWarningDialogFragment extends InstrumentedDialogFragment {
R.string.zen_access_revoke_warning_dialog_title, label); R.string.zen_access_revoke_warning_dialog_title, label);
final String summary = getResources() final String summary = getResources()
.getString(R.string.zen_access_revoke_warning_dialog_summary); .getString(R.string.zen_access_revoke_warning_dialog_summary);
ZenAccessDetails parent = (ZenAccessDetails) getTargetFragment();
return new AlertDialog.Builder(getContext()) return new AlertDialog.Builder(getContext())
.setMessage(summary) .setMessage(summary)
.setTitle(title) .setTitle(title)
@@ -66,6 +71,7 @@ public class FriendlyWarningDialogFragment extends InstrumentedDialogFragment {
(dialog, id) -> { (dialog, id) -> {
ZenAccessController.deleteRules(getContext(), pkg); ZenAccessController.deleteRules(getContext(), pkg);
ZenAccessController.setAccess(getContext(), pkg, false); ZenAccessController.setAccess(getContext(), pkg, false);
parent.refreshUi();
}) })
.setNegativeButton(R.string.cancel, .setNegativeButton(R.string.cancel,
(dialog, id) -> { (dialog, id) -> {

View File

@@ -22,6 +22,7 @@ import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
@@ -38,10 +39,11 @@ public class ScaryWarningDialogFragment extends InstrumentedDialogFragment {
return SettingsEnums.DIALOG_ZEN_ACCESS_GRANT; return SettingsEnums.DIALOG_ZEN_ACCESS_GRANT;
} }
public ScaryWarningDialogFragment setPkgInfo(String pkg, CharSequence label) { public ScaryWarningDialogFragment setPkgInfo(String pkg, CharSequence label, Fragment target) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(KEY_PKG, pkg); args.putString(KEY_PKG, pkg);
args.putString(KEY_LABEL, TextUtils.isEmpty(label) ? pkg : label.toString()); args.putString(KEY_LABEL, TextUtils.isEmpty(label) ? pkg : label.toString());
setTargetFragment(target, 0);
setArguments(args); setArguments(args);
return this; return this;
} }
@@ -57,12 +59,18 @@ public class ScaryWarningDialogFragment extends InstrumentedDialogFragment {
label); label);
final String summary = getResources() final String summary = getResources()
.getString(R.string.zen_access_warning_dialog_summary); .getString(R.string.zen_access_warning_dialog_summary);
ZenAccessDetails parent = (ZenAccessDetails) getTargetFragment();
return new AlertDialog.Builder(getContext()) 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,
(dialog, id) -> ZenAccessController.setAccess(getContext(), pkg, true)) (dialog, id) -> {
ZenAccessController.setAccess(getContext(), pkg, true);
parent.refreshUi();
})
.setNegativeButton(R.string.deny, .setNegativeButton(R.string.deny,
(dialog, id) -> { (dialog, id) -> {
// pass // pass

View File

@@ -79,11 +79,11 @@ public class ZenAccessDetails extends AppInfoWithHeader implements
final boolean access = (Boolean) newValue; final boolean access = (Boolean) newValue;
if (access) { if (access) {
new ScaryWarningDialogFragment() new ScaryWarningDialogFragment()
.setPkgInfo(mPackageName, label) .setPkgInfo(mPackageName, label, ZenAccessDetails.this)
.show(getFragmentManager(), "dialog"); .show(getFragmentManager(), "dialog");
} else { } else {
new FriendlyWarningDialogFragment() new FriendlyWarningDialogFragment()
.setPkgInfo(mPackageName, label) .setPkgInfo(mPackageName, label, ZenAccessDetails.this)
.show(getFragmentManager(), "dialog"); .show(getFragmentManager(), "dialog");
} }
return false; return false;

View File

@@ -53,11 +53,6 @@ public class ZenAccessSettingObserverMixin extends ContentObserver implements Li
@Override @Override
public void onStart() { public void onStart() {
mContext.getContentResolver().registerContentObserver(
Settings.Secure.getUriFor(
Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES),
false /* notifyForDescendants */,
this /* observer */);
mContext.getContentResolver().registerContentObserver( mContext.getContentResolver().registerContentObserver(
Settings.Secure.getUriFor(Settings.Secure.ENABLED_NOTIFICATION_LISTENERS), Settings.Secure.getUriFor(Settings.Secure.ENABLED_NOTIFICATION_LISTENERS),
false /* notifyForDescendants */, false /* notifyForDescendants */,

View File

@@ -73,7 +73,7 @@ public class ZenAccessSettingObserverMixinTest {
mLifecycle.handleLifecycleEvent(ON_START); mLifecycle.handleLifecycleEvent(ON_START);
mContext.getContentResolver().notifyChange(Settings.Secure.getUriFor( mContext.getContentResolver().notifyChange(Settings.Secure.getUriFor(
Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES), null); Settings.Secure.ENABLED_NOTIFICATION_LISTENERS), null);
verify(mListener).onZenAccessPolicyChanged(); verify(mListener).onZenAccessPolicyChanged();
} }
@@ -84,7 +84,7 @@ public class ZenAccessSettingObserverMixinTest {
mLifecycle.handleLifecycleEvent(ON_STOP); mLifecycle.handleLifecycleEvent(ON_STOP);
mContext.getContentResolver().notifyChange(Settings.Secure.getUriFor( mContext.getContentResolver().notifyChange(Settings.Secure.getUriFor(
Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES), null); Settings.Secure.ENABLED_NOTIFICATION_LISTENERS), null);
verify(mListener, never()).onZenAccessPolicyChanged(); verify(mListener, never()).onZenAccessPolicyChanged();
} }