From 0d2b748aea748c823b48450fd45df13520d7e71b Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Tue, 16 Mar 2021 19:30:08 +0900 Subject: [PATCH] Check for FEATURE_TELEPHONY instead of CM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../com/android/server/policy/LegacyGlobalActions.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/policy/LegacyGlobalActions.java b/services/core/java/com/android/server/policy/LegacyGlobalActions.java index 9c3a394400543..5b48abb3e1f2d 100644 --- a/services/core/java/com/android/server/policy/LegacyGlobalActions.java +++ b/services/core/java/com/android/server/policy/LegacyGlobalActions.java @@ -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 =