Merge "Reflash the Network selection value when onResume" into udc-qpr-dev am: c5944f5cbd am: b1ceb4cc82

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/24444208

Change-Id: Ieb88bcd6ceb55950048e565a192d8c8f920710a2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
SongFerng Wang
2023-08-28 19:19:16 +00:00
committed by Automerger Merge Worker

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() {
mAllowedNetworkTypesListener.register(mContext, mSubId);
}
@OnLifecycleEvent(ON_STOP)
public void onStop() {
mAllowedNetworkTypesListener.unregister(mContext, mSubId);
/**
* 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();
}
});
});
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;
}