package com.zxhyis.toolss.ui.page.appmanager

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

object UsageAccessSettings {
    fun Context.checkUsageAccessSettings(): Boolean {

        val appOpsManager = getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager

        return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            appOpsManager.unsafeCheckOpNoThrow(
                AppOpsManager.OPSTR_GET_USAGE_STATS,
                android.os.Process.myUid(),
                this.packageName
            ) == AppOpsManager.MODE_ALLOWED
        } else {
            appOpsManager.checkOpNoThrow(
                AppOpsManager.OPSTR_GET_USAGE_STATS,
                android.os.Process.myUid(),
                this.packageName
            ) == AppOpsManager.MODE_ALLOWED
        }
    }
}