Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 920a2547 authored by Michael Bestas's avatar Michael Bestas Committed by jrior001
Browse files

Revert "Adding Notification Channel"

* This is apparently causing issues for many users,
  while using plain old notifications doesn't.
  Setting API to 27 is also not helping, so just
  roll back to what AOSP shipped.

This reverts commit 3d59c126.

Change-Id: I4b6914f7fd1a1afc13cc38241ae8e5677e6620ea
parent 05072614
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -33,8 +33,4 @@
    <!-- Setting title for accessing the cLock widget settings -->
    <string name="menu_item_widget_settings">Widget settings</string>

    <!-- Notification channels -->
    <string name="channel_default">Others</string>
    <string name="channel_expired_events">Firing alarms &amp; timers</string>
    <string name="channel_important">Important notifications</string>
</resources>
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ public class DeskClockApplication extends Application {

        final Context applicationContext = getApplicationContext();
        final SharedPreferences prefs = getDefaultSharedPreferences(applicationContext);

        DataModel.getDataModel().init(applicationContext, prefs);
        UiDataModel.getUiDataModel().init(applicationContext, prefs);
        Controller.getController().setContext(applicationContext);
+0 −158
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.deskclock;

import android.annotation.TargetApi;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build.VERSION_CODES;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.annotation.StringDef;
import android.support.v4.app.NotificationCompat;
import android.support.v4.os.BuildCompat;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Contains info on how to create {@link NotificationChannel
 * NotificationChannels}
 */
public class NotificationChannelManager {

    private static NotificationChannelManager sInstance;

    public static NotificationChannelManager getInstance() {
        if (sInstance == null) {
            sInstance = new NotificationChannelManager();
        }
        return sInstance;
    }

    /**
     * Set the channel of notification appropriately. Will create the channel if
     * it does not already exist. Safe to call pre-O (will no-op).
     */
    @TargetApi(26)
    public static void applyChannel(@NonNull NotificationCompat.Builder notification,
            @NonNull Context context, @Channel String channelId) {
        if (!BuildCompat.isAtLeastO()) {
            return;
        }

        NotificationChannel channel = NotificationChannelManager
                .getInstance().getChannel(context, channelId);
        notification.setChannelId(channel.getId());
    }

    /** The base Channel IDs for {@link NotificationChannel} */
    @Retention(RetentionPolicy.SOURCE)
    @StringDef({ Channel.EVENT_EXPIRED, Channel.HIGH_NOTIFICATION,
            Channel.DEFAULT_NOTIFICATION })
    public @interface Channel {
        String EVENT_EXPIRED = "eventExpire";
        String HIGH_NOTIFICATION = "highNotif";
        String DEFAULT_NOTIFICATION = "defaultNotif";
    }

    @Channel
    private static final String[] allChannels = new String[] {
            Channel.EVENT_EXPIRED,
            Channel.HIGH_NOTIFICATION,
            Channel.DEFAULT_NOTIFICATION
    };

    @NonNull
    @RequiresApi(26)
    private NotificationChannel getChannel(@NonNull Context context,
            @Channel String channelId) {
        NotificationChannel channel = getNotificationManager(context)
                .getNotificationChannel(channelId);
        if (channel == null) {
            channel = createChannel(context, channelId);
        }
        return channel;
    }

    @RequiresApi(26)
    private NotificationChannel createChannel(Context context,
            @Channel String channelId) {
        Uri silentRingtone = Uri.EMPTY;
        CharSequence name;
        int importance;
        boolean canShowBadge;
        boolean lights;
        boolean vibration;
        boolean dnd;
        Uri sound;

        switch (channelId) {
        case Channel.EVENT_EXPIRED:
            name = context.getString(R.string.channel_expired_events);
            importance = NotificationManager.IMPORTANCE_HIGH;
            canShowBadge = false;
            lights = false;
            vibration = false;
            sound = null;
            dnd = true;
            break;

        case Channel.HIGH_NOTIFICATION:
            name = context.getString(R.string.channel_important);
            importance = NotificationManager.IMPORTANCE_DEFAULT;
            canShowBadge = false;
            lights = false;
            vibration = false;
            sound = null;
            dnd = true;
            break;

        case Channel.DEFAULT_NOTIFICATION:
            name = context.getString(R.string.channel_default);
            importance = NotificationManager.IMPORTANCE_LOW;
            canShowBadge = false;
            lights = false;
            vibration = false;
            sound = null;
            dnd = true;
            break;

        default:
            throw new IllegalArgumentException("Unknown channel: " + channelId);
        }
        NotificationChannel channel = new NotificationChannel(channelId, name,
                importance);
        channel.setShowBadge(canShowBadge);
        channel.enableVibration(vibration);
        channel.setSound(sound, null);
        channel.enableLights(lights);
        channel.setBypassDnd(dnd);

        getNotificationManager(context).createNotificationChannel(channel);
        return channel;
    }

    private static NotificationManager getNotificationManager(
            @NonNull Context context) {
        return context.getSystemService(NotificationManager.class);
    }
}
+7 −17
Original line number Diff line number Diff line
@@ -33,8 +33,6 @@ import com.android.deskclock.AlarmClockFragment;
import com.android.deskclock.AlarmUtils;
import com.android.deskclock.DeskClock;
import com.android.deskclock.LogUtils;
import com.android.deskclock.NotificationChannelManager;
import com.android.deskclock.NotificationChannelManager.Channel;
import com.android.deskclock.R;
import com.android.deskclock.Utils;
import com.android.deskclock.provider.Alarm;
@@ -88,8 +86,7 @@ public final class AlarmNotifications {
            AlarmInstance instance) {
        LogUtils.v("Displaying low priority notification for alarm instance: " + instance.mId);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context,
                Channel.DEFAULT_NOTIFICATION)
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setShowWhen(false)
                .setContentTitle(context.getString(
                        R.string.alarm_alert_predismiss_title))
@@ -138,8 +135,7 @@ public final class AlarmNotifications {
            AlarmInstance instance) {
        LogUtils.v("Displaying high priority notification for alarm instance: " + instance.mId);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context,
                Channel.HIGH_NOTIFICATION)
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setShowWhen(false)
                .setContentTitle(context.getString(R.string.alarm_alert_predismiss_title))
                .setContentText(AlarmUtils.getAlarmText(context, instance, true /* includeLabel */))
@@ -247,7 +243,7 @@ public final class AlarmNotifications {
        Notification summary = getActiveGroupSummaryNotification(context, UPCOMING_GROUP_KEY);
        if (summary == null
                || !Objects.equals(summary.contentIntent, firstUpcoming.contentIntent)) {
            summary = new NotificationCompat.Builder(context, Channel.HIGH_NOTIFICATION)
            summary = new NotificationCompat.Builder(context)
                    .setShowWhen(false)
                    .setContentIntent(firstUpcoming.contentIntent)
                    .setColor(ContextCompat.getColor(context, R.color.default_background))
@@ -281,7 +277,7 @@ public final class AlarmNotifications {
        Notification summary = getActiveGroupSummaryNotification(context, MISSED_GROUP_KEY);
        if (summary == null
                || !Objects.equals(summary.contentIntent, firstMissed.contentIntent)) {
            summary = new NotificationCompat.Builder(context, Channel.HIGH_NOTIFICATION)
            summary = new NotificationCompat.Builder(context)
                    .setShowWhen(false)
                    .setContentIntent(firstMissed.contentIntent)
                    .setColor(ContextCompat.getColor(context, R.color.default_background))
@@ -301,8 +297,7 @@ public final class AlarmNotifications {
            AlarmInstance instance) {
        LogUtils.v("Displaying snoozed notification for alarm instance: " + instance.mId);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context,
                Channel.HIGH_NOTIFICATION)
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setShowWhen(false)
                .setContentTitle(instance.getLabelOrDefault(context))
                .setContentText(context.getString(R.string.alarm_alert_snooze_until,
@@ -346,9 +341,7 @@ public final class AlarmNotifications {

        String label = instance.mLabel;
        String alarmTime = AlarmUtils.getFormattedTime(context, instance.getAlarmTime());

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context,
                Channel.HIGH_NOTIFICATION)
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setShowWhen(false)
                .setContentTitle(context.getString(R.string.alarm_missed_title))
                .setContentText(instance.mLabel.isEmpty() ? alarmTime :
@@ -391,9 +384,7 @@ public final class AlarmNotifications {
        LogUtils.v("Displaying alarm notification for alarm instance: " + instance.mId);

        Resources resources = service.getResources();

        NotificationCompat.Builder notification = new NotificationCompat.Builder(service,
                Channel.EVENT_EXPIRED)
        NotificationCompat.Builder notification = new NotificationCompat.Builder(service)
                .setContentTitle(instance.getLabelOrDefault(service))
                .setContentText(AlarmUtils.getFormattedTime(service, instance.getAlarmTime()))
                .setColor(ContextCompat.getColor(service, R.color.default_background))
@@ -443,7 +434,6 @@ public final class AlarmNotifications {
                true);
        notification.setPriority(NotificationCompat.PRIORITY_MAX);

        NotificationChannelManager.applyChannel(notification, service, Channel.EVENT_EXPIRED);
        clearNotification(service, instance);
        service.startForeground(ALARM_FIRING_NOTIFICATION_ID, notification.build());
    }
+0 −3
Original line number Diff line number Diff line
@@ -33,8 +33,6 @@ import android.widget.RemoteViews;
import com.android.deskclock.R;
import com.android.deskclock.Utils;
import com.android.deskclock.events.Events;
import com.android.deskclock.NotificationChannelManager.Channel;
import com.android.deskclock.NotificationChannelManager;
import com.android.deskclock.stopwatch.StopwatchService;

import java.util.ArrayList;
@@ -140,7 +138,6 @@ class StopwatchNotificationBuilder {
                .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
                .setColor(ContextCompat.getColor(context, R.color.default_background));

        NotificationChannelManager.applyChannel(notification, context, Channel.HIGH_NOTIFICATION);
        if (Utils.isNOrLater()) {
            notification.setGroup(nm.getStopwatchNotificationGroupKey());
        }
Loading