Reflash the Network selection value when onResume

Bug: 293983798
Test: build pass. atest AutoSelectPreferenceControllerTest
Change-Id: I7ed0a8ec655d8c00bc30695f0bd7c3cc6f84a2ae
This commit is contained in:
SongFerngWang
2023-08-16 18:55:43 +08:00
committed by SongFerng Wang
parent fdb53691b1
commit 8373fdd0d2

View File

@@ -16,6 +16,7 @@
package com.android.settings.network.telephony.gsm;
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
import static androidx.lifecycle.Lifecycle.Event.ON_START;
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
@@ -36,10 +37,11 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.lifecycle.LifecycleEventObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
@@ -63,10 +65,10 @@ import java.util.concurrent.atomic.AtomicLong;
* Preference controller for "Auto Select Network"
*/
public class AutoSelectPreferenceController extends TelephonyTogglePreferenceController
implements LifecycleObserver{
implements LifecycleEventObserver{
private static final long MINIMUM_DIALOG_TIME_MILLIS = TimeUnit.SECONDS.toMillis(1);
private static final String LOG_TAG = "AutoSelectPreferenceController";
private static final String INTERNAL_LOG_TAG_INIT = "Init";
private static final String INTERNAL_LOG_TAG_ONRESUME = "OnResume";
private static final String INTERNAL_LOG_TAG_AFTERSET = "AfterSet";
private final Handler mUiHandler;
@@ -110,14 +112,37 @@ public class AutoSelectPreferenceController extends TelephonyTogglePreferenceCon
}
}
@OnLifecycleEvent(ON_START)
public void onStart() {
/**
* Implementation of LifecycleEventObserver.
*/
@SuppressWarnings("FutureReturnValueIgnored")
public void onStateChanged(@NonNull LifecycleOwner lifecycleOwner,
@NonNull Lifecycle.Event event) {
switch (event) {
case ON_START:
mAllowedNetworkTypesListener.register(mContext, mSubId);
break;
case ON_RESUME:
ThreadUtils.postOnBackgroundThread(() -> {
queryNetworkSelectionMode(INTERNAL_LOG_TAG_ONRESUME);
//Update UI in UI thread
mUiHandler.post(() -> {
if (mSwitchPreference != null) {
mRecursiveUpdate.getAndIncrement();
mSwitchPreference.setChecked(isChecked());
mRecursiveUpdate.decrementAndGet();
updateListenerValue();
}
@OnLifecycleEvent(ON_STOP)
public void onStop() {
});
});
break;
case ON_STOP:
mAllowedNetworkTypesListener.unregister(mContext, mSubId);
break;
default:
// Do nothing
break;
}
}
@Override
@@ -243,19 +268,6 @@ public class AutoSelectPreferenceController extends TelephonyTogglePreferenceCon
updateUiAutoSelectValue(status);
}
};
ThreadUtils.postOnBackgroundThread(() -> {
queryNetworkSelectionMode(INTERNAL_LOG_TAG_INIT);
//Update UI in UI thread
mUiHandler.post(() -> {
if (mSwitchPreference != null) {
mRecursiveUpdate.getAndIncrement();
mSwitchPreference.setChecked(isChecked());
mRecursiveUpdate.decrementAndGet();
updateListenerValue();
}
});
});
return this;
}