Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c5944f5c authored by SongFerng Wang's avatar SongFerng Wang Committed by Android (Google) Code Review
Browse files

Merge "Reflash the Network selection value when onResume" into udc-qpr-dev

parents 4b4328cb 8373fdd0
Loading
Loading
Loading
Loading
+37 −25
Original line number Diff line number Diff line
@@ -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;
    }