diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-12-09 04:17:20 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-12-09 04:17:20 +0000 |
commit | 6e206426bcc8c683a61eec2bf8101bf90e4e4c7e (patch) | |
tree | aefa4fcdc1ae237b62c45fdc6ce15d3041fdacd7 | |
parent | bc44ce99703dd3062c6440aced7c12dbbab3fc19 (diff) | |
parent | b0e720abb12e558ff7e6537366a9c0c80288695b (diff) | |
download | modules-utils-6e206426bcc8c683a61eec2bf8101bf90e4e4c7e.tar.gz |
Snap for 11200327 from b0e720abb12e558ff7e6537366a9c0c80288695b to 24Q1-release
Change-Id: Ib95c44e3bced1c5add723c5cf997f80f090735dd
14 files changed, 24 insertions, 375 deletions
diff --git a/java/com/android/modules/expresslog/Android.bp b/java/com/android/modules/expresslog/Android.bp index cacc7f8..59504bd 100644 --- a/java/com/android/modules/expresslog/Android.bp +++ b/java/com/android/modules/expresslog/Android.bp @@ -28,12 +28,16 @@ java_library { libs: [ "framework-statsd", ], + static_libs: [ + "expresslog-catalog", + ], } genrule { name: "statslog-expresslog-java-gen", tools: ["stats-log-api-gen"], cmd: "$(location stats-log-api-gen) --java $(out) --module expresslog" + - " --javaPackage com.android.modules.expresslog --javaClass StatsExpressLog", + " --javaPackage com.android.modules.expresslog" + + " --javaClass StatsExpressLog", out: ["com/android/modules/expresslog/StatsExpressLog.java"], } diff --git a/java/com/android/modules/expresslog/Counter.java b/java/com/android/modules/expresslog/Counter.java index b788c3f..bcacb8b 100644 --- a/java/com/android/modules/expresslog/Counter.java +++ b/java/com/android/modules/expresslog/Counter.java @@ -18,8 +18,6 @@ package com.android.modules.expresslog; import android.annotation.NonNull; -import com.android.modules.expresslog.StatsExpressLog; - /** Counter encapsulates StatsD write API calls */ public final class Counter { @@ -49,7 +47,8 @@ public final class Counter { * @param amount to increment counter */ public static void logIncrement(@NonNull String metricId, long amount) { - final long metricIdHash = Utils.hashString(metricId); + final long metricIdHash = + MetricIds.getMetricIdHash(metricId, MetricIds.METRIC_TYPE_COUNTER); StatsExpressLog.write(StatsExpressLog.EXPRESS_EVENT_REPORTED, metricIdHash, amount); } @@ -60,7 +59,8 @@ public final class Counter { * @param amount to increment counter */ public static void logIncrementWithUid(@NonNull String metricId, int uid, long amount) { - final long metricIdHash = Utils.hashString(metricId); + final long metricIdHash = + MetricIds.getMetricIdHash(metricId, MetricIds.METRIC_TYPE_COUNTER_WITH_UID); StatsExpressLog.write( StatsExpressLog.EXPRESS_UID_EVENT_REPORTED, metricIdHash, amount, uid); } diff --git a/java/com/android/modules/expresslog/Histogram.java b/java/com/android/modules/expresslog/Histogram.java index be300bf..4f61c85 100644 --- a/java/com/android/modules/expresslog/Histogram.java +++ b/java/com/android/modules/expresslog/Histogram.java @@ -20,14 +20,12 @@ import android.annotation.FloatRange; import android.annotation.IntRange; import android.annotation.NonNull; -import com.android.modules.expresslog.StatsExpressLog; - import java.util.Arrays; /** Histogram encapsulates StatsD write API calls */ public final class Histogram { - private final long mMetricIdHash; + private final String mMetricId; private final BinOptions mBinOptions; /** @@ -37,7 +35,7 @@ public final class Histogram { * @param binOptions to calculate bin index for samples */ public Histogram(@NonNull String metricId, @NonNull BinOptions binOptions) { - mMetricIdHash = Utils.hashString(metricId); + mMetricId = metricId; mBinOptions = binOptions; } @@ -47,9 +45,10 @@ public final class Histogram { * @param sample value */ public void logSample(float sample) { + final long hash = MetricIds.getMetricIdHash(mMetricId, MetricIds.METRIC_TYPE_HISTOGRAM); final int binIndex = mBinOptions.getBinForSample(sample); - StatsExpressLog.write(StatsExpressLog.EXPRESS_HISTOGRAM_SAMPLE_REPORTED, mMetricIdHash, - /*count*/ 1, binIndex); + StatsExpressLog.write( + StatsExpressLog.EXPRESS_HISTOGRAM_SAMPLE_REPORTED, hash, /*count*/ 1, binIndex); } /** @@ -59,9 +58,15 @@ public final class Histogram { * @param sample value */ public void logSampleWithUid(int uid, float sample) { + final long hash = + MetricIds.getMetricIdHash(mMetricId, MetricIds.METRIC_TYPE_HISTOGRAM_WITH_UID); final int binIndex = mBinOptions.getBinForSample(sample); - StatsExpressLog.write(StatsExpressLog.EXPRESS_UID_HISTOGRAM_SAMPLE_REPORTED, - mMetricIdHash, /*count*/ 1, binIndex, uid); + StatsExpressLog.write( + StatsExpressLog.EXPRESS_UID_HISTOGRAM_SAMPLE_REPORTED, + hash, /*count*/ + 1, + binIndex, + uid); } /** Used by Histogram to map data sample to corresponding bin */ diff --git a/java/com/android/modules/expresslog/Utils.java b/java/com/android/modules/expresslog/Utils.java deleted file mode 100644 index fde90fc..0000000 --- a/java/com/android/modules/expresslog/Utils.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.modules.expresslog; - -final class Utils { - static native long hashString(String stringToHash); -} diff --git a/java/com/android/modules/utils/testing/AbstractExtendedMockitoRule.java b/java/com/android/modules/utils/testing/AbstractExtendedMockitoRule.java index 5256d6a..2242ca0 100644 --- a/java/com/android/modules/utils/testing/AbstractExtendedMockitoRule.java +++ b/java/com/android/modules/utils/testing/AbstractExtendedMockitoRule.java @@ -77,7 +77,6 @@ public abstract class AbstractExtendedMockitoRule<R extends AbstractExtendedMock private final Set<Class<?>> mMockedStaticClasses; private final Set<Class<?>> mSpiedStaticClasses; private final List<StaticMockFixture> mStaticMockFixtures; - private final @Nullable SessionBuilderVisitor mSessionBuilderConfigurator; private final boolean mClearInlineMocks; private MockitoSession mMockitoSession; @@ -88,7 +87,6 @@ public abstract class AbstractExtendedMockitoRule<R extends AbstractExtendedMock mMockitoFramework = builder.mMockitoFramework; mMockitoSession = builder.mMockitoSession; mAfterSessionFinishedCallback = builder.mAfterSessionFinishedCallback; - mSessionBuilderConfigurator = builder.mSessionBuilderConfigurator; mMockedStaticClasses = builder.mMockedStaticClasses; mSpiedStaticClasses = builder.mSpiedStaticClasses; mStaticMockFixtures = builder.mStaticMockFixtures == null ? Collections.emptyList() @@ -98,7 +96,6 @@ public abstract class AbstractExtendedMockitoRule<R extends AbstractExtendedMock + ", mockedStaticClasses=" + mMockedStaticClasses + ", spiedStaticClasses=" + mSpiedStaticClasses + ", staticMockFixtures=" + mStaticMockFixtures - + ", sessionBuilderConfigurator=" + mSessionBuilderConfigurator + ", afterSessionFinishedCallback=" + mAfterSessionFinishedCallback + ", mockitoFramework=" + mMockitoFramework + ", mockitoSession=" + mMockitoSession @@ -219,10 +216,6 @@ public abstract class AbstractExtendedMockitoRule<R extends AbstractExtendedMock Log.v(TAG, "Calling spyStatic() on " + clazz); sessionBuilder.spyStatic(clazz); } - if (mSessionBuilderConfigurator != null) { - Log.v(TAG, "Visiting " + mSessionBuilderConfigurator + " with " + sessionBuilder); - mSessionBuilderConfigurator.visit(sessionBuilder); - } } private void setUpMockBehaviors() { @@ -287,7 +280,6 @@ public abstract class AbstractExtendedMockitoRule<R extends AbstractExtendedMock Strictness mStrictness = Strictness.LENIENT; @Nullable MockitoFramework mMockitoFramework; @Nullable MockitoSession mMockitoSession; - @Nullable SessionBuilderVisitor mSessionBuilderConfigurator; @Nullable Runnable mAfterSessionFinishedCallback; boolean mClearInlineMocks = true; @@ -321,11 +313,9 @@ public abstract class AbstractExtendedMockitoRule<R extends AbstractExtendedMock * com.android.dx.mockito.inline.extended.StaticMockitoSessionBuilder#mockStatic(Class)}. * * @throws IllegalStateException if the same class was already passed to - * {@link #mockStatic(Class)} or {@link #spyStatic(Class)} or if - * {@link #configureSessionBuilder(SessionBuilderVisitor)} was called before. + * {@link #mockStatic(Class)} or {@link #spyStatic(Class)}. */ public final B mockStatic(Class<?> clazz) { - checkConfigureSessionBuilderNotCalled(); mMockedStaticClasses.add(checkClassNotMockedOrSpied(clazz)); return thisBuilder(); } @@ -335,11 +325,9 @@ public abstract class AbstractExtendedMockitoRule<R extends AbstractExtendedMock * com.android.dx.mockito.inline.extended.StaticMockitoSessionBuilder#spyStatic(Class)}. * * @throws IllegalStateException if the same class was already passed to - * {@link #mockStatic(Class)} or {@link #spyStatic(Class)} or if - * {@link #configureSessionBuilder(SessionBuilderVisitor)} was called before. + * {@link #mockStatic(Class)} or {@link #spyStatic(Class)}. */ public final B spyStatic(Class<?> clazz) { - checkConfigureSessionBuilderNotCalled(); mSpiedStaticClasses.add(checkClassNotMockedOrSpied(clazz)); return thisBuilder(); } @@ -361,25 +349,6 @@ public abstract class AbstractExtendedMockitoRule<R extends AbstractExtendedMock return thisBuilder(); } - // TODO(b/281577492): remove once CachedAppOptimizerTest doesn't use anymore - /** - * Alternative for {@link #spyStatic(Class)} / {@link #mockStatic(Class)}; typically used - * when the same setup is shared by multiple tests. - * - * @deprecated use {@link #addStaticMockFixtures(Supplier...)} instead - * - * @throws IllegalStateException if {@link #mockStatic(Class)} or {@link #spyStatic(Class)} - * was called before. - */ - @Deprecated - public final B configureSessionBuilder( - SessionBuilderVisitor sessionBuilderConfigurator) { - checkState(mMockedStaticClasses.isEmpty(), "mockStatic() already called"); - checkState(mSpiedStaticClasses.isEmpty(), "spyStatic() already called"); - mSessionBuilderConfigurator = Objects.requireNonNull(sessionBuilderConfigurator); - return thisBuilder(); - } - /** * Runs the given {@code runnable} after the session finished. * @@ -425,11 +394,6 @@ public abstract class AbstractExtendedMockitoRule<R extends AbstractExtendedMock return (B) this; } - private void checkConfigureSessionBuilderNotCalled() { - checkState(mSessionBuilderConfigurator == null, - "configureSessionBuilder() already called"); - } - private Class<?> checkClassNotMockedOrSpied(Class<?> clazz) { Objects.requireNonNull(clazz); checkState(!mMockedStaticClasses.contains(clazz), "class %s already mocked", clazz); @@ -438,17 +402,6 @@ public abstract class AbstractExtendedMockitoRule<R extends AbstractExtendedMock } } - /** - * Visitor for {@link StaticMockitoSessionBuilder}. - */ - public interface SessionBuilderVisitor { - - /** - * Visits it. - */ - void visit(StaticMockitoSessionBuilder builder); - } - // Copied from com.android.internal.util.Preconditions, as that method is not available on RVC private static void checkState(boolean expression, String messageTemplate, Object... messageArgs) { diff --git a/javatests/com/android/modules/expresslog/Android.bp b/javatests/com/android/modules/expresslog/Android.bp index dd52750..9396e17 100644 --- a/javatests/com/android/modules/expresslog/Android.bp +++ b/javatests/com/android/modules/expresslog/Android.bp @@ -37,40 +37,7 @@ android_test { "android.test.runner", ], - jni_libs: [ - "libexpresslog_test_jni", - ], - test_suites: [ "general-tests", ], } - -cc_library_shared { - name: "libexpresslog_test_jni", - - sdk_version: "current", - min_sdk_version: "30", - - cflags: [ - "-Wall", - "-Werror", - "-Wextra", - - "-DNAMESPACE_FOR_HASH_FUNCTIONS=farmhash", - ], - srcs: [ - "jni/onload.cpp", - ], - header_libs: [ - "liblog_headers", - "libnativehelper_header_only", - ], - shared_libs: [ - "liblog", - ], - static_libs: [ - "libexpresslog_jni", - "libtextclassifier_hash_static", - ], -} diff --git a/javatests/com/android/modules/expresslog/ScaledRangeOptionsTest.java b/javatests/com/android/modules/expresslog/ScaledRangeOptionsTest.java index 8defce7..1c42788 100644 --- a/javatests/com/android/modules/expresslog/ScaledRangeOptionsTest.java +++ b/javatests/com/android/modules/expresslog/ScaledRangeOptionsTest.java @@ -27,10 +27,6 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) @SmallTest public class ScaledRangeOptionsTest { - static { - System.loadLibrary("expresslog_test_jni"); - } - private static final String TAG = ScaledRangeOptionsTest.class.getSimpleName(); @Test diff --git a/javatests/com/android/modules/expresslog/UniformOptionsTest.java b/javatests/com/android/modules/expresslog/UniformOptionsTest.java index 3cc03ec..cad4c3f 100644 --- a/javatests/com/android/modules/expresslog/UniformOptionsTest.java +++ b/javatests/com/android/modules/expresslog/UniformOptionsTest.java @@ -26,10 +26,6 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) @SmallTest public class UniformOptionsTest { - static { - System.loadLibrary("expresslog_test_jni"); - } - private static final String TAG = UniformOptionsTest.class.getSimpleName(); @Test diff --git a/javatests/com/android/modules/expresslog/jni/.clang-format b/javatests/com/android/modules/expresslog/jni/.clang-format deleted file mode 100644 index cead3a0..0000000 --- a/javatests/com/android/modules/expresslog/jni/.clang-format +++ /dev/null @@ -1,17 +0,0 @@ -BasedOnStyle: Google -AllowShortIfStatementsOnASingleLine: true -AllowShortFunctionsOnASingleLine: false -AllowShortLoopsOnASingleLine: true -BinPackArguments: true -BinPackParameters: true -ColumnLimit: 100 -CommentPragmas: NOLINT:.* -ContinuationIndentWidth: 8 -DerivePointerAlignment: false -IndentWidth: 4 -PointerAlignment: Left -TabWidth: 4 -AccessModifierOffset: -4 -IncludeCategories: - - Regex: '^"Log\.h"' - Priority: -1 diff --git a/javatests/com/android/modules/expresslog/jni/onload.cpp b/javatests/com/android/modules/expresslog/jni/onload.cpp deleted file mode 100644 index a112467..0000000 --- a/javatests/com/android/modules/expresslog/jni/onload.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "TeX" - -#include <jni.h> -#include <log/log.h> - -namespace android { -extern int register_com_android_modules_expresslog_Utils(JNIEnv* env); -} // namespace android - -using namespace android; - -extern "C" jint JNI_OnLoad(JavaVM* vm, void* /* reserved */) { - JNIEnv* env = NULL; - jint result = -1; - - if (vm->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK) { - ALOGE("GetEnv failed!"); - return result; - } - ALOG_ASSERT(env, "Could not retrieve the env!"); - - register_com_android_modules_expresslog_Utils(env); - return JNI_VERSION_1_4; -} diff --git a/javatests/com/android/modules/utils/testing/ExtendedMockitoRuleTest.java b/javatests/com/android/modules/utils/testing/ExtendedMockitoRuleTest.java index 765b318..26d0cc3 100644 --- a/javatests/com/android/modules/utils/testing/ExtendedMockitoRuleTest.java +++ b/javatests/com/android/modules/utils/testing/ExtendedMockitoRuleTest.java @@ -65,7 +65,6 @@ public final class ExtendedMockitoRuleTest { private @Mock Statement mStatement; private @Mock Runnable mRunnable; - private @Mock ExtendedMockitoRule.SessionBuilderVisitor mSessionBuilderVisitor; private @Mock StaticMockFixture mStaticMockFixture1; private @Mock StaticMockFixture mStaticMockFixture2; private @Mock StaticMockFixture mStaticMockFixture3; @@ -100,12 +99,6 @@ public final class ExtendedMockitoRuleTest { } @Test - public void testBuilder_configureSessionBuilder_null() { - assertThrows(NullPointerException.class, - () -> mBuilder.configureSessionBuilder(null)); - } - - @Test public void testBuilder_mockStatic_null() { assertThrows(NullPointerException.class, () -> mBuilder.mockStatic(null)); } @@ -420,18 +413,6 @@ public final class ExtendedMockitoRuleTest { } @Test - public void testSpyStatic_afterConfigureSessionBuilder() throws Throwable { - assertThrows(IllegalStateException.class, () -> mBuilder - .configureSessionBuilder(mSessionBuilderVisitor).spyStatic(StaticClass.class)); - } - - @Test - public void testMockStatic_afterConfigureSessionBuilder() throws Throwable { - assertThrows(IllegalStateException.class, () -> mBuilder - .configureSessionBuilder(mSessionBuilderVisitor).mockStatic(StaticClass.class)); - } - - @Test public void testAddStaticMockFixtures_once() throws Throwable { InOrder inOrder = inOrder(mStaticMockFixture1, mStaticMockFixture2); @@ -515,26 +496,6 @@ public final class ExtendedMockitoRuleTest { } @Test - public void testConfigureSessionBuilder_afterMockStatic() throws Throwable { - assertThrows(IllegalStateException.class, () -> mBuilder.mockStatic(StaticClass.class) - .configureSessionBuilder(mSessionBuilderVisitor)); - } - - @Test - public void testConfigureSessionBuilder_afterSpyStatic() throws Throwable { - assertThrows(IllegalStateException.class, () -> mBuilder.spyStatic(StaticClass.class) - .configureSessionBuilder(mSessionBuilderVisitor)); - } - - @Test - public void testConfigureSessionBuilder() throws Throwable { - mUnsafeBuilder.configureSessionBuilder(mSessionBuilderVisitor) - .build().apply(mStatement, mDescription).evaluate(); - - verify(mSessionBuilderVisitor).visit(notNull()); - } - - @Test public void testAfterSessionFinished() throws Throwable { mUnsafeBuilder.afterSessionFinished(mRunnable).build().apply(mStatement, mDescription) .evaluate(); diff --git a/jni/expresslog/.clang-format b/jni/expresslog/.clang-format deleted file mode 100644 index cead3a0..0000000 --- a/jni/expresslog/.clang-format +++ /dev/null @@ -1,17 +0,0 @@ -BasedOnStyle: Google -AllowShortIfStatementsOnASingleLine: true -AllowShortFunctionsOnASingleLine: false -AllowShortLoopsOnASingleLine: true -BinPackArguments: true -BinPackParameters: true -ColumnLimit: 100 -CommentPragmas: NOLINT:.* -ContinuationIndentWidth: 8 -DerivePointerAlignment: false -IndentWidth: 4 -PointerAlignment: Left -TabWidth: 4 -AccessModifierOffset: -4 -IncludeCategories: - - Regex: '^"Log\.h"' - Priority: -1 diff --git a/jni/expresslog/Android.bp b/jni/expresslog/Android.bp deleted file mode 100644 index 7bef576..0000000 --- a/jni/expresslog/Android.bp +++ /dev/null @@ -1,53 +0,0 @@ -// -// Copyright (C) 2023 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// JNI library for Utils.hashString -package { - default_applicable_licenses: ["Android-Apache-2.0"], -} - -cc_library_static { - name: "libexpresslog_jni", - - sdk_version: "current", - min_sdk_version: "30", - - cflags: [ - "-Wall", - "-Werror", - "-Wextra", - - "-DNAMESPACE_FOR_HASH_FUNCTIONS=farmhash", - ], - srcs: [ - "com_android_modules_expresslog_Utils.cpp", - ], - header_libs: [ - "liblog_headers", - "libnativehelper_header_only", - "libtextclassifier_hash_headers", - ], - shared_libs: [ - "liblog", - ], - static_libs: [ - "libtextclassifier_hash_static", - ], - visibility: ["//visibility:public"], - apex_available: [ - "//apex_available:anyapex", - "//apex_available:platform", - ], -} diff --git a/jni/expresslog/com_android_modules_expresslog_Utils.cpp b/jni/expresslog/com_android_modules_expresslog_Utils.cpp deleted file mode 100644 index ed4d0ed..0000000 --- a/jni/expresslog/com_android_modules_expresslog_Utils.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_NAMESPACE "TeX.tag." -#define LOG_TAG "TeX" - -#include <log/log.h> -#include <nativehelper/scoped_local_ref.h> -#include <nativehelper/scoped_utf_chars.h> -#include <utils/hash/farmhash.h> - -// ---------------------------------------------------------------------------- -// JNI Glue -// ---------------------------------------------------------------------------- - -static jclass gStringClass = nullptr; - -/** - * Class: com_android_modules_expresslog_Utils - * Method: hashString - * Signature: (Ljava/lang/String;)J - */ -static jlong hashString(JNIEnv* env, jclass /*class*/, jstring metricNameObj) { - ScopedUtfChars name(env, metricNameObj); - if (name.c_str() == nullptr) { - return 0; - } - - return static_cast<jlong>(farmhash::Fingerprint64(name.c_str(), name.size())); -} - -static const JNINativeMethod gMethods[] = { - {"hashString", "(Ljava/lang/String;)J", (void*)hashString}, -}; - -namespace android { - -int register_com_android_modules_expresslog_Utils(JNIEnv* env, const char* const utilsClassName) { - static const char* const kStringClassName = "java/lang/String"; - - ScopedLocalRef<jclass> utilsCls(env, env->FindClass(utilsClassName)); - if (utilsCls.get() == nullptr) { - ALOGE("jni expresslog registration failure, class not found '%s'", utilsClassName); - return JNI_ERR; - } - - jclass stringClass = env->FindClass(kStringClassName); - if (stringClass == nullptr) { - ALOGE("jni expresslog registration failure, class not found '%s'", kStringClassName); - return JNI_ERR; - } - gStringClass = static_cast<jclass>(env->NewGlobalRef(stringClass)); - if (gStringClass == nullptr) { - ALOGE("jni expresslog Unable to create global reference '%s'", kStringClassName); - return JNI_ERR; - } - - const jint count = sizeof(gMethods) / sizeof(gMethods[0]); - int status = env->RegisterNatives(utilsCls.get(), gMethods, count); - if (status < 0) { - ALOGE("jni expresslog registration failure, status: %d", status); - return JNI_ERR; - } - return JNI_VERSION_1_4; -} - -int register_com_android_modules_expresslog_Utils(JNIEnv* env) { - static const char* const kUtilsClassName = "com/android/modules/expresslog/Utils"; - return register_com_android_modules_expresslog_Utils(env, kUtilsClassName); -} - -} // namespace android |