Quellcode durchsuchen

v1.0.0开发:集成msa sdk1.0.23

#Suyghur vor 3 Jahren
Ursprung
Commit
7b8e5685ff

+ 1 - 1
build.gradle

@@ -23,7 +23,7 @@ buildscript {
     }
     dependencies {
         classpath "com.android.tools.build:gradle:4.1.3"
-
+        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION"
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
     }

+ 10 - 4
demo/build.gradle

@@ -1,5 +1,6 @@
 plugins {
     id 'com.android.application'
+    id 'kotlin-android'
 }
 
 def keystorePropertiesFile = rootProject.file("keystore.properties")
@@ -11,7 +12,7 @@ android {
     buildToolsVersion BUILD_TOOLS_VERSION
 
     defaultConfig {
-        applicationId "com.qsgame.demo"
+        applicationId "com.yyxx.support.demo"
         minSdkVersion MIN_SDK_VERSION
         targetSdkVersion TARGET_SDK_VERSION
         versionCode 1
@@ -19,7 +20,7 @@ android {
 
         ndk {
             // 设置支持的SO库架构
-            abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
+            abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
         }
     }
 
@@ -34,13 +35,13 @@ android {
 
     buildTypes {
         debug {
-            minifyEnabled MINIFY_ENABLE
+            minifyEnabled false
             signingConfig signingConfigs.config
             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
         }
 
         release {
-            minifyEnabled MINIFY_ENABLE
+            minifyEnabled false
             signingConfig signingConfigs.config
             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
         }
@@ -64,8 +65,13 @@ android {
         sourceCompatibility JavaVersion.VERSION_1_8
         targetCompatibility JavaVersion.VERSION_1_8
     }
+
+    kotlinOptions {
+        jvmTarget = "1.8"
+    }
 }
 
 dependencies {
     implementation project(':library_support')
+    implementation files('libs/oaid_sdk_1.0.23.jar')
 }

BIN
demo/libs/oaid_sdk_1.0.23.jar


+ 23 - 1
demo/src/main/AndroidManifest.xml

@@ -1,12 +1,34 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
     package="com.yyxx.support.demo">
 
+    <!-- msa sdk -->
+    <uses-sdk tools:overrideLibrary="com.zui.opendeviceidlibrary" />
+    <!-- asus -->
+    <uses-permission android:name="com.asus.msa.SupplementaryDID.ACCESS" />
+    <!-- freeme -->
+    <uses-permission android:name="freemme.permission.msa" />
+    <!-- msa sdk -->
+
     <application
+        android:name=".DemoApplication"
         android:allowBackup="true"
         android:icon="@mipmap/ic_launcher"
         android:label="@string/app_name"
         android:supportsRtl="true"
-        android:theme="@style/AppTheme" />
+        android:theme="@style/AppTheme">
+
+        <activity
+            android:name=".DemoActivity"
+            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
+            android:launchMode="singleTask"
+            android:screenOrientation="portrait">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
 
 </manifest>

+ 17 - 0
demo/src/main/assets/supplierconfig.json

@@ -0,0 +1,17 @@
+{
+  "supplier":{
+    "vivo":{
+      "appid":"100215079"
+    },
+    "xiaomi":{
+
+    },
+    "huawei":{
+
+    },
+    "oppo":{
+
+    }
+  }
+
+}

+ 84 - 0
demo/src/main/java/com/yyxx/support/demo/DemoActivity.kt

@@ -0,0 +1,84 @@
+package com.yyxx.support.demo
+
+import android.app.Activity
+import android.os.Bundle
+import android.view.View
+import android.widget.Button
+import android.widget.LinearLayout
+import android.widget.ScrollView
+import android.widget.TextView
+import cn.yyxx.support.device.DeviceInfoUtils
+import cn.yyxx.support.hawkeye.LogUtils
+import cn.yyxx.support.msa.MsaDeviceIdsHandler
+
+/**
+ * @author #Suyghur.
+ * Created on 2021/04/23
+ */
+class DemoActivity : Activity(), View.OnClickListener {
+
+    private val events = mutableListOf(
+            Item(0, "00 获取MSA DeviceIds"),
+            Item(1, "111111"),
+            Item(2, "222222"),
+            Item(3, "333333")
+    )
+
+    private lateinit var textView: TextView
+    private val sb = StringBuilder()
+    private var hasReadIds = false
+
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+        initView()
+        initDeviceInfo()
+    }
+
+    private fun initView() {
+        val layout = LinearLayout(this)
+        layout.orientation = LinearLayout.VERTICAL
+        textView = TextView(this)
+        layout.addView(textView)
+        for (event in events) {
+            with(Button(this)) {
+                id = event.id
+                tag = event.id
+                text = event.name
+                setOnClickListener(this@DemoActivity)
+                layout.addView(this)
+            }
+        }
+        val scrollView = ScrollView(this)
+        scrollView.addView(layout)
+        setContentView(scrollView)
+    }
+
+    private fun initDeviceInfo() {
+        LogUtils.d("initDeviceInfo")
+        sb.append("Android ID : ").append(DeviceInfoUtils.getAndroidDeviceId(this)).append("\n")
+        sb.append("手机制造商 : ").append(DeviceInfoUtils.getDeviceManufacturer()).append("\n")
+        sb.append("手机品牌 : ").append(DeviceInfoUtils.getDeviceBrand()).append("\n")
+        sb.append("手机型号 : ").append(DeviceInfoUtils.getDeviceModel()).append("\n")
+        sb.append("CPU核数 : ").append(DeviceInfoUtils.getCpuCount()).append("\n")
+        sb.append("CPU架构 : ").append(DeviceInfoUtils.getCpuAbi()).append("\n")
+        sb.append("本机运行内存Ram : ").append(DeviceInfoUtils.getDeviceRam()).append("\n")
+        sb.append("本应用可用运行内存Ram : ").append(DeviceInfoUtils.getAppAvailRam(this)).append("\n")
+        textView.text = sb.toString()
+    }
+
+    override fun onClick(v: View?) {
+        v?.apply {
+            when (tag as Int) {
+                0 -> {
+                    if (!hasReadIds) {
+                        sb.append("OAID : ").append(MsaDeviceIdsHandler.oaid).append("\n")
+                        sb.append("VAID : ").append(MsaDeviceIdsHandler.vaid).append("\n")
+                        sb.append("AAID : ").append(MsaDeviceIdsHandler.aaid).append("\n")
+                        textView.text = sb.toString()
+                        hasReadIds = true
+                    }
+                }
+            }
+        }
+    }
+}

+ 29 - 0
demo/src/main/java/com/yyxx/support/demo/DemoApplication.kt

@@ -0,0 +1,29 @@
+package com.yyxx.support.demo
+
+import android.app.Application
+import android.content.Context
+import cn.yyxx.support.hawkeye.LogUtils
+import cn.yyxx.support.msa.MsaDeviceIdsHandler
+
+/**
+ * @author #Suyghur.
+ * Created on 2021/04/23
+ */
+class DemoApplication : Application() {
+
+    override fun attachBaseContext(base: Context?) {
+        super.attachBaseContext(base)
+        MsaDeviceIdsHandler.initMsaDeviceIds(this) { code, msg, ids ->
+            LogUtils.i("initMsaDeviceIds code : $code , msg : $msg")
+//            if (code == 0) {
+//                LogUtils.d("oaid : ${ids["oaid"]}")
+//                LogUtils.d("vaid : ${ids["vaid"]}")
+//                LogUtils.d("aaid : ${ids["aaid"]}")
+//            }
+        }
+    }
+
+    override fun onCreate() {
+        super.onCreate()
+    }
+}

+ 7 - 0
demo/src/main/java/com/yyxx/support/demo/Item.kt

@@ -0,0 +1,7 @@
+package com.yyxx.support.demo
+
+/**
+ * @author #Suyghur.
+ * Created on 2021/04/23
+ */
+class Item(val id: Int, val name: String)

BIN
demo/src/main/jniLibs/arm64-v8a/libsecsdk.so


BIN
demo/src/main/jniLibs/armeabi-v7a/libsecsdk.so


BIN
demo/src/main/jniLibs/armeabi/libsecsdk.so


BIN
demo/src/main/jniLibs/x86/libsecsdk.so


BIN
demo/src/main/jniLibs/x86_64/libsecsdk.so


BIN
demo/src/main/res/mipmap-xhdpi/ic_launcher.png


+ 1 - 1
library_support/build.gradle

@@ -42,7 +42,7 @@ android {
 
 dependencies {
     compileOnly files('libs/android-support-v4.jar')
-//    implementation 'com.android.support:support-annotations:28.0.0'
+    compileOnly files('libs/oaid_sdk_1.0.23.jar')
 }
 
 apply from: 'buildJar.gradle'

BIN
library_support/libs/oaid_sdk_1.0.23.jar


+ 3 - 0
library_support/proguard-rules.pro

@@ -114,7 +114,10 @@
 -keep class android.support.annotation.GuardedBy{*;}
 -keep class cn.yyxx.support.AppUtils{ public <fields>;public <methods>;}
 -keep class cn.yyxx.support.BeanUtils{ public <fields>;public <methods>;}
+-keep class cn.yyxx.support.device.DeviceInfoUtils{ public <fields>;public <methods>;}
+-keep class cn.yyxx.support.FileUtils{ public <fields>;public <methods>;}
 -keep class cn.yyxx.support.HostModelUtils{ public <fields>;public <methods>;}
 -keep class cn.yyxx.support.ResUtils{ public <fields>;public <methods>;}
+-keep class cn.yyxx.support.msa.**{ public <fields>; public <methods>;}
 -keep class cn.yyxx.support.hawkeye.**{ public <fields>; public <methods>;}
 -keep class cn.yyxx.support.volley.**{  public <fields>; public <methods>;}

+ 28 - 0
library_support/src/main/java/cn/yyxx/support/FileUtils.java

@@ -0,0 +1,28 @@
+package cn.yyxx.support;
+
+import java.io.FileReader;
+import java.io.Reader;
+
+/**
+ * @author #Suyghur.
+ * Created on 2021/04/23
+ */
+public class FileUtils {
+    public static String loadReaderAsString(Reader reader) throws Exception {
+        StringBuilder builder = new StringBuilder();
+        char[] buffer = new char[4096];
+        int readLength = reader.read(buffer);
+        while (readLength >= 0) {
+            builder.append(buffer, 0, readLength);
+            readLength = reader.read(buffer);
+        }
+        return builder.toString();
+    }
+
+    public static String loadFileAsString(String fileName) throws Exception {
+        FileReader reader = new FileReader(fileName);
+        String text = loadReaderAsString(reader);
+        reader.close();
+        return text;
+    }
+}

+ 340 - 0
library_support/src/main/java/cn/yyxx/support/device/DeviceInfoUtils.java

@@ -0,0 +1,340 @@
+package cn.yyxx.support.device;
+
+import android.annotation.SuppressLint;
+import android.app.ActivityManager;
+import android.content.Context;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.os.Build;
+import android.telephony.TelephonyManager;
+import android.text.TextUtils;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.lang.reflect.Method;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.Enumeration;
+
+import cn.yyxx.support.FileUtils;
+import cn.yyxx.support.hawkeye.LogUtils;
+
+/**
+ * @author #Suyghur.
+ * Created on 2021/04/23
+ */
+public class DeviceInfoUtils {
+
+    private static final int IMEI = 1000;
+    private static final int IMSI = 2000;
+    private static final int SIM = 3000;
+    private static final int SIM_OPERATOR = 4000;
+    private static final int SIM_OPERATOR_NAME = 5000;
+    private static final int NETWORK_OPERATOR = 6000;
+    private static final int NETWORK_OPERATOR_NAME = 7000;
+    private static final int DEVICE_SOFTWARE_VERSION = 8000;
+    private static final int PHONE_NUMBER = 9000;
+
+    @SuppressLint("MissingPermission")
+    private static String getTelephoneInfo(Context context, int type) {
+        String info = "";
+        try {
+            if (context == null) {
+                return info;
+            }
+            TelephonyManager phone = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+            if (phone != null) {
+                switch (type) {
+                    case IMEI:
+                        info = phone.getDeviceId();
+                        break;
+                    case IMSI:
+                        info = phone.getSubscriberId();
+                        break;
+                    case SIM:
+                        info = phone.getSimSerialNumber();
+                        break;
+                    case SIM_OPERATOR:
+                        info = phone.getSimOperator();
+                        break;
+                    case SIM_OPERATOR_NAME:
+                        info = phone.getSimOperatorName();
+                        break;
+                    case NETWORK_OPERATOR:
+                        info = phone.getNetworkOperator();
+                        break;
+                    case NETWORK_OPERATOR_NAME:
+                        info = phone.getNetworkOperatorName();
+                        break;
+                    case DEVICE_SOFTWARE_VERSION:
+                        info = phone.getDeviceSoftwareVersion();
+                        break;
+                    case PHONE_NUMBER:
+                        info = phone.getLine1Number();
+                        break;
+                }
+            }
+        } catch (Exception e) {
+            LogUtils.e("get phone info error: " + e.getLocalizedMessage());
+        }
+        return info;
+    }
+
+    /**
+     * 获取手机品牌
+     */
+    public static String getDeviceBrand() {
+        return Build.BRAND;
+    }
+
+    /**
+     * 获取手机型号
+     */
+    public static String getDeviceModel() {
+        return Build.MODEL;
+    }
+
+    /**
+     * 获取手机制造商
+     */
+    public static String getDeviceManufacturer() {
+        return Build.MANUFACTURER;
+    }
+
+    /**
+     * 获取手机号码
+     */
+    @SuppressLint("MissingPermission")
+    public static String getPhoneNumber(Context context) {
+        return getTelephoneInfo(context, PHONE_NUMBER);
+    }
+
+    /**
+     * 获取imei
+     */
+    public static String getImei(Context context) {
+        String imei = getTelephoneInfo(context, IMEI);
+        return TextUtils.isEmpty(imei) ? "0" : imei;
+    }
+
+    /**
+     * 获取imsi
+     */
+    public static String getImsi(Context context) {
+        return getTelephoneInfo(context, IMSI);
+    }
+
+
+    /**
+     * 获得手机sim
+     */
+    public static String getSim(Context context) {
+        return getTelephoneInfo(context, SIM);
+    }
+
+    /**
+     * 获取手机序列号
+     */
+    public static String getSerialNumber() {
+        String serial = "";
+        try {
+            Class<?> c = Class.forName("android.os.SystemProperties");
+            Method get = c.getMethod("get", String.class);
+            serial = (String) get.invoke(c, "ro.serialno");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return serial;
+    }
+
+    /**
+     * 获取安卓设备ID
+     */
+    public static String getAndroidDeviceId(Context context) {
+        String androidId = "";
+        if (context == null) {
+            return androidId;
+        }
+        androidId = android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
+        return androidId;
+    }
+
+    /**
+     * 获取cpu架构
+     */
+    public static String getCpuAbi() {
+        String[] abis;
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            abis = Build.SUPPORTED_ABIS;
+        } else {
+            abis = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
+        }
+        StringBuilder abiStr = new StringBuilder();
+        for (String abi : abis) {
+            abiStr.append(abi);
+            abiStr.append(',');
+        }
+        return abiStr.toString();
+    }
+
+    /**
+     * 获取cpu核数
+     */
+    public static String getCpuCount() {
+        return Runtime.getRuntime().availableProcessors() + "";
+    }
+
+    /**
+     * 获取手机运行内存ram
+     */
+    public static String getDeviceRam() {
+        String path = "/proc/meminfo";
+        String firstLine = null;
+        int totalRam = 0;
+        try {
+            FileReader fileReader = new FileReader(path);
+            BufferedReader br = new BufferedReader(fileReader, 8192);
+            firstLine = br.readLine().split("\\s+")[1];
+            br.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        if (firstLine != null) {
+            totalRam = (int) Math.ceil((Float.valueOf(Float.parseFloat(firstLine) / (1024 * 1024)).doubleValue()));
+        }
+        //返回1GB/2GB/3GB/4GB
+        return totalRam + "GB";
+    }
+
+    /**
+     * 获取应用可用运行内存Ram
+     */
+    public static String getAppAvailRam(Context context) {
+        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+        ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
+        am.getMemoryInfo(mi);
+        //mi.availMem
+        return String.valueOf(mi.availMem / 1024 / 1024);
+    }
+
+    /**
+     * 获得手机MAC
+     *
+     * @param context
+     * @return
+     */
+    public static String getMacAddress(Context context) {
+        String s = null;
+        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
+            s = getMacFromWifiInfo(context);
+        } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
+            s = getMacFromFile();
+        } else {
+            s = getMachineHardwareAddress();
+        }
+        if (TextUtils.isEmpty(s)) {
+            s = "";
+        }
+        return s.toLowerCase();
+    }
+
+    /**
+     * 6.0以上7.0以下获取mac
+     */
+    private static String getMacFromFile() {
+        String str = "";
+        String macSerial = "";
+        try {
+            Process pp = Runtime.getRuntime().exec("cat /sys/class/net/wlan0/address");
+            InputStreamReader ir = new InputStreamReader(pp.getInputStream());
+            LineNumberReader input = new LineNumberReader(ir);
+
+            for (; null != str; ) {
+                str = input.readLine();
+                if (str != null) {
+                    macSerial = str.trim();// 去空格
+                    break;
+                }
+            }
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        if ("".equals(macSerial)) {
+            try {
+                return FileUtils.loadFileAsString("/sys/class/net/eth0/address").toUpperCase().substring(0, 17);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+
+        }
+        return macSerial;
+    }
+
+    /**
+     * 6.0以下获取mac
+     */
+    private static String getMacFromWifiInfo(Context context) {
+        try {
+            WifiManager wifi = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
+            WifiInfo info = wifi.getConnectionInfo();
+            return info.getMacAddress();
+        } catch (Exception e) {
+            e.printStackTrace();
+            return "";
+        }
+    }
+
+
+    /**
+     * 7.0以上获取mac
+     * 获取设备HardwareAddress地址
+     */
+    public static String getMachineHardwareAddress() {
+        Enumeration<NetworkInterface> interfaces = null;
+        try {
+            interfaces = NetworkInterface.getNetworkInterfaces();
+        } catch (SocketException e) {
+            e.printStackTrace();
+        }
+        String hardWareAddress = null;
+        NetworkInterface iF = null;
+        if (interfaces == null) {
+            return null;
+        }
+        while (interfaces.hasMoreElements()) {
+            iF = interfaces.nextElement();
+            try {
+                if (!iF.getName().equalsIgnoreCase("wlan0")) {
+                    continue;
+                }
+                hardWareAddress = bytes2String(iF.getHardwareAddress());
+                if (hardWareAddress != null) {
+                    break;
+                }
+            } catch (SocketException e) {
+                e.printStackTrace();
+            }
+        }
+
+        return hardWareAddress;
+    }
+
+    /***
+     * byte转为String
+     */
+    private static String bytes2String(byte[] bytes) {
+        if (bytes == null || bytes.length == 0) {
+            return null;
+        }
+        StringBuilder buf = new StringBuilder();
+        for (byte b : bytes) {
+            buf.append(String.format("%02X:", b));
+        }
+        if (buf.length() > 0) {
+            buf.deleteCharAt(buf.length() - 1);
+        }
+        return buf.toString();
+    }
+}

+ 12 - 0
library_support/src/main/java/cn/yyxx/support/msa/IMsaDeviceIdsCallback.java

@@ -0,0 +1,12 @@
+package cn.yyxx.support.msa;
+
+import java.util.Map;
+
+/**
+ * @author #Suyghur.
+ * Created on 2021/04/23
+ */
+public interface IMsaDeviceIdsCallback {
+
+    void onIdsRead(int code, String msg, Map<String, String> ids);
+}

+ 65 - 0
library_support/src/main/java/cn/yyxx/support/msa/MsaDeviceIdsHandler.java

@@ -0,0 +1,65 @@
+package cn.yyxx.support.msa;
+
+import android.content.Context;
+
+import com.bun.miitmdid.core.ErrorCode;
+import com.bun.miitmdid.core.MdidSdkHelper;
+import com.bun.miitmdid.interfaces.IIdentifierListener;
+import com.bun.miitmdid.interfaces.IdSupplier;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import cn.yyxx.support.hawkeye.LogUtils;
+
+/**
+ * @author #Suyghur.
+ * Created on 2021/04/23
+ */
+public class MsaDeviceIdsHandler {
+
+    private static final String VERSION = "1.0.23";
+
+    public static String oaid = "";
+    public static String vaid = "";
+    public static String aaid = "";
+
+    public static void initMsaDeviceIds(Context context, final IMsaDeviceIdsCallback callback) {
+        LogUtils.i("attach msa sdk , version : " + VERSION);
+        int code = MdidSdkHelper.InitSdk(context, true, new IIdentifierListener() {
+            @Override
+            public void OnSupport(boolean isSupport, IdSupplier idSupplier) {
+                if (isSupport) {
+                    Map<String, String> ids = new HashMap<>();
+                    oaid = idSupplier.getOAID();
+                    vaid = idSupplier.getVAID();
+                    aaid = idSupplier.getAAID();
+                    ids.put("oaid", oaid);
+                    ids.put("vaid", vaid);
+                    ids.put("aaid", aaid);
+                    callback.onIdsRead(0, "获取MsaIds成功", ids);
+                } else {
+                    callback.onIdsRead(-1, "不支持的设备", null);
+                }
+            }
+        });
+
+        switch (code) {
+            case ErrorCode.INIT_ERROR_DEVICE_NOSUPPORT:
+                callback.onIdsRead(-1, "不支持的设备", null);
+                break;
+            case ErrorCode.INIT_ERROR_LOAD_CONFIGFILE:
+                callback.onIdsRead(-1, "加载配置文件出错", null);
+                break;
+            case ErrorCode.INIT_ERROR_MANUFACTURER_NOSUPPORT:
+                callback.onIdsRead(-1, "不支持的设备厂商", null);
+                break;
+            case ErrorCode.INIT_ERROR_RESULT_DELAY:
+                LogUtils.e("initMsaDeviceIds : 获取接口是异步的,结果会在回调中返回,回调执行的回调可能在工作线程");
+                break;
+            case ErrorCode.INIT_HELPER_CALL_ERROR:
+                callback.onIdsRead(-1, "反射调用出错", null);
+                break;
+        }
+    }
+}