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-->
|
<!-- [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>
|
<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 -->
|
<!-- [CHAR LIMIT=NONE] App notification settings: Visibility override option title -->
|
||||||
<string name="app_notification_sensitive_title">Hide sensitive content</string>
|
<string name="app_notification_visibility_override_title">On the lock screen</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=20] Notification settings: App notifications row summary when banned -->
|
<!-- [CHAR LIMIT=20] Notification settings: App notifications row summary when banned -->
|
||||||
<string name="app_notification_row_banned">Blocked</string>
|
<string name="app_notification_row_banned">Blocked</string>
|
||||||
|
@@ -45,11 +45,10 @@
|
|||||||
android:layout="@layout/two_buttons_panel"
|
android:layout="@layout/two_buttons_panel"
|
||||||
android:order="6" />
|
android:order="6" />
|
||||||
|
|
||||||
<!-- Sensitive -->
|
<!-- Visibility Override -->
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
<DropDownPreference
|
||||||
android:key="sensitive"
|
android:key="visibility_override"
|
||||||
android:title="@string/app_notification_sensitive_title"
|
android:title="@string/app_notification_visibility_override_title"
|
||||||
android:summary="@string/app_notification_sensitive_summary"
|
|
||||||
android:order="7" />
|
android:order="7" />
|
||||||
|
|
||||||
<!-- Bypass DND -->
|
<!-- Bypass DND -->
|
||||||
|
@@ -24,8 +24,8 @@ import android.content.pm.ApplicationInfo;
|
|||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.service.notification.NotificationListenerService.Ranking;
|
import android.service.notification.NotificationListenerService.Ranking;
|
||||||
|
import android.support.v7.preference.DropDownPreference;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -76,8 +76,9 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
mImportanceTitle = (RestrictedPreference) findPreference(KEY_IMPORTANCE_TITLE);
|
mImportanceTitle = (RestrictedPreference) findPreference(KEY_IMPORTANCE_TITLE);
|
||||||
mPriority =
|
mPriority =
|
||||||
(RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BYPASS_DND);
|
(RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BYPASS_DND);
|
||||||
mSensitive =
|
mVisibilityOverride =
|
||||||
(RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_SENSITIVE);
|
(DropDownPreference) getPreferenceScreen().findPreference(
|
||||||
|
KEY_VISIBILITY_OVERRIDE);
|
||||||
mBlock = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BLOCK);
|
mBlock = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BLOCK);
|
||||||
mSilent = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_SILENT);
|
mSilent = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_SILENT);
|
||||||
|
|
||||||
@@ -94,7 +95,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
|
|
||||||
setupImportancePrefs(mAppRow.systemApp, mAppRow.appImportance, mAppRow.banned);
|
setupImportancePrefs(mAppRow.systemApp, mAppRow.appImportance, mAppRow.banned);
|
||||||
setupPriorityPref(mAppRow.appBypassDnd);
|
setupPriorityPref(mAppRow.appBypassDnd);
|
||||||
setupSensitivePref(mAppRow.appSensitive);
|
setupVisOverridePref(mAppRow.appVisOverride);
|
||||||
updateDependents(mAppRow.appImportance);
|
updateDependents(mAppRow.appImportance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,8 +103,6 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
protected void updateDependents(int importance) {
|
protected void updateDependents(int importance) {
|
||||||
final boolean lockscreenSecure = new LockPatternUtils(getActivity()).isSecure(
|
final boolean lockscreenSecure = new LockPatternUtils(getActivity()).isSecure(
|
||||||
UserHandle.myUserId());
|
UserHandle.myUserId());
|
||||||
final boolean lockscreenNotificationsEnabled = getLockscreenNotificationsEnabled();
|
|
||||||
final boolean allowPrivate = getLockscreenAllowPrivateNotifications();
|
|
||||||
|
|
||||||
if (getPreferenceScreen().findPreference(mBlock.getKey()) != null) {
|
if (getPreferenceScreen().findPreference(mBlock.getKey()) != null) {
|
||||||
setVisible(mSilent, checkCanBeVisible(Ranking.IMPORTANCE_MIN, importance));
|
setVisible(mSilent, checkCanBeVisible(Ranking.IMPORTANCE_MIN, importance));
|
||||||
@@ -111,8 +110,8 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
}
|
}
|
||||||
setVisible(mPriority, checkCanBeVisible(Ranking.IMPORTANCE_DEFAULT, importance)
|
setVisible(mPriority, checkCanBeVisible(Ranking.IMPORTANCE_DEFAULT, importance)
|
||||||
&& !mDndVisualEffectsSuppressed);
|
&& !mDndVisualEffectsSuppressed);
|
||||||
setVisible(mSensitive, checkCanBeVisible(Ranking.IMPORTANCE_MIN, importance)
|
setVisible(mVisibilityOverride,
|
||||||
&& lockscreenSecure && lockscreenNotificationsEnabled && allowPrivate);
|
checkCanBeVisible(Ranking.IMPORTANCE_MIN, importance) && lockscreenSecure);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean checkCanBeVisible(int minImportanceVisible, int importance) {
|
protected boolean checkCanBeVisible(int minImportanceVisible, int importance) {
|
||||||
@@ -122,16 +121,6 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
return importance >= minImportanceVisible;
|
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() {
|
private List<ResolveInfo> queryNotificationConfigActivities() {
|
||||||
if (DEBUG) Log.d(TAG, "APP_NOTIFICATION_PREFS_CATEGORY_INTENT is "
|
if (DEBUG) Log.d(TAG, "APP_NOTIFICATION_PREFS_CATEGORY_INTENT is "
|
||||||
+ APP_NOTIFICATION_PREFS_CATEGORY_INTENT);
|
+ APP_NOTIFICATION_PREFS_CATEGORY_INTENT);
|
||||||
|
@@ -48,7 +48,7 @@ public class NotificationBackend {
|
|||||||
row.banned = getNotificationsBanned(row.pkg, row.uid);
|
row.banned = getNotificationsBanned(row.pkg, row.uid);
|
||||||
row.appImportance = getImportance(row.pkg, row.uid);
|
row.appImportance = getImportance(row.pkg, row.uid);
|
||||||
row.appBypassDnd = getBypassZenMode(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;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,20 +88,18 @@ public class NotificationBackend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getSensitive(String pkg, int uid) {
|
public int getVisibilityOverride(String pkg, int uid) {
|
||||||
try {
|
try {
|
||||||
return sINM.getVisibilityOverride(pkg, uid) == Notification.VISIBILITY_PRIVATE;
|
return sINM.getVisibilityOverride(pkg, uid);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.w(TAG, "Error calling NoMan", 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 {
|
try {
|
||||||
sINM.setVisibilityOverride(pkg, uid,
|
sINM.setVisibilityOverride(pkg, uid, override);
|
||||||
sensitive ? Notification.VISIBILITY_PRIVATE
|
|
||||||
: NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE);
|
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.w(TAG, "Error calling NoMan", e);
|
Log.w(TAG, "Error calling NoMan", e);
|
||||||
@@ -143,6 +141,6 @@ public class NotificationBackend {
|
|||||||
public boolean systemApp;
|
public boolean systemApp;
|
||||||
public int appImportance;
|
public int appImportance;
|
||||||
public boolean appBypassDnd;
|
public boolean appBypassDnd;
|
||||||
public boolean appSensitive;
|
public int appVisOverride;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,7 @@ import android.os.Bundle;
|
|||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.service.notification.NotificationListenerService.Ranking;
|
import android.service.notification.NotificationListenerService.Ranking;
|
||||||
|
import android.support.v7.preference.DropDownPreference;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -41,6 +42,8 @@ import android.view.View;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
|
|
||||||
abstract public class NotificationSettingsBase extends SettingsPreferenceFragment {
|
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";
|
private static final String TUNER_SETTING = "show_importance_slider";
|
||||||
|
|
||||||
protected static final String KEY_BYPASS_DND = "bypass_dnd";
|
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 = "importance";
|
||||||
protected static final String KEY_IMPORTANCE_TITLE = "importance_title";
|
protected static final String KEY_IMPORTANCE_TITLE = "importance_title";
|
||||||
protected static final String KEY_IMPORTANCE_RESET = "importance_reset_button";
|
protected static final String KEY_IMPORTANCE_RESET = "importance_reset_button";
|
||||||
@@ -68,7 +71,7 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
protected RestrictedPreference mImportanceTitle;
|
protected RestrictedPreference mImportanceTitle;
|
||||||
protected LayoutPreference mImportanceReset;
|
protected LayoutPreference mImportanceReset;
|
||||||
protected RestrictedSwitchPreference mPriority;
|
protected RestrictedSwitchPreference mPriority;
|
||||||
protected RestrictedSwitchPreference mSensitive;
|
protected DropDownPreference mVisibilityOverride;
|
||||||
protected RestrictedSwitchPreference mBlock;
|
protected RestrictedSwitchPreference mBlock;
|
||||||
protected RestrictedSwitchPreference mSilent;
|
protected RestrictedSwitchPreference mSilent;
|
||||||
protected EnforcedAdmin mSuspendedAppsAdmin;
|
protected EnforcedAdmin mSuspendedAppsAdmin;
|
||||||
@@ -144,9 +147,6 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
if (mPriority != null) {
|
if (mPriority != null) {
|
||||||
mPriority.setDisabledByAdmin(mSuspendedAppsAdmin);
|
mPriority.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||||
}
|
}
|
||||||
if (mSensitive != null) {
|
|
||||||
mSensitive.setDisabledByAdmin(mSuspendedAppsAdmin);
|
|
||||||
}
|
|
||||||
if (mImportanceTitle != null) {
|
if (mImportanceTitle != null) {
|
||||||
mImportanceTitle.setDisabledByAdmin(mSuspendedAppsAdmin);
|
mImportanceTitle.setDisabledByAdmin(mSuspendedAppsAdmin);
|
||||||
}
|
}
|
||||||
@@ -273,18 +273,62 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setupSensitivePref(boolean sensitive) {
|
protected void setupVisOverridePref(int sensitive) {
|
||||||
mSensitive.setDisabledByAdmin(mSuspendedAppsAdmin);
|
ArrayList<CharSequence> entries = new ArrayList<>();
|
||||||
mSensitive.setChecked(sensitive);
|
ArrayList<CharSequence> values = new ArrayList<>();
|
||||||
mSensitive.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
||||||
|
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
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
final boolean sensitive = (Boolean) newValue;
|
int sensitive = Integer.parseInt((String) newValue);
|
||||||
return mBackend.setSensitive(mPkgInfo.packageName, mUid, sensitive);
|
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);
|
abstract void updateDependents(int progress);
|
||||||
|
|
||||||
protected void setVisible(Preference p, boolean visible) {
|
protected void setVisible(Preference p, boolean visible) {
|
||||||
|
Reference in New Issue
Block a user