Use TelecomManager.isInCall instead of TelephonyManager.getCallState

UserManager.canSwitchUsers and UserManager.getUserSwitchability were
using the deprecated method TelephonyManager.getCallState and
comparing the result with TelephonyManager.CALL_STATE_IDLE to findout
whether there is an ongoing telephone call. This CL changes those
methods to use a helper method, which calls TelecomManager.isInCall
instead of the deprecated one.

Also UserInteractor.canSwitchUsers was sometimes failing with a
SecurityException during a user switch and crashing the systemui
process, causing it to restart after the user switch. This change
also saves the user switch flow from the underlying problem.

Bug: 257538981
Test: atest UserManagerTest
Change-Id: I378527db7decc170d385f0f1d89235b6f02649e6
This commit is contained in:
Yasin Kilicdere
2022-12-05 16:26:43 +00:00
parent 189b67e821
commit c347965080

View File

@@ -59,7 +59,7 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.location.LocationManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.telecom.TelecomManager;
import android.util.AndroidException;
import android.util.ArraySet;
import android.util.Log;
@@ -2139,13 +2139,8 @@ public class UserManager {
mContext.getContentResolver(),
Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED, 0) != 0;
boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM);
boolean inCall = false;
TelephonyManager telephonyManager = mContext.getSystemService(TelephonyManager.class);
if (telephonyManager != null) {
inCall = telephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE;
}
boolean isUserSwitchDisallowed = hasUserRestrictionForUser(DISALLOW_USER_SWITCH, mUserId);
return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall
return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall()
&& !isUserSwitchDisallowed;
}
@@ -2184,11 +2179,8 @@ public class UserManager {
android.Manifest.permission.MANAGE_USERS,
android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true)
public @UserSwitchabilityResult int getUserSwitchability(UserHandle userHandle) {
final TelephonyManager tm =
(TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
int flags = SWITCHABILITY_STATUS_OK;
if (tm.getCallState() != TelephonyManager.CALL_STATE_IDLE) {
if (inCall()) {
flags |= SWITCHABILITY_STATUS_USER_IN_CALL;
}
if (hasUserRestrictionForUser(DISALLOW_USER_SWITCH, userHandle)) {
@@ -5622,6 +5614,11 @@ public class UserManager {
}
}
private boolean inCall() {
final TelecomManager telecomManager = mContext.getSystemService(TelecomManager.class);
return telecomManager != null && telecomManager.isInCall();
}
/* Cache key for anything that assumes that userIds cannot be re-used without rebooting. */
private static final String CACHE_KEY_STATIC_USER_PROPERTIES = "cache_key.static_user_props";