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

Commit 17326f0b authored by joonhunshin's avatar joonhunshin Committed by Joonhun Shin
Browse files

Data only device(without FEATURE_TELEPHON_CALLING) : Add to check required...

Data only device(without FEATURE_TELEPHON_CALLING) : Add to check required telephony feature before calling the TelephonyManager interface.

If the device does not have Telephony feature calling, the some of interfaces in TelephonyManager throw UnsupportedOperationException.

Bug: 297989574
Test: oriole with ATT SIM, boot completed
      APM/data/wifi on/off
Change-Id: Ia0e21b98e236e5df09d8f883ce095cdd811135fb
parent a5281200
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.hardware.radio.modem.ImeiInfo;
import android.net.Uri;
@@ -1078,10 +1079,21 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    public void notifySmsSent(String destinationAddress) {
        TelephonyManager m = (TelephonyManager) getContext().getSystemService(
                Context.TELEPHONY_SERVICE);
        if (!mFeatureFlags.enforceTelephonyFeatureMappingForPublicApis()) {
            if (m != null && m.isEmergencyNumber(destinationAddress)) {
                mLocalLog.log("Emergency SMS detected, recording time.");
                mTimeLastEmergencySmsSentMs = SystemClock.elapsedRealtime();
            }
        } else {
            if (mContext.getPackageManager() != null
                    && mContext.getPackageManager().hasSystemFeature(
                            PackageManager.FEATURE_TELEPHONY_CALLING)) {
                if (m != null && m.isEmergencyNumber(destinationAddress)) {
                    mLocalLog.log("Emergency SMS detected, recording time.");
                    mTimeLastEmergencySmsSentMs = SystemClock.elapsedRealtime();
                }
            }
        }
    }

    /**
+27 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import static org.mockito.Mockito.when;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.hardware.radio.modem.ImeiInfo;
import android.os.AsyncResult;
import android.os.Bundle;
@@ -690,6 +691,32 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        assertFalse(mPhoneUT.isInEmergencySmsMode());
    }

    @Test
    @SmallTest
    public void testEmergencySmsModeWithTelephonyFeatureMapping() {
        String emergencyNumber = "111";
        int timeout = 200;
        mContextFixture.getCarrierConfigBundle().putInt(
                CarrierConfigManager.KEY_EMERGENCY_SMS_MODE_TIMER_MS_INT, timeout);
        doReturn(true).when(mTelephonyManager).isEmergencyNumber(emergencyNumber);

        // Feature flag enabled
        // Device does not have FEATURE_TELEPHONY_CALLING
        doReturn(true).when(mFeatureFlags).enforceTelephonyFeatureMappingForPublicApis();
        doReturn(false).when(mPackageManager).hasSystemFeature(
                eq(PackageManager.FEATURE_TELEPHONY_CALLING));
        mPhoneUT.notifySmsSent(emergencyNumber);
        processAllMessages();
        assertFalse(mPhoneUT.isInEmergencySmsMode());

        // Device has FEATURE_TELEPHONY_CALLING
        doReturn(true).when(mPackageManager).hasSystemFeature(
                eq(PackageManager.FEATURE_TELEPHONY_CALLING));
        mPhoneUT.notifySmsSent(emergencyNumber);
        processAllMessages();
        assertTrue(mPhoneUT.isInEmergencySmsMode());
    }

    @Test
    @SmallTest
    public void testSendBurstDtmf() {