blob: 5b5c11effc217017931948a47d55a40a1a2791d0 [file] [log] [blame]
Santiago Etchebehereab639852019-02-26 10:42:44 -08001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.customization.module;
17
Chihhang Chuangeecf85e2021-06-14 13:48:57 +080018import static com.android.wallpaper.picker.CustomizationPickerActivity.WALLPAPER_FLAVOR_EXTRA;
19import static com.android.wallpaper.picker.CustomizationPickerActivity.WALLPAPER_FOCUS;
Chuck Liao4a777fb2020-08-15 04:15:46 +080020
Santiago Etchebehereab639852019-02-26 10:42:44 -080021import android.content.Context;
Chuck Liao4a777fb2020-08-15 04:15:46 +080022import android.content.Intent;
23import android.net.Uri;
Santiago Etchebehereab639852019-02-26 10:42:44 -080024
25import androidx.fragment.app.Fragment;
Santiago Etchebehere43b25182019-05-24 11:37:15 -070026import androidx.fragment.app.FragmentActivity;
Santiago Etchebehereab639852019-02-26 10:42:44 -080027
Santiago Etchebehere43b25182019-05-24 11:37:15 -070028import com.android.customization.model.theme.OverlayManagerCompat;
29import com.android.customization.model.theme.ThemeBundleProvider;
30import com.android.customization.model.theme.ThemeManager;
Santiago Etchebehereab639852019-02-26 10:42:44 -080031import com.android.wallpaper.model.CategoryProvider;
32import com.android.wallpaper.model.WallpaperInfo;
33import com.android.wallpaper.module.BaseWallpaperInjector;
34import com.android.wallpaper.module.DefaultCategoryProvider;
Chihhang Chuang1473ab02021-06-10 10:49:38 +080035import com.android.wallpaper.module.HubSections;
Santiago Etchebehereab639852019-02-26 10:42:44 -080036import com.android.wallpaper.module.LoggingOptInStatusProvider;
Santiago Etchebehereab639852019-02-26 10:42:44 -080037import com.android.wallpaper.module.WallpaperPreferences;
38import com.android.wallpaper.module.WallpaperRotationRefresher;
39import com.android.wallpaper.monitor.PerformanceMonitor;
Chihhang Chuangeecf85e2021-06-14 13:48:57 +080040import com.android.wallpaper.picker.CustomizationPickerActivity;
Santiago Etchebehere57778a22019-11-08 14:09:56 -080041import com.android.wallpaper.picker.PreviewFragment;
Santiago Etchebehereab639852019-02-26 10:42:44 -080042
43public class DefaultCustomizationInjector extends BaseWallpaperInjector
44 implements CustomizationInjector {
45 private CategoryProvider mCategoryProvider;
Santiago Etchebeheref64c5d02019-04-09 11:53:35 -030046 private ThemesUserEventLogger mUserEventLogger;
Santiago Etchebehereab639852019-02-26 10:42:44 -080047 private WallpaperRotationRefresher mWallpaperRotationRefresher;
48 private PerformanceMonitor mPerformanceMonitor;
49 private WallpaperPreferences mPrefs;
Chihhang Chuang1473ab02021-06-10 10:49:38 +080050 private HubSections mHubSections;
Santiago Etchebehereab639852019-02-26 10:42:44 -080051
52 @Override
53 public synchronized WallpaperPreferences getPreferences(Context context) {
54 if (mPrefs == null) {
55 mPrefs = new DefaultCustomizationPreferences(context.getApplicationContext());
56 }
57 return mPrefs;
58 }
59
Santiago Etchebehereab639852019-02-26 10:42:44 -080060 @Override
61 public CustomizationPreferences getCustomizationPreferences(Context context) {
62 return (CustomizationPreferences) getPreferences(context);
63 }
64
65 @Override
66 public synchronized CategoryProvider getCategoryProvider(Context context) {
67 if (mCategoryProvider == null) {
68 mCategoryProvider = new DefaultCategoryProvider(context.getApplicationContext());
69 }
70 return mCategoryProvider;
71 }
72
73 @Override
Santiago Etchebeheref64c5d02019-04-09 11:53:35 -030074 public synchronized ThemesUserEventLogger getUserEventLogger(Context context) {
Santiago Etchebehereab639852019-02-26 10:42:44 -080075 if (mUserEventLogger == null) {
Santiago Etchebeheref64c5d02019-04-09 11:53:35 -030076 mUserEventLogger = new StatsLogUserEventLogger();
Santiago Etchebehereab639852019-02-26 10:42:44 -080077 }
78 return mUserEventLogger;
79 }
80
81 @Override
82 public synchronized WallpaperRotationRefresher getWallpaperRotationRefresher() {
83 if (mWallpaperRotationRefresher == null) {
84 mWallpaperRotationRefresher = new WallpaperRotationRefresher() {
85 @Override
86 public void refreshWallpaper(Context context, Listener listener) {
87 // Not implemented
88 listener.onError();
89 }
90 };
91 }
92 return mWallpaperRotationRefresher;
93 }
94
95 @Override
96 public Fragment getPreviewFragment(
Clément Julliardfe839762019-05-02 07:13:56 -070097 Context context,
Santiago Etchebehereab639852019-02-26 10:42:44 -080098 WallpaperInfo wallpaperInfo,
99 int mode,
Ching-Sung Li3e5a8052020-06-06 12:10:46 +0800100 boolean viewAsHome,
Santiago Etchebehereab639852019-02-26 10:42:44 -0800101 boolean testingModeEnabled) {
chihhangchuang172211a2020-07-02 21:01:47 +0800102 return PreviewFragment.newInstance(wallpaperInfo, mode, viewAsHome, testingModeEnabled);
Santiago Etchebehereab639852019-02-26 10:42:44 -0800103 }
104
105 @Override
Chuck Liao4a777fb2020-08-15 04:15:46 +0800106 public Intent getDeepLinkRedirectIntent(Context context, Uri uri) {
107 Intent intent = new Intent();
108 intent.setClass(context, CustomizationPickerActivity.class);
109 intent.setData(uri);
110 intent.putExtra(WALLPAPER_FLAVOR_EXTRA, WALLPAPER_FOCUS);
111 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
112 return intent;
113 }
114
115 @Override
Chuck Liaodfff1de2020-12-22 23:18:47 +0800116 public String getDownloadableIntentAction() {
117 return null;
118 }
119
120 @Override
Santiago Etchebehereab639852019-02-26 10:42:44 -0800121 public synchronized PerformanceMonitor getPerformanceMonitor() {
122 if (mPerformanceMonitor == null) {
123 mPerformanceMonitor = new PerformanceMonitor() {
124 @Override
125 public void recordFullResPreviewLoadedMemorySnapshot() {
126 // No Op
127 }
128 };
129 }
130 return mPerformanceMonitor;
131 }
132
133 @Override
134 public synchronized LoggingOptInStatusProvider getLoggingOptInStatusProvider(Context context) {
135 return null;
136 }
137
Santiago Etchebehere43b25182019-05-24 11:37:15 -0700138 @Override
139 public ThemeManager getThemeManager(ThemeBundleProvider provider, FragmentActivity activity,
Santiago Etchebehere1754f332020-04-09 19:17:19 -0700140 OverlayManagerCompat overlayManagerCompat, ThemesUserEventLogger logger) {
141 return new ThemeManager(provider, activity, overlayManagerCompat, logger);
Santiago Etchebehere43b25182019-05-24 11:37:15 -0700142 }
143
Chihhang Chuang1473ab02021-06-10 10:49:38 +0800144 @Override
145 public HubSections getHubSections() {
146 if (mHubSections == null) {
147 mHubSections = new DefaultCustomizationSections();
148 }
149 return mHubSections;
150 }
Santiago Etchebehereab639852019-02-26 10:42:44 -0800151}