Show HUN for imcoming call after leaving Dialer app

Bug:139027928
Test: Manually
Change-Id: Ief7e075e278738cd5f71d3836fc2e80c5f6f60b8
diff --git a/src/com/android/car/dialer/ui/activecall/InCallActivity.java b/src/com/android/car/dialer/ui/activecall/InCallActivity.java
index e374564..7b8215c 100644
--- a/src/com/android/car/dialer/ui/activecall/InCallActivity.java
+++ b/src/com/android/car/dialer/ui/activecall/InCallActivity.java
@@ -31,6 +31,7 @@
 import com.android.car.dialer.Constants;
 import com.android.car.dialer.R;
 import com.android.car.dialer.log.L;
+import com.android.car.dialer.notification.InCallNotificationController;
 
 import java.util.List;
 
@@ -41,6 +42,7 @@
     private Fragment mIncomingCallFragment;
 
     private MutableLiveData<Boolean> mShowIncomingCall;
+    private LiveData<Call> mIncomingCallLiveData;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -56,16 +58,26 @@
 
         mShowIncomingCall = new MutableLiveData();
         InCallViewModel inCallViewModel = ViewModelProviders.of(this).get(InCallViewModel.class);
-        LiveData<Call> incomingCallLiveData = LiveDataFunctions.iff(mShowIncomingCall,
+        mIncomingCallLiveData = LiveDataFunctions.iff(mShowIncomingCall,
                 inCallViewModel.getIncomingCall());
-        incomingCallLiveData.observe(this, this::updateIncomingCallVisibility);
-        LiveDataFunctions.pair(inCallViewModel.getOngoingCallList(), incomingCallLiveData).observe(
+        mIncomingCallLiveData.observe(this, this::updateIncomingCallVisibility);
+        LiveDataFunctions.pair(inCallViewModel.getOngoingCallList(), mIncomingCallLiveData).observe(
                 this, this::maybeFinishActivity);
 
         handleIntent();
     }
 
     @Override
+    protected void onStop() {
+        super.onStop();
+        L.d(TAG, "onStop");
+        if (mShowIncomingCall.getValue()) {
+            InCallNotificationController.get()
+                    .showInCallNotification(mIncomingCallLiveData.getValue());
+        }
+    }
+
+    @Override
     protected void onNewIntent(Intent i) {
         super.onNewIntent(i);
         L.d(TAG, "onNewIntent");
diff --git a/src/com/android/car/dialer/ui/activecall/InCallViewModel.java b/src/com/android/car/dialer/ui/activecall/InCallViewModel.java
index f5f8704..bcb9753 100644
--- a/src/com/android/car/dialer/ui/activecall/InCallViewModel.java
+++ b/src/com/android/car/dialer/ui/activecall/InCallViewModel.java
@@ -78,6 +78,9 @@
         public void onServiceConnected(ComponentName name, IBinder binder) {
             L.d(TAG, "onServiceConnected: %s, service: %s", name, binder);
             mInCallService = ((InCallServiceImpl.LocalBinder) binder).getService();
+            for (Call call : mInCallService.getCalls()) {
+                call.registerCallback(mCallStateChangedCallback);
+            }
             updateCallList();
             mInCallService.addActiveCallListChangedCallback(InCallViewModel.this);
         }
@@ -235,6 +238,9 @@
     protected void onCleared() {
         mContext.unbindService(mInCallServiceConnection);
         if (mInCallService != null) {
+            for (Call call : mInCallService.getCalls()) {
+                call.unregisterCallback(mCallStateChangedCallback);
+            }
             mInCallService.removeActiveCallListChangedCallback(this);
         }
         mInCallService = null;