Merge "Check if the SubscriptionsChangeListener has been started before stop" am: 162029c5b6
am: e67b576ab9
Original change: https://android-review.googlesource.com/c/platform/packages/apps/Settings/+/1679185 Change-Id: I7e906e3982dab72dfed796bc061f37468c2e3f2d
This commit is contained in:
@@ -27,12 +27,15 @@ import android.os.Looper;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
|
import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.telephony.TelephonyIntents;
|
import com.android.internal.telephony.TelephonyIntents;
|
||||||
|
|
||||||
/** Helper class for listening to changes in availability of telephony subscriptions */
|
/** Helper class for listening to changes in availability of telephony subscriptions */
|
||||||
public class SubscriptionsChangeListener extends ContentObserver {
|
public class SubscriptionsChangeListener extends ContentObserver {
|
||||||
|
|
||||||
|
private static final String TAG = "SubscriptionsChangeListener";
|
||||||
|
|
||||||
public interface SubscriptionsChangeListenerClient {
|
public interface SubscriptionsChangeListenerClient {
|
||||||
void onAirplaneModeChanged(boolean airplaneModeEnabled);
|
void onAirplaneModeChanged(boolean airplaneModeEnabled);
|
||||||
void onSubscriptionsChanged();
|
void onSubscriptionsChanged();
|
||||||
@@ -44,6 +47,7 @@ public class SubscriptionsChangeListener extends ContentObserver {
|
|||||||
private OnSubscriptionsChangedListener mSubscriptionsChangedListener;
|
private OnSubscriptionsChangedListener mSubscriptionsChangedListener;
|
||||||
private Uri mAirplaneModeSettingUri;
|
private Uri mAirplaneModeSettingUri;
|
||||||
private BroadcastReceiver mBroadcastReceiver;
|
private BroadcastReceiver mBroadcastReceiver;
|
||||||
|
private boolean mRunning = false;
|
||||||
|
|
||||||
public SubscriptionsChangeListener(Context context, SubscriptionsChangeListenerClient client) {
|
public SubscriptionsChangeListener(Context context, SubscriptionsChangeListenerClient client) {
|
||||||
super(new Handler(Looper.getMainLooper()));
|
super(new Handler(Looper.getMainLooper()));
|
||||||
@@ -75,12 +79,19 @@ public class SubscriptionsChangeListener extends ContentObserver {
|
|||||||
final IntentFilter radioTechnologyChangedFilter = new IntentFilter(
|
final IntentFilter radioTechnologyChangedFilter = new IntentFilter(
|
||||||
TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
|
TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
|
||||||
mContext.registerReceiver(mBroadcastReceiver, radioTechnologyChangedFilter);
|
mContext.registerReceiver(mBroadcastReceiver, radioTechnologyChangedFilter);
|
||||||
|
mRunning = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
mSubscriptionManager.removeOnSubscriptionsChangedListener(mSubscriptionsChangedListener);
|
if (mRunning) {
|
||||||
mContext.getContentResolver().unregisterContentObserver(this);
|
mSubscriptionManager.removeOnSubscriptionsChangedListener(
|
||||||
mContext.unregisterReceiver(mBroadcastReceiver);
|
mSubscriptionsChangedListener);
|
||||||
|
mContext.getContentResolver().unregisterContentObserver(this);
|
||||||
|
mContext.unregisterReceiver(mBroadcastReceiver);
|
||||||
|
mRunning = false;
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "Stop has been called without associated Start.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAirplaneModeOn() {
|
public boolean isAirplaneModeOn() {
|
||||||
|
Reference in New Issue
Block a user