<commit_before>module AndroidDebug
    # Native ADB implementation so we dont need the ANDROID_HOME
    class AdbNative
        require 'socket'

        attr_reader :soc
        
        def send_command(command, new_connection = true)
            host = "localhost"
            port = 5037
            @soc.nil? || @soc.closed? || new_connection and @soc = TCPSocket.open(host, port)
            begin
                @soc.print("%04x" % command.size)
                @soc.print(command)
                response = read_soc
                if(response.match(/OKAY\d{4}.+/))
                    return(response["OKAY0000".length, response.size])   
                else
                    return(response)
                end
            rescue Errno::EPIPE
                puts("Connection to the ADB has been torn down.")
            end
        end

        def read_soc
            return @soc.recvfrom(1024)[0].strip
        end

        def devices
            devices = send_command("host:devices")
            if(devices == "")
                return({})
            else
                # Converts an array to a hash
                return(Hash[*devices.split(/\t/)])
            end
        end

        def version
            return(send_command("host:version"))
        end

        def jdwp_pids(device)
            send_command("host:track-devices")
            send_command("host:transport-#{device}")
            send_command("track-jdwp", false)
            
            # format [4-size][rest]
            size = @soc.recvfrom(4)[0].to_i(16)
            ret = @soc.recvfrom(size)[0].strip
            return(ret[4, ret.size])
        end

        def jdpw_handshake(device, pid)
            send_command("host:transport:#{device}")
            send_command("jdwp:#{pid}")
            
        end

        def shell_command(command, transport = "any", new_connection = true)
            send_command("host:transport-#{transport}", new_connection)
            send_command("shell:#{command}", false)
            return(@soc.read.strip)
        end

        def launch_activity(activity, clazz)
            shell_command("am start #{activity}/#{clazz}")
        end

        def set_activity_debug(activity)
            set_activity_debug("am set-debug-app -w #{activity}")
        end
    end
end

adb = AndroidDebug::AdbNative.new
device = adb.devices.keys[0]
puts device
adb.jdwp_pids(device).each do |pid|
    puts("==#{pid}")

end<commit_msg>ADB native checkin<commit_after>module AndroidDebug
    # Native ADB implementation so we dont need the ANDROID_HOME
    class AdbNative
        require 'socket'

        attr_reader :soc
        
        def send_command(command, new_connection = true)
            host = "localhost"
            port = 5037
            @soc.nil? || @soc.closed? || new_connection and @soc = TCPSocket.open(host, port)
            begin
                @soc.print("%04x" % command.size)
                @soc.print(command)
                response = read_soc
                if(response.match(/OKAY\d{4}.+/))
                    return(response["OKAY0000".length, response.size])   
                else
                    return(response)
                end
            rescue Errno::EPIPE
                puts("Connection to the ADB has been torn down.")
            end
        end

        def read_soc
            return @soc.recvfrom(1024)[0].strip
        end

        def devices
            devices = send_command("host:devices")
            if(devices == "")
                return({})
            else
                # Converts an array to a hash
                return(Hash[*devices.split(/\t/)])
            end
        end

        def version
            return(send_command("host:version"))
        end

        def jdwp_pids(device)
            send_command("host:track-devices")
            send_command("host:transport-#{device}")
            send_command("track-jdwp", false)
            
            # format [4-size][rest]
            size = @soc.recvfrom(4)[0].to_i(16)
            ret = @soc.recvfrom(size)[0].strip
            return(ret[4, ret.size])
        end

        def jdpw_handshake(device, pid)
            send_command("host:transport:#{device}")
            send_command("jdwp:#{pid}")
            
        end

        def shell_command(command, transport = "any", new_connection = true)
            send_command("host:transport-#{transport}", new_connection)
            send_command("shell:#{command}", false)
            return(@soc.read.strip)
        end

        def launch_activity(activity, clazz)
            shell_command("am start #{activity}/#{clazz}")
        end

        def set_activity_debug(activity)
            shell_command("am set-debug-app -w #{activity}")
        end
    end
end

adb = AndroidDebug::AdbNative.new
device = adb.devices.keys[0]
puts device
adb.jdwp_pids(device).each do |pid|
    puts("==#{pid}")

end
{'fraction_non_alphanumeric': 0.11030008110300081, 'fraction_numerical': 0.009732360097323601, 'mean_word_length': 1.6253326237360297, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1859025', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1356, 'n_words': 283}