am 9cb66e89: Merge "Perist Throttle data across reboots" into froyo
Merge commit '9cb66e89cd0c4bfa8d77591719023b7153fee9b9' into froyo-plus-aosp * commit '9cb66e89cd0c4bfa8d77591719023b7153fee9b9': Perist Throttle data across reboots
This commit is contained in:
@@ -28,11 +28,11 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.net.IThrottleManager;
|
import android.net.IThrottleManager;
|
||||||
import android.net.ThrottleManager;
|
import android.net.ThrottleManager;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
|
import android.os.Environment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
@@ -48,7 +48,12 @@ import android.util.Slog;
|
|||||||
|
|
||||||
import com.android.internal.telephony.TelephonyProperties;
|
import com.android.internal.telephony.TelephonyProperties;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
@@ -353,6 +358,8 @@ public class ThrottleService extends IThrottleManager.Stub {
|
|||||||
|
|
||||||
onResetAlarm();
|
onResetAlarm();
|
||||||
|
|
||||||
|
onPollAlarm();
|
||||||
|
|
||||||
Intent broadcast = new Intent(ThrottleManager.POLICY_CHANGED_ACTION);
|
Intent broadcast = new Intent(ThrottleManager.POLICY_CHANGED_ACTION);
|
||||||
mContext.sendBroadcast(broadcast);
|
mContext.sendBroadcast(broadcast);
|
||||||
}
|
}
|
||||||
@@ -591,7 +598,6 @@ public class ThrottleService extends IThrottleManager.Stub {
|
|||||||
|
|
||||||
ThrottleService mParent;
|
ThrottleService mParent;
|
||||||
Context mContext;
|
Context mContext;
|
||||||
SharedPreferences mSharedPreferences;
|
|
||||||
|
|
||||||
DataRecorder(Context context, ThrottleService parent) {
|
DataRecorder(Context context, ThrottleService parent) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -605,9 +611,6 @@ public class ThrottleService extends IThrottleManager.Stub {
|
|||||||
mPeriodStart = Calendar.getInstance();
|
mPeriodStart = Calendar.getInstance();
|
||||||
mPeriodEnd = Calendar.getInstance();
|
mPeriodEnd = Calendar.getInstance();
|
||||||
|
|
||||||
mSharedPreferences = mContext.getSharedPreferences("ThrottleData",
|
|
||||||
android.content.Context.MODE_PRIVATE);
|
|
||||||
|
|
||||||
zeroData(0);
|
zeroData(0);
|
||||||
retrieve();
|
retrieve();
|
||||||
}
|
}
|
||||||
@@ -698,24 +701,35 @@ public class ThrottleService extends IThrottleManager.Stub {
|
|||||||
record();
|
record();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void record() {
|
private File getDataFile() {
|
||||||
// serialize into a secure setting
|
File dataDir = Environment.getDataDirectory();
|
||||||
|
File throttleDir = new File(dataDir, "system/throttle");
|
||||||
|
throttleDir.mkdirs();
|
||||||
|
File dataFile = new File(throttleDir, "data");
|
||||||
|
return dataFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final int DATA_FILE_VERSION = 1;
|
||||||
|
|
||||||
|
private void record() {
|
||||||
|
// 1 int version
|
||||||
// 1 int mPeriodCount
|
// 1 int mPeriodCount
|
||||||
// 13*6 long[PERIOD_COUNT] mPeriodRxData
|
// 13*6 long[PERIOD_COUNT] mPeriodRxData
|
||||||
// 13*6 long[PERIOD_COUNT] mPeriodTxData
|
// 13*6 long[PERIOD_COUNT] mPeriodTxData
|
||||||
// 1 int mCurrentPeriod
|
// 1 int mCurrentPeriod
|
||||||
// 13 long periodStartMS
|
// 13 long periodStartMS
|
||||||
// 13 long periodEndMS
|
// 13 long periodEndMS
|
||||||
// 199 chars max
|
// 200 chars max
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(DATA_FILE_VERSION);
|
||||||
|
builder.append(":");
|
||||||
builder.append(mPeriodCount);
|
builder.append(mPeriodCount);
|
||||||
builder.append(":");
|
builder.append(":");
|
||||||
for(int i=0; i < mPeriodCount; i++) {
|
for(int i = 0; i < mPeriodCount; i++) {
|
||||||
builder.append(mPeriodRxData[i]);
|
builder.append(mPeriodRxData[i]);
|
||||||
builder.append(":");
|
builder.append(":");
|
||||||
}
|
}
|
||||||
for(int i=0; i < mPeriodCount; i++) {
|
for(int i = 0; i < mPeriodCount; i++) {
|
||||||
builder.append(mPeriodTxData[i]);
|
builder.append(mPeriodTxData[i]);
|
||||||
builder.append(":");
|
builder.append(":");
|
||||||
}
|
}
|
||||||
@@ -726,32 +740,64 @@ public class ThrottleService extends IThrottleManager.Stub {
|
|||||||
builder.append(mPeriodEnd.getTimeInMillis());
|
builder.append(mPeriodEnd.getTimeInMillis());
|
||||||
builder.append(":");
|
builder.append(":");
|
||||||
|
|
||||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
BufferedWriter out = null;
|
||||||
|
try {
|
||||||
editor.putString("Data", builder.toString());
|
out = new BufferedWriter(new FileWriter(getDataFile()),256);
|
||||||
editor.commit();
|
out.write(builder.toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Slog.e(TAG, "Error writing data file");
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
if (out != null) {
|
||||||
|
try {
|
||||||
|
out.close();
|
||||||
|
} catch (Exception e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void retrieve() {
|
private void retrieve() {
|
||||||
String data = mSharedPreferences.getString("Data", "");
|
File f = getDataFile();
|
||||||
// String data = Settings.Secure.getString(mContext.getContentResolver(),
|
byte[] buffer;
|
||||||
// Settings.Secure.THROTTLE_VALUE);
|
FileInputStream s = null;
|
||||||
|
try {
|
||||||
|
buffer = new byte[(int)f.length()];
|
||||||
|
s = new FileInputStream(f);
|
||||||
|
s.read(buffer);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Slog.e(TAG, "Error reading data file");
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
if (s != null) {
|
||||||
|
try {
|
||||||
|
s.close();
|
||||||
|
} catch (Exception e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String data = new String(buffer);
|
||||||
if (data == null || data.length() == 0) return;
|
if (data == null || data.length() == 0) return;
|
||||||
|
|
||||||
synchronized (mParent) {
|
synchronized (mParent) {
|
||||||
String[] parsed = data.split(":");
|
String[] parsed = data.split(":");
|
||||||
int parsedUsed = 0;
|
int parsedUsed = 0;
|
||||||
if (parsed.length < 6) return;
|
if (parsed.length < 6) {
|
||||||
|
Slog.e(TAG, "reading data file with insufficient length - ignoring");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Integer.parseInt(parsed[parsedUsed++]) != DATA_FILE_VERSION) {
|
||||||
|
Slog.e(TAG, "reading data file with bad version - ignoring");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mPeriodCount = Integer.parseInt(parsed[parsedUsed++]);
|
mPeriodCount = Integer.parseInt(parsed[parsedUsed++]);
|
||||||
if (parsed.length != 4 + (2 * mPeriodCount)) return;
|
if (parsed.length != 4 + (2 * mPeriodCount)) return;
|
||||||
|
|
||||||
mPeriodRxData = new long[mPeriodCount];
|
mPeriodRxData = new long[mPeriodCount];
|
||||||
for(int i=0; i < mPeriodCount; i++) {
|
for(int i = 0; i < mPeriodCount; i++) {
|
||||||
mPeriodRxData[i] = Long.parseLong(parsed[parsedUsed++]);
|
mPeriodRxData[i] = Long.parseLong(parsed[parsedUsed++]);
|
||||||
}
|
}
|
||||||
mPeriodTxData = new long[mPeriodCount];
|
mPeriodTxData = new long[mPeriodCount];
|
||||||
for(int i=0; i < mPeriodCount; i++) {
|
for(int i = 0; i < mPeriodCount; i++) {
|
||||||
mPeriodTxData[i] = Long.parseLong(parsed[parsedUsed++]);
|
mPeriodTxData[i] = Long.parseLong(parsed[parsedUsed++]);
|
||||||
}
|
}
|
||||||
mCurrentPeriod = Integer.parseInt(parsed[parsedUsed++]);
|
mCurrentPeriod = Integer.parseInt(parsed[parsedUsed++]);
|
||||||
|
|||||||
Reference in New Issue
Block a user