package com.example.modifier.utils

import android.provider.Settings
import com.example.modifier.constants.CMD_HOME
import com.example.modifier.constants.CMD_MESSAGING_APP
import com.example.modifier.constants.CMD_START_PLAY_STORE
import com.example.modifier.constants.PACKAGE_GMS
import com.example.modifier.constants.PACKAGE_GSF
import com.example.modifier.constants.PACKAGE_MESSAGING
import com.example.modifier.constants.PACKAGE_PLAY
import com.example.modifier.extension.clear
import com.example.modifier.extension.kill

suspend fun clear(gsf: Boolean, gms: Boolean, sms: Boolean) {
    try {
        val cmds: MutableList<String> = ArrayList()
        // suspend
        if (gsf) {
            cmds.add(PACKAGE_GSF.kill())
            cmds.add("echo 'gsf suspended'")
        }
        if (gms) {
            cmds.add(PACKAGE_GMS.kill())
            cmds.add("echo 'gms suspended'")
        }
        if (sms) {
            cmds.add(PACKAGE_MESSAGING.kill())
            cmds.add("echo 'sms suspended'")
        }
        cmds.add("sleep 1")
        // clear
        if (gsf) {
            cmds.add(PACKAGE_GSF.clear())
            cmds.add("echo 'cleared gsf'")
        }
        if (gms) {
            cmds.add(PACKAGE_GMS.clear())
            cmds.add("echo 'cleared gms'")
        }
        if (sms) {
            cmds.add(PACKAGE_MESSAGING.clear())
            cmds.add("echo 'cleared sms'")
        }
        cmds.add("sleep 1")
        cmds.add("sleep 1")
        shellRun(*cmds.toTypedArray<String>())
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

suspend fun resetAll() {
    try {
        clearConv()
        shellRun(
            "settings put secure location_mode 0",
            "settings put secure android_id ${genAndroidId()}",
            PACKAGE_GSF.clear(),
            "sleep 1",
            PACKAGE_GMS.clear(),
            "sleep 1",
            CMD_START_PLAY_STORE,
            "sleep 1",
            CMD_HOME,
            "sleep 10",
            PACKAGE_GMS.clear(),
            "sleep 2",
//            "pm revoke com.google.android.gms android.permission.ACCESS_FINE_LOCATION",
//            "pm revoke com.google.android.gms android.permission.ACCESS_COARSE_LOCATION",
            "pm revoke com.google.android.gms android.permission.NEARBY_WIFI_DEVICES",
//            "pm revoke com.google.android.gms android.permission.BLUETOOTH_CONNECT",
//            "pm revoke com.google.android.gms android.permission.BLUETOOTH_SCAN",
//            "pm revoke com.google.android.gms android.permission.BLUETOOTH_ADVERTISE",
//            "pm revoke com.google.android.gms android.permission.UWB_RANGING",
//            "pm revoke com.google.android.gms android.permission.GET_ACCOUNTS",
//            "pm revoke com.google.android.gms android.permission.SYSTEM_ALERT_WINDOW",
//            "pm revoke com.google.android.gms android.permission.POST_NOTIFICATIONS",
//            "pm revoke com.google.android.gms android.permission.CAMERA",
//            "pm revoke com.google.android.gms android.permission.RECEIVE_MMS",
//            "pm revoke com.google.android.gms android.permission.GET_APP_OPS_STATS",
//            "pm revoke com.google.android.gms android.permission.PROCESS_OUTGOING_CALLS",
//            "pm revoke com.google.android.gms android.permission.READ_CALL_LOG",
//            "pm revoke com.google.android.gms android.permission.WRITE_CONTACTS",
//            "pm revoke com.google.android.gms android.permission.CALL_PHONE",
//            "pm revoke com.google.android.gms android.permission.RECORD_AUDIO",
//            "pm revoke com.google.android.gms android.permission.READ_LOGS",
//            "pm revoke com.google.android.gms android.permission.READ_MEDIA_AUDIO",
//            "pm revoke com.google.android.gms android.permission.READ_MEDIA_IMAGES",
//            "pm revoke com.google.android.gms android.permission.READ_MEDIA_VIDEO",
//            "pm revoke com.google.android.gms android.permission.ACCESS_MEDIA_LOCATION",
//            "pm revoke com.google.android.gms android.permission.ACCESS_BROADCAST_RESPONSE_STATS",
//            "pm revoke com.google.android.gms android.permission.WRITE_CALL_LOG",
//            "pm revoke com.google.android.gms android.permission.BODY_SENSORS",
//            "pm revoke com.google.android.gms android.permission.DUMP",
            "sleep 10",
            PACKAGE_MESSAGING.clear(),
            "sleep 3",
            CMD_MESSAGING_APP,
            "sleep 3",
            CMD_MESSAGING_APP
        )
    } catch (e: Exception) {
        e.printStackTrace()
    }
}