diff options
author | Robert Greenwalt <robdroid@android.com> | 2010-04-14 12:11:03 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-04-14 12:11:03 -0700 |
commit | c059f34230b29312e384a12da57c31b2c38c3ca9 (patch) | |
tree | 8245aa2df49df0b682bc7f8d9019c2280a19ff67 /services | |
parent | 7ba155bf5a06faa577df34d0bc38b1e8223fdf31 (diff) | |
parent | b26c8dd432bf0ea8042e04e63c57913c7bd4e3d4 (diff) | |
download | frameworks_base-c059f34230b29312e384a12da57c31b2c38c3ca9.zip frameworks_base-c059f34230b29312e384a12da57c31b2c38c3ca9.tar.gz frameworks_base-c059f34230b29312e384a12da57c31b2c38c3ca9.tar.bz2 |
am b26c8dd4: am 9cb66e89: Merge "Perist Throttle data across reboots" into froyo
Merge commit 'b26c8dd432bf0ea8042e04e63c57913c7bd4e3d4' into kraken
* commit 'b26c8dd432bf0ea8042e04e63c57913c7bd4e3d4':
Perist Throttle data across reboots
Diffstat (limited to 'services')
-rw-r--r-- | services/java/com/android/server/ThrottleService.java | 88 |
1 files changed, 67 insertions, 21 deletions
diff --git a/services/java/com/android/server/ThrottleService.java b/services/java/com/android/server/ThrottleService.java index 71557f5..16fd104 100644 --- a/services/java/com/android/server/ThrottleService.java +++ b/services/java/com/android/server/ThrottleService.java @@ -28,11 +28,11 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.res.Resources; -import android.content.SharedPreferences; import android.database.ContentObserver; import android.net.IThrottleManager; import android.net.ThrottleManager; import android.os.Binder; +import android.os.Environment; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; @@ -48,7 +48,12 @@ import android.util.Slog; import com.android.internal.telephony.TelephonyProperties; +import java.io.BufferedWriter; +import java.io.File; import java.io.FileDescriptor; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; import java.io.PrintWriter; import java.util.Calendar; import java.util.GregorianCalendar; @@ -353,6 +358,8 @@ public class ThrottleService extends IThrottleManager.Stub { onResetAlarm(); + onPollAlarm(); + Intent broadcast = new Intent(ThrottleManager.POLICY_CHANGED_ACTION); mContext.sendBroadcast(broadcast); } @@ -591,7 +598,6 @@ public class ThrottleService extends IThrottleManager.Stub { ThrottleService mParent; Context mContext; - SharedPreferences mSharedPreferences; DataRecorder(Context context, ThrottleService parent) { mContext = context; @@ -605,9 +611,6 @@ public class ThrottleService extends IThrottleManager.Stub { mPeriodStart = Calendar.getInstance(); mPeriodEnd = Calendar.getInstance(); - mSharedPreferences = mContext.getSharedPreferences("ThrottleData", - android.content.Context.MODE_PRIVATE); - zeroData(0); retrieve(); } @@ -698,24 +701,35 @@ public class ThrottleService extends IThrottleManager.Stub { record(); } - private void record() { - // serialize into a secure setting + private File getDataFile() { + 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 // 13*6 long[PERIOD_COUNT] mPeriodRxData // 13*6 long[PERIOD_COUNT] mPeriodTxData // 1 int mCurrentPeriod // 13 long periodStartMS // 13 long periodEndMS - // 199 chars max + // 200 chars max StringBuilder builder = new StringBuilder(); + builder.append(DATA_FILE_VERSION); + builder.append(":"); builder.append(mPeriodCount); builder.append(":"); - for(int i=0; i < mPeriodCount; i++) { + for(int i = 0; i < mPeriodCount; i++) { builder.append(mPeriodRxData[i]); builder.append(":"); } - for(int i=0; i < mPeriodCount; i++) { + for(int i = 0; i < mPeriodCount; i++) { builder.append(mPeriodTxData[i]); builder.append(":"); } @@ -726,32 +740,64 @@ public class ThrottleService extends IThrottleManager.Stub { builder.append(mPeriodEnd.getTimeInMillis()); builder.append(":"); - SharedPreferences.Editor editor = mSharedPreferences.edit(); - - editor.putString("Data", builder.toString()); - editor.commit(); + BufferedWriter out = null; + try { + out = new BufferedWriter(new FileWriter(getDataFile()),256); + 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() { - String data = mSharedPreferences.getString("Data", ""); -// String data = Settings.Secure.getString(mContext.getContentResolver(), -// Settings.Secure.THROTTLE_VALUE); + File f = getDataFile(); + byte[] buffer; + 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; - synchronized (mParent) { String[] parsed = data.split(":"); 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++]); if (parsed.length != 4 + (2 * mPeriodCount)) return; mPeriodRxData = new long[mPeriodCount]; - for(int i=0; i < mPeriodCount; i++) { + for(int i = 0; i < mPeriodCount; i++) { mPeriodRxData[i] = Long.parseLong(parsed[parsedUsed++]); } mPeriodTxData = new long[mPeriodCount]; - for(int i=0; i < mPeriodCount; i++) { + for(int i = 0; i < mPeriodCount; i++) { mPeriodTxData[i] = Long.parseLong(parsed[parsedUsed++]); } mCurrentPeriod = Integer.parseInt(parsed[parsedUsed++]); |