Merge "Stop depending on empty Settings"
This commit is contained in:
committed by
Android (Google) Code Review
commit
fcfc260cf5
@@ -22,6 +22,7 @@ import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
@@ -39,10 +40,12 @@ public class FriendlyWarningDialogFragment extends InstrumentedDialogFragment {
|
||||
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();
|
||||
args.putString(KEY_PKG, pkg);
|
||||
args.putString(KEY_LABEL, TextUtils.isEmpty(label) ? pkg : label.toString());
|
||||
setTargetFragment(target, 0);
|
||||
setArguments(args);
|
||||
return this;
|
||||
}
|
||||
@@ -58,6 +61,8 @@ public class FriendlyWarningDialogFragment extends InstrumentedDialogFragment {
|
||||
R.string.zen_access_revoke_warning_dialog_title, label);
|
||||
final String summary = getResources()
|
||||
.getString(R.string.zen_access_revoke_warning_dialog_summary);
|
||||
|
||||
ZenAccessDetails parent = (ZenAccessDetails) getTargetFragment();
|
||||
return new AlertDialog.Builder(getContext())
|
||||
.setMessage(summary)
|
||||
.setTitle(title)
|
||||
@@ -66,6 +71,7 @@ public class FriendlyWarningDialogFragment extends InstrumentedDialogFragment {
|
||||
(dialog, id) -> {
|
||||
ZenAccessController.deleteRules(getContext(), pkg);
|
||||
ZenAccessController.setAccess(getContext(), pkg, false);
|
||||
parent.refreshUi();
|
||||
})
|
||||
.setNegativeButton(R.string.cancel,
|
||||
(dialog, id) -> {
|
||||
|
@@ -22,6 +22,7 @@ import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
@@ -38,10 +39,11 @@ public class ScaryWarningDialogFragment extends InstrumentedDialogFragment {
|
||||
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();
|
||||
args.putString(KEY_PKG, pkg);
|
||||
args.putString(KEY_LABEL, TextUtils.isEmpty(label) ? pkg : label.toString());
|
||||
setTargetFragment(target, 0);
|
||||
setArguments(args);
|
||||
return this;
|
||||
}
|
||||
@@ -57,12 +59,18 @@ public class ScaryWarningDialogFragment extends InstrumentedDialogFragment {
|
||||
label);
|
||||
final String summary = getResources()
|
||||
.getString(R.string.zen_access_warning_dialog_summary);
|
||||
|
||||
ZenAccessDetails parent = (ZenAccessDetails) getTargetFragment();
|
||||
|
||||
return new AlertDialog.Builder(getContext())
|
||||
.setMessage(summary)
|
||||
.setTitle(title)
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.allow,
|
||||
(dialog, id) -> ZenAccessController.setAccess(getContext(), pkg, true))
|
||||
(dialog, id) -> {
|
||||
ZenAccessController.setAccess(getContext(), pkg, true);
|
||||
parent.refreshUi();
|
||||
})
|
||||
.setNegativeButton(R.string.deny,
|
||||
(dialog, id) -> {
|
||||
// pass
|
||||
|
@@ -79,11 +79,11 @@ public class ZenAccessDetails extends AppInfoWithHeader implements
|
||||
final boolean access = (Boolean) newValue;
|
||||
if (access) {
|
||||
new ScaryWarningDialogFragment()
|
||||
.setPkgInfo(mPackageName, label)
|
||||
.setPkgInfo(mPackageName, label, ZenAccessDetails.this)
|
||||
.show(getFragmentManager(), "dialog");
|
||||
} else {
|
||||
new FriendlyWarningDialogFragment()
|
||||
.setPkgInfo(mPackageName, label)
|
||||
.setPkgInfo(mPackageName, label, ZenAccessDetails.this)
|
||||
.show(getFragmentManager(), "dialog");
|
||||
}
|
||||
return false;
|
||||
|
@@ -53,11 +53,6 @@ public class ZenAccessSettingObserverMixin extends ContentObserver implements Li
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
Settings.Secure.getUriFor(
|
||||
Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES),
|
||||
false /* notifyForDescendants */,
|
||||
this /* observer */);
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
Settings.Secure.getUriFor(Settings.Secure.ENABLED_NOTIFICATION_LISTENERS),
|
||||
false /* notifyForDescendants */,
|
||||
|
@@ -73,7 +73,7 @@ public class ZenAccessSettingObserverMixinTest {
|
||||
mLifecycle.handleLifecycleEvent(ON_START);
|
||||
|
||||
mContext.getContentResolver().notifyChange(Settings.Secure.getUriFor(
|
||||
Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES), null);
|
||||
Settings.Secure.ENABLED_NOTIFICATION_LISTENERS), null);
|
||||
|
||||
verify(mListener).onZenAccessPolicyChanged();
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public class ZenAccessSettingObserverMixinTest {
|
||||
mLifecycle.handleLifecycleEvent(ON_STOP);
|
||||
|
||||
mContext.getContentResolver().notifyChange(Settings.Secure.getUriFor(
|
||||
Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES), null);
|
||||
Settings.Secure.ENABLED_NOTIFICATION_LISTENERS), null);
|
||||
|
||||
verify(mListener, never()).onZenAccessPolicyChanged();
|
||||
}
|
||||
|
Reference in New Issue
Block a user