Merge "Fixed UID mismatch in telephony registry"

This commit is contained in:
Hui Wang
2023-04-27 17:27:19 +00:00
committed by Gerrit Code Review

View File

@@ -1578,18 +1578,20 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
return; return;
} }
final long callingIdentity = Binder.clearCallingIdentity();
try {
synchronized (mRecords) { synchronized (mRecords) {
String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId=" + phoneId String str = "notifyServiceStateForSubscriber: subId=" + subId + " phoneId="
+ " state=" + state; + phoneId + " state=" + state;
if (VDBG) { if (VDBG) {
log(str); log(str);
} }
mLocalLog.log(str); mLocalLog.log(str);
// for service state updates, don't notify clients when subId is invalid. This prevents // for service state updates, don't notify clients when subId is invalid. This
// us from sending incorrect notifications like b/133140128 // prevents us from sending incorrect notifications like b/133140128
// In the future, we can remove this logic for every notification here and add a // In the future, we can remove this logic for every notification here and add a
// callback so listeners know when their PhoneStateListener's subId becomes invalid, but // callback so listeners know when their PhoneStateListener's subId becomes invalid,
// for now we use the simplest fix. // but for now we use the simplest fix.
if (validatePhoneId(phoneId) && SubscriptionManager.isValidSubscriptionId(subId)) { if (validatePhoneId(phoneId) && SubscriptionManager.isValidSubscriptionId(subId)) {
mServiceState[phoneId] = state; mServiceState[phoneId] = state;
@@ -1614,7 +1616,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
if (DBG) { if (DBG) {
log("notifyServiceStateForSubscriber: callback.onSSC r=" + r log("notifyServiceStateForSubscriber: callback.onSSC r=" + r
+ " subId=" + subId + " phoneId=" + phoneId + " subId=" + subId + " phoneId=" + phoneId
+ " state=" + state); + " state=" + stateToSend);
} }
r.callback.onServiceStateChanged(stateToSend); r.callback.onServiceStateChanged(stateToSend);
} catch (RemoteException ex) { } catch (RemoteException ex) {
@@ -1629,6 +1631,9 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
handleRemoveListLocked(); handleRemoveListLocked();
} }
broadcastServiceStateChanged(state, phoneId, subId); broadcastServiceStateChanged(state, phoneId, subId);
} finally {
Binder.restoreCallingIdentity(callingIdentity);
}
} }
public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId, public void notifySimActivationStateChangedForPhoneId(int phoneId, int subId,
@@ -3161,13 +3166,10 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
public static final String ACTION_SIGNAL_STRENGTH_CHANGED = "android.intent.action.SIG_STR"; public static final String ACTION_SIGNAL_STRENGTH_CHANGED = "android.intent.action.SIG_STR";
private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) { private void broadcastServiceStateChanged(ServiceState state, int phoneId, int subId) {
final long ident = Binder.clearCallingIdentity();
try { try {
mBatteryStats.notePhoneState(state.getState()); mBatteryStats.notePhoneState(state.getState());
} catch (RemoteException re) { } catch (RemoteException re) {
// Can't do much // Can't do much
} finally {
Binder.restoreCallingIdentity(ident);
} }
// Send the broadcast exactly once to all possible disjoint sets of apps. // Send the broadcast exactly once to all possible disjoint sets of apps.
@@ -3184,8 +3186,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
// - Sanitized ServiceState sent to all other apps with READ_PHONE_STATE // - Sanitized ServiceState sent to all other apps with READ_PHONE_STATE
// - Sanitized ServiceState sent to all other apps with READ_PRIVILEGED_PHONE_STATE but not // - Sanitized ServiceState sent to all other apps with READ_PRIVILEGED_PHONE_STATE but not
// READ_PHONE_STATE // READ_PHONE_STATE
if (Binder.withCleanCallingIdentity(() -> if (LocationAccessPolicy.isLocationModeEnabled(mContext, mContext.getUserId())) {
LocationAccessPolicy.isLocationModeEnabled(mContext, mContext.getUserId()))) {
Intent fullIntent = createServiceStateIntent(state, subId, phoneId, false); Intent fullIntent = createServiceStateIntent(state, subId, phoneId, false);
mContext.createContextAsUser(UserHandle.ALL, 0).sendBroadcastMultiplePermissions( mContext.createContextAsUser(UserHandle.ALL, 0).sendBroadcastMultiplePermissions(
fullIntent, fullIntent,