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

Commit aeaad6bd authored by Jeremy Goldman's avatar Jeremy Goldman Committed by Android (Google) Code Review
Browse files

Merge "Check if the SubscriptionsChangeListener has been started before stop" into sc-dev

parents 770ad5cb 9c69df3b
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -27,12 +27,15 @@ import android.os.Looper;
import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
import android.util.Log;

import com.android.internal.telephony.TelephonyIntents;

/** Helper class for listening to changes in availability of telephony subscriptions */
public class SubscriptionsChangeListener extends ContentObserver {

    private static final String TAG = "SubscriptionsChangeListener";

    public interface SubscriptionsChangeListenerClient {
        void onAirplaneModeChanged(boolean airplaneModeEnabled);
        void onSubscriptionsChanged();
@@ -44,6 +47,7 @@ public class SubscriptionsChangeListener extends ContentObserver {
    private OnSubscriptionsChangedListener mSubscriptionsChangedListener;
    private Uri mAirplaneModeSettingUri;
    private BroadcastReceiver mBroadcastReceiver;
    private boolean mRunning = false;

    public SubscriptionsChangeListener(Context context, SubscriptionsChangeListenerClient client) {
        super(new Handler(Looper.getMainLooper()));
@@ -75,12 +79,19 @@ public class SubscriptionsChangeListener extends ContentObserver {
        final IntentFilter radioTechnologyChangedFilter = new IntentFilter(
                TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
        mContext.registerReceiver(mBroadcastReceiver, radioTechnologyChangedFilter);
        mRunning = true;
    }

    public void stop() {
        mSubscriptionManager.removeOnSubscriptionsChangedListener(mSubscriptionsChangedListener);
        if (mRunning) {
            mSubscriptionManager.removeOnSubscriptionsChangedListener(
                    mSubscriptionsChangedListener);
            mContext.getContentResolver().unregisterContentObserver(this);
            mContext.unregisterReceiver(mBroadcastReceiver);
            mRunning = false;
        } else {
            Log.d(TAG, "Stop has been called without associated Start.");
        }
    }

    public boolean isAirplaneModeOn() {