Revert "Revert "Remove the system new message notification automatically.""

This reverts commit de705fdb1d33c79ef676271fd6938120e15912f0.

The root cause was not caused by the original CL and it is now fixed.

BUG: 28874264

Change-Id: If250a2e59b8230fe54fdf5d35d3b669a70fe9a28
diff --git a/src/java/com/android/internal/telephony/InboundSmsHandler.java b/src/java/com/android/internal/telephony/InboundSmsHandler.java
index 8aed4e8..5fa8264 100644
--- a/src/java/com/android/internal/telephony/InboundSmsHandler.java
+++ b/src/java/com/android/internal/telephony/InboundSmsHandler.java
@@ -58,6 +58,7 @@
 import android.service.carrier.ICarrierMessagingCallback;
 import android.service.carrier.ICarrierMessagingService;
 import android.service.carrier.MessagePdu;
+import android.service.notification.StatusBarNotification;
 import android.telephony.CarrierMessagingServiceManager;
 import android.telephony.Rlog;
 import android.telephony.SmsManager;
@@ -877,6 +878,7 @@
         Notification.Builder mBuilder = new Notification.Builder(mContext)
                 .setSmallIcon(com.android.internal.R.drawable.sym_action_chat)
                 .setAutoCancel(true)
+                .setVisibility(Notification.VISIBILITY_PUBLIC)
                 .setDefaults(Notification.DEFAULT_ALL)
                 .setContentTitle(mContext.getString(R.string.new_sms_notification_title))
                 .setContentText(mContext.getString(R.string.new_sms_notification_content))
@@ -887,6 +889,13 @@
                 NOTIFICATION_TAG, NOTIFICATION_ID_NEW_MESSAGE, mBuilder.build());
     }
 
+    static void cancelNewMessageNotification(Context context) {
+        NotificationManager mNotificationManager =
+            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+        mNotificationManager.cancel(InboundSmsHandler.NOTIFICATION_TAG,
+            InboundSmsHandler.NOTIFICATION_ID_NEW_MESSAGE);
+    }
+
     /**
      * Filters the SMS.
      *
diff --git a/src/java/com/android/internal/telephony/SmsBroadcastUndelivered.java b/src/java/com/android/internal/telephony/SmsBroadcastUndelivered.java
index 51f8425..57299fe 100644
--- a/src/java/com/android/internal/telephony/SmsBroadcastUndelivered.java
+++ b/src/java/com/android/internal/telephony/SmsBroadcastUndelivered.java
@@ -23,10 +23,8 @@
 import android.content.IntentFilter;
 import android.database.Cursor;
 import android.database.SQLException;
-import android.net.Uri;
 import android.os.UserHandle;
 import android.os.UserManager;
-import android.provider.Telephony;
 import android.telephony.Rlog;
 
 import com.android.internal.telephony.cdma.CdmaInboundSmsHandler;
@@ -81,18 +79,25 @@
      */
     private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
         @Override
-        public void onReceive(Context context, Intent intent) {
+        public void onReceive(final Context context, Intent intent) {
             Rlog.d(TAG, "Received broadcast " + intent.getAction());
             if (Intent.ACTION_USER_UNLOCKED.equals(intent.getAction())) {
-                new ScanRawTableThread().start();
+                new ScanRawTableThread(context).start();
             }
         }
     };
 
     private class ScanRawTableThread extends Thread {
+        private final Context context;
+
+        private ScanRawTableThread(Context context) {
+            this.context = context;
+        }
+
         @Override
         public void run() {
             scanRawTable();
+            InboundSmsHandler.cancelNewMessageNotification(context);
         }
     }
 
@@ -123,7 +128,7 @@
         UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
 
         if (userManager.isUserUnlocked()) {
-            new ScanRawTableThread().start();
+            new ScanRawTableThread(context).start();
         } else {
             IntentFilter userFilter = new IntentFilter();
             userFilter.addAction(Intent.ACTION_USER_UNLOCKED);