summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/notification
diff options
context:
space:
mode:
authorEric Erfanian <erfanian@google.com>2017-03-15 14:41:07 -0700
committerEric Erfanian <erfanian@google.com>2017-03-15 16:24:23 -0700
commitd5e47f6da5b08b13ecdfa7f1edc7e12aeb83fab9 (patch)
treeb54abbb51fb7d66e7755a1fbb5db023ff601090b /java/com/android/dialer/notification
parent30436e7e6d3f2c8755a91b2b6222b74d465a9e87 (diff)
Update Dialer source from latest green build.
* Refactor voicemail component * Add new enriched calling components Test: treehugger, manual aosp testing Change-Id: I521a0f86327d4b42e14d93927c7d613044ed5942
Diffstat (limited to 'java/com/android/dialer/notification')
-rw-r--r--java/com/android/dialer/notification/AndroidManifest.xml21
-rw-r--r--java/com/android/dialer/notification/GroupedNotificationUtil.java66
-rw-r--r--java/com/android/dialer/notification/NotificationChannelManager.java232
-rw-r--r--java/com/android/dialer/notification/res/values/ids.xml27
-rw-r--r--java/com/android/dialer/notification/res/values/strings.xml25
5 files changed, 371 insertions, 0 deletions
diff --git a/java/com/android/dialer/notification/AndroidManifest.xml b/java/com/android/dialer/notification/AndroidManifest.xml
new file mode 100644
index 000000000..c5484f263
--- /dev/null
+++ b/java/com/android/dialer/notification/AndroidManifest.xml
@@ -0,0 +1,21 @@
+<!--
+ ~ 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
+ -->
+
+<manifest
+ package="com.android.dialer.notification"
+ xmlns:android="http://schemas.android.com/apk/res/android">
+ <uses-sdk android:minSdkVersion="23" />
+</manifest>
diff --git a/java/com/android/dialer/notification/GroupedNotificationUtil.java b/java/com/android/dialer/notification/GroupedNotificationUtil.java
new file mode 100644
index 000000000..63ea51739
--- /dev/null
+++ b/java/com/android/dialer/notification/GroupedNotificationUtil.java
@@ -0,0 +1,66 @@
+/*
+ * 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.dialer.notification;
+
+import android.app.NotificationManager;
+import android.service.notification.StatusBarNotification;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import java.util.Objects;
+
+/** Utilities for dealing with grouped notifications */
+public final class GroupedNotificationUtil {
+
+ /**
+ * Remove notification(s) that were added as part of a group. Will ensure that if this is the last
+ * notification in the group the summary will be removed.
+ *
+ * @param tag String tag as included in {@link NotificationManager#notify(String, int,
+ * android.app.Notification)}. If null will remove all notifications under id
+ * @param id notification id as included with {@link NotificationManager#notify(String, int,
+ * android.app.Notification)}.
+ * @param summaryTag String tag of the summary notification
+ */
+ public static void removeNotification(
+ @NonNull NotificationManager notificationManager,
+ @Nullable String tag,
+ int id,
+ @NonNull String summaryTag) {
+ if (tag == null) {
+ // Clear all missed call notifications
+ for (StatusBarNotification notification : notificationManager.getActiveNotifications()) {
+ if (notification.getId() == id) {
+ notificationManager.cancel(notification.getTag(), id);
+ }
+ }
+ } else {
+ notificationManager.cancel(tag, id);
+
+ // See if other non-summary missed call notifications exist, and if not then clear the summary
+ boolean clearSummary = true;
+ for (StatusBarNotification notification : notificationManager.getActiveNotifications()) {
+ if (notification.getId() == id && !Objects.equals(summaryTag, notification.getTag())) {
+ clearSummary = false;
+ break;
+ }
+ }
+ if (clearSummary) {
+ notificationManager.cancel(summaryTag, id);
+ }
+ }
+ }
+}
diff --git a/java/com/android/dialer/notification/NotificationChannelManager.java b/java/com/android/dialer/notification/NotificationChannelManager.java
new file mode 100644
index 000000000..9ff57321e
--- /dev/null
+++ b/java/com/android/dialer/notification/NotificationChannelManager.java
@@ -0,0 +1,232 @@
+/*
+ * 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.dialer.notification;
+
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationChannelGroup;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.media.AudioAttributes;
+import android.net.Uri;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.annotation.StringDef;
+import android.support.v4.os.BuildCompat;
+import android.telecom.PhoneAccount;
+import android.telecom.PhoneAccountHandle;
+import android.telecom.TelecomManager;
+import android.telephony.TelephonyManager;
+import com.android.contacts.common.compat.TelephonyManagerCompat;
+import com.android.dialer.buildtype.BuildType;
+import com.android.dialer.common.LogUtil;
+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 instance;
+
+ public static NotificationChannelManager getInstance() {
+ if (instance == null) {
+ instance = new NotificationChannelManager();
+ }
+ return instance;
+ }
+
+ /**
+ * Set the channel of notification appropriately. Will create the channel if it does not already
+ * exist. Safe to call pre-O (will no-op).
+ *
+ * <p>phoneAccount should only be null if channelName is {@link Channel#MISC}.
+ */
+ public static void applyChannel(
+ @NonNull Notification.Builder notification,
+ @NonNull Context context,
+ @Channel String channelName,
+ @Nullable PhoneAccountHandle phoneAccount) {
+ if (phoneAccount == null) {
+ if (!Channel.MISC.equals(channelName)) {
+ IllegalArgumentException exception =
+ new IllegalArgumentException(
+ "Phone account handle must not be null unless on Channel.MISC");
+ if (BuildType.get() >= BuildType.RELEASE) {
+ LogUtil.e("NotificationChannelManager.applyChannel", null, exception);
+ } else {
+ throw exception;
+ }
+ }
+ }
+
+ if (BuildCompat.isAtLeastO()) {
+ NotificationChannel channel =
+ NotificationChannelManager.getInstance().getChannel(context, channelName, phoneAccount);
+ notification.setChannel(channel.getId());
+ }
+ }
+
+ /** The base Channel IDs for {@link NotificationChannel} */
+ @Retention(RetentionPolicy.SOURCE)
+ @StringDef({
+ Channel.INCOMING_CALL,
+ Channel.ONGOING_CALL,
+ Channel.MISSED_CALL,
+ Channel.VOICEMAIL,
+ Channel.EXTERNAL_CALL,
+ Channel.MISC
+ })
+ public @interface Channel {
+ String INCOMING_CALL = "incomingCall";
+ String ONGOING_CALL = "ongoingCall";
+ String MISSED_CALL = "missedCall";
+ String VOICEMAIL = "voicemail";
+ String EXTERNAL_CALL = "externalCall";
+ String MISC = "miscellaneous";
+ }
+
+ private NotificationChannelManager() {}
+
+ private NotificationChannel getChannel(
+ @NonNull Context context,
+ @Channel String channelName,
+ @Nullable PhoneAccountHandle phoneAccount) {
+ String channelId = channelNameToId(channelName, phoneAccount);
+ NotificationChannel channel = getNotificationManager(context).getNotificationChannel(channelId);
+ if (channel == null) {
+ channel = createChannel(context, channelName, phoneAccount);
+ }
+ return channel;
+ }
+
+ private static String channelNameToId(
+ @Channel String name, @Nullable PhoneAccountHandle phoneAccountHandle) {
+ if (phoneAccountHandle == null) {
+ return name;
+ } else {
+ return name + ":" + phoneAccountHandle.getId();
+ }
+ }
+
+ private NotificationChannel createChannel(
+ Context context,
+ @Channel String channelName,
+ @Nullable PhoneAccountHandle phoneAccountHandle) {
+ String channelId = channelNameToId(channelName, phoneAccountHandle);
+
+ if (phoneAccountHandle != null) {
+ PhoneAccount account = getTelecomManager(context).getPhoneAccount(phoneAccountHandle);
+ NotificationChannelGroup group =
+ new NotificationChannelGroup(
+ phoneAccountHandle.getId(),
+ (account == null) ? phoneAccountHandle.getId() : account.getLabel().toString());
+ getNotificationManager(context)
+ .createNotificationChannelGroup(group); // No-op if already exists
+ } else if (!Channel.MISC.equals(channelName)) {
+ LogUtil.w(
+ "NotificationChannelManager.createChannel",
+ "Null PhoneAccountHandle with channel " + channelName);
+ }
+
+ Uri silentRingtone = Uri.parse("");
+
+ CharSequence name;
+ int importance;
+ boolean canShowBadge;
+ boolean lights;
+ boolean vibration;
+ Uri sound;
+ switch (channelName) {
+ case Channel.INCOMING_CALL:
+ name = context.getText(R.string.notification_channel_incoming_call);
+ importance = NotificationManager.IMPORTANCE_MAX;
+ canShowBadge = false;
+ lights = true;
+ vibration = false;
+ sound = silentRingtone;
+ break;
+ case Channel.MISSED_CALL:
+ name = context.getText(R.string.notification_channel_missed_call);
+ importance = NotificationManager.IMPORTANCE_DEFAULT;
+ canShowBadge = true;
+ lights = true;
+ vibration = true;
+ sound = silentRingtone;
+ break;
+ case Channel.ONGOING_CALL:
+ name = context.getText(R.string.notification_channel_ongoing_call);
+ importance = NotificationManager.IMPORTANCE_DEFAULT;
+ canShowBadge = false;
+ lights = false;
+ vibration = false;
+ sound = null;
+ break;
+ case Channel.VOICEMAIL:
+ name = context.getText(R.string.notification_channel_voicemail);
+ importance = NotificationManager.IMPORTANCE_DEFAULT;
+ canShowBadge = true;
+ lights = true;
+ vibration = true;
+ sound =
+ TelephonyManagerCompat.getVoicemailRingtoneUri(
+ getTelephonyManager(context), phoneAccountHandle);
+ break;
+ case Channel.EXTERNAL_CALL:
+ name = context.getText(R.string.notification_channel_external_call);
+ importance = NotificationManager.IMPORTANCE_HIGH;
+ canShowBadge = false;
+ lights = true;
+ vibration = true;
+ sound = null;
+ break;
+ case Channel.MISC:
+ name = context.getText(R.string.notification_channel_misc);
+ importance = NotificationManager.IMPORTANCE_DEFAULT;
+ canShowBadge = false;
+ lights = true;
+ vibration = true;
+ sound = null;
+ break;
+ default:
+ throw new IllegalArgumentException("Unknown channel: " + channelName);
+ }
+
+ NotificationChannel channel = new NotificationChannel(channelId, name, importance);
+ channel.setShowBadge(canShowBadge);
+ if (sound != null) {
+ channel.setSound(
+ sound,
+ new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build());
+ }
+ channel.enableLights(lights);
+ channel.enableVibration(vibration);
+ getNotificationManager(context).createNotificationChannel(channel);
+ return channel;
+ }
+
+ private static NotificationManager getNotificationManager(@NonNull Context context) {
+ return context.getSystemService(NotificationManager.class);
+ }
+
+ private static TelephonyManager getTelephonyManager(@NonNull Context context) {
+ return context.getSystemService(TelephonyManager.class);
+ }
+
+ private static TelecomManager getTelecomManager(@NonNull Context context) {
+ return context.getSystemService(TelecomManager.class);
+ }
+}
diff --git a/java/com/android/dialer/notification/res/values/ids.xml b/java/com/android/dialer/notification/res/values/ids.xml
new file mode 100644
index 000000000..6bdb489a7
--- /dev/null
+++ b/java/com/android/dialer/notification/res/values/ids.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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
+ -->
+
+<resources>
+ <item name="notification_incoming_call" type="id"/>
+ <item name="notification_ongoing_call" type="id"/>
+ <item name="notification_missed_call" type="id"/>
+ <item name="notification_voicemail" type="id"/>
+ <item name="notification_external_call" type="id"/>
+ <item name="notification_call_blocking_disabled_by_emergency_call" type="id"/>
+ <item name="notification_spam_call" type="id"/>
+ <item name="notification_feedback" type="id"/>
+</resources>
diff --git a/java/com/android/dialer/notification/res/values/strings.xml b/java/com/android/dialer/notification/res/values/strings.xml
new file mode 100644
index 000000000..2fc4962c6
--- /dev/null
+++ b/java/com/android/dialer/notification/res/values/strings.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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
+ -->
+
+<resources>
+ <string name="notification_channel_incoming_call">Incoming calls</string>
+ <string name="notification_channel_ongoing_call">Ongoing calls</string>
+ <string name="notification_channel_missed_call">Missed calls</string>
+ <string name="notification_channel_voicemail">Voicemails</string>
+ <string name="notification_channel_external_call">External calls</string>
+ <string name="notification_channel_misc">Miscellaneous</string>
+</resources>