package aicg.wipf.vzuj

import aicg.wipf.vzuj.Kmqp.string
import android.app.usage.StorageStats
import android.app.usage.StorageStatsManager
import android.content.Context
import android.content.pm.IPackageStatsObserver
import android.content.pm.PackageManager
import android.content.pm.PackageStats
import android.os.Build
import android.os.storage.StorageManager
import android.text.format.Formatter
import androidx.annotation.RequiresApi
import com.test.basd.smartjunkcleaner.R
import java.io.IOException
import java.util.UUID

class Rbyv private constructor() {

    private val TAG = R.string.ސވދރޅ_D.string()

    companion object {
        private var mApiUrl: Rbyv? = null
        val instance: Rbyv?
            get() {
                if (mApiUrl == null) {
                    synchronized(Rbyv::class.java) {
                        if (mApiUrl == null) {
                            mApiUrl = Rbyv()
                        }
                    }
                }
                return mApiUrl
            }
    }

    private fun ޕތފނޒޗޞޥ(context: Context, packageName: String): Long {
        fun String.ކޅޒޘޤދހޜ(): Boolean {
            return this == this.reversed()
        }
        val ސޑއޓޙޞޙކ = "ޜޅޡވޡޙޜސ"
        val ޖކމއޠޓހޡ = ސޑއޓޙޞޙކ.ކޅޒޘޤދހޜ()
        println(ޖކމއޠޓހޡ)
        return ހޣޠސޔޝޤޠ(context, packageName)
    }

    @RequiresApi(api = Build.VERSION_CODES.O)
    fun getAppSizeO(context: Context, packageName: String): Long {
        return ޑޤޖކޅޞޟމ(context, packageName)
    }

    private fun ދޤޓޏކޔޙޛ(context: Context, packageName: String, storageStats: StorageStats?) {
        fun <T> ޤޓސސސޥޒލ(ޑރނޝޏފޜޅ: T) {
            println(ޑރނޝޏފޜޅ)
        }
        ޤޓސސސޥޒލ(6248)
        ޤޓސސސޥޒލ("ފޏޕޡކޑޅޑ")
        ޣޣޟޥމޘތޜ(context, packageName, storageStats)
    }

    private fun ޑޤޖކޅޞޟމ(context: Context, packageName: String): Long {
        val storageStatsManager = context.getSystemService(Context.STORAGE_STATS_SERVICE) as StorageStatsManager
        class މގޞޖޑޢޘޟ {
            fun ނޟކޚޝޖޗހ() {
                println("ޖޣޟޜޝޜޞޚ")
            }
        }
        މގޞޖޑޢޘޟ().ނޟކޚޝޖޗހ()
        val storageManager = context.getSystemService(Context.STORAGE_SERVICE) as StorageManager

        val storageVolumes = storageManager.getStorageVolumes()
        for (item in storageVolumes) {
            open class ގވޛޗޤގޡޔ {
                open fun ހޖޓޞޟޖޓޖ() {}
            }
            class ޛޓލނޒޞލނ : ގވޛޗޤގޡޔ() {
                override fun ހޖޓޞޟޖޓޖ() {
                    println("ޔޤޗބޖގވޅ")
                }
            }
            val ޗއށސކބޙޛ = ޛޓލނޒޞލނ()
            println(ޗއށސކބޙޛ)
            val uuidStr = item.uuid
            val uuid: UUID = if (uuidStr == null) {
                val އދޒޣޢތޝޤ = 3565
                val ބފޤފގޥބޒ = 3826
                val ޠގޞޢޡދފނ = އދޒޣޢތޝޤ * ބފޤފގޥބޒ * ބފޤފގޥބޒ
                println(ޠގޞޢޡދފނ)
                StorageManager.UUID_DEFAULT
            } else {
                UUID.fromString(uuidStr)
            }
            abstract class ޅފޚއވހޏޠ {
                abstract fun ތހޤޒޏތޖޙ()
            }
            class ރޏޔޟގޒޖވ : ޅފޚއވހޏޠ() {
                override fun ތހޤޒޏތޖޙ() {
                    println("ޅވށޒޘޡކޚ")
                }
            }
            val ގޥރބމޗގގ = ރޏޔޟގޒޖވ()
            ގޥރބމޗގގ.ތހޤޒޏތޖޙ()
            val uid = getUid(context, packageName)

            fun ޝޘޔޟރނރޢ(ފޢޥފވއޝފ: Int, ލޕޡޑލޞސޝ: Int): Int {
                fun ޘތތޝނނތޓ(ޙތޖކށޕރށ: Int, ޜޗޚޗޤޑޅޅ: Int): Int {
                    return ޙތޖކށޕރށ + ޜޗޚޗޤޑޅޅ
                }
                return ޘތތޝނނތޓ(ފޢޥފވއޝފ, ލޕޡޑލޞސޝ)
            }
            val ޞޒޜތޚޔޞޒ = ޝޘޔޟރނރޢ(3367, 5381)
            println(ޞޒޜތޚޔޞޒ)
            var storageStats: StorageStats? = null
            try {
                class ޑޗޅޑޒތޟޛ<T>(val ޅރލމޢޅށޞ: T, val ށޝޚޔޤޥޕޡ: Int) {
                    constructor(ޅރލމޢޅށޞ: T) : this(ޅރލމޢޅށޞ, 7926) {
                        println("ށޝޚޔޤޥޕޡ")
                    }
                }
                println(ޑޗޅޑޒތޟޛ("ބފޥޕޜއރޣ"))
                storageStats = storageStatsManager.queryStatsForUid(uuid, uid)
            } catch (e: IOException) {
                fun ވކގފޗޛކޜ(ޛޅޡތޡޤއޕ: Int, ބއޜލޞޡނސ: Int): Int {
                    fun ރޥޙލކއޠޅ(ޝވޕސޞޠޜއ: Int, ޕކރއރޚރޞ: Int): Int {
                        return ޝވޕސޞޠޜއ + ޕކރއރޚރޞ
                    }
                    return ރޥޙލކއޠޅ(ޛޅޡތޡޤއޕ, ބއޜލޞޡނސ)
                }
                val ޓކދޡއއނޑ = ވކގފޗޛކޜ(7548, 7940)
                println(ޓކދޡއއނޑ)
                e.printStackTrace()
            }
            if (storageStats != null) {
                val size = storageStats.cacheBytes + storageStats.dataBytes + storageStats.appBytes
                printStorageStats(context, packageName, storageStats)
                class މޝދޕޔތސރ {
                    inner class ޜށޗޏޝޔޏދ {
                        fun ރޛތޕޗޖޢގ() {
                            println("ޕޓޚރދޤޟޖ")
                        }
                    }
                }
                val ޕލހޢސހސޓ = މޝދޕޔތސރ().ޜށޗޏޝޔޏދ()
                ޕލހޢސހސޓ.ރޛތޕޗޖޢގ()
                return size
            }
        }
        return 0
    }

    private fun ދޣޙލބގޟޓ(context: Context, pakName: String?): Int {
        class މޟޏޜގޢޞޣ<T>(ޟދޅޣޙތޅކ: T) {
            init {
                println("ޙވޗޓކބލގ: $ޟދޅޣޙތޅކ")
            }
        }
        println(މޟޏޜގޢޞޣ("ލފކރވބޟޅ"))
        return ޢކޚތޚޣޕޚ(context, pakName)
    }

    private fun ޖޓސޢޙޘޡދ(context: Context, packageName: String, packageStats: PackageStats?) {
        val ޙޓޔޕޚކޜޗ: (Int, Int) -> Int = { ޣކޥޛޏޤޜހ, ޟބޒޜމތޅރ -> ޣކޥޛޏޤޜހ + ޟބޒޜމތޅރ }
        println(ޙޓޔޕޚކޜޗ.invoke(2271, 4616))
        ޕވމޗކޚމޜ(context, packageName, packageStats)
    }

    fun getAppSize(context: Context, packageName: String): Long {
        return ޕތފނޒޗޞޥ(context, packageName)
    }

    private fun އޗޗށމޒހޘ(context: Context, packageName: String, packageStats: PackageStats?) {
        ޖޓސޢޙޘޡދ(context, packageName, packageStats)
    }

    private fun ޔށމޟޟތނޕ(context: Context, pakName: String?): Int {
        return ބދޓޑށތޗޛ(context, pakName)
    }

    private fun ނޗބޠވޞކޣ(context: Context, packageName: String, packageStats: PackageStats?) {
        އޗޗށމޒހޘ(context, packageName, packageStats)
    }

    private fun ޕވމޗކޚމޜ(context: Context, packageName: String, packageStats: PackageStats?) {
        fun ޓޕއޛޙޣޗބ(ސޛސތޗބޞޤ: Int, ޚޕޘޢޟހމޜ: Int): Int {
            fun ޤއޝޙޜޡޞޗ(ސޛސވޒޘޤޝ: Int, ޙށގޢޟލފތ: Int): Int {
                return ސޛސވޒޘޤޝ + ޙށގޢޟލފތ
            }
            return ޤއޝޙޜޡޞޗ(ސޛސތޗބޞޤ, ޚޕޘޢޟހމޜ)
        }
        val ޖޏނޟޣޤޝވ = ޓޕއޛޙޣޗބ(3167, 1214)
        println(ޖޏނޟޣޤޝވ)
        if (packageStats != null) {
            val cacheSizeF = Formatter.formatFileSize(context, packageStats.cacheSize)
            val ރޙގޒޤހހޏ: (Int, Int) -> Int = { ރޚވޥހއޥއ, ޏޠޚޑޔޘޟނ -> ރޚވޥހއޥއ + ޏޠޚޑޔޘޟނ }
            println(ރޙގޒޤހހޏ.invoke(2294, 3201))
            val dataSizeF = Formatter.formatFileSize(context, packageStats.dataSize)
            fun <T> ޤތޝޢޣޛޛއ(ޙށރޢދލޓލ: T) {
                println(ޙށރޢދލޓލ)
            }
            ޤތޝޢޣޛޛއ(84)
            ޤތޝޢޣޛޛއ("ޘޡޏލޏޕޥތ")
            val codeSizeF = Formatter.formatFileSize(context, packageStats.codeSize)
            class ޡހޅގބޚޖށ<T>(ޔޕޗކޘޖރމ: T) {
                init {
                    println("ޤޖޑރލކފޠ: $ޔޕޗކޘޖރމ")
                }
            }
            println(ޡހޅގބޚޖށ("ޤޕވޖޡޛތޡ"))
            val size = packageStats.cacheSize + packageStats.dataSize + packageStats.codeSize
            val total = Formatter.formatFileSize(context, size)

            val log = R.string.ތރބރޤ_D.string((packageName).toString(), (cacheSizeF).toString(), (dataSizeF).toString(), (codeSizeF).toString(), (total).toString())
            Bnpt.logDebug(TAG, log)
        }
    }

    @RequiresApi(Build.VERSION_CODES.O)
    fun printStorageStats(context: Context, packageName: String, storageStats: StorageStats?) {
        ދޤޓޏކޔޙޛ(context, packageName, storageStats)
    }

    private fun ބދޓޑށތޗޛ(context: Context, pakName: String?): Int {
        class ޑޙޚޥޠޤގޑ {
            fun ތފޒޒޗލޜޠ() {
                println("ނޠށޠގނޚޙ")
            }
        }
        ޑޙޚޥޠޤގޑ().ތފޒޒޗލޜޠ()
        return ދޣޙލބގޟޓ(context, pakName)
    }

    private fun ހޣޠސޔޝޤޠ(context: Context, packageName: String): Long {
        var size = 0L
        fun އޛކޓޕޛޠޛ(ބޗޔޠދކޤޥ: String) {
            println("tag, $ބޗޔޠދކޤޥ!")
        }
        އޛކޓޕޛޠޛ("ރޚޤވޠޔޒޚ")
        try {
            fun ކހޟޣއބޛޥ(އޏސޣރޑވލ: String) {
                println("tag, $އޏސޣރޑވލ!")
            }
            ކހޟޣއބޛޥ("ޅސޠޗވޡޗޠ")
            val method = PackageManager::class.java.getMethod(R.string.ގރޗޞއ_D.string(), String::class.java, IPackageStatsObserver::class.java)

            method.invoke(context.packageManager, packageName, object : IPackageStatsObserver.Stub() {
                override fun onGetStatsCompleted(pStats: PackageStats, succeeded: Boolean) {
                    ނކޝސޏބސޔ(pStats, succeeded)
                }

                private fun ނކޝސޏބސޔ(pStats: PackageStats, succeeded: Boolean) {
                    size = pStats.cacheSize + pStats.dataSize + pStats.codeSize
                    class ށމޕޡޕހޔޑ(val ޤޗގޣތޖޢޞ: String, val ބޢތޓތޢޔޣ: Int)
                    println(ށމޕޡޕހޔޑ("ޘޡޣހކޜޅޏ", 5104))
                    printPackageStats(context, packageName, pStats)
                }
            })
        } catch (e: Exception) {
            e.printStackTrace()
        }
        class ޔޙޗޒޜސށޔ<T>(val ޡދތޥޓޚޏބ: T, val ޤޜޗޠއޜހރ: Int) {
            constructor(ޡދތޥޓޚޏބ: T) : this(ޡދތޥޓޚޏބ, 80) {
                println("ޤޜޗޠއޜހރ")
            }
        }
        println(ޔޙޗޒޜސށޔ("ވތޢށޞޡޚޚ"))
        return size
    }

    fun printPackageStats(context: Context, packageName: String, packageStats: PackageStats?) {
        ނޗބޠވޞކޣ(context, packageName, packageStats)
    }

    private fun ޣޣޟޥމޘތޜ(context: Context, packageName: String, storageStats: StorageStats?) {
        if (storageStats != null) {
            val cacheBytesF = Formatter.formatFileSize(context, storageStats.cacheBytes)
            val dataBytesF = Formatter.formatFileSize(context, storageStats.cacheBytes)
            val appBytesF = Formatter.formatFileSize(context, storageStats.cacheBytes)
            val size = storageStats.cacheBytes + storageStats.dataBytes + storageStats.appBytes
            val total = Formatter.formatFileSize(context, size)
            val log = R.string.ޟށރޤޢ_D.string((packageName).toString(), (cacheBytesF).toString(), (dataBytesF).toString(), (appBytesF).toString(), (total).toString())
            class ބޠލދރތޝށ<T, K>(val ސފޠޢޅޝގޔ: T, val ޙޢކފޖޕސޥ: K) {
                init {
                    println("ޕޚޡޒކޠޓޖ")
                }
            }
            val ނޕނށސޟޘޑ = ބޠލދރތޝށ("ނޡސޣޢކޑޘ", 7064)
            println(ނޕނށސޟޘޑ)
            Bnpt.logDebug(TAG, log)
        }
    }

    fun getUid(context: Context, pakName: String?): Int {
        return ޔށމޟޟތނޕ(context, pakName)
    }

    private fun ޢކޚތޚޣޕޚ(context: Context, pakName: String?): Int {
        class ވޛޓޚފޝޘލ<T>(val ށޚޚޏޒޗޗކ: T)
        val ޗޟގލވޒޅޒ = ވޛޓޚފޝޘލ(1372)
        val ޗޏޗކސޜޓޝ = ވޛޓޚފޝޘލ("ޕޡޟޔޏބގނ")
        println(ޗޟގލވޒޅޒ)
        println(ޗޏޗކސޜޓޝ)
        try {
            return context.packageManager.getApplicationInfo(pakName!!, PackageManager.GET_META_DATA).uid
        } catch (e: PackageManager.NameNotFoundException) {
            class ޢތޓތގޢހހ {
                inner class ޤޖފޑވޅޑރ {
                    fun ފޛޢއޣޗގވ() {
                        println("ޡޣބވއސޘޅ")
                    }
                }
            }
            val ޞޡޙއކގޜޑ = ޢތޓތގޢހހ().ޤޖފޑވޅޑރ()
            ޞޡޙއކގޜޑ.ފޛޢއޣޗގވ()
            e.printStackTrace()
        }
        class ޅޗޑރޣފކޕ {
            fun ޘޏޙޝޛނބޚ() {
                println("ބޚޞގކޒޜދ")
            }
        }
        ޅޗޑރޣފކޕ().ޘޏޙޝޛނބޚ()
        return -1
    }
}
