Importance slide updates.
- Make settings match systemui - prevent users from blocking system notification topics, and share said code with systemui Bug: 26575595 Change-Id: I3911046e2f96897b26b9b9597835a8d7b771996f
This commit is contained in:
@@ -55,23 +55,26 @@
|
|||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/low_importance"
|
android:id="@+id/low_importance"
|
||||||
android:src="@android:drawable/ic_menu_close_clear_cancel"
|
android:src="@*android:drawable/ic_notification_block"
|
||||||
android:layout_gravity="center_vertical|start"
|
android:layout_gravity="center_vertical|start"
|
||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
android:layout_height="24dp" />
|
android:layout_height="24dp" />
|
||||||
|
|
||||||
<SeekBar
|
<SeekBar
|
||||||
android:id="@*android:id/seekbar"
|
android:id="@*android:id/seekbar"
|
||||||
android:layout_marginStart="24dp"
|
android:layout_marginStart="56dp"
|
||||||
android:layout_marginEnd="24dp"
|
android:layout_marginEnd="56dp"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:focusable="true"/>
|
android:focusable="true"
|
||||||
|
android:background="#00ffffff"
|
||||||
|
style="@android:style/Widget.Material.SeekBar.Discrete"
|
||||||
|
android:tickMarkTint="@android:color/black"/>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/max_importance"
|
android:id="@+id/max_importance"
|
||||||
android:src="@android:drawable/ic_popup_reminder"
|
android:src="@*android:drawable/ic_notification_alert"
|
||||||
android:layout_gravity="center_vertical|end"
|
android:layout_gravity="center_vertical|end"
|
||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
android:layout_height="24dp" />
|
android:layout_height="24dp" />
|
||||||
|
@@ -34,11 +34,8 @@ import android.content.IntentFilter;
|
|||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.IPackageManager;
|
import android.content.pm.IPackageManager;
|
||||||
import android.content.pm.IntentFilterVerificationInfo;
|
import android.content.pm.IntentFilterVerificationInfo;
|
||||||
import android.content.pm.PackageInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.pm.Signature;
|
|
||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
@@ -707,35 +704,6 @@ public final class Utils extends com.android.settingslib.Utils {
|
|||||||
return tm.getSimCount() > 1;
|
return tm.getSimCount() > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine whether a package is a "system package", in which case certain things (like
|
|
||||||
* disabling notifications or disabling the package altogether) should be disallowed.
|
|
||||||
*/
|
|
||||||
public static boolean isSystemPackage(PackageManager pm, PackageInfo pkg) {
|
|
||||||
if (sSystemSignature == null) {
|
|
||||||
sSystemSignature = new Signature[]{ getSystemSignature(pm) };
|
|
||||||
}
|
|
||||||
return sSystemSignature[0] != null && sSystemSignature[0].equals(getFirstSignature(pkg));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Signature[] sSystemSignature;
|
|
||||||
|
|
||||||
private static Signature getFirstSignature(PackageInfo pkg) {
|
|
||||||
if (pkg != null && pkg.signatures != null && pkg.signatures.length > 0) {
|
|
||||||
return pkg.signatures[0];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Signature getSystemSignature(PackageManager pm) {
|
|
||||||
try {
|
|
||||||
final PackageInfo sys = pm.getPackageInfo("android", PackageManager.GET_SIGNATURES);
|
|
||||||
return getFirstSignature(sys);
|
|
||||||
} catch (NameNotFoundException e) {
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns elapsed time for the given millis, in the following format:
|
* Returns elapsed time for the given millis, in the following format:
|
||||||
* 2d 5h 40m 29s
|
* 2d 5h 40m 29s
|
||||||
|
@@ -70,7 +70,6 @@ public class AppNotificationSettings extends SettingsPreferenceFragment {
|
|||||||
private PreferenceCategory mCategories;
|
private PreferenceCategory mCategories;
|
||||||
private AppRow mAppRow;
|
private AppRow mAppRow;
|
||||||
private boolean mCreated;
|
private boolean mCreated;
|
||||||
private boolean mIsSystemPackage;
|
|
||||||
private int mUid;
|
private int mUid;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -126,12 +125,10 @@ public class AppNotificationSettings extends SettingsPreferenceFragment {
|
|||||||
toastAndFinish();
|
toastAndFinish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mIsSystemPackage = Utils.isSystemPackage(pm, info);
|
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.app_notification_settings);
|
addPreferencesFromResource(R.xml.app_notification_settings);
|
||||||
mBlock = (SwitchPreference) findPreference(KEY_BLOCK);
|
mBlock = (SwitchPreference) findPreference(KEY_BLOCK);
|
||||||
|
|
||||||
mAppRow = mBackend.loadAppRow(pm, info.applicationInfo);
|
mAppRow = mBackend.loadAppRow(pm, info);
|
||||||
|
|
||||||
// load settings intent
|
// load settings intent
|
||||||
ArrayMap<String, AppRow> rows = new ArrayMap<String, AppRow>();
|
ArrayMap<String, AppRow> rows = new ArrayMap<String, AppRow>();
|
||||||
@@ -160,7 +157,7 @@ public class AppNotificationSettings extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mBlock.setChecked(mAppRow.banned);
|
mBlock.setChecked(mAppRow.banned);
|
||||||
updateDependents(mAppRow.banned);
|
updateDependents(mAppRow.systemApp, mAppRow.banned);
|
||||||
|
|
||||||
mBlock.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
mBlock.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -171,7 +168,7 @@ public class AppNotificationSettings extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
final boolean success = mBackend.setNotificationsBanned(pkg, mUid, banned);
|
final boolean success = mBackend.setNotificationsBanned(pkg, mUid, banned);
|
||||||
if (success) {
|
if (success) {
|
||||||
updateDependents(banned);
|
updateDependents(mAppRow.systemApp, banned);
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
@@ -200,8 +197,8 @@ public class AppNotificationSettings extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDependents(boolean banned) {
|
private void updateDependents(boolean isSystemPackage, boolean banned) {
|
||||||
setVisible(mBlock, !mIsSystemPackage);
|
setVisible(mBlock, !isSystemPackage);
|
||||||
if (mCategories != null) {
|
if (mCategories != null) {
|
||||||
setVisible(mCategories, !banned);
|
setVisible(mCategories, !banned);
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,7 @@ public class ImportanceSeekBarPreference extends SeekBarPreference implements
|
|||||||
private Callback mCallback;
|
private Callback mCallback;
|
||||||
private TextView mSummaryTextView;
|
private TextView mSummaryTextView;
|
||||||
private String mSummary;
|
private String mSummary;
|
||||||
|
private int mMinProgress;
|
||||||
|
|
||||||
public ImportanceSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
public ImportanceSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
||||||
int defStyleRes) {
|
int defStyleRes) {
|
||||||
@@ -59,6 +60,10 @@ public class ImportanceSeekBarPreference extends SeekBarPreference implements
|
|||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMinimumProgress(int minProgress) {
|
||||||
|
mMinProgress = minProgress;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||||
super.onBindViewHolder(view);
|
super.onBindViewHolder(view);
|
||||||
@@ -72,8 +77,12 @@ public class ImportanceSeekBarPreference extends SeekBarPreference implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProgressChanged(SeekBar seekBar, final int progress, boolean fromTouch) {
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
|
||||||
super.onProgressChanged(seekBar, progress, fromTouch);
|
super.onProgressChanged(seekBar, progress, fromTouch);
|
||||||
|
if (progress < mMinProgress) {
|
||||||
|
seekBar.setProgress(mMinProgress);
|
||||||
|
progress = mMinProgress;
|
||||||
|
}
|
||||||
if (mSummaryTextView != null) {
|
if (mSummaryTextView != null) {
|
||||||
mSummaryTextView.setText(getProgressSummary(progress));
|
mSummaryTextView.setText(getProgressSummary(progress));
|
||||||
}
|
}
|
||||||
|
@@ -22,12 +22,14 @@ import android.app.Notification;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ParceledListSlice;
|
import android.content.pm.ParceledListSlice;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.service.notification.NotificationListenerService;
|
import android.service.notification.NotificationListenerService;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import com.android.settingslib.Utils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -52,12 +54,19 @@ public class NotificationBackend {
|
|||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TopicRow loadTopicRow(PackageManager pm, ApplicationInfo app, Notification.Topic topic) {
|
public AppRow loadAppRow(PackageManager pm, PackageInfo app) {
|
||||||
|
final AppRow row = loadAppRow(pm, app.applicationInfo);
|
||||||
|
row.systemApp = Utils.isSystemPackage(pm, app);
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TopicRow loadTopicRow(PackageManager pm, PackageInfo app, Notification.Topic topic) {
|
||||||
final TopicRow row = new TopicRow();
|
final TopicRow row = new TopicRow();
|
||||||
row.pkg = app.packageName;
|
row.pkg = app.packageName;
|
||||||
row.uid = app.uid;
|
row.uid = app.applicationInfo.uid;
|
||||||
row.label = topic.getLabel();
|
row.label = topic.getLabel();
|
||||||
row.icon = app.loadIcon(pm);
|
row.icon = app.applicationInfo.loadIcon(pm);
|
||||||
|
row.systemApp = Utils.isSystemPackage(pm, app);
|
||||||
row.topic = topic;
|
row.topic = topic;
|
||||||
row.priority = getBypassZenMode(row.pkg, row.uid, row.topic);
|
row.priority = getBypassZenMode(row.pkg, row.uid, row.topic);
|
||||||
row.sensitive = getSensitive(row.pkg, row.uid, row.topic);
|
row.sensitive = getSensitive(row.pkg, row.uid, row.topic);
|
||||||
@@ -170,6 +179,7 @@ public class NotificationBackend {
|
|||||||
public Intent settingsIntent;
|
public Intent settingsIntent;
|
||||||
public boolean banned;
|
public boolean banned;
|
||||||
public boolean first; // first app in section
|
public boolean first; // first app in section
|
||||||
|
public boolean systemApp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TopicRow extends AppRow {
|
public static class TopicRow extends AppRow {
|
||||||
|
@@ -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;
|
import android.service.notification.NotificationListenerService;
|
||||||
|
import android.service.notification.NotificationListenerService.Ranking;
|
||||||
import android.support.v14.preference.SwitchPreference;
|
import android.support.v14.preference.SwitchPreference;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
||||||
@@ -130,9 +131,11 @@ public class TopicNotificationSettings extends SettingsPreferenceFragment {
|
|||||||
mPriority = (SwitchPreference) findPreference(KEY_BYPASS_DND);
|
mPriority = (SwitchPreference) findPreference(KEY_BYPASS_DND);
|
||||||
mSensitive = (SwitchPreference) findPreference(KEY_SENSITIVE);
|
mSensitive = (SwitchPreference) findPreference(KEY_SENSITIVE);
|
||||||
|
|
||||||
mTopicRow = mBackend.loadTopicRow(pm, info.applicationInfo, topic);
|
mTopicRow = mBackend.loadTopicRow(pm, info, topic);
|
||||||
|
|
||||||
mImportance.setMax(4);
|
mImportance.setMinimumProgress(
|
||||||
|
mTopicRow.systemApp ? Ranking.IMPORTANCE_LOW : Ranking.IMPORTANCE_NONE);
|
||||||
|
mImportance.setMax(Ranking.IMPORTANCE_MAX);
|
||||||
// TODO: stop defaulting to 'normal' in the UI when there are mocks for this scenario.
|
// TODO: stop defaulting to 'normal' in the UI when there are mocks for this scenario.
|
||||||
int importance =
|
int importance =
|
||||||
mTopicRow.importance == NotificationListenerService.Ranking.IMPORTANCE_UNSPECIFIED
|
mTopicRow.importance == NotificationListenerService.Ranking.IMPORTANCE_UNSPECIFIED
|
||||||
|
Reference in New Issue
Block a user