Merge "Use SatelliteManager API to check device support satellite or not." into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
2342373850
@@ -152,7 +152,7 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
|
||||
}
|
||||
|
||||
private void updateTitle() {
|
||||
getActivity().setTitle(getSubjectString());
|
||||
findPreference("satellite_setting").setTitle(getSubjectString());
|
||||
}
|
||||
|
||||
// About satellite content
|
||||
@@ -315,7 +315,6 @@ public class SatelliteSetting extends RestrictedDashboardFragment {
|
||||
}
|
||||
|
||||
private boolean isSatelliteAttachSupported(int subId) {
|
||||
|
||||
return mConfigBundle.getBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, false);
|
||||
}
|
||||
|
||||
|
@@ -23,6 +23,7 @@ import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ESOS_SUPPORTE
|
||||
import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_SMS;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.OutcomeReceiver;
|
||||
import android.os.PersistableBundle;
|
||||
import android.telephony.TelephonyCallback;
|
||||
import android.telephony.TelephonyManager;
|
||||
@@ -41,6 +42,8 @@ import com.android.settings.network.CarrierConfigCache;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/** Preference controller for Satellite functions in mobile network settings. */
|
||||
public class SatelliteSettingsPreferenceCategoryController
|
||||
@@ -55,6 +58,8 @@ public class SatelliteSettingsPreferenceCategoryController
|
||||
private SatelliteManager mSatelliteManager;
|
||||
private TelephonyManager mTelephonyManager;
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
@VisibleForTesting
|
||||
AtomicBoolean mIsSatelliteSupported = new AtomicBoolean(false);
|
||||
|
||||
public SatelliteSettingsPreferenceCategoryController(Context context, String key) {
|
||||
super(context, key);
|
||||
@@ -71,6 +76,7 @@ public class SatelliteSettingsPreferenceCategoryController
|
||||
mCarrierConfigCache = CarrierConfigCache.getInstance(mContext);
|
||||
mSatelliteManager = mContext.getSystemService(SatelliteManager.class);
|
||||
mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
|
||||
requestIsSatelliteSupported();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,7 +99,7 @@ public class SatelliteSettingsPreferenceCategoryController
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
if (mSatelliteManager == null) {
|
||||
if (!mIsSatelliteSupported.get()) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@@ -142,6 +148,21 @@ public class SatelliteSettingsPreferenceCategoryController
|
||||
}
|
||||
}
|
||||
|
||||
private void requestIsSatelliteSupported() {
|
||||
if (mSatelliteManager == null) {
|
||||
Log.d(TAG, "SatelliteManager is null");
|
||||
return;
|
||||
}
|
||||
mSatelliteManager.requestIsSupported(Executors.newSingleThreadExecutor(),
|
||||
new OutcomeReceiver<>() {
|
||||
@Override
|
||||
public void onResult(Boolean result) {
|
||||
mIsSatelliteSupported.set(result);
|
||||
SatelliteSettingsPreferenceCategoryController.this.displayPreference();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static class CarrierRoamingNtnModeCallback extends TelephonyCallback implements
|
||||
TelephonyCallback.CarrierRoamingNtnListener {
|
||||
|
@@ -78,12 +78,24 @@ public class SatelliteSettingsPreferenceCategoryControllerTest {
|
||||
mController = new SatelliteSettingsPreferenceCategoryController(mContext, KEY);
|
||||
when(mCarrierConfigCache.getConfigForSubId(TEST_SUB_ID)).thenReturn(mPersistableBundle);
|
||||
when(mContext.getSystemService(SatelliteManager.class)).thenReturn(satelliteManager);
|
||||
mController.mIsSatelliteSupported.set(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG)
|
||||
public void getAvailabilityStatus_noSatelliteManager_returnUnsupported() {
|
||||
when(mContext.getSystemService(SatelliteManager.class)).thenReturn(null);
|
||||
mController.init(TEST_SUB_ID);
|
||||
|
||||
int result = mController.getAvailabilityStatus(TEST_SUB_ID);
|
||||
|
||||
assertThat(result).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG)
|
||||
public void getAvailabilityStatus_deviceUnsupported_returnUnsupported() {
|
||||
when(mContext.getSystemService(SatelliteManager.class)).thenReturn(null);
|
||||
mController.mIsSatelliteSupported.set(false);
|
||||
|
||||
int result = mController.getAvailabilityStatus(TEST_SUB_ID);
|
||||
|
||||
|
Reference in New Issue
Block a user