Merging from ub-launcher3-master @ build 6925377

Test: manual, presubmit on the source branch
x20/teams/android-launcher/merge/ub-launcher3-master_master_6925377.html

Change-Id: I1252294d2557d3ed52f63adaf528aae08d36fa02
diff --git a/robolectric_tests/config/robolectric.properties b/robolectric_tests/config/robolectric.properties
index 197c393..6a5d031 100644
--- a/robolectric_tests/config/robolectric.properties
+++ b/robolectric_tests/config/robolectric.properties
@@ -1,2 +1,2 @@
-manifest=vendor/unbundled_google/packages/WallpaperPickerGoogle/AndroidManifest.xml
+manifest=packages/apps/ThemePicker/AndroidManifest.xml
 sdk=27
diff --git a/src/com/android/customization/module/StatsLogUserEventLogger.java b/src/com/android/customization/module/StatsLogUserEventLogger.java
index 16e1d8b..fb7e15d 100644
--- a/src/com/android/customization/module/StatsLogUserEventLogger.java
+++ b/src/com/android/customization/module/StatsLogUserEventLogger.java
@@ -18,8 +18,25 @@
 import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_COLOR;
 import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_FONT;
 import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SHAPE;
+import static com.android.systemui.shared.system.SysUiStatsLog.STYLE_UICHANGED__ACTION__APP_LAUNCHED;
+import static com.android.systemui.shared.system.SysUiStatsLog.STYLE_UICHANGED__LAUNCHED_PREFERENCE__LAUNCHED_CROP_AND_SET_ACTION;
+import static com.android.systemui.shared.system.SysUiStatsLog.STYLE_UICHANGED__LAUNCHED_PREFERENCE__LAUNCHED_DEEP_LINK;
+import static com.android.systemui.shared.system.SysUiStatsLog.STYLE_UICHANGED__LAUNCHED_PREFERENCE__LAUNCHED_LAUNCHER;
+import static com.android.systemui.shared.system.SysUiStatsLog.STYLE_UICHANGED__LAUNCHED_PREFERENCE__LAUNCHED_LAUNCH_ICON;
+import static com.android.systemui.shared.system.SysUiStatsLog.STYLE_UICHANGED__LAUNCHED_PREFERENCE__LAUNCHED_PREFERENCE_UNSPECIFIED;
+import static com.android.systemui.shared.system.SysUiStatsLog.STYLE_UICHANGED__LAUNCHED_PREFERENCE__LAUNCHED_SETTINGS;
+import static com.android.systemui.shared.system.SysUiStatsLog.STYLE_UICHANGED__LAUNCHED_PREFERENCE__LAUNCHED_SUW;
+import static com.android.systemui.shared.system.SysUiStatsLog.STYLE_UICHANGED__LAUNCHED_PREFERENCE__LAUNCHED_TIPS;
 import static com.android.systemui.shared.system.SysUiStatsLog.STYLE_UI_CHANGED;
+import static com.android.wallpaper.util.LaunchSourceUtils.LAUNCH_SOURCE_DEEP_LINK;
+import static com.android.wallpaper.util.LaunchSourceUtils.LAUNCH_SOURCE_LAUNCHER;
+import static com.android.wallpaper.util.LaunchSourceUtils.LAUNCH_SOURCE_SETTINGS;
+import static com.android.wallpaper.util.LaunchSourceUtils.LAUNCH_SOURCE_SUW;
+import static com.android.wallpaper.util.LaunchSourceUtils.LAUNCH_SOURCE_TIPS;
+import static com.android.wallpaper.util.LaunchSourceUtils.WALLPAPER_LAUNCH_SOURCE;
 
+import android.app.WallpaperManager;
+import android.content.Intent;
 import android.stats.style.nano.StyleEnums;
 
 import androidx.annotation.Nullable;
@@ -33,8 +50,6 @@
 import java.util.Map;
 import java.util.Objects;
 
-
-
 /**
  * StatsLog-backed implementation of {@link ThemesUserEventLogger}.
  */
@@ -43,25 +58,32 @@
     private static final String TAG = "StatsLogUserEventLogger";
 
     @Override
+    public void logAppLaunched(Intent launchSource) {
+        SysUiStatsLog.write(STYLE_UI_CHANGED, STYLE_UICHANGED__ACTION__APP_LAUNCHED, 0, 0, 0, 0, 0,
+                0, 0, 0, 0, 0, getAppLaunchSource(launchSource));
+    }
+
+    @Override
     public void logResumed(boolean provisioned, boolean wallpaper) {
-        SysUiStatsLog.write(STYLE_UI_CHANGED, StyleEnums.ONRESUME, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+        SysUiStatsLog.write(STYLE_UI_CHANGED, StyleEnums.ONRESUME, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                0);
     }
 
     @Override
     public void logStopped() {
-        SysUiStatsLog.write(STYLE_UI_CHANGED, StyleEnums.ONSTOP, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+        SysUiStatsLog.write(STYLE_UI_CHANGED, StyleEnums.ONSTOP, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
     }
 
     @Override
     public void logActionClicked(String collectionId, int actionLabelResId) {
         SysUiStatsLog.write(STYLE_UI_CHANGED, StyleEnums.WALLPAPER_EXPLORE, 0, 0, 0, 0, 0,
-                collectionId.hashCode(), 0, 0, 0, 0);
+                collectionId.hashCode(), 0, 0, 0, 0, 0);
     }
 
     @Override
     public void logIndividualWallpaperSelected(String collectionId) {
         SysUiStatsLog.write(STYLE_UI_CHANGED, StyleEnums.WALLPAPER_SELECT, 0, 0, 0, 0, 0,
-                collectionId.hashCode(), 0, 0, 0, 0);
+                collectionId.hashCode(), 0, 0, 0, 0, 0);
     }
 
     @Override
@@ -69,7 +91,7 @@
         SysUiStatsLog.write(STYLE_UI_CHANGED, StyleEnums.WALLPAPER_OPEN_CATEGORY,
                 0, 0, 0, 0, 0,
                 collectionId.hashCode(),
-                0, 0, 0, 0);
+                0, 0, 0, 0, 0);
     }
 
     @Override
@@ -78,7 +100,7 @@
                 0, 0, 0, 0, 0,
                 collectionId.hashCode(),
                 wallpaperId != null ? wallpaperId.hashCode() : 0,
-                0, 0, 0);
+                0, 0, 0, 0);
     }
 
     @Override
@@ -88,7 +110,7 @@
                 0, 0, 0, 0, 0,
                 collectionId.hashCode(),
                 wallpaperId != null ? wallpaperId.hashCode() : 0,
-                0, 0, 0);
+                0, 0, 0, 0);
     }
 
     @Override
@@ -97,7 +119,7 @@
                 0, 0, 0, 0, 0,
                 collectionId.hashCode(),
                 wallpaperId != null ? wallpaperId.hashCode() : 0,
-                0, 0, 0);
+                0, 0, 0, 0);
     }
 
     @Nullable
@@ -112,7 +134,7 @@
                 Objects.hashCode(getThemePackage(theme, OVERLAY_CATEGORY_COLOR)),
                 Objects.hashCode(getThemePackage(theme,OVERLAY_CATEGORY_FONT)),
                 Objects.hashCode(getThemePackage(theme, OVERLAY_CATEGORY_SHAPE)),
-                0, 0, 0, 0, 0, 0, 0);
+                0, 0, 0, 0, 0, 0, 0, 0);
     }
 
     @Override
@@ -121,7 +143,7 @@
                 Objects.hashCode(getThemePackage(theme, OVERLAY_CATEGORY_COLOR)),
                 Objects.hashCode(getThemePackage(theme,OVERLAY_CATEGORY_FONT)),
                 Objects.hashCode(getThemePackage(theme, OVERLAY_CATEGORY_SHAPE)),
-                0, 0, 0, 0, 0, 0, 0);
+                0, 0, 0, 0, 0, 0, 0, 0);
     }
 
     @Override
@@ -129,7 +151,7 @@
         SysUiStatsLog.write(STYLE_UI_CHANGED, StyleEnums.PICKER_SELECT,
                 0, 0, 0,
                 Objects.hashCode(clock.getId()),
-                0, 0, 0, 0, 0, 0);
+                0, 0, 0, 0, 0, 0, 0);
     }
 
     @Override
@@ -137,7 +159,7 @@
         SysUiStatsLog.write(STYLE_UI_CHANGED, StyleEnums.PICKER_APPLIED,
                 0, 0, 0,
                 Objects.hashCode(clock.getId()),
-                0, 0, 0, 0, 0, 0);
+                0, 0, 0, 0, 0, 0, 0);
     }
 
     @Override
@@ -145,7 +167,7 @@
         SysUiStatsLog.write(STYLE_UI_CHANGED, StyleEnums.PICKER_SELECT,
                 0, 0, 0, 0,
                 grid.cols,
-                0, 0, 0, 0, 0);
+                0, 0, 0, 0, 0, 0);
     }
 
     @Override
@@ -153,6 +175,33 @@
         SysUiStatsLog.write(STYLE_UI_CHANGED, StyleEnums.PICKER_APPLIED,
                 0, 0, 0, 0,
                 grid.cols,
-                0, 0, 0, 0, 0);
+                0, 0, 0, 0, 0, 0);
+    }
+
+    private int getAppLaunchSource(Intent launchSource) {
+        if (launchSource.hasExtra(WALLPAPER_LAUNCH_SOURCE)) {
+            switch (launchSource.getStringExtra(WALLPAPER_LAUNCH_SOURCE)) {
+                case LAUNCH_SOURCE_LAUNCHER:
+                    return STYLE_UICHANGED__LAUNCHED_PREFERENCE__LAUNCHED_LAUNCHER;
+                case LAUNCH_SOURCE_SETTINGS:
+                    return STYLE_UICHANGED__LAUNCHED_PREFERENCE__LAUNCHED_SETTINGS;
+                case LAUNCH_SOURCE_SUW:
+                    return STYLE_UICHANGED__LAUNCHED_PREFERENCE__LAUNCHED_SUW;
+                case LAUNCH_SOURCE_TIPS:
+                    return STYLE_UICHANGED__LAUNCHED_PREFERENCE__LAUNCHED_TIPS;
+                case LAUNCH_SOURCE_DEEP_LINK:
+                    return STYLE_UICHANGED__LAUNCHED_PREFERENCE__LAUNCHED_DEEP_LINK;
+                default:
+                    return STYLE_UICHANGED__LAUNCHED_PREFERENCE__LAUNCHED_PREFERENCE_UNSPECIFIED;
+            }
+        } else if (launchSource.getAction() != null && launchSource.getAction().equals(
+                WallpaperManager.ACTION_CROP_AND_SET_WALLPAPER)) {
+            return STYLE_UICHANGED__LAUNCHED_PREFERENCE__LAUNCHED_CROP_AND_SET_ACTION;
+        } else if (launchSource.getCategories() != null
+                && launchSource.getCategories().contains(Intent.CATEGORY_LAUNCHER)) {
+            return STYLE_UICHANGED__LAUNCHED_PREFERENCE__LAUNCHED_LAUNCH_ICON;
+        } else {
+            return STYLE_UICHANGED__LAUNCHED_PREFERENCE__LAUNCHED_PREFERENCE_UNSPECIFIED;
+        }
     }
 }
diff --git a/src/com/android/customization/picker/CustomizationPickerActivity.java b/src/com/android/customization/picker/CustomizationPickerActivity.java
index 786bebd..7736ee2 100644
--- a/src/com/android/customization/picker/CustomizationPickerActivity.java
+++ b/src/com/android/customization/picker/CustomizationPickerActivity.java
@@ -142,8 +142,10 @@
 
         Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
         if (fragment == null) {
-            // App launch specific logic: log the "app launched" event and set up daily logging.
-            mUserEventLogger.logAppLaunched();
+            // App launch specific logic: log the "app launch source" event.
+            if (getIntent() != null) {
+                mUserEventLogger.logAppLaunched(getIntent());
+            }
             WallpaperPreferences preferences = injector.getPreferences(this);
             preferences.incrementAppLaunched();
             DailyLoggingAlarmScheduler.setAlarm(getApplicationContext());
@@ -199,6 +201,11 @@
 
     private void skipToWallpaperPicker() {
         Intent intent = new Intent(this, TopLevelPickerActivity.class);
+
+        if (getIntent() != null && getIntent().getExtras() != null) {
+            intent.putExtras(getIntent().getExtras());
+        }
+
         if (DeepLinkUtils.isDeepLink(getIntent())) {
             intent.setData(getIntent().getData());
         }