Merge "Merge "improve mism support for phonestatelistner" into qt-dev am: 62751b8014" into qt-dev-plus-aosp

am: fd1359d926

Change-Id: I9dae41bb301e2ad2e717f20a7f7403c300575d5f
This commit is contained in:
Chen Xu
2019-05-01 15:16:42 -07:00
committed by android-build-merger
5 changed files with 53 additions and 25 deletions

View File

@@ -94,8 +94,7 @@ public class MobileSignalController extends SignalController<
mPhone = phone;
mDefaults = defaults;
mSubscriptionInfo = info;
mPhoneStateListener = new MobilePhoneStateListener(info.getSubscriptionId(),
receiverLooper);
mPhoneStateListener = new MobilePhoneStateListener(receiverLooper);
mNetworkNameSeparator = getStringIfExists(R.string.status_bar_network_name_separator);
mNetworkNameDefault = getStringIfExists(
com.android.internal.R.string.lockscreen_carrier_default);
@@ -574,8 +573,8 @@ public class MobileSignalController extends SignalController<
}
class MobilePhoneStateListener extends PhoneStateListener {
public MobilePhoneStateListener(int subId, Looper looper) {
super(subId, looper);
public MobilePhoneStateListener(Looper looper) {
super(looper);
}
@Override

View File

@@ -662,8 +662,9 @@ public class NetworkControllerImpl extends BroadcastReceiver
cachedControllers.remove(subId);
} else {
MobileSignalController controller = new MobileSignalController(mContext, mConfig,
mHasMobileDataFeature, mPhone, mCallbackHandler,
this, subscriptions.get(i), mSubDefaults, mReceiverHandler.getLooper());
mHasMobileDataFeature, mPhone.createForSubscriptionId(subId),
mCallbackHandler, this, subscriptions.get(i),
mSubDefaults, mReceiverHandler.getLooper());
controller.setUserSetupComplete(mUserSetup);
mMobileSignalControllers.put(subId, controller);
if (subscriptions.get(i).getSimSlotIndex() == 0) {
@@ -1049,7 +1050,8 @@ public class NetworkControllerImpl extends BroadcastReceiver
SubscriptionInfo info = new SubscriptionInfo(id, "", simSlotIndex, "", "", 0, 0, "", 0,
null, null, null, "", false, null, null);
MobileSignalController controller = new MobileSignalController(mContext,
mConfig, mHasMobileDataFeature, mPhone, mCallbackHandler, this, info,
mConfig, mHasMobileDataFeature,
mPhone.createForSubscriptionId(info.getSubscriptionId()), mCallbackHandler, this, info,
mSubDefaults, mReceiverHandler.getLooper());
mMobileSignalControllers.put(id, controller);
controller.getState().userSetup = true;

View File

@@ -130,6 +130,7 @@ public class NetworkControllerBaseTest extends SysuiTestCase {
when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(true);
when(mMockCm.getDefaultNetworkCapabilitiesForUser(0)).thenReturn(
new NetworkCapabilities[] { mNetCapabilities });
when(mMockTm.createForSubscriptionId(anyInt())).thenReturn(mMockTm);
mSignalStrength = mock(SignalStrength.class);
mServiceState = mock(ServiceState.class);

View File

@@ -38,6 +38,8 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import dalvik.system.VMRuntime;
/**
* A listener class for monitoring changes in specific telephony states
* on the device, including service state, signal strength, message
@@ -400,8 +402,12 @@ public class PhoneStateListener {
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public PhoneStateListener(Integer subId) {
this(subId, Looper.myLooper());
if (subId != null && VMRuntime.getRuntime().getTargetSdkVersion()
>= Build.VERSION_CODES.Q) {
throw new IllegalArgumentException("PhoneStateListener with subId: "
+ subId + " is not supported, use default constructor");
}
}
/**
* Create a PhoneStateListener for the Phone using the specified subscription
* and non-null Looper.
@@ -410,6 +416,11 @@ public class PhoneStateListener {
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public PhoneStateListener(Integer subId, Looper looper) {
this(subId, new HandlerExecutor(new Handler(looper)));
if (subId != null && VMRuntime.getRuntime().getTargetSdkVersion()
>= Build.VERSION_CODES.Q) {
throw new IllegalArgumentException("PhoneStateListener with subId: "
+ subId + " is not supported, use default constructor");
}
}
/**

View File

@@ -108,6 +108,8 @@ import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import dalvik.system.VMRuntime;
/**
* Provides access to information about the telephony services on
* the device. Applications can use the methods in this class to
@@ -4869,18 +4871,22 @@ public class TelephonyManager {
* Registers a listener object to receive notification of changes
* in specified telephony states.
* <p>
* To register a listener, pass a {@link PhoneStateListener}
* and specify at least one telephony state of interest in
* the events argument.
* To register a listener, pass a {@link PhoneStateListener} and specify at least one telephony
* state of interest in the events argument.
*
* At registration, and when a specified telephony state
* changes, the telephony manager invokes the appropriate
* callback method on the listener object and passes the
* current (updated) values.
* At registration, and when a specified telephony state changes, the telephony manager invokes
* the appropriate callback method on the listener object and passes the current (updated)
* values.
* <p>
* To unregister a listener, pass the listener object and set the
* events argument to
* To un-register a listener, pass the listener object and set the events argument to
* {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0).
*
* If this TelephonyManager object has been created with {@link #createForSubscriptionId},
* applies to the given subId. Otherwise, applies to
* {@link SubscriptionManager#getDefaultSubscriptionId()}. To listen events for multiple subIds,
* pass a separate listener object to each TelephonyManager object created with
* {@link #createForSubscriptionId}.
*
* Note: if you call this method while in the middle of a binder transaction, you <b>must</b>
* call {@link android.os.Binder#clearCallingIdentity()} before calling this method. A
* {@link SecurityException} will be thrown otherwise.
@@ -4895,17 +4901,26 @@ public class TelephonyManager {
if (mContext == null) return;
try {
boolean notifyNow = (getITelephony() != null);
// If the listener has not explicitly set the subId (for example, created with the
// default constructor), replace the subId so it will listen to the account the
// telephony manager is created with.
if (listener.mSubId == null) {
listener.mSubId = mSubId;
}
ITelephonyRegistry registry = getTelephonyRegistry();
if (registry != null) {
registry.listenForSubscriber(listener.mSubId, getOpPackageName(),
int subId;
// subId from phonestatelistner is deprecated Q on forward, use the subId from
// TelephonyManager instance.
if (VMRuntime.getRuntime().getTargetSdkVersion() >= Build.VERSION_CODES.Q
|| listener.mSubId == null) {
subId = mSubId;
} else {
subId = listener.mSubId;
}
registry.listenForSubscriber(subId, getOpPackageName(),
listener.callback, events, notifyNow);
// TODO: remove this once we remove PhoneStateListener constructor with subId.
if (events == PhoneStateListener.LISTEN_NONE) {
listener.mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
} else {
listener.mSubId = subId;
}
} else {
Rlog.w(TAG, "telephony registry not ready.");
}