Added reset geo-fencing checking after airplane mode support

The out-of-polygon cell broadcast messages will not be
considered for rebroadcasting after airplane mode turned on
or reboot.

Bug: 143614007
Test: Unit tests
Change-Id: Id54bc210958ddf440efea5c3e042e33ba6936a29
(cherry picked from commit 7afa1c0dca8361c50f649610f07aac79084ecbd1)
Merged-in: Id54bc210958ddf440efea5c3e042e33ba6936a29
diff --git a/src/com/android/cellbroadcastservice/CellBroadcastHandler.java b/src/com/android/cellbroadcastservice/CellBroadcastHandler.java
index a5d1c8a..56a89c4 100644
--- a/src/com/android/cellbroadcastservice/CellBroadcastHandler.java
+++ b/src/com/android/cellbroadcastservice/CellBroadcastHandler.java
@@ -37,9 +37,11 @@
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
+import android.os.HandlerExecutor;
 import android.os.Looper;
 import android.os.Message;
 import android.os.Process;
+import android.os.SystemClock;
 import android.os.SystemProperties;
 import android.os.UserHandle;
 import android.provider.Settings;
@@ -102,7 +104,7 @@
     public final LocationRequester mLocationRequester;
 
     /** Timestamp of last airplane mode on */
-    private long mLastAirplaneModeTime = 0;
+    protected long mLastAirplaneModeTime = 0;
 
     /** Resource cache */
     private final Map<Integer, Resources> mResourcesCache = new HashMap<>();
@@ -117,11 +119,11 @@
     private final Map<Integer, Integer> mServiceCategoryCrossRATMap;
 
     private CellBroadcastHandler(Context context) {
-        this("CellBroadcastHandler", context);
+        this("CellBroadcastHandler", context, Looper.myLooper());
     }
 
-    protected CellBroadcastHandler(String debugTag, Context context) {
-        super(debugTag, context);
+    protected CellBroadcastHandler(String debugTag, Context context, Looper looper) {
+        super(debugTag, context, looper);
         mLocationRequester = new LocationRequester(
                 context,
                 (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE),
@@ -318,9 +320,11 @@
         long expirationDuration = res.getInteger(R.integer.message_expiration_time);
         long dupCheckTime = System.currentTimeMillis() - expirationDuration;
 
-        // Some carriers require reset duplication detection after airplane mode.
-        if (res.getBoolean(R.bool.reset_duplicate_detection_on_airplane_mode)) {
+        // Some carriers require reset duplication detection after airplane mode or reboot.
+        if (res.getBoolean(R.bool.reset_on_power_cycle_or_airplane_mode)) {
             dupCheckTime = Long.max(dupCheckTime, mLastAirplaneModeTime);
+            dupCheckTime = Long.max(dupCheckTime,
+                    System.currentTimeMillis() - SystemClock.elapsedRealtime());
         }
 
         List<SmsCbMessage> cbMessages = new ArrayList<>();