Fix creating ConnectivityUtil to work on any platform
After this CL, ConnectivityUtil for default subId is used again on pre
N because TelephonyManager has createForSubscriptionId() for a specific
subId from N.
Nevertheless, listen() uses the default subId on PhoneStateListener
instead of the subId on the manager still even N. On O and beyond,
ConnectivityUtil works correctly on multi-sim devices.
Revert "Fix missing computeIfAbsent() method in L_MR1 and M"
This reverts commit f0ccb76d8d.
Reason for revert: Manage ConnectivityUtil instances for subIds at least
on N instead.
Test: Manual
Signed-off-by: Taesu Lee <taesu82.lee@samsung.com>
Change-Id: I2f08928a6798a2ce275c5c75569ad379999d274c
This commit is contained in:
@@ -23,6 +23,16 @@ import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.messaging.datamodel.data.ParticipantData;
|
||||
|
||||
/**
|
||||
* ConnectivityUtil listens to the network service state changes.
|
||||
*
|
||||
* On N and beyond, This class instance can be created via ConnectivityUtil(context, subId), use
|
||||
* ConnectivityUtil(context) for others.
|
||||
*
|
||||
* Note that TelephonyManager has createForSubscriptionId() for a specific subId from N but listen()
|
||||
* does not use the subId on the manager, and uses the default subId on PhoneStateListener. From O,
|
||||
* the manager uses its' own subId in listen().
|
||||
*/
|
||||
public class ConnectivityUtil {
|
||||
// Assume not connected until informed differently
|
||||
private volatile int mCurrentServiceState = ServiceState.STATE_POWER_OFF;
|
||||
@@ -40,6 +50,7 @@ public class ConnectivityUtil {
|
||||
}
|
||||
|
||||
public ConnectivityUtil(final Context context, final int subId) {
|
||||
Assert.isTrue(OsUtil.isAtLeastN());
|
||||
mTelephonyManager =
|
||||
((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE))
|
||||
.createForSubscriptionId(subId);
|
||||
|
||||
Reference in New Issue
Block a user