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//www.java2s.com
*
* 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")
publicclass CommandResult implements Parcelable {
privatefinal String TAG = getClass().getSimpleName();
privatefinallong mStartTime;
privatefinalint mExitValue;
privatefinal String mStdout;
privatefinal String mStderr;
privatefinallong 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());
}
publicboolean success() {
return (mExitValue == 0);
}
publiclong getEndTime() {
return mEndTime;
}
public String getStderr() {
returnnew String(mStderr);
}
public String getStdout() {
returnnew String(mStdout);
}
publicInteger getExitValue() {
return mExitValue;
}
publiclong getStartTime() {
return mStartTime;
}
@SuppressWarnings("UnnecessaryExplicitNumericCast")
privatevoid 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 = newFile(
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
publicint describeContents() {
return 0;
}
@Override
publicvoid 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
publicboolean 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
publicint 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;
}
}