修改id获取方式
This commit is contained in:
parent
770c98d3cc
commit
288de5f8b6
@ -1,8 +1,5 @@
|
||||
package com.cege.games.release;
|
||||
|
||||
import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
|
||||
import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
|
||||
|
||||
import android.Manifest;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
@ -15,7 +12,6 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
import android.view.Window;
|
||||
import android.widget.Toast;
|
||||
@ -24,8 +20,6 @@ import androidx.annotation.MainThread;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
import androidx.biometric.BiometricManager;
|
||||
import androidx.biometric.BiometricPrompt;
|
||||
import androidx.browser.customtabs.CustomTabsIntent;
|
||||
import androidx.core.app.ActivityOptionsCompat;
|
||||
|
||||
@ -35,7 +29,6 @@ import com.bytedance.sdk.open.tiktok.authorize.model.Authorization;
|
||||
import com.bytedance.sdk.open.tiktok.base.MediaContent;
|
||||
import com.bytedance.sdk.open.tiktok.base.VideoObject;
|
||||
import com.bytedance.sdk.open.tiktok.share.Share;
|
||||
import com.cege.games.release.activity.BiometricActivity;
|
||||
import com.cege.games.release.activity.CustomCaptureActivity;
|
||||
import com.cege.games.release.activity.WebPageActivity;
|
||||
import com.cege.games.release.apple.AppleLoginActivity;
|
||||
@ -64,11 +57,7 @@ import com.jc.jcfw.JcSDK;
|
||||
import com.jc.jcfw.appauth.AuthStateManager;
|
||||
import com.jc.jcfw.appauth.JConfiguration;
|
||||
import com.jc.jcfw.google.PayClient;
|
||||
import com.jc.jcfw.security.BiometricHelper;
|
||||
import com.jc.jcfw.security.CryptographyManager;
|
||||
import com.jc.jcfw.security.CryptographyManagerImpl;
|
||||
import com.jc.jcfw.security.EncryptedData;
|
||||
import com.jc.jcfw.util.Installation;
|
||||
import com.jc.jcfw.util.IDUtils;
|
||||
import com.jc.jcfw.util.JsonUtils;
|
||||
import com.king.zxing.CameraScan;
|
||||
import com.king.zxing.util.CodeUtils;
|
||||
@ -105,8 +94,6 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
|
||||
import pub.devrel.easypermissions.AfterPermissionGranted;
|
||||
import pub.devrel.easypermissions.EasyPermissions;
|
||||
|
||||
@ -211,9 +198,9 @@ public class MainActivity extends UnityPlayerActivity
|
||||
PayClient payClient = PayClient.getInstance();
|
||||
payClient.init(this);
|
||||
accountManager = AccountManager.get(this.getApplicationContext());
|
||||
String id = Installation.id(this);
|
||||
String id = IDUtils.id(this);
|
||||
Log.i(TAG, "custom id:: " + id);
|
||||
Log.i(TAG, "build info::" + Installation.getBuildInfo());
|
||||
Log.i(TAG, "build info::" + IDUtils.getBuildInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
237
app/src/com/jc/jcfw/util/IDUtils.java
Normal file
237
app/src/com/jc/jcfw/util/IDUtils.java
Normal file
@ -0,0 +1,237 @@
|
||||
package com.jc.jcfw.util;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
public class IDUtils {
|
||||
private static String sID = null;
|
||||
private static final String INSTALLATION = "INSTALLATION";
|
||||
|
||||
public synchronized static String id(Context context) {
|
||||
if (sID == null) {
|
||||
File installation = new File(context.getFilesDir(), INSTALLATION);
|
||||
try {
|
||||
if (!installation.exists())
|
||||
writeInstallationFile(installation);
|
||||
sID = readInstallationFile(installation);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return sID;
|
||||
}
|
||||
|
||||
private static String readInstallationFile(File installation) throws IOException {
|
||||
RandomAccessFile f = new RandomAccessFile(installation, "r");
|
||||
byte[] bytes = new byte[(int) f.length()];
|
||||
f.readFully(bytes);
|
||||
f.close();
|
||||
return new String(bytes);
|
||||
}
|
||||
|
||||
private static void writeInstallationFile(File installation) throws IOException {
|
||||
FileOutputStream out = new FileOutputStream(installation);
|
||||
String id = UUID.randomUUID().toString();
|
||||
out.write(id.getBytes());
|
||||
out.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Device Id
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
// @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
|
||||
// public static String getDeviceId(Context context) {
|
||||
// if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
|
||||
// TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
// String deviceId = telephonyManager.getDeviceId();
|
||||
// return deviceId;
|
||||
// }
|
||||
// return "";
|
||||
// }
|
||||
|
||||
/**
|
||||
* 通过系统接口,获取Wifi Mac地址,适用于6.0以下版本
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
// @SuppressLint("HardwareIds")
|
||||
// public static String getWifiMacAddress(Context context) {
|
||||
// WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
// WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||
// return wifiInfo.getMacAddress();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 通过扫描网络接口,获取Wifi Mac地址,适用于6.0及以上版本
|
||||
// *
|
||||
// * @return
|
||||
// * @throws SocketException
|
||||
// */
|
||||
// public static String getWifiMacAddress() throws SocketException {
|
||||
// StringBuilder wifiMacAddressBuild = new StringBuilder();
|
||||
// Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
||||
// while (interfaces.hasMoreElements()) {
|
||||
// NetworkInterface anInterface = interfaces.nextElement();
|
||||
// if (!"wlan0".equals(anInterface.getName())) {
|
||||
// //测试发现wlan0才是正确的Wifi Mac地址
|
||||
// continue;
|
||||
// }
|
||||
// byte[] address = anInterface.getHardwareAddress();
|
||||
// if (address == null || address.length == 0) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// StringBuilder builder = new StringBuilder();
|
||||
// for (byte b : address) {
|
||||
// builder.append(String.format("%02X:", b));
|
||||
// }
|
||||
// if (builder.length() > 0) {
|
||||
// builder.deleteCharAt(builder.length() - 1);
|
||||
// }
|
||||
// wifiMacAddressBuild.append(anInterface.getName()).append(" -> ").append(builder).append("\n");
|
||||
// }
|
||||
// if (wifiMacAddressBuild.length() > 0) {
|
||||
// wifiMacAddressBuild.deleteCharAt(wifiMacAddressBuild.length() - 1);
|
||||
// }
|
||||
// return wifiMacAddressBuild.toString();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 通过分析IP,获取Wifi Mac地址,适用于6.0及以上版本
|
||||
// *
|
||||
// * @return
|
||||
// * @throws SocketException
|
||||
// */
|
||||
// public static String getWifiMacAddressByIp() {
|
||||
// String strMacAddr = null;
|
||||
// try {
|
||||
// //获得IpD地址
|
||||
// InetAddress ip = getLocalInetAddress();
|
||||
// byte[] b = NetworkInterface.getByInetAddress(ip).getHardwareAddress();
|
||||
// StringBuffer buffer = new StringBuffer();
|
||||
// for (int i = 0; i < b.length; i++) {
|
||||
// if (i != 0) {
|
||||
// buffer.append(':');
|
||||
// }
|
||||
// String str = Integer.toHexString(b[i] & 0xFF);
|
||||
// buffer.append(str.length() == 1 ? 0 + str : str);
|
||||
// }
|
||||
// strMacAddr = buffer.toString().toUpperCase();
|
||||
// } catch (Exception e) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// return strMacAddr;
|
||||
// }
|
||||
//
|
||||
// private static InetAddress getLocalInetAddress() {
|
||||
// InetAddress ip = null;
|
||||
// try {
|
||||
// //列举
|
||||
// Enumeration<NetworkInterface> en_netInterface = NetworkInterface.getNetworkInterfaces();
|
||||
// while (en_netInterface.hasMoreElements()) {//是否还有元素
|
||||
// NetworkInterface ni = (NetworkInterface) en_netInterface.nextElement();//得到下一个元素
|
||||
// Enumeration<InetAddress> en_ip = ni.getInetAddresses();//得到一个ip地址的列举
|
||||
// while (en_ip.hasMoreElements()) {
|
||||
// ip = en_ip.nextElement();
|
||||
// if (!ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1)
|
||||
// break;
|
||||
// else
|
||||
// ip = null;
|
||||
// }
|
||||
//
|
||||
// if (ip != null) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// } catch (SocketException e) {
|
||||
//
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return ip;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取Android Id
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
@SuppressLint("HardwareIds")
|
||||
public static String getAndroidId(Context context) {
|
||||
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Build的部分信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getBuildInfo() {
|
||||
//这里选用了几个不会随系统更新而改变的值
|
||||
StringBuffer buildSB = new StringBuffer();
|
||||
buildSB.append(Build.BRAND).append("/");
|
||||
buildSB.append(Build.PRODUCT).append("/");
|
||||
buildSB.append(Build.DEVICE).append("/");
|
||||
buildSB.append(Build.ID).append("/");
|
||||
buildSB.append(Build.VERSION.INCREMENTAL);
|
||||
return buildSB.toString();
|
||||
// return Build.FINGERPRINT;
|
||||
}
|
||||
|
||||
/**
|
||||
* 最终方案,获取设备ID
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public static String getDeviceUUID(Context context) {
|
||||
String uuid = loadDeviceUUID(context);
|
||||
if (TextUtils.isEmpty(uuid)) {
|
||||
uuid = buildDeviceUUID(context);
|
||||
saveDeviceUUID(context, uuid);
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
private static String buildDeviceUUID(Context context) {
|
||||
String androidId = getAndroidId(context);
|
||||
if (!"9774d56d682e549c".equals(androidId)) {
|
||||
Random random = new Random();
|
||||
androidId = Integer.toHexString(random.nextInt())
|
||||
+ Integer.toHexString(random.nextInt())
|
||||
+ Integer.toHexString(random.nextInt());
|
||||
}
|
||||
return new UUID(androidId.hashCode(), getBuildInfo().hashCode()).toString();
|
||||
}
|
||||
|
||||
private static void saveDeviceUUID(Context context, String uuid) {
|
||||
context.getSharedPreferences("device_uuid", Context.MODE_PRIVATE)
|
||||
.edit()
|
||||
.putString("uuid", uuid)
|
||||
.apply();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String loadDeviceUUID(Context context) {
|
||||
return context.getSharedPreferences("device_uuid", Context.MODE_PRIVATE)
|
||||
.getString("uuid", null);
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package com.jc.jcfw.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Installation {
|
||||
private static String sID = null;
|
||||
private static final String INSTALLATION = "INSTALLATION";
|
||||
|
||||
public synchronized static String id(Context context) {
|
||||
if (sID == null) {
|
||||
File installation = new File(context.getFilesDir(), INSTALLATION);
|
||||
try {
|
||||
if (!installation.exists())
|
||||
writeInstallationFile(installation);
|
||||
sID = readInstallationFile(installation);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return sID;
|
||||
}
|
||||
|
||||
private static String readInstallationFile(File installation) throws IOException {
|
||||
RandomAccessFile f = new RandomAccessFile(installation, "r");
|
||||
byte[] bytes = new byte[(int) f.length()];
|
||||
f.readFully(bytes);
|
||||
f.close();
|
||||
return new String(bytes);
|
||||
}
|
||||
|
||||
private static void writeInstallationFile(File installation) throws IOException {
|
||||
FileOutputStream out = new FileOutputStream(installation);
|
||||
String id = UUID.randomUUID().toString();
|
||||
out.write(id.getBytes());
|
||||
out.close();
|
||||
}
|
||||
|
||||
public static String getBuildInfo() {
|
||||
//这里选用了几个不会随系统更新而改变的值
|
||||
StringBuffer buildSB = new StringBuffer();
|
||||
buildSB.append(Build.BRAND).append("/");
|
||||
buildSB.append(Build.PRODUCT).append("/");
|
||||
buildSB.append(Build.DEVICE).append("/");
|
||||
buildSB.append(Build.ID).append("/");
|
||||
buildSB.append(Build.VERSION.INCREMENTAL);
|
||||
return buildSB.toString();
|
||||
// return Build.FINGERPRINT;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user