Make UI and wording dynamically show on

- Satellite preferences may show on by deifferent reason. To fullfill
   these conditions, let category be able to dynamically show on base on
   the preference exist or not.
 - Show string of Connectivity or Messaging for service state change.

Flag: com.android.settings.flags.satellite_oem_settings_ux_migration
Fix: b/378408939
Test: atest pass
Test: make pass
Change-Id: Ibb0f9089805bb35d0334603e55d292c9883262ff
This commit is contained in:
tomhsu
2024-11-25 05:24:49 +00:00
committed by Tom Hsu
parent 9b65eafc84
commit db43380380
5 changed files with 151 additions and 71 deletions

View File

@@ -86,6 +86,7 @@ public class SatelliteSettingPreferenceController extends
@Override
public void displayPreference(@NonNull PreferenceScreen screen) {
super.displayPreference(screen);
updateState(screen.findPreference(getPreferenceKey()));
}
@Override

View File

@@ -16,55 +16,120 @@
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.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.satellite.SatelliteManager;
import android.telephony.TelephonyCallback;
import android.telephony.TelephonyManager;
import android.telephony.satellite.NtnSignalStrength;
import android.util.Log;
import com.android.internal.telephony.flags.Flags;
import com.android.settings.network.CarrierConfigCache;
import androidx.annotation.NonNull;
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
extends TelephonyBasePreferenceController {
extends TelephonyBasePreferenceController implements DefaultLifecycleObserver {
private static final String TAG = "SatelliteSettingsPrefCategoryCon";
private CarrierConfigCache mCarrierConfigCache;
private SatelliteManager mSatelliteManager;
private PreferenceCategory mPreferenceCategory;
private TelephonyManager mTelephonyManager = null;
@VisibleForTesting
final CarrierRoamingNtnModeCallback mCarrierRoamingNtnModeCallback =
new CarrierRoamingNtnModeCallback();
public SatelliteSettingsPreferenceCategoryController(Context context, String key) {
super(context, key);
mCarrierConfigCache = CarrierConfigCache.getInstance(context);
mSatelliteManager = context.getSystemService(SatelliteManager.class);
setAvailabilityStatus(UNSUPPORTED_ON_DEVICE);
mTelephonyManager = context.getSystemService(TelephonyManager.class);
}
/**
* Set subId for Satellite Settings category .
*
* @param subId subscription ID.
*/
public void init(int subId) {
Log.d(TAG, "init(), subId=" + 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
public int getAvailabilityStatus(int subId) {
if (!Flags.carrierEnabledSatelliteFlag()) {
Log.d(TAG, "getAvailabilityStatus(" + subId + ") : carrierEnabledSatelliteFlag "
+ "is disabled");
return UNSUPPORTED_ON_DEVICE;
return isAvailable() ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
public void onResume(@NonNull LifecycleOwner owner) {
mTelephonyManager.registerTelephonyCallback(mContext.getMainExecutor(),
mCarrierRoamingNtnModeCallback);
}
@Override
public void onPause(@NonNull LifecycleOwner owner) {
mTelephonyManager.unregisterTelephonyCallback(mCarrierRoamingNtnModeCallback);
}
@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);
}
}
if (mSatelliteManager == null) {
Log.d(TAG, "getAvailabilityStatus(" + subId + ") : SatelliteManager is null");
return UNSUPPORTED_ON_DEVICE;
@Override
public void onCarrierRoamingNtnEligibleStateChanged(boolean eligible) {
// Do nothing
}
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(subId);
final boolean isSatelliteAttachSupported = carrierConfig.getBoolean(
CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL);
@Override
public void onCarrierRoamingNtnModeChanged(boolean active) {
// Do nothing
}
return isSatelliteAttachSupported ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
@Override
public void onCarrierRoamingNtnSignalStrengthChanged(NtnSignalStrength ntnSignalStrength) {
// Do nothing
}
}
}