Allow notifications be to hidden from the lockscreen by app.
Bug: 26642033 Change-Id: I932defebe00c566c0a930a0cabc118238c349272
This commit is contained in:
@@ -6037,11 +6037,8 @@
|
||||
<!-- [CHAR LIMIT=NONE] App notification settings: Override DND option description-->
|
||||
<string name="app_notification_override_dnd_summary">Let these notifications continue to interrupt when Do Not Disturb is set to Priority Only</string>
|
||||
|
||||
<!-- [CHAR LIMIT=NONE] App notification settings: Sensitive option title -->
|
||||
<string name="app_notification_sensitive_title">Hide sensitive content</string>
|
||||
|
||||
<!-- [CHAR LIMIT=NONE] App notification settings: Sensitive option description-->
|
||||
<string name="app_notification_sensitive_summary">When the device is locked, hide content in these notifications that might reveal private information</string>
|
||||
<!-- [CHAR LIMIT=NONE] App notification settings: Visibility override option title -->
|
||||
<string name="app_notification_visibility_override_title">On the lock screen</string>
|
||||
|
||||
<!-- [CHAR LIMIT=20] Notification settings: App notifications row summary when banned -->
|
||||
<string name="app_notification_row_banned">Blocked</string>
|
||||
|
@@ -45,11 +45,10 @@
|
||||
android:layout="@layout/two_buttons_panel"
|
||||
android:order="6" />
|
||||
|
||||
<!-- Sensitive -->
|
||||
<com.android.settingslib.RestrictedSwitchPreference
|
||||
android:key="sensitive"
|
||||
android:title="@string/app_notification_sensitive_title"
|
||||
android:summary="@string/app_notification_sensitive_summary"
|
||||
<!-- Visibility Override -->
|
||||
<DropDownPreference
|
||||
android:key="visibility_override"
|
||||
android:title="@string/app_notification_visibility_override_title"
|
||||
android:order="7" />
|
||||
|
||||
<!-- Bypass DND -->
|
||||
|
@@ -24,8 +24,8 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.NotificationListenerService.Ranking;
|
||||
import android.support.v7.preference.DropDownPreference;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -76,8 +76,9 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
mImportanceTitle = (RestrictedPreference) findPreference(KEY_IMPORTANCE_TITLE);
|
||||
mPriority =
|
||||
(RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BYPASS_DND);
|
||||
mSensitive =
|
||||
(RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_SENSITIVE);
|
||||
mVisibilityOverride =
|
||||
(DropDownPreference) getPreferenceScreen().findPreference(
|
||||
KEY_VISIBILITY_OVERRIDE);
|
||||
mBlock = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BLOCK);
|
||||
mSilent = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_SILENT);
|
||||
|
||||
@@ -94,7 +95,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
|
||||
setupImportancePrefs(mAppRow.systemApp, mAppRow.appImportance, mAppRow.banned);
|
||||
setupPriorityPref(mAppRow.appBypassDnd);
|
||||
setupSensitivePref(mAppRow.appSensitive);
|
||||
setupVisOverridePref(mAppRow.appVisOverride);
|
||||
updateDependents(mAppRow.appImportance);
|
||||
}
|
||||
|
||||
@@ -102,8 +103,6 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
protected void updateDependents(int importance) {
|
||||
final boolean lockscreenSecure = new LockPatternUtils(getActivity()).isSecure(
|
||||
UserHandle.myUserId());
|
||||
final boolean lockscreenNotificationsEnabled = getLockscreenNotificationsEnabled();
|
||||
final boolean allowPrivate = getLockscreenAllowPrivateNotifications();
|
||||
|
||||
if (getPreferenceScreen().findPreference(mBlock.getKey()) != null) {
|
||||
setVisible(mSilent, checkCanBeVisible(Ranking.IMPORTANCE_MIN, importance));
|
||||
@@ -111,8 +110,8 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
}
|
||||
setVisible(mPriority, checkCanBeVisible(Ranking.IMPORTANCE_DEFAULT, importance)
|
||||
&& !mDndVisualEffectsSuppressed);
|
||||
setVisible(mSensitive, checkCanBeVisible(Ranking.IMPORTANCE_MIN, importance)
|
||||
&& lockscreenSecure && lockscreenNotificationsEnabled && allowPrivate);
|
||||
setVisible(mVisibilityOverride,
|
||||
checkCanBeVisible(Ranking.IMPORTANCE_MIN, importance) && lockscreenSecure);
|
||||
}
|
||||
|
||||
protected boolean checkCanBeVisible(int minImportanceVisible, int importance) {
|
||||
@@ -122,16 +121,6 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
||||
return importance >= minImportanceVisible;
|
||||
}
|
||||
|
||||
private boolean getLockscreenNotificationsEnabled() {
|
||||
return Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
|
||||
}
|
||||
|
||||
private boolean getLockscreenAllowPrivateNotifications() {
|
||||
return Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0;
|
||||
}
|
||||
|
||||
private List<ResolveInfo> queryNotificationConfigActivities() {
|
||||
if (DEBUG) Log.d(TAG, "APP_NOTIFICATION_PREFS_CATEGORY_INTENT is "
|
||||
+ APP_NOTIFICATION_PREFS_CATEGORY_INTENT);
|
||||
|
@@ -48,7 +48,7 @@ public class NotificationBackend {
|
||||
row.banned = getNotificationsBanned(row.pkg, row.uid);
|
||||
row.appImportance = getImportance(row.pkg, row.uid);
|
||||
row.appBypassDnd = getBypassZenMode(row.pkg, row.uid);
|
||||
row.appSensitive = getSensitive(row.pkg, row.uid);
|
||||
row.appVisOverride = getVisibilityOverride(row.pkg, row.uid);
|
||||
return row;
|
||||
}
|
||||
|
||||
@@ -88,20 +88,18 @@ public class NotificationBackend {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getSensitive(String pkg, int uid) {
|
||||
public int getVisibilityOverride(String pkg, int uid) {
|
||||
try {
|
||||
return sINM.getVisibilityOverride(pkg, uid) == Notification.VISIBILITY_PRIVATE;
|
||||
return sINM.getVisibilityOverride(pkg, uid);
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Error calling NoMan", e);
|
||||
return false;
|
||||
return NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setSensitive(String pkg, int uid, boolean sensitive) {
|
||||
public boolean setVisibilityOverride(String pkg, int uid, int override) {
|
||||
try {
|
||||
sINM.setVisibilityOverride(pkg, uid,
|
||||
sensitive ? Notification.VISIBILITY_PRIVATE
|
||||
: NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE);
|
||||
sINM.setVisibilityOverride(pkg, uid, override);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Error calling NoMan", e);
|
||||
@@ -143,6 +141,6 @@ public class NotificationBackend {
|
||||
public boolean systemApp;
|
||||
public int appImportance;
|
||||
public boolean appBypassDnd;
|
||||
public boolean appSensitive;
|
||||
public int appVisOverride;
|
||||
}
|
||||
}
|
||||
|
@@ -34,6 +34,7 @@ import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.NotificationListenerService.Ranking;
|
||||
import android.support.v7.preference.DropDownPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@@ -41,6 +42,8 @@ import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
abstract public class NotificationSettingsBase extends SettingsPreferenceFragment {
|
||||
@@ -49,7 +52,7 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
||||
private static final String TUNER_SETTING = "show_importance_slider";
|
||||
|
||||
protected static final String KEY_BYPASS_DND = "bypass_dnd";
|
||||
protected static final String KEY_SENSITIVE = "sensitive";
|
||||
protected static final String KEY_VISIBILITY_OVERRIDE = "visibility_override";
|
||||
protected static final String KEY_IMPORTANCE = "importance";
|
||||
protected static final String KEY_IMPORTANCE_TITLE = "importance_title";
|
||||
protected static final String KEY_IMPORTANCE_RESET = "importance_reset_button";
|
||||
@@ -68,7 +71,7 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
||||
protected RestrictedPreference mImportanceTitle;
|
||||
protected LayoutPreference mImportanceReset;
|
||||
protected RestrictedSwitchPreference mPriority;
|
||||
protected RestrictedSwitchPreference mSensitive;
|
||||
protected DropDownPreference mVisibilityOverride;
|
||||
protected RestrictedSwitchPreference mBlock;
|
||||
protected RestrictedSwitchPreference mSilent;
|
||||
protected EnforcedAdmin mSuspendedAppsAdmin;
|
||||
@@ -144,9 +147,6 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
||||
if (mPriority != null) {
|
||||
mPriority.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
}
|
||||
if (mSensitive != null) {
|
||||
mSensitive.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
}
|
||||
if (mImportanceTitle != null) {
|
||||
mImportanceTitle.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
}
|
||||
@@ -273,18 +273,62 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
||||
});
|
||||
}
|
||||
|
||||
protected void setupSensitivePref(boolean sensitive) {
|
||||
mSensitive.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||
mSensitive.setChecked(sensitive);
|
||||
mSensitive.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
protected void setupVisOverridePref(int sensitive) {
|
||||
ArrayList<CharSequence> entries = new ArrayList<>();
|
||||
ArrayList<CharSequence> values = new ArrayList<>();
|
||||
|
||||
if (getLockscreenNotificationsEnabled() && getLockscreenAllowPrivateNotifications()) {
|
||||
entries.add(getString(R.string.lock_screen_notifications_summary_show));
|
||||
values.add(Integer.toString(Ranking.VISIBILITY_NO_OVERRIDE));
|
||||
}
|
||||
|
||||
entries.add(getString(R.string.lock_screen_notifications_summary_hide));
|
||||
values.add(Integer.toString(Notification.VISIBILITY_PRIVATE));
|
||||
entries.add(getString(R.string.lock_screen_notifications_summary_disable));
|
||||
values.add(Integer.toString(Notification.VISIBILITY_SECRET));
|
||||
mVisibilityOverride.setEntries(entries.toArray(new CharSequence[entries.size()]));
|
||||
mVisibilityOverride.setEntryValues(values.toArray(new CharSequence[values.size()]));
|
||||
|
||||
if (sensitive == Ranking.VISIBILITY_NO_OVERRIDE) {
|
||||
mVisibilityOverride.setValue(Integer.toString(getGlobalVisibility()));
|
||||
} else {
|
||||
mVisibilityOverride.setValue(Integer.toString(sensitive));
|
||||
}
|
||||
mVisibilityOverride.setSummary("%s");
|
||||
|
||||
mVisibilityOverride.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final boolean sensitive = (Boolean) newValue;
|
||||
return mBackend.setSensitive(mPkgInfo.packageName, mUid, sensitive);
|
||||
int sensitive = Integer.parseInt((String) newValue);
|
||||
if (sensitive == getGlobalVisibility()) {
|
||||
sensitive = Ranking.VISIBILITY_NO_OVERRIDE;
|
||||
}
|
||||
mBackend.setVisibilityOverride(mPkgInfo.packageName, mUid, sensitive);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private int getGlobalVisibility() {
|
||||
int globalVis = Ranking.VISIBILITY_NO_OVERRIDE;
|
||||
if (!getLockscreenNotificationsEnabled()) {
|
||||
globalVis = Notification.VISIBILITY_SECRET;
|
||||
} else if (!getLockscreenAllowPrivateNotifications()) {
|
||||
globalVis = Notification.VISIBILITY_PRIVATE;
|
||||
}
|
||||
return globalVis;
|
||||
}
|
||||
|
||||
protected boolean getLockscreenNotificationsEnabled() {
|
||||
return Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
|
||||
}
|
||||
|
||||
protected boolean getLockscreenAllowPrivateNotifications() {
|
||||
return Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0;
|
||||
}
|
||||
|
||||
abstract void updateDependents(int progress);
|
||||
|
||||
protected void setVisible(Preference p, boolean visible) {
|
||||
|
Reference in New Issue
Block a user