diff options
Diffstat (limited to 'java/com/android')
-rw-r--r-- | java/com/android/incallui/call/DialerCall.java | 30 | ||||
-rw-r--r-- | java/com/android/incallui/rtt/impl/RttChatAdapter.java | 1 | ||||
-rw-r--r-- | java/com/android/incallui/rtt/impl/RttChatMessageViewHolder.java | 1 | ||||
-rw-r--r-- | java/com/android/incallui/rtt/protocol/RttChatMessage.java (renamed from java/com/android/incallui/rtt/impl/RttChatMessage.java) | 39 |
4 files changed, 54 insertions, 17 deletions
diff --git a/java/com/android/incallui/call/DialerCall.java b/java/com/android/incallui/call/DialerCall.java index d57de15e5..d736edc94 100644 --- a/java/com/android/incallui/call/DialerCall.java +++ b/java/com/android/incallui/call/DialerCall.java @@ -83,6 +83,7 @@ import com.android.dialer.util.PermissionsUtil; import com.android.incallui.audiomode.AudioModeProvider; import com.android.incallui.call.state.DialerCallState; import com.android.incallui.latencyreport.LatencyReport; +import com.android.incallui.rtt.protocol.RttChatMessage; import com.android.incallui.speakeasy.runtime.Constraints; import com.android.incallui.videotech.VideoTech; import com.android.incallui.videotech.VideoTech.VideoTechListener; @@ -92,6 +93,7 @@ import com.android.incallui.videotech.ims.ImsVideoTech; import com.android.incallui.videotech.utils.VideoUtils; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.MoreExecutors; +import java.io.IOException; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; @@ -1084,6 +1086,28 @@ public class DialerCall implements VideoTechListener, StateChangedListener, Capa getTelecomCall().respondToRttRequest(rttRequestId, accept); } + @TargetApi(28) + private void saveRttTranscript() { + if (!BuildCompat.isAtLeastP()) { + return; + } + // Save any remaining text in the buffer that's not shown by UI yet. + // This may happen when the call is switched to background before disconnect. + try { + String messageLeft = getRttCall().readImmediately(); + if (!TextUtils.isEmpty(messageLeft)) { + rttTranscript = + RttChatMessage.getRttTranscriptWithNewRemoteMessage(rttTranscript, messageLeft); + } + } catch (IOException e) { + LogUtil.e("DialerCall.saveRttTranscript", "error when reading remaining message", e); + } + Futures.addCallback( + RttTranscriptUtil.saveRttTranscript(context, rttTranscript), + new DefaultFutureCallback<>(), + MoreExecutors.directExecutor()); + } + public boolean hasReceivedVideoUpgradeRequest() { return VideoUtils.hasReceivedVideoUpgradeRequest(getVideoTech().getSessionModificationState()); } @@ -1615,11 +1639,9 @@ public class DialerCall implements VideoTechListener, StateChangedListener, Capa videoTechManager.dispatchRemovedFromCallList(); } // TODO(a bug): Add tests for it to make sure no crash on subsequent call to this method. + // TODO(wangqi): Consider moving this to a DialerCallListener. if (rttTranscript != null && !isCallRemoved) { - Futures.addCallback( - RttTranscriptUtil.saveRttTranscript(context, rttTranscript), - new DefaultFutureCallback<>(), - MoreExecutors.directExecutor()); + saveRttTranscript(); } isCallRemoved = true; } diff --git a/java/com/android/incallui/rtt/impl/RttChatAdapter.java b/java/com/android/incallui/rtt/impl/RttChatAdapter.java index f1cde759c..96ff58b79 100644 --- a/java/com/android/incallui/rtt/impl/RttChatAdapter.java +++ b/java/com/android/incallui/rtt/impl/RttChatAdapter.java @@ -29,6 +29,7 @@ import android.view.ViewGroup; import com.android.dialer.common.LogUtil; import com.android.dialer.rtt.RttTranscript; import com.android.dialer.rtt.RttTranscriptMessage; +import com.android.incallui.rtt.protocol.RttChatMessage; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; diff --git a/java/com/android/incallui/rtt/impl/RttChatMessageViewHolder.java b/java/com/android/incallui/rtt/impl/RttChatMessageViewHolder.java index 2beea9530..56161eccc 100644 --- a/java/com/android/incallui/rtt/impl/RttChatMessageViewHolder.java +++ b/java/com/android/incallui/rtt/impl/RttChatMessageViewHolder.java @@ -25,6 +25,7 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; +import com.android.incallui.rtt.protocol.RttChatMessage; /** ViewHolder class for RTT chat message bubble. */ public class RttChatMessageViewHolder extends ViewHolder { diff --git a/java/com/android/incallui/rtt/impl/RttChatMessage.java b/java/com/android/incallui/rtt/protocol/RttChatMessage.java index 2f3933a50..5680529ee 100644 --- a/java/com/android/incallui/rtt/impl/RttChatMessage.java +++ b/java/com/android/incallui/rtt/protocol/RttChatMessage.java @@ -14,25 +14,24 @@ * limitations under the License */ -package com.android.incallui.rtt.impl; +package com.android.incallui.rtt.protocol; import android.support.annotation.NonNull; import com.android.dialer.common.Assert; import com.android.dialer.rtt.RttTranscript; import com.android.dialer.rtt.RttTranscriptMessage; -import com.android.incallui.rtt.protocol.Constants; import com.google.common.base.Splitter; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** Message class that holds one RTT chat content. */ -final class RttChatMessage { +public final class RttChatMessage { private static final Splitter SPLITTER = Splitter.on(Constants.BUBBLE_BREAKER); - boolean isRemote; - long timstamp; + public boolean isRemote; + private long timstamp; private final StringBuilder content = new StringBuilder(); private boolean isFinished; @@ -44,7 +43,7 @@ final class RttChatMessage { isFinished = true; } - void unfinish() { + public void unfinish() { isFinished = false; } @@ -74,7 +73,7 @@ final class RttChatMessage { * * <p>"hello world" -> "hello new world" : "\b\b\b\b\bnew world" */ - static String computeChangedString(String oldMessage, String newMesssage) { + public static String computeChangedString(String oldMessage, String newMesssage) { StringBuilder modify = new StringBuilder(); int indexChangeStart = 0; while (indexChangeStart < oldMessage.length() @@ -91,8 +90,21 @@ final class RttChatMessage { return modify.toString(); } + public static RttTranscript getRttTranscriptWithNewRemoteMessage( + RttTranscript rttTranscript, @NonNull String text) { + List<RttChatMessage> messageList = fromTranscript(rttTranscript); + updateRemoteRttChatMessage(messageList, text); + return RttTranscript.newBuilder() + .setId(rttTranscript.getId()) + .setNumber(rttTranscript.getNumber()) + .setTimestamp(rttTranscript.getTimestamp()) + .addAllMessages(toTranscriptMessageList(messageList)) + .build(); + } + /** Update list of {@code RttChatMessage} based on given remote text. */ - static void updateRemoteRttChatMessage(List<RttChatMessage> messageList, @NonNull String text) { + public static void updateRemoteRttChatMessage( + List<RttChatMessage> messageList, @NonNull String text) { Assert.isNotNull(messageList); Iterator<String> splitText = SPLITTER.split(text).iterator(); @@ -163,7 +175,7 @@ final class RttChatMessage { return i; } - static int getLastIndexRemoteMessage(List<RttChatMessage> messageList) { + public static int getLastIndexRemoteMessage(List<RttChatMessage> messageList) { int i = messageList.size() - 1; while (i >= 0 && !messageList.get(i).isRemote) { i--; @@ -171,7 +183,7 @@ final class RttChatMessage { return i; } - static int getLastIndexLocalMessage(List<RttChatMessage> messageList) { + public static int getLastIndexLocalMessage(List<RttChatMessage> messageList) { int i = messageList.size() - 1; while (i >= 0 && messageList.get(i).isRemote) { i--; @@ -179,7 +191,8 @@ final class RttChatMessage { return i; } - static List<RttTranscriptMessage> toTranscriptMessageList(List<RttChatMessage> messageList) { + public static List<RttTranscriptMessage> toTranscriptMessageList( + List<RttChatMessage> messageList) { List<RttTranscriptMessage> transcriptMessageList = new ArrayList<>(); for (RttChatMessage message : messageList) { transcriptMessageList.add( @@ -193,7 +206,7 @@ final class RttChatMessage { return transcriptMessageList; } - static List<RttChatMessage> fromTranscript(RttTranscript rttTranscript) { + public static List<RttChatMessage> fromTranscript(RttTranscript rttTranscript) { List<RttChatMessage> messageList = new ArrayList<>(); if (rttTranscript == null) { return messageList; @@ -211,7 +224,7 @@ final class RttChatMessage { return messageList; } - RttChatMessage() { + public RttChatMessage() { timstamp = System.currentTimeMillis(); } } |