Android Open Source - Pimp_my_Z1 Command Result






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

/*
 * Performance Control - An Android CPU Control application Copyright (C) 2012
 * James Roberts// w ww . j  a v a 2  s .co m
 *
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 */

package com.androguide.honamicontrol.helpers.CMDProcessor;

import android.os.Environment;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

@SuppressWarnings("AccessOfSystemProperties")
public class CommandResult implements Parcelable {
    private final String TAG = getClass().getSimpleName();
    private final long mStartTime;
    private final int mExitValue;
    private final String mStdout;
    private final String mStderr;
    private final long mEndTime;

    public CommandResult(long startTime,
                         int exitValue,
                         String stdout,
                         String stderr,
                         long endTime) {
        mStartTime = startTime;
        mExitValue = exitValue;
        mStdout = stdout;
        mStderr = stderr;
        mEndTime = endTime;

        Log.d(TAG, "Time to execute: " + (mEndTime - mStartTime) + " ns (nanoseconds)");
        // this is set last so log from here
        checkForErrors();
    }

    // pretty much just forward the constructor from parcelable to our main
    // loading constructor
    @SuppressWarnings("CastToConcreteClass")
    public CommandResult(Parcel inParcel) {
        this(inParcel.readLong(),
                inParcel.readInt(),
                inParcel.readString(),
                inParcel.readString(),
                inParcel.readLong());
    }

    public boolean success() {
        return (mExitValue == 0);
    }

    public long getEndTime() {
        return mEndTime;
    }

    public String getStderr() {
        return new String(mStderr);
    }

    public String getStdout() {
        return new String(mStdout);
    }

    public Integer getExitValue() {
        return mExitValue;
    }

    public long getStartTime() {
        return mStartTime;
    }

    @SuppressWarnings("UnnecessaryExplicitNumericCast")
    private void checkForErrors() {
        if (mExitValue != 0
                || !"".equals(mStderr.trim())) {
            // don't log the commands that failed
            // because the cpu was offline
            boolean skipOfflineCpu =
                    // if core is off locking fails
                    mStderr.contains("chmod: /sys/devices/system/cpu/cpu")
                            // if core is off applying cpu freqs fails
                            || mStderr.contains(": can't create /sys/devices/system/cpu/cpu");
            String lineEnding = System.getProperty("line.separator");
            FileWriter errorWriter = null;
            try {
                File errorLogFile = new File(
                        Environment.getExternalStorageDirectory()
                                + "/aokp/error.txt");
                if (!errorLogFile.exists()) {
                    errorLogFile.createNewFile();
                }
                errorWriter = new FileWriter(errorLogFile, true);
                // only log the cpu state as offline while writing
                if (skipOfflineCpu) {
                    errorWriter.write(lineEnding);
                    errorWriter.write("Attempted to write to an offline cpu core (ignore me).");
                } else {
                    errorWriter.write(TAG + " shell error detected!");
                    errorWriter.write(lineEnding);
                    errorWriter.write("CommandResult {" + this.toString() + '}');
                    errorWriter.write(lineEnding);
                }
                errorWriter.write(lineEnding);
            } catch (IOException e) {
                Log.e(TAG, "Failed to write command result to error file", e);
            } finally {
                if (errorWriter != null) {
                    try {
                        errorWriter.close();
                    } catch (IOException ignored) {
                        // let it go
                    }
                }
            }
        }
    }

    // implement parcelable
    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeLong(mStartTime);
        parcel.writeInt(mExitValue);
        parcel.writeString(mStdout);
        parcel.writeString(mStderr);
        parcel.writeLong(mEndTime);
    }

    @Override
    public String toString() {
        return "CommandResult{" +
                ", mStartTime=" + mStartTime +
                ", mExitValue=" + mExitValue +
                ", stdout='" + mStdout + "'" +
                ", stderr='" + mStderr + "'" +
                ", mEndTime=" + mEndTime +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof CommandResult)) {
            return false;
        }

        CommandResult that = (CommandResult) o;

        return (mStartTime == that.mStartTime &&
                mExitValue == that.mExitValue &&
                mStdout == that.mStdout &&
                mStderr == that.mStderr &&
                mEndTime == that.mEndTime);
    }

    @Override
    public int hashCode() {
        int result = 0;
        result = 31 * result + (int) (mStartTime ^ (mStartTime >>> 32));
        result = 31 * result + mExitValue;
        result = 31 * result + (mStdout != null ? mStdout.hashCode() : 0);
        result = 31 * result + (mStderr != null ? mStderr.hashCode() : 0);
        result = 31 * result + (int) (mEndTime ^ (mEndTime >>> 32));
        return result;
    }
}




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