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

Commit 4317d8a7 authored by Rambo Wang's avatar Rambo Wang
Browse files

Add UT cases to disallow null thresholds even for privileged apps

Add UT cases to cover the system privileged app with permission
which is allowed to set SystemThresholdReportingRequestedWhileIdle
to true with empty signal strength thresholds but not with null.

Bug: 205585585
Test: atest SignalStrengthUpdateRequestTest
Change-Id: I21631539ea5a068566e143c9418648e04d5a18b9
parent 35aec1e7
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.internal.telephony;

import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertThrows;

import android.os.Parcel;
import android.telephony.AccessNetworkConstants;
import android.telephony.SignalStrengthUpdateRequest;
@@ -30,6 +32,7 @@ import junit.framework.TestCase;
import org.junit.Test;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class SignalStrengthUpdateRequestTest extends TestCase {
@@ -162,6 +165,27 @@ public class SignalStrengthUpdateRequestTest extends TestCase {
        assertEquals(infos, request.getSignalThresholdInfos());
    }

    @Test
    @SmallTest
    public void testSetSystemThresholdReportingRequestedWhileIdleToTrue_withNullThresholds() {
        assertThrows(IllegalArgumentException.class,
                () -> new SignalStrengthUpdateRequest.Builder()
                        .setSystemThresholdReportingRequestedWhileIdle(true).build());
    }

    @Test
    @SmallTest
    public void testSetSystemThresholdReportingRequestedWhileIdleToTrue_withEmptyThresholds() {
        SignalStrengthUpdateRequest request = new SignalStrengthUpdateRequest.Builder()
                .setSignalThresholdInfos(Collections.EMPTY_LIST)
                .setSystemThresholdReportingRequestedWhileIdle(true)
                .build();

        assertThat(request.getSignalThresholdInfos()).isEmpty();
        assertThat(request.isReportingRequestedWhileIdle()).isFalse();
        assertThat(request.isSystemThresholdReportingRequestedWhileIdle()).isTrue();
    }

    private void validateBuilderWithInvalidParam(Collection<SignalThresholdInfo> infos) {
        try {
            new SignalStrengthUpdateRequest.Builder()