Skip to content

Commit

Permalink
fixed the time in state reset bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulkumar66 committed Aug 25, 2014
1 parent 2df4efd commit 20492b2
Show file tree
Hide file tree
Showing 25 changed files with 230 additions and 162 deletions.
16 changes: 15 additions & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
android:targetSdkVersion="21" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
<uses-permission android:name="android.permission.BATTERY_STATS" />
<uses-permission android:name="android.permission.DUMP" />

<application
android:allowBackup="true"
Expand Down Expand Up @@ -47,6 +48,19 @@
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<receiver
android:name="com.phantomLord.cpufrequtils.app.receivers.SaveReferenceReceiver"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
</intent-filter>
</receiver>

<service android:name="com.phantomLord.cpufrequtils.app.services.BootService" >
</service>
<service android:name="com.phantomLord.cpufrequtils.app.services.SaveSinceUnpluggedReferenceService" >
</service>
</application>

</manifest>
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ Simple Android App for

To Download the App

http://forum.xda-developers.com/devdb/project/dl/?id=5724&task=get
http://forum.xda-developers.com/devdb/project/dl/?id=7519&task=get


Third party libraries:

* aChartEngine
* Sherlock-navigation-Drawer
* Actionbar Sherlock
* Android-Common (https://github.com/asksven/AndroidCommon)
Expand All @@ -33,6 +32,7 @@ http://forum.xda-developers.com/showthread.php?t=2728587


=== LICENSE ===

See the LICENSE file.


Expand Down
Binary file removed res/drawable-hdpi/chart.png
Binary file not shown.
Binary file removed res/drawable-mdpi/chart.png
Binary file not shown.
Binary file removed res/drawable-nodpi/github.png
Binary file not shown.
Binary file removed res/drawable-xhdpi/chart.png
Binary file not shown.
Binary file removed res/drawable-xxhdpi/chart.png
Binary file not shown.
12 changes: 0 additions & 12 deletions res/layout/piechart.xml

This file was deleted.

3 changes: 2 additions & 1 deletion res/layout/time_in_states.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
android:id="@+id/time_in_state_listView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.6" >
android:layout_weight="0.6"
android:divider="@null" >
</ListView>

<TextView
Expand Down
3 changes: 2 additions & 1 deletion res/layout/wakelocksfragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
android:id="@+id/wakelock_data_listview1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp" >
android:layout_marginTop="8dp"
android:divider="@null" >
</ListView>

</LinearLayout>
26 changes: 0 additions & 26 deletions res/menu/main.xml

This file was deleted.

4 changes: 0 additions & 4 deletions res/values/colors_apptheme.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,14 @@ public View getView(int position, View arg1, ViewGroup arg2) {
ProgressBar progress = (ProgressBar) rowView
.findViewById(R.id.kernel_progress);

NativeKernelWakelock nativeWakeLock = kernelWakelocks
.get(position);
NativeKernelWakelock nativeWakeLock = kernelWakelocks.get(position);
String kernelWakelock = kernelWakelocks.get(position).getName();
mKernelWakelock.setText(kernelWakelock.substring(1,
kernelWakelock.length() - 1));
mKernelWakelock.setText(kernelWakelock);
WakeupInfo
.setText(SysUtils.secToString(nativeWakeLock.getDuration() / 1000));
progress.setMax(totaltime);
progress.setProgress((int) nativeWakeLock.getDuration() / 1000);
wakeUpCount.setText("x" + nativeWakeLock.getCount()
wakeUpCount.setText("x" + nativeWakeLock.getCount() + " "
+ context.getString(R.string.times));

return rowView;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.phantomLord.cpufrequtils.app.adapters;

import java.util.ArrayList;
import java.util.HashMap;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
Expand All @@ -18,10 +20,12 @@
import com.phantomLord.cpufrequtils.app.utils.SysUtils;
import com.phantomLord.cpufrequtils.app.utils.TimeInStateReader;

@SuppressLint("UseSparseArrays")
public class TimeInStatesListAdapter extends BaseAdapter {

Context context;
ArrayList<CpuState> states = new ArrayList<>();
HashMap<Integer, Long> _states = new HashMap<Integer, Long>();
public long totaltime = 0;
TimeInStateReader statesReader;
LayoutInflater infalter;
Expand All @@ -32,12 +36,13 @@ public TimeInStatesListAdapter(Context context) {
this.context = context;
prefs = PreferenceManager.getDefaultSharedPreferences(context);
filterNonZeroVals = prefs.getBoolean(Constants.PREF_ZERO_VALS, true);
statesReader = new TimeInStateReader();
states = statesReader.getCpuStateTime(true);
statesReader = TimeInStateReader.TimeInStatesReader();
states = statesReader.getCpuStateTime(true, filterNonZeroVals);
totaltime = statesReader.getTotalTimeInState();
/*
* remove zero values
*/

infalter = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
Expand All @@ -52,7 +57,6 @@ public View getView(int position, View convertView, ViewGroup parent) {
.findViewById(R.id.progress);
TextView time = (TextView) rowView.findViewById(R.id.time);
TextView percentage = (TextView) rowView.findViewById(R.id.percentage);

if (states.get(position).getFrequency() == 0)
frequencyTextView.setText(context.getString(R.string.deep_sleep));
else
Expand Down Expand Up @@ -92,14 +96,15 @@ public long getItemId(int position) {
}

public void refresh() {
states = statesReader.getCpuStateTime(true);
states = statesReader.getCpuStateTime(true, filterNonZeroVals);
totaltime = statesReader.getTotalTimeInState();
notifyDataSetChanged();
}

public void saveOffsets() {
String data = "";
ArrayList<CpuState> newStates = statesReader.getCpuStateTime(true);
ArrayList<CpuState> newStates = statesReader.getCpuStateTime(true,
filterNonZeroVals);
for (CpuState state : newStates) {
data += state.getFrequency() + " " + state.getTime() + ",";
}
Expand All @@ -112,24 +117,22 @@ public void reset() {
removeOffsets();
saveOffsets();
loadPreviousStats();
states = statesReader.getCpuStateTime(true);
states = statesReader.getCpuStateTime(true, filterNonZeroVals);
totaltime = statesReader.getTotalTimeInState();
refresh();
}

public void loadPreviousStats() {
ArrayList<CpuState> newStates = new ArrayList<>();
String data = prefs.getString(Constants.PREF_TIS_RESET_STATS, null);

if (data.length() > 0) {
String[] line = data.split(",");
for (String str : line) {
String[] val = str.split(" ");
newStates.add(new CpuState(Integer.parseInt(val[0]), Long
.parseLong(val[1])));
_states.put(Integer.parseInt(val[0]), Long.parseLong(val[1]));
}
}
statesReader.setNewStates(newStates);
statesReader.newStates = _states;
}

public void removeOffsets() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ public class BootReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent mIntent = new Intent(context, BootService.class);
context.startService(mIntent);
context.startService(new Intent(context, BootService.class));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.phantomLord.cpufrequtils.app.receivers;

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;

import com.phantomLord.cpufrequtils.app.services.SaveSinceUnpluggedReferenceService;

public class SaveReferenceReceiver extends WakefulBroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_POWER_DISCONNECTED.equals(intent.getAction())) {
context.startService(new Intent(context,
SaveSinceUnpluggedReferenceService.class));
}
}

}
17 changes: 7 additions & 10 deletions src/com/phantomLord/cpufrequtils/app/services/BootService.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
package com.phantomLord.cpufrequtils.app.services;

import android.app.Service;
import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.preference.PreferenceManager;

import com.phantomLord.cpufrequtils.app.utils.Constants;
import com.phantomLord.cpufrequtils.app.utils.SysUtils;

public class BootService extends Service {
public class BootService extends IntentService {

SharedPreferences prefs;
Context context;

@Override
public IBinder onBind(Intent arg0) {
return null;
public BootService() {
super("Boot Service");
}

@SuppressWarnings("deprecation")
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
protected void onHandleIntent(Intent intent) {
context = getApplicationContext();
prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
editor.putString(Constants.PREF_TIS_RESET_STATS, null);
editor.commit();
try {
Thread.sleep(20000);
Thread.sleep(30000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.phantomLord.cpufrequtils.app.services;

import android.app.IntentService;
import android.content.Intent;
import android.util.Log;

import com.phantomLord.cpufrequtils.app.utils.Constants;

public class SaveSinceUnpluggedReferenceService extends IntentService {

public SaveSinceUnpluggedReferenceService() {
super("Save Unplugged reference service");
}

@Override
protected void onHandleIntent(Intent intent) {
Log.d(Constants.App_Tag, "Saving Unplugged References ");

stopSelf();
}

}
Loading

0 comments on commit 20492b2

Please sign in to comment.