Implement per-app sensitivity settings toggle.
Change-Id: Iaa1de63b720bf93bdf432117604740e509fe3ab0 Depends-On: I2d5cf6782273744cbf9b309dec76780cc0a4c39e Bug: 16324353
This commit is contained in:
@@ -39,7 +39,6 @@
|
|||||||
android:key="sensitive"
|
android:key="sensitive"
|
||||||
android:title="@string/app_notification_sensitive_title"
|
android:title="@string/app_notification_sensitive_title"
|
||||||
android:summary="@string/app_notification_sensitive_summary"
|
android:summary="@string/app_notification_sensitive_summary"
|
||||||
android:enabled="false"
|
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -137,7 +137,9 @@ public class AppNotificationSettings extends SettingsPreferenceFragment {
|
|||||||
mSensitive = (SwitchPreference) findPreference(KEY_SENSITIVE);
|
mSensitive = (SwitchPreference) findPreference(KEY_SENSITIVE);
|
||||||
|
|
||||||
final boolean secure = new LockPatternUtils(getActivity()).isSecure();
|
final boolean secure = new LockPatternUtils(getActivity()).isSecure();
|
||||||
if (!secure) {
|
final boolean enabled = getLockscreenNotificationsEnabled();
|
||||||
|
final boolean allowPrivate = getLockscreenAllowPrivateNotifications();
|
||||||
|
if (!secure || !enabled || !allowPrivate) {
|
||||||
getPreferenceScreen().removePreference(mSensitive);
|
getPreferenceScreen().removePreference(mSensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,6 +195,16 @@ public class AppNotificationSettings extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 void toastAndFinish() {
|
private void toastAndFinish() {
|
||||||
Toast.makeText(mContext, R.string.app_not_found_dlg_text, Toast.LENGTH_SHORT).show();
|
Toast.makeText(mContext, R.string.app_not_found_dlg_text, Toast.LENGTH_SHORT).show();
|
||||||
getActivity().finish();
|
getActivity().finish();
|
||||||
|
@@ -41,6 +41,7 @@ import android.os.SystemClock;
|
|||||||
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 android.service.notification.NotificationListenerService;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
@@ -568,13 +569,28 @@ public class NotificationAppList extends PinnedHeaderListFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean getSensitive(String pkg, int uid) {
|
public boolean getSensitive(String pkg, int uid) {
|
||||||
// TODO get visibility state from NoMan
|
INotificationManager nm = INotificationManager.Stub.asInterface(
|
||||||
|
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
||||||
|
try {
|
||||||
|
return nm.getPackageVisibilityOverride(pkg, uid) == Notification.VISIBILITY_PRIVATE;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.w(TAG, "Error calling NoMan", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean setSensitive(String pkg, int uid, boolean sensitive) {
|
public boolean setSensitive(String pkg, int uid, boolean sensitive) {
|
||||||
// TODO save visibility state to NoMan
|
INotificationManager nm = INotificationManager.Stub.asInterface(
|
||||||
|
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
||||||
|
try {
|
||||||
|
nm.setPackageVisibilityOverride(pkg, uid,
|
||||||
|
sensitive ? Notification.VISIBILITY_PRIVATE
|
||||||
|
: NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE);
|
||||||
return true;
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.w(TAG, "Error calling NoMan", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user