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

Commit 5c90e11a authored by Y's avatar Y
Browse files

add upper bound on nitz year

-framework will ignore NITZ time after Jan 1, 2038 to avoid malicious
basestation hack phone time and cause phone crashes
-unit test

Bug: 29083635
Change-Id: I4f60610ed13f5d6e7b0cf18f43708be2e528368c
parent 5dc5ace2
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -349,6 +349,8 @@ public class ServiceStateTracker extends Handler {
    public CellLocation mCellLoc;
    private CellLocation mNewCellLoc;
    public static final int MS_PER_HOUR = 60 * 60 * 1000;
    /* Time stamp after 19 January 2038 is not supported under 32 bit */
    private static final int MAX_NITZ_YEAR = 2037;
    /**
     * Sometimes we get the NITZ time before we know what country we
     * are in. Keep the time zone information from the NITZ string so
@@ -3686,6 +3688,10 @@ public class ServiceStateTracker extends Handler {
            String[] nitzSubs = nitz.split("[/:,+-]");

            int year = 2000 + Integer.parseInt(nitzSubs[0]);
            if (year > MAX_NITZ_YEAR) {
                if (DBG) loge("NITZ year: " + year + " exceeds limit, skip NITZ time update");
                return;
            }
            c.set(Calendar.YEAR, year);

            // month is 0 based!
+9 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.os.Looper;
import android.os.Message;
import android.os.Parcel;
import android.os.Registrant;
import android.os.SystemClock;
import android.service.carrier.CarrierIdentifier;
import android.telephony.CellInfo;
import android.telephony.CellInfoGsm;
import android.telephony.Rlog;
@@ -1075,6 +1077,13 @@ public class SimulatedCommands extends BaseCommands
        mDcSuccess = success;
    }

    public void triggerNITZupdate(String NITZStr) {
        if (NITZStr != null) {
            mNITZTimeRegistrant.notifyRegistrant(new AsyncResult (null, new Object[]{NITZStr,
                    SystemClock.elapsedRealtime()}, null));
        }
    }

    @Override
    public void setupDataCall(int radioTechnology, int profile,
            String apn, String user, String password, int authType,
+37 −14
Original line number Diff line number Diff line
@@ -16,14 +16,17 @@

package com.android.internal.telephony;

import android.app.IAlarmManager;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncResult;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Message;
import android.os.Parcel;
import android.os.RegistrantList;
import android.os.SystemClock;
import android.os.UserHandle;
import android.telephony.CellInfo;
import android.telephony.CellInfoGsm;
@@ -40,29 +43,28 @@ import com.android.internal.telephony.dataconnection.DcTracker;
import com.android.internal.telephony.test.SimulatedCommands;
import com.android.internal.telephony.uicc.IccCardApplicationStatus;

import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;

import java.util.ArrayList;

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.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;

import java.util.ArrayList;

public class ServiceStateTrackerTest extends TelephonyTest {

    @Mock
@@ -71,6 +73,8 @@ public class ServiceStateTrackerTest extends TelephonyTest {
    private ProxyController mProxyController;
    @Mock
    private Handler mTestHandler;
    @Mock
    protected IAlarmManager mAlarmManager;

    private ServiceStateTracker sst;
    private ServiceStateTrackerTestHandler mSSTTestHandler;
@@ -817,4 +821,23 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        sst.requestShutdown();
        assertEquals(true, sst.isDeviceShuttingDown());
    }

    @Test
    @SmallTest
    public void testSetTimeFromNITZStr() throws Exception {
        doReturn(mAlarmManager).when(mIBinder).queryLocalInterface(anyString());
        mServiceManagerMockedServices.put(Context.ALARM_SERVICE, mIBinder);

        // Mock sending incorrect nitz str from RIL
        mSimulatedCommands.triggerNITZupdate("38/06/20,00:00:00+0");
        waitForMs(100);
        // AlarmManger.setTime is triggered by SystemClock.setCurrentTimeMillis().
        // Verify system time is not set to incorrect NITZ time
        verify(mAlarmManager, times(0)).setTime(anyLong());

        // Mock sending correct nitz str from RIL
        mSimulatedCommands.triggerNITZupdate("15/06/20,00:00:00+0");
        waitForMs(100);
        verify(mAlarmManager, times(1)).setTime(anyLong());
    }
}
 No newline at end of file