Merge "Start to use notification channel" into ub-contactsdialer-i-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 779230f..5a7facb 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -332,6 +332,15 @@
android:name=".quickcontact.QuickContactBroadcastReceiver"
android:exported="false"/>
+ <!-- Responsible for creating notification channels when boot is completed or when app is
+ re-installed -->
+ <receiver android:name=".interactions.OnBootOrUpgradeReceiver">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED" />
+ <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
+ </intent-filter>
+ </receiver>
+
<activity-alias
android:name="ContactShortcut"
android:icon="@drawable/logo_quick_contacts_color_44in48dp"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 538336c..1ea9708 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1583,4 +1583,7 @@
<!-- The notification title shown while SIM contacts are being imported [CHAR LIMIT=40] -->
<string name="importing_sim_in_progress_title">Importing SIM</string>
+ <!-- Text shown when viewing channel settings for default Contacts notifications [CHAR LIMIT=50] -->
+ <string name="contacts_default_notification_channel">Notifications</string>
+
</resources>
diff --git a/src/com/android/contacts/SimImportService.java b/src/com/android/contacts/SimImportService.java
index f21e1e1..4d4f551 100644
--- a/src/com/android/contacts/SimImportService.java
+++ b/src/com/android/contacts/SimImportService.java
@@ -35,6 +35,7 @@
import com.android.contacts.model.SimCard;
import com.android.contacts.model.SimContact;
import com.android.contacts.model.account.AccountWithDataSet;
+import com.android.contacts.util.ContactsNotificationChannelsUtil;
import com.android.contactsbind.FeedbackHelper;
import java.util.ArrayList;
@@ -189,6 +190,7 @@
final Intent intent = new Intent(this, PeopleActivity.class);
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setOngoing(false)
+ .setChannel(ContactsNotificationChannelsUtil.DEFAULT_CHANNEL)
.setAutoCancel(true)
.setContentTitle(this.getString(R.string.importing_sim_finished_title))
.setColor(this.getResources().getColor(R.color.dialtacts_theme_color))
@@ -201,6 +203,7 @@
final Intent intent = new Intent(this, PeopleActivity.class);
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setOngoing(false)
+ .setChannel(ContactsNotificationChannelsUtil.DEFAULT_CHANNEL)
.setAutoCancel(true)
.setContentTitle(this.getString(R.string.importing_sim_failed_title))
.setContentText(this.getString(R.string.importing_sim_failed_message))
@@ -214,6 +217,7 @@
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
final String description = getString(R.string.importing_sim_in_progress_title);
builder.setOngoing(true)
+ .setChannel(ContactsNotificationChannelsUtil.DEFAULT_CHANNEL)
.setProgress(/* current */ 0, /* max */ 100, /* indeterminate */ true)
.setContentTitle(description)
.setColor(this.getResources().getColor(R.color.dialtacts_theme_color))
diff --git a/src/com/android/contacts/interactions/OnBootOrUpgradeReceiver.java b/src/com/android/contacts/interactions/OnBootOrUpgradeReceiver.java
new file mode 100644
index 0000000..5c55f20
--- /dev/null
+++ b/src/com/android/contacts/interactions/OnBootOrUpgradeReceiver.java
@@ -0,0 +1,35 @@
+/*
+ * 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.contacts.interactions;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+import com.android.contacts.util.ContactsNotificationChannelsUtil;
+
+public class OnBootOrUpgradeReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ final String action = intent.getAction();
+ if (Intent.ACTION_BOOT_COMPLETED.equals(action)
+ || Intent.ACTION_MY_PACKAGE_REPLACED.equals(action)) {
+ ContactsNotificationChannelsUtil.createDefaultChannel(context);
+ }
+ }
+}
diff --git a/src/com/android/contacts/util/ContactsNotificationChannelsUtil.java b/src/com/android/contacts/util/ContactsNotificationChannelsUtil.java
new file mode 100644
index 0000000..3aa75c9
--- /dev/null
+++ b/src/com/android/contacts/util/ContactsNotificationChannelsUtil.java
@@ -0,0 +1,44 @@
+/*
+ * 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.contacts.util;
+
+import android.annotation.TargetApi;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.Build;
+import android.support.v4.os.BuildCompat;
+
+import com.android.contacts.R;
+
+@TargetApi(Build.VERSION_CODES.O)
+public class ContactsNotificationChannelsUtil {
+ public static String DEFAULT_CHANNEL = "DEFAULT_CHANNEL";
+
+ private ContactsNotificationChannelsUtil() {}
+
+ public static void createDefaultChannel(Context context) {
+ if (!BuildCompat.isAtLeastO()) {
+ return;
+ }
+ final NotificationManager nm = context.getSystemService(NotificationManager.class);
+ final NotificationChannel channel = new NotificationChannel(DEFAULT_CHANNEL,
+ context.getString(R.string.contacts_default_notification_channel),
+ NotificationManager.IMPORTANCE_DEFAULT);
+ nm.createNotificationChannel(channel);
+ }
+}
diff --git a/src/com/android/contacts/vcard/NotificationImportExportListener.java b/src/com/android/contacts/vcard/NotificationImportExportListener.java
index cf815bc..f4d682c 100644
--- a/src/com/android/contacts/vcard/NotificationImportExportListener.java
+++ b/src/com/android/contacts/vcard/NotificationImportExportListener.java
@@ -32,6 +32,7 @@
import android.widget.Toast;
import com.android.contacts.R;
+import com.android.contacts.util.ContactsNotificationChannelsUtil;
import com.android.vcard.VCardEntry;
import java.text.NumberFormat;
@@ -221,6 +222,7 @@
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setOngoing(true)
+ .setChannel(ContactsNotificationChannelsUtil.DEFAULT_CHANNEL)
.setProgress(totalCount, currentCount, totalCount == - 1)
.setTicker(tickerText)
.setContentTitle(description)
@@ -246,6 +248,7 @@
/* package */ static Notification constructCancelNotification(
Context context, String description) {
return new NotificationCompat.Builder(context)
+ .setChannel(ContactsNotificationChannelsUtil.DEFAULT_CHANNEL)
.setAutoCancel(true)
.setSmallIcon(android.R.drawable.stat_notify_error)
.setColor(context.getResources().getColor(R.color.dialtacts_theme_color))
@@ -276,6 +279,7 @@
/* package */ static Notification constructFinishNotificationWithFlags(
Context context, String title, String description, Intent intent, int flags) {
return new NotificationCompat.Builder(context)
+ .setChannel(ContactsNotificationChannelsUtil.DEFAULT_CHANNEL)
.setAutoCancel(true)
.setColor(context.getResources().getColor(R.color.dialtacts_theme_color))
.setSmallIcon(R.drawable.quantum_ic_done_vd_theme_24)
@@ -299,6 +303,7 @@
/* package */ static Notification constructImportFailureNotification(
Context context, String reason) {
return new NotificationCompat.Builder(context)
+ .setChannel(ContactsNotificationChannelsUtil.DEFAULT_CHANNEL)
.setAutoCancel(true)
.setColor(context.getResources().getColor(R.color.dialtacts_theme_color))
.setSmallIcon(android.R.drawable.stat_notify_error)