• 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.android.server.telecom.callsequencing.voip;
18 
19 import android.telecom.CallAttributes;
20 import android.telecom.Log;
21 import android.telecom.VideoProfile;
22 
23 /**
24  * This remapping class is needed because {@link VideoProfile} has more fine grain levels of video
25  * states as apposed to Transactional video states (defined in  {@link CallAttributes.CallType}.
26  * To be more specific, there are 3 video states (rx, tx, and bi-directional).
27  * {@link CallAttributes.CallType} only has 2 states (audio and video).
28  *
29  * The reason why Transactional calls have fewer states is due to the fact that the framework is
30  * only used by VoIP apps and Telecom only cares to know if the call is audio or video.
31  *
32  * Calls that are backed by a {@link android.telecom.ConnectionService} have the ability to be
33  * managed calls (non-VoIP) and Dialer needs more fine grain video states to update the UI. Thus,
34  * {@link VideoProfile} is used for {@link android.telecom.ConnectionService} backed calls.
35  */
36 public class VideoStateTranslation {
37     private static final String TAG = VideoStateTranslation.class.getSimpleName();
38 
39     /**
40      * Client --> Telecom
41      * This should be used when the client application is signaling they are changing the video
42      * state.
43      */
TransactionalVideoStateToVideoProfileState(int callType)44     public static int TransactionalVideoStateToVideoProfileState(int callType) {
45         if (callType == CallAttributes.AUDIO_CALL) {
46             Log.i(TAG, "CallAttributes.AUDIO_CALL --> VideoProfile.STATE_AUDIO_ONLY");
47             return VideoProfile.STATE_AUDIO_ONLY;
48         } else if (callType == CallAttributes.VIDEO_CALL) {
49             Log.i(TAG, "CallAttributes.VIDEO_CALL--> VideoProfile.STATE_BIDIRECTIONAL");
50             return VideoProfile.STATE_BIDIRECTIONAL;
51         } else {
52             Log.w(TAG, "CallType=[%d] does not have a VideoProfile mapping", callType);
53             return VideoProfile.STATE_AUDIO_ONLY;
54         }
55     }
56 
57     /**
58      * Telecom --> Client
59      * This should be used when Telecom is informing the client of a video state change.
60      */
VideoProfileStateToTransactionalVideoState(int videoProfileState)61     public static int VideoProfileStateToTransactionalVideoState(int videoProfileState) {
62         switch (videoProfileState) {
63             case VideoProfile.STATE_AUDIO_ONLY -> {
64                 Log.i(TAG, "%s --> CallAttributes.AUDIO_CALL",
65                         VideoProfileStateToString(videoProfileState));
66                 return CallAttributes.AUDIO_CALL;
67             }
68             case VideoProfile.STATE_BIDIRECTIONAL, VideoProfile.STATE_TX_ENABLED,
69                     VideoProfile.STATE_RX_ENABLED -> {
70                 Log.i(TAG, "%s --> CallAttributes.VIDEO_CALL",
71                         VideoProfileStateToString(videoProfileState));
72                 return CallAttributes.VIDEO_CALL;
73             }
74             default -> {
75                 Log.w(TAG, "VideoProfile=[%d] does not have a CallType mapping", videoProfileState);
76                 return CallAttributes.AUDIO_CALL;
77             }
78         }
79     }
80 
TransactionalVideoStateToString(int transactionalVideoState)81     public static String TransactionalVideoStateToString(int transactionalVideoState) {
82         if (transactionalVideoState == CallAttributes.AUDIO_CALL) {
83             return "CallAttributes.AUDIO_CALL";
84         } else if (transactionalVideoState == CallAttributes.VIDEO_CALL) {
85             return "CallAttributes.VIDEO_CALL";
86         } else {
87             return "CallAttributes.UNKNOWN";
88         }
89     }
90 
VideoProfileStateToString(int videoProfileState)91     private static String VideoProfileStateToString(int videoProfileState) {
92         switch (videoProfileState) {
93             case VideoProfile.STATE_BIDIRECTIONAL -> {
94                 return "VideoProfile.STATE_BIDIRECTIONAL";
95             }
96             case VideoProfile.STATE_RX_ENABLED -> {
97                 return "VideoProfile.STATE_RX_ENABLED";
98             }
99             case VideoProfile.STATE_TX_ENABLED -> {
100                 return "VideoProfile.STATE_TX_ENABLED";
101             }
102             case VideoProfile.STATE_AUDIO_ONLY -> {
103                 return "VideoProfile.STATE_AUDIO_ONLY";
104             }
105             default -> {
106                 return "VideoProfile.UNKNOWN";
107             }
108         }
109     }
110 }
111