Loading core/java/android/app/Activity.java +12 −1 Original line number Diff line number Diff line Loading @@ -1427,7 +1427,9 @@ public class Activity extends ContextThemeWrapper * <li> The function will be called between {@link #onStop} and * {@link #onDestroy}. * <li> A new instance of the activity will <em>always</em> be immediately * created after this one's {@link #onDestroy()} is called. * created after this one's {@link #onDestroy()} is called. In particular, * <em>no</em> messages will be dispatched during this time (when the returned * object does not have an activity to be associated with). * <li> The object you return here will <em>always</em> be available from * the {@link #getLastNonConfigurationInstance()} method of the following * activity instance as described there. Loading @@ -1440,6 +1442,15 @@ public class Activity extends ContextThemeWrapper * may change based on the configuration, including any data loaded from * resources such as strings, layouts, or drawables. * * <p>The guarantee of no message handling during the switch to the next * activity simplifies use with active objects. For example if your retained * state is an {@link android.os.AsyncTask} you are guaranteed that its * call back functions (like {@link android.os.AsyncTask#onPostExecute}) will * not be called from the call here until you execute the next instance's * {@link #onCreate(Bundle)}. (Note however that there is of course no such * guarantee for {@link android.os.AsyncTask#doInBackground} since that is * running in a separate thread.) * * @return Return any Object holding the desired state to propagate to the * next activity instance. */ Loading core/java/android/os/BatteryStats.java +20 −5 Original line number Diff line number Diff line Loading @@ -397,7 +397,7 @@ public abstract class BatteryStats implements Parcelable { } } public final class HistoryItem implements Parcelable { public final static class HistoryItem implements Parcelable { public HistoryItem next; public long time; Loading Loading @@ -482,6 +482,18 @@ public abstract class BatteryStats implements Parcelable { dest.writeInt(states); } public void setTo(HistoryItem o) { time = o.time; cmd = o.cmd; batteryLevel = o.batteryLevel; batteryStatus = o.batteryStatus; batteryHealth = o.batteryHealth; batteryPlugType = o.batteryPlugType; batteryTemperature = o.batteryTemperature; batteryVoltage = o.batteryVoltage; states = o.states; } public void setTo(long time, byte cmd, HistoryItem o) { this.time = time; this.cmd = cmd; Loading Loading @@ -526,6 +538,10 @@ public abstract class BatteryStats implements Parcelable { } } public abstract boolean startIteratingHistoryLocked(); public abstract boolean getNextHistoryLocked(HistoryItem out); /** * Return the current history of battery state changes. */ Loading Loading @@ -1688,8 +1704,8 @@ public abstract class BatteryStats implements Parcelable { */ @SuppressWarnings("unused") public void dumpLocked(PrintWriter pw) { HistoryItem rec = getHistory(); if (rec != null) { final HistoryItem rec = new HistoryItem(); if (startIteratingHistoryLocked()) { pw.println("Battery History:"); long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); int oldState = 0; Loading @@ -1698,7 +1714,7 @@ public abstract class BatteryStats implements Parcelable { int oldPlug = -1; int oldTemp = -1; int oldVolt = -1; while (rec != null) { while (getNextHistoryLocked(rec)) { pw.print(" "); TimeUtils.formatDuration(rec.time-now, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); pw.print(" "); Loading Loading @@ -1803,7 +1819,6 @@ public abstract class BatteryStats implements Parcelable { pw.println(); } oldState = rec.states; rec = rec.next; } pw.println(""); } Loading core/java/com/android/internal/os/BatteryStatsImpl.java +68 −12 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.ReentrantLock; /** * All information we are collecting about things that can happen that impact Loading Loading @@ -3834,6 +3835,22 @@ public final class BatteryStatsImpl extends BatteryStats { } } private HistoryItem mHistoryIterator; public boolean startIteratingHistoryLocked() { return (mHistoryIterator = mHistory) != null; } public boolean getNextHistoryLocked(HistoryItem out) { HistoryItem cur = mHistoryIterator; if (cur == null) { return false; } out.setTo(cur); mHistoryIterator = cur.next; return true; } @Override public HistoryItem getHistory() { return mHistory; Loading Loading @@ -3960,7 +3977,7 @@ public final class BatteryStatsImpl extends BatteryStats { } if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { if (mFile != null) { writeLocked(); writeAsyncLocked(); } } } Loading Loading @@ -4356,11 +4373,22 @@ public final class BatteryStatsImpl extends BatteryStats { } public void shutdownLocked() { writeLocked(); writeSyncLocked(); mShuttingDown = true; } public void writeLocked() { Parcel mPendingWrite = null; final ReentrantLock mWriteLock = new ReentrantLock(); public void writeAsyncLocked() { writeLocked(false); } public void writeSyncLocked() { writeLocked(true); } void writeLocked(boolean sync) { if (mFile == null) { Slog.w("BatteryStats", "writeLocked: no file associated with this instance"); return; Loading @@ -4370,23 +4398,51 @@ public final class BatteryStatsImpl extends BatteryStats { return; } try { FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); Parcel out = Parcel.obtain(); writeSummaryToParcel(out); stream.write(out.marshall()); out.recycle(); mLastWriteTime = SystemClock.elapsedRealtime(); if (mPendingWrite != null) { mPendingWrite.recycle(); } mPendingWrite = out; if (sync) { commitPendingDataToDisk(); } else { Thread thr = new Thread("BatteryStats-Write") { @Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); commitPendingDataToDisk(); } }; thr.start(); } } public void commitPendingDataToDisk() { Parcel next; synchronized (this) { next = mPendingWrite; mPendingWrite = null; mWriteLock.lock(); } try { FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); stream.write(next.marshall()); stream.flush(); stream.close(); mFile.commit(); mLastWriteTime = SystemClock.elapsedRealtime(); return; } catch (IOException e) { Slog.w("BatteryStats", "Error writing battery statistics", e); } mFile.rollback(); } finally { next.recycle(); mWriteLock.unlock(); } } static byte[] readFully(FileInputStream stream) throws java.io.IOException { Loading services/java/com/android/server/WindowManagerService.java +5 −0 Original line number Diff line number Diff line Loading @@ -8316,6 +8316,11 @@ public class WindowManagerService extends IWindowManager.Stub return; } if (mDisplay == null) { // Not yet initialized, nothing to do. return; } boolean recoveringMemory = false; if (mForceRemoves != null) { recoveringMemory = true; Loading services/java/com/android/server/am/ActivityManagerService.java +2 −2 Original line number Diff line number Diff line Loading @@ -1383,7 +1383,7 @@ public final class ActivityManagerService extends ActivityManagerNative mBatteryStatsService = new BatteryStatsService(new File( systemDir, "batterystats.bin").toString()); mBatteryStatsService.getActiveStatistics().readLocked(); mBatteryStatsService.getActiveStatistics().writeLocked(); mBatteryStatsService.getActiveStatistics().writeAsyncLocked(); mOnBattery = mBatteryStatsService.getActiveStatistics().getIsOnBattery(); mBatteryStatsService.getActiveStatistics().setCallback(this); Loading Loading @@ -1536,7 +1536,7 @@ public final class ActivityManagerService extends ActivityManagerNative if (mLastWriteTime < (now-BATTERY_STATS_TIME)) { mLastWriteTime = now; mBatteryStatsService.getActiveStatistics().writeLocked(); mBatteryStatsService.getActiveStatistics().writeAsyncLocked(); } } } Loading Loading
core/java/android/app/Activity.java +12 −1 Original line number Diff line number Diff line Loading @@ -1427,7 +1427,9 @@ public class Activity extends ContextThemeWrapper * <li> The function will be called between {@link #onStop} and * {@link #onDestroy}. * <li> A new instance of the activity will <em>always</em> be immediately * created after this one's {@link #onDestroy()} is called. * created after this one's {@link #onDestroy()} is called. In particular, * <em>no</em> messages will be dispatched during this time (when the returned * object does not have an activity to be associated with). * <li> The object you return here will <em>always</em> be available from * the {@link #getLastNonConfigurationInstance()} method of the following * activity instance as described there. Loading @@ -1440,6 +1442,15 @@ public class Activity extends ContextThemeWrapper * may change based on the configuration, including any data loaded from * resources such as strings, layouts, or drawables. * * <p>The guarantee of no message handling during the switch to the next * activity simplifies use with active objects. For example if your retained * state is an {@link android.os.AsyncTask} you are guaranteed that its * call back functions (like {@link android.os.AsyncTask#onPostExecute}) will * not be called from the call here until you execute the next instance's * {@link #onCreate(Bundle)}. (Note however that there is of course no such * guarantee for {@link android.os.AsyncTask#doInBackground} since that is * running in a separate thread.) * * @return Return any Object holding the desired state to propagate to the * next activity instance. */ Loading
core/java/android/os/BatteryStats.java +20 −5 Original line number Diff line number Diff line Loading @@ -397,7 +397,7 @@ public abstract class BatteryStats implements Parcelable { } } public final class HistoryItem implements Parcelable { public final static class HistoryItem implements Parcelable { public HistoryItem next; public long time; Loading Loading @@ -482,6 +482,18 @@ public abstract class BatteryStats implements Parcelable { dest.writeInt(states); } public void setTo(HistoryItem o) { time = o.time; cmd = o.cmd; batteryLevel = o.batteryLevel; batteryStatus = o.batteryStatus; batteryHealth = o.batteryHealth; batteryPlugType = o.batteryPlugType; batteryTemperature = o.batteryTemperature; batteryVoltage = o.batteryVoltage; states = o.states; } public void setTo(long time, byte cmd, HistoryItem o) { this.time = time; this.cmd = cmd; Loading Loading @@ -526,6 +538,10 @@ public abstract class BatteryStats implements Parcelable { } } public abstract boolean startIteratingHistoryLocked(); public abstract boolean getNextHistoryLocked(HistoryItem out); /** * Return the current history of battery state changes. */ Loading Loading @@ -1688,8 +1704,8 @@ public abstract class BatteryStats implements Parcelable { */ @SuppressWarnings("unused") public void dumpLocked(PrintWriter pw) { HistoryItem rec = getHistory(); if (rec != null) { final HistoryItem rec = new HistoryItem(); if (startIteratingHistoryLocked()) { pw.println("Battery History:"); long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); int oldState = 0; Loading @@ -1698,7 +1714,7 @@ public abstract class BatteryStats implements Parcelable { int oldPlug = -1; int oldTemp = -1; int oldVolt = -1; while (rec != null) { while (getNextHistoryLocked(rec)) { pw.print(" "); TimeUtils.formatDuration(rec.time-now, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); pw.print(" "); Loading Loading @@ -1803,7 +1819,6 @@ public abstract class BatteryStats implements Parcelable { pw.println(); } oldState = rec.states; rec = rec.next; } pw.println(""); } Loading
core/java/com/android/internal/os/BatteryStatsImpl.java +68 −12 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.ReentrantLock; /** * All information we are collecting about things that can happen that impact Loading Loading @@ -3834,6 +3835,22 @@ public final class BatteryStatsImpl extends BatteryStats { } } private HistoryItem mHistoryIterator; public boolean startIteratingHistoryLocked() { return (mHistoryIterator = mHistory) != null; } public boolean getNextHistoryLocked(HistoryItem out) { HistoryItem cur = mHistoryIterator; if (cur == null) { return false; } out.setTo(cur); mHistoryIterator = cur.next; return true; } @Override public HistoryItem getHistory() { return mHistory; Loading Loading @@ -3960,7 +3977,7 @@ public final class BatteryStatsImpl extends BatteryStats { } if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { if (mFile != null) { writeLocked(); writeAsyncLocked(); } } } Loading Loading @@ -4356,11 +4373,22 @@ public final class BatteryStatsImpl extends BatteryStats { } public void shutdownLocked() { writeLocked(); writeSyncLocked(); mShuttingDown = true; } public void writeLocked() { Parcel mPendingWrite = null; final ReentrantLock mWriteLock = new ReentrantLock(); public void writeAsyncLocked() { writeLocked(false); } public void writeSyncLocked() { writeLocked(true); } void writeLocked(boolean sync) { if (mFile == null) { Slog.w("BatteryStats", "writeLocked: no file associated with this instance"); return; Loading @@ -4370,23 +4398,51 @@ public final class BatteryStatsImpl extends BatteryStats { return; } try { FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); Parcel out = Parcel.obtain(); writeSummaryToParcel(out); stream.write(out.marshall()); out.recycle(); mLastWriteTime = SystemClock.elapsedRealtime(); if (mPendingWrite != null) { mPendingWrite.recycle(); } mPendingWrite = out; if (sync) { commitPendingDataToDisk(); } else { Thread thr = new Thread("BatteryStats-Write") { @Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); commitPendingDataToDisk(); } }; thr.start(); } } public void commitPendingDataToDisk() { Parcel next; synchronized (this) { next = mPendingWrite; mPendingWrite = null; mWriteLock.lock(); } try { FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); stream.write(next.marshall()); stream.flush(); stream.close(); mFile.commit(); mLastWriteTime = SystemClock.elapsedRealtime(); return; } catch (IOException e) { Slog.w("BatteryStats", "Error writing battery statistics", e); } mFile.rollback(); } finally { next.recycle(); mWriteLock.unlock(); } } static byte[] readFully(FileInputStream stream) throws java.io.IOException { Loading
services/java/com/android/server/WindowManagerService.java +5 −0 Original line number Diff line number Diff line Loading @@ -8316,6 +8316,11 @@ public class WindowManagerService extends IWindowManager.Stub return; } if (mDisplay == null) { // Not yet initialized, nothing to do. return; } boolean recoveringMemory = false; if (mForceRemoves != null) { recoveringMemory = true; Loading
services/java/com/android/server/am/ActivityManagerService.java +2 −2 Original line number Diff line number Diff line Loading @@ -1383,7 +1383,7 @@ public final class ActivityManagerService extends ActivityManagerNative mBatteryStatsService = new BatteryStatsService(new File( systemDir, "batterystats.bin").toString()); mBatteryStatsService.getActiveStatistics().readLocked(); mBatteryStatsService.getActiveStatistics().writeLocked(); mBatteryStatsService.getActiveStatistics().writeAsyncLocked(); mOnBattery = mBatteryStatsService.getActiveStatistics().getIsOnBattery(); mBatteryStatsService.getActiveStatistics().setCallback(this); Loading Loading @@ -1536,7 +1536,7 @@ public final class ActivityManagerService extends ActivityManagerNative if (mLastWriteTime < (now-BATTERY_STATS_TIME)) { mLastWriteTime = now; mBatteryStatsService.getActiveStatistics().writeLocked(); mBatteryStatsService.getActiveStatistics().writeAsyncLocked(); } } } Loading