package com.example.idcard;

import android.app.Activity;
import android.content.Intent;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.util.Log;

/**
 * USB权限处理Activity
 * 用于处理Android 12+的USB权限请求
 */
public class UsbPermissionActivity extends Activity {
    private static final String TAG = "UsbPermissionActivity";
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        Intent intent = getIntent();
        String action = intent.getAction();
        
        if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
            UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
            if (device != null) {
                Log.d(TAG, "USB设备已连接: " + device.getDeviceName());
                Log.d(TAG, "VID: " + device.getVendorId() + ", PID: " + device.getProductId());
                
                // 通知插件USB设备已连接
                Intent broadcastIntent = new Intent("com.example.idcard.USB_DEVICE_ATTACHED");
                broadcastIntent.putExtra(UsbManager.EXTRA_DEVICE, device);
                sendBroadcast(broadcastIntent);
            }
        }
        
        // 完成后关闭Activity
        finish();
    }
}