Support App Links

Video: https://drive.google.com/file/d/11_MclDVE8Q_ojSYoCDxmK4Ah_FoABPhd/view?usp=sharing

Bug: 163019082
Change-Id: I1aa6ca4e58aff3ad1a9067ff44fb398b1336770b
diff --git a/src/com/android/customization/module/DefaultCustomizationInjector.java b/src/com/android/customization/module/DefaultCustomizationInjector.java
index e18cb2d..b8cdc6d 100644
--- a/src/com/android/customization/module/DefaultCustomizationInjector.java
+++ b/src/com/android/customization/module/DefaultCustomizationInjector.java
@@ -15,7 +15,12 @@
  */
 package com.android.customization.module;
 
+import static com.android.customization.picker.CustomizationPickerActivity.WALLPAPER_FLAVOR_EXTRA;
+import static com.android.customization.picker.CustomizationPickerActivity.WALLPAPER_FOCUS;
+
 import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
 
 import androidx.fragment.app.Fragment;
 import androidx.fragment.app.FragmentActivity;
@@ -23,6 +28,7 @@
 import com.android.customization.model.theme.OverlayManagerCompat;
 import com.android.customization.model.theme.ThemeBundleProvider;
 import com.android.customization.model.theme.ThemeManager;
+import com.android.customization.picker.CustomizationPickerActivity;
 import com.android.wallpaper.model.CategoryProvider;
 import com.android.wallpaper.model.WallpaperInfo;
 import com.android.wallpaper.module.BaseWallpaperInjector;
@@ -95,6 +101,16 @@
     }
 
     @Override
+    public Intent getDeepLinkRedirectIntent(Context context, Uri uri) {
+        Intent intent = new Intent();
+        intent.setClass(context, CustomizationPickerActivity.class);
+        intent.setData(uri);
+        intent.putExtra(WALLPAPER_FLAVOR_EXTRA, WALLPAPER_FOCUS);
+        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+        return intent;
+    }
+
+    @Override
     public synchronized PerformanceMonitor getPerformanceMonitor() {
         if (mPerformanceMonitor == null) {
             mPerformanceMonitor = new PerformanceMonitor() {
diff --git a/src/com/android/customization/picker/CustomizationPickerActivity.java b/src/com/android/customization/picker/CustomizationPickerActivity.java
index 240f879..382a63c 100644
--- a/src/com/android/customization/picker/CustomizationPickerActivity.java
+++ b/src/com/android/customization/picker/CustomizationPickerActivity.java
@@ -75,6 +75,7 @@
 import com.android.wallpaper.picker.TopLevelPickerActivity;
 import com.android.wallpaper.picker.WallpaperPickerDelegate;
 import com.android.wallpaper.picker.WallpapersUiContainer;
+import com.android.wallpaper.util.DeepLinkUtils;
 import com.android.wallpaper.widget.BottomActionBar;
 import com.android.wallpaper.widget.BottomActionBar.BottomActionBarHost;
 
@@ -91,10 +92,10 @@
         CategoryFragmentHost, ThemeFragmentHost, GridFragmentHost, ClockFragmentHost,
         BottomActionBarHost {
 
-    private static final String TAG = "CustomizationPickerActivity";
-    @VisibleForTesting static final String WALLPAPER_FLAVOR_EXTRA =
+    public static final String WALLPAPER_FLAVOR_EXTRA =
             "com.android.launcher3.WALLPAPER_FLAVOR";
-    @VisibleForTesting static final String WALLPAPER_FOCUS = "focus_wallpaper";
+    public static final String WALLPAPER_FOCUS = "focus_wallpaper";
+    private static final String TAG = "CustomizationPickerActivity";
     @VisibleForTesting static final String WALLPAPER_ONLY = "wallpaper_only";
 
     private WallpaperPickerDelegate mDelegate;
@@ -105,15 +106,12 @@
     private CategoryFragment mWallpaperCategoryFragment;
     private BottomActionBar mBottomActionBar;
 
-    private boolean mWallpaperCategoryInitialized;
-
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         Injector injector = InjectorProvider.getInjector();
         mDelegate = new WallpaperPickerDelegate(this, this, injector);
         mUserEventLogger = injector.getUserEventLogger(this);
         initSections();
-        mWallpaperCategoryInitialized = false;
 
         // Restore this Activity's state before restoring contained Fragments state.
         super.onCreate(savedInstanceState);
@@ -190,6 +188,9 @@
 
     private void skipToWallpaperPicker() {
         Intent intent = new Intent(this, TopLevelPickerActivity.class);
+        if (DeepLinkUtils.isDeepLink(getIntent())) {
+            intent.setData(getIntent().getData());
+        }
         startActivity(intent);
         finish();
     }
@@ -372,6 +373,11 @@
     }
 
     @Override
+    public void fetchCategories() {
+        mDelegate.initialize(!mDelegate.getCategoryProvider().isCategoriesFetched());
+    }
+
+    @Override
     public void onWallpapersReady() {
 
     }
@@ -471,7 +477,6 @@
      * {@link CustomizationSection} corresponding to the "Wallpaper" section of the Picker.
      */
     private class WallpaperSection extends CustomizationSection {
-        private boolean mForceCategoryRefresh;
 
         private WallpaperSection(int id) {
             super(id, null);
@@ -482,18 +487,9 @@
             if (mWallpaperCategoryFragment == null) {
                 mWallpaperCategoryFragment = CategoryFragment.newInstance(
                         getString(R.string.wallpaper_title));
-                mForceCategoryRefresh = true;
             }
             return mWallpaperCategoryFragment;
         }
-
-        @Override
-        void onVisible() {
-            if (!mWallpaperCategoryInitialized) {
-                mDelegate.initialize(mForceCategoryRefresh);
-            }
-            mWallpaperCategoryInitialized = true;
-        }
     }
 
     private class ThemeSection extends CustomizationSection<ThemeBundle> {
diff --git a/src_override/com/android/wallpaper/module/WallpapersInjector.java b/src_override/com/android/wallpaper/module/WallpapersInjector.java
index b9a6952..d113c1b 100755
--- a/src_override/com/android/wallpaper/module/WallpapersInjector.java
+++ b/src_override/com/android/wallpaper/module/WallpapersInjector.java
@@ -16,6 +16,8 @@
 package com.android.wallpaper.module;
 
 import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
 
 import androidx.fragment.app.Fragment;
 
@@ -23,6 +25,7 @@
 import com.android.wallpaper.model.WallpaperInfo;
 import com.android.wallpaper.monitor.PerformanceMonitor;
 import com.android.wallpaper.picker.ImagePreviewFragment;
+import com.android.wallpaper.picker.TopLevelPickerActivity;
 
 /**
  * A concrete, real implementation of the dependency provider.
@@ -75,6 +78,15 @@
     }
 
     @Override
+    public Intent getDeepLinkRedirectIntent(Context context, Uri uri) {
+        Intent intent = new Intent();
+        intent.setClass(context, TopLevelPickerActivity.class);
+        intent.setData(uri);
+        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+        return intent;
+    }
+
+    @Override
     public synchronized PerformanceMonitor getPerformanceMonitor() {
         if (mPerformanceMonitor == null) {
             mPerformanceMonitor = new PerformanceMonitor() {