Skip to content

Commit

Permalink
[WIP]To work with Kimono build
Browse files Browse the repository at this point in the history
This likely will not be merged, just a reference for build-time JNI replacement.
  • Loading branch information
johnxwork committed Jan 6, 2025
1 parent 8577a94 commit 1274167
Show file tree
Hide file tree
Showing 27 changed files with 298 additions and 161 deletions.
18 changes: 15 additions & 3 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,19 @@ deps = {
'packages': [
{
'package': 'chromium/third_party/jdk',
'version': '2Of9Pe_OdO4xoAATuiLDiMVNebKTNO3WrwJGqil4RosC',
'version': 'U-h0kbYoIUjL__n_sfiudzFLH7-C9vKVsLSOA2XHkBEC',
},
],
# Needed on Linux for use on chromium_presubmit (for checkstyle).
'condition': 'checkout_android or checkout_linux',
'dep_type': 'cipd',
},

'src/third_party/jdk/current': {
'packages': [
{
'package': 'chromium/third_party/jdk',
'version': 'U-h0kbYoIUjL__n_sfiudzFLH7-C9vKVsLSOA2XHkBEC',
},
],
# Needed on Linux for use on chromium_presubmit (for checkstyle).
Expand Down Expand Up @@ -1735,7 +1747,7 @@ deps = {
'packages': [
{
'package': 'chromium/third_party/r8',
'version': 'iFuVaazPwWVf3lFPwZbgAKcF-mHQhFetogi2J9b5ktYC',
'version': 'lrcfrwv2WpEoHAk051sZiwXxKxnNIUTYYEwM3oBDlhMC',
},
],
'condition': 'checkout_android',
Expand All @@ -1749,7 +1761,7 @@ deps = {
'packages': [
{
'package': 'chromium/third_party/r8',
'version': 'PwglNZFRNPkBBXdnY9NfrZFk2ULWDTRxhV9rl2kvkpUC',
'version': 'zh70w_Qc37LtNjNFZAOnZVT6jxYseh_1UEkt_lwbRuQC',
},
],
'condition': 'checkout_android',
Expand Down
1 change: 1 addition & 0 deletions base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4104,6 +4104,7 @@ if (enable_nocompile_tests) {

if (is_android || is_robolectric) {
generate_jni("base_jni_headers") {
jni_prefix = "cobalt"
sources = [
"android/java/src/org/chromium/base/ApkAssets.java",
"android/java/src/org/chromium/base/ApplicationStatus.java",
Expand Down
1 change: 1 addition & 0 deletions base/android/java/src/org/chromium/base/ApkAssets.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class ApkAssets {

@CalledByNative
public static long[] open(String fileName, String splitName) {
Log.e(LOGTAG, "here in ApkAssets_open "+fileName+", "+splitName);
AssetFileDescriptor afd = null;
try {
Context context = ContextUtils.getApplicationContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ public SourceVersion getSupportedSourceVersion() {
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
if (processingEnv.getOptions().containsKey(PACKAGE_PREFIX_OPTION)) {
// if (processingEnv.getOptions().containsKey(PACKAGE_PREFIX_OPTION)) {
mGenJniClassName = ClassName.get(
String.format("%s.%s", processingEnv.getOptions().get(PACKAGE_PREFIX_OPTION),
String.format("%s.%s", "cobalt",
mGenJniClassName.packageName()),
mGenJniClassName.simpleName());
}
// }
}

/**
Expand Down Expand Up @@ -236,7 +236,7 @@ String getNativeMethodName(String packageName, String className, String oldMetho
// e.g. org.chromium.base.Foo_Class.bar
// => org_chromium_base_Foo_1Class_bar()
final String packagePrefix =
processingEnv.getOptions().getOrDefault(PACKAGE_PREFIX_OPTION, "");
processingEnv.getOptions().getOrDefault(PACKAGE_PREFIX_OPTION, "cobalt");
return (packagePrefix.length() > 0
? String.format(
"%s.%s.%s.%s", packagePrefix, packageName, className, oldMethodName)
Expand Down
8 changes: 6 additions & 2 deletions base/android/jni_generator/jni_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,10 @@ def JavaToJni(self, param):
'Inner class (%s) can not be imported '
'and used by JNI (%s). Please import the outer '
'class and use Outer.Inner instead.' % (qualified_name, param))
return prefix + qualified_name + ';'
ret = prefix + qualified_name + ';'
ret = ret.replace('Lorg', 'Lcobalt/org')
print(ret)
return ret

# Is it an inner class from an outer class import? (e.g. referencing
# Class.Inner from import pkg.Class).
Expand Down Expand Up @@ -1551,7 +1554,7 @@ def GenerateJNIHeader(input_file, output_file, options):
# The current package-prefix implementation does not support adding
# prefix to java compiled classes. The current support is only for
# java source files.
assert not options.package_prefix
options.package_prefix = None
jni_from_javap = JNIFromJavaP.CreateFromClass(input_file, options)
content = jni_from_javap.GetContent()
else:
Expand Down Expand Up @@ -1685,6 +1688,7 @@ def main():
parser.add_argument('--stamp',
help='Process --prev_output_dir and touch this file.')
args = parser.parse_args()
args.package_prefix = 'cobalt'
# Kotlin files are not supported by jni_generator.py, but they do end up in
# the list of source files passed to jni_generator.py.
input_files = [f for f in args.input_files if not f.endswith('.kt')]
Expand Down
1 change: 1 addition & 0 deletions base/android/jni_generator/jni_registration_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@ def main(argv):
'Adds a prefix to the classes fully qualified-name. Effectively changing a class name from'
'foo.bar -> prefix.foo.bar')
args = arg_parser.parse_args(build_utils.ExpandFileArgs(argv[1:]))
args.package_prefix = 'cobalt'

if not args.enable_proxy_mocks and args.require_mocks:
arg_parser.error(
Expand Down
3 changes: 2 additions & 1 deletion build/config/android/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ if (is_android || is_chromeos) {
enable_incremental_d8 = true

# Use hashed symbol names to reduce JNI symbol overhead.
use_hashed_jni_names = !is_java_debug
# Cobalt avoids hash names to facilitate Kimono build.
use_hashed_jni_names = false

# Enables JNI multiplexing to reduce JNI native methods overhead.
allow_jni_multiplexing = false
Expand Down
8 changes: 8 additions & 0 deletions build/config/android/rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ if (enable_java_templates) {
args += [ "--split_name=${invoker.split_name}" ]
}

if (defined(invoker.jni_prefix)) {
args += ["--package_prefix=${invoker.jni_prefix}" ]
}

outputs = []
foreach(_name, _input_names) {
_name = get_path_info(_name, "name") + "_jni.h"
Expand Down Expand Up @@ -431,6 +435,10 @@ if (enable_java_templates && is_android) {
args += [ "--use-proxy-hash" ]
}

#if (defined(invoker.jni_prefix)) {
# args += ["--package_prefix=${invoker.jni_prefix}" ]
#}

if (defined(invoker.enable_native_mocks) && invoker.enable_native_mocks) {
args += [ "--enable-proxy-mocks" ]

Expand Down
5 changes: 4 additions & 1 deletion cobalt/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ android_resources("cobalt_java_resources") {
"apk/app/src/app/res/mipmap-xxhdpi/ic_app.png",
"apk/app/src/app/res/values/strings.xml",
"apk/app/src/main/res/layout/coat_error_dialog.xml",
"apk/app/src/main/res/layout/content_shell_activity.xml",
"apk/app/src/main/res/layout/shell_view.xml",
"apk/app/src/main/res/values/colors.xml",
"apk/app/src/main/res/values/ids.xml",
"apk/app/src/main/res/values/overlayable.xml",
Expand Down Expand Up @@ -44,7 +46,8 @@ android_library("cobalt_apk_java") {
"//components/embedder_support/android:view_java",
"//content/public/android:content_java",
"//content/shell/android:content_shell_apk_java",
"//content/shell/android:content_shell_apk_resources",

#"//content/shell/android:content_shell_apk_resources",
"//content/shell/android:content_shell_java",
"//content/shell/android:content_shell_manifest",
"//media/capture/video/android:capture_java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@
import android.app.Application;
import android.content.Context;
import dev.cobalt.coat.StarboardBridge;

import org.chromium.content_shell_apk.ContentShellApplication;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils;
import org.chromium.base.PathUtils;
import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.ui.base.ResourceBundle;

/** Android Application hosting the Starboard application. */
public class CobaltApplication extends ContentShellApplication implements StarboardBridge.HostApplication {
public class CobaltApplication extends Application implements StarboardBridge.HostApplication {
private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "content_shell";

StarboardBridge starboardBridge;

@Override
Expand All @@ -33,4 +40,19 @@ public void setStarboardBridge(StarboardBridge starboardBridge) {
public StarboardBridge getStarboardBridge() {
return starboardBridge;
}

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
boolean isBrowserProcess = !ContextUtils.getProcessName().contains(":");
ContextUtils.initApplicationContext(this);
ResourceBundle.setNoAvailableLocalePaks();
LibraryLoader.getInstance().setLibraryProcessType(isBrowserProcess
? LibraryProcessType.PROCESS_BROWSER
: LibraryProcessType.PROCESS_CHILD);
if (isBrowserProcess) {
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
ApplicationStatus.initialize(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public abstract class CobaltActivity extends Activity {

private static final String ACTIVE_SHELL_URL_KEY = "activeUrl";
public static final String COMMAND_LINE_ARGS_KEY = "commandLineArgs";
public static final String COMMAND_LINE_FILE = "/data/local/tmp/content-shell-command-line";

private static final Pattern URL_PARAM_PATTERN = Pattern.compile("^[a-zA-Z0-9_=]*$");

Expand All @@ -102,7 +103,7 @@ public abstract class CobaltActivity extends Activity {
protected void createContent(final Bundle savedInstanceState) {
// Initializing the command line must occur before loading the library.
if (!CommandLine.isInitialized()) {
((CobaltApplication) getApplication()).initCommandLine();
CommandLine.initFromFile(COMMAND_LINE_FILE);

// Note that appendSwitchesAndArguments excludes cobaltCommandLineParams[0]
// as the program name, and all other arguments SHOULD start with '--'.
Expand Down Expand Up @@ -231,7 +232,7 @@ private void finishInitialization(Bundle savedInstanceState) {
mShellManager.getContentViewRenderView().setOverlayVideoMode(true);
mShellManager.launchShell(shellUrl);

toggleFullscreenMode(true);
// toggleFullscreenMode(true);
}

// Initially copied from ContentShellActiviy.java
Expand Down Expand Up @@ -287,10 +288,10 @@ protected void shellHandleIntent(Intent intent) {
}
}

protected void toggleFullscreenMode(boolean enterFullscreen) {
LinearLayout toolBar = (LinearLayout) findViewById(R.id.toolbar);
toolBar.setVisibility(enterFullscreen ? View.GONE : View.VISIBLE);
}
// protected void toggleFullscreenMode(boolean enterFullscreen) {
// LinearLayout toolBar = (LinearLayout) findViewById(R.id.toolbar);
// toolBar.setVisibility(enterFullscreen ? View.GONE : View.VISIBLE);
// }

// Initially copied from ContentShellActiviy.java
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
Copyright 2012 The Chromium Authors
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<merge xmlns:android="http://schemas.android.com/apk/res/android">
<cobalt.org.chromium.content_shell.ShellManager
android:id="@+id/shell_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</merge>
55 changes: 55 additions & 0 deletions cobalt/android/apk/app/src/main/res/layout/shell_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
Copyright 2012 The Chromium Authors
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<cobalt.org.chromium.content_shell.Shell
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/progress">
<ImageButton android:id="@+id/stop_reload_button"
android:layout_width="38dp"
android:layout_height="38dp"
android:src="@android:drawable/ic_menu_close_clear_cancel"
android:scaleType="centerCrop"
tools:ignore="ContentDescription" />
<EditText android:id="@+id/url"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="bottom"
android:textSize="18sp"
android:singleLine="true"
android:selectAllOnFocus="true"
android:hint="@string/url_hint"
android:inputType="textUri"
android:imeOptions="actionGo" />
<ImageButton android:id="@+id/prev"
android:layout_width="38dp"
android:layout_height="38dp"
android:src="@android:drawable/ic_media_previous"
android:scaleType="center"
tools:ignore="ContentDescription" />
<ImageButton android:id="@+id/next"
android:layout_width="38dp"
android:layout_height="38dp"
android:src="@android:drawable/ic_media_next"
android:scaleType="center"
tools:ignore="ContentDescription" />
</LinearLayout>
<FrameLayout android:id="@+id/contentview_holder"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</cobalt.org.chromium.content_shell.Shell>
47 changes: 20 additions & 27 deletions cobalt/android/apk/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2016 The Cobalt Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
<!--
Copyright 2012 The Chromium Authors
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<resources>
<!-- Error message when there's a problem connecting to the network. -->
<string name="starboard_platform_connection_error">Can\'t connect right now</string>
<!-- Button label on network connection error to retry the request. -->
<string name="starboard_platform_retry">Try again</string>
<!-- Button label on network connection error to open system network settings. -->
<string name="starboard_platform_network_settings">Open network settings</string>
<!-- Toast message when we can't get the device account to sign in. -->
<string name="starboard_account_picker_error">Account not available.</string>
<!-- Toast message when we the account can't be authorized. -->
<string name="starboard_account_auth_error">Account authorization failed.</string>
<!-- Toast message indicating that the selected account is no longer available to sign-in. -->
<string name="starboard_missing_account">Account not available:\n%1$s</string>
<!-- Toast message shown when the user has denied permission to get device accounts. -->
<string name="starboard_accounts_permission">Sign in requires Contacts permission to be granted in system settings.</string>
<string name="url_hint">Type URL Here</string>
<string name="browser_process_initialization_failed">Initialization failed.</string>
<!-- Error message when there's a problem connecting to the network. -->
<string name="starboard_platform_connection_error">Can\'t connect right now</string>
<!-- Button label on network connection error to retry the request. -->
<string name="starboard_platform_retry">Try again</string>
<!-- Button label on network connection error to open system network settings. -->
<string name="starboard_platform_network_settings">Open network settings</string>
<!-- Toast message when we can't get the device account to sign in. -->
<string name="starboard_account_picker_error">Account not available.</string>
<!-- Toast message when we the account can't be authorized. -->
<string name="starboard_account_auth_error">Account authorization failed.</string>
<!-- Toast message indicating that the selected account is no longer available to sign-in. -->
<string name="starboard_missing_account">Account not available:\n%1$s</string>
<!-- Toast message shown when the user has denied permission to get device accounts. -->
<string name="starboard_accounts_permission">Sign in requires Contacts permission to be granted in system settings.</string>
</resources>
3 changes: 3 additions & 0 deletions cobalt/build/configs/android_common.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import("//cobalt/build/configs/common.gn")
# This flag comes from build/config/compiler/compiler.gni
# TODO(b/380339614): Remove this flag after resolving build errors.
treat_warnings_as_errors = false
# hashed jni names make build artifact opaque for Kimono build.
use_hashed_jni_names = false
use_errorprone_java_compiler = false

# Overriding flag from //media/media_options.gni.
# Cobalt doesn't use //third_party/ffmpeg.
Expand Down
2 changes: 1 addition & 1 deletion cobalt/build/gn.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def write_build_args(build_args_path, original_lines, dict_settings,
if os.getenv('IS_CI', default='0') == '1':
f.write(f'cc_wrapper = "{CC_WRAPPER}" {gen_comment}\n')
else:
f.write(f'use_remoteexec = true {gen_comment}\n')
f.write(f'use_remoteexec = false {gen_comment}\n')
f.write(f'build_type = "{build_type}" {gen_comment}\n')
for key, value in _BUILD_TYPES[build_type].items():
f.write(f'{key} = {value} {gen_comment}\n')
Expand Down
Loading

0 comments on commit 1274167

Please sign in to comment.