Snap for 4793185 from 23db26fdfa70b4e1bbccee34fcef51d2bc70f52d to pi-release

Change-Id: Iaed9323dd66cae65e38c21b4a8ffde7c6f13a13d
diff --git a/src/com/android/phone/CdmaOptions.java b/src/com/android/phone/CdmaOptions.java
index ff37c70..7f7d58c 100644
--- a/src/com/android/phone/CdmaOptions.java
+++ b/src/com/android/phone/CdmaOptions.java
@@ -26,9 +26,11 @@
 import android.telephony.CarrierConfigManager;
 import android.text.TextUtils;
 
+import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.logging.MetricsLogger;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.internal.telephony.Phone;
+import com.android.internal.telephony.PhoneConstants;
 import com.android.settingslib.RestrictedLockUtils;
 
 /**
@@ -53,6 +55,12 @@
     private PreferenceScreen mPrefScreen;
     private Phone mPhone;
 
+    // Constructor for CdmaOptionsTest, since PreferenceScreen is final and cannot be mocked
+    @VisibleForTesting
+    public CdmaOptions(Phone phone) {
+        mPhone = phone;
+    }
+
     public CdmaOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen, Phone phone) {
         mPrefFragment = prefFragment;
         mPrefScreen = prefScreen;
@@ -79,8 +87,7 @@
         PersistableBundle carrierConfig =
                 PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
         // Some CDMA carriers want the APN settings.
-        boolean addAPNExpand =
-                carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL);
+        boolean addAPNExpand = shouldAddApnExpandPreference(carrierConfig);
         boolean addCdmaSubscription =
                 deviceSupportsNvAndRuim();
         // Read platform settings for carrier settings
@@ -94,6 +101,7 @@
         // Calling add or remove explicitly to make sure they are updated.
 
         if (addAPNExpand) {
+            log("update: addAPNExpand");
             mButtonAPNExpand.setDisabledByAdmin(
                     MobileNetworkSettings.isDpcApnEnforced(mButtonAPNExpand.getContext())
                             ? RestrictedLockUtils.getDeviceOwner(mButtonAPNExpand.getContext())
@@ -136,6 +144,19 @@
         }
     }
 
+    /**
+     * Return whether we should add the APN expandable preference based on the phone type and
+     * carrier config
+     */
+    @VisibleForTesting
+    public boolean shouldAddApnExpandPreference(PersistableBundle config) {
+        if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA
+                && config.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL)) {
+            return true;
+        }
+        return false;
+    }
+
     private boolean deviceSupportsNvAndRuim() {
         // retrieve the list of subscription types supported by device.
         String subscriptionsSupported = SystemProperties.get("ril.subscription.types");
diff --git a/src/com/android/phone/GsmUmtsOptions.java b/src/com/android/phone/GsmUmtsOptions.java
index 220cf34..19cd3ef 100644
--- a/src/com/android/phone/GsmUmtsOptions.java
+++ b/src/com/android/phone/GsmUmtsOptions.java
@@ -26,8 +26,8 @@
 
 import com.android.internal.logging.MetricsLogger;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
-import com.android.internal.telephony.PhoneFactory;
 import com.android.settingslib.RestrictedLockUtils;
 
 /**
@@ -72,9 +72,11 @@
         boolean addAPNExpand = true;
         boolean addNetworkOperatorsCategory = true;
         boolean addCarrierSettings = true;
-        if (PhoneFactory.getDefaultPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
+        Phone phone = PhoneGlobals.getPhone(subId);
+        if (phone == null) return;
+        if (phone.getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
             log("Not a GSM phone");
-            mCategoryAPNExpand.setEnabled(false);
+            addAPNExpand = false;
             mNetworkOperator.setEnabled(false);
         } else {
             log("Not a CDMA phone");
@@ -96,7 +98,7 @@
             }
 
             if (carrierConfig.getBoolean(CarrierConfigManager.KEY_CSP_ENABLED_BOOL)) {
-                if (PhoneFactory.getDefaultPhone().isCspPlmnEnabled()) {
+                if (phone.isCspPlmnEnabled()) {
                     log("[CSP] Enabling Operator Selection menu.");
                     mNetworkOperator.setEnabled(true);
                 } else {
@@ -114,6 +116,7 @@
         // Calling add or remove explicitly to make sure they are updated.
 
         if (addAPNExpand) {
+            log("update: addAPNExpand");
             mButtonAPNExpand.setDisabledByAdmin(
                     MobileNetworkSettings.isDpcApnEnforced(mButtonAPNExpand.getContext())
                             ? RestrictedLockUtils.getDeviceOwner(mButtonAPNExpand.getContext())
diff --git a/src/com/android/phone/MobileNetworkSettings.java b/src/com/android/phone/MobileNetworkSettings.java
index 799b9bc..691d9ff 100644
--- a/src/com/android/phone/MobileNetworkSettings.java
+++ b/src/com/android/phone/MobileNetworkSettings.java
@@ -1929,15 +1929,10 @@
 
             updateGsmUmtsOptions(this, prefSet, mPhone.getSubId(), mNetworkQueryService);
 
-            PreferenceCategory apnExpand =
-                    (PreferenceCategory) prefSet.findPreference(CATEGORY_GSM_APN_EXPAND_KEY);
             PreferenceCategory networkOperatorCategory =
                     (PreferenceCategory) prefSet.findPreference(
                             NetworkOperators.CATEGORY_NETWORK_OPERATORS_KEY);
             Preference carrierSettings = prefSet.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
-            if (apnExpand != null) {
-                apnExpand.setEnabled(isWorldMode() || enable);
-            }
             if (networkOperatorCategory != null) {
                 if (enable) {
                     networkOperatorCategory.setEnabled(true);
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index f7d1747..e80a06e 100644
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -162,15 +162,6 @@
                         mSsNotification =
                                 (SuppServiceNotification)((AsyncResult) msg.obj).result;
                         if (mOriginalConnection != null) {
-                            if (mSsNotification.history != null) {
-                                Bundle lastForwardedNumber = new Bundle();
-                                Log.v(TelephonyConnection.this,
-                                        "Updating call history info in extras.");
-                                lastForwardedNumber.putStringArrayList(
-                                        Connection.EXTRA_LAST_FORWARDED_NUMBER,
-                                        new ArrayList(Arrays.asList(mSsNotification.history)));
-                                putExtras(lastForwardedNumber);
-                            }
                             handleSuppServiceNotification(mSsNotification);
                         }
                     }
diff --git a/tests/src/com/android/phone/CdmaOptionsTest.java b/tests/src/com/android/phone/CdmaOptionsTest.java
new file mode 100644
index 0000000..446f2c5
--- /dev/null
+++ b/tests/src/com/android/phone/CdmaOptionsTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.phone;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.os.PersistableBundle;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
+import android.telephony.CarrierConfigManager;
+
+import com.android.internal.telephony.Phone;
+import com.android.internal.telephony.PhoneConstants;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+@RunWith(AndroidJUnit4.class)
+public class CdmaOptionsTest {
+    @Mock
+    private Phone mMockPhone;
+
+    private CdmaOptions mCdmaOptions;
+    private Context mContext;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = InstrumentationRegistry.getContext();
+        mCdmaOptions = new CdmaOptions(mMockPhone);
+    }
+
+    @Test
+    public void shouldAddApnExpandPreference_doesNotExpandOnGsm() {
+        when(mMockPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_GSM);
+        PersistableBundle bundle = new PersistableBundle();
+        bundle.putBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL, true);
+        assertFalse(mCdmaOptions.shouldAddApnExpandPreference(bundle));
+
+        when(mMockPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_CDMA);
+        bundle.putBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL, false);
+        assertFalse(mCdmaOptions.shouldAddApnExpandPreference(bundle));
+
+        when(mMockPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_CDMA);
+        bundle.putBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL, true);
+        assertTrue(mCdmaOptions.shouldAddApnExpandPreference(bundle));
+    }
+}