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

Commit fdeb3ac6 authored by Wenyi Wang's avatar Wenyi Wang Committed by android-build-merger
Browse files

Merge "Start to use notification channel" into ub-contactsdialer-i-dev

am: 10faad74

Change-Id: I3587fff0823a678064e9d7fd823f3cd95ebf96a1
parents 189002c7 10faad74
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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"
+3 −0
Original line number Diff line number Diff line
@@ -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>
+4 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.android.contacts.database.SimContactDao;
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 @@ public class SimImportService extends Service {
        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 @@ public class SimImportService extends Service {
        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 @@ public class SimImportService extends Service {
        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))
+35 −0
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.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);
        }
    }
}
+44 −0
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.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);
    }
}
Loading