// Path: src/com/painless/glclock/Globals.java
// public class Globals {
// 
// 	public static float compassRotation = 0;
// 
// 	public static int cpuUsage = 0;
// 	public static int cpuUsageAngle = 0;
// 
// 	public static int battery = 0;
// 	public static int batteryCount = 0;
// 
// 	public static int ramUsage = 0;
// }


import android.os.Handler;
import com.painless.glclock.Globals;
import java.io.RandomAccessFile;
package com.painless.glclock.service;




public final class CpuService implements Runnable, RService {

	private static final long REFRESH_RATE = 5000;	// 5 seconds.

	private final Handler updateHandler;

	// keep these static to prevent restart
	private static long lastTotal = -1, lastIdle = -1;

	private boolean running = false;

	public CpuService() {
		updateHandler = new Handler();
	}

	@Override
	public void run() {
		try {
			final RandomAccessFile reader = new RandomAccessFile("/proc/stat", "r");
			String line = reader.readLine();
			reader.close();

			line = line.split(" ", 2) [1];
			final String values[] = line.trim().split(" ");

			final long idle = Long.parseLong(values[3]);
			long total = 0;
			for (int i=0; i<values.length; i++) {
				total += Long.parseLong(values[i]);
			}

			if (lastTotal > 0) {
				final long idleD = idle - lastIdle;
				final long totalD = total - lastTotal;
// Path: src/com/painless/glclock/Globals.java
// public class Globals {
// 
// 	public static float compassRotation = 0;
// 
// 	public static int cpuUsage = 0;
// 	public static int cpuUsageAngle = 0;
// 
// 	public static int battery = 0;
// 	public static int batteryCount = 0;
// 
// 	public static int ramUsage = 0;
// }


// Path: src/com/painless/glclock/service/CpuService.java
import android.os.Handler;
import com.painless.glclock.Globals;
import java.io.RandomAccessFile;

package com.painless.glclock.service;




public final class CpuService implements Runnable, RService {

	private static final long REFRESH_RATE = 5000;	// 5 seconds.

	private final Handler updateHandler;

	// keep these static to prevent restart
	private static long lastTotal = -1, lastIdle = -1;

	private boolean running = false;

	public CpuService() {
		updateHandler = new Handler();
	}

	@Override
	public void run() {
		try {
			final RandomAccessFile reader = new RandomAccessFile("/proc/stat", "r");
			String line = reader.readLine();
			reader.close();

			line = line.split(" ", 2) [1];
			final String values[] = line.trim().split(" ");

			final long idle = Long.parseLong(values[3]);
			long total = 0;
			for (int i=0; i<values.length; i++) {
				total += Long.parseLong(values[i]);
			}

			if (lastTotal > 0) {
				final long idleD = idle - lastIdle;
				final long totalD = total - lastTotal;
				Globals.cpuUsage = (int) (1000 * (totalD - idleD) / totalD + 5) / 10;