import Build from "android.os.Build"
import Settings from "android.provider.Settings"
import { UTSAndroid } from "io.dcloud.uts";

type DevicesInfo = {
	ANDROID_ID : String,
	MANUFACTURER : String,
	MODEL : String,
	BOARD : String,
	PRODUCT : String,
	BRAND : String,
	HOST : String,
	SDK_INT : Int,
	RELEASE : String,
	SERIAL : String,
	HARDWARE : String,
	FINGERPRINT : String
}
export function getDevicesInfo() : DevicesInfo {
	const context = UTSAndroid.getAppContext();
	let androidId = "";
	const tempAndroidId = Settings.Secure.getString(context?.contentResolver, Settings.Secure.ANDROID_ID);
	if (tempAndroidId != null && tempAndroidId !== "") {
		androidId = tempAndroidId;
	}
	//3. 兼容处理 SERIAL（低版本兼容 + 高版本返回空）
	let serial = "";
	if (Build.VERSION.SDK_INT < 26) {
		//@ts-ignore 抑制低版本废弃警告
		const tempSerial = Build.SERIAL;
		if (tempSerial != null && tempSerial !== "") {
			serial = tempSerial;
		}
	}
	return {
		ANDROID_ID: androidId != null ? androidId : "unknown",
		MANUFACTURER: Build.MANUFACTURER != null ? Build.MANUFACTURER : "unknown",
		MODEL: Build.MODEL != null ? Build.MODEL : "unknown",
		BOARD: Build.BOARD != null ? Build.BOARD : "unknown",
		PRODUCT: Build.PRODUCT != null ? Build.PRODUCT : "unknown",
		BRAND: Build.BRAND != null ? Build.BRAND : "unknown",
		HOST: Build.HOST != null ? Build.HOST : "unknown",
		SDK_INT: Build.VERSION.SDK_INT,
		RELEASE: Build.VERSION.RELEASE != null ? Build.VERSION.RELEASE : "unknown",
		SERIAL: serial != null ? serial : "unknown",
		HARDWARE: Build.HARDWARE != null ? Build.HARDWARE : "unknown",
		FINGERPRINT: Build.FINGERPRINT != null ? Build.FINGERPRINT : "unknown"
	}
    /*const res:DevicesInfo={
	ANDROID_ID:Settings.Secure.getString(context?.contentResolver,Settings.Secure.ANDROID_ID),
	MANUFACTURER:Build.MANUFACTURER,
	MODEL:Build.MODEL,
	BOARD:Build.BOARD,
	PRODUCT:Build.PRODUCT,
	BRAND:Build.BRAND,
	HOST:Build.HOST,
	SDK_INT:Build.VERSION.SDK_INT,
	RELEASE:Build.VERSION.RELEASE,
	SERIAL:Build.SERIAL,
	HARDWARE:Build.HARDWARE,
	FINGERPRINT:Build.FINGERPRINT
};
return res; */
// 3. 构建设备信息（统一空值兜底）