Make Satellite UI updatable during receiving callback (part I)

- Refactor code
 - Make Satellite category and preference be updatable by callback.

Flag: EXEMPT bug fix
Fix: 396233604
Test: atest pass
Change-Id: If2e3d9b82950f05c4911ee7ce3bb41fb26e0d3e4
This commit is contained in:
tom hsu
2025-02-17 17:22:07 +00:00
parent be9c39f0aa
commit 048be18c5e
2 changed files with 141 additions and 94 deletions

View File

@@ -58,30 +58,34 @@ public class SatelliteSettingPreferenceController extends
private static final String TAG = "SatelliteSettingPreferenceController";
@VisibleForTesting
final CarrierRoamingNtnModeCallback mCarrierRoamingNtnModeCallback =
new CarrierRoamingNtnModeCallback();
new CarrierRoamingNtnModeCallback(this);
CarrierConfigCache mCarrierConfigCache;
SatelliteManager mSatelliteManager;
private TelephonyManager mTelephonyManager = null;
private TelephonyManager mTelephonyManager;
@Nullable
private Boolean mIsSatelliteEligible = null;
private boolean mIsServiceDataType = false;
@VisibleForTesting
boolean mIsSatelliteSmsAvailableForManualType = false;
private PersistableBundle mCarrierConfigs = new PersistableBundle();
private PreferenceScreen mPreferenceScreen;
public SatelliteSettingPreferenceController(@NonNull Context context, @NonNull String key) {
super(context, key);
mCarrierConfigCache = CarrierConfigCache.getInstance(context);
mSatelliteManager = context.getSystemService(SatelliteManager.class);
mTelephonyManager = context.getSystemService(TelephonyManager.class);
}
private static void logd(String message) {
Log.d(TAG, message);
}
private static void loge(String message) {
Log.e(TAG, message);
/**
* Set subId for Satellite Settings page.
*
* @param subId subscription ID.
*/
public void initialize(int subId) {
logd("initialize(), subId=" + subId);
mSubId = subId;
mCarrierConfigCache = CarrierConfigCache.getInstance(mContext);
mSatelliteManager = mContext.getSystemService(SatelliteManager.class);
mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
if (mTelephonyManager != null) {
mTelephonyManager = mTelephonyManager.createForSubscriptionId(subId);
}
mCarrierConfigs = mCarrierConfigCache.getConfigForSubId(subId);
}
@Override
@@ -95,43 +99,58 @@ public class SatelliteSettingPreferenceController extends
return UNSUPPORTED_ON_DEVICE;
}
boolean isSatelliteAttachSupport = mCarrierConfigs.getBoolean(
KEY_SATELLITE_ATTACH_SUPPORTED_BOOL);
if (isSatelliteAttachSupport && isCarrierRoamingNtnConnectedTypeAuto()
&& mIsSatelliteSmsAvailableForManualType) {
return AVAILABLE;
if (!mCarrierConfigs.getBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL)) {
return CONDITIONALLY_UNAVAILABLE;
}
return CONDITIONALLY_UNAVAILABLE;
if (isCarrierRoamingNtnConnectedTypeManual()) {
return mCarrierRoamingNtnModeCallback.isSatelliteSmsAvailable()
? AVAILABLE
: CONDITIONALLY_UNAVAILABLE;
} else {
return AVAILABLE;
}
}
@Override
public void onResume(@NonNull LifecycleOwner owner) {
if (com.android.settings.flags.Flags.satelliteOemSettingsUxMigration()) {
mTelephonyManager.registerTelephonyCallback(mContext.getMainExecutor(),
mCarrierRoamingNtnModeCallback);
if (mTelephonyManager != null) {
mTelephonyManager.registerTelephonyCallback(mContext.getMainExecutor(),
mCarrierRoamingNtnModeCallback);
}
}
}
@Override
public void onPause(@NonNull LifecycleOwner owner) {
if (com.android.settings.flags.Flags.satelliteOemSettingsUxMigration()) {
mTelephonyManager.unregisterTelephonyCallback(mCarrierRoamingNtnModeCallback);
if (mTelephonyManager != null) {
mTelephonyManager.unregisterTelephonyCallback(mCarrierRoamingNtnModeCallback);
}
}
}
@Override
public void displayPreference(@NonNull PreferenceScreen screen) {
super.displayPreference(screen);
if (mPreferenceScreen == null) {
mPreferenceScreen = screen;
}
updateState(screen.findPreference(getPreferenceKey()));
}
void displayPreference() {
if (mPreferenceScreen != null) {
displayPreference(mPreferenceScreen);
}
}
@Override
public void updateState(@Nullable Preference preference) {
super.updateState(preference);
if (preference != null && preference.getKey().equals(getPreferenceKey())) {
mCarrierRoamingNtnModeCallback.mPref = preference;
updateTitle(preference);
updateSummary(preference);
}
}
@@ -145,9 +164,10 @@ public class SatelliteSettingPreferenceController extends
// This will setup the Home and Search affordance
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, true);
intent.putExtra(SatelliteSetting.SUB_ID, mSubId);
intent.putExtra(SatelliteSetting.EXTRA_IS_SERVICE_DATA_TYPE, mIsServiceDataType);
intent.putExtra(SatelliteSetting.EXTRA_IS_SERVICE_DATA_TYPE,
mCarrierRoamingNtnModeCallback.isSatelliteServiceDataType());
intent.putExtra(SatelliteSetting.EXTRA_IS_SMS_AVAILABLE_FOR_MANUAL_TYPE,
mIsSatelliteSmsAvailableForManualType);
mCarrierRoamingNtnModeCallback.isSatelliteSmsAvailable());
mContext.startActivity(intent);
return true;
}
@@ -155,16 +175,10 @@ public class SatelliteSettingPreferenceController extends
return false;
}
/**
* Set subId for Satellite Settings page.
*
* @param subId subscription ID.
*/
public void initialize(int subId) {
logd("init(), subId=" + subId);
mSubId = subId;
mTelephonyManager = mTelephonyManager.createForSubscriptionId(subId);
mCarrierConfigs = mCarrierConfigCache.getConfigForSubId(subId);
private void updateTitle(Preference preference) {
preference.setTitle(mCarrierRoamingNtnModeCallback.isSatelliteServiceDataType()
? R.string.title_satellite_setting_connectivity
: R.string.satellite_setting_title);
}
private void updateSummary(Preference preference) {
@@ -182,7 +196,12 @@ public class SatelliteSettingPreferenceController extends
return;
}
if (isCarrierRoamingNtnConnectedTypeAuto()) {
if (isCarrierRoamingNtnConnectedTypeManual()) {
preference.setSummary(
mCarrierRoamingNtnModeCallback.isSatelliteSmsAvailable()
? R.string.satellite_setting_enabled_summary
: R.string.satellite_setting_disabled_summary);
} else {
try {
Set<Integer> restrictionReason =
mSatelliteManager.getAttachRestrictionReasonsForCarrier(mSubId);
@@ -199,23 +218,42 @@ public class SatelliteSettingPreferenceController extends
loge(ex.toString());
preference.setSummary(R.string.satellite_setting_disabled_summary);
}
} else {
preference.setSummary(mIsSatelliteSmsAvailableForManualType
? R.string.satellite_setting_enabled_summary
: R.string.satellite_setting_disabled_summary);
}
}
private boolean isCarrierRoamingNtnConnectedTypeAuto() {
return CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC == mCarrierConfigs.getInt(
private boolean isCarrierRoamingNtnConnectedTypeManual() {
return CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC != mCarrierConfigs.getInt(
KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT,
CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC);
}
private static void logd(String message) {
Log.d(TAG, message);
}
private static void loge(String message) {
Log.e(TAG, message);
}
@VisibleForTesting
class CarrierRoamingNtnModeCallback extends TelephonyCallback implements
static class CarrierRoamingNtnModeCallback extends TelephonyCallback implements
TelephonyCallback.CarrierRoamingNtnListener {
Preference mPref = null;
SatelliteSettingPreferenceController mSatelliteSettingPreferenceController;
private boolean mIsSatelliteServiceDataType = false;
private boolean mIsSatelliteSmsAvailable = false;
CarrierRoamingNtnModeCallback(
SatelliteSettingPreferenceController satelliteSettingPreferenceController) {
mSatelliteSettingPreferenceController = satelliteSettingPreferenceController;
}
boolean isSatelliteServiceDataType() {
return mIsSatelliteServiceDataType;
}
boolean isSatelliteSmsAvailable() {
return mIsSatelliteSmsAvailable;
}
@Override
public void onCarrierRoamingNtnAvailableServicesChanged(int[] availableServices) {
@@ -226,15 +264,9 @@ public class SatelliteSettingPreferenceController extends
boolean isDataAvailable = availableServicesList.contains(SERVICE_TYPE_DATA);
logd("isSmsAvailable : " + isSmsAvailable
+ " / isDataAvailable " + isDataAvailable);
if (mPref == null) {
logd("Satellite preference is not initialized yet");
return;
}
mIsServiceDataType = isDataAvailable;
mIsSatelliteSmsAvailableForManualType = isSmsAvailable;
mPref.setTitle(isDataAvailable ? R.string.title_satellite_setting_connectivity
: R.string.satellite_setting_title);
updateSummary(mPref);
mIsSatelliteServiceDataType = isDataAvailable;
mIsSatelliteSmsAvailable = isSmsAvailable;
mSatelliteSettingPreferenceController.displayPreference();
}
@Override