1 /**
2  * Copyright (C) 2022 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.telephony.imsmedia;
18 
19 import android.os.Parcel;
20 import android.telephony.imsmedia.MediaQualityThreshold;
21 import android.telephony.imsmedia.TextConfig;
22 
23 import com.android.telephony.imsmedia.util.Log;
24 
25 /**
26  * Text session implementation for internal AP based RTP stack. This handles all API calls from
27  * applications and passes it to native library.
28  */
29 public class TextLocalSession {
30     private static final String TAG = "TextLocalSession";
31     private int mSessionId;
32     private long mNativeObject = 0;
33 
34     /**
35      * Instantiates a new text session
36      *
37      * @param sessionId    : session identifier
38      * @param nativeObject : jni object modifier for calling jni methods
39      */
TextLocalSession(final int sessionId, final long nativeObject)40     TextLocalSession(final int sessionId, final long nativeObject) {
41         mSessionId = sessionId;
42         mNativeObject = nativeObject;
43     }
44 
45     /** Returns the unique session identifier */
getSessionId()46     public int getSessionId() {
47         Log.dc(TAG, "getSessionId");
48         return mSessionId;
49     }
50 
51     /**
52      * Send request message with the corresponding arguments to libimsmediajni
53      * library to operate
54      *
55      * @param sessionId : session identifier
56      * @param parcel    : parcel argument to send to jni
57      */
sendRequest(final int sessionId, final Parcel parcel)58     public void sendRequest(final int sessionId, final Parcel parcel) {
59         if (mNativeObject != 0) {
60             if (parcel == null) {
61                 return;
62             }
63             byte[] data = parcel.marshall();
64             JNIImsMediaService.sendMessage(mNativeObject, sessionId, data);
65             parcel.recycle();
66         }
67     }
68 
69     /**
70      * Modifies the configuration of the RTP session after the session is opened. It can be used
71      * modify the direction, access network, codec parameters RTCP configuration, remote address and
72      * remote port number. The service will apply if anything changed in this invocation compared to
73      * previous and respond the updated the config in ImsMediaSession#onModifySessionResponse() API
74      *
75      * @param config provides remote end point info and codec details
76      */
modifySession(final TextConfig config)77     public void modifySession(final TextConfig config) {
78         Parcel parcel = Parcel.obtain();
79         parcel.writeInt(TextSession.CMD_MODIFY_SESSION);
80         if (config != null) {
81             config.writeToParcel(parcel, 0);
82         }
83         sendRequest(mSessionId, parcel);
84     }
85 
86     /**
87      * Sets the media quality threshold parameters of the session to get media quality
88      * notifications.
89      *
90      * @param threshold media quality thresholds for various quality parameters
91      */
setMediaQualityThreshold(final MediaQualityThreshold threshold)92     public void setMediaQualityThreshold(final MediaQualityThreshold threshold) {
93         Parcel parcel = Parcel.obtain();
94         parcel.writeInt(TextSession.CMD_SET_MEDIA_QUALITY_THRESHOLD);
95         if (threshold != null) {
96             threshold.writeToParcel(parcel, 0);
97         }
98         sendRequest(mSessionId, parcel);
99     }
100 
101     /**
102      * Send Rtt text string to the network
103      *
104      * @param text The text string
105      */
sendRtt(String text)106     public void sendRtt(String text) {
107         Parcel parcel = Parcel.obtain();
108         parcel.writeInt(TextSession.CMD_SEND_RTT);
109         parcel.writeString(text);
110         sendRequest(mSessionId, parcel);
111     }
112 }
113