For subscriptions that support wifi calling, we have a preference on the
mobile network details page which leads to a Wifi Calling page. That
page already supports the concept of multiple subscriptions with a
header strip containing a tab for each subscription that supports wifi
calling. However, we were not necessarily selecting the *correct* tab
when going to this page. So you might be viewing the mobile network
details for subscription B and click on "Wifi Calling", only to land on
the page with the tab for subscription A selected.
This CL fixes the problem by adding an extra with the current
subscription id to the Preference's intent in
WifiCallingPreferenceController, and then reads that extra in
WifiCallingSettings and uses it to select the appropriate tab.
Fixes:
117135894
Test: make RunSettingsRoboTests
Change-Id: I3aec30072712247d14fe0fb6b61207535f9e981c
import android.content.pm.ResolveInfo;
import android.os.Looper;
import android.os.PersistableBundle;
+import android.provider.Settings;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telephony.CarrierConfigManager;
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
+ Intent intent = mPreference.getIntent();
+ if (intent != null) {
+ intent.putExtra(Settings.EXTRA_SUB_ID, mSubId);
+ }
if (!isAvailable()) {
// Set category as invisible
final Preference preferenceCateogry = screen.findPreference(KEY_PREFERENCE_CATEGORY);
package com.android.settings.wifi.calling;
import android.app.settings.SettingsEnums;
+import android.content.Intent;
import android.os.Bundle;
+import android.provider.Settings;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
+import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import com.android.internal.util.CollectionUtils;
import com.android.settings.R;
import com.android.settings.core.InstrumentedFragment;
+import com.android.settings.network.SubscriptionUtil;
import com.android.settings.search.actionbar.SearchMenuController;
import com.android.settings.support.actionbar.HelpMenuController;
import com.android.settings.support.actionbar.HelpResourceProvider;
mPagerAdapter = new WifiCallingViewPagerAdapter(getChildFragmentManager(), mViewPager);
mViewPager.setAdapter(mPagerAdapter);
mViewPager.addOnPageChangeListener(new InternalViewPagerListener());
-
+ maybeSetViewForSubId();
return view;
}
+ private void maybeSetViewForSubId() {
+ if (mSil == null) {
+ return;
+ }
+ Intent intent = getActivity().getIntent();
+ if (intent == null) {
+ return;
+ }
+ int subId = intent.getIntExtra(Settings.EXTRA_SUB_ID,
+ SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+ if (SubscriptionManager.isValidSubscriptionId(subId)) {
+ for (SubscriptionInfo subInfo : mSil) {
+ if (subId == subInfo.getSubscriptionId()) {
+ mViewPager.setCurrentItem(mSil.indexOf(subInfo));
+ break;
+ }
+ }
+ }
+ }
+
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
return R.string.help_uri_wifi_calling;
}
- private final class WifiCallingViewPagerAdapter extends FragmentPagerAdapter {
+ @VisibleForTesting
+ final class WifiCallingViewPagerAdapter extends FragmentPagerAdapter {
private final RtlCompatibleViewPager mViewPager;
public WifiCallingViewPagerAdapter(FragmentManager fragmentManager,
}
}
+ @VisibleForTesting
+ boolean isWfcEnabledByPlatform(SubscriptionInfo info) {
+ ImsManager imsManager = ImsManager.getInstance(getActivity(), info.getSimSlotIndex());
+ return imsManager.isWfcEnabledByPlatform();
+ }
+
private void updateSubList() {
- mSil = SubscriptionManager.from(getActivity()).getActiveSubscriptionInfoList(true);
+ mSil = SubscriptionUtil.getActiveSubscriptions(
+ getContext().getSystemService(SubscriptionManager.class));
// Only config Wfc if it's enabled by platform.
if (mSil == null) {
return;
}
for (int i = 0; i < mSil.size(); ) {
- ImsManager imsManager = ImsManager.getInstance(getActivity(),
- mSil.get(i).getSimSlotIndex());
- if (!imsManager.isWfcEnabledByPlatform()) {
+ if (!isWfcEnabledByPlatform(mSil.get(i))) {
mSil.remove(i);
} else {
i++;
import static org.mockito.Mockito.when;
import android.content.Context;
+import android.content.Intent;
import android.os.PersistableBundle;
+import android.provider.Settings;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
when(mPreferenceScreen.findPreference(
WifiCallingPreferenceController.KEY_PREFERENCE_CATEGORY)).thenReturn(
mPreferenceCategory);
+ when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
+ mPreference);
}
@Test
}
@Test
+ public void displayPreference_available_setsSubscriptionIdOnIntent() {
+ Intent intent = new Intent();
+ mPreference.setIntent(intent);
+ mController.displayPreference(mPreferenceScreen);
+ assertThat(intent.getIntExtra(Settings.EXTRA_SUB_ID,
+ SubscriptionManager.INVALID_SUBSCRIPTION_ID)).isEqualTo(SUB_ID);
+ }
+
+ @Test
public void getAvailabilityStatus_noWiFiCalling_shouldReturnUnsupported() {
mController.init(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
--- /dev/null
+/*
+ * Copyright (C) 2019 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 static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Intent;
+import android.provider.Settings;
+import android.telephony.SubscriptionInfo;
+import android.view.View;
+
+import androidx.fragment.app.FragmentActivity;
+
+import com.android.settings.R;
+import com.android.settings.network.SubscriptionUtil;
+import com.android.settings.widget.RtlCompatibleViewPager;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.shadows.androidx.fragment.FragmentController;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+
+@RunWith(RobolectricTestRunner.class)
+public class WifiCallingSettingsTest {
+
+ private WifiCallingSettings mFragment;
+
+ @Before
+ public void setUp() {
+ mFragment = spy(new WifiCallingSettings());
+ }
+
+ @Test
+ public void setupFragment_noSubscriptions_noCrash() {
+ FragmentController.setupFragment(mFragment, FragmentActivity.class, 0 /* containerViewId*/,
+ null /* bundle */);
+ }
+
+ @Test
+ public void setupFragment_oneSubscription_noCrash() {
+ SubscriptionInfo info = mock(SubscriptionInfo.class);
+ when(info.getSubscriptionId()).thenReturn(111);
+
+ SubscriptionUtil.setActiveSubscriptionsForTesting(new ArrayList<>(
+ Collections.singletonList(info)));
+ doReturn(true).when(mFragment).isWfcEnabledByPlatform(any(SubscriptionInfo.class));
+
+ Intent intent = new Intent();
+ intent.putExtra(Settings.EXTRA_SUB_ID, info.getSubscriptionId());
+ FragmentController.of(mFragment, intent).create(0 /* containerViewId*/,
+ null /* bundle */).start().resume().visible().get();
+
+ View view = mFragment.getView();
+ RtlCompatibleViewPager pager = view.findViewById(R.id.view_pager);
+ WifiCallingSettings.WifiCallingViewPagerAdapter adapter =
+ (WifiCallingSettings.WifiCallingViewPagerAdapter) pager.getAdapter();
+ assertThat(adapter.getCount()).isEqualTo(1);
+ }
+
+ @Test
+ public void setupFragment_twoSubscriptions_correctSelection() {
+ SubscriptionInfo info1 = mock(SubscriptionInfo.class);
+ SubscriptionInfo info2 = mock(SubscriptionInfo.class);
+ when(info1.getSubscriptionId()).thenReturn(111);
+ when(info2.getSubscriptionId()).thenReturn(222);
+
+ SubscriptionUtil.setActiveSubscriptionsForTesting(new ArrayList<>(
+ Arrays.asList(info1, info2)));
+ doReturn(true).when(mFragment).isWfcEnabledByPlatform(any(SubscriptionInfo.class));
+
+ Intent intent = new Intent();
+ intent.putExtra(Settings.EXTRA_SUB_ID, info2.getSubscriptionId());
+ FragmentController.of(mFragment, intent).create(0 /* containerViewId*/,
+ null /* bundle */).start().resume().visible().get();
+
+ View view = mFragment.getView();
+ RtlCompatibleViewPager pager = view.findViewById(R.id.view_pager);
+ assertThat(pager.getCurrentItem()).isEqualTo(1);
+
+ WifiCallingSettings.WifiCallingViewPagerAdapter adapter =
+ (WifiCallingSettings.WifiCallingViewPagerAdapter) pager.getAdapter();
+ assertThat(adapter.getCount()).isEqualTo(2);
+ }
+}