diff options
Diffstat (limited to 'base/android')
100 files changed, 2666 insertions, 3061 deletions
diff --git a/base/android/animation_frame_time_histogram.cc b/base/android/animation_frame_time_histogram.cc index 2cf7516..c2b48d3 100644 --- a/base/android/animation_frame_time_histogram.cc +++ b/base/android/animation_frame_time_histogram.cc @@ -8,6 +8,8 @@ #include "base/metrics/histogram_macros.h" #include "jni/AnimationFrameTimeHistogram_jni.h" +using base::android::JavaParamRef; + // static void SaveHistogram(JNIEnv* env, const JavaParamRef<jobject>& jcaller, diff --git a/base/android/apk_assets.cc b/base/android/apk_assets.cc index 5319e73..19a202c 100644 --- a/base/android/apk_assets.cc +++ b/base/android/apk_assets.cc @@ -10,24 +10,20 @@ #include "base/android/jni_array.h" #include "base/android/jni_string.h" #include "base/android/scoped_java_ref.h" +#include "base/file_descriptor_store.h" #include "jni/ApkAssets_jni.h" namespace base { namespace android { -bool RegisterApkAssets(JNIEnv* env) { - return RegisterNativesImpl(env); -} - int OpenApkAsset(const std::string& file_path, base::MemoryMappedFile::Region* region) { - // The AAssetManager API of the NDK is does not expose a method for accessing - // raw resources :(. + // The AssetManager API of the NDK does not expose a method for accessing raw + // resources :( JNIEnv* env = base::android::AttachCurrentThread(); ScopedJavaLocalRef<jlongArray> jarr = Java_ApkAssets_open( - env, - base::android::GetApplicationContext(), - base::android::ConvertUTF8ToJavaString(env, file_path).obj()); + env, base::android::GetApplicationContext(), + base::android::ConvertUTF8ToJavaString(env, file_path)); std::vector<jlong> results; base::android::JavaLongArrayToLongVector(env, jarr.obj(), &results); CHECK_EQ(3U, results.size()); @@ -37,15 +33,16 @@ int OpenApkAsset(const std::string& file_path, return fd; } -bool RegisterApkAssetWithGlobalDescriptors(base::GlobalDescriptors::Key key, - const std::string& file_path) { +bool RegisterApkAssetWithFileDescriptorStore(const std::string& key, + const base::FilePath& file_path) { base::MemoryMappedFile::Region region = base::MemoryMappedFile::Region::kWholeFile; - int asset_fd = OpenApkAsset(file_path, ®ion); - if (asset_fd != -1) { - base::GlobalDescriptors::GetInstance()->Set(key, asset_fd, region); - } - return asset_fd != -1; + int asset_fd = OpenApkAsset(file_path.value(), ®ion); + if (asset_fd == -1) + return false; + base::FileDescriptorStore::GetInstance().Set(key, base::ScopedFD(asset_fd), + region); + return true; } } // namespace android diff --git a/base/android/apk_assets.h b/base/android/apk_assets.h index 6eb5da3..cdac000 100644 --- a/base/android/apk_assets.h +++ b/base/android/apk_assets.h @@ -8,14 +8,12 @@ #include <string> #include "base/android/jni_android.h" +#include "base/files/file_path.h" #include "base/files/memory_mapped_file.h" -#include "base/posix/global_descriptors.h" namespace base { namespace android { -bool RegisterApkAssets(JNIEnv* env); - // Opens an asset (e.g. a .pak file) from the apk. // Can be used from renderer process. // Fails if the asset is not stored uncompressed within the .apk. @@ -28,11 +26,12 @@ BASE_EXPORT int OpenApkAsset( const std::string& file_path, base::MemoryMappedFile::Region* region); -// Registers an uncompressed asset from within the apk with GlobalDescriptors. +// Registers an uncompressed asset from within the apk in the +// FileDescriptorStore. // Returns: true in case of success, false otherwise. -BASE_EXPORT bool RegisterApkAssetWithGlobalDescriptors( - base::GlobalDescriptors::Key key, - const std::string& file_path); +BASE_EXPORT bool RegisterApkAssetWithFileDescriptorStore( + const std::string& key, + const base::FilePath& file_path); } // namespace android } // namespace base diff --git a/base/android/base_jni_onload.cc b/base/android/base_jni_onload.cc index 7ab4982..0a82db4 100644 --- a/base/android/base_jni_onload.cc +++ b/base/android/base_jni_onload.cc @@ -12,13 +12,11 @@ namespace base { namespace android { -namespace { - -bool RegisterJNI(JNIEnv* env) { +bool OnJNIOnLoadRegisterJNI(JNIEnv* env) { return RegisterLibraryLoaderEntryHook(env); } -bool Init() { +bool OnJNIOnLoadInit() { InitAtExitManager(); JNIEnv* env = base::android::AttachCurrentThread(); base::android::InitReplacementClassLoader(env, @@ -26,32 +24,5 @@ bool Init() { return true; } -} // namespace - - -bool OnJNIOnLoadRegisterJNI(JavaVM* vm, - std::vector<RegisterCallback> callbacks) { - base::android::InitVM(vm); - JNIEnv* env = base::android::AttachCurrentThread(); - - callbacks.push_back(base::Bind(&RegisterJNI)); - for (std::vector<RegisterCallback>::reverse_iterator i = - callbacks.rbegin(); i != callbacks.rend(); ++i) { - if (!i->Run(env)) - return false; - } - return true; -} - -bool OnJNIOnLoadInit(std::vector<InitCallback> callbacks) { - callbacks.push_back(base::Bind(&Init)); - for (std::vector<InitCallback>::reverse_iterator i = - callbacks.rbegin(); i != callbacks.rend(); ++i) { - if (!i->Run()) - return false; - } - return true; -} - } // namespace android } // namespace base diff --git a/base/android/base_jni_onload.h b/base/android/base_jni_onload.h index dcc7756..be637d5 100644 --- a/base/android/base_jni_onload.h +++ b/base/android/base_jni_onload.h @@ -14,17 +14,12 @@ namespace base { namespace android { -// Returns whether JNI registration succeeded. Caller shall put the -// RegisterCallback into |callbacks| in reverse order. +// Returns whether JNI registration succeeded. typedef base::Callback<bool(JNIEnv*)> RegisterCallback; -BASE_EXPORT bool OnJNIOnLoadRegisterJNI( - JavaVM* vm, - std::vector<RegisterCallback> callbacks); - -// Returns whether initialization succeeded. Caller shall put the -// InitCallback into |callbacks| in reverse order. -typedef base::Callback<bool(void)> InitCallback; -BASE_EXPORT bool OnJNIOnLoadInit(std::vector<InitCallback> callbacks); +BASE_EXPORT bool OnJNIOnLoadRegisterJNI(JNIEnv* env); + +// Returns whether initialization succeeded. +BASE_EXPORT bool OnJNIOnLoadInit(); } // namespace android } // namespace base diff --git a/base/android/base_jni_registrar.cc b/base/android/base_jni_registrar.cc index bc34979..972c333 100644 --- a/base/android/base_jni_registrar.cc +++ b/base/android/base_jni_registrar.cc @@ -5,30 +5,23 @@ #include "base/android/base_jni_registrar.h" #include "base/android/animation_frame_time_histogram.h" -#include "base/android/apk_assets.h" #include "base/android/application_status_listener.h" -#include "base/android/build_info.h" -#include "base/android/callback_android.h" #include "base/android/command_line_android.h" -#include "base/android/content_uri_utils.h" #include "base/android/context_utils.h" #include "base/android/cpu_features.h" -#include "base/android/event_log.h" +#include "base/android/early_trace_event_binding.h" #include "base/android/field_trial_list.h" #include "base/android/important_file_writer_android.h" +#include "base/android/java_exception_reporter.h" #include "base/android/java_handler_thread.h" -#include "base/android/java_runtime.h" #include "base/android/jni_android.h" #include "base/android/jni_registrar.h" -#include "base/android/jni_utils.h" -#include "base/android/locale_utils.h" #include "base/android/memory_pressure_listener_android.h" #include "base/android/path_service_android.h" -#include "base/android/path_utils.h" #include "base/android/record_histogram.h" #include "base/android/record_user_action.h" -#include "base/android/sys_utils.h" -#include "base/android/thread_utils.h" +#include "base/android/statistics_recorder_android.h" +#include "base/android/time_utils.h" #include "base/android/trace_event_binding.h" #include "base/macros.h" #include "base/message_loop/message_pump_android.h" @@ -41,33 +34,27 @@ namespace android { static RegistrationMethod kBaseRegisteredMethods[] = { {"AnimationFrameTimeHistogram", base::android::RegisterAnimationFrameTimeHistogram}, - {"ApkAssets", base::android::RegisterApkAssets}, {"ApplicationStatusListener", base::android::ApplicationStatusListener::RegisterBindings}, - {"BuildInfo", base::android::BuildInfo::RegisterBindings}, - {"CallbackAndroid", base::android::RegisterCallbackAndroid}, {"CommandLine", base::android::RegisterCommandLine}, - {"ContentUriUtils", base::RegisterContentUriUtils}, {"ContextUtils", base::android::RegisterContextUtils}, {"CpuFeatures", base::android::RegisterCpuFeatures}, - {"EventLog", base::android::RegisterEventLog}, + {"EarlyTraceEvent", base::android::RegisterEarlyTraceEvent}, {"FieldTrialList", base::android::RegisterFieldTrialList}, {"ImportantFileWriterAndroid", base::android::RegisterImportantFileWriterAndroid}, - {"JNIUtils", base::android::RegisterJNIUtils}, - {"LocaleUtils", base::android::RegisterLocaleUtils}, {"MemoryPressureListenerAndroid", base::android::MemoryPressureListenerAndroid::Register}, + {"JavaExceptionReporter", base::android::RegisterJavaExceptionReporterJni}, {"JavaHandlerThread", base::android::JavaHandlerThread::RegisterBindings}, {"PathService", base::android::RegisterPathService}, - {"PathUtils", base::android::RegisterPathUtils}, {"PowerMonitor", base::RegisterPowerMonitor}, {"RecordHistogram", base::android::RegisterRecordHistogram}, {"RecordUserAction", base::android::RegisterRecordUserAction}, - {"Runtime", base::android::JavaRuntime::Register}, + {"StatisticsRecorderAndroid", + base::android::RegisterStatisticsRecorderAndroid}, {"SystemMessageHandler", base::MessagePumpForUI::RegisterBindings}, - {"SysUtils", base::android::SysUtils::Register}, - {"ThreadUtils", base::RegisterThreadUtils}, + {"TimeUtils", base::android::RegisterTimeUtils}, {"TraceEvent", base::android::RegisterTraceEvent}, }; diff --git a/base/android/build_info.cc b/base/android/build_info.cc index ef8f572..80b9e0a 100644 --- a/base/android/build_info.cc +++ b/base/android/build_info.cc @@ -38,7 +38,7 @@ struct BuildInfoSingletonTraits { } static const bool kRegisterAtExit = false; -#ifndef NDEBUG +#if DCHECK_IS_ON() static const bool kAllowedToAccessOnNonjoinableThread = true; #endif }; @@ -81,10 +81,5 @@ void BuildInfo::ClearJavaExceptionInfo() { java_exception_info_ = nullptr; } -// static -bool BuildInfo::RegisterBindings(JNIEnv* env) { - return RegisterNativesImpl(env); -} - } // namespace android } // namespace base diff --git a/base/android/build_info.h b/base/android/build_info.h index 838d6f8..cce74f4 100644 --- a/base/android/build_info.h +++ b/base/android/build_info.h @@ -26,7 +26,8 @@ enum SdkVersion { SDK_VERSION_KITKAT_WEAR = 20, SDK_VERSION_LOLLIPOP = 21, SDK_VERSION_LOLLIPOP_MR1 = 22, - SDK_VERSION_MARSHMALLOW = 23 + SDK_VERSION_MARSHMALLOW = 23, + SDK_VERSION_NOUGAT = 24 }; // BuildInfo is a singleton class that stores android build and device @@ -110,8 +111,6 @@ class BASE_EXPORT BuildInfo { void ClearJavaExceptionInfo(); - static bool RegisterBindings(JNIEnv* env); - private: friend struct BuildInfoSingletonTraits; diff --git a/base/android/command_line_android.cc b/base/android/command_line_android.cc index e196aed..21ae182 100644 --- a/base/android/command_line_android.cc +++ b/base/android/command_line_android.cc @@ -12,6 +12,8 @@ using base::android::ConvertUTF8ToJavaString; using base::android::ConvertJavaStringToUTF8; +using base::android::JavaParamRef; +using base::android::ScopedJavaLocalRef; using base::CommandLine; namespace { diff --git a/base/android/content_uri_utils.cc b/base/android/content_uri_utils.cc index 31f7b4f..f7484cf 100644 --- a/base/android/content_uri_utils.cc +++ b/base/android/content_uri_utils.cc @@ -10,19 +10,16 @@ #include "jni/ContentUriUtils_jni.h" using base::android::ConvertUTF8ToJavaString; +using base::android::ScopedJavaLocalRef; namespace base { -bool RegisterContentUriUtils(JNIEnv* env) { - return RegisterNativesImpl(env); -} - bool ContentUriExists(const FilePath& content_uri) { JNIEnv* env = base::android::AttachCurrentThread(); ScopedJavaLocalRef<jstring> j_uri = ConvertUTF8ToJavaString(env, content_uri.value()); return Java_ContentUriUtils_contentUriExists( - env, base::android::GetApplicationContext(), j_uri.obj()); + env, base::android::GetApplicationContext(), j_uri); } File OpenContentUriForRead(const FilePath& content_uri) { @@ -30,7 +27,7 @@ File OpenContentUriForRead(const FilePath& content_uri) { ScopedJavaLocalRef<jstring> j_uri = ConvertUTF8ToJavaString(env, content_uri.value()); jint fd = Java_ContentUriUtils_openContentUriForRead( - env, base::android::GetApplicationContext(), j_uri.obj()); + env, base::android::GetApplicationContext(), j_uri); if (fd < 0) return File(); return File(fd); @@ -40,9 +37,8 @@ std::string GetContentUriMimeType(const FilePath& content_uri) { JNIEnv* env = base::android::AttachCurrentThread(); ScopedJavaLocalRef<jstring> j_uri = ConvertUTF8ToJavaString(env, content_uri.value()); - ScopedJavaLocalRef<jstring> j_mime = - Java_ContentUriUtils_getMimeType( - env, base::android::GetApplicationContext(), j_uri.obj()); + ScopedJavaLocalRef<jstring> j_mime = Java_ContentUriUtils_getMimeType( + env, base::android::GetApplicationContext(), j_uri); if (j_mime.is_null()) return std::string(); diff --git a/base/android/content_uri_utils.h b/base/android/content_uri_utils.h index 59fa1e6..6d817c0 100644 --- a/base/android/content_uri_utils.h +++ b/base/android/content_uri_utils.h @@ -13,8 +13,6 @@ namespace base { -bool RegisterContentUriUtils(JNIEnv* env); - // Opens a content URI for read and returns the file descriptor to the caller. // Returns -1 if the URI is invalid. BASE_EXPORT File OpenContentUriForRead(const FilePath& content_uri); diff --git a/base/android/context_utils.cc b/base/android/context_utils.cc index e9ab723..e2c4ed0 100644 --- a/base/android/context_utils.cc +++ b/base/android/context_utils.cc @@ -33,9 +33,9 @@ void SetNativeApplicationContext(JNIEnv* env, const JavaRef<jobject>& context) { } // namespace -jobject GetApplicationContext() { +const JavaRef<jobject>& GetApplicationContext() { DCHECK(!g_application_context.Get().is_null()); - return g_application_context.Get().obj(); + return g_application_context.Get(); } static void InitNativeSideApplicationContext( diff --git a/base/android/context_utils.h b/base/android/context_utils.h index f172d93..c5289f1 100644 --- a/base/android/context_utils.h +++ b/base/android/context_utils.h @@ -16,7 +16,7 @@ namespace android { // Gets a global ref to the application context set with // InitApplicationContext(). Ownership is retained by the function - the caller // must NOT release it. -BASE_EXPORT jobject GetApplicationContext(); +BASE_EXPORT const JavaRef<jobject>& GetApplicationContext(); bool RegisterContextUtils(JNIEnv* env); diff --git a/base/android/event_log.cc b/base/android/event_log.cc index a4b1dd1..3eb5926 100644 --- a/base/android/event_log.cc +++ b/base/android/event_log.cc @@ -12,9 +12,5 @@ void EventLogWriteInt(int tag, int value) { Java_EventLog_writeEvent(AttachCurrentThread(), tag, value); } -bool RegisterEventLog(JNIEnv* env) { - return RegisterNativesImpl(env); -} - } // namespace android } // namespace base diff --git a/base/android/event_log.h b/base/android/event_log.h index dad4e4c..ebd5919 100644 --- a/base/android/event_log.h +++ b/base/android/event_log.h @@ -14,8 +14,6 @@ namespace android { void BASE_EXPORT EventLogWriteInt(int tag, int value); -bool RegisterEventLog(JNIEnv* env); - } // namespace android } // namespace base diff --git a/base/android/field_trial_list.cc b/base/android/field_trial_list.cc index 9731a48..5150b81 100644 --- a/base/android/field_trial_list.cc +++ b/base/android/field_trial_list.cc @@ -12,6 +12,8 @@ using base::android::ConvertJavaStringToUTF8; using base::android::ConvertUTF8ToJavaString; +using base::android::JavaParamRef; +using base::android::ScopedJavaLocalRef; static ScopedJavaLocalRef<jstring> FindFullName( JNIEnv* env, diff --git a/base/android/fifo_utils.cc b/base/android/fifo_utils.cc deleted file mode 100644 index 8f3e95f..0000000 --- a/base/android/fifo_utils.cc +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2013 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. - -#include "base/android/fifo_utils.h" - -#include <sys/stat.h> - -#include "base/files/file_path.h" - -namespace base { -namespace android { - -bool CreateFIFO(const FilePath& path, int mode) { - // Default permissions for mkfifo() is ignored, chmod() is required. - return mkfifo(path.value().c_str(), mode) == 0 && - chmod(path.value().c_str(), mode) == 0; -} - -bool RedirectStream(FILE* stream, const FilePath& path, const char* mode) { - return freopen(path.value().c_str(), mode, stream) != NULL; -} - -} // namespace android -} // namespace base diff --git a/base/android/fifo_utils.h b/base/android/fifo_utils.h deleted file mode 100644 index 0bad8e2..0000000 --- a/base/android/fifo_utils.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2013 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. - -#ifndef BASE_ANDROID_FIFO_UTILS_H_ -#define BASE_ANDROID_FIFO_UTILS_H_ - -#include <stdio.h> - -#include "base/base_export.h" - -namespace base { - -class FilePath; - -namespace android { - -// Creates a fifo at the given |path| with POSIX permissions set to |mode|, -// returning true if it was successfully created and permissions were set. -BASE_EXPORT bool CreateFIFO(const FilePath& path, int mode); - -// Redirects the |stream| to the file provided by |path| with |mode| -// permissions, returning true if successful. -BASE_EXPORT bool RedirectStream(FILE* stream, - const FilePath& path, - const char* mode); - -} // namespace android -} // namespace base - -#endif // BASE_ANDROID_FIFO_UTILS_H_ diff --git a/base/android/java/src/org/chromium/base/ActivityState.java b/base/android/java/src/org/chromium/base/ActivityState.java index 98aff62..f4e6413 100644 --- a/base/android/java/src/org/chromium/base/ActivityState.java +++ b/base/android/java/src/org/chromium/base/ActivityState.java @@ -4,10 +4,20 @@ package org.chromium.base; +import android.support.annotation.IntDef; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + /** * A set of states that represent the last state change of an Activity. */ public interface ActivityState { + + @Retention(RetentionPolicy.SOURCE) + @IntDef({CREATED, STARTED, RESUMED, PAUSED, STOPPED, DESTROYED}) + public @interface ActivityStateEnum {} + /** * Represents Activity#onCreate(). */ diff --git a/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java b/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java index 9c9c16b..f773859 100644 --- a/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java +++ b/base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java @@ -21,6 +21,7 @@ import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.net.Uri; import android.os.Build; import android.os.PowerManager; import android.os.Process; @@ -31,8 +32,10 @@ import android.view.View; import android.view.ViewGroup.MarginLayoutParams; import android.view.Window; import android.view.WindowManager; +import android.view.inputmethod.InputMethodSubtype; import android.widget.TextView; +import java.io.File; import java.lang.reflect.Method; /** @@ -44,6 +47,22 @@ public class ApiCompatibilityUtils { } /** + * Compares two long values numerically. The value returned is identical to what would be + * returned by {@link Long#compare(long, long)} which is available since API level 19. + */ + public static int compareLong(long lhs, long rhs) { + return lhs < rhs ? -1 : (lhs == rhs ? 0 : 1); + } + + /** + * Compares two boolean values. The value returned is identical to what would be returned by + * {@link Boolean#compare(boolean, boolean)} which is available since API level 19. + */ + public static int compareBoolean(boolean lhs, boolean rhs) { + return lhs == rhs ? 0 : lhs ? 1 : -1; + } + + /** * Returns true if view's layout direction is right-to-left. * * @param view the View whose layout is being considered @@ -394,13 +413,7 @@ public class ApiCompatibilityUtils { */ public static void setStatusBarColor(Window window, int statusBarColor) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - // If both system bars are black, we can remove these from our layout, - // removing or shrinking the SurfaceFlinger overlay required for our views. - if (statusBarColor == Color.BLACK && window.getNavigationBarColor() == Color.BLACK) { - window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - } else { - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - } + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(statusBarColor); } } @@ -515,7 +528,19 @@ public class ApiCompatibilityUtils { } /** - * See {@link android.os.StatFs#getBlockCount()}. + * See {@link android.os.StatFs#getAvailableBlocksLong}. + */ + @SuppressWarnings("deprecation") + public static long getAvailableBlocks(StatFs statFs) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + return statFs.getAvailableBlocksLong(); + } else { + return statFs.getAvailableBlocks(); + } + } + + /** + * See {@link android.os.StatFs#getBlockCount}. */ @SuppressWarnings("deprecation") public static long getBlockCount(StatFs statFs) { @@ -527,7 +552,7 @@ public class ApiCompatibilityUtils { } /** - * See {@link android.os.StatFs#getBlockSize()}. + * See {@link android.os.StatFs#getBlockSize}. */ @SuppressWarnings("deprecation") public static long getBlockSize(StatFs statFs) { @@ -559,4 +584,68 @@ public class ApiCompatibilityUtils { return false; } + + /** + * @see Context#checkPermission(String, int, int) + */ + public static int checkPermission(Context context, String permission, int pid, int uid) { + try { + return context.checkPermission(permission, pid, uid); + } catch (RuntimeException e) { + // Some older versions of Android throw odd errors when checking for permissions, so + // just swallow the exception and treat it as the permission is denied. + // crbug.com/639099 + return PackageManager.PERMISSION_DENIED; + } + } + + /** + * @see android.view.inputmethod.InputMethodSubType#getLocate() + */ + @SuppressWarnings("deprecation") + public static String getLocale(InputMethodSubtype inputMethodSubType) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + return inputMethodSubType.getLanguageTag(); + } else { + return inputMethodSubType.getLocale(); + } + } + + /** + * Get a URI for |file| which has the image capture. This function assumes that path of |file| + * is based on the result of UiUtils.getDirectoryForImageCapture(). + * + * @param context The application context. + * @param file image capture file. + * @return URI for |file|. + */ + public static Uri getUriForImageCaptureFile(Context context, File file) { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 + ? ContentUriUtils.getContentUriFromFile(context, file) + : Uri.fromFile(file); + } + + /** + * @see android.view.Window#FEATURE_INDETERMINATE_PROGRESS + */ + public static void setWindowIndeterminateProgress(Window window) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + @SuppressWarnings("deprecation") + int featureNumber = Window.FEATURE_INDETERMINATE_PROGRESS; + + @SuppressWarnings("deprecation") + int featureValue = Window.PROGRESS_VISIBILITY_OFF; + + window.setFeatureInt(featureNumber, featureValue); + } + } + + /** + * Null-safe equivalent of {@code a.equals(b)}. + * + * @see Objects#equals(Object, Object) + */ + public static boolean objectEquals(Object a, Object b) { + return (a == null) ? (b == null) : a.equals(b); + } } diff --git a/base/android/java/src/org/chromium/base/ApplicationStatus.java b/base/android/java/src/org/chromium/base/ApplicationStatus.java index 37af12d..8d82ed7 100644 --- a/base/android/java/src/org/chromium/base/ApplicationStatus.java +++ b/base/android/java/src/org/chromium/base/ApplicationStatus.java @@ -4,11 +4,14 @@ package org.chromium.base; +import android.annotation.SuppressLint; import android.app.Activity; import android.app.Application; import android.app.Application.ActivityLifecycleCallbacks; import android.os.Bundle; +import org.chromium.base.ActivityState.ActivityStateEnum; +import org.chromium.base.ApplicationState.ApplicationStateEnum; import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.MainDex; @@ -34,6 +37,7 @@ public class ApplicationStatus { /** * @return The current {@link ActivityState} of the activity. */ + @ActivityStateEnum public int getStatus() { return mStatus; } @@ -41,7 +45,7 @@ public class ApplicationStatus { /** * @param status The new {@link ActivityState} of the activity. */ - public void setStatus(int status) { + public void setStatus(@ActivityStateEnum int status) { mStatus = status; } @@ -54,6 +58,7 @@ public class ApplicationStatus { } private static Object sCachedApplicationStateLock = new Object(); + @ApplicationStateEnum private static Integer sCachedApplicationState; /** Last activity that was shown (or null if none or it was destroyed). */ @@ -89,7 +94,7 @@ public class ApplicationStatus { * Called when the application's state changes. * @param newState The application state. */ - public void onApplicationStateChange(int newState); + public void onApplicationStateChange(@ApplicationStateEnum int newState); } /** @@ -101,7 +106,7 @@ public class ApplicationStatus { * @param activity The activity that had a state change. * @param newState New activity state. */ - public void onActivityStateChange(Activity activity, int newState); + public void onActivityStateChange(Activity activity, @ActivityStateEnum int newState); } private ApplicationStatus() {} @@ -170,7 +175,7 @@ public class ApplicationStatus { * @param activity Current activity. * @param newState New state value. */ - private static void onStateChange(Activity activity, int newState) { + private static void onStateChange(Activity activity, @ActivityStateEnum int newState) { if (activity == null) throw new IllegalArgumentException("null activity is not supported"); if (sActivity == null @@ -183,7 +188,13 @@ public class ApplicationStatus { int oldApplicationState = getStateForApplication(); if (newState == ActivityState.CREATED) { - assert !sActivityInfo.containsKey(activity); + // TODO(tedchoc): crbug/691100. The timing of application callback lifecycles were + // changed in O and the activity info may have been lazily created + // on first access to avoid a crash on startup. This should be removed + // once the new lifecycle APIs are available. + if (!BuildInfo.isAtLeastO()) { + assert !sActivityInfo.containsKey(activity); + } sActivityInfo.put(activity, new ActivityInfo()); } @@ -195,6 +206,13 @@ public class ApplicationStatus { ActivityInfo info = sActivityInfo.get(activity); info.setStatus(newState); + // Remove before calling listeners so that isEveryActivityDestroyed() returns false when + // this was the last activity. + if (newState == ActivityState.DESTROYED) { + sActivityInfo.remove(activity); + if (activity == sActivity) sActivity = null; + } + // Notify all state observers that are specifically listening to this activity. for (ActivityStateListener listener : info.getListeners()) { listener.onActivityStateChange(activity, newState); @@ -212,11 +230,6 @@ public class ApplicationStatus { listener.onApplicationStateChange(applicationState); } } - - if (newState == ActivityState.DESTROYED) { - sActivityInfo.remove(activity); - if (activity == sActivity) sActivity = null; - } } /** @@ -289,6 +302,7 @@ public class ApplicationStatus { * @param activity The activity whose state is to be returned. * @return The state of the specified activity (see {@link ActivityState}). */ + @ActivityStateEnum public static int getStateForActivity(Activity activity) { ActivityInfo info = sActivityInfo.get(activity); return info != null ? info.getStatus() : ActivityState.DESTROYED; @@ -297,6 +311,7 @@ public class ApplicationStatus { /** * @return The state of the application (see {@link ApplicationState}). */ + @ApplicationStateEnum @CalledByNative public static int getStateForApplication() { synchronized (sCachedApplicationStateLock) { @@ -343,11 +358,19 @@ public class ApplicationStatus { * @param listener Listener to receive state changes. * @param activity Activity to track or {@code null} to track all activities. */ + @SuppressLint("NewApi") public static void registerStateListenerForActivity(ActivityStateListener listener, Activity activity) { assert activity != null; ActivityInfo info = sActivityInfo.get(activity); + // TODO(tedchoc): crbug/691100. The timing of application callback lifecycles were changed + // in O and the activity info may need to be lazily created if the onCreate + // event has not yet been received. + if (BuildInfo.isAtLeastO() && info == null && !activity.isDestroyed()) { + info = new ActivityInfo(); + sActivityInfo.put(activity, info); + } assert info != null && info.getStatus() != ActivityState.DESTROYED; info.getListeners().addObserver(listener); } @@ -430,6 +453,7 @@ public class ApplicationStatus { * HAS_STOPPED_ACTIVITIES if none are running/paused and one is stopped. * HAS_DESTROYED_ACTIVITIES if none are running/paused/stopped. */ + @ApplicationStateEnum private static int determineApplicationState() { boolean hasPausedActivity = false; boolean hasStoppedActivity = false; @@ -454,5 +478,5 @@ public class ApplicationStatus { // Called to notify the native side of state changes. // IMPORTANT: This is always called on the main thread! - private static native void nativeOnApplicationStateChange(int newState); + private static native void nativeOnApplicationStateChange(@ApplicationStateEnum int newState); } diff --git a/base/android/java/src/org/chromium/base/BaseChromiumApplication.java b/base/android/java/src/org/chromium/base/BaseChromiumApplication.java index 44c69dc..6b97bdd 100644 --- a/base/android/java/src/org/chromium/base/BaseChromiumApplication.java +++ b/base/android/java/src/org/chromium/base/BaseChromiumApplication.java @@ -10,6 +10,7 @@ import android.content.Context; import android.os.Bundle; import android.view.Window; +import org.chromium.base.annotations.SuppressFBWarnings; import org.chromium.base.multidex.ChromiumMultiDexInstaller; import java.lang.reflect.InvocationHandler; @@ -21,8 +22,7 @@ import java.lang.reflect.Proxy; * Basic application functionality that should be shared among all browser applications. */ public class BaseChromiumApplication extends Application { - - private static final String TAG = "cr.base"; + private static final String TAG = "base"; private static final String TOOLBAR_CALLBACK_INTERNAL_WRAPPER_CLASS = "android.support.v7.internal.app.ToolbarActionBar$ToolbarCallbackWrapper"; // In builds using the --use_unpublished_apis flag, the ToolbarActionBar class name does not @@ -42,6 +42,8 @@ public class BaseChromiumApplication extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); + assert getBaseContext() != null; + checkAppBeingReplaced(); ChromiumMultiDexInstaller.install(this); } @@ -58,7 +60,7 @@ public class BaseChromiumApplication extends Application { } private ObserverList<WindowFocusChangedListener> mWindowFocusListeners = - new ObserverList<WindowFocusChangedListener>(); + new ObserverList<>(); /** * Intercepts calls to an existing Window.Callback. Most invocations are passed on directly @@ -144,6 +146,18 @@ public class BaseChromiumApplication extends Application { ((BaseChromiumApplication) context.getApplicationContext()).initCommandLine(); } + /** Ensure this application object is not out-of-date. */ + @SuppressFBWarnings("DM_EXIT") + private void checkAppBeingReplaced() { + // During app update the old apk can still be triggered by broadcasts and spin up an + // out-of-date application. Kill old applications in this bad state. See + // http://crbug.com/658130 for more context and http://b.android.com/56296 for the bug. + if (getResources() == null) { + Log.e(TAG, "getResources() null, closing app."); + System.exit(0); + } + } + /** Register hooks and listeners to start tracking the application status. */ private void startTrackingApplicationStatus() { ApplicationStatus.initialize(this); @@ -158,7 +172,7 @@ public class BaseChromiumApplication extends Application { @Override public void onActivityDestroyed(Activity activity) { - if (BuildConfig.IS_DEBUG) { + if (BuildConfig.DCHECK_IS_ON) { assert (Proxy.isProxyClass(activity.getWindow().getCallback().getClass()) || activity.getWindow().getCallback().getClass().getName().equals( TOOLBAR_CALLBACK_WRAPPER_CLASS) @@ -169,7 +183,7 @@ public class BaseChromiumApplication extends Application { @Override public void onActivityPaused(Activity activity) { - if (BuildConfig.IS_DEBUG) { + if (BuildConfig.DCHECK_IS_ON) { assert (Proxy.isProxyClass(activity.getWindow().getCallback().getClass()) || activity.getWindow().getCallback().getClass().getName().equals( TOOLBAR_CALLBACK_WRAPPER_CLASS) @@ -180,7 +194,7 @@ public class BaseChromiumApplication extends Application { @Override public void onActivityResumed(Activity activity) { - if (BuildConfig.IS_DEBUG) { + if (BuildConfig.DCHECK_IS_ON) { assert (Proxy.isProxyClass(activity.getWindow().getCallback().getClass()) || activity.getWindow().getCallback().getClass().getName().equals( TOOLBAR_CALLBACK_WRAPPER_CLASS) @@ -191,7 +205,7 @@ public class BaseChromiumApplication extends Application { @Override public void onActivitySaveInstanceState(Activity activity, Bundle outState) { - if (BuildConfig.IS_DEBUG) { + if (BuildConfig.DCHECK_IS_ON) { assert (Proxy.isProxyClass(activity.getWindow().getCallback().getClass()) || activity.getWindow().getCallback().getClass().getName().equals( TOOLBAR_CALLBACK_WRAPPER_CLASS) @@ -202,7 +216,7 @@ public class BaseChromiumApplication extends Application { @Override public void onActivityStarted(Activity activity) { - if (BuildConfig.IS_DEBUG) { + if (BuildConfig.DCHECK_IS_ON) { assert (Proxy.isProxyClass(activity.getWindow().getCallback().getClass()) || activity.getWindow().getCallback().getClass().getName().equals( TOOLBAR_CALLBACK_WRAPPER_CLASS) @@ -213,7 +227,7 @@ public class BaseChromiumApplication extends Application { @Override public void onActivityStopped(Activity activity) { - if (BuildConfig.IS_DEBUG) { + if (BuildConfig.DCHECK_IS_ON) { assert (Proxy.isProxyClass(activity.getWindow().getCallback().getClass()) || activity.getWindow().getCallback().getClass().getName().equals( TOOLBAR_CALLBACK_WRAPPER_CLASS) diff --git a/base/android/java/src/org/chromium/base/BuildInfo.java b/base/android/java/src/org/chromium/base/BuildInfo.java index ea6a019..141b62b 100644 --- a/base/android/java/src/org/chromium/base/BuildInfo.java +++ b/base/android/java/src/org/chromium/base/BuildInfo.java @@ -11,7 +11,6 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.os.Build; import android.os.StrictMode; -import android.util.Log; import org.chromium.base.annotations.CalledByNative; @@ -72,7 +71,7 @@ public class BuildInfo { PackageInfo packageInfo = packageManager.getPackageInfo("com.google.android.gms", 0); msg = Integer.toString(packageInfo.versionCode); } catch (NameNotFoundException e) { - Log.d(TAG, "GMS package is not found: %s", e); + Log.d(TAG, "GMS package is not found.", e); } return msg; } @@ -137,6 +136,13 @@ public class BuildInfo { return Build.TYPE; } + /** + * Check if this is a debuggable build of Android. Use this to enable developer-only features. + */ + public static boolean isDebugAndroid() { + return "eng".equals(Build.TYPE) || "userdebug".equals(Build.TYPE); + } + @CalledByNative public static int getSdkInt() { return Build.VERSION.SDK_INT; @@ -148,4 +154,21 @@ public class BuildInfo { public static boolean isGreaterThanN() { return Build.VERSION.SDK_INT > 24 || Build.VERSION.CODENAME.equals("NMR1"); } + + /** + * @return Whether the current device is running Android O release or newer. + */ + public static boolean isAtLeastO() { + return !"REL".equals(Build.VERSION.CODENAME) + && ("O".equals(Build.VERSION.CODENAME) || Build.VERSION.CODENAME.startsWith("OMR")); + } + + /** + * @return Whether the current app targets the SDK for at least O + */ + public static boolean targetsAtLeastO(Context appContext) { + return isAtLeastO() + && appContext.getApplicationInfo().targetSdkVersion + == Build.VERSION_CODES.CUR_DEVELOPMENT; + } } diff --git a/base/android/java/src/org/chromium/base/CommandLine.java b/base/android/java/src/org/chromium/base/CommandLine.java index efef22a..b6246f3 100644 --- a/base/android/java/src/org/chromium/base/CommandLine.java +++ b/base/android/java/src/org/chromium/base/CommandLine.java @@ -134,8 +134,8 @@ public abstract class CommandLine { * @param file The fully qualified command line file. */ public static void initFromFile(String file) { - // Arbitrary clamp of 8k on the amount of file we read in. - char[] buffer = readUtf8FileFully(file, 8 * 1024); + // Arbitrary clamp of 16k on the amount of file we read in. + char[] buffer = readUtf8FileFullyCrashIfTooBig(file, 16 * 1024); init(buffer == null ? null : tokenizeQuotedAruments(buffer)); } @@ -238,10 +238,10 @@ public abstract class CommandLine { /** * @param fileName the file to read in. * @param sizeLimit cap on the file size. - * @return Array of chars read from the file, or null if the file cannot be read - * or if its length exceeds |sizeLimit|. + * @return Array of chars read from the file, or null if the file cannot be read. + * @throws RuntimeException if the file size exceeds |sizeLimit|. */ - private static char[] readUtf8FileFully(String fileName, int sizeLimit) { + private static char[] readUtf8FileFullyCrashIfTooBig(String fileName, int sizeLimit) { Reader reader = null; File f = new File(fileName); long fileLength = f.length(); @@ -251,9 +251,8 @@ public abstract class CommandLine { } if (fileLength > sizeLimit) { - Log.w(TAG, "File " + fileName + " length " + fileLength + " exceeds limit " - + sizeLimit); - return null; + throw new RuntimeException( + "File " + fileName + " length " + fileLength + " exceeds limit " + sizeLimit); } try { diff --git a/base/android/java/src/org/chromium/base/CommandLineInitUtil.java b/base/android/java/src/org/chromium/base/CommandLineInitUtil.java index 6aa227c..bec9b40 100644 --- a/base/android/java/src/org/chromium/base/CommandLineInitUtil.java +++ b/base/android/java/src/org/chromium/base/CommandLineInitUtil.java @@ -51,7 +51,9 @@ public final class CommandLineInitUtil { public static void initCommandLine(Context context, String fileName) { if (!CommandLine.isInitialized()) { File commandLineFile = getAlternativeCommandLinePath(context, fileName); - if (commandLineFile == null) { + if (commandLineFile != null) { + Log.i(TAG, "Using alternative command line file in " + commandLineFile.getPath()); + } else { commandLineFile = new File(COMMAND_LINE_FILE_PATH, fileName); } CommandLine.initFromFile(commandLineFile.getPath()); @@ -59,7 +61,9 @@ public final class CommandLineInitUtil { } /** - * Use an alternative path if adb is enabled and this is the debug app. + * Use an alternative path if: + * - The current build is "eng" or "userdebug", OR + * - adb is enabled and this is the debug app. */ @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") private static File getAlternativeCommandLinePath(Context context, String fileName) { @@ -67,13 +71,15 @@ public final class CommandLineInitUtil { new File(COMMAND_LINE_FILE_PATH_DEBUG_APP, fileName); if (!alternativeCommandLineFile.exists()) return null; try { + if (BuildInfo.isDebugAndroid()) { + return alternativeCommandLineFile; + } + String debugApp = Build.VERSION.SDK_INT < 17 ? getDebugAppPreJBMR1(context) : getDebugAppJBMR1(context); if (debugApp != null && debugApp.equals(context.getApplicationContext().getPackageName())) { - Log.i(TAG, "Using alternative command line file in " - + alternativeCommandLineFile.getPath()); return alternativeCommandLineFile; } } catch (RuntimeException e) { diff --git a/base/android/java/src/org/chromium/base/ContentUriUtils.java b/base/android/java/src/org/chromium/base/ContentUriUtils.java index 5448aa0..9253f28 100644 --- a/base/android/java/src/org/chromium/base/ContentUriUtils.java +++ b/base/android/java/src/org/chromium/base/ContentUriUtils.java @@ -6,15 +6,20 @@ package org.chromium.base; import android.content.ContentResolver; import android.content.Context; +import android.content.res.AssetFileDescriptor; import android.database.Cursor; import android.net.Uri; +import android.os.Build; import android.os.ParcelFileDescriptor; +import android.provider.DocumentsContract; import android.util.Log; +import android.webkit.MimeTypeMap; import org.chromium.base.annotations.CalledByNative; import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; /** * This class provides methods to access content URI schemes. @@ -67,9 +72,9 @@ public abstract class ContentUriUtils { */ @CalledByNative public static int openContentUriForRead(Context context, String uriString) { - ParcelFileDescriptor pfd = getParcelFileDescriptor(context, uriString); - if (pfd != null) { - return pfd.detachFd(); + AssetFileDescriptor afd = getAssetFileDescriptor(context, uriString); + if (afd != null) { + return afd.getParcelFileDescriptor().detachFd(); } return -1; } @@ -83,7 +88,21 @@ public abstract class ContentUriUtils { */ @CalledByNative public static boolean contentUriExists(Context context, String uriString) { - return getParcelFileDescriptor(context, uriString) != null; + AssetFileDescriptor asf = null; + try { + asf = getAssetFileDescriptor(context, uriString); + return asf != null; + } finally { + // Do not use StreamUtil.closeQuietly here, as AssetFileDescriptor + // does not implement Closeable until KitKat. + if (asf != null) { + try { + asf.close(); + } catch (IOException e) { + // Closing quietly. + } + } + } } /** @@ -96,8 +115,11 @@ public abstract class ContentUriUtils { @CalledByNative public static String getMimeType(Context context, String uriString) { ContentResolver resolver = context.getContentResolver(); - if (resolver == null) return null; Uri uri = Uri.parse(uriString); + if (isVirtualDocument(uri, context)) { + String[] streamTypes = resolver.getStreamTypes(uri, "*/*"); + return (streamTypes != null && streamTypes.length > 0) ? streamTypes[0] : null; + } return resolver.getType(uri); } @@ -106,15 +128,36 @@ public abstract class ContentUriUtils { * * @param context {@link Context} in interest. * @param uriString the content URI to open. - * @return ParcelFileDescriptor of the content URI, or NULL if the file does not exist. + * @return AssetFileDescriptor of the content URI, or NULL if the file does not exist. */ - private static ParcelFileDescriptor getParcelFileDescriptor(Context context, String uriString) { + private static AssetFileDescriptor getAssetFileDescriptor(Context context, String uriString) { ContentResolver resolver = context.getContentResolver(); Uri uri = Uri.parse(uriString); - ParcelFileDescriptor pfd = null; try { - pfd = resolver.openFileDescriptor(uri, "r"); + if (isVirtualDocument(uri, context)) { + String[] streamTypes = resolver.getStreamTypes(uri, "*/*"); + if (streamTypes != null && streamTypes.length > 0) { + AssetFileDescriptor afd = + resolver.openTypedAssetFileDescriptor(uri, streamTypes[0], null); + if (afd.getStartOffset() != 0) { + // Do not use StreamUtil.closeQuietly here, as AssetFileDescriptor + // does not implement Closeable until KitKat. + try { + afd.close(); + } catch (IOException e) { + // Closing quietly. + } + throw new SecurityException("Cannot open files with non-zero offset type."); + } + return afd; + } + } else { + ParcelFileDescriptor pfd = resolver.openFileDescriptor(uri, "r"); + if (pfd != null) { + return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH); + } + } } catch (FileNotFoundException e) { Log.w(TAG, "Cannot find content uri: " + uriString, e); } catch (SecurityException e) { @@ -124,37 +167,103 @@ public abstract class ContentUriUtils { } catch (IllegalStateException e) { Log.w(TAG, "Unknown content uri: " + uriString, e); } - return pfd; + + return null; } /** * Method to resolve the display name of a content URI. * * @param uri the content URI to be resolved. - * @param contentResolver the content resolver to query. + * @param context {@link Context} in interest. * @param columnField the column field to query. * @return the display name of the @code uri if present in the database * or an empty string otherwise. */ - public static String getDisplayName( - Uri uri, ContentResolver contentResolver, String columnField) { - if (contentResolver == null || uri == null) return ""; + public static String getDisplayName(Uri uri, Context context, String columnField) { + if (uri == null) return ""; + ContentResolver contentResolver = context.getContentResolver(); Cursor cursor = null; try { cursor = contentResolver.query(uri, null, null, null, null); if (cursor != null && cursor.getCount() >= 1) { cursor.moveToFirst(); - int index = cursor.getColumnIndex(columnField); - if (index > -1) return cursor.getString(index); + int displayNameIndex = cursor.getColumnIndex(columnField); + if (displayNameIndex == -1) { + return ""; + } + String displayName = cursor.getString(displayNameIndex); + // For Virtual documents, try to modify the file extension so it's compatible + // with the alternative MIME type. + if (hasVirtualFlag(cursor)) { + String[] mimeTypes = contentResolver.getStreamTypes(uri, "*/*"); + if (mimeTypes != null && mimeTypes.length > 0) { + String ext = + MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeTypes[0]); + if (ext != null) { + // Just append, it's simpler and more secure than altering an + // existing extension. + displayName += "." + ext; + } + } + } + return displayName; } } catch (NullPointerException e) { // Some android models don't handle the provider call correctly. // see crbug.com/345393 return ""; } finally { - if (cursor != null) cursor.close(); + StreamUtil.closeQuietly(cursor); } return ""; } + + /** + * Checks whether the passed Uri represents a virtual document. + * + * @param uri the content URI to be resolved. + * @param contentResolver the content resolver to query. + * @return True for virtual file, false for any other file. + */ + private static boolean isVirtualDocument(Uri uri, Context context) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return false; + if (uri == null) return false; + if (!DocumentsContract.isDocumentUri(context, uri)) return false; + ContentResolver contentResolver = context.getContentResolver(); + Cursor cursor = null; + try { + cursor = contentResolver.query(uri, null, null, null, null); + + if (cursor != null && cursor.getCount() >= 1) { + cursor.moveToFirst(); + return hasVirtualFlag(cursor); + } + } catch (NullPointerException e) { + // Some android models don't handle the provider call correctly. + // see crbug.com/345393 + return false; + } finally { + StreamUtil.closeQuietly(cursor); + } + return false; + } + + /** + * Checks whether the passed cursor for a document has a virtual document flag. + * + * The called must close the passed cursor. + * + * @param cursor Cursor with COLUMN_FLAGS. + * @return True for virtual file, false for any other file. + */ + private static boolean hasVirtualFlag(Cursor cursor) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return false; + int index = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_FLAGS); + if (index > -1) { + return (cursor.getLong(index) & DocumentsContract.Document.FLAG_VIRTUAL_DOCUMENT) != 0; + } + return false; + } } diff --git a/base/android/java/src/org/chromium/base/ContextUtils.java b/base/android/java/src/org/chromium/base/ContextUtils.java index 4b615cb..448eff9 100644 --- a/base/android/java/src/org/chromium/base/ContextUtils.java +++ b/base/android/java/src/org/chromium/base/ContextUtils.java @@ -9,11 +9,13 @@ import android.content.SharedPreferences; import android.preference.PreferenceManager; import org.chromium.base.annotations.JNINamespace; +import org.chromium.base.annotations.MainDex; /** * This class provides Android application context related utility methods. */ @JNINamespace("base::android") +@MainDex public class ContextUtils { private static final String TAG = "ContextUtils"; private static Context sApplicationContext; diff --git a/base/android/java/src/org/chromium/base/FileUtils.java b/base/android/java/src/org/chromium/base/FileUtils.java index 2c0d8f5..2ad70dd 100644 --- a/base/android/java/src/org/chromium/base/FileUtils.java +++ b/base/android/java/src/org/chromium/base/FileUtils.java @@ -12,6 +12,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.List; /** * Helper methods for dealing with Files. @@ -37,6 +38,18 @@ public class FileUtils { } /** + * Delete the given files or directories by calling {@link #recursivelyDeleteFile(File)}. + * @param files The files to delete. + */ + public static void batchDeleteFiles(List<File> files) { + assert !ThreadUtils.runningOnUiThread(); + + for (File file : files) { + if (file.exists()) recursivelyDeleteFile(file); + } + } + + /** * Extracts an asset from the app's APK to a file. * @param context * @param assetName Name of the asset to extract. diff --git a/base/android/java/src/org/chromium/base/JNIUtils.java b/base/android/java/src/org/chromium/base/JNIUtils.java index f971b5e..3fcec91 100644 --- a/base/android/java/src/org/chromium/base/JNIUtils.java +++ b/base/android/java/src/org/chromium/base/JNIUtils.java @@ -12,6 +12,8 @@ import org.chromium.base.annotations.MainDex; */ @MainDex public class JNIUtils { + private static Boolean sSelectiveJniRegistrationEnabled; + /** * This returns a ClassLoader that is capable of loading Chromium Java code. Such a ClassLoader * is needed for the few cases where the JNI mechanism is unable to automatically determine the @@ -21,4 +23,24 @@ public class JNIUtils { public static Object getClassLoader() { return JNIUtils.class.getClassLoader(); } + + /** + * @return whether or not the current process supports selective JNI registration. + */ + @CalledByNative + public static boolean isSelectiveJniRegistrationEnabled() { + if (sSelectiveJniRegistrationEnabled == null) { + sSelectiveJniRegistrationEnabled = false; + } + return sSelectiveJniRegistrationEnabled; + } + + /** + * Allow this process to selectively perform JNI registration. This must be called before + * loading native libraries or it will have no effect. + */ + public static void enableSelectiveJniRegistration() { + assert sSelectiveJniRegistrationEnabled == null; + sSelectiveJniRegistrationEnabled = true; + } } diff --git a/base/android/java/src/org/chromium/base/LocaleUtils.java b/base/android/java/src/org/chromium/base/LocaleUtils.java index 5c26e7a..2f51455 100644 --- a/base/android/java/src/org/chromium/base/LocaleUtils.java +++ b/base/android/java/src/org/chromium/base/LocaleUtils.java @@ -4,9 +4,18 @@ package org.chromium.base; +import android.annotation.TargetApi; +import android.os.Build; +import android.os.LocaleList; +import android.text.TextUtils; + import org.chromium.base.annotations.CalledByNative; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.Locale; +import java.util.Map; /** * This class provides the locale related methods. @@ -18,41 +27,176 @@ public class LocaleUtils { private LocaleUtils() { } + private static final Map<String, String> LANGUAGE_MAP_FOR_CHROMIUM; + private static final Map<String, String> LANGUAGE_MAP_FOR_ANDROID; + + static { + // A variation of this mapping also exists in: + // build/android/gyp/package_resources.py + HashMap<String, String> mapForChromium = new HashMap<>(); + mapForChromium.put("iw", "he"); // Hebrew + mapForChromium.put("ji", "yi"); // Yiddish + mapForChromium.put("in", "id"); // Indonesian + mapForChromium.put("tl", "fil"); // Filipino + LANGUAGE_MAP_FOR_CHROMIUM = Collections.unmodifiableMap(mapForChromium); + } + + static { + HashMap<String, String> mapForAndroid = new HashMap<>(); + mapForAndroid.put("und", ""); // Undefined + mapForAndroid.put("fil", "tl"); // Filipino + LANGUAGE_MAP_FOR_ANDROID = Collections.unmodifiableMap(mapForAndroid); + } + /** - * @return the string for the given locale, translating - * Android deprecated language codes into the modern ones - * used by Chromium. + * Java keeps deprecated language codes for Hebrew, Yiddish and Indonesian but Chromium uses + * updated ones. Similarly, Android uses "tl" while Chromium uses "fil" for Tagalog/Filipino. + * So apply a mapping here. + * See http://developer.android.com/reference/java/util/Locale.html + * @return a updated language code for Chromium with given language string. */ - public static String getLocale(Locale locale) { - String language = locale.getLanguage(); - String country = locale.getCountry(); + public static String getUpdatedLanguageForChromium(String language) { + String updatedLanguageCode = LANGUAGE_MAP_FOR_CHROMIUM.get(language); + return updatedLanguageCode == null ? language : updatedLanguageCode; + } + + /** + * @return a locale with updated language codes for Chromium, with translated modern language + * codes used by Chromium. + */ + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + @VisibleForTesting + public static Locale getUpdatedLocaleForChromium(Locale locale) { + String languageForChrome = LANGUAGE_MAP_FOR_CHROMIUM.get(locale.getLanguage()); + if (languageForChrome == null) { + return locale; + } + return new Locale.Builder().setLocale(locale).setLanguage(languageForChrome).build(); + } + + /** + * Android uses "tl" while Chromium uses "fil" for Tagalog/Filipino. + * So apply a mapping here. + * See http://developer.android.com/reference/java/util/Locale.html + * @return a updated language code for Android with given language string. + */ + public static String getUpdatedLanguageForAndroid(String language) { + String updatedLanguageCode = LANGUAGE_MAP_FOR_ANDROID.get(language); + return updatedLanguageCode == null ? language : updatedLanguageCode; + } + + /** + * @return a locale with updated language codes for Android, from translated modern language + * codes used by Chromium. + */ + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + @VisibleForTesting + public static Locale getUpdatedLocaleForAndroid(Locale locale) { + String languageForAndroid = LANGUAGE_MAP_FOR_ANDROID.get(locale.getLanguage()); + if (languageForAndroid == null) { + return locale; + } + return new Locale.Builder().setLocale(locale).setLanguage(languageForAndroid).build(); + } + + /** + * This function creates a Locale object from xx-XX style string where xx is language code + * and XX is a country code. This works for API level lower than 21. + * @return the locale that best represents the language tag. + */ + public static Locale forLanguageTagCompat(String languageTag) { + String[] tag = languageTag.split("-"); + if (tag.length == 0) { + return new Locale(""); + } + String language = getUpdatedLanguageForAndroid(tag[0]); + if ((language.length() != 2 && language.length() != 3) || language.equals("und")) { + return new Locale(""); + } + if (tag.length == 1) { + return new Locale(language); + } + String country = tag[1]; + if (country.length() != 2 && country.length() != 3) { + return new Locale(language); + } + return new Locale(language, country); + } - // Android uses deprecated lanuages codes for Hebrew and Indonesian but Chromium uses the - // updated codes. Also, Android uses "tl" while Chromium uses "fil" for Tagalog/Filipino. - // So apply a mapping. - // See http://developer.android.com/reference/java/util/Locale.html - if ("iw".equals(language)) { - language = "he"; - } else if ("in".equals(language)) { - language = "id"; - } else if ("tl".equals(language)) { - language = "fil"; + /** + * This function creates a Locale object from xx-XX style string where xx is language code + * and XX is a country code. + * @return the locale that best represents the language tag. + */ + public static Locale forLanguageTag(String languageTag) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + Locale locale = Locale.forLanguageTag(languageTag); + return getUpdatedLocaleForAndroid(locale); + } + return forLanguageTagCompat(languageTag); + } + + /** + * Converts Locale object to the BCP 47 compliant string format. + * This works for API level lower than 24. + * + * Note that for Android M or before, we cannot use Locale.getLanguage() and + * Locale.toLanguageTag() for this purpose. Since Locale.getLanguage() returns deprecated + * language code even if the Locale object is constructed with updated language code. As for + * Locale.toLanguageTag(), it does a special conversion from deprecated language code to updated + * one, but it is only usable for Android N or after. + * @return a well-formed IETF BCP 47 language tag with language and country code that + * represents this locale. + */ + public static String toLanguageTag(Locale locale) { + String language = getUpdatedLanguageForChromium(locale.getLanguage()); + String country = locale.getCountry(); + if (language.equals("no") && country.equals("NO") && locale.getVariant().equals("NY")) { + return "nn-NO"; } return country.isEmpty() ? language : language + "-" + country; } /** - * @return the default locale, translating Android deprecated - * language codes into the modern ones used by Chromium. + * Converts LocaleList object to the comma separated BCP 47 compliant string format. + * + * @return a well-formed IETF BCP 47 language tag with language and country code that + * represents this locale list. + */ + @TargetApi(Build.VERSION_CODES.N) + public static String toLanguageTags(LocaleList localeList) { + ArrayList<String> newLocaleList = new ArrayList<>(); + for (int i = 0; i < localeList.size(); i++) { + Locale locale = getUpdatedLocaleForChromium(localeList.get(i)); + newLocaleList.add(toLanguageTag(locale)); + } + return TextUtils.join(",", newLocaleList); + } + + /** + * @return a comma separated language tags string that represents a default locale. + * Each language tag is well-formed IETF BCP 47 language tag with language and country + * code. */ @CalledByNative - public static String getDefaultLocale() { - return getLocale(Locale.getDefault()); + public static String getDefaultLocaleString() { + return toLanguageTag(Locale.getDefault()); + } + + /** + * @return a comma separated language tags string that represents a default locale or locales. + * Each language tag is well-formed IETF BCP 47 language tag with language and country + * code. + */ + public static String getDefaultLocaleListString() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + return toLanguageTags(LocaleList.getDefault()); + } + return getDefaultLocaleString(); } /** - * Get the default country code set during install. - * @return country code. + * @return The default country code set during install. */ @CalledByNative private static String getDefaultCountryCode() { diff --git a/base/android/java/src/org/chromium/base/Log.java b/base/android/java/src/org/chromium/base/Log.java index 8815e63..399f16d 100644 --- a/base/android/java/src/org/chromium/base/Log.java +++ b/base/android/java/src/org/chromium/base/Log.java @@ -347,6 +347,11 @@ public class Log { } } + /** Handy function to get a loggable stack trace from a Throwable. */ + public static String getStackTraceString(Throwable tr) { + return android.util.Log.getStackTraceString(tr); + } + private static Throwable getThrowableToLog(Object[] args) { if (args == null || args.length == 0) return null; diff --git a/base/android/java/src/org/chromium/base/ObserverList.java b/base/android/java/src/org/chromium/base/ObserverList.java index 7a2ab98..59276c6 100644 --- a/base/android/java/src/org/chromium/base/ObserverList.java +++ b/base/android/java/src/org/chromium/base/ObserverList.java @@ -21,7 +21,7 @@ import javax.annotation.concurrent.NotThreadSafe; * The implementation (and the interface) is heavily influenced by the C++ ObserverList. * Notable differences: * - The iterator implements NOTIFY_EXISTING_ONLY. - * - The FOR_EACH_OBSERVER closure is left to the clients to implement in terms of iterator(). + * - The range-based for loop is left to the clients to implement in terms of iterator(). * <p/> * This class is not threadsafe. Observers MUST be added, removed and will be notified on the same * thread this is created. @@ -44,9 +44,9 @@ public class ObserverList<E> implements Iterable<E> { } public final List<E> mObservers = new ArrayList<E>(); - private int mIterationDepth = 0; - private int mCount = 0; - private boolean mNeedsCompact = false; + private int mIterationDepth; + private int mCount; + private boolean mNeedsCompact; public ObserverList() {} @@ -190,8 +190,8 @@ public class ObserverList<E> implements Iterable<E> { private class ObserverListIterator implements RewindableIterator<E> { private int mListEndMarker; - private int mIndex = 0; - private boolean mIsExhausted = false; + private int mIndex; + private boolean mIsExhausted; private ObserverListIterator() { ObserverList.this.incrementIterationDepth(); diff --git a/base/android/java/src/org/chromium/base/PathUtils.java b/base/android/java/src/org/chromium/base/PathUtils.java index c3d3e7e..00977d5 100644 --- a/base/android/java/src/org/chromium/base/PathUtils.java +++ b/base/android/java/src/org/chromium/base/PathUtils.java @@ -34,13 +34,9 @@ public abstract class PathUtils { private static final AtomicBoolean sInitializationStarted = new AtomicBoolean(); private static AsyncTask<Void, Void, String[]> sDirPathFetchTask; - // In setPrivateDataDirectorySuffix(), we store the app's context. If the AsyncTask started in - // setPrivateDataDirectorySuffix() fails to complete by the time we need the values, we will - // need the context so that we can restart the task synchronously on the UI thread. - private static Context sDataDirectoryAppContext; - - // We also store the directory path suffix from setPrivateDataDirectorySuffix() for the same - // reason as above. + // If the AsyncTask started in setPrivateDataDirectorySuffix() fails to complete by the time we + // need the values, we will need the suffix so that we can restart the task synchronously on + // the UI thread. private static String sDataDirectorySuffix; // Prevent instantiation. @@ -101,13 +97,14 @@ public abstract class PathUtils { */ private static String[] setPrivateDataDirectorySuffixInternal() { String[] paths = new String[NUM_DIRECTORIES]; - paths[DATA_DIRECTORY] = sDataDirectoryAppContext.getDir(sDataDirectorySuffix, - Context.MODE_PRIVATE).getPath(); - paths[THUMBNAIL_DIRECTORY] = sDataDirectoryAppContext.getDir( + Context appContext = ContextUtils.getApplicationContext(); + paths[DATA_DIRECTORY] = appContext.getDir( + sDataDirectorySuffix, Context.MODE_PRIVATE).getPath(); + paths[THUMBNAIL_DIRECTORY] = appContext.getDir( THUMBNAIL_DIRECTORY_NAME, Context.MODE_PRIVATE).getPath(); - paths[DATABASE_DIRECTORY] = sDataDirectoryAppContext.getDatabasePath("foo").getParent(); - if (sDataDirectoryAppContext.getCacheDir() != null) { - paths[CACHE_DIRECTORY] = sDataDirectoryAppContext.getCacheDir().getPath(); + paths[DATABASE_DIRECTORY] = appContext.getDatabasePath("foo").getParent(); + if (appContext.getCacheDir() != null) { + paths[CACHE_DIRECTORY] = appContext.getCacheDir().getPath(); } return paths; } @@ -124,12 +121,12 @@ public abstract class PathUtils { * @param suffix The private data directory suffix. * @see Context#getDir(String, int) */ - public static void setPrivateDataDirectorySuffix(String suffix, Context context) { + public static void setPrivateDataDirectorySuffix(String suffix) { // This method should only be called once, but many tests end up calling it multiple times, // so adding a guard here. if (!sInitializationStarted.getAndSet(true)) { + assert ContextUtils.getApplicationContext() != null; sDataDirectorySuffix = suffix; - sDataDirectoryAppContext = context.getApplicationContext(); sDirPathFetchTask = new AsyncTask<Void, Void, String[]>() { @Override protected String[] doInBackground(Void... unused) { @@ -151,7 +148,7 @@ public abstract class PathUtils { * @return the private directory that is used to store application data. */ @CalledByNative - public static String getDataDirectory(Context appContext) { + public static String getDataDirectory() { assert sDirPathFetchTask != null : "setDataDirectorySuffix must be called first."; return getDirectoryPath(DATA_DIRECTORY); } @@ -160,7 +157,7 @@ public abstract class PathUtils { * @return the private directory that is used to store application database. */ @CalledByNative - public static String getDatabaseDirectory(Context appContext) { + public static String getDatabaseDirectory() { assert sDirPathFetchTask != null : "setDataDirectorySuffix must be called first."; return getDirectoryPath(DATABASE_DIRECTORY); } @@ -168,15 +165,14 @@ public abstract class PathUtils { /** * @return the cache directory. */ - @SuppressWarnings("unused") @CalledByNative - public static String getCacheDirectory(Context appContext) { + public static String getCacheDirectory() { assert sDirPathFetchTask != null : "setDataDirectorySuffix must be called first."; return getDirectoryPath(CACHE_DIRECTORY); } @CalledByNative - public static String getThumbnailCacheDirectory(Context appContext) { + public static String getThumbnailCacheDirectory() { assert sDirPathFetchTask != null : "setDataDirectorySuffix must be called first."; return getDirectoryPath(THUMBNAIL_DIRECTORY); } @@ -186,7 +182,7 @@ public abstract class PathUtils { */ @SuppressWarnings("unused") @CalledByNative - private static String getDownloadsDirectory(Context appContext) { + private static String getDownloadsDirectory() { // Temporarily allowing disk access while fixing. TODO: http://crbug.com/508615 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); String downloadsPath; @@ -207,8 +203,8 @@ public abstract class PathUtils { */ @SuppressWarnings("unused") @CalledByNative - private static String getNativeLibraryDirectory(Context appContext) { - ApplicationInfo ai = appContext.getApplicationInfo(); + private static String getNativeLibraryDirectory() { + ApplicationInfo ai = ContextUtils.getApplicationContext().getApplicationInfo(); if ((ai.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0 || (ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { return ai.nativeLibraryDir; diff --git a/base/android/java/src/org/chromium/base/PerfTraceEvent.java b/base/android/java/src/org/chromium/base/PerfTraceEvent.java index c0e4b21..8a87773 100644 --- a/base/android/java/src/org/chromium/base/PerfTraceEvent.java +++ b/base/android/java/src/org/chromium/base/PerfTraceEvent.java @@ -8,12 +8,12 @@ import android.os.Debug; import android.os.Debug.MemoryInfo; import android.util.Log; -import org.chromium.base.annotations.SuppressFBWarnings; - import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.chromium.base.annotations.SuppressFBWarnings; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -42,7 +42,7 @@ import java.util.List; public class PerfTraceEvent { private static final int MAX_NAME_LENGTH = 40; private static final String MEMORY_TRACE_NAME_SUFFIX = "_BZR_PSS"; - private static File sOutputFile = null; + private static File sOutputFile; /** The event types understood by the perf trace scripts. */ private enum EventType { @@ -63,9 +63,9 @@ public class PerfTraceEvent { } } - private static boolean sEnabled = false; + private static boolean sEnabled; private static boolean sTrackTiming = true; - private static boolean sTrackMemory = false; + private static boolean sTrackMemory; // A list of performance trace event strings. // Events are stored as a JSON dict much like TraceEvent. diff --git a/base/android/java/src/org/chromium/base/PowerMonitor.java b/base/android/java/src/org/chromium/base/PowerMonitor.java index 5d8fa0c..ae36a75 100644 --- a/base/android/java/src/org/chromium/base/PowerMonitor.java +++ b/base/android/java/src/org/chromium/base/PowerMonitor.java @@ -4,74 +4,61 @@ package org.chromium.base; +import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.BatteryManager; -import android.os.Handler; -import android.os.Looper; import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.JNINamespace; - /** * Integrates native PowerMonitor with the java side. */ @JNINamespace("base::android") -public class PowerMonitor implements ApplicationStatus.ApplicationStateListener { - private static final long SUSPEND_DELAY_MS = 1 * 60 * 1000; // 1 minute. - private static class LazyHolder { - private static final PowerMonitor INSTANCE = new PowerMonitor(); - } +public class PowerMonitor { private static PowerMonitor sInstance; private boolean mIsBatteryPower; - private final Handler mHandler = new Handler(Looper.getMainLooper()); - - // Asynchronous task used to fire the "paused" event to the native side 1 minute after the main - // activity transitioned to the "paused" state. This event is not sent immediately because it - // would be too aggressive. An Android activity can be in the "paused" state quite often. This - // can happen when a dialog window shows up for instance. - private static final Runnable sSuspendTask = new Runnable() { - @Override - public void run() { - nativeOnMainActivitySuspended(); - } - }; - public static void createForTests(Context context) { + public static void createForTests() { // Applications will create this once the JNI side has been fully wired up both sides. For // tests, we just need native -> java, that is, we don't need to notify java -> native on // creation. - sInstance = LazyHolder.INSTANCE; + sInstance = new PowerMonitor(); } /** * Create a PowerMonitor instance if none exists. - * @param context The context to register broadcast receivers for. The application context - * will be used from this parameter. */ - public static void create(Context context) { - context = context.getApplicationContext(); - if (sInstance == null) { - sInstance = LazyHolder.INSTANCE; - ApplicationStatus.registerApplicationStateListener(sInstance); - IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); - Intent batteryStatusIntent = context.registerReceiver(null, ifilter); - if (batteryStatusIntent != null) onBatteryChargingChanged(batteryStatusIntent); - } + public static void create() { + ThreadUtils.assertOnUiThread(); + + if (sInstance != null) return; + + Context context = ContextUtils.getApplicationContext(); + sInstance = new PowerMonitor(); + IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); + Intent batteryStatusIntent = context.registerReceiver(null, ifilter); + if (batteryStatusIntent != null) onBatteryChargingChanged(batteryStatusIntent); + + IntentFilter powerConnectedFilter = new IntentFilter(); + powerConnectedFilter.addAction(Intent.ACTION_POWER_CONNECTED); + powerConnectedFilter.addAction(Intent.ACTION_POWER_DISCONNECTED); + context.registerReceiver(new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + PowerMonitor.onBatteryChargingChanged(intent); + } + }, powerConnectedFilter); } private PowerMonitor() { } - public static void onBatteryChargingChanged(Intent intent) { - if (sInstance == null) { - // We may be called by the framework intent-filter before being fully initialized. This - // is not a problem, since our constructor will check for the state later on. - return; - } + private static void onBatteryChargingChanged(Intent intent) { + assert sInstance != null; int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); // If we're not plugged, assume we're running on battery power. sInstance.mIsBatteryPower = chargePlug != BatteryManager.BATTERY_PLUGGED_USB @@ -79,23 +66,15 @@ public class PowerMonitor implements ApplicationStatus.ApplicationStateListener nativeOnBatteryChargingChanged(); } - @Override - public void onApplicationStateChange(int newState) { - if (newState == ApplicationState.HAS_RUNNING_ACTIVITIES) { - // Remove the callback from the message loop in case it hasn't been executed yet. - mHandler.removeCallbacks(sSuspendTask); - nativeOnMainActivityResumed(); - } else if (newState == ApplicationState.HAS_PAUSED_ACTIVITIES) { - mHandler.postDelayed(sSuspendTask, SUSPEND_DELAY_MS); - } - } - @CalledByNative private static boolean isBatteryPower() { + // Creation of the PowerMonitor can be deferred based on the browser startup path. If the + // battery power is requested prior to the browser triggering the creation, force it to be + // created now. + if (sInstance == null) create(); + return sInstance.mIsBatteryPower; } private static native void nativeOnBatteryChargingChanged(); - private static native void nativeOnMainActivitySuspended(); - private static native void nativeOnMainActivityResumed(); } diff --git a/base/android/java/src/org/chromium/base/PowerStatusReceiver.java b/base/android/java/src/org/chromium/base/PowerStatusReceiver.java deleted file mode 100644 index 904a740..0000000 --- a/base/android/java/src/org/chromium/base/PowerStatusReceiver.java +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 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. - -package org.chromium.base; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; - - -/** - * A BroadcastReceiver that listens to changes in power status and notifies - * PowerMonitor. - * It's instantiated by the framework via the application intent-filter - * declared in its manifest. - */ -public class PowerStatusReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - PowerMonitor.onBatteryChargingChanged(intent); - } -} diff --git a/base/android/java/src/org/chromium/base/ResourceExtractor.java b/base/android/java/src/org/chromium/base/ResourceExtractor.java index 2854b02..c1d1856 100644 --- a/base/android/java/src/org/chromium/base/ResourceExtractor.java +++ b/base/android/java/src/org/chromium/base/ResourceExtractor.java @@ -4,18 +4,12 @@ package org.chromium.base; -import android.annotation.TargetApi; -import android.content.Context; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.AsyncTask; -import android.os.Build; import android.os.Handler; import android.os.Looper; -import android.os.Trace; - -import org.chromium.base.annotations.SuppressFBWarnings; import java.io.File; import java.io.FileOutputStream; @@ -23,7 +17,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; @@ -38,23 +34,7 @@ public class ResourceExtractor { private static final String V8_NATIVES_DATA_FILENAME = "natives_blob.bin"; private static final String V8_SNAPSHOT_DATA_FILENAME = "snapshot_blob.bin"; private static final String APP_VERSION_PREF = "org.chromium.base.ResourceExtractor.Version"; - - private static ResourceEntry[] sResourcesToExtract = new ResourceEntry[0]; - - /** - * Holds information about a res/raw file (e.g. locale .pak files). - */ - public static final class ResourceEntry { - public final int resourceId; - public final String pathWithinApk; - public final String extractedFileName; - - public ResourceEntry(int resourceId, String pathWithinApk, String extractedFileName) { - this.resourceId = resourceId; - this.pathWithinApk = pathWithinApk; - this.extractedFileName = extractedFileName; - } - } + private static final String FALLBACK_LOCALE = "en-US"; private class ExtractTask extends AsyncTask<Void, Void, Void> { private static final int BUFFER_SIZE = 16 * 1024; @@ -92,12 +72,12 @@ public class ResourceExtractor { return; } - beginTraceSection("checkPakTimeStamp"); + TraceEvent.begin("checkPakTimeStamp"); long curAppVersion = getApkVersion(); SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences(); long prevAppVersion = sharedPrefs.getLong(APP_VERSION_PREF, 0); boolean versionChanged = curAppVersion != prevAppVersion; - endTraceSection(); + TraceEvent.end("checkPakTimeStamp"); if (versionChanged) { deleteFiles(); @@ -107,23 +87,23 @@ public class ResourceExtractor { sharedPrefs.edit().putLong(APP_VERSION_PREF, curAppVersion).apply(); } - beginTraceSection("WalkAssets"); + TraceEvent.begin("WalkAssets"); byte[] buffer = new byte[BUFFER_SIZE]; try { - for (ResourceEntry entry : sResourcesToExtract) { - File output = new File(outputDir, entry.extractedFileName); + for (String assetName : mAssetsToExtract) { + File output = new File(outputDir, assetName); // TODO(agrieve): It would be better to check that .length == expectedLength. // http://crbug.com/606413 if (output.length() != 0) { continue; } - beginTraceSection("ExtractResource"); - InputStream inputStream = mContext.getResources().openRawResource( - entry.resourceId); + TraceEvent.begin("ExtractResource"); + InputStream inputStream = + ContextUtils.getApplicationContext().getAssets().open(assetName); try { extractResourceHelper(inputStream, output, buffer); } finally { - endTraceSection(); // ExtractResource + TraceEvent.end("ExtractResource"); } } } catch (IOException e) { @@ -131,25 +111,21 @@ public class ResourceExtractor { // Try to recover here, can we try again after deleting files instead of // returning null? It might be useful to gather UMA here too to track if // this happens with regularity. - Log.w(TAG, "Exception unpacking required pak resources: %s", e.getMessage()); + Log.w(TAG, "Exception unpacking required pak asset: %s", e.getMessage()); deleteFiles(); return; } finally { - endTraceSection(); // WalkAssets + TraceEvent.end("WalkAssets"); } } @Override protected Void doInBackground(Void... unused) { - // TODO(lizeb): Use chrome tracing here (and above in - // doInBackgroundImpl) when it will be possible. This is currently - // not doable since the native library is not loaded yet, and the - // TraceEvent calls are dropped before this point. - beginTraceSection("ResourceExtractor.ExtractTask.doInBackground"); + TraceEvent.begin("ResourceExtractor.ExtractTask.doInBackground"); try { doInBackgroundImpl(); } finally { - endTraceSection(); + TraceEvent.end("ResourceExtractor.ExtractTask.doInBackground"); } return null; } @@ -163,64 +139,60 @@ public class ResourceExtractor { @Override protected void onPostExecute(Void result) { - beginTraceSection("ResourceExtractor.ExtractTask.onPostExecute"); + TraceEvent.begin("ResourceExtractor.ExtractTask.onPostExecute"); try { onPostExecuteImpl(); } finally { - endTraceSection(); + TraceEvent.end("ResourceExtractor.ExtractTask.onPostExecute"); } } /** Returns a number that is different each time the apk changes. */ private long getApkVersion() { - PackageManager pm = mContext.getPackageManager(); + PackageManager pm = ContextUtils.getApplicationContext().getPackageManager(); try { - // More appropriate would be versionCode, but it doesn't change while developing. - PackageInfo pi = pm.getPackageInfo(mContext.getPackageName(), 0); - return pi.lastUpdateTime; + // Use lastUpdateTime since versionCode does not change when developing locally, + // but also use versionCode since it is possible for Chrome to be updated without + // the lastUpdateTime being changed (http://crbug.org/673458). + PackageInfo pi = + pm.getPackageInfo(ContextUtils.getApplicationContext().getPackageName(), 0); + // Xor'ing versionCode into upper half of the long to ensure it doesn't somehow + // exactly offset an increase in time. + return pi.lastUpdateTime ^ (((long) pi.versionCode) << 32); } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException(e); } } - - @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) - private void beginTraceSection(String section) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) return; - Trace.beginSection(section); - } - - @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) - private void endTraceSection() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) return; - Trace.endSection(); - } } - private final Context mContext; private ExtractTask mExtractTask; + private final String[] mAssetsToExtract = detectFilesToExtract(); private static ResourceExtractor sInstance; - public static ResourceExtractor get(Context context) { + public static ResourceExtractor get() { if (sInstance == null) { - sInstance = new ResourceExtractor(context); + sInstance = new ResourceExtractor(); } return sInstance; } - /** - * Specifies the files that should be extracted from the APK. - * and moved to {@link #getOutputDir()}. - */ - @SuppressFBWarnings("EI_EXPOSE_STATIC_REP2") - public static void setResourcesToExtract(ResourceEntry[] entries) { - assert (sInstance == null || sInstance.mExtractTask == null) - : "Must be called before startExtractingResources is called"; - sResourcesToExtract = entries; - } - - private ResourceExtractor(Context context) { - mContext = context.getApplicationContext(); + private static String[] detectFilesToExtract() { + Locale defaultLocale = Locale.getDefault(); + String language = LocaleUtils.getUpdatedLanguageForChromium(defaultLocale.getLanguage()); + // Currenty (Oct 2016), this array can be as big as 4 entries, so using a capacity + // that allows a bit of growth, but is still in the right ballpark.. + ArrayList<String> activeLocalePakFiles = new ArrayList<String>(6); + for (String locale : BuildConfig.COMPRESSED_LOCALES) { + if (locale.startsWith(language)) { + activeLocalePakFiles.add(locale + ".pak"); + } + } + if (activeLocalePakFiles.isEmpty() && BuildConfig.COMPRESSED_LOCALES.length > 0) { + assert Arrays.asList(BuildConfig.COMPRESSED_LOCALES).contains(FALLBACK_LOCALE); + activeLocalePakFiles.add(FALLBACK_LOCALE + ".pak"); + } + return activeLocalePakFiles.toArray(new String[activeLocalePakFiles.size()]); } /** @@ -301,7 +273,7 @@ public class ResourceExtractor { } private File getAppDataDir() { - return new File(PathUtils.getDataDirectory(mContext)); + return new File(PathUtils.getDataDirectory()); } private File getOutputDir() { @@ -348,6 +320,6 @@ public class ResourceExtractor { * Pak extraction not necessarily required by the embedder. */ private static boolean shouldSkipPakExtraction() { - return sResourcesToExtract.length == 0; + return get().mAssetsToExtract.length == 0; } } diff --git a/base/android/java/src/org/chromium/base/SecureRandomInitializer.java b/base/android/java/src/org/chromium/base/SecureRandomInitializer.java index 457e2ef..294b1e6 100644 --- a/base/android/java/src/org/chromium/base/SecureRandomInitializer.java +++ b/base/android/java/src/org/chromium/base/SecureRandomInitializer.java @@ -4,6 +4,8 @@ package org.chromium.base; +import android.annotation.SuppressLint; + import java.io.FileInputStream; import java.io.IOException; import java.security.SecureRandom; @@ -13,30 +15,25 @@ import java.security.SecureRandom; * <= 4.3. See * {@link http://android-developers.blogspot.com/2013/08/some-securerandom-thoughts.html}. */ +// TODO(crbug.com/635567): Fix this properly. +@SuppressLint("SecureRandom") public class SecureRandomInitializer { private static final int NUM_RANDOM_BYTES = 16; - private static byte[] sSeedBytes = new byte[NUM_RANDOM_BYTES]; - /** * Safely initializes the random number generator, by seeding it with data from /dev/urandom. */ public static void initialize(SecureRandom generator) throws IOException { FileInputStream fis = null; try { + byte[] seedBytes = new byte[NUM_RANDOM_BYTES]; fis = new FileInputStream("/dev/urandom"); - if (fis.read(sSeedBytes) != sSeedBytes.length) { + if (fis.read(seedBytes) != seedBytes.length) { throw new IOException("Failed to get enough random data."); } - generator.setSeed(sSeedBytes); + generator.setSeed(seedBytes); } finally { - try { - if (fis != null) { - fis.close(); - } - } catch (IOException e) { - // Ignore exception closing the device. - } + StreamUtil.closeQuietly(fis); } } } diff --git a/base/android/java/src/org/chromium/base/SysUtils.java b/base/android/java/src/org/chromium/base/SysUtils.java index 04a8332..5ab77df 100644 --- a/base/android/java/src/org/chromium/base/SysUtils.java +++ b/base/android/java/src/org/chromium/base/SysUtils.java @@ -4,6 +4,9 @@ package org.chromium.base; +import android.content.Context; +import android.content.pm.PackageManager; +import android.os.Build; import android.os.StrictMode; import android.util.Log; @@ -99,6 +102,24 @@ public class SysUtils { return sLowEndDevice.booleanValue(); } + /** + * Resets the cached value, if any. + */ + @VisibleForTesting + public static void reset() { + sLowEndDevice = null; + } + + public static boolean hasCamera(final Context context) { + final PackageManager pm = context.getPackageManager(); + // JellyBean support. + boolean hasCamera = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + hasCamera |= pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY); + } + return hasCamera; + } + private static boolean detectLowEndDevice() { assert CommandLine.isInitialized(); if (CommandLine.getInstance().hasSwitch(BaseSwitches.ENABLE_LOW_END_DEVICE_MODE)) { diff --git a/base/android/java/src/org/chromium/base/SystemMessageHandler.java b/base/android/java/src/org/chromium/base/SystemMessageHandler.java index ebcc0d9..abfa2d8 100644 --- a/base/android/java/src/org/chromium/base/SystemMessageHandler.java +++ b/base/android/java/src/org/chromium/base/SystemMessageHandler.java @@ -25,10 +25,12 @@ class SystemMessageHandler extends Handler { // Native class pointer set by the constructor of the SharedClient native class. private long mMessagePumpDelegateNative = 0; + private long mMessagePumpNative = 0; private long mDelayedScheduledTimeTicks = 0; - private SystemMessageHandler(long messagePumpDelegateNative) { + protected SystemMessageHandler(long messagePumpDelegateNative, long messagePumpNative) { mMessagePumpDelegateNative = messagePumpDelegateNative; + mMessagePumpNative = messagePumpNative; } @Override @@ -36,7 +38,8 @@ class SystemMessageHandler extends Handler { if (msg.what == DELAYED_SCHEDULED_WORK) { mDelayedScheduledTimeTicks = 0; } - nativeDoRunLoopOnce(mMessagePumpDelegateNative, mDelayedScheduledTimeTicks); + nativeDoRunLoopOnce( + mMessagePumpDelegateNative, mMessagePumpNative, mDelayedScheduledTimeTicks); } @SuppressWarnings("unused") @@ -153,10 +156,11 @@ class SystemMessageHandler extends Handler { } @CalledByNative - private static SystemMessageHandler create(long messagePumpDelegateNative) { - return new SystemMessageHandler(messagePumpDelegateNative); + private static SystemMessageHandler create( + long messagePumpDelegateNative, long messagePumpNative) { + return new SystemMessageHandler(messagePumpDelegateNative, messagePumpNative); } private native void nativeDoRunLoopOnce( - long messagePumpDelegateNative, long delayedScheduledTimeTicks); + long messagePumpDelegateNative, long messagePumpNative, long delayedScheduledTimeTicks); } diff --git a/base/android/java/src/org/chromium/base/ThreadUtils.java b/base/android/java/src/org/chromium/base/ThreadUtils.java index ef2887a..737d7f6 100644 --- a/base/android/java/src/org/chromium/base/ThreadUtils.java +++ b/base/android/java/src/org/chromium/base/ThreadUtils.java @@ -34,6 +34,11 @@ public class ThreadUtils { @VisibleForTesting public static void setUiThread(Looper looper) { synchronized (sLock) { + if (looper == null) { + // Used to reset the looper after tests. + sUiThreadHandler = null; + return; + } if (sUiThreadHandler != null && sUiThreadHandler.getLooper() != looper) { throw new RuntimeException("UI thread looper is already set to " + sUiThreadHandler.getLooper() + " (Main thread looper is " @@ -189,7 +194,9 @@ public class ThreadUtils { * Asserts that the current thread is running on the main thread. */ public static void assertOnUiThread() { - assert runningOnUiThread(); + if (BuildConfig.DCHECK_IS_ON && !runningOnUiThread()) { + throw new IllegalStateException("Must be called on the Ui thread."); + } } /** diff --git a/base/android/java/src/org/chromium/base/TraceEvent.java b/base/android/java/src/org/chromium/base/TraceEvent.java index 878275c..71bfac1 100644 --- a/base/android/java/src/org/chromium/base/TraceEvent.java +++ b/base/android/java/src/org/chromium/base/TraceEvent.java @@ -12,18 +12,19 @@ import android.util.Printer; import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.JNINamespace; +import org.chromium.base.annotations.MainDex; /** * Java mirror of Chrome trace event API. See base/trace_event/trace_event.h. Unlike the native * version, Java does not have stack objects, so a TRACE_EVENT() which does both TRACE_EVENT_BEGIN() * and TRACE_EVENT_END() in ctor/dtor is not possible. - * It is OK to use tracing before the native library has loaded, but such traces will - * be ignored. (Perhaps we could devise to buffer them up in future?). + * It is OK to use tracing before the native library has loaded, in a slightly restricted fashion. + * @see EarlyTraceEvent for details. */ @JNINamespace("base::android") +@MainDex public class TraceEvent { - - private static volatile boolean sEnabled = false; - private static volatile boolean sATraceEnabled = false; // True when taking an Android systrace. + private static volatile boolean sEnabled; + private static volatile boolean sATraceEnabled; // True when taking an Android systrace. private static class BasicLooperMonitor implements Printer { @Override @@ -82,14 +83,14 @@ public class TraceEvent { MIN_INTERESTING_DURATION_MILLIS * 3; // Stats tracking - private long mLastIdleStartedAt = 0L; - private long mLastWorkStartedAt = 0L; - private int mNumTasksSeen = 0; - private int mNumIdlesSeen = 0; - private int mNumTasksSinceLastIdle = 0; + private long mLastIdleStartedAt; + private long mLastWorkStartedAt; + private int mNumTasksSeen; + private int mNumIdlesSeen; + private int mNumTasksSinceLastIdle; // State - private boolean mIdleMonitorAttached = false; + private boolean mIdleMonitorAttached; // Called from within the begin/end methods only. // This method can only execute on the looper thread, because that is @@ -179,11 +180,26 @@ public class TraceEvent { */ @CalledByNative public static void setEnabled(boolean enabled) { - sEnabled = enabled; - // Android M+ systrace logs this on its own. Only log it if not writing to Android systrace. - if (sATraceEnabled) return; - ThreadUtils.getUiThreadLooper().setMessageLogging( - enabled ? LooperMonitorHolder.sInstance : null); + if (enabled) EarlyTraceEvent.disable(); + // Only disable logging if Chromium enabled it originally, so as to not disrupt logging done + // by other applications + if (sEnabled != enabled) { + sEnabled = enabled; + // Android M+ systrace logs this on its own. Only log it if not writing to Android + // systrace. + if (sATraceEnabled) return; + ThreadUtils.getUiThreadLooper().setMessageLogging( + enabled ? LooperMonitorHolder.sInstance : null); + } + } + + /** + * May enable early tracing depending on the environment. + * + * Must be called after the command-line has been read. + */ + public static void maybeEnableEarlyTracing() { + EarlyTraceEvent.maybeEnable(); } /** @@ -254,7 +270,7 @@ public class TraceEvent { * @param name The name of the event. */ public static void begin(String name) { - if (sEnabled) nativeBegin(name, null); + begin(name, null); } /** @@ -263,6 +279,7 @@ public class TraceEvent { * @param arg The arguments of the event. */ public static void begin(String name, String arg) { + EarlyTraceEvent.begin(name); if (sEnabled) nativeBegin(name, arg); } @@ -271,7 +288,7 @@ public class TraceEvent { * @param name The name of the event. */ public static void end(String name) { - if (sEnabled) nativeEnd(name, null); + end(name, null); } /** @@ -280,6 +297,7 @@ public class TraceEvent { * @param arg The arguments of the event. */ public static void end(String name, String arg) { + EarlyTraceEvent.end(name); if (sEnabled) nativeEnd(name, arg); } diff --git a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java index f6bf867..d3e0fb9 100644 --- a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java +++ b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java @@ -4,6 +4,7 @@ package org.chromium.base.library_loader; +import android.annotation.SuppressLint; import android.content.Context; import android.os.AsyncTask; import android.os.SystemClock; @@ -12,8 +13,10 @@ import org.chromium.base.CommandLine; import org.chromium.base.ContextUtils; import org.chromium.base.Log; import org.chromium.base.TraceEvent; +import org.chromium.base.VisibleForTesting; import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.JNINamespace; +import org.chromium.base.annotations.MainDex; import org.chromium.base.metrics.RecordHistogram; import java.util.concurrent.atomic.AtomicBoolean; @@ -35,6 +38,7 @@ import javax.annotation.Nullable; * the native counterpart to this class. */ @JNINamespace("base::android") +@MainDex public class LibraryLoader { private static final String TAG = "LibraryLoader"; @@ -129,18 +133,14 @@ public class LibraryLoader { /** * This method blocks until the library is fully loaded and initialized. - * - * @param context The context in which the method is called. */ - public void ensureInitialized(Context context) throws ProcessInitException { - // TODO(wnwen): Move this call appropriately down to the tests that need it. - ContextUtils.initApplicationContext(context.getApplicationContext()); + public void ensureInitialized() throws ProcessInitException { synchronized (sLock) { if (mInitialized) { // Already initialized, nothing to do. return; } - loadAlreadyLocked(context); + loadAlreadyLocked(ContextUtils.getApplicationContext()); initializeAlreadyLocked(); } } @@ -159,13 +159,26 @@ public class LibraryLoader { * this is called on will be the thread that runs the native code's static initializers. * See the comment in doInBackground() for more considerations on this. * - * @param context The context the code is running. - * * @throws ProcessInitException if the native library failed to load. */ - public void loadNow(Context context) throws ProcessInitException { + public void loadNow() throws ProcessInitException { + loadNowOverrideApplicationContext(ContextUtils.getApplicationContext()); + } + + /** + * Override kept for callers that need to load from a different app context. Do not use unless + * specifically required to load from another context that is not the current process's app + * context. + * + * @param appContext The overriding app context to be used to load libraries. + * @throws ProcessInitException if the native library failed to load with this context. + */ + public void loadNowOverrideApplicationContext(Context appContext) throws ProcessInitException { synchronized (sLock) { - loadAlreadyLocked(context); + if (mLoaded && appContext != ContextUtils.getApplicationContext()) { + throw new IllegalStateException("Attempt to load again from alternate context."); + } + loadAlreadyLocked(appContext); } } @@ -197,7 +210,10 @@ public class LibraryLoader { TraceEvent.begin("LibraryLoader.asyncPrefetchLibrariesToMemory"); int percentage = nativePercentageOfResidentNativeLibraryCode(); boolean success = false; - if (coldStart) { + // Arbitrary percentage threshold. If most of the native library is already + // resident (likely with monochrome), don't bother creating a prefetch process. + boolean prefetch = coldStart && percentage < 90; + if (prefetch) { success = nativeForkAndPrefetchNativeLibrary(); if (!success) { Log.w(TAG, "Forking a process to prefetch the native library failed."); @@ -206,7 +222,7 @@ public class LibraryLoader { // As this runs in a background thread, it can be called before histograms are // initialized. In this instance, histograms are dropped. RecordHistogram.initialize(); - if (coldStart) { + if (prefetch) { RecordHistogram.recordBooleanHistogram("LibraryLoader.PrefetchStatus", success); } if (percentage != -1) { @@ -247,7 +263,9 @@ public class LibraryLoader { // Invoke either Linker.loadLibrary(...) or System.loadLibrary(...), triggering // JNI_OnLoad in native code - private void loadAlreadyLocked(Context context) throws ProcessInitException { + // TODO(crbug.com/635567): Fix this properly. + @SuppressLint("DefaultLocale") + private void loadAlreadyLocked(Context appContext) throws ProcessInitException { try { if (!mLoaded) { assert !mInitialized; @@ -273,25 +291,35 @@ public class LibraryLoader { String libFilePath = System.mapLibraryName(library); if (Linker.isInZipFile()) { // Load directly from the APK. - zipFilePath = context.getApplicationInfo().sourceDir; + zipFilePath = appContext.getApplicationInfo().sourceDir; Log.i(TAG, "Loading " + library + " from within " + zipFilePath); } else { // The library is in its own file. Log.i(TAG, "Loading " + library); } - // Load the library using this Linker. May throw UnsatisfiedLinkError. - loadLibrary(linker, zipFilePath, libFilePath); + try { + // Load the library using this Linker. May throw UnsatisfiedLinkError. + loadLibrary(linker, zipFilePath, libFilePath); + } catch (UnsatisfiedLinkError e) { + Log.e(TAG, "Unable to load library: " + library); + throw(e); + } } linker.finishLibraryLoad(); } else { if (sLibraryPreloader != null) { - mLibraryPreloaderStatus = sLibraryPreloader.loadLibrary(context); + mLibraryPreloaderStatus = sLibraryPreloader.loadLibrary(appContext); } // Load libraries using the system linker. for (String library : NativeLibraries.LIBRARIES) { - System.loadLibrary(library); + try { + System.loadLibrary(library); + } catch (UnsatisfiedLinkError e) { + Log.e(TAG, "Unable to load library: " + library); + throw(e); + } } } @@ -307,21 +335,6 @@ public class LibraryLoader { } catch (UnsatisfiedLinkError e) { throw new ProcessInitException(LoaderErrors.LOADER_ERROR_NATIVE_LIBRARY_LOAD_FAILED, e); } - // Check that the version of the library we have loaded matches the version we expect - Log.i(TAG, String.format( - "Expected native library version number \"%s\", " - + "actual native library version number \"%s\"", - NativeLibraries.sVersionNumber, - nativeGetVersionNumber())); - if (!NativeLibraries.sVersionNumber.equals(nativeGetVersionNumber())) { - throw new ProcessInitException(LoaderErrors.LOADER_ERROR_NATIVE_LIBRARY_WRONG_VERSION); - } - } - - // Returns whether the given split name is that of the ABI split. - private static boolean isAbiSplit(String splitName) { - // The split name for the ABI split is manually set in the build rules. - return splitName.startsWith("abi_"); } // The WebView requires the Command Line to be switched over before @@ -363,6 +376,14 @@ public class LibraryLoader { throw new ProcessInitException(LoaderErrors.LOADER_ERROR_FAILED_TO_REGISTER_JNI); } + // Check that the version of the library we have loaded matches the version we expect + Log.i(TAG, String.format("Expected native library version number \"%s\", " + + "actual native library version number \"%s\"", + NativeLibraries.sVersionNumber, nativeGetVersionNumber())); + if (!NativeLibraries.sVersionNumber.equals(nativeGetVersionNumber())) { + throw new ProcessInitException(LoaderErrors.LOADER_ERROR_NATIVE_LIBRARY_WRONG_VERSION); + } + // From now on, keep tracing in sync with native. TraceEvent.registerNativeEnabledObserver(); @@ -375,18 +396,19 @@ public class LibraryLoader { } // Called after all native initializations are complete. - public void onNativeInitializationComplete(Context context) { - recordBrowserProcessHistogram(context); + public void onNativeInitializationComplete() { + recordBrowserProcessHistogram(); } // Record Chromium linker histogram state for the main browser process. Called from // onNativeInitializationComplete(). - private void recordBrowserProcessHistogram(Context context) { + private void recordBrowserProcessHistogram() { if (Linker.getInstance().isUsed()) { - nativeRecordChromiumAndroidLinkerBrowserHistogram(mIsUsingBrowserSharedRelros, - mLoadAtFixedAddressFailed, - getLibraryLoadFromApkStatus(context), - mLibraryLoadTimeMs); + nativeRecordChromiumAndroidLinkerBrowserHistogram( + mIsUsingBrowserSharedRelros, + mLoadAtFixedAddressFailed, + getLibraryLoadFromApkStatus(), + mLibraryLoadTimeMs); } if (sLibraryPreloader != null) { nativeRecordLibraryPreloaderBrowserHistogram(mLibraryPreloaderStatus); @@ -395,7 +417,7 @@ public class LibraryLoader { // Returns the device's status for loading a library directly from the APK file. // This method can only be called when the Chromium linker is used. - private int getLibraryLoadFromApkStatus(Context context) { + private int getLibraryLoadFromApkStatus() { assert Linker.getInstance().isUsed(); if (mLibraryWasLoadedFromApk) { @@ -432,6 +454,15 @@ public class LibraryLoader { return sInstance.mLibraryProcessType; } + /** + * Override the library loader (normally with a mock) for testing. + * @param loader the mock library loader. + */ + @VisibleForTesting + public static void setLibraryLoaderForTesting(LibraryLoader loader) { + sInstance = loader; + } + private native void nativeInitCommandLine(String[] initCommandLine); // Only methods needed before or during normal JNI registration are during System.OnLoad. diff --git a/base/android/java/src/org/chromium/base/library_loader/Linker.java b/base/android/java/src/org/chromium/base/library_loader/Linker.java index 271e6cb..7d19995 100644 --- a/base/android/java/src/org/chromium/base/library_loader/Linker.java +++ b/base/android/java/src/org/chromium/base/library_loader/Linker.java @@ -503,32 +503,24 @@ public abstract class Linker { } /** - * Determine whether a library is the linker library. Also deal with the - * component build that adds a .cr suffix to the name. + * Determine whether a library is the linker library. * * @param library the name of the library. * @return true is the library is the Linker's own JNI library. */ public boolean isChromiumLinkerLibrary(String library) { - return library.equals(LINKER_JNI_LIBRARY) || library.equals(LINKER_JNI_LIBRARY + ".cr"); + return library.equals(LINKER_JNI_LIBRARY); } /** * Load the Linker JNI library. Throws UnsatisfiedLinkError on error. - * In a component build, the suffix ".cr" is added to each library name, so - * if the initial load fails we retry with a suffix. */ protected static void loadLinkerJniLibrary() { String libName = "lib" + LINKER_JNI_LIBRARY + ".so"; if (DEBUG) { Log.i(TAG, "Loading " + libName); } - try { - System.loadLibrary(LINKER_JNI_LIBRARY); - } catch (UnsatisfiedLinkError e) { - Log.w(TAG, "Couldn't load " + libName + ", trying " + libName + ".cr"); - System.loadLibrary(LINKER_JNI_LIBRARY + ".cr"); - } + System.loadLibrary(LINKER_JNI_LIBRARY); } /** diff --git a/base/android/java/src/org/chromium/base/library_loader/ModernLinker.java b/base/android/java/src/org/chromium/base/library_loader/ModernLinker.java index 7716a8d..15021c7 100644 --- a/base/android/java/src/org/chromium/base/library_loader/ModernLinker.java +++ b/base/android/java/src/org/chromium/base/library_loader/ModernLinker.java @@ -251,8 +251,6 @@ class ModernLinker extends Linker { Log.i(TAG, "disableSharedRelros() called"); } synchronized (mLock) { - assert !mPrepareLibraryLoadCalled; - // Mark this as a service process, and disable wait for shared RELRO. mInBrowserProcess = false; mWaitForSharedRelros = false; @@ -388,7 +386,7 @@ class ModernLinker extends Linker { // We are in the browser, and with a current load address that indicates that // there is enough address space for shared RELRO to operate. Create the // shared RELRO, and store it in the map. - String relroPath = PathUtils.getDataDirectory(null) + "/RELRO:" + libFilePath; + String relroPath = PathUtils.getDataDirectory() + "/RELRO:" + libFilePath; if (nativeCreateSharedRelro(dlopenExtPath, mCurrentLoadAddress, relroPath, libInfo)) { mSharedRelros.put(dlopenExtPath, libInfo); diff --git a/base/android/java/src/org/chromium/base/metrics/RecordHistogram.java b/base/android/java/src/org/chromium/base/metrics/RecordHistogram.java index 56a5803..eaf57b7 100644 --- a/base/android/java/src/org/chromium/base/metrics/RecordHistogram.java +++ b/base/android/java/src/org/chromium/base/metrics/RecordHistogram.java @@ -25,16 +25,23 @@ import java.util.concurrent.TimeUnit; */ @JNINamespace("base::android") public class RecordHistogram { - private static boolean sIsDisabledForTests = false; + private static Throwable sDisabledBy; private static Map<String, Long> sCache = Collections.synchronizedMap(new HashMap<String, Long>()); /** - * Tests may not have native initialized, so they may need to disable metrics. + * Tests may not have native initialized, so they may need to disable metrics. The value should + * be reset after the test done, to avoid carrying over state to unrelated tests. + * + * In JUnit tests this can be done automatically using + * {@link org.chromium.chrome.browser.DisableHistogramsRule} */ @VisibleForTesting - public static void disableForTests() { - sIsDisabledForTests = true; + public static void setDisabledForTests(boolean disabled) { + if (disabled && sDisabledBy != null) { + throw new IllegalStateException("Histograms are already disabled.", sDisabledBy); + } + sDisabledBy = disabled ? new Throwable() : null; } private static long getCachedHistogramKey(String name) { @@ -54,7 +61,7 @@ public class RecordHistogram { * @param sample sample to be recorded, either true or false */ public static void recordBooleanHistogram(String name, boolean sample) { - if (sIsDisabledForTests) return; + if (sDisabledBy != null) return; long key = getCachedHistogramKey(name); long result = nativeRecordBooleanHistogram(name, key, sample); if (result != key) sCache.put(name, result); @@ -70,7 +77,7 @@ public class RecordHistogram { * lower than |boundary| */ public static void recordEnumeratedHistogram(String name, int sample, int boundary) { - if (sIsDisabledForTests) return; + if (sDisabledBy != null) return; long key = getCachedHistogramKey(name); long result = nativeRecordEnumeratedHistogram(name, key, sample, boundary); if (result != key) sCache.put(name, result); @@ -111,13 +118,13 @@ public class RecordHistogram { * UMA_HISTOGRAM_CUSTOM_COUNTS C++ macro. * @param name name of the histogram * @param sample sample to be recorded, at least |min| and at most |max| - 1 - * @param min lower bound for expected sample values + * @param min lower bound for expected sample values. It must be >= 1 * @param max upper bounds for expected sample values * @param numBuckets the number of buckets */ public static void recordCustomCountHistogram( String name, int sample, int min, int max, int numBuckets) { - if (sIsDisabledForTests) return; + if (sDisabledBy != null) return; long key = getCachedHistogramKey(name); long result = nativeRecordCustomCountHistogram(name, key, sample, min, max, numBuckets); if (result != key) sCache.put(name, result); @@ -134,7 +141,7 @@ public class RecordHistogram { */ public static void recordLinearCountHistogram( String name, int sample, int min, int max, int numBuckets) { - if (sIsDisabledForTests) return; + if (sDisabledBy != null) return; long key = getCachedHistogramKey(name); long result = nativeRecordLinearCountHistogram(name, key, sample, min, max, numBuckets); if (result != key) sCache.put(name, result); @@ -147,7 +154,7 @@ public class RecordHistogram { * @param sample sample to be recorded, at least 0 and at most 100. */ public static void recordPercentageHistogram(String name, int sample) { - if (sIsDisabledForTests) return; + if (sDisabledBy != null) return; long key = getCachedHistogramKey(name); long result = nativeRecordEnumeratedHistogram(name, key, sample, 101); if (result != key) sCache.put(name, result); @@ -160,7 +167,7 @@ public class RecordHistogram { * values. */ public static void recordSparseSlowlyHistogram(String name, int sample) { - if (sIsDisabledForTests) return; + if (sDisabledBy != null) return; long key = getCachedHistogramKey(name); long result = nativeRecordSparseHistogram(name, key, sample); if (result != key) sCache.put(name, result); @@ -218,6 +225,19 @@ public class RecordHistogram { timeUnit.toMillis(min), timeUnit.toMillis(max), numBuckets); } + /** + * Records a sample in a histogram of sizes in KB. This is the Java equivalent of the + * UMA_HISTOGRAM_MEMORY_KB C++ macro. + * + * Good for sizes up to about 500MB. + * + * @param name name of the histogram. + * @param sizeInkB Sample to record in KB. + */ + public static void recordMemoryKBHistogram(String name, int sizeInKB) { + recordCustomCountHistogram(name, sizeInKB, 1000, 500000, 50); + } + private static int clampToInt(long value) { if (value > Integer.MAX_VALUE) return Integer.MAX_VALUE; // Note: Clamping to MIN_VALUE rather than 0, to let base/ histograms code @@ -228,7 +248,7 @@ public class RecordHistogram { private static void recordCustomTimesHistogramMilliseconds( String name, long duration, long min, long max, int numBuckets) { - if (sIsDisabledForTests) return; + if (sDisabledBy != null) return; long key = getCachedHistogramKey(name); // Note: Duration, min and max are clamped to int here because that's what's expected by // the native histograms API. Callers of these functions still pass longs because that's @@ -253,7 +273,7 @@ public class RecordHistogram { * Initializes the metrics system. */ public static void initialize() { - if (sIsDisabledForTests) return; + if (sDisabledBy != null) return; nativeInitialize(); } diff --git a/base/android/java_handler_thread.cc b/base/android/java_handler_thread.cc index 7527034..76ee301 100644 --- a/base/android/java_handler_thread.cc +++ b/base/android/java_handler_thread.cc @@ -20,8 +20,8 @@ namespace android { JavaHandlerThread::JavaHandlerThread(const char* name) { JNIEnv* env = base::android::AttachCurrentThread(); - java_thread_.Reset(Java_JavaHandlerThread_create( - env, ConvertUTF8ToJavaString(env, name).obj())); + java_thread_.Reset( + Java_JavaHandlerThread_create(env, ConvertUTF8ToJavaString(env, name))); } JavaHandlerThread::~JavaHandlerThread() { @@ -35,8 +35,7 @@ void JavaHandlerThread::Start() { base::WaitableEvent initialize_event( WaitableEvent::ResetPolicy::AUTOMATIC, WaitableEvent::InitialState::NOT_SIGNALED); - Java_JavaHandlerThread_start(env, - java_thread_.obj(), + Java_JavaHandlerThread_start(env, java_thread_, reinterpret_cast<intptr_t>(this), reinterpret_cast<intptr_t>(&initialize_event)); // Wait for thread to be initialized so it is ready to be used when Start @@ -49,8 +48,7 @@ void JavaHandlerThread::Stop() { JNIEnv* env = base::android::AttachCurrentThread(); base::WaitableEvent shutdown_event(WaitableEvent::ResetPolicy::AUTOMATIC, WaitableEvent::InitialState::NOT_SIGNALED); - Java_JavaHandlerThread_stop(env, - java_thread_.obj(), + Java_JavaHandlerThread_stop(env, java_thread_, reinterpret_cast<intptr_t>(this), reinterpret_cast<intptr_t>(&shutdown_event)); // Wait for thread to shut down before returning. @@ -63,17 +61,25 @@ void JavaHandlerThread::InitializeThread(JNIEnv* env, jlong event) { // TYPE_JAVA to get the Android java style message loop. message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_JAVA)); - static_cast<MessageLoopForUI*>(message_loop_.get())->Start(); + StartMessageLoop(); reinterpret_cast<base::WaitableEvent*>(event)->Signal(); } void JavaHandlerThread::StopThread(JNIEnv* env, const JavaParamRef<jobject>& obj, jlong event) { - static_cast<MessageLoopForUI*>(message_loop_.get())->QuitWhenIdle(); + StopMessageLoop(); reinterpret_cast<base::WaitableEvent*>(event)->Signal(); } +void JavaHandlerThread::StartMessageLoop() { + static_cast<MessageLoopForUI*>(message_loop_.get())->Start(); +} + +void JavaHandlerThread::StopMessageLoop() { + static_cast<MessageLoopForUI*>(message_loop_.get())->QuitWhenIdle(); +} + // static bool JavaHandlerThread::RegisterBindings(JNIEnv* env) { return RegisterNativesImpl(env); diff --git a/base/android/java_handler_thread.h b/base/android/java_handler_thread.h index 1709ff4..96f2f0a 100644 --- a/base/android/java_handler_thread.h +++ b/base/android/java_handler_thread.h @@ -14,7 +14,6 @@ namespace base { class MessageLoop; -class WaitableEvent; namespace android { @@ -41,10 +40,15 @@ class BASE_EXPORT JavaHandlerThread { const JavaParamRef<jobject>& obj, jlong event); + virtual void StartMessageLoop(); + virtual void StopMessageLoop(); + static bool RegisterBindings(JNIEnv* env); - private: + protected: std::unique_ptr<base::MessageLoop> message_loop_; + + private: ScopedJavaGlobalRef<jobject> java_thread_; }; diff --git a/base/android/java_message_handler_factory.h b/base/android/java_message_handler_factory.h new file mode 100644 index 0000000..801617d --- /dev/null +++ b/base/android/java_message_handler_factory.h @@ -0,0 +1,33 @@ +// Copyright 2016 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. + +#ifndef BASE_ANDROID_JAVA_MESSAGE_HANDLER_FACTORY_H_ +#define BASE_ANDROID_JAVA_MESSAGE_HANDLER_FACTORY_H_ + +#include "base/android/scoped_java_ref.h" +#include "base/message_loop/message_pump.h" + +namespace base { + +class MessagePumpForUI; +class WaitableEvent; + +namespace android { + +// Factory for creating the Java-side system message handler - only used for +// testing. +class JavaMessageHandlerFactory { + public: + virtual ~JavaMessageHandlerFactory() {} + virtual base::android::ScopedJavaLocalRef<jobject> CreateMessageHandler( + JNIEnv* env, + base::MessagePump::Delegate* delegate, + MessagePumpForUI* message_pump, + WaitableEvent* test_done_event) = 0; +}; + +} // namespace android +} // namespace base + +#endif // BASE_ANDROID_JAVA_MESSAGE_HANDLER_FACTORY_H_ diff --git a/base/android/java_runtime.cc b/base/android/java_runtime.cc index 5be9adf..5fae49a 100644 --- a/base/android/java_runtime.cc +++ b/base/android/java_runtime.cc @@ -9,16 +9,12 @@ namespace base { namespace android { -bool JavaRuntime::Register(JNIEnv* env) { - return JNI_Runtime::RegisterNativesImpl(env); -} - void JavaRuntime::GetMemoryUsage(long* total_memory, long* free_memory) { JNIEnv* env = base::android::AttachCurrentThread(); base::android::ScopedJavaLocalRef<jobject> runtime = JNI_Runtime::Java_Runtime_getRuntime(env); - *total_memory = JNI_Runtime::Java_Runtime_totalMemory(env, runtime.obj()); - *free_memory = JNI_Runtime::Java_Runtime_freeMemory(env, runtime.obj()); + *total_memory = JNI_Runtime::Java_Runtime_totalMemory(env, runtime); + *free_memory = JNI_Runtime::Java_Runtime_freeMemory(env, runtime); } } // namespace android diff --git a/base/android/java_runtime.h b/base/android/java_runtime.h index 4ca889e..2034fb9 100644 --- a/base/android/java_runtime.h +++ b/base/android/java_runtime.h @@ -14,9 +14,6 @@ namespace android { // Wrapper class for using the java.lang.Runtime object from jni. class BASE_EXPORT JavaRuntime { public: - // Registers the jni class (once per process). - static bool Register(JNIEnv* env); - // Fills the total memory used and memory allocated for objects by the java // heap in the current process. Returns true on success. static void GetMemoryUsage(long* total_memory, long* free_memory); diff --git a/base/android/javatests/src/org/chromium/base/AdvancedMockContextTest.java b/base/android/javatests/src/org/chromium/base/AdvancedMockContextTest.java index 02dbeb1..20c626d 100644 --- a/base/android/javatests/src/org/chromium/base/AdvancedMockContextTest.java +++ b/base/android/javatests/src/org/chromium/base/AdvancedMockContextTest.java @@ -1,4 +1,4 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// 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. @@ -9,15 +9,21 @@ import android.content.ComponentCallbacks; import android.content.ComponentCallbacks2; import android.content.Context; import android.content.res.Configuration; -import android.test.InstrumentationTestCase; -import android.test.suitebuilder.annotation.SmallTest; +import android.support.test.InstrumentationRegistry; +import android.support.test.filters.SmallTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.chromium.base.test.BaseJUnit4ClassRunner; import org.chromium.base.test.util.AdvancedMockContext; /** * Tests for {@link org.chromium.base.test.util.AdvancedMockContext}. */ -public class AdvancedMockContextTest extends InstrumentationTestCase { +@RunWith(BaseJUnit4ClassRunner.class) +public class AdvancedMockContextTest { private static class Callback1 implements ComponentCallbacks { protected Configuration mConfiguration; protected boolean mOnLowMemoryCalled; @@ -42,9 +48,10 @@ public class AdvancedMockContextTest extends InstrumentationTestCase { } } + @Test @SmallTest public void testComponentCallbacksForTargetContext() { - Context targetContext = getInstrumentation().getTargetContext(); + Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); Application targetApplication = (Application) targetContext.getApplicationContext(); AdvancedMockContext context = new AdvancedMockContext(targetContext); Callback1 callback1 = new Callback1(); @@ -53,18 +60,18 @@ public class AdvancedMockContextTest extends InstrumentationTestCase { context.registerComponentCallbacks(callback2); targetApplication.onLowMemory(); - assertTrue("onLowMemory should have been called.", callback1.mOnLowMemoryCalled); - assertTrue("onLowMemory should have been called.", callback2.mOnLowMemoryCalled); + Assert.assertTrue("onLowMemory should have been called.", callback1.mOnLowMemoryCalled); + Assert.assertTrue("onLowMemory should have been called.", callback2.mOnLowMemoryCalled); Configuration configuration = new Configuration(); targetApplication.onConfigurationChanged(configuration); - assertEquals("onConfigurationChanged should have been called.", configuration, + Assert.assertEquals("onConfigurationChanged should have been called.", configuration, callback1.mConfiguration); - assertEquals("onConfigurationChanged should have been called.", configuration, + Assert.assertEquals("onConfigurationChanged should have been called.", configuration, callback2.mConfiguration); targetApplication.onTrimMemory(ComponentCallbacks2.TRIM_MEMORY_MODERATE); - assertEquals("onTrimMemory should have been called.", ComponentCallbacks2 - .TRIM_MEMORY_MODERATE, callback2.mLevel); + Assert.assertEquals("onTrimMemory should have been called.", + ComponentCallbacks2.TRIM_MEMORY_MODERATE, callback2.mLevel); } } diff --git a/base/android/javatests/src/org/chromium/base/ApiCompatibilityUtilsTest.java b/base/android/javatests/src/org/chromium/base/ApiCompatibilityUtilsTest.java index 45b3e21..de0858a 100644 --- a/base/android/javatests/src/org/chromium/base/ApiCompatibilityUtilsTest.java +++ b/base/android/javatests/src/org/chromium/base/ApiCompatibilityUtilsTest.java @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// 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. @@ -8,13 +8,20 @@ import android.annotation.TargetApi; import android.app.Activity; import android.os.Build; import android.os.SystemClock; -import android.test.InstrumentationTestCase; -import android.test.suitebuilder.annotation.SmallTest; +import android.support.test.InstrumentationRegistry; +import android.support.test.filters.SmallTest; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.chromium.base.test.BaseJUnit4ClassRunner; /** * Test of ApiCompatibilityUtils */ -public class ApiCompatibilityUtilsTest extends InstrumentationTestCase { +@RunWith(BaseJUnit4ClassRunner.class) +public class ApiCompatibilityUtilsTest { private static final long WAIT_TIMEOUT_IN_MS = 5000; private static final long SLEEP_INTERVAL_IN_MS = 50; @@ -42,30 +49,40 @@ public class ApiCompatibilityUtilsTest extends InstrumentationTestCase { } } + @Test @SmallTest - public void testFinishAndRemoveTask() throws InterruptedException { - MockActivity activity = new MockActivity(); - ApiCompatibilityUtils.finishAndRemoveTask(activity); + public void testFinishAndRemoveTask() { + InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() { + @Override + public void run() { + MockActivity activity = new MockActivity(); + ApiCompatibilityUtils.finishAndRemoveTask(activity); - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { - assertEquals(1, activity.mFinishAndRemoveTaskCallbackCount); - assertEquals(0, activity.mFinishCallbackCount); - } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) { - long startTime = SystemClock.uptimeMillis(); - while (activity.mFinishCallbackCount == 0 - && SystemClock.uptimeMillis() - startTime < WAIT_TIMEOUT_IN_MS) { - Thread.sleep(SLEEP_INTERVAL_IN_MS); - } + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { + Assert.assertEquals(1, activity.mFinishAndRemoveTaskCallbackCount); + Assert.assertEquals(0, activity.mFinishCallbackCount); + } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) { + long startTime = SystemClock.uptimeMillis(); + while (activity.mFinishCallbackCount == 0 + && SystemClock.uptimeMillis() - startTime < WAIT_TIMEOUT_IN_MS) { + try { + Thread.sleep(SLEEP_INTERVAL_IN_MS); + } catch (InterruptedException e) { + throw new RuntimeException("Interrupted thread sleep", e); + } + } - // MockActivity#finishAndRemoveTask() never sets isFinishing() to true for LOLLIPOP to - // simulate an exceptional case. In that case, MockActivity#finish() should be called - // after 3 tries. - assertEquals(3, activity.mFinishAndRemoveTaskCallbackCount); - assertEquals(1, activity.mFinishCallbackCount); - } else { - assertEquals(0, activity.mFinishAndRemoveTaskCallbackCount); - assertEquals(1, activity.mFinishCallbackCount); - } - assertTrue(activity.mIsFinishing); + // MockActivity#finishAndRemoveTask() never sets isFinishing() to true for + // LOLLIPOP to simulate an exceptional case. In that case, MockActivity#finish() + // should be called after 3 tries. + Assert.assertEquals(3, activity.mFinishAndRemoveTaskCallbackCount); + Assert.assertEquals(1, activity.mFinishCallbackCount); + } else { + Assert.assertEquals(0, activity.mFinishAndRemoveTaskCallbackCount); + Assert.assertEquals(1, activity.mFinishCallbackCount); + } + Assert.assertTrue(activity.mIsFinishing); + } + }); } } diff --git a/base/android/javatests/src/org/chromium/base/CommandLineTest.java b/base/android/javatests/src/org/chromium/base/CommandLineTest.java index 2b1a967..47749fb 100644 --- a/base/android/javatests/src/org/chromium/base/CommandLineTest.java +++ b/base/android/javatests/src/org/chromium/base/CommandLineTest.java @@ -1,15 +1,21 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// 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.base; -import android.test.InstrumentationTestCase; -import android.test.suitebuilder.annotation.SmallTest; +import android.support.test.filters.SmallTest; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.chromium.base.test.BaseJUnit4ClassRunner; import org.chromium.base.test.util.Feature; -public class CommandLineTest extends InstrumentationTestCase { +@RunWith(BaseJUnit4ClassRunner.class) +public class CommandLineTest { // A reference command line. Note that switch2 is [brea\d], switch3 is [and "butter"], // and switch4 is [a "quoted" 'food'!] static final String INIT_SWITCHES[] = { "init_command", "--SWITCH", "Arg", @@ -27,60 +33,61 @@ public class CommandLineTest extends InstrumentationTestCase { static final String CL_ADDED_SWITCH_2 = "username"; static final String CL_ADDED_VALUE_2 = "bozo"; - @Override + @Before public void setUp() throws Exception { CommandLine.reset(); } void checkInitSwitches() { CommandLine cl = CommandLine.getInstance(); - assertFalse(cl.hasSwitch("init_command")); - assertFalse(cl.hasSwitch("switch")); - assertTrue(cl.hasSwitch("SWITCH")); - assertFalse(cl.hasSwitch("--SWITCH")); - assertFalse(cl.hasSwitch("Arg")); - assertFalse(cl.hasSwitch("actually_an_arg")); - assertEquals("brea\\d", cl.getSwitchValue("switch2")); - assertEquals("and \"butter\"", cl.getSwitchValue("switch3")); - assertEquals("a \"quoted\" 'food'!", cl.getSwitchValue("switch4")); - assertNull(cl.getSwitchValue("SWITCH")); - assertNull(cl.getSwitchValue("non-existant")); + Assert.assertFalse(cl.hasSwitch("init_command")); + Assert.assertFalse(cl.hasSwitch("switch")); + Assert.assertTrue(cl.hasSwitch("SWITCH")); + Assert.assertFalse(cl.hasSwitch("--SWITCH")); + Assert.assertFalse(cl.hasSwitch("Arg")); + Assert.assertFalse(cl.hasSwitch("actually_an_arg")); + Assert.assertEquals("brea\\d", cl.getSwitchValue("switch2")); + Assert.assertEquals("and \"butter\"", cl.getSwitchValue("switch3")); + Assert.assertEquals("a \"quoted\" 'food'!", cl.getSwitchValue("switch4")); + Assert.assertNull(cl.getSwitchValue("SWITCH")); + Assert.assertNull(cl.getSwitchValue("non-existant")); } void checkSettingThenGetting() { CommandLine cl = CommandLine.getInstance(); // Add a plain switch. - assertFalse(cl.hasSwitch(CL_ADDED_SWITCH)); + Assert.assertFalse(cl.hasSwitch(CL_ADDED_SWITCH)); cl.appendSwitch(CL_ADDED_SWITCH); - assertTrue(cl.hasSwitch(CL_ADDED_SWITCH)); + Assert.assertTrue(cl.hasSwitch(CL_ADDED_SWITCH)); // Add a switch paired with a value. - assertFalse(cl.hasSwitch(CL_ADDED_SWITCH_2)); - assertNull(cl.getSwitchValue(CL_ADDED_SWITCH_2)); + Assert.assertFalse(cl.hasSwitch(CL_ADDED_SWITCH_2)); + Assert.assertNull(cl.getSwitchValue(CL_ADDED_SWITCH_2)); cl.appendSwitchWithValue(CL_ADDED_SWITCH_2, CL_ADDED_VALUE_2); - assertTrue(CL_ADDED_VALUE_2.equals(cl.getSwitchValue(CL_ADDED_SWITCH_2))); + Assert.assertTrue(CL_ADDED_VALUE_2.equals(cl.getSwitchValue(CL_ADDED_SWITCH_2))); // Append a few new things. final String switchesAndArgs[] = { "dummy", "--superfast", "--speed=turbo" }; - assertFalse(cl.hasSwitch("dummy")); - assertFalse(cl.hasSwitch("superfast")); - assertNull(cl.getSwitchValue("speed")); + Assert.assertFalse(cl.hasSwitch("dummy")); + Assert.assertFalse(cl.hasSwitch("superfast")); + Assert.assertNull(cl.getSwitchValue("speed")); cl.appendSwitchesAndArguments(switchesAndArgs); - assertFalse(cl.hasSwitch("dummy")); - assertFalse(cl.hasSwitch("command")); - assertTrue(cl.hasSwitch("superfast")); - assertTrue("turbo".equals(cl.getSwitchValue("speed"))); + Assert.assertFalse(cl.hasSwitch("dummy")); + Assert.assertFalse(cl.hasSwitch("command")); + Assert.assertTrue(cl.hasSwitch("superfast")); + Assert.assertTrue("turbo".equals(cl.getSwitchValue("speed"))); } void checkTokenizer(String[] expected, String toParse) { String[] actual = CommandLine.tokenizeQuotedAruments(toParse.toCharArray()); - assertEquals(expected.length, actual.length); + Assert.assertEquals(expected.length, actual.length); for (int i = 0; i < expected.length; ++i) { - assertEquals("comparing element " + i, expected[i], actual[i]); + Assert.assertEquals("comparing element " + i, expected[i], actual[i]); } } + @Test @SmallTest @Feature({"Android-AppBase"}) public void testJavaInitialization() { @@ -89,6 +96,7 @@ public class CommandLineTest extends InstrumentationTestCase { checkSettingThenGetting(); } + @Test @SmallTest @Feature({"Android-AppBase"}) public void testBufferInitialization() { @@ -97,6 +105,7 @@ public class CommandLineTest extends InstrumentationTestCase { checkSettingThenGetting(); } + @Test @SmallTest @Feature({"Android-AppBase"}) public void testArgumentTokenizer() { diff --git a/base/android/javatests/src/org/chromium/base/ObserverListTest.java b/base/android/javatests/src/org/chromium/base/ObserverListTest.java index 94a9c71..1899f45 100644 --- a/base/android/javatests/src/org/chromium/base/ObserverListTest.java +++ b/base/android/javatests/src/org/chromium/base/ObserverListTest.java @@ -1,12 +1,16 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// 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.base; -import android.test.InstrumentationTestCase; -import android.test.suitebuilder.annotation.SmallTest; +import android.support.test.filters.SmallTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.chromium.base.test.BaseJUnit4ClassRunner; import org.chromium.base.test.util.Feature; import java.util.Collection; @@ -16,7 +20,8 @@ import java.util.NoSuchElementException; /** * Tests for (@link ObserverList}. */ -public class ObserverListTest extends InstrumentationTestCase { +@RunWith(BaseJUnit4ClassRunner.class) +public class ObserverListTest { interface Observer { void observe(int x); } @@ -79,6 +84,7 @@ public class ObserverListTest extends InstrumentationTestCase { return num; } + @Test @SmallTest @Feature({"Android-AppBase"}) public void testRemoveWhileIteration() { @@ -105,17 +111,18 @@ public class ObserverListTest extends InstrumentationTestCase { for (Observer obs : observerList) obs.observe(10); // observe should be called twice on a. - assertEquals(20, a.mTotal); + Assert.assertEquals(20, a.mTotal); // observe should be called twice on b. - assertEquals(-20, b.mTotal); + Assert.assertEquals(-20, b.mTotal); // evil removed c from the observerList before it got any callbacks. - assertEquals(0, c.mTotal); + Assert.assertEquals(0, c.mTotal); // observe should be called once on d. - assertEquals(-10, d.mTotal); + Assert.assertEquals(-10, d.mTotal); // e was never added to the list, observe should not be called. - assertEquals(0, e.mTotal); + Assert.assertEquals(0, e.mTotal); } + @Test @SmallTest @Feature({"Android-AppBase"}) public void testAddWhileIteration() { @@ -131,12 +138,13 @@ public class ObserverListTest extends InstrumentationTestCase { for (Observer obs : observerList) obs.observe(10); - assertTrue(observerList.hasObserver(c)); - assertEquals(10, a.mTotal); - assertEquals(-10, b.mTotal); - assertEquals(0, c.mTotal); + Assert.assertTrue(observerList.hasObserver(c)); + Assert.assertEquals(10, a.mTotal); + Assert.assertEquals(-10, b.mTotal); + Assert.assertEquals(0, c.mTotal); } + @Test @SmallTest @Feature({"Android-AppBase"}) public void testIterator() { @@ -144,38 +152,39 @@ public class ObserverListTest extends InstrumentationTestCase { observerList.addObserver(5); observerList.addObserver(10); observerList.addObserver(15); - assertEquals(3, getSizeOfIterable(observerList)); + Assert.assertEquals(3, getSizeOfIterable(observerList)); observerList.removeObserver(10); - assertEquals(2, getSizeOfIterable(observerList)); + Assert.assertEquals(2, getSizeOfIterable(observerList)); Iterator<Integer> it = observerList.iterator(); - assertTrue(it.hasNext()); - assertTrue(5 == it.next()); - assertTrue(it.hasNext()); - assertTrue(15 == it.next()); - assertFalse(it.hasNext()); + Assert.assertTrue(it.hasNext()); + Assert.assertTrue(5 == it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertTrue(15 == it.next()); + Assert.assertFalse(it.hasNext()); boolean removeExceptionThrown = false; try { it.remove(); - fail("Expecting UnsupportedOperationException to be thrown here."); + Assert.fail("Expecting UnsupportedOperationException to be thrown here."); } catch (UnsupportedOperationException e) { removeExceptionThrown = true; } - assertTrue(removeExceptionThrown); - assertEquals(2, getSizeOfIterable(observerList)); + Assert.assertTrue(removeExceptionThrown); + Assert.assertEquals(2, getSizeOfIterable(observerList)); boolean noElementExceptionThrown = false; try { it.next(); - fail("Expecting NoSuchElementException to be thrown here."); + Assert.fail("Expecting NoSuchElementException to be thrown here."); } catch (NoSuchElementException e) { noElementExceptionThrown = true; } - assertTrue(noElementExceptionThrown); + Assert.assertTrue(noElementExceptionThrown); } + @Test @SmallTest @Feature({"Android-AppBase"}) public void testRewindableIterator() { @@ -183,52 +192,54 @@ public class ObserverListTest extends InstrumentationTestCase { observerList.addObserver(5); observerList.addObserver(10); observerList.addObserver(15); - assertEquals(3, getSizeOfIterable(observerList)); + Assert.assertEquals(3, getSizeOfIterable(observerList)); ObserverList.RewindableIterator<Integer> it = observerList.rewindableIterator(); - assertTrue(it.hasNext()); - assertTrue(5 == it.next()); - assertTrue(it.hasNext()); - assertTrue(10 == it.next()); - assertTrue(it.hasNext()); - assertTrue(15 == it.next()); - assertFalse(it.hasNext()); + Assert.assertTrue(it.hasNext()); + Assert.assertTrue(5 == it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertTrue(10 == it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertTrue(15 == it.next()); + Assert.assertFalse(it.hasNext()); it.rewind(); - assertTrue(it.hasNext()); - assertTrue(5 == it.next()); - assertTrue(it.hasNext()); - assertTrue(10 == it.next()); - assertTrue(it.hasNext()); - assertTrue(15 == it.next()); - assertEquals(5, (int) observerList.mObservers.get(0)); + Assert.assertTrue(it.hasNext()); + Assert.assertTrue(5 == it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertTrue(10 == it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertTrue(15 == it.next()); + Assert.assertEquals(5, (int) observerList.mObservers.get(0)); observerList.removeObserver(5); - assertEquals(null, observerList.mObservers.get(0)); + Assert.assertEquals(null, observerList.mObservers.get(0)); it.rewind(); - assertEquals(10, (int) observerList.mObservers.get(0)); - assertTrue(it.hasNext()); - assertTrue(10 == it.next()); - assertTrue(it.hasNext()); - assertTrue(15 == it.next()); + Assert.assertEquals(10, (int) observerList.mObservers.get(0)); + Assert.assertTrue(it.hasNext()); + Assert.assertTrue(10 == it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertTrue(15 == it.next()); } + @Test @SmallTest @Feature({"Android-AppBase"}) public void testAddObserverReturnValue() { ObserverList<Object> observerList = new ObserverList<Object>(); Object a = new Object(); - assertTrue(observerList.addObserver(a)); - assertFalse(observerList.addObserver(a)); + Assert.assertTrue(observerList.addObserver(a)); + Assert.assertFalse(observerList.addObserver(a)); Object b = new Object(); - assertTrue(observerList.addObserver(b)); - assertFalse(observerList.addObserver(null)); + Assert.assertTrue(observerList.addObserver(b)); + Assert.assertFalse(observerList.addObserver(null)); } + @Test @SmallTest @Feature({"Android-AppBase"}) public void testRemoveObserverReturnValue() { @@ -239,91 +250,92 @@ public class ObserverListTest extends InstrumentationTestCase { observerList.addObserver(a); observerList.addObserver(b); - assertTrue(observerList.removeObserver(a)); - assertFalse(observerList.removeObserver(a)); - assertFalse(observerList.removeObserver(new Object())); - assertTrue(observerList.removeObserver(b)); - assertFalse(observerList.removeObserver(null)); + Assert.assertTrue(observerList.removeObserver(a)); + Assert.assertFalse(observerList.removeObserver(a)); + Assert.assertFalse(observerList.removeObserver(new Object())); + Assert.assertTrue(observerList.removeObserver(b)); + Assert.assertFalse(observerList.removeObserver(null)); // If we remove an object while iterating, it will be replaced by 'null'. observerList.addObserver(a); - assertTrue(observerList.removeObserver(a)); - assertFalse(observerList.removeObserver(null)); + Assert.assertTrue(observerList.removeObserver(a)); + Assert.assertFalse(observerList.removeObserver(null)); } + @Test @SmallTest @Feature({"Android-AppBase"}) public void testSize() { ObserverList<Object> observerList = new ObserverList<Object>(); - assertEquals(0, observerList.size()); - assertTrue(observerList.isEmpty()); + Assert.assertEquals(0, observerList.size()); + Assert.assertTrue(observerList.isEmpty()); observerList.addObserver(null); - assertEquals(0, observerList.size()); - assertTrue(observerList.isEmpty()); + Assert.assertEquals(0, observerList.size()); + Assert.assertTrue(observerList.isEmpty()); Object a = new Object(); observerList.addObserver(a); - assertEquals(1, observerList.size()); - assertFalse(observerList.isEmpty()); + Assert.assertEquals(1, observerList.size()); + Assert.assertFalse(observerList.isEmpty()); observerList.addObserver(a); - assertEquals(1, observerList.size()); - assertFalse(observerList.isEmpty()); + Assert.assertEquals(1, observerList.size()); + Assert.assertFalse(observerList.isEmpty()); observerList.addObserver(null); - assertEquals(1, observerList.size()); - assertFalse(observerList.isEmpty()); + Assert.assertEquals(1, observerList.size()); + Assert.assertFalse(observerList.isEmpty()); Object b = new Object(); observerList.addObserver(b); - assertEquals(2, observerList.size()); - assertFalse(observerList.isEmpty()); + Assert.assertEquals(2, observerList.size()); + Assert.assertFalse(observerList.isEmpty()); observerList.removeObserver(null); - assertEquals(2, observerList.size()); - assertFalse(observerList.isEmpty()); + Assert.assertEquals(2, observerList.size()); + Assert.assertFalse(observerList.isEmpty()); observerList.removeObserver(new Object()); - assertEquals(2, observerList.size()); - assertFalse(observerList.isEmpty()); + Assert.assertEquals(2, observerList.size()); + Assert.assertFalse(observerList.isEmpty()); observerList.removeObserver(b); - assertEquals(1, observerList.size()); - assertFalse(observerList.isEmpty()); + Assert.assertEquals(1, observerList.size()); + Assert.assertFalse(observerList.isEmpty()); observerList.removeObserver(b); - assertEquals(1, observerList.size()); - assertFalse(observerList.isEmpty()); + Assert.assertEquals(1, observerList.size()); + Assert.assertFalse(observerList.isEmpty()); observerList.removeObserver(a); - assertEquals(0, observerList.size()); - assertTrue(observerList.isEmpty()); + Assert.assertEquals(0, observerList.size()); + Assert.assertTrue(observerList.isEmpty()); observerList.removeObserver(a); observerList.removeObserver(b); observerList.removeObserver(null); observerList.removeObserver(new Object()); - assertEquals(0, observerList.size()); - assertTrue(observerList.isEmpty()); + Assert.assertEquals(0, observerList.size()); + Assert.assertTrue(observerList.isEmpty()); observerList.addObserver(new Object()); observerList.addObserver(new Object()); observerList.addObserver(new Object()); observerList.addObserver(a); - assertEquals(4, observerList.size()); - assertFalse(observerList.isEmpty()); + Assert.assertEquals(4, observerList.size()); + Assert.assertFalse(observerList.isEmpty()); observerList.clear(); - assertEquals(0, observerList.size()); - assertTrue(observerList.isEmpty()); + Assert.assertEquals(0, observerList.size()); + Assert.assertTrue(observerList.isEmpty()); observerList.removeObserver(a); observerList.removeObserver(b); observerList.removeObserver(null); observerList.removeObserver(new Object()); - assertEquals(0, observerList.size()); - assertTrue(observerList.isEmpty()); + Assert.assertEquals(0, observerList.size()); + Assert.assertTrue(observerList.isEmpty()); } } diff --git a/base/android/javatests/src/org/chromium/base/metrics/RecordHistogramTest.java b/base/android/javatests/src/org/chromium/base/metrics/RecordHistogramTest.java index 6b1888c..daf639b 100644 --- a/base/android/javatests/src/org/chromium/base/metrics/RecordHistogramTest.java +++ b/base/android/javatests/src/org/chromium/base/metrics/RecordHistogramTest.java @@ -1,14 +1,19 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// 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.base.metrics; -import android.test.InstrumentationTestCase; -import android.test.suitebuilder.annotation.SmallTest; +import android.support.test.filters.SmallTest; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; import org.chromium.base.library_loader.LibraryLoader; import org.chromium.base.library_loader.LibraryProcessType; +import org.chromium.base.test.BaseJUnit4ClassRunner; import org.chromium.base.test.util.MetricsUtils.HistogramDelta; import java.util.concurrent.TimeUnit; @@ -16,42 +21,43 @@ import java.util.concurrent.TimeUnit; /** * Tests for the Java API for recording UMA histograms. */ -public class RecordHistogramTest extends InstrumentationTestCase { - @Override - protected void setUp() throws Exception { - super.setUp(); - LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER) - .ensureInitialized(getInstrumentation().getTargetContext()); +@RunWith(BaseJUnit4ClassRunner.class) +public class RecordHistogramTest { + @Before + public void setUp() throws Exception { + LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized(); RecordHistogram.initialize(); } /** * Tests recording of boolean histograms. */ + @Test @SmallTest public void testRecordBooleanHistogram() { String histogram = "HelloWorld.BooleanMetric"; HistogramDelta falseCount = new HistogramDelta(histogram, 0); HistogramDelta trueCount = new HistogramDelta(histogram, 1); - assertEquals(0, trueCount.getDelta()); - assertEquals(0, falseCount.getDelta()); + Assert.assertEquals(0, trueCount.getDelta()); + Assert.assertEquals(0, falseCount.getDelta()); RecordHistogram.recordBooleanHistogram(histogram, true); - assertEquals(1, trueCount.getDelta()); - assertEquals(0, falseCount.getDelta()); + Assert.assertEquals(1, trueCount.getDelta()); + Assert.assertEquals(0, falseCount.getDelta()); RecordHistogram.recordBooleanHistogram(histogram, true); - assertEquals(2, trueCount.getDelta()); - assertEquals(0, falseCount.getDelta()); + Assert.assertEquals(2, trueCount.getDelta()); + Assert.assertEquals(0, falseCount.getDelta()); RecordHistogram.recordBooleanHistogram(histogram, false); - assertEquals(2, trueCount.getDelta()); - assertEquals(1, falseCount.getDelta()); + Assert.assertEquals(2, trueCount.getDelta()); + Assert.assertEquals(1, falseCount.getDelta()); } /** * Tests recording of enumerated histograms. */ + @Test @SmallTest public void testRecordEnumeratedHistogram() { String histogram = "HelloWorld.EnumeratedMetric"; @@ -60,29 +66,30 @@ public class RecordHistogramTest extends InstrumentationTestCase { HistogramDelta twoCount = new HistogramDelta(histogram, 2); final int boundary = 3; - assertEquals(0, zeroCount.getDelta()); - assertEquals(0, oneCount.getDelta()); - assertEquals(0, twoCount.getDelta()); + Assert.assertEquals(0, zeroCount.getDelta()); + Assert.assertEquals(0, oneCount.getDelta()); + Assert.assertEquals(0, twoCount.getDelta()); RecordHistogram.recordEnumeratedHistogram(histogram, 0, boundary); - assertEquals(1, zeroCount.getDelta()); - assertEquals(0, oneCount.getDelta()); - assertEquals(0, twoCount.getDelta()); + Assert.assertEquals(1, zeroCount.getDelta()); + Assert.assertEquals(0, oneCount.getDelta()); + Assert.assertEquals(0, twoCount.getDelta()); RecordHistogram.recordEnumeratedHistogram(histogram, 0, boundary); - assertEquals(2, zeroCount.getDelta()); - assertEquals(0, oneCount.getDelta()); - assertEquals(0, twoCount.getDelta()); + Assert.assertEquals(2, zeroCount.getDelta()); + Assert.assertEquals(0, oneCount.getDelta()); + Assert.assertEquals(0, twoCount.getDelta()); RecordHistogram.recordEnumeratedHistogram(histogram, 2, boundary); - assertEquals(2, zeroCount.getDelta()); - assertEquals(0, oneCount.getDelta()); - assertEquals(1, twoCount.getDelta()); + Assert.assertEquals(2, zeroCount.getDelta()); + Assert.assertEquals(0, oneCount.getDelta()); + Assert.assertEquals(1, twoCount.getDelta()); } /** * Tests recording of count histograms. */ + @Test @SmallTest public void testRecordCountHistogram() { String histogram = "HelloWorld.CountMetric"; @@ -91,39 +98,40 @@ public class RecordHistogramTest extends InstrumentationTestCase { HistogramDelta twoCount = new HistogramDelta(histogram, 2); HistogramDelta eightThousandCount = new HistogramDelta(histogram, 8000); - assertEquals(0, zeroCount.getDelta()); - assertEquals(0, oneCount.getDelta()); - assertEquals(0, twoCount.getDelta()); - assertEquals(0, eightThousandCount.getDelta()); + Assert.assertEquals(0, zeroCount.getDelta()); + Assert.assertEquals(0, oneCount.getDelta()); + Assert.assertEquals(0, twoCount.getDelta()); + Assert.assertEquals(0, eightThousandCount.getDelta()); RecordHistogram.recordCountHistogram(histogram, 0); - assertEquals(1, zeroCount.getDelta()); - assertEquals(0, oneCount.getDelta()); - assertEquals(0, twoCount.getDelta()); - assertEquals(0, eightThousandCount.getDelta()); + Assert.assertEquals(1, zeroCount.getDelta()); + Assert.assertEquals(0, oneCount.getDelta()); + Assert.assertEquals(0, twoCount.getDelta()); + Assert.assertEquals(0, eightThousandCount.getDelta()); RecordHistogram.recordCountHistogram(histogram, 0); - assertEquals(2, zeroCount.getDelta()); - assertEquals(0, oneCount.getDelta()); - assertEquals(0, twoCount.getDelta()); - assertEquals(0, eightThousandCount.getDelta()); + Assert.assertEquals(2, zeroCount.getDelta()); + Assert.assertEquals(0, oneCount.getDelta()); + Assert.assertEquals(0, twoCount.getDelta()); + Assert.assertEquals(0, eightThousandCount.getDelta()); RecordHistogram.recordCountHistogram(histogram, 2); - assertEquals(2, zeroCount.getDelta()); - assertEquals(0, oneCount.getDelta()); - assertEquals(1, twoCount.getDelta()); - assertEquals(0, eightThousandCount.getDelta()); + Assert.assertEquals(2, zeroCount.getDelta()); + Assert.assertEquals(0, oneCount.getDelta()); + Assert.assertEquals(1, twoCount.getDelta()); + Assert.assertEquals(0, eightThousandCount.getDelta()); RecordHistogram.recordCountHistogram(histogram, 8000); - assertEquals(2, zeroCount.getDelta()); - assertEquals(0, oneCount.getDelta()); - assertEquals(1, twoCount.getDelta()); - assertEquals(1, eightThousandCount.getDelta()); + Assert.assertEquals(2, zeroCount.getDelta()); + Assert.assertEquals(0, oneCount.getDelta()); + Assert.assertEquals(1, twoCount.getDelta()); + Assert.assertEquals(1, eightThousandCount.getDelta()); } /** * Tests recording of custom times histograms. */ + @Test @SmallTest public void testRecordCustomTimesHistogram() { String histogram = "HelloWorld.CustomTimesMetric"; @@ -131,36 +139,37 @@ public class RecordHistogramTest extends InstrumentationTestCase { HistogramDelta oneCount = new HistogramDelta(histogram, 1); HistogramDelta twoCount = new HistogramDelta(histogram, 100); - assertEquals(0, zeroCount.getDelta()); - assertEquals(0, oneCount.getDelta()); - assertEquals(0, twoCount.getDelta()); + Assert.assertEquals(0, zeroCount.getDelta()); + Assert.assertEquals(0, oneCount.getDelta()); + Assert.assertEquals(0, twoCount.getDelta()); TimeUnit milli = TimeUnit.MILLISECONDS; RecordHistogram.recordCustomTimesHistogram(histogram, 0, 1, 100, milli, 3); - assertEquals(1, zeroCount.getDelta()); - assertEquals(0, oneCount.getDelta()); - assertEquals(0, twoCount.getDelta()); + Assert.assertEquals(1, zeroCount.getDelta()); + Assert.assertEquals(0, oneCount.getDelta()); + Assert.assertEquals(0, twoCount.getDelta()); RecordHistogram.recordCustomTimesHistogram(histogram, 0, 1, 100, milli, 3); - assertEquals(2, zeroCount.getDelta()); - assertEquals(0, oneCount.getDelta()); - assertEquals(0, twoCount.getDelta()); + Assert.assertEquals(2, zeroCount.getDelta()); + Assert.assertEquals(0, oneCount.getDelta()); + Assert.assertEquals(0, twoCount.getDelta()); RecordHistogram.recordCustomTimesHistogram(histogram, 95, 1, 100, milli, 3); - assertEquals(2, zeroCount.getDelta()); - assertEquals(1, oneCount.getDelta()); - assertEquals(0, twoCount.getDelta()); + Assert.assertEquals(2, zeroCount.getDelta()); + Assert.assertEquals(1, oneCount.getDelta()); + Assert.assertEquals(0, twoCount.getDelta()); RecordHistogram.recordCustomTimesHistogram(histogram, 200, 1, 100, milli, 3); - assertEquals(2, zeroCount.getDelta()); - assertEquals(1, oneCount.getDelta()); - assertEquals(1, twoCount.getDelta()); + Assert.assertEquals(2, zeroCount.getDelta()); + Assert.assertEquals(1, oneCount.getDelta()); + Assert.assertEquals(1, twoCount.getDelta()); } /** * Tests recording of linear count histograms. */ + @Test @SmallTest public void testRecordLinearCountHistogram() { String histogram = "HelloWorld.LinearCountMetric"; @@ -171,23 +180,23 @@ public class RecordHistogramTest extends InstrumentationTestCase { final int max = 3; final int numBuckets = 4; - assertEquals(0, zeroCount.getDelta()); - assertEquals(0, oneCount.getDelta()); - assertEquals(0, twoCount.getDelta()); + Assert.assertEquals(0, zeroCount.getDelta()); + Assert.assertEquals(0, oneCount.getDelta()); + Assert.assertEquals(0, twoCount.getDelta()); RecordHistogram.recordLinearCountHistogram(histogram, 0, min, max, numBuckets); - assertEquals(1, zeroCount.getDelta()); - assertEquals(0, oneCount.getDelta()); - assertEquals(0, twoCount.getDelta()); + Assert.assertEquals(1, zeroCount.getDelta()); + Assert.assertEquals(0, oneCount.getDelta()); + Assert.assertEquals(0, twoCount.getDelta()); RecordHistogram.recordLinearCountHistogram(histogram, 0, min, max, numBuckets); - assertEquals(2, zeroCount.getDelta()); - assertEquals(0, oneCount.getDelta()); - assertEquals(0, twoCount.getDelta()); + Assert.assertEquals(2, zeroCount.getDelta()); + Assert.assertEquals(0, oneCount.getDelta()); + Assert.assertEquals(0, twoCount.getDelta()); RecordHistogram.recordLinearCountHistogram(histogram, 2, min, max, numBuckets); - assertEquals(2, zeroCount.getDelta()); - assertEquals(0, oneCount.getDelta()); - assertEquals(1, twoCount.getDelta()); + Assert.assertEquals(2, zeroCount.getDelta()); + Assert.assertEquals(0, oneCount.getDelta()); + Assert.assertEquals(1, twoCount.getDelta()); } } diff --git a/base/android/jni_android.cc b/base/android/jni_android.cc index 3b53624..56dc5c2 100644 --- a/base/android/jni_android.cc +++ b/base/android/jni_android.cc @@ -11,33 +11,40 @@ #include "base/android/build_info.h" #include "base/android/jni_string.h" #include "base/android/jni_utils.h" +#include "base/debug/debugging_flags.h" #include "base/lazy_instance.h" #include "base/logging.h" +#include "base/threading/thread_local.h" namespace { using base::android::GetClass; using base::android::MethodID; using base::android::ScopedJavaLocalRef; -bool g_disable_manual_jni_registration = false; +base::android::JniRegistrationType g_jni_registration_type = + base::android::ALL_JNI_REGISTRATION; JavaVM* g_jvm = NULL; -base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >::Leaky +base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject>>::Leaky g_class_loader = LAZY_INSTANCE_INITIALIZER; jmethodID g_class_loader_load_class_method_id = 0; +#if BUILDFLAG(ENABLE_PROFILING) && HAVE_TRACE_STACK_FRAME_POINTERS +base::LazyInstance<base::ThreadLocalPointer<void>>::Leaky + g_stack_frame_pointer = LAZY_INSTANCE_INITIALIZER; +#endif + } // namespace namespace base { namespace android { -bool IsManualJniRegistrationDisabled() { - return g_disable_manual_jni_registration; +JniRegistrationType GetJniRegistrationType() { + return g_jni_registration_type; } -void DisableManualJniRegistration() { - DCHECK(!g_disable_manual_jni_registration); - g_disable_manual_jni_registration = true; +void SetJniRegistrationType(JniRegistrationType jni_registration_type) { + g_jni_registration_type = jni_registration_type; } JNIEnv* AttachCurrentThread() { @@ -233,16 +240,7 @@ void CheckException(JNIEnv* env) { } // Now, feel good about it and die. - // TODO(lhchavez): Remove this hack. See b/28814913 for details. - // We're using BuildInfo's java_exception_info() instead of storing the - // exception info a few lines above to avoid extra copies. It will be - // truncated to 1024 bytes anyways. - const char* exception_string = - base::android::BuildInfo::GetInstance()->java_exception_info(); - if (exception_string) - LOG(FATAL) << exception_string; - else - LOG(FATAL) << "Unhandled exception"; + LOG(FATAL) << "Please include Java exception stack in crash report"; } std::string GetJavaExceptionInfo(JNIEnv* env, jthrowable java_throwable) { @@ -291,6 +289,22 @@ std::string GetJavaExceptionInfo(JNIEnv* env, jthrowable java_throwable) { return ConvertJavaStringToUTF8(exception_string); } +#if BUILDFLAG(ENABLE_PROFILING) && HAVE_TRACE_STACK_FRAME_POINTERS + +JNIStackFrameSaver::JNIStackFrameSaver(void* current_fp) { + previous_fp_ = g_stack_frame_pointer.Pointer()->Get(); + g_stack_frame_pointer.Pointer()->Set(current_fp); +} + +JNIStackFrameSaver::~JNIStackFrameSaver() { + g_stack_frame_pointer.Pointer()->Set(previous_fp_); +} + +void* JNIStackFrameSaver::SavedFrame() { + return g_stack_frame_pointer.Pointer()->Get(); +} + +#endif // ENABLE_PROFILING && HAVE_TRACE_STACK_FRAME_POINTERS } // namespace android } // namespace base diff --git a/base/android/jni_android.h b/base/android/jni_android.h index 909e3da..de53c10 100644 --- a/base/android/jni_android.h +++ b/base/android/jni_android.h @@ -14,6 +14,39 @@ #include "base/atomicops.h" #include "base/base_export.h" #include "base/compiler_specific.h" +#include "base/debug/stack_trace.h" +#include "base/macros.h" + +#if HAVE_TRACE_STACK_FRAME_POINTERS + +// When profiling is enabled (enable_profiling=true) this macro is added to +// all generated JNI stubs so that it becomes the last thing that runs before +// control goes into Java. +// +// This macro saves stack frame pointer of the current function. Saved value +// used later by JNI_LINK_SAVED_FRAME_POINTER. +#define JNI_SAVE_FRAME_POINTER \ + base::android::JNIStackFrameSaver jni_frame_saver(__builtin_frame_address(0)) + +// When profiling is enabled (enable_profiling=true) this macro is added to +// all generated JNI callbacks so that it becomes the first thing that runs +// after control returns from Java. +// +// This macro links stack frame of the current function to the stack frame +// saved by JNI_SAVE_FRAME_POINTER, allowing frame-based unwinding +// (used by the heap profiler) to produce complete traces. +#define JNI_LINK_SAVED_FRAME_POINTER \ + base::debug::ScopedStackFrameLinker jni_frame_linker( \ + __builtin_frame_address(0), \ + base::android::JNIStackFrameSaver::SavedFrame()) + +#else + +// Frame-based stack unwinding is not supported, do nothing. +#define JNI_SAVE_FRAME_POINTER +#define JNI_LINK_SAVED_FRAME_POINTER + +#endif // HAVE_TRACE_STACK_FRAME_POINTERS namespace base { namespace android { @@ -21,12 +54,23 @@ namespace android { // Used to mark symbols to be exported in a shared library's symbol table. #define JNI_EXPORT __attribute__ ((visibility("default"))) -// Used to disable manual JNI registration in binaries that prefer to use native -// JNI exports for startup performance. This is not compatible with the crazy -// linker and so defaults to off. Call DisableManualJniRegistration at the very -// beginning of JNI_OnLoad to use this. -BASE_EXPORT bool IsManualJniRegistrationDisabled(); -BASE_EXPORT void DisableManualJniRegistration(); +// The level of JNI registration required for the current process. +enum JniRegistrationType { + // Register all native methods. + ALL_JNI_REGISTRATION, + // Register some native methods, as controlled by the jni_generator. + SELECTIVE_JNI_REGISTRATION, + // Do not register any native methods. + NO_JNI_REGISTRATION, +}; + +BASE_EXPORT JniRegistrationType GetJniRegistrationType(); + +// Set the JniRegistrationType for this process (defaults to +// ALL_JNI_REGISTRATION). This should be called in the JNI_OnLoad function +// which is called when the native library is first loaded. +BASE_EXPORT void SetJniRegistrationType( + JniRegistrationType jni_registration_type); // Contains the registration method information for initializing JNI bindings. struct RegistrationMethod { @@ -122,6 +166,24 @@ BASE_EXPORT void CheckException(JNIEnv* env); BASE_EXPORT std::string GetJavaExceptionInfo(JNIEnv* env, jthrowable java_throwable); +#if HAVE_TRACE_STACK_FRAME_POINTERS + +// Saves caller's PC and stack frame in a thread-local variable. +// Implemented only when profiling is enabled (enable_profiling=true). +class BASE_EXPORT JNIStackFrameSaver { + public: + JNIStackFrameSaver(void* current_fp); + ~JNIStackFrameSaver(); + static void* SavedFrame(); + + private: + void* previous_fp_; + + DISALLOW_COPY_AND_ASSIGN(JNIStackFrameSaver); +}; + +#endif // HAVE_TRACE_STACK_FRAME_POINTERS + } // namespace android } // namespace base diff --git a/base/android/jni_generator/golden_sample_for_tests_jni.h b/base/android/jni_generator/golden_sample_for_tests_jni.h deleted file mode 100644 index e982609..0000000 --- a/base/android/jni_generator/golden_sample_for_tests_jni.h +++ /dev/null @@ -1,481 +0,0 @@ -// Copyright 2014 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 file is autogenerated by -// base/android/jni_generator/jni_generator.py -// For -// org/chromium/example/jni_generator/SampleForTests - -#ifndef org_chromium_example_jni_generator_SampleForTests_JNI -#define org_chromium_example_jni_generator_SampleForTests_JNI - -#include <jni.h> - -#include "base/android/jni_generator/jni_generator_helper.h" - -#include "base/android/jni_int_wrapper.h" - -// Step 1: forward declarations. -namespace { -const char kInnerStructAClassPath[] = - "org/chromium/example/jni_generator/SampleForTests$InnerStructA"; -const char kSampleForTestsClassPath[] = - "org/chromium/example/jni_generator/SampleForTests"; -const char kInnerStructBClassPath[] = - "org/chromium/example/jni_generator/SampleForTests$InnerStructB"; -// Leaking this jclass as we cannot use LazyInstance from some threads. -jclass g_InnerStructA_clazz = NULL; -#define InnerStructA_clazz(env) g_InnerStructA_clazz -// Leaking this jclass as we cannot use LazyInstance from some threads. -jclass g_SampleForTests_clazz = NULL; -#define SampleForTests_clazz(env) g_SampleForTests_clazz -// Leaking this jclass as we cannot use LazyInstance from some threads. -jclass g_InnerStructB_clazz = NULL; -#define InnerStructB_clazz(env) g_InnerStructB_clazz - -} // namespace - -namespace base { -namespace android { - -// Step 2: method stubs. - -static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller, - const JavaParamRef<jstring>& param); - -static jlong - Java_org_chromium_example_jni_1generator_SampleForTests_nativeInit(JNIEnv* - env, jobject jcaller, - jstring param) { - return Init(env, JavaParamRef<jobject>(env, jcaller), - JavaParamRef<jstring>(env, param)); -} - -static void - Java_org_chromium_example_jni_1generator_SampleForTests_nativeDestroy(JNIEnv* - env, - jobject jcaller, - jlong nativeCPPClass) { - CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); - CHECK_NATIVE_PTR(env, jcaller, native, "Destroy"); - return native->Destroy(env, JavaParamRef<jobject>(env, jcaller)); -} - -static jdouble GetDoubleFunction(JNIEnv* env, const JavaParamRef<jobject>& - jcaller); - -static jdouble - Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetDoubleFunction(JNIEnv* - env, jobject jcaller) { - return GetDoubleFunction(env, JavaParamRef<jobject>(env, jcaller)); -} - -static jfloat GetFloatFunction(JNIEnv* env, const JavaParamRef<jclass>& - jcaller); - -static jfloat - Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetFloatFunction(JNIEnv* - env, jclass jcaller) { - return GetFloatFunction(env, JavaParamRef<jclass>(env, jcaller)); -} - -static void SetNonPODDatatype(JNIEnv* env, const JavaParamRef<jobject>& jcaller, - const JavaParamRef<jobject>& rect); - -static void - Java_org_chromium_example_jni_1generator_SampleForTests_nativeSetNonPODDatatype(JNIEnv* - env, jobject jcaller, - jobject rect) { - return SetNonPODDatatype(env, JavaParamRef<jobject>(env, jcaller), - JavaParamRef<jobject>(env, rect)); -} - -static ScopedJavaLocalRef<jobject> GetNonPODDatatype(JNIEnv* env, const - JavaParamRef<jobject>& jcaller); - -static jobject - Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetNonPODDatatype(JNIEnv* - env, jobject jcaller) { - return GetNonPODDatatype(env, JavaParamRef<jobject>(env, jcaller)).Release(); -} - -static jint - Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod(JNIEnv* - env, - jobject jcaller, - jlong nativeCPPClass) { - CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); - CHECK_NATIVE_PTR(env, jcaller, native, "Method", 0); - return native->Method(env, JavaParamRef<jobject>(env, jcaller)); -} - -static jdouble - Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethodOtherP0(JNIEnv* - env, - jobject jcaller, - jlong nativePtr) { - CPPClass::InnerClass* native = - reinterpret_cast<CPPClass::InnerClass*>(nativePtr); - CHECK_NATIVE_PTR(env, jcaller, native, "MethodOtherP0", 0); - return native->MethodOtherP0(env, JavaParamRef<jobject>(env, jcaller)); -} - -static void - Java_org_chromium_example_jni_1generator_SampleForTests_nativeAddStructB(JNIEnv* - env, - jobject jcaller, - jlong nativeCPPClass, - jobject b) { - CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); - CHECK_NATIVE_PTR(env, jcaller, native, "AddStructB"); - return native->AddStructB(env, JavaParamRef<jobject>(env, jcaller), - JavaParamRef<jobject>(env, b)); -} - -static void - Java_org_chromium_example_jni_1generator_SampleForTests_nativeIterateAndDoSomethingWithStructB(JNIEnv* - env, - jobject jcaller, - jlong nativeCPPClass) { - CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); - CHECK_NATIVE_PTR(env, jcaller, native, "IterateAndDoSomethingWithStructB"); - return native->IterateAndDoSomethingWithStructB(env, - JavaParamRef<jobject>(env, jcaller)); -} - -static jstring - Java_org_chromium_example_jni_1generator_SampleForTests_nativeReturnAString(JNIEnv* - env, - jobject jcaller, - jlong nativeCPPClass) { - CPPClass* native = reinterpret_cast<CPPClass*>(nativeCPPClass); - CHECK_NATIVE_PTR(env, jcaller, native, "ReturnAString", NULL); - return native->ReturnAString(env, JavaParamRef<jobject>(env, - jcaller)).Release(); -} - -static base::subtle::AtomicWord g_SampleForTests_javaMethod = 0; -static jint Java_SampleForTests_javaMethod(JNIEnv* env, jobject obj, - JniIntWrapper foo, - JniIntWrapper bar) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, - SampleForTests_clazz(env), 0); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_INSTANCE>( - env, SampleForTests_clazz(env), - "javaMethod", - -"(" -"I" -"I" -")" -"I", - &g_SampleForTests_javaMethod); - - jint ret = - env->CallIntMethod(obj, - method_id, as_jint(foo), as_jint(bar)); - jni_generator::CheckException(env); - return ret; -} - -static base::subtle::AtomicWord g_SampleForTests_staticJavaMethod = 0; -static jboolean Java_SampleForTests_staticJavaMethod(JNIEnv* env) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, SampleForTests_clazz(env), - SampleForTests_clazz(env), false); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_STATIC>( - env, SampleForTests_clazz(env), - "staticJavaMethod", - -"(" -")" -"Z", - &g_SampleForTests_staticJavaMethod); - - jboolean ret = - env->CallStaticBooleanMethod(SampleForTests_clazz(env), - method_id); - jni_generator::CheckException(env); - return ret; -} - -static base::subtle::AtomicWord g_SampleForTests_packagePrivateJavaMethod = 0; -static void Java_SampleForTests_packagePrivateJavaMethod(JNIEnv* env, jobject - obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, - SampleForTests_clazz(env)); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_INSTANCE>( - env, SampleForTests_clazz(env), - "packagePrivateJavaMethod", - -"(" -")" -"V", - &g_SampleForTests_packagePrivateJavaMethod); - - env->CallVoidMethod(obj, - method_id); - jni_generator::CheckException(env); - -} - -static base::subtle::AtomicWord g_SampleForTests_methodThatThrowsException = 0; -static void Java_SampleForTests_methodThatThrowsException(JNIEnv* env, jobject - obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, - SampleForTests_clazz(env)); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_INSTANCE>( - env, SampleForTests_clazz(env), - "methodThatThrowsException", - -"(" -")" -"V", - &g_SampleForTests_methodThatThrowsException); - - env->CallVoidMethod(obj, - method_id); - -} - -static base::subtle::AtomicWord g_InnerStructA_create = 0; -static ScopedJavaLocalRef<jobject> Java_InnerStructA_create(JNIEnv* env, jlong - l, - JniIntWrapper i, - jstring s) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, InnerStructA_clazz(env), - InnerStructA_clazz(env), NULL); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_STATIC>( - env, InnerStructA_clazz(env), - "create", - -"(" -"J" -"I" -"Ljava/lang/String;" -")" -"Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;", - &g_InnerStructA_create); - - jobject ret = - env->CallStaticObjectMethod(InnerStructA_clazz(env), - method_id, l, as_jint(i), s); - jni_generator::CheckException(env); - return ScopedJavaLocalRef<jobject>(env, ret); -} - -static base::subtle::AtomicWord g_SampleForTests_addStructA = 0; -static void Java_SampleForTests_addStructA(JNIEnv* env, jobject obj, jobject a) - { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, - SampleForTests_clazz(env)); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_INSTANCE>( - env, SampleForTests_clazz(env), - "addStructA", - -"(" -"Lorg/chromium/example/jni_generator/SampleForTests$InnerStructA;" -")" -"V", - &g_SampleForTests_addStructA); - - env->CallVoidMethod(obj, - method_id, a); - jni_generator::CheckException(env); - -} - -static base::subtle::AtomicWord g_SampleForTests_iterateAndDoSomething = 0; -static void Java_SampleForTests_iterateAndDoSomething(JNIEnv* env, jobject obj) - { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, - SampleForTests_clazz(env)); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_INSTANCE>( - env, SampleForTests_clazz(env), - "iterateAndDoSomething", - -"(" -")" -"V", - &g_SampleForTests_iterateAndDoSomething); - - env->CallVoidMethod(obj, - method_id); - jni_generator::CheckException(env); - -} - -static base::subtle::AtomicWord g_InnerStructB_getKey = 0; -static jlong Java_InnerStructB_getKey(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, - InnerStructB_clazz(env), 0); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_INSTANCE>( - env, InnerStructB_clazz(env), - "getKey", - -"(" -")" -"J", - &g_InnerStructB_getKey); - - jlong ret = - env->CallLongMethod(obj, - method_id); - jni_generator::CheckException(env); - return ret; -} - -static base::subtle::AtomicWord g_InnerStructB_getValue = 0; -static ScopedJavaLocalRef<jstring> Java_InnerStructB_getValue(JNIEnv* env, - jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, - InnerStructB_clazz(env), NULL); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_INSTANCE>( - env, InnerStructB_clazz(env), - "getValue", - -"(" -")" -"Ljava/lang/String;", - &g_InnerStructB_getValue); - - jstring ret = - static_cast<jstring>(env->CallObjectMethod(obj, - method_id)); - jni_generator::CheckException(env); - return ScopedJavaLocalRef<jstring>(env, ret); -} - -// Step 3: RegisterNatives. - -static const JNINativeMethod kMethodsSampleForTests[] = { - { "nativeInit", -"(" -"Ljava/lang/String;" -")" -"J", - reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeInit) - }, - { "nativeDestroy", -"(" -"J" -")" -"V", - reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeDestroy) - }, - { "nativeGetDoubleFunction", -"(" -")" -"D", - reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetDoubleFunction) - }, - { "nativeGetFloatFunction", -"(" -")" -"F", - reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetFloatFunction) - }, - { "nativeSetNonPODDatatype", -"(" -"Landroid/graphics/Rect;" -")" -"V", - reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeSetNonPODDatatype) - }, - { "nativeGetNonPODDatatype", -"(" -")" -"Ljava/lang/Object;", - reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeGetNonPODDatatype) - }, - { "nativeMethod", -"(" -"J" -")" -"I", - reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod) - }, - { "nativeMethodOtherP0", -"(" -"J" -")" -"D", - reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethodOtherP0) - }, - { "nativeAddStructB", -"(" -"J" -"Lorg/chromium/example/jni_generator/SampleForTests$InnerStructB;" -")" -"V", - reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeAddStructB) - }, - { "nativeIterateAndDoSomethingWithStructB", -"(" -"J" -")" -"V", - reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeIterateAndDoSomethingWithStructB) - }, - { "nativeReturnAString", -"(" -"J" -")" -"Ljava/lang/String;", - reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeReturnAString) - }, -}; - -static bool RegisterNativesImpl(JNIEnv* env) { - - g_InnerStructA_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( - base::android::GetClass(env, kInnerStructAClassPath).obj())); - g_SampleForTests_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( - base::android::GetClass(env, kSampleForTestsClassPath).obj())); - g_InnerStructB_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( - base::android::GetClass(env, kInnerStructBClassPath).obj())); - - const int kMethodsSampleForTestsSize = arraysize(kMethodsSampleForTests); - - if (env->RegisterNatives(SampleForTests_clazz(env), - kMethodsSampleForTests, - kMethodsSampleForTestsSize) < 0) { - jni_generator::HandleRegistrationError( - env, SampleForTests_clazz(env), __FILE__); - return false; - } - - return true; -} - -} // namespace android -} // namespace base - -#endif // org_chromium_example_jni_generator_SampleForTests_JNI diff --git a/base/android/jni_generator/java/src/org/chromium/example/jni_generator/SampleForTests.java b/base/android/jni_generator/java/src/org/chromium/example/jni_generator/SampleForTests.java index 4958f04..42d8e56 100644 --- a/base/android/jni_generator/java/src/org/chromium/example/jni_generator/SampleForTests.java +++ b/base/android/jni_generator/java/src/org/chromium/example/jni_generator/SampleForTests.java @@ -10,6 +10,7 @@ import org.chromium.base.annotations.AccessedByNative; import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNativeUnchecked; import org.chromium.base.annotations.JNINamespace; +import org.chromium.base.annotations.NativeCall; import org.chromium.base.annotations.NativeClassQualifiedName; import java.util.ArrayList; @@ -164,6 +165,13 @@ class SampleForTests { // String constants that look like comments don't confuse the generator: private String mArrgh = "*/*"; + private @interface SomeAnnotation {} + + // The generator is not confused by @Annotated parameters. + @CalledByNative + void javaMethodWithAnnotatedParam(@SomeAnnotation int foo) { + } + // --------------------------------------------------------------------------------------------- // Java fields which are accessed from C++ code only must be annotated with @AccessedByNative to // prevent them being eliminated when unreferenced code is stripped. @@ -301,4 +309,10 @@ class SampleForTests { native void nativeAddStructB(long nativeCPPClass, InnerStructB b); native void nativeIterateAndDoSomethingWithStructB(long nativeCPPClass); native String nativeReturnAString(long nativeCPPClass); + + // This inner class shows how to annotate native methods on inner classes. + static class InnerClass { + @NativeCall("InnerClass") + private static native int nativeGetInnerIntFunction(); + } } diff --git a/base/android/jni_generator/jni_generator.gyp b/base/android/jni_generator/jni_generator.gyp deleted file mode 100644 index ce936a0..0000000 --- a/base/android/jni_generator/jni_generator.gyp +++ /dev/null @@ -1,72 +0,0 @@ -# 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. - -{ - 'targets': [ - # GYP: //base/android/jni_generator:jni_generator_tests - { - 'target_name': 'jni_generator_py_tests', - 'type': 'none', - 'variables': { - 'stamp': '<(INTERMEDIATE_DIR)/jni_generator_py_tests.stamp', - }, - 'actions': [ - { - 'action_name': 'run_jni_generator_py_tests', - 'inputs': [ - 'jni_generator.py', - 'jni_generator_tests.py', - 'java/src/org/chromium/example/jni_generator/SampleForTests.java', - 'golden_sample_for_tests_jni.h', - ], - 'outputs': [ - '<(stamp)', - ], - 'action': [ - 'python', 'jni_generator_tests.py', - '--stamp=<(stamp)', - ], - }, - ], - }, - # GYP: //base/android/jni_generator:jni_sample_header - { - 'target_name': 'jni_sample_header', - 'type': 'none', - 'sources': [ - 'java/src/org/chromium/example/jni_generator/SampleForTests.java', - ], - 'variables': { - 'jni_gen_package': 'example', - }, - 'includes': [ '../../../build/jni_generator.gypi' ], - }, - # GYP: //base/android/jni_generator:jni_sample_java - { - 'target_name': 'jni_sample_java', - 'type': 'none', - 'variables': { - 'java_in_dir': '../../../base/android/jni_generator/java', - }, - 'dependencies': [ - '<(DEPTH)/base/base.gyp:base_java', - ], - 'includes': [ '../../../build/java.gypi' ], - }, - # GYP: //base/android/jni_generator:jni_generator_tests - { - 'target_name': 'jni_generator_tests', - 'type': 'executable', - 'dependencies': [ - '../../base.gyp:test_support_base', - 'jni_generator_py_tests', - 'jni_sample_header', - 'jni_sample_java', - ], - 'sources': [ - 'sample_for_tests.cc', - ], - }, - ], -} diff --git a/base/android/jni_generator/jni_generator.py b/base/android/jni_generator/jni_generator.py index b0134d6..99d8b42 100755 --- a/base/android/jni_generator/jni_generator.py +++ b/base/android/jni_generator/jni_generator.py @@ -138,7 +138,7 @@ def JavaDataTypeToC(java_type): def WrapCTypeForDeclaration(c_type): """Wrap the C datatype in a JavaRef if required.""" if re.match(RE_SCOPED_JNI_TYPES, c_type): - return 'const JavaParamRef<' + c_type + '>&' + return 'const base::android::JavaParamRef<' + c_type + '>&' else: return c_type @@ -153,7 +153,11 @@ def JavaDataTypeToCForCalledByNativeParam(java_type): if java_type == 'int': return 'JniIntWrapper' else: - return JavaDataTypeToC(java_type) + c_type = JavaDataTypeToC(java_type) + if re.match(RE_SCOPED_JNI_TYPES, c_type): + return 'const base::android::JavaRefOrBare<' + c_type + '>&' + else: + return c_type def JavaReturnValueToC(java_type): @@ -352,8 +356,14 @@ class JniParams(object): ret = [] for p in [p.strip() for p in params.split(',')]: items = p.split(' ') + + # Remove @Annotations from parameters. + while items[0].startswith('@'): + del items[0] + if 'final' in items: items.remove('final') + param = Param( datatype=items[0], name=(items[1] if len(items) > 1 else 'p%s' % len(ret)), @@ -402,6 +412,19 @@ def ExtractNatives(contents, ptr_type): return natives +def IsMainDexJavaClass(contents): + """Returns "true" if the class is annotated with "@MainDex", "false" if not. + + JNI registration doesn't always need to be completed for non-browser processes + since most Java code is only used by the browser process. Classes that are + needed by non-browser processes must explicitly be annotated with @MainDex + to force JNI registration. + """ + re_maindex = re.compile(r'@MainDex[\s\S]*class\s+\w+\s*{') + found = re.search(re_maindex, contents) + return 'true' if found else 'false' + + def GetStaticCastForReturnType(return_type): type_map = { 'String' : 'jstring', 'java/lang/String' : 'jstring', @@ -508,11 +531,17 @@ RE_SCOPED_JNI_TYPES = re.compile('jobject|jclass|jstring|jthrowable|.*Array') RE_CALLED_BY_NATIVE = re.compile( '@CalledByNative(?P<Unchecked>(Unchecked)*?)(?:\("(?P<annotation>.*)"\))?' '\s+(?P<prefix>[\w ]*?)' + '(:?\s*@\w+)?' # Ignore annotations in return types. '\s*(?P<return_type>\S+?)' '\s+(?P<name>\w+)' '\s*\((?P<params>[^\)]*)\)') +# Removes empty lines that are indented (i.e. start with 2x spaces). +def RemoveIndentedEmptyLines(string): + return re.sub('^(?: {2})+$\n', '', string, flags=re.MULTILINE) + + def ExtractCalledByNatives(contents): """Parses all methods annotated with @CalledByNative. @@ -618,8 +647,8 @@ class JNIFromJavaP(object): value=value.group('value'))) self.inl_header_file_generator = InlHeaderFileGenerator( - self.namespace, self.fully_qualified_class, [], - self.called_by_natives, self.constant_fields, options) + self.namespace, self.fully_qualified_class, [], self.called_by_natives, + self.constant_fields, options) def GetContent(self): return self.inl_header_file_generator.GetContent() @@ -653,12 +682,13 @@ class JNIFromJavaSource(object): jni_namespace = ExtractJNINamespace(contents) or options.namespace natives = ExtractNatives(contents, options.ptr_type) called_by_natives = ExtractCalledByNatives(contents) + maindex = IsMainDexJavaClass(contents) if len(natives) == 0 and len(called_by_natives) == 0: raise SyntaxError('Unable to find any JNI methods for %s.' % fully_qualified_class) inl_header_file_generator = InlHeaderFileGenerator( - jni_namespace, fully_qualified_class, natives, called_by_natives, - [], options) + jni_namespace, fully_qualified_class, natives, called_by_natives, [], + options, maindex) self.content = inl_header_file_generator.GetContent() @classmethod @@ -694,7 +724,7 @@ class InlHeaderFileGenerator(object): """Generates an inline header file for JNI integration.""" def __init__(self, namespace, fully_qualified_class, natives, - called_by_natives, constant_fields, options): + called_by_natives, constant_fields, options, maindex='false'): self.namespace = namespace self.fully_qualified_class = fully_qualified_class self.class_name = self.fully_qualified_class.split('/')[-1] @@ -702,6 +732,7 @@ class InlHeaderFileGenerator(object): self.called_by_natives = called_by_natives self.header_guard = fully_qualified_class.replace('/', '_') + '_JNI' self.constant_fields = constant_fields + self.maindex = maindex self.options = options @@ -760,6 +791,8 @@ $CLOSE_NAMESPACE 'HEADER_GUARD': self.header_guard, 'INCLUDES': self.GetIncludesString(), } + assert ((values['JNI_NATIVE_METHODS'] == '') == + (values['REGISTER_NATIVES'] == '')) return WrapOutput(template.substitute(values)) def GetClassPathDefinitionsString(self): @@ -818,7 +851,7 @@ $CLOSE_NAMESPACE def GetJNINativeMethodsString(self): """Returns the implementation of the array of native methods.""" - if self.options.native_exports and not self.options.native_exports_optional: + if not self.options.native_exports_optional: return '' template = Template("""\ static const JNINativeMethod kMethods${JAVA_CLASS}[] = { @@ -829,10 +862,13 @@ ${KMETHODS} def GetRegisterNativesString(self): """Returns the code for RegisterNatives.""" + natives = self.GetRegisterNativesImplString() + if not natives: + return '' + template = Template("""\ ${REGISTER_NATIVES_SIGNATURE} { ${EARLY_EXIT} -${CLASSES} ${NATIVES} return true; } @@ -841,20 +877,20 @@ ${NATIVES} early_exit = '' if self.options.native_exports_optional: early_exit = """\ - if (base::android::IsManualJniRegistrationDisabled()) return true; -""" + if (jni_generator::ShouldSkipJniRegistration(%s)) + return true; +""" % self.maindex - natives = self.GetRegisterNativesImplString() values = {'REGISTER_NATIVES_SIGNATURE': signature, 'EARLY_EXIT': early_exit, - 'CLASSES': self.GetFindClasses(), 'NATIVES': natives, } + return template.substitute(values) def GetRegisterNativesImplString(self): """Returns the shared implementation for RegisterNatives.""" - if self.options.native_exports and not self.options.native_exports_optional: + if not self.options.native_exports_optional: return '' template = Template("""\ @@ -954,7 +990,8 @@ ${NATIVES} return template.substitute(values) def GetJavaParamRefForCall(self, c_type, name): - return Template('JavaParamRef<${TYPE}>(env, ${NAME})').substitute({ + return Template( + 'base::android::JavaParamRef<${TYPE}>(env, ${NAME})').substitute({ 'TYPE': c_type, 'NAME': name, }) @@ -979,15 +1016,15 @@ ${NATIVES} params_in_call.append(p.name) params_in_call = ', '.join(params_in_call) - if self.options.native_exports: - stub_visibility = 'extern "C" __attribute__((visibility("default")))\n' - else: - stub_visibility = 'static ' return_type = return_declaration = JavaDataTypeToC(native.return_type) post_call = '' if re.match(RE_SCOPED_JNI_TYPES, return_type): post_call = '.Release()' - return_declaration = 'ScopedJavaLocalRef<' + return_type + '>' + return_declaration = ('base::android::ScopedJavaLocalRef<' + return_type + + '>') + profiling_entered_native = '' + if self.options.enable_profiling: + profiling_entered_native = 'JNI_LINK_SAVED_FRAME_POINTER;' values = { 'RETURN': return_type, 'RETURN_DECLARATION': return_declaration, @@ -997,7 +1034,7 @@ ${NATIVES} 'PARAMS_IN_CALL': params_in_call, 'POST_CALL': post_call, 'STUB_NAME': self.GetStubName(native), - 'STUB_VISIBILITY': stub_visibility, + 'PROFILING_ENTERED_NATIVE': profiling_entered_native, } if is_method: @@ -1010,8 +1047,8 @@ ${NATIVES} 'P0_TYPE': native.p0_type, }) template = Template("""\ -${STUB_VISIBILITY}${RETURN} ${STUB_NAME}(JNIEnv* env, - ${PARAMS_IN_STUB}) { +JNI_GENERATOR_EXPORT ${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_STUB}) { + ${PROFILING_ENTERED_NATIVE} ${P0_TYPE}* native = reinterpret_cast<${P0_TYPE}*>(${PARAM0_NAME}); CHECK_NATIVE_PTR(env, jcaller, native, "${NAME}"${OPTIONAL_ERROR_RETURN}); return native->${NAME}(${PARAMS_IN_CALL})${POST_CALL}; @@ -1021,16 +1058,21 @@ ${STUB_VISIBILITY}${RETURN} ${STUB_NAME}(JNIEnv* env, template = Template(""" static ${RETURN_DECLARATION} ${NAME}(JNIEnv* env, ${PARAMS}); -${STUB_VISIBILITY}${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_STUB}) { +JNI_GENERATOR_EXPORT ${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_STUB}) { + ${PROFILING_ENTERED_NATIVE} return ${NAME}(${PARAMS_IN_CALL})${POST_CALL}; } """) - return template.substitute(values) + return RemoveIndentedEmptyLines(template.substitute(values)) def GetArgument(self, param): - return ('as_jint(' + param.name + ')' - if param.datatype == 'int' else param.name) + if param.datatype == 'int': + return 'as_jint(' + param.name + ')' + elif re.match(RE_SCOPED_JNI_TYPES, JavaDataTypeToC(param.datatype)): + return param.name + '.obj()' + else: + return param.name def GetArgumentsInCall(self, params): """Return a string of arguments to call from native into Java""" @@ -1043,8 +1085,9 @@ ${STUB_VISIBILITY}${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_STUB}) { first_param_in_declaration = '' first_param_in_call = ('%s_clazz(env)' % java_class) else: - first_param_in_declaration = ', jobject obj' - first_param_in_call = 'obj' + first_param_in_declaration = ( + ', const base::android::JavaRefOrBare<jobject>& obj') + first_param_in_call = 'obj.obj()' params_in_declaration = self.GetCalledByNativeParamsInDeclaration( called_by_native) if params_in_declaration: @@ -1070,10 +1113,13 @@ ${STUB_VISIBILITY}${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_STUB}) { pre_call = ' ' + pre_call return_declaration = return_type + ' ret =' if re.match(RE_SCOPED_JNI_TYPES, return_type): - return_type = 'ScopedJavaLocalRef<' + return_type + '>' + return_type = 'base::android::ScopedJavaLocalRef<' + return_type + '>' return_clause = 'return ' + return_type + '(env, ret);' else: return_clause = 'return ret;' + profiling_leaving_native = '' + if self.options.enable_profiling: + profiling_leaving_native = 'JNI_SAVE_FRAME_POINTER;' return { 'JAVA_CLASS': java_class, 'RETURN_TYPE': return_type, @@ -1089,7 +1135,8 @@ ${STUB_VISIBILITY}${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_STUB}) { 'PARAMS_IN_CALL': params_in_call, 'METHOD_ID_VAR_NAME': called_by_native.method_id_var_name, 'CHECK_EXCEPTION': check_exception, - 'GET_METHOD_ID_IMPL': self.GetMethodIDImpl(called_by_native) + 'GET_METHOD_ID_IMPL': self.GetMethodIDImpl(called_by_native), + 'PROFILING_LEAVING_NATIVE': profiling_leaving_native, } @@ -1106,11 +1153,11 @@ ${FUNCTION_SIGNATURE} {""") template = Template(""" static base::subtle::AtomicWord g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = 0; ${FUNCTION_HEADER} - /* Must call RegisterNativesImpl() */ CHECK_CLAZZ(env, ${FIRST_PARAM_IN_CALL}, ${JAVA_CLASS}_clazz(env)${OPTIONAL_ERROR_RETURN}); jmethodID method_id = ${GET_METHOD_ID_IMPL} + ${PROFILING_LEAVING_NATIVE} ${RETURN_DECLARATION} ${PRE_CALL}env->${ENV_CALL}(${FIRST_PARAM_IN_CALL}, method_id${PARAMS_IN_CALL})${POST_CALL}; @@ -1125,7 +1172,7 @@ ${FUNCTION_HEADER} function_header_with_unused_template.substitute(values)) else: values['FUNCTION_HEADER'] = function_header_template.substitute(values) - return template.substitute(values) + return RemoveIndentedEmptyLines(template.substitute(values)) def GetKMethodArrayEntry(self, native): template = Template(' { "native${NAME}", ${JNI_SIGNATURE}, ' + @@ -1153,13 +1200,9 @@ ${FUNCTION_HEADER} ret = [] template = Template("""\ const char k${JAVA_CLASS}ClassPath[] = "${JNI_CLASS_PATH}";""") - native_classes = self.GetUniqueClasses(self.natives) - called_by_native_classes = self.GetUniqueClasses(self.called_by_natives) - if self.options.native_exports: - all_classes = called_by_native_classes - else: - all_classes = native_classes - all_classes.update(called_by_native_classes) + all_classes = self.GetUniqueClasses(self.called_by_natives) + if self.options.native_exports_optional: + all_classes.update(self.GetUniqueClasses(self.natives)) for clazz in all_classes: values = { @@ -1169,21 +1212,14 @@ const char k${JAVA_CLASS}ClassPath[] = "${JNI_CLASS_PATH}";""") ret += [template.substitute(values)] ret += '' - class_getter_methods = [] - if self.options.native_exports: - template = Template("""\ + template = Template("""\ // Leaking this jclass as we cannot use LazyInstance from some threads. base::subtle::AtomicWord g_${JAVA_CLASS}_clazz __attribute__((unused)) = 0; #define ${JAVA_CLASS}_clazz(env) \ base::android::LazyGetClass(env, k${JAVA_CLASS}ClassPath, \ &g_${JAVA_CLASS}_clazz)""") - else: - template = Template("""\ -// Leaking this jclass as we cannot use LazyInstance from some threads. -jclass g_${JAVA_CLASS}_clazz = NULL; -#define ${JAVA_CLASS}_clazz(env) g_${JAVA_CLASS}_clazz""") - for clazz in called_by_native_classes: + for clazz in all_classes: values = { 'JAVA_CLASS': clazz, } @@ -1191,19 +1227,6 @@ jclass g_${JAVA_CLASS}_clazz = NULL; return '\n'.join(ret) - def GetFindClasses(self): - """Returns the imlementation of FindClass for all known classes.""" - if self.options.native_exports: - return '\n' - template = Template("""\ - g_${JAVA_CLASS}_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( - base::android::GetClass(env, k${JAVA_CLASS}ClassPath).obj()));""") - ret = [] - for clazz in self.GetUniqueClasses(self.called_by_natives): - values = {'JAVA_CLASS': clazz} - ret += [template.substitute(values)] - return '\n'.join(ret) - def GetMethodIDImpl(self, called_by_native): """Returns the implementation of GetMethodID.""" template = Template("""\ @@ -1366,15 +1389,12 @@ See SampleForTests.java for more details. help='The path to cpp command.') option_parser.add_option('--javap', default='javap', help='The path to javap command.') - option_parser.add_option('--native_exports', action='store_true', - help='Native method registration through .so ' - 'exports.') option_parser.add_option('--native_exports_optional', action='store_true', help='Support both explicit and native method' 'registration.') + option_parser.add_option('--enable_profiling', action='store_true', + help='Add additional profiling instrumentation.') options, args = option_parser.parse_args(argv) - if options.native_exports_optional: - options.native_exports = True if options.jar_file: input_file = ExtractJarInputFile(options.jar_file, options.input_file, options.output_dir) @@ -1391,9 +1411,7 @@ See SampleForTests.java for more details. GenerateJNIHeader(input_file, output_file, options) if options.depfile: - build_utils.WriteDepfile( - options.depfile, - build_utils.GetPythonDependencies()) + build_utils.WriteDepfile(options.depfile, output_file) if __name__ == '__main__': diff --git a/base/android/jni_generator/jni_generator_helper.h b/base/android/jni_generator/jni_generator_helper.h index 9075d3c..3062806 100644 --- a/base/android/jni_generator/jni_generator_helper.h +++ b/base/android/jni_generator/jni_generator_helper.h @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - #ifndef BASE_ANDROID_JNI_GENERATOR_JNI_GENERATOR_HELPER_H_ #define BASE_ANDROID_JNI_GENERATOR_JNI_GENERATOR_HELPER_H_ @@ -11,30 +10,53 @@ #include "base/android/jni_android.h" #include "base/android/scoped_java_ref.h" #include "base/logging.h" +#include "build/build_config.h" // Project-specific macros used by the header files generated by // jni_generator.py. Different projects can then specify their own // implementation for this file. #define CHECK_NATIVE_PTR(env, jcaller, native_ptr, method_name, ...) \ - DCHECK(native_ptr) << method_name; + DCHECK(native_ptr) << method_name; -#define CHECK_CLAZZ(env, jcaller, clazz, ...) \ - DCHECK(clazz); +#define CHECK_CLAZZ(env, jcaller, clazz, ...) DCHECK(clazz); -namespace jni_generator { +#if defined(ARCH_CPU_X86) +// Dalvik JIT generated code doesn't guarantee 16-byte stack alignment on +// x86 - use force_align_arg_pointer to realign the stack at the JNI +// boundary. crbug.com/655248 +#define JNI_GENERATOR_EXPORT \ + extern "C" __attribute__((visibility("default"), force_align_arg_pointer)) +#else +#define JNI_GENERATOR_EXPORT extern "C" __attribute__((visibility("default"))) +#endif - inline void HandleRegistrationError(JNIEnv* env, jclass clazz, - const char* filename) { - LOG(ERROR) << "RegisterNatives failed in " << filename; - } +namespace jni_generator { - inline void CheckException(JNIEnv* env) { - base::android::CheckException(env); +inline void HandleRegistrationError(JNIEnv* env, + jclass clazz, + const char* filename) { + LOG(ERROR) << "RegisterNatives failed in " << filename; +} + +inline void CheckException(JNIEnv* env) { + base::android::CheckException(env); +} + +inline bool ShouldSkipJniRegistration(bool is_maindex_class) { + switch (base::android::GetJniRegistrationType()) { + case base::android::ALL_JNI_REGISTRATION: + return false; + case base::android::NO_JNI_REGISTRATION: + // TODO(estevenson): Change this to a DCHECK. + return true; + case base::android::SELECTIVE_JNI_REGISTRATION: + return !is_maindex_class; + default: + NOTREACHED(); + return false; } +} } // namespace jni_generator -using base::android::ScopedJavaLocalRef; -using base::android::JavaParamRef; - #endif // BASE_ANDROID_JNI_GENERATOR_JNI_GENERATOR_HELPER_H_ diff --git a/base/android/jni_generator/jni_generator_tests.py b/base/android/jni_generator/jni_generator_tests.py index 5126896..c0c8238 100755 --- a/base/android/jni_generator/jni_generator_tests.py +++ b/base/android/jni_generator/jni_generator_tests.py @@ -40,8 +40,8 @@ class TestOptions(object): self.ptr_type = 'long' self.cpp = 'cpp' self.javap = 'javap' - self.native_exports = False - self.native_exports_optional = False + self.native_exports_optional = True + self.enable_profiling = False class TestGenerator(unittest.TestCase): def assertObjEquals(self, first, second): @@ -403,6 +403,10 @@ class TestGenerator(unittest.TestCase): return } } + @CalledByNative + public static @Status int updateStatus(@Status int status) { + return getAndUpdateStatus(status); + } @CalledByNativeUnchecked private void uncheckedCall(int iParam); @@ -525,6 +529,17 @@ class TestGenerator(unittest.TestCase): unchecked=False, ), CalledByNative( + return_type='int', + system_class=False, + static=True, + name='updateStatus', + method_id_var_name='updateStatus', + java_class_name='', + params=[Param(datatype='int', name='status')], + env_call=('Integer', ''), + unchecked=False, + ), + CalledByNative( return_type='void', system_class=False, static=False, @@ -819,7 +834,7 @@ public class java.util.HashSet { content = file(os.path.join(script_dir, 'java/src/org/chromium/example/jni_generator/SampleForTests.java') ).read() - golden_file = os.path.join(script_dir, 'golden_sample_for_tests_jni.h') + golden_file = os.path.join(script_dir, 'SampleForTests_jni.golden') golden_content = file(golden_file).read() jni_from_java = jni_generator.JNIFromJavaSource( content, 'org/chromium/example/jni_generator/SampleForTests', @@ -935,7 +950,34 @@ class Foo { natives, [], [], test_options) self.assertGoldenTextEquals(h.GetContent()) - def runNativeExportsOption(self, optional): + def testMainDexFile(self): + test_data = """ + package org.chromium.example.jni_generator; + + @MainDex + class Test { + private static native int nativeStaticMethod(long nativeTest, int arg1); + } + """ + options = TestOptions() + jni_from_java = jni_generator.JNIFromJavaSource( + test_data, 'org/chromium/foo/Bar', options) + self.assertGoldenTextEquals(jni_from_java.GetContent()) + + def testNonMainDexFile(self): + test_data = """ + package org.chromium.example.jni_generator; + + class Test { + private static native int nativeStaticMethod(long nativeTest, int arg1); + } + """ + options = TestOptions() + jni_from_java = jni_generator.JNIFromJavaSource( + test_data, 'org/chromium/foo/Bar', options) + self.assertGoldenTextEquals(jni_from_java.GetContent()) + + def testNativeExportsOnlyOption(self): test_data = """ package org.chromium.example.jni_generator; @@ -967,19 +1009,10 @@ class Foo { } """ options = TestOptions() - options.native_exports = True - options.native_exports_optional = optional + options.native_exports_optional = False jni_from_java = jni_generator.JNIFromJavaSource( test_data, 'org/chromium/example/jni_generator/SampleForTests', options) - return jni_from_java.GetContent() - - def testNativeExportsOption(self): - content = self.runNativeExportsOption(False) - self.assertGoldenTextEquals(content) - - def testNativeExportsOptionalOption(self): - content = self.runNativeExportsOption(True) - self.assertGoldenTextEquals(content) + self.assertGoldenTextEquals(jni_from_java.GetContent()) def testOuterInnerRaises(self): test_data = """ @@ -1041,7 +1074,7 @@ class Foo { def TouchStamp(stamp_path): dir_name = os.path.dirname(stamp_path) if not os.path.isdir(dir_name): - os.makedirs() + os.makedirs(dir_name) with open(stamp_path, 'a'): os.utime(stamp_path, None) diff --git a/base/android/jni_generator/sample_for_tests.cc b/base/android/jni_generator/sample_for_tests.cc index 08e5ac9..42b2143 100644 --- a/base/android/jni_generator/sample_for_tests.cc +++ b/base/android/jni_generator/sample_for_tests.cc @@ -51,8 +51,8 @@ void CPPClass::AddStructB(JNIEnv* env, const JavaParamRef<jobject>& caller, const JavaParamRef<jobject>& structb) { long key = Java_InnerStructB_getKey(env, structb); - std::string value = ConvertJavaStringToUTF8( - env, Java_InnerStructB_getValue(env, structb).obj()); + std::string value = + ConvertJavaStringToUTF8(env, Java_InnerStructB_getValue(env, structb)); map_[key] = value; } @@ -100,6 +100,10 @@ static ScopedJavaLocalRef<jobject> GetNonPODDatatype( return ScopedJavaLocalRef<jobject>(); } +static jint GetInnerIntFunction(JNIEnv*, const JavaParamRef<jclass>&) { + return 0; +} + } // namespace android } // namespace base @@ -113,7 +117,7 @@ int main() { // This is how you call a java method from C++. Note that you must have // obtained the jobject somehow. - jobject my_java_object = NULL; + ScopedJavaLocalRef<jobject> my_java_object; int bar = base::android::Java_SampleForTests_javaMethod( env, my_java_object, 1, 2); @@ -123,14 +127,16 @@ int main() { // Creates a "struct" that will then be used by the java side. ScopedJavaLocalRef<jobject> struct_a = base::android::Java_InnerStructA_create( - env, 0, 1, ConvertUTF8ToJavaString(env, "test").obj()); - base::android::Java_SampleForTests_addStructA( - env, my_java_object, struct_a.obj()); + env, 0, 1, ConvertUTF8ToJavaString(env, "test")); + base::android::Java_SampleForTests_addStructA(env, my_java_object, + struct_a); } base::android::Java_SampleForTests_iterateAndDoSomething(env, my_java_object); base::android::Java_SampleForTests_packagePrivateJavaMethod(env, my_java_object); base::android::Java_SampleForTests_methodThatThrowsException(env, my_java_object); + base::android::Java_SampleForTests_javaMethodWithAnnotatedParam( + env, my_java_object, 42); return 0; } diff --git a/base/android/jni_generator/testCalledByNatives.golden b/base/android/jni_generator/testCalledByNatives.golden index 3bc586c..ac86b2e 100644 --- a/base/android/jni_generator/testCalledByNatives.golden +++ b/base/android/jni_generator/testCalledByNatives.golden @@ -21,32 +21,31 @@ namespace { const char kTestJniClassPath[] = "org/chromium/TestJni"; const char kInfoBarClassPath[] = "org/chromium/TestJni$InfoBar"; // Leaking this jclass as we cannot use LazyInstance from some threads. -jclass g_TestJni_clazz = NULL; -#define TestJni_clazz(env) g_TestJni_clazz +base::subtle::AtomicWord g_TestJni_clazz __attribute__((unused)) = 0; +#define TestJni_clazz(env) base::android::LazyGetClass(env, kTestJniClassPath, &g_TestJni_clazz) // Leaking this jclass as we cannot use LazyInstance from some threads. -jclass g_InfoBar_clazz = NULL; -#define InfoBar_clazz(env) g_InfoBar_clazz +base::subtle::AtomicWord g_InfoBar_clazz __attribute__((unused)) = 0; +#define InfoBar_clazz(env) base::android::LazyGetClass(env, kInfoBarClassPath, &g_InfoBar_clazz) } // namespace // Step 2: method stubs. static base::subtle::AtomicWord g_TestJni_showConfirmInfoBar = 0; -static ScopedJavaLocalRef<jobject> Java_TestJni_showConfirmInfoBar(JNIEnv* env, - jobject obj, JniIntWrapper nativeInfoBar, - jstring buttonOk, - jstring buttonCancel, - jstring title, - jobject icon) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static base::android::ScopedJavaLocalRef<jobject> + Java_TestJni_showConfirmInfoBar(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper nativeInfoBar, + const base::android::JavaRefOrBare<jstring>& buttonOk, + const base::android::JavaRefOrBare<jstring>& buttonCancel, + const base::android::JavaRefOrBare<jstring>& title, + const base::android::JavaRefOrBare<jobject>& icon) { + CHECK_CLAZZ(env, obj.obj(), TestJni_clazz(env), NULL); jmethodID method_id = base::android::MethodID::LazyGet< base::android::MethodID::TYPE_INSTANCE>( env, TestJni_clazz(env), "showConfirmInfoBar", - "(" "I" "Ljava/lang/String;" @@ -58,28 +57,27 @@ static ScopedJavaLocalRef<jobject> Java_TestJni_showConfirmInfoBar(JNIEnv* env, &g_TestJni_showConfirmInfoBar); jobject ret = - env->CallObjectMethod(obj, - method_id, as_jint(nativeInfoBar), buttonOk, buttonCancel, title, - icon); + env->CallObjectMethod(obj.obj(), + method_id, as_jint(nativeInfoBar), buttonOk.obj(), buttonCancel.obj(), + title.obj(), icon.obj()); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jobject>(env, ret); + return base::android::ScopedJavaLocalRef<jobject>(env, ret); } static base::subtle::AtomicWord g_TestJni_showAutoLoginInfoBar = 0; -static ScopedJavaLocalRef<jobject> Java_TestJni_showAutoLoginInfoBar(JNIEnv* - env, jobject obj, JniIntWrapper nativeInfoBar, - jstring realm, - jstring account, - jstring args) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static base::android::ScopedJavaLocalRef<jobject> + Java_TestJni_showAutoLoginInfoBar(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper nativeInfoBar, + const base::android::JavaRefOrBare<jstring>& realm, + const base::android::JavaRefOrBare<jstring>& account, + const base::android::JavaRefOrBare<jstring>& args) { + CHECK_CLAZZ(env, obj.obj(), TestJni_clazz(env), NULL); jmethodID method_id = base::android::MethodID::LazyGet< base::android::MethodID::TYPE_INSTANCE>( env, TestJni_clazz(env), "showAutoLoginInfoBar", - "(" "I" "Ljava/lang/String;" @@ -90,40 +88,39 @@ static ScopedJavaLocalRef<jobject> Java_TestJni_showAutoLoginInfoBar(JNIEnv* &g_TestJni_showAutoLoginInfoBar); jobject ret = - env->CallObjectMethod(obj, - method_id, as_jint(nativeInfoBar), realm, account, args); + env->CallObjectMethod(obj.obj(), + method_id, as_jint(nativeInfoBar), realm.obj(), account.obj(), + args.obj()); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jobject>(env, ret); + return base::android::ScopedJavaLocalRef<jobject>(env, ret); } static base::subtle::AtomicWord g_InfoBar_dismiss = 0; -static void Java_InfoBar_dismiss(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static void Java_InfoBar_dismiss(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), InfoBar_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< base::android::MethodID::TYPE_INSTANCE>( env, InfoBar_clazz(env), "dismiss", - "(" ")" "V", &g_InfoBar_dismiss); - env->CallVoidMethod(obj, + env->CallVoidMethod(obj.obj(), method_id); jni_generator::CheckException(env); - } static base::subtle::AtomicWord g_TestJni_shouldShowAutoLogin = 0; -static jboolean Java_TestJni_shouldShowAutoLogin(JNIEnv* env, jobject view, - jstring realm, - jstring account, - jstring args) { - /* Must call RegisterNativesImpl() */ +static jboolean Java_TestJni_shouldShowAutoLogin(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& view, + const base::android::JavaRefOrBare<jstring>& realm, + const base::android::JavaRefOrBare<jstring>& account, + const base::android::JavaRefOrBare<jstring>& args) { CHECK_CLAZZ(env, TestJni_clazz(env), TestJni_clazz(env), false); jmethodID method_id = @@ -131,7 +128,6 @@ static jboolean Java_TestJni_shouldShowAutoLogin(JNIEnv* env, jobject view, base::android::MethodID::TYPE_STATIC>( env, TestJni_clazz(env), "shouldShowAutoLogin", - "(" "Landroid/view/View;" "Ljava/lang/String;" @@ -143,15 +139,14 @@ static jboolean Java_TestJni_shouldShowAutoLogin(JNIEnv* env, jobject view, jboolean ret = env->CallStaticBooleanMethod(TestJni_clazz(env), - method_id, view, realm, account, args); + method_id, view.obj(), realm.obj(), account.obj(), args.obj()); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_TestJni_openUrl = 0; -static ScopedJavaLocalRef<jobject> Java_TestJni_openUrl(JNIEnv* env, jstring - url) { - /* Must call RegisterNativesImpl() */ +static base::android::ScopedJavaLocalRef<jobject> Java_TestJni_openUrl(JNIEnv* + env, const base::android::JavaRefOrBare<jstring>& url) { CHECK_CLAZZ(env, TestJni_clazz(env), TestJni_clazz(env), NULL); jmethodID method_id = @@ -159,7 +154,6 @@ static ScopedJavaLocalRef<jobject> Java_TestJni_openUrl(JNIEnv* env, jstring base::android::MethodID::TYPE_STATIC>( env, TestJni_clazz(env), "openUrl", - "(" "Ljava/lang/String;" ")" @@ -168,27 +162,25 @@ static ScopedJavaLocalRef<jobject> Java_TestJni_openUrl(JNIEnv* env, jstring jobject ret = env->CallStaticObjectMethod(TestJni_clazz(env), - method_id, url); + method_id, url.obj()); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jobject>(env, ret); + return base::android::ScopedJavaLocalRef<jobject>(env, ret); } static base::subtle::AtomicWord g_TestJni_activateHardwareAcceleration = 0; -static void Java_TestJni_activateHardwareAcceleration(JNIEnv* env, jobject obj, - jboolean activated, +static void Java_TestJni_activateHardwareAcceleration(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, jboolean activated, JniIntWrapper iPid, JniIntWrapper iType, JniIntWrapper iPrimaryID, JniIntWrapper iSecondaryID) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), TestJni_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< base::android::MethodID::TYPE_INSTANCE>( env, TestJni_clazz(env), "activateHardwareAcceleration", - "(" "Z" "I" @@ -199,310 +191,307 @@ static void Java_TestJni_activateHardwareAcceleration(JNIEnv* env, jobject obj, "V", &g_TestJni_activateHardwareAcceleration); - env->CallVoidMethod(obj, + env->CallVoidMethod(obj.obj(), method_id, activated, as_jint(iPid), as_jint(iType), as_jint(iPrimaryID), as_jint(iSecondaryID)); jni_generator::CheckException(env); +} + +static base::subtle::AtomicWord g_TestJni_updateStatus = 0; +static jint Java_TestJni_updateStatus(JNIEnv* env, JniIntWrapper status) { + CHECK_CLAZZ(env, TestJni_clazz(env), + TestJni_clazz(env), 0); + jmethodID method_id = + base::android::MethodID::LazyGet< + base::android::MethodID::TYPE_STATIC>( + env, TestJni_clazz(env), + "updateStatus", +"(" +"I" +")" +"I", + &g_TestJni_updateStatus); + jint ret = + env->CallStaticIntMethod(TestJni_clazz(env), + method_id, as_jint(status)); + jni_generator::CheckException(env); + return ret; } static base::subtle::AtomicWord g_TestJni_uncheckedCall = 0; -static void Java_TestJni_uncheckedCall(JNIEnv* env, jobject obj, JniIntWrapper - iParam) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static void Java_TestJni_uncheckedCall(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper iParam) { + CHECK_CLAZZ(env, obj.obj(), TestJni_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< base::android::MethodID::TYPE_INSTANCE>( env, TestJni_clazz(env), "uncheckedCall", - "(" "I" ")" "V", &g_TestJni_uncheckedCall); - env->CallVoidMethod(obj, + env->CallVoidMethod(obj.obj(), method_id, as_jint(iParam)); - } static base::subtle::AtomicWord g_TestJni_returnByteArray = 0; -static ScopedJavaLocalRef<jbyteArray> Java_TestJni_returnByteArray(JNIEnv* env, - jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static base::android::ScopedJavaLocalRef<jbyteArray> + Java_TestJni_returnByteArray(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), TestJni_clazz(env), NULL); jmethodID method_id = base::android::MethodID::LazyGet< base::android::MethodID::TYPE_INSTANCE>( env, TestJni_clazz(env), "returnByteArray", - "(" ")" "[B", &g_TestJni_returnByteArray); jbyteArray ret = - static_cast<jbyteArray>(env->CallObjectMethod(obj, + static_cast<jbyteArray>(env->CallObjectMethod(obj.obj(), method_id)); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jbyteArray>(env, ret); + return base::android::ScopedJavaLocalRef<jbyteArray>(env, ret); } static base::subtle::AtomicWord g_TestJni_returnBooleanArray = 0; -static ScopedJavaLocalRef<jbooleanArray> Java_TestJni_returnBooleanArray(JNIEnv* - env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static base::android::ScopedJavaLocalRef<jbooleanArray> + Java_TestJni_returnBooleanArray(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), TestJni_clazz(env), NULL); jmethodID method_id = base::android::MethodID::LazyGet< base::android::MethodID::TYPE_INSTANCE>( env, TestJni_clazz(env), "returnBooleanArray", - "(" ")" "[Z", &g_TestJni_returnBooleanArray); jbooleanArray ret = - static_cast<jbooleanArray>(env->CallObjectMethod(obj, + static_cast<jbooleanArray>(env->CallObjectMethod(obj.obj(), method_id)); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jbooleanArray>(env, ret); + return base::android::ScopedJavaLocalRef<jbooleanArray>(env, ret); } static base::subtle::AtomicWord g_TestJni_returnCharArray = 0; -static ScopedJavaLocalRef<jcharArray> Java_TestJni_returnCharArray(JNIEnv* env, - jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static base::android::ScopedJavaLocalRef<jcharArray> + Java_TestJni_returnCharArray(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), TestJni_clazz(env), NULL); jmethodID method_id = base::android::MethodID::LazyGet< base::android::MethodID::TYPE_INSTANCE>( env, TestJni_clazz(env), "returnCharArray", - "(" ")" "[C", &g_TestJni_returnCharArray); jcharArray ret = - static_cast<jcharArray>(env->CallObjectMethod(obj, + static_cast<jcharArray>(env->CallObjectMethod(obj.obj(), method_id)); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jcharArray>(env, ret); + return base::android::ScopedJavaLocalRef<jcharArray>(env, ret); } static base::subtle::AtomicWord g_TestJni_returnShortArray = 0; -static ScopedJavaLocalRef<jshortArray> Java_TestJni_returnShortArray(JNIEnv* - env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static base::android::ScopedJavaLocalRef<jshortArray> + Java_TestJni_returnShortArray(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), TestJni_clazz(env), NULL); jmethodID method_id = base::android::MethodID::LazyGet< base::android::MethodID::TYPE_INSTANCE>( env, TestJni_clazz(env), "returnShortArray", - "(" ")" "[S", &g_TestJni_returnShortArray); jshortArray ret = - static_cast<jshortArray>(env->CallObjectMethod(obj, + static_cast<jshortArray>(env->CallObjectMethod(obj.obj(), method_id)); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jshortArray>(env, ret); + return base::android::ScopedJavaLocalRef<jshortArray>(env, ret); } static base::subtle::AtomicWord g_TestJni_returnIntArray = 0; -static ScopedJavaLocalRef<jintArray> Java_TestJni_returnIntArray(JNIEnv* env, - jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static base::android::ScopedJavaLocalRef<jintArray> + Java_TestJni_returnIntArray(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), TestJni_clazz(env), NULL); jmethodID method_id = base::android::MethodID::LazyGet< base::android::MethodID::TYPE_INSTANCE>( env, TestJni_clazz(env), "returnIntArray", - "(" ")" "[I", &g_TestJni_returnIntArray); jintArray ret = - static_cast<jintArray>(env->CallObjectMethod(obj, + static_cast<jintArray>(env->CallObjectMethod(obj.obj(), method_id)); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jintArray>(env, ret); + return base::android::ScopedJavaLocalRef<jintArray>(env, ret); } static base::subtle::AtomicWord g_TestJni_returnLongArray = 0; -static ScopedJavaLocalRef<jlongArray> Java_TestJni_returnLongArray(JNIEnv* env, - jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static base::android::ScopedJavaLocalRef<jlongArray> + Java_TestJni_returnLongArray(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), TestJni_clazz(env), NULL); jmethodID method_id = base::android::MethodID::LazyGet< base::android::MethodID::TYPE_INSTANCE>( env, TestJni_clazz(env), "returnLongArray", - "(" ")" "[J", &g_TestJni_returnLongArray); jlongArray ret = - static_cast<jlongArray>(env->CallObjectMethod(obj, + static_cast<jlongArray>(env->CallObjectMethod(obj.obj(), method_id)); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jlongArray>(env, ret); + return base::android::ScopedJavaLocalRef<jlongArray>(env, ret); } static base::subtle::AtomicWord g_TestJni_returnDoubleArray = 0; -static ScopedJavaLocalRef<jdoubleArray> Java_TestJni_returnDoubleArray(JNIEnv* - env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static base::android::ScopedJavaLocalRef<jdoubleArray> + Java_TestJni_returnDoubleArray(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), TestJni_clazz(env), NULL); jmethodID method_id = base::android::MethodID::LazyGet< base::android::MethodID::TYPE_INSTANCE>( env, TestJni_clazz(env), "returnDoubleArray", - "(" ")" "[D", &g_TestJni_returnDoubleArray); jdoubleArray ret = - static_cast<jdoubleArray>(env->CallObjectMethod(obj, + static_cast<jdoubleArray>(env->CallObjectMethod(obj.obj(), method_id)); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jdoubleArray>(env, ret); + return base::android::ScopedJavaLocalRef<jdoubleArray>(env, ret); } static base::subtle::AtomicWord g_TestJni_returnObjectArray = 0; -static ScopedJavaLocalRef<jobjectArray> Java_TestJni_returnObjectArray(JNIEnv* - env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static base::android::ScopedJavaLocalRef<jobjectArray> + Java_TestJni_returnObjectArray(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), TestJni_clazz(env), NULL); jmethodID method_id = base::android::MethodID::LazyGet< base::android::MethodID::TYPE_INSTANCE>( env, TestJni_clazz(env), "returnObjectArray", - "(" ")" "[Ljava/lang/Object;", &g_TestJni_returnObjectArray); jobjectArray ret = - static_cast<jobjectArray>(env->CallObjectMethod(obj, + static_cast<jobjectArray>(env->CallObjectMethod(obj.obj(), method_id)); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jobjectArray>(env, ret); + return base::android::ScopedJavaLocalRef<jobjectArray>(env, ret); } static base::subtle::AtomicWord g_TestJni_returnArrayOfByteArray = 0; -static ScopedJavaLocalRef<jobjectArray> - Java_TestJni_returnArrayOfByteArray(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static base::android::ScopedJavaLocalRef<jobjectArray> + Java_TestJni_returnArrayOfByteArray(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), TestJni_clazz(env), NULL); jmethodID method_id = base::android::MethodID::LazyGet< base::android::MethodID::TYPE_INSTANCE>( env, TestJni_clazz(env), "returnArrayOfByteArray", - "(" ")" "[[B", &g_TestJni_returnArrayOfByteArray); jobjectArray ret = - static_cast<jobjectArray>(env->CallObjectMethod(obj, + static_cast<jobjectArray>(env->CallObjectMethod(obj.obj(), method_id)); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jobjectArray>(env, ret); + return base::android::ScopedJavaLocalRef<jobjectArray>(env, ret); } static base::subtle::AtomicWord g_TestJni_getCompressFormat = 0; -static ScopedJavaLocalRef<jobject> Java_TestJni_getCompressFormat(JNIEnv* env, - jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static base::android::ScopedJavaLocalRef<jobject> + Java_TestJni_getCompressFormat(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), TestJni_clazz(env), NULL); jmethodID method_id = base::android::MethodID::LazyGet< base::android::MethodID::TYPE_INSTANCE>( env, TestJni_clazz(env), "getCompressFormat", - "(" ")" "Landroid/graphics/Bitmap$CompressFormat;", &g_TestJni_getCompressFormat); jobject ret = - env->CallObjectMethod(obj, + env->CallObjectMethod(obj.obj(), method_id); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jobject>(env, ret); + return base::android::ScopedJavaLocalRef<jobject>(env, ret); } static base::subtle::AtomicWord g_TestJni_getCompressFormatList = 0; -static ScopedJavaLocalRef<jobject> Java_TestJni_getCompressFormatList(JNIEnv* - env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static base::android::ScopedJavaLocalRef<jobject> + Java_TestJni_getCompressFormatList(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), TestJni_clazz(env), NULL); jmethodID method_id = base::android::MethodID::LazyGet< base::android::MethodID::TYPE_INSTANCE>( env, TestJni_clazz(env), "getCompressFormatList", - "(" ")" "Ljava/util/List;", &g_TestJni_getCompressFormatList); jobject ret = - env->CallObjectMethod(obj, + env->CallObjectMethod(obj.obj(), method_id); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jobject>(env, ret); + return base::android::ScopedJavaLocalRef<jobject>(env, ret); } // Step 3: RegisterNatives. -static bool RegisterNativesImpl(JNIEnv* env) { - - g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( - base::android::GetClass(env, kTestJniClassPath).obj())); - g_InfoBar_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( - base::android::GetClass(env, kInfoBarClassPath).obj())); - - return true; -} - #endif // org_chromium_TestJni_JNI diff --git a/base/android/jni_generator/testConstantsFromJavaP.golden b/base/android/jni_generator/testConstantsFromJavaP.golden index 97c00f9..b16956f 100644 --- a/base/android/jni_generator/testConstantsFromJavaP.golden +++ b/base/android/jni_generator/testConstantsFromJavaP.golden @@ -20,8 +20,8 @@ namespace { const char kMotionEventClassPath[] = "android/view/MotionEvent"; // Leaking this jclass as we cannot use LazyInstance from some threads. -jclass g_MotionEvent_clazz = NULL; -#define MotionEvent_clazz(env) g_MotionEvent_clazz +base::subtle::AtomicWord g_MotionEvent_clazz __attribute__((unused)) = 0; +#define MotionEvent_clazz(env) base::android::LazyGetClass(env, kMotionEventClassPath, &g_MotionEvent_clazz) } // namespace @@ -113,11 +113,11 @@ enum Java_MotionEvent_constant_fields { // Step 2: method stubs. static base::subtle::AtomicWord g_MotionEvent_finalize = 0; -static void Java_MotionEvent_finalize(JNIEnv* env, jobject obj) __attribute__ - ((unused)); -static void Java_MotionEvent_finalize(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static void Java_MotionEvent_finalize(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static void Java_MotionEvent_finalize(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -127,22 +127,21 @@ static void Java_MotionEvent_finalize(JNIEnv* env, jobject obj) { "()V", &g_MotionEvent_finalize); - env->CallVoidMethod(obj, + env->CallVoidMethod(obj.obj(), method_id); jni_generator::CheckException(env); - } static base::subtle::AtomicWord g_MotionEvent_obtainAVME_J_J_I_I_LAVMEPP_LAVMEPC_I_I_F_F_I_I_I_I = 0; -static ScopedJavaLocalRef<jobject> +static base::android::ScopedJavaLocalRef<jobject> Java_MotionEvent_obtainAVME_J_J_I_I_LAVMEPP_LAVMEPC_I_I_F_F_I_I_I_I(JNIEnv* env, jlong p0, jlong p1, JniIntWrapper p2, JniIntWrapper p3, - jobjectArray p4, - jobjectArray p5, + const base::android::JavaRefOrBare<jobjectArray>& p4, + const base::android::JavaRefOrBare<jobjectArray>& p5, JniIntWrapper p6, JniIntWrapper p7, jfloat p8, @@ -151,14 +150,14 @@ static ScopedJavaLocalRef<jobject> JniIntWrapper p11, JniIntWrapper p12, JniIntWrapper p13) __attribute__ ((unused)); -static ScopedJavaLocalRef<jobject> +static base::android::ScopedJavaLocalRef<jobject> Java_MotionEvent_obtainAVME_J_J_I_I_LAVMEPP_LAVMEPC_I_I_F_F_I_I_I_I(JNIEnv* env, jlong p0, jlong p1, JniIntWrapper p2, JniIntWrapper p3, - jobjectArray p4, - jobjectArray p5, + const base::android::JavaRefOrBare<jobjectArray>& p4, + const base::android::JavaRefOrBare<jobjectArray>& p5, JniIntWrapper p6, JniIntWrapper p7, jfloat p8, @@ -167,7 +166,6 @@ static ScopedJavaLocalRef<jobject> JniIntWrapper p11, JniIntWrapper p12, JniIntWrapper p13) { - /* Must call RegisterNativesImpl() */ CHECK_CLAZZ(env, MotionEvent_clazz(env), MotionEvent_clazz(env), NULL); jmethodID method_id = @@ -180,23 +178,23 @@ static ScopedJavaLocalRef<jobject> jobject ret = env->CallStaticObjectMethod(MotionEvent_clazz(env), - method_id, p0, p1, as_jint(p2), as_jint(p3), p4, p5, as_jint(p6), - as_jint(p7), p8, p9, as_jint(p10), as_jint(p11), as_jint(p12), - as_jint(p13)); + method_id, p0, p1, as_jint(p2), as_jint(p3), p4.obj(), p5.obj(), + as_jint(p6), as_jint(p7), p8, p9, as_jint(p10), as_jint(p11), + as_jint(p12), as_jint(p13)); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jobject>(env, ret); + return base::android::ScopedJavaLocalRef<jobject>(env, ret); } static base::subtle::AtomicWord g_MotionEvent_obtainAVME_J_J_I_I_AI_LAVMEPC_I_F_F_I_I_I_I = 0; -static ScopedJavaLocalRef<jobject> +static base::android::ScopedJavaLocalRef<jobject> Java_MotionEvent_obtainAVME_J_J_I_I_AI_LAVMEPC_I_F_F_I_I_I_I(JNIEnv* env, jlong p0, jlong p1, JniIntWrapper p2, JniIntWrapper p3, - jintArray p4, - jobjectArray p5, + const base::android::JavaRefOrBare<jintArray>& p4, + const base::android::JavaRefOrBare<jobjectArray>& p5, JniIntWrapper p6, jfloat p7, jfloat p8, @@ -204,14 +202,14 @@ static ScopedJavaLocalRef<jobject> JniIntWrapper p10, JniIntWrapper p11, JniIntWrapper p12) __attribute__ ((unused)); -static ScopedJavaLocalRef<jobject> +static base::android::ScopedJavaLocalRef<jobject> Java_MotionEvent_obtainAVME_J_J_I_I_AI_LAVMEPC_I_F_F_I_I_I_I(JNIEnv* env, jlong p0, jlong p1, JniIntWrapper p2, JniIntWrapper p3, - jintArray p4, - jobjectArray p5, + const base::android::JavaRefOrBare<jintArray>& p4, + const base::android::JavaRefOrBare<jobjectArray>& p5, JniIntWrapper p6, jfloat p7, jfloat p8, @@ -219,7 +217,6 @@ static ScopedJavaLocalRef<jobject> JniIntWrapper p10, JniIntWrapper p11, JniIntWrapper p12) { - /* Must call RegisterNativesImpl() */ CHECK_CLAZZ(env, MotionEvent_clazz(env), MotionEvent_clazz(env), NULL); jmethodID method_id = @@ -232,15 +229,16 @@ static ScopedJavaLocalRef<jobject> jobject ret = env->CallStaticObjectMethod(MotionEvent_clazz(env), - method_id, p0, p1, as_jint(p2), as_jint(p3), p4, p5, as_jint(p6), p7, - p8, as_jint(p9), as_jint(p10), as_jint(p11), as_jint(p12)); + method_id, p0, p1, as_jint(p2), as_jint(p3), p4.obj(), p5.obj(), + as_jint(p6), p7, p8, as_jint(p9), as_jint(p10), as_jint(p11), + as_jint(p12)); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jobject>(env, ret); + return base::android::ScopedJavaLocalRef<jobject>(env, ret); } static base::subtle::AtomicWord g_MotionEvent_obtainAVME_J_J_I_F_F_F_F_I_F_F_I_I = 0; -static ScopedJavaLocalRef<jobject> +static base::android::ScopedJavaLocalRef<jobject> Java_MotionEvent_obtainAVME_J_J_I_F_F_F_F_I_F_F_I_I(JNIEnv* env, jlong p0, jlong p1, JniIntWrapper p2, @@ -253,7 +251,7 @@ static ScopedJavaLocalRef<jobject> jfloat p9, JniIntWrapper p10, JniIntWrapper p11) __attribute__ ((unused)); -static ScopedJavaLocalRef<jobject> +static base::android::ScopedJavaLocalRef<jobject> Java_MotionEvent_obtainAVME_J_J_I_F_F_F_F_I_F_F_I_I(JNIEnv* env, jlong p0, jlong p1, JniIntWrapper p2, @@ -266,7 +264,6 @@ static ScopedJavaLocalRef<jobject> jfloat p9, JniIntWrapper p10, JniIntWrapper p11) { - /* Must call RegisterNativesImpl() */ CHECK_CLAZZ(env, MotionEvent_clazz(env), MotionEvent_clazz(env), NULL); jmethodID method_id = @@ -282,12 +279,12 @@ static ScopedJavaLocalRef<jobject> method_id, p0, p1, as_jint(p2), p3, p4, p5, p6, as_jint(p7), p8, p9, as_jint(p10), as_jint(p11)); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jobject>(env, ret); + return base::android::ScopedJavaLocalRef<jobject>(env, ret); } static base::subtle::AtomicWord g_MotionEvent_obtainAVME_J_J_I_I_F_F_F_F_I_F_F_I_I = 0; -static ScopedJavaLocalRef<jobject> +static base::android::ScopedJavaLocalRef<jobject> Java_MotionEvent_obtainAVME_J_J_I_I_F_F_F_F_I_F_F_I_I(JNIEnv* env, jlong p0, jlong p1, JniIntWrapper p2, @@ -301,7 +298,7 @@ static ScopedJavaLocalRef<jobject> jfloat p10, JniIntWrapper p11, JniIntWrapper p12) __attribute__ ((unused)); -static ScopedJavaLocalRef<jobject> +static base::android::ScopedJavaLocalRef<jobject> Java_MotionEvent_obtainAVME_J_J_I_I_F_F_F_F_I_F_F_I_I(JNIEnv* env, jlong p0, jlong p1, JniIntWrapper p2, @@ -315,7 +312,6 @@ static ScopedJavaLocalRef<jobject> jfloat p10, JniIntWrapper p11, JniIntWrapper p12) { - /* Must call RegisterNativesImpl() */ CHECK_CLAZZ(env, MotionEvent_clazz(env), MotionEvent_clazz(env), NULL); jmethodID method_id = @@ -331,25 +327,24 @@ static ScopedJavaLocalRef<jobject> method_id, p0, p1, as_jint(p2), as_jint(p3), p4, p5, p6, p7, as_jint(p8), p9, p10, as_jint(p11), as_jint(p12)); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jobject>(env, ret); + return base::android::ScopedJavaLocalRef<jobject>(env, ret); } static base::subtle::AtomicWord g_MotionEvent_obtainAVME_J_J_I_F_F_I = 0; -static ScopedJavaLocalRef<jobject> +static base::android::ScopedJavaLocalRef<jobject> Java_MotionEvent_obtainAVME_J_J_I_F_F_I(JNIEnv* env, jlong p0, jlong p1, JniIntWrapper p2, jfloat p3, jfloat p4, JniIntWrapper p5) __attribute__ ((unused)); -static ScopedJavaLocalRef<jobject> +static base::android::ScopedJavaLocalRef<jobject> Java_MotionEvent_obtainAVME_J_J_I_F_F_I(JNIEnv* env, jlong p0, jlong p1, JniIntWrapper p2, jfloat p3, jfloat p4, JniIntWrapper p5) { - /* Must call RegisterNativesImpl() */ CHECK_CLAZZ(env, MotionEvent_clazz(env), MotionEvent_clazz(env), NULL); jmethodID method_id = @@ -364,15 +359,16 @@ static ScopedJavaLocalRef<jobject> env->CallStaticObjectMethod(MotionEvent_clazz(env), method_id, p0, p1, as_jint(p2), p3, p4, as_jint(p5)); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jobject>(env, ret); + return base::android::ScopedJavaLocalRef<jobject>(env, ret); } static base::subtle::AtomicWord g_MotionEvent_obtainAVME_AVME = 0; -static ScopedJavaLocalRef<jobject> Java_MotionEvent_obtainAVME_AVME(JNIEnv* env, - jobject p0) __attribute__ ((unused)); -static ScopedJavaLocalRef<jobject> Java_MotionEvent_obtainAVME_AVME(JNIEnv* env, - jobject p0) { - /* Must call RegisterNativesImpl() */ +static base::android::ScopedJavaLocalRef<jobject> + Java_MotionEvent_obtainAVME_AVME(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& p0) __attribute__ ((unused)); +static base::android::ScopedJavaLocalRef<jobject> + Java_MotionEvent_obtainAVME_AVME(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& p0) { CHECK_CLAZZ(env, MotionEvent_clazz(env), MotionEvent_clazz(env), NULL); jmethodID method_id = @@ -385,17 +381,18 @@ static ScopedJavaLocalRef<jobject> Java_MotionEvent_obtainAVME_AVME(JNIEnv* env, jobject ret = env->CallStaticObjectMethod(MotionEvent_clazz(env), - method_id, p0); + method_id, p0.obj()); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jobject>(env, ret); + return base::android::ScopedJavaLocalRef<jobject>(env, ret); } static base::subtle::AtomicWord g_MotionEvent_obtainNoHistory = 0; -static ScopedJavaLocalRef<jobject> Java_MotionEvent_obtainNoHistory(JNIEnv* env, - jobject p0) __attribute__ ((unused)); -static ScopedJavaLocalRef<jobject> Java_MotionEvent_obtainNoHistory(JNIEnv* env, - jobject p0) { - /* Must call RegisterNativesImpl() */ +static base::android::ScopedJavaLocalRef<jobject> + Java_MotionEvent_obtainNoHistory(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& p0) __attribute__ ((unused)); +static base::android::ScopedJavaLocalRef<jobject> + Java_MotionEvent_obtainNoHistory(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& p0) { CHECK_CLAZZ(env, MotionEvent_clazz(env), MotionEvent_clazz(env), NULL); jmethodID method_id = @@ -408,17 +405,17 @@ static ScopedJavaLocalRef<jobject> Java_MotionEvent_obtainNoHistory(JNIEnv* env, jobject ret = env->CallStaticObjectMethod(MotionEvent_clazz(env), - method_id, p0); + method_id, p0.obj()); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jobject>(env, ret); + return base::android::ScopedJavaLocalRef<jobject>(env, ret); } static base::subtle::AtomicWord g_MotionEvent_recycle = 0; -static void Java_MotionEvent_recycle(JNIEnv* env, jobject obj) __attribute__ - ((unused)); -static void Java_MotionEvent_recycle(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static void Java_MotionEvent_recycle(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static void Java_MotionEvent_recycle(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -428,18 +425,17 @@ static void Java_MotionEvent_recycle(JNIEnv* env, jobject obj) { "()V", &g_MotionEvent_recycle); - env->CallVoidMethod(obj, + env->CallVoidMethod(obj.obj(), method_id); jni_generator::CheckException(env); - } static base::subtle::AtomicWord g_MotionEvent_getDeviceId = 0; -static jint Java_MotionEvent_getDeviceId(JNIEnv* env, jobject obj) __attribute__ - ((unused)); -static jint Java_MotionEvent_getDeviceId(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jint Java_MotionEvent_getDeviceId(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jint Java_MotionEvent_getDeviceId(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -450,18 +446,18 @@ static jint Java_MotionEvent_getDeviceId(JNIEnv* env, jobject obj) { &g_MotionEvent_getDeviceId); jint ret = - env->CallIntMethod(obj, + env->CallIntMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getSource = 0; -static jint Java_MotionEvent_getSource(JNIEnv* env, jobject obj) __attribute__ - ((unused)); -static jint Java_MotionEvent_getSource(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jint Java_MotionEvent_getSource(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jint Java_MotionEvent_getSource(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -472,19 +468,19 @@ static jint Java_MotionEvent_getSource(JNIEnv* env, jobject obj) { &g_MotionEvent_getSource); jint ret = - env->CallIntMethod(obj, + env->CallIntMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_setSource = 0; -static void Java_MotionEvent_setSource(JNIEnv* env, jobject obj, JniIntWrapper - p0) __attribute__ ((unused)); -static void Java_MotionEvent_setSource(JNIEnv* env, jobject obj, JniIntWrapper - p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static void Java_MotionEvent_setSource(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static void Java_MotionEvent_setSource(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -494,18 +490,17 @@ static void Java_MotionEvent_setSource(JNIEnv* env, jobject obj, JniIntWrapper "(I)V", &g_MotionEvent_setSource); - env->CallVoidMethod(obj, + env->CallVoidMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); - } static base::subtle::AtomicWord g_MotionEvent_getAction = 0; -static jint Java_MotionEvent_getAction(JNIEnv* env, jobject obj) __attribute__ - ((unused)); -static jint Java_MotionEvent_getAction(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jint Java_MotionEvent_getAction(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jint Java_MotionEvent_getAction(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -516,18 +511,18 @@ static jint Java_MotionEvent_getAction(JNIEnv* env, jobject obj) { &g_MotionEvent_getAction); jint ret = - env->CallIntMethod(obj, + env->CallIntMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getActionMasked = 0; -static jint Java_MotionEvent_getActionMasked(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jint Java_MotionEvent_getActionMasked(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jint Java_MotionEvent_getActionMasked(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jint Java_MotionEvent_getActionMasked(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -538,18 +533,18 @@ static jint Java_MotionEvent_getActionMasked(JNIEnv* env, jobject obj) { &g_MotionEvent_getActionMasked); jint ret = - env->CallIntMethod(obj, + env->CallIntMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getActionIndex = 0; -static jint Java_MotionEvent_getActionIndex(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jint Java_MotionEvent_getActionIndex(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jint Java_MotionEvent_getActionIndex(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jint Java_MotionEvent_getActionIndex(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -560,18 +555,18 @@ static jint Java_MotionEvent_getActionIndex(JNIEnv* env, jobject obj) { &g_MotionEvent_getActionIndex); jint ret = - env->CallIntMethod(obj, + env->CallIntMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getFlags = 0; -static jint Java_MotionEvent_getFlags(JNIEnv* env, jobject obj) __attribute__ - ((unused)); -static jint Java_MotionEvent_getFlags(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jint Java_MotionEvent_getFlags(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jint Java_MotionEvent_getFlags(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -582,18 +577,18 @@ static jint Java_MotionEvent_getFlags(JNIEnv* env, jobject obj) { &g_MotionEvent_getFlags); jint ret = - env->CallIntMethod(obj, + env->CallIntMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getDownTime = 0; -static jlong Java_MotionEvent_getDownTime(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jlong Java_MotionEvent_getDownTime(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jlong Java_MotionEvent_getDownTime(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jlong Java_MotionEvent_getDownTime(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -604,18 +599,18 @@ static jlong Java_MotionEvent_getDownTime(JNIEnv* env, jobject obj) { &g_MotionEvent_getDownTime); jlong ret = - env->CallLongMethod(obj, + env->CallLongMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getEventTime = 0; -static jlong Java_MotionEvent_getEventTime(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jlong Java_MotionEvent_getEventTime(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jlong Java_MotionEvent_getEventTime(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jlong Java_MotionEvent_getEventTime(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -626,18 +621,18 @@ static jlong Java_MotionEvent_getEventTime(JNIEnv* env, jobject obj) { &g_MotionEvent_getEventTime); jlong ret = - env->CallLongMethod(obj, + env->CallLongMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getXF = 0; -static jfloat Java_MotionEvent_getXF(JNIEnv* env, jobject obj) __attribute__ - ((unused)); -static jfloat Java_MotionEvent_getXF(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getXF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jfloat Java_MotionEvent_getXF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -648,18 +643,18 @@ static jfloat Java_MotionEvent_getXF(JNIEnv* env, jobject obj) { &g_MotionEvent_getXF); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getYF = 0; -static jfloat Java_MotionEvent_getYF(JNIEnv* env, jobject obj) __attribute__ - ((unused)); -static jfloat Java_MotionEvent_getYF(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getYF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jfloat Java_MotionEvent_getYF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -670,18 +665,18 @@ static jfloat Java_MotionEvent_getYF(JNIEnv* env, jobject obj) { &g_MotionEvent_getYF); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getPressureF = 0; -static jfloat Java_MotionEvent_getPressureF(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jfloat Java_MotionEvent_getPressureF(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getPressureF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jfloat Java_MotionEvent_getPressureF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -692,18 +687,18 @@ static jfloat Java_MotionEvent_getPressureF(JNIEnv* env, jobject obj) { &g_MotionEvent_getPressureF); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getSizeF = 0; -static jfloat Java_MotionEvent_getSizeF(JNIEnv* env, jobject obj) __attribute__ - ((unused)); -static jfloat Java_MotionEvent_getSizeF(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getSizeF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jfloat Java_MotionEvent_getSizeF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -714,18 +709,18 @@ static jfloat Java_MotionEvent_getSizeF(JNIEnv* env, jobject obj) { &g_MotionEvent_getSizeF); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getTouchMajorF = 0; -static jfloat Java_MotionEvent_getTouchMajorF(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jfloat Java_MotionEvent_getTouchMajorF(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getTouchMajorF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jfloat Java_MotionEvent_getTouchMajorF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -736,18 +731,18 @@ static jfloat Java_MotionEvent_getTouchMajorF(JNIEnv* env, jobject obj) { &g_MotionEvent_getTouchMajorF); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getTouchMinorF = 0; -static jfloat Java_MotionEvent_getTouchMinorF(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jfloat Java_MotionEvent_getTouchMinorF(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getTouchMinorF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jfloat Java_MotionEvent_getTouchMinorF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -758,18 +753,18 @@ static jfloat Java_MotionEvent_getTouchMinorF(JNIEnv* env, jobject obj) { &g_MotionEvent_getTouchMinorF); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getToolMajorF = 0; -static jfloat Java_MotionEvent_getToolMajorF(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jfloat Java_MotionEvent_getToolMajorF(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getToolMajorF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jfloat Java_MotionEvent_getToolMajorF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -780,18 +775,18 @@ static jfloat Java_MotionEvent_getToolMajorF(JNIEnv* env, jobject obj) { &g_MotionEvent_getToolMajorF); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getToolMinorF = 0; -static jfloat Java_MotionEvent_getToolMinorF(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jfloat Java_MotionEvent_getToolMinorF(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getToolMinorF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jfloat Java_MotionEvent_getToolMinorF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -802,18 +797,18 @@ static jfloat Java_MotionEvent_getToolMinorF(JNIEnv* env, jobject obj) { &g_MotionEvent_getToolMinorF); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getOrientationF = 0; -static jfloat Java_MotionEvent_getOrientationF(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jfloat Java_MotionEvent_getOrientationF(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getOrientationF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jfloat Java_MotionEvent_getOrientationF(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -824,19 +819,19 @@ static jfloat Java_MotionEvent_getOrientationF(JNIEnv* env, jobject obj) { &g_MotionEvent_getOrientationF); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getAxisValueF_I = 0; -static jfloat Java_MotionEvent_getAxisValueF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getAxisValueF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getAxisValueF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getAxisValueF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -847,18 +842,18 @@ static jfloat Java_MotionEvent_getAxisValueF_I(JNIEnv* env, jobject obj, &g_MotionEvent_getAxisValueF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getPointerCount = 0; -static jint Java_MotionEvent_getPointerCount(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jint Java_MotionEvent_getPointerCount(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jint Java_MotionEvent_getPointerCount(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jint Java_MotionEvent_getPointerCount(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -869,19 +864,19 @@ static jint Java_MotionEvent_getPointerCount(JNIEnv* env, jobject obj) { &g_MotionEvent_getPointerCount); jint ret = - env->CallIntMethod(obj, + env->CallIntMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getPointerId = 0; -static jint Java_MotionEvent_getPointerId(JNIEnv* env, jobject obj, - JniIntWrapper p0) __attribute__ ((unused)); -static jint Java_MotionEvent_getPointerId(JNIEnv* env, jobject obj, - JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jint Java_MotionEvent_getPointerId(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jint Java_MotionEvent_getPointerId(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -892,19 +887,19 @@ static jint Java_MotionEvent_getPointerId(JNIEnv* env, jobject obj, &g_MotionEvent_getPointerId); jint ret = - env->CallIntMethod(obj, + env->CallIntMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getToolType = 0; -static jint Java_MotionEvent_getToolType(JNIEnv* env, jobject obj, JniIntWrapper - p0) __attribute__ ((unused)); -static jint Java_MotionEvent_getToolType(JNIEnv* env, jobject obj, JniIntWrapper - p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jint Java_MotionEvent_getToolType(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jint Java_MotionEvent_getToolType(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -915,19 +910,19 @@ static jint Java_MotionEvent_getToolType(JNIEnv* env, jobject obj, JniIntWrapper &g_MotionEvent_getToolType); jint ret = - env->CallIntMethod(obj, + env->CallIntMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_findPointerIndex = 0; -static jint Java_MotionEvent_findPointerIndex(JNIEnv* env, jobject obj, - JniIntWrapper p0) __attribute__ ((unused)); -static jint Java_MotionEvent_findPointerIndex(JNIEnv* env, jobject obj, - JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jint Java_MotionEvent_findPointerIndex(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jint Java_MotionEvent_findPointerIndex(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -938,19 +933,19 @@ static jint Java_MotionEvent_findPointerIndex(JNIEnv* env, jobject obj, &g_MotionEvent_findPointerIndex); jint ret = - env->CallIntMethod(obj, + env->CallIntMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getXF_I = 0; -static jfloat Java_MotionEvent_getXF_I(JNIEnv* env, jobject obj, JniIntWrapper - p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getXF_I(JNIEnv* env, jobject obj, JniIntWrapper - p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getXF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getXF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -961,19 +956,19 @@ static jfloat Java_MotionEvent_getXF_I(JNIEnv* env, jobject obj, JniIntWrapper &g_MotionEvent_getXF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getYF_I = 0; -static jfloat Java_MotionEvent_getYF_I(JNIEnv* env, jobject obj, JniIntWrapper - p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getYF_I(JNIEnv* env, jobject obj, JniIntWrapper - p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getYF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getYF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -984,19 +979,19 @@ static jfloat Java_MotionEvent_getYF_I(JNIEnv* env, jobject obj, JniIntWrapper &g_MotionEvent_getYF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getPressureF_I = 0; -static jfloat Java_MotionEvent_getPressureF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getPressureF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getPressureF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getPressureF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1007,19 +1002,19 @@ static jfloat Java_MotionEvent_getPressureF_I(JNIEnv* env, jobject obj, &g_MotionEvent_getPressureF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getSizeF_I = 0; -static jfloat Java_MotionEvent_getSizeF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getSizeF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getSizeF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getSizeF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1030,19 +1025,19 @@ static jfloat Java_MotionEvent_getSizeF_I(JNIEnv* env, jobject obj, &g_MotionEvent_getSizeF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getTouchMajorF_I = 0; -static jfloat Java_MotionEvent_getTouchMajorF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getTouchMajorF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getTouchMajorF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getTouchMajorF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1053,19 +1048,19 @@ static jfloat Java_MotionEvent_getTouchMajorF_I(JNIEnv* env, jobject obj, &g_MotionEvent_getTouchMajorF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getTouchMinorF_I = 0; -static jfloat Java_MotionEvent_getTouchMinorF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getTouchMinorF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getTouchMinorF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getTouchMinorF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1076,19 +1071,19 @@ static jfloat Java_MotionEvent_getTouchMinorF_I(JNIEnv* env, jobject obj, &g_MotionEvent_getTouchMinorF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getToolMajorF_I = 0; -static jfloat Java_MotionEvent_getToolMajorF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getToolMajorF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getToolMajorF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getToolMajorF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1099,19 +1094,19 @@ static jfloat Java_MotionEvent_getToolMajorF_I(JNIEnv* env, jobject obj, &g_MotionEvent_getToolMajorF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getToolMinorF_I = 0; -static jfloat Java_MotionEvent_getToolMinorF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getToolMinorF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getToolMinorF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getToolMinorF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1122,19 +1117,19 @@ static jfloat Java_MotionEvent_getToolMinorF_I(JNIEnv* env, jobject obj, &g_MotionEvent_getToolMinorF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getOrientationF_I = 0; -static jfloat Java_MotionEvent_getOrientationF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getOrientationF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getOrientationF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getOrientationF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1145,21 +1140,20 @@ static jfloat Java_MotionEvent_getOrientationF_I(JNIEnv* env, jobject obj, &g_MotionEvent_getOrientationF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getAxisValueF_I_I = 0; -static jfloat Java_MotionEvent_getAxisValueF_I_I(JNIEnv* env, jobject obj, - JniIntWrapper p0, +static jfloat Java_MotionEvent_getAxisValueF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getAxisValueF_I_I(JNIEnv* env, jobject obj, - JniIntWrapper p0, +static jfloat Java_MotionEvent_getAxisValueF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1170,21 +1164,20 @@ static jfloat Java_MotionEvent_getAxisValueF_I_I(JNIEnv* env, jobject obj, &g_MotionEvent_getAxisValueF_I_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0), as_jint(p1)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getPointerCoords = 0; -static void Java_MotionEvent_getPointerCoords(JNIEnv* env, jobject obj, - JniIntWrapper p0, - jobject p1) __attribute__ ((unused)); -static void Java_MotionEvent_getPointerCoords(JNIEnv* env, jobject obj, - JniIntWrapper p0, - jobject p1) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static void Java_MotionEvent_getPointerCoords(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, + const base::android::JavaRefOrBare<jobject>& p1) __attribute__ ((unused)); +static void Java_MotionEvent_getPointerCoords(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, + const base::android::JavaRefOrBare<jobject>& p1) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1194,21 +1187,19 @@ static void Java_MotionEvent_getPointerCoords(JNIEnv* env, jobject obj, "(ILandroid/view/MotionEvent$PointerCoords;)V", &g_MotionEvent_getPointerCoords); - env->CallVoidMethod(obj, - method_id, as_jint(p0), p1); + env->CallVoidMethod(obj.obj(), + method_id, as_jint(p0), p1.obj()); jni_generator::CheckException(env); - } static base::subtle::AtomicWord g_MotionEvent_getPointerProperties = 0; -static void Java_MotionEvent_getPointerProperties(JNIEnv* env, jobject obj, - JniIntWrapper p0, - jobject p1) __attribute__ ((unused)); -static void Java_MotionEvent_getPointerProperties(JNIEnv* env, jobject obj, - JniIntWrapper p0, - jobject p1) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static void Java_MotionEvent_getPointerProperties(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, + const base::android::JavaRefOrBare<jobject>& p1) __attribute__ ((unused)); +static void Java_MotionEvent_getPointerProperties(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, + const base::android::JavaRefOrBare<jobject>& p1) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1218,18 +1209,17 @@ static void Java_MotionEvent_getPointerProperties(JNIEnv* env, jobject obj, "(ILandroid/view/MotionEvent$PointerProperties;)V", &g_MotionEvent_getPointerProperties); - env->CallVoidMethod(obj, - method_id, as_jint(p0), p1); + env->CallVoidMethod(obj.obj(), + method_id, as_jint(p0), p1.obj()); jni_generator::CheckException(env); - } static base::subtle::AtomicWord g_MotionEvent_getMetaState = 0; -static jint Java_MotionEvent_getMetaState(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jint Java_MotionEvent_getMetaState(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jint Java_MotionEvent_getMetaState(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jint Java_MotionEvent_getMetaState(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1240,18 +1230,18 @@ static jint Java_MotionEvent_getMetaState(JNIEnv* env, jobject obj) { &g_MotionEvent_getMetaState); jint ret = - env->CallIntMethod(obj, + env->CallIntMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getButtonState = 0; -static jint Java_MotionEvent_getButtonState(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jint Java_MotionEvent_getButtonState(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jint Java_MotionEvent_getButtonState(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jint Java_MotionEvent_getButtonState(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1262,18 +1252,18 @@ static jint Java_MotionEvent_getButtonState(JNIEnv* env, jobject obj) { &g_MotionEvent_getButtonState); jint ret = - env->CallIntMethod(obj, + env->CallIntMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getRawX = 0; -static jfloat Java_MotionEvent_getRawX(JNIEnv* env, jobject obj) __attribute__ - ((unused)); -static jfloat Java_MotionEvent_getRawX(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getRawX(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jfloat Java_MotionEvent_getRawX(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1284,18 +1274,18 @@ static jfloat Java_MotionEvent_getRawX(JNIEnv* env, jobject obj) { &g_MotionEvent_getRawX); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getRawY = 0; -static jfloat Java_MotionEvent_getRawY(JNIEnv* env, jobject obj) __attribute__ - ((unused)); -static jfloat Java_MotionEvent_getRawY(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getRawY(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jfloat Java_MotionEvent_getRawY(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1306,18 +1296,18 @@ static jfloat Java_MotionEvent_getRawY(JNIEnv* env, jobject obj) { &g_MotionEvent_getRawY); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getXPrecision = 0; -static jfloat Java_MotionEvent_getXPrecision(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jfloat Java_MotionEvent_getXPrecision(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getXPrecision(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jfloat Java_MotionEvent_getXPrecision(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1328,18 +1318,18 @@ static jfloat Java_MotionEvent_getXPrecision(JNIEnv* env, jobject obj) { &g_MotionEvent_getXPrecision); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getYPrecision = 0; -static jfloat Java_MotionEvent_getYPrecision(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jfloat Java_MotionEvent_getYPrecision(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getYPrecision(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jfloat Java_MotionEvent_getYPrecision(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1350,18 +1340,18 @@ static jfloat Java_MotionEvent_getYPrecision(JNIEnv* env, jobject obj) { &g_MotionEvent_getYPrecision); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistorySize = 0; -static jint Java_MotionEvent_getHistorySize(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jint Java_MotionEvent_getHistorySize(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jint Java_MotionEvent_getHistorySize(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jint Java_MotionEvent_getHistorySize(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1372,19 +1362,19 @@ static jint Java_MotionEvent_getHistorySize(JNIEnv* env, jobject obj) { &g_MotionEvent_getHistorySize); jint ret = - env->CallIntMethod(obj, + env->CallIntMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalEventTime = 0; -static jlong Java_MotionEvent_getHistoricalEventTime(JNIEnv* env, jobject obj, - JniIntWrapper p0) __attribute__ ((unused)); -static jlong Java_MotionEvent_getHistoricalEventTime(JNIEnv* env, jobject obj, - JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jlong Java_MotionEvent_getHistoricalEventTime(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jlong Java_MotionEvent_getHistoricalEventTime(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1395,19 +1385,19 @@ static jlong Java_MotionEvent_getHistoricalEventTime(JNIEnv* env, jobject obj, &g_MotionEvent_getHistoricalEventTime); jlong ret = - env->CallLongMethod(obj, + env->CallLongMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalXF_I = 0; -static jfloat Java_MotionEvent_getHistoricalXF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalXF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getHistoricalXF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getHistoricalXF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1418,19 +1408,19 @@ static jfloat Java_MotionEvent_getHistoricalXF_I(JNIEnv* env, jobject obj, &g_MotionEvent_getHistoricalXF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalYF_I = 0; -static jfloat Java_MotionEvent_getHistoricalYF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalYF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getHistoricalYF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getHistoricalYF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1441,19 +1431,19 @@ static jfloat Java_MotionEvent_getHistoricalYF_I(JNIEnv* env, jobject obj, &g_MotionEvent_getHistoricalYF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalPressureF_I = 0; -static jfloat Java_MotionEvent_getHistoricalPressureF_I(JNIEnv* env, jobject - obj, JniIntWrapper p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalPressureF_I(JNIEnv* env, jobject - obj, JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getHistoricalPressureF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getHistoricalPressureF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1464,19 +1454,19 @@ static jfloat Java_MotionEvent_getHistoricalPressureF_I(JNIEnv* env, jobject &g_MotionEvent_getHistoricalPressureF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalSizeF_I = 0; -static jfloat Java_MotionEvent_getHistoricalSizeF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalSizeF_I(JNIEnv* env, jobject obj, - JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getHistoricalSizeF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getHistoricalSizeF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1487,19 +1477,19 @@ static jfloat Java_MotionEvent_getHistoricalSizeF_I(JNIEnv* env, jobject obj, &g_MotionEvent_getHistoricalSizeF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalTouchMajorF_I = 0; -static jfloat Java_MotionEvent_getHistoricalTouchMajorF_I(JNIEnv* env, jobject - obj, JniIntWrapper p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalTouchMajorF_I(JNIEnv* env, jobject - obj, JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getHistoricalTouchMajorF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getHistoricalTouchMajorF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1510,19 +1500,19 @@ static jfloat Java_MotionEvent_getHistoricalTouchMajorF_I(JNIEnv* env, jobject &g_MotionEvent_getHistoricalTouchMajorF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalTouchMinorF_I = 0; -static jfloat Java_MotionEvent_getHistoricalTouchMinorF_I(JNIEnv* env, jobject - obj, JniIntWrapper p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalTouchMinorF_I(JNIEnv* env, jobject - obj, JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getHistoricalTouchMinorF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getHistoricalTouchMinorF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1533,19 +1523,19 @@ static jfloat Java_MotionEvent_getHistoricalTouchMinorF_I(JNIEnv* env, jobject &g_MotionEvent_getHistoricalTouchMinorF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalToolMajorF_I = 0; -static jfloat Java_MotionEvent_getHistoricalToolMajorF_I(JNIEnv* env, jobject - obj, JniIntWrapper p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalToolMajorF_I(JNIEnv* env, jobject - obj, JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getHistoricalToolMajorF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getHistoricalToolMajorF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1556,19 +1546,19 @@ static jfloat Java_MotionEvent_getHistoricalToolMajorF_I(JNIEnv* env, jobject &g_MotionEvent_getHistoricalToolMajorF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalToolMinorF_I = 0; -static jfloat Java_MotionEvent_getHistoricalToolMinorF_I(JNIEnv* env, jobject - obj, JniIntWrapper p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalToolMinorF_I(JNIEnv* env, jobject - obj, JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getHistoricalToolMinorF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getHistoricalToolMinorF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1579,19 +1569,19 @@ static jfloat Java_MotionEvent_getHistoricalToolMinorF_I(JNIEnv* env, jobject &g_MotionEvent_getHistoricalToolMinorF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalOrientationF_I = 0; -static jfloat Java_MotionEvent_getHistoricalOrientationF_I(JNIEnv* env, jobject - obj, JniIntWrapper p0) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalOrientationF_I(JNIEnv* env, jobject - obj, JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jfloat Java_MotionEvent_getHistoricalOrientationF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static jfloat Java_MotionEvent_getHistoricalOrientationF_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1602,21 +1592,20 @@ static jfloat Java_MotionEvent_getHistoricalOrientationF_I(JNIEnv* env, jobject &g_MotionEvent_getHistoricalOrientationF_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalAxisValueF_I_I = 0; -static jfloat Java_MotionEvent_getHistoricalAxisValueF_I_I(JNIEnv* env, jobject - obj, JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalAxisValueF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalAxisValueF_I_I(JNIEnv* env, jobject - obj, JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalAxisValueF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1627,21 +1616,20 @@ static jfloat Java_MotionEvent_getHistoricalAxisValueF_I_I(JNIEnv* env, jobject &g_MotionEvent_getHistoricalAxisValueF_I_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0), as_jint(p1)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalXF_I_I = 0; -static jfloat Java_MotionEvent_getHistoricalXF_I_I(JNIEnv* env, jobject obj, - JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalXF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalXF_I_I(JNIEnv* env, jobject obj, - JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalXF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1652,21 +1640,20 @@ static jfloat Java_MotionEvent_getHistoricalXF_I_I(JNIEnv* env, jobject obj, &g_MotionEvent_getHistoricalXF_I_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0), as_jint(p1)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalYF_I_I = 0; -static jfloat Java_MotionEvent_getHistoricalYF_I_I(JNIEnv* env, jobject obj, - JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalYF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalYF_I_I(JNIEnv* env, jobject obj, - JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalYF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1677,21 +1664,20 @@ static jfloat Java_MotionEvent_getHistoricalYF_I_I(JNIEnv* env, jobject obj, &g_MotionEvent_getHistoricalYF_I_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0), as_jint(p1)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalPressureF_I_I = 0; -static jfloat Java_MotionEvent_getHistoricalPressureF_I_I(JNIEnv* env, jobject - obj, JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalPressureF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalPressureF_I_I(JNIEnv* env, jobject - obj, JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalPressureF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1702,21 +1688,20 @@ static jfloat Java_MotionEvent_getHistoricalPressureF_I_I(JNIEnv* env, jobject &g_MotionEvent_getHistoricalPressureF_I_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0), as_jint(p1)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalSizeF_I_I = 0; -static jfloat Java_MotionEvent_getHistoricalSizeF_I_I(JNIEnv* env, jobject obj, - JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalSizeF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalSizeF_I_I(JNIEnv* env, jobject obj, - JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalSizeF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1727,21 +1712,20 @@ static jfloat Java_MotionEvent_getHistoricalSizeF_I_I(JNIEnv* env, jobject obj, &g_MotionEvent_getHistoricalSizeF_I_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0), as_jint(p1)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalTouchMajorF_I_I = 0; -static jfloat Java_MotionEvent_getHistoricalTouchMajorF_I_I(JNIEnv* env, jobject - obj, JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalTouchMajorF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalTouchMajorF_I_I(JNIEnv* env, jobject - obj, JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalTouchMajorF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1752,21 +1736,20 @@ static jfloat Java_MotionEvent_getHistoricalTouchMajorF_I_I(JNIEnv* env, jobject &g_MotionEvent_getHistoricalTouchMajorF_I_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0), as_jint(p1)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalTouchMinorF_I_I = 0; -static jfloat Java_MotionEvent_getHistoricalTouchMinorF_I_I(JNIEnv* env, jobject - obj, JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalTouchMinorF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalTouchMinorF_I_I(JNIEnv* env, jobject - obj, JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalTouchMinorF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1777,21 +1760,20 @@ static jfloat Java_MotionEvent_getHistoricalTouchMinorF_I_I(JNIEnv* env, jobject &g_MotionEvent_getHistoricalTouchMinorF_I_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0), as_jint(p1)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalToolMajorF_I_I = 0; -static jfloat Java_MotionEvent_getHistoricalToolMajorF_I_I(JNIEnv* env, jobject - obj, JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalToolMajorF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalToolMajorF_I_I(JNIEnv* env, jobject - obj, JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalToolMajorF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1802,21 +1784,20 @@ static jfloat Java_MotionEvent_getHistoricalToolMajorF_I_I(JNIEnv* env, jobject &g_MotionEvent_getHistoricalToolMajorF_I_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0), as_jint(p1)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalToolMinorF_I_I = 0; -static jfloat Java_MotionEvent_getHistoricalToolMinorF_I_I(JNIEnv* env, jobject - obj, JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalToolMinorF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalToolMinorF_I_I(JNIEnv* env, jobject - obj, JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalToolMinorF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1827,21 +1808,20 @@ static jfloat Java_MotionEvent_getHistoricalToolMinorF_I_I(JNIEnv* env, jobject &g_MotionEvent_getHistoricalToolMinorF_I_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0), as_jint(p1)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalOrientationF_I_I = 0; -static jfloat Java_MotionEvent_getHistoricalOrientationF_I_I(JNIEnv* env, - jobject obj, JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalOrientationF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalOrientationF_I_I(JNIEnv* env, - jobject obj, JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalOrientationF_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1852,23 +1832,22 @@ static jfloat Java_MotionEvent_getHistoricalOrientationF_I_I(JNIEnv* env, &g_MotionEvent_getHistoricalOrientationF_I_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0), as_jint(p1)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalAxisValueF_I_I_I = 0; -static jfloat Java_MotionEvent_getHistoricalAxisValueF_I_I_I(JNIEnv* env, - jobject obj, JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalAxisValueF_I_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1, JniIntWrapper p2) __attribute__ ((unused)); -static jfloat Java_MotionEvent_getHistoricalAxisValueF_I_I_I(JNIEnv* env, - jobject obj, JniIntWrapper p0, +static jfloat Java_MotionEvent_getHistoricalAxisValueF_I_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1, JniIntWrapper p2) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1879,23 +1858,22 @@ static jfloat Java_MotionEvent_getHistoricalAxisValueF_I_I_I(JNIEnv* env, &g_MotionEvent_getHistoricalAxisValueF_I_I_I); jfloat ret = - env->CallFloatMethod(obj, + env->CallFloatMethod(obj.obj(), method_id, as_jint(p0), as_jint(p1), as_jint(p2)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_getHistoricalPointerCoords = 0; -static void Java_MotionEvent_getHistoricalPointerCoords(JNIEnv* env, jobject - obj, JniIntWrapper p0, +static void Java_MotionEvent_getHistoricalPointerCoords(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1, - jobject p2) __attribute__ ((unused)); -static void Java_MotionEvent_getHistoricalPointerCoords(JNIEnv* env, jobject - obj, JniIntWrapper p0, + const base::android::JavaRefOrBare<jobject>& p2) __attribute__ ((unused)); +static void Java_MotionEvent_getHistoricalPointerCoords(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0, JniIntWrapper p1, - jobject p2) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + const base::android::JavaRefOrBare<jobject>& p2) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1905,18 +1883,17 @@ static void Java_MotionEvent_getHistoricalPointerCoords(JNIEnv* env, jobject "(IILandroid/view/MotionEvent$PointerCoords;)V", &g_MotionEvent_getHistoricalPointerCoords); - env->CallVoidMethod(obj, - method_id, as_jint(p0), as_jint(p1), p2); + env->CallVoidMethod(obj.obj(), + method_id, as_jint(p0), as_jint(p1), p2.obj()); jni_generator::CheckException(env); - } static base::subtle::AtomicWord g_MotionEvent_getEdgeFlags = 0; -static jint Java_MotionEvent_getEdgeFlags(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jint Java_MotionEvent_getEdgeFlags(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jint Java_MotionEvent_getEdgeFlags(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jint Java_MotionEvent_getEdgeFlags(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1927,19 +1904,19 @@ static jint Java_MotionEvent_getEdgeFlags(JNIEnv* env, jobject obj) { &g_MotionEvent_getEdgeFlags); jint ret = - env->CallIntMethod(obj, + env->CallIntMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_setEdgeFlags = 0; -static void Java_MotionEvent_setEdgeFlags(JNIEnv* env, jobject obj, - JniIntWrapper p0) __attribute__ ((unused)); -static void Java_MotionEvent_setEdgeFlags(JNIEnv* env, jobject obj, - JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static void Java_MotionEvent_setEdgeFlags(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static void Java_MotionEvent_setEdgeFlags(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1949,19 +1926,18 @@ static void Java_MotionEvent_setEdgeFlags(JNIEnv* env, jobject obj, "(I)V", &g_MotionEvent_setEdgeFlags); - env->CallVoidMethod(obj, + env->CallVoidMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); - } static base::subtle::AtomicWord g_MotionEvent_setAction = 0; -static void Java_MotionEvent_setAction(JNIEnv* env, jobject obj, JniIntWrapper - p0) __attribute__ ((unused)); -static void Java_MotionEvent_setAction(JNIEnv* env, jobject obj, JniIntWrapper - p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static void Java_MotionEvent_setAction(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static void Java_MotionEvent_setAction(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1971,19 +1947,19 @@ static void Java_MotionEvent_setAction(JNIEnv* env, jobject obj, JniIntWrapper "(I)V", &g_MotionEvent_setAction); - env->CallVoidMethod(obj, + env->CallVoidMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); - } static base::subtle::AtomicWord g_MotionEvent_offsetLocation = 0; -static void Java_MotionEvent_offsetLocation(JNIEnv* env, jobject obj, jfloat p0, +static void Java_MotionEvent_offsetLocation(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, jfloat p0, jfloat p1) __attribute__ ((unused)); -static void Java_MotionEvent_offsetLocation(JNIEnv* env, jobject obj, jfloat p0, +static void Java_MotionEvent_offsetLocation(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, jfloat p0, jfloat p1) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -1993,19 +1969,19 @@ static void Java_MotionEvent_offsetLocation(JNIEnv* env, jobject obj, jfloat p0, "(FF)V", &g_MotionEvent_offsetLocation); - env->CallVoidMethod(obj, + env->CallVoidMethod(obj.obj(), method_id, p0, p1); jni_generator::CheckException(env); - } static base::subtle::AtomicWord g_MotionEvent_setLocation = 0; -static void Java_MotionEvent_setLocation(JNIEnv* env, jobject obj, jfloat p0, +static void Java_MotionEvent_setLocation(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, jfloat p0, jfloat p1) __attribute__ ((unused)); -static void Java_MotionEvent_setLocation(JNIEnv* env, jobject obj, jfloat p0, +static void Java_MotionEvent_setLocation(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, jfloat p0, jfloat p1) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -2015,18 +1991,19 @@ static void Java_MotionEvent_setLocation(JNIEnv* env, jobject obj, jfloat p0, "(FF)V", &g_MotionEvent_setLocation); - env->CallVoidMethod(obj, + env->CallVoidMethod(obj.obj(), method_id, p0, p1); jni_generator::CheckException(env); - } static base::subtle::AtomicWord g_MotionEvent_transform = 0; -static void Java_MotionEvent_transform(JNIEnv* env, jobject obj, jobject p0) - __attribute__ ((unused)); -static void Java_MotionEvent_transform(JNIEnv* env, jobject obj, jobject p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static void Java_MotionEvent_transform(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, const + base::android::JavaRefOrBare<jobject>& p0) __attribute__ ((unused)); +static void Java_MotionEvent_transform(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, const + base::android::JavaRefOrBare<jobject>& p0) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -2036,29 +2013,27 @@ static void Java_MotionEvent_transform(JNIEnv* env, jobject obj, jobject p0) { "(Landroid/graphics/Matrix;)V", &g_MotionEvent_transform); - env->CallVoidMethod(obj, - method_id, p0); + env->CallVoidMethod(obj.obj(), + method_id, p0.obj()); jni_generator::CheckException(env); - } static base::subtle::AtomicWord g_MotionEvent_addBatchV_J_F_F_F_F_I = 0; -static void Java_MotionEvent_addBatchV_J_F_F_F_F_I(JNIEnv* env, jobject obj, - jlong p0, +static void Java_MotionEvent_addBatchV_J_F_F_F_F_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, jlong p0, jfloat p1, jfloat p2, jfloat p3, jfloat p4, JniIntWrapper p5) __attribute__ ((unused)); -static void Java_MotionEvent_addBatchV_J_F_F_F_F_I(JNIEnv* env, jobject obj, - jlong p0, +static void Java_MotionEvent_addBatchV_J_F_F_F_F_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, jlong p0, jfloat p1, jfloat p2, jfloat p3, jfloat p4, JniIntWrapper p5) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -2068,23 +2043,21 @@ static void Java_MotionEvent_addBatchV_J_F_F_F_F_I(JNIEnv* env, jobject obj, "(JFFFFI)V", &g_MotionEvent_addBatchV_J_F_F_F_F_I); - env->CallVoidMethod(obj, + env->CallVoidMethod(obj.obj(), method_id, p0, p1, p2, p3, p4, as_jint(p5)); jni_generator::CheckException(env); - } static base::subtle::AtomicWord g_MotionEvent_addBatchV_J_LAVMEPC_I = 0; -static void Java_MotionEvent_addBatchV_J_LAVMEPC_I(JNIEnv* env, jobject obj, - jlong p0, - jobjectArray p1, +static void Java_MotionEvent_addBatchV_J_LAVMEPC_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, jlong p0, + const base::android::JavaRefOrBare<jobjectArray>& p1, JniIntWrapper p2) __attribute__ ((unused)); -static void Java_MotionEvent_addBatchV_J_LAVMEPC_I(JNIEnv* env, jobject obj, - jlong p0, - jobjectArray p1, +static void Java_MotionEvent_addBatchV_J_LAVMEPC_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, jlong p0, + const base::android::JavaRefOrBare<jobjectArray>& p1, JniIntWrapper p2) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -2094,19 +2067,19 @@ static void Java_MotionEvent_addBatchV_J_LAVMEPC_I(JNIEnv* env, jobject obj, "(J[Landroid/view/MotionEvent$PointerCoords;I)V", &g_MotionEvent_addBatchV_J_LAVMEPC_I); - env->CallVoidMethod(obj, - method_id, p0, p1, as_jint(p2)); + env->CallVoidMethod(obj.obj(), + method_id, p0, p1.obj(), as_jint(p2)); jni_generator::CheckException(env); - } static base::subtle::AtomicWord g_MotionEvent_toString = 0; -static ScopedJavaLocalRef<jstring> Java_MotionEvent_toString(JNIEnv* env, - jobject obj) __attribute__ ((unused)); -static ScopedJavaLocalRef<jstring> Java_MotionEvent_toString(JNIEnv* env, - jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static base::android::ScopedJavaLocalRef<jstring> + Java_MotionEvent_toString(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static base::android::ScopedJavaLocalRef<jstring> + Java_MotionEvent_toString(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env), NULL); jmethodID method_id = base::android::MethodID::LazyGet< @@ -2117,18 +2090,18 @@ static ScopedJavaLocalRef<jstring> Java_MotionEvent_toString(JNIEnv* env, &g_MotionEvent_toString); jstring ret = - static_cast<jstring>(env->CallObjectMethod(obj, + static_cast<jstring>(env->CallObjectMethod(obj.obj(), method_id)); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jstring>(env, ret); + return base::android::ScopedJavaLocalRef<jstring>(env, ret); } static base::subtle::AtomicWord g_MotionEvent_actionToString = 0; -static ScopedJavaLocalRef<jstring> Java_MotionEvent_actionToString(JNIEnv* env, - JniIntWrapper p0) __attribute__ ((unused)); -static ScopedJavaLocalRef<jstring> Java_MotionEvent_actionToString(JNIEnv* env, - JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ +static base::android::ScopedJavaLocalRef<jstring> + Java_MotionEvent_actionToString(JNIEnv* env, JniIntWrapper p0) __attribute__ + ((unused)); +static base::android::ScopedJavaLocalRef<jstring> + Java_MotionEvent_actionToString(JNIEnv* env, JniIntWrapper p0) { CHECK_CLAZZ(env, MotionEvent_clazz(env), MotionEvent_clazz(env), NULL); jmethodID method_id = @@ -2143,15 +2116,15 @@ static ScopedJavaLocalRef<jstring> Java_MotionEvent_actionToString(JNIEnv* env, static_cast<jstring>(env->CallStaticObjectMethod(MotionEvent_clazz(env), method_id, as_jint(p0))); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jstring>(env, ret); + return base::android::ScopedJavaLocalRef<jstring>(env, ret); } static base::subtle::AtomicWord g_MotionEvent_axisToString = 0; -static ScopedJavaLocalRef<jstring> Java_MotionEvent_axisToString(JNIEnv* env, - JniIntWrapper p0) __attribute__ ((unused)); -static ScopedJavaLocalRef<jstring> Java_MotionEvent_axisToString(JNIEnv* env, - JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ +static base::android::ScopedJavaLocalRef<jstring> + Java_MotionEvent_axisToString(JNIEnv* env, JniIntWrapper p0) __attribute__ + ((unused)); +static base::android::ScopedJavaLocalRef<jstring> + Java_MotionEvent_axisToString(JNIEnv* env, JniIntWrapper p0) { CHECK_CLAZZ(env, MotionEvent_clazz(env), MotionEvent_clazz(env), NULL); jmethodID method_id = @@ -2166,14 +2139,14 @@ static ScopedJavaLocalRef<jstring> Java_MotionEvent_axisToString(JNIEnv* env, static_cast<jstring>(env->CallStaticObjectMethod(MotionEvent_clazz(env), method_id, as_jint(p0))); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jstring>(env, ret); + return base::android::ScopedJavaLocalRef<jstring>(env, ret); } static base::subtle::AtomicWord g_MotionEvent_axisFromString = 0; -static jint Java_MotionEvent_axisFromString(JNIEnv* env, jstring p0) - __attribute__ ((unused)); -static jint Java_MotionEvent_axisFromString(JNIEnv* env, jstring p0) { - /* Must call RegisterNativesImpl() */ +static jint Java_MotionEvent_axisFromString(JNIEnv* env, const + base::android::JavaRefOrBare<jstring>& p0) __attribute__ ((unused)); +static jint Java_MotionEvent_axisFromString(JNIEnv* env, const + base::android::JavaRefOrBare<jstring>& p0) { CHECK_CLAZZ(env, MotionEvent_clazz(env), MotionEvent_clazz(env), 0); jmethodID method_id = @@ -2186,18 +2159,21 @@ static jint Java_MotionEvent_axisFromString(JNIEnv* env, jstring p0) { jint ret = env->CallStaticIntMethod(MotionEvent_clazz(env), - method_id, p0); + method_id, p0.obj()); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_MotionEvent_writeToParcel = 0; -static void Java_MotionEvent_writeToParcel(JNIEnv* env, jobject obj, jobject p0, +static void Java_MotionEvent_writeToParcel(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, const + base::android::JavaRefOrBare<jobject>& p0, JniIntWrapper p1) __attribute__ ((unused)); -static void Java_MotionEvent_writeToParcel(JNIEnv* env, jobject obj, jobject p0, +static void Java_MotionEvent_writeToParcel(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, const + base::android::JavaRefOrBare<jobject>& p0, JniIntWrapper p1) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), MotionEvent_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -2207,22 +2183,13 @@ static void Java_MotionEvent_writeToParcel(JNIEnv* env, jobject obj, jobject p0, "(Landroid/os/Parcel;I)V", &g_MotionEvent_writeToParcel); - env->CallVoidMethod(obj, - method_id, p0, as_jint(p1)); + env->CallVoidMethod(obj.obj(), + method_id, p0.obj(), as_jint(p1)); jni_generator::CheckException(env); - } // Step 3: RegisterNatives. -static bool RegisterNativesImpl(JNIEnv* env) { - - g_MotionEvent_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( - base::android::GetClass(env, kMotionEventClassPath).obj())); - - return true; -} - } // namespace JNI_MotionEvent #endif // android_view_MotionEvent_JNI diff --git a/base/android/jni_generator/testFromJavaP.golden b/base/android/jni_generator/testFromJavaP.golden index f32666c..18a9430 100644 --- a/base/android/jni_generator/testFromJavaP.golden +++ b/base/android/jni_generator/testFromJavaP.golden @@ -20,8 +20,8 @@ namespace { const char kInputStreamClassPath[] = "java/io/InputStream"; // Leaking this jclass as we cannot use LazyInstance from some threads. -jclass g_InputStream_clazz = NULL; -#define InputStream_clazz(env) g_InputStream_clazz +base::subtle::AtomicWord g_InputStream_clazz __attribute__((unused)) = 0; +#define InputStream_clazz(env) base::android::LazyGetClass(env, kInputStreamClassPath, &g_InputStream_clazz) } // namespace @@ -30,11 +30,11 @@ namespace JNI_InputStream { // Step 2: method stubs. static base::subtle::AtomicWord g_InputStream_available = 0; -static jint Java_InputStream_available(JNIEnv* env, jobject obj) __attribute__ - ((unused)); -static jint Java_InputStream_available(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jint Java_InputStream_available(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jint Java_InputStream_available(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), InputStream_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -45,18 +45,18 @@ static jint Java_InputStream_available(JNIEnv* env, jobject obj) { &g_InputStream_available); jint ret = - env->CallIntMethod(obj, + env->CallIntMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_InputStream_close = 0; -static void Java_InputStream_close(JNIEnv* env, jobject obj) __attribute__ - ((unused)); -static void Java_InputStream_close(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static void Java_InputStream_close(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static void Java_InputStream_close(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), InputStream_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -66,18 +66,18 @@ static void Java_InputStream_close(JNIEnv* env, jobject obj) { "()V", &g_InputStream_close); - env->CallVoidMethod(obj, + env->CallVoidMethod(obj.obj(), method_id); jni_generator::CheckException(env); - } static base::subtle::AtomicWord g_InputStream_mark = 0; -static void Java_InputStream_mark(JNIEnv* env, jobject obj, JniIntWrapper p0) - __attribute__ ((unused)); -static void Java_InputStream_mark(JNIEnv* env, jobject obj, JniIntWrapper p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static void Java_InputStream_mark(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) __attribute__ + ((unused)); +static void Java_InputStream_mark(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, JniIntWrapper p0) { + CHECK_CLAZZ(env, obj.obj(), InputStream_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -87,18 +87,17 @@ static void Java_InputStream_mark(JNIEnv* env, jobject obj, JniIntWrapper p0) { "(I)V", &g_InputStream_mark); - env->CallVoidMethod(obj, + env->CallVoidMethod(obj.obj(), method_id, as_jint(p0)); jni_generator::CheckException(env); - } static base::subtle::AtomicWord g_InputStream_markSupported = 0; -static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) - __attribute__ ((unused)); -static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jboolean Java_InputStream_markSupported(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jboolean Java_InputStream_markSupported(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), InputStream_clazz(env), false); jmethodID method_id = base::android::MethodID::LazyGet< @@ -109,18 +108,18 @@ static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) { &g_InputStream_markSupported); jboolean ret = - env->CallBooleanMethod(obj, + env->CallBooleanMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_InputStream_readI = 0; -static jint Java_InputStream_readI(JNIEnv* env, jobject obj) __attribute__ - ((unused)); -static jint Java_InputStream_readI(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jint Java_InputStream_readI(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static jint Java_InputStream_readI(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), InputStream_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -131,18 +130,20 @@ static jint Java_InputStream_readI(JNIEnv* env, jobject obj) { &g_InputStream_readI); jint ret = - env->CallIntMethod(obj, + env->CallIntMethod(obj.obj(), method_id); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_InputStream_readI_AB = 0; -static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) - __attribute__ ((unused)); -static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jint Java_InputStream_readI_AB(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, const + base::android::JavaRefOrBare<jbyteArray>& p0) __attribute__ ((unused)); +static jint Java_InputStream_readI_AB(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, const + base::android::JavaRefOrBare<jbyteArray>& p0) { + CHECK_CLAZZ(env, obj.obj(), InputStream_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -153,23 +154,24 @@ static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) { &g_InputStream_readI_AB); jint ret = - env->CallIntMethod(obj, - method_id, p0); + env->CallIntMethod(obj.obj(), + method_id, p0.obj()); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_InputStream_readI_AB_I_I = 0; -static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray - p0, +static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, const + base::android::JavaRefOrBare<jbyteArray>& p0, JniIntWrapper p1, JniIntWrapper p2) __attribute__ ((unused)); -static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray - p0, +static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, const + base::android::JavaRefOrBare<jbyteArray>& p0, JniIntWrapper p1, JniIntWrapper p2) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, + CHECK_CLAZZ(env, obj.obj(), InputStream_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -180,18 +182,18 @@ static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray &g_InputStream_readI_AB_I_I); jint ret = - env->CallIntMethod(obj, - method_id, p0, as_jint(p1), as_jint(p2)); + env->CallIntMethod(obj.obj(), + method_id, p0.obj(), as_jint(p1), as_jint(p2)); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_InputStream_reset = 0; -static void Java_InputStream_reset(JNIEnv* env, jobject obj) __attribute__ - ((unused)); -static void Java_InputStream_reset(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static void Java_InputStream_reset(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static void Java_InputStream_reset(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), InputStream_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -201,18 +203,18 @@ static void Java_InputStream_reset(JNIEnv* env, jobject obj) { "()V", &g_InputStream_reset); - env->CallVoidMethod(obj, + env->CallVoidMethod(obj.obj(), method_id); jni_generator::CheckException(env); - } static base::subtle::AtomicWord g_InputStream_skip = 0; -static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) - __attribute__ ((unused)); -static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static jlong Java_InputStream_skip(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, jlong p0) __attribute__ + ((unused)); +static jlong Java_InputStream_skip(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj, jlong p0) { + CHECK_CLAZZ(env, obj.obj(), InputStream_clazz(env), 0); jmethodID method_id = base::android::MethodID::LazyGet< @@ -223,17 +225,17 @@ static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) { &g_InputStream_skip); jlong ret = - env->CallLongMethod(obj, + env->CallLongMethod(obj.obj(), method_id, p0); jni_generator::CheckException(env); return ret; } static base::subtle::AtomicWord g_InputStream_Constructor = 0; -static ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(JNIEnv* env) - __attribute__ ((unused)); -static ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(JNIEnv* env) { - /* Must call RegisterNativesImpl() */ +static base::android::ScopedJavaLocalRef<jobject> + Java_InputStream_Constructor(JNIEnv* env) __attribute__ ((unused)); +static base::android::ScopedJavaLocalRef<jobject> + Java_InputStream_Constructor(JNIEnv* env) { CHECK_CLAZZ(env, InputStream_clazz(env), InputStream_clazz(env), NULL); jmethodID method_id = @@ -248,19 +250,11 @@ static ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(JNIEnv* env) { env->NewObject(InputStream_clazz(env), method_id); jni_generator::CheckException(env); - return ScopedJavaLocalRef<jobject>(env, ret); + return base::android::ScopedJavaLocalRef<jobject>(env, ret); } // Step 3: RegisterNatives. -static bool RegisterNativesImpl(JNIEnv* env) { - - g_InputStream_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( - base::android::GetClass(env, kInputStreamClassPath).obj())); - - return true; -} - } // namespace JNI_InputStream #endif // java_io_InputStream_JNI diff --git a/base/android/jni_generator/testFromJavaPGenerics.golden b/base/android/jni_generator/testFromJavaPGenerics.golden index 489872c..c076c39 100644 --- a/base/android/jni_generator/testFromJavaPGenerics.golden +++ b/base/android/jni_generator/testFromJavaPGenerics.golden @@ -20,8 +20,8 @@ namespace { const char kHashSetClassPath[] = "java/util/HashSet"; // Leaking this jclass as we cannot use LazyInstance from some threads. -jclass g_HashSet_clazz = NULL; -#define HashSet_clazz(env) g_HashSet_clazz +base::subtle::AtomicWord g_HashSet_clazz __attribute__((unused)) = 0; +#define HashSet_clazz(env) base::android::LazyGetClass(env, kHashSetClassPath, &g_HashSet_clazz) } // namespace @@ -30,11 +30,11 @@ namespace JNI_HashSet { // Step 2: method stubs. static base::subtle::AtomicWord g_HashSet_dummy = 0; -static void Java_HashSet_dummy(JNIEnv* env, jobject obj) __attribute__ - ((unused)); -static void Java_HashSet_dummy(JNIEnv* env, jobject obj) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, +static void Java_HashSet_dummy(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) __attribute__ ((unused)); +static void Java_HashSet_dummy(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& obj) { + CHECK_CLAZZ(env, obj.obj(), HashSet_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< @@ -44,22 +44,13 @@ static void Java_HashSet_dummy(JNIEnv* env, jobject obj) { "()V", &g_HashSet_dummy); - env->CallVoidMethod(obj, + env->CallVoidMethod(obj.obj(), method_id); jni_generator::CheckException(env); - } // Step 3: RegisterNatives. -static bool RegisterNativesImpl(JNIEnv* env) { - - g_HashSet_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( - base::android::GetClass(env, kHashSetClassPath).obj())); - - return true; -} - } // namespace JNI_HashSet #endif // java_util_HashSet_JNI diff --git a/base/android/jni_generator/testInnerClassNatives.golden b/base/android/jni_generator/testInnerClassNatives.golden index ad140e2..20b8830 100644 --- a/base/android/jni_generator/testInnerClassNatives.golden +++ b/base/android/jni_generator/testInnerClassNatives.golden @@ -21,18 +21,23 @@ namespace { const char kTestJniClassPath[] = "org/chromium/TestJni"; const char kMyInnerClassClassPath[] = "org/chromium/TestJni$MyInnerClass"; // Leaking this jclass as we cannot use LazyInstance from some threads. -jclass g_TestJni_clazz = NULL; -#define TestJni_clazz(env) g_TestJni_clazz +base::subtle::AtomicWord g_TestJni_clazz __attribute__((unused)) = 0; +#define TestJni_clazz(env) base::android::LazyGetClass(env, kTestJniClassPath, &g_TestJni_clazz) +// Leaking this jclass as we cannot use LazyInstance from some threads. +base::subtle::AtomicWord g_MyInnerClass_clazz __attribute__((unused)) = 0; +#define MyInnerClass_clazz(env) base::android::LazyGetClass(env, kMyInnerClassClassPath, &g_MyInnerClass_clazz) } // namespace // Step 2: method stubs. -static jint Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller); +static jint Init(JNIEnv* env, const base::android::JavaParamRef<jobject>& + jcaller); -static jint Java_org_chromium_TestJni_00024MyInnerClass_nativeInit(JNIEnv* env, - jobject jcaller) { - return Init(env, JavaParamRef<jobject>(env, jcaller)); +JNI_GENERATOR_EXPORT jint + Java_org_chromium_TestJni_00024MyInnerClass_nativeInit(JNIEnv* env, jobject + jcaller) { + return Init(env, base::android::JavaParamRef<jobject>(env, jcaller)); } // Step 3: RegisterNatives. @@ -47,9 +52,8 @@ static const JNINativeMethod kMethodsMyInnerClass[] = { }; static bool RegisterNativesImpl(JNIEnv* env) { - - g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( - base::android::GetClass(env, kTestJniClassPath).obj())); + if (jni_generator::ShouldSkipJniRegistration(false)) + return true; const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass); diff --git a/base/android/jni_generator/testInnerClassNativesBothInnerAndOuter.golden b/base/android/jni_generator/testInnerClassNativesBothInnerAndOuter.golden index 0a890e7..67352e7 100644 --- a/base/android/jni_generator/testInnerClassNativesBothInnerAndOuter.golden +++ b/base/android/jni_generator/testInnerClassNativesBothInnerAndOuter.golden @@ -22,24 +22,31 @@ const char kMyOtherInnerClassClassPath[] = "org/chromium/TestJni$MyOtherInnerClass"; const char kTestJniClassPath[] = "org/chromium/TestJni"; // Leaking this jclass as we cannot use LazyInstance from some threads. -jclass g_TestJni_clazz = NULL; -#define TestJni_clazz(env) g_TestJni_clazz +base::subtle::AtomicWord g_MyOtherInnerClass_clazz __attribute__((unused)) = 0; +#define MyOtherInnerClass_clazz(env) base::android::LazyGetClass(env, kMyOtherInnerClassClassPath, &g_MyOtherInnerClass_clazz) +// Leaking this jclass as we cannot use LazyInstance from some threads. +base::subtle::AtomicWord g_TestJni_clazz __attribute__((unused)) = 0; +#define TestJni_clazz(env) base::android::LazyGetClass(env, kTestJniClassPath, &g_TestJni_clazz) } // namespace // Step 2: method stubs. -static jint Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller); +static jint Init(JNIEnv* env, const base::android::JavaParamRef<jobject>& + jcaller); -static jint Java_org_chromium_TestJni_nativeInit(JNIEnv* env, jobject jcaller) { - return Init(env, JavaParamRef<jobject>(env, jcaller)); +JNI_GENERATOR_EXPORT jint Java_org_chromium_TestJni_nativeInit(JNIEnv* env, + jobject jcaller) { + return Init(env, base::android::JavaParamRef<jobject>(env, jcaller)); } -static jint Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller); +static jint Init(JNIEnv* env, const base::android::JavaParamRef<jobject>& + jcaller); -static jint Java_org_chromium_TestJni_00024MyOtherInnerClass_nativeInit(JNIEnv* - env, jobject jcaller) { - return Init(env, JavaParamRef<jobject>(env, jcaller)); +JNI_GENERATOR_EXPORT jint + Java_org_chromium_TestJni_00024MyOtherInnerClass_nativeInit(JNIEnv* env, + jobject jcaller) { + return Init(env, base::android::JavaParamRef<jobject>(env, jcaller)); } // Step 3: RegisterNatives. @@ -61,9 +68,8 @@ static const JNINativeMethod kMethodsTestJni[] = { }; static bool RegisterNativesImpl(JNIEnv* env) { - - g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( - base::android::GetClass(env, kTestJniClassPath).obj())); + if (jni_generator::ShouldSkipJniRegistration(false)) + return true; const int kMethodsMyOtherInnerClassSize = arraysize(kMethodsMyOtherInnerClass); diff --git a/base/android/jni_generator/testInnerClassNativesMultiple.golden b/base/android/jni_generator/testInnerClassNativesMultiple.golden index 268f794..7807efa 100644 --- a/base/android/jni_generator/testInnerClassNativesMultiple.golden +++ b/base/android/jni_generator/testInnerClassNativesMultiple.golden @@ -23,25 +23,35 @@ const char kMyOtherInnerClassClassPath[] = const char kTestJniClassPath[] = "org/chromium/TestJni"; const char kMyInnerClassClassPath[] = "org/chromium/TestJni$MyInnerClass"; // Leaking this jclass as we cannot use LazyInstance from some threads. -jclass g_TestJni_clazz = NULL; -#define TestJni_clazz(env) g_TestJni_clazz +base::subtle::AtomicWord g_MyOtherInnerClass_clazz __attribute__((unused)) = 0; +#define MyOtherInnerClass_clazz(env) base::android::LazyGetClass(env, kMyOtherInnerClassClassPath, &g_MyOtherInnerClass_clazz) +// Leaking this jclass as we cannot use LazyInstance from some threads. +base::subtle::AtomicWord g_TestJni_clazz __attribute__((unused)) = 0; +#define TestJni_clazz(env) base::android::LazyGetClass(env, kTestJniClassPath, &g_TestJni_clazz) +// Leaking this jclass as we cannot use LazyInstance from some threads. +base::subtle::AtomicWord g_MyInnerClass_clazz __attribute__((unused)) = 0; +#define MyInnerClass_clazz(env) base::android::LazyGetClass(env, kMyInnerClassClassPath, &g_MyInnerClass_clazz) } // namespace // Step 2: method stubs. -static jint Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller); +static jint Init(JNIEnv* env, const base::android::JavaParamRef<jobject>& + jcaller); -static jint Java_org_chromium_TestJni_00024MyInnerClass_nativeInit(JNIEnv* env, - jobject jcaller) { - return Init(env, JavaParamRef<jobject>(env, jcaller)); +JNI_GENERATOR_EXPORT jint + Java_org_chromium_TestJni_00024MyInnerClass_nativeInit(JNIEnv* env, jobject + jcaller) { + return Init(env, base::android::JavaParamRef<jobject>(env, jcaller)); } -static jint Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller); +static jint Init(JNIEnv* env, const base::android::JavaParamRef<jobject>& + jcaller); -static jint Java_org_chromium_TestJni_00024MyOtherInnerClass_nativeInit(JNIEnv* - env, jobject jcaller) { - return Init(env, JavaParamRef<jobject>(env, jcaller)); +JNI_GENERATOR_EXPORT jint + Java_org_chromium_TestJni_00024MyOtherInnerClass_nativeInit(JNIEnv* env, + jobject jcaller) { + return Init(env, base::android::JavaParamRef<jobject>(env, jcaller)); } // Step 3: RegisterNatives. @@ -65,9 +75,8 @@ static const JNINativeMethod kMethodsMyInnerClass[] = { }; static bool RegisterNativesImpl(JNIEnv* env) { - - g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( - base::android::GetClass(env, kTestJniClassPath).obj())); + if (jni_generator::ShouldSkipJniRegistration(false)) + return true; const int kMethodsMyOtherInnerClassSize = arraysize(kMethodsMyOtherInnerClass); diff --git a/base/android/jni_generator/testMultipleJNIAdditionalImport.golden b/base/android/jni_generator/testMultipleJNIAdditionalImport.golden index 6de8c21..0eecb5a 100644 --- a/base/android/jni_generator/testMultipleJNIAdditionalImport.golden +++ b/base/android/jni_generator/testMultipleJNIAdditionalImport.golden @@ -20,30 +20,31 @@ namespace { const char kFooClassPath[] = "org/chromium/foo/Foo"; // Leaking this jclass as we cannot use LazyInstance from some threads. -jclass g_Foo_clazz = NULL; -#define Foo_clazz(env) g_Foo_clazz +base::subtle::AtomicWord g_Foo_clazz __attribute__((unused)) = 0; +#define Foo_clazz(env) base::android::LazyGetClass(env, kFooClassPath, &g_Foo_clazz) } // namespace // Step 2: method stubs. -static void DoSomething(JNIEnv* env, const JavaParamRef<jclass>& jcaller, - const JavaParamRef<jobject>& callback1, - const JavaParamRef<jobject>& callback2); - -static void Java_org_chromium_foo_Foo_nativeDoSomething(JNIEnv* env, jclass +static void DoSomething(JNIEnv* env, const base::android::JavaParamRef<jclass>& jcaller, + const base::android::JavaParamRef<jobject>& callback1, + const base::android::JavaParamRef<jobject>& callback2); + +JNI_GENERATOR_EXPORT void Java_org_chromium_foo_Foo_nativeDoSomething(JNIEnv* + env, jclass jcaller, jobject callback1, jobject callback2) { - return DoSomething(env, JavaParamRef<jclass>(env, jcaller), - JavaParamRef<jobject>(env, callback1), JavaParamRef<jobject>(env, - callback2)); + return DoSomething(env, base::android::JavaParamRef<jclass>(env, jcaller), + base::android::JavaParamRef<jobject>(env, callback1), + base::android::JavaParamRef<jobject>(env, callback2)); } static base::subtle::AtomicWord g_Foo_calledByNative = 0; -static void Java_Foo_calledByNative(JNIEnv* env, jobject callback1, - jobject callback2) { - /* Must call RegisterNativesImpl() */ +static void Java_Foo_calledByNative(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& callback1, + const base::android::JavaRefOrBare<jobject>& callback2) { CHECK_CLAZZ(env, Foo_clazz(env), Foo_clazz(env)); jmethodID method_id = @@ -51,7 +52,6 @@ static void Java_Foo_calledByNative(JNIEnv* env, jobject callback1, base::android::MethodID::TYPE_STATIC>( env, Foo_clazz(env), "calledByNative", - "(" "Lorg/chromium/foo/Bar1$Callback;" "Lorg/chromium/foo/Bar2$Callback;" @@ -60,9 +60,8 @@ static void Java_Foo_calledByNative(JNIEnv* env, jobject callback1, &g_Foo_calledByNative); env->CallStaticVoidMethod(Foo_clazz(env), - method_id, callback1, callback2); + method_id, callback1.obj(), callback2.obj()); jni_generator::CheckException(env); - } // Step 3: RegisterNatives. @@ -77,9 +76,8 @@ static const JNINativeMethod kMethodsFoo[] = { }; static bool RegisterNativesImpl(JNIEnv* env) { - - g_Foo_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( - base::android::GetClass(env, kFooClassPath).obj())); + if (jni_generator::ShouldSkipJniRegistration(false)) + return true; const int kMethodsFooSize = arraysize(kMethodsFoo); diff --git a/base/android/jni_generator/testNativeExportsOption.golden b/base/android/jni_generator/testNativeExportsOption.golden deleted file mode 100644 index 2c89e3b..0000000 --- a/base/android/jni_generator/testNativeExportsOption.golden +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright 2014 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 file is autogenerated by -// base/android/jni_generator/jni_generator.py -// For -// org/chromium/example/jni_generator/SampleForTests - -#ifndef org_chromium_example_jni_generator_SampleForTests_JNI -#define org_chromium_example_jni_generator_SampleForTests_JNI - -#include <jni.h> - -#include "base/android/jni_generator/jni_generator_helper.h" - -#include "base/android/jni_int_wrapper.h" - -// Step 1: forward declarations. -namespace { -const char kSampleForTestsClassPath[] = - "org/chromium/example/jni_generator/SampleForTests"; -// Leaking this jclass as we cannot use LazyInstance from some threads. -base::subtle::AtomicWord g_SampleForTests_clazz __attribute__((unused)) = 0; -#define SampleForTests_clazz(env) base::android::LazyGetClass(env, kSampleForTestsClassPath, &g_SampleForTests_clazz) - -} // namespace - -// Step 2: method stubs. -extern "C" __attribute__((visibility("default"))) -jint - Java_org_chromium_example_jni_1generator_SampleForTests_nativeStaticMethod(JNIEnv* - env, - jobject jcaller, - jlong nativeTest, - jint arg1) { - Test* native = reinterpret_cast<Test*>(nativeTest); - CHECK_NATIVE_PTR(env, jcaller, native, "StaticMethod", 0); - return native->StaticMethod(env, JavaParamRef<jobject>(env, jcaller), arg1); -} - -extern "C" __attribute__((visibility("default"))) -jint - Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod(JNIEnv* - env, - jobject jcaller, - jlong nativeTest, - jint arg1) { - Test* native = reinterpret_cast<Test*>(nativeTest); - CHECK_NATIVE_PTR(env, jcaller, native, "Method", 0); - return native->Method(env, JavaParamRef<jobject>(env, jcaller), arg1); -} - -static jint Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller); - -extern "C" __attribute__((visibility("default"))) -jint - Java_org_chromium_example_jni_1generator_SampleForTests_00024MyInnerClass_nativeInit(JNIEnv* - env, jobject jcaller) { - return Init(env, JavaParamRef<jobject>(env, jcaller)); -} - -static jint Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller); - -extern "C" __attribute__((visibility("default"))) -jint - Java_org_chromium_example_jni_1generator_SampleForTests_00024MyOtherInnerClass_nativeInit(JNIEnv* - env, jobject jcaller) { - return Init(env, JavaParamRef<jobject>(env, jcaller)); -} - -static base::subtle::AtomicWord g_SampleForTests_testMethodWithParam = 0; -static void Java_SampleForTests_testMethodWithParam(JNIEnv* env, jobject obj, - JniIntWrapper iParam) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, - SampleForTests_clazz(env)); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_INSTANCE>( - env, SampleForTests_clazz(env), - "testMethodWithParam", - -"(" -"I" -")" -"V", - &g_SampleForTests_testMethodWithParam); - - env->CallVoidMethod(obj, - method_id, as_jint(iParam)); - jni_generator::CheckException(env); - -} - -static base::subtle::AtomicWord g_SampleForTests_testMethodWithParamAndReturn = - 0; -static ScopedJavaLocalRef<jstring> - Java_SampleForTests_testMethodWithParamAndReturn(JNIEnv* env, jobject obj, - JniIntWrapper iParam) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, - SampleForTests_clazz(env), NULL); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_INSTANCE>( - env, SampleForTests_clazz(env), - "testMethodWithParamAndReturn", - -"(" -"I" -")" -"Ljava/lang/String;", - &g_SampleForTests_testMethodWithParamAndReturn); - - jstring ret = - static_cast<jstring>(env->CallObjectMethod(obj, - method_id, as_jint(iParam))); - jni_generator::CheckException(env); - return ScopedJavaLocalRef<jstring>(env, ret); -} - -static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithParam = 0; -static jint Java_SampleForTests_testStaticMethodWithParam(JNIEnv* env, - JniIntWrapper iParam) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, SampleForTests_clazz(env), - SampleForTests_clazz(env), 0); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_STATIC>( - env, SampleForTests_clazz(env), - "testStaticMethodWithParam", - -"(" -"I" -")" -"I", - &g_SampleForTests_testStaticMethodWithParam); - - jint ret = - env->CallStaticIntMethod(SampleForTests_clazz(env), - method_id, as_jint(iParam)); - jni_generator::CheckException(env); - return ret; -} - -static base::subtle::AtomicWord g_SampleForTests_testMethodWithNoParam = 0; -static jdouble Java_SampleForTests_testMethodWithNoParam(JNIEnv* env) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, SampleForTests_clazz(env), - SampleForTests_clazz(env), 0); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_STATIC>( - env, SampleForTests_clazz(env), - "testMethodWithNoParam", - -"(" -")" -"D", - &g_SampleForTests_testMethodWithNoParam); - - jdouble ret = - env->CallStaticDoubleMethod(SampleForTests_clazz(env), - method_id); - jni_generator::CheckException(env); - return ret; -} - -static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithNoParam = - 0; -static ScopedJavaLocalRef<jstring> - Java_SampleForTests_testStaticMethodWithNoParam(JNIEnv* env) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, SampleForTests_clazz(env), - SampleForTests_clazz(env), NULL); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_STATIC>( - env, SampleForTests_clazz(env), - "testStaticMethodWithNoParam", - -"(" -")" -"Ljava/lang/String;", - &g_SampleForTests_testStaticMethodWithNoParam); - - jstring ret = -static_cast<jstring>(env->CallStaticObjectMethod(SampleForTests_clazz(env), - method_id)); - jni_generator::CheckException(env); - return ScopedJavaLocalRef<jstring>(env, ret); -} - -// Step 3: RegisterNatives. - -static bool RegisterNativesImpl(JNIEnv* env) { - - return true; -} - -#endif // org_chromium_example_jni_generator_SampleForTests_JNI diff --git a/base/android/jni_generator/testNativeExportsOptionalOption.golden b/base/android/jni_generator/testNativeExportsOptionalOption.golden deleted file mode 100644 index 03484c9..0000000 --- a/base/android/jni_generator/testNativeExportsOptionalOption.golden +++ /dev/null @@ -1,272 +0,0 @@ -// Copyright 2014 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 file is autogenerated by -// base/android/jni_generator/jni_generator.py -// For -// org/chromium/example/jni_generator/SampleForTests - -#ifndef org_chromium_example_jni_generator_SampleForTests_JNI -#define org_chromium_example_jni_generator_SampleForTests_JNI - -#include <jni.h> - -#include "base/android/jni_generator/jni_generator_helper.h" - -#include "base/android/jni_int_wrapper.h" - -// Step 1: forward declarations. -namespace { -const char kSampleForTestsClassPath[] = - "org/chromium/example/jni_generator/SampleForTests"; -// Leaking this jclass as we cannot use LazyInstance from some threads. -base::subtle::AtomicWord g_SampleForTests_clazz __attribute__((unused)) = 0; -#define SampleForTests_clazz(env) base::android::LazyGetClass(env, kSampleForTestsClassPath, &g_SampleForTests_clazz) - -} // namespace - -// Step 2: method stubs. -extern "C" __attribute__((visibility("default"))) -jint - Java_org_chromium_example_jni_1generator_SampleForTests_nativeStaticMethod(JNIEnv* - env, - jobject jcaller, - jlong nativeTest, - jint arg1) { - Test* native = reinterpret_cast<Test*>(nativeTest); - CHECK_NATIVE_PTR(env, jcaller, native, "StaticMethod", 0); - return native->StaticMethod(env, JavaParamRef<jobject>(env, jcaller), arg1); -} - -extern "C" __attribute__((visibility("default"))) -jint - Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod(JNIEnv* - env, - jobject jcaller, - jlong nativeTest, - jint arg1) { - Test* native = reinterpret_cast<Test*>(nativeTest); - CHECK_NATIVE_PTR(env, jcaller, native, "Method", 0); - return native->Method(env, JavaParamRef<jobject>(env, jcaller), arg1); -} - -static jint Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller); - -extern "C" __attribute__((visibility("default"))) -jint - Java_org_chromium_example_jni_1generator_SampleForTests_00024MyInnerClass_nativeInit(JNIEnv* - env, jobject jcaller) { - return Init(env, JavaParamRef<jobject>(env, jcaller)); -} - -static jint Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller); - -extern "C" __attribute__((visibility("default"))) -jint - Java_org_chromium_example_jni_1generator_SampleForTests_00024MyOtherInnerClass_nativeInit(JNIEnv* - env, jobject jcaller) { - return Init(env, JavaParamRef<jobject>(env, jcaller)); -} - -static base::subtle::AtomicWord g_SampleForTests_testMethodWithParam = 0; -static void Java_SampleForTests_testMethodWithParam(JNIEnv* env, jobject obj, - JniIntWrapper iParam) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, - SampleForTests_clazz(env)); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_INSTANCE>( - env, SampleForTests_clazz(env), - "testMethodWithParam", - -"(" -"I" -")" -"V", - &g_SampleForTests_testMethodWithParam); - - env->CallVoidMethod(obj, - method_id, as_jint(iParam)); - jni_generator::CheckException(env); - -} - -static base::subtle::AtomicWord g_SampleForTests_testMethodWithParamAndReturn = - 0; -static ScopedJavaLocalRef<jstring> - Java_SampleForTests_testMethodWithParamAndReturn(JNIEnv* env, jobject obj, - JniIntWrapper iParam) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, obj, - SampleForTests_clazz(env), NULL); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_INSTANCE>( - env, SampleForTests_clazz(env), - "testMethodWithParamAndReturn", - -"(" -"I" -")" -"Ljava/lang/String;", - &g_SampleForTests_testMethodWithParamAndReturn); - - jstring ret = - static_cast<jstring>(env->CallObjectMethod(obj, - method_id, as_jint(iParam))); - jni_generator::CheckException(env); - return ScopedJavaLocalRef<jstring>(env, ret); -} - -static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithParam = 0; -static jint Java_SampleForTests_testStaticMethodWithParam(JNIEnv* env, - JniIntWrapper iParam) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, SampleForTests_clazz(env), - SampleForTests_clazz(env), 0); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_STATIC>( - env, SampleForTests_clazz(env), - "testStaticMethodWithParam", - -"(" -"I" -")" -"I", - &g_SampleForTests_testStaticMethodWithParam); - - jint ret = - env->CallStaticIntMethod(SampleForTests_clazz(env), - method_id, as_jint(iParam)); - jni_generator::CheckException(env); - return ret; -} - -static base::subtle::AtomicWord g_SampleForTests_testMethodWithNoParam = 0; -static jdouble Java_SampleForTests_testMethodWithNoParam(JNIEnv* env) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, SampleForTests_clazz(env), - SampleForTests_clazz(env), 0); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_STATIC>( - env, SampleForTests_clazz(env), - "testMethodWithNoParam", - -"(" -")" -"D", - &g_SampleForTests_testMethodWithNoParam); - - jdouble ret = - env->CallStaticDoubleMethod(SampleForTests_clazz(env), - method_id); - jni_generator::CheckException(env); - return ret; -} - -static base::subtle::AtomicWord g_SampleForTests_testStaticMethodWithNoParam = - 0; -static ScopedJavaLocalRef<jstring> - Java_SampleForTests_testStaticMethodWithNoParam(JNIEnv* env) { - /* Must call RegisterNativesImpl() */ - CHECK_CLAZZ(env, SampleForTests_clazz(env), - SampleForTests_clazz(env), NULL); - jmethodID method_id = - base::android::MethodID::LazyGet< - base::android::MethodID::TYPE_STATIC>( - env, SampleForTests_clazz(env), - "testStaticMethodWithNoParam", - -"(" -")" -"Ljava/lang/String;", - &g_SampleForTests_testStaticMethodWithNoParam); - - jstring ret = -static_cast<jstring>(env->CallStaticObjectMethod(SampleForTests_clazz(env), - method_id)); - jni_generator::CheckException(env); - return ScopedJavaLocalRef<jstring>(env, ret); -} - -// Step 3: RegisterNatives. - -static const JNINativeMethod kMethodsMyOtherInnerClass[] = { - { "nativeInit", -"(" -")" -"I", - reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_00024MyOtherInnerClass_nativeInit) - }, -}; - -static const JNINativeMethod kMethodsMyInnerClass[] = { - { "nativeInit", -"(" -")" -"I", - reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_00024MyInnerClass_nativeInit) - }, -}; - -static const JNINativeMethod kMethodsSampleForTests[] = { - { "nativeStaticMethod", -"(" -"J" -"I" -")" -"I", - reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeStaticMethod) - }, - { "nativeMethod", -"(" -"J" -"I" -")" -"I", - reinterpret_cast<void*>(Java_org_chromium_example_jni_1generator_SampleForTests_nativeMethod) - }, -}; - -static bool RegisterNativesImpl(JNIEnv* env) { - if (base::android::IsManualJniRegistrationDisabled()) return true; - - const int kMethodsMyOtherInnerClassSize = - arraysize(kMethodsMyOtherInnerClass); - - if (env->RegisterNatives(MyOtherInnerClass_clazz(env), - kMethodsMyOtherInnerClass, - kMethodsMyOtherInnerClassSize) < 0) { - jni_generator::HandleRegistrationError( - env, MyOtherInnerClass_clazz(env), __FILE__); - return false; - } - - const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass); - - if (env->RegisterNatives(MyInnerClass_clazz(env), - kMethodsMyInnerClass, - kMethodsMyInnerClassSize) < 0) { - jni_generator::HandleRegistrationError( - env, MyInnerClass_clazz(env), __FILE__); - return false; - } - - const int kMethodsSampleForTestsSize = arraysize(kMethodsSampleForTests); - - if (env->RegisterNatives(SampleForTests_clazz(env), - kMethodsSampleForTests, - kMethodsSampleForTestsSize) < 0) { - jni_generator::HandleRegistrationError( - env, SampleForTests_clazz(env), __FILE__); - return false; - } - - return true; -} - -#endif // org_chromium_example_jni_generator_SampleForTests_JNI diff --git a/base/android/jni_generator/testNatives.golden b/base/android/jni_generator/testNatives.golden index f9538a3..3362c92 100644 --- a/base/android/jni_generator/testNatives.golden +++ b/base/android/jni_generator/testNatives.golden @@ -20,30 +20,33 @@ namespace { const char kTestJniClassPath[] = "org/chromium/TestJni"; // Leaking this jclass as we cannot use LazyInstance from some threads. -jclass g_TestJni_clazz = NULL; -#define TestJni_clazz(env) g_TestJni_clazz +base::subtle::AtomicWord g_TestJni_clazz __attribute__((unused)) = 0; +#define TestJni_clazz(env) base::android::LazyGetClass(env, kTestJniClassPath, &g_TestJni_clazz) } // namespace // Step 2: method stubs. -static jint Init(JNIEnv* env, const JavaParamRef<jobject>& jcaller); +static jint Init(JNIEnv* env, const base::android::JavaParamRef<jobject>& + jcaller); -static jint Java_org_chromium_TestJni_nativeInit(JNIEnv* env, jobject jcaller) { - return Init(env, JavaParamRef<jobject>(env, jcaller)); +JNI_GENERATOR_EXPORT jint Java_org_chromium_TestJni_nativeInit(JNIEnv* env, + jobject jcaller) { + return Init(env, base::android::JavaParamRef<jobject>(env, jcaller)); } -static void Java_org_chromium_TestJni_nativeDestroy(JNIEnv* env, +JNI_GENERATOR_EXPORT void Java_org_chromium_TestJni_nativeDestroy(JNIEnv* env, jobject jcaller, jint nativeChromeBrowserProvider) { ChromeBrowserProvider* native = reinterpret_cast<ChromeBrowserProvider*>(nativeChromeBrowserProvider); CHECK_NATIVE_PTR(env, jcaller, native, "Destroy"); - return native->Destroy(env, JavaParamRef<jobject>(env, jcaller)); + return native->Destroy(env, base::android::JavaParamRef<jobject>(env, + jcaller)); } -static jlong Java_org_chromium_TestJni_nativeAddBookmark(JNIEnv* env, - jobject jcaller, +JNI_GENERATOR_EXPORT jlong Java_org_chromium_TestJni_nativeAddBookmark(JNIEnv* + env, jobject jcaller, jint nativeChromeBrowserProvider, jstring url, jstring title, @@ -52,71 +55,79 @@ static jlong Java_org_chromium_TestJni_nativeAddBookmark(JNIEnv* env, ChromeBrowserProvider* native = reinterpret_cast<ChromeBrowserProvider*>(nativeChromeBrowserProvider); CHECK_NATIVE_PTR(env, jcaller, native, "AddBookmark", 0); - return native->AddBookmark(env, JavaParamRef<jobject>(env, jcaller), - JavaParamRef<jstring>(env, url), JavaParamRef<jstring>(env, title), - isFolder, parentId); + return native->AddBookmark(env, base::android::JavaParamRef<jobject>(env, + jcaller), base::android::JavaParamRef<jstring>(env, url), + base::android::JavaParamRef<jstring>(env, title), isFolder, parentId); } -static ScopedJavaLocalRef<jstring> GetDomainAndRegistry(JNIEnv* env, const - JavaParamRef<jclass>& jcaller, - const JavaParamRef<jstring>& url); +static base::android::ScopedJavaLocalRef<jstring> GetDomainAndRegistry(JNIEnv* + env, const base::android::JavaParamRef<jclass>& jcaller, + const base::android::JavaParamRef<jstring>& url); -static jstring Java_org_chromium_TestJni_nativeGetDomainAndRegistry(JNIEnv* env, - jclass jcaller, +JNI_GENERATOR_EXPORT jstring + Java_org_chromium_TestJni_nativeGetDomainAndRegistry(JNIEnv* env, jclass + jcaller, jstring url) { - return GetDomainAndRegistry(env, JavaParamRef<jclass>(env, jcaller), - JavaParamRef<jstring>(env, url)).Release(); + return GetDomainAndRegistry(env, base::android::JavaParamRef<jclass>(env, + jcaller), base::android::JavaParamRef<jstring>(env, url)).Release(); } static void CreateHistoricalTabFromState(JNIEnv* env, const - JavaParamRef<jclass>& jcaller, - const JavaParamRef<jbyteArray>& state, + base::android::JavaParamRef<jclass>& jcaller, + const base::android::JavaParamRef<jbyteArray>& state, jint tab_index); -static void Java_org_chromium_TestJni_nativeCreateHistoricalTabFromState(JNIEnv* - env, jclass jcaller, +JNI_GENERATOR_EXPORT void + Java_org_chromium_TestJni_nativeCreateHistoricalTabFromState(JNIEnv* env, + jclass jcaller, jbyteArray state, jint tab_index) { - return CreateHistoricalTabFromState(env, JavaParamRef<jclass>(env, jcaller), - JavaParamRef<jbyteArray>(env, state), tab_index); + return CreateHistoricalTabFromState(env, + base::android::JavaParamRef<jclass>(env, jcaller), + base::android::JavaParamRef<jbyteArray>(env, state), tab_index); } -static ScopedJavaLocalRef<jbyteArray> GetStateAsByteArray(JNIEnv* env, const - JavaParamRef<jobject>& jcaller, - const JavaParamRef<jobject>& view); +static base::android::ScopedJavaLocalRef<jbyteArray> GetStateAsByteArray(JNIEnv* + env, const base::android::JavaParamRef<jobject>& jcaller, + const base::android::JavaParamRef<jobject>& view); -static jbyteArray Java_org_chromium_TestJni_nativeGetStateAsByteArray(JNIEnv* - env, jobject jcaller, +JNI_GENERATOR_EXPORT jbyteArray + Java_org_chromium_TestJni_nativeGetStateAsByteArray(JNIEnv* env, jobject + jcaller, jobject view) { - return GetStateAsByteArray(env, JavaParamRef<jobject>(env, jcaller), - JavaParamRef<jobject>(env, view)).Release(); + return GetStateAsByteArray(env, base::android::JavaParamRef<jobject>(env, + jcaller), base::android::JavaParamRef<jobject>(env, view)).Release(); } -static ScopedJavaLocalRef<jobjectArray> GetAutofillProfileGUIDs(JNIEnv* env, - const JavaParamRef<jclass>& jcaller); +static base::android::ScopedJavaLocalRef<jobjectArray> + GetAutofillProfileGUIDs(JNIEnv* env, const + base::android::JavaParamRef<jclass>& jcaller); -static jobjectArray +JNI_GENERATOR_EXPORT jobjectArray Java_org_chromium_TestJni_nativeGetAutofillProfileGUIDs(JNIEnv* env, jclass jcaller) { - return GetAutofillProfileGUIDs(env, JavaParamRef<jclass>(env, + return GetAutofillProfileGUIDs(env, base::android::JavaParamRef<jclass>(env, jcaller)).Release(); } -static void SetRecognitionResults(JNIEnv* env, const JavaParamRef<jobject>& - jcaller, +static void SetRecognitionResults(JNIEnv* env, const + base::android::JavaParamRef<jobject>& jcaller, jint sessionId, - const JavaParamRef<jobjectArray>& results); + const base::android::JavaParamRef<jobjectArray>& results); -static void Java_org_chromium_TestJni_nativeSetRecognitionResults(JNIEnv* env, - jobject jcaller, +JNI_GENERATOR_EXPORT void + Java_org_chromium_TestJni_nativeSetRecognitionResults(JNIEnv* env, jobject + jcaller, jint sessionId, jobjectArray results) { - return SetRecognitionResults(env, JavaParamRef<jobject>(env, jcaller), - sessionId, JavaParamRef<jobjectArray>(env, results)); + return SetRecognitionResults(env, base::android::JavaParamRef<jobject>(env, + jcaller), sessionId, base::android::JavaParamRef<jobjectArray>(env, + results)); } -static jlong Java_org_chromium_TestJni_nativeAddBookmarkFromAPI(JNIEnv* env, - jobject jcaller, +JNI_GENERATOR_EXPORT jlong + Java_org_chromium_TestJni_nativeAddBookmarkFromAPI(JNIEnv* env, jobject + jcaller, jint nativeChromeBrowserProvider, jstring url, jobject created, @@ -128,33 +139,39 @@ static jlong Java_org_chromium_TestJni_nativeAddBookmarkFromAPI(JNIEnv* env, ChromeBrowserProvider* native = reinterpret_cast<ChromeBrowserProvider*>(nativeChromeBrowserProvider); CHECK_NATIVE_PTR(env, jcaller, native, "AddBookmarkFromAPI", 0); - return native->AddBookmarkFromAPI(env, JavaParamRef<jobject>(env, jcaller), - JavaParamRef<jstring>(env, url), JavaParamRef<jobject>(env, created), - JavaParamRef<jobject>(env, isBookmark), JavaParamRef<jobject>(env, date), - JavaParamRef<jbyteArray>(env, favicon), JavaParamRef<jstring>(env, title), - JavaParamRef<jobject>(env, visits)); + return native->AddBookmarkFromAPI(env, + base::android::JavaParamRef<jobject>(env, jcaller), + base::android::JavaParamRef<jstring>(env, url), + base::android::JavaParamRef<jobject>(env, created), + base::android::JavaParamRef<jobject>(env, isBookmark), + base::android::JavaParamRef<jobject>(env, date), + base::android::JavaParamRef<jbyteArray>(env, favicon), + base::android::JavaParamRef<jstring>(env, title), + base::android::JavaParamRef<jobject>(env, visits)); } -static jint FindAll(JNIEnv* env, const JavaParamRef<jobject>& jcaller, - const JavaParamRef<jstring>& find); - -static jint Java_org_chromium_TestJni_nativeFindAll(JNIEnv* env, jobject +static jint FindAll(JNIEnv* env, const base::android::JavaParamRef<jobject>& jcaller, + const base::android::JavaParamRef<jstring>& find); + +JNI_GENERATOR_EXPORT jint Java_org_chromium_TestJni_nativeFindAll(JNIEnv* env, + jobject jcaller, jstring find) { - return FindAll(env, JavaParamRef<jobject>(env, jcaller), - JavaParamRef<jstring>(env, find)); + return FindAll(env, base::android::JavaParamRef<jobject>(env, jcaller), + base::android::JavaParamRef<jstring>(env, find)); } -static ScopedJavaLocalRef<jobject> GetInnerClass(JNIEnv* env, const - JavaParamRef<jclass>& jcaller); +static base::android::ScopedJavaLocalRef<jobject> GetInnerClass(JNIEnv* env, + const base::android::JavaParamRef<jclass>& jcaller); -static jobject Java_org_chromium_TestJni_nativeGetInnerClass(JNIEnv* env, jclass - jcaller) { - return GetInnerClass(env, JavaParamRef<jclass>(env, jcaller)).Release(); +JNI_GENERATOR_EXPORT jobject + Java_org_chromium_TestJni_nativeGetInnerClass(JNIEnv* env, jclass jcaller) { + return GetInnerClass(env, base::android::JavaParamRef<jclass>(env, + jcaller)).Release(); } -static jobject Java_org_chromium_TestJni_nativeQueryBitmap(JNIEnv* env, - jobject jcaller, +JNI_GENERATOR_EXPORT jobject Java_org_chromium_TestJni_nativeQueryBitmap(JNIEnv* + env, jobject jcaller, jint nativeChromeBrowserProvider, jobjectArray projection, jstring selection, @@ -163,14 +180,15 @@ static jobject Java_org_chromium_TestJni_nativeQueryBitmap(JNIEnv* env, ChromeBrowserProvider* native = reinterpret_cast<ChromeBrowserProvider*>(nativeChromeBrowserProvider); CHECK_NATIVE_PTR(env, jcaller, native, "QueryBitmap", NULL); - return native->QueryBitmap(env, JavaParamRef<jobject>(env, jcaller), - JavaParamRef<jobjectArray>(env, projection), JavaParamRef<jstring>(env, - selection), JavaParamRef<jobjectArray>(env, selectionArgs), - JavaParamRef<jstring>(env, sortOrder)).Release(); + return native->QueryBitmap(env, base::android::JavaParamRef<jobject>(env, + jcaller), base::android::JavaParamRef<jobjectArray>(env, projection), + base::android::JavaParamRef<jstring>(env, selection), + base::android::JavaParamRef<jobjectArray>(env, selectionArgs), + base::android::JavaParamRef<jstring>(env, sortOrder)).Release(); } -static void Java_org_chromium_TestJni_nativeGotOrientation(JNIEnv* env, - jobject jcaller, +JNI_GENERATOR_EXPORT void Java_org_chromium_TestJni_nativeGotOrientation(JNIEnv* + env, jobject jcaller, jint nativeDataFetcherImplAndroid, jdouble alpha, jdouble beta, @@ -178,19 +196,21 @@ static void Java_org_chromium_TestJni_nativeGotOrientation(JNIEnv* env, DataFetcherImplAndroid* native = reinterpret_cast<DataFetcherImplAndroid*>(nativeDataFetcherImplAndroid); CHECK_NATIVE_PTR(env, jcaller, native, "GotOrientation"); - return native->GotOrientation(env, JavaParamRef<jobject>(env, jcaller), alpha, - beta, gamma); + return native->GotOrientation(env, base::android::JavaParamRef<jobject>(env, + jcaller), alpha, beta, gamma); } -static ScopedJavaLocalRef<jthrowable> MessWithJavaException(JNIEnv* env, const - JavaParamRef<jclass>& jcaller, - const JavaParamRef<jthrowable>& e); +static base::android::ScopedJavaLocalRef<jthrowable> + MessWithJavaException(JNIEnv* env, const + base::android::JavaParamRef<jclass>& jcaller, + const base::android::JavaParamRef<jthrowable>& e); -static jthrowable Java_org_chromium_TestJni_nativeMessWithJavaException(JNIEnv* - env, jclass jcaller, +JNI_GENERATOR_EXPORT jthrowable + Java_org_chromium_TestJni_nativeMessWithJavaException(JNIEnv* env, jclass + jcaller, jthrowable e) { - return MessWithJavaException(env, JavaParamRef<jclass>(env, jcaller), - JavaParamRef<jthrowable>(env, e)).Release(); + return MessWithJavaException(env, base::android::JavaParamRef<jclass>(env, + jcaller), base::android::JavaParamRef<jthrowable>(env, e)).Release(); } // Step 3: RegisterNatives. @@ -301,9 +321,8 @@ static const JNINativeMethod kMethodsTestJni[] = { }; static bool RegisterNativesImpl(JNIEnv* env) { - - g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( - base::android::GetClass(env, kTestJniClassPath).obj())); + if (jni_generator::ShouldSkipJniRegistration(false)) + return true; const int kMethodsTestJniSize = arraysize(kMethodsTestJni); diff --git a/base/android/jni_generator/testNativesLong.golden b/base/android/jni_generator/testNativesLong.golden index d5b67ba..ec029ce 100644 --- a/base/android/jni_generator/testNativesLong.golden +++ b/base/android/jni_generator/testNativesLong.golden @@ -20,19 +20,20 @@ namespace { const char kTestJniClassPath[] = "org/chromium/TestJni"; // Leaking this jclass as we cannot use LazyInstance from some threads. -jclass g_TestJni_clazz = NULL; -#define TestJni_clazz(env) g_TestJni_clazz +base::subtle::AtomicWord g_TestJni_clazz __attribute__((unused)) = 0; +#define TestJni_clazz(env) base::android::LazyGetClass(env, kTestJniClassPath, &g_TestJni_clazz) } // namespace // Step 2: method stubs. -static void Java_org_chromium_TestJni_nativeDestroy(JNIEnv* env, +JNI_GENERATOR_EXPORT void Java_org_chromium_TestJni_nativeDestroy(JNIEnv* env, jobject jcaller, jlong nativeChromeBrowserProvider) { ChromeBrowserProvider* native = reinterpret_cast<ChromeBrowserProvider*>(nativeChromeBrowserProvider); CHECK_NATIVE_PTR(env, jcaller, native, "Destroy"); - return native->Destroy(env, JavaParamRef<jobject>(env, jcaller)); + return native->Destroy(env, base::android::JavaParamRef<jobject>(env, + jcaller)); } // Step 3: RegisterNatives. @@ -46,9 +47,8 @@ static const JNINativeMethod kMethodsTestJni[] = { }; static bool RegisterNativesImpl(JNIEnv* env) { - - g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( - base::android::GetClass(env, kTestJniClassPath).obj())); + if (jni_generator::ShouldSkipJniRegistration(false)) + return true; const int kMethodsTestJniSize = arraysize(kMethodsTestJni); diff --git a/base/android/jni_generator/testSingleJNIAdditionalImport.golden b/base/android/jni_generator/testSingleJNIAdditionalImport.golden index 1b2895e..ef618da 100644 --- a/base/android/jni_generator/testSingleJNIAdditionalImport.golden +++ b/base/android/jni_generator/testSingleJNIAdditionalImport.golden @@ -20,26 +20,27 @@ namespace { const char kFooClassPath[] = "org/chromium/foo/Foo"; // Leaking this jclass as we cannot use LazyInstance from some threads. -jclass g_Foo_clazz = NULL; -#define Foo_clazz(env) g_Foo_clazz +base::subtle::AtomicWord g_Foo_clazz __attribute__((unused)) = 0; +#define Foo_clazz(env) base::android::LazyGetClass(env, kFooClassPath, &g_Foo_clazz) } // namespace // Step 2: method stubs. -static void DoSomething(JNIEnv* env, const JavaParamRef<jclass>& jcaller, - const JavaParamRef<jobject>& callback); - -static void Java_org_chromium_foo_Foo_nativeDoSomething(JNIEnv* env, jclass +static void DoSomething(JNIEnv* env, const base::android::JavaParamRef<jclass>& jcaller, + const base::android::JavaParamRef<jobject>& callback); + +JNI_GENERATOR_EXPORT void Java_org_chromium_foo_Foo_nativeDoSomething(JNIEnv* + env, jclass jcaller, jobject callback) { - return DoSomething(env, JavaParamRef<jclass>(env, jcaller), - JavaParamRef<jobject>(env, callback)); + return DoSomething(env, base::android::JavaParamRef<jclass>(env, jcaller), + base::android::JavaParamRef<jobject>(env, callback)); } static base::subtle::AtomicWord g_Foo_calledByNative = 0; -static void Java_Foo_calledByNative(JNIEnv* env, jobject callback) { - /* Must call RegisterNativesImpl() */ +static void Java_Foo_calledByNative(JNIEnv* env, const + base::android::JavaRefOrBare<jobject>& callback) { CHECK_CLAZZ(env, Foo_clazz(env), Foo_clazz(env)); jmethodID method_id = @@ -47,7 +48,6 @@ static void Java_Foo_calledByNative(JNIEnv* env, jobject callback) { base::android::MethodID::TYPE_STATIC>( env, Foo_clazz(env), "calledByNative", - "(" "Lorg/chromium/foo/Bar$Callback;" ")" @@ -55,9 +55,8 @@ static void Java_Foo_calledByNative(JNIEnv* env, jobject callback) { &g_Foo_calledByNative); env->CallStaticVoidMethod(Foo_clazz(env), - method_id, callback); + method_id, callback.obj()); jni_generator::CheckException(env); - } // Step 3: RegisterNatives. @@ -71,9 +70,8 @@ static const JNINativeMethod kMethodsFoo[] = { }; static bool RegisterNativesImpl(JNIEnv* env) { - - g_Foo_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( - base::android::GetClass(env, kFooClassPath).obj())); + if (jni_generator::ShouldSkipJniRegistration(false)) + return true; const int kMethodsFooSize = arraysize(kMethodsFoo); diff --git a/base/android/jni_utils.cc b/base/android/jni_utils.cc index b4d682b..848dfd7 100644 --- a/base/android/jni_utils.cc +++ b/base/android/jni_utils.cc @@ -4,7 +4,6 @@ #include "base/android/jni_utils.h" -#include "base/android/jni_android.h" #include "base/android/scoped_java_ref.h" #include "jni/JNIUtils_jni.h" @@ -16,8 +15,8 @@ ScopedJavaLocalRef<jobject> GetClassLoader(JNIEnv* env) { return Java_JNIUtils_getClassLoader(env); } -bool RegisterJNIUtils(JNIEnv* env) { - return RegisterNativesImpl(env); +bool isSelectiveJniRegistrationEnabled(JNIEnv* env) { + return Java_JNIUtils_isSelectiveJniRegistrationEnabled(env); } } // namespace android diff --git a/base/android/jni_utils.h b/base/android/jni_utils.h index b793aed..ef645c2 100644 --- a/base/android/jni_utils.h +++ b/base/android/jni_utils.h @@ -18,7 +18,8 @@ namespace android { // via JNI from Java. BASE_EXPORT ScopedJavaLocalRef<jobject> GetClassLoader(JNIEnv* env); -bool RegisterJNIUtils(JNIEnv* env); +// Returns true if the current process permits selective JNI registration. +BASE_EXPORT bool isSelectiveJniRegistrationEnabled(JNIEnv* env); } // namespace android } // namespace base diff --git a/base/android/jni_weak_ref.cc b/base/android/jni_weak_ref.cc index 55244f2..fe7ea2e 100644 --- a/base/android/jni_weak_ref.cc +++ b/base/android/jni_weak_ref.cc @@ -4,24 +4,34 @@ #include "base/android/jni_weak_ref.h" +#include <utility> + #include "base/android/jni_android.h" #include "base/logging.h" using base::android::AttachCurrentThread; -JavaObjectWeakGlobalRef::JavaObjectWeakGlobalRef() - : obj_(NULL) { -} +JavaObjectWeakGlobalRef::JavaObjectWeakGlobalRef() : obj_(nullptr) {} JavaObjectWeakGlobalRef::JavaObjectWeakGlobalRef( const JavaObjectWeakGlobalRef& orig) - : obj_(NULL) { + : obj_(nullptr) { Assign(orig); } +JavaObjectWeakGlobalRef::JavaObjectWeakGlobalRef(JavaObjectWeakGlobalRef&& orig) + : obj_(orig.obj_) { + orig.obj_ = nullptr; +} + JavaObjectWeakGlobalRef::JavaObjectWeakGlobalRef(JNIEnv* env, jobject obj) : obj_(env->NewWeakGlobalRef(obj)) { - DCHECK(obj_); +} + +JavaObjectWeakGlobalRef::JavaObjectWeakGlobalRef( + JNIEnv* env, + const base::android::JavaRef<jobject>& obj) + : obj_(env->NewWeakGlobalRef(obj.obj())) { } JavaObjectWeakGlobalRef::~JavaObjectWeakGlobalRef() { @@ -32,10 +42,14 @@ void JavaObjectWeakGlobalRef::operator=(const JavaObjectWeakGlobalRef& rhs) { Assign(rhs); } +void JavaObjectWeakGlobalRef::operator=(JavaObjectWeakGlobalRef&& rhs) { + std::swap(obj_, rhs.obj_); +} + void JavaObjectWeakGlobalRef::reset() { if (obj_) { AttachCurrentThread()->DeleteWeakGlobalRef(obj_); - obj_ = NULL; + obj_ = nullptr; } } @@ -46,7 +60,7 @@ base::android::ScopedJavaLocalRef<jobject> base::android::ScopedJavaLocalRef<jobject> GetRealObject( JNIEnv* env, jweak obj) { - jobject real = NULL; + jobject real = nullptr; if (obj) real = env->NewLocalRef(obj); return base::android::ScopedJavaLocalRef<jobject>(env, real); @@ -60,5 +74,5 @@ void JavaObjectWeakGlobalRef::Assign(const JavaObjectWeakGlobalRef& other) { if (obj_) env->DeleteWeakGlobalRef(obj_); - obj_ = other.obj_ ? env->NewWeakGlobalRef(other.obj_) : NULL; + obj_ = other.obj_ ? env->NewWeakGlobalRef(other.obj_) : nullptr; } diff --git a/base/android/jni_weak_ref.h b/base/android/jni_weak_ref.h index c851046..223c47b 100644 --- a/base/android/jni_weak_ref.h +++ b/base/android/jni_weak_ref.h @@ -18,14 +18,22 @@ class BASE_EXPORT JavaObjectWeakGlobalRef { public: JavaObjectWeakGlobalRef(); JavaObjectWeakGlobalRef(const JavaObjectWeakGlobalRef& orig); + JavaObjectWeakGlobalRef(JavaObjectWeakGlobalRef&& orig); JavaObjectWeakGlobalRef(JNIEnv* env, jobject obj); + JavaObjectWeakGlobalRef(JNIEnv* env, + const base::android::JavaRef<jobject>& obj); virtual ~JavaObjectWeakGlobalRef(); void operator=(const JavaObjectWeakGlobalRef& rhs); + void operator=(JavaObjectWeakGlobalRef&& rhs); base::android::ScopedJavaLocalRef<jobject> get(JNIEnv* env) const; - bool is_empty() const { return obj_ == NULL; } + // Returns true if the weak reference has not been initialized to point at + // an object (or ḣas had reset() called). + // Do not call this to test if the object referred to still exists! The weak + // reference remains initialized even if the target object has been collected. + bool is_uninitialized() const { return obj_ == nullptr; } void reset(); diff --git a/base/android/junit/src/org/chromium/base/BaseChromiumApplicationTest.java b/base/android/junit/src/org/chromium/base/BaseChromiumApplicationTest.java index bfcd7aa..269f84b 100644 --- a/base/android/junit/src/org/chromium/base/BaseChromiumApplicationTest.java +++ b/base/android/junit/src/org/chromium/base/BaseChromiumApplicationTest.java @@ -10,18 +10,19 @@ import static org.mockito.Mockito.verify; import android.app.Activity; import android.view.KeyEvent; -import junit.framework.Assert; - import org.chromium.base.BaseChromiumApplication.WindowFocusChangedListener; -import org.chromium.base.test.shadows.ShadowMultiDex; import org.chromium.testing.local.LocalRobolectricTestRunner; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.Shadows; import org.robolectric.annotation.Config; import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; import org.robolectric.shadows.ShadowActivity; +import org.robolectric.shadows.multidex.ShadowMultiDex; import org.robolectric.util.ActivityController; /** Unit tests for {@link BaseChromiumApplication}. */ @@ -52,7 +53,7 @@ public class BaseChromiumApplicationTest { @Test public void testWindowsFocusChanged() throws Exception { - BaseChromiumApplication app = (BaseChromiumApplication) Robolectric.application; + BaseChromiumApplication app = (BaseChromiumApplication) RuntimeEnvironment.application; WindowFocusChangedListener mock = mock(WindowFocusChangedListener.class); app.registerWindowFocusChangedListener(mock); @@ -60,7 +61,7 @@ public class BaseChromiumApplicationTest { ActivityController<Activity> controller = Robolectric.buildActivity(Activity.class).create().start().visible(); TrackingShadowActivity shadow = - (TrackingShadowActivity) Robolectric.shadowOf(controller.get()); + (TrackingShadowActivity) Shadows.shadowOf(controller.get()); controller.get().getWindow().getCallback().onWindowFocusChanged(true); // Assert that listeners were notified. diff --git a/base/android/library_loader/library_loader_hooks.cc b/base/android/library_loader/library_loader_hooks.cc index 025075e..621575c 100644 --- a/base/android/library_loader/library_loader_hooks.cc +++ b/base/android/library_loader/library_loader_hooks.cc @@ -10,7 +10,7 @@ #include "base/android/library_loader/library_prefetcher.h" #include "base/at_exit.h" #include "base/metrics/histogram.h" -#include "base/metrics/sparse_histogram.h" +#include "base/metrics/histogram_macros.h" #include "jni/LibraryLoader_jni.h" namespace base { @@ -21,6 +21,7 @@ namespace { base::AtExitManager* g_at_exit_manager = NULL; const char* g_library_version_number = ""; LibraryLoadedHook* g_registration_callback = NULL; +NativeInitializationHook* g_native_initialization_hook = NULL; enum RendererHistogramCode { // Renderer load at fixed address success, fail, or not attempted. @@ -149,6 +150,11 @@ static void RegisterLibraryPreloaderRendererHistogram( g_library_preloader_renderer_histogram_code_registered = true; } +void SetNativeInitializationHook( + NativeInitializationHook native_initialization_hook) { + g_native_initialization_hook = native_initialization_hook; +} + void RecordLibraryLoaderRendererHistograms() { RecordChromiumAndroidLinkerRendererHistogram(); RecordLibraryPreloaderRendereHistogram(); @@ -167,6 +173,9 @@ static void InitCommandLine( static jboolean LibraryLoaded(JNIEnv* env, const JavaParamRef<jobject>& jcaller) { + if (g_native_initialization_hook && !g_native_initialization_hook()) { + return false; + } if (g_registration_callback == NULL) { return true; } diff --git a/base/android/library_loader/library_loader_hooks.h b/base/android/library_loader/library_loader_hooks.h index 3e8969b..5c37e6e 100644 --- a/base/android/library_loader/library_loader_hooks.h +++ b/base/android/library_loader/library_loader_hooks.h @@ -8,6 +8,7 @@ #include <jni.h> #include "base/base_export.h" +#include "base/callback.h" namespace base { namespace android { @@ -27,6 +28,11 @@ enum LibraryProcessType { PROCESS_WEBVIEW_CHILD = 4, }; +typedef bool NativeInitializationHook(); + +BASE_EXPORT void SetNativeInitializationHook( + NativeInitializationHook native_initialization_hook); + // Record any pending renderer histogram value as histograms. Pending values // are set by RegisterChromiumAndroidLinkerRendererHistogram and // RegisterLibraryPreloaderRendererHistogram. diff --git a/base/android/library_loader/library_prefetcher.cc b/base/android/library_loader/library_prefetcher.cc index c7ec990..a946c82 100644 --- a/base/android/library_loader/library_prefetcher.cc +++ b/base/android/library_loader/library_prefetcher.cc @@ -16,6 +16,7 @@ #include "base/macros.h" #include "base/posix/eintr_wrapper.h" #include "base/strings/string_util.h" +#include "build/build_config.h" namespace base { namespace android { @@ -50,6 +51,13 @@ bool PathMatchesSuffix(const std::string& path) { // Heap allocations, syscalls and library functions are not allowed in this // function. // Returns true for success. +#if defined(ADDRESS_SANITIZER) +// Disable AddressSanitizer instrumentation for this function. It is touching +// memory that hasn't been allocated by the app, though the addresses are +// valid. Furthermore, this takes place in a child process. See crbug.com/653372 +// for the context. +__attribute__((no_sanitize_address)) +#endif bool Prefetch(const std::vector<std::pair<uintptr_t, uintptr_t>>& ranges) { for (const auto& range : ranges) { const uintptr_t page_mask = kPageSize - 1; diff --git a/base/android/linker/BUILD.gn b/base/android/linker/BUILD.gn index 3724b88..c2bfb11 100644 --- a/base/android/linker/BUILD.gn +++ b/base/android/linker/BUILD.gn @@ -6,7 +6,6 @@ import("//build/config/android/config.gni") assert(is_android) -# GYP: //base/base.gyp:chromium_android_linker shared_library("chromium_android_linker") { sources = [ "android_dlext.h", diff --git a/base/android/linker/config.gni b/base/android/linker/config.gni index 174c1ab..27793ff 100644 --- a/base/android/linker/config.gni +++ b/base/android/linker/config.gni @@ -6,7 +6,8 @@ import("//build/config/android/config.gni") import("//build/config/compiler/compiler.gni") import("//build/config/sanitizers/sanitizers.gni") -# Chromium linker crashes on component builds on Android 4.4. See b/11379966 +# Chromium linker doesn't reliably support loading multiple libraries; +# disable for component builds, see crbug.com/657093. # Chromium linker causes instrumentation to return incorrect results. chromium_linker_supported = !is_component_build && !enable_profiling && !use_order_profiling && !is_asan diff --git a/base/android/locale_utils.cc b/base/android/locale_utils.cc index af46f89..b3a2346 100644 --- a/base/android/locale_utils.cc +++ b/base/android/locale_utils.cc @@ -16,16 +16,12 @@ std::string GetDefaultCountryCode() { return ConvertJavaStringToUTF8(Java_LocaleUtils_getDefaultCountryCode(env)); } -std::string GetDefaultLocale() { +std::string GetDefaultLocaleString() { JNIEnv* env = base::android::AttachCurrentThread(); - ScopedJavaLocalRef<jstring> locale = Java_LocaleUtils_getDefaultLocale( - env); + ScopedJavaLocalRef<jstring> locale = + Java_LocaleUtils_getDefaultLocaleString(env); return ConvertJavaStringToUTF8(locale); } -bool RegisterLocaleUtils(JNIEnv* env) { - return RegisterNativesImpl(env); -} - } // namespace android } // namespace base diff --git a/base/android/locale_utils.h b/base/android/locale_utils.h index 9e03b83..be68890 100644 --- a/base/android/locale_utils.h +++ b/base/android/locale_utils.h @@ -16,10 +16,8 @@ namespace android { BASE_EXPORT std::string GetDefaultCountryCode(); -// Return the current default locale of the device. -BASE_EXPORT std::string GetDefaultLocale(); - -BASE_EXPORT bool RegisterLocaleUtils(JNIEnv* env); +// Return the current default locale of the device as string. +BASE_EXPORT std::string GetDefaultLocaleString(); } // namespace android } // namespace base diff --git a/base/android/memory_pressure_listener_android.cc b/base/android/memory_pressure_listener_android.cc index 5975b94..32e0871 100644 --- a/base/android/memory_pressure_listener_android.cc +++ b/base/android/memory_pressure_listener_android.cc @@ -8,6 +8,8 @@ #include "base/memory/memory_pressure_listener.h" #include "jni/MemoryPressureListener_jni.h" +using base::android::JavaParamRef; + // Defined and called by JNI. static void OnMemoryPressure(JNIEnv* env, const JavaParamRef<jclass>& clazz, diff --git a/base/android/path_utils.cc b/base/android/path_utils.cc index b765449..89ab833 100644 --- a/base/android/path_utils.cc +++ b/base/android/path_utils.cc @@ -17,8 +17,7 @@ namespace android { bool GetDataDirectory(FilePath* result) { JNIEnv* env = AttachCurrentThread(); - ScopedJavaLocalRef<jstring> path = - Java_PathUtils_getDataDirectory(env, GetApplicationContext()); + ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDataDirectory(env); FilePath data_path(ConvertJavaStringToUTF8(path)); *result = data_path; return true; @@ -26,8 +25,7 @@ bool GetDataDirectory(FilePath* result) { bool GetDatabaseDirectory(FilePath* result) { JNIEnv* env = AttachCurrentThread(); - ScopedJavaLocalRef<jstring> path = - Java_PathUtils_getDatabaseDirectory(env, GetApplicationContext()); + ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDatabaseDirectory(env); FilePath data_path(ConvertJavaStringToUTF8(path)); *result = data_path; return true; @@ -35,8 +33,7 @@ bool GetDatabaseDirectory(FilePath* result) { bool GetCacheDirectory(FilePath* result) { JNIEnv* env = AttachCurrentThread(); - ScopedJavaLocalRef<jstring> path = - Java_PathUtils_getCacheDirectory(env, GetApplicationContext()); + ScopedJavaLocalRef<jstring> path = Java_PathUtils_getCacheDirectory(env); FilePath cache_path(ConvertJavaStringToUTF8(path)); *result = cache_path; return true; @@ -45,7 +42,7 @@ bool GetCacheDirectory(FilePath* result) { bool GetThumbnailCacheDirectory(FilePath* result) { JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef<jstring> path = - Java_PathUtils_getThumbnailCacheDirectory(env, GetApplicationContext()); + Java_PathUtils_getThumbnailCacheDirectory(env); FilePath thumbnail_cache_path(ConvertJavaStringToUTF8(path)); *result = thumbnail_cache_path; return true; @@ -53,8 +50,7 @@ bool GetThumbnailCacheDirectory(FilePath* result) { bool GetDownloadsDirectory(FilePath* result) { JNIEnv* env = AttachCurrentThread(); - ScopedJavaLocalRef<jstring> path = - Java_PathUtils_getDownloadsDirectory(env, GetApplicationContext()); + ScopedJavaLocalRef<jstring> path = Java_PathUtils_getDownloadsDirectory(env); FilePath downloads_path(ConvertJavaStringToUTF8(path)); *result = downloads_path; return true; @@ -63,7 +59,7 @@ bool GetDownloadsDirectory(FilePath* result) { bool GetNativeLibraryDirectory(FilePath* result) { JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef<jstring> path = - Java_PathUtils_getNativeLibraryDirectory(env, GetApplicationContext()); + Java_PathUtils_getNativeLibraryDirectory(env); FilePath library_path(ConvertJavaStringToUTF8(path)); *result = library_path; return true; @@ -78,9 +74,5 @@ bool GetExternalStorageDirectory(FilePath* result) { return true; } -bool RegisterPathUtils(JNIEnv* env) { - return RegisterNativesImpl(env); -} - } // namespace android } // namespace base diff --git a/base/android/path_utils.h b/base/android/path_utils.h index 6501f1b..7402644 100644 --- a/base/android/path_utils.h +++ b/base/android/path_utils.h @@ -48,8 +48,6 @@ BASE_EXPORT bool GetNativeLibraryDirectory(FilePath* result); // is placed in the FilePath pointed to by 'result'. BASE_EXPORT bool GetExternalStorageDirectory(FilePath* result); -bool RegisterPathUtils(JNIEnv* env); - } // namespace android } // namespace base diff --git a/base/android/record_histogram.cc b/base/android/record_histogram.cc index 3c51fe2..1a207a1 100644 --- a/base/android/record_histogram.cc +++ b/base/android/record_histogram.cc @@ -53,12 +53,16 @@ class HistogramCache { jstring j_histogram_name, int32_t expected_min, int32_t expected_max, - int32_t expected_bucket_count, + uint32_t expected_bucket_count, HistogramBase* histogram) { + std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name); + bool valid_arguments = Histogram::InspectConstructionArguments( + histogram_name, &expected_min, &expected_max, &expected_bucket_count); + DCHECK(valid_arguments); DCHECK(histogram->HasConstructionArguments(expected_min, expected_max, expected_bucket_count)) - << ConvertJavaStringToUTF8(env, j_histogram_name) << "/" << expected_min - << "/" << expected_max << "/" << expected_bucket_count << " vs. " + << histogram_name << "/" << expected_min << "/" << expected_max << "/" + << expected_bucket_count << " vs. " << HistogramConstructionParamsToString(histogram); } @@ -113,6 +117,8 @@ class HistogramCache { return histogram; } + DCHECK_GE(min, 1) << "The min expected sample must be >= 1"; + std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name); histogram = Histogram::FactoryGet(histogram_name, min, max, num_buckets, diff --git a/base/android/scoped_java_ref.cc b/base/android/scoped_java_ref.cc index 4d4ef6d..2876ba4 100644 --- a/base/android/scoped_java_ref.cc +++ b/base/android/scoped_java_ref.cc @@ -26,7 +26,9 @@ ScopedJavaLocalFrame::ScopedJavaLocalFrame(JNIEnv* env, int capacity) DCHECK(!failed); } -ScopedJavaLocalFrame::~ScopedJavaLocalFrame() { env_->PopLocalFrame(NULL); } +ScopedJavaLocalFrame::~ScopedJavaLocalFrame() { + env_->PopLocalFrame(nullptr); +} #if DCHECK_IS_ON() // This constructor is inlined when DCHECKs are disabled; don't add anything @@ -69,14 +71,14 @@ void JavaRef<jobject>::ResetLocalRef(JNIEnv* env) { if (obj_) { DCHECK_EQ(env, AttachCurrentThread()); // Is |env| on correct thread. env->DeleteLocalRef(obj_); - obj_ = NULL; + obj_ = nullptr; } } void JavaRef<jobject>::ResetGlobalRef() { if (obj_) { AttachCurrentThread()->DeleteGlobalRef(obj_); - obj_ = NULL; + obj_ = nullptr; } } diff --git a/base/android/scoped_java_ref.h b/base/android/scoped_java_ref.h index a1b4b13..6d728e9 100644 --- a/base/android/scoped_java_ref.h +++ b/base/android/scoped_java_ref.h @@ -9,6 +9,7 @@ #include <stddef.h> #include <type_traits> +#include <utility> #include "base/base_export.h" #include "base/logging.h" @@ -43,23 +44,23 @@ template<typename T> class JavaRef; template<> class BASE_EXPORT JavaRef<jobject> { public: + // Initializes a null reference. Don't add anything else here; it's inlined. + JavaRef() : obj_(nullptr) {} + // Allow nullptr to be converted to JavaRef. This avoids having to declare an - // empty ScopedJavaLocalRef just to pass null to a function with a JavaRef - // parameter, and makes C++ "nullptr" and Java "null" equivalent. + // empty JavaRef just to pass null to a function, and makes C++ "nullptr" and + // Java "null" equivalent. JavaRef(std::nullptr_t) : JavaRef() {} - // Public to allow destruction of temporary JavaRef objects created by the - // nullptr conversion. Don't add anything else here; it's inlined. + // Public to allow destruction of null JavaRef objects. + // Don't add anything else here; it's inlined. ~JavaRef() {} jobject obj() const { return obj_; } - bool is_null() const { return obj_ == NULL; } + bool is_null() const { return obj_ == nullptr; } protected: - // Initializes a NULL reference. Don't add anything else here; it's inlined. - JavaRef() : obj_(NULL) {} - // Takes ownership of the |obj| reference passed; requires it to be a local // reference type. #if DCHECK_IS_ON() @@ -70,6 +71,8 @@ class BASE_EXPORT JavaRef<jobject> { JavaRef(JNIEnv* env, jobject obj) : obj_(obj) {} #endif + void swap(JavaRef& other) { std::swap(obj_, other.obj_); } + // The following are implementation detail convenience methods, for // use by the sub-classes. JNIEnv* SetNewLocalRef(JNIEnv* env, jobject obj); @@ -90,14 +93,13 @@ class BASE_EXPORT JavaRef<jobject> { template<typename T> class JavaRef : public JavaRef<jobject> { public: + JavaRef() {} JavaRef(std::nullptr_t) : JavaRef<jobject>(nullptr) {} ~JavaRef() {} T obj() const { return static_cast<T>(JavaRef<jobject>::obj()); } protected: - JavaRef() {} - JavaRef(JNIEnv* env, T obj) : JavaRef<jobject>(env, obj) {} private: @@ -144,7 +146,8 @@ class JavaParamRef : public JavaRef<T> { template<typename T> class ScopedJavaLocalRef : public JavaRef<T> { public: - ScopedJavaLocalRef() : env_(NULL) {} + ScopedJavaLocalRef() : env_(nullptr) {} + ScopedJavaLocalRef(std::nullptr_t) : env_(nullptr) {} // Non-explicit copy constructor, to allow ScopedJavaLocalRef to be returned // by value as this is the normal usage pattern. @@ -153,14 +156,18 @@ class ScopedJavaLocalRef : public JavaRef<T> { this->SetNewLocalRef(env_, other.obj()); } - template<typename U> - explicit ScopedJavaLocalRef(const U& other) - : env_(NULL) { + ScopedJavaLocalRef(ScopedJavaLocalRef<T>&& other) : env_(other.env_) { + this->swap(other); + } + + explicit ScopedJavaLocalRef(const JavaRef<T>& other) : env_(nullptr) { this->Reset(other); } // Assumes that |obj| is a local reference to a Java object and takes // ownership of this local reference. + // TODO(torne): this shouldn't be used outside of JNI helper functions but + // there are currently some cases where there aren't helpers for things. ScopedJavaLocalRef(JNIEnv* env, T obj) : JavaRef<T>(env, obj), env_(env) {} ~ScopedJavaLocalRef() { @@ -173,31 +180,32 @@ class ScopedJavaLocalRef : public JavaRef<T> { this->Reset(other); } + void operator=(ScopedJavaLocalRef<T>&& other) { + env_ = other.env_; + this->swap(other); + } + void Reset() { this->ResetLocalRef(env_); } - template<typename U> - void Reset(const ScopedJavaLocalRef<U>& other) { + void Reset(const ScopedJavaLocalRef<T>& other) { // We can copy over env_ here as |other| instance must be from the same // thread as |this| local ref. (See class comment for multi-threading // limitations, and alternatives). this->Reset(other.env_, other.obj()); } - template<typename U> - void Reset(const U& other) { - // If |env_| was not yet set (is still NULL) it will be attached to the + void Reset(const JavaRef<T>& other) { + // If |env_| was not yet set (is still null) it will be attached to the // current thread in SetNewLocalRef(). this->Reset(env_, other.obj()); } - template<typename U> - void Reset(JNIEnv* env, U obj) { - static_assert(std::is_convertible<U, T>::value, - "U must be convertible to T"); - env_ = this->SetNewLocalRef(env, obj); - } + // Creates a new local reference to the Java object, unlike the constructor + // with the same parameters that takes ownership of the existing reference. + // TODO(torne): these should match as this is confusing. + void Reset(JNIEnv* env, T obj) { env_ = this->SetNewLocalRef(env, obj); } // Releases the local reference to the caller. The caller *must* delete the // local reference when it is done with it. Note that calling a Java method @@ -227,17 +235,17 @@ template<typename T> class ScopedJavaGlobalRef : public JavaRef<T> { public: ScopedJavaGlobalRef() {} + ScopedJavaGlobalRef(std::nullptr_t) {} ScopedJavaGlobalRef(const ScopedJavaGlobalRef<T>& other) { this->Reset(other); } + ScopedJavaGlobalRef(ScopedJavaGlobalRef<T>&& other) { this->swap(other); } + ScopedJavaGlobalRef(JNIEnv* env, T obj) { this->Reset(env, obj); } - template<typename U> - explicit ScopedJavaGlobalRef(const U& other) { - this->Reset(other); - } + explicit ScopedJavaGlobalRef(const JavaRef<T>& other) { this->Reset(other); } ~ScopedJavaGlobalRef() { this->Reset(); @@ -249,26 +257,19 @@ class ScopedJavaGlobalRef : public JavaRef<T> { this->Reset(other); } + void operator=(ScopedJavaGlobalRef<T>&& other) { this->swap(other); } + void Reset() { this->ResetGlobalRef(); } - template<typename U> - void Reset(const U& other) { - this->Reset(NULL, other.obj()); - } + void Reset(const JavaRef<T>& other) { this->Reset(nullptr, other.obj()); } - template<typename U> - void Reset(JNIEnv* env, const JavaParamRef<U>& other) { + void Reset(JNIEnv* env, const JavaParamRef<T>& other) { this->Reset(env, other.obj()); } - template<typename U> - void Reset(JNIEnv* env, U obj) { - static_assert(std::is_convertible<U, T>::value, - "U must be convertible to T"); - this->SetNewGlobalRef(env, obj); - } + void Reset(JNIEnv* env, T obj) { this->SetNewGlobalRef(env, obj); } // Releases the global reference to the caller. The caller *must* delete the // global reference when it is done with it. Note that calling a Java method @@ -278,6 +279,22 @@ class ScopedJavaGlobalRef : public JavaRef<T> { } }; +// Temporary type for parameters to Java functions, to allow incremental +// migration from bare jobject to JavaRef. Don't use outside JNI generator. +template <typename T> +class JavaRefOrBare { + public: + JavaRefOrBare(std::nullptr_t) : obj_(nullptr) {} + JavaRefOrBare(const JavaRef<T>& ref) : obj_(ref.obj()) {} + JavaRefOrBare(T obj) : obj_(obj) {} + T obj() const { return obj_; } + + private: + T obj_; + + DISALLOW_COPY_AND_ASSIGN(JavaRefOrBare); +}; + } // namespace android } // namespace base diff --git a/base/android/scoped_java_ref_unittest.cc b/base/android/scoped_java_ref_unittest.cc index 3f4419a..99d035b 100644 --- a/base/android/scoped_java_ref_unittest.cc +++ b/base/android/scoped_java_ref_unittest.cc @@ -106,6 +106,17 @@ TEST_F(ScopedJavaRefTest, RefCounts) { EXPECT_EQ(2, g_local_refs); } EXPECT_EQ(1, g_local_refs); + { + ScopedJavaLocalRef<jstring> str4((ScopedJavaLocalRef<jstring>(str2))); + EXPECT_EQ(2, g_local_refs); + } + EXPECT_EQ(1, g_local_refs); + { + ScopedJavaLocalRef<jstring> str5; + str5 = ScopedJavaLocalRef<jstring>(str2); + EXPECT_EQ(2, g_local_refs); + } + EXPECT_EQ(1, g_local_refs); str2.Reset(); EXPECT_EQ(0, g_local_refs); global_str.Reset(); diff --git a/base/android/sys_utils.cc b/base/android/sys_utils.cc index e89c1b3..a576644 100644 --- a/base/android/sys_utils.cc +++ b/base/android/sys_utils.cc @@ -11,10 +11,6 @@ namespace base { namespace android { -bool SysUtils::Register(JNIEnv* env) { - return RegisterNativesImpl(env); -} - bool SysUtils::IsLowEndDeviceFromJni() { JNIEnv* env = AttachCurrentThread(); return Java_SysUtils_isLowEndDevice(env); @@ -22,4 +18,4 @@ bool SysUtils::IsLowEndDeviceFromJni() { } // namespace android -} // namespace base
\ No newline at end of file +} // namespace base diff --git a/base/android/sys_utils.h b/base/android/sys_utils.h index 85dc035..2edbdd5 100644 --- a/base/android/sys_utils.h +++ b/base/android/sys_utils.h @@ -12,8 +12,6 @@ namespace android { class BASE_EXPORT SysUtils { public: - static bool Register(JNIEnv* env); - // Returns true iff this is a low-end device. static bool IsLowEndDeviceFromJni(); }; diff --git a/base/android/thread_utils.h b/base/android/thread_utils.h deleted file mode 100644 index cbe65f0..0000000 --- a/base/android/thread_utils.h +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -#ifndef BASE_ANDROID_THREAD_UTILS_H_ -#define BASE_ANDROID_THREAD_UTILS_H_ - -#include "base/android/jni_android.h" - -namespace base { - -bool RegisterThreadUtils(JNIEnv* env); - -} // namespace base - -#endif // BASE_ANDROID_THREAD_UTILS_H_ |