Import updated Android SetupCompat Library 738259266

Copied from google3/third_party/java_src/android_libs/setupcompat

Test: mm

Included changes:
  - 738259266 Avoid exception on checking the length of fragment tag
  - 738245976 Log the duration metrics on fragment stop
  - 737952184 [Expressive style] Prevent client update visibility frequ...

Bug: 404516903
PiperOrigin-RevId: 738259266
Change-Id: If53e0aafecbc681f7353ccbbbcc6e7d486b92068
diff --git a/main/java/com/google/android/setupcompat/PartnerCustomizationLayout.java b/main/java/com/google/android/setupcompat/PartnerCustomizationLayout.java
index 35efc23..6a4f732 100644
--- a/main/java/com/google/android/setupcompat/PartnerCustomizationLayout.java
+++ b/main/java/com/google/android/setupcompat/PartnerCustomizationLayout.java
@@ -323,7 +323,7 @@
     }
   }
 
-  private void logFooterButtonMetrics() {
+  private void logFooterButtonMetrics(PersistableBundle bundle) {
     if (VERSION.SDK_INT >= Build.VERSION_CODES.Q
         && activity != null
         && WizardManagerHelper.isAnySetupWizard(activity.getIntent())
@@ -351,7 +351,10 @@
 
       PersistableBundle persistableBundle =
           PersistableBundles.mergeBundles(
-              footerBarMixin.getLoggingMetrics(), primaryButtonMetrics, secondaryButtonMetrics);
+              footerBarMixin.getLoggingMetrics(),
+              primaryButtonMetrics,
+              secondaryButtonMetrics,
+              bundle);
 
       SetupMetricsLogger.logCustomEvent(
           getContext(),
diff --git a/main/java/com/google/android/setupcompat/internal/LifecycleFragment.java b/main/java/com/google/android/setupcompat/internal/LifecycleFragment.java
index ce4345d..6027d29 100644
--- a/main/java/com/google/android/setupcompat/internal/LifecycleFragment.java
+++ b/main/java/com/google/android/setupcompat/internal/LifecycleFragment.java
@@ -47,7 +47,7 @@
 
   /** Interface for listening to lifecycle changes of the fragment. */
   public interface OnFragmentLifecycleChangeListener {
-    void onStop();
+    void onStop(PersistableBundle bundle);
   }
 
   /**
@@ -137,8 +137,12 @@
   @Override
   public void onResume() {
     super.onResume();
-    LOG.atDebug("onResume host=" + getActivity().getClass().getSimpleName());
     startInNanos = ClockProvider.timeInNanos();
+    LOG.atDebug(
+        "onResume host="
+            + getActivity().getClass().getSimpleName()
+            + ", startInNanos="
+            + startInNanos);
     logScreenResume();
   }
 
@@ -152,9 +156,16 @@
   @Override
   public void onStop() {
     super.onStop();
-    LOG.atDebug("onStop host=" + getActivity().getClass().getSimpleName());
-    if (lifecycleChangeListener != null) {
-      lifecycleChangeListener.onStop();
+    long onStopTimestamp = System.nanoTime();
+    LOG.atDebug(
+        "onStop host="
+            + getActivity().getClass().getSimpleName()
+            + ", onStopTimestamp="
+            + onStopTimestamp);
+    if (VERSION.SDK_INT >= VERSION_CODES.Q && lifecycleChangeListener != null) {
+      PersistableBundle bundle = new PersistableBundle();
+      bundle.putLong("onScreenStop", onStopTimestamp);
+      lifecycleChangeListener.onStop(bundle);
     }
   }
 
diff --git a/main/java/com/google/android/setupcompat/template/FooterBarMixin.java b/main/java/com/google/android/setupcompat/template/FooterBarMixin.java
index 7afa16d..7aa9cd4 100644
--- a/main/java/com/google/android/setupcompat/template/FooterBarMixin.java
+++ b/main/java/com/google/android/setupcompat/template/FooterBarMixin.java
@@ -27,6 +27,7 @@
 import android.graphics.Color;
 import android.graphics.Paint;
 import android.graphics.drawable.GradientDrawable;
+import android.os.Build.VERSION;
 import android.os.Build.VERSION_CODES;
 import android.os.PersistableBundle;
 import androidx.fragment.app.Fragment;
@@ -55,6 +56,7 @@
 import com.google.android.setupcompat.R;
 import com.google.android.setupcompat.internal.FooterButtonPartnerConfig;
 import com.google.android.setupcompat.internal.TemplateLayout;
+import com.google.android.setupcompat.logging.CustomEvent;
 import com.google.android.setupcompat.logging.LoggingObserver;
 import com.google.android.setupcompat.logging.LoggingObserver.SetupCompatUiEvent.ButtonInflatedEvent;
 import com.google.android.setupcompat.logging.internal.FooterBarMixinMetrics;
@@ -166,15 +168,24 @@
       public void onVisibilityChanged(int visibility) {
         if (buttonContainer != null) {
           Button button = buttonContainer.findViewById(id);
-          if (button != null) {
-            button.setVisibility(visibility);
-            autoSetButtonBarVisibility();
 
-            if (PartnerConfigHelper.isGlifExpressiveEnabled(context)) {
-              // Re-layout the buttons when visibility changes, especially when tertiary button is
-              // enabled to avoid the button layout is not correct.
-              repopulateButtons();
-            }
+          if (button == null) {
+            LOG.atDebug("onVisibilityChanged: button is null, skiped.");
+            return;
+          }
+
+          if (button.getVisibility() == visibility) {
+            LOG.atDebug("onVisibilityChanged: button visibility is not changed, skiped.");
+            return;
+          }
+
+          button.setVisibility(visibility);
+          autoSetButtonBarVisibility();
+
+          if (PartnerConfigHelper.isGlifExpressiveEnabled(context)) {
+            // Re-layout the buttons when visibility changes, especially when tertiary button is
+            // enabled to avoid the button layout is not correct.
+            repopulateButtons();
           }
         }
       }
@@ -1442,15 +1453,19 @@
    * Assigns logging metrics to bundle for PartnerCustomizationLayout to log metrics to SetupWizard.
    */
   @TargetApi(VERSION_CODES.Q)
+  @SuppressLint("ObsoleteSdkInt")
   public PersistableBundle getLoggingMetrics() {
     LOG.atDebug("FooterBarMixin fragment name=" + hostFragmentName + ", Tag=" + hostFragmentTag);
     PersistableBundle persistableBundle = metrics.getMetrics();
-    if (PartnerConfigHelper.isEnhancedSetupDesignMetricsEnabled(context)) {
+    if (VERSION.SDK_INT >= VERSION_CODES.Q
+        && PartnerConfigHelper.isEnhancedSetupDesignMetricsEnabled(context)) {
       if (hostFragmentName != null) {
-        persistableBundle.putString(KEY_HOST_FRAGMENT_NAME, hostFragmentName);
+        persistableBundle.putString(
+            KEY_HOST_FRAGMENT_NAME, CustomEvent.trimsStringOverMaxLength(hostFragmentName));
       }
       if (hostFragmentTag != null) {
-        persistableBundle.putString(KEY_HOST_FRAGMENT_TAG, hostFragmentTag);
+        persistableBundle.putString(
+            KEY_HOST_FRAGMENT_TAG, CustomEvent.trimsStringOverMaxLength(hostFragmentTag));
       }
     }
     return persistableBundle;