Commit 28e7c592 authored by Anna Malova's avatar Anna Malova Committed by Commit Bot

Add ExternalAuthUtils resolver to AppHooksModule

Bug: 885099
Change-Id: If444f4cf341c83647bd126d2519ff8cedb8da621
Reviewed-on: https://chromium-review.googlesource.com/c/1340002
Commit-Queue: Anna Malova <amalova@chromium.org>
Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609117}
parent 808437f7
......@@ -5,6 +5,8 @@
package org.chromium.chrome.browser;
import org.chromium.chrome.browser.customtabs.CustomTabsConnection;
import org.chromium.chrome.browser.dependency_injection.ModuleFactoryOverrides;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import dagger.Module;
import dagger.Provides;
......@@ -15,8 +17,16 @@ import dagger.Provides;
*/
@Module
public class AppHooksModule {
/** See {@link ModuleFactoryOverrides} */
public interface Factory { AppHooksModule create(); }
@Provides
public static CustomTabsConnection provideCustomTabsConnection() {
return CustomTabsConnection.getInstance();
}
@Provides
public ExternalAuthUtils provideExternalAuthUtils() {
return ExternalAuthUtils.getInstance();
}
}
......@@ -223,6 +223,13 @@ public class ChromeApplication extends Application {
ModuleFactoryOverrides.getOverrideFor(ChromeAppModule.Factory.class);
ChromeAppModule module =
overriddenFactory == null ? new ChromeAppModule() : overriddenFactory.create();
return DaggerChromeAppComponent.builder().chromeAppModule(module).build();
AppHooksModule.Factory appHooksFactory =
ModuleFactoryOverrides.getOverrideFor(AppHooksModule.Factory.class);
AppHooksModule appHooksModule =
appHooksFactory == null ? new AppHooksModule() : appHooksFactory.create();
return DaggerChromeAppComponent.builder().chromeAppModule(module)
.appHooksModule(appHooksModule).build();
}
}
......@@ -323,7 +323,8 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent
return;
}
if (!ExternalAuthUtils.getInstance().isGoogleSigned(componentName.getPackageName())) {
ExternalAuthUtils authUtils = getComponent().getParent().resolveExternalAuthUtils();
if (!authUtils.isGoogleSigned(componentName.getPackageName())) {
Log.w(TAG, "The %s package is not Google-signed.", componentName.getPackageName());
ModuleMetrics.recordLoadResult(ModuleMetrics.LoadResult.NOT_GOOGLE_SIGNED);
return;
......
......@@ -15,6 +15,8 @@ import dagger.Subcomponent;
@Subcomponent(modules = {ChromeActivityCommonsModule.class, ContextualSuggestionsModule.class})
@ActivityScope
public interface ChromeActivityComponent {
ChromeAppComponent getParent();
// Temporary getters for DI migration process.
ContextualSuggestionsCoordinator resolveContextualSuggestionsCoordinator();
}
......@@ -9,6 +9,7 @@ import org.chromium.chrome.browser.contextual_suggestions.ContextualSuggestionsM
import org.chromium.chrome.browser.contextual_suggestions.EnabledStateMonitor;
import org.chromium.chrome.browser.customtabs.dependency_injection.CustomTabActivityComponent;
import org.chromium.chrome.browser.customtabs.dependency_injection.CustomTabActivityModule;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import javax.inject.Singleton;
......@@ -30,4 +31,6 @@ public interface ChromeAppComponent {
// Temporary getters for DI migration process. All of these getters
// should eventually be replaced with constructor injection.
EnabledStateMonitor resolveContextualSuggestionsEnabledStateMonitor();
ExternalAuthUtils resolveExternalAuthUtils();
}
......@@ -13,6 +13,7 @@ import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.test.InstrumentationRegistry;
import org.chromium.chrome.browser.AppHooksModule;
import org.chromium.chrome.browser.customtabs.dynamicmodule.BaseActivityDelegate;
import org.chromium.chrome.browser.customtabs.dynamicmodule.BaseModuleEntryPoint;
import org.chromium.chrome.browser.customtabs.dynamicmodule.IActivityDelegate;
......@@ -20,6 +21,7 @@ import org.chromium.chrome.browser.customtabs.dynamicmodule.IActivityHost;
import org.chromium.chrome.browser.customtabs.dynamicmodule.IModuleHost;
import org.chromium.chrome.browser.customtabs.dynamicmodule.IObjectWrapper;
import org.chromium.chrome.browser.document.ChromeLauncherActivity;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
/**
* Utility class that contains fake CCT dynamic module classes and convenience calls
......@@ -32,6 +34,22 @@ public class CustomTabsDynamicModuleTestUtils {
/* package */ final static ComponentName FAKE_MODULE_COMPONENT_NAME = new ComponentName(
FAKE_MODULE_PACKAGE_NAME, FAKE_MODULE_CLASS_NAME);
/**
* To load a fake module in tests we need to bypass a check if package name of module
* is Google-signed. This class overrides this check for testing.
*/
/* package */ static class AppHooksModuleForTest extends AppHooksModule {
@Override
public ExternalAuthUtils provideExternalAuthUtils() {
return new ExternalAuthUtils() {
@Override
public boolean isGoogleSigned(String packageName) {
return true;
}
};
}
}
/**
* This class is used to test CCT module loader.
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment