Merge "Update EngagementSignalsCallbackRemote to implement EngagementSignalsCallback" into androidx-main
diff --git a/browser/browser/api/current.txt b/browser/browser/api/current.txt
index 1cb34f0..42d5a3b 100644
--- a/browser/browser/api/current.txt
+++ b/browser/browser/api/current.txt
@@ -203,7 +203,7 @@
     method @androidx.browser.customtabs.CustomTabsService.Result protected abstract int postMessage(androidx.browser.customtabs.CustomTabsSessionToken, String, android.os.Bundle?);
     method protected abstract boolean receiveFile(androidx.browser.customtabs.CustomTabsSessionToken, android.net.Uri, int, android.os.Bundle?);
     method protected abstract boolean requestPostMessageChannel(androidx.browser.customtabs.CustomTabsSessionToken, android.net.Uri);
-    method protected boolean setEngagementSignalsCallback(androidx.browser.customtabs.CustomTabsSessionToken, androidx.browser.customtabs.EngagementSignalsCallbackRemote, android.os.Bundle);
+    method protected boolean setEngagementSignalsCallback(androidx.browser.customtabs.CustomTabsSessionToken, androidx.browser.customtabs.EngagementSignalsCallback, android.os.Bundle);
     method protected abstract boolean updateVisuals(androidx.browser.customtabs.CustomTabsSessionToken, android.os.Bundle?);
     method protected abstract boolean validateRelationship(androidx.browser.customtabs.CustomTabsSessionToken, @androidx.browser.customtabs.CustomTabsService.Relation int, android.net.Uri, android.os.Bundle?);
     method protected abstract boolean warmup(long);
@@ -265,12 +265,6 @@
     method public default void onVerticalScrollEvent(boolean, android.os.Bundle);
   }
 
-  public final class EngagementSignalsCallbackRemote {
-    method public void onGreatestScrollPercentageIncreased(@IntRange(from=1, to=100) int, android.os.Bundle) throws android.os.RemoteException;
-    method public void onSessionEnded(boolean, android.os.Bundle) throws android.os.RemoteException;
-    method public void onVerticalScrollEvent(boolean, android.os.Bundle) throws android.os.RemoteException;
-  }
-
   public class PostMessageService extends android.app.Service {
     ctor public PostMessageService();
     method public android.os.IBinder onBind(android.content.Intent?);
diff --git a/browser/browser/api/public_plus_experimental_current.txt b/browser/browser/api/public_plus_experimental_current.txt
index 1cb34f0..42d5a3b 100644
--- a/browser/browser/api/public_plus_experimental_current.txt
+++ b/browser/browser/api/public_plus_experimental_current.txt
@@ -203,7 +203,7 @@
     method @androidx.browser.customtabs.CustomTabsService.Result protected abstract int postMessage(androidx.browser.customtabs.CustomTabsSessionToken, String, android.os.Bundle?);
     method protected abstract boolean receiveFile(androidx.browser.customtabs.CustomTabsSessionToken, android.net.Uri, int, android.os.Bundle?);
     method protected abstract boolean requestPostMessageChannel(androidx.browser.customtabs.CustomTabsSessionToken, android.net.Uri);
-    method protected boolean setEngagementSignalsCallback(androidx.browser.customtabs.CustomTabsSessionToken, androidx.browser.customtabs.EngagementSignalsCallbackRemote, android.os.Bundle);
+    method protected boolean setEngagementSignalsCallback(androidx.browser.customtabs.CustomTabsSessionToken, androidx.browser.customtabs.EngagementSignalsCallback, android.os.Bundle);
     method protected abstract boolean updateVisuals(androidx.browser.customtabs.CustomTabsSessionToken, android.os.Bundle?);
     method protected abstract boolean validateRelationship(androidx.browser.customtabs.CustomTabsSessionToken, @androidx.browser.customtabs.CustomTabsService.Relation int, android.net.Uri, android.os.Bundle?);
     method protected abstract boolean warmup(long);
@@ -265,12 +265,6 @@
     method public default void onVerticalScrollEvent(boolean, android.os.Bundle);
   }
 
-  public final class EngagementSignalsCallbackRemote {
-    method public void onGreatestScrollPercentageIncreased(@IntRange(from=1, to=100) int, android.os.Bundle) throws android.os.RemoteException;
-    method public void onSessionEnded(boolean, android.os.Bundle) throws android.os.RemoteException;
-    method public void onVerticalScrollEvent(boolean, android.os.Bundle) throws android.os.RemoteException;
-  }
-
   public class PostMessageService extends android.app.Service {
     ctor public PostMessageService();
     method public android.os.IBinder onBind(android.content.Intent?);
diff --git a/browser/browser/api/restricted_current.txt b/browser/browser/api/restricted_current.txt
index 20835a4..19a1da2 100644
--- a/browser/browser/api/restricted_current.txt
+++ b/browser/browser/api/restricted_current.txt
@@ -214,7 +214,7 @@
     method @androidx.browser.customtabs.CustomTabsService.Result protected abstract int postMessage(androidx.browser.customtabs.CustomTabsSessionToken, String, android.os.Bundle?);
     method protected abstract boolean receiveFile(androidx.browser.customtabs.CustomTabsSessionToken, android.net.Uri, int, android.os.Bundle?);
     method protected abstract boolean requestPostMessageChannel(androidx.browser.customtabs.CustomTabsSessionToken, android.net.Uri);
-    method protected boolean setEngagementSignalsCallback(androidx.browser.customtabs.CustomTabsSessionToken, androidx.browser.customtabs.EngagementSignalsCallbackRemote, android.os.Bundle);
+    method protected boolean setEngagementSignalsCallback(androidx.browser.customtabs.CustomTabsSessionToken, androidx.browser.customtabs.EngagementSignalsCallback, android.os.Bundle);
     method protected abstract boolean updateVisuals(androidx.browser.customtabs.CustomTabsSessionToken, android.os.Bundle?);
     method protected abstract boolean validateRelationship(androidx.browser.customtabs.CustomTabsSessionToken, @androidx.browser.customtabs.CustomTabsService.Relation int, android.net.Uri, android.os.Bundle?);
     method protected abstract boolean warmup(long);
@@ -276,12 +276,6 @@
     method public default void onVerticalScrollEvent(boolean, android.os.Bundle);
   }
 
-  public final class EngagementSignalsCallbackRemote {
-    method public void onGreatestScrollPercentageIncreased(@IntRange(from=1, to=100) int, android.os.Bundle) throws android.os.RemoteException;
-    method public void onSessionEnded(boolean, android.os.Bundle) throws android.os.RemoteException;
-    method public void onVerticalScrollEvent(boolean, android.os.Bundle) throws android.os.RemoteException;
-  }
-
   public class PostMessageService extends android.app.Service {
     ctor public PostMessageService();
     method public android.os.IBinder onBind(android.content.Intent?);
diff --git a/browser/browser/src/main/java/androidx/browser/customtabs/CustomTabsService.java b/browser/browser/src/main/java/androidx/browser/customtabs/CustomTabsService.java
index 8747f31..ee1e791 100644
--- a/browser/browser/src/main/java/androidx/browser/customtabs/CustomTabsService.java
+++ b/browser/browser/src/main/java/androidx/browser/customtabs/CustomTabsService.java
@@ -274,7 +274,7 @@
         public boolean setEngagementSignalsCallback(
                 @NonNull ICustomTabsCallback customTabsCallback, @NonNull IBinder callback,
                 @NonNull Bundle extras) {
-            EngagementSignalsCallbackRemote remote = EngagementSignalsCallbackRemote.fromBinder(
+            EngagementSignalsCallback remote = EngagementSignalsCallbackRemote.fromBinder(
                     callback);
             return CustomTabsService.this.setEngagementSignalsCallback(
                     new CustomTabsSessionToken(customTabsCallback, getSessionIdFromBundle(extras)),
@@ -506,11 +506,11 @@
     }
 
     /**
-     * Sets an {@link EngagementSignalsCallbackRemote} to execute callbacks for events related to
+     * Sets an {@link EngagementSignalsCallback} to execute callbacks for events related to
      * the user's engagement with the webpage within the tab.
      *
      * @param sessionToken The unique identifier for the session.
-     * @param callback The {@link EngagementSignalsCallbackRemote} to execute the callbacks.
+     * @param callback The {@link EngagementSignalsCallback} to execute the callbacks.
      * @param extras Reserved for future use.
      * @return Whether the callback connection is allowed. If false, no callbacks will be called for
      *         this session.
@@ -520,7 +520,7 @@
     @SuppressWarnings("ExecutorRegistration")
     protected boolean setEngagementSignalsCallback(
             @NonNull CustomTabsSessionToken sessionToken,
-            @NonNull EngagementSignalsCallbackRemote callback, @NonNull Bundle extras) {
+            @NonNull EngagementSignalsCallback callback, @NonNull Bundle extras) {
         return false;
     }
 
diff --git a/browser/browser/src/main/java/androidx/browser/customtabs/EngagementSignalsCallbackRemote.java b/browser/browser/src/main/java/androidx/browser/customtabs/EngagementSignalsCallbackRemote.java
index 9e02c71..44dcc86 100644
--- a/browser/browser/src/main/java/androidx/browser/customtabs/EngagementSignalsCallbackRemote.java
+++ b/browser/browser/src/main/java/androidx/browser/customtabs/EngagementSignalsCallbackRemote.java
@@ -20,16 +20,21 @@
 import android.os.IBinder;
 import android.os.RemoteException;
 import android.support.customtabs.IEngagementSignalsCallback;
+import android.util.Log;
 
 import androidx.annotation.IntRange;
 import androidx.annotation.NonNull;
+import androidx.annotation.RestrictTo;
 
 /**
  * Remote class used to execute callbacks from a binder of {@link EngagementSignalsCallback}. This
  * is a thin wrapper around {@link IEngagementSignalsCallback} that is passed to the Custom Tabs
  * implementation for the calls across process boundaries.
  */
-public final class EngagementSignalsCallbackRemote {
+@RestrictTo(RestrictTo.Scope.LIBRARY)
+/* package */ final class EngagementSignalsCallbackRemote implements EngagementSignalsCallback {
+    private static final String TAG = "EngagementSigsCallbkRmt";
+
     private final IEngagementSignalsCallback mCallbackBinder;
 
     private EngagementSignalsCallbackRemote(@NonNull IEngagementSignalsCallback callbackBinder) {
@@ -53,9 +58,13 @@
      *                      user scrolls back up toward the top of the page.
      * @param extras Reserved for future use.
      */
-    public void onVerticalScrollEvent(boolean isDirectionUp, @NonNull Bundle extras) throws
-            RemoteException {
-        mCallbackBinder.onVerticalScrollEvent(isDirectionUp, extras);
+    @Override
+    public void onVerticalScrollEvent(boolean isDirectionUp, @NonNull Bundle extras) {
+        try {
+            mCallbackBinder.onVerticalScrollEvent(isDirectionUp, extras);
+        } catch (RemoteException e) {
+            Log.e(TAG, "RemoteException during IEngagementSignalsCallback transaction");
+        }
     }
 
     /**
@@ -68,10 +77,14 @@
      *                         made down the current page.
      * @param extras Reserved for future use.
      */
+    @Override
     public void onGreatestScrollPercentageIncreased(
-            @IntRange(from = 1, to = 100) int scrollPercentage, @NonNull Bundle extras) throws
-            RemoteException {
-        mCallbackBinder.onGreatestScrollPercentageIncreased(scrollPercentage, extras);
+            @IntRange(from = 1, to = 100) int scrollPercentage, @NonNull Bundle extras) {
+        try {
+            mCallbackBinder.onGreatestScrollPercentageIncreased(scrollPercentage, extras);
+        } catch (RemoteException e) {
+            Log.e(TAG, "RemoteException during IEngagementSignalsCallback transaction");
+        }
     }
 
     /**
@@ -82,8 +95,12 @@
      *                        scrolling.
      * @param extras Reserved for future use.
      */
-    public void onSessionEnded(boolean didUserInteract, @NonNull Bundle extras)
-            throws RemoteException {
-        mCallbackBinder.onSessionEnded(didUserInteract, extras);
+    @Override
+    public void onSessionEnded(boolean didUserInteract, @NonNull Bundle extras) {
+        try {
+            mCallbackBinder.onSessionEnded(didUserInteract, extras);
+        } catch (RemoteException e) {
+            Log.e(TAG, "RemoteException during IEngagementSignalsCallback transaction");
+        }
     }
 }