diff options
author | 2020-01-24 21:35:38 +0000 | |
---|---|---|
committer | 2020-01-24 21:35:38 +0000 | |
commit | 46fb154c3a33c3bb4ff0634938d91cc269496e79 (patch) | |
tree | 1df899053a69c0fd3a5fb010766cbc77f63828c0 | |
parent | 7e14df89945c88596c6bec8970de67fd3f62045d (diff) | |
parent | b23f936e90322170118fa2040c8b1af5a45d2925 (diff) |
Merge "wifi: Remove libwifijni & use logcat binary instead"
-rw-r--r-- | apex/Android.bp | 1 | ||||
-rw-r--r-- | service/Android.bp | 38 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiDiagnostics.java | 30 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiNative.java | 45 | ||||
-rw-r--r-- | service/jni/com_android_server_wifi_WifiNative.cpp | 90 | ||||
-rw-r--r-- | service/jni/jni_helper.cpp | 67 | ||||
-rw-r--r-- | service/jni/jni_helper.h | 121 | ||||
-rw-r--r-- | service/tests/wifitests/Android.bp | 1 | ||||
-rw-r--r-- | service/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java | 1 |
9 files changed, 14 insertions, 380 deletions
diff --git a/apex/Android.bp b/apex/Android.bp index 1278b3040c..a758067a23 100644 --- a/apex/Android.bp +++ b/apex/Android.bp @@ -17,7 +17,6 @@ apex_defaults { name: "com.android.wifi-defaults", androidManifest: ":com.android.wifi-androidManifest", - native_shared_libs: ["libwifi-jni"], java_libs: [ "wifi-service", "framework-wifi", diff --git a/service/Android.bp b/service/Android.bp index e0c886a243..51b11e6591 100644 --- a/service/Android.bp +++ b/service/Android.bp @@ -26,43 +26,6 @@ java_defaults { }, } -// Make the JNI part -// ============================================================ -cc_library_shared { - name: "libwifi-jni", - - cflags: [ - "-Wall", - "-Werror", - "-Wextra", - "-Wno-unused-parameter", - "-Wno-unused-function", - "-Wunused-variable", - "-Winit-self", - "-Wwrite-strings", - "-Wshadow", - ], - - shared_libs: [ - "liblog", - "libnativehelper", - "libcutils", - "libutils", - "libdl", - ], - - srcs: [ - "jni/com_android_server_wifi_WifiNative.cpp", - "jni/jni_helper.cpp", - ], - - product_variables: { - pdk: { - enabled: false, - }, - }, -} - filegroup { name: "wifi-service-srcs", srcs: [ @@ -152,7 +115,6 @@ java_library { required: [ "cacerts_wfa", - "libwifi-jni", "services", "wifi-service-resources", ], diff --git a/service/java/com/android/server/wifi/WifiDiagnostics.java b/service/java/com/android/server/wifi/WifiDiagnostics.java index 3e22d863fd..f047f3273f 100644 --- a/service/java/com/android/server/wifi/WifiDiagnostics.java +++ b/service/java/com/android/server/wifi/WifiDiagnostics.java @@ -315,7 +315,7 @@ class WifiDiagnostics extends BaseWifiDiagnostics { byte[] fwMemoryDump; byte[] mDriverStateDump; byte[] alertData; - LimitedCircularArray<String> kernelLogLines; + ArrayList<String> kernelLogLines; ArrayList<String> logcatLines; void clearVerboseLogs() { @@ -634,8 +634,8 @@ class WifiDiagnostics extends BaseWifiDiagnostics { } } - report.logcatLines = getLogcat(127); - report.kernelLogLines = getKernelLog(127); + report.logcatLines = getLogcatSystem(127); + report.kernelLogLines = getLogcatKernel(127); if (captureFWDump) { report.fwMemoryDump = mWifiNative.getFwMemoryDump(); @@ -694,10 +694,11 @@ class WifiDiagnostics extends BaseWifiDiagnostics { return result; } - private ArrayList<String> getLogcat(int maxLines) { - ArrayList<String> lines = new ArrayList<String>(maxLines); + private ArrayList<String> getLogcat(String logcatSections, int maxLines) { + ArrayList<String> lines = new ArrayList<>(maxLines); try { - Process process = mJavaRuntime.exec(String.format("logcat -t %d", maxLines)); + Process process = mJavaRuntime.exec( + String.format("logcat -b %s -t %d", logcatSections, maxLines)); BufferedReader reader = new BufferedReader( new InputStreamReader(process.getInputStream())); String line; @@ -714,18 +715,15 @@ class WifiDiagnostics extends BaseWifiDiagnostics { mLog.dump("Exception while capturing logcat: %").c(e.toString()).flush(); } return lines; + } - private LimitedCircularArray<String> getKernelLog(int maxLines) { - if (DBG) mLog.tC("Reading kernel log ..."); - LimitedCircularArray<String> lines = new LimitedCircularArray<String>(maxLines); - String log = mWifiNative.readKernelLog(); - String logLines[] = log.split("\n"); - for (int i = 0; i < logLines.length; i++) { - lines.addLast(logLines[i]); - } - if (DBG) mLog.dump("Added % lines").c(logLines.length).flush(); - return lines; + private ArrayList<String> getLogcatSystem(int maxLines) { + return getLogcat("main,system,crash", maxLines); + } + + private ArrayList<String> getLogcatKernel(int maxLines) { + return getLogcat("kernel", maxLines); } /** Packet fate reporting */ diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index cf953e76ba..6d0aaa8791 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -54,10 +54,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.nio.CharBuffer; -import java.nio.charset.CharacterCodingException; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -80,7 +76,6 @@ import java.util.TimeZone; */ public class WifiNative { private static final String TAG = "WifiNative"; - private static final String JNI_LIB = "/apex/com.android.wifi/lib64/libwifi-jni.so"; private final SupplicantStaIfaceHal mSupplicantStaIfaceHal; private final HostapdHal mHostapdHal; @@ -3491,44 +3486,4 @@ public class WifiNative { return iface.phyCapabilities.isWifiStandardSupported(standard); } } - - /******************************************************** - * JNI operations - ********************************************************/ - /* Register native functions */ - static { - /* Native functions are defined in libwifi-jni.so */ - try { - System.load(JNI_LIB); - registerNatives(); - } catch (UnsatisfiedLinkError e) { - Log.e(TAG, "Failed to load jni library", e); - } - } - - private static native int registerNatives(); - /* kernel logging support */ - private static native byte[] readKernelLogNative(); - - /** - * Fetches the latest kernel logs. - */ - public synchronized String readKernelLog() { - try { - byte[] bytes = readKernelLogNative(); - if (bytes != null) { - CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder(); - try { - CharBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes)); - return decoded.toString(); - } catch (CharacterCodingException cce) { - return new String(bytes, StandardCharsets.ISO_8859_1); - } - } - } catch (UnsatisfiedLinkError e) { - // TODO (b/145196311): Fix this linker error. - Log.e(TAG, "Failed to load jni library", e); - } - return "*** failed to read kernel log ***"; - } } diff --git a/service/jni/com_android_server_wifi_WifiNative.cpp b/service/jni/com_android_server_wifi_WifiNative.cpp deleted file mode 100644 index 262357ac65..0000000000 --- a/service/jni/com_android_server_wifi_WifiNative.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2017, 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 "wifi-jni" - -#include <ctype.h> -#include <stdlib.h> -#include <sys/klog.h> - -#include <log/log.h> -#include <jni.h> -#include <nativehelper/jni_macros.h> -#include <nativehelper/JNIHelp.h> - -#include "jni_helper.h" - -namespace android { - - -static jbyteArray android_net_wifi_readKernelLogNative(JNIEnv *env, jclass cls) { - JNIHelper helper(env); - ALOGV("Reading kernel logs"); - - int size = klogctl(/* SYSLOG_ACTION_SIZE_BUFFER */ 10, 0, 0); - if (size < 1) { - ALOGD("no kernel logs"); - return helper.newByteArray(0).detach(); - } - - char *buf = (char *)malloc(size); - if (buf == NULL) { - ALOGD("can't allocate temporary storage"); - return helper.newByteArray(0).detach(); - } - - int read = klogctl(/* SYSLOG_ACTION_READ_ALL */ 3, buf, size); - if (read < 0) { - ALOGD("can't read logs - %d", read); - free(buf); - return helper.newByteArray(0).detach(); - } else { - ALOGV("read %d bytes", read); - } - - if (read != size) { - ALOGV("read %d bytes, expecting %d", read, size); - } - - JNIObject<jbyteArray> result = helper.newByteArray(read); - if (result.isNull()) { - ALOGD("can't allocate array"); - free(buf); - return result.detach(); - } - - helper.setByteArrayRegion(result, 0, read, (jbyte*)buf); - free(buf); - return result.detach(); -} - -// ---------------------------------------------------------------------------- - -/* - * JNI registration. - */ -static JNINativeMethod gWifiMethods[] = { - NATIVE_METHOD(android_net_wifi, readKernelLogNative, "()[B"), -}; - -/* User to register native functions */ -extern "C" -jint Java_com_android_server_wifi_WifiNative_registerNatives(JNIEnv* env, jclass clazz) { - return jniRegisterNativeMethods(env, - "com/android/server/wifi/WifiNative", gWifiMethods, NELEM(gWifiMethods)); -} - -}; // namespace android diff --git a/service/jni/jni_helper.cpp b/service/jni/jni_helper.cpp deleted file mode 100644 index 60110c942d..0000000000 --- a/service/jni/jni_helper.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2016, 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 "wifi" - -#include <hardware_legacy/wifi_hal.h> -#include <nativehelper/ScopedUtfChars.h> -#include <utils/Log.h> -#include <utils/String16.h> -#include <utils/misc.h> - -#include "jni_helper.h" - -namespace android { - -/* JNI Helpers for wifi_hal implementation */ - -JNIHelper::JNIHelper(JavaVM *vm) -{ - vm->AttachCurrentThread(&mEnv, NULL); - mVM = vm; -} - -JNIHelper::JNIHelper(JNIEnv *env) -{ - mVM = NULL; - mEnv = env; -} - -JNIHelper::~JNIHelper() -{ - if (mVM != NULL) { - // mVM->DetachCurrentThread(); /* 'attempting to detach while still running code' */ - mVM = NULL; /* not really required; but may help debugging */ - mEnv = NULL; /* not really required; but may help debugging */ - } -} - -jobject JNIHelper::newLocalRef(jobject obj) { - return mEnv->NewLocalRef(obj); -} - -void JNIHelper::deleteLocalRef(jobject obj) { - mEnv->DeleteLocalRef(obj); -} - -JNIObject<jbyteArray> JNIHelper::newByteArray(int num) { - return JNIObject<jbyteArray>(*this, mEnv->NewByteArray(num)); -} - -void JNIHelper::setByteArrayRegion(jbyteArray array, int from, int to, const jbyte *bytes) { - mEnv->SetByteArrayRegion(array, from, to, bytes); -} -}; // namespace android diff --git a/service/jni/jni_helper.h b/service/jni/jni_helper.h deleted file mode 100644 index 82b5c70043..0000000000 --- a/service/jni/jni_helper.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2016, 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. - */ - -#include <jni.h> - -namespace android { - -/* JNI Helpers for wifi_hal to WifiNative bridge implementation */ - -class JNIHelper; - -template<typename T> -class JNIObject { -protected: - JNIHelper &mHelper; - T mObj; -public: - JNIObject(JNIHelper &helper, T obj); - JNIObject(const JNIObject<T>& rhs); - virtual ~JNIObject(); - JNIHelper& getHelper() const { - return mHelper; - } - T get() const { - return mObj; - } - operator T() const { - return mObj; - } - bool isNull() const { - return mObj == NULL; - } - void release(); - T detach() { - T tObj = mObj; - mObj = NULL; - return tObj; - } - T clone(); - JNIObject<T>& operator = (const JNIObject<T>& rhs) { - release(); - mHelper = rhs.mHelper; - mObj = rhs.mObj; - return *this; - } - void print() { - ALOGD("holding %p", mObj); - } - -private: - template<typename T2> - JNIObject(const JNIObject<T2>& rhs); // NOLINT(implicit) -}; - -class JNIHelper { - JavaVM *mVM; - JNIEnv *mEnv; - -public : - explicit JNIHelper(JavaVM *vm); - explicit JNIHelper(JNIEnv *env); - ~JNIHelper(); - - /* helpers to deal with static members */ - JNIObject<jbyteArray> newByteArray(int num); - void setByteArrayRegion(jbyteArray array, int from, int to, const jbyte *bytes); - -private: - /* Jni wrappers */ - friend class JNIObject<jbyteArray>; - jobject newLocalRef(jobject obj); - void deleteLocalRef(jobject obj); -}; - -template<typename T> -JNIObject<T>::JNIObject(JNIHelper &helper, T obj) - : mHelper(helper), mObj(obj) -{ } - -template<typename T> -JNIObject<T>::JNIObject(const JNIObject<T>& rhs) - : mHelper(rhs.mHelper), mObj(NULL) -{ - mObj = (T)mHelper.newLocalRef(rhs.mObj); -} - -template<typename T> -JNIObject<T>::~JNIObject() { - release(); -} - -template<typename T> -void JNIObject<T>::release() -{ - if (mObj != NULL) { - mHelper.deleteLocalRef(mObj); - mObj = NULL; - } -} - -template<typename T> -T JNIObject<T>::clone() -{ - return mHelper.newLocalRef(mObj); -} -} - -#define THROW(env, message) (env).throwException(message, __LINE__) diff --git a/service/tests/wifitests/Android.bp b/service/tests/wifitests/Android.bp index e9bb540336..0b1bcda5aa 100644 --- a/service/tests/wifitests/Android.bp +++ b/service/tests/wifitests/Android.bp @@ -94,7 +94,6 @@ android_test { // These must be explicitly included because they are not normally accessible // from apps. jni_libs: [ - "libwifi-jni", "libbase", "libc++", "ld-android", diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java index 590db40309..a20bb98729 100644 --- a/service/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java +++ b/service/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java @@ -111,7 +111,6 @@ public class WifiDiagnosticsTest extends WifiBaseTest { }; when(mWifiNative.getRingBufferStatus()).thenReturn(ringBufferStatuses); - when(mWifiNative.readKernelLog()).thenReturn(""); when(mBuildProperties.isEngBuild()).thenReturn(false); when(mBuildProperties.isUserdebugBuild()).thenReturn(false); when(mBuildProperties.isUserBuild()).thenReturn(true); |