|
|
@@ -1,15 +1,16 @@
|
|
|
package com.atmob.flutter_device;
|
|
|
|
|
|
import android.content.Context;
|
|
|
+import android.util.Log;
|
|
|
|
|
|
import com.atmob.device.AtmobDevices;
|
|
|
import com.atmob.device.DevicesResultCallback;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
-import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
import io.flutter.plugin.common.MethodCall;
|
|
|
import io.flutter.plugin.common.MethodChannel;
|
|
|
@@ -19,7 +20,7 @@ public class FlutterDeviceUtil {
|
|
|
|
|
|
public static void getDeviceInfo(Context applicationContext, MethodCall call, MethodChannel.Result result) {
|
|
|
AtmobDevices atmobDevices = AtmobDevices.get(applicationContext);
|
|
|
- Map<String,Object> deviceInfo = new HashMap<>();
|
|
|
+ Map<String, Object> deviceInfo = new HashMap<>();
|
|
|
/**
|
|
|
* String? packageName;
|
|
|
*
|
|
|
@@ -34,9 +35,6 @@ public class FlutterDeviceUtil {
|
|
|
* String? osVersion;
|
|
|
*
|
|
|
* //Android特有
|
|
|
- * String? oaid;
|
|
|
- *
|
|
|
- * String? aaid;
|
|
|
*
|
|
|
* String? androidId;
|
|
|
*
|
|
|
@@ -52,56 +50,60 @@ public class FlutterDeviceUtil {
|
|
|
*
|
|
|
* String? userAgent;
|
|
|
*/
|
|
|
- deviceInfo.put("packageName",atmobDevices.getPackageName());
|
|
|
- deviceInfo.put("appVersionName",atmobDevices.getVersionName());
|
|
|
- deviceInfo.put("appVersionCode",atmobDevices.getVersionCode());
|
|
|
- deviceInfo.put("brand",atmobDevices.getBrand());
|
|
|
- deviceInfo.put("model",atmobDevices.getModel());
|
|
|
- deviceInfo.put("osVersion",String.valueOf(atmobDevices.getOSVersion()));
|
|
|
+ deviceInfo.put("packageName", atmobDevices.getPackageName());
|
|
|
+ deviceInfo.put("appVersionName", atmobDevices.getVersionName());
|
|
|
+ deviceInfo.put("appVersionCode", atmobDevices.getVersionCode());
|
|
|
+ deviceInfo.put("brand", atmobDevices.getBrand());
|
|
|
+ deviceInfo.put("model", atmobDevices.getModel());
|
|
|
+ deviceInfo.put("osVersion", String.valueOf(atmobDevices.getOSVersion()));
|
|
|
+
|
|
|
+ deviceInfo.put("androidId", atmobDevices.getAndroidId());
|
|
|
+ deviceInfo.put("imei", atmobDevices.getIMEI());
|
|
|
+ deviceInfo.put("simImei0", atmobDevices.getSimIMEI0());
|
|
|
+ deviceInfo.put("simImei1", atmobDevices.getSimIMEI1());
|
|
|
+ deviceInfo.put("mac", atmobDevices.getMac());
|
|
|
+ deviceInfo.put("wifiName", atmobDevices.getSSID());
|
|
|
+ deviceInfo.put("userAgent", atmobDevices.getUA());
|
|
|
|
|
|
- ExecutorService executorService = Executors.newCachedThreadPool();
|
|
|
- CountDownLatch latch = new CountDownLatch(2);
|
|
|
+ result.success(deviceInfo);
|
|
|
+ }
|
|
|
|
|
|
- atmobDevices.getMdidOAID(executorService, new DevicesResultCallback<String>() {
|
|
|
+ public static void getOaid(Context applicationContext, MethodCall call, MethodChannel.Result result) {
|
|
|
+ AtmobDevices atmobDevices = AtmobDevices.get(applicationContext);
|
|
|
+ AtomicBoolean isCall = new AtomicBoolean(false);
|
|
|
+ atmobDevices.getMdidOAID(Executors.newCachedThreadPool(), new DevicesResultCallback<String>() {
|
|
|
@Override
|
|
|
public void onResult(String oaid) {
|
|
|
- deviceInfo.put("oaid", oaid);
|
|
|
- latch.countDown();
|
|
|
+ if (isCall.compareAndSet(false, true)) {
|
|
|
+ result.success(oaid);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onError(Exception e) {
|
|
|
- latch.countDown();
|
|
|
+ if (isCall.compareAndSet(false, true)) {
|
|
|
+ result.error("-1", e.getMessage(), null);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
- atmobDevices.getMdidAAID(executorService, new DevicesResultCallback<String>() {
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void getAaid(Context applicationContext, MethodCall call, MethodChannel.Result result) {
|
|
|
+ AtmobDevices atmobDevices = AtmobDevices.get(applicationContext);
|
|
|
+ AtomicBoolean isCall = new AtomicBoolean(false);
|
|
|
+ atmobDevices.getGoogleAAID(Executors.newCachedThreadPool(), new DevicesResultCallback<String>() {
|
|
|
@Override
|
|
|
public void onResult(String aaid) {
|
|
|
- deviceInfo.put("aaid", aaid);
|
|
|
- latch.countDown();
|
|
|
+ if (isCall.compareAndSet(false, true)) {
|
|
|
+ result.success(aaid);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onError(Exception e) {
|
|
|
- latch.countDown();
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- deviceInfo.put("androidId",atmobDevices.getAndroidId());
|
|
|
- deviceInfo.put("imei",atmobDevices.getIMEI());
|
|
|
- deviceInfo.put("simImei0",atmobDevices.getSimIMEI0());
|
|
|
- deviceInfo.put("simImei1",atmobDevices.getSimIMEI1());
|
|
|
- deviceInfo.put("mac",atmobDevices.getMac());
|
|
|
- deviceInfo.put("wifiName",atmobDevices.getSSID());
|
|
|
- deviceInfo.put("userAgent",atmobDevices.getUA());
|
|
|
-
|
|
|
- executorService.submit(() -> {
|
|
|
- try {
|
|
|
- latch.await();
|
|
|
- result.success(deviceInfo);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- e.printStackTrace();
|
|
|
- result.error("error","get device info error",null);
|
|
|
+ if (isCall.compareAndSet(false, true)) {
|
|
|
+ result.error("-1", e.getMessage(), null);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
}
|