Add ContentObserver to RedactNotificationPreferenceController
- Monitor the LOCK_SCREEN_SHOW_NOTIFICATIONS to decide the enabled/disabled status. Fixes: 134055112 Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.notification Change-Id: I7c7edbe13f47638df69f31d15d863c2088a5774f
This commit is contained in:
@@ -23,17 +23,29 @@ import static android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFIC
|
|||||||
import android.app.KeyguardManager;
|
import android.app.KeyguardManager;
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.database.ContentObserver;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.internal.widget.LockPatternUtils;
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
|
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||||
|
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||||
|
|
||||||
public class RedactNotificationPreferenceController extends TogglePreferenceController {
|
/**
|
||||||
|
* The controller of the sensitive notifications.
|
||||||
|
*/
|
||||||
|
public class RedactNotificationPreferenceController extends TogglePreferenceController implements
|
||||||
|
LifecycleObserver, OnStart, OnStop {
|
||||||
private static final String TAG = "LockScreenNotifPref";
|
private static final String TAG = "LockScreenNotifPref";
|
||||||
|
|
||||||
static final String KEY_LOCKSCREEN_REDACT = "lock_screen_redact";
|
static final String KEY_LOCKSCREEN_REDACT = "lock_screen_redact";
|
||||||
@@ -43,6 +55,17 @@ public class RedactNotificationPreferenceController extends TogglePreferenceCont
|
|||||||
private UserManager mUm;
|
private UserManager mUm;
|
||||||
private KeyguardManager mKm;
|
private KeyguardManager mKm;
|
||||||
private final int mProfileUserId;
|
private final int mProfileUserId;
|
||||||
|
private Preference mPreference;
|
||||||
|
private ContentObserver mContentObserver =
|
||||||
|
new ContentObserver(new Handler(Looper.getMainLooper())) {
|
||||||
|
@Override
|
||||||
|
public void onChange(boolean selfChange) {
|
||||||
|
if (mPreference != null) {
|
||||||
|
mPreference.setEnabled(
|
||||||
|
getAvailabilityStatus() != DISABLED_DEPENDENT_SETTING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public RedactNotificationPreferenceController(Context context, String settingKey) {
|
public RedactNotificationPreferenceController(Context context, String settingKey) {
|
||||||
super(context, settingKey);
|
super(context, settingKey);
|
||||||
@@ -54,6 +77,12 @@ public class RedactNotificationPreferenceController extends TogglePreferenceCont
|
|||||||
mProfileUserId = Utils.getManagedProfileId(mUm, UserHandle.myUserId());
|
mProfileUserId = Utils.getManagedProfileId(mUm, UserHandle.myUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChecked() {
|
public boolean isChecked() {
|
||||||
int userId = KEY_LOCKSCREEN_REDACT.equals(getPreferenceKey())
|
int userId = KEY_LOCKSCREEN_REDACT.equals(getPreferenceKey())
|
||||||
@@ -108,6 +137,18 @@ public class RedactNotificationPreferenceController extends TogglePreferenceCont
|
|||||||
return AVAILABLE;
|
return AVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
mContext.getContentResolver().registerContentObserver(
|
||||||
|
Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS),
|
||||||
|
false /* notifyForDescendants */, mContentObserver);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
mContext.getContentResolver().unregisterContentObserver(mContentObserver);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean adminAllowsNotifications(int userId) {
|
private boolean adminAllowsNotifications(int userId) {
|
||||||
final int dpmFlags = mDpm.getKeyguardDisabledFeatures(null/* admin */, userId);
|
final int dpmFlags = mDpm.getKeyguardDisabledFeatures(null/* admin */, userId);
|
||||||
return (dpmFlags & KEYGUARD_DISABLE_SECURE_NOTIFICATIONS) == 0;
|
return (dpmFlags & KEYGUARD_DISABLE_SECURE_NOTIFICATIONS) == 0;
|
||||||
@@ -123,7 +164,7 @@ public class RedactNotificationPreferenceController extends TogglePreferenceCont
|
|||||||
LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, userId) != 0;
|
LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, userId) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getLockscreenNotificationsEnabled(int userId) {
|
private boolean getLockscreenNotificationsEnabled(int userId) {
|
||||||
return Settings.Secure.getIntForUser(mContext.getContentResolver(),
|
return Settings.Secure.getIntForUser(mContext.getContentResolver(),
|
||||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1, userId) != 0;
|
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1, userId) != 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user