• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.android.car.kitchensink.radio;
18 
19 import android.content.BroadcastReceiver;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.util.Log;
23 
24 import androidx.core.app.NotificationManagerCompat;
25 
26 public final class AlertSnoozeReceiver extends BroadcastReceiver {
27     private static final String TAG = AlertSnoozeReceiver.class.getSimpleName();
28 
29     @Override
onReceive(Context context, Intent intent)30     public void onReceive(Context context, Intent intent) {
31         String action = intent.getAction();
32         if (!AlertNotificationHelper.ACTION_NOTIFICATION.equals(action)) {
33             Log.e(TAG, "Undefined action " + action);
34             return;
35         }
36         int notificationId = intent.getIntExtra(AlertNotificationHelper.EXTRA_KEY_NOTIFICATION_ID,
37                 AlertNotificationHelper.INVALID_NOTIFICATION_ID);
38         if (notificationId == AlertNotificationHelper.INVALID_NOTIFICATION_ID) {
39             Log.e(TAG,  "Invalid notification id");
40             return;
41         }
42         Log.i(TAG, action + " for alert notification " + notificationId);
43 
44         NotificationManagerCompat notificationManagerCompat =
45                 NotificationManagerCompat.from(context);
46         String title = intent.getStringExtra(AlertNotificationHelper.EXTRA_KEY_TITLE);
47         String text = intent.getStringExtra(AlertNotificationHelper.EXTRA_KEY_TEXT);
48         long alertTimeMs = intent.getLongExtra(AlertNotificationHelper.EXTRA_KEY_ALERT_TIME_MS,
49                 System.currentTimeMillis());
50         notificationManagerCompat.cancel(notificationId);
51         AlertNotificationHelper.createRadioAlertNotification(context, title, text, alertTimeMs,
52                 notificationId);
53     }
54 }
55