package net.geedge.api.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import net.geedge.api.util.AdbUtil;
import org.springframework.web.servlet.HandlerInterceptor;

public class APIInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        AdbUtil adbUtil = AdbUtil.getInstance();
        if (!adbUtil.connect()) {
            // 记录日志或设置响应状态
            response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "device connect error");
            return false;
        }

        // init
        adbUtil.init(false);
        return true;
    }

}