Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 15665a6d authored by Daniel Bergløv's avatar Daniel Bergløv Committed by Steve Kondik
Browse files

Processor.java: Fixes and Cleanups

1: Fix issue where Processor settings FC whenever one of the /sys/devices/system/cpu/cpu0/cpufreq/* files is missing.
2: Cleanup for better overview.
3: No need to add empty content to disabled/removed elements.
4: Do not start the current cpu freq loop if the files needed are missing.
5: Also add the check for missing or empty files in the 'onResume' part.
6: Disable elements with missing files rather than remove them to maintain the layout.

Change-Id: Ib0cc3b01cbce368e23530760e2d87eedd04ad10a
parent eb194fcc
Loading
Loading
Loading
Loading
+71 −63
Original line number Diff line number Diff line
@@ -101,84 +101,89 @@ public class Processor extends SettingsPreferenceFragment implements
        mMinFrequencyFormat = getString(R.string.cpu_min_freq_summary);
        mMaxFrequencyFormat = getString(R.string.cpu_max_freq_summary);

        String[] availableGovernors = Utils.fileReadOneLine(GOV_LIST_FILE).split(" ");
        String[] availableFrequencies = new String[0];
        String availableFrequenciesLine = Utils.fileReadOneLine(FREQ_LIST_FILE);
        if (availableFrequenciesLine != null)
            availableFrequencies = availableFrequenciesLine.split(" ");
        String[] availableGovernors = new String[0];
        String[] frequencies;
        String availableGovernorsLine;
        String availableFrequenciesLine;
        String temp;

        frequencies = new String[availableFrequencies.length];
        for (int i = 0; i < frequencies.length; i++) {
            frequencies[i] = toMHz(availableFrequencies[i]);
        }

        addPreferencesFromResource(R.xml.processor_settings);

        PreferenceScreen prefScreen = getPreferenceScreen();

        // Governer
        temp = Utils.fileReadOneLine(GOV_FILE);

        mGovernorPref = (ListPreference) prefScreen.findPreference(GOV_PREF);
        mCurFrequencyPref = (Preference) prefScreen.findPreference(FREQ_CUR_PREF);
        mMinFrequencyPref = (ListPreference) prefScreen.findPreference(FREQ_MIN_PREF);
        mMaxFrequencyPref = (ListPreference) prefScreen.findPreference(FREQ_MAX_PREF);

        /* Governor
        Some systems might not use governors */
        if (Utils.fileExists(GOV_LIST_FILE) == false || Utils.fileExists(GOV_FILE) == false || (temp = Utils.fileReadOneLine(GOV_FILE)) == null || (availableGovernorsLine = Utils.fileReadOneLine(GOV_LIST_FILE)) == null) {
            prefScreen.removePreference(mGovernorPref);

        } else {
            availableGovernors = availableGovernorsLine.split(" ");

            mGovernorPref.setEntryValues(availableGovernors);
            mGovernorPref.setEntries(availableGovernors);
            mGovernorPref.setValue(temp);
            mGovernorPref.setSummary(String.format(mGovernorFormat, temp));
            mGovernorPref.setOnPreferenceChangeListener(this);

        // Some systems might not use governors
        if (temp == null) {
            prefScreen.removePreference(mGovernorPref);
        }

        if (!Utils.fileExists(FREQ_CUR_FILE)) {
            FREQ_CUR_FILE = FREQINFO_CUR_FILE;
        }
        // Disable the min/max list if we dont have a list file
        if (Utils.fileExists(FREQ_LIST_FILE) == false || (availableFrequenciesLine = Utils.fileReadOneLine(FREQ_LIST_FILE)) == null) {
            mMinFrequencyPref.setEnabled(false);
            mMaxFrequencyPref.setEnabled(false);

        // Cur frequency
        temp = Utils.fileReadOneLine(FREQ_CUR_FILE);
        } else {
            availableFrequencies = availableFrequenciesLine.split(" ");

        mCurFrequencyPref = (Preference) prefScreen.findPreference(FREQ_CUR_PREF);
        mCurFrequencyPref.setSummary(toMHz(temp));
            frequencies = new String[availableFrequencies.length];
            for (int i = 0; i < frequencies.length; i++) {
                frequencies[i] = toMHz(availableFrequencies[i]);
            }

            // Min frequency
        temp = Utils.fileReadOneLine(FREQ_MIN_FILE);
            if (Utils.fileExists(FREQ_MIN_FILE) == false || (temp = Utils.fileReadOneLine(FREQ_MIN_FILE)) == null) {
                mMinFrequencyPref.setEnabled(false);

        mMinFrequencyPref = (ListPreference) prefScreen.findPreference(FREQ_MIN_PREF);
            } else {
                mMinFrequencyPref.setEntryValues(availableFrequencies);
                mMinFrequencyPref.setEntries(frequencies);
                mMinFrequencyPref.setValue(temp);
                mMinFrequencyPref.setSummary(String.format(mMinFrequencyFormat, toMHz(temp)));
                mMinFrequencyPref.setOnPreferenceChangeListener(this);

        if (temp == null) {
            prefScreen.removePreference(mMinFrequencyPref);
            }

            // Max frequency
        temp = Utils.fileReadOneLine(FREQ_MAX_FILE);
            if (Utils.fileExists(FREQ_MAX_FILE) == false || (temp = Utils.fileReadOneLine(FREQ_MAX_FILE)) == null) {
                mMaxFrequencyPref.setEnabled(false);

        mMaxFrequencyPref = (ListPreference) prefScreen.findPreference(FREQ_MAX_PREF);
            } else {
                mMaxFrequencyPref.setEntryValues(availableFrequencies);
                mMaxFrequencyPref.setEntries(frequencies);
                mMaxFrequencyPref.setValue(temp);
                mMaxFrequencyPref.setSummary(String.format(mMaxFrequencyFormat, toMHz(temp)));
                mMaxFrequencyPref.setOnPreferenceChangeListener(this);

        if (temp == null) {
            prefScreen.removePreference(mMaxFrequencyPref);
            }
        }

        // Disable the min/max list if we dont have a list file
        if (availableFrequenciesLine == null) {
            mMinFrequencyPref.setEnabled(false);
            mMaxFrequencyPref.setEnabled(false);
        // Cur frequency
        if (!Utils.fileExists(FREQ_CUR_FILE)) {
            FREQ_CUR_FILE = FREQINFO_CUR_FILE;
        }

        if (Utils.fileExists(FREQ_CUR_FILE) == false || (temp = Utils.fileReadOneLine(FREQ_CUR_FILE)) == null) {
            mCurFrequencyPref.setEnabled(false);

        } else {
            mCurFrequencyPref.setSummary(toMHz(temp));

            mCurCPUThread.start();
        }
    }

    @Override
    public void onResume() {
@@ -186,17 +191,20 @@ public class Processor extends SettingsPreferenceFragment implements

        super.onResume();

        temp = Utils.fileReadOneLine(FREQ_MAX_FILE);
        mMaxFrequencyPref.setValue(temp);
        mMaxFrequencyPref.setSummary(String.format(mMaxFrequencyFormat, toMHz(temp)));

        temp = Utils.fileReadOneLine(FREQ_MIN_FILE);
        if (Utils.fileExists(FREQ_MIN_FILE) != false && (temp = Utils.fileReadOneLine(FREQ_MIN_FILE)) != null) {
            mMinFrequencyPref.setValue(temp);
            mMinFrequencyPref.setSummary(String.format(mMinFrequencyFormat, toMHz(temp)));
        }

        temp = Utils.fileReadOneLine(GOV_FILE);
        if (Utils.fileExists(FREQ_MAX_FILE) != false && (temp = Utils.fileReadOneLine(FREQ_MAX_FILE)) != null) {
            mMaxFrequencyPref.setValue(temp);
            mMaxFrequencyPref.setSummary(String.format(mMaxFrequencyFormat, toMHz(temp)));
        }

        if (Utils.fileExists(GOV_FILE) != false && (temp = Utils.fileReadOneLine(GOV_FILE)) != null) {
            mGovernorPref.setSummary(String.format(mGovernorFormat, temp));
        }
    }

    @Override
    public void onDestroy() {