<commit_before>/* Copyright (C) 2013 <NAME> <<EMAIL>>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "dgladbdevice.h"

namespace {

class DGLEmptyOutputFilter : public DGLAdbOutputFilter {
    virtual bool filter(const std::vector<std::string>& input,
                        std::vector<std::string>&) override {

        for (size_t i = 0; i < input.size(); i++) {
            if (input[i].size()) {
                return false;
            }
        }
        return true;
    }
};

class DGLGetPropOutputFilter : public DGLAdbOutputFilter {
    virtual bool filter(const std::vector<std::string>& input,
                        std::vector<std::string>& output) override {
        if (input.size() > 2 || input.size() < 1 ||
            input[0].find("not found") != std::string::npos) {
            return false;
        }
        output.push_back(input[0]);
        return true;
    }
};

class DGLUnixSocketsFilter : public DGLAdbOutputFilter {
    virtual bool filter(const std::vector<std::string>& input,
                        std::vector<std::string>& output) override {
        if (!input.size()) return false;
        size_t pathOffset = input[0].find("Path");

        if (pathOffset == std::string::npos) {
            return false;
        }

        for (size_t i = 1; i < input.size(); i++) {
            if (input[i].size() > pathOffset) {
                std::string path = input[i].substr(pathOffset);
                size_t j = 0; 
                while (j < path.size() && path[j] != '/') j++;
                output.push_back(path.substr(j));
            }
        }
        output.push_back(input[0]);
        return true;
    }
};

class DGLTransferFilter : public DGLAdbOutputFilter {
    virtual bool filter(const std::vector<std::string>& input,
                        std::vector<std::string>& output) override {
        if (input.size() > 2 || input.size() < 1 ||
            input[0].find("bytes in") == std::string::npos) {
            return false;
        }
        output.push_back(input[0]);
        return true;
    }
};

class DGLInstallerFilter : public DGLAdbOutputFilter {
    virtual bool filter(const std::vector<std::string>& input,
                        std::vector<std::string>& output) override {
        output = input;
        if (input.size() < 2 ||
            input[input.size() - 2].find("Success") == std::string::npos) {
            return false;
        }
        return true;
    }
};

class DGLPackageListFilter : public DGLAdbOutputFilter {
    virtual bool filter(const std::vector<std::string>& input,
        std::vector<std::string>& output) override {
        
        const size_t offset = strlen("package:");

        for (size_t i = 0; i < input.size(); i++) {
            int pos = input[i].find("package:"); 
            if (pos == 0) {
                output.push_back(input[i].substr(offset));
            }
        }
        if (output.size()) {
            return true;
        }
        return false;
    }
};
}

DGLAdbDeviceProcess::DGLAdbDeviceProcess(const std::string& pid,
                                         const std::string& name,
                                         const std::string& portName)
        : m_Pid(pid), m_Name(name), m_PortName(portName) {}

bool DGLAdbDeviceProcess::operator==(const DGLAdbDeviceProcess& rhs) const {
    return 
        rhs.getName() == m_Name && 
        rhs.getPid() == m_Pid;
    //we don't compare port strings, as they are not mandatory in ctor
}

bool DGLAdbDeviceProcess::operator<(const DGLAdbDeviceProcess& other) const {<commit_msg>Android: getting list of packages: handle negative pm answer, when framework is not running.<commit_after>/* Copyright (C) 2013 <NAME> <<EMAIL>>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "dgladbdevice.h"

namespace {

class DGLEmptyOutputFilter : public DGLAdbOutputFilter {
    virtual bool filter(const std::vector<std::string>& input,
                        std::vector<std::string>&) override {

        for (size_t i = 0; i < input.size(); i++) {
            if (input[i].size()) {
                return false;
            }
        }
        return true;
    }
};

class DGLGetPropOutputFilter : public DGLAdbOutputFilter {
    virtual bool filter(const std::vector<std::string>& input,
                        std::vector<std::string>& output) override {
        if (input.size() > 2 || input.size() < 1 ||
            input[0].find("not found") != std::string::npos) {
            return false;
        }
        output.push_back(input[0]);
        return true;
    }
};

class DGLUnixSocketsFilter : public DGLAdbOutputFilter {
    virtual bool filter(const std::vector<std::string>& input,
                        std::vector<std::string>& output) override {
        if (!input.size()) return false;
        size_t pathOffset = input[0].find("Path");

        if (pathOffset == std::string::npos) {
            return false;
        }

        for (size_t i = 1; i < input.size(); i++) {
            if (input[i].size() > pathOffset) {
                std::string path = input[i].substr(pathOffset);
                size_t j = 0; 
                while (j < path.size() && path[j] != '/') j++;
                output.push_back(path.substr(j));
            }
        }
        output.push_back(input[0]);
        return true;
    }
};

class DGLTransferFilter : public DGLAdbOutputFilter {
    virtual bool filter(const std::vector<std::string>& input,
                        std::vector<std::string>& output) override {
        if (input.size() > 2 || input.size() < 1 ||
            input[0].find("bytes in") == std::string::npos) {
            return false;
        }
        output.push_back(input[0]);
        return true;
    }
};

class DGLInstallerFilter : public DGLAdbOutputFilter {
    virtual bool filter(const std::vector<std::string>& input,
                        std::vector<std::string>& output) override {
        output = input;
        if (input.size() < 2 ||
            input[input.size() - 2].find("Success") == std::string::npos) {
            return false;
        }
        return true;
    }
};

class DGLPackageListFilter : public DGLAdbOutputFilter {
    virtual bool filter(const std::vector<std::string>& input,
        std::vector<std::string>& output) override {
        
        const size_t offset = strlen("package:");

        bool frameworkNotRunning = false;

        for (size_t i = 0; i < input.size(); i++) {
            int pos = input[i].find("package:"); 
            if (pos == 0) {
                output.push_back(input[i].substr(offset));
            } else {
                if (input[i].find("Could not access the Package Manager") != std::string::npos) {
                    frameworkNotRunning = true;
                }
            }
        }

        return (output.size() > 0 || frameworkNotRunning);
    }
};
}

DGLAdbDeviceProcess::DGLAdbDeviceProcess(const std::string& pid,
                                         const std::string& name,
                                         const std::string& portName)
        : m_Pid(pid), m_Name(name), m_PortName(portName) {}

bool DGLAdbDeviceProcess::operator==(const DGLAdbDeviceProcess& rhs) const {
    return 
        rhs.getName() == m_Name && 
        rhs.getPid() == m_Pid;
    //we don't compare port strings, as they are not mandatory in ctor
}

bool DGLAdbDeviceProcess::operator<(const DGLAdbDeviceProcess& other) const {
{'fraction_non_alphanumeric': 0.1285325765637933, 'fraction_numerical': 0.006030507272082299, 'mean_word_length': 2.1666042680643955, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5777905', 'n_tokens_mistral': 2445, 'n_tokens_neox': 2366, 'n_words': 643}