package com.xhly.manageapp.broadcastreceiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.xhly.corelib.Const
import com.xhly.corelib.eventbus.UIEvent
import com.xhly.corelib.utils.LogShow

class USBReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        val booleanExtra = intent.getBooleanExtra(USB_CONNECTED, false)
        val booleanExtra1 = intent.getBooleanExtra(USB_FUNCTION_MTP, false)
        val booleanExtra2 = intent.getBooleanExtra(USB_FUNCTION_PTP, false)
        val booleanExtra3 = intent.getBooleanExtra(USB_FUNCTION_ADB, false)
        LogShow("USBReceiver获取权限成功：1.链接==$booleanExtra,mtp==$booleanExtra1,ptp==$booleanExtra2,adb==$booleanExtra3")
        if (booleanExtra){
            UIEvent(Const.USB_CONNECTED).post()
        }else{
            UIEvent(Const.USB_NOCONNECTED).post()
        }
    }

    companion object {
        const val ACTION_USB_STATE = "android.hardware.usb.action.USB_STATE"
        const val USB_FUNCTION_MTP = "mtp"
        const val USB_FUNCTION_PTP = "ptp"
        const val USB_FUNCTION_ADB = "adb"
        const val USB_CONNECTED = "connected"
    }
}
