Fixed battery drain after modem reset

After modem crashes and resets, telephony should resend
the indication filter to the modem again. Otherwise modem
keeps sending unnecessary indications when the screen is off,
which causes battery drain.

Test: Telephony sanity tests and unit tests
Bug: 111125632
Change-Id: I12f2561a2ca8877e2528795b1f5a1af0305657ae
(cherry picked from commit 371e214031abee8757ecbbe6eb923b5b785963d4)
diff --git a/src/java/com/android/internal/telephony/DeviceStateMonitor.java b/src/java/com/android/internal/telephony/DeviceStateMonitor.java
index 04e96ca..92a78f7 100644
--- a/src/java/com/android/internal/telephony/DeviceStateMonitor.java
+++ b/src/java/com/android/internal/telephony/DeviceStateMonitor.java
@@ -64,6 +64,7 @@
     private static final int EVENT_POWER_SAVE_MODE_CHANGED      = 3;
     private static final int EVENT_CHARGING_STATE_CHANGED       = 4;
     private static final int EVENT_TETHERING_STATE_CHANGED      = 5;
+    private static final int EVENT_RADIO_AVAILABLE              = 6;
 
     // TODO(b/74006656) load hysteresis values from a property when DeviceStateMonitor starts
     private static final int HYSTERESIS_KBPS = 50;
@@ -200,6 +201,7 @@
         mPhone.getContext().registerReceiver(mBroadcastReceiver, filter, null, mPhone);
 
         mPhone.mCi.registerForRilConnected(this, EVENT_RIL_CONNECTED, null);
+        mPhone.mCi.registerForAvailable(this, EVENT_RADIO_AVAILABLE, null);
     }
 
     /**
@@ -344,7 +346,8 @@
         log("handleMessage msg=" + msg, false);
         switch (msg.what) {
             case EVENT_RIL_CONNECTED:
-                onRilConnected();
+            case EVENT_RADIO_AVAILABLE:
+                onReset();
                 break;
             case EVENT_UPDATE_MODE_CHANGED:
                 onSetIndicationUpdateMode(msg.arg1, msg.arg2);
@@ -420,14 +423,14 @@
     }
 
     /**
-     * Called when RIL is connected during boot up or reconnected after modem restart.
+     * Called when RIL is connected during boot up or radio becomes available after modem restart.
      *
      * When modem crashes, if the user turns the screen off before RIL reconnects, device
      * state and filter cannot be sent to modem. Resend the state here so that modem
      * has the correct state (to stop signal strength reporting, etc).
      */
-    private void onRilConnected() {
-        log("RIL connected.", true);
+    private void onReset() {
+        log("onReset.", true);
         sendDeviceState(CHARGING_STATE, mIsCharging);
         sendDeviceState(LOW_DATA_EXPECTED, mIsLowDataExpected);
         sendDeviceState(POWER_SAVE_MODE, mIsPowerSaveOn);
diff --git a/tests/telephonytests/src/com/android/internal/telephony/DeviceStateMonitorTest.java b/tests/telephonytests/src/com/android/internal/telephony/DeviceStateMonitorTest.java
index 591b111..1f883b8 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/DeviceStateMonitorTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/DeviceStateMonitorTest.java
@@ -124,4 +124,12 @@
         verify(mSimulatedCommandsVerifier, times(1)).sendDeviceState(eq(CHARGING_STATE),
                 eq(false), nullable(Message.class));
     }
+
+    @FlakyTest
+    public void testReset() throws Exception {
+        mDSM.obtainMessage(6).sendToTarget();
+
+        verify(mSimulatedCommandsVerifier, times(1)).setUnsolResponseFilter(eq(-1),
+                nullable(Message.class));
+    }
 }