import android.os.UEventObserver;
import android.provider.Settings;
import android.util.EventLog;
-import android.util.Log;
+import android.util.Slog;
+import android.os.Handler;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
+import java.util.Timer;
+import java.util.TimerTask;
/**
private boolean mSentLowBatteryBroadcast = false;
+ private final Handler mHandler = new Handler();
+
public BatteryService(Context context) {
mContext = context;
mBatteryStats = BatteryStatsService.getService();
// set initial status
update();
+
+ // start auto refresh
+ autoRefresh();
+ }
+
+ private Runnable mUpdateResults = new Runnable() {
+ public void run() {
+ update();
+ }
+ };
+
+ private final void autoRefresh() {
+ // Schedule every minute
+ new Timer().scheduleAtFixedRate(new TimerTask() {
+ @Override // Override!!
+ public void run() {
+ mHandler.post(mUpdateResults);
+ }
+ }, 60000, 60000);
}
final boolean isPowered() {
void systemReady() {
// check our power situation now that it is safe to display the shutdown dialog.
shutdownIfNoPower();
+ shutdownIfOverTemp();
}
private final void shutdownIfNoPower() {
}
}
+ private final void shutdownIfOverTemp() {
+ // shut down gracefully if temperature is too high (> 68.0C)
+ // wait until the system has booted before attempting to display the shutdown dialog.
+ if (mBatteryTemperature > 680 && ActivityManagerNative.isSystemReady()) {
+ Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
+ intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ mContext.startActivity(intent);
+ }
+ }
+
private native void native_update();
private synchronized final void update() {
long dischargeDuration = 0;
shutdownIfNoPower();
+ shutdownIfOverTemp();
mBatteryLevelCritical = mBatteryLevel <= CRITICAL_BATTERY_LEVEL;
if (mAcOnline) {
intent.putExtra(BatteryManager.EXTRA_TECHNOLOGY, mBatteryTechnology);
if (false) {
- Log.d(TAG, "updateBattery level:" + mBatteryLevel +
+ Slog.d(TAG, "updateBattery level:" + mBatteryLevel +
" scale:" + BATTERY_SCALE + " status:" + mBatteryStatus +
" health:" + mBatteryHealth + " present:" + mBatteryPresent +
" voltage: " + mBatteryVoltage +
// add dump file to drop box
db.addFile("BATTERY_DISCHARGE_INFO", dumpFile, DropBoxManager.IS_TEXT);
} catch (RemoteException e) {
- Log.e(TAG, "failed to dump battery service", e);
+ Slog.e(TAG, "failed to dump battery service", e);
} catch (IOException e) {
- Log.e(TAG, "failed to write dumpsys file", e);
+ Slog.e(TAG, "failed to write dumpsys file", e);
} finally {
// make sure we clean up
if (dumpStream != null) {
try {
dumpStream.close();
} catch (IOException e) {
- Log.e(TAG, "failed to close dumpsys output stream");
+ Slog.e(TAG, "failed to close dumpsys output stream");
}
}
if (dumpFile != null && !dumpFile.delete()) {
- Log.e(TAG, "failed to delete temporary dumpsys file: "
+ Slog.e(TAG, "failed to delete temporary dumpsys file: "
+ dumpFile.getAbsolutePath());
}
}
// If the discharge cycle is bad enough we want to know about it.
logBatteryStats();
}
- if (LOCAL_LOGV) Log.v(TAG, "duration threshold: " + durationThreshold +
+ if (LOCAL_LOGV) Slog.v(TAG, "duration threshold: " + durationThreshold +
" discharge threshold: " + dischargeThreshold);
- if (LOCAL_LOGV) Log.v(TAG, "duration: " + duration + " discharge: " +
+ if (LOCAL_LOGV) Slog.v(TAG, "duration: " + duration + " discharge: " +
(mDischargeStartLevel - mBatteryLevel));
} catch (NumberFormatException e) {
- Log.e(TAG, "Invalid DischargeThresholds GService string: " +
+ Slog.e(TAG, "Invalid DischargeThresholds GService string: " +
durationThresholdString + " or " + dischargeThresholdString);
return;
}
mBatteryStatus == BatteryManager.BATTERY_STATUS_FULL) {
return com.android.internal.R.drawable.stat_sys_battery;
} else {
- return com.android.internal.R.drawable.stat_sys_battery_unknown;
+ return mBatteryPresent ?
+ com.android.internal.R.drawable.stat_sys_battery_unknown :
+ com.android.internal.R.drawable.gpm_ac_adapter;
}
}