From 26e69c7f1753176fd9f468aea161d5800ca0672c Mon Sep 17 00:00:00 2001 From: Hao <131711973+haozheng-cobalt@users.noreply.github.com> Date: Tue, 17 Dec 2024 16:54:58 -0800 Subject: [PATCH] Revert "Create StarboardBridge native class with jni_generator (#4545)" This reverts commit 45806093af89eb40bc99d48cdf100e50f921baa5. --- cobalt/android/BUILD.gn | 9 -- .../java/dev/cobalt/coat/StarboardBridge.java | 107 ++++++++---------- starboard/android/shared/BUILD.gn | 4 - starboard/android/shared/android_main.cc | 7 -- .../android/shared/application_android.cc | 40 +++++-- .../android/shared/application_android.h | 5 - starboard/android/shared/starboard_bridge.cc | 65 ----------- starboard/android/shared/starboard_bridge.h | 66 ----------- 8 files changed, 75 insertions(+), 228 deletions(-) delete mode 100644 starboard/android/shared/starboard_bridge.cc delete mode 100644 starboard/android/shared/starboard_bridge.h diff --git a/cobalt/android/BUILD.gn b/cobalt/android/BUILD.gn index 831a54795fc..85e5e0d69d7 100644 --- a/cobalt/android/BUILD.gn +++ b/cobalt/android/BUILD.gn @@ -32,21 +32,13 @@ jinja_template("cobalt_manifest") { variables = [ "manifest_package=dev.cobalt.coat" ] } -generate_jni("jni_headers") { - sources = [ "apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java" ] -} - # TODO(cobalt): Re-enable or remove disabled java files. android_library("cobalt_apk_java") { testonly = true resources_package = "dev.cobalt.coat" - annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ] - deps = [ ":cobalt_java_resources", - ":jni_headers", "//base:base_java", - "//base:jni_java", "//base:process_launcher_java", "//build/android:build_java", "//components/embedder_support/android:view_java", @@ -65,7 +57,6 @@ android_library("cobalt_apk_java") { "//ui/android:ui_no_recycler_view_java", "//url:gurl_java", ] - sources = [ "apk/app/src/app/java/dev/cobalt/app/CobaltApplication.java", "apk/app/src/app/java/dev/cobalt/app/MainActivity.java", diff --git a/cobalt/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java b/cobalt/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java index 6660df76f44..d94590f0052 100644 --- a/cobalt/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java +++ b/cobalt/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java @@ -52,12 +52,8 @@ import java.util.HashMap; import java.util.Locale; import java.util.TimeZone; -import org.chromium.base.annotations.CalledByNative; -import org.chromium.base.annotations.JNINamespace; -import org.chromium.base.annotations.NativeMethods; /** Implementation of the required JNI methods called by the Starboard C++ code. */ -@JNINamespace("starboard::android::shared") public class StarboardBridge { /** Interface to be implemented by the Android Application hosting the starboard app. */ @@ -148,19 +144,7 @@ public StarboardBridge( private native void closeNativeStarboard(long nativeApp); - @NativeMethods - interface Natives { - void onStop(); - - long currentMonotonicTime(); - - // TODO(cobalt, b/372559388): move below native methods to the Natives interface. - // boolean initJNI(); - - // long startNativeStarboard(); - - // void closeNativeStarboard(long nativeApp); - } + private native long nativeCurrentMonotonicTime(); protected void onActivityStart(Activity activity) { Log.e(TAG, "onActivityStart ran"); @@ -179,6 +163,8 @@ protected void onActivityStop(Activity activity) { afterStopped(); } + private native void nativeOnStop(); + protected void onActivityDestroy(Activity activity) { if (applicationStopped) { // We can't restart the starboard app, so kill the process for a clean start next time. @@ -201,7 +187,7 @@ protected void onServiceDestroy(Service service) { } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative protected void beforeStartOrResume() { Log.i(TAG, "Prepare to resume"); // Bring our platform services to life before resuming so that they're ready to deal with @@ -216,7 +202,7 @@ protected void beforeStartOrResume() { } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative protected void beforeSuspend() { try { Log.i(TAG, "Prepare to suspend"); @@ -234,7 +220,7 @@ protected void beforeSuspend() { } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative protected void afterStopped() { applicationStopped = true; ttsHelper.shutdown(); @@ -254,20 +240,20 @@ protected void afterStopped() { } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative protected void applicationStarted() { applicationReady = true; } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative protected void applicationStopping() { applicationReady = false; applicationStopped = true; } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative public void requestSuspend() { Activity activity = activityHolder.get(); if (activity != null) { @@ -287,7 +273,7 @@ public boolean onSearchRequested() { // private native boolean nativeOnSearchRequested(); @SuppressWarnings("unused") - @CalledByNative + @UsedByNative public Context getApplicationContext() { if (appContext == null) { throw new IllegalArgumentException("appContext cannot be null"); @@ -296,7 +282,7 @@ public Context getApplicationContext() { } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative void raisePlatformError(@PlatformError.ErrorType int errorType, long data) { PlatformError error = new PlatformError(activityHolder, errorType, data); error.raise(); @@ -316,7 +302,7 @@ protected Holder getActivityHolder() { } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative protected String[] getArgs() { if (args == null) { throw new IllegalArgumentException("args cannot be null"); @@ -326,7 +312,7 @@ protected String[] getArgs() { /** Returns the URL from the Intent that started the app. */ @SuppressWarnings("unused") - @CalledByNative + @UsedByNative protected String getStartDeepLink() { if (startDeepLink == null) { throw new IllegalArgumentException("startDeepLink cannot be null"); @@ -354,7 +340,7 @@ private void nativeHandleDeepLink(String url) { * May be overridden for use cases that need to segregate storage. */ @SuppressWarnings("unused") - @CalledByNative + @UsedByNative protected String getFilesAbsolutePath() { return appContext.getFilesDir().getAbsolutePath(); } @@ -364,7 +350,7 @@ protected String getFilesAbsolutePath() { * overridden for use cases that need to segregate storage. */ @SuppressWarnings("unused") - @CalledByNative + @UsedByNative protected String getCacheAbsolutePath() { return appContext.getCacheDir().getAbsolutePath(); } @@ -376,9 +362,6 @@ protected String getCacheAbsolutePath() { */ @SuppressWarnings("unused") @UsedByNative - // TODO: (cobalt b/372559388) Migrate complicated returned type functions to JNI zero. - // The @CalledByNative annotation has strict signature parsing rules, - // and Pair is not be supported well. Pair getLocalInterfaceAddressAndNetmask(boolean wantIPv6) { try { Enumeration it = NetworkInterface.getNetworkInterfaces(); @@ -426,7 +409,7 @@ Pair getLocalInterfaceAddressAndNetmask(boolean wantIPv6) { } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative CobaltTextToSpeechHelper getTextToSpeechHelper() { if (ttsHelper == null) { throw new IllegalArgumentException("ttsHelper cannot be null for native code"); @@ -438,7 +421,7 @@ CobaltTextToSpeechHelper getTextToSpeechHelper() { * @return A new CaptionSettings object with the current system caption settings. */ @SuppressWarnings("unused") - @CalledByNative + @UsedByNative CaptionSettings getCaptionSettings() { CaptioningManager cm = (CaptioningManager) appContext.getSystemService(Context.CAPTIONING_SERVICE); @@ -447,13 +430,13 @@ CaptionSettings getCaptionSettings() { /** Java-layer implementation of SbSystemGetLocaleId. */ @SuppressWarnings("unused") - @CalledByNative + @UsedByNative String systemGetLocaleId() { return Locale.getDefault().toLanguageTag(); } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative String getTimeZoneId() { Locale locale = Locale.getDefault(); Calendar calendar = Calendar.getInstance(locale); @@ -465,19 +448,19 @@ String getTimeZoneId() { } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative SizeF getDisplayDpi() { return DisplayUtil.getDisplayDpi(); } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative Size getDisplaySize() { return DisplayUtil.getSystemDisplaySize(); } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative public ResourceOverlay getResourceOverlay() { if (resourceOverlay == null) { throw new IllegalArgumentException("resourceOverlay cannot be null for native code"); @@ -499,7 +482,7 @@ private static String getSystemProperty(String name) { } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative Size getDeviceResolution() { String displaySize = android.os.Build.VERSION.SDK_INT < 28 @@ -523,7 +506,7 @@ Size getDeviceResolution() { } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative boolean isNetworkConnected() { if (networkStatus == null) { throw new IllegalArgumentException("networkStatus cannot be null for native code"); @@ -537,7 +520,7 @@ boolean isNetworkConnected() { * @return true if no device is connected. */ @SuppressWarnings("unused") - @CalledByNative + @UsedByNative public boolean isMicrophoneDisconnected() { // A check specifically for microphones is not available before API 28, so it is assumed that a // connected input audio device is a microphone. @@ -566,7 +549,7 @@ public boolean isMicrophoneDisconnected() { * @return true if the microphone mute is on. */ @SuppressWarnings("unused") - @CalledByNative + @UsedByNative public boolean isMicrophoneMute() { AudioManager audioManager = (AudioManager) appContext.getSystemService(AUDIO_SERVICE); return audioManager.isMicrophoneMute(); @@ -576,7 +559,7 @@ public boolean isMicrophoneMute() { * @return true if we have an active network connection and it's on an wireless network. */ @SuppressWarnings("unused") - @CalledByNative + @UsedByNative boolean isCurrentNetworkWireless() { ConnectivityManager connMgr = (ConnectivityManager) appContext.getSystemService(Context.CONNECTIVITY_SERVICE); @@ -596,7 +579,7 @@ boolean isCurrentNetworkWireless() { * @return true if the user has enabled accessibility high contrast text in the operating system. */ @SuppressWarnings("unused") - @CalledByNative + @UsedByNative boolean isAccessibilityHighContrastTextEnabled() { AccessibilityManager am = (AccessibilityManager) appContext.getSystemService(Context.ACCESSIBILITY_SERVICE); @@ -611,7 +594,7 @@ boolean isAccessibilityHighContrastTextEnabled() { } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative void updateMediaSession( int playbackState, long actions, @@ -630,7 +613,7 @@ void updateMediaSession( } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative public void deactivateMediaSession() { // TODO(b/377019873): re-enable Log.e(TAG, "MediaSession is disabled"); @@ -639,7 +622,7 @@ public void deactivateMediaSession() { /** Returns string for kSbSystemPropertyUserAgentAuxField */ @SuppressWarnings("unused") - @CalledByNative + @UsedByNative protected String getUserAgentAuxField() { StringBuilder sb = new StringBuilder(); @@ -667,20 +650,20 @@ protected String getUserAgentAuxField() { /** Returns string for kSbSystemPropertyAdvertisingId */ @SuppressWarnings("unused") - @CalledByNative + @UsedByNative protected String getAdvertisingId() { return this.advertisingId.getId(); } /** Returns boolean for kSbSystemPropertyLimitAdTracking */ @SuppressWarnings("unused") - @CalledByNative + @UsedByNative protected boolean getLimitAdTracking() { return this.advertisingId.isLimitAdTrackingEnabled(); } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative AudioOutputManager getAudioOutputManager() { if (audioOutputManager == null) { throw new IllegalArgumentException("audioOutputManager cannot be null for native code"); @@ -690,7 +673,7 @@ AudioOutputManager getAudioOutputManager() { /** Returns Java layer implementation for AudioPermissionRequester */ // @SuppressWarnings("unused") - // @CalledByNative + // @UsedByNative // AudioPermissionRequester getAudioPermissionRequester() { // return audioPermissionRequester; // } @@ -700,7 +683,7 @@ AudioOutputManager getAudioOutputManager() { // } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative public void resetVideoSurface() { Activity activity = activityHolder.get(); if (activity instanceof CobaltActivity) { @@ -709,7 +692,7 @@ public void resetVideoSurface() { } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative public void setVideoSurfaceBounds(final int x, final int y, final int width, final int height) { Activity activity = activityHolder.get(); if (activity instanceof CobaltActivity) { @@ -719,7 +702,7 @@ public void setVideoSurfaceBounds(final int x, final int y, final int width, fin /** Return supported hdr types. */ @SuppressWarnings("unused") - @CalledByNative + @UsedByNative public int[] getSupportedHdrTypes() { Display defaultDisplay = DisplayUtil.getDefaultDisplay(); if (defaultDisplay == null) { @@ -797,12 +780,12 @@ public byte[] sendToCobaltService(String serviceName, byte [] data) { /** Returns the application start timestamp. */ @SuppressWarnings("unused") - @CalledByNative + @UsedByNative protected long getAppStartTimestamp() { Activity activity = activityHolder.get(); if (activity instanceof CobaltActivity) { long javaStartTimestamp = ((CobaltActivity) activity).getAppStartTimestamp(); - long cppTimestamp = StarboardBridgeJni.get().currentMonotonicTime(); + long cppTimestamp = nativeCurrentMonotonicTime(); long javaStopTimestamp = System.nanoTime(); return cppTimestamp - (javaStopTimestamp - javaStartTimestamp) / timeNanosecondsPerMicrosecond; @@ -811,7 +794,7 @@ protected long getAppStartTimestamp() { } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative void reportFullyDrawn() { Activity activity = activityHolder.get(); if (activity != null) { @@ -820,7 +803,7 @@ void reportFullyDrawn() { } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative public void setCrashContext(String key, String value) { Log.i(TAG, "setCrashContext Called: " + key + ", " + value); crashContext.put(key, value); @@ -838,19 +821,19 @@ public void registerCrashContextUpdateHandler(CrashContextUpdateHandler handler) } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative protected boolean getIsAmatiDevice() { return this.isAmatiDevice; } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative protected String getBuildFingerprint() { return Build.FINGERPRINT; } @SuppressWarnings("unused") - @CalledByNative + @UsedByNative protected long getPlayServicesVersion() { try { if (android.os.Build.VERSION.SDK_INT < 28) { diff --git a/starboard/android/shared/BUILD.gn b/starboard/android/shared/BUILD.gn index 0acc55f11d5..6fc15ad2016 100644 --- a/starboard/android/shared/BUILD.gn +++ b/starboard/android/shared/BUILD.gn @@ -263,8 +263,6 @@ static_library("starboard_platform") { #"speech_synthesis_internal.cc", #"speech_synthesis_is_supported.cc", #"speech_synthesis_speak.cc", - "starboard_bridge.cc", - "starboard_bridge.h", "system_get_extensions.cc", "system_get_locale_id.cc", "system_get_path.cc", @@ -316,14 +314,12 @@ static_library("starboard_platform") { public_deps = [ ":starboard_base_symbolize", ":starboard_jni_state", - "//cobalt/android:jni_headers", "//starboard/common", "//starboard/shared/starboard/media:media_util", "//starboard/shared/starboard/player/filter:filter_based_player_sources", ] deps = [ - "//base", "//third_party/libevent", "//third_party/opus", ] diff --git a/starboard/android/shared/android_main.cc b/starboard/android/shared/android_main.cc index b16001e7a70..0ed8090673a 100644 --- a/starboard/android/shared/android_main.cc +++ b/starboard/android/shared/android_main.cc @@ -35,8 +35,6 @@ #include "starboard/crashpad_wrapper/wrapper.h" // nogncheck #endif -#include "starboard/android/shared/starboard_bridge.h" - namespace starboard { namespace android { namespace shared { @@ -294,15 +292,10 @@ void StarboardThreadLaunch() { } #endif // SB_IS(EVERGREEN_COMPATIBLE) -// TODO(cobalt, b/372559388): consolidate this function when fully deprecate -// JniEnvExt. extern "C" SB_EXPORT_PLATFORM void Java_dev_cobalt_coat_StarboardBridge_initJNI( JniEnvExt* env, jobject starboard_bridge) { JniEnvExt::Initialize(env, starboard_bridge); - - // Initialize the singleton instance of StarboardBridge - StarboardBridge::GetInstance()->Initialize(env, starboard_bridge); } extern "C" SB_EXPORT_PLATFORM jlong diff --git a/starboard/android/shared/application_android.cc b/starboard/android/shared/application_android.cc index 9db7e234b47..5d076a7f268 100644 --- a/starboard/android/shared/application_android.cc +++ b/starboard/android/shared/application_android.cc @@ -24,7 +24,6 @@ #include #include -#include "base/android/jni_android.h" #include "starboard/extension/accessibility.h" #include "starboard/android/shared/file_internal.h" @@ -45,6 +44,14 @@ namespace starboard { namespace android { namespace shared { +namespace { +int64_t GetAppStartTimestamp() { + JniEnvExt* env = JniEnvExt::Get(); + jlong app_start_timestamp = + env->CallStarboardLongMethodOrAbort("getAppStartTimestamp", "()J"); + return app_start_timestamp; +} +} // namespace // TODO(cobalt, b/378708359): Remove this dummy init. void stubSbEventHandle(const SbEvent* event) { @@ -63,19 +70,18 @@ ApplicationAndroid::ApplicationAndroid( // from the assets. The use ICU is used in our logging. SbFileAndroidInitialize(); - base::android::ScopedJavaLocalRef resource_overlay = - starboard_bridge_->GetResourceOverlay(); - resource_overlay_ = - JniEnvExt::Get()->ConvertLocalRefToGlobalRef(resource_overlay.obj()); - + JniEnvExt* env = JniEnvExt::Get(); + jobject local_ref = env->CallStarboardObjectMethodOrAbort( + "getResourceOverlay", "()Ldev/cobalt/coat/ResourceOverlay;"); + resource_overlay_ = env->ConvertLocalRefToGlobalRef(local_ref); SbAudioSinkPrivate::Initialize(); - - app_start_timestamp_ = starboard_bridge_->GetAppStartTimestamp(); - starboard_bridge_->ApplicationStarted(); + app_start_timestamp_ = GetAppStartTimestamp(); + env->CallStarboardVoidMethodOrAbort("applicationStarted", "()V"); } ApplicationAndroid::~ApplicationAndroid() { - starboard_bridge_->ApplicationStopping(); + JniEnvExt* env = JniEnvExt::Get(); + env->CallStarboardVoidMethodOrAbort("applicationStopping", "()V"); // The application is exiting. // Release the global reference. @@ -88,6 +94,12 @@ ApplicationAndroid::~ApplicationAndroid() { JniEnvExt::OnThreadShutdown(); } +extern "C" SB_EXPORT_PLATFORM void +Java_dev_cobalt_coat_StarboardBridge_nativeOnStop(JniEnvExt* env) { + SbAudioSinkPrivate::TearDown(); + SbFileAndroidTeardown(); +} + extern "C" SB_EXPORT_PLATFORM jboolean Java_dev_cobalt_coat_StarboardBridge_nativeOnSearchRequested( JniEnvExt* env, @@ -96,6 +108,14 @@ Java_dev_cobalt_coat_StarboardBridge_nativeOnSearchRequested( return true; } +extern "C" SB_EXPORT_PLATFORM jlong +Java_dev_cobalt_coat_StarboardBridge_nativeCurrentMonotonicTime( + JNIEnv* env, + jobject jcaller, + jboolean online) { + return CurrentMonotonicTime(); +} + extern "C" SB_EXPORT_PLATFORM void Java_dev_cobalt_coat_CobaltSystemConfigChangeReceiver_nativeDateTimeConfigurationChanged( JNIEnv* env, diff --git a/starboard/android/shared/application_android.h b/starboard/android/shared/application_android.h index c97c11b76f8..16c2a577840 100644 --- a/starboard/android/shared/application_android.h +++ b/starboard/android/shared/application_android.h @@ -29,8 +29,6 @@ #include "starboard/shared/starboard/queue_application.h" #include "starboard/types.h" -#include "starboard/android/shared/starboard_bridge.h" - namespace starboard { namespace android { namespace shared { @@ -68,9 +66,6 @@ class ApplicationAndroid void WakeSystemEventWait() override {} private: - // starboard_bridge_ is a global singleton, use a raw pointer to not interfere - // with it's lifecycle management. - StarboardBridge* starboard_bridge_; jobject resource_overlay_; Mutex overlay_mutex_; diff --git a/starboard/android/shared/starboard_bridge.cc b/starboard/android/shared/starboard_bridge.cc deleted file mode 100644 index 734bbf54673..00000000000 --- a/starboard/android/shared/starboard_bridge.cc +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2024 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. - -#include "starboard/android/shared/starboard_bridge.h" - -#include "starboard/android/shared/file_internal.h" -#include "starboard/common/time.h" -#include "starboard/media.h" -#include "starboard/shared/starboard/audio_sink/audio_sink_internal.h" - -// Must come after all headers that specialize FromJniType() / ToJniType(). -#include "cobalt/android/jni_headers/StarboardBridge_jni.h" - -namespace starboard { -namespace android { -namespace shared { - -extern "C" SB_EXPORT_PLATFORM void JNI_StarboardBridge_OnStop(JNIEnv* env) { - SbAudioSinkPrivate::TearDown(); - SbFileAndroidTeardown(); -} - -extern "C" SB_EXPORT_PLATFORM jlong -JNI_StarboardBridge_CurrentMonotonicTime(JNIEnv* env) { - return CurrentMonotonicTime(); -} - -long StarboardBridge::GetAppStartTimestamp() { - JNIEnv* env = base::android::AttachCurrentThread(); - CHECK(env); - return Java_StarboardBridge_getAppStartTimestamp(env, j_starboard_bridge_); -} - -base::android::ScopedJavaLocalRef -StarboardBridge::GetResourceOverlay() { - JNIEnv* env = base::android::AttachCurrentThread(); - CHECK(env); - return Java_StarboardBridge_getResourceOverlay(env, j_starboard_bridge_); -} - -void StarboardBridge::ApplicationStarted() { - JNIEnv* env = base::android::AttachCurrentThread(); - CHECK(env); - return Java_StarboardBridge_applicationStarted(env, j_starboard_bridge_); -} - -void StarboardBridge::ApplicationStopping() { - JNIEnv* env = base::android::AttachCurrentThread(); - CHECK(env); - return Java_StarboardBridge_applicationStopping(env, j_starboard_bridge_); -} -} // namespace shared -} // namespace android -} // namespace starboard diff --git a/starboard/android/shared/starboard_bridge.h b/starboard/android/shared/starboard_bridge.h deleted file mode 100644 index 415923cb3f2..00000000000 --- a/starboard/android/shared/starboard_bridge.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2024 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. - -#ifndef STARBOARD_ANDROID_SHARED_STARBOARD_BRIDGE_H_ -#define STARBOARD_ANDROID_SHARED_STARBOARD_BRIDGE_H_ - -#include - -#include "base/android/scoped_java_ref.h" -#include "base/memory/singleton.h" - -namespace starboard { -namespace android { -namespace shared { - -// This class serves as a bridge between the native code and Android -// StarboardBridge Java class. -class StarboardBridge { - public: - // Returns the singleton. - static StarboardBridge* GetInstance() { - return base::Singleton::get(); - } - - void Initialize(JNIEnv* env, jobject obj) { - j_starboard_bridge_.Reset(env, obj); - } - - long GetAppStartTimestamp(); - - base::android::ScopedJavaLocalRef GetResourceOverlay(); - - void ApplicationStarted(); - - void ApplicationStopping(); - - private: - StarboardBridge() = default; - ~StarboardBridge() = default; - - // Prevent copy construction and assignment - StarboardBridge(const StarboardBridge&) = delete; - StarboardBridge& operator=(const StarboardBridge&) = delete; - - friend struct base::DefaultSingletonTraits; - - // Java StarboardBridge instance. - base::android::ScopedJavaGlobalRef j_starboard_bridge_; -}; - -} // namespace shared -} // namespace android -} // namespace starboard - -#endif // STARBOARD_ANDROID_SHARED_STARBOARD_BRIDGE_H_