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

Commit e6eeeeeb authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk
Browse files

Telephony: use FEATURE_TELEPHONY_* instead of config_*_capable

Also, clean up annotations around is(Device)*Capable.

Bug: 353979854
Test: atest CtsTelephonyTestCases:android.telephony.cts.TelephonyManagerTest
Flag: EXEMPT no behavior change as long as device pass CTS
Change-Id: Ibcf8bd206e0e33b3daeca2e5fb18d69ed338149c
parent 1acd29dc
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -2173,8 +2173,7 @@ class DatabaseHelper extends SQLiteOpenHelper {
                                            (1 << AudioManager.STREAM_NOTIFICATION) |
                                            (1 << AudioManager.STREAM_SYSTEM) |
                                            (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
            if (!mContext.getResources().getBoolean(
                    com.android.internal.R.bool.config_voice_capable)) {
            if (!getTelephonyManager().isVoiceCapable()) {
                ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
            }
            loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
+25 −11
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static android.provider.Telephony.Carriers.INVALID_APN_ID;
import static com.android.internal.util.Preconditions.checkNotNull;
import android.Manifest;
import android.annotation.BoolRes;
import android.annotation.BytesLong;
import android.annotation.CallbackExecutor;
import android.annotation.CurrentTimeMillisLong;
@@ -6886,6 +6887,26 @@ public class TelephonyManager {
        }
    }
    // Suppressing AndroidFrameworkCompatChange because we're querying vendor
    // partition SDK level, not application's target SDK version.
    @SuppressWarnings("AndroidFrameworkCompatChange")
    private boolean hasCapability(@NonNull String feature, @BoolRes int legacySetting) {
        if (mContext == null) return true;
        if (mContext.getPackageManager().hasSystemFeature(feature)) return true;
        // Check SDK version of the vendor partition.
        final int vendorApiLevel = SystemProperties.getInt(
                "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
        // Devices shipped with 2024Q2 or later are required to declare FEATURE_TELEPHONY_*
        // for individual sub-features (calling, messaging, data), so there's no need to check
        // the legacy setting.
        if (vendorApiLevel < Build.VENDOR_API_2024_Q2) {
            return mContext.getResources().getBoolean(legacySetting);
        }
        return false;
    }
    // TODO(b/316183370): replace all @code with @link in javadoc after feature is released
    /**
     * @return true if the current device is "voice capable".
@@ -6905,11 +6926,9 @@ public class TelephonyManager {
     * device (when {@code #isDeviceVoiceCapable} return {@code true}), caller should check for
     * subscription-level voice capability as well. See {@code #isDeviceVoiceCapable} for details.
     */
    @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING)
    @Deprecated
    public boolean isVoiceCapable() {
        if (mContext == null) return true;
        return mContext.getResources().getBoolean(
        return hasCapability(PackageManager.FEATURE_TELEPHONY_CALLING,
                com.android.internal.R.bool.config_voice_capable);
    }
@@ -6932,7 +6951,6 @@ public class TelephonyManager {
     *
     * @see SubscriptionInfo#getServiceCapabilities()
     */
    @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING)
    @FlaggedApi(Flags.FLAG_DATA_ONLY_CELLULAR_SERVICE)
    public boolean isDeviceVoiceCapable() {
        return isVoiceCapable();
@@ -6951,10 +6969,9 @@ public class TelephonyManager {
     * device (when {@code #isDeviceSmsCapable} return {@code true}), caller should check for
     * subscription-level SMS capability as well. See {@code #isDeviceSmsCapable} for details.
     */
    @RequiresFeature(PackageManager.FEATURE_TELEPHONY_MESSAGING)
    @Deprecated
    public boolean isSmsCapable() {
        if (mContext == null) return true;
        return mContext.getResources().getBoolean(
        return hasCapability(PackageManager.FEATURE_TELEPHONY_MESSAGING,
                com.android.internal.R.bool.config_sms_capable);
    }
@@ -6974,7 +6991,6 @@ public class TelephonyManager {
     *
     * @see SubscriptionInfo#getServiceCapabilities()
     */
    @RequiresFeature(PackageManager.FEATURE_TELEPHONY_MESSAGING)
    @FlaggedApi(Flags.FLAG_DATA_ONLY_CELLULAR_SERVICE)
    public boolean isDeviceSmsCapable() {
        return isSmsCapable();
@@ -14542,10 +14558,8 @@ public class TelephonyManager {
     * data connections over the telephony network.
     * <p>
     */
    @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA)
    public boolean isDataCapable() {
        if (mContext == null) return true;
        return mContext.getResources().getBoolean(
        return hasCapability(PackageManager.FEATURE_TELEPHONY_DATA,
                com.android.internal.R.bool.config_mobile_data_capable);
    }
+2 −2
Original line number Diff line number Diff line
@@ -169,13 +169,13 @@ public interface TelephonyProperties

    /**
     * Set to false to disable SMS receiving, default is
     * the value of config_sms_capable
     * the value of TelephonyManager.isDeviceSmsCapable
     */
    static final String PROPERTY_SMS_RECEIVE = "telephony.sms.receive";

    /**
     * Set to false to disable SMS sending, default is
     * the value of config_sms_capable
     * the value of TelephonyManager.isDeviceSmsCapable
     */
    static final String PROPERTY_SMS_SEND = "telephony.sms.send";