Move 'show hidden channels' option

Make it more prominent to make it more clear what's happening
when you unblock an app

Test: DeletedChannelsPreferenceControllerTest
Test: ShowMorePreferenceControllerTest
Flag: com.android.server.notification.notification_hide_unused_channels
Bug: 322536537
Change-Id: I745b2037b4dc907a4307fa7f70ecc3a4c9db2dd2
This commit is contained in:
Julia Reynolds
2024-06-25 16:46:41 -04:00
parent add6f2d24f
commit 477ebd25f2
9 changed files with 227 additions and 45 deletions

View File

@@ -21,6 +21,8 @@ import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_CACHED;
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC;
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED_BY_ANY_LAUNCHER;
import static com.android.server.notification.Flags.notificationHideUnusedChannels;
import android.app.INotificationManager;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
@@ -78,6 +80,9 @@ public class NotificationBackend {
public AppRow loadAppRow(Context context, PackageManager pm, ApplicationInfo app) {
final AppRow row = new AppRow();
if (notificationHideUnusedChannels()) {
row.showAllChannels = false;
}
row.pkg = app.packageName;
row.uid = app.uid;
try {
@@ -686,5 +691,6 @@ public class NotificationBackend {
public int channelCount;
public Map<String, NotificationsSentState> sentByChannel;
public NotificationsSentState sentByApp;
public boolean showAllChannels = true;
}
}

View File

@@ -16,16 +16,10 @@
package com.android.settings.notification.app;
import static com.android.server.notification.Flags.notificationHideUnusedChannels;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
@@ -107,38 +101,8 @@ public class AppNotificationSettings extends NotificationSettings {
mControllers.add(new BubbleSummaryPreferenceController(context, mBackend));
mControllers.add(new NotificationsOffPreferenceController(context));
mControllers.add(new DeletedChannelsPreferenceController(context, mBackend));
mControllers.add(new ShowMorePreferenceController(
context, mDependentFieldListener, mBackend));
return new ArrayList<>(mControllers);
}
private final int SHOW_ALL_CHANNELS = 1;
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if (notificationHideUnusedChannels()) {
menu.add(Menu.NONE, SHOW_ALL_CHANNELS, Menu.NONE,
mShowAll ? R.string.hide_unused_channels : R.string.show_unused_channels);
}
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (!notificationHideUnusedChannels()) {
return super.onOptionsItemSelected(item);
}
switch (item.getItemId()) {
case SHOW_ALL_CHANNELS:
mShowAll = !mShowAll;
item.setTitle(mShowAll
? R.string.hide_unused_channels
: R.string.show_unused_channels);
ChannelListPreferenceController list =
use(ChannelListPreferenceController.class);
list.setShowAll(mShowAll);
list.updateState(findPreference(list.getPreferenceKey()));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

View File

@@ -59,8 +59,6 @@ public class ChannelListPreferenceController extends NotificationPreferenceContr
private List<NotificationChannelGroup> mChannelGroupList;
private PreferenceCategory mPreference;
private boolean mShowAll;
public ChannelListPreferenceController(Context context, NotificationBackend backend) {
super(context, backend);
}
@@ -100,7 +98,7 @@ public class ChannelListPreferenceController extends NotificationPreferenceContr
@Override
protected Void doInBackground(Void... unused) {
if (notificationHideUnusedChannels()) {
if (mShowAll) {
if (mAppRow.showAllChannels) {
mChannelGroupList = mBackend.getGroups(mAppRow.pkg, mAppRow.uid).getList();
} else {
mChannelGroupList = mBackend.getGroupsWithRecentBlockedFilter(mAppRow.pkg,
@@ -123,10 +121,6 @@ public class ChannelListPreferenceController extends NotificationPreferenceContr
}.execute();
}
protected void setShowAll(boolean showAll) {
mShowAll = showAll;
}
/**
* Update the preferences group to match the
* @param groupPrefsList

View File

@@ -16,6 +16,8 @@
package com.android.settings.notification.app;
import static com.android.server.notification.Flags.notificationHideUnusedChannels;
import android.content.Context;
import androidx.preference.Preference;
@@ -44,6 +46,9 @@ public class DeletedChannelsPreferenceController extends NotificationPreferenceC
if (!super.isAvailable()) {
return false;
}
if (notificationHideUnusedChannels()) {
return false;
}
// only visible on app screen
if (mChannel != null || hasValidGroup()) {
return false;

View File

@@ -0,0 +1,75 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification.app;
import static com.android.server.notification.Flags.notificationHideUnusedChannels;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.notification.NotificationBackend;
import org.jetbrains.annotations.NotNull;
public class ShowMorePreferenceController extends NotificationPreferenceController {
private static final String KEY = "more";
private NotificationSettings.DependentFieldListener mDependentFieldListener;
public ShowMorePreferenceController(Context context,
NotificationSettings.DependentFieldListener dependentFieldListener,
NotificationBackend backend) {
super(context, backend);
mDependentFieldListener = dependentFieldListener;
}
@Override
public String getPreferenceKey() {
return KEY;
}
@Override
public boolean isAvailable() {
if (!notificationHideUnusedChannels()) {
return false;
}
if (mAppRow == null) {
return false;
}
if (mAppRow.banned || mAppRow.showAllChannels) {
return false;
}
return true;
}
@Override
boolean isIncludedInFilter() {
return false;
}
@Override
public void updateState(Preference preference) {
preference.setOnPreferenceClickListener(preference1 -> {
mAppRow.showAllChannels = true;
mDependentFieldListener.onFieldValueChanged();
return true;
});
}
}