package com.xyzshell.andinfo.libs

import android.app.ActivityManager
import android.content.Context
import android.os.Build

// 设备信息工具类
class DeviceInfo(private val context: Context) {

    // ActivityManager 用于获取内存等系统服务
    private val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager

    // 设备代号
    val device: String
        get() = Build.DEVICE

    // 品牌
    val brand: String
        get() = Build.BRAND

    // 机型
    val model: String
        get() = Build.MODEL

    // 制造商
    val manufacturer: String
        get() = Build.MANUFACTURER

    // 产品名称
    val productName: String
        get() = Build.PRODUCT

    // 硬件名称
    val hardwareName: String
        get() = Build.HARDWARE

    // 主板名称
    val boardName: String
        get() = Build.BOARD

    // 硬件SKU（Android 12及以上）
    val hardwareSku: String?
        get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) Build.SKU else null

    // ODM SKU（Android 12及以上）
    val odmSku: String?
        get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) Build.ODM_SKU else null

    // SoC制造商（Android 12及以上）
    val socManufacturer: String?
        get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) Build.SOC_MANUFACTURER else null

    // SoC型号（Android 12及以上）
    val socModel: String?
        get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) Build.SOC_MODEL else null

    /**
     * 获取内存信息
     * @return ActivityManager.MemoryInfo 内存信息对象
     */
    fun getMemoryInfo(): ActivityManager.MemoryInfo {
        val memoryInfo = ActivityManager.MemoryInfo()
        activityManager.getMemoryInfo(memoryInfo)
        return memoryInfo
    }
}
