-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright (c) 2012 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. | ||
--> | ||
|
||
<!-- | ||
This is a dummy manifest which is required by: | ||
1. aapt when generating R.java in java.gypi: | ||
Nothing in the manifest is used, but it is still required by aapt. | ||
2. lint: [min|target]SdkVersion are required by lint and should | ||
be kept up to date. | ||
--> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="org.dummy"> | ||
|
||
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="24" /> | ||
|
||
</manifest> |
50 changes: 50 additions & 0 deletions
50
build/android/buildhooks/java/org/chromium/build/BuildHooks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
build/android/buildhooks/java/org/chromium/build/BuildHooksAndroid.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
54 changes: 54 additions & 0 deletions
54
build/android/buildhooks/java/org/chromium/build/BuildHooksAndroidImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} | ||
} |
16 changes: 16 additions & 0 deletions
16
build/android/buildhooks/java/templates/BuildHooksConfig.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |