Check for FEATURE_TELEPHONY instead of CM

The ConnectivityManager#isNetworkSupported has been
deprecated a long time ago and can no longer be called
from the system server as it's moving to a mainline
module. Instead of checking for support of a MOBILE
network, ask for FEATURE_TELEPHONY.

Note that this might not be 100% behavior-neutral, as
the old ConnectivityManager#isNetworkSupported would
return based on an OEM-configured resource, while the
new one is based on whether the device supports the
feature ; in particular, devices with phone call
support but without data support have the feature,
but may not have had the resource configuration. The
contention is that the new behavior is better, because
Airplane mode should depend on whether there is a
telephony radio on the device, not on whether that
radio supports data transfers.

Bug: 172183305
Test: FrameworksServicesTests
Change-Id: Ifb5ba537cb029b3aeebf74407002d873ec614f8d
This commit is contained in:
Chalard Jean 2021-03-16 19:30:08 +09:00
parent 5b30e438de
commit 0d2b748aea

View File

@ -24,11 +24,11 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.database.ContentObserver;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
@ -113,7 +113,7 @@ class LegacyGlobalActions implements DialogInterface.OnDismissListener, DialogIn
private boolean mDeviceProvisioned = false;
private ToggleAction.State mAirplaneState = ToggleAction.State.Off;
private boolean mIsWaitingForEcmExit = false;
private boolean mHasTelephony;
private final boolean mHasTelephony;
private boolean mHasVibrator;
private final boolean mShowSilentToggle;
private final EmergencyAffordanceManager mEmergencyAffordanceManager;
@ -137,9 +137,8 @@ class LegacyGlobalActions implements DialogInterface.OnDismissListener, DialogIn
filter.addAction(TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
context.registerReceiver(mBroadcastReceiver, filter);
ConnectivityManager cm = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
mHasTelephony = cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
mHasTelephony =
context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
// get notified of phone state changes
TelephonyManager telephonyManager =