Merge "Use alternative PhoneStateListener formal API"

This commit is contained in:
Paul Hu
2021-02-25 12:14:53 +00:00
committed by Gerrit Code Review

View File

@@ -40,6 +40,8 @@ import com.android.internal.annotations.VisibleForTesting;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; 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 * A class to encapsulate management of the "Smart Networking" capability of
@@ -73,6 +75,32 @@ public class MultinetworkPolicyTracker {
private volatile int mMeteredMultipathPreference; private volatile int mMeteredMultipathPreference;
private int mActiveSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 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) { public MultinetworkPolicyTracker(Context ctx, Handler handler) {
this(ctx, handler, null); this(ctx, handler, null);
} }
@@ -93,14 +121,8 @@ public class MultinetworkPolicyTracker {
} }
}; };
ctx.getSystemService(TelephonyManager.class).listen( ctx.getSystemService(TelephonyManager.class).registerPhoneStateListener(
new PhoneStateListener(handler.getLooper()) { new HandlerExecutor(handler), new ActiveDataSubscriptionIdChangedListener());
@Override
public void onActiveDataSubscriptionIdChanged(int subId) {
mActiveSubId = subId;
reevaluateInternal();
}
}, PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE);
updateAvoidBadWifi(); updateAvoidBadWifi();
updateMeteredMultipathPreference(); updateMeteredMultipathPreference();