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

Commit 881a4e39 authored by Jack Yu's avatar Jack Yu Committed by Android (Google) Code Review
Browse files

Merge "More CDMA cleanup" into main

parents ddced4be ee223e33
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import android.util.LocalLog;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.hidden_from_bootclasspath.com.android.internal.telephony.flags.Flags;
import com.android.internal.telephony.CarrierServiceBindHelper;
import com.android.internal.telephony.CommandException;
import com.android.internal.telephony.CommandsInterface;
@@ -1661,6 +1662,7 @@ public class UiccController extends Handler {
     * @return true if CDMA is supported by the device
     */
    public static boolean isCdmaSupported(Context context) {
        if (Flags.phoneTypeCleanup()) return false;
        PackageManager packageManager = context.getPackageManager();
        boolean isCdmaSupported =
                packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CDMA);
+0 −13
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
@@ -308,9 +307,6 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        int dds = SubscriptionManager.getDefaultDataSubscriptionId();
        doReturn(dds).when(mPhone).getSubId();

        doReturn(true).when(mPackageManager)
                .hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CDMA);

        // Set cellular radio on after boot by default
        mContextFixture.putBooleanResource(
                R.bool.config_enable_cellular_on_boot_default, true);
@@ -2942,15 +2938,6 @@ public class ServiceStateTrackerTest extends TelephonyTest {
                sSnetworkRegistrationInfo.getDataSpecificInfo().getVopsSupportInfo());
    }


    @Test
    @SmallTest
    public void testEriLoading() {
        sst.obtainMessage(GsmCdmaPhone.EVENT_CARRIER_CONFIG_CHANGED, null).sendToTarget();
        waitForLastHandlerAction(mSSTTestHandler.getThreadHandler());
        verify(mEriManager, times(1)).loadEriFile();
    }

    @Test
    public void testLastKnownCellIdentity() throws Exception {
        CellIdentityLte cellIdentity =
+0 −272
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony.cdma;

import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.AsyncResult;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Telephony;
import android.test.mock.MockContentResolver;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;

import androidx.test.filters.FlakyTest;
import androidx.test.filters.MediumTest;

import com.android.internal.telephony.FakeSmsContentProvider;
import com.android.internal.telephony.InboundSmsHandler;
import com.android.internal.telephony.InboundSmsTracker;
import com.android.internal.telephony.SmsStorageMonitor;
import com.android.internal.telephony.TelephonyTest;
import com.android.internal.telephony.cdma.sms.SmsEnvelope;
import com.android.internal.util.IState;
import com.android.internal.util.StateMachine;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
public class CdmaInboundSmsHandlerTest extends TelephonyTest {
    // Mocked classes
    private SmsStorageMonitor mSmsStorageMonitor;
    private android.telephony.SmsMessage mSmsMessage;
    private SmsMessage mCdmaSmsMessage;

    private CdmaInboundSmsHandler mCdmaInboundSmsHandler;
    private SmsEnvelope mSmsEnvelope = new SmsEnvelope();
    private FakeSmsContentProvider mContentProvider;
    private InboundSmsTracker mInboundSmsTracker;
    private final byte[] mSmsPdu = new byte[]{(byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
    private final int mSubId0 = 0;
    private static final UserHandle MOCKED_MAIN_USER = UserHandle.of(10);

    private IState getCurrentState() {
        try {
            Method method = StateMachine.class.getDeclaredMethod("getCurrentState");
            method.setAccessible(true);
            return (IState) method.invoke(mCdmaInboundSmsHandler);
        } catch (Exception e) {
            fail(e.toString());
            return null;
        }
    }

    @Before
    public void setUp() throws Exception {
        super.setUp(getClass().getSimpleName());
        mSmsStorageMonitor = mock(SmsStorageMonitor.class);
        mSmsMessage = mock(android.telephony.SmsMessage.class);
        mCdmaSmsMessage = mock(SmsMessage.class);

        Field field = SmsMessage.class.getDeclaredField("mEnvelope");
        field.setAccessible(true);
        field.set(mCdmaSmsMessage, mSmsEnvelope);

        UserManager userManager = (UserManager) mContextFixture.getTestDouble().
                getSystemService(Context.USER_SERVICE);
        doReturn(MOCKED_MAIN_USER).when(userManager).getMainUser();
        doReturn(true).when(userManager).isUserUnlocked();
        doReturn(true).when(mFeatureFlags).smsMmsDeliverBroadcastsRedirectToMainUser();

        try {
            doReturn(new int[]{0, MOCKED_MAIN_USER.getIdentifier()})
                .when(mIActivityManager).getRunningUserIds();
        } catch (RemoteException re) {
            StringWriter reString = new StringWriter();
            re.printStackTrace(new PrintWriter(reString));
            fail("Unexpected RemoteException: " + reString);
        }

        mSmsMessage.mWrappedSmsMessage = mCdmaSmsMessage;
        doReturn(mSmsPdu).when(mCdmaSmsMessage).getPdu();

        doReturn(true).when(mTelephonyManager).getSmsReceiveCapableForPhone(anyInt(), anyBoolean());
        doReturn(true).when(mSmsStorageMonitor).isStorageAvailable();

        mInboundSmsTracker = new InboundSmsTracker(
                mContext,
                mSmsPdu, /* pdu */
                System.currentTimeMillis(), /* timestamp */
                -1, /* destPort */
                true, /* is3gpp2 */
                false, /* is3gpp2WapPdu */
                "1234567890", /* address */
                "1234567890", /* displayAddress */
                "This is the message body of a single-part message" /* messageBody */,
                false, /* isClass0 */
                mSubId0,
                InboundSmsHandler.SOURCE_NOT_INJECTED);

        doReturn(mInboundSmsTracker).when(mTelephonyComponentFactory)
                .makeInboundSmsTracker(any(Context.class), nullable(byte[].class), anyLong(),
                anyInt(), anyBoolean(),
                anyBoolean(), nullable(String.class), nullable(String.class),
                nullable(String.class), anyBoolean(), anyInt(), anyInt());
        doReturn(mInboundSmsTracker).when(mTelephonyComponentFactory)
                .makeInboundSmsTracker(any(Context.class), nullable(byte[].class), anyLong(),
                anyInt(), anyBoolean(),
                nullable(String.class), nullable(String.class), anyInt(), anyInt(),
                anyInt(), anyBoolean(), nullable(String.class), anyBoolean(), anyInt(),
                anyInt());
        doReturn(mInboundSmsTracker).when(mTelephonyComponentFactory)
                .makeInboundSmsTracker(any(Context.class), nullable(Cursor.class), anyBoolean());

        mContentProvider = new FakeSmsContentProvider();
        ((MockContentResolver)mContext.getContentResolver()).addProvider(
                Telephony.Sms.CONTENT_URI.getAuthority(), mContentProvider);

        mCdmaInboundSmsHandler = CdmaInboundSmsHandler.makeInboundSmsHandler(mContext,
            mSmsStorageMonitor, mPhone, null, mTestableLooper.getLooper(),
                mFeatureFlags);
        monitorTestableLooper(new TestableLooper(mCdmaInboundSmsHandler.getHandler().getLooper()));
        processAllMessages();
    }

    @After
    public void tearDown() throws Exception {
        // wait for wakelock to be released; timeout at 10s
        int i = 0;
        while (mCdmaInboundSmsHandler.getWakeLock().isHeld() && i < 100) {
            processAllMessages();
            waitForMs(100);
            i++;
        }
        assertFalse(mCdmaInboundSmsHandler.getWakeLock().isHeld());
        mCdmaInboundSmsHandler.quit();
        mCdmaInboundSmsHandler = null;
        mContentProvider.shutdown();
        mContentProvider = null;
        mSmsEnvelope = null;
        mInboundSmsTracker = null;
        super.tearDown();
    }

    private void transitionFromStartupToIdle() {
        // verify initially in StartupState
        assertEquals("StartupState", getCurrentState().getName());

        // trigger transition to IdleState
        mCdmaInboundSmsHandler.sendMessage(InboundSmsHandler.EVENT_START_ACCEPTING_SMS);
        processAllMessages();

        assertEquals("IdleState", getCurrentState().getName());
    }

    @FlakyTest
    @Test
    @MediumTest
    @Ignore
    public void testNewSms() {
        transitionFromStartupToIdle();

        // send new SMS to state machine and verify that triggers SMS_DELIVER_ACTION
        doReturn(SmsEnvelope.TELESERVICE_WMT).when(mCdmaSmsMessage).getTeleService();
        mCdmaInboundSmsHandler.sendMessage(InboundSmsHandler.EVENT_NEW_SMS,
                new AsyncResult(null, mSmsMessage, null));
        processAllMessages();

        ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(mContext).sendBroadcast(intentArgumentCaptor.capture());
        assertEquals(Telephony.Sms.Intents.SMS_DELIVER_ACTION,
                intentArgumentCaptor.getValue().getAction());

        // verify a message id was created on receive.
        assertNotEquals(0L,
                intentArgumentCaptor.getValue().getLongExtra("messageId", 0L));
        assertEquals("WaitingState", getCurrentState().getName());

        mContextFixture.sendBroadcastToOrderedBroadcastReceivers();

        intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(mContext, times(2)).sendBroadcast(intentArgumentCaptor.capture());
        assertEquals(Telephony.Sms.Intents.SMS_RECEIVED_ACTION,
                intentArgumentCaptor.getAllValues().get(1).getAction());
        assertEquals("WaitingState", getCurrentState().getName());

        mContextFixture.sendBroadcastToOrderedBroadcastReceivers();
        processAllMessages();

        assertEquals("IdleState", getCurrentState().getName());
    }

    @FlakyTest /* flakes 0.43% of the time */
    @Test
    @MediumTest
    public void testNewSmsFromBlockedNumber_noBroadcastsSent() {
        String blockedNumber = "123456789";
        mInboundSmsTracker = new InboundSmsTracker(
                mContext,
                mSmsPdu, /* pdu */
                System.currentTimeMillis(), /* timestamp */
                -1, /* destPort */
                true, /* is3gpp2 */
                false, /* is3gpp2WapPdu */
                "1234567890", /* address */
                blockedNumber, /* displayAddress */
                "This is the message body of a single-part message" /* messageBody */,
                false, /* isClass0 */
                mSubId0,
                InboundSmsHandler.SOURCE_NOT_INJECTED);
        doReturn(mInboundSmsTracker).when(mTelephonyComponentFactory)
                .makeInboundSmsTracker(any(Context.class), nullable(byte[].class), anyLong(),
                anyInt(), anyBoolean(),
                anyBoolean(), nullable(String.class), nullable(String.class),
                nullable(String.class), anyBoolean(), anyInt(), anyInt());
        mFakeBlockedNumberContentProvider.mBlockedNumbers.add(blockedNumber);

        transitionFromStartupToIdle();

        doReturn(SmsEnvelope.TELESERVICE_WMT).when(mCdmaSmsMessage).getTeleService();
        mCdmaInboundSmsHandler.sendMessage(InboundSmsHandler.EVENT_NEW_SMS,
                new AsyncResult(null, mSmsMessage, null));
        processAllMessages();

        verify(mContext, never()).sendBroadcast(any(Intent.class));
        assertEquals("IdleState", getCurrentState().getName());
    }
}
+0 −766

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −101
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony.cdma;

import static org.mockito.Mockito.*;

import android.os.Binder;
import android.os.HandlerThread;
import android.os.Message;

import androidx.test.filters.SmallTest;

import com.android.internal.telephony.SMSDispatcher;
import com.android.internal.telephony.SmsDispatchersController;
import com.android.internal.telephony.TelephonyTest;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class CdmaSmsDispatcherTest extends TelephonyTest {
    // Mocked classes
    private SmsDispatchersController mSmsDispatchersController;
    private SMSDispatcher.SmsTracker mSmsTracker;

    private CdmaSMSDispatcher mCdmaSmsDispatcher;
    private CdmaSmsDispatcherTestHandler mCdmaSmsDispatcherTestHandler;
    private int mCallingUserId;

    private class CdmaSmsDispatcherTestHandler extends HandlerThread {

        private CdmaSmsDispatcherTestHandler(String name) {
            super(name);
        }

        @Override
        public void onLooperPrepared() {
            mCdmaSmsDispatcher = new CdmaSMSDispatcher(mPhone, mSmsDispatchersController);
            setReady(true);
        }
    }

    @Before
    public void setUp() throws Exception {
        super.setUp(getClass().getSimpleName());
        mSmsDispatchersController = mock(SmsDispatchersController.class);
        mSmsTracker = mock(SMSDispatcher.SmsTracker.class);

        setupMockPackagePermissionChecks();
        doReturn(mSmsUsageMonitor).when(mSmsDispatchersController).getUsageMonitor();
        mCdmaSmsDispatcherTestHandler = new CdmaSmsDispatcherTestHandler(TAG);
        mCdmaSmsDispatcherTestHandler.start();
        waitUntilReady();
        mCallingUserId = Binder.getCallingUserHandle().getIdentifier();
    }

    @After
    public void tearDown() throws Exception {
        mCdmaSmsDispatcherTestHandler.quit();
        mCdmaSmsDispatcherTestHandler.join();
        mCdmaSmsDispatcherTestHandler = null;
        mCdmaSmsDispatcher = null;
        super.tearDown();
    }

    @Test @SmallTest
    public void testSendSms() {
        doReturn(mServiceState).when(mPhone).getServiceState();
        mCdmaSmsDispatcher.sendSms(mSmsTracker);
        verify(mSimulatedCommandsVerifier).sendCdmaSms(nullable(byte[].class), any(Message.class));
    }

    @Test @SmallTest
    public void testSendText() {
        mCdmaSmsDispatcher.sendText("111"/* desAddr*/, "222" /*scAddr*/, TAG,
                null, null, null, null, mCallingUserId, false, -1, false, -1, false, 0L);
        verify(mSimulatedCommandsVerifier).sendCdmaSms(any(byte[].class), any(Message.class));
    }

    @Test @SmallTest
    public void testSendTextWithOutDesAddr() {
        mCdmaSmsDispatcher.sendText(null, "222" /*scAddr*/, TAG,
                null, null, null, null, mCallingUserId, false, -1, false, -1, false, 0L);
        verify(mSimulatedCommandsVerifier, times(0)).sendImsGsmSms(anyString(), anyString(),
                anyInt(), anyInt(), any(Message.class));
    }
}
Loading