From 670d8ced196922101c5f6f9f9c402c150197eb50 Mon Sep 17 00:00:00 2001 From: tc214 <307301662@qq.com> Date: Tue, 10 Apr 2018 12:37:29 +0800 Subject: [PATCH] upload dir build --- build/android/AndroidManifest.xml | 20 +++++ .../java/org/chromium/build/BuildHooks.java | 50 +++++++++++ .../org/chromium/build/BuildHooksAndroid.java | 82 +++++++++++++++++++ .../chromium/build/BuildHooksAndroidImpl.java | 54 ++++++++++++ .../java/templates/BuildHooksConfig.template | 16 ++++ 5 files changed, 222 insertions(+) create mode 100644 build/android/AndroidManifest.xml create mode 100644 build/android/buildhooks/java/org/chromium/build/BuildHooks.java create mode 100644 build/android/buildhooks/java/org/chromium/build/BuildHooksAndroid.java create mode 100644 build/android/buildhooks/java/org/chromium/build/BuildHooksAndroidImpl.java create mode 100644 build/android/buildhooks/java/templates/BuildHooksConfig.template diff --git a/build/android/AndroidManifest.xml b/build/android/AndroidManifest.xml new file mode 100644 index 0000000..d02cc17 --- /dev/null +++ b/build/android/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + + + + diff --git a/build/android/buildhooks/java/org/chromium/build/BuildHooks.java b/build/android/buildhooks/java/org/chromium/build/BuildHooks.java new file mode 100644 index 0000000..7364898 --- /dev/null +++ b/build/android/buildhooks/java/org/chromium/build/BuildHooks.java @@ -0,0 +1,50 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.build; + +/** + * All Java targets that support android have dependence on this class. + */ +public abstract class BuildHooks { + /** + * Defines an interface for reporting assertion error. + */ + @FunctionalInterface + public interface ReportAssertionCallback { + void run(AssertionError arg); + } + + private static ReportAssertionCallback sReportAssertionCallback; + + /** + * This method is used to handle assert failures when asserts are enabled by + * //build/android/bytecode:java_bytecode_rewriter. For non-release builds, this is always + * enabled and assert failures will result in an assertion error being thrown. For release + * builds, this is only enabled when report_java_assert = true. Assert failures will result in + * an error report being uploaded to the crash servers only if the callback is set (so that this + * can be a no-op for WebView in Monochrome). This also means that asserts hit before the + * callback is set will be no-op's as well. + */ + public static void assertFailureHandler(AssertionError assertionError) { + if (BuildHooksConfig.REPORT_JAVA_ASSERT) { + if (sReportAssertionCallback != null) { + sReportAssertionCallback.run(assertionError); + } + } else { + throw assertionError; + } + } + + /** + * Set the callback function that handles assert failure. + * This should be called from attachBaseContext. + */ + public static void setReportAssertionCallback(ReportAssertionCallback callback) { + if (!BuildHooksConfig.REPORT_JAVA_ASSERT) { + throw new AssertionError(); + } + sReportAssertionCallback = callback; + } +} diff --git a/build/android/buildhooks/java/org/chromium/build/BuildHooksAndroid.java b/build/android/buildhooks/java/org/chromium/build/BuildHooksAndroid.java new file mode 100644 index 0000000..fdf0a86 --- /dev/null +++ b/build/android/buildhooks/java/org/chromium/build/BuildHooksAndroid.java @@ -0,0 +1,82 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.build; + +import android.content.Context; +import android.content.res.AssetManager; +import android.content.res.Resources; + +/** + * All Java targets that require android have dependence on this class. Add methods that do not + * require Android to {@link BuildHooks}. + * + * This class provides hooks needed when bytecode rewriting. Static convenience methods are used to + * minimize the amount of code required to be manually generated when bytecode rewriting. + * + * This class contains default implementations for all methods and is used when no other + * implementation is supplied to an android_apk target (via build_hooks_android_impl_deps). + */ +public abstract class BuildHooksAndroid { + private static final BuildHooksAndroidImpl sInstance = new BuildHooksAndroidImpl(); + + public static Resources getResources(Context context) { + return sInstance.getResourcesImpl(context); + } + + protected abstract Resources getResourcesImpl(Context context); + + public static AssetManager getAssets(Context context) { + return sInstance.getAssetsImpl(context); + } + + protected abstract AssetManager getAssetsImpl(Context context); + + public static Resources.Theme getTheme(Context context) { + return sInstance.getThemeImpl(context); + } + + protected abstract Resources.Theme getThemeImpl(Context context); + + public static void setTheme(Context context, int theme) { + sInstance.setThemeImpl(context, theme); + } + + protected abstract void setThemeImpl(Context context, int theme); + + public static Context createConfigurationContext(Context context) { + return sInstance.createConfigurationContextImpl(context); + } + + protected abstract Context createConfigurationContextImpl(Context context); + + public static int getIdentifier( + Resources resources, String name, String defType, String defPackage) { + return sInstance.getIdentifierImpl(resources, name, defType, defPackage); + } + + protected abstract int getIdentifierImpl( + Resources resources, String name, String defType, String defPackage); + + public static boolean isEnabled() { + return sInstance.isEnabledImpl(); + } + + protected abstract boolean isEnabledImpl(); + + public static void initCustomResources(Context context) { + sInstance.initCustomResourcesImpl(context); + } + + protected abstract void initCustomResourcesImpl(Context context); + + /** + * Record custom resources related UMA. Requires native library to be loaded. + */ + public static void maybeRecordResourceMetrics() { + sInstance.maybeRecordResourceMetricsImpl(); + } + + protected abstract void maybeRecordResourceMetricsImpl(); +} \ No newline at end of file diff --git a/build/android/buildhooks/java/org/chromium/build/BuildHooksAndroidImpl.java b/build/android/buildhooks/java/org/chromium/build/BuildHooksAndroidImpl.java new file mode 100644 index 0000000..5b9b997 --- /dev/null +++ b/build/android/buildhooks/java/org/chromium/build/BuildHooksAndroidImpl.java @@ -0,0 +1,54 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.build; + +import android.content.Context; +import android.content.res.AssetManager; +import android.content.res.Resources; + +/** + * Instantiatable version of {@link BuildHooksAndroid} with dummy implementations. + */ +public class BuildHooksAndroidImpl extends BuildHooksAndroid { + @Override + protected final Resources getResourcesImpl(Context context) { + return null; + } + + @Override + protected AssetManager getAssetsImpl(Context context) { + return null; + } + + @Override + protected Resources.Theme getThemeImpl(Context context) { + return null; + } + + @Override + protected void setThemeImpl(Context context, int theme) {} + + @Override + protected Context createConfigurationContextImpl(Context context) { + return null; + } + + @Override + protected int getIdentifierImpl( + Resources resources, String name, String defType, String defPackage) { + return resources.getIdentifier(name, defType, defPackage); + } + + @Override + protected boolean isEnabledImpl() { + return false; + } + + @Override + protected void initCustomResourcesImpl(Context context) {} + + @Override + protected void maybeRecordResourceMetricsImpl() {} +} diff --git a/build/android/buildhooks/java/templates/BuildHooksConfig.template b/build/android/buildhooks/java/templates/BuildHooksConfig.template new file mode 100644 index 0000000..bdaa550 --- /dev/null +++ b/build/android/buildhooks/java/templates/BuildHooksConfig.template @@ -0,0 +1,16 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.build; + +/** + * BuildHooks configuration. Generated on a per-target basis. + */ +public class BuildHooksConfig { +#if defined(_REPORT_JAVA_ASSERT) + public static final boolean REPORT_JAVA_ASSERT = true; +#else + public static final boolean REPORT_JAVA_ASSERT = false; +#endif +}