From 5611013803f18e51c954bcd6e310cc6f259d4731 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Thu, 16 Feb 2023 08:11:51 -0800 Subject: [PATCH] Fix runtime crash caused by java.lang.ClassNotFoundException (#25101) --- examples/java-matter-controller/Manifest.txt | 2 +- .../java_deps/stub_src/android/util/Log.java | 81 +++++++++++++++++-- 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/examples/java-matter-controller/Manifest.txt b/examples/java-matter-controller/Manifest.txt index 8e57ca291f8ebb..ebdd1a402677f7 100644 --- a/examples/java-matter-controller/Manifest.txt +++ b/examples/java-matter-controller/Manifest.txt @@ -1,3 +1,3 @@ Main-Class: com.matter.controller.Main -Class-Path: ../lib/third_party/connectedhomeip/src/controller/java/CHIPController.jar ../lib/third_party/connectedhomeip/src/setup_payload/java/SetupPayloadParser.jar +Class-Path: ../lib/third_party/connectedhomeip/src/controller/java/CHIPController.jar ../lib/third_party/connectedhomeip/src/setup_payload/java/SetupPayloadParser.jar ../lib/third_party/connectedhomeip/third_party/java_deps/stub_src/Android.jar ../lib/third_party/connectedhomeip/third_party/java_deps/json-20220924.jar ../lib/third_party/connectedhomeip/third_party/java_deps/jsr305-3.0.2.jar diff --git a/third_party/java_deps/stub_src/android/util/Log.java b/third_party/java_deps/stub_src/android/util/Log.java index f67df58ed091c1..3b8e7c0d3d9c24 100644 --- a/third_party/java_deps/stub_src/android/util/Log.java +++ b/third_party/java_deps/stub_src/android/util/Log.java @@ -21,19 +21,88 @@ package android.util; public final class Log { - public static int d(String tag, String message) { - return 0; + + public static final int VERBOSE = 2; + + public static final int DEBUG = 3; + + public static final int INFO = 4; + + public static final int WARN = 5; + + public static final int ERROR = 6; + + public static final int ASSERT = 7; + + public static final int NONE = Integer.MAX_VALUE; + + /** + * Send a DEBUG log message. + * + * @param tag Used to identify the source of a log message. It usually identifies the class or + * activity where the log call occurs. + * @param msg The message you would like logged. + * @return A positive value if the message was loggable. + */ + public static int d(String tag, String msg) { + return log(DEBUG, tag, msg); } + /** + * Send a ERROR log message. + * + * @param tag Used to identify the source of a log message. It usually identifies the class or + * activity where the log call occurs. + * @param msg The message you would like logged. + * @return A positive value if the message was loggable. + */ public static int e(String tag, String msg) { - return 0; + return log(ERROR, tag, msg); } + /** + * Send a ERROR log message and log the exception. + * + * @param tag Used to identify the source of a log message. It usually identifies the class or + * activity where the log call occurs. + * @param msg The message you would like logged. + * @param tr An exception to log. + * @return A positive value if the message was loggable. + */ public static int e(String tag, String msg, Throwable tr) { - return 0; + return log(ERROR, tag, msg, tr); } - public static int w(String tag, String message) { - return 0; + /** + * Send a WARN log message. + * + * @param tag Used to identify the source of a log message. It usually identifies the class or + * activity where the log call occurs. + * @param msg The message you would like logged. + * @return A positive value if the message was loggable. + */ + public static int w(String tag, String msg) { + return log(WARN, tag, msg); + } + + private static int log(int level, String tag, String msg) { + if (level > ASSERT) { + return -1; + } + + System.out.println(tag + ':' + msg); + + return 1; + } + + private static int log(int level, String tag, String msg, Throwable tr) { + if (level > ASSERT) { + return -1; + } + + System.out.println(tag + ':' + msg); + System.out.println(tr.toString()); + + return 1; } }