Show app level settings when app doesn't use topics.
Change-Id: I3c31a1bdddc70077182ea910911de1444472b7a9
This commit is contained in:
@@ -42,36 +42,17 @@ import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
/** These settings are per topic, so should not be returned in global search results. */
|
||||
public class TopicNotificationSettings extends SettingsPreferenceFragment {
|
||||
public class TopicNotificationSettings extends NotificationSettingsBase {
|
||||
private static final String TAG = "TopicNotiSettings";
|
||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
|
||||
protected static final String ARG_TOPIC = "arg_topic";
|
||||
protected static final String ARG_PACKAGE_INFO = "arg_info";
|
||||
private static final String KEY_BYPASS_DND = "bypass_dnd";
|
||||
private static final String KEY_SENSITIVE = "sensitive";
|
||||
private static final String KEY_IMPORTANCE = "importance";
|
||||
|
||||
private final NotificationBackend mBackend = new NotificationBackend();
|
||||
|
||||
private Context mContext;
|
||||
private ImportanceSeekBarPreference mImportance;
|
||||
private SwitchPreference mPriority;
|
||||
private SwitchPreference mSensitive;
|
||||
private TopicRow mTopicRow;
|
||||
private boolean mCreated;
|
||||
private int mUid;
|
||||
private boolean mDndVisualEffectsSuppressed;
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
if (DEBUG) Log.d(TAG, "onActivityCreated mCreated=" + mCreated);
|
||||
if (mCreated) {
|
||||
Log.w(TAG, "onActivityCreated: ignoring duplicate call");
|
||||
return;
|
||||
}
|
||||
mCreated = true;
|
||||
if (mTopicRow == null) return;
|
||||
AppHeader.createAppHeader(
|
||||
this, mTopicRow.icon, mTopicRow.label, mTopicRow.pkg, mTopicRow.uid);
|
||||
@@ -85,102 +66,36 @@ public class TopicNotificationSettings extends SettingsPreferenceFragment {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mContext = getActivity();
|
||||
Intent intent = getActivity().getIntent();
|
||||
Bundle args = getArguments();
|
||||
if (DEBUG) Log.d(TAG, "onCreate getIntent()=" + intent);
|
||||
if (intent == null && args == null) {
|
||||
Log.w(TAG, "No intent");
|
||||
toastAndFinish();
|
||||
return;
|
||||
}
|
||||
|
||||
NotificationManager.Policy policy =
|
||||
NotificationManager.from(mContext).getNotificationPolicy();
|
||||
mDndVisualEffectsSuppressed = policy == null ? false : policy.suppressedVisualEffects != 0;
|
||||
|
||||
Bundle args = getArguments();
|
||||
final Notification.Topic topic = args != null && args.containsKey(ARG_TOPIC)
|
||||
? (Notification.Topic) args.getParcelable(ARG_TOPIC) : null;
|
||||
|
||||
if (topic == null) {
|
||||
toastAndFinish();
|
||||
return;
|
||||
}
|
||||
|
||||
final PackageInfo info = args != null && args.containsKey(ARG_PACKAGE_INFO)
|
||||
? (PackageInfo) args.getParcelable(ARG_PACKAGE_INFO) : null;
|
||||
if (info == null) {
|
||||
Log.w(TAG, "Failed to find package info");
|
||||
toastAndFinish();
|
||||
return;
|
||||
}
|
||||
|
||||
mUid = args != null && args.containsKey(AppInfoBase.ARG_PACKAGE_UID)
|
||||
? args.getInt(AppInfoBase.ARG_PACKAGE_UID)
|
||||
: intent.getIntExtra(Settings.EXTRA_APP_UID, -1);
|
||||
if (mUid == -1) {
|
||||
Log.w(TAG, "Missing extras: " + Settings.EXTRA_APP_UID + " was " + mUid);
|
||||
toastAndFinish();
|
||||
return;
|
||||
}
|
||||
|
||||
final PackageManager pm = getPackageManager();
|
||||
|
||||
addPreferencesFromResource(R.xml.topic_notification_settings);
|
||||
mTopicRow = mBackend.loadTopicRow(mPm, mPkgInfo, topic);
|
||||
|
||||
mImportance = (ImportanceSeekBarPreference) findPreference(KEY_IMPORTANCE);
|
||||
setupImportancePref(mTopicRow, mTopicRow.topic, mTopicRow.importance);
|
||||
|
||||
mPriority = (SwitchPreference) findPreference(KEY_BYPASS_DND);
|
||||
setupPriorityPref(mTopicRow.topic, mTopicRow.priority);
|
||||
|
||||
mSensitive = (SwitchPreference) findPreference(KEY_SENSITIVE);
|
||||
setupSensitivePref(mTopicRow.topic, mTopicRow.sensitive);
|
||||
|
||||
mTopicRow = mBackend.loadTopicRow(pm, info, topic);
|
||||
|
||||
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.
|
||||
int importance =
|
||||
mTopicRow.importance == NotificationListenerService.Ranking.IMPORTANCE_UNSPECIFIED
|
||||
? NotificationListenerService.Ranking.IMPORTANCE_DEFAULT
|
||||
: mTopicRow.importance;
|
||||
mImportance.setProgress(importance);
|
||||
mImportance.setCallback(new ImportanceSeekBarPreference.Callback() {
|
||||
@Override
|
||||
public void onImportanceChanged(int progress) {
|
||||
mBackend.setImportance(mTopicRow.pkg, mTopicRow.uid, mTopicRow.topic, progress);
|
||||
updateDependents(progress);
|
||||
}
|
||||
});
|
||||
mPriority.setChecked(mTopicRow.priority);
|
||||
mSensitive.setChecked(mTopicRow.sensitive);
|
||||
|
||||
mPriority.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final boolean bypassZenMode = (Boolean) newValue;
|
||||
return mBackend.setBypassZenMode(info.packageName, mUid, topic, bypassZenMode);
|
||||
}
|
||||
});
|
||||
|
||||
mSensitive.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final boolean sensitive = (Boolean) newValue;
|
||||
return mBackend.setSensitive(info.packageName, mUid, topic, sensitive);
|
||||
}
|
||||
});
|
||||
updateDependents(mTopicRow.importance);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (mUid != -1 && getPackageManager().getPackagesForUid(mUid) == null) {
|
||||
// App isn't around anymore, must have been removed.
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDependents(int importance) {
|
||||
protected void updateDependents(int importance) {
|
||||
final boolean lockscreenSecure = new LockPatternUtils(getActivity()).isSecure(
|
||||
UserHandle.myUserId());
|
||||
final boolean lockscreenNotificationsEnabled = getLockscreenNotificationsEnabled();
|
||||
@@ -193,16 +108,6 @@ public class TopicNotificationSettings extends SettingsPreferenceFragment {
|
||||
&& lockscreenSecure && lockscreenNotificationsEnabled && allowPrivate);
|
||||
}
|
||||
|
||||
private void setVisible(Preference p, boolean visible) {
|
||||
final boolean isVisible = getPreferenceScreen().findPreference(p.getKey()) != null;
|
||||
if (isVisible == visible) return;
|
||||
if (visible) {
|
||||
getPreferenceScreen().addPreference(p);
|
||||
} else {
|
||||
getPreferenceScreen().removePreference(p);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getLockscreenNotificationsEnabled() {
|
||||
return Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
|
||||
@@ -212,9 +117,4 @@ public class TopicNotificationSettings extends SettingsPreferenceFragment {
|
||||
return Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0;
|
||||
}
|
||||
|
||||
private void toastAndFinish() {
|
||||
Toast.makeText(mContext, R.string.app_not_found_dlg_text, Toast.LENGTH_SHORT).show();
|
||||
getActivity().finish();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user