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

Commit 668eaf11 authored by Rambo Wang's avatar Rambo Wang
Browse files

Add BarringInfo in RadioIndicationFilter and DeviceStateMonitor

- Enable/disable barring indication based on current device states.
- Automatically pull barring info when screen, charging or tethering
  goes from off to on while the other two are off.
- Call setIndiationFilter_1_5() when radio hal @1.5 is supported.
  Make sure the input filter bits are supported before calling HAL.

Bug: 147264488 150916043
Test: atest com.android.internal.telephony.DeviceStateMonitorTest
Test: atest com.android.internal.telephony.RILTest
Merged-In: I491f12062a4d02f90c62e54673b1cb89db243dd2
Change-Id: I491f12062a4d02f90c62e54673b1cb89db243dd2
(cherry picked from commit 30dde1ed)
parent d6455281
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.display.DisplayManager;
import android.hardware.radio.V1_2.IndicationFilter;
import android.hardware.radio.V1_5.IndicationFilter;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
@@ -380,7 +380,6 @@ public class DeviceStateMonitor extends Handler {
        // 1. The device is charging.
        // 2. When the screen is on.
        // 3. When data tethering is on.
        // 4. When the update mode is IGNORE_SCREEN_OFF.
        if (mIsCharging || mIsScreenOn || mIsTetheringOn) {
            return false;
        }
@@ -389,6 +388,17 @@ public class DeviceStateMonitor extends Handler {
        return true;
    }

    /**
     * @return True if BarryingInfo update should be turned off.
     */
    private boolean shouldTurnOffBarringInfo() {
        // We should not turn off BarringInfo update if one of the following condition is true.
        // 1. The device is charging.
        // 2. When the screen is on.
        // 3. When the tethering is on.
        return !(mIsCharging || mIsScreenOn || mIsTetheringOn);
    }

    /**
     * Set if Telephony need always report signal strength.
     *
@@ -435,18 +445,22 @@ public class DeviceStateMonitor extends Handler {
     * @param state True if enabled/on, otherwise disabled/off.
     */
    private void onUpdateDeviceState(int eventType, boolean state) {
        boolean shouldPollBarringInfo = false;
        switch (eventType) {
            case EVENT_SCREEN_STATE_CHANGED:
                if (mIsScreenOn == state) return;
                shouldPollBarringInfo = shouldTurnOffBarringInfo();
                mIsScreenOn = state;
                break;
            case EVENT_CHARGING_STATE_CHANGED:
                if (mIsCharging == state) return;
                shouldPollBarringInfo = shouldTurnOffBarringInfo();
                mIsCharging = state;
                sendDeviceState(CHARGING_STATE, mIsCharging);
                break;
            case EVENT_TETHERING_STATE_CHANGED:
                if (mIsTetheringOn == state) return;
                shouldPollBarringInfo = shouldTurnOffBarringInfo();
                mIsTetheringOn = state;
                break;
            case EVENT_POWER_SAVE_MODE_CHANGED:
@@ -499,7 +513,17 @@ public class DeviceStateMonitor extends Handler {
            newFilter |= IndicationFilter.PHYSICAL_CHANNEL_CONFIG;
        }

        if (!shouldTurnOffBarringInfo()) {
            newFilter |= IndicationFilter.BARRING_INFO;
        }

        setUnsolResponseFilter(newFilter, false);

        if (shouldPollBarringInfo) {
            if (DBG) log("Manually pull barring info...", true);
            // use a null message since we don't care of receiving response
            mPhone.mCi.getBarringInfo(null);
        }
    }

    /**
+28 −4
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ import android.hardware.radio.V1_0.HardwareConfigModem;
import android.hardware.radio.V1_0.IRadio;
import android.hardware.radio.V1_0.IccIo;
import android.hardware.radio.V1_0.ImsSmsMessage;
import android.hardware.radio.V1_0.IndicationFilter;
import android.hardware.radio.V1_0.LceDataInfo;
import android.hardware.radio.V1_0.MvnoType;
import android.hardware.radio.V1_0.NvWriteItem;
@@ -52,6 +51,7 @@ import android.hardware.radio.V1_0.UusInfo;
import android.hardware.radio.V1_4.CarrierRestrictionsWithPriority;
import android.hardware.radio.V1_4.SimLockMultiSimPolicy;
import android.hardware.radio.V1_5.AccessNetwork;
import android.hardware.radio.V1_5.IndicationFilter;
import android.hardware.radio.V1_5.RadioAccessNetworks;
import android.hardware.radio.deprecated.V1_0.IOemHook;
import android.net.InetAddresses;
@@ -189,6 +189,19 @@ public class RIL extends BaseCommands implements CommandsInterface {
    // IRadio version
    private HalVersion mRadioVersion = RADIO_HAL_VERSION_UNKNOWN;

    private static final int INDICATION_FILTERS_ALL_V1_0 =
            IndicationFilter.SIGNAL_STRENGTH
            | IndicationFilter.FULL_NETWORK_STATE
            | IndicationFilter.DATA_CALL_DORMANCY_CHANGED;
    private static final int INDICATION_FILTERS_ALL_V1_2 =
            INDICATION_FILTERS_ALL_V1_0
            | IndicationFilter.LINK_CAPACITY_ESTIMATE
            | IndicationFilter.PHYSICAL_CHANNEL_CONFIG;
    private static final  int INDICATION_FILTERS_ALL_V1_5 =
            INDICATION_FILTERS_ALL_V1_2
            | IndicationFilter.REGISTRATION_FAILURE
            | IndicationFilter.BARRING_INFO;

    //***** Instance Variables

    @UnsupportedAppUsage
@@ -4633,19 +4646,30 @@ public class RIL extends BaseCommands implements CommandsInterface {
                riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " " + filter);
            }

            if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_2)) {
            if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
                try {
                    android.hardware.radio.V1_5.IRadio radioProxy15 =
                            (android.hardware.radio.V1_5.IRadio) radioProxy;

                    filter &= INDICATION_FILTERS_ALL_V1_5;
                    radioProxy15.setIndicationFilter_1_5(rr.mSerial, filter);
                } catch (RemoteException | RuntimeException e) {
                    handleRadioProxyExceptionForRR(rr, "setIndicationFilter_1_5", e);
                }
            } else if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_2)) {
                try {
                    android.hardware.radio.V1_2.IRadio radioProxy12 =
                            (android.hardware.radio.V1_2.IRadio) radioProxy;

                    filter &= INDICATION_FILTERS_ALL_V1_2;
                    radioProxy12.setIndicationFilter_1_2(rr.mSerial, filter);
                } catch (RemoteException | RuntimeException e) {
                    handleRadioProxyExceptionForRR(rr, "setIndicationFilter_1_2", e);
                }
            } else {
                try {
                    int filter10 = filter & IndicationFilter.ALL;
                    radioProxy.setIndicationFilter(rr.mSerial, filter10);
                    filter &= INDICATION_FILTERS_ALL_V1_0;
                    radioProxy.setIndicationFilter(rr.mSerial, filter);
                } catch (RemoteException | RuntimeException e) {
                    handleRadioProxyExceptionForRR(rr, "setIndicationFilter", e);
                }
+33 −4
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import static android.hardware.radio.V1_0.DeviceStateType.LOW_DATA_EXPECTED;
import static android.hardware.radio.V1_0.DeviceStateType.POWER_SAVE_MODE;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotEquals;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
@@ -33,7 +33,7 @@ import static java.util.Arrays.asList;

import android.annotation.IntDef;
import android.content.Intent;
import android.hardware.radio.V1_2.IndicationFilter;
import android.hardware.radio.V1_5.IndicationFilter;
import android.net.ConnectivityManager;
import android.os.BatteryManager;
import android.os.Message;
@@ -65,7 +65,8 @@ public class DeviceStateMonitorTest extends TelephonyTest {
            | IndicationFilter.FULL_NETWORK_STATE
            | IndicationFilter.DATA_CALL_DORMANCY_CHANGED
            | IndicationFilter.LINK_CAPACITY_ESTIMATE
            | IndicationFilter.PHYSICAL_CHANNEL_CONFIG;
            | IndicationFilter.PHYSICAL_CHANNEL_CONFIG
            | IndicationFilter.BARRING_INFO;

    // INDICATION_FILTERS_ALL but excludes Indication.SIGNAL_STRENGTH
    private static final int INDICATION_FILTERS_WHEN_TETHERING_ON =
@@ -193,7 +194,7 @@ public class DeviceStateMonitorTest extends TelephonyTest {
        ArgumentCaptor<Integer> acIndicationFilter = ArgumentCaptor.forClass(Integer.class);
        verify(mSimulatedCommandsVerifier).setUnsolResponseFilter(
                acIndicationFilter.capture(), nullable(Message.class));
        assertTrue((acIndicationFilter.getValue() & indicationFilter) != 0);
        assertNotEquals((acIndicationFilter.getValue() & indicationFilter), 0);

        // Turn off the state again
        updateState(state, STATE_OFF);
@@ -336,4 +337,32 @@ public class DeviceStateMonitorTest extends TelephonyTest {
        assertEquals(
                DeviceStateMonitor.CELL_INFO_INTERVAL_SHORT_MS, mDSM.computeCellInfoMinInterval());
    }

    @Test
    public void testGetBarringInfo() {
        // At beginning, all states off. Now turn screen on
        updateState(STATE_TYPE_SCREEN, STATE_ON);

        ArgumentCaptor<Integer> acBarringInfo = ArgumentCaptor.forClass(Integer.class);
        verify(mSimulatedCommandsVerifier).setUnsolResponseFilter(acBarringInfo.capture(),
                nullable(Message.class));
        assertNotEquals((acBarringInfo.getValue() & IndicationFilter.BARRING_INFO), 0);
        verify(mSimulatedCommandsVerifier).getBarringInfo(nullable(Message.class));

        reset(mSimulatedCommandsVerifier);

        // Turn screen off
        updateState(STATE_TYPE_SCREEN, STATE_OFF);
        verify(mSimulatedCommandsVerifier, never()).getBarringInfo(nullable(Message.class));
        verify(mSimulatedCommandsVerifier).setUnsolResponseFilter(acBarringInfo.capture(),
                nullable(Message.class));
        assertEquals((acBarringInfo.getValue() & IndicationFilter.BARRING_INFO), 0);

        reset(mSimulatedCommandsVerifier);

        // Turn tethering on, then screen on, getBarringInfo() should only be called once
        updateState(STATE_TYPE_TETHERING, STATE_ON);
        updateState(STATE_TYPE_SCREEN, STATE_ON);
        verify(mSimulatedCommandsVerifier).getBarringInfo(nullable(Message.class));
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -2366,4 +2366,10 @@ public class SimulatedCommands extends BaseCommands
    public Handler getHandler() {
        return mHandlerThread.getThreadHandler();
    }

    @Override
    public void getBarringInfo(Message result) {
        SimulatedCommandsVerifier.getInstance().getBarringInfo(result);
        resultSuccess(result, null);
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -1454,4 +1454,8 @@ public class SimulatedCommandsVerifier implements CommandsInterface {

    @Override
    public void unregisterUiccApplicationEnablementChanged(Handler h) {}

    @Override
    public void getBarringInfo(Message result) {
    }
}