diff --git a/app/build.gradle b/app/build.gradle index 5902dc0..06580f6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -58,7 +58,7 @@ dependencies { } monitorPlugin { whiteList = [ - //"com.peakmain.asmactualcombat.utils.TestUtils", + "com.peakmain.asmactualcombat.utils.TestUtils", "com.peakmain.plugin" ] methodStatus = 1 diff --git a/app/src/main/java/com/peakmain/asmactualcombat/App.java b/app/src/main/java/com/peakmain/asmactualcombat/App.java index f7c3d8e..d924fe3 100644 --- a/app/src/main/java/com/peakmain/asmactualcombat/App.java +++ b/app/src/main/java/com/peakmain/asmactualcombat/App.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.net.wifi.ScanResult; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.telephony.SubscriptionInfo; @@ -87,29 +88,14 @@ public String onReplaceMethodListener(int telephoneState, TelephonyManager manag } @Override - public String onReplaceMethodListener(int wifiInfoState, WifiInfo wifiInfo) { - switch (wifiInfoState) { - case SensorsDataConstants.GET_MAC_ADDRESS: - LogUtils.e("替换GET_MAC_ADDRESS"); - break; - case SensorsDataConstants.GET_SSID: - LogUtils.e("替换GET_SSID"); - break; - case SensorsDataConstants.GET_BSSID: - LogUtils.e("替换GET_SSIDGET_BSSID"); - break; - case SensorsDataConstants.GET_IP_ADDRESS: - LogUtils.e("替换GET_IP_ADDRESS"); - break; - default: - break; - } - return ""; + public WifiInfo onReplaceMethodListener(WifiManager wifiManager) { + LogUtils.e("替换WifiManager"); + return null; } @Override - public WifiInfo onReplaceMethodListener(WifiManager wifiManager) { - LogUtils.e("替换WifiManager"); + public List onReplaceWifiManagerMethodListener(WifiManager wifiManager) { + LogUtils.e("替换onReplaceWifiManagerMethodListener"); return null; } diff --git a/plugin/src/main/groovy/com/peakmain/analytics/plugin/transform/MonitorAnalyticsTransform.groovy b/plugin/src/main/groovy/com/peakmain/analytics/plugin/transform/MonitorAnalyticsTransform.groovy index 858b149..82446f4 100644 --- a/plugin/src/main/groovy/com/peakmain/analytics/plugin/transform/MonitorAnalyticsTransform.groovy +++ b/plugin/src/main/groovy/com/peakmain/analytics/plugin/transform/MonitorAnalyticsTransform.groovy @@ -51,25 +51,27 @@ class MonitorAnalyticsTransform { * 过滤不需要修改的class */ protected static boolean isShouldModify(String className) { + boolean isShouldModify = false if (!isAndroidGenerated(className)) { for (pkgName in special) { if (className.startsWith(pkgName)) { return true } } - } else { + isShouldModify = true if (!isLeanback(className)) { for (pkgName in exclude) { if (className.startsWith(pkgName)) { - return false + isShouldModify = false + break } } } } - return true + return isShouldModify } - private static boolean isLeanback(String className) { + private static boolean isLeanback(String className) { return className.startsWith("android.support.v17.leanback") || className.startsWith("androidx.leanback") } @@ -81,12 +83,12 @@ class MonitorAnalyticsTransform { className.contains('BuildConfig.class') } - static File modifyClassFile(File dir, File classFile, File tempDir,MonitorConfig monitorConfig) { + static File modifyClassFile(File dir, File classFile, File tempDir, MonitorConfig monitorConfig) { File modified = null try { String className = path2ClassName(classFile.absolutePath.replace(dir.absolutePath + File.separator, "")) byte[] sourceClassBytes = IOUtils.toByteArray(new FileInputStream(classFile)) - byte[] modifiedClassBytes = modifyClass(sourceClassBytes,monitorConfig) + byte[] modifiedClassBytes = modifyClass(sourceClassBytes, monitorConfig) if (modifiedClassBytes) { modified = new File(tempDir, className.replace('.', '') + '.class') if (modified.exists()) { @@ -102,15 +104,15 @@ class MonitorAnalyticsTransform { return modified } - private static byte[] modifyClass(byte[] srcClass,MonitorConfig monitorConfig) throws IOException { + private static byte[] modifyClass(byte[] srcClass, MonitorConfig monitorConfig) throws IOException { ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS) - PeakmainVisitor classVisitor = new PeakmainVisitor(classWriter,monitorConfig) + PeakmainVisitor classVisitor = new PeakmainVisitor(classWriter, monitorConfig) ClassReader cr = new ClassReader(srcClass) cr.accept(classVisitor, ClassReader.SKIP_FRAMES) return classWriter.toByteArray() } - static File modifyJar(File jarFile, File tempDir, boolean nameHex,MonitorConfig monitorConfig) { + static File modifyJar(File jarFile, File tempDir, boolean nameHex, MonitorConfig monitorConfig) { /** * 读取原 jar */ @@ -128,7 +130,7 @@ class MonitorAnalyticsTransform { Enumeration enumeration = file.entries() while (enumeration.hasMoreElements()) { JarEntry jarEntry = (JarEntry) enumeration.nextElement() - InputStream inputStream = null + InputStream inputStream try { inputStream = file.getInputStream(jarEntry) } catch (Exception e) { @@ -147,7 +149,7 @@ class MonitorAnalyticsTransform { if (entryName.endsWith(".class")) { className = entryName.replace(Matcher.quoteReplacement(File.separator), ".").replace(".class", "") if (isShouldModify(className)) { - modifiedClassBytes = modifyClass(sourceClassBytes,monitorConfig) + modifiedClassBytes = modifyClass(sourceClassBytes, monitorConfig) } } if (modifiedClassBytes == null) { @@ -161,6 +163,7 @@ class MonitorAnalyticsTransform { file.close() return outputJar } + static String path2ClassName(String pathName) { pathName.replace(File.separator, ".").replace(".class", "") } diff --git a/plugin/src/main/groovy/com/peakmain/analytics/plugin/transform/MonitorTransform.groovy b/plugin/src/main/groovy/com/peakmain/analytics/plugin/transform/MonitorTransform.groovy index d94d522..6fad196 100644 --- a/plugin/src/main/groovy/com/peakmain/analytics/plugin/transform/MonitorTransform.groovy +++ b/plugin/src/main/groovy/com/peakmain/analytics/plugin/transform/MonitorTransform.groovy @@ -4,6 +4,7 @@ import com.android.build.api.transform.* import com.android.build.gradle.internal.pipeline.TransformManager import com.android.ide.common.internal.WaitableExecutor import com.peakmain.analytics.plugin.ext.MonitorConfig +import com.peakmain.analytics.plugin.utils.log.Logger import groovy.io.FileType import org.apache.commons.codec.digest.DigestUtils import org.apache.commons.io.FileUtils @@ -68,7 +69,7 @@ class MonitorTransform extends Transform { @Override void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException { super.transform(transformInvocation) - _transform(transformInvocation.context, transformInvocation.inputs, transformInvocation.outputProvider) + _transform(transformInvocation.context, transformInvocation.inputs, transformInvocation.outputProvider, transformInvocation.isIncremental()) } /** * @@ -76,10 +77,12 @@ class MonitorTransform extends Transform { * @param inputs 有两种类型,一种是目录,一种是 jar 包,要分开遍历 * @param outputProvider 输出路径 */ - void _transform(Context context, Collection inputs, TransformOutputProvider outputProvider) throws IOException, TransformException, InterruptedException { + void _transform(Context context, Collection inputs, + TransformOutputProvider outputProvider, boolean isIncremental) + throws IOException, TransformException, InterruptedException { println(monitorConfig.toString()) long startTime = System.currentTimeMillis() - if (!incremental) { + if (!isIncremental) { //不是增量更新删除所有的outputProvider outputProvider.deleteAll() } @@ -91,12 +94,12 @@ class MonitorTransform extends Transform { waitableExecutor.execute(new Callable() { @Override Object call() throws Exception { - handleDirectoryInput(context, directoryInput, outputProvider,monitorConfig) + handleDirectoryInput(context, directoryInput, outputProvider, monitorConfig,isIncremental) return null } }) } else { - handleDirectoryInput(context, directoryInput, outputProvider,monitorConfig) + handleDirectoryInput(context, directoryInput, outputProvider, monitorConfig,isIncremental) } } // 遍历jar 第三方引入的 class @@ -105,12 +108,12 @@ class MonitorTransform extends Transform { waitableExecutor.execute(new Callable() { @Override Object call() throws Exception { - handleJarInput(context,jarInput, outputProvider,monitorConfig) + handleJarInput(context, jarInput, outputProvider, monitorConfig,isIncremental) return null } }) } else { - handleJarInput(context,jarInput, outputProvider,monitorConfig) + handleJarInput(context, jarInput, outputProvider, monitorConfig,isIncremental) } } } @@ -120,36 +123,97 @@ class MonitorTransform extends Transform { println("[MonitorTransform]: 此次编译共耗时:${System.currentTimeMillis() - startTime}毫秒") } - void handleDirectoryInput(Context context, DirectoryInput directoryInput, TransformOutputProvider outputProvider,MonitorConfig monitorConfig) { - - File dest = outputProvider.getContentLocation(directoryInput.name, directoryInput.contentTypes, directoryInput.scopes, Format.DIRECTORY) + void handleDirectoryInput(Context context, DirectoryInput directoryInput, TransformOutputProvider outputProvider, MonitorConfig monitorConfig,boolean isIncremental) { File dir = directoryInput.file - if (dir) { - HashMap modifyMap = new HashMap<>() - dir.traverse(type: FileType.FILES, nameFilter: ~/.*\.class/) { - File classFile -> - if (MonitorAnalyticsTransform.isShouldModify(classFile.name)) { - File modified = MonitorAnalyticsTransform.modifyClassFile(dir, classFile, context.getTemporaryDir(),monitorConfig) + File dest = outputProvider.getContentLocation(directoryInput.getName(), + directoryInput.getContentTypes(), directoryInput.getScopes(), + Format.DIRECTORY) + FileUtils.forceMkdir(dest) + String srcDirPath = dir.absolutePath + String destDirPath = dest.absolutePath + if (isIncremental) { + Map fileStatusMap = directoryInput.getChangedFiles() + for (Map.Entry changedFile : fileStatusMap.entrySet()) { + Status status = changedFile.getValue() + File inputFile = changedFile.getKey() + String destFilePath = inputFile.absolutePath.replace(srcDirPath, destDirPath) + File destFile = new File(destFilePath) + switch (status) { + case Status.NOTCHANGED: + break + case Status.REMOVED: + Logger.info("目录 status = $status:$inputFile.absolutePath") + if (destFile.exists()) { + //noinspection ResultOfMethodCallIgnored + destFile.delete() + } + break + case Status.ADDED: + case Status.CHANGED: + Logger.info("目录 status = $status:$inputFile.absolutePath") + File modified = MonitorAnalyticsTransform.modifyClassFile(dir, inputFile, context.getTemporaryDir(),monitorConfig) + if (destFile.exists()) { + destFile.delete() + } if (modified != null) { - String ke = classFile.absolutePath.replace(dir.absolutePath, "") - modifyMap.put(ke, modified) + FileUtils.copyFile(modified, destFile) + modified.delete() + } else { + FileUtils.copyFile(inputFile, destFile) } - } + break + default: + break + } } - FileUtils.copyDirectory(directoryInput.file, dest) - modifyMap.entrySet().each { - Map.Entry en -> - File target = new File(dest.absolutePath + en.getKey()) - if (target.exists()) { - target.delete() - } - FileUtils.copyFile(en.getValue(), target) - en.getValue().delete() + }else { + FileUtils.copyDirectory(dir, dest) + dir.traverse(type: FileType.FILES, nameFilter: ~/.*\.class/) { + File inputFile -> + forEachDir(dir, inputFile, context, srcDirPath, destDirPath) } } + + } + void forEachDir(File dir, File inputFile, Context context, String srcDirPath, String destDirPath) { + File modified = MonitorAnalyticsTransform.modifyClassFile(dir, inputFile, context.getTemporaryDir(),monitorConfig) + if (modified != null) { + File target = new File(inputFile.absolutePath.replace(srcDirPath, destDirPath)) + if (target.exists()) { + target.delete() + } + FileUtils.copyFile(modified, target) + modified.delete() + } } + void handleJarInput(Context context, JarInput jarInput, TransformOutputProvider outputProvider, MonitorConfig monitorConfig,boolean isIncremental) { + //获得输出文件 + File destFile = outputProvider.getContentLocation(jarInput.name, jarInput.contentTypes, jarInput.scopes, Format.JAR) + if (isIncremental) { + Status status = jarInput.getStatus() + switch (status) { + case Status.NOTCHANGED: + break + case Status.ADDED: + case Status.CHANGED: + Logger.info("jar status = $status:$destFile.absolutePath") + transformJar(context,jarInput, outputProvider, monitorConfig) + break + case Status.REMOVED: + Logger.info("jar status = $status:$destFile.absolutePath") + if (destFile.exists()) { + FileUtils.forceDelete(destFile) + } + break + default: + break + } + } else { + transformJar(context,jarInput, outputProvider, monitorConfig) + } - void handleJarInput(Context context,JarInput jarInput, TransformOutputProvider outputProvider,MonitorConfig monitorConfig) { + } + void transformJar(Context context,JarInput jarInput,TransformOutputProvider outputProvider,MonitorConfig monitorConfig1) { String destName = jarInput.file.name /**截取文件路径的 md5 值重命名输出文件,因为可能同名,会覆盖*/ @@ -161,7 +225,7 @@ class MonitorTransform extends Transform { /** 获得输出文件*/ File dest = outputProvider.getContentLocation(destName + "_" + hexName, jarInput.contentTypes, jarInput.scopes, Format.JAR) - def modifiedJar = MonitorAnalyticsTransform.modifyJar(jarInput.file, context.getTemporaryDir(), true,monitorConfig) + def modifiedJar = MonitorAnalyticsTransform.modifyJar(jarInput.file, context.getTemporaryDir(), true, monitorConfig) if (modifiedJar == null) { modifiedJar = jarInput.file } diff --git a/plugin/src/main/groovy/com/peakmain/analytics/plugin/utils/MethodFieldUtils.groovy b/plugin/src/main/groovy/com/peakmain/analytics/plugin/utils/MethodFieldUtils.groovy index 4dac879..cd918bf 100644 --- a/plugin/src/main/groovy/com/peakmain/analytics/plugin/utils/MethodFieldUtils.groovy +++ b/plugin/src/main/groovy/com/peakmain/analytics/plugin/utils/MethodFieldUtils.groovy @@ -3,7 +3,7 @@ package com.peakmain.analytics.plugin.utils import org.objectweb.asm.Opcodes class MethodFieldUtils { - public static final String PLUGIN_VERSION = "1.0.8" + public static final String PLUGIN_VERSION = "1.0.9" enum StatusEnum { METHOD_STATE_NORMAL(0), METHOD_STATE_REPLACE(1) diff --git a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-groovydoc.jar b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-groovydoc.jar index c011d02..c27da55 100644 Binary files a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-groovydoc.jar and b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-groovydoc.jar differ diff --git a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-groovydoc.jar.md5 b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-groovydoc.jar.md5 index 61883cf..0792b6b 100644 --- a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-groovydoc.jar.md5 +++ b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-groovydoc.jar.md5 @@ -1 +1 @@ -b4c17a7fd0b505c4dc894880d98f27cd \ No newline at end of file +fd77a7a0540b0878f100c98ca65a69d1 \ No newline at end of file diff --git a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-groovydoc.jar.sha1 b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-groovydoc.jar.sha1 index beb1221..efdf694 100644 --- a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-groovydoc.jar.sha1 +++ b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-groovydoc.jar.sha1 @@ -1 +1 @@ -137e1ee3b23a4079e5919c42ea42c3eea0c29069 \ No newline at end of file +d43f5bfd21977d58746d7b8f3b1ac0ad1a7b10bd \ No newline at end of file diff --git a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-javadoc.jar b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-javadoc.jar index e40b5a5..4f7c4fb 100644 Binary files a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-javadoc.jar and b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-javadoc.jar differ diff --git a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-javadoc.jar.md5 b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-javadoc.jar.md5 index d018456..b5a6151 100644 --- a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-javadoc.jar.md5 +++ b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-javadoc.jar.md5 @@ -1 +1 @@ -f408535cd0f2cea5899204f98c7b5e9b \ No newline at end of file +672e91d539a1b015d1a5f93e252997d4 \ No newline at end of file diff --git a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-javadoc.jar.sha1 b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-javadoc.jar.sha1 index eec5196..939e701 100644 --- a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-javadoc.jar.sha1 +++ b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-javadoc.jar.sha1 @@ -1 +1 @@ -5a08f219ef3f743b0862047a6a203610fbc26f8e \ No newline at end of file +3e55508966d0714ba5e6d7bdc38993b0fe7bdd12 \ No newline at end of file diff --git a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-sources.jar b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-sources.jar index 3783e78..9a2d3b7 100644 Binary files a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-sources.jar and b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-sources.jar differ diff --git a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-sources.jar.md5 b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-sources.jar.md5 index dce3d25..dab5bb1 100644 --- a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-sources.jar.md5 +++ b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-sources.jar.md5 @@ -1 +1 @@ -79995d67cd36046edfcb9139d9b2345d \ No newline at end of file +6fc84fdd20111cd7a574e2a6706a19d0 \ No newline at end of file diff --git a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-sources.jar.sha1 b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-sources.jar.sha1 index 930fa97..577ba21 100644 --- a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-sources.jar.sha1 +++ b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0-sources.jar.sha1 @@ -1 +1 @@ -98401e6af6769b357c21a838321b6797ee62c7e7 \ No newline at end of file +3f9e42b7cb5cd1b8224c0e0c6f891f7128e006b6 \ No newline at end of file diff --git a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0.jar b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0.jar index 505d7df..fdc865b 100644 Binary files a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0.jar and b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0.jar differ diff --git a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0.jar.md5 b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0.jar.md5 index 568dcdb..0a7d391 100644 --- a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0.jar.md5 +++ b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0.jar.md5 @@ -1 +1 @@ -23c16c1a1bd5ef8e30fbda3d15775866 \ No newline at end of file +52967815474cef07778ea4f48610d6e0 \ No newline at end of file diff --git a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0.jar.sha1 b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0.jar.sha1 index 86171f8..8f77c0b 100644 --- a/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0.jar.sha1 +++ b/repo/com/peakmain/android.plugin/1.0.0/android.plugin-1.0.0.jar.sha1 @@ -1 +1 @@ -8b3de2a58c940a1bf96b8f9fdc57d189d270f13c \ No newline at end of file +bfef381a9258fc2390f4ae21d5e4b2a5a81a09af \ No newline at end of file diff --git a/repo/com/peakmain/android.plugin/maven-metadata.xml b/repo/com/peakmain/android.plugin/maven-metadata.xml index 0d13227..0f3416f 100644 --- a/repo/com/peakmain/android.plugin/maven-metadata.xml +++ b/repo/com/peakmain/android.plugin/maven-metadata.xml @@ -7,6 +7,6 @@ 1.0.0 - 20220524013406 + 20220524074110 diff --git a/repo/com/peakmain/android.plugin/maven-metadata.xml.md5 b/repo/com/peakmain/android.plugin/maven-metadata.xml.md5 index 898452d..a4b1c16 100644 --- a/repo/com/peakmain/android.plugin/maven-metadata.xml.md5 +++ b/repo/com/peakmain/android.plugin/maven-metadata.xml.md5 @@ -1 +1 @@ -6d9d64fa6fd79490f4dcbef88761e8a5 \ No newline at end of file +d80c19aaad554188a998e5bc89e7b0d1 \ No newline at end of file diff --git a/repo/com/peakmain/android.plugin/maven-metadata.xml.sha1 b/repo/com/peakmain/android.plugin/maven-metadata.xml.sha1 index 483884f..3c530b4 100644 --- a/repo/com/peakmain/android.plugin/maven-metadata.xml.sha1 +++ b/repo/com/peakmain/android.plugin/maven-metadata.xml.sha1 @@ -1 +1 @@ -c39cd021c6cf90315f8cefb0ca2e010e233528e2 \ No newline at end of file +44f0f57831684c02f4a9c03dfd88eccf74f2d8e5 \ No newline at end of file diff --git a/sdk/src/main/java/com/peakmain/sdk/interfaces/OnReplaceMethodListener.java b/sdk/src/main/java/com/peakmain/sdk/interfaces/OnReplaceMethodListener.java index f69367a..e7982b9 100644 --- a/sdk/src/main/java/com/peakmain/sdk/interfaces/OnReplaceMethodListener.java +++ b/sdk/src/main/java/com/peakmain/sdk/interfaces/OnReplaceMethodListener.java @@ -3,6 +3,7 @@ import android.content.ContentResolver; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.net.wifi.ScanResult; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.telephony.SubscriptionInfo; @@ -21,10 +22,11 @@ public interface OnReplaceMethodListener { String onReplaceMethodListener(@SensorsDataConstants.TELEPHONY_STATE int telephoneState, TelephonyManager manager, int slotIndex); - String onReplaceMethodListener(@SensorsDataConstants.WIFI_STATE int wifiInfoState, WifiInfo wifiInfo); WifiInfo onReplaceMethodListener(WifiManager wifiManager); + List onReplaceWifiManagerMethodListener(WifiManager wifiManager); + String onReplaceMethodListener(SubscriptionInfo subscriptionInfo); List onReplaceMethodListener(PackageManager manager); diff --git a/sdk/src/main/java/com/peakmain/sdk/utils/ReplaceMethodUtils.java b/sdk/src/main/java/com/peakmain/sdk/utils/ReplaceMethodUtils.java index fc257c8..d6986f3 100644 --- a/sdk/src/main/java/com/peakmain/sdk/utils/ReplaceMethodUtils.java +++ b/sdk/src/main/java/com/peakmain/sdk/utils/ReplaceMethodUtils.java @@ -8,7 +8,6 @@ import android.net.wifi.WifiManager; import android.telephony.SubscriptionInfo; import android.telephony.TelephonyManager; -import android.text.TextUtils; import com.peakmain.sdk.constants.SensorsDataConstants; import com.peakmain.sdk.interfaces.OnReplaceMethodListener; @@ -120,37 +119,7 @@ public static String getSimSerialNumber(TelephonyManager manager, int subId) { return ""; } - public static String getMacAddress(WifiInfo wifiInfo) { - if (getInstance().mOnReplaceMethodListener != null) { - return getInstance().mOnReplaceMethodListener.onReplaceMethodListener(SensorsDataConstants.GET_MAC_ADDRESS, wifiInfo); - } - return ""; - } - - public static String getSSID(WifiInfo wifiInfo) { - if (getInstance().mOnReplaceMethodListener != null) { - return getInstance().mOnReplaceMethodListener.onReplaceMethodListener( - SensorsDataConstants.GET_SSID, wifiInfo); - } - return ""; - } - - public static String getBSSID(WifiInfo wifiInfo) { - if (getInstance().mOnReplaceMethodListener != null) { - return getInstance().mOnReplaceMethodListener.onReplaceMethodListener( - SensorsDataConstants.GET_BSSID, wifiInfo); - } - return ""; - } - public static int getIpAddress(WifiInfo wifiInfo) { - if (getInstance().mOnReplaceMethodListener != null) { - String ipAddressStr = getInstance().mOnReplaceMethodListener.onReplaceMethodListener( - SensorsDataConstants.GET_SSID, wifiInfo); - return !TextUtils.isEmpty(ipAddressStr) ? Integer.parseInt(ipAddressStr) : -1; - } - return -1; - } public static WifiInfo getConnectionInfo(WifiManager wifiManager) { if (getInstance().mOnReplaceMethodListener != null) { @@ -183,7 +152,9 @@ public static String getString(ContentResolver resolver, String name) { } public static List getScanResults(WifiManager wifiManager) { - + if (getInstance().mOnReplaceMethodListener != null) { + return getInstance().mOnReplaceMethodListener.onReplaceWifiManagerMethodListener(wifiManager); + } return new ArrayList<>(); }