frameworks/base
Révision | 2a452f756905f5640154b12db0884b1b6bd78e87 (tree) |
---|---|
l'heure | 2010-11-22 16:07:16 |
Auteur | Stephane Lajeunesse <stephane.lajeunesse@gmai...> |
Commiter | Chih-Wei Huang |
BatteryService: update battery status periodically
@@ -35,6 +35,7 @@ import android.os.UEventObserver; | ||
35 | 35 | import android.provider.Settings; |
36 | 36 | import android.util.EventLog; |
37 | 37 | import android.util.Slog; |
38 | +import android.os.Handler; | |
38 | 39 | |
39 | 40 | import java.io.File; |
40 | 41 | import java.io.FileDescriptor; |
@@ -42,6 +43,8 @@ import java.io.FileInputStream; | ||
42 | 43 | import java.io.FileOutputStream; |
43 | 44 | import java.io.IOException; |
44 | 45 | import java.io.PrintWriter; |
46 | +import java.util.Timer; | |
47 | +import java.util.TimerTask; | |
45 | 48 | |
46 | 49 | |
47 | 50 | /** |
@@ -119,6 +122,8 @@ class BatteryService extends Binder { | ||
119 | 122 | |
120 | 123 | private boolean mSentLowBatteryBroadcast = false; |
121 | 124 | |
125 | + private final Handler mHandler = new Handler(); | |
126 | + | |
122 | 127 | public BatteryService(Context context) { |
123 | 128 | mContext = context; |
124 | 129 | mBatteryStats = BatteryStatsService.getService(); |
@@ -132,6 +137,25 @@ class BatteryService extends Binder { | ||
132 | 137 | |
133 | 138 | // set initial status |
134 | 139 | update(); |
140 | + | |
141 | + // start auto refresh | |
142 | + autoRefresh(); | |
143 | + } | |
144 | + | |
145 | + private Runnable mUpdateResults = new Runnable() { | |
146 | + public void run() { | |
147 | + update(); | |
148 | + } | |
149 | + }; | |
150 | + | |
151 | + private final void autoRefresh() { | |
152 | + // Schedule every minute | |
153 | + new Timer().scheduleAtFixedRate(new TimerTask() { | |
154 | + @Override // Override!! | |
155 | + public void run() { | |
156 | + mHandler.post(mUpdateResults); | |
157 | + } | |
158 | + }, 60000, 60000); | |
135 | 159 | } |
136 | 160 | |
137 | 161 | final boolean isPowered() { |