Merge "Make UI and wording dynamically show on" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
29bb748539
@@ -12302,8 +12302,10 @@
|
|||||||
<string name="satellite_warning_dialog_title">Can’t turn on <xliff:g id="function" example="bluetooth">%1$s</xliff:g></string>
|
<string name="satellite_warning_dialog_title">Can’t turn on <xliff:g id="function" example="bluetooth">%1$s</xliff:g></string>
|
||||||
<!-- Content for satellite warning dialog to avoid user using wifi/bluetooth/airplane mode [CHAR_LIMIT=NONE] -->
|
<!-- Content for satellite warning dialog to avoid user using wifi/bluetooth/airplane mode [CHAR_LIMIT=NONE] -->
|
||||||
<string name="satellite_warning_dialog_content">To turn on <xliff:g id="function" example="bluetooth">%1$s</xliff:g>, first end the satellite connection</string>
|
<string name="satellite_warning_dialog_content">To turn on <xliff:g id="function" example="bluetooth">%1$s</xliff:g>, first end the satellite connection</string>
|
||||||
<!-- Category title for satellite functions in mobile network settings [CHAR LIMIT=60] -->
|
<!-- Category title for satellite functions with data transmission in mobile network settings [CHAR LIMIT=60] -->
|
||||||
<string name="category_title_satellite_connectivity">Satellite connectivity</string>
|
<string name="category_title_satellite_connectivity">Satellite connectivity</string>
|
||||||
|
<!-- Title for satellite functions with data transmission in mobile network settings [CHAR LIMIT=60] -->
|
||||||
|
<string name="satellite_setting_connectivity">Satellite connectivity</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- Title for Apn settings in mobile network settings [CHAR LIMIT=60] -->
|
<!-- Title for Apn settings in mobile network settings [CHAR LIMIT=60] -->
|
||||||
|
@@ -206,7 +206,7 @@
|
|||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="telephony_satellite_settings_category_key"
|
android:key="telephony_satellite_settings_category_key"
|
||||||
android:title="@string/category_title_satellite_connectivity"
|
android:title="@string/satellite_setting_title"
|
||||||
settings:controller="com.android.settings.network.telephony.SatelliteSettingsPreferenceCategoryController">
|
settings:controller="com.android.settings.network.telephony.SatelliteSettingsPreferenceCategoryController">
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedPreference
|
<com.android.settingslib.RestrictedPreference
|
||||||
|
@@ -86,6 +86,7 @@ public class SatelliteSettingPreferenceController extends
|
|||||||
@Override
|
@Override
|
||||||
public void displayPreference(@NonNull PreferenceScreen screen) {
|
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
|
updateState(screen.findPreference(getPreferenceKey()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -16,55 +16,120 @@
|
|||||||
|
|
||||||
package com.android.settings.network.telephony;
|
package com.android.settings.network.telephony;
|
||||||
|
|
||||||
|
import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_DATA;
|
||||||
|
import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_SMS;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.PersistableBundle;
|
import android.telephony.TelephonyCallback;
|
||||||
import android.telephony.CarrierConfigManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.telephony.satellite.SatelliteManager;
|
import android.telephony.satellite.NtnSignalStrength;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.telephony.flags.Flags;
|
import androidx.annotation.NonNull;
|
||||||
import com.android.settings.network.CarrierConfigCache;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
import androidx.lifecycle.DefaultLifecycleObserver;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
/** Preference controller for Satellite functions in mobile network settings.*/
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** Preference controller for Satellite functions in mobile network settings. */
|
||||||
public class SatelliteSettingsPreferenceCategoryController
|
public class SatelliteSettingsPreferenceCategoryController
|
||||||
extends TelephonyBasePreferenceController {
|
extends TelephonyBasePreferenceController implements DefaultLifecycleObserver {
|
||||||
private static final String TAG = "SatelliteSettingsPrefCategoryCon";
|
private static final String TAG = "SatelliteSettingsPrefCategoryCon";
|
||||||
|
|
||||||
private CarrierConfigCache mCarrierConfigCache;
|
private PreferenceCategory mPreferenceCategory;
|
||||||
private SatelliteManager mSatelliteManager;
|
private TelephonyManager mTelephonyManager = null;
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
final CarrierRoamingNtnModeCallback mCarrierRoamingNtnModeCallback =
|
||||||
|
new CarrierRoamingNtnModeCallback();
|
||||||
|
|
||||||
public SatelliteSettingsPreferenceCategoryController(Context context, String key) {
|
public SatelliteSettingsPreferenceCategoryController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mCarrierConfigCache = CarrierConfigCache.getInstance(context);
|
setAvailabilityStatus(UNSUPPORTED_ON_DEVICE);
|
||||||
mSatelliteManager = context.getSystemService(SatelliteManager.class);
|
mTelephonyManager = context.getSystemService(TelephonyManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set subId for Satellite Settings category .
|
* Set subId for Satellite Settings category .
|
||||||
|
*
|
||||||
* @param subId subscription ID.
|
* @param subId subscription ID.
|
||||||
*/
|
*/
|
||||||
public void init(int subId) {
|
public void init(int subId) {
|
||||||
Log.d(TAG, "init(), subId=" + subId);
|
Log.d(TAG, "init(), subId=" + subId);
|
||||||
mSubId = subId;
|
mSubId = subId;
|
||||||
|
mTelephonyManager = mTelephonyManager.createForSubscriptionId(subId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mPreferenceCategory = screen.findPreference(getPreferenceKey());
|
||||||
|
if (mPreferenceCategory.getPreferenceCount() > 0) {
|
||||||
|
for (int i = 0; i < mPreferenceCategory.getPreferenceCount(); i++) {
|
||||||
|
if (mPreferenceCategory.getPreference(i).isVisible()) {
|
||||||
|
setAvailabilityStatus(AVAILABLE_UNSEARCHABLE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus(int subId) {
|
public int getAvailabilityStatus(int subId) {
|
||||||
if (!Flags.carrierEnabledSatelliteFlag()) {
|
return isAvailable() ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
|
||||||
Log.d(TAG, "getAvailabilityStatus(" + subId + ") : carrierEnabledSatelliteFlag "
|
|
||||||
+ "is disabled");
|
|
||||||
return UNSUPPORTED_ON_DEVICE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSatelliteManager == null) {
|
@Override
|
||||||
Log.d(TAG, "getAvailabilityStatus(" + subId + ") : SatelliteManager is null");
|
public void onResume(@NonNull LifecycleOwner owner) {
|
||||||
return UNSUPPORTED_ON_DEVICE;
|
mTelephonyManager.registerTelephonyCallback(mContext.getMainExecutor(),
|
||||||
|
mCarrierRoamingNtnModeCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(subId);
|
@Override
|
||||||
final boolean isSatelliteAttachSupported = carrierConfig.getBoolean(
|
public void onPause(@NonNull LifecycleOwner owner) {
|
||||||
CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL);
|
mTelephonyManager.unregisterTelephonyCallback(mCarrierRoamingNtnModeCallback);
|
||||||
|
}
|
||||||
|
|
||||||
return isSatelliteAttachSupported ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
@VisibleForTesting
|
||||||
|
class CarrierRoamingNtnModeCallback extends TelephonyCallback implements
|
||||||
|
TelephonyCallback.CarrierRoamingNtnModeListener {
|
||||||
|
@Override
|
||||||
|
public void onCarrierRoamingNtnAvailableServicesChanged(List<Integer> availableServices) {
|
||||||
|
CarrierRoamingNtnModeListener.super.onCarrierRoamingNtnAvailableServicesChanged(
|
||||||
|
availableServices);
|
||||||
|
boolean isSmsAvailable = availableServices.contains(SERVICE_TYPE_SMS);
|
||||||
|
boolean isDataAvailable = availableServices.contains(SERVICE_TYPE_DATA);
|
||||||
|
Log.i(TAG, "isSmsAvailable : " + isSmsAvailable
|
||||||
|
+ " / isDataAvailable " + isDataAvailable);
|
||||||
|
if (mPreferenceCategory == null) {
|
||||||
|
Log.d(TAG, "Satellite preference category is not initialized yet");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isDataAvailable) {
|
||||||
|
mPreferenceCategory.setTitle(R.string.category_title_satellite_connectivity);
|
||||||
|
} else if (isSmsAvailable) {
|
||||||
|
mPreferenceCategory.setTitle(R.string.satellite_setting_title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCarrierRoamingNtnEligibleStateChanged(boolean eligible) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCarrierRoamingNtnModeChanged(boolean active) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCarrierRoamingNtnSignalStrengthChanged(NtnSignalStrength ntnSignalStrength) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,38 +16,37 @@
|
|||||||
|
|
||||||
package com.android.settings.network.telephony;
|
package com.android.settings.network.telephony;
|
||||||
|
|
||||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_DATA;
|
||||||
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_SMS;
|
||||||
|
|
||||||
|
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
|
||||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.PersistableBundle;
|
|
||||||
import android.platform.test.annotations.DisableFlags;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
|
||||||
import android.telephony.CarrierConfigManager;
|
|
||||||
import android.telephony.satellite.SatelliteManager;
|
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.internal.telephony.flags.Flags;
|
import com.android.settings.R;
|
||||||
import com.android.settings.network.CarrierConfigCache;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.junit.MockitoJUnit;
|
import org.mockito.junit.MockitoJUnit;
|
||||||
import org.mockito.junit.MockitoRule;
|
import org.mockito.junit.MockitoRule;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class SatelliteSettingsPreferenceCategoryControllerTest {
|
public class SatelliteSettingsPreferenceCategoryControllerTest {
|
||||||
private static final String KEY = "key";
|
private static final String KEY = "key";
|
||||||
@@ -55,16 +54,9 @@ public class SatelliteSettingsPreferenceCategoryControllerTest {
|
|||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||||
@Rule
|
|
||||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private CarrierConfigCache mCarrierConfigCache;
|
|
||||||
|
|
||||||
private Context mContext = null;
|
private Context mContext = null;
|
||||||
private SatelliteManager mSatelliteManager = null;
|
|
||||||
private SatelliteSettingsPreferenceCategoryController mController = null;
|
private SatelliteSettingsPreferenceCategoryController mController = null;
|
||||||
private PersistableBundle mCarrierConfig = new PersistableBundle();
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -72,25 +64,38 @@ public class SatelliteSettingsPreferenceCategoryControllerTest {
|
|||||||
Looper.prepare();
|
Looper.prepare();
|
||||||
}
|
}
|
||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
mSatelliteManager = new SatelliteManager(mContext);
|
|
||||||
CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
|
|
||||||
when(mContext.getSystemService(SatelliteManager.class)).thenReturn(mSatelliteManager);
|
|
||||||
mController = new SatelliteSettingsPreferenceCategoryController(mContext, KEY);
|
mController = new SatelliteSettingsPreferenceCategoryController(mContext, KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisableFlags(Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG)
|
public void getAvailabilityStatus_default_returnUnsupported() {
|
||||||
public void getAvailabilityStatus_featureDisabled_returnUnsupport() {
|
|
||||||
int result = mController.getAvailabilityStatus(TEST_SUB_ID);
|
int result = mController.getAvailabilityStatus(TEST_SUB_ID);
|
||||||
|
|
||||||
assertThat(result).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
assertThat(result).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableFlags(Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG)
|
public void getAvailabilityStatus_hasAvailablePreference_returnAvailableUnsearchable() {
|
||||||
public void getAvailabilityStatus_noSatellite_returnUnsupport() {
|
PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
||||||
when(mContext.getSystemService(SatelliteManager.class)).thenReturn(null);
|
PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext);
|
||||||
mController = new SatelliteSettingsPreferenceCategoryController(mContext, KEY);
|
PreferenceCategory preferenceCategory = new PreferenceCategory(mContext);
|
||||||
|
preferenceCategory.setKey(KEY);
|
||||||
|
preferenceScreen.addPreference(preferenceCategory);
|
||||||
|
preferenceCategory.addPreference(new Preference(mContext));
|
||||||
|
mController.displayPreference(preferenceScreen);
|
||||||
|
|
||||||
|
int result = mController.getAvailabilityStatus(TEST_SUB_ID);
|
||||||
|
|
||||||
|
assertThat(result).isEqualTo(AVAILABLE_UNSEARCHABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_noAvailablePreference_returnUnsupported() {
|
||||||
|
PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
||||||
|
PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext);
|
||||||
|
PreferenceCategory preferenceCategory = new PreferenceCategory(mContext);
|
||||||
|
preferenceCategory.setKey(KEY);
|
||||||
|
preferenceScreen.addPreference(preferenceCategory);
|
||||||
|
mController.displayPreference(preferenceScreen);
|
||||||
|
|
||||||
int result = mController.getAvailabilityStatus(TEST_SUB_ID);
|
int result = mController.getAvailabilityStatus(TEST_SUB_ID);
|
||||||
|
|
||||||
@@ -98,30 +103,37 @@ public class SatelliteSettingsPreferenceCategoryControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableFlags(Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG)
|
public void setPreferenceTitle_hasDataService_showConnectivity() {
|
||||||
public void getAvailabilityStatus_carrierIsNotSupport_returnUnavailable() {
|
PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
||||||
when(mContext.getSystemService(SatelliteManager.class)).thenReturn(null);
|
PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext);
|
||||||
mCarrierConfig.putBoolean(
|
PreferenceCategory preferenceCategory = new PreferenceCategory(mContext);
|
||||||
CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL,
|
preferenceCategory.setKey(KEY);
|
||||||
false);
|
preferenceScreen.addPreference(preferenceCategory);
|
||||||
when(mCarrierConfigCache.getConfigForSubId(TEST_SUB_ID)).thenReturn(mCarrierConfig);
|
preferenceCategory.addPreference(new Preference(mContext));
|
||||||
|
mController.displayPreference(preferenceScreen);
|
||||||
|
|
||||||
int result = mController.getAvailabilityStatus(TEST_SUB_ID);
|
mController.mCarrierRoamingNtnModeCallback.onCarrierRoamingNtnAvailableServicesChanged(
|
||||||
|
List.of(SERVICE_TYPE_DATA));
|
||||||
|
|
||||||
assertThat(result).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
assertThat(preferenceCategory.getTitle()).isEqualTo(
|
||||||
|
mContext.getString(R.string.satellite_setting_connectivity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableFlags(Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG)
|
public void setPreferenceTitle_hasSmsService_showMessaging() {
|
||||||
public void getAvailabilityStatus_carrierIsSupport_returnAvailable() {
|
PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
||||||
when(mContext.getSystemService(SatelliteManager.class)).thenReturn(null);
|
PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext);
|
||||||
mCarrierConfig.putBoolean(
|
PreferenceCategory preferenceCategory = new PreferenceCategory(mContext);
|
||||||
CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL,
|
preferenceCategory.setKey(KEY);
|
||||||
true);
|
preferenceScreen.addPreference(preferenceCategory);
|
||||||
when(mCarrierConfigCache.getConfigForSubId(TEST_SUB_ID)).thenReturn(mCarrierConfig);
|
preferenceCategory.addPreference(new Preference(mContext));
|
||||||
|
mController.displayPreference(preferenceScreen);
|
||||||
|
|
||||||
int result = mController.getAvailabilityStatus(TEST_SUB_ID);
|
mController.mCarrierRoamingNtnModeCallback.onCarrierRoamingNtnAvailableServicesChanged(
|
||||||
|
List.of(SERVICE_TYPE_SMS));
|
||||||
|
|
||||||
assertThat(result).isEqualTo(AVAILABLE);
|
assertThat(preferenceCategory.getTitle()).isEqualTo(
|
||||||
|
mContext.getString(R.string.satellite_setting_title));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user