Merge "[Settings] Fix failure test case"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ec4d8ef..0c33b04 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -141,7 +141,8 @@
<activity android:name=".network.telephony.MobileNetworkActivity"
android:label="@string/network_settings_title"
android:exported="true"
- android:launchMode="singleTask">
+ android:launchMode="singleTask"
+ android:configChanges="orientation|screenSize|keyboardHidden">
<intent-filter android:priority="1">
<!-- Displays the MobileNetworkActivity and opt-in dialog for capability discovery. -->
<action android:name="android.telephony.ims.action.SHOW_CAPABILITY_DISCOVERY_OPT_IN" />
diff --git a/res/layout/dialog_sim_status.xml b/res/layout/dialog_sim_status.xml
index 27d12a8..c169e58 100644
--- a/res/layout/dialog_sim_status.xml
+++ b/res/layout/dialog_sim_status.xml
@@ -166,6 +166,7 @@
android:id="@+id/esim_id_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:textIsSelectable="true"
android:text="@string/device_info_not_available"/>
<TextView
diff --git a/res/layout/wifi_calling_settings_preferences.xml b/res/layout/wifi_calling_settings_preferences.xml
index 98acd95..9a6cbe6 100644
--- a/res/layout/wifi_calling_settings_preferences.xml
+++ b/res/layout/wifi_calling_settings_preferences.xml
@@ -29,16 +29,11 @@
<FrameLayout
android:id="@android:id/tabcontent"
- android:layout_width="0dip"
- android:layout_height="0dip" />
-
- <FrameLayout
- android:id="@+id/prefs_container"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
- android:clipChildren="false"
- android:clipToPadding="false"
+ android:clipChildren="true"
+ android:clipToPadding="true"
android:smoothScrollbar="false" />
</LinearLayout>
diff --git a/res/xml/wifi_calling_settings.xml b/res/xml/wifi_calling_settings.xml
index 0276bdb..902ff1a 100644
--- a/res/xml/wifi_calling_settings.xml
+++ b/res/xml/wifi_calling_settings.xml
@@ -21,6 +21,7 @@
<com.android.settings.wifi.calling.ListWithEntrySummaryPreference
android:key="wifi_calling_mode"
+ isPreferenceVisible="false"
android:title="@string/wifi_calling_mode_title"
android:summary="@string/wifi_calling_mode_title"
android:entries="@array/wifi_calling_mode_choices"
@@ -30,6 +31,7 @@
<com.android.settings.wifi.calling.ListWithEntrySummaryPreference
android:key="wifi_calling_roaming_mode"
+ isPreferenceVisible="false"
android:title="@string/wifi_calling_roaming_mode_title"
android:summary="@string/wifi_calling_roaming_mode_summary"
android:entries="@array/wifi_calling_mode_choices_v2"
@@ -39,7 +41,12 @@
<Preference
android:key="emergency_address_key"
+ isPreferenceVisible="false"
android:title="@string/emergency_address_title"
android:summary="@string/emergency_address_summary" />
+ <com.android.settings.wifi.calling.LinkifyDescriptionPreference
+ android:key="no_options_description"
+ isPreferenceVisible="false" />
+
</PreferenceScreen>
diff --git a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
index 25e0ae0..aa58663 100644
--- a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
+++ b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
@@ -23,9 +23,11 @@
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyCallback;
import android.telephony.TelephonyManager;
import android.util.Log;
+import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
@@ -59,16 +61,25 @@
private CarrierConfigManager mCarrierConfigManager;
private PreferenceEntriesBuilder mBuilder;
private SubscriptionsChangeListener mSubscriptionsListener;
+ private int mCallState = TelephonyManager.CALL_STATE_IDLE;
+ private PhoneCallStateTelephonyCallback mTelephonyCallback;
public EnabledNetworkModePreferenceController(Context context, String key) {
super(context, key);
mSubscriptionsListener = new SubscriptionsChangeListener(context, this);
mCarrierConfigManager = mContext.getSystemService(CarrierConfigManager.class);
+ if (mTelephonyCallback == null) {
+ mTelephonyCallback = new PhoneCallStateTelephonyCallback();
+ }
}
@Override
public int getAvailabilityStatus(int subId) {
boolean visible;
+ if (!isCallStateIdle()) {
+ return AVAILABLE_UNSEARCHABLE;
+ }
+
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
visible = false;
@@ -87,23 +98,28 @@
return visible ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
+ protected boolean isCallStateIdle() {
+ return mCallState == TelephonyManager.CALL_STATE_IDLE;
+ }
@OnLifecycleEvent(ON_START)
public void onStart() {
mSubscriptionsListener.start();
- if (mAllowedNetworkTypesListener == null) {
+ if (mAllowedNetworkTypesListener == null || mTelephonyCallback == null) {
return;
}
mAllowedNetworkTypesListener.register(mContext, mSubId);
+ mTelephonyCallback.register(mTelephonyManager, mSubId);
}
@OnLifecycleEvent(ON_STOP)
public void onStop() {
mSubscriptionsListener.stop();
- if (mAllowedNetworkTypesListener == null) {
+ if (mAllowedNetworkTypesListener == null || mTelephonyCallback == null) {
return;
}
mAllowedNetworkTypesListener.unregister(mContext, mSubId);
+ mTelephonyCallback.unregister();
}
@Override
@@ -125,6 +141,7 @@
listPreference.setEntryValues(mBuilder.getEntryValues());
listPreference.setValue(Integer.toString(mBuilder.getSelectedEntryValue()));
listPreference.setSummary(mBuilder.getSummary());
+ listPreference.setEnabled(isCallStateIdle());
}
@Override
@@ -157,7 +174,6 @@
updatePreference();
});
}
-
lifecycle.addObserver(this);
}
@@ -828,6 +844,43 @@
}
+ @VisibleForTesting
+ class PhoneCallStateTelephonyCallback extends TelephonyCallback implements
+ TelephonyCallback.CallStateListener {
+
+ private TelephonyManager mTelephonyManager;
+
+ @Override
+ public void onCallStateChanged(int state) {
+ Log.d(LOG_TAG, "onCallStateChanged:" + state);
+ mCallState = state;
+ mBuilder.updateConfig();
+ updatePreference();
+ }
+
+ public void register(TelephonyManager telephonyManager, int subId) {
+ mTelephonyManager = telephonyManager;
+
+ // assign current call state so that it helps to show correct preference state even
+ // before first onCallStateChanged() by initial registration.
+ mCallState = mTelephonyManager.getCallState(subId);
+ mTelephonyManager.registerTelephonyCallback(
+ mContext.getMainExecutor(), mTelephonyCallback);
+ }
+
+ public void unregister() {
+ mCallState = TelephonyManager.CALL_STATE_IDLE;
+ if (mTelephonyManager != null) {
+ mTelephonyManager.unregisterTelephonyCallback(this);
+ }
+ }
+ }
+
+ @VisibleForTesting
+ PhoneCallStateTelephonyCallback getTelephonyCallback() {
+ return mTelephonyCallback;
+ }
+
@Override
public void onAirplaneModeChanged(boolean airplaneModeEnabled) {
}
diff --git a/src/com/android/settings/wifi/calling/LinkifyDescriptionPreference.java b/src/com/android/settings/wifi/calling/LinkifyDescriptionPreference.java
new file mode 100644
index 0000000..60400b0
--- /dev/null
+++ b/src/com/android/settings/wifi/calling/LinkifyDescriptionPreference.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2021 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.settings.wifi.calling;
+
+import android.content.Context;
+import android.text.SpannableString;
+import android.text.TextUtils;
+import android.text.method.LinkMovementMethod;
+import android.text.style.ClickableSpan;
+import android.text.util.Linkify;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.TextView;
+
+import androidx.core.text.util.LinkifyCompat;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceViewHolder;
+
+import com.android.settings.R;
+
+/** A preference which supports linkify text as a description in the summary **/
+public class LinkifyDescriptionPreference extends Preference {
+
+ public LinkifyDescriptionPreference(Context context) {
+ this(context, null);
+ }
+
+ public LinkifyDescriptionPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ public void onBindViewHolder(PreferenceViewHolder holder) {
+ super.onBindViewHolder(holder);
+
+ final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
+ if (summaryView == null || summaryView.getVisibility() != View.VISIBLE) {
+ return;
+ }
+
+ final CharSequence summary = getSummary();
+ if (TextUtils.isEmpty(summary)) {
+ return;
+ }
+
+ summaryView.setMaxLines(Integer.MAX_VALUE);
+
+ final SpannableString spannableSummary = new SpannableString(summary);
+ if (spannableSummary.getSpans(0, spannableSummary.length(), ClickableSpan.class)
+ .length > 0) {
+ summaryView.setMovementMethod(LinkMovementMethod.getInstance());
+ }
+ LinkifyCompat.addLinks(summaryView,
+ Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS);
+ }
+}
diff --git a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
index 18583f1..19664be 100644
--- a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
@@ -35,7 +35,6 @@
import android.telephony.ims.ImsMmTelManager;
import android.telephony.ims.ProvisioningManager;
import android.text.TextUtils;
-import android.text.util.Linkify;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -58,8 +57,11 @@
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.network.ims.WifiCallingQueryImsState;
import com.android.settings.widget.SettingsMainSwitchBar;
+import com.android.settings.wifi.calling.LinkifyDescriptionPreference;
import com.android.settingslib.widget.OnMainSwitchChangeListener;
+import java.util.List;
+
/**
* This is the inner class of {@link WifiCallingSettings} fragment.
* The preference screen lets you enable/disable Wi-Fi Calling and change Wi-Fi Calling mode.
@@ -73,6 +75,7 @@
private static final String BUTTON_WFC_MODE = "wifi_calling_mode";
private static final String BUTTON_WFC_ROAMING_MODE = "wifi_calling_roaming_mode";
private static final String PREFERENCE_EMERGENCY_ADDRESS = "emergency_address_key";
+ private static final String PREFERENCE_NO_OPTIONS_DESC = "no_options_description";
@VisibleForTesting
static final int REQUEST_CHECK_WFC_EMERGENCY_ADDRESS = 1;
@@ -92,7 +95,6 @@
private ListWithEntrySummaryPreference mButtonWfcMode;
private ListWithEntrySummaryPreference mButtonWfcRoamingMode;
private Preference mUpdateAddress;
- private TextView mEmptyView;
private boolean mValidListener = false;
private boolean mEditableWfcMode = true;
@@ -157,7 +159,7 @@
}
/*
- * Launch carrier emergency address managemnent activity
+ * Launch carrier emergency address management activity
*/
private final OnPreferenceClickListener mUpdateAddressListener =
preference -> {
@@ -186,14 +188,6 @@
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
- mEmptyView = getView().findViewById(android.R.id.empty);
- setEmptyView(mEmptyView);
- mEmptyView.setAutoLinkMask(Linkify.WEB_URLS);
- final Resources res = getResourcesForSubId();
- final String emptyViewText = res.getString(R.string.wifi_calling_off_explanation,
- res.getString(R.string.wifi_calling_off_explanation_2));
- mEmptyView.setText(emptyViewText);
-
mSwitchBar = getView().findViewById(R.id.switch_bar);
mSwitchBar.show();
}
@@ -309,6 +303,9 @@
mIntentFilter = new IntentFilter();
mIntentFilter.addAction(ImsManager.ACTION_WFC_IMS_REGISTRATION_ERROR);
+
+ updateDescriptionForOptions(
+ List.of(mButtonWfcMode, mButtonWfcRoamingMode, mUpdateAddress));
}
@Override
@@ -324,7 +321,7 @@
final View view = inflater.inflate(
R.layout.wifi_calling_settings_preferences, container, false);
- final ViewGroup prefs_container = view.findViewById(R.id.prefs_container);
+ final ViewGroup prefs_container = view.findViewById(android.R.id.tabcontent);
Utils.prepareCustomPreferencesList(container, view, prefs_container, false);
final View prefs = super.onCreateView(inflater, prefs_container, savedInstanceState);
prefs_container.addView(prefs);
@@ -573,28 +570,35 @@
final PreferenceScreen preferenceScreen = getPreferenceScreen();
final boolean updateAddressEnabled = (getCarrierActivityIntent() != null);
if (wfcEnabled) {
- if (mEditableWfcMode) {
- preferenceScreen.addPreference(mButtonWfcMode);
- } else {
- // Don't show WFC (home) preference if it's not editable.
- preferenceScreen.removePreference(mButtonWfcMode);
- }
- if (mEditableWfcRoamingMode && !mUseWfcHomeModeForRoaming) {
- preferenceScreen.addPreference(mButtonWfcRoamingMode);
- } else {
- // Don't show WFC roaming preference if it's not editable.
- preferenceScreen.removePreference(mButtonWfcRoamingMode);
- }
- if (updateAddressEnabled) {
- preferenceScreen.addPreference(mUpdateAddress);
- } else {
- preferenceScreen.removePreference(mUpdateAddress);
- }
+ // Don't show WFC (home) preference if it's not editable.
+ mButtonWfcMode.setVisible(mEditableWfcMode);
+ // Don't show WFC roaming preference if it's not editable.
+ mButtonWfcRoamingMode.setVisible(
+ mEditableWfcRoamingMode && !mUseWfcHomeModeForRoaming);
+ mUpdateAddress.setVisible(updateAddressEnabled);
} else {
- preferenceScreen.removePreference(mButtonWfcMode);
- preferenceScreen.removePreference(mButtonWfcRoamingMode);
- preferenceScreen.removePreference(mUpdateAddress);
+ mButtonWfcMode.setVisible(false);
+ mButtonWfcRoamingMode.setVisible(false);
+ mUpdateAddress.setVisible(false);
}
+ updateDescriptionForOptions(
+ List.of(mButtonWfcMode, mButtonWfcRoamingMode, mUpdateAddress));
+ }
+
+ private void updateDescriptionForOptions(List<Preference> visibleOptions) {
+ LinkifyDescriptionPreference pref = findPreference(PREFERENCE_NO_OPTIONS_DESC);
+ if (pref == null) {
+ return;
+ }
+
+ boolean optionsAvailable = visibleOptions.stream().anyMatch(Preference::isVisible);
+ if (!optionsAvailable) {
+ final Resources res = getResourcesForSubId();
+ String emptyViewText = res.getString(R.string.wifi_calling_off_explanation,
+ res.getString(R.string.wifi_calling_off_explanation_2));
+ pref.setSummary(emptyViewText);
+ }
+ pref.setVisible(!optionsAvailable);
}
@Override
diff --git a/tests/unit/src/com/android/settings/network/EnabledNetworkModePreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/EnabledNetworkModePreferenceControllerTest.java
index 81841b7..20f8a55 100644
--- a/tests/unit/src/com/android/settings/network/EnabledNetworkModePreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/EnabledNetworkModePreferenceControllerTest.java
@@ -19,6 +19,7 @@
import static androidx.lifecycle.Lifecycle.Event.ON_START;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.android.settings.network.telephony.MobileNetworkUtils.getRafFromNetworkType;
import static com.android.settings.network.telephony.TelephonyConstants.RadioAccessFamily.CDMA;
@@ -32,6 +33,8 @@
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -154,6 +157,30 @@
@UiThreadTest
@Test
+ public void getAvailabilityStatus_callStateIsIdle_returnAvailable() {
+ mockEnabledNetworkMode(TelephonyManagerConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA);
+ mController.getTelephonyCallback().onCallStateChanged(TelephonyManager.CALL_STATE_IDLE);
+
+ mController.updateState(mPreference);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ assertTrue(mPreference.isEnabled());
+ }
+
+ @UiThreadTest
+ @Test
+ public void getAvailabilityStatus_duringCalling_returnAvailable() {
+ mockEnabledNetworkMode(TelephonyManagerConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA);
+ mController.getTelephonyCallback().onCallStateChanged(TelephonyManager.CALL_STATE_OFFHOOK);
+
+ mController.updateState(mPreference);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
+ assertFalse(mPreference.isEnabled());
+ }
+
+ @UiThreadTest
+ @Test
public void updateState_LteWorldPhone_GlobalHasLte() {
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);