package com.zxhy.simplefilesmanager.simplejoke.permission

import android.Manifest
import android.content.ClipboardManager
import android.content.pm.PackageManager
import android.os.Build
import androidx.core.content.ContextCompat
import android.content.Context
import android.os.Environment


object JoPermissionJoCheckEx {

    //Android 13以后,读写权限无法弹出系统弹窗,分化为Manifest.permission.READ_MEDIA_*权限
    //Android 11以后,Manifest.permission.READ_EXTERNAL_STORAGE 授予后还需授予 额外储存管理权限 ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
    //Android 11以下使用Manifest.permission.READ_EXTERNAL_STORAGE
    fun Context.jostorejoPermissionCheck(): Boolean {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {//Android 13以后
            dfzz()
            return Environment.isExternalStorageManager()
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {//Android 11以后
            dfzz()
            val flag1 = Environment.isExternalStorageManager()
            val flag2 = arrayOf(
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE
            ).all {
                ContextCompat.checkSelfPermission(this, it) == PackageManager.PERMISSION_GRANTED
            }
            return flag1 or flag2
        } else { //Android 11以下,Android 6以上
            dfzz()
            return arrayOf(
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE
            ).all {
                ContextCompat.checkSelfPermission(this, it) == PackageManager.PERMISSION_GRANTED
            }
        }
    }


    /**
     * 垃圾代码
     */
    fun dfzz(): Int {
        ClipboardManager.OnPrimaryClipChangedListener {

        }
        AbstractMethodError().printStackTrace()
        var result = 0
        AutoCloseable {
            result = (System.currentTimeMillis() + 100).toInt()
        }.close()
        repeat(10) {
            result = ArrayDeque<String>().add("jojo").xor(true).compareTo(true).and(result)
        }

        return result
    }
}

