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 package android.telecom.cts.apps; 17 18 import static android.telecom.cts.apps.NotificationUtils.createCallStyleNotification; 19 20 import android.app.Notification; 21 import android.app.NotificationManager; 22 import android.content.Context; 23 import android.telecom.CallAttributes; 24 import android.util.Log; 25 26 /** 27 * This class should contain all the resources associated with a single call. This includes things 28 * like Notifications, Audio Records, Audio Tracks, but is not limited to just those objects. 29 */ 30 public class CallResources { 31 private static final String TAG = CallResources.class.getSimpleName(); 32 private final CallAttributes mCallAttributes; 33 private String mCallId = ""; 34 35 /** 36 * Notification properties 37 */ 38 private final Notification mNotification; 39 private final String mCallChannelId; 40 private final int mNotificationId; 41 CallResources(Context context, CallAttributes callAttributes, String callChannelId, int notificationId)42 public CallResources(Context context, 43 CallAttributes callAttributes, 44 String callChannelId, 45 int notificationId) { 46 mCallAttributes = callAttributes; 47 mCallChannelId = callChannelId; 48 mNotificationId = notificationId; 49 mNotification = createCallStyleNotification( 50 context, 51 callChannelId, 52 callAttributes.getDisplayName().toString(), 53 AttributesUtil.isOutgoing(callAttributes)); 54 postInitialCallStyleNotification(context); 55 } 56 getCallAttributes()57 public CallAttributes getCallAttributes() { 58 return mCallAttributes; 59 } 60 setCallId(String id)61 public void setCallId(String id) { 62 mCallId = id; 63 } 64 65 /** 66 * Notification helpers 67 */ 68 getNotificationId()69 public int getNotificationId() { 70 return mNotificationId; 71 } 72 postInitialCallStyleNotification(Context context)73 public void postInitialCallStyleNotification(Context context) { 74 NotificationManager nm = context.getSystemService(NotificationManager.class); 75 nm.notify(mNotificationId, mNotification); 76 Log.i(TAG, String.format("postInitialCallStyleNotification: posted notification for" 77 + " callId=[%s], mNotificationId=[%s], notification=[%s]", mCallId, 78 mNotificationId, mNotification)); 79 } 80 updateNotificationToOngoing(Context context)81 public void updateNotificationToOngoing(Context context) { 82 NotificationUtils.updateNotificationToOngoing( 83 context, 84 mCallChannelId, 85 mCallAttributes.getDisplayName().toString(), 86 mNotificationId); 87 } 88 clearCallNotification(Context context)89 public void clearCallNotification(Context context) { 90 NotificationUtils.clearNotification(context, mNotificationId); 91 } 92 destroyResources(Context context)93 public void destroyResources(Context context) { 94 clearCallNotification(context); 95 } 96 } 97