Android Open Source - Pimp_my_Z1 Power Management Activity






From Project

Back to project page Pimp_my_Z1.

License

The source code is released under:

GNU General Public License

If you think the Android project Pimp_my_Z1 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**   Copyright (C) 2013  Louis Teboul (a.k.a Androguide)
 */* w w w  . j ava2 s  .c om*/
 *    admin@pimpmyrom.org  || louisteboul@gmail.com
 *    http://pimpmyrom.org || http://androguide.fr
 *    71 quai Clmenceau, 69300 Caluire-et-Cuire, FRANCE.
 *
 *     This program is free software; you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation; either version 2 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License along
 *      with this program; if not, write to the Free Software Foundation, Inc.,
 *      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 **/

package com.androguide.honamicontrol.kernel.powermanagement;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.Toast;

import com.androguide.honamicontrol.R;
import com.androguide.honamicontrol.helpers.CMDProcessor.CMDProcessor;
import com.androguide.honamicontrol.helpers.CPUHelper;
import com.androguide.honamicontrol.helpers.Helpers;

import java.util.ArrayList;

public class PowerManagementActivity extends ActionBarActivity implements PowerManagementInterface {

    private int spinnerCounter = 0, ecoCoresCounter = 0, alucardCoresCounter = 0, hotplugCounter = 0;
    private Boolean isIntelliPlugOn;
    private LinearLayout mCardIntelliEco, mCardIntelliCores, mCardAlucardCores;
    private Spinner mEcoCoresSpinner;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //noinspection ConstantConditions
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setIcon(getResources().getDrawable(R.drawable.ic_tools_power_management));
        setContentView(R.layout.card_power_management);
        final SharedPreferences bootPrefs = getSharedPreferences("BOOT_PREFS", 0);

        mCardIntelliEco = (LinearLayout) findViewById(R.id.card_intelliplug_eco_mode);
        mCardIntelliCores = (LinearLayout) findViewById(R.id.card_intelliplug_eco_cores);
        mCardAlucardCores = (LinearLayout) findViewById(R.id.card_alucard_cores);

        // Sched MC
        if (Helpers.doesFileExist(SCHED_MC_POWER_SAVINGS)) {
            Spinner schedMcSpinner = (Spinner) findViewById(R.id.sched_mc_spinner);
            ArrayList<String> schedMCEntries = new ArrayList<String>();
            schedMCEntries.add(getString(R.string.disabled));
            schedMCEntries.add(getString(R.string.moderate));
            schedMCEntries.add(getString(R.string.aggressive));
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_row, schedMCEntries);
            schedMcSpinner.setAdapter(adapter);
            schedMcSpinner.setSelection(Integer.valueOf(CPUHelper.readOneLineNotRoot(SCHED_MC_POWER_SAVINGS)));
            schedMcSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                    bootPrefs.edit().putInt("SCHED_MC_LEVEL", i).commit();
                    if (spinnerCounter > 0)
                        Helpers.CMDProcessorWrapper.runSuCommand("busybox echo " + i + " > " + SCHED_MC_POWER_SAVINGS);
                    else
                        spinnerCounter++;
                }

                @Override
                public void onNothingSelected(AdapterView<?> adapterView) {

                }
            });
        }

        // Hotplug Driver
        Spinner hotplugDriverSpinner = (Spinner) findViewById(R.id.hotplug_spinner);
        ArrayList<String> availableDrivers = new ArrayList<String>();
        availableDrivers.add("MPDecision");
        Boolean hasIntelliPlug = false;
        Boolean hasAlucardPlug = false;
        int intelliState = 0;
        int alucardState = 0;

        try {
            if (Helpers.doesFileExist(INTELLI_PLUG_TOGGLE)) {
                hasIntelliPlug = true;
                intelliState = Integer.parseInt(CPUHelper.readOneLineNotRoot(INTELLI_PLUG_TOGGLE));
                availableDrivers.add("Intelliplug");
            }

            if (Helpers.doesFileExist(ALUCARD_HOTPLUG_TOGGLE)) {
                hasAlucardPlug = true;
                alucardState = Integer.parseInt(CPUHelper.readOneLineNotRoot(ALUCARD_HOTPLUG_TOGGLE));
                availableDrivers.add("Alucard Hotplug");
            }

            ArrayAdapter<String> hotplugAdapter = new ArrayAdapter<String>(this, R.layout.spinner_row, availableDrivers);
            hotplugDriverSpinner.setAdapter(hotplugAdapter);

            /** If the kernel doesn't have intelliplug nor alucard hotplug */
            if (!hasAlucardPlug && !hasIntelliPlug) {
                // then default to mpdecision
                hotplugDriverSpinner.setSelection(0);

                /** If the kernel has intelliplug but not alucard hotplug */
            } else if (hasIntelliPlug && !hasAlucardPlug) {

                if (intelliState == 1) // If intelliplug is on, intelliplug is the current hotplug driver
                    hotplugDriverSpinner.setSelection(1);
                else
                    hotplugDriverSpinner.setSelection(0); // else it's mpdecision

                /** If the kernel has alucard hotplug but not intelliplug */
            } else if (!hasIntelliPlug) {

                if (alucardState == 1)
                    hotplugDriverSpinner.setSelection(2); // if alucard hotplug is on, then it's the current hotplug driver
                else
                    hotplugDriverSpinner.setSelection(0); // else it's mpdecision

                /** If the kernel has both intelliplug & alucard hotplug */
            } else {
                if (intelliState == 1 && alucardState == 0) // if intelliplug is on & alucard is off, intelliplug is the current driver
                    hotplugDriverSpinner.setSelection(1);
                else if (intelliState == 0 && alucardState == 1) // if alucard is on & intelliplug is off, alucard is the current driver
                    hotplugDriverSpinner.setSelection(2);
                else if (intelliState == 0 && alucardState == 0) // if neither alucard or intelliplug is on, mpdecision is the current driver
                    hotplugDriverSpinner.setSelection(0);
                else if (intelliState == 1 && alucardState == 1) { // if both alucard & intelliplug are on, notifiy the user and default back to mpdecision
                    Toast.makeText(this, getString(R.string.multiple_hotplug_drivers_warning), Toast.LENGTH_LONG).show();
                    hotplugDriverSpinner.setSelection(0);
                    CMDProcessor.runSuCommand("busybox echo 0 > " + INTELLI_PLUG_TOGGLE + "\nbusybox echo 0 > " + ALUCARD_HOTPLUG_TOGGLE + "\nstart mpdecision");
                }
            }

        } catch (Exception e) {
            Log.e("PowerManagement", e.getMessage());
        }

        hotplugDriverSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

                bootPrefs.edit().putInt("HOTPLUG_DRIVER", pos).commit();
                switch (pos) {
                    case 0:
                        mCardIntelliEco.setVisibility(View.GONE);
                        mCardIntelliCores.setVisibility(View.GONE);
                        mCardAlucardCores.setVisibility(View.GONE);
                        isIntelliPlugOn = false;
                        if (hotplugCounter > 0) {
                            CMDProcessor.runSuCommand("echo 0 > " + INTELLI_PLUG_TOGGLE);
                            CMDProcessor.runSuCommand("echo 0 > " + ALUCARD_HOTPLUG_TOGGLE);
                            CMDProcessor.runSuCommand("start mpdecision");
                        } else hotplugCounter++;
                        break;

                    case 1:
                        mCardAlucardCores.setVisibility(View.GONE);
                        mCardIntelliEco.setVisibility(View.VISIBLE);
                        mCardIntelliCores.setVisibility(View.VISIBLE);
                        isIntelliPlugOn = true;
                        if (hotplugCounter > 0) {
                            CMDProcessor.runSuCommand("echo 0 > " + ALUCARD_HOTPLUG_TOGGLE);
                            CMDProcessor.runSuCommand("stop mpdecision");
                            CMDProcessor.runSuCommand("echo 1 > " + INTELLI_PLUG_TOGGLE);
                        } else hotplugCounter++;
                        break;

                    case 2:
                        mCardIntelliEco.setVisibility(View.GONE);
                        mCardIntelliCores.setVisibility(View.GONE);
                        mCardAlucardCores.setVisibility(View.VISIBLE);
                        isIntelliPlugOn = false;
                        if (hotplugCounter > 0) {
                            CMDProcessor.runSuCommand("echo 0 > " + INTELLI_PLUG_TOGGLE);
                            CMDProcessor.runSuCommand("stop mpdecision");
                            CMDProcessor.runSuCommand("echo 1 > " + ALUCARD_HOTPLUG_TOGGLE);
                        } else hotplugCounter++;
                        break;
                    default:
                        break;
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });

        // Intelliplug Eco Mode
        if (Helpers.doesFileExist(INTELLI_PLUG_ECO_MODE)) {
            final Switch intelliEcoSwitch = (Switch) findViewById(R.id.intelliplug_eco_switch);
            int currEcoState = Integer.parseInt(CPUHelper.readOneLineNotRoot(INTELLI_PLUG_ECO_MODE));

            if (currEcoState == 0) {
                intelliEcoSwitch.setChecked(false);
                findViewById(R.id.intelliplug_eco_cores_spinner).setEnabled(false);
            } else if (currEcoState == 1) {
                intelliEcoSwitch.setChecked(true);
                findViewById(R.id.intelliplug_eco_cores_spinner).setEnabled(true);
            }

            intelliEcoSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isOn) {
                    bootPrefs.edit().putBoolean("INTELLI_PLUG_ECO", isOn).commit();

                    if (isOn) {
                        Helpers.CMDProcessorWrapper.runSuCommand("busybox echo 1 > " + INTELLI_PLUG_ECO_MODE);
                        findViewById(R.id.intelliplug_eco_cores_spinner).setEnabled(true);
                    } else {
                        Helpers.CMDProcessorWrapper.runSuCommand("busybox echo 0 > " + INTELLI_PLUG_ECO_MODE);
                        findViewById(R.id.intelliplug_eco_cores_spinner).setEnabled(false);
                    }
                }
            });
        }

        // Intelliplug eco cores
        if (Helpers.doesFileExist(INTELLI_PLUG_ECO_CORES)) {
            Spinner intelliEcoCoresSpinner = (Spinner) findViewById(R.id.intelliplug_eco_cores_spinner);
            mEcoCoresSpinner = intelliEcoCoresSpinner;
            ArrayList<String> possibleEcoCores = new ArrayList<String>();
            possibleEcoCores.add("1");
            possibleEcoCores.add("2");
            possibleEcoCores.add("3");
            ArrayAdapter<String> ecoCoresAdapter = new ArrayAdapter<String>(this, R.layout.spinner_row, possibleEcoCores);
            intelliEcoCoresSpinner.setAdapter(ecoCoresAdapter);
            intelliEcoCoresSpinner.setSelection(Integer.parseInt(CPUHelper.readOneLineNotRoot(INTELLI_PLUG_ECO_CORES)) - 1);
            if (!bootPrefs.getBoolean("INTELLI_PLUG_ECO", false))
                intelliEcoCoresSpinner.setEnabled(false);
            intelliEcoCoresSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    int toApply = position + 1;
                    if (ecoCoresCounter > 0) {
                        Helpers.CMDProcessorWrapper.runSuCommand("busybox echo " + toApply + " > " + INTELLI_PLUG_ECO_CORES);
                        bootPrefs.edit().putInt("INTELLI_PLUG_ECO_CORES", toApply).commit();
                    } else {
                        ecoCoresCounter++;
                    }
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {

                }
            });
        }

        // Alucard eco cores
        if (Helpers.doesFileExist(ALUCARD_HOTPLUG_CORES)) {
            final Spinner alucardCoresSpinner = (Spinner) findViewById(R.id.alucard_cores_spinner);
            mEcoCoresSpinner = alucardCoresSpinner;
            ArrayList<String> possibleEcoCores = new ArrayList<String>();
            possibleEcoCores.add("1");
            possibleEcoCores.add("2");
            possibleEcoCores.add("3");
            possibleEcoCores.add("4");
            ArrayAdapter<String> ecoCoresAdapter = new ArrayAdapter<String>(this, R.layout.spinner_row, possibleEcoCores);
            alucardCoresSpinner.setAdapter(ecoCoresAdapter);
            alucardCoresSpinner.setSelection(Integer.parseInt(CPUHelper.readOneLineNotRoot(ALUCARD_HOTPLUG_CORES)) - 1);
            alucardCoresSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    int toApply = position + 1;
                    if (alucardCoresCounter > 0) {
                        Helpers.CMDProcessorWrapper.runSuCommand("busybox echo " + toApply + " > " + ALUCARD_HOTPLUG_CORES);
                        bootPrefs.edit().putInt("ALUCARD_CORES", toApply).commit();
                    } else {
                        alucardCoresCounter++;
                    }
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {

                }
            });
        }

        // Power Suspend
        if (Helpers.doesFileExist(POWER_SUSPEND_TOGGLE)) {
            Switch powerSuspendSwitch = (Switch) findViewById(R.id.power_suspend_switch);
            int isPowerSuspendOn = Integer.parseInt(CPUHelper.readOneLineNotRoot(POWER_SUSPEND_TOGGLE));
            if (isPowerSuspendOn == 0)
                powerSuspendSwitch.setChecked(false);
            else if (isPowerSuspendOn == 1)
                powerSuspendSwitch.setChecked(true);

            powerSuspendSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    bootPrefs.edit().putBoolean("POWER_SUSPEND", isChecked).commit();
                    if (isChecked)
                        Helpers.CMDProcessorWrapper.runSuCommand("busybox echo 1 > " + POWER_SUSPEND_TOGGLE);
                    else {
                        Helpers.CMDProcessorWrapper.runSuCommand("busybox echo 0 > " + POWER_SUSPEND_TOGGLE);
                    }
                }
            });
        } else {
            findViewById(R.id.card_power_suspend).setVisibility(View.GONE);
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}




Java Source Code List

com.androguide.honamicontrol.MainActivity.java
com.androguide.honamicontrol.PresentationActivity.java
com.androguide.honamicontrol.SettingsActivity.java
com.androguide.honamicontrol.bootservice.BootHelper.java
com.androguide.honamicontrol.bootservice.BootReceiver.java
com.androguide.honamicontrol.cards.CardDoubleSeekBarPA.java
com.androguide.honamicontrol.cards.CardDoubleSeekBar.java
com.androguide.honamicontrol.cards.CardImageLocal.java
com.androguide.honamicontrol.cards.CardSeekBarGeneric.java
com.androguide.honamicontrol.cards.CardSeekBarReadahead.java
com.androguide.honamicontrol.cards.CardSeekBarSC.java
com.androguide.honamicontrol.cards.CardSeekBarSysctl.java
com.androguide.honamicontrol.cards.CardSeekBarVibrator.java
com.androguide.honamicontrol.cards.CardSeekBar.java
com.androguide.honamicontrol.cards.CardSpinnerSchedMCDisabled.java
com.androguide.honamicontrol.cards.CardSpinnerSchedMC.java
com.androguide.honamicontrol.cards.CardSpinnerVoltage.java
com.androguide.honamicontrol.cards.CardSpinner.java
com.androguide.honamicontrol.cards.CardSwitchDisabled.java
com.androguide.honamicontrol.cards.CardSwitchPlugin.java
com.androguide.honamicontrol.cards.CardTopImageLocal.java
com.androguide.honamicontrol.fragments.CardsFragment.java
com.androguide.honamicontrol.fragments.HelpFragment.java
com.androguide.honamicontrol.fragments.WelcomeFragment.java
com.androguide.honamicontrol.helpers.CPUHelper.java
com.androguide.honamicontrol.helpers.FileHelper.java
com.androguide.honamicontrol.helpers.Helpers.java
com.androguide.honamicontrol.helpers.NegativeSeekBar.java
com.androguide.honamicontrol.helpers.ShellInterface.java
com.androguide.honamicontrol.helpers.SystemPropertiesReflection.java
com.androguide.honamicontrol.helpers.CMDProcessor.AbstractAsyncSuCMDProcessor.java
com.androguide.honamicontrol.helpers.CMDProcessor.CMDProcessor.java
com.androguide.honamicontrol.helpers.CMDProcessor.ChildProcess.java
com.androguide.honamicontrol.helpers.CMDProcessor.CommandResult.java
com.androguide.honamicontrol.helpers.CMDProcessor.Constants.java
com.androguide.honamicontrol.helpers.CMDProcessor.Shell.java
com.androguide.honamicontrol.kernel.KernelFragment.java
com.androguide.honamicontrol.kernel.colorcontrol.ColorControlActivity.java
com.androguide.honamicontrol.kernel.colorcontrol.ColorControlInterface.java
com.androguide.honamicontrol.kernel.cpucontrol.CPUActivity.java
com.androguide.honamicontrol.kernel.cpucontrol.CPUFragment.java
com.androguide.honamicontrol.kernel.cpucontrol.CPUInterface.java
com.androguide.honamicontrol.kernel.cpucontrol.GovernorDialog.java
com.androguide.honamicontrol.kernel.gpucontrol.GPUActivity.java
com.androguide.honamicontrol.kernel.gpucontrol.GPUInterface.java
com.androguide.honamicontrol.kernel.iotweaks.IOTweaksActivity.java
com.androguide.honamicontrol.kernel.iotweaks.IOTweaksInterface.java
com.androguide.honamicontrol.kernel.memory.MemoryManagementActivity.java
com.androguide.honamicontrol.kernel.memory.MemoryManagementInterface.java
com.androguide.honamicontrol.kernel.misc.MiscActivity.java
com.androguide.honamicontrol.kernel.misc.MiscInterface.java
com.androguide.honamicontrol.kernel.powermanagement.PowerManagementActivity.java
com.androguide.honamicontrol.kernel.powermanagement.PowerManagementInterface.java
com.androguide.honamicontrol.kernel.voltagecontrol.VoltageActivity.java
com.androguide.honamicontrol.kernel.voltagecontrol.VoltageInterface.java
com.androguide.honamicontrol.profiles.BalancedProfile.java
com.androguide.honamicontrol.profiles.BatteryMaxProfile.java
com.androguide.honamicontrol.profiles.BatteryProfile.java
com.androguide.honamicontrol.profiles.BenchmarkProfile.java
com.androguide.honamicontrol.profiles.PerformanceProfile.java
com.androguide.honamicontrol.profiles.ProfileEnabler.java
com.androguide.honamicontrol.profiles.Profile.java
com.androguide.honamicontrol.soundcontrol.SoundControlActivity.java
com.androguide.honamicontrol.soundcontrol.SoundControlFragment.java
com.androguide.honamicontrol.soundcontrol.SoundControlInterface.java
com.androguide.honamicontrol.soundcontrol.SoundFragment.java
com.androguide.honamicontrol.touchscreen.TouchScreenFragment.java
com.androguide.honamicontrol.touchscreen.TouchScreenInterface.java
com.astuetz.viewpager.extensions.PagerSlidingTabStrip.java
com.echo.holographlibrary.BarGraph.java
com.echo.holographlibrary.Bar.java
com.echo.holographlibrary.LineGraph.java
com.echo.holographlibrary.LinePoint.java
com.echo.holographlibrary.Line.java
com.echo.holographlibrary.PieGraph.java
com.echo.holographlibrary.PieSlice.java
com.fima.cardsui.StackAdapter.java
com.fima.cardsui.SwipeDismissTouchListener.java
com.fima.cardsui.Utils.java
com.fima.cardsui.objects.AbstractCard.java
com.fima.cardsui.objects.CardStack.java
com.fima.cardsui.objects.Card.java
com.fima.cardsui.views.CardCategory.java
com.fima.cardsui.views.CardDownload.java
com.fima.cardsui.views.CardEditText.java
com.fima.cardsui.views.CardEdit.java
com.fima.cardsui.views.CardImage.java
com.fima.cardsui.views.CardPresentation.java
com.fima.cardsui.views.CardSeekBar.java
com.fima.cardsui.views.CardSpinner.java
com.fima.cardsui.views.CardTextStripe.java
com.fima.cardsui.views.CardText.java
com.fima.cardsui.views.CardTopImage.java
com.fima.cardsui.views.CardUI.java
com.fima.cardsui.views.QuickReturnListView.java