Merge "Adjust display name of call log for 4G conference call" into atel.lnx.2.0-dev
diff --git a/InCallUI/res/values-zh-rCN/qtistrings.xml b/InCallUI/res/values-zh-rCN/qtistrings.xml
index 63af255..120af0a 100644
--- a/InCallUI/res/values-zh-rCN/qtistrings.xml
+++ b/InCallUI/res/values-zh-rCN/qtistrings.xml
@@ -47,4 +47,104 @@
     <string name="modify_call_option_vt_tx">视频发送</string>
     <string name="modify_call_option_vt_rx">视频接收</string>
     <string name="modify_call_option_voice">仅限语音</string>
+    <!-- Call substate label -->
+    <string name="call_substate_label">" 通话质量不佳 - \u000a"</string>
+    <!-- Call substate label for call resumed -->
+    <string name="call_substate_call_resumed">"通话继续\u000a"</string>
+    <!-- Call substate label for call connected suspended (audio) -->
+    <string name="call_substate_connected_suspended_audio">"暂停连接\u000a"</string>
+    <!-- Call substate label for call connected suspended (video) -->
+    <string name="call_substate_connected_suspended_video">"视频电话暂停\u000a"</string>
+    <!-- Call substate label for avp retry -->
+    <string name="call_substate_avp_retry">"AVP 重试\u000a"</string>
+    <!-- Video quality changed message -->
+    <string name="video_quality_changed">" 视频画质变为\u0020"</string>
+    <!-- Video quality High -->
+    <string name="video_quality_high">"高画质"</string>
+    <!-- Video quality Medium -->
+    <string name="video_quality_medium">"中画质"</string>
+    <!-- Video quality Low -->
+    <string name="video_quality_low">"低画质"</string>
+    <!-- Video quality Unknown -->
+    <string name="video_quality_unknown">"未知"</string>
+    <!-- Message indicating that Video Started flowing for IMS-VT calls -->
+    <string name="player_started">"播放器已启动"</string>
+    <!-- Message indicating that Video Stopped flowing for IMS-VT calls -->
+    <string name="player_stopped">"播放暂停"</string>
+    <!-- Message indicating that camera failure has occurred for the selected camera and
+         as result camera is not ready -->
+    <string name="camera_not_ready">"摄像头故障"</string>
+    <!-- Message indicating that camera is ready/available -->
+    <string name="camera_ready">"摄像头就绪"</string>
+    <!-- Message indicating unknown call session event -->
+    <string name="unknown_call_session_event">"未知电话"</string>
+    <!-- Message indicating data usage -->
+    <string name="data_usage_label">"流量使用: "</string>
+    <!-- Modify call error cause -->
+    <string name="modify_call_failed_due_to_low_battery">"由于电池电量不足,无法修改通话。"</string>
+    <!-- Message indicating video calls not allowed if user enabled TTY Mode -->
+    <string name="video_call_not_allowed_if_tty_enabled">"请关闭 TTY 模式以便升级到视频电话。"</string>
+    <!-- Text for the onscreen "Add Participant" button -->
+    <string name="onscreenAddParticipant">"添加参与者"</string>
+    <!-- Description of the deflect target in the Slide unlock screen. [CHAR LIMIT=NONE] -->
+    <string name="qti_description_target_deflect">"转移"</string>
+    <string name="qti_description_deflect_error">"号码未设置。通过 IMS 设置提供号码,然后重试。"</string>
+    <string name="qti_description_deflect_service_error">"不支持呼叫转移服务。"</string>
+    <!-- Message indicating call failed due to handover not feasible -->
+    <string name="call_failed_ho_not_feasible">"无法从 LTE 切换到 3G/2G,通话已结束。"</string>
+    <!-- Title of the IMS to CS redial dialog -->
+    <string name="cs_redial_option">"重拨选项"</string>
+    <!-- Message text of the IMS to CS redial dialog -->
+    <string name="cs_redial_msg">"无法拨打 IMS 视频通话,是否要拨打非 IMS 的语音通话?"</string>
+    <!-- Yes option of the IMS to CS redial dialog -->
+    <string name="cs_redial_yes">"是"</string>
+    <!-- No option of the IMS to CS redial dialog -->
+    <string name="cs_redial_no">"否"</string>
+    <!-- Session modify cause unspecified -->
+    <string name="session_modify_cause_unspecified"></string>
+    <!-- Session modify cause code upgrade local request -->
+    <string name="session_modify_cause_upgrade_local_request">"应用户请求,通话已升级"</string>
+    <!-- Session modify cause code upgrade remote request -->
+    <string name="session_modify_cause_upgrade_remote_request">"应远程用户请求,通话已升级"</string>
+    <!-- Session modify cause code downgrade local request -->
+    <string name="session_modify_cause_downgrade_local_request">"应用户请求,通话已降级"</string>
+    <!-- Session modify cause code downgrade remote request -->
+    <string name="session_modify_cause_downgrade_remote_request">"应远程用户请求,通话已降级"</string>
+    <!-- Session modify cause code downgrade rtp timeout -->
+    <string name="session_modify_cause_downgrade_rtp_timeout">"由于 RTP 超时,通话已降级"</string>
+    <!-- Session modify cause code downgrade qos -->
+    <string name="session_modify_cause_downgrade_qos">"由于服务质量,通话已降级"</string>
+    <!-- Session modify cause code downgrade packet loss -->
+    <string name="session_modify_cause_downgrade_packet_loss">"由于数据包丢失,通话已降级"</string>
+    <!-- Session modify cause code downgrade low thrput -->
+    <string name="session_modify_cause_downgrade_low_thrput">"由于吞吐量低,通话已降级"</string>
+    <!-- Session modify cause code downgrade thermal mitigation -->
+    <string name="session_modify_cause_downgrade_thermal_mitigation">"由于设备过热,通话已降级"</string>
+    <!-- Session modify cause code downgrade lipsync -->
+    <string name="session_modify_cause_downgrade_lipsync">"由于嘴唇同步功能,通话已降级"</string>
+    <!-- Session modify cause code downgrade generic error -->
+    <string name="session_modify_cause_downgrade_generic_error">"由于一般错误,通话已降级"</string>
+    <!-- Title for low battery alert dialogue -->
+    <string name="low_battery">"电池电量不足"</string>
+    <!-- Yes option of the low battery alert dialog -->
+    <string name="low_battery_yes">"是"</string>
+    <!-- No option of the low battery alert dialog -->
+    <string name="low_battery_no">"否"</string>
+    <!-- Message text of the low battery alert dialog in cases when video call can be downgraded to voice call -->
+    <string name="low_battery_downgrade_to_voice_msg">"要将视频通话转换为音频通话吗?"</string>
+    <!-- Message text of the low battery alert dialog in cases video call doesn't have downgrade capabilities -->
+    <string name="low_battery_hangup_msg">"要挂断电话吗?"</string>
+    <!-- Description of the call transfer related strings [CHAR LIMIT=NONE] -->
+    <string name="qti_ims_transfer_num_error">"号码未设置。通过 IMS 设置提供号码,然后重试。"</string>
+    <string name="qti_ims_transfer_request_error">"呼叫转移请求失败。"</string>
+    <string name="qti_ims_transfer_request_success">"呼叫转移请求成功。"</string>
+    <!-- Text for the onscreen "blind transfer" button -->
+    <string name="qti_ims_onscreenBlindTransfer">"无条件转移"</string>
+    <!-- Text for the onscreen "assured transfer" button -->
+    <string name="qti_ims_onscreenAssuredTransfer">"固定转移"</string>
+    <!-- Text for the onscreen "consultative transfer" button -->
+    <string name="qti_ims_onscreenConsultativeTransfer">"询问转移"</string>
+    <!-- Text for operator specific emergency number -->
+    <add-resource type="string" name="emergency_call_dialog_number_for_display_operator"/>
+    <string name="emergency_call_dialog_number_for_display_operator">"紧急呼救"</string>
 </resources>
diff --git a/InCallUI/src/com/android/incallui/CallButtonPresenter.java b/InCallUI/src/com/android/incallui/CallButtonPresenter.java
index 510e035..b5002db 100644
--- a/InCallUI/src/com/android/incallui/CallButtonPresenter.java
+++ b/InCallUI/src/com/android/incallui/CallButtonPresenter.java
@@ -528,7 +528,10 @@
         if (mEnhanceEnable && hasVideoCallCapabilities(call)) {
             boolean isAudioAndVtCap = (VideoProfile.isAudioOnly(mCall.getVideoState()) &&
                     PresenceHelper.getVTCapability(call.getNumber()));
-            showRxTx = (VideoProfile.isReceptionEnabled(mCall.getVideoState()) || isAudioAndVtCap);
+            showRxTx = ((VideoProfile.isReceptionEnabled(mCall.getVideoState()) &&
+                    !VideoProfile.isBidirectional(mCall.getVideoState())) || isAudioAndVtCap);
+            //"hide me" show be show if call is video call or voice call only, "hide me"
+            //is mean that call can upgrade to Rx video call for voice call only.
             showRx = (VideoProfile.isBidirectional(mCall.getVideoState()) || isAudioAndVtCap);
             showVolte = VideoProfile.isVideo(mCall.getVideoState());
             Log.v(this, "updateButtonsState showRxTx = " + showRxTx +
diff --git a/InCallUI/src/com/android/incallui/GlowPadAnswerFragment.java b/InCallUI/src/com/android/incallui/GlowPadAnswerFragment.java
index d9b4dda..98e797e 100644
--- a/InCallUI/src/com/android/incallui/GlowPadAnswerFragment.java
+++ b/InCallUI/src/com/android/incallui/GlowPadAnswerFragment.java
@@ -104,7 +104,12 @@
                 handleDrawableResourceId = R.drawable.ic_incall_audio_handle;
                 break;
             case TARGET_SET_FOR_VIDEO_WITHOUT_SMS:
-                targetResourceId = R.array.incoming_call_widget_video_without_sms_targets;
+                if (isEnhanceUIEnabled) {
+                    targetResourceId =
+                            R.array.enhance_incoming_call_widget_video_without_sms_targets;
+                } else {
+                    targetResourceId = R.array.incoming_call_widget_video_without_sms_targets;
+                }
                 targetDescriptionsResourceId =
                         R.array.incoming_call_widget_video_without_sms_target_descriptions;
                 directionDescriptionsResourceId =
@@ -112,7 +117,11 @@
                 handleDrawableResourceId = R.drawable.ic_incall_video_handle;
                 break;
             case TARGET_SET_FOR_VIDEO_WITH_SMS:
-                targetResourceId = R.array.incoming_call_widget_video_with_sms_targets;
+                if (isEnhanceUIEnabled) {
+                    targetResourceId = R.array.enhance_incoming_call_widget_video_with_sms_targets;
+                } else {
+                    targetResourceId = R.array.incoming_call_widget_video_with_sms_targets;
+                }
                 targetDescriptionsResourceId =
                         R.array.incoming_call_widget_video_with_sms_target_descriptions;
                 directionDescriptionsResourceId =
diff --git a/InCallUI/src/com/android/incallui/InCallServiceImpl.java b/InCallUI/src/com/android/incallui/InCallServiceImpl.java
index 5ca721b..5c9f706 100644
--- a/InCallUI/src/com/android/incallui/InCallServiceImpl.java
+++ b/InCallUI/src/com/android/incallui/InCallServiceImpl.java
@@ -32,7 +32,7 @@
  */
 public class InCallServiceImpl extends InCallService {
 
-    static int sPhoneCount = 0;
+    static int sPhoneCount = TelephonyManager.getDefault().getPhoneCount();
 
     @Override
     public void onCallAudioStateChanged(CallAudioState audioState) {
@@ -63,7 +63,6 @@
     @Override
     public IBinder onBind(Intent intent) {
         final Context context = getApplicationContext();
-        sPhoneCount = QtiCallUtils.getPhoneCount(context);
         final ContactInfoCache contactInfoCache = ContactInfoCache.getInstance(context);
         InCallPresenter.getInstance().setUp(
                 getApplicationContext(),
diff --git a/InCallUI/src/com/android/incallui/VideoCallFragment.java b/InCallUI/src/com/android/incallui/VideoCallFragment.java
index 1d5d58e..087f278 100644
--- a/InCallUI/src/com/android/incallui/VideoCallFragment.java
+++ b/InCallUI/src/com/android/incallui/VideoCallFragment.java
@@ -858,7 +858,12 @@
 
             Log.d(this, "inflateVideoCallViews: sVideoSurfacesInUse=" + sVideoSurfacesInUse);
             //If peer adjusted screen size is not available, set screen size to default display size
-            Point screenSize = sDisplaySize == null ? getScreenSize() : sDisplaySize;
+            Point screenSize = getScreenSize();
+            if (sDisplaySize != null) {
+                screenSize = VideoCallPresenter.resizeForAspectRatio(screenSize,
+                        sDisplaySize.x, sDisplaySize.y);
+            }
+
             setSurfaceSizeAndTranslation(displaySurface, screenSize);
 
             if (!sVideoSurfacesInUse) {
diff --git a/InCallUI/src/com/android/incallui/VideoCallPresenter.java b/InCallUI/src/com/android/incallui/VideoCallPresenter.java
index 82aae4c..9a3e34b 100644
--- a/InCallUI/src/com/android/incallui/VideoCallPresenter.java
+++ b/InCallUI/src/com/android/incallui/VideoCallPresenter.java
@@ -1220,6 +1220,12 @@
         Point size = ui.getScreenSize();
         Log.v(this, "setDisplayVideoSize: windowmgr width=" + size.x
                 + " windowmgr height=" + size.y);
+        size = resizeForAspectRatio(size, width, height);
+        ui.setDisplayVideoSize(size.x, size.y);
+    }
+
+    public static Point resizeForAspectRatio(Point inSize, int width, int height) {
+        Point size = new Point(inSize);
         if (size.y * width > size.x * height) {
             // current display height is too much. Correct it
             size.y = (int) (size.x * height / width);
@@ -1227,7 +1233,7 @@
             // current display width is too much. Correct it
             size.x = (int) (size.y * width / height);
         }
-        ui.setDisplayVideoSize(size.x, size.y);
+        return size;
     }
 
     /**
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java
index d7bb71f..6142d52 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -1553,7 +1553,7 @@
     }
 
     private void showVideoCallWelcomeDialog() {
-        if (DialerUtils.canShowWelcomeScreen(this)) {
+        if (DialerUtils.canShowWelcomeScreen(this) || DialerUtils.isFirstLaunch(this)) {
             final Intent intent = new Intent(this, VideoCallWelcomeActivity.class);
             startActivity(intent);
         }
diff --git a/src/com/android/dialer/dialpad/DialpadFragment.java b/src/com/android/dialer/dialpad/DialpadFragment.java
index 8dab294..0e89101 100644
--- a/src/com/android/dialer/dialpad/DialpadFragment.java
+++ b/src/com/android/dialer/dialpad/DialpadFragment.java
@@ -99,6 +99,9 @@
 import com.android.phone.common.dialpad.DialpadKeyButton;
 import com.android.phone.common.dialpad.DialpadView;
 
+import static android.Manifest.permission.READ_CALL_LOG;
+import static android.Manifest.permission.WRITE_CALL_LOG;
+
 import java.util.HashSet;
 import java.util.List;
 
@@ -113,8 +116,9 @@
         DialpadKeyButton.OnPressedListener {
     private static final String TAG = "DialpadFragment";
 
-    /* define for Activity permission request for Android6.0 */
+    /* define for Activity permission request for Android >= 6.0 */
     private static final int PERMISSION_REQUEST_CODE_LOCATION = 2;
+    private static final int READ_WRITE_CALL_LOG_PERMISSION_REQUEST_CODE = 3;
     /**
      * LinearLayout with getter and setter methods for the translationY property using floats,
      * for animation purposes.
@@ -192,7 +196,6 @@
     /** Stream type used to play the DTMF tones off call, and mapped to the volume control keys */
     private static final int DIAL_TONE_STREAM_TYPE = AudioManager.STREAM_DTMF;
 
-
     private OnDialpadQueryChangedListener mDialpadQueryListener;
 
     private DialpadView mDialpadView;
@@ -265,6 +268,8 @@
 
     private CallStateReceiver mCallStateReceiver;
 
+    private boolean mHasReadAndWriteCallLogPermission = false;
+
     private class CallStateReceiver extends BroadcastReceiver {
         /**
          * Receive call state changes so that we can take down the
@@ -752,8 +757,16 @@
         final StopWatch stopWatch = StopWatch.start("Dialpad.onResume");
 
         // Query the last dialed number. Do it first because hitting
+        mHasReadAndWriteCallLogPermission =
+                PermissionsUtil.hasPermission(getActivity(), READ_CALL_LOG) &&
+                PermissionsUtil.hasPermission(getActivity(), WRITE_CALL_LOG);
         // the DB is 'slow'. This call is asynchronous.
-        queryLastOutgoingCall();
+        if (mHasReadAndWriteCallLogPermission){
+            queryLastOutgoingCall();
+        } else {
+            ActivityCompat.requestPermissions(getActivity(), new String[] {READ_CALL_LOG,
+                    WRITE_CALL_LOG}, READ_WRITE_CALL_LOG_PERMISSION_REQUEST_CODE);
+        }
 
         stopWatch.lap("qloc");
 
@@ -2045,6 +2058,15 @@
                     handleDialButtonPressed();
                 }
                 break;
+            case READ_WRITE_CALL_LOG_PERMISSION_REQUEST_CODE:
+                for (int i = 0; i < grantResults.length; i++) {
+                    mHasReadAndWriteCallLogPermission &=
+                            PackageManager.PERMISSION_GRANTED == grantResults[i];
+                }
+                if (mHasReadAndWriteCallLogPermission) {
+                    queryLastOutgoingCall();
+                }
+                break;
             default:
                 super.onRequestPermissionsResult(requestCode, permissions, grantResults);
         }
diff --git a/src/com/android/dialer/util/DialerUtils.java b/src/com/android/dialer/util/DialerUtils.java
index 08827df..a71e287 100644
--- a/src/com/android/dialer/util/DialerUtils.java
+++ b/src/com/android/dialer/util/DialerUtils.java
@@ -51,6 +51,7 @@
 
     private static final String PREFS_MESSAGE = "video_call_welcome";
     private static final String KEY_STATE = "message-repeat";
+    private static final String KEY_FIRST_LAUNCH = "first-launch";
     /**
      * Attempts to start an activity and displays a toast with the default error message if the
      * activity is not found, instead of throwing an exception.
@@ -198,12 +199,25 @@
 
 
     /**
+     * @return true if it is the first launch.
+     */
+    public static boolean isFirstLaunch(Context context) {
+        final SharedPreferences prefs = context.getSharedPreferences(
+                PREFS_MESSAGE, Context.MODE_PRIVATE);
+        boolean isFirstLaunch = prefs.getBoolean(KEY_FIRST_LAUNCH, true);
+        if (isFirstLaunch) {
+            prefs.edit().putBoolean(KEY_FIRST_LAUNCH, false).apply();
+        }
+        return isFirstLaunch;
+    }
+
+    /**
      * @return true if the Welcome Screen shall be presented to the user, false otherwise.
      */
     public static boolean canShowWelcomeScreen(Context context) {
         final SharedPreferences prefs = context.getSharedPreferences(
                 PREFS_MESSAGE, Context.MODE_PRIVATE);
-        return prefs.getBoolean(KEY_STATE, true);
+        return prefs.getBoolean(KEY_STATE, false);
     }
 
 
diff --git a/src/com/android/dialer/util/IntentUtil.java b/src/com/android/dialer/util/IntentUtil.java
index 8d47075..bb87a49 100644
--- a/src/com/android/dialer/util/IntentUtil.java
+++ b/src/com/android/dialer/util/IntentUtil.java
@@ -177,7 +177,8 @@
                     if (subRes.getBoolean(R.bool.config_enable_conference_dialer)) {
                         TelephonyManager telephonyMgr = (TelephonyManager) context.
                                 getSystemService(Context.TELEPHONY_SERVICE);
-                        isEnabled = telephonyMgr.isImsRegistered();
+                        isEnabled = telephonyMgr.isImsRegisteredForSubscriber(subInfo
+                                .getSubscriptionId());
                         if (isEnabled) {
                             break;
                         }