Search in sources :

Example 21 with NotificationChannelGroup

use of android.app.NotificationChannelGroup in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DescriptionPreferenceControllerTest method testIsAvailable_notIfNoChannelGroupDesc.

@Test
public void testIsAvailable_notIfNoChannelGroupDesc() {
    NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
    NotificationChannelGroup group = mock(NotificationChannelGroup.class);
    mController.onResume(appRow, null, group, null);
    assertFalse(mController.isAvailable());
}
Also used : NotificationChannelGroup(android.app.NotificationChannelGroup) Test(org.junit.Test)

Example 22 with NotificationChannelGroup

use of android.app.NotificationChannelGroup in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BlockPreferenceControllerTest method testUpdateState_group.

@Test
public void testUpdateState_group() {
    NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
    NotificationChannelGroup group = mock(NotificationChannelGroup.class);
    when(group.isBlocked()).thenReturn(true);
    mController.onResume(appRow, null, group, null);
    mController.updateState(mPreference);
    assertFalse(mSwitch.isChecked());
    appRow.banned = true;
    mController.onResume(appRow, null, group, null);
    when(group.isBlocked()).thenReturn(true);
    mController.updateState(mPreference);
    assertFalse(mSwitch.isChecked());
    appRow.banned = false;
    mController.onResume(appRow, null, group, null);
    when(group.isBlocked()).thenReturn(false);
    mController.updateState(mPreference);
    assertTrue(mSwitch.isChecked());
}
Also used : NotificationChannelGroup(android.app.NotificationChannelGroup) Test(org.junit.Test)

Example 23 with NotificationChannelGroup

use of android.app.NotificationChannelGroup in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationChannelSlice method getDisplayableChannels.

private List<NotificationChannel> getDisplayableChannels(NotificationBackend.AppRow appRow) {
    final List<NotificationChannelGroup> channelGroupList = mNotificationBackend.getGroups(appRow.pkg, appRow.uid).getList();
    final List<NotificationChannel> channels = channelGroupList.stream().flatMap(group -> group.getChannels().stream().filter(channel -> isChannelEnabled(group, channel, appRow))).collect(Collectors.toList());
    // Pack the notification channel with notification sent state for sorting.
    final List<NotificationChannelState> channelStates = new ArrayList<>();
    for (NotificationChannel channel : channels) {
        NotificationsSentState sentState = appRow.sentByChannel.get(channel.getId());
        if (sentState == null) {
            sentState = new NotificationsSentState();
        }
        channelStates.add(new NotificationChannelState(sentState, channel));
    }
    // Sort the notification channels with notification sent count by descending.
    return channelStates.stream().sorted(CHANNEL_STATE_COMPARATOR).map(state -> state.getNotificationChannel()).limit(DEFAULT_EXPANDED_ROW_COUNT).collect(Collectors.toList());
}
Also used : NotificationChannel(android.app.NotificationChannel) Bundle(android.os.Bundle) EXTRA_TOGGLE_STATE(android.app.slice.Slice.EXTRA_TOGGLE_STATE) PackageManager(android.content.pm.PackageManager) ListBuilder(androidx.slice.builders.ListBuilder) Uri(android.net.Uri) TimeoutException(java.util.concurrent.TimeoutException) PendingIntent(android.app.PendingIntent) Drawable(android.graphics.drawable.Drawable) SubSettings(com.android.settings.SubSettings) Future(java.util.concurrent.Future) NotificationChannel(android.app.NotificationChannel) Log(android.util.Log) R(com.android.settings.R) SliceAction(androidx.slice.builders.SliceAction) Collectors(java.util.stream.Collectors) CustomSliceable(com.android.settings.slices.CustomSliceable) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) List(java.util.List) Application(android.app.Application) Utils(com.android.settings.Utils) RestrictedLockUtilsInternal(com.android.settingslib.RestrictedLockUtilsInternal) NotificationBackend(com.android.settings.notification.NotificationBackend) AppNotificationSettings(com.android.settings.notification.AppNotificationSettings) IMPORTANCE_NONE(android.app.NotificationManager.IMPORTANCE_NONE) Context(android.content.Context) Slice(androidx.slice.Slice) Intent(android.content.Intent) NotificationsSentState(com.android.settings.notification.NotificationBackend.NotificationsSentState) PackageInfo(android.content.pm.PackageInfo) ArrayList(java.util.ArrayList) AppInfoBase(com.android.settings.applications.AppInfoBase) IMPORTANCE_LOW(android.app.NotificationManager.IMPORTANCE_LOW) ChannelNotificationSettings(com.android.settings.notification.ChannelNotificationSettings) AppAndNotificationDashboardFragment(com.android.settings.applications.AppAndNotificationDashboardFragment) UserHandle(android.os.UserHandle) SliceBroadcastReceiver(com.android.settings.slices.SliceBroadcastReceiver) Settings(android.provider.Settings) SliceBuilderUtils(com.android.settings.slices.SliceBuilderUtils) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) RestrictedLockUtils(com.android.settingslib.RestrictedLockUtils) SettingsEnums(android.app.settings.SettingsEnums) TextUtils(android.text.TextUtils) NotificationChannelGroup(android.app.NotificationChannelGroup) ApplicationsState(com.android.settingslib.applications.ApplicationsState) ThreadUtils(com.android.settingslib.utils.ThreadUtils) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) IconCompat(androidx.core.graphics.drawable.IconCompat) CustomSliceRegistry(com.android.settings.slices.CustomSliceRegistry) Comparator(java.util.Comparator) NotificationChannelGroup(android.app.NotificationChannelGroup) NotificationsSentState(com.android.settings.notification.NotificationBackend.NotificationsSentState) ArrayList(java.util.ArrayList)

Example 24 with NotificationChannelGroup

use of android.app.NotificationChannelGroup in project Signal-Android by signalapp.

the class NotificationChannels method onCreate.

@TargetApi(26)
private static void onCreate(@NonNull Context context, @NonNull NotificationManager notificationManager) {
    NotificationChannelGroup messagesGroup = new NotificationChannelGroup(CATEGORY_MESSAGES, context.getResources().getString(R.string.NotificationChannel_group_chats));
    notificationManager.createNotificationChannelGroup(messagesGroup);
    NotificationChannel messages = new NotificationChannel(getMessagesChannel(context), context.getString(R.string.NotificationChannel_channel_messages), NotificationManager.IMPORTANCE_HIGH);
    NotificationChannel calls = new NotificationChannel(CALLS, context.getString(R.string.NotificationChannel_calls), NotificationManager.IMPORTANCE_HIGH);
    NotificationChannel failures = new NotificationChannel(FAILURES, context.getString(R.string.NotificationChannel_failures), NotificationManager.IMPORTANCE_HIGH);
    NotificationChannel backups = new NotificationChannel(BACKUPS, context.getString(R.string.NotificationChannel_backups), NotificationManager.IMPORTANCE_LOW);
    NotificationChannel lockedStatus = new NotificationChannel(LOCKED_STATUS, context.getString(R.string.NotificationChannel_locked_status), NotificationManager.IMPORTANCE_LOW);
    NotificationChannel other = new NotificationChannel(OTHER, context.getString(R.string.NotificationChannel_other), NotificationManager.IMPORTANCE_LOW);
    NotificationChannel voiceNotes = new NotificationChannel(VOICE_NOTES, context.getString(R.string.NotificationChannel_voice_notes), NotificationManager.IMPORTANCE_LOW);
    NotificationChannel joinEvents = new NotificationChannel(JOIN_EVENTS, context.getString(R.string.NotificationChannel_contact_joined_signal), NotificationManager.IMPORTANCE_DEFAULT);
    NotificationChannel background = new NotificationChannel(BACKGROUND, context.getString(R.string.NotificationChannel_background_connection), getDefaultBackgroundChannelImportance(notificationManager));
    NotificationChannel callStatus = new NotificationChannel(CALL_STATUS, context.getString(R.string.NotificationChannel_call_status), NotificationManager.IMPORTANCE_LOW);
    messages.setGroup(CATEGORY_MESSAGES);
    setVibrationEnabled(messages, SignalStore.settings().isMessageVibrateEnabled());
    messages.setSound(SignalStore.settings().getMessageNotificationSound(), getRingtoneAudioAttributes());
    setLedPreference(messages, SignalStore.settings().getMessageLedColor());
    calls.setShowBadge(false);
    backups.setShowBadge(false);
    lockedStatus.setShowBadge(false);
    other.setShowBadge(false);
    setVibrationEnabled(other, false);
    voiceNotes.setShowBadge(false);
    joinEvents.setShowBadge(false);
    background.setShowBadge(false);
    callStatus.setShowBadge(false);
    notificationManager.createNotificationChannels(Arrays.asList(messages, calls, failures, backups, lockedStatus, other, voiceNotes, joinEvents, background, callStatus));
    if (BuildConfig.PLAY_STORE_DISABLED) {
        NotificationChannel appUpdates = new NotificationChannel(APP_UPDATES, context.getString(R.string.NotificationChannel_app_updates), NotificationManager.IMPORTANCE_HIGH);
        notificationManager.createNotificationChannel(appUpdates);
    } else {
        notificationManager.deleteNotificationChannel(APP_UPDATES);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup) TargetApi(android.annotation.TargetApi)

Example 25 with NotificationChannelGroup

use of android.app.NotificationChannelGroup in project xDrip by NightscoutFoundation.

the class NotificationChannels method getChan.

@TargetApi(26)
public static NotificationChannel getChan(NotificationCompat.Builder wip) {
    final Notification temp = wip.build();
    if (temp.getChannelId() == null)
        return null;
    // create generic audio attributes
    final AudioAttributes generic_audio = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN).build();
    // create notification channel for hashing purposes from the existing notification builder
    NotificationChannel template = new NotificationChannel(temp.getChannelId(), getString(temp.getChannelId()), NotificationManager.IMPORTANCE_DEFAULT);
    // mirror the notification parameters in the channel
    template.setGroup(temp.getChannelId());
    template.setVibrationPattern(wip.mNotification.vibrate);
    template.setSound(wip.mNotification.sound, generic_audio);
    template.setLightColor(wip.mNotification.ledARGB);
    if ((wip.mNotification.ledOnMS != 0) && (wip.mNotification.ledOffMS != 0))
        // weird how this doesn't work like vibration pattern
        template.enableLights(true);
    template.setDescription(temp.getChannelId() + " " + wip.hashCode());
    // get a nice string to identify the hash
    final String mhash = my_text_hash(template);
    // create another notification channel using the hash because id is immutable
    final NotificationChannel channel = new NotificationChannel(template.getId() + mhash, getString(temp.getChannelId()) + mhash, NotificationManager.IMPORTANCE_DEFAULT);
    // mirror the settings from the previous channel
    channel.setSound(template.getSound(), generic_audio);
    if (addChannelGroup()) {
        channel.setGroup(template.getGroup());
    } else {
        channel.setGroup(channel.getId());
    }
    channel.setDescription(template.getDescription());
    channel.setVibrationPattern(template.getVibrationPattern());
    template.setLightColor(wip.mNotification.ledARGB);
    if ((wip.mNotification.ledOnMS != 0) && (wip.mNotification.ledOffMS != 0))
        // weird how this doesn't work like vibration pattern
        template.enableLights(true);
    template.setDescription(temp.getChannelId() + " " + wip.hashCode());
    // create a group to hold this channel if one doesn't exist or update text
    getNotifManager().createNotificationChannelGroup(new NotificationChannelGroup(channel.getGroup(), getString(channel.getGroup())));
    // create this channel if it doesn't exist or update text
    getNotifManager().createNotificationChannel(channel);
    return channel;
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup) AudioAttributes(android.media.AudioAttributes) Notification(android.app.Notification) TargetApi(android.annotation.TargetApi)

Aggregations

NotificationChannelGroup (android.app.NotificationChannelGroup)46 NotificationChannel (android.app.NotificationChannel)31 Test (org.junit.Test)20 TargetApi (android.annotation.TargetApi)8 Preference (android.support.v7.preference.Preference)6 PreferenceCategory (android.support.v7.preference.PreferenceCategory)6 LayoutPreference (com.android.settings.applications.LayoutPreference)6 MasterSwitchPreference (com.android.settings.widget.MasterSwitchPreference)6 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)6 FooterPreference (com.android.settingslib.widget.FooterPreference)6 NotificationManager (android.app.NotificationManager)5 Notification (android.app.Notification)4 AudioAttributes (android.media.AudioAttributes)4 ArrayList (java.util.ArrayList)4 Context (android.content.Context)2 Uri (android.net.Uri)2 RequiresApi (androidx.annotation.RequiresApi)2 Preference (androidx.preference.Preference)2 JSONObject (org.json.JSONObject)2 Application (android.app.Application)1