From 0daf560dd5809fc7334d0105ef47345377f5fd88 Mon Sep 17 00:00:00 2001 From: maxli Date: Mon, 8 Jan 2024 16:46:32 +0800 Subject: [PATCH] feat(android): add bugly app id register --- .../com/tencent/mtt/hippy/HippyEngine.java | 4 +- .../bridge/libraryloader/LibraryLoader.java | 2 +- .../tencent/mtt/hippy/utils/BuglyUtils.java | 45 +++++++++++++++++++ .../tencent/mtt/hippy/example/MyActivity.java | 2 +- .../com/tencent/smtt/flexbox/FlexNode.java | 2 +- 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 android/sdk/src/main/java/com/tencent/mtt/hippy/utils/BuglyUtils.java diff --git a/android/sdk/src/main/java/com/tencent/mtt/hippy/HippyEngine.java b/android/sdk/src/main/java/com/tencent/mtt/hippy/HippyEngine.java index 9c4ee5b2154..19428289d23 100644 --- a/android/sdk/src/main/java/com/tencent/mtt/hippy/HippyEngine.java +++ b/android/sdk/src/main/java/com/tencent/mtt/hippy/HippyEngine.java @@ -43,6 +43,7 @@ import com.tencent.mtt.hippy.bridge.HippyCoreAPI; import com.tencent.mtt.hippy.bridge.bundleloader.HippyBundleLoader; import com.tencent.mtt.hippy.bridge.libraryloader.LibraryLoader; +import com.tencent.mtt.hippy.utils.BuglyUtils; import com.tencent.mtt.hippy.v8.V8; import com.tencent.mtt.hippy.common.HippyJsException; import com.tencent.mtt.hippy.common.HippyMap; @@ -84,11 +85,12 @@ public static HippyEngine create(EngineInitParams params) { if (params == null) { throw new RuntimeException("Hippy: initParams must no be null"); } - LibraryLoader.loadLibraryIfNeed(params.soLoader); + LibraryLoader.loadLibraryIfNeeded(params.soLoader); if (sLogAdapter == null && params.logAdapter != null) { setNativeLogHandler(params.logAdapter); } ContextHolder.initAppContext(params.context); + BuglyUtils.registerSdkAppIdIfNeeded(params.context); params.check(); LogUtils.enableDebugLog(params.enableLog); HippyEngine hippyEngine; diff --git a/android/sdk/src/main/java/com/tencent/mtt/hippy/bridge/libraryloader/LibraryLoader.java b/android/sdk/src/main/java/com/tencent/mtt/hippy/bridge/libraryloader/LibraryLoader.java index 2f8c2617d89..ed28b2d49bb 100644 --- a/android/sdk/src/main/java/com/tencent/mtt/hippy/bridge/libraryloader/LibraryLoader.java +++ b/android/sdk/src/main/java/com/tencent/mtt/hippy/bridge/libraryloader/LibraryLoader.java @@ -27,7 +27,7 @@ public class LibraryLoader { "hippy", "flexbox" }; - public static void loadLibraryIfNeed(HippySoLoaderAdapter soLoaderAdapter) { + public static void loadLibraryIfNeeded(HippySoLoaderAdapter soLoaderAdapter) { if (hasLoaded || BuildConfig.ENABLE_SO_DOWNLOAD) { return; } diff --git a/android/sdk/src/main/java/com/tencent/mtt/hippy/utils/BuglyUtils.java b/android/sdk/src/main/java/com/tencent/mtt/hippy/utils/BuglyUtils.java new file mode 100644 index 00000000000..06b42d716f5 --- /dev/null +++ b/android/sdk/src/main/java/com/tencent/mtt/hippy/utils/BuglyUtils.java @@ -0,0 +1,45 @@ +/* Tencent is pleased to support the open source community by making Hippy available. + * Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.tencent.mtt.hippy.utils; + +import android.content.Context; +import android.content.SharedPreferences; +import androidx.annotation.Nullable; +import com.tencent.mtt.hippy.BuildConfig; + +public class BuglyUtils { + + private static final String BUGLY_KEY = "BuglySdkInfos"; + private static final String SDK_APP_ID = "8aa644f958"; + private static boolean sHasCommitted = false; + + public static void registerSdkAppIdIfNeeded(@Nullable Context context) { + if (sHasCommitted || context == null) { + return; + } + Context appContext = context.getApplicationContext(); + SharedPreferences settings = appContext.getSharedPreferences(BUGLY_KEY, Context.MODE_PRIVATE); + String version = settings.getString(SDK_APP_ID, null); + if (!BuildConfig.LIBRARY_VERSION.equals(version)) { + SharedPreferences.Editor editor = settings.edit(); + editor.putString(SDK_APP_ID, BuildConfig.LIBRARY_VERSION); + sHasCommitted = editor.commit(); + } else { + sHasCommitted = true; + } + } +} diff --git a/examples/android-demo/src/main/java/com/tencent/mtt/hippy/example/MyActivity.java b/examples/android-demo/src/main/java/com/tencent/mtt/hippy/example/MyActivity.java index ab7e42c1eb2..a0c977d5cf1 100644 --- a/examples/android-demo/src/main/java/com/tencent/mtt/hippy/example/MyActivity.java +++ b/examples/android-demo/src/main/java/com/tencent/mtt/hippy/example/MyActivity.java @@ -171,7 +171,7 @@ public void handleBackgroundTracing(String details) { } list[1] = sb.toString(); - LibraryLoader.loadLibraryIfNeed(initParams.soLoader); + LibraryLoader.loadLibraryIfNeeded(initParams.soLoader); HippyBridgeImpl.createSnapshotFromScript(list, basePath, snapshotPath, diff --git a/layout/android/java/com/tencent/smtt/flexbox/FlexNode.java b/layout/android/java/com/tencent/smtt/flexbox/FlexNode.java index 41d62ad290e..b168556298e 100755 --- a/layout/android/java/com/tencent/smtt/flexbox/FlexNode.java +++ b/layout/android/java/com/tencent/smtt/flexbox/FlexNode.java @@ -36,7 +36,7 @@ public class FlexNode implements FlexNodeAPI { static { - LibraryLoader.loadLibraryIfNeed("flexbox"); + LibraryLoader.loadLibraryIfNeeded("flexbox"); } private FlexNode mParent; private List mChildren;