/
AppHooks.java
301 lines (261 loc) · 10.3 KB
/
AppHooks.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import org.chromium.base.ContextUtils;
import org.chromium.base.PackageUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.customtabs.CustomTabsConnection;
import org.chromium.chrome.browser.directactions.DirectActionCoordinator;
import org.chromium.chrome.browser.feedback.FeedbackReporter;
import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncher;
import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncherImpl;
import org.chromium.chrome.browser.gsa.GSAHelper;
import org.chromium.chrome.browser.historyreport.AppIndexingReporter;
import org.chromium.chrome.browser.init.ChromeStartupDelegate;
import org.chromium.chrome.browser.init.ProcessInitializationHandler;
import org.chromium.chrome.browser.instantapps.InstantAppsHandler;
import org.chromium.chrome.browser.metrics.VariationsSession;
import org.chromium.chrome.browser.notifications.chime.ChimeDelegate;
import org.chromium.chrome.browser.omaha.RequestGenerator;
import org.chromium.chrome.browser.partnerbookmarks.PartnerBookmark;
import org.chromium.chrome.browser.partnerbookmarks.PartnerBookmarksProviderIterator;
import org.chromium.chrome.browser.password_manager.GooglePasswordManagerUIProvider;
import org.chromium.chrome.browser.policy.PolicyAuditor;
import org.chromium.chrome.browser.rlz.RevenueStats;
import org.chromium.chrome.browser.survey.SurveyController;
import org.chromium.chrome.browser.sync.TrustedVaultClient;
import org.chromium.chrome.browser.ui.signin.GoogleActivityController;
import org.chromium.chrome.browser.usage_stats.DigitalWellbeingClient;
import org.chromium.chrome.browser.webapps.GooglePlayWebApkInstallDelegate;
import org.chromium.chrome.browser.xsurface.ProcessScope;
import org.chromium.chrome.browser.xsurface.ProcessScopeDependencyProvider;
import org.chromium.chrome.modules.image_editor.ImageEditorModuleProvider;
import org.chromium.components.policy.AppRestrictionsProvider;
import org.chromium.components.policy.CombinedPolicyProvider;
import org.chromium.components.signin.AccountManagerDelegate;
import org.chromium.components.signin.SystemAccountManagerDelegate;
import org.chromium.components.webapps.AppDetailsDelegate;
import java.util.Collections;
import java.util.List;
/**
* Base class for defining methods where different behavior is required by downstream targets.
* The correct version of {@link AppHooksImpl} will be determined at compile time via build rules.
* See http://crbug/560466.
*
* Note that new functionality should not be added to AppHooks. Instead the delegate pattern in
* go/apphooks-migration should be followed to solve this class of problems.
*/
public abstract class AppHooks {
private static AppHooksImpl sInstance;
/**
* Sets a mocked instance for testing.
*/
@VisibleForTesting
public static void setInstanceForTesting(AppHooksImpl instance) {
sInstance = instance;
}
@CalledByNative
public static AppHooks get() {
if (sInstance == null) sInstance = new AppHooksImpl();
return sInstance;
}
/**
* Creates a new {@link AccountManagerDelegate}.
* @return the created {@link AccountManagerDelegate}.
*/
public AccountManagerDelegate createAccountManagerDelegate() {
return new SystemAccountManagerDelegate();
}
/**
* @return An instance of AppDetailsDelegate that can be queried about app information for the
* App Banner feature. Will be null if one is unavailable.
*/
public AppDetailsDelegate createAppDetailsDelegate() {
return null;
}
/**
* Creates a new {@link AppIndexingReporter}.
* @return the created {@link AppIndexingReporter}.
*/
public AppIndexingReporter createAppIndexingReporter() {
return new AppIndexingReporter();
}
/**
* @return An instance of {@link CustomTabsConnection}. Should not be called
* outside of {@link CustomTabsConnection#getInstance()}.
*/
public CustomTabsConnection createCustomTabsConnection() {
return new CustomTabsConnection();
}
/**
* Returns a new {@link DirectActionCoordinator} instance, if available.
*/
@Nullable
public DirectActionCoordinator createDirectActionCoordinator() {
return null;
}
/**
* Creates a new {@link SurveyController}.
* @return The created {@link SurveyController}.
*/
public SurveyController createSurveyController() {
return new SurveyController();
}
/**
* @return An instance of {@link FeedbackReporter} to report feedback.
*/
public FeedbackReporter createFeedbackReporter() {
return new FeedbackReporter() {};
}
/**
* @return An instance of GoogleActivityController.
*/
public GoogleActivityController createGoogleActivityController() {
return new GoogleActivityController();
}
/**
* @return An instance of {@link GSAHelper} that handles the start point of chrome's integration
* with GSA.
*/
public GSAHelper createGsaHelper() {
return new GSAHelper();
}
/**
* Returns a new instance of HelpAndFeedbackLauncher.
*/
public HelpAndFeedbackLauncher createHelpAndFeedbackLauncher() {
return new HelpAndFeedbackLauncherImpl();
}
public InstantAppsHandler createInstantAppsHandler() {
return new InstantAppsHandler();
}
/**
* @return An instance of {@link GooglePasswordManagerUIProvider}. Will be null if one is not
* available.
*/
public GooglePasswordManagerUIProvider createGooglePasswordManagerUIProvider() {
return null;
}
/**
* @return An instance of RequestGenerator to be used for Omaha XML creation. Will be null if
* a generator is unavailable.
*/
public RequestGenerator createOmahaRequestGenerator() {
return null;
}
/**
* @return a new {@link ProcessInitializationHandler} instance.
*/
public ProcessInitializationHandler createProcessInitializationHandler() {
return new ProcessInitializationHandler();
}
/**
* @return An instance of RevenueStats to be installed as a singleton.
*/
public RevenueStats createRevenueStatsInstance() {
return new RevenueStats();
}
/**
* Returns a new instance of VariationsSession.
*/
public VariationsSession createVariationsSession() {
return new VariationsSession();
}
/** Returns the singleton instance of GooglePlayWebApkInstallDelegate. */
public GooglePlayWebApkInstallDelegate getGooglePlayWebApkInstallDelegate() {
return null;
}
/**
* @return An instance of PolicyAuditor that notifies the policy system of the user's activity.
* Only applicable when the user has a policy active, that is tracking the activity.
*/
public PolicyAuditor getPolicyAuditor() {
return null;
}
public void registerPolicyProviders(CombinedPolicyProvider combinedProvider) {
combinedProvider.registerProvider(
new AppRestrictionsProvider(ContextUtils.getApplicationContext()));
}
/**
* @return A list of allowlisted app package names whose completed notifications
* we should suppress.
*/
public List<String> getOfflinePagesSuppressNotificationPackages() {
return Collections.emptyList();
}
/**
* @return An iterator of partner bookmarks.
*/
@Nullable
public PartnerBookmark.BookmarkIterator getPartnerBookmarkIterator() {
return PartnerBookmarksProviderIterator.createIfAvailable();
}
/**
* @return A new {@link DigitalWellbeingClient} instance.
*/
public DigitalWellbeingClient createDigitalWellbeingClient() {
return new DigitalWellbeingClient();
}
/**
* Checks the Google Play services availability on the this device.
*
* This is a workaround for the
* versioned API of {@link GoogleApiAvailability#isGooglePlayServicesAvailable()}. The current
* Google Play services SDK version doesn't have this API yet.
*
* TODO(zqzhang): Remove this method after the SDK is updated.
*
* @return status code indicating whether there was an error. The possible return values are the
* same as {@link GoogleApiAvailability#isGooglePlayServicesAvailable()}.
*/
public int isGoogleApiAvailableWithMinApkVersion(int minApkVersion) {
int apkVersion =
PackageUtils.getPackageVersion(GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE);
return apkVersion < 0 ? ConnectionResult.SERVICE_MISSING
: apkVersion < minApkVersion ? ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED
: ConnectionResult.SUCCESS;
}
/**
* Returns a new {@link TrustedVaultClient.Backend} instance.
*/
public TrustedVaultClient.Backend createSyncTrustedVaultClientBackend() {
return new TrustedVaultClient.EmptyBackend();
}
/**
* This is deprecated, and should not be called. Use FeedHooks instead.
*/
public @Nullable ProcessScope getExternalSurfaceProcessScope(
ProcessScopeDependencyProvider dependencies) {
return null;
}
/**
* Returns the URL to the WebAPK creation/update server.
*/
public String getWebApkServerUrl() {
return "";
}
/**
* Returns a Chime Delegate if the chime module is defined.
*/
public ChimeDelegate getChimeDelegate() {
return new ChimeDelegate();
}
public @Nullable ImageEditorModuleProvider getImageEditorModuleProvider() {
return null;
}
public ChromeStartupDelegate createChromeStartupDelegate() {
return new ChromeStartupDelegate();
}
public boolean canStartForegroundServiceWhileInvisible() {
return true;
}
public String getDefaultQueryTilesServerUrl() {
return "";
}
// Stop! Do not add new methods to AppHooks anymore. Follow go/apphooks-migration instead.
}