Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 220bc70f authored by Brad Ebinger's avatar Brad Ebinger Committed by Automerger Merge Worker
Browse files

Merge "Enforce READ_PHONE_STATE for APIs involving call state" into sc-dev am: 3bf5cbb8

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13986047

Change-Id: I185ceb19fc96b1c38731d68757668cd54cdff412
parents 75f9be30 3bf5cbb8
Loading
Loading
Loading
Loading
+5 −3
Original line number Original line Diff line number Diff line
@@ -40283,6 +40283,7 @@ package android.telecom {
    field public static final int DURATION_MEDIUM = 2; // 0x2
    field public static final int DURATION_MEDIUM = 2; // 0x2
    field public static final int DURATION_SHORT = 1; // 0x1
    field public static final int DURATION_SHORT = 1; // 0x1
    field public static final int DURATION_VERY_SHORT = 0; // 0x0
    field public static final int DURATION_VERY_SHORT = 0; // 0x0
    field public static final long ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION = 157233955L; // 0x95f3323L
    field public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
    field public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
    field public static final String EXTRA_CALL_DISCONNECT_CAUSE = "android.telecom.extra.CALL_DISCONNECT_CAUSE";
    field public static final String EXTRA_CALL_DISCONNECT_CAUSE = "android.telecom.extra.CALL_DISCONNECT_CAUSE";
    field public static final String EXTRA_CALL_DISCONNECT_MESSAGE = "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
    field public static final String EXTRA_CALL_DISCONNECT_MESSAGE = "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
@@ -41889,7 +41890,7 @@ package android.telephony {
    method @Deprecated public void onBarringInfoChanged(@NonNull android.telephony.BarringInfo);
    method @Deprecated public void onBarringInfoChanged(@NonNull android.telephony.BarringInfo);
    method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public void onCallDisconnectCauseChanged(int, int);
    method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public void onCallDisconnectCauseChanged(int, int);
    method @Deprecated public void onCallForwardingIndicatorChanged(boolean);
    method @Deprecated public void onCallForwardingIndicatorChanged(boolean);
    method @Deprecated public void onCallStateChanged(int, String);
    method @Deprecated @RequiresPermission(value=android.Manifest.permission.READ_PHONE_STATE, conditional=true) public void onCallStateChanged(int, String);
    method @Deprecated public void onCellInfoChanged(java.util.List<android.telephony.CellInfo>);
    method @Deprecated public void onCellInfoChanged(java.util.List<android.telephony.CellInfo>);
    method @Deprecated public void onCellLocationChanged(android.telephony.CellLocation);
    method @Deprecated public void onCellLocationChanged(android.telephony.CellLocation);
    method @Deprecated public void onDataActivity(int);
    method @Deprecated public void onDataActivity(int);
@@ -42435,7 +42436,7 @@ package android.telephony {
  }
  }
  public static interface TelephonyCallback.CallStateListener {
  public static interface TelephonyCallback.CallStateListener {
    method public void onCallStateChanged(int);
    method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public void onCallStateChanged(int);
  }
  }
  public static interface TelephonyCallback.CarrierNetworkListener {
  public static interface TelephonyCallback.CarrierNetworkListener {
@@ -42525,7 +42526,8 @@ package android.telephony {
    method public int getActiveModemCount();
    method public int getActiveModemCount();
    method @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public java.util.List<android.telephony.CellInfo> getAllCellInfo();
    method @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public java.util.List<android.telephony.CellInfo> getAllCellInfo();
    method @RequiresPermission("android.permission.READ_PRIVILEGED_PHONE_STATE") public int getCallComposerStatus();
    method @RequiresPermission("android.permission.READ_PRIVILEGED_PHONE_STATE") public int getCallComposerStatus();
    method public int getCallState();
    method @Deprecated @RequiresPermission(value=android.Manifest.permission.READ_PHONE_STATE, conditional=true) public int getCallState();
    method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public int getCallStateForSubscription();
    method public int getCardIdForDefaultEuicc();
    method public int getCardIdForDefaultEuicc();
    method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) @WorkerThread public android.os.PersistableBundle getCarrierConfig();
    method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) @WorkerThread public android.os.PersistableBundle getCarrierConfig();
    method public int getCarrierIdFromSimMccMnc();
    method public int getCarrierIdFromSimMccMnc();
+1 −1
Original line number Original line Diff line number Diff line
@@ -10878,7 +10878,7 @@ package android.telecom {
    method public java.util.List<android.telecom.PhoneAccount> getAllPhoneAccounts();
    method public java.util.List<android.telecom.PhoneAccount> getAllPhoneAccounts();
    method public int getAllPhoneAccountsCount();
    method public int getAllPhoneAccountsCount();
    method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public java.util.List<android.telecom.PhoneAccountHandle> getCallCapablePhoneAccounts(boolean);
    method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public java.util.List<android.telecom.PhoneAccountHandle> getCallCapablePhoneAccounts(boolean);
    method public int getCallState();
    method @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}, conditional=true) public int getCallState();
    method public android.telecom.PhoneAccountHandle getConnectionManager();
    method public android.telecom.PhoneAccountHandle getConnectionManager();
    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getCurrentTtyMode();
    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getCurrentTtyMode();
    method @Nullable @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String getDefaultDialerPackage(@NonNull android.os.UserHandle);
    method @Nullable @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String getDefaultDialerPackage(@NonNull android.os.UserHandle);
+5 −0
Original line number Original line Diff line number Diff line
@@ -703,6 +703,10 @@ public class PhoneStateListener {
     * calling {@link TelephonyManager#getCallState()} from within this callback may return a
     * calling {@link TelephonyManager#getCallState()} from within this callback may return a
     * different state than the callback reports.
     * different state than the callback reports.
     *
     *
     * Requires Permission:
     * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} for applications
     * targeting API level 31+.
     *
     * @param state call state
     * @param state call state
     * @param phoneNumber call phone number. If application does not have
     * @param phoneNumber call phone number. If application does not have
     * {@link android.Manifest.permission#READ_CALL_LOG READ_CALL_LOG} permission or carrier
     * {@link android.Manifest.permission#READ_CALL_LOG READ_CALL_LOG} permission or carrier
@@ -712,6 +716,7 @@ public class PhoneStateListener {
     * @deprecated Use {@link TelephonyCallback.CallStateListener} instead.
     * @deprecated Use {@link TelephonyCallback.CallStateListener} instead.
     */
     */
    @Deprecated
    @Deprecated
    @RequiresPermission(value = android.Manifest.permission.READ_PHONE_STATE, conditional = true)
    public void onCallStateChanged(@CallState int state, String phoneNumber) {
    public void onCallStateChanged(@CallState int state, String phoneNumber) {
        // default implementation empty
        // default implementation empty
    }
    }
+1 −0
Original line number Original line Diff line number Diff line
@@ -752,6 +752,7 @@ public class TelephonyCallback {
         *
         *
         * @param state the current call state
         * @param state the current call state
         */
         */
        @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
        public void onCallStateChanged(@Annotation.CallState int state);
        public void onCallStateChanged(@Annotation.CallState int state);
    }
    }


+26 −0
Original line number Original line Diff line number Diff line
@@ -44,6 +44,7 @@ import android.os.Process;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserHandle;
import android.provider.DeviceConfig;
import android.provider.DeviceConfig;
import android.telecom.TelecomManager;
import android.telephony.Annotation;
import android.telephony.Annotation;
import android.telephony.Annotation.RadioPowerState;
import android.telephony.Annotation.RadioPowerState;
import android.telephony.Annotation.SrvccState;
import android.telephony.Annotation.SrvccState;
@@ -215,6 +216,18 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
            return Binder.withCleanCallingIdentity(() -> CompatChanges.isChangeEnabled(
            return Binder.withCleanCallingIdentity(() -> CompatChanges.isChangeEnabled(
                    TelephonyCallback.PHONE_STATE_LISTENER_LIMIT_CHANGE_ID, uid));
                    TelephonyCallback.PHONE_STATE_LISTENER_LIMIT_CHANGE_ID, uid));
        }
        }

        /**
         * See {@link TelecomManager#ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION} for more
         * information.
         * @noinspection ConstantConditions
         */
        public boolean isCallStateReadPhoneStateEnforcedInPlatformCompat(String packageName,
                UserHandle userHandle) {
            return Binder.withCleanCallingIdentity(() -> CompatChanges.isChangeEnabled(
                    TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, packageName,
                    userHandle));
        }
    }
    }


    private final Context mContext;
    private final Context mContext;
@@ -2947,6 +2960,19 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
            }
            }
        }
        }


        // Only check READ_PHONE_STATE for CALL_STATE_CHANGED for API 31+.
        if (mConfigurationProvider.isCallStateReadPhoneStateEnforcedInPlatformCompat(callingPackage,
                Binder.getCallingUserHandle())) {
            if (events.contains(TelephonyCallback.EVENT_LEGACY_CALL_STATE_CHANGED)
                    || events.contains(TelephonyCallback.EVENT_CALL_STATE_CHANGED)) {
                if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
                        mContext, subId, callingPackage, callingFeatureId, message)) {
                    throw new SecurityException("CALL_STATE_CHANGED event requires "
                            + "READ_PHONE_STATE");
                }
            }
        }

        if (isPrecisePhoneStatePermissionRequired(events)) {
        if (isPrecisePhoneStatePermissionRequired(events)) {
            // check if calling app has either permission READ_PRECISE_PHONE_STATE
            // check if calling app has either permission READ_PRECISE_PHONE_STATE
            // or with carrier privileges
            // or with carrier privileges
Loading