private void addLooperCheck()

in TransformCore/src/main/java/com/facebook/ads/injkit/threadcheck/ThreadCheckInjector.java [150:182]


  private void addLooperCheck(
      ClassNode classNode, MethodNode method, boolean checkForPositiveLooperMatch) {
    if (method.instructions == null) {
      method.instructions = new InsnList();
    }

    InsnList insns = new InsnList();

    invokeStatic(insns, androidLooper, GET_CURRENT_LOOPER, "()L" + androidLooper + ";");
    invokeStatic(insns, androidLooper, GET_MAIN_LOOPER, "()L" + androidLooper + ";");

    LabelNode conditionOk = new LabelNode(new Label());
    insns.add(
        new JumpInsnNode(
            checkForPositiveLooperMatch ? Opcodes.IF_ACMPEQ : Opcodes.IF_ACMPNE, conditionOk));

    // Condition not OK:

    insns.add(new LdcInsnNode(Type.getType("L" + classNode.name + ";")));
    insns.add(new LdcInsnNode(method.name));
    insns.add(new LdcInsnNode(method.desc));
    invokeStatic(
        insns,
        AsmNameUtils.classJavaNameToInternalName(config.getViolationHandlerClass()),
        checkForPositiveLooperMatch ? UI_VIOLATION_METHOD_NAME : WORKER_VIOLATION_METHOD_NAME,
        VIOLATION_METHOD_DESC);

    // Condition OK:

    insns.add(conditionOk);

    method.instructions.insert(insns);
  }