Link back to app settings from channel page

Test: manual
Change-Id: Ieb1118bd662a662bd34027f2ef44b420d4c94183
This commit is contained in:
Julia Reynolds
2017-02-09 10:06:34 -05:00
parent fd1e070118
commit e971015fd9
3 changed files with 63 additions and 46 deletions

View File

@@ -61,11 +61,6 @@ public class AppNotificationSettings extends NotificationSettingsBase {
private static final String TAG = "AppNotificationSettings";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
private static final Intent APP_NOTIFICATION_PREFS_CATEGORY_INTENT
= new Intent(Intent.ACTION_MAIN)
.addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES);
private static final String KEY_CHANNELS = "channels";
private static final String KEY_BLOCK = "block";
private DashboardFeatureProvider mDashboardFeatureProvider;
@@ -270,46 +265,6 @@ public class AppNotificationSettings extends NotificationSettingsBase {
setVisible(mBadge, !banned);
}
private List<ResolveInfo> queryNotificationConfigActivities() {
if (DEBUG) Log.d(TAG, "APP_NOTIFICATION_PREFS_CATEGORY_INTENT is "
+ APP_NOTIFICATION_PREFS_CATEGORY_INTENT);
final List<ResolveInfo> resolveInfos = mPm.queryIntentActivities(
APP_NOTIFICATION_PREFS_CATEGORY_INTENT,
0 //PackageManager.MATCH_DEFAULT_ONLY
);
return resolveInfos;
}
private void collectConfigActivities(ArrayMap<String, AppRow> rows) {
final List<ResolveInfo> resolveInfos = queryNotificationConfigActivities();
applyConfigActivities(rows, resolveInfos);
}
private void applyConfigActivities(ArrayMap<String, AppRow> rows,
List<ResolveInfo> resolveInfos) {
if (DEBUG) Log.d(TAG, "Found " + resolveInfos.size() + " preference activities"
+ (resolveInfos.size() == 0 ? " ;_;" : ""));
for (ResolveInfo ri : resolveInfos) {
final ActivityInfo activityInfo = ri.activityInfo;
final ApplicationInfo appInfo = activityInfo.applicationInfo;
final AppRow row = rows.get(appInfo.packageName);
if (row == null) {
if (DEBUG) Log.v(TAG, "Ignoring notification preference activity ("
+ activityInfo.name + ") for unknown package "
+ activityInfo.packageName);
continue;
}
if (row.settingsIntent != null) {
if (DEBUG) Log.v(TAG, "Ignoring duplicate notification preference activity ("
+ activityInfo.name + ") for package "
+ activityInfo.packageName);
continue;
}
row.settingsIntent = new Intent(APP_NOTIFICATION_PREFS_CATEGORY_INTENT)
.setClassName(activityInfo.packageName, activityInfo.name);
}
}
private Comparator<NotificationChannel> mChannelComparator =
new Comparator<NotificationChannel>() {
private final Collator sCollator = Collator.getInstance();

View File

@@ -35,6 +35,7 @@ import android.provider.Settings;
import android.service.notification.NotificationListenerService.Ranking;
import android.support.v7.preference.Preference;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -98,6 +99,12 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
FeatureFactory.getFactory(activity).getDashboardFeatureProvider(activity);
addPreferencesFromResource(R.xml.channel_notification_settings);
// load settings intent
ArrayMap<String, NotificationBackend.AppRow>
rows = new ArrayMap<String, NotificationBackend.AppRow>();
rows.put(mAppRow.pkg, mAppRow);
collectConfigActivities(rows);
mBlock = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BLOCK);
mBadge = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BADGE);
mImportance = (RestrictedDropDownPreference) findPreference(KEY_IMPORTANCE);
@@ -127,8 +134,9 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
.setSummary(mAppRow.label)
.setPackageName(mAppRow.pkg)
.setUid(mAppRow.uid)
.setAppNotifPrefIntent(mAppRow.settingsIntent)
.setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
AppHeaderController.ActionType.ACTION_NONE)
AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
.done(getPrefContext());
getPreferenceScreen().addPreference(pref);
}

View File

@@ -23,28 +23,39 @@ import com.android.settings.applications.AppInfoBase;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;
import android.widget.Toast;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import java.util.List;
abstract public class NotificationSettingsBase extends SettingsPreferenceFragment {
private static final String TAG = "NotifiSettingsBase";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
private static final Intent APP_NOTIFICATION_PREFS_CATEGORY_INTENT
= new Intent(Intent.ACTION_MAIN)
.addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES);
protected static final String KEY_BLOCK = "block";
protected static final String KEY_BADGE = "badge";
@@ -155,6 +166,49 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
getActivity().finish();
}
private List<ResolveInfo> queryNotificationConfigActivities() {
if (DEBUG) Log.d(TAG, "APP_NOTIFICATION_PREFS_CATEGORY_INTENT is "
+ APP_NOTIFICATION_PREFS_CATEGORY_INTENT);
final List<ResolveInfo> resolveInfos = mPm.queryIntentActivities(
APP_NOTIFICATION_PREFS_CATEGORY_INTENT,
0 //PackageManager.MATCH_DEFAULT_ONLY
);
return resolveInfos;
}
protected void collectConfigActivities(ArrayMap<String, NotificationBackend.AppRow> rows) {
final List<ResolveInfo> resolveInfos = queryNotificationConfigActivities();
applyConfigActivities(rows, resolveInfos);
}
private void applyConfigActivities(ArrayMap<String, NotificationBackend.AppRow> rows,
List<ResolveInfo> resolveInfos) {
if (DEBUG) Log.d(TAG, "Found " + resolveInfos.size() + " preference activities"
+ (resolveInfos.size() == 0 ? " ;_;" : ""));
for (ResolveInfo ri : resolveInfos) {
final ActivityInfo activityInfo = ri.activityInfo;
final ApplicationInfo appInfo = activityInfo.applicationInfo;
final NotificationBackend.AppRow row = rows.get(appInfo.packageName);
if (row == null) {
if (DEBUG) Log.v(TAG, "Ignoring notification preference activity ("
+ activityInfo.name + ") for unknown package "
+ activityInfo.packageName);
continue;
}
if (row.settingsIntent != null) {
if (DEBUG) Log.v(TAG, "Ignoring duplicate notification preference activity ("
+ activityInfo.name + ") for package "
+ activityInfo.packageName);
continue;
}
row.settingsIntent = new Intent(APP_NOTIFICATION_PREFS_CATEGORY_INTENT)
.setClassName(activityInfo.packageName, activityInfo.name);
if (mChannel != null) {
row.settingsIntent.putExtra(Notification.EXTRA_CHANNEL_ID, mChannel.getId());
}
}
}
private PackageInfo findPackageInfo(String pkg, int uid) {
if (pkg == null || uid < 0) {
return null;