<commit_before>/*
 * Copyright (C) 2015 <NAME>
 *
 * 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.
 */

package com.grarak.kerneladiutor.utils.kernel;

import android.content.Context;

import com.grarak.kerneladiutor.utils.Constants;
import com.grarak.kerneladiutor.utils.Utils;
import com.grarak.kerneladiutor.utils.root.Control;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by willi on 26.12.14.
 */
public class CPUVoltage implements Constants {

    private static String CPU_VOLTAGE_FILE;
    private static String[] mCpuFreqs;

    public static void activateOverrideVmin(boolean active, Context context) {
        Control.runCommand(active ? "1" : "0", CPU_OVERRIDE_VMIN, Control.CommandType.GENERIC, context);
    }

    public static boolean isOverrideVminActive() {
        return Utils.readFile(CPU_OVERRIDE_VMIN).equals("1");
    }

    public static boolean hasOverrideVmin() {
        return Utils.existFile(CPU_OVERRIDE_VMIN);
    }

    public static void setGlobalOffset(String voltage, Context context) {
        String command = "";
        int adjust = Utils.stringToInt(voltage);

        switch (CPU_VOLTAGE_FILE) {
            case CPU_VDD_VOLTAGE:
            case CPU_FAUX_VOLTAGE:
                command = String.valueOf(adjust * 1000);
                if (adjust > 0) command = "+" + command;
                break;
            default:
                for (String volt : getVoltages())
                    command += command.isEmpty() ? (Utils.stringToInt(volt) + adjust) :
                            " " + (Utils.stringToInt(volt) + adjust);
                break;
        }

        Control.runCommand(command, CPU_VOLTAGE_FILE, Control.CommandType.GENERIC, context);
    }

    public static void setVoltage(String freq, String voltage, Context context) {
        String command = "";
        int position = 0;
        for (int i = 0; i < getFreqs().size(); i++) {
            if (freq.equals(getFreqs().get(i)))
                position = i;
        }
        switch (CPU_VOLTAGE_FILE) {
            case CPU_VDD_VOLTAGE:
            case CPU_FAUX_VOLTAGE:
                command = getFreqs().get(position) + " " + Utils.stringToInt(voltage) * 1000;
                Control.runCommand(command, CPU_VOLTAGE_FILE, Control.CommandType.GENERIC, String.valueOf(position), context);
                break;
            default:
                List<String> voltages = getVoltages();
                for (int i = 0; i < voltages.size(); i++)
                    if (i == position)
                        command += command.isEmpty() ? voltage : " " + voltage;
                    else
                        command += command.isEmpty() ? voltages.get(i) : " " + voltages.get(i);
                Control.runCommand(command, CPU_VOLTAGE_FILE, Control.CommandType.GENERIC, context);
                break;
        }
    }

    public static List<String> getVoltages() {
        String value = Utils.readFile(CPU_VOLTAGE_FILE);
        if (value != null) {
            String[] lines;
            value = value.replace(" ", "");
            switch (CPU_VOLTAGE_FILE) {
                case CPU_VDD_VOLTAGE:
                case CPU_FAUX_VOLTAGE:
                    lines = value.split("\\r?\\n");
                    break;
                default:
                    lines = value.split("mV");
                    break;
            }
            String[] voltages = new String[lines.length];
            for (int i = 0; i < voltages.length; i++) {
                String[] voltageLine;
                switch (CPU_VOLTAGE_FILE) {
                    case CPU_VDD_VOLTAGE:
                    case CPU_FAUX_VOLTAGE:
                        voltageLine = lines[i].split(":");
                        break;
                    default:
                        voltageLine = lines[i].split("mhz:");
                        break;
                }
                if (voltageLine.length > 1) {
                    switch (CPU_VOLTAGE_FILE) {
                        case CPU_VDD_VOLTAGE:
                        case CPU_FAUX_VOLTAGE:
                            voltages[i] = String.valueOf(Utils.stringToInt(voltageLine[1]) / 1000).trim();
                            break;<commit_msg>Voltage: Fix vdd levels don't divide voltage by 1000<commit_after>/*
 * Copyright (C) 2015 <NAME>
 *
 * 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.
 */

package com.grarak.kerneladiutor.utils.kernel;

import android.content.Context;

import com.grarak.kerneladiutor.utils.Constants;
import com.grarak.kerneladiutor.utils.Utils;
import com.grarak.kerneladiutor.utils.root.Control;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by willi on 26.12.14.
 */
public class CPUVoltage implements Constants {

    private static String CPU_VOLTAGE_FILE;
    private static String[] mCpuFreqs;

    public static void activateOverrideVmin(boolean active, Context context) {
        Control.runCommand(active ? "1" : "0", CPU_OVERRIDE_VMIN, Control.CommandType.GENERIC, context);
    }

    public static boolean isOverrideVminActive() {
        return Utils.readFile(CPU_OVERRIDE_VMIN).equals("1");
    }

    public static boolean hasOverrideVmin() {
        return Utils.existFile(CPU_OVERRIDE_VMIN);
    }

    public static void setGlobalOffset(String voltage, Context context) {
        int adjust = Utils.stringToInt(voltage);
        String command = String.valueOf(adjust);

        switch (CPU_VOLTAGE_FILE) {
            case CPU_VDD_VOLTAGE:
            case CPU_FAUX_VOLTAGE:
                if (CPU_VOLTAGE_FILE.equals(CPU_FAUX_VOLTAGE))
                    command = String.valueOf(adjust * 1000);
                if (adjust > 0) command = "+" + command;
                break;
            default:
                command = "";
                for (String volt : getVoltages())
                    command += command.isEmpty() ? (Utils.stringToInt(volt) + adjust) :
                            " " + (Utils.stringToInt(volt) + adjust);
                break;
        }

        Control.runCommand(command, CPU_VOLTAGE_FILE, Control.CommandType.GENERIC, context);
    }

    public static void setVoltage(String freq, String voltage, Context context) {
        String command = "";
        int position = 0;
        for (int i = 0; i < getFreqs().size(); i++) {
            if (freq.equals(getFreqs().get(i)))
                position = i;
        }
        switch (CPU_VOLTAGE_FILE) {
            case CPU_VDD_VOLTAGE:
            case CPU_FAUX_VOLTAGE:
                command = getFreqs().get(position) + " " + Utils.stringToInt(voltage) * 1000;
                Control.runCommand(command, CPU_VOLTAGE_FILE, Control.CommandType.GENERIC, String.valueOf(position), context);
                break;
            default:
                List<String> voltages = getVoltages();
                for (int i = 0; i < voltages.size(); i++)
                    if (i == position)
                        command += command.isEmpty() ? voltage : " " + voltage;
                    else
                        command += command.isEmpty() ? voltages.get(i) : " " + voltages.get(i);
                Control.runCommand(command, CPU_VOLTAGE_FILE, Control.CommandType.GENERIC, context);
                break;
        }
    }

    public static List<String> getVoltages() {
        String value = Utils.readFile(CPU_VOLTAGE_FILE);
        if (value != null) {
            String[] lines;
            value = value.replace(" ", "");
            switch (CPU_VOLTAGE_FILE) {
                case CPU_VDD_VOLTAGE:
                case CPU_FAUX_VOLTAGE:
                    lines = value.split("\\r?\\n");
                    break;
                default:
                    lines = value.split("mV");
                    break;
            }
            String[] voltages = new String[lines.length];
            for (int i = 0; i < voltages.length; i++) {
                String[] voltageLine;
                switch (CPU_VOLTAGE_FILE) {
                    case CPU_VDD_VOLTAGE:
                    case CPU_FAUX_VOLTAGE:
                        voltageLine = lines[i].split(":");
                        break;
                    default:
                        voltageLine = lines[i].split("mhz:");
                        break;
                }
                if (voltageLine.length > 1) {
                    switch (CPU_VOLTAGE_FILE) {
                        case CPU_FAUX_VOLTAGE:
                            voltages[i] = String.valueOf(Utils.stringToInt(voltageLine[1]) / 1000).trim();
                            break;
{'fraction_non_alphanumeric': 0.1, 'fraction_numerical': 0.007875647668393783, 'mean_word_length': 1.8104251601630752, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7322395', 'n_tokens_mistral': 2773, 'n_tokens_neox': 2573, 'n_words': 649}