Merge "Use alternative PhoneStateListener formal API" am: 73e1c90697
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1554994 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I221f70b66e229c7209111227c40a0f4c0e616d85
This commit is contained in:
@@ -40,6 +40,8 @@ import com.android.internal.annotations.VisibleForTesting;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
|
||||
/**
|
||||
* A class to encapsulate management of the "Smart Networking" capability of
|
||||
@@ -73,6 +75,32 @@ public class MultinetworkPolicyTracker {
|
||||
private volatile int mMeteredMultipathPreference;
|
||||
private int mActiveSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
|
||||
// Mainline module can't use internal HandlerExecutor, so add an identical executor here.
|
||||
private static class HandlerExecutor implements Executor {
|
||||
@NonNull
|
||||
private final Handler mHandler;
|
||||
|
||||
HandlerExecutor(@NonNull Handler handler) {
|
||||
mHandler = handler;
|
||||
}
|
||||
@Override
|
||||
public void execute(Runnable command) {
|
||||
if (!mHandler.post(command)) {
|
||||
throw new RejectedExecutionException(mHandler + " is shutting down");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected class ActiveDataSubscriptionIdChangedListener extends PhoneStateListener
|
||||
implements PhoneStateListener.ActiveDataSubscriptionIdChangedListener {
|
||||
@Override
|
||||
public void onActiveDataSubscriptionIdChanged(int subId) {
|
||||
mActiveSubId = subId;
|
||||
reevaluateInternal();
|
||||
}
|
||||
}
|
||||
|
||||
public MultinetworkPolicyTracker(Context ctx, Handler handler) {
|
||||
this(ctx, handler, null);
|
||||
}
|
||||
@@ -93,14 +121,8 @@ public class MultinetworkPolicyTracker {
|
||||
}
|
||||
};
|
||||
|
||||
ctx.getSystemService(TelephonyManager.class).listen(
|
||||
new PhoneStateListener(handler.getLooper()) {
|
||||
@Override
|
||||
public void onActiveDataSubscriptionIdChanged(int subId) {
|
||||
mActiveSubId = subId;
|
||||
reevaluateInternal();
|
||||
}
|
||||
}, PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE);
|
||||
ctx.getSystemService(TelephonyManager.class).registerPhoneStateListener(
|
||||
new HandlerExecutor(handler), new ActiveDataSubscriptionIdChangedListener());
|
||||
|
||||
updateAvoidBadWifi();
|
||||
updateMeteredMultipathPreference();
|
||||
|
||||
Reference in New Issue
Block a user