diff --git a/README.md b/README.md
index 6ff05e3..84925ca 100755
--- a/README.md
+++ b/README.md
@@ -11,9 +11,6 @@ Performance-Tweaker is a simple app for tweaking:
* Virtual Memory
* Build prop Editor
-It also can monitor:
- * Battery or Wakelocks Stats i.e Spot rogue applications or sources which are causing battery drain
-
## Contribution
diff --git a/app/build.gradle b/app/build.gradle
index 3b8c772..a54a12c 100755
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -60,11 +60,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
- implementation 'com.github.lzyzsd:circleprogress:1.2.1'
- implementation 'org.codehaus.jackson:jackson-core-asl:1.9.13'
- implementation 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
implementation 'com.facebook.android:audience-network-sdk:5.8.0'
- implementation 'com.google.code.gson:gson:2.8.0'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.5@aar') {
transitive = true;
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index cb4a4f9..808808d 100755
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -5,11 +5,9 @@
-
-
-
+
diff --git a/app/src/main/java/com/asksven/android/common/CommonLogSettings.java b/app/src/main/java/com/asksven/android/common/CommonLogSettings.java
deleted file mode 100644
index 2f227dd..0000000
--- a/app/src/main/java/com/asksven/android/common/CommonLogSettings.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.asksven.android.common;
-
-/**
- * @author sven
- *
- */
-public class CommonLogSettings
-{
- public static final String LOGGING_TAG = "AndoidCommon";
- public static boolean DEBUG = false;
- public static boolean TRACE = false;
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/NonRootShell.java b/app/src/main/java/com/asksven/android/common/NonRootShell.java
deleted file mode 100644
index 5e763df..0000000
--- a/app/src/main/java/com/asksven/android/common/NonRootShell.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/**
- *
- */
-package com.asksven.android.common;
-
-import com.stericson.RootTools.RootTools;
-import com.stericson.RootTools.execution.CommandCapture;
-import com.stericson.RootTools.execution.Shell;
-
-import java.util.ArrayList;
-import java.util.List;
-
-//import com.asksven.android.contrib.Shell;
-
-/**
- * @author sven
- * Sigleton performing su operations
- *
- */
-public class NonRootShell
-{
- static NonRootShell m_instance = null;
- static Shell m_shell = null;
- private NonRootShell()
- {
- }
-
- public static NonRootShell getInstance()
- {
- if (m_instance == null)
- {
- m_instance = new NonRootShell();
- try
- {
- m_shell = RootTools.getShell(false);
- }
- catch (Exception e)
- {
- m_shell = null;
- }
- }
-
- return m_instance;
- }
-
- public synchronized List run(String command)
- {
- final List res = new ArrayList();
-
- if (m_shell == null)
- {
- // reopen if for whatever reason the shell got closed
- NonRootShell.getInstance();
- }
-
- CommandCapture shellCommand = new CommandCapture(0, command)
- {
- @Override
- public void output(int id, String line)
- {
- res.add(line);
- }
- };
- try
- {
- m_shell.add(shellCommand);
-
- // we need to make this synchronous
- while (!shellCommand.isFinished())
- {
- Thread.sleep(100);
- }
- }
- catch (Exception e)
- {
-
- }
-
- return res;
-
- }
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/RootShell.java b/app/src/main/java/com/asksven/android/common/RootShell.java
deleted file mode 100644
index 0e8e493..0000000
--- a/app/src/main/java/com/asksven/android/common/RootShell.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- *
- */
-package com.asksven.android.common;
-
-import com.stericson.RootTools.RootTools;
-import com.stericson.RootTools.execution.CommandCapture;
-import com.stericson.RootTools.execution.Shell;
-
-import java.util.ArrayList;
-import java.util.List;
-
-//import com.asksven.android.contrib.Shell;
-
-/**
- * @author sven
- * Sigleton performing su operations
- *
- */
-public class RootShell
-{
- static RootShell m_instance = null;
- static Shell m_shell = null;
- private RootShell()
- {
- }
-
- public static RootShell getInstance()
- {
- if (m_instance == null)
- {
- m_instance = new RootShell();
- try
- {
- m_shell = RootTools.getShell(true);
- }
- catch (Exception e)
- {
- m_shell = null;
- }
- }
-
- return m_instance;
- }
-
-// public List run1(String command)
-// {
-// return Shell.SU.run(command);
-// }
-
- public synchronized List run(String command)
- {
- final List res = new ArrayList();
-
- if (!RootTools.isRootAvailable())
- {
- return res;
- }
-
- if (m_shell == null)
- {
- // reopen if for whatever reason the shell got closed
- RootShell.getInstance();
- }
-
- CommandCapture shellCommand = new CommandCapture(0, command)
- {
- @Override
- public void output(int id, String line)
- {
- res.add(line);
- }
- };
- try
- {
- RootTools.getShell(true).add(shellCommand);
-
- // we need to make this synchronous
- while (!shellCommand.isFinished())
- {
- Thread.sleep(100);
- }
- }
- catch (Exception e)
- {
-
- }
-
- return res;
-
- }
-
- public boolean phoneRooted()
- {
- return RootTools.isRootAvailable();
- }
-
- public boolean hasRootPermissions()
- {
- return ((m_shell != null) && (RootTools.isRootAvailable()));
- }
-}
diff --git a/app/src/main/java/com/asksven/android/common/dto/AlarmDto.java b/app/src/main/java/com/asksven/android/common/dto/AlarmDto.java
deleted file mode 100644
index abcc451..0000000
--- a/app/src/main/java/com/asksven/android/common/dto/AlarmDto.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2014 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.dto;
-
-import org.codehaus.jackson.annotate.JsonProperty;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-
-/**
- * A DTO class for Alarms
- * @author sven
- *
- */
-public class AlarmDto implements Serializable
-{
-
- // from StatElement
- @JsonProperty("uid") public int m_uid = -1;
-
- @JsonProperty("total") public long m_total;
-
- // from Alarm
- @JsonProperty("package_name") public String m_strPackageName;
-
- // from Alarm
- @JsonProperty("details") public String m_details;
-
- @JsonProperty("wakeups") public long m_nWakeups;
-
- @JsonProperty("total_count") public long m_nTotalCount;
-
- @JsonProperty("time_running_ms") public long m_timeRunning;
-
- @JsonProperty("items") public ArrayList m_items;
-}
diff --git a/app/src/main/java/com/asksven/android/common/dto/AlarmItemDto.java b/app/src/main/java/com/asksven/android/common/dto/AlarmItemDto.java
deleted file mode 100644
index 801c83e..0000000
--- a/app/src/main/java/com/asksven/android/common/dto/AlarmItemDto.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2014 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.dto;
-
-import org.codehaus.jackson.annotate.JsonProperty;
-
-import java.io.Serializable;
-
-/**
- * A DTO for AlarmItems
- * @author sven
- *
- */
-public class AlarmItemDto implements Serializable
-{
- @JsonProperty("number") public long m_nNumber;
-
- @JsonProperty("intent") public String m_strIntent;
-}
diff --git a/app/src/main/java/com/asksven/android/common/dto/MiscDto.java b/app/src/main/java/com/asksven/android/common/dto/MiscDto.java
deleted file mode 100644
index f00f432..0000000
--- a/app/src/main/java/com/asksven/android/common/dto/MiscDto.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2014 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.dto;
-
-import org.codehaus.jackson.annotate.JsonProperty;
-
-import java.io.Serializable;
-
-/**
- * A FTO for Misc
- * @author sven
- *
- */
-public class MiscDto implements Serializable
-{
-
- // from StatElement
- @JsonProperty("uid") public int m_uid = -1;
-
- @JsonProperty("total") public long m_total;
-
- // from Misc
- @JsonProperty("name") public String m_name;
-
- @JsonProperty("time_on_ms") public long m_timeOn;
-
- @JsonProperty("time_running_ms") public long m_timeRunning;
-}
diff --git a/app/src/main/java/com/asksven/android/common/dto/NativeKernelWakelockDto.java b/app/src/main/java/com/asksven/android/common/dto/NativeKernelWakelockDto.java
deleted file mode 100644
index f401fdc..0000000
--- a/app/src/main/java/com/asksven/android/common/dto/NativeKernelWakelockDto.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2014 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.dto;
-
-import org.codehaus.jackson.annotate.JsonProperty;
-
-import java.io.Serializable;
-
-/**
- * A DTO for NativeKernelWakelock
- * @author sven
- *
- */
-public class NativeKernelWakelockDto implements Serializable
-{
-
- // from StatElement
- @JsonProperty("uid") public int m_uid = -1;
-
- @JsonProperty("total") public long m_total;
-
- // from NativeKernelWakelock
- @JsonProperty("name") public String m_name;
-
- @JsonProperty("details") public String m_details;
-
- @JsonProperty("count") public int m_count;
-
- @JsonProperty("expire_count") public int m_expireCount;
-
- @JsonProperty("wake_count") public int m_wakeCount;
-
- @JsonProperty("active_since") public long m_activeSince;
-
- @JsonProperty("total_time") public long m_ttlTime;
-
- @JsonProperty("sleep_time") public long m_sleepTime;
-
- @JsonProperty("max_time") public long m_maxTime;
-
- @JsonProperty("last_change") public long m_lastChange;
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/dto/NetworkUsageDto.java b/app/src/main/java/com/asksven/android/common/dto/NetworkUsageDto.java
deleted file mode 100644
index 88a47a5..0000000
--- a/app/src/main/java/com/asksven/android/common/dto/NetworkUsageDto.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2014 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.dto;
-
-import org.codehaus.jackson.annotate.JsonProperty;
-
-import java.io.Serializable;
-
-/**
- * A DTO for NetworkUsage
- * @author sven
- *
- */
-public class NetworkUsageDto implements Serializable
-{
-
- // from StatElement
- @JsonProperty("uid") public int m_uid = -1;
-
- @JsonProperty("total") public long m_total;
-
- // from NetworkUsage
- @JsonProperty("bytes_received") public long m_bytesReceived=0;
-
- @JsonProperty("bytes_sent") public long m_bytesSent=0;
-
- @JsonProperty("iface") public String m_iface = "";
-}
diff --git a/app/src/main/java/com/asksven/android/common/dto/ProcessDto.java b/app/src/main/java/com/asksven/android/common/dto/ProcessDto.java
deleted file mode 100644
index c42c458..0000000
--- a/app/src/main/java/com/asksven/android/common/dto/ProcessDto.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2014 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.dto;
-
-import com.google.gson.annotations.SerializedName;
-
-import org.codehaus.jackson.annotate.JsonProperty;
-
-import java.io.Serializable;
-
-/**
- * A DTO for Process
- * @author sven
- *
- */
-public class ProcessDto implements Serializable
-{
-
- // from StatElement
- @JsonProperty("uid") public int m_uid = -1;
-
- @JsonProperty("total") public long m_total;
-
- // from Process
- @JsonProperty("name") public String m_name;
-
- @JsonProperty("system_time") public long m_systemTime;
-
- @SerializedName("user_time") public long m_userTime;
-
- @JsonProperty("starts") public int m_starts;
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/dto/SensorUsageDto.java b/app/src/main/java/com/asksven/android/common/dto/SensorUsageDto.java
deleted file mode 100644
index 785732e..0000000
--- a/app/src/main/java/com/asksven/android/common/dto/SensorUsageDto.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2016 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.dto;
-
-import org.codehaus.jackson.annotate.JsonProperty;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-
-/**
- * A DTO class for Alarms
- * @author sven
- *
- */
-public class SensorUsageDto implements Serializable
-{
-
- // from StatElement
- @JsonProperty("uid") public int m_uid = -1;
-
- // from Sensor
- @JsonProperty("package_name") public String m_strPackageName;
-
- // from Alarm
- @JsonProperty("details") public String m_details;
-
- @JsonProperty("total") public long m_totalTime;
-
- @JsonProperty("items") public ArrayList m_items;
-}
diff --git a/app/src/main/java/com/asksven/android/common/dto/SensorUsageItemDto.java b/app/src/main/java/com/asksven/android/common/dto/SensorUsageItemDto.java
deleted file mode 100644
index 9e0992b..0000000
--- a/app/src/main/java/com/asksven/android/common/dto/SensorUsageItemDto.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2016 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.dto;
-
-import org.codehaus.jackson.annotate.JsonProperty;
-
-import java.io.Serializable;
-
-/**
- * A DTO for SensorItems
- * @author sven
- *
- */
-public class SensorUsageItemDto implements Serializable
-{
- @JsonProperty("time") public long m_nTime;
- @JsonProperty("handle") public int m_nHandle;
-
- @JsonProperty("sensor") public String m_strSensor;
-
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/dto/StateDto.java b/app/src/main/java/com/asksven/android/common/dto/StateDto.java
deleted file mode 100644
index 4587ccf..0000000
--- a/app/src/main/java/com/asksven/android/common/dto/StateDto.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2014 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.dto;
-
-import org.codehaus.jackson.annotate.JsonProperty;
-
-import java.io.Serializable;
-
-/**
- * A DTO for State
- * @author sven
- *
- */
-public class StateDto implements Serializable
-{
-
- // from StatElement
- @JsonProperty("uid") public int m_uid = -1;
-
- @JsonProperty("total") public long m_total;
-
- // from State
- @JsonProperty("freq") public int m_freq = 0;
-
- @JsonProperty("duration_ms") public long m_duration = 0;
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/dto/UidInfoDto.java b/app/src/main/java/com/asksven/android/common/dto/UidInfoDto.java
deleted file mode 100644
index 6e08a1b..0000000
--- a/app/src/main/java/com/asksven/android/common/dto/UidInfoDto.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.dto;
-
-import org.codehaus.jackson.annotate.JsonProperty;
-
-import java.io.Serializable;
-
-/**
- * @author sven
- *
- */
-public class UidInfoDto implements Serializable
-{
- @JsonProperty("uid") public int m_uid;
- @JsonProperty("name") public String m_uidName = "";
- @JsonProperty("package")public String m_uidNamePackage = "";
- @JsonProperty("unique") public boolean m_uidUniqueName = false;
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/dto/WakelockDto.java b/app/src/main/java/com/asksven/android/common/dto/WakelockDto.java
deleted file mode 100644
index c151215..0000000
--- a/app/src/main/java/com/asksven/android/common/dto/WakelockDto.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2014 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.dto;
-
-import org.codehaus.jackson.annotate.JsonProperty;
-
-import java.io.Serializable;
-
-/**
- * A DTO for Wakelock
- * @author sven
- *
- */
-public class WakelockDto implements Serializable
-{
-
- // from StatElement
- @JsonProperty("uid") public int m_uid;
-
- @JsonProperty("total") public long m_total;
-
- // from Wakelock
- @JsonProperty("wake_type") public int m_wakeType;
-
- @JsonProperty("name") public String m_name;
-
- @JsonProperty("duration_ms") public long m_duration;
-
- @JsonProperty("count") public int m_count;
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/kernelutils/AlarmsDumpsys.java b/app/src/main/java/com/asksven/android/common/kernelutils/AlarmsDumpsys.java
deleted file mode 100644
index 8c636fa..0000000
--- a/app/src/main/java/com/asksven/android/common/kernelutils/AlarmsDumpsys.java
+++ /dev/null
@@ -1,746 +0,0 @@
-/**
- *
- */
-package com.asksven.android.common.kernelutils;
-
-import android.os.Build;
-import android.util.Log;
-
-import com.asksven.android.common.NonRootShell;
-import com.asksven.android.common.RootShell;
-import com.asksven.android.common.privateapiproxies.Alarm;
-import com.asksven.android.common.privateapiproxies.StatElement;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-//import com.asksven.android.contrib.Shell;
-
-/**
- * Parses the content of 'dumpsys alarm'
- * processes the result of 'dumpsys alarm' as explained in KB article
- * https://github.com/asksven/BetterBatteryStats-Knowledge-Base/wiki/AlarmManager
- * @author sven
- */
-public class AlarmsDumpsys
-{
- static final String TAG = "AlarmsDumpsys";
- static final String PERMISSION_DENIED = "su rights required to access alarms are not available / were not granted";
- static final String SERVICE_NOT_ACCESSIBLE = "Can't find service: alarm";
-
- public static ArrayList getAlarms(boolean useRoot)
- {
- String release = Build.VERSION.RELEASE;
- int sdk = Build.VERSION.SDK_INT;
- Log.i(TAG, "getAlarms: SDK=" + sdk + ", RELEASE=" + release);
-
- List res = null;
- if (true) //(useRoot) // dumpsys seems to always require root, even if perm is available
- {
- res = RootShell.getInstance().run("dumpsys alarm");
- }
- else
- {
- res = NonRootShell.getInstance().run("dumpsys alarm");
- }
-
- if (sdk < 17) // Build.VERSION_CODES.JELLY_BEAN_MR1)
- {
- return getAlarmsPriorTo_4_2_2(res);
- }
- else if (sdk == Build.VERSION_CODES.JELLY_BEAN_MR1)
- {
- if (release.equals("4.2.2"))
- {
- return getAlarmsFrom_4_2_2(res);
- }
- else
- {
- return getAlarmsPriorTo_4_2_2(res);
- }
- }
-
- else if (sdk <= 19)
- {
- return getAlarmsFrom_4_3(res);
- }
- else if (sdk < 23 )
- {
- return getAlarmsFrom_5(res);
- }
- else
- {
- return getAlarmsFrom_6(res);
- }
- }
- /**
- * Returns a list of alarm value objects
- * @return
- * @throws Exception
- */
- protected static ArrayList getAlarmsPriorTo_4_2_2(List res)
- {
- ArrayList myAlarms = null;
- long nTotalCount = 0;
-
-// if (res.getSuccess())
- if ((res != null) && (res.size() != 0))
-
- {
-// String strRes = res.getResultLine();
- if (!res.contains("Permission Denial"))
- {
- Pattern begin = Pattern.compile("Alarm Stats");
- boolean bParsing = false;
-// ArrayList myRes = res.getResult(); // getTestData();
-
- // we are looking for multiline entries in the format
- // '
- // ' ms running, wakeups
- // ' alarms: act= flg= (repeating 1..n times)
- Pattern packagePattern = Pattern.compile("\\s\\s([a-z][a-zA-Z0-9\\.]+)");
- Pattern timePattern = Pattern.compile("\\s\\s(\\d+)ms running, (\\d+) wakeups");
- Pattern numberPattern = Pattern.compile("\\s\\s(\\d+) alarms: (flg=[a-z0-9]+\\s){0,1}(act|cmp)=([A-Za-z0-9\\-\\_\\.\\{\\}\\/\\{\\}\\$]+)");
-
- myAlarms = new ArrayList();
- Alarm myAlarm = null;
-
- // process the file
- for (int i=0; i < res.size(); i++)
- {
- // skip till start mark found
- if (bParsing)
- {
- // parse the alarms by block
- String line = res.get(i);
- Matcher mPackage = packagePattern.matcher(line);
- Matcher mTime = timePattern.matcher(line);
- Matcher mNumber = numberPattern.matcher(line);
-
- // first line
- if ( mPackage.find() )
- {
- try
- {
- // if there was a previous Alarm populated store it
- if (myAlarm != null)
- {
- myAlarms.add(myAlarm);
- }
- // we are interested in the first token
- String strPackageName = mPackage.group(1);
- myAlarm = new Alarm(strPackageName);
- }
- catch (Exception e)
- {
- Log.e(TAG, "Error: parsing error in package line (" + line + ")");
- }
- }
-
- // second line
- if ( mTime.find() )
- {
- try
- {
- // we are interested in the second token
- String strWakeups = mTime.group(2);
- long nWakeups = Long.parseLong(strWakeups);
-
- if (myAlarm == null)
- {
- Log.e(TAG, "Error: time line found but without alarm object (" + line + ")");
- }
- else
- {
- myAlarm.setWakeups(nWakeups);
- nTotalCount += nWakeups;
- }
- }
- catch (Exception e)
- {
- Log.e(TAG, "Error: parsing error in time line (" + line + ")");
- }
- }
-
- // third line (and following till next package
- if ( mNumber.find() )
- {
- try
- {
- // we are interested in the first and second token
- String strNumber = mNumber.group(1);
- String strIntent = mNumber.group(4);
- long nNumber = Long.parseLong(strNumber);
-
- if (myAlarm == null)
- {
- Log.e(TAG, "Error: number line found but without alarm object (" + line + ")");
- }
- else
- {
- myAlarm.addItem(nNumber, strIntent);
- }
- }
- catch (Exception e)
- {
- Log.e(TAG, "Error: parsing error in number line (" + line + ")");
- }
- }
- }
- else
- {
- // look for beginning
- Matcher line = begin.matcher(res.get(i));
- if (line.find())
- {
- bParsing = true;
- }
- }
- }
- // the last populated alarms has not been added to the list yet
- myAlarms.add(myAlarm);
-
- }
- else
- {
- myAlarms = new ArrayList();
- Alarm myAlarm = new Alarm(PERMISSION_DENIED);
- myAlarm.setWakeups(1);
- myAlarms.add(myAlarm);
- }
- }
- else
- {
- myAlarms = new ArrayList();
- Alarm myAlarm = new Alarm(PERMISSION_DENIED);
- myAlarm.setWakeups(1);
- myAlarms.add(myAlarm);
-
- }
-
-
- for (int i=0; i < myAlarms.size(); i++)
- {
- ((Alarm)myAlarms.get(i)).setTotalCount(nTotalCount);
- }
- return myAlarms;
- }
-
- protected static ArrayList getAlarmsFrom_4_2_2(List res)
- {
- ArrayList myAlarms = null;
- long nTotalCount = 0;
-
- if ((res != null) && (res.size() != 0))
-
- {
- Pattern begin = Pattern.compile("Alarm Stats");
- boolean bParsing = false;
-
- // we are looking for multiline entries in the format
- // ' +ms running, wakeups
- // ' +ms wakes alarms: act= (repeating 1..n times)
- Pattern packagePattern = Pattern.compile("\\s\\s([a-z][a-zA-Z0-9\\.]+)\\s\\+(.*), (\\d+) wakeups:");
- Pattern numberPattern = Pattern.compile("\\s\\s\\s\\s\\+([0-9a-z]+)ms (\\d+) wakes (\\d+) alarms: (act|cmp)=([A-Za-z0-9\\-\\_\\.\\$\\{\\}]+)");
-
- myAlarms = new ArrayList();
- Alarm myAlarm = null;
-
- // process the file
- for (int i=0; i < res.size(); i++)
- {
- // skip till start mark found
- if (bParsing)
- {
- // parse the alarms by block
- String line = res.get(i);
- Matcher mPackage = packagePattern.matcher(line);
- Matcher mNumber = numberPattern.matcher(line);
-
- // first line
- if ( mPackage.find() )
- {
- try
- {
- // if there was a previous Alarm populated store it
- if (myAlarm != null)
- {
- myAlarms.add(myAlarm);
- }
- // we are interested in the first token
- String strPackageName = mPackage.group(1);
- myAlarm = new Alarm(strPackageName);
-
- String strWakeups = mPackage.group(3);
- long nWakeups = Long.parseLong(strWakeups);
- myAlarm.setWakeups(nWakeups);
- nTotalCount += nWakeups;
-
- }
- catch (Exception e)
- {
- Log.e(TAG, "Error: parsing error in package line (" + line + ")");
- }
- }
-
- // second line (and following till next package)
- if ( mNumber.find() )
- {
- try
- {
- // we are interested in the first and second token
- String strNumber = mNumber.group(2);
- String strIntent = mNumber.group(5);
- long nNumber = Long.parseLong(strNumber);
-
- if (myAlarm == null)
- {
- Log.e(TAG, "Error: number line found but without alarm object (" + line + ")");
- }
- else
- {
- myAlarm.addItem(nNumber, strIntent);
- }
- }
- catch (Exception e)
- {
- Log.e(TAG, "Error: parsing error in number line (" + line + ")");
- }
- }
- }
- else
- {
- // look for beginning
- Matcher line = begin.matcher(res.get(i));
- if (line.find())
- {
- bParsing = true;
- }
- }
- }
- // the last populated alarms has not been added to the list yet
- myAlarms.add(myAlarm);
-
- }
- else
- {
- myAlarms = new ArrayList();
- Alarm myAlarm = new Alarm(PERMISSION_DENIED);
- myAlarm.setWakeups(1);
- myAlarms.add(myAlarm);
-
- }
-
-
- for (int i=0; i < myAlarms.size(); i++)
- {
- Alarm myAlarm = (Alarm)myAlarms.get(i);
- if (myAlarm != null)
- {
- myAlarm.setTotalCount(nTotalCount);
- }
- }
- return myAlarms;
- }
- protected static ArrayList getAlarmsFrom_4_3(List res)
- {
- ArrayList myAlarms = null;
- long nTotalCount = 0;
-
- if ((res != null) && (res.size() != 0))
-
- {
- Pattern begin = Pattern.compile("Alarm Stats");
- boolean bParsing = false;
-
- // we are looking for multiline entries in the format
- // ' +ms running, wakeups
- // ' +ms wakes alarms: act= (repeating 1..n times)
- Pattern packagePattern = Pattern.compile("\\s\\s([a-z][a-zA-Z0-9\\.]+)\\s\\+(.*), (\\d+) wakeups:");
- Pattern numberPattern = Pattern.compile("\\s\\s\\s\\s\\+([0-9a-z]+)ms (\\d+) wakes (\\d+) alarms: (act|cmp)=(.*)");
-
- myAlarms = new ArrayList();
- Alarm myAlarm = null;
-
- // process the file
- for (int i=0; i < res.size(); i++)
- {
- // skip till start mark found
- if (bParsing)
- {
- // parse the alarms by block
- String line = res.get(i);
- Matcher mPackage = packagePattern.matcher(line);
- Matcher mNumber = numberPattern.matcher(line);
-
- // first line
- if ( mPackage.find() )
- {
- try
- {
- // if there was a previous Alarm populated store it
- if (myAlarm != null)
- {
- myAlarms.add(myAlarm);
- }
- // we are interested in the first token
- String strPackageName = mPackage.group(1);
- myAlarm = new Alarm(strPackageName);
-
- String strWakeups = mPackage.group(3);
- long nWakeups = Long.parseLong(strWakeups);
- myAlarm.setWakeups(nWakeups);
- nTotalCount += nWakeups;
-
- }
- catch (Exception e)
- {
- Log.e(TAG, "Error: parsing error in package line (" + line + ")");
- }
- }
-
- // second line (and following till next package)
- if ( mNumber.find() )
- {
- try
- {
- // we are interested in the first and second token
- String strNumber = mNumber.group(2);
- String strIntent = mNumber.group(5);
- long nNumber = Long.parseLong(strNumber);
-
- if (myAlarm == null)
- {
- Log.e(TAG, "Error: number line found but without alarm object (" + line + ")");
- }
- else
- {
- myAlarm.addItem(nNumber, strIntent);
- }
- }
- catch (Exception e)
- {
- Log.e(TAG, "Error: parsing error in number line (" + line + ")");
- }
- }
- }
- else
- {
- // look for beginning
- Matcher line = begin.matcher(res.get(i));
- if (line.find())
- {
- bParsing = true;
- }
- }
- }
- // the last populated alarms has not been added to the list yet
- myAlarms.add(myAlarm);
-
- }
- else
- {
- myAlarms = new ArrayList();
- Alarm myAlarm = new Alarm(PERMISSION_DENIED);
- myAlarm.setWakeups(1);
- myAlarms.add(myAlarm);
-
- }
-
-
- for (int i=0; i < myAlarms.size(); i++)
- {
- Alarm myAlarm = (Alarm)myAlarms.get(i);
- if (myAlarm != null)
- {
- myAlarm.setTotalCount(nTotalCount);
- }
- }
- return myAlarms;
- }
-
- protected static ArrayList getAlarmsFrom_5(List res)
- {
- ArrayList myAlarms = null;
- long nTotalCount = 0;
-
- if ((res != null) && (res.size() != 0))
-
- {
- Pattern begin = Pattern.compile("Alarm Stats");
- boolean bParsing = false;
-
- // we are looking for multiline entries in the format
- // ' +ms running, wakeups
- // ' +ms wakes alarms: act= (repeating 1..n times)
- Pattern packagePattern = Pattern.compile("\\s\\s.*:([a-z][a-zA-Z0-9\\.]+)\\s\\+(.*), (\\d+) wakeups:");
- Pattern numberPattern = Pattern.compile("\\s\\s\\s\\s\\+([0-9a-z]+)ms (\\d+) wakes (\\d+) alarms: (\\*alarm\\*|\\*walarm\\*):(.*)");
-
- myAlarms = new ArrayList();
- Alarm myAlarm = null;
-
- // process the file
- for (int i=0; i < res.size(); i++)
- {
- // skip till start mark found
- if (bParsing)
- {
- // parse the alarms by block
- String line = res.get(i);
- Matcher mPackage = packagePattern.matcher(line);
- Matcher mNumber = numberPattern.matcher(line);
-
- // first line
- if ( mPackage.find() )
- {
- try
- {
- // if there was a previous Alarm populated store it
- if (myAlarm != null)
- {
- myAlarms.add(myAlarm);
- }
- // we are interested in the first token
- String strPackageName = mPackage.group(1);
- myAlarm = new Alarm(strPackageName);
-
- String strWakeups = mPackage.group(3);
- long nWakeups = Long.parseLong(strWakeups);
- myAlarm.setWakeups(nWakeups);
- nTotalCount += nWakeups;
-
- }
- catch (Exception e)
- {
- Log.e(TAG, "Error: parsing error in package line (" + line + ")");
- }
- }
-
- // second line (and following till next package)
- if ( mNumber.find() )
- {
- try
- {
- // we are interested in the first and second token
- String strNumber = mNumber.group(2);
- String strIntent = mNumber.group(5);
- long nNumber = Long.parseLong(strNumber);
-
- if (myAlarm == null)
- {
- Log.e(TAG, "Error: number line found but without alarm object (" + line + ")");
- }
- else
- {
- myAlarm.addItem(nNumber, strIntent);
- }
- }
- catch (Exception e)
- {
- Log.e(TAG, "Error: parsing error in number line (" + line + ")");
- }
- }
- }
- else
- {
- // look for beginning
- Matcher line = begin.matcher(res.get(i));
- if (line.find())
- {
- bParsing = true;
- }
- }
- }
- // the last populated alarms has not been added to the list yet
- myAlarms.add(myAlarm);
-
- }
- else
- {
- myAlarms = new ArrayList();
- Alarm myAlarm = new Alarm(PERMISSION_DENIED);
- myAlarm.setWakeups(1);
- myAlarms.add(myAlarm);
-
- }
-
-
- for (int i=0; i < myAlarms.size(); i++)
- {
- Alarm myAlarm = (Alarm)myAlarms.get(i);
- if (myAlarm != null)
- {
- myAlarm.setTotalCount(nTotalCount);
- }
- }
- return myAlarms;
- }
-
- protected static ArrayList getAlarmsFrom_6(List res)
- {
- ArrayList myAlarms = null;
- long nTotalCount = 0;
-
- if ((res != null) && (res.size() != 0))
-
- {
- Pattern begin = Pattern.compile("Alarm Stats");
- boolean bParsing = false;
-
- // we are looking for multiline entries in the format
- // ' +ms running, wakeups
- // ' +ms wakes alarms: act= (repeating 1..n times)
- Pattern packagePattern = Pattern.compile("\\s\\s.*:([a-z][a-zA-Z0-9\\.]+)\\s\\+(.*), (\\d+) wakeups:");
- Pattern numberPattern = Pattern.compile("\\s\\s\\s\\s\\+([0-9a-z]+)ms (\\d+) wakes (\\d+) alarms(.*)");
- Pattern detailsPattern = Pattern.compile("\\s\\s\\s\\s\\s\\s(\\*alarm\\*|\\*walarm\\*):(.*)");
-
- myAlarms = new ArrayList();
- Alarm myAlarm = null;
- long nNumber = 0;
-
- // process the file
- for (int i=0; i < res.size(); i++)
- {
- // skip till start mark found
- if (bParsing)
- {
- // parse the alarms by block
- String line = res.get(i);
-
- Matcher mPackage = packagePattern.matcher(line);
- Matcher mNumber = numberPattern.matcher(line);
- Matcher mDetails = detailsPattern.matcher(line);
-
- // first line
- if ( mPackage.find() )
- {
- try
- {
- // if there was a previous Alarm populated store it
- if (myAlarm != null)
- {
- myAlarms.add(myAlarm);
- }
- // we are interested in the first token
- String strPackageName = mPackage.group(1);
- myAlarm = new Alarm(strPackageName);
-
- String strWakeups = mPackage.group(3);
- long nWakeups = Long.parseLong(strWakeups);
- myAlarm.setWakeups(nWakeups);
- nTotalCount += nWakeups;
-
- }
- catch (Exception e)
- {
- Log.e(TAG, "Error: parsing error in package line (" + line + ")");
- }
- }
-
- // second line
- if ( mNumber.find() )
- {
- try
- {
- // we are interested in the first and second token
- String strNumber = mNumber.group(2);
- nNumber = Long.parseLong(strNumber);
-
- if (myAlarm == null)
- {
- Log.e(TAG, "Error: number line found but without alarm object (" + line + ")");
- }
-
- }
- catch (Exception e)
- {
- Log.e(TAG, "Error: parsing error in number line (" + line + ")");
- }
- }
- // third line
- if ( mDetails.find() )
- {
- try
- {
- // we are interested in the first and second token
- String strIntent = mDetails.group(2);
-
- if (myAlarm == null)
- {
- Log.e(TAG, "Error: number line found but without alarm object (" + line + ")");
- }
- else
- {
- System.out.println("Added: " + strIntent + "(" + nNumber + ")");
- myAlarm.addItem(nNumber, strIntent);
- }
- }
- catch (Exception e)
- {
- Log.e(TAG, "Error: parsing error in number line (" + line + ")");
- }
- }
-
- }
- else
- {
- // look for beginning
- Matcher line = begin.matcher(res.get(i));
- if (line.find())
- {
- bParsing = true;
- }
- }
- }
- // the last populated alarms has not been added to the list yet
- if (myAlarm != null)
- {
- myAlarms.add(myAlarm);
- }
-
- }
- else
- {
- myAlarms = new ArrayList();
- Alarm myAlarm = new Alarm(PERMISSION_DENIED);
- myAlarm.setWakeups(1);
- myAlarms.add(myAlarm);
-
- }
-
-
- for (int i=0; i < myAlarms.size(); i++)
- {
- Alarm myAlarm = (Alarm)myAlarms.get(i);
- if (myAlarm != null)
- {
- myAlarm.setTotalCount(nTotalCount);
- }
- }
- return myAlarms;
- }
- public static boolean alarmsAccessible()
- {
- List res = RootShell.getInstance().run("dumpsys alarm");
-
- if ((res == null) || (res.size() == 0))
- {
- return false;
- }
- else
- {
- String val = res.get(0);
- if (val.equals(SERVICE_NOT_ACCESSIBLE))
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- }
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/kernelutils/CpuStates.java b/app/src/main/java/com/asksven/android/common/kernelutils/CpuStates.java
deleted file mode 100644
index d8e5678..0000000
--- a/app/src/main/java/com/asksven/android/common/kernelutils/CpuStates.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.asksven.android.common.kernelutils;
-
-
-/**
- * This class retrieves time in state info from sysfs
- * Adapted from
- * https://github.com/project-voodoo/android_oc-uv_stability_test
- * and
- * https://github.com/storm717/cpuspy
- * @author sven
- *
- */
-
-import android.os.SystemClock;
-import android.util.Log;
-
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-
-public class CpuStates
-{
- private static final String TAG = "CpuStates";
-
- // path to sysfs
- public static final String TIME_IN_STATE_PATH = "/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state";
- public static final String VERSION_PATH = "/proc/version";
-
-
- public static ArrayList getTimesInStates()
- {
- ArrayList states = new ArrayList();
- long totalTime = 0;
- try
- {
- // create a buffered reader to read in the time-in-states log
- InputStream is = new FileInputStream (TIME_IN_STATE_PATH);
- InputStreamReader ir = new InputStreamReader (is);
- BufferedReader br = new BufferedReader (ir);
-
- String line;
- while ( (line = br.readLine ()) != null )
- {
- // split open line and convert to Integers
- String[] nums = line.split (" ");
-
- // duration x 10 to store ms
- State myState = new State(Integer.parseInt(nums[0]), Long.parseLong(nums[1])*10);
- totalTime += myState.m_duration;
- states.add(myState);
- }
-
- is.close ();
-
- }
- catch (Exception e)
- {
- Log.e (TAG, e.getMessage() );
- return null;
- }
-
- // add in sleep state
- long sleepTime = SystemClock.elapsedRealtime() - SystemClock.uptimeMillis();
- states.add( new State(0, sleepTime));
- totalTime += sleepTime;
-
- // store the total time in order to be able to calculate ratio
- for (int i = 0; i < states.size(); i++ )
- {
- states.get(i).setTotal(totalTime);
- }
-
- return states;
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/asksven/android/common/kernelutils/NativeKernelWakelock.java b/app/src/main/java/com/asksven/android/common/kernelutils/NativeKernelWakelock.java
deleted file mode 100644
index 460e69e..0000000
--- a/app/src/main/java/com/asksven/android/common/kernelutils/NativeKernelWakelock.java
+++ /dev/null
@@ -1,435 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.kernelutils;
-
-import android.util.Log;
-
-import com.asksven.android.common.dto.NativeKernelWakelockDto;
-import com.asksven.android.common.nameutils.UidNameResolver;
-import com.asksven.android.common.privateapiproxies.StatElement;
-import com.asksven.android.common.utils.StringUtils;
-import com.google.gson.annotations.SerializedName;
-
-import java.io.Serializable;
-import java.util.Comparator;
-import java.util.List;
-
-//import android.content.Context;
-
-/**
- * @author sven
- *
- */
-public class NativeKernelWakelock extends StatElement implements Comparable, Serializable
-{
-
- // a kernel wakelock from /proc/wakelocks is of the format
- // [name, count, expire_count, wake_count, active_since, total_time, sleep_time, max_time, last_change]
-
- /**
- * the tag for logging
- */
- private static transient final String TAG = "NativeKernelWakelock";
-
- /**
- * the name of the wakelock holder
- */
- @SerializedName("name")
- private String m_name;
-
- /**
- * the details (packages) for that wakelock (if any
- */
- @SerializedName("details")
- private String m_details;
-
- /**
- * the count
- */
- @SerializedName("count")
- private int m_count;
-
- /**
- * the expire count
- */
- @SerializedName("expire_count")
- private int m_expireCount;
-
- /**
- * the wake count
- */
- @SerializedName("wake_count")
- private int m_wakeCount;
-
- /**
- * the active_since time
- */
- @SerializedName("active_since")
- private long m_activeSince;
-
- /**
- * the total_time
- */
- @SerializedName("total_time")
- private long m_ttlTime;
-
- /**
- * the sleep time
- */
- @SerializedName("sleep_time")
- private long m_sleepTime;
-
- /**
- * the max time
- */
- @SerializedName("max_time")
- private long m_maxTime;
-
- /**
- * the last change
- */
- @SerializedName("last_change")
- private long m_lastChange;
-
- public NativeKernelWakelock()
- {
-
- }
-
- /**
- * Creates a wakelock instance
- * @param wakeType the type of wakelock (partial or full)
- * @param name the speaking name
- * @param duration the duration the wakelock was held
- * @param time the battery realtime
- * @param count the number of time the wakelock was active
- */
- public NativeKernelWakelock(String name, String details, int count, int expire_count, int wake_count, long active_since, long total_time, long sleep_time, long max_time, long last_change, long time)
- {
- // hack: remove "deleted: " from wakelock label (Siyah 1.5b6)
- if (name.startsWith("\"deleted: "))
- {
- m_name = "\"" + name.split(" ")[1];
- }
- else
- {
- m_name = name;
- }
- m_details = details;
- m_count = count;
- m_expireCount = expire_count;
- m_wakeCount = wake_count;
- m_activeSince = active_since;
- m_ttlTime = total_time;
- m_sleepTime = sleep_time;
- m_maxTime = max_time;
- m_lastChange = last_change;
- setTotal(time);
- }
-
- public NativeKernelWakelock(NativeKernelWakelockDto source)
- {
-
- this.setUid(source.m_uid);
- this.m_activeSince = source.m_activeSince;
- this.m_count = source.m_count;
- this.m_details = source.m_details;
- this.m_expireCount = source.m_expireCount;
- this.m_lastChange = source.m_lastChange;
- this.m_maxTime = source.m_maxTime;
- this.m_name = source.m_name;
- this.m_sleepTime = source.m_sleepTime;
- this.m_ttlTime = source.m_ttlTime;
- this.m_wakeCount = source.m_wakeCount;
- setTotal(source.m_total);
-
- }
-
- public NativeKernelWakelockDto toDto()
- {
- NativeKernelWakelockDto ret = new NativeKernelWakelockDto();
- ret.m_uid = this.getuid();
- ret.m_activeSince = this.m_activeSince;
- ret.m_count = this.m_count;
- ret.m_details = this.m_details;
- ret.m_expireCount = this.m_expireCount;
- ret.m_lastChange = this.m_lastChange;
- ret.m_maxTime = this.m_maxTime;
- ret.m_name = this.m_name;
- ret.m_sleepTime = this.m_sleepTime;
- ret.m_ttlTime = this.m_ttlTime;
- ret.m_wakeCount = this.m_wakeCount;
- ret.m_total = this.getTotal();
- return ret;
- }
-
- public NativeKernelWakelock clone()
- {
- NativeKernelWakelock clone = new NativeKernelWakelock(m_name, m_details, m_count, m_expireCount, m_wakeCount, m_activeSince, m_ttlTime,
- m_sleepTime, m_maxTime, m_lastChange, getTotal());
- clone.m_icon = m_icon;
- clone.m_uidInfo = m_uidInfo;
- clone.setUid(getuid());
-
- return clone;
- }
-
- /**
- * Substracts the values from a previous object
- * found in myList from the current Process
- * in order to obtain an object containing only the data since a referenc
- * @param myList
- */
- public void substractFromRef(List myList )
- {
- if (myList != null)
- {
- for (int i = 0; i < myList.size(); i++)
- {
- try
- {
- NativeKernelWakelock myRef = (NativeKernelWakelock) myList.get(i);
- if ( (this.getName().equals(myRef.getName())) && (this.getuid() == myRef.getuid()) )
- {
-// Log.i(TAG, "Substracting " + myRef.toString() + " from " + this.toString());
- this.m_count -= myRef.m_count;
- this.m_expireCount -= myRef.m_expireCount;
- this.m_wakeCount -= myRef.m_wakeCount;
- this.m_activeSince -= myRef.m_activeSince;
- this.m_ttlTime -= myRef.m_ttlTime;
- this.m_sleepTime -= myRef.m_sleepTime;
- this.m_maxTime -= myRef.m_maxTime;
- this.m_lastChange = Math.max(this.m_lastChange, myRef.m_lastChange);
- this.setTotal( this.getTotal() - myRef.getTotal() );
-
- // for kernel wakelocks we need to merge the package list (aka. fqn)
- // we don't care about double entries here, this must be handeled in getFqn
- if (!myRef.m_details.equals(""))
- {
- if (!this.m_details.equals(""))
- {
- this.m_details += ", " + myRef.m_details;
- }
- else
- {
- this.m_details = myRef.m_details;
- }
- }
-
-// Log.i(TAG, "Result: " + this.toString());
-
- if ((m_count < 0) || (m_sleepTime < 0) || (this.getTotal() < 0))
- {
- Log.e(TAG, "substractFromRef generated negative values (" + this.toString() + " - " + myRef.toString() + ")");
-// this.m_count = Math.max(0, this.m_count);
-// this.m_expireCount = Math.max(0, this.m_expireCount);
-// this.m_wakeCount = Math.max(0, this.m_wakeCount);
-// this.m_activeSince = Math.max(0, this.m_activeSince);
-// this.m_ttlTime = Math.max(0, this.m_ttlTime);
-// this.m_sleepTime = Math.max(0, this.m_sleepTime);
-// this.m_maxTime = Math.max(0, this.m_maxTime);
- }
- }
- }
- catch (ClassCastException e)
- {
- // just log as it is no error not to change the process
- // being substracted from to do nothing
- Log.e(TAG, "substractFromRef was called with a wrong list type");
- }
-
- }
- }
- }
-
-
- /**
- * @return the name
- */
- public String getName()
- {
- return m_name;
- }
-
- /**
- * @return the duration
- */
- public long getDuration()
- {
- return m_sleepTime;
- }
-
- /**
- * @return the count
- */
- public int getCount()
- {
- return m_count;
- }
-
- /**
- * the expire count
- */
- public int getExpireCount()
- {
- return m_expireCount;
- }
-
- /**
- * the wake count
- */
- public int getWakeCount()
- {
- return m_wakeCount;
- }
-
- /**
- * the active_since time
- */
- public long getActiveSince()
- {
- return m_activeSince;
- }
-
- /**
- * the total_time
- */
- public long getTtlTime()
- {
- return m_ttlTime;
- }
-
- /**
- * the sleep time
- */
- public long getSleepTime()
- {
- return m_sleepTime;
- }
-
- /**
- * the max time
- */
- public long getMaxTime()
- {
- return m_maxTime;
- }
-
- /**
- * the last change
- */
- public long getLastChange()
- {
- return m_lastChange;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString()
- {
- return getName() + " ["
- + "m_name=" + m_name + ", "
- + "m_count=" + m_count + ", "
- + "m_expire_count=" + m_expireCount + ", "
- + "m_wake_count=" + m_wakeCount + ", "
- + "m_active_since="+ m_activeSince + ", "
- + "m_total_time="+ m_ttlTime + ", "
- + "m_sleep_time=" + m_sleepTime + ", "
- + "m_max_time=" + m_maxTime + ", "
- + "m_last_change=" + m_lastChange + ", "
-
- + "]";
- }
-
- /**
- * Compare a given Wakelock with this object.
- * If the duration of this object is
- * greater than the received object,
- * then this object is greater than the other.
- */
- public int compareTo(NativeKernelWakelock o)
- {
- // we want to sort in descending order
- return ((int)(o.getDuration() - this.getDuration()));
- }
-
- /**
- * Returns the full qualified name (default, can be overwritten)
- * @return the full qualified name
- */
- public String getFqn(UidNameResolver resolver)
- {
- // we need to do some formating here as m_details may be of the form "a, b, a, c, b"
- if (m_details.equals(""))
- {
- return m_details;
- }
- else
- {
- // remove any left over "(" and ")"
- m_details.replace("(", "");
- m_details.replace(")", "");
-
- // merge
- String[] splitArray = m_details.split(", ");
-
- m_details = StringUtils.join(splitArray, ", ", true);
- return m_details;
- }
-
- }
-
- /**
- * returns a string representation of the data
- */
- public String getData(long totalTime)
- {
- return this.formatDuration(getDuration())
- + " (" + getDuration()/1000 + " s)"
- + " Cnt:(c/wc/ec)" + getCount() + "/" + m_wakeCount + "/" + m_expireCount
- + " " + this.formatRatio(getDuration(), totalTime);
- }
-
- /**
- * returns the values of the data
- */
- public double[] getValues()
- {
- double[] retVal = new double[2];
- retVal[0] = getDuration();
- return retVal;
- }
-
- public static class CountComparator implements Comparator
- {
- public int compare(NativeKernelWakelock a, NativeKernelWakelock b)
- {
- return ((int)(b.getCount() - a.getCount()));
- }
- }
-
- public static class TimeComparator implements Comparator
- {
- public int compare(NativeKernelWakelock a, NativeKernelWakelock b)
- {
- return ((int)(b.getDuration() - a.getDuration()));
- }
- }
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/kernelutils/Netstats.java b/app/src/main/java/com/asksven/android/common/kernelutils/Netstats.java
deleted file mode 100644
index e01dd28..0000000
--- a/app/src/main/java/com/asksven/android/common/kernelutils/Netstats.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.asksven.android.common.kernelutils;
-
-import android.util.Log;
-
-import com.asksven.android.common.RootShell;
-import com.asksven.android.common.privateapiproxies.NetworkUsage;
-import com.asksven.android.common.privateapiproxies.StatElement;
-import com.asksven.android.common.utils.StringUtils;
-
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-//import com.asksven.android.contrib.Shell;
-
-/**
- * Parses the content of /proc/net/xt_qtaguid/stats
- * instead of using the API functions NetworkStats stats = new NetworkStatsFactory().readNetworkStatsDetail(uid-here) because http://stackoverflow.com/questions/9080229/why-i-cant-read-proc-net-xt-qtaguid-stats-correctly-by-filereader-in-android-i
- * format is:
- * idx iface acct_tag_hex uid_tag_int cnt_set rx_bytes rx_packets tx_bytes tx_packets rx_tcp_bytes rx_tcp_packets rx_udp_bytes rx_udp_packets rx_other_bytes rx_other_packets tx_tcp_bytes tx_tcp_packets tx_udp_bytes tx_udp_packets tx_other_bytes tx_other_packets
- * example data:
- * 2 bnep1 0x0 0 0 21672 217 101512 526 0 0 16940 200 4732 17 0 0 50421 174 51091 352
- * 3 bnep1 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- * 4 bnep0 0x0 0 0 151693 2305 408790 2375 334 7 151359 2298 0 0 1010 5 309743 1720 98037 650
- * 5 bnep0 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- * 6 wl0.1 0x0 0 0 10836 131 18274 139 0 0 8716 109 2120 22 0 0 15114 96 3160 43
- * 7 wl0.1 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- * 8 wlan0 0x0 0 0 6449931 34871 624544 8518 335259 2562 5965630 30745 149042 1564 12579 203 467333 7261 144632 1054
- * 9 wlan0 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- * 10 wlan0 0x0 1000 0 12096 146 14679 194 11944 144 152 2 0 0 14332 189 347 5 0 0
- * 11 wlan0 0x0 1000 1 1885 10 1867 26 1885 10 0 0 0 0 1466 20 401 6 0 0
- * 12 wlan0 0x0 1014 0 317376 551 238620 615 0 0 317376 551 0 0 0 0 238620 615 0 0
- * 13 wlan0 0x0 1014 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- * 14 wlan0 0x0 10003 0 697215 713 84843 848 697215 713 0 0 0 0 84371 840 472 8 0 0
- * 15 wlan0 0x0 10003 1 1938719 2030 321314 2437 1938719 2030 0 0 0 0 321314 2437 0 0 0 0
- * value holder is Netstat
- * @author sven
- */
-public class Netstats
-{
- static final String TAG = "Netstats";
- private static String FILE_PATH = "/proc/net/xt_qtaguid/stats";
- static final String PERMISSION_DENIED = "su rights required to access alarms are not available / were not granted";
-
- private static final String KEY_IDX = "idx";
- private static final String KEY_IFACE = "iface";
- private static final String KEY_UID = "uid_tag_int";
- private static final String KEY_COUNTER_SET = "cnt_set";
- private static final String KEY_TAG_HEX = "acct_tag_hex";
- private static final String KEY_RX_BYTES = "rx_bytes";
- private static final String KEY_RX_PACKETS = "rx_packets";
- private static final String KEY_TX_BYTES = "tx_bytes";
- private static final String KEY_TX_PACKETS = "tx_packets";
-
-
- public static ArrayList parseNetstats()
- {
- List stats = getStats();
- return parseNetstats(stats);
- }
-
- public static ArrayList parseNetstats(List stats)
- {
- ArrayList myStats = new ArrayList();
- if ((stats != null) && (stats.size() != 0))
- {
-// String strRes = res.getResultLine();
- if (true) //(!strRes.contains("Permission Denial"))
- {
- ArrayList keys = new ArrayList();
- keys.add(KEY_IDX);
- keys.add(KEY_IFACE);
- keys.add(KEY_TAG_HEX);
- keys.add(KEY_UID);
- keys.add(KEY_COUNTER_SET);
- keys.add(KEY_RX_BYTES);
- keys.add(KEY_RX_PACKETS);
- keys.add(KEY_TX_BYTES);
- keys.add(KEY_TX_PACKETS);
-
- final ArrayList values = new ArrayList();
- final HashMap parsed = new HashMap();
-
-// ArrayList myRes = res.getResult(); // getTestData();
-
-
- // process the file, starting on line 2
- long totalBytes = 0;
- for (int i=1; i < stats.size(); i++)
- {
- String line = stats.get(i);
- StringUtils.splitLine(line, values);
- StringUtils.parseLine(keys, values, parsed);
-
- try
- {
- //Netstat entry = new Netstat();
- NetworkUsage entry = new NetworkUsage(
- StringUtils.getParsedInt(parsed, KEY_UID),
- parsed.get(KEY_IFACE),
- StringUtils.getParsedLong(parsed, KEY_RX_BYTES),
- StringUtils.getParsedLong(parsed, KEY_TX_BYTES));
-
- myStats = addToStats(myStats, entry);
- totalBytes += entry.getTotalBytes();
- }
- catch (Exception e)
- {
- Log.e(TAG, "An error occured while parsing " + line + ": " + e.getMessage());
- }
- }
-
- // set the total so that we can calculate the ratio
- for (int i = 0; i < myStats.size(); i++)
- {
- myStats.get(i).setTotal(totalBytes);
- }
-
- }
- }
-
- return myStats;
- }
-
- private static List getStats()
- {
-// ExecResult res = Exec.execPrint(new String[]{"su", "-c", "cat /proc/net/xt_qtaguid/stats"});
- List res = RootShell.getInstance().run("cat /proc/net/xt_qtaguid/stats");
- //Util.run("su", "cat /proc/net/xt_qtaguid/stats");
- return res;
- }
-
- /**
- * Stats may be duplicate for one uid+iface so we sum them up
- * @param stats
- * @param entry
- * @return
- */
- static ArrayList addToStats(ArrayList stats, NetworkUsage entry)
- {
- boolean merged = false;
- for (int i=0; i < stats.size(); i++)
- {
- NetworkUsage current = (NetworkUsage) stats.get(i);
-
- if ( (current.getuid() == entry.getuid()) && (current.getInterface().equals(entry.getInterface())) )
- {
- current.addBytesReceived(entry.getBytesReceived());
- current.addBytesSent(entry.getBytesSent());
- merged = true;
- break;
- }
- }
-
- // if not summed up add normally
- if (!merged)
- {
- stats.add(entry);
- }
- return stats;
- }
- public static boolean fileExists()
- {
- boolean exists = false;
- FileReader fr = null;
- try
- {
- fr = new FileReader(FILE_PATH);
- exists = true;
- }
- catch (Exception e)
- {
- exists = false;
- }
- finally
- {
- if (exists)
- {
- try
- {
- fr.close();
- }
- catch (IOException e)
- {
- // do nothing
- }
- }
- }
- return exists;
- }
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/kernelutils/OtherStatsDumpsys.java b/app/src/main/java/com/asksven/android/common/kernelutils/OtherStatsDumpsys.java
deleted file mode 100644
index b32bc9e..0000000
--- a/app/src/main/java/com/asksven/android/common/kernelutils/OtherStatsDumpsys.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/**
- *
- */
-package com.asksven.android.common.kernelutils;
-
-import android.os.SystemClock;
-import android.util.Log;
-
-import com.asksven.android.common.NonRootShell;
-import com.asksven.android.common.RootShell;
-import com.asksven.android.common.privateapiproxies.Misc;
-import com.asksven.android.common.privateapiproxies.StatElement;
-import com.asksven.android.common.utils.DateUtils;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-//import com.asksven.android.contrib.Shell;
-
-/**
- * Parses the content of 'dumpsys battery'
- * @author sven
- */
-public class OtherStatsDumpsys
-{
- static final String TAG = "OtherStatsDumpsys";
- static final String PERMISSION_DENIED = "su rights required to access alarms are not available / were not granted";
-
- /**
- * Returns a list of alarm value objects
- * @return
- * @throws Exception
- */
- public static ArrayList getOtherStats(boolean showWifi, boolean showBt, boolean useRoot)
- {
- final String START_PATTERN = "Statistics since last charge";
- final String STOP_PATTERN = "Statistics since last unplugged";
-
- ArrayList myOther = null;
- long nTotalCount = 0;
- List res = null;
-
- if (useRoot)
- {
- res = RootShell.getInstance().run("dumpsys batterystats");
- }
- else
- {
- res = NonRootShell.getInstance().run("dumpsys batterystats");
- }
-
- //List res = getTestData();
-
- if ((res != null) && (res.size() != 0))
-
- {
- if (res.contains("Permission Denial"))
- {
- Pattern begin = Pattern.compile(START_PATTERN);
- Pattern end = Pattern.compile(STOP_PATTERN);
-
- boolean bParsing = false;
-
- // we are looking for single line entries in the format
- // Screen on: 29s 297ms (99.7%), Input events: 0, Active phone call: 0ms (0.0%)
- // Screen brightnesses: dark 29s 297ms (100.0%)
- // Signal levels: none 21s 595ms (73.5%) 0x, poor 4s 447ms (15.1%) 3x, moderate 3s 295ms (11.2%) 1x, good 36ms (0.1%) 1x
- // Radio types: none 22s 610ms (77.0%) 0x, hsdpa 4s 635ms (15.8%) 2x, other 2s 128ms (7.2%) 1x
- // Wifi on: 0ms (0.0%), Wifi running: 0ms (0.0%), Bluetooth on: 0ms (0.0%)
-
- Pattern patternScreenOn = Pattern.compile("\\s\\sScreen on:\\s(.*) \\(.*\\sActive phone call:\\s(.*)\\s\\(.*");
- Pattern patternWifiOn = Pattern.compile("\\s\\sWifi on:\\s(.*) \\(.*\\sWifi running:\\s(.*)\\s\\(.*\\sBluetooth on:\\s(.*)\\s\\(.*");
-
- myOther = new ArrayList();
- Misc myMisc = null;
-
- // process the file
- long total = 0;
- for (int i=0; i < res.size(); i++)
- {
- // skip till start mark found
- if (bParsing)
- {
- // look for end
- Matcher endMatcher = end.matcher(res.get(i));
- if (endMatcher.find())
- {
- break;
- }
-
- // parse the alarms by block
- String line = res.get(i);
- Matcher screenOnMatcher = patternScreenOn.matcher(line);
- Matcher wifiOnMatcher = patternWifiOn.matcher(line);
-
- // screen on line
- if ( screenOnMatcher.find() )
- {
- try
- {
- long durationScreenOn = DateUtils.durationToLong(screenOnMatcher.group(1));
- long durationInCall = DateUtils.durationToLong(screenOnMatcher.group(2));
-
- myMisc = new Misc("Screen On", durationScreenOn, SystemClock.elapsedRealtime());
- myOther.add(myMisc);
-
- myMisc = new Misc("Phone On", durationInCall, SystemClock.elapsedRealtime());
- myOther.add(myMisc);
-
- Log.i(TAG, "Adding partial wakelock: " + myMisc.toString());
- }
- catch (Exception e)
- {
- Log.e(TAG, "Error: parsing error in package line (" + line + ")");
- }
- }
-
- // phone on line
- if ( wifiOnMatcher.find() )
- {
- try
- {
- long durationWifiOn = DateUtils.durationToLong(wifiOnMatcher.group(1));
- long durationWifiRunning = DateUtils.durationToLong(wifiOnMatcher.group(2));
- long durationBtRunning = DateUtils.durationToLong(wifiOnMatcher.group(3));
-
-
- if (showWifi)
- {
- myMisc = new Misc("Wifi On", durationWifiOn, SystemClock.elapsedRealtime());
- myOther.add(myMisc);
-
- myMisc = new Misc("Wifi Running", durationWifiRunning, SystemClock.elapsedRealtime());
- myOther.add(myMisc);
- }
-
- if (showBt)
- {
- myMisc = new Misc("Bluetooth On", durationBtRunning, SystemClock.elapsedRealtime());
- myOther.add(myMisc);
- }
- Log.i(TAG, "Adding partial wakelock: " + myMisc.toString());
- }
- catch (Exception e)
- {
- Log.e(TAG, "Error: parsing error in package line (" + line + ")");
- }
- }
-
- }
- else
- {
- // look for beginning
- Matcher line = begin.matcher(res.get(i));
- if (line.find())
- {
- bParsing = true;
- }
- }
- }
-
- // set the total
- for (int i=0; i < myOther.size(); i++)
- {
- myOther.get(i).setTotal(total);
- }
- }
- else
- {
- myOther = new ArrayList();
- Misc myWl = new Misc(PERMISSION_DENIED, 1, 1);
- myOther.add(myWl);
- }
- }
- else
- {
- myOther = new ArrayList();
- Misc myWl = new Misc(PERMISSION_DENIED, 1, 1);
- myOther.add(myWl);
-
- }
-
- return myOther;
- }
-
-
- static ArrayList getTestData()
- {
- ArrayList myRet = new ArrayList()
- {{
- add("Alarm Stats:");
- add(" All partial wake locks:");
- add(" Wake lock 1001 RILJ: 1h 8m 23s 575ms (930 times) realtime");
- add(" Wake lock 1013 AudioMix: 26m 33s 343ms (10 times) realtime");
- add(" Wake lock u0a203 android.media.MediaPlayer: 26m 20s 380ms (3 times) realtime");
- add(" Wake lock u0a203 pocketcasts_wake_lock: 26m 19s 956ms (3 times) realtime");
- add(" Wake lock u0a18 NlpCollectorWakeLock: 5m 1s 608ms (347 times) realtime");
- add(" Wake lock u0a18 NlpWakeLock: 1m 58s 440ms (1473 times) realtime");
- add(" Wake lock u0a18 Checkin Service: 1m 36s 820ms (47 times) realtime");
- add(" Wake lock u0a203 pocketcasts_update_wake_lock: 44s 69ms (5 times) realtime");
- add(" Wake lock 1000 ActivityManager-Launch: 27s 214ms (72 times) realtime");
- add(" Wake lock u0a18 WakefulIntentService[GCoreUlr-LocationReportingService]: 27s 108ms (11 times) realtime");
- add(" Wake lock u0a47 StartingAlertService: 23s 785ms (15 times) realtime");
- add(" Wake lock u0a59 *sync*/gmail-ls/com.google/sven.knispel@gmail.com: 17s 777ms (6 times) realtime");
- add(" Wake lock 1000 AlarmManager: 17s 235ms (193 times) realtime");
- add(" Wake lock u0a18 Icing: 14s 250ms (45 times) realtime");
- add(" Wake lock u0a18 GCM_CONN_ALARM: 13s 467ms (25 times) realtime");
- add(" Wake lock u0a18 ezk: 11s 653ms (136 times) realtime");
- add(" Wake lock u0a178 AlarmManager: 10s 671ms (162 times) realtime");
-
- }};
-
- return myRet;
- }
-}
diff --git a/app/src/main/java/com/asksven/android/common/kernelutils/ProcessStatsDumpsys.java b/app/src/main/java/com/asksven/android/common/kernelutils/ProcessStatsDumpsys.java
deleted file mode 100644
index f110018..0000000
--- a/app/src/main/java/com/asksven/android/common/kernelutils/ProcessStatsDumpsys.java
+++ /dev/null
@@ -1,280 +0,0 @@
-/**
- *
- */
-package com.asksven.android.common.kernelutils;
-
-import android.content.Context;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.util.Log;
-
-import com.asksven.android.common.NonRootShell;
-import com.asksven.android.common.RootShell;
-import com.asksven.android.common.privateapiproxies.Process;
-import com.asksven.android.common.privateapiproxies.StatElement;
-import com.asksven.android.common.utils.DateUtils;
-import com.asksven.android.common.utils.SysUtils;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Parses the content of 'dumpsys battery'
- * @author sven
- */
-public class ProcessStatsDumpsys
-{
- static final String TAG = "OtherStatsDumpsys";
- static final String PERMISSION_DENIED = "su rights required to access alarms are not available / were not granted";
-
- /**
- * Returns a list of alarm value objects
- * @return
- * @throws Exception
- */
- public static ArrayList getProcesses(Context ctx)
- {
- ArrayList myProcesses = new ArrayList();
-
- // get the list of all installed packages
- PackageManager pm = ctx.getPackageManager();
- List apps = pm.getInstalledApplications(PackageManager.GET_META_DATA);
-// List packages = pm.getInstalledPackages(PackageManager.GET_META_DATA);
-
- HashMap xrefPackages = new HashMap();
-
- for (int i=0; i < apps.size(); i++)
- {
- xrefPackages.put(apps.get(i).packageName, apps.get(i).uid);
- }
-
- List res = null;
-
- if (SysUtils.hasDumpsysPermission(ctx))
- {
- res = NonRootShell.getInstance().run("dumpsys batterystats");
- }
- else
- {
- res = RootShell.getInstance().run("dumpsys batterystats");
-
- }
-
- HashMap> xrefUserNames = getProcesses(res);
-
- // go through the processes and set the proper uid
- Iterator userNames = xrefUserNames.keySet().iterator();
- while (userNames.hasNext())
- {
- String userName = userNames.next();
- List procs = xrefUserNames.get(userName);
- int uid = -1;
- if (!userName.equals(""))
- {
- if (userName.startsWith("u0a"))
- {
- // resolve though xrefPackages
- uid = -1;
- }
- else
- {
- uid = Integer.valueOf(userName);
- }
- }
-
- for (int i=0; i < procs.size(); i++)
- {
- Process proc = procs.get(i);
- if (uid == -1)
- {
- String packageName = proc.getName();
- if ((packageName != null) && (xrefPackages != null))
- {
- try
- {
- Integer lookupUid = xrefPackages.get(packageName);
- if (lookupUid != null)
- {
- uid = lookupUid;
- }
- else
- {
- Log.d(TAG, "Package " + packageName + " was not found in xref");
- }
- }
- catch (Exception e)
- {
- Log.e(TAG, "An error occured when retrieving uid=" + uid + " for package=" + packageName);
- }
- }
- }
- proc.setUid(uid);
- myProcesses.add(proc);
- }
- }
-
- return myProcesses;
- }
-
-
- static ArrayList getTestData()
- {
- ArrayList myRet = new ArrayList()
- {{
- add("Alarm Stats:");
- add(" All partial wake locks:");
- add(" Wake lock 1001 RILJ: 1h 8m 23s 575ms (930 times) realtime");
- add(" Wake lock 1013 AudioMix: 26m 33s 343ms (10 times) realtime");
- add(" Wake lock u0a203 android.media.MediaPlayer: 26m 20s 380ms (3 times) realtime");
- add(" Wake lock u0a203 pocketcasts_wake_lock: 26m 19s 956ms (3 times) realtime");
- add(" Wake lock u0a18 NlpCollectorWakeLock: 5m 1s 608ms (347 times) realtime");
- add(" Wake lock u0a18 NlpWakeLock: 1m 58s 440ms (1473 times) realtime");
- add(" Wake lock u0a18 Checkin Service: 1m 36s 820ms (47 times) realtime");
- add(" Wake lock u0a203 pocketcasts_update_wake_lock: 44s 69ms (5 times) realtime");
- add(" Wake lock 1000 ActivityManager-Launch: 27s 214ms (72 times) realtime");
- add(" Wake lock u0a18 WakefulIntentService[GCoreUlr-LocationReportingService]: 27s 108ms (11 times) realtime");
- add(" Wake lock u0a47 StartingAlertService: 23s 785ms (15 times) realtime");
- add(" Wake lock u0a59 *sync*/gmail-ls/com.google/sven.knispel@gmail.com: 17s 777ms (6 times) realtime");
- add(" Wake lock 1000 AlarmManager: 17s 235ms (193 times) realtime");
- add(" Wake lock u0a18 Icing: 14s 250ms (45 times) realtime");
- add(" Wake lock u0a18 GCM_CONN_ALARM: 13s 467ms (25 times) realtime");
- add(" Wake lock u0a18 ezk: 11s 653ms (136 times) realtime");
- add(" Wake lock u0a178 AlarmManager: 10s 671ms (162 times) realtime");
-
- }};
-
- return myRet;
- }
-
- protected static HashMap> getProcesses(List res)
- {
- HashMap> xref = new HashMap>();
-
- final String START_PATTERN = "Statistics since last charge";
- final String STOP_PATTERN = "Statistics since last unplugged";
-
- if ((res != null) && (res.size() != 0))
-
- {
- Pattern begin = Pattern.compile(START_PATTERN);
- Pattern end = Pattern.compile(STOP_PATTERN);
-
- boolean bParsing = false;
-
- Pattern patternUser = Pattern.compile("\\s\\s((u0a)?\\d+):");
- Pattern patternProcess = Pattern.compile("\\s\\s\\s\\sProc\\s(.*):");
- Pattern patternCpu = Pattern.compile("\\s\\s\\s\\s\\s\\sCPU:\\s(.*) usr \\+ (.*) krn.*");
- Pattern patternStarts = Pattern.compile("\\s\\s\\s\\s\\s\\s(\\d+) proc starts");
-
- String user = "";
- String process = "";
- long userCpu = 0;
- long systemCpu = 0;
- int starts = 0;
-
- for (int i=0; i < res.size(); i++)
- {
- // skip till start mark found
- if (bParsing)
- {
-
- // look for end
- Matcher endMatcher = end.matcher(res.get(i));
- if (endMatcher.find())
- {
- // add whatever was not saved yet
- if (!user.equals("") && !process.equals(""))
- {
- Process myProc = new Process(process, userCpu, systemCpu, starts);
- List myList = xref.get(user);
- if (myList == null)
- {
- myList = new ArrayList();
- xref.put(user, myList);
- }
- myList.add(myProc);
- }
-
- break;
- }
-
- String line = res.get(i);
- Matcher mUser = patternUser.matcher(line);
- Matcher mProcess = patternProcess.matcher(line);
- Matcher mCpu = patternCpu.matcher(line);
- Matcher mStarts = patternStarts.matcher(line);
-
- if ( mUser.find() )
- {
- // check if we had detected something previously
- if (!user.equals("") && !process.equals(""))
- {
- Process myProc = new Process(process, userCpu, systemCpu, starts);
- List myList = xref.get(user);
- if (myList == null)
- {
- myList = new ArrayList();
- xref.put(user, myList);
- }
- myList.add(myProc);
- }
- user = mUser.group(1);
- process = "";
- userCpu = 0;
- systemCpu = 0;
- starts = 0;
-
- }
- if ( mProcess.find() )
- {
- // check if we had detected something previously
- if (!user.equals("") && !process.equals(""))
- {
- Process myProc = new Process(process, userCpu, systemCpu, starts);
- List myList = xref.get(user);
- if (myList == null)
- {
- myList = new ArrayList();
- xref.put(user, myList);
- }
- myList.add(myProc);
- }
- process = mProcess.group(1);
- userCpu = 0;
- systemCpu = 0;
- starts = 0;
-
- }
- if ( mCpu.find() )
- {
- userCpu = DateUtils.durationToLong(mCpu.group(1));
- systemCpu = DateUtils.durationToLong(mCpu.group(2));
-
- }
- if ( mStarts.find() )
- {
- starts = Integer.valueOf(mStarts.group(1));
- }
-
- }
- else
- {
- // look for beginning
- Matcher line = begin.matcher(res.get(i));
- if (line.find())
- {
- bParsing = true;
- }
- }
-
- }
- }
-
- return xref;
- }
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/kernelutils/State.java b/app/src/main/java/com/asksven/android/common/kernelutils/State.java
deleted file mode 100644
index f963397..0000000
--- a/app/src/main/java/com/asksven/android/common/kernelutils/State.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.asksven.android.common.kernelutils;
-
-import android.util.Log;
-
-import com.asksven.android.common.dto.StateDto;
-import com.asksven.android.common.privateapiproxies.StatElement;
-import com.google.gson.annotations.SerializedName;
-
-import java.io.Serializable;
-import java.text.DecimalFormat;
-import java.util.List;
-
-
-/**
- * Value holder for CpuState
- * @author sven
- *
- */
-
-/** simple struct for states/time */
-public class State extends StatElement implements Comparable, Serializable
-{
- /**
- * the tag for logging
- */
- private transient static final String TAG = "Process";
-
- private static final long serialVersionUID = 1L;
-
-
- @SerializedName("freq")
- public int m_freq = 0;
-
- @SerializedName("duration_ms")
- public long m_duration = 0;
-
- public State()
- {
-
- }
-
- public State(int freq, long duration)
- {
- m_freq = freq;
- m_duration = duration;
-
- }
-
- public State(StateDto source)
- {
- this.setUid(source.m_uid);
- this.m_duration = source.m_duration;
- this.m_freq = source.m_freq;
- this.setTotal(source.m_total);
- }
-
- public State clone()
- {
- State clone = new State(m_freq, m_duration);
- clone.setTotal(this.getTotal());
- return clone;
- }
-
- public StateDto toDto()
- {
- StateDto ret = new StateDto();
- ret.m_uid = this.getuid();
- ret.m_duration = this.m_duration;
- ret.m_freq = this.m_freq;
- ret.m_total = this.getTotal();
-
- return ret;
- }
-
- public String getName()
- {
- String ret = formatFreq(m_freq);
- if (ret.equals("0 kHz"))
- {
- ret = "Deep Sleep";
- }
- return ret;
- }
-
- public String toString()
- {
- return getName() + " " + m_duration;
- }
-
- public String getData(long totalTime)
- {
- return formatDuration(m_duration) + " " + this.formatRatio(m_duration, totalTime);
- }
-
- /**
- * returns a string representation of the data
- */
- public String getVals()
- {
-
- return getName() + " " + this.formatDuration(m_duration) + " (" + m_duration/1000 + " s)"
- + " in " + this.formatDuration(getTotal()) + " (" + getTotal()/1000 + " s)"
- + " Ratio: " + formatRatio(m_duration, getTotal());
- }
-
- /**
- * returns the values of the data
- */
- public double[] getValues()
- {
- double[] retVal = new double[2];
- retVal[0] = m_duration;
- return retVal;
- }
-
- /**
- * Formats a freq in Hz in a readable form
- * @param freqHz
- * @return
- */
- String formatFreq(int freqkHz)
- {
- double freq = freqkHz;
- double freqMHz = freq / 1000;
- double freqGHz = freq / 1000 / 1000;
-
- String formatedFreq = "";
- DecimalFormat df = new DecimalFormat("#.##");
-
- if (freqGHz >= 1)
- {
- formatedFreq = df.format(freqGHz) + " GHz";
- }
- else if (freqMHz >= 1)
- {
- formatedFreq = df.format(freqMHz) + " MHz";
- }
-
- else
- {
- formatedFreq = df.format(freqkHz) + " kHz";
- }
-
- return formatedFreq;
-
- }
-
- /**
- * Substracts the values from a previous object
- * found in myList from the current Process
- * in order to obtain an object containing only the data since a referenc
- * @param myList
- */
- public void substractFromRef(List myList )
- {
- if (myList != null)
- {
- for (int i = 0; i < myList.size(); i++)
- {
- try
- {
- State myRef = (State) myList.get(i);
- if ( (this.getName().equals(myRef.getName())) && (this.getuid() == myRef.getuid()) )
- {
- this.m_duration -= myRef.m_duration;
- this.setTotal( this.getTotal() - myRef.getTotal() );
- if (m_duration < 0)
- {
- Log.e(TAG, "substractFromRef generated negative values (" + this.m_duration + " - " + myRef.m_duration + ")");
- }
- break;
- }
- }
- catch (ClassCastException e)
- {
- // just log as it is no error not to change the process
- // being substracted from to do nothing
- Log.e(TAG, "substractFromRef was called with a wrong list type");
- }
-
- }
- }
- }
-
- /**
- * Compare a given Wakelock with this object.
- * If the duration of this object is
- * greater than the received object,
- * then this object is greater than the other.
- */
- public int compareTo(State o)
- {
- // we want to sort in descending order
- return ((int)( (o.m_freq) - (this.m_freq) ));
- }
-
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/kernelutils/Wakelocks.java b/app/src/main/java/com/asksven/android/common/kernelutils/Wakelocks.java
deleted file mode 100644
index b27e3a6..0000000
--- a/app/src/main/java/com/asksven/android/common/kernelutils/Wakelocks.java
+++ /dev/null
@@ -1,278 +0,0 @@
-/**
- *
- */
-package com.asksven.android.common.kernelutils;
-
-import android.app.ActivityManager;
-import android.app.ActivityManager.RunningAppProcessInfo;
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.os.SystemClock;
-import android.util.Log;
-
-import com.asksven.android.common.CommonLogSettings;
-import com.asksven.android.common.privateapiproxies.NativeKernelWakelock;
-import com.asksven.android.common.privateapiproxies.StatElement;
-import com.asksven.android.contrib.Shell;
-import com.asksven.android.contrib.Util;
-
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-
-/**
- * @author sven
- *
- * Parsing of /proc/wakelocks
- *
- * Fields:
- * total_time: accumulates the total amount of time that the corresponding suspend blocker has been held.
- * active_since: tracks how long a suspend blocker has been held since it was last acquired, or (presumably) zero if it is not currently held.
- * count: the number of times that the suspend blocker has been acquired. This is useful in combination with total_time, as it allows you to calculate the average hold time for the suspend blocker.
- * expire_count: the number of times that the suspend blocker has timed out. This indicates that some application has an input device open, but is not reading from it, which is a bug, as noted earlier.
- * max_time: the longest hold time for the suspend blocker. This allows finding cases where suspend blockers are held for too long, but are eventually released. (In contrast, active_since is more useful in the held-forever case.)
- * sleep_time: the total time that the suspend blocker was held while the display was powered off.
- * wake_count: the number of times that the suspend blocker was the first to be acquired in the resume path.
- *
- */
-public class Wakelocks
-{
- private final static String TAG ="Wakelocks";
- private static String FILE_PATH = "/proc/wakelocks";
-
- public static ArrayList parseProcWakelocks(Context context)
- {
- if (CommonLogSettings.DEBUG)
- {
- Log.i(TAG, "Parsing " + FILE_PATH);
- }
-
- String delimiter = String.valueOf('\t');
- ArrayList myRet = new ArrayList();
- // format
- // [name, count, expire_count, wake_count, active_since, total_time, sleep_time, max_time, last_change]
- ArrayList rows = parseDelimitedFile(FILE_PATH, delimiter);
-
- long msSinceBoot = SystemClock.elapsedRealtime();
-
- // list the running processes
- ActivityManager actvityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
- List procInfos = actvityManager.getRunningAppProcesses();
- PackageManager pack=context.getPackageManager();
-
- // start with 1
- for (int i=1; i < rows.size(); i++ )
- {
- try
- {
- // times in file are microseconds
- String[] data = (String[]) rows.get(i);
- String name = data[0];
- int count = Integer.valueOf(data[1]);
- int expire_count = Integer.valueOf(data[2]);
- int wake_count = Integer.valueOf(data[3]);
- long active_since = Long.valueOf(data[4]);
- long total_time = Long.valueOf(data[5]) / 1000000;
- long sleep_time = Long.valueOf(data[6]) / 1000000;
- long max_time = Long.valueOf(data[7]) / 1000000;
- long last_change = Long.valueOf(data[8]);
-
- // post-processing of eventX-YYYY processes
- String details = "";
-// name = "event3-30240";
- // we start with a " here as that is the way the data comes from /proc
- if (name.startsWith("\"event"))
- {
- String process = name.replaceAll("\"", "");
- if (CommonLogSettings.DEBUG)
- {
- Log.d(TAG, "Pattern 'event' found in " + process);
- }
-
- int proc = 0;
- String[] parts = process.split("-");
- if (parts.length == 2)
- {
- try
- {
- proc = Integer.valueOf(parts[1]);
- if (CommonLogSettings.DEBUG)
- {
- Log.d(TAG, "Resolving proc name for 'event' " + proc);
- }
- }
- catch (Exception e)
- {
- Log.e(TAG, "Cound not split process name " + process);
- }
- }
-
- if (proc != 0)
- {
- // search for the process in the task list
- for (int psCount = 0; psCount < procInfos.size(); psCount++)
- {
- int id = procInfos.get(psCount).pid;
- if ( id == proc)
- {
- String processName = procInfos.get(psCount).processName;
-
- details= processName;
- String appName = "";
-
- String[] pkgList = procInfos.get(count).pkgList;
- for (int j=0; j < pkgList.length; j++)
- {
- if (details.length() > 0)
- {
- details += ", ";
- }
- details += pkgList[j];
- }
-
- if (CommonLogSettings.DEBUG)
- {
- Log.d(TAG, "Pattern 'event' resolved to " + details);
- }
- }
- }
- }
- }
-
- NativeKernelWakelock wl = new NativeKernelWakelock(
- name, details, count, expire_count, wake_count,
- active_since, total_time, sleep_time, max_time,
- last_change, msSinceBoot);
- myRet.add(wl);
- }
- catch (Exception e)
- {
- // go on
- }
- }
- return myRet;
- }
- protected static ArrayList parseDelimitedFile(String filePath, String delimiter)
- {
- ArrayList rows = new ArrayList();
- try
- {
- FileReader fr = new FileReader(filePath);
- BufferedReader br = new BufferedReader(fr);
- String currentRecord;
- while ((currentRecord = br.readLine()) != null)
- rows.add(currentRecord.split(delimiter));
- br.close();
- }
- catch (Exception e)
- {
- Log.i(TAG, "An error occured while parsing " + filePath + ": " + e.getMessage() + ". Retrying with root");
-
- // retry with root
-
- List res = Shell.SU.run("cat " + filePath);
- for (int i=0; i < res.size(); i++)
- {
- rows.add(res.get(i).split(delimiter));
- }
-
- if (res.isEmpty())
- {
- Log.i(TAG, "Wakelocks could not be read from " + filePath + ", even with root");
- }
- }
- return rows;
- }
-
- public static boolean fileExists()
- {
- boolean exists = false;
- FileReader fr = null;
- try
- {
- fr = new FileReader(FILE_PATH);
- exists = true;
- }
- catch (Exception e)
- {
- exists = false;
- }
- finally
- {
- if (exists)
- {
- try
- {
- fr.close();
- }
- catch (IOException e)
- {
- // do nothing
- }
- }
- }
- return exists;
- }
-
- public static boolean isDiscreteKwlPatch()
- {
- boolean ret = false;
-
- String filePath = "/sys/module/wakelock/parameters/default_stats";
- try
- {
- FileReader fr = new FileReader(filePath);
- BufferedReader br = new BufferedReader(fr);
-
- // read first line
- String currentRecord = br.readLine();
-
- if (!currentRecord.equals("0"))
- {
- ret = true;
- }
- br.close();
- }
- catch (Exception e)
- {
-
- }
- return ret;
- }
-
- public static boolean hasWakelocks(Context context)
- {
- boolean myRet = false;
- String filePath = "/sys/power/wake_lock";
- ArrayList res = Util.run("su", "cat " + filePath);
- // Format: 0 /sys/power/wake_lock
- final ArrayList values = new ArrayList();
- if (res.size() != 0)
- {
- String line = res.get(0);
- try
- {
- myRet = line.contains("PowerManagerService");
- if (myRet)
- {
- Log.i(TAG, "Detected userland wakelock in line " + line);
- }
- else
- {
- Log.i(TAG, "No userland wakelock detected in line " + line);
- }
- }
- catch (Exception e)
- {
- // something went wrong
- Log.e(TAG, "Exeception processsing " + filePath + ": " + e.getMessage());
- myRet = false;
- }
- }
- return myRet;
- }
-
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/asksven/android/common/kernelutils/WakeupSources.java b/app/src/main/java/com/asksven/android/common/kernelutils/WakeupSources.java
deleted file mode 100644
index f1fdc08..0000000
--- a/app/src/main/java/com/asksven/android/common/kernelutils/WakeupSources.java
+++ /dev/null
@@ -1,244 +0,0 @@
-/**
- *
- */
-package com.asksven.android.common.kernelutils;
-
-import android.app.ActivityManager;
-import android.app.ActivityManager.RunningAppProcessInfo;
-import android.content.Context;
-import android.os.Build;
-import android.os.SystemClock;
-import android.util.Log;
-
-import com.asksven.android.common.CommonLogSettings;
-import com.asksven.android.common.privateapiproxies.NativeKernelWakelock;
-import com.asksven.android.common.privateapiproxies.StatElement;
-import com.asksven.android.contrib.Shell;
-
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-
-/**
- * @author sven
- * Parser for wakeup_sources
- *
- **********************************
- * From pm_wakeup.h
- * struct wakeup_source - Representation of wakeup sources
- *
- * @total_time: Total time this wakeup source has been active.
- * @max_time: Maximum time this wakeup source has been continuously active.
- * @last_time: Monotonic clock when the wakeup source's was touched last time.
- * @prevent_sleep_time: Total time this source has been preventing autosleep.
- * @event_count: Number of signaled wakeup events.
- * @active_count: Number of times the wakeup sorce was activated.
- * @relax_count: Number of times the wakeup sorce was deactivated.
- * @expire_count: Number of times the wakeup source's timeout has expired.
- * @wakeup_count: Number of times the wakeup source might abort suspend.
- * @active: Status of the wakeup source.
- * @has_timeout: The wakeup source has been activated with a timeout.
- * struct wakeup_source {
- * const char *name;
- * struct list_head entry;
- * spinlock_t lock;
- * struct timer_list timer;
- * unsigned long timer_expires;
- * ktime_t total_time;
- * ktime_t max_time;
- * ktime_t last_time;
- * ktime_t start_prevent_time;
- * ktime_t prevent_sleep_time;
- * unsigned long event_count;
- * unsigned long active_count;
- * unsigned long relax_count;
- * unsigned long expire_count;
- * unsigned long wakeup_count;
- * bool active:1;
- * bool autosleep_enabled:1;
- * };
- *
- */
-public class WakeupSources extends Wakelocks
-{
- private final static String TAG ="WakeupSources";
- private static String FILE_PATH = "/sys/kernel/debug/wakeup_sources";
- //private static String FILE_PATH = "/sdcard/wakeup_sources.txt";
-
- public static ArrayList parseWakeupSources(Context context)
- {
- Log.i(TAG, "Parsing " + FILE_PATH);
-
- String delimiter = String.valueOf('\t');
- delimiter = delimiter + "+";
- ArrayList myRet = new ArrayList();
- // format
- // new [name active_count event_count wakeup_count expire_count active_since total_time max_time last_change prevent_suspend_time]
- ArrayList rows = parseDelimitedFile(FILE_PATH, delimiter);
-
- long msSinceBoot = SystemClock.elapsedRealtime();
-
- // list the running processes
- ActivityManager actvityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
- List procInfos = actvityManager.getRunningAppProcesses();
-
- // start with 1
- for (int i=1; i < rows.size(); i++ )
- {
- try
- {
- // times in file are milliseconds
- String[] data = (String[]) rows.get(i);
- String name = data[0].trim(); // name
- int count = Integer.valueOf(data[1]); // active_count
- int expire_count = Integer.valueOf(data[4]); // expire_count
- int wake_count = Integer.valueOf(data[3]); // wakeup_count
- long active_since = Long.valueOf(data[5]); // active_since
- long total_time = Long.valueOf(data[6]); // total_time
- long sleep_time = Long.valueOf(data[9]); // prevent_suspend_time
- long max_time = Long.valueOf(data[7]); // max_time
- long last_change = Long.valueOf(data[8]); // last_change
-
- // post-processing of eventX-YYYY processes
- String details = "";
-
- // we start with a " here as that is the way the data comes from /proc
- if (name.startsWith("\"event"))
- {
- String process = name.replaceAll("\"", "");
- if (CommonLogSettings.DEBUG)
- {
- Log.d(TAG, "Pattern 'event' found in " + process);
- }
-
- int proc = 0;
- String[] parts = process.split("-");
- if (parts.length == 2)
- {
- try
- {
- proc = Integer.valueOf(parts[1]);
- if (CommonLogSettings.DEBUG)
- {
- Log.d(TAG, "Resolving proc name for 'event' " + proc);
- }
- }
- catch (Exception e)
- {
- Log.e(TAG, "Cound not split process name " + process);
- }
- }
-
- if (proc != 0)
- {
- // search for the process in the task list
- for (int psCount = 0; psCount < procInfos.size(); psCount++)
- {
- int id = procInfos.get(psCount).pid;
- if ( id == proc)
- {
- String processName = procInfos.get(psCount).processName;
-
- details= processName;
- String appName = "";
-
- String[] pkgList = procInfos.get(count).pkgList;
- for (int j=0; j < pkgList.length; j++)
- {
- if (details.length() > 0)
- {
- details += ", ";
- }
- details += pkgList[j];
- }
-
- if (CommonLogSettings.DEBUG)
- {
- Log.d(TAG, "Pattern 'event' resolved to " + details);
- }
- }
- }
- }
- }
- if (CommonLogSettings.DEBUG)
- {
- Log.d(TAG, "Native Kernel wakelock parsed"
- + " name=" + name
- + " details=" + details
- + " count=" + count
- + " expire_count=" + expire_count
- + " wake_count=" + wake_count
- + " active_since=" + active_since
- + " total_time=" + total_time
- + " sleep_time=" + sleep_time
- + " max_time=" + max_time
- + "last_change=" + last_change
- + "ms_since_boot=" + msSinceBoot);
- }
- NativeKernelWakelock wl = null;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
- {
- // on L sleep time is always 0 so use total time instead
- wl = new NativeKernelWakelock(
- name, details, count, expire_count, wake_count,
- active_since, total_time, total_time, max_time,
- last_change, msSinceBoot);
- }
- else
- {
- wl = new NativeKernelWakelock(
- name, details, count, expire_count, wake_count,
- active_since, total_time, sleep_time, max_time,
- last_change, msSinceBoot);
- }
- myRet.add(wl);
- }
- catch (Exception e)
- {
- // go on
- }
- }
- return myRet;
- }
-
- public static boolean fileExists()
- {
- boolean exists = false;
- FileReader fr = null;
- try
- {
- fr = new FileReader(FILE_PATH);
- exists = true;
- }
- catch (Exception e)
- {
- List res = Shell.SU.run("cat " + FILE_PATH);
-
- if ((res == null)||(res.size()==0))
- {
- exists = false;
- }
- else
- {
- exists = true;
- }
- }
- finally
- {
- if (fr != null && exists)
- {
- try
- {
- fr.close();
- }
- catch (IOException e)
- {
- // do nothing
- }
- }
- }
- return exists;
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/asksven/android/common/kernelutils/WakeupSourcesLg.java b/app/src/main/java/com/asksven/android/common/kernelutils/WakeupSourcesLg.java
deleted file mode 100644
index 873459e..0000000
--- a/app/src/main/java/com/asksven/android/common/kernelutils/WakeupSourcesLg.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/**
- *
- */
-package com.asksven.android.common.kernelutils;
-
-import android.app.ActivityManager;
-import android.app.ActivityManager.RunningAppProcessInfo;
-import android.content.Context;
-import android.os.Build;
-import android.os.SystemClock;
-import android.util.Log;
-
-import com.asksven.android.common.CommonLogSettings;
-import com.asksven.android.common.privateapiproxies.NativeKernelWakelock;
-import com.asksven.android.common.privateapiproxies.StatElement;
-
-import java.util.ArrayList;
-import java.util.List;
-
-
-/**
- * @author sven
- * Parser for wakeup_sources for the LG G3 for Android 5
- *
- * we don't have sources but the wakeups sources format was changed by LG to being. This parser parses that specific format
- *
- * name active_count event_count wakeup_count expire_count pending_count active_since total_time max_time last_change prevent_suspend_time
- * qcom_sap_wakelock 0 0 0 0 0 0 0 0 2316399 0
- * qcom_rx_wakelock 82 198 0 82 0 0 4033 137 2416130 0
- * wlan 5 5 0 2 0 0 3702 1031 2431550 0
- *
- *
- */
-public class WakeupSourcesLg extends Wakelocks
-{
- private final static String TAG ="WakeupSourcesLgG3";
- private static String FILE_PATH = "/sys/kernel/debug/wakeup_sources";
- //private static String FILE_PATH = "/sdcard/wakeup_sources.txt";
-
- public static ArrayList parseWakeupSources(Context context)
- {
- Log.i(TAG, "Parsing " + FILE_PATH);
-
- String delimiter = String.valueOf('\t');
- delimiter = delimiter + "+";
- ArrayList myRet = new ArrayList();
- // format
- // new [name active_count event_count wakeup_count expire_count active_since total_time max_time last_change prevent_suspend_time]
- ArrayList rows = parseDelimitedFile(FILE_PATH, delimiter);
-
- long msSinceBoot = SystemClock.elapsedRealtime();
-
- // list the running processes
- ActivityManager actvityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
- List procInfos = actvityManager.getRunningAppProcesses();
-
- // start with 1
- for (int i=1; i < rows.size(); i++ )
- {
- try
- {
- // different mapping from LG G3
- // name active_count event_count wakeup_count expire_count pending_count active_since total_time max_time last_change prevent_suspend_time
- // times in file are milliseconds
- String[] data = (String[]) rows.get(i);
- String name = data[0].trim(); // name
- int count = Integer.valueOf(data[1]); // active_count
- int expire_count = Integer.valueOf(data[4]); // expire_count
- int wake_count = Integer.valueOf(data[3]); // wakeup_count
- long active_since = Long.valueOf(data[6]); // active_since
- long total_time = Long.valueOf(data[7]); // total_time
- long sleep_time = Long.valueOf(data[10]); // prevent_suspend_time
- long max_time = Long.valueOf(data[8]); // max_time
- long last_change = Long.valueOf(data[9]); // last_change
-
- // post-processing of eventX-YYYY processes
- String details = "";
-
- // we start with a " here as that is the way the data comes from /proc
- if (name.startsWith("\"event"))
- {
- String process = name.replaceAll("\"", "");
- if (CommonLogSettings.DEBUG)
- {
- Log.d(TAG, "Pattern 'event' found in " + process);
- }
-
- int proc = 0;
- String[] parts = process.split("-");
- if (parts.length == 2)
- {
- try
- {
- proc = Integer.valueOf(parts[1]);
- if (CommonLogSettings.DEBUG)
- {
- Log.d(TAG, "Resolving proc name for 'event' " + proc);
- }
- }
- catch (Exception e)
- {
- Log.e(TAG, "Cound not split process name " + process);
- }
- }
-
- if (proc != 0)
- {
- // search for the process in the task list
- for (int psCount = 0; psCount < procInfos.size(); psCount++)
- {
- int id = procInfos.get(psCount).pid;
- if ( id == proc)
- {
- String processName = procInfos.get(psCount).processName;
-
- details= processName;
- String appName = "";
-
- String[] pkgList = procInfos.get(count).pkgList;
- for (int j=0; j < pkgList.length; j++)
- {
- if (details.length() > 0)
- {
- details += ", ";
- }
- details += pkgList[j];
- }
-
- if (CommonLogSettings.DEBUG)
- {
- Log.d(TAG, "Pattern 'event' resolved to " + details);
- }
- }
- }
- }
- }
- if (CommonLogSettings.DEBUG)
- {
- Log.d(TAG, "Native Kernel wakelock parsed"
- + " name=" + name
- + " details=" + details
- + " count=" + count
- + " expire_count=" + expire_count
- + " wake_count=" + wake_count
- + " active_since=" + active_since
- + " total_time=" + total_time
- + " sleep_time=" + sleep_time
- + " max_time=" + max_time
- + "last_change=" + last_change
- + "ms_since_boot=" + msSinceBoot);
- }
- NativeKernelWakelock wl = null;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
- {
- // on L sleep time is always 0 so use total time instead
- wl = new NativeKernelWakelock(
- name, details, count, expire_count, wake_count,
- active_since, total_time, total_time, max_time,
- last_change, msSinceBoot);
- }
- else
- {
- wl = new NativeKernelWakelock(
- name, details, count, expire_count, wake_count,
- active_since, total_time, sleep_time, max_time,
- last_change, msSinceBoot);
- }
- myRet.add(wl);
- }
- catch (Exception e)
- {
- // go on
- }
- }
- return myRet;
- }
-
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/asksven/android/common/location/GeoUtils.java b/app/src/main/java/com/asksven/android/common/location/GeoUtils.java
deleted file mode 100644
index 9211913..0000000
--- a/app/src/main/java/com/asksven/android/common/location/GeoUtils.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- *
- */
-package com.asksven.android.common.location;
-
-import android.content.Context;
-import android.location.Address;
-import android.location.Geocoder;
-import android.location.Location;
-import android.util.Log;
-
-import com.asksven.android.common.networkutils.DataNetwork;
-
-import java.util.List;
-
-/**
- * Helper class for retrieing geo data for a given location
- * As geo data requires data connection the call is only made
- * if proper data connectivity exists
- * @author sven
- *
- */
-public class GeoUtils
-{
- private static final String TAG = "GeoUtils";
-
- public static String getNearestAddress(Context ctx, Location loc)
- {
- if (!DataNetwork.hasDataConnection(ctx))
- {
- return "";
- }
-
- Address address = getGeoData(ctx, loc);
- String strRet = "";
- if (address != null)
- {
- String addr0 = address.getAddressLine(0);
- String addr1 = address.getAddressLine(1);
- if (!addr0.equals(""))
- {
- strRet = addr0;
- }
- if (!addr1.equals(""))
- {
- if (!strRet.equals(""))
- {
- strRet = strRet + ", ";
- }
- strRet = strRet + addr1;
- }
- }
- return strRet;
-
- }
- public static String getNearestCity(Context ctx, Location loc)
- {
- if (!DataNetwork.hasDataConnection(ctx))
- {
- return "";
- }
-
- Address address = getGeoData(ctx, loc);
- String strRet = "";
- if (address != null)
- {
- strRet = address.getLocality();
- }
- return strRet;
- }
-
- public static Address getGeoData(Context ctx, Location loc)
- {
- if (!DataNetwork.hasDataConnection(ctx))
- {
- return null;
- }
-
- Geocoder myGeocoder = new Geocoder(ctx);
- Address address = null;
- try
- {
- List list = myGeocoder.getFromLocation(
- loc.getLatitude(),
- loc.getLongitude(), 1);
- if (list != null & list.size() > 0)
- {
- address = list.get(0);
- }
- }
- catch (Exception e)
- {
- Log.e(TAG, "Failed while retrieving nearest city");
- }
- return address;
- }
-}
diff --git a/app/src/main/java/com/asksven/android/common/nameutils/UidInfo.java b/app/src/main/java/com/asksven/android/common/nameutils/UidInfo.java
deleted file mode 100644
index b1b7a27..0000000
--- a/app/src/main/java/com/asksven/android/common/nameutils/UidInfo.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.nameutils;
-
-import com.asksven.android.common.dto.UidInfoDto;
-
-/**
- * @author sven
- *
- */
-public class UidInfo
-{
- private int m_uid;
- private String m_uidName = "";
- private String m_uidNamePackage = "";
- private boolean m_uidUniqueName = false;
-
- public UidInfo()
- {
- }
-
- public UidInfo(UidInfoDto source)
- {
- this.m_uid = source.m_uid;
- this.m_uidName = source.m_uidName;
- this.m_uidNamePackage = source.m_uidNamePackage;
- this.m_uidUniqueName = source.m_uidUniqueName;
- }
-
- public UidInfoDto toDto()
- {
- UidInfoDto ret = new UidInfoDto();
- ret.m_uid = this.m_uid;
- ret.m_uidName = this.m_uidName;
- ret.m_uidNamePackage = this.m_uidNamePackage;
- ret.m_uidUniqueName = this.m_uidUniqueName;
-
- return ret;
- }
-
- /**
- * @return the m_uid
- */
- public int getUid()
- {
- return m_uid;
- }
-
- /**
- * @param m_uid the m_uid to set
- */
- public void setUid(int m_uid)
- {
- this.m_uid = m_uid;
- }
-
- /**
- * @return the uidName
- */
- public String getName()
- {
- return m_uidName;
- }
-
- /**
- * @param uidName the uidName to set
- */
- public void setName(String uidName)
- {
- this.m_uidName = uidName;
- }
-
- /**
- * @return the uidNamePackage
- */
- public String getNamePackage()
- {
- return m_uidNamePackage;
- }
-
- /**
- * @param uidNamePackage the uidNamePackage to set
- */
- public void setNamePackage(String uidNamePackage)
- {
- this.m_uidNamePackage = uidNamePackage;
- }
-
- /**
- * @return the uidUniqueName
- */
- public boolean isUniqueName()
- {
- return m_uidUniqueName;
- }
-
- /**
- * @param uidUniqueName the uidUniqueName to set
- */
- public void setUniqueName(boolean uidUniqueName)
- {
- this.m_uidUniqueName = uidUniqueName;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "UidInfo [m_uid=" + m_uid + ", m_uidName=" + m_uidName
- + ", m_uidNamePackage=" + m_uidNamePackage
- + ", m_uidUniqueName=" + m_uidUniqueName + "]";
- }
-
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/nameutils/UidNameResolver.java b/app/src/main/java/com/asksven/android/common/nameutils/UidNameResolver.java
deleted file mode 100644
index fba0266..0000000
--- a/app/src/main/java/com/asksven/android/common/nameutils/UidNameResolver.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.nameutils;
-
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.graphics.drawable.Drawable;
-
-import com.performancetweaker.app.PerfTweakerApplication;
-
-/**
- * @author sven
- *
- */
-public class UidNameResolver
-{
-
- protected String[] m_packages;
- protected String[] m_packageNames;
- private static UidNameResolver m_instance;
-
- public static UidNameResolver getInstance()
- {
- if (m_instance == null)
- {
- m_instance = new UidNameResolver();
- }
-
- return m_instance;
- }
-
- public Drawable getIcon(String packageName)
- {
- Drawable icon = null;
- // retrieve and store the icon for that package
- String myPackage = packageName;
- if (!myPackage.equals(""))
- {
- PackageManager manager = PerfTweakerApplication.getAppContext().getPackageManager();
- try
- {
- icon = manager.getApplicationIcon(myPackage);
- }
- catch (Exception e)
- {
- // nop: no icon found
- icon = null;
- }
- }
- return icon;
- }
-
- public String getLabel(String packageName)
- {
- String ret = packageName;
- PackageManager pm = PerfTweakerApplication.getAppContext().getPackageManager();
- try
- {
- ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
- CharSequence label = ai.loadLabel(pm);
- if (label != null)
- {
- ret = label.toString();
- }
- }
- catch (NameNotFoundException e)
- {
- ret = packageName;
- }
-
- return ret;
- }
-
- // Side effects: sets mName and mUniqueName
- // Sets mNamePackage, mName and mUniqueName
- public synchronized UidInfo getNameForUid(int uid)
- {
- String uidName = "";
- String uidNamePackage = "";
- boolean uidUniqueName = false;
-
- com.asksven.android.common.nameutils.UidInfo myInfo = new UidInfo();
- myInfo.setUid(uid);
- myInfo.setName(uidName);
- myInfo.setNamePackage(uidNamePackage);
- myInfo.setUniqueName(uidUniqueName);
-
-
- PackageManager pm = PerfTweakerApplication.getAppContext().getPackageManager();
- m_packages = pm.getPackagesForUid(uid);
-
- if (m_packages == null)
- {
- uidName = Integer.toString(uid);
-
- myInfo.setName(uidName);
- return myInfo;
- }
-
- m_packageNames = new String[m_packages.length];
- System.arraycopy(m_packages, 0, m_packageNames, 0, m_packages.length);
-
- // Convert package names to user-facing labels where possible
- for (int i = 0; i < m_packageNames.length; i++)
- {
- m_packageNames[i] = getLabel(m_packageNames[i]);
- }
-
- if (m_packageNames.length == 1)
- {
- uidNamePackage = m_packages[0];
- uidName = m_packageNames[0];
- uidUniqueName = true;
- }
- else
- {
- uidName = "UID"; // Default name
- // Look for an official name for this UID.
- for (String name : m_packages)
- {
- try
- {
- PackageInfo pi = pm.getPackageInfo(name, 0);
- if (pi.sharedUserLabel != 0)
- {
- CharSequence nm = pm.getText(name,
- pi.sharedUserLabel, pi.applicationInfo);
- if (nm != null)
- {
- uidName = nm.toString();
- break;
- }
- }
- }
- catch (PackageManager.NameNotFoundException e)
- {
- }
- }
- }
- myInfo.setName(uidName);
- myInfo.setNamePackage(uidNamePackage);
- myInfo.setUniqueName(uidUniqueName);
-
- return myInfo;
- }
-
- /**
- * Returns the name for UIDs < 2000
- * @param uid
- * @return
- */
- String getName(int uid)
- {
- String ret = "";
- switch (uid)
- {
- case 0:
- ret = "root";
- break;
- case 1000:
- ret = "system";
- break;
- case 1001:
- ret = "radio";
- break;
- case 1002:
- ret = "bluetooth";
- break;
- case 1003:
- ret = "graphics";
- break;
- case 1004:
- ret = "input";
- break;
- case 1005:
- ret = "audio";
- break;
- case 1006:
- ret = "camera";
- break;
- case 1007:
- ret = "log";
- break;
- case 1008:
- ret = "compass";
- break;
- case 1009:
- ret = "mount";
- break;
- case 1010:
- ret = "wifi";
- break;
- case 1011:
- ret = "adb";
- break;
- case 1013:
- ret = "media";
- break;
- case 1014:
- ret = "dhcp";
- break;
-
- }
- return ret;
- }
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/networkutils/DataNetwork.java b/app/src/main/java/com/asksven/android/common/networkutils/DataNetwork.java
deleted file mode 100644
index 21094ee..0000000
--- a/app/src/main/java/com/asksven/android/common/networkutils/DataNetwork.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2011-12 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.networkutils;
-
-import android.content.Context;
-import android.net.ConnectivityManager;
-
-/**
- * Helper class for data connectivity
- * @author sven
- *
- */
-public class DataNetwork
-{
- public static boolean hasDataConnection(Context ctx)
- {
- boolean ret = true;
- ConnectivityManager myConnectivity =
- (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
-
- // if no network connection is available buffer the update
- // @see android.net.NetworkInfo
- if ( (myConnectivity == null)
- || (myConnectivity.getActiveNetworkInfo() == null)
- || (!myConnectivity.getActiveNetworkInfo().isAvailable()) )
- {
-
- ret = false;
- }
-
- return ret;
- }
-
- public static boolean hasWifiConnection(Context ctx)
- {
- boolean ret = false;
- ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
- if( cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting() )
- {
- ret = true;
- }
- else
- {
- ret = false;
- }
-
- return ret;
- }
-}
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/Alarm.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/Alarm.java
deleted file mode 100644
index aa3b7fa..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/Alarm.java
+++ /dev/null
@@ -1,463 +0,0 @@
-/*
- * Copyright (C) 2011-2012 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.privateapiproxies;
-
-import android.graphics.drawable.Drawable;
-import android.util.Log;
-
-import com.asksven.android.common.CommonLogSettings;
-import com.asksven.android.common.dto.AlarmDto;
-import com.asksven.android.common.dto.AlarmItemDto;
-import com.asksven.android.common.nameutils.UidNameResolver;
-import com.asksven.android.common.utils.DateUtils;
-import com.google.gson.annotations.SerializedName;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
-
-//import android.content.Context;
-//import android.content.pm.PackageManager;
-
-/**
- * @author sven
- * Value holder for alarms
- */
-public class Alarm extends StatElement implements Comparable, Serializable
-{
- /**
- * the tag for logging
- */
- private static transient final String TAG = "Alarm";
-
- /** The name of the app responsible for the alarm */
- @SerializedName("package_name")
- String m_strPackageName;
-
- /**
- * the details, if any
- */
-
- @SerializedName("details")
- String m_details;
-
- /** The number od wakeups */
- @SerializedName("wakeups")
- long m_nWakeups;
-
- /** The duration of the sample */
- @SerializedName("time_runing_ms")
- long m_timeRunning;
-
- /** The total count */
- @SerializedName("total_count")
- long m_nTotalCount;
-
-
- /** The details */
- @SerializedName("items")
- ArrayList m_items;
-
-
- /**
- * The default cctor
- * @param strName
- */
- public Alarm(String strName)
- {
- m_strPackageName = strName;
- m_details = "";
- m_items = new ArrayList();
-
- }
-
- public Alarm(String strName, String strDetails)
- {
- m_strPackageName = strName;
- m_details = strDetails;
- m_items = new ArrayList();
-
- }
-
- /**
- * The default cctor
- * @param strName
- */
- public Alarm(String strName, String strDetails, long lWakeups, long lCount, long timeRunning, ArrayList items)
- {
- m_strPackageName = strName;
- m_details = strDetails;
- m_nWakeups = lWakeups;
- m_nTotalCount = lCount;
- m_timeRunning = timeRunning;
- setTotal(m_timeRunning);
- m_items = items;
-
- }
-
- public Alarm(AlarmDto source)
- {
-
- this.setUid(source.m_uid);
- this.m_strPackageName = source.m_strPackageName;
- this.m_details = source.m_details;
- this.m_nWakeups = source.m_nWakeups;
- this.m_timeRunning = source.m_timeRunning;
- this.m_nTotalCount = source.m_nTotalCount;
-
- if (source.m_items != null)
- {
- this.m_items = new ArrayList();
- for (int i=0; i < source.m_items.size(); i++)
- {
- AlarmItem item = new AlarmItem();
- item.m_nNumber = source.m_items.get(i).m_nNumber;
- item.m_strIntent = source.m_items.get(i).m_strIntent;
- this.m_items.add(item);
- }
- }
- }
-
- public Alarm clone()
- {
- Alarm clone = new Alarm(m_strPackageName, m_details);
- clone.setWakeups(getWakeups());
- clone.setTimeRunning(getTimeRunning());
- clone.setTotalCount(m_nTotalCount);
- for (int i=0; i < m_items.size(); i++)
- {
- clone.m_items.add(m_items.get(i).clone());
- }
- return clone;
- }
- /**
- * Store the number of wakeups
- * @param nCount
- */
- public void setWakeups(long nCount)
- {
- m_nWakeups = nCount;
- }
-
- /**
- * Store the time running
- * @param nTimeRunning
- */
- public void setTimeRunning(long nTimeRunning)
- {
- m_timeRunning = nTimeRunning;
- }
- /**
- * Set the total wakeup count for the sum of all alarms
- * @param nCount
- */
- public void setTotalCount(long nCount)
- {
- m_nTotalCount = nCount;
- }
-
- /**
- * Return the max of all alarms (wakeups)
- */
- public double getMaxValue()
- {
- return m_nTotalCount;
- }
-
- /* (non-Javadoc)
- * @see com.asksven.android.common.privateapiproxies.StatElement#getName()
- */
- public String getName()
- {
- return m_strPackageName;
- }
-
- public String getDetails()
- {
- return m_details;
- }
-
- /**
- * Returns the number of wakeups
- * @return
- */
- public long getWakeups()
- {
- return m_nWakeups;
- }
-
- /**
- * @see getWakeups
- * @return
- */
- long getCount()
- {
- return getWakeups();
- }
-
- /**
- * Not supported for alarms
- * @return 0
- */
- long getDuration()
- {
- return 0;
- }
-
- /**
- * @return the time running
- */
- public long getTimeRunning()
- {
- return m_timeRunning;
- }
- /**
- * returns the values of the data
- */
- public double[] getValues()
- {
- double[] retVal = new double[2];
- retVal[0] = getCount();
- return retVal;
- }
-
- /**
- * returns a string representation of the data
- */
- public String getData(long totalTime)
- {
- String strRet = "";
- strRet = "Wakeups: " + getCount();
- if ((getCount() > 0) && (getTimeRunning() > 0))
- {
- strRet += " (" + DateUtils.formatFrequency(getCount(), totalTime) + ")";
- }
-
- return strRet;
- }
-
-
- /**
- * returns a string representation of the detailed data (including children)
- */
- public String getDetailedData()
- {
- String strRet = "";
- strRet = "Wakeups: " + getCount();
-
- if ((getCount() > 0) && (getTimeRunning() > 0))
- {
- strRet += " (" + DateUtils.formatFrequency(getCount(), getTimeRunning()) + ")";
- }
-
- strRet += "\n";
-
- for (int i=0; i < m_items.size(); i++)
- {
- strRet += " " + m_items.get(i).getData() + "\n";
- }
-
- return strRet;
- }
-
- /**
- * Returns the full qualified name (default, can be overwritten)
- * @return the full qualified name
- */
- public String getFqn(UidNameResolver resolver)
- {
- return m_details;
- }
-
- /**
- * returns the representation of the data for file dump
- */
- public String getDumpData(UidNameResolver nameResolver, long totalTime)
- {
- return this.getName() + " (" + this.getFqn(nameResolver) + "): " + this.getDetailedData();
- }
-
-
- /**
- * Adds an item
- * @param nCount
- * @param strIntent
- */
- public void addItem(long nCount, String strIntent)
- {
- m_items.add(new AlarmItem(nCount, strIntent));
- }
-
- /**
- * Retrieve the list of items
- * @return
- */
- public ArrayList getItems()
- {
- return m_items;
- }
-
- public void setItems(ArrayList items)
- {
- m_items = items;
- }
-
- /**
- * Substracts the values from a previous object
- * found in myList from the current Process
- * in order to obtain an object containing only the data since a referenc
- * @param myList
- */
- public void substractFromRef(List myList )
- {
- if (myList != null)
- {
- for (int i = 0; i < myList.size(); i++)
- {
- try
- {
- Alarm myRef = (Alarm) myList.get(i);
- if (this.getName().equals(myRef.getName()))
- {
- // process main values
- if (CommonLogSettings.DEBUG)
- Log.i(TAG, "Substracting " + myRef.toString() + " from " + this.toString());
-
- this.m_nWakeups -= myRef.getCount();
- this.m_timeRunning -= myRef.getTimeRunning();
- this.m_nTotalCount -= myRef.getMaxValue();
- Log.i(TAG, "Result: " + this.toString());
-
- // and process items
- for (int j=0; j < this.m_items.size(); j++)
- {
- AlarmItem myItem = this.m_items.get(j);
- myItem.substractFromRef(myRef.getItems());
- }
-
- if (this.getCount() < 0)
- {
- Log.e(TAG, "substractFromRef generated negative values (" + this.toString() + " - " + myRef.toString() + ")");
- }
- if (this.getItems().size() < myRef.getItems().size())
- {
- Log.e(TAG, "substractFromRef error processing alarm items: ref can not have less items");
- }
-
- }
- }
- catch (ClassCastException e)
- {
- // just log as it is no error not to change the process
- // being substracted from to do nothing
- Log.e(TAG, "substractFromRef was called with a wrong list type");
- }
-
- }
- }
- }
-
- public String getPackageName()
- {
- return m_strPackageName;
- }
-
- public Drawable getIcon(UidNameResolver resolver)
- {
- if (m_icon == null)
- {
- // retrieve and store the icon for that package
- String myPackage = m_strPackageName;
- if (!myPackage.equals(""))
- {
- m_icon = resolver.getIcon(myPackage);
- }
- }
- return m_icon;
- }
-
- /**
- * Compare a given Wakelock with this object.
- * If the duration of this object is
- * greater than the received object,
- * then this object is greater than the other.
- */
- public int compareTo(Alarm o)
- {
- // we want to sort in descending order
- return ((int)(o.getWakeups() - this.getWakeups()));
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString()
- {
- return getName() + " ["
- + getData(0)
- + "]";
- }
-
- public AlarmDto toDto()
- {
- AlarmDto ret = new AlarmDto();
-
- ret.m_uid = this.getuid();
- ret.m_strPackageName = this.m_strPackageName;
- ret.m_details = this.m_details;
- ret.m_nWakeups = this.m_nWakeups;
- ret.m_nTotalCount = this.m_nTotalCount;
- ret.m_timeRunning = this.m_timeRunning;
- ret.m_total = this.getTotal();
-
-
- if (m_items != null)
- {
- ret.m_items = new ArrayList();
- for (int i=0; i < m_items.size(); i++)
- {
- AlarmItemDto item = new AlarmItemDto();
- item.m_nNumber = m_items.get(i).m_nNumber;
- item.m_strIntent = m_items.get(i).m_strIntent;
- ret.m_items.add(item);
- }
- }
- return ret;
- }
-
-
-
- public static class CountComparator implements Comparator
- {
- public int compare(Alarm a, Alarm b)
- {
- return ((int)(b.getCount() - a.getCount()));
- }
- }
-
- public static class TimeComparator implements Comparator
- {
- public int compare(Alarm a, Alarm b)
- {
- return ((int)(b.getDuration() - a.getDuration()));
- }
- }
-
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/AlarmItem.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/AlarmItem.java
deleted file mode 100644
index 8a0c83e..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/AlarmItem.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright (C) 2011-2012 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.privateapiproxies;
-
-import android.util.Log;
-
-import com.google.gson.annotations.SerializedName;
-
-import org.codehaus.jackson.annotate.JsonIgnore;
-import org.codehaus.jackson.annotate.JsonProperty;
-
-import java.io.Serializable;
-import java.util.List;
-
-//import android.content.Context;
-//import android.content.pm.PackageManager;
-//import android.graphics.drawable.Drawable;
-
-/**
- * Value holder for alarm items
- * @author sven
- *
- */
-public class AlarmItem implements Serializable
-{
- /**
- * the tag for logging
- */
- private static transient final String TAG = "Alarm";
-
- @SerializedName("number")
- @JsonProperty("number")
- long m_nNumber;
-
- @SerializedName("intent")
- @JsonProperty("intent")
- String m_strIntent;
-
- public AlarmItem()
- {
-
- }
-
- /**
- * Default cctor
- * @param nCount
- * @param strIntent
- */
- @JsonIgnore
- public AlarmItem(long nCount, String strIntent)
- {
- m_nNumber = nCount;
- m_strIntent = strIntent;
- }
-
- public AlarmItem clone()
- {
- AlarmItem clone = new AlarmItem(m_nNumber, m_strIntent);
- return clone;
- }
-
- /**
- * Returns the intent name
- * @return
- */
- @JsonProperty("intent")
- public String getIntent()
- {
- return m_strIntent;
- }
-
- /**
- * Returns the count
- * @return
- */
- @JsonIgnore
- public long getCount()
- {
- return m_nNumber;
- }
- /**
- * Returns the data as a string
- * @return
- */
- @JsonIgnore
- public String getData()
- {
- return "Alarms: " + m_nNumber + ", Intent: " + m_strIntent;
- }
- /**
- * Substracts the values from a previous object
- * found in myList from the current Process
- * in order to obtain an object containing only the data since a referenc
- * @param myList
- */
- public void substractFromRef(List myList )
- {
- if (myList != null)
- {
- for (int i = 0; i < myList.size(); i++)
- {
- try
- {
- AlarmItem myRef = (AlarmItem) myList.get(i);
- if (this.getIntent().equals(myRef.getIntent()))
- {
- // process main values
- this.m_nNumber -= myRef.getCount();
- Log.i(TAG, "Result: " + this.toString());
- }
- }
- catch (ClassCastException e)
- {
- // just log as it is no error not to change the process
- // being substracted from to do nothing
- Log.e(TAG, "AlarmItem.substractFromRef was called with a wrong list type");
- }
- }
- }
- }
-}
-
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/BatteryInfoUnavailableException.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/BatteryInfoUnavailableException.java
deleted file mode 100644
index 9b69711..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/BatteryInfoUnavailableException.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- *
- */
-package com.asksven.android.common.privateapiproxies;
-
-/**
- * @author sven
- *
- */
-public class BatteryInfoUnavailableException extends Exception
-{
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public BatteryInfoUnavailableException()
- {
-
- }
-
- public BatteryInfoUnavailableException(String msg)
- {
- super(msg);
- }
-}
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/BatteryStatsProxy.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/BatteryStatsProxy.java
deleted file mode 100644
index b589818..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/BatteryStatsProxy.java
+++ /dev/null
@@ -1,3587 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.privateapiproxies;
-
-
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.hardware.Sensor;
-import android.hardware.SensorManager;
-import android.os.Build;
-import android.os.IBinder;
-import android.os.MemoryFile;
-import android.os.Parcel;
-import android.os.ParcelFileDescriptor;
-import android.os.Parcelable;
-import android.os.SystemClock;
-import android.util.Log;
-import android.util.SparseArray;
-
-import com.asksven.android.common.CommonLogSettings;
-import com.asksven.android.common.nameutils.UidInfo;
-import com.asksven.android.common.nameutils.UidNameResolver;
-import com.asksven.android.common.utils.DateUtils;
-import com.asksven.android.system.AndroidVersion;
-
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-
-
-
-
-/**
- * A proxy to the non-public API BatteryStats
- * http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3.3_r1/android/os/BatteryStats.java/?v=source
- * @author sven
- *
- */
-public class BatteryStatsProxy
-{
- /*
- * Instance of the BatteryStatsImpl
- */
- private Object m_Instance = null;
- @SuppressWarnings("rawtypes")
- private Class m_ClassDefinition = null;
-
- private static final String TAG = "BatteryStatsProxy";
-
- /**
- * Type to be passed to getNetworkActivityCount for different
- * stats.
- */
- private static final int NETWORK_MOBILE_RX_BYTES = 0; // received bytes using mobile data
-
- private static final int NETWORK_MOBILE_TX_BYTES = 1; // transmitted bytes using mobile data
-
- private static final int NETWORK_WIFI_RX_BYTES = 2; // received bytes using wifi
-
- private static final int NETWORK_WIFI_TX_BYTES = 3; // transmitted bytes using wifi
-
- /*
- * The UID stats are kept here as their methods / data can not be accessed
- * outside of this class due to non-public types (Uid, Proc, etc.)
- */
- private SparseArray extends Object> m_uidStats = null;
-
- /**
- * An instance to the UidNameResolver
- */
- private static BatteryStatsProxy m_proxy = null;
-
- synchronized public static BatteryStatsProxy getInstance(Context ctx)
- {
- if (m_proxy == null)
- {
- if (Build.VERSION.SDK_INT >= 22)
- {
- m_proxy = new BatteryStatsProxy(ctx, true);
- }
- else
- {
- m_proxy = new BatteryStatsProxy(ctx);
- }
- }
-
- return m_proxy;
- }
-
- public void invalidate()
- {
- m_proxy = null;
- }
-
- /**
- * Default cctor
- */
- protected BatteryStatsProxy(Context context)
- {
- /*
- * As BatteryStats is a service we need to get a binding using the IBatteryStats.Stub.getStatistics()
- * method (using reflection).
- * If we would be using a public API the code would look like:
- * @see com.android.settings.fuelgauge.PowerUsageSummary.java
- * protected void onCreate(Bundle icicle) {
- * super.onCreate(icicle);
- *
- * mStats = (BatteryStatsImpl)getLastNonConfigurationInstance();
- *
- * addPreferencesFromResource(R.xml.power_usage_summary);
- * mBatteryInfo = IBatteryStats.Stub.asInterface(
- * ServiceManager.getService("batteryinfo"));
- * mAppListGroup = (PreferenceGroup) findPreference("app_list");
- * mPowerProfile = new PowerProfile(this);
- * }
- *
- * followed by
- * private void load() {
- * try {
- * byte[] data = mBatteryInfo.getStatistics();
- * Parcel parcel = Parcel.obtain();
- * parcel.unmarshall(data, 0, data.length);
- * parcel.setDataPosition(0);
- * mStats = com.android.internal.os.BatteryStatsImpl.CREATOR
- * .createFromParcel(parcel);
- * mStats.distributeWorkLocked(BatteryStats.STATS_SINCE_CHARGED);
- * } catch (RemoteException e) {
- * Log.e(TAG, "RemoteException:", e);
- * }
- * }
- */
-
- try
- {
- ClassLoader cl = context.getClassLoader();
-
- m_ClassDefinition = cl.loadClass("com.android.internal.os.BatteryStatsImpl");
-
- // get the IBinder to the "batteryinfo" service
- @SuppressWarnings("rawtypes")
- Class serviceManagerClass = cl.loadClass("android.os.ServiceManager");
-
- // parameter types
- @SuppressWarnings("rawtypes")
- Class[] paramTypesGetService= new Class[1];
- paramTypesGetService[0]= String.class;
-
- @SuppressWarnings("unchecked")
- Method methodGetService = serviceManagerClass.getMethod("getService", paramTypesGetService);
-
- String service = "";
- if (Build.VERSION.SDK_INT >= 19)
- {
- // kitkat and following
- service = "batterystats";
- }
- else
- {
- service = "batteryinfo";
- }
- // parameters
- Object[] paramsGetService= new Object[1];
- paramsGetService[0] = service;
-
- if (CommonLogSettings.DEBUG)
- {
- Log.i(TAG, "invoking android.os.ServiceManager.getService(\"batteryinfo\")");
- }
- IBinder serviceBinder = (IBinder) methodGetService.invoke(serviceManagerClass, paramsGetService);
-
- if (CommonLogSettings.DEBUG)
- {
- Log.i(TAG, "android.os.ServiceManager.getService(\"batteryinfo\") returned a service binder");
- }
-
- // now we have a binder. Let's us that on IBatteryStats.Stub.asInterface
- // to get an IBatteryStats
- // Note the $-syntax here as Stub is a nested class
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsStub = cl.loadClass("com.android.internal.app.IBatteryStats$Stub");
-
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypesAsInterface= new Class[1];
- paramTypesAsInterface[0]= IBinder.class;
-
- @SuppressWarnings("unchecked")
- Method methodAsInterface = iBatteryStatsStub.getMethod("asInterface", paramTypesAsInterface);
-
- // Parameters
- Object[] paramsAsInterface= new Object[1];
- paramsAsInterface[0] = serviceBinder;
-
- if (CommonLogSettings.DEBUG)
- {
- Log.i(TAG, "invoking com.android.internal.app.IBatteryStats$Stub.asInterface");
- }
- Object iBatteryStatsInstance = methodAsInterface.invoke(iBatteryStatsStub, paramsAsInterface);
-
- // and finally we call getStatistics from that IBatteryStats to obtain a Parcel
- @SuppressWarnings("rawtypes")
- Class iBatteryStats = cl.loadClass("com.android.internal.app.IBatteryStats");
-
- @SuppressWarnings("unchecked")
- Method methodGetStatistics = iBatteryStats.getMethod("getStatistics");
-
- if (CommonLogSettings.DEBUG)
- {
- Log.i(TAG, "invoking getStatistics");
- }
- byte[] data = (byte[]) methodGetStatistics.invoke(iBatteryStatsInstance);
-
- if (CommonLogSettings.DEBUG)
- {
- Log.i(TAG, "retrieving parcel");
- }
-
- Parcel parcel = Parcel.obtain();
- parcel.unmarshall(data, 0, data.length);
- parcel.setDataPosition(0);
-
- @SuppressWarnings("rawtypes")
- Class batteryStatsImpl = cl.loadClass("com.android.internal.os.BatteryStatsImpl");
-
- if (CommonLogSettings.DEBUG)
- {
- Log.i(TAG, "reading CREATOR field");
- }
- Field creatorField = batteryStatsImpl.getField("CREATOR");
-
- // From here on we don't need reflection anymore
- @SuppressWarnings("rawtypes")
- Parcelable.Creator batteryStatsImpl_CREATOR = (Parcelable.Creator) creatorField.get(batteryStatsImpl);
-
- m_Instance = batteryStatsImpl_CREATOR.createFromParcel(parcel);
- }
- catch( Exception e )
- {
- if (e instanceof InvocationTargetException && e.getCause() != null) {
- Log.e(TAG, "An exception occured in BatteryStatsProxy(). Message: " + e.getCause().getMessage());
- } else {
- Log.e(TAG, "An exception occured in BatteryStatsProxy(). Message: " + e.getMessage());
- }
- m_Instance = null;
-
- }
- }
-
- protected BatteryStatsProxy(Context context, boolean dummy) // just need a different signature
- {
- /*
- * Same as default cctor but reading the parcel as stream and not as byte[]
- * see here for details: https://android.googlesource.com/platform/frameworks/base.git/+/nougat-mr2.1-release/core/java/com/android/internal/os/BatteryStatsHelper.java
- */
-
- try
- {
- ClassLoader cl = context.getClassLoader();
-
- m_ClassDefinition = cl.loadClass("com.android.internal.os.BatteryStatsImpl");
-
- // get the IBinder to the "batteryinfo" service
- @SuppressWarnings("rawtypes")
- Class serviceManagerClass = cl.loadClass("android.os.ServiceManager");
-
- // parameter types
- @SuppressWarnings("rawtypes")
- Class[] paramTypesGetService= new Class[1];
- paramTypesGetService[0]= String.class;
-
- @SuppressWarnings("unchecked")
- Method methodGetService = serviceManagerClass.getMethod("getService", paramTypesGetService);
-
- String service = "batterystats";
-
- // parameters
- Object[] paramsGetService= new Object[1];
- paramsGetService[0] = service;
-
- if (CommonLogSettings.DEBUG)
- {
- Log.i(TAG, "invoking android.os.ServiceManager.getService(\"batteryinfo\")");
- }
- IBinder serviceBinder = (IBinder) methodGetService.invoke(serviceManagerClass, paramsGetService);
-
- if (CommonLogSettings.DEBUG)
- {
- Log.i(TAG, "android.os.ServiceManager.getService(\"batteryinfo\") returned a service binder");
- }
-
- // now we have a binder. Let's us that on IBatteryStats.Stub.asInterface
- // to get an IBatteryStats
- // Note the $-syntax here as Stub is a nested class
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsStub = cl.loadClass("com.android.internal.app.IBatteryStats$Stub");
-
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypesAsInterface= new Class[1];
- paramTypesAsInterface[0]= IBinder.class;
-
- @SuppressWarnings("unchecked")
- Method methodAsInterface = iBatteryStatsStub.getMethod("asInterface", paramTypesAsInterface);
-
- // Parameters
- Object[] paramsAsInterface= new Object[1];
- paramsAsInterface[0] = serviceBinder;
-
- if (CommonLogSettings.DEBUG)
- {
- Log.i(TAG, "invoking com.android.internal.app.IBatteryStats$Stub.asInterface");
- }
- Object iBatteryStatsInstance = methodAsInterface.invoke(iBatteryStatsStub, paramsAsInterface);
-
- // and finally we call getStatistics from that IBatteryStats to obtain a Parcel
- @SuppressWarnings("rawtypes")
- Class iBatteryStats = cl.loadClass("com.android.internal.app.IBatteryStats");
-
- @SuppressWarnings("unchecked")
- Method methodGetStatisticsStream = iBatteryStats.getMethod("getStatisticsStream");
- // returns a ParcelFileDescriptor
-
- if (CommonLogSettings.DEBUG)
- {
- Log.i(TAG, "invoking getStatisticsStream");
- }
- ParcelFileDescriptor pfd = (ParcelFileDescriptor) methodGetStatisticsStream.invoke(iBatteryStatsInstance);
-
-
- if (pfd != null)
- {
- FileInputStream fis = new ParcelFileDescriptor.AutoCloseInputStream(pfd);
-
- try
- {
- if (CommonLogSettings.DEBUG) { Log.i(TAG, "retrieving parcel"); }
-
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[1];
- paramTypes[0]= FileDescriptor.class;
-
-
- // we want to access MemoryFile.getSize(pfd.getFileDescriptor()) but this methos id hidden
- Method methodGetSize = MemoryFile.class.getMethod("getSize", paramTypes);
- methodGetSize.setAccessible(true);
- int size = (int) methodGetSize.invoke(null, /* null = static method */ pfd.getFileDescriptor());
- byte[] data = readFully(fis, size);
- Parcel parcel = Parcel.obtain();
- parcel.unmarshall(data, 0, data.length);
- parcel.setDataPosition(0);
-
- @SuppressWarnings("rawtypes")
- Class batteryStatsImpl = cl.loadClass("com.android.internal.os.BatteryStatsImpl");
-
- if (CommonLogSettings.DEBUG) { Log.i(TAG, "reading CREATOR field"); }
- Field creatorField = batteryStatsImpl.getField("CREATOR");
-
- // From here on we don't need reflection anymore
- @SuppressWarnings("rawtypes")
- Parcelable.Creator batteryStatsImpl_CREATOR = (Parcelable.Creator) creatorField.get(batteryStatsImpl);
-
- m_Instance = batteryStatsImpl_CREATOR.createFromParcel(parcel);
-
- }
- catch (IOException e)
- {
- Log.w(TAG, "Unable to read statistics stream", e);
- }
- }
-
- }
- catch( Exception e )
- {
- if (e instanceof InvocationTargetException && e.getCause() != null) {
- Log.e(TAG, "An exception occured in BatteryStatsProxy(). Message: " + e.getCause().getMessage());
- } else {
- Log.e(TAG, "An exception occured in BatteryStatsProxy(). Message: " + e.getMessage());
- }
- m_Instance = null;
-
- }
- }
-
- // both these methods come from com/android/internal/os/BatteryStatsHelper.java
- protected static byte[] readFully(FileInputStream stream) throws java.io.IOException {
- return readFully(stream, stream.available());
- }
- protected static byte[] readFully(FileInputStream stream, int avail) throws java.io.IOException {
- int pos = 0;
- byte[] data = new byte[avail];
- while (true) {
- int amt = stream.read(data, pos, data.length-pos);
- Log.i(TAG, "Read " + amt + " bytes at " + pos
- + " of avail " + data.length);
- if (amt <= 0) {
- Log.i(TAG, "**** FINISHED READING: pos=" + pos
- + " len=" + data.length);
- return data;
- }
- pos += amt;
- avail = stream.available();
- if (avail > data.length-pos) {
- byte[] newData = new byte[pos+avail];
- System.arraycopy(data, 0, newData, 0, pos);
- data = newData;
- }
- }
- }
- /**
- * Returns true if the proxy could not be initialized properly
- * @return true if the proxy wasn't initialized
- */
- public boolean initFailed()
- {
- return m_Instance == null;
- }
-
- /**
- * Returns the total, last, or current battery realtime in microseconds.
- *
- * @param curTime the current elapsed realtime in microseconds.
- * @param iStatsType one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
- */
- public Long computeBatteryRealtime(long curTime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("computeBatteryRealtime", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(curTime);
- params[1]= new Integer(iStatsType);
-
- ret = (Long) method.invoke(m_Instance, params);
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Returns the total, last, or current battery realtime in microseconds.
- *
- * @param curTime the current elapsed realtime in microseconds.
- */
- public Long getBatteryRealtime(long curTime) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[1];
- paramTypes[0]= long.class;
-
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("getBatteryRealtime", paramTypes);
-
- //Parameters
- Object[] params= new Object[1];
- params[0]= new Long(curTime);
-
-
- ret= (Long) method.invoke(m_Instance, params);
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Returns the total, last, or current battery uptime in microseconds.
- *
- * @param curTime the current elapsed realtime in microseconds.
- * @param iStatsType one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
- */
- public Long computeBatteryUptime(long curTime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("computeBatteryUptime", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(curTime);
- params[1]= new Integer(iStatsType);
-
- ret= (Long) method.invoke(m_Instance, params);
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Returns the total, last, or current screen on time in microseconds.
- *
- * @param batteryRealtime the battery realtime in microseconds (@see computeBatteryRealtime).
- * @param iStatsType one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
- */
- public Long getScreenOnTime(long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("getScreenOnTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(batteryRealtime);
- params[1]= new Integer(iStatsType);
-
- ret= (Long) method.invoke(m_Instance, params);
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Returns if phone is on battery.
- *
- */
- public boolean getIsOnBattery() throws BatteryInfoUnavailableException
- {
- boolean ret = true;
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("getIsOnBattery", paramTypes);
-
-
- ret= (Boolean) method.invoke(m_Instance);
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = true;
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Returns the total, last, or current phone on time in microseconds.
- *
- * @param batteryRealtime the battery realtime in microseconds (@see computeBatteryRealtime).
- * @param iStatsType one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
- */
- public Long getPhoneOnTime(long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("getPhoneOnTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(batteryRealtime);
- params[1]= new Integer(iStatsType);
-
- ret= (Long) method.invoke(m_Instance, params);
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Returns the total, last, or current wifi on time in microseconds.
- *
- * @param batteryRealtime the battery realtime in microseconds (@see computeBatteryRealtime).
- * @param iStatsType one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
- */
- public Long getWifiOnTime(long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("getWifiOnTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(batteryRealtime);
- params[1]= new Integer(iStatsType);
-
- ret= (Long) method.invoke(m_Instance, params);
-
- if (CommonLogSettings.DEBUG)
- {
- Log.i(TAG, "getWifiOnTime with params " + params[0] + " and " + params[1] + " returned " + ret);
- }
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Returns the total, last, or current wifi on time in microseconds.
- *
- * @param batteryRealtime the battery realtime in microseconds (@see computeBatteryRealtime).
- * @param iStatsType one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
- */
- public Long getGlobalWifiRunningTime(long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("getGlobalWifiRunningTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(batteryRealtime);
- params[1]= new Integer(iStatsType);
-
- ret= (Long) method.invoke(m_Instance, params);
-
- if (CommonLogSettings.DEBUG)
- {
- Log.i(TAG, "getGlobalWifiRunningTime with params " + params[0] + " and " + params[1] + " returned " + ret);
- }
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Returns the total, last, or current wifi running time in microseconds.
- *
- * @param batteryRealtime the battery realtime in microseconds (@see computeBatteryRealtime).
- * @param iStatsType one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
- */
- public Long getWifiRunningTime(Context context, long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- this.collectUidStats();
- if (m_uidStats != null)
- {
- try
- {
-
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsUid = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid");
-
- int NU = m_uidStats.size();
- for (int iu = 0; iu < NU; iu++)
- {
- // Object is an instance of BatteryStats.Uid
- Object myUid = m_uidStats.valueAt(iu);
-
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = iBatteryStatsUid.getMethod("getWifiRunningTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(batteryRealtime);
- params[1]= new Integer(iStatsType);
-
- ret += (Long) method.invoke(myUid, params);
-
- if (CommonLogSettings.DEBUG)
- {
- Log.i(TAG, "getWifiRunningTime with params " + params[0] + " and " + params[1] + " returned " + ret);
- }
-
-
- }
- }
- catch( IllegalArgumentException e )
- {
- Log.e(TAG, "getWifiRunning threw an IllegalArgumentException: " + e.getMessage());
- throw e;
- }
- catch( Exception e )
- {
- Log.e(TAG, "getWifiRunning threw an Exception: " + e.getMessage());
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
- }
- return ret;
- }
-
- /**
- * Returns the total, last, or current wifi lock time in microseconds.
- *
- * @param batteryRealtime the battery realtime in microseconds (@see computeBatteryRealtime).
- * @param iStatsType one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
- */
- public Long getFullWifiLockTime(Context context, long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- this.collectUidStats();
- if (m_uidStats != null)
- {
- try
- {
-
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsUid = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid");
-
- int NU = m_uidStats.size();
- for (int iu = 0; iu < NU; iu++)
- {
- // Object is an instance of BatteryStats.Uid
- Object myUid = m_uidStats.valueAt(iu);
-
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = iBatteryStatsUid.getMethod("getFullWifiLockTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(batteryRealtime);
- params[1]= new Integer(iStatsType);
-
- ret += (Long) method.invoke(myUid, params);
-
- }
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
- }
- return ret;
- }
-
- /**
- * Returns the total, last, or current wifi scanning time in microseconds.
- *
- * @param batteryRealtime the battery realtime in microseconds (@see computeBatteryRealtime).
- * @param iStatsType one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
- */
- public Long getScanWifiLockTime(Context context, long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- this.collectUidStats();
- if (m_uidStats != null)
- {
- try
- {
-
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsUid = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid");
-
- int NU = m_uidStats.size();
- for (int iu = 0; iu < NU; iu++)
- {
- // Object is an instance of BatteryStats.Uid
- Object myUid = m_uidStats.valueAt(iu);
-
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = iBatteryStatsUid.getMethod("getScanWifiLockTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(batteryRealtime);
- params[1]= new Integer(iStatsType);
-
- ret += (Long) method.invoke(myUid, params);
-
- }
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
- }
- return ret;
- }
-
- /**
- * Returns the total, last, or current wifi multicast time in microseconds.
- *
- * @param batteryRealtime the battery realtime in microseconds (@see computeBatteryRealtime).
- * @param iStatsType one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
- */
- public Long getWifiMulticastTime(Context context, long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- this.collectUidStats();
- if (m_uidStats != null)
- {
- try
- {
-
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsUid = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid");
-
- int NU = m_uidStats.size();
- for (int iu = 0; iu < NU; iu++)
- {
- // Object is an instance of BatteryStats.Uid
- Object myUid = m_uidStats.valueAt(iu);
-
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = iBatteryStatsUid.getMethod("getWifiMulticastTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(batteryRealtime);
- params[1]= new Integer(iStatsType);
-
- ret += (Long) method.invoke(myUid, params);
-
- }
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
- }
- return ret;
- }
-
- /**
- * Returns the time in microseconds the phone has been running with the given data connection type.
- *
- * @params dataType the given data connection type (@see http://www.netmite.com/android/mydroid/donut/frameworks/base/core/java/android/os/BatteryStats.java)
- * @param batteryRealtime the battery realtime in microseconds (@see computeBatteryRealtime).
- * @param iStatsType one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
- */
- public Long getPhoneDataConnectionTime(int dataType, long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[3];
- paramTypes[0]= int.class;
- paramTypes[1]= long.class;
- paramTypes[2]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("getPhoneDataConnectionTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[3];
- params[0]= new Integer(dataType);
- params[1]= new Long(batteryRealtime);
- params[2]= new Integer(iStatsType);
-
- ret= (Long) method.invoke(m_Instance, params);
- if (CommonLogSettings.DEBUG)
- {
- Log.i(TAG, "getPhoneDataConnectionTime with params " + params[0] + ", " + params[1] + "and " + params[2] + " returned " + ret);
- }
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Returns the time in microseconds the phone has been running with the given signal strength.
- *
- * @params signalStrength the given data connection type (@see http://www.netmite.com/android/mydroid/donut/frameworks/base/core/java/android/os/BatteryStats.java)
- * @param batteryRealtime the battery realtime in microseconds (@see computeBatteryRealtime).
- * @param iStatsType one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
- */
- public Long getPhoneSignalStrengthTime(int signalStrength, long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[3];
- paramTypes[0]= int.class;
- paramTypes[1]= long.class;
- paramTypes[2]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("getPhoneDataConnectionTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[3];
- params[0]= new Integer(signalStrength);
- params[1]= new Long(batteryRealtime);
- params[2]= new Integer(iStatsType);
-
- ret= (Long) method.invoke(m_Instance, params);
- if (CommonLogSettings.DEBUG)
- {
- Log.i(TAG, "getPhoneSignalStrengthTime with params " + params[0] + ", " + params[1] + "and " + params[2] + " returned " + ret);
- }
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Returns the time in microseconds the screen has been running with the given brightness
- */
- public Long getScreenBrightnessTime(int brightness, long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[3];
- paramTypes[0]= int.class;
- paramTypes[1]= long.class;
- paramTypes[2]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("getScreenBrightnessTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[3];
- params[0]= new Integer(brightness);
- params[1]= new Long(batteryRealtime);
- params[2]= new Integer(iStatsType);
-
- ret= (Long) method.invoke(m_Instance, params);
- if (CommonLogSettings.DEBUG)
- {
- Log.i(TAG, "getScreenBrightnessTime with params " + params[0] + ", " + params[1] + "and " + params[2] + " returned " + ret);
- }
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Returns the total, last, or current audio on time in microseconds.
- *
- * @param batteryRealtime the battery realtime in microseconds (@see computeBatteryRealtime).
- * @param iStatsType one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
- */
- public Long getAudioTurnedOnTime(Context context, long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- this.collectUidStats();
- if (m_uidStats != null)
- {
- try
- {
-
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsUid = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid");
-
- int NU = m_uidStats.size();
- for (int iu = 0; iu < NU; iu++)
- {
- // Object is an instance of BatteryStats.Uid
- Object myUid = m_uidStats.valueAt(iu);
-
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = iBatteryStatsUid.getMethod("getAudioTurnedOnTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(batteryRealtime);
- params[1]= new Integer(iStatsType);
-
- ret += (Long) method.invoke(myUid, params);
-
- }
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
- }
- return ret;
- }
-
- /**
- * Returns the total, last, or current video on time in microseconds.
- *
- * @param batteryRealtime the battery realtime in microseconds (@see computeBatteryRealtime).
- * @param iStatsType one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
- */
- public Long getVideoTurnedOnTime(Context context, long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- this.collectUidStats();
- if (m_uidStats != null)
- {
- try
- {
-
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsUid = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid");
-
- int NU = m_uidStats.size();
- for (int iu = 0; iu < NU; iu++)
- {
- // Object is an instance of BatteryStats.Uid
- Object myUid = m_uidStats.valueAt(iu);
-
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = iBatteryStatsUid.getMethod("getVideoTurnedTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(batteryRealtime);
- params[1]= new Integer(iStatsType);
-
- ret += (Long) method.invoke(myUid, params);
-
- }
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
- }
- return ret;
- }
-
-
- /**
- * Returns the totalsensor time in microseconds.
-
- * @param context
- * @param batteryRealtime
- * @param iStatsType
- * @return
- * @throws BatteryInfoUnavailableException
- */
- public Long getSensorOnTime(Context context, long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- this.collectUidStats();
- if (m_uidStats != null)
- {
- try
- {
-
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsUid = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid");
-
- int NU = m_uidStats.size();
- for (int iu = 0; iu < NU; iu++)
- {
- // Object is an instance of BatteryStats.Uid
- Object myUid = m_uidStats.valueAt(iu);
-
- Method methodGetUid = iBatteryStatsUid.getMethod("getUid");
- Integer uid = (Integer) methodGetUid.invoke(myUid);
-
- @SuppressWarnings("unchecked")
- Method methodGetSensorStats = iBatteryStatsUid.getMethod("getSensorStats");
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
- {
- // call public SparseArray extends BatteryStats.Uid.Sensor> getSensorStats()
- SparseArray extends Object> sensorStats = (SparseArray extends Object>) methodGetSensorStats.invoke(myUid);
-
- if (sensorStats.size() > 0)
- {
- for (int i = 0; i < sensorStats.size(); i++)
- {
- // Object is a BatteryStatsTypes.Uid.Proc
- Object sensor = sensorStats.valueAt(i);
- @SuppressWarnings("rawtypes")
- Class batteryStatsUidSensor = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid$Sensor");
-
- Method methodGetSensorTime = batteryStatsUidSensor.getMethod("getSensorTime");
- Object timer = methodGetSensorTime.invoke(sensor);
-
- Method methodGetHandle = batteryStatsUidSensor.getMethod("getHandle");
- Integer handle = (Integer) methodGetHandle.invoke(sensor);
-
- Class batteryStatsUidTimer = cl.loadClass("com.android.internal.os.BatteryStatsImpl$StopwatchTimer");
-
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramsTypesGetTotalTimeLocked= new Class[1];
- paramsTypesGetTotalTimeLocked[0]= long.class;
-
- // method is protected so we must make it accessible
- Method computeRunTimeLocked = batteryStatsUidTimer.getDeclaredMethod("computeRunTimeLocked", paramsTypesGetTotalTimeLocked);
- computeRunTimeLocked.setAccessible(true);
-
-
- //Parameters
- Object[] params= new Object[1];
- params[0]= new Long(batteryRealtime);
-
- // call public long getTotalTimeLocked(long elapsedRealtimeUs, int which)
- Long value = (Long) computeRunTimeLocked.invoke(timer, params);
- ret += value;
-
- Log.i("BBS.Sensors",
- "UID=" + uid
- + ", Sensor=" +decodeSensor(handle) + " (" + handle + ") "
- + ", time=" + DateUtils.formatDuration((long)value/1000) + " (" + value + ")");
- }
- }
- }
- else
- {
- // call public Map getSensorStats()
- Map sensorStats = (Map) methodGetSensorStats.invoke(myUid);
-
- if (sensorStats.size() > 0)
- {
- // Map of String, BatteryStats.Uid.Wakelock
- for (Map.Entry sensorEntry : sensorStats.entrySet())
- {
- Object sensor = sensorEntry.getValue();
-
- @SuppressWarnings("rawtypes")
- Class batteryStatsUidSensor = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid$Sensor");
-
- Method methodGetSensorTime = batteryStatsUidSensor.getMethod("getSensorTime");
- Object timer = methodGetSensorTime.invoke(sensor);
-
- Method methodGetHandle = batteryStatsUidSensor.getMethod("getHandle");
- Integer handle = (Integer) methodGetHandle.invoke(sensor);
-
- Class batteryStatsUidTimer = cl.loadClass("com.android.internal.os.BatteryStatsImpl$StopwatchTimer");
-
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramsTypesGetTotalTimeLocked= new Class[1];
- paramsTypesGetTotalTimeLocked[0]= long.class;
-
- // method is protected so we must make it accessible
- Method computeRunTimeLocked = batteryStatsUidTimer.getDeclaredMethod("computeRunTimeLocked", paramsTypesGetTotalTimeLocked);
- computeRunTimeLocked.setAccessible(true);
-
-
- //Parameters
- Object[] params= new Object[1];
- params[0]= new Long(batteryRealtime);
-
- // call public long getTotalTimeLocked(long elapsedRealtimeUs, int which)
- Long value = (Long) computeRunTimeLocked.invoke(timer, params);
- ret += value;
-
- Log.i("BBS.Sensors",
- "UID=" + uid
- + ", Sensor=" +decodeSensor(handle) + " (" + handle + ") "
- + ", time=" + DateUtils.formatDuration((long)value/1000) + " (" + value + ")");
- }
- }
-
- }
- }
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
- }
- return ret;
- }
-
- /**
- * Returns the sensor stats.
-
- * @param context
- * @param batteryRealtime
- * @param iStatsType
- * @return
- * @throws BatteryInfoUnavailableException
- */
- @SuppressLint("NewApi")
- public ArrayList getSensorStats(Context context, long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- ArrayList myRet = new ArrayList();
-
- this.collectUidStats();
- if (m_uidStats != null)
- {
- try
- {
-
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsUid = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid");
-
- int NU = m_uidStats.size();
- for (int iu = 0; iu < NU; iu++)
- {
- // Object is an instance of BatteryStats.Uid
- Object myUid = m_uidStats.valueAt(iu);
-
- Method methodGetUid = iBatteryStatsUid.getMethod("getUid");
- Integer uid = (Integer) methodGetUid.invoke(myUid);
-
- @SuppressWarnings("unchecked")
- Method methodGetSensorStats = iBatteryStatsUid.getMethod("getSensorStats");
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
- {
- // call public SparseArray extends BatteryStats.Uid.Sensor> getSensorStats()
- SparseArray extends Object> sensorStats = (SparseArray extends Object>) methodGetSensorStats.invoke(myUid);
- Long uidTotalSensorTime = 0L;
-
- if (sensorStats.size() > 0)
- {
- ArrayList myItems = new ArrayList();
-
- for (int i = 0; i < sensorStats.size(); i++)
- {
- // Object is a BatteryStatsTypes.Uid.Proc
- Object sensor = sensorStats.valueAt(i);
- @SuppressWarnings("rawtypes")
- Class batteryStatsUidSensor = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid$Sensor");
-
- Method methodGetSensorTime = batteryStatsUidSensor.getMethod("getSensorTime");
- Object timer = methodGetSensorTime.invoke(sensor);
-
- Method methodGetHandle = batteryStatsUidSensor.getMethod("getHandle");
- Integer handle = (Integer) methodGetHandle.invoke(sensor);
-
- Class batteryStatsUidTimer = cl.loadClass("com.android.internal.os.BatteryStatsImpl$StopwatchTimer");
-
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramsTypesGetTotalTimeLocked= new Class[1];
- paramsTypesGetTotalTimeLocked[0]= long.class;
-
- // method is protected so we must make it accessible
- Method computeRunTimeLocked = batteryStatsUidTimer.getDeclaredMethod("computeRunTimeLocked", paramsTypesGetTotalTimeLocked);
- computeRunTimeLocked.setAccessible(true);
-
-
- //Parameters
- Object[] params= new Object[1];
- params[0]= new Long(batteryRealtime);
-
- // call public long getTotalTimeLocked(long elapsedRealtimeUs, int which)
- Long value = (Long) computeRunTimeLocked.invoke(timer, params);
- uidTotalSensorTime += value;
-
- Log.i("BBS.Sensors",
- "UID=" + uid
- + ", Sensor=" +decodeSensor(handle) + " (" + handle + ") "
- + ", time=" + DateUtils.formatDuration((long)value/1000) + " (" + value + ")");
-
- Sensor lookup = findSensor(context, handle);
-
- String sensorText = "";
-
- if (lookup == null)
- {
- sensorText = "Unknown";
- }
- else
- {
- // we try to get the most info out of the API
- if (Build.VERSION.SDK_INT >= 21)
- {
- sensorText = lookup.getName() + "(" + handle+ "), wakeup=" + lookup.isWakeUpSensor();
- }
- else
- {
- sensorText = lookup.getName();
- }
-
-
- }
- SensorUsageItem myItem = new SensorUsageItem(value/1000, sensorText, handle);
- myItems.add(myItem);
- }
- SensorUsage myData = new SensorUsage(uidTotalSensorTime.longValue()/1000);
- // try resolving names
- UidInfo myInfo = UidNameResolver.getInstance().getNameForUid(uid);
- myData.setUidInfo(myInfo);
- myData.setItems(myItems);
- myRet.add(myData);
-
-
- }
- }
- else
- {
- Long uidTotalSensorTime = 0L;
- // call public Map getSensorStats()
- Map sensorStats = (Map) methodGetSensorStats.invoke(myUid);
-
- if (sensorStats.size() > 0)
- {
- ArrayList myItems = new ArrayList();
-
- // Map of String, BatteryStats.Uid.Wakelock
- for (Map.Entry sensorEntry : sensorStats.entrySet())
- {
- Object sensor = sensorEntry.getValue();
-
- @SuppressWarnings("rawtypes")
- Class batteryStatsUidSensor = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid$Sensor");
-
- Method methodGetSensorTime = batteryStatsUidSensor.getMethod("getSensorTime");
- Object timer = methodGetSensorTime.invoke(sensor);
-
- Method methodGetHandle = batteryStatsUidSensor.getMethod("getHandle");
- Integer handle = (Integer) methodGetHandle.invoke(sensor);
-
- Class batteryStatsUidTimer = cl.loadClass("com.android.internal.os.BatteryStatsImpl$StopwatchTimer");
-
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramsTypesGetTotalTimeLocked= new Class[1];
- paramsTypesGetTotalTimeLocked[0]= long.class;
-
- // method is protected so we must make it accessible
- Method computeRunTimeLocked = batteryStatsUidTimer.getDeclaredMethod("computeRunTimeLocked", paramsTypesGetTotalTimeLocked);
- computeRunTimeLocked.setAccessible(true);
-
-
- //Parameters
- Object[] params= new Object[1];
- params[0]= new Long(batteryRealtime);
-
- // call public long getTotalTimeLocked(long elapsedRealtimeUs, int which)
- Long value = (Long) computeRunTimeLocked.invoke(timer, params);
- uidTotalSensorTime += value;
-
- Log.i("BBS.Sensors",
- "UID=" + uid
- + ", Sensor=" +decodeSensor(handle) + " (" + handle + ") "
- + ", time=" + DateUtils.formatDuration((long)value/1000) + " (" + value + ")");
-
- Sensor lookup = findSensor(context, handle);
-
- String sensorText = "";
-
- if (lookup == null)
- {
- sensorText = "Unknown";
- }
- else
- {
- // we try to get the most info out of the API
- if (Build.VERSION.SDK_INT >= 21)
- {
- sensorText = lookup.getName() + "(" + handle+ "), wakeup=" + lookup.isWakeUpSensor();
- }
- else
- {
- sensorText = lookup.getName();
- }
-
-
- }
- SensorUsageItem myItem = new SensorUsageItem(value/1000, sensorText, handle);
- myItems.add(myItem);
- }
- SensorUsage myData = new SensorUsage(uidTotalSensorTime.longValue()/1000);
- // try resolving names
- UidInfo myInfo = UidNameResolver.getInstance().getNameForUid(uid);
- myData.setUidInfo(myInfo);
- myData.setItems(myItems);
- myRet.add(myData);
-
-
- }
-
- }
- }
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- myRet = new ArrayList();
- throw new BatteryInfoUnavailableException();
- }
- }
- return myRet;
- }
-
- /**
- * Decodes the sensor handle using the constants from https://developer.android.com/reference/android/hardware/Sensor.html#STRING_TYPE_ACCELEROMETER
- * @param handle the sensor handle number
- * @return a string describing the sensor
- */
- String decodeSensor(int handle)
- {
- switch (handle)
- {
- case Sensor.TYPE_ACCELEROMETER: return "Accelerometer";
- case Sensor.TYPE_AMBIENT_TEMPERATURE: return "Ambient Temperatur";
- case Sensor.TYPE_GAME_ROTATION_VECTOR: return "Game Rotation Vector";
- case Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR: return "Geomagnetic rotation Vector";
- case Sensor.TYPE_GRAVITY: return "Gravity";
- case Sensor.TYPE_GYROSCOPE: return "Gyroscope";
- case Sensor.TYPE_GYROSCOPE_UNCALIBRATED: return "Gyroscope Uncalibrated";
- case Sensor.TYPE_HEART_RATE: return "Heart Rate";
- case Sensor.TYPE_LIGHT: return "Light";
- case Sensor.TYPE_LINEAR_ACCELERATION: return "Linear Acceleration";
- case Sensor.TYPE_MAGNETIC_FIELD: return "Megnetic Field";
- case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED: return "Magnetic Field Uncalibrated";
- case Sensor.TYPE_ORIENTATION: return "Orientation";
- case Sensor.TYPE_PRESSURE: return "Pressure";
- case Sensor.TYPE_PROXIMITY: return "Proximity";
- case Sensor.TYPE_RELATIVE_HUMIDITY: return "Relative Humidity";
- case Sensor.TYPE_ROTATION_VECTOR: return "Rotation Vector";
- case Sensor.TYPE_SIGNIFICANT_MOTION: return "Significant Motion";
- case Sensor.TYPE_STEP_COUNTER: return "Step Counter";
- case Sensor.TYPE_STEP_DETECTOR: return "Step Detection";
- case Sensor.TYPE_TEMPERATURE: return "Temperature";
- case -10000: return "GPS";
-
- default: return "Unknown";
-
-
- }
- }
-
- @SuppressLint("NewApi")
- Sensor findSensor(Context ctx, int handle)
- {
- String TAG = "BBS.Sensors";
- Sensor retVal = null;
-
- // Enumerate all sensors
- final SensorManager sensorManager = (SensorManager)ctx.getSystemService(Context.SENSOR_SERVICE);
- List sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
-
- if ( (sensors == null) || (sensors.size() == 0)) return null;
- for (int i=0; i < sensors.size(); i++)
- {
- Sensor sensor = sensors.get(i);
- Method methodGetHandle;
-
- int hhandle = -1;
- try
- {
- methodGetHandle = sensor.getClass().getDeclaredMethod("getHandle");
- methodGetHandle.setAccessible(true);
- hhandle = ((Integer) methodGetHandle.invoke(sensor)).intValue();
-
- } catch (Exception e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- if (hhandle == handle)
- {
- retVal = sensor;
- return retVal;
- }
- if (Build.VERSION.SDK_INT >= 21)
- {
- Log.i(TAG, "name=" + sensor.getName() + ", handle=" + handle+ ", wakeup=" + sensor.isWakeUpSensor() + ", type=" + sensor.getStringType());
- }
- else
- {
- Log.i(TAG, "name=" + sensor.getName() + ", handle=" + handle);
- }
- }
-
- return null;
- }
-
- /**
- * Returns the total GPS time in microseconds.
-
- * @param context
- * @param batteryRealtime
- * @param iStatsType
- * @return
- * @throws BatteryInfoUnavailableException
- */
- public Long getGpsOnTime(Context context, long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- this.collectUidStats();
- if (m_uidStats != null)
- {
- try
- {
-
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsUid = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid");
-
- int NU = m_uidStats.size();
- for (int iu = 0; iu < NU; iu++)
- {
- // Object is an instance of BatteryStats.Uid
- Object myUid = m_uidStats.valueAt(iu);
-
- Method methodGetUid = iBatteryStatsUid.getMethod("getUid");
- Integer uid = (Integer) methodGetUid.invoke(myUid);
-
- @SuppressWarnings("unchecked")
- Method methodGetSensorStats = iBatteryStatsUid.getMethod("getSensorStats");
-
- // call public SparseArray extends BatteryStats.Uid.Sensor> getSensorStats()
- SparseArray extends Object> sensorStats = (SparseArray extends Object>) methodGetSensorStats.invoke(myUid);
-
- if (sensorStats.size() > 0)
- {
- for (int i = 0; i < sensorStats.size(); i++)
- {
- // Object is a BatteryStatsTypes.Uid.Proc
- Object sensor = sensorStats.valueAt(i);
- @SuppressWarnings("rawtypes")
- Class batteryStatsUidSensor = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid$Sensor");
-
- Method methodGetSensorTime = batteryStatsUidSensor.getMethod("getSensorTime");
- Object timer = methodGetSensorTime.invoke(sensor);
-
- Method methodGetHandle = batteryStatsUidSensor.getMethod("getHandle");
- Integer handle = (Integer) methodGetHandle.invoke(sensor);
-
- // hack -> see https://developer.android.com/reference/android/hardware/Sensor.html
- // GPS is not defined in the HAL but has a constant value of -10000
- if (handle == -10000)
- {
- Class batteryStatsUidTimer = cl.loadClass("com.android.internal.os.BatteryStatsImpl$StopwatchTimer");
-
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramsTypesGetTotalTimeLocked= new Class[1];
- paramsTypesGetTotalTimeLocked[0]= long.class;
-
- // method is protected so we must make it accessible
- Method computeRunTimeLocked = batteryStatsUidTimer.getDeclaredMethod("computeRunTimeLocked", paramsTypesGetTotalTimeLocked);
- computeRunTimeLocked.setAccessible(true);
-
-
- //Parameters
- Object[] params= new Object[1];
- params[0]= new Long(batteryRealtime);
-
- // call public long getTotalTimeLocked(long elapsedRealtimeUs, int which)
- Long value = (Long) computeRunTimeLocked.invoke(timer, params);
- ret += value;
-
- Log.i("Sensors", "UID=" + uid + ", Sensor=" + handle + ", time=" + value);
- }
- }
- }
- }
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
- }
- return ret;
- }
-
- /**
- * Returns the total, last, or current bluetooth on time in microseconds.
- *
- * @param batteryRealtime the battery realtime in microseconds (@see computeBatteryRealtime).
- * @param iStatsType one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
- */
- public Long getBluetoothOnTime(long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("getBluetoothOnTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(batteryRealtime);
- params[1]= new Integer(iStatsType);
-
- ret= (Long) method.invoke(m_Instance, params);
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Returns the total, last, or current bluetooth on time in microseconds.
- *
- */
- public Long getBluetoothInStateTime(int state, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- if (Build.VERSION.SDK_INT < 6)
- {
- Log.e(TAG, "Bluetooth in state time is supported only from Marshmallow");
- }
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= int.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("getBluetoothControllerActivity", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Integer(state);
- params[1]= new Integer(iStatsType);
-
- ret= (Long) method.invoke(m_Instance, params);
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Returns the time in doze mode POWERSAVE
- * @param batteryRealtime
- * @param iStatsType
- * @return
- */
- public long getPowerSaveModeEnabledTime(long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("getPowerSaveModeEnabledTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(batteryRealtime);
- params[1]= new Integer(iStatsType);
-
- ret= (Long) method.invoke(m_Instance, params);
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Returns the time in doze mode IDLE
- * @param batteryRealtime
- * @param iStatsType
- * @return
- */
- public long getDeviceIdleModeEnabledTime(long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("getDeviceIdleModeEnabledTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(batteryRealtime);
- params[1]= new Integer(iStatsType);
-
- ret= (Long) method.invoke(m_Instance, params);
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Returns the time in doze mode INTERACTIVE
- * @param batteryRealtime
- * @param iStatsType
- * @return
- */
- public long getInteractiveTime(long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("getInteractiveTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(batteryRealtime);
- params[1]= new Integer(iStatsType);
-
- ret= (Long) method.invoke(m_Instance, params);
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Returns the time in doze mode IDLING
- * @param batteryRealtime
- * @param iStatsType
- * @return
- */
- public long getDeviceIdlingTime(long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("getDeviceIdlingTime", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(batteryRealtime);
- params[1]= new Integer(iStatsType);
-
- ret= (Long) method.invoke(m_Instance, params);
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
-
- /**
- * Returns the network activity
- * @param batteryRealtime
- * @param iStatsType
- * @return
- */
- public long getNetworkActivityBytes(long batteryRealtime, int iStatsType) throws BatteryInfoUnavailableException
- {
- Long ret = new Long(0);
-
- try
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[2];
- paramTypes[0]= long.class;
- paramTypes[1]= int.class;
-
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("getNetworkActivityBytes", paramTypes);
-
- //Parameters
- Object[] params= new Object[2];
- params[0]= new Long(batteryRealtime);
- params[1]= new Integer(iStatsType);
-
- ret= (Long) method.invoke(m_Instance, params);
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = new Long(0);
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
-
- /**
- * Returns the current battery percentage level if we are in a discharge cycle, otherwise
- * returns the level at the last plug event.
- */
- public int getDischargeCurrentLevel() throws BatteryInfoUnavailableException
- {
- int ret = 0;
-
- try
- {
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("getDischargeCurrentLevel");
-
- Integer oRet = (Integer) method.invoke(m_Instance);
- ret = oRet.intValue();
-
- }
- catch( IllegalArgumentException e )
- {
- throw e;
- }
- catch( Exception e )
- {
- ret = 0;
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
- }
-
- /**
- * Initalizes the collection of history items
- */
- public boolean startIteratingHistoryLocked() throws BatteryInfoUnavailableException
- {
- Boolean ret = false;
-
- try
- {
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("startIteratingHistoryLocked");
-
- ret= (Boolean) method.invoke(m_Instance);
-
- }
- catch( IllegalArgumentException e )
- {
- Log.e(TAG, "An exception occured in startIteratingHistoryLocked(). Message: " + e.getMessage() + ", cause: " + e.getCause().getMessage());
- throw e;
- }
- catch( Exception e )
- {
- ret = false;
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Initalizes the collection of history items
- */
- public boolean finishIteratingHistoryLocked() throws BatteryInfoUnavailableException
- {
- Boolean ret = false;
-
- try
- {
- @SuppressWarnings("unchecked")
- Method method = m_ClassDefinition.getMethod("finishIteratingHistoryLocked");
-
- ret= (Boolean) method.invoke(m_Instance);
-
- }
- catch( IllegalArgumentException e )
- {
- Log.e(TAG, "An exception occured in finishIteratingHistoryLocked(). Message: " + e.getMessage() + ", cause: " + e.getCause().getMessage());
- throw e;
- }
- catch( Exception e )
- {
- ret = false;
- throw new BatteryInfoUnavailableException();
- }
-
- return ret;
-
-
- }
-
- /**
- * Collect the UidStats using reflection and store them
- */
- @SuppressWarnings("unchecked")
- private void collectUidStats()
- {
- try
- {
- Method method = m_ClassDefinition.getMethod("getUidStats");
-
- m_uidStats = (SparseArray extends Object>) method.invoke(m_Instance);
-
- }
- catch( IllegalArgumentException e )
- {
- Log.e(TAG, "An exception occured in collectUidStats(). Message: " + e.getMessage() + ", cause: " + e.getCause().getMessage());
- throw e;
- }
- catch( Exception e )
- {
- m_uidStats = null;
- }
-
- }
-
- /**
- * Obtain the wakelock stats as a list of Wakelocks (@see com.asksven.android.common.privateapiproxies.Wakelock}
- * @param context a Context
- * @param iWakeType a type of wakelock @see com.asksven.android.common.privateapiproxies.BatteryStatsTypes
- * @param iStatType a type of stat @see com.asksven.android.common.privateapiproxies.BatteryStatsTypes
- * @return a List of Wakelock s
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- public ArrayList getWakelockStats(Context context, int iWakeType, int iStatType, int iWlPctRef) throws Exception
- {
- // type checks
- boolean validTypes = (BatteryStatsTypes.assertValidWakeType(iWakeType)
- && BatteryStatsTypes.assertValidStatType(iStatType)
- && BatteryStatsTypes.assertValidWakelockPctRef(iWlPctRef));
- if (!validTypes)
- {
- Log.e(TAG, "Invalid WakeType or StatType");
- throw new Exception("Invalid WakeType of StatType");
- }
-
- ArrayList myStats = new ArrayList();
-
- this.collectUidStats();
- if (m_uidStats != null)
- {
- long uSecBatteryTime = this.computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, iStatType);
- long uSecAwakeTime = this.computeBatteryUptime(SystemClock.elapsedRealtime() * 1000, iStatType);
- long uSecScreenOnTime =this.getScreenOnTime(uSecBatteryTime, iStatType);
-
- try
- {
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsUid = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid");
- int NU = m_uidStats.size();
- for (int iu = 0; iu < NU; iu++)
- {
- // Object is an instance of BatteryStats.Uid
- Object myUid = m_uidStats.valueAt(iu);
-
- // Process wake lock usage
- Method methodGetWakelockStats = iBatteryStatsUid.getMethod("getWakelockStats");
-
- // Map of String, BatteryStats.Uid.Wakelock
- Map wakelockStats = (Map) methodGetWakelockStats.invoke(myUid);
-
- Method methodGetUid = iBatteryStatsUid.getMethod("getUid");
- Integer uid = (Integer) methodGetUid.invoke(myUid);
-
- long wakelockTime = 0;
- int wakelockCount = 0;
-
- // Map of String, BatteryStats.Uid.Wakelock
- for (Map.Entry wakelockEntry : wakelockStats.entrySet())
- {
- // BatteryStats.Uid.Wakelock
- Object wakelock = wakelockEntry.getValue();
-
- @SuppressWarnings("rawtypes")
- Class batteryStatsUidWakelock = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid$Wakelock");
-
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypesGetWakeTime= new Class[1];
- paramTypesGetWakeTime[0]= int.class;
-
- Method methodGetWakeTime = batteryStatsUidWakelock.getMethod("getWakeTime", paramTypesGetWakeTime);
-
-
- //Parameters
- Object[] paramsGetWakeTime= new Object[1];
-
- // Partial wake locks BatteryStatsTypes.WAKE_TYPE_PARTIAL
- // are the ones that should normally be of interest but
- // WAKE_TYPE_PARTIAL, WAKE_TYPE_FULL, WAKE_TYPE_WINDOW
- // are possible
- paramsGetWakeTime[0]= Integer.valueOf(iWakeType);
-
- // BatteryStats.Timer
- Object wakeTimer = methodGetWakeTime.invoke(wakelock, paramsGetWakeTime);
- if (wakeTimer != null)
- {
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsTimer = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Timer");
-
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypesGetTotalTimeLocked= new Class[2];
- paramTypesGetTotalTimeLocked[0]= long.class;
- paramTypesGetTotalTimeLocked[1]= int.class;
-
- Method methodGetTotalTimeLocked = iBatteryStatsTimer.getMethod("getTotalTimeLocked", paramTypesGetTotalTimeLocked);
-
- //Parameters
- Object[] paramsGetTotalTimeLocked= new Object[2];
- paramsGetTotalTimeLocked[0]= new Long(uSecBatteryTime);
- paramsGetTotalTimeLocked[1]= Integer.valueOf(iStatType);
-
- Long wake = (Long) methodGetTotalTimeLocked.invoke(wakeTimer, paramsGetTotalTimeLocked);
-// Log.d(TAG, "Wakelocks inner: Process = " + wakelockEntry.getKey() + " wakelock [s] " + wake);
- wakelockTime += wake;
-
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypesGetCountLocked= new Class[1];
- paramTypesGetCountLocked[0]= int.class;
-
- Method methodGetCountLocked = iBatteryStatsTimer.getMethod("getCountLocked", paramTypesGetCountLocked);
-
- //Parameters
- Object[] paramsGetCountLocked= new Object[1];
- paramsGetCountLocked[0]= new Integer(iStatType);
-
- Integer count = (Integer) methodGetCountLocked.invoke(wakeTimer, paramsGetCountLocked);
-// Log.d(TAG, "Wakelocks inner: Process = " + wakelockEntry.getKey() + " count " + count);
- wakelockCount += count;
-
- }
-// else
-// {
-// Log.d(TAG, "Wakelocks: Process = " + wakelockEntry.getKey() + " with no Timer spotted");
-// }
- // convert so milliseconds
- wakelockTime /= 1000;
-
- long uSec = 0;
- switch (iWlPctRef)
- {
- case 0:
- uSec = uSecBatteryTime;
- break;
- case 1:
- uSec = uSecAwakeTime;
- break;
- case 2:
- uSec = (uSecAwakeTime - uSecScreenOnTime);
- break;
- }
-
- // On L Preview partial wakelocks are expressed in milliseconds
- Wakelock myWl = null;
- if (Build.VERSION.SDK_INT >= 20)
- {
- myWl = new Wakelock(iWakeType, wakelockEntry.getKey(), wakelockTime, uSec, wakelockCount);
-
- }
- else
- {
- myWl = new Wakelock(iWakeType, wakelockEntry.getKey(), wakelockTime, uSec / 1000, wakelockCount);
- }
-
- // opt for lazy loading: do no populate UidInfo, just uid. UidInfo will be fetched on demand
- myWl.setUid(uid);
- myStats.add(myWl);
-
-// Log.d(TAG, "Wakelocks: Process = " + wakelockEntry.getKey() + " wakelock [s] " + wakelockTime + ", count " + wakelockCount);
- }
- }
- }
- catch( Exception e )
- {
- Log.e(TAG, "An exception occured in getWakelockStats(). Message: " + e.getMessage() + ", cause: " + e.getCause().getMessage());
- throw e;
- }
- }
- return myStats;
- }
-
- /**
- * Obtain the wakelock stats as a list of Wakelocks (@see com.asksven.android.common.privateapiproxies.Wakelock}
- * @param context a Context
- * @return a List of Wakelock s
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- public ArrayList getKernelWakelockStats(Context context, int iStatType, boolean bAlternate) throws Exception
- {
- // type checks
- boolean validTypes = BatteryStatsTypes.assertValidStatType(iStatType);
- if (!validTypes)
- {
- Log.e(TAG, "Invalid WakeType or StatType");
- throw new Exception("Invalid WakeType or StatType");
- }
-
- Log.d(TAG, "getWakelockStats was called with params "
- +"[iStatType] = " + iStatType);
-
- ArrayList myStats = new ArrayList();
-
- long uSecBatteryTime = this.computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, iStatType);
- //long uSecBatteryTime = this.computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, iStatType);
- //long msSinceBoot = SystemClock.elapsedRealtime();
-
- try
- {
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class iBatteryStats = cl.loadClass("com.android.internal.os.BatteryStatsImpl");
-
- // Process wake lock usage
- Method methodGetKernelWakelockStats = iBatteryStats.getMethod("getKernelWakelockStats");
-
- Class classSamplingTimer = cl.loadClass("com.android.internal.os.BatteryStatsImpl$SamplingTimer");
-
- Field currentReportedCount = classSamplingTimer.getDeclaredField("mCurrentReportedCount");
- Field currentReportedTotalTime = classSamplingTimer.getDeclaredField("mCurrentReportedTotalTime");
- Field unpluggedReportedCount = classSamplingTimer.getDeclaredField("mUnpluggedReportedCount");
- Field unpluggedReportedTotalTime = classSamplingTimer.getDeclaredField("mUnpluggedReportedTotalTime");
- //Field inDischarge = classSamplingTimer.getDeclaredField("mInDischarge");
- Field trackingReportedValues = classSamplingTimer.getDeclaredField("mTrackingReportedValues");
-
- currentReportedCount.setAccessible(true);
- currentReportedTotalTime.setAccessible(true);
- unpluggedReportedCount.setAccessible(true);
- unpluggedReportedTotalTime.setAccessible(true);
- //inDischarge.setAccessible(true);
- trackingReportedValues.setAccessible(true);
-
- //Parameters
- Object[] params= new Object[1];
-
-
- // Map of String, BatteryStatsImpl.SamplingTimer
- Map kernelWakelockStats = (Map) methodGetKernelWakelockStats.invoke(m_Instance);
-
-
- // Map of String, BatteryStats.Uid.Wakelock
- for (Map.Entry wakelockEntry : kernelWakelockStats.entrySet())
- {
- // BatteryStats.SamplingTimer
- String wakelockName = wakelockEntry.getKey();
- Object samplingTimer = wakelockEntry.getValue();
-
- params[0]= samplingTimer;
-
- // read private fields
- Integer currentReportedCountVal = (Integer) currentReportedCount.get(params[0]);
- Long currentReportedTotalTimeVal = (Long) currentReportedTotalTime.get(params[0]);
-
- Integer unpluggedReportedCountVal = (Integer) unpluggedReportedCount.get(params[0]);
- Long unpluggedReportedTotalTimeVal = (Long) unpluggedReportedTotalTime.get(params[0]);
-
- //Boolean inDischargeVal = (Boolean) inDischarge.get(params[0]);
- Boolean trackingReportedValuesVal = (Boolean) trackingReportedValues.get(params[0]);
-
- if (CommonLogSettings.DEBUG)
- {
- Log.d(TAG, "Kernel wakelock '" + wakelockEntry.getKey() + "'"
- + " : reading fields from SampleTimer: "
- + " [currentReportedCountVal] = " + currentReportedCountVal
- + " [currentReportedTotalTimeVal] = " + currentReportedTotalTimeVal
- + " [unpluggedReportedCountVal] = " + unpluggedReportedCountVal
- + " [mUnpluggedReportedTotalTimeVal] = " + unpluggedReportedTotalTimeVal
- //+ " [mInDischarge] = " + inDischargeVal
- + " [mTrackingReportedValues] = " + trackingReportedValuesVal);
- }
-
-//
-// @SuppressWarnings("rawtypes")
-// Class batteryStatsSamplingTimerClass = cl.loadClass("com.android.internal.os.BatteryStatsImpl$SamplingTimer");
-
- //Parameters Types
-// @SuppressWarnings("rawtypes")
-// Class[] paramTypesGetTotalTimeLocked= new Class[2];
-// paramTypesGetTotalTimeLocked[0]= long.class;
-// paramTypesGetTotalTimeLocked[1]= int.class;
-//
-// //Parameters
-// Object[] paramGetTotalTimeLocked= new Object[2];
-// paramGetTotalTimeLocked[0]= new Long(uSecBatteryTime);
-// paramGetTotalTimeLocked[1]= new Integer(iStatType);
-//
-//
-// Method methodGetTotalTimeLocked = classSamplingTimer
-// .getMethod("getTotalTimeLocked", paramTypesGetTotalTimeLocked);
-//
-// //Parameters Types
-// @SuppressWarnings("rawtypes")
-// Class[] paramTypesGetCountLocked= new Class[1];
-// paramTypesGetCountLocked[0]= int.class;
-//
-// //Parameters
-// Object[] paramGetCountLocked= new Object[1];
-// paramGetCountLocked[0]= new Integer(iStatType);
-//
-// Method methodGetCountLocked = classSamplingTimer
-// .getMethod("getCountLocked", paramTypesGetCountLocked);
-//
-//
-// Long wake = (Long) methodGetTotalTimeLocked.invoke(samplingTimer, paramGetTotalTimeLocked);
-//
-// Integer count = (Integer) methodGetCountLocked.invoke(samplingTimer, paramGetCountLocked);
-//
-// if (CommonLogSettings.DEBUG)
-// {
-// Log.d(TAG, "Kernel wakelock: " + wakelockEntry.getKey() + " wakelock [s] " + wake / 1000
-// + " count " + count);
-// }
-
- // public NativeKernelWakelock(String name, String details, int count, int expire_count, int wake_count,
- // long active_since, long total_time, long sleep_time, long max_time, long last_change, long time)
- //public KernelWakelock(String name, long duration, long time, int count)
- // return the data depending on the method
- //if (!bAlternate)
- //{
- //KernelWakelock myWl = new KernelWakelock(wakelockEntry.getKey(), wake / 1000, uSecBatteryTime / 1000, count);
-
-// NativeKernelWakelock myWl = new NativeKernelWakelock(wakelockEntry.getKey() + " *api*", "", count.intValue(), 0, 0,
-// 0L, wake/1000, wake/1000, 0L, 0L, uSecBatteryTime / 1000);
-// myStats.add(myWl);
- //}
-// else
-// {
- if (CommonLogSettings.DEBUG)
- {
- Log.d(TAG, "Kernel wakelock: " + wakelockEntry.getKey() + " wakelock [s] " + currentReportedTotalTimeVal / 1000
- + " count " + currentReportedCountVal);
- }
-
- NativeKernelWakelock myWl = new NativeKernelWakelock(
- wakelockEntry.getKey(), "*api*", currentReportedCountVal, 0, 0, 0L,
- currentReportedTotalTimeVal / 1000, currentReportedTotalTimeVal / 1000, 0L, 0L,
- uSecBatteryTime / 1000);
- myStats.add(myWl);
-// }
- }
- }
- catch( Exception e )
- {
- Log.e(TAG, "An exception occured in getKernelWakelockStats(). Message: " + e.getMessage() + ", cause: " + e.getCause().getMessage());
- throw e;
- }
-
- return myStats;
- }
-
- /**
- * Obtain the process stats as a list of Processes (@see com.asksven.android.common.privateapiproxies.Process}
- * @param context a Context
- * @param iStatType a type of stat @see com.asksven.android.common.privateapiproxies.BatteryStatsTypes
- * @return a List of Process es
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- public ArrayList getProcessStats(Context context, int iStatType) throws Exception
- {
- // type checks
- boolean validTypes = BatteryStatsTypes.assertValidStatType(iStatType);
- if (!validTypes)
- {
- Log.e(TAG, "Invalid WakeType or StatType");
- throw new Exception("Invalid StatType");
- }
-
- ArrayList myStats = new ArrayList();
-
- this.collectUidStats();
- if (m_uidStats != null)
- {
- try
- {
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsUid = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid");
- int NU = m_uidStats.size();
- for (int iu = 0; iu < NU; iu++)
- {
- // Object is an instance of BatteryStats.Uid
- Object myUid = m_uidStats.valueAt(iu);
-
- Method methodGetProcessStats = iBatteryStatsUid.getMethod("getProcessStats");
-
- Method methodGetUid = iBatteryStatsUid.getMethod("getUid");
- Integer uid = (Integer) methodGetUid.invoke(myUid);
-
- // Map of String, BatteryStats.Uid.Proc
- Map processStats = (Map) methodGetProcessStats.invoke(myUid);
-
- if (processStats.size() > 0)
- {
- for (Map.Entry ent : processStats.entrySet())
- {
- if (CommonLogSettings.TRACE)
- {
- Log.d(TAG, "Process name = " + ent.getKey());
- }
- // Object is a BatteryStatsTypes.Uid.Proc
- Object ps = ent.getValue();
- @SuppressWarnings("rawtypes")
- Class batteryStatsUidProc = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid$Proc");
-
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypesGetXxxTime= new Class[1];
- paramTypesGetXxxTime[0]= int.class;
-
- Method methodGetUserTime = batteryStatsUidProc.getMethod("getUserTime", paramTypesGetXxxTime);
- Method methodGetSystemTime = batteryStatsUidProc.getMethod("getSystemTime", paramTypesGetXxxTime);
- Method methodGetStarts = batteryStatsUidProc.getMethod("getStarts", paramTypesGetXxxTime);
-
- //Parameters
- Object[] paramsGetXxxTime= new Object[1];
- paramsGetXxxTime[0]= new Integer(iStatType);
-
- Long userTime = (Long) methodGetUserTime.invoke(ps, paramsGetXxxTime);
- Long systemTime = (Long) methodGetSystemTime.invoke(ps, paramsGetXxxTime);
- Integer starts = (Integer) methodGetStarts.invoke(ps, paramsGetXxxTime);
-
- // starting in kitkat usertime and system time are expressed in 1/100s
- // @see https://android.googlesource.com/platform/frameworks/base/+/android-4.4_r1.1/core/java/android/os/BatteryStats.java
- // line 343ff
- if (Build.VERSION.SDK_INT >= 19)
- {
- userTime *= 10;
- systemTime *= 10;
- }
-
-
- if (CommonLogSettings.TRACE)
- {
- Log.d(TAG, "UserTime = " + userTime);
- Log.d(TAG, "SystemTime = " + systemTime);
- Log.d(TAG, "Starts = " + starts);
- }
-
- boolean ignore = false;
-
- // take only the processes with CPU time
- if ((userTime + systemTime) > 100)
- {
- Process myPs = new Process(ent.getKey(), userTime, systemTime, starts);
- // opt for lazy loading: do no populate UidInfo, just uid. UidInfo will be fetched on demand
- myPs.setUid(uid);
- // try resolving names
-// String myName = m_nameResolver.getLabel(context, ent.getKey());
-
- myStats.add(myPs);
- }
- else
- {
- if (CommonLogSettings.TRACE)
- {
- Log.d(TAG, "Process " + ent.getKey() + " was discarded (CPU time =0)");
- }
- }
- }
- }
- }
- }
- catch( Exception e )
- {
- Log.e(TAG, "An exception occured in getProcessStats(). Message: " + e.getMessage() + ", cause: " + e.getCause().getMessage());
- throw e;
- }
- }
- return myStats;
- }
-
- /**
- * Obtain the wakeup stats as a list of Alarms (@see com.asksven.android.common.privateapiproxies.Alarm}
- * @param context a Context
- * @param iStatType a type of stat @see com.asksven.android.common.privateapiproxies.BatteryStatsTypes
- * @return a List of Process es
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- public ArrayList getWakeupStats(Context context, int iStatType) throws Exception
- {
- if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.LOLLIPOP_MR1)
- {
- return getWakeupStatsPre6(context, iStatType);
- }
- else
- {
- return getWakeupStatsPost6(context, iStatType);
- }
- }
-
-
- @SuppressWarnings("unchecked")
- public ArrayList getWakeupStatsPre6(Context context, int iStatType) throws Exception
- {
- // type checks
- boolean validTypes = BatteryStatsTypes.assertValidStatType(iStatType);
- if (!validTypes)
- {
- Log.e(TAG, "Invalid WakeType or StatType");
- throw new Exception("Invalid StatType");
- }
-
- ArrayList myStats = new ArrayList();
-
- this.collectUidStats();
- if (m_uidStats != null)
- {
- try
- {
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsUid = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid");
- int NU = m_uidStats.size();
- for (int iu = 0; iu < NU; iu++)
- {
- // Object is an instance of BatteryStats.Uid
- Object myUid = m_uidStats.valueAt(iu);
-
- Method methodGetPackageStats = iBatteryStatsUid.getMethod("getPackageStats");
-
- Method methodGetUid = iBatteryStatsUid.getMethod("getUid");
- Integer uid = (Integer) methodGetUid.invoke(myUid);
-
- // Map of String, BatteryStats.Uid.Proc
- Map packageStats = (Map) methodGetPackageStats.invoke(myUid);
-
- if (packageStats.size() > 0)
- {
- for (Map.Entry ent : packageStats.entrySet())
- {
- if (CommonLogSettings.TRACE)
- {
- Log.d(TAG, "Package name = " + ent.getKey());
- }
- // Object is a BatteryStatsTypes.Uid.Proc
- Object ps = ent.getValue();
- @SuppressWarnings("rawtypes")
- Class batteryStatsUidPkg = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid$Pkg");
-
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypesGetWakeups= new Class[1];
- paramTypesGetWakeups[0]= int.class;
-
- Method methodGetWakeups = batteryStatsUidPkg.getMethod("getWakeups", paramTypesGetWakeups);
-
- //Parameters
- Object[] paramsGetWakeups= new Object[1];
- paramsGetWakeups[0]= new Integer(iStatType);
-
- int wakeups = (Integer) methodGetWakeups.invoke(ps, paramsGetWakeups);
-
- if (CommonLogSettings.TRACE)
- {
- Log.d(TAG, "uid = " + uid);
- Log.d(TAG, "wkeups = " + wakeups);
- }
-
- boolean ignore = false;
-
- if ((wakeups) > 0)
- {
- Alarm myWakeup = new Alarm(ent.getKey(), "*api*");
- myWakeup.setWakeups(wakeups);
- // opt for lazy loading: do no populate UidInfo, just uid. UidInfo will be fetched on demand
- myWakeup.setUid(uid);
- // try resolving names
-// String myName = m_nameResolver.getLabel(context, ent.getKey());
-
- myStats.add(myWakeup);
- }
- else
- {
- if (CommonLogSettings.TRACE)
- {
- Log.d(TAG, "Process " + ent.getKey() + " was discarded (CPU time =0)");
- }
- }
- }
- }
- }
- }
- catch( Exception e )
- {
- Log.e(TAG, "An exception occured in getWakeupStats(). Message: " + e.getMessage() + ", cause: " + e.getCause().getMessage());
- throw e;
- }
- }
- return myStats;
- }
-
- @SuppressLint("NewApi")
- @SuppressWarnings("unchecked")
- public ArrayList getWakeupStatsPost6(Context context, int iStatType) throws Exception
- {
- // type checks
- boolean validTypes = BatteryStatsTypes.assertValidStatType(iStatType);
- if (!validTypes)
- {
- Log.e(TAG, "Invalid WakeType or StatType");
- throw new Exception("Invalid StatType");
- }
-
- ArrayList myStats = new ArrayList();
-
- this.collectUidStats();
- if (m_uidStats != null)
- {
- try
- {
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsUid = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid");
- int NU = m_uidStats.size();
- for (int iu = 0; iu < NU; iu++)
- {
- // Object is an instance of BatteryStats.Uid
- Object myUid = m_uidStats.valueAt(iu);
-
- Method methodGetPackageStats = iBatteryStatsUid.getMethod("getPackageStats");
-
- Method methodGetUid = iBatteryStatsUid.getMethod("getUid");
- Integer uid = (Integer) methodGetUid.invoke(myUid);
-
- // Map of String, BatteryStats.Uid.Proc
- Map packageStats = (Map) methodGetPackageStats.invoke(myUid);
-
- if (packageStats.size() > 0)
- {
- for (Map.Entry ent : packageStats.entrySet())
- {
- if (CommonLogSettings.TRACE)
- {
- Log.d(TAG, "Package name = " + ent.getKey());
- }
- // Object is a BatteryStatsTypes.Uid.Proc
- Object ps = ent.getValue();
- @SuppressWarnings("rawtypes")
- Class batteryStatsUidPkg = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid$Pkg");
-
- Method methodGetWakeupAlarmStats = batteryStatsUidPkg.getMethod("getWakeupAlarmStats");
- Map wakeupStats =
- (Map) methodGetWakeupAlarmStats.invoke(ps);
-
- for (Map.Entry wa : wakeupStats.entrySet())
- {
- Class batteryStatsCounter = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Counter");
-
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramsTypesGetCountLocked= new Class[1];
- paramsTypesGetCountLocked[0]= int.class;
-
- Method methodGetCountLocked = batteryStatsCounter.getMethod("getCountLocked", paramsTypesGetCountLocked);
-
- // Parameters
- Object[] paramsGetCountLocked= new Object[1];
- paramsGetCountLocked[0]= new Integer(iStatType);
-
- Object counter = wa.getValue();
-
- int wakeups = (Integer) methodGetCountLocked.invoke(counter, paramsGetCountLocked);
-
- if ((wakeups) > 0)
- {
- Alarm myWakeup = new Alarm(ent.getKey(), "*api*");
- myWakeup.setWakeups(wakeups);
- // opt for lazy loading: do no populate UidInfo, just uid. UidInfo will be fetched on demand
- myWakeup.setUid(uid);
-
- myStats.add(myWakeup);
- }
- else
- {
- if (CommonLogSettings.TRACE)
- {
- Log.d(TAG, "Process " + ent.getKey() + " was discarded (CPU time =0)");
- }
- }
-
- }
- }
- }
- }
- }
- catch( Exception e )
- {
- Log.e(TAG, "An exception occured in getWakeupStats(). Message: " + e.getMessage() + ", cause: " + e.getCause().getMessage());
- throw e;
- }
- }
- return myStats;
- }
-
- @SuppressWarnings("unchecked")
- public Long getSyncOnTime(Context context, long batteryRealtime, int iStatsType) throws Exception
- {
- // type checks
- boolean validTypes = BatteryStatsTypes.assertValidStatType(iStatsType);
- if (!validTypes)
- {
- Log.e(TAG, "Invalid WakeType or StatType");
- throw new Exception("Invalid StatType");
- }
-
- Long ret = 0L;
-
- this.collectUidStats();
- if (m_uidStats != null)
- {
- try
- {
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsUid = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid");
- int NU = m_uidStats.size();
- for (int iu = 0; iu < NU; iu++)
- {
- // Object is an instance of BatteryStats.Uid
- Object myUid = m_uidStats.valueAt(iu);
-
- Method methodGetSyncStats = iBatteryStatsUid.getMethod("getSyncStats");
-
- Method methodGetUid = iBatteryStatsUid.getMethod("getUid");
- Integer uid = (Integer) methodGetUid.invoke(myUid);
-
- // Map of String, BatteryStats.Uid.Proc
- Map syncStats = (Map) methodGetSyncStats.invoke(myUid);
-
- if (syncStats.size() > 0)
- {
- for (Map.Entry ent : syncStats.entrySet())
- {
- if (CommonLogSettings.TRACE)
- {
- Log.d(TAG, "Package name = " + ent.getKey());
- }
- // Object is a BatteryStatsTypes.Uid.Proc
- Object timer = ent.getValue();
- @SuppressWarnings("rawtypes")
- Class batteryStatsTimer = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Timer");
-
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramsTypesGetTotalTimeLocked= new Class[1];
- paramsTypesGetTotalTimeLocked[0]= long.class;
-
- // method is protected so we must make it accessible
- Method computeRunTimeLocked = batteryStatsTimer.getDeclaredMethod("computeRunTimeLocked", paramsTypesGetTotalTimeLocked);
- computeRunTimeLocked.setAccessible(true);
-
-
- //Parameters
- Object[] params= new Object[1];
- params[0]= new Long(batteryRealtime);
-
- // call public long getTotalTimeLocked(long elapsedRealtimeUs, int which)
- Long value = (Long) computeRunTimeLocked.invoke(timer, params);
- ret += value;
-
- }
- }
- }
- }
- catch( Exception e )
- {
- Log.e(TAG, "An exception occured in getSyncOnTime(). Message: " + e.getMessage());
- throw e;
- }
- }
- return ret;
- }
-
- /**
- * Obtain the network usage stats as a list of NetworkUsages (@see com.asksven.android.common.privateapiproxies.NetworkUsage}
- * @param context a Context
- * @param iStatType a type of stat @see com.asksven.android.common.privateapiproxies.BatteryStatsTypes
- * @return a List of NetworkUsage s
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- public ArrayList getNetworkUsageStats(Context context, int iStatType) throws Exception
- {
- // type checks
- boolean validTypes = BatteryStatsTypes.assertValidStatType(iStatType);
- if (!validTypes)
- {
- Log.e(TAG, "Invalid WakeType or StatType");
- throw new Exception("Invalid StatType");
- }
-
- ArrayList myStats = new ArrayList();
-
- this.collectUidStats();
- if (m_uidStats != null)
- {
- try
- {
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class iBatteryStatsUid = cl.loadClass("com.android.internal.os.BatteryStatsImpl$Uid");
- int NU = m_uidStats.size();
- for (int iu = 0; iu < NU; iu++)
- {
- // Object is an instance of BatteryStats.Uid
- Object myUid = m_uidStats.valueAt(iu);
-
- Long bytesReceived = 0L;
- Long bytesSent = 0L;
- Long bytesReceivedWifi = 0L;
- Long bytesReceivedMobile = 0L;
- Long bytesSentWifi = 0L;
- Long bytesSentMobile = 0L;
-
-
- // getTcpBytesReceived and getTcpBytesSent are available in API level < 19.
- // They are replaced by getNetworkActivityCount in API level >= 19.
- if (Build.VERSION.SDK_INT < 19)
- {
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypesGetTcpBytesXxx = new Class[1];
- paramTypesGetTcpBytesXxx[0] = int.class;
-
- Method methodGetTcpBytesReceived = iBatteryStatsUid.getMethod("getTcpBytesReceived", paramTypesGetTcpBytesXxx);
- Method methodGetTcpBytesSent = iBatteryStatsUid.getMethod("getTcpBytesSent", paramTypesGetTcpBytesXxx);
-
- //Parameters
- Object[] paramGetTcpBytesXxx = new Object[1];
- paramGetTcpBytesXxx[0] = new Integer(iStatType);
-
- bytesReceived = (Long) methodGetTcpBytesReceived.invoke(myUid, paramGetTcpBytesXxx);
- bytesSent = (Long) methodGetTcpBytesSent.invoke(myUid, paramGetTcpBytesXxx);
- }
- else if (Build.VERSION.SDK_INT <= 21)
- {
- @SuppressWarnings("rawtypes")
- Class[] paramTypesGetNetworkActivity = new Class[] {int.class, int.class};
- Method methodGetNetworkActivity = iBatteryStatsUid.getMethod("getNetworkActivityCount",
- paramTypesGetNetworkActivity);
- // Parameters for getting received bytes from mobile
- Object paramGetNetworkActivityCount [] = {NETWORK_MOBILE_RX_BYTES,
- iStatType};
- bytesReceivedMobile = (Long) methodGetNetworkActivity.invoke(myUid, paramGetNetworkActivityCount);
- // change parameter to get received bytes from wifi
- paramGetNetworkActivityCount[0] = NETWORK_WIFI_RX_BYTES;
- // add together for now
- bytesReceivedWifi = (Long) methodGetNetworkActivity.invoke(myUid, paramGetNetworkActivityCount);
-
- // same for transmitted bytes
- paramGetNetworkActivityCount[0] = NETWORK_MOBILE_TX_BYTES;
- bytesSentMobile = (Long) methodGetNetworkActivity.invoke(myUid, paramGetNetworkActivityCount);
- paramGetNetworkActivityCount[0] = NETWORK_WIFI_TX_BYTES;
- bytesSentWifi = (Long) methodGetNetworkActivity.invoke(myUid, paramGetNetworkActivityCount);
- }
- else
- {
- @SuppressWarnings("rawtypes")
- Class[] paramTypesGetNetworkActivity = new Class[] {int.class, int.class};
- Method methodGetNetworkActivity = iBatteryStatsUid.getMethod("getNetworkActivityBytes",
- paramTypesGetNetworkActivity);
-
- // Parameters for getting received bytes from mobile
- Object paramGetNetworkActivityCount [] = {NETWORK_MOBILE_RX_BYTES,
- iStatType};
- bytesReceivedMobile = (Long) methodGetNetworkActivity.invoke(myUid, paramGetNetworkActivityCount);
- // change parameter to get received bytes from wifi
- paramGetNetworkActivityCount[0] = NETWORK_WIFI_RX_BYTES;
- // add together for now
- bytesReceivedWifi = (Long) methodGetNetworkActivity.invoke(myUid, paramGetNetworkActivityCount);
-
- // same for transmitted bytes
- paramGetNetworkActivityCount[0] = NETWORK_MOBILE_TX_BYTES;
- bytesSentMobile = (Long) methodGetNetworkActivity.invoke(myUid, paramGetNetworkActivityCount);
- paramGetNetworkActivityCount[0] = NETWORK_WIFI_TX_BYTES;
- bytesSentWifi = (Long) methodGetNetworkActivity.invoke(myUid, paramGetNetworkActivityCount);
- }
-
- Method methodGetUid = iBatteryStatsUid.getMethod("getUid");
- Integer uid = (Integer) methodGetUid.invoke(myUid);
-
- if (CommonLogSettings.DEBUG)
- {
- Log.d(TAG, "Uid = " + uid + ": received:" + bytesReceived + ", sent: " + bytesSent);
- }
-
- NetworkUsage myData = null;
- if (Build.VERSION.SDK_INT >= 19)
- {
- // we have data separated for Wifi and Mobile
- myData = new NetworkUsage(uid, "Wifi", bytesReceivedWifi, bytesSentWifi);
- // try resolving names
- UidInfo myInfo = UidNameResolver.getInstance().getNameForUid(uid);
- myData.setUidInfo(myInfo);
- myStats.add(myData);
-
- myData = new NetworkUsage(uid, "Mobile", bytesReceivedMobile, bytesSentMobile);
- // try resolving names
- myData.setUidInfo(myInfo);
- myStats.add(myData);
-
- }
- {
- myData = new NetworkUsage(uid, bytesReceived, bytesSent);
- // try resolving names
- UidInfo myInfo = UidNameResolver.getInstance().getNameForUid(uid);
- myData.setUidInfo(myInfo);
- myStats.add(myData);
- }
- }
- }
- catch( Exception e )
- {
- throw e;
- }
- }
- return myStats;
- }
-
-
- /**
- * Obtain the network usage stats as a list of NetworkUsages (@see com.asksven.android.common.privateapiproxies.NetworkUsage}
- * @return a List of NetworkUsage s
- * @throws Exception
- */
- public ArrayList getKernelNetworkStats(int iStatsType)
- {
-
- ArrayList myRet = new ArrayList();
- try
- {
- @SuppressWarnings("unchecked")
- // we must use getDeclaredMethod as that method is private
- Method method = m_ClassDefinition.getDeclaredMethod("getNetworkStatsDetailGroupedByUid");
- method.setAccessible(true);
-
- Object networkStats = method.invoke(m_Instance);
- String myRes = "tada";
- }
- catch (Exception e)
- {
- myRet = null;
- }
- return myRet;
-
-
- }
-
- @SuppressWarnings("unchecked")
- public ArrayList getHistory(Context context) throws Exception
- {
-
- ArrayList myStats = new ArrayList();
-
- try
- {
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class classHistoryItem = cl.loadClass("android.os.BatteryStats$HistoryItem");
-
-
- // get constructor
- Constructor cctor = classHistoryItem.getConstructor();
-
- Object myHistoryItem = cctor.newInstance();
-
- // prepare the method call for getNextHistoryItem
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[1];
- paramTypes[0]= classHistoryItem;
-
-
- @SuppressWarnings("unchecked")
- Method methodNext = m_ClassDefinition.getMethod("getNextHistoryLocked", paramTypes);
-
- //Parameters
- Object[] params= new Object[1];
-
- // initalize hist and iterate like this
- // if (stats.startIteratingHistoryLocked()) {
- // final HistoryItem rec = new HistoryItem();
- // while (stats.getNextHistoryLocked(rec)) {
- int statsType = 0;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
- {
- statsType = BatteryStatsTypesLolipop.STATS_CURRENT;
- }
- else
- {
- statsType = BatteryStatsTypes.STATS_CURRENT;
- }
- // read the time of query for history
- Long statTimeRef = Long.valueOf(this.computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000,
- statsType));
- statTimeRef = System.currentTimeMillis();
-
- if (CommonLogSettings.DEBUG)
- {
- Log.d(TAG, "Reference time (" + statTimeRef + ": " + DateUtils.format(DateUtils.DATE_FORMAT_NOW, statTimeRef));
- }
- // statTimeLast stores the timestamp of the last sample
- Long statTimeLast = Long.valueOf(0);
-
- if (this.startIteratingHistoryLocked())
- {
- params[0]= myHistoryItem;
- Boolean bNext = (Boolean) methodNext.invoke(m_Instance, params);
- while (bNext)
- {
- // process stats: create HistoryItems from params
- Field timeField = classHistoryItem.getField("time"); // long
-
-
- Field cmdField = classHistoryItem.getField("cmd"); // byte
- Byte cmdValue = (Byte) cmdField.get(params[0]);
-
- // process only valid items
- byte updateCmd = 0;
-
- // different versions -> different HistoryItem constants
- if ( (Build.VERSION.SDK_INT == Build.VERSION_CODES.ICE_CREAM_SANDWICH) || (Build.VERSION.SDK_INT == Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) )
- {
- updateCmd = HistoryItemIcs.CMD_UPDATE;
- }
- else if ( (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) || (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT_WATCH) )
- {
- updateCmd = HistoryItemKitKat.CMD_UPDATE;
- }
- else if ( (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) || (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) || (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR2))
- {
- updateCmd = HistoryItemJellyBean.CMD_UPDATE;
- }
- else if ( (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) )
- {
- updateCmd = HistoryItemLolipop.CMD_UPDATE;
- }
- else
- {
- updateCmd = HistoryItem.CMD_UPDATE;
- }
-
- if (cmdValue == updateCmd)
- {
- Field batteryLevelField = classHistoryItem.getField("batteryLevel"); // byte
- Field batteryStatusField = classHistoryItem.getField("batteryStatus"); // byte
- Field batteryHealthField = classHistoryItem.getField("batteryHealth"); // byte
- Field batteryPlugTypeField = classHistoryItem.getField("batteryPlugType"); // byte
-
- Field batteryTemperatureField = classHistoryItem.getField("batteryTemperature"); // char
- Field batteryVoltageField = classHistoryItem.getField("batteryVoltage"); // char
-
- Field statesField = classHistoryItem.getField("states"); // int
-
- // retrieve all values
- @SuppressWarnings("rawtypes")
- Long timeValue = (Long) timeField.get(params[0]);
-
- // store values only once
- if (!statTimeLast.equals(timeValue))
- {
- Byte batteryLevelValue = (Byte) batteryLevelField.get(params[0]);
- Byte batteryStatusValue = (Byte) batteryStatusField.get(params[0]);
- Byte batteryHealthValue = (Byte) batteryHealthField.get(params[0]);
- Byte batteryPlugTypeValue = (Byte) batteryPlugTypeField.get(params[0]);
-
- String batteryTemperatureValue = String.valueOf(batteryTemperatureField.get(params[0]));
- String batteryVoltageValue = String.valueOf(batteryVoltageField.get(params[0]));
-
- Integer statesValue = (Integer) statesField.get(params[0]);
-
- HistoryItem myItem = null;
-
- // different versions -> different HistoryItem constants
- if ( (Build.VERSION.SDK_INT == Build.VERSION_CODES.ICE_CREAM_SANDWICH) || (Build.VERSION.SDK_INT == Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) )
- {
- myItem = new HistoryItemIcs(timeValue, cmdValue, batteryLevelValue,
- batteryStatusValue, batteryHealthValue, batteryPlugTypeValue,
- batteryTemperatureValue, batteryVoltageValue, statesValue);
- }
- else if ( (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) || (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT_WATCH) )
- {
- myItem = new HistoryItemKitKat(timeValue, cmdValue, batteryLevelValue,
- batteryStatusValue, batteryHealthValue, batteryPlugTypeValue,
- batteryTemperatureValue, batteryVoltageValue, statesValue);
- }
- else if ( (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) || (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) || (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR2))
- {
- myItem = new HistoryItemJellyBean(timeValue, cmdValue, batteryLevelValue,
- batteryStatusValue, batteryHealthValue, batteryPlugTypeValue,
- batteryTemperatureValue, batteryVoltageValue, statesValue);
- }
- else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
- {
- myItem = new HistoryItemLolipop(timeValue, cmdValue, batteryLevelValue,
- batteryStatusValue, batteryHealthValue, batteryPlugTypeValue,
- batteryTemperatureValue, batteryVoltageValue, statesValue);
- }
- else
- {
- myItem = new HistoryItem(timeValue, cmdValue, batteryLevelValue,
- batteryStatusValue, batteryHealthValue, batteryPlugTypeValue,
- batteryTemperatureValue, batteryVoltageValue, statesValue);
- }
-
- myStats.add(myItem);
-
- }
- // overwrite the time of the last sample
- statTimeLast = timeValue;
-
- }
- else
- {
- Log.d(TAG, "Skipped item");
- }
-
- bNext = (Boolean) methodNext.invoke(m_Instance, params);
- }
-
- // norm the time of each sample
- // stat time last is the number of millis since
- // the stats is being collected
- // the ref time is a full plain time (with date)
- Long offset = statTimeRef - statTimeLast;
-
- if (CommonLogSettings.DEBUG)
- {
- Log.d(TAG, "Reference time (" + statTimeRef + ")" + DateUtils.format(DateUtils.DATE_FORMAT_NOW, statTimeRef));
-
- Log.d(TAG, "Last sample (" + statTimeLast + ")" + DateUtils.format(DateUtils.DATE_FORMAT_NOW, statTimeLast));
-
- Log.d(TAG, "Correcting all HistoryItem times by an offset of (" + offset + ")" + DateUtils.formatDuration(offset * 1000));
- }
-
- for (int i=0; i < myStats.size(); i++)
- {
- myStats.get(i).setOffset(offset);
- }
- }
- }
- catch( Exception e )
- {
- Log.e(TAG, "An exception occured in getHistory(). Message: " + e.getMessage() + ", cause: " + e.getCause().getMessage());
- throw e;
- }
-
- return myStats;
- }
-
-
- @SuppressWarnings("unchecked")
- public ArrayList dumpHistory(Context context) throws Exception
- {
-
- ArrayList myStats = new ArrayList();
-
- try
- {
- ClassLoader cl = context.getClassLoader();
- @SuppressWarnings("rawtypes")
- Class classHistoryItem = cl.loadClass("android.os.BatteryStats$HistoryItem");
-
-
- // get constructor
- Constructor cctor = classHistoryItem.getConstructor();
-
- Object myHistoryItem = cctor.newInstance();
-
- // prepare the method call for getNextHistoryItem
- //Parameters Types
- @SuppressWarnings("rawtypes")
- Class[] paramTypes= new Class[1];
- paramTypes[0]= classHistoryItem;
-
-
- @SuppressWarnings("unchecked")
- Method methodNext = m_ClassDefinition.getMethod("getNextHistoryLocked", paramTypes);
-
- //Parameters
- Object[] params= new Object[1];
-
- // initalize hist and iterate like this
- // if (stats.startIteratingHistoryLocked()) {
- // final HistoryItem rec = new HistoryItem();
- // while (stats.getNextHistoryLocked(rec)) {
- int statsType = 0;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
- {
- statsType = BatteryStatsTypesLolipop.STATS_CURRENT;
- }
- else
- {
- statsType = BatteryStatsTypes.STATS_CURRENT;
- }
-
- // read the time of query for history
- Long statTimeRef = Long.valueOf(this.computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000,
- statsType));
- statTimeRef = System.currentTimeMillis();
-
- if (CommonLogSettings.DEBUG)
- {
- Log.d(TAG, "Reference time (" + statTimeRef + ": " + DateUtils.format(DateUtils.DATE_FORMAT_NOW, statTimeRef));
- }
- // statTimeLast stores the timestamp of the last sample
- Long statTimeLast = Long.valueOf(0);
-
- if (this.startIteratingHistoryLocked())
- {
- params[0]= myHistoryItem;
- Boolean bNext = (Boolean) methodNext.invoke(m_Instance, params);
- while (bNext)
- {
- // process stats: create HistoryItems from params
- Field timeField = classHistoryItem.getField("time"); // long
-
-
- Field cmdField = classHistoryItem.getField("cmd"); // byte
- Byte cmdValue = (Byte) cmdField.get(params[0]);
-
- // process only valid items
- byte updateCmd = 0;
-
- // ICS has a different implementation of HistoryItems constants
- if (AndroidVersion.isIcs())
- {
- updateCmd = HistoryItemIcs.CMD_UPDATE;
- }
- else
- {
- updateCmd = HistoryItem.CMD_UPDATE;
- }
-
- if (true) //(cmdValue == updateCmd)
- {
- Field batteryLevelField = classHistoryItem.getField("batteryLevel"); // byte
- Field batteryStatusField = classHistoryItem.getField("batteryStatus"); // byte
- Field batteryHealthField = classHistoryItem.getField("batteryHealth"); // byte
- Field batteryPlugTypeField = classHistoryItem.getField("batteryPlugType"); // byte
-
- Field batteryTemperatureField = classHistoryItem.getField("batteryTemperature"); // char
- Field batteryVoltageField = classHistoryItem.getField("batteryVoltage"); // char
-
- Field statesField = classHistoryItem.getField("states"); // int
-
- // retrieve all values
- @SuppressWarnings("rawtypes")
- Long timeValue = (Long) timeField.get(params[0]);
-
- Byte batteryLevelValue = (Byte) batteryLevelField.get(params[0]);
- Byte batteryStatusValue = (Byte) batteryStatusField.get(params[0]);
- Byte batteryHealthValue = (Byte) batteryHealthField.get(params[0]);
- Byte batteryPlugTypeValue = (Byte) batteryPlugTypeField.get(params[0]);
-
- String batteryTemperatureValue = String.valueOf(batteryTemperatureField.get(params[0]));
- String batteryVoltageValue = String.valueOf(batteryVoltageField.get(params[0]));
-
- Integer statesValue = (Integer) statesField.get(params[0]);
-
- HistoryItem myItem = null;
-
- // There different implementation of HistoryItems constants
- if (AndroidVersion.isLolipop())
- {
- myItem = new HistoryItemLolipop(timeValue, cmdValue, batteryLevelValue,
- batteryStatusValue, batteryHealthValue, batteryPlugTypeValue,
- batteryTemperatureValue, batteryVoltageValue, statesValue);
- }
- if (AndroidVersion.isKitKat())
- {
- myItem = new HistoryItemKitKat(timeValue, cmdValue, batteryLevelValue,
- batteryStatusValue, batteryHealthValue, batteryPlugTypeValue,
- batteryTemperatureValue, batteryVoltageValue, statesValue);
- }
- else if (AndroidVersion.isIcs())
- {
- myItem = new HistoryItemIcs(timeValue, cmdValue, batteryLevelValue,
- batteryStatusValue, batteryHealthValue, batteryPlugTypeValue,
- batteryTemperatureValue, batteryVoltageValue, statesValue);
- }
- else
- {
- myItem = new HistoryItem(timeValue, cmdValue, batteryLevelValue,
- batteryStatusValue, batteryHealthValue, batteryPlugTypeValue,
- batteryTemperatureValue, batteryVoltageValue, statesValue);
- }
-
- myStats.add(myItem);
- }
- else
- {
- Log.d(TAG, "Skipped item");
- }
-
- bNext = (Boolean) methodNext.invoke(m_Instance, params);
- }
-
- // norm the time of each sample
- // stat time last is the number of millis since
- // the stats is being collected
- // the ref time is a full plain time (with date)
- Long offset = statTimeRef - statTimeLast;
-
- // be sure to release
-// this.finishIteratingHistoryLocked();
-
- for (int i=0; i < myStats.size(); i++)
- {
- myStats.get(i).setOffset(offset);
- }
-
- }
- }
- catch( Exception e )
- {
- Log.e(TAG, "An exception occured in dumpHistory(). Message: " + e.getMessage() + ", cause: " + e.getCause().getMessage());
- throw e;
- }
-
- int oldVal = 0;
- // iterate over myStats
- for (int i=0; i < myStats.size(); i++)
- {
- HistoryItem myItem = myStats.get(i);
- Log.i(TAG, myItem.toString() + " " + myItem.printBitDescriptions(oldVal, myItem.m_statesValue));
- oldVal = myItem.m_statesValue;
- }
- return myStats;
- }
-
-
-}
-
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/BatteryStatsTypes.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/BatteryStatsTypes.java
deleted file mode 100644
index 479df73..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/BatteryStatsTypes.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.asksven.android.common.privateapiproxies;
-
-
-
-
-/**
- * This class holds the required constants from BatteryStats
- * Copyright (C) 2008 The Android Open Source Project applies
- * @see android.os.BatteryStats
- * @author sven
- *
- */
-public class BatteryStatsTypes
-{
- /**
- * A constant indicating a partial wake lock timer.
- */
- public static final int WAKE_TYPE_PARTIAL = 0;
-
- /**
- * A constant indicating a full wake lock timer.
- */
- public static final int WAKE_TYPE_FULL = 1;
-
- /**
- * A constant indicating a window wake lock timer.
- */
- public static final int WAKE_TYPE_WINDOW = 2;
-
- /**
- * Constants for data connection type
- */
- public static final int DATA_CONNECTION_NONE = 0;
-
- /**
- * Constants for signal strength
- */
- public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0;
- public static final int SIGNAL_STRENGTH_POOR = 1;
- public static final int SIGNAL_STRENGTH_MODERATE = 2;
- public static final int SIGNAL_STRENGTH_GOOD = 3;
- public static final int SIGNAL_STRENGTH_GREAT = 4;
-
- /**
- * Constants for screen brightness
- */
-
- public static final int SCREEN_BRIGHTNESS_DARK = 0;
- public static final int SCREEN_BRIGHTNESS_DIM = 1;
- public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
- public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
- public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
-
- /**
- * Constants for BT and Wifi state
- */
-
- public static final int CONTROLLER_IDLE_TIME = 0;
- public static final int CONTROLLER_RX_TIME = 1;
- public static final int CONTROLLER_TX_TIME = 2;
- public static final int CONTROLLER_ENERGY = 3;
-
- /**
- * Enum of valid wakelock types
- */
- public static final boolean assertValidWakeType(int iWakeType)
- {
- boolean ret = false;
- switch (iWakeType)
- {
- case WAKE_TYPE_PARTIAL:
- ret = true;
- break;
- case WAKE_TYPE_FULL:
- ret = true;
- break;
- case WAKE_TYPE_WINDOW:
- ret = true;
- break;
- default:
- ret = false;
- break;
-
- }
- return ret;
- }
-
- /**
- * Include all of the data in the stats, including previously saved data.
- */
- public static final int STATS_SINCE_CHARGED = 0;
-
- /**
- * Include only the last run in the stats.
- */
- public static final int STATS_LAST = 1;
-
- /**
- * Include only the current run in the stats.
- */
- public static final int STATS_CURRENT = 2;
-
- /**
- * Include only the run since the last time the device was unplugged in the stats.
- */
- public static final int STATS_SINCE_UNPLUGGED = 3;
-
- /**
- * Enum of valid stat types
- */
- public static final boolean assertValidStatType(int iStatType)
- {
- boolean ret = false;
- switch (iStatType)
- {
- case STATS_SINCE_CHARGED:
- ret = true;
- break;
- case STATS_LAST:
- ret = true;
- break;
- case STATS_CURRENT:
- ret = true;
- break;
- case STATS_SINCE_UNPLUGGED:
- ret = true;
- break;
-
- default:
- ret = false;
- break;
-
- }
- return ret;
- }
-
- /**
- * Enum of valid stat types
- */
- public static final boolean assertValidWakelockPctRef(int iPctType)
- {
- boolean ret = false;
- switch (iPctType)
- {
- case 0: // % of battery time
- ret = true;
- break;
- case 1: // % of awake time
- ret = true;
- break;
- case 2: // % of time awake - time with screen on
- ret = true;
- break;
- default:
- ret = false;
- break;
-
- }
- return ret;
- }
-}
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/BatteryStatsTypesLolipop.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/BatteryStatsTypesLolipop.java
deleted file mode 100644
index 4451330..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/BatteryStatsTypesLolipop.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.asksven.android.common.privateapiproxies;
-
-
-
-
-/**
- * This class holds the required constants from BatteryStats
- * Copyright (C) 2008 The Android Open Source Project applies
- * @see android.os.BatteryStats
- * @author sven
- *
- */
-public class BatteryStatsTypesLolipop extends BatteryStatsTypes
-{
-
- /** Include all of the data in the stats, including previously saved data */
- public static final int STATS_SINCE_CHARGED = 0;
-
- /** Include only the current run in the stats */
- public static final int STATS_CURRENT = 1;
-
- /** Include only the run since the last time the device was unplugged in the stats */
- public static final int STATS_SINCE_UNPLUGGED = 2;
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/HistoryItem.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/HistoryItem.java
deleted file mode 100644
index debc3bc..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/HistoryItem.java
+++ /dev/null
@@ -1,478 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.asksven.android.common.privateapiproxies;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-import com.asksven.android.common.utils.DateUtils;
-
-import java.io.Serializable;
-
-/**
- * Value holder for BatteryStats$HistoryItem
- * @author sven
- *
- */
-public class HistoryItem implements Serializable, Parcelable
-{
- static final long serialVersionUID = 1L;
- static final byte CMD_UPDATE = 0;
- static final byte CMD_START = 1;
- static final byte CMD_OVERFLOW = 2;
- // Constants from SCREEN_BRIGHTNESS_*
- static final int STATE_BRIGHTNESS_MASK = 0x000000f;
- static final int STATE_BRIGHTNESS_SHIFT = 0;
- // Constants from SIGNAL_STRENGTH_*
- static final int STATE_SIGNAL_STRENGTH_MASK = 0x00000f0;
- static final int STATE_SIGNAL_STRENGTH_SHIFT = 4;
- // Constants from ServiceState.STATE_*
- static final int STATE_PHONE_STATE_MASK = 0x0000f00;
- static final int STATE_PHONE_STATE_SHIFT = 8;
- // Constants from DATA_CONNECTION_*
- static final int STATE_DATA_CONNECTION_MASK = 0x000f000;
- static final int STATE_DATA_CONNECTION_SHIFT = 12;
-
- static final int STATE_BATTERY_PLUGGED_FLAG = 1<<30;
- static final int STATE_SCREEN_ON_FLAG = 1<<29;
- static final int STATE_GPS_ON_FLAG = 1<<28;
- static final int STATE_PHONE_IN_CALL_FLAG = 1<<27;
- static final int STATE_PHONE_SCANNING_FLAG = 1<<26;
- static final int STATE_WIFI_ON_FLAG = 1<<25;
- static final int STATE_WIFI_RUNNING_FLAG = 1<<24;
- static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<23;
- static final int STATE_WIFI_SCAN_LOCK_FLAG = 1<<22;
- static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<21;
- static final int STATE_BLUETOOTH_ON_FLAG = 1<<20;
- static final int STATE_AUDIO_ON_FLAG = 1<<19;
- static final int STATE_VIDEO_ON_FLAG = 1<<18;
- static final int STATE_WAKE_LOCK_FLAG = 1<<17;
- static final int STATE_SENSOR_ON_FLAG = 1<<16;
-
- static final int MOST_INTERESTING_STATES =
- STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG
- | STATE_GPS_ON_FLAG | STATE_PHONE_IN_CALL_FLAG;
-
- protected Long m_time;
- protected Long m_offset;
- protected Byte m_cmd;
- protected Byte m_batteryLevel;
- protected Byte m_batteryStatusValue;
- protected Byte m_batteryHealthValue;
- protected Byte m_batteryPlugTypeValue;
- protected String m_batteryTemperatureValue;
- protected String m_batteryVoltageValue;
- protected Integer m_statesValue;
-
- public HistoryItem(Long time, Byte cmd, Byte batteryLevel, Byte batteryStatusValue,
- Byte batteryHealthValue, Byte batteryPlugTypeValue,
- String batteryTemperatureValue, String batteryVoltageValue,
- Integer statesValue)
- {
- m_time = time;
- m_offset = Long.valueOf(0);
- m_cmd = cmd;
- m_batteryLevel = batteryLevel;
- m_batteryStatusValue = batteryStatusValue;
- m_batteryHealthValue = batteryHealthValue;
- m_batteryPlugTypeValue = batteryPlugTypeValue;
- m_batteryTemperatureValue = batteryTemperatureValue;
- m_batteryVoltageValue = batteryVoltageValue;
- m_statesValue = statesValue;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString()
- {
- String strTime = DateUtils.format("HH:mm:ss", m_time);
-
- return "HistoryItem [m_time=" + strTime + ", m_cmd=" + m_cmd
- + ", m_batteryLevel=" + m_batteryLevel
- + ", m_batteryStatusValue=" + m_batteryStatusValue
- + ", m_batteryHealthValue=" + m_batteryHealthValue
- + ", m_batteryPlugTypeValue=" + m_batteryPlugTypeValue
- + ", m_statesValue=" + m_statesValue + "]";
- }
-
- /**
- * @return the m_cmd
- */
- public Byte getCmd()
- {
- return m_cmd;
- }
-
- /**
- * Returns the raw time of the HistoryItem as tring
- * @return the RAW time as sting
- */
- public String getTime()
- {
- return DateUtils.format("HH:mm:ss", m_time);
-
- }
-
- /**
- * returns the "real" time of the HistoryItem by applying the offset
- * calculated as the difference of the most recent
- * sample from the stats and the current time at the point of reading
- * the stats. This norms the last sample to the time the data is queried
- * @return the normalized time
- */
- public String getNormalizedTime()
- {
- return DateUtils.format("dd.MM.yyyy HH:mm:ss S", m_time + m_offset);
-
- }
-
- public Long getNormalizedTimeLong()
- {
- return m_time + m_offset;
-
- }
- /**
- * @return the m_batteryLevel
- */
- public String getBatteryLevel()
- {
- return String.valueOf(m_batteryLevel);
- }
-
- /**
- * @return the m_batteryLevel
- */
- public int getBatteryLevelInt()
- {
- return m_batteryLevel;
- }
-
- /**
- * @return the m_statesValue
- */
- public Integer getStatesValue()
- {
- return m_statesValue;
- }
-
-
- /**
- * @return the m_bCharging as "0" or "1"
- */
- public String getCharging()
- {
- return getBooleanAsString(isCharging());
- }
-
- /**
- * @return the m_bCharging as "0" or "1"
- */
- public int getChargingInt()
- {
- return getBooleanAsInt(isCharging());
- }
-
- /**
- * @return the m_bScreenOn as "0" or "1"
- */
- public String getScreenOn()
- {
-
- return getBooleanAsString(isScreenOn());
- }
-
- /**
- * @return the m_bScreenOn as "0" or "1"
- */
- public int getScreenOnInt()
- {
-
- return getBooleanAsInt(isScreenOn());
- }
-
-
- /**
- * @return the m_bWakelock as "0" or "1"
- */
- public String getWakelock()
- {
- return getBooleanAsString(isWakeLock());
- }
-
- /**
- * @return the m_bWakelock as "0" or "1"
- */
- public int getWakelockInt()
- {
- return getBooleanAsInt(isWakeLock());
- }
-
- /**
- * @return the m_bWifiRunning as "0" or "1"
- */
- public String getWifiRunning()
- {
- return getBooleanAsString(isWifiRunning());
- }
-
- /**
- * @return the m_bWifiRunning as "0" or "1"
- */
- public int getWifiRunningInt()
- {
- return getBooleanAsInt(isWifiRunning());
- }
-
- /**
- * @return the m_bGpsOn as "0" or "1"
- */
- public String getGpsOn()
- {
-
- return getBooleanAsString(isGpsOn());
- }
-
- /**
- * @return the m_bGpsOn as "0" or "1"
- */
- public int getGpsOnInt()
- {
-
- return getBooleanAsInt(isGpsOn());
- }
-
- /**
- * @return the m_bPhoneInCall as "0" or "1"
- */
- public String getPhoneInCall()
- {
-
- return getBooleanAsString(isPhoneInCall());
- }
-
- /**
- * @return the m_bPhoneScanning as "0" or "1"
- */
- public String getPhoneScanning()
- {
- return getBooleanAsString(isPhoneScanning());
- }
-
- /**
- * @return the m_bBluetoothOn as "0" or "1"
- */
- public String getBluetoothOn()
- {
- return getBooleanAsString(isBluetoothOn());
- }
-
- /**
- * @return the m_bBluetoothInt as integer
- */
- public int getBluetoothOnInt()
- {
-
- return getBooleanAsInt(isBluetoothOn());
- }
-
-
- /**
- * @return the m_bCharging as "0" or "1"
- */
- protected String getBooleanAsString(boolean bVal)
- {
- if (bVal)
- {
- return "1";
- }
- else
- {
- return "0";
- }
- }
-
- /**
- * @return the boolean as 0 or 1
- */
- protected int getBooleanAsInt(boolean bVal)
- {
- if (bVal)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
-
- /**
- * @return true is phone is charging
- */
- public boolean isCharging()
- {
- boolean bCharging = (m_statesValue & STATE_BATTERY_PLUGGED_FLAG) != 0;
-
- return bCharging;
- }
-
- /**
- * @return true if screen is on
- */
- public boolean isScreenOn()
- {
- boolean bScreenOn = (m_statesValue & STATE_SCREEN_ON_FLAG) != 0;
- return bScreenOn;
- }
-
- /**
- * @return true is GPS is on
- */
- public boolean isGpsOn()
- {
- boolean bGpsOn = (m_statesValue & STATE_GPS_ON_FLAG) != 0;
- return bGpsOn;
- }
-
- /**
- * @return true is wifi is running
- */
- public boolean isWifiRunning()
- {
- boolean bWifiRunning = (m_statesValue & STATE_WIFI_RUNNING_FLAG) != 0;
- return bWifiRunning;
- }
-
- /**
- * @return true is a wakelock is present
- */
- public boolean isWakeLock()
- {
- boolean bWakeLock = (m_statesValue & STATE_WAKE_LOCK_FLAG) != 0;
- return bWakeLock;
- }
-
- /**
- * @return true if Phone is in Call
- */
- public boolean isPhoneInCall()
- {
-
- boolean bPhoneInCall = (m_statesValue & STATE_PHONE_IN_CALL_FLAG) != 0;
-
- return bPhoneInCall;
- }
-
- /**
- * @return true if Phone is Scanning
- */
- public boolean isPhoneScanning()
- {
- boolean bPhoneScanning = (m_statesValue & STATE_PHONE_SCANNING_FLAG) != 0;
-
- return bPhoneScanning;
- }
-
- /**
- * @return the true if bluetooth is on
- */
- public boolean isBluetoothOn()
- {
- boolean bBluetoothOn = (m_statesValue & STATE_BLUETOOTH_ON_FLAG) != 0;
-
- return bBluetoothOn;
- }
-
-
- public void setOffset(Long offset)
- {
- m_offset = offset;
- }
-
- /* (non-Javadoc)
- * @see android.os.Parcelable#describeContents()
- */
- @Override
- public int describeContents()
- {
- // TODO Auto-generated method stub
- return 0;
- }
-
- /* (non-Javadoc)
- * @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
- */
- @Override
- public void writeToParcel(Parcel dest, int flags)
- {
- // TODO Auto-generated method stub
- dest.writeLong(m_time);
- dest.writeLong(m_offset);
- dest.writeByte(m_cmd);
- dest.writeByte(m_batteryLevel);
- dest.writeByte(m_batteryStatusValue);
- dest.writeByte(m_batteryHealthValue);
- dest.writeByte(m_batteryPlugTypeValue);
- dest.writeString(m_batteryTemperatureValue);
- dest.writeString(m_batteryVoltageValue);
- dest.writeInt(m_statesValue);
- }
-
- public static final class BitDescription
- {
- public final int mask;
- public final int shift;
- public final String name;
- public final String[] values;
-
- public BitDescription(int mask, String name)
- {
- this.mask = mask;
- this.shift = -1;
- this.name = name;
- this.values = null;
- }
-
- public BitDescription(int mask, int shift, String name, String[] values)
- {
- this.mask = mask;
- this.shift = shift;
- this.name = name;
- this.values = values;
- }
- }
-
- static final String[] SCREEN_BRIGHTNESS_NAMES = {"dark", "dim", "medium", "light", "bright"};
-
- public static final String[] SIGNAL_STRENGTH_NAMES = {"none", "poor", "moderate", "good", "great"};
-
- static final String[] DATA_CONNECTION_NAMES = {
- "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
- "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
- "ehrpd", "hspap", "other"};
-
-
-
- String printBitDescriptions(int oldval, int newval)
- {
- String ret = "";
-
-
- return ret;
- }
-}
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/HistoryItemIcs.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/HistoryItemIcs.java
deleted file mode 100644
index cca444a..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/HistoryItemIcs.java
+++ /dev/null
@@ -1,164 +0,0 @@
-package com.asksven.android.common.privateapiproxies;
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-import android.os.Parcelable;
-
-import java.io.Serializable;
-
-/**
- * ICS specific Value holder for BatteryStats$HistoryItem
- * @author sven
- *
- */
-public class HistoryItemIcs extends HistoryItem implements Serializable, Parcelable
-{
- static final long serialVersionUID = 1L;
- public static final byte CMD_NULL = 0;
- public static final byte CMD_UPDATE = 1;
- public static final byte CMD_START = 2;
- public static final byte CMD_OVERFLOW = 3;
-
- public byte cmd = CMD_NULL;
- // Constants from SCREEN_BRIGHTNESS_*
- public static final int STATE_BRIGHTNESS_MASK = 0x0000000f;
- public static final int STATE_BRIGHTNESS_SHIFT = 0;
- // Constants from SIGNAL_STRENGTH_*
- public static final int STATE_SIGNAL_STRENGTH_MASK = 0x000000f0;
- public static final int STATE_SIGNAL_STRENGTH_SHIFT = 4;
- // Constants from ServiceState.STATE_*
- public static final int STATE_PHONE_STATE_MASK = 0x00000f00;
- public static final int STATE_PHONE_STATE_SHIFT = 8;
- // Constants from DATA_CONNECTION_*
- public static final int STATE_DATA_CONNECTION_MASK = 0x0000f000;
- public static final int STATE_DATA_CONNECTION_SHIFT = 12;
-
- // These states always appear directly in the first int token
- // of a delta change; they should be ones that change relatively
- // frequently.
- public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
- public static final int STATE_SENSOR_ON_FLAG = 1<<29;
- public static final int STATE_GPS_ON_FLAG = 1<<28;
- public static final int STATE_PHONE_SCANNING_FLAG = 1<<27;
- public static final int STATE_WIFI_RUNNING_FLAG = 1<<26;
- public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<25;
- public static final int STATE_WIFI_SCAN_LOCK_FLAG = 1<<24;
- public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<23;
- // These are on the lower bits used for the command; if they change
- // we need to write another int of data.
- public static final int STATE_AUDIO_ON_FLAG = 1<<22;
- public static final int STATE_VIDEO_ON_FLAG = 1<<21;
- public static final int STATE_SCREEN_ON_FLAG = 1<<20;
- public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19;
- public static final int STATE_PHONE_IN_CALL_FLAG = 1<<18;
- public static final int STATE_WIFI_ON_FLAG = 1<<17;
- public static final int STATE_BLUETOOTH_ON_FLAG = 1<<16;
-
- public static final int MOST_INTERESTING_STATES =
- STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG
- | STATE_GPS_ON_FLAG | STATE_PHONE_IN_CALL_FLAG;
-
- public HistoryItemIcs(Long time, Byte cmd, Byte batteryLevel, Byte batteryStatusValue,
- Byte batteryHealthValue, Byte batteryPlugTypeValue,
- String batteryTemperatureValue, String batteryVoltageValue,
- Integer statesValue)
- {
- super(time, cmd, batteryLevel, batteryStatusValue,
- batteryHealthValue, batteryPlugTypeValue,
- batteryTemperatureValue, batteryVoltageValue,
- statesValue);
- }
-
-
-
- /**
- * @return true is phone is charging
- */
- public boolean isCharging()
- {
- boolean bCharging = (m_statesValue & STATE_BATTERY_PLUGGED_FLAG) != 0;
-
- return bCharging;
- }
-
- /**
- * @return true if screen is on
- */
- public boolean isScreenOn()
- {
- boolean bScreenOn = (m_statesValue & STATE_SCREEN_ON_FLAG) != 0;
- return bScreenOn;
- }
-
- /**
- * @return true is GPS is on
- */
- public boolean isGpsOn()
- {
- boolean bGpsOn = (m_statesValue & STATE_GPS_ON_FLAG) != 0;
- return bGpsOn;
- }
-
- /**
- * @return true is wifi is running
- */
- public boolean isWifiRunning()
- {
- boolean bWifiRunning = (m_statesValue & STATE_WIFI_RUNNING_FLAG) != 0;
- return bWifiRunning;
- }
-
- /**
- * @return true is a wakelock is present
- */
- public boolean isWakeLock()
- {
- boolean bWakeLock = (m_statesValue & STATE_WAKE_LOCK_FLAG) != 0;
- return bWakeLock;
- }
-
- /**
- * @return true if Phone is in Call
- */
- public boolean isPhoneInCall()
- {
-
- boolean bPhoneInCall = (m_statesValue & STATE_PHONE_IN_CALL_FLAG) != 0;
-
- return bPhoneInCall;
- }
-
- /**
- * @return true if Phone is Scanning
- */
- public boolean isPhoneScanning()
- {
- boolean bPhoneScanning = (m_statesValue & STATE_PHONE_SCANNING_FLAG) != 0;
-
- return bPhoneScanning;
- }
-
- /**
- * @return the true if bluetooth is on
- */
- public boolean isBluetoothOn()
- {
- boolean bBluetoothOn = (m_statesValue & STATE_BLUETOOTH_ON_FLAG) != 0;
-
- return bBluetoothOn;
- }
-}
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/HistoryItemJellyBean.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/HistoryItemJellyBean.java
deleted file mode 100644
index ec9ded2..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/HistoryItemJellyBean.java
+++ /dev/null
@@ -1,176 +0,0 @@
-package com.asksven.android.common.privateapiproxies;
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-import android.os.Parcelable;
-
-import java.io.Serializable;
-
-/**
- * ICS specific Value holder for BatteryStats$HistoryItem
- * @author sven
- *
- */
-public class HistoryItemJellyBean extends HistoryItem implements Serializable, Parcelable
-{
-
- public static final byte CMD_NULL = 0;
- public static final byte CMD_UPDATE = 1;
- public static final byte CMD_START = 2;
- public static final byte CMD_OVERFLOW = 3;
-
- public byte cmd = CMD_NULL;
-
- public byte batteryLevel;
- public byte batteryStatus;
- public byte batteryHealth;
- public byte batteryPlugType;
-
- public short batteryTemperature;
- public char batteryVoltage;
-
- // Constants from SCREEN_BRIGHTNESS_*
- public static final int STATE_BRIGHTNESS_MASK = 0x0000000f;
- public static final int STATE_BRIGHTNESS_SHIFT = 0;
- // Constants from SIGNAL_STRENGTH_*
- public static final int STATE_SIGNAL_STRENGTH_MASK = 0x000000f0;
- public static final int STATE_SIGNAL_STRENGTH_SHIFT = 4;
- // Constants from ServiceState.STATE_*
- public static final int STATE_PHONE_STATE_MASK = 0x00000f00;
- public static final int STATE_PHONE_STATE_SHIFT = 8;
- // Constants from DATA_CONNECTION_*
- public static final int STATE_DATA_CONNECTION_MASK = 0x0000f000;
- public static final int STATE_DATA_CONNECTION_SHIFT = 12;
-
- // These states always appear directly in the first int token
- // of a delta change; they should be ones that change relatively
- // frequently.
- public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
- public static final int STATE_SENSOR_ON_FLAG = 1<<29;
- public static final int STATE_GPS_ON_FLAG = 1<<28;
- public static final int STATE_PHONE_SCANNING_FLAG = 1<<27;
- public static final int STATE_WIFI_RUNNING_FLAG = 1<<26;
- public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<25;
- public static final int STATE_WIFI_SCAN_LOCK_FLAG = 1<<24;
- public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<23;
- // These are on the lower bits used for the command; if they change
- // we need to write another int of data.
- public static final int STATE_AUDIO_ON_FLAG = 1<<22;
- public static final int STATE_VIDEO_ON_FLAG = 1<<21;
- public static final int STATE_SCREEN_ON_FLAG = 1<<20;
- public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19;
- public static final int STATE_PHONE_IN_CALL_FLAG = 1<<18;
- public static final int STATE_WIFI_ON_FLAG = 1<<17;
- public static final int STATE_BLUETOOTH_ON_FLAG = 1<<16;
-
- public static final int MOST_INTERESTING_STATES =
- STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG
- | STATE_GPS_ON_FLAG | STATE_PHONE_IN_CALL_FLAG;
-
- public HistoryItemJellyBean(Long time, Byte cmd, Byte batteryLevel, Byte batteryStatusValue,
- Byte batteryHealthValue, Byte batteryPlugTypeValue,
- String batteryTemperatureValue, String batteryVoltageValue,
- Integer statesValue)
- {
- super(time, cmd, batteryLevel, batteryStatusValue,
- batteryHealthValue, batteryPlugTypeValue,
- batteryTemperatureValue, batteryVoltageValue,
- statesValue);
- }
-
-
-
- /**
- * @return true is phone is charging
- */
- public boolean isCharging()
- {
- boolean bCharging = (m_statesValue & STATE_BATTERY_PLUGGED_FLAG) != 0;
-
- return bCharging;
- }
-
- /**
- * @return true if screen is on
- */
- public boolean isScreenOn()
- {
- boolean bScreenOn = (m_statesValue & STATE_SCREEN_ON_FLAG) != 0;
- return bScreenOn;
- }
-
- /**
- * @return true is GPS is on
- */
- public boolean isGpsOn()
- {
- boolean bGpsOn = (m_statesValue & STATE_GPS_ON_FLAG) != 0;
- return bGpsOn;
- }
-
- /**
- * @return true is wifi is running
- */
- public boolean isWifiRunning()
- {
- boolean bWifiRunning = (m_statesValue & STATE_WIFI_RUNNING_FLAG) != 0;
- return bWifiRunning;
- }
-
- /**
- * @return true is a wakelock is present
- */
- public boolean isWakeLock()
- {
- boolean bWakeLock = (m_statesValue & STATE_WAKE_LOCK_FLAG) != 0;
- return bWakeLock;
- }
-
- /**
- * @return true if Phone is in Call
- */
- public boolean isPhoneInCall()
- {
-
- boolean bPhoneInCall = (m_statesValue & STATE_PHONE_IN_CALL_FLAG) != 0;
-
- return bPhoneInCall;
- }
-
- /**
- * @return true if Phone is Scanning
- */
- public boolean isPhoneScanning()
- {
- boolean bPhoneScanning = (m_statesValue & STATE_PHONE_SCANNING_FLAG) != 0;
-
- return bPhoneScanning;
- }
-
- /**
- * @return the true if bluetooth is on
- */
- public boolean isBluetoothOn()
- {
- boolean bBluetoothOn = (m_statesValue & STATE_BLUETOOTH_ON_FLAG) != 0;
-
- return bBluetoothOn;
- }
-
-
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/HistoryItemKitKat.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/HistoryItemKitKat.java
deleted file mode 100644
index 64ba94e..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/HistoryItemKitKat.java
+++ /dev/null
@@ -1,233 +0,0 @@
-package com.asksven.android.common.privateapiproxies;
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-import android.os.Parcelable;
-
-import java.io.Serializable;
-
-/**
- * ICS specific Value holder for BatteryStats$HistoryItem
- * @author sven
- *
- */
-public class HistoryItemKitKat extends HistoryItem implements Serializable, Parcelable
-{
- static final long serialVersionUID = 1L;
- public static final byte CMD_NULL = 0;
- public static final byte CMD_UPDATE = 1;
- public static final byte CMD_START = 2;
- public static final byte CMD_OVERFLOW = 3;
-
- public byte cmd = CMD_NULL;
-
- public byte batteryLevel;
- public byte batteryStatus;
- public byte batteryHealth;
- public byte batteryPlugType;
-
- public char batteryTemperature;
- public char batteryVoltage;
-
- // Constants from SCREEN_BRIGHTNESS_*
- public static final int STATE_BRIGHTNESS_MASK = 0x0000000f;
- public static final int STATE_BRIGHTNESS_SHIFT = 0;
- // Constants from SIGNAL_STRENGTH_*
- public static final int STATE_SIGNAL_STRENGTH_MASK = 0x000000f0;
- public static final int STATE_SIGNAL_STRENGTH_SHIFT = 4;
- // Constants from ServiceState.STATE_*
- public static final int STATE_PHONE_STATE_MASK = 0x00000f00;
- public static final int STATE_PHONE_STATE_SHIFT = 8;
- // Constants from DATA_CONNECTION_*
- public static final int STATE_DATA_CONNECTION_MASK = 0x0000f000;
- public static final int STATE_DATA_CONNECTION_SHIFT = 12;
-
- // These states always appear directly in the first int token
- // of a delta change; they should be ones that change relatively
- // frequently.
- public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
- public static final int STATE_SENSOR_ON_FLAG = 1<<29;
- public static final int STATE_GPS_ON_FLAG = 1<<28;
- public static final int STATE_PHONE_SCANNING_FLAG = 1<<27;
- public static final int STATE_WIFI_RUNNING_FLAG = 1<<26;
- public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<25;
- public static final int STATE_WIFI_SCAN_FLAG = 1<<24;
- public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<23;
- // These are on the lower bits used for the command; if they change
- // we need to write another int of data.
- public static final int STATE_AUDIO_ON_FLAG = 1<<22;
- public static final int STATE_VIDEO_ON_FLAG = 1<<21;
- public static final int STATE_SCREEN_ON_FLAG = 1<<20;
- public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19;
- public static final int STATE_PHONE_IN_CALL_FLAG = 1<<18;
- public static final int STATE_WIFI_ON_FLAG = 1<<17;
- public static final int STATE_BLUETOOTH_ON_FLAG = 1<<16;
-
- public static final int MOST_INTERESTING_STATES =
- STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG
- | STATE_GPS_ON_FLAG | STATE_PHONE_IN_CALL_FLAG;
-
-
- public HistoryItemKitKat(Long time, Byte cmd, Byte batteryLevel, Byte batteryStatusValue,
- Byte batteryHealthValue, Byte batteryPlugTypeValue,
- String batteryTemperatureValue, String batteryVoltageValue,
- Integer statesValue)
- {
- super(time, cmd, batteryLevel, batteryStatusValue,
- batteryHealthValue, batteryPlugTypeValue,
- batteryTemperatureValue, batteryVoltageValue,
- statesValue);
- }
-
-
-
- /**
- * @return true is phone is charging
- */
- public boolean isCharging()
- {
- boolean bCharging = (m_statesValue & STATE_BATTERY_PLUGGED_FLAG) != 0;
-
- return bCharging;
- }
-
- /**
- * @return true if screen is on
- */
- public boolean isScreenOn()
- {
- boolean bScreenOn = (m_statesValue & STATE_SCREEN_ON_FLAG) != 0;
- return bScreenOn;
- }
-
- /**
- * @return true is GPS is on
- */
- public boolean isGpsOn()
- {
- boolean bGpsOn = (m_statesValue & STATE_GPS_ON_FLAG) != 0;
- return bGpsOn;
- }
-
- /**
- * @return true is wifi is running
- */
- public boolean isWifiRunning()
- {
- boolean bWifiRunning = (m_statesValue & STATE_WIFI_RUNNING_FLAG) != 0;
- return bWifiRunning;
- }
-
- /**
- * @return true is a wakelock is present
- */
- public boolean isWakeLock()
- {
- boolean bWakeLock = (m_statesValue & STATE_WAKE_LOCK_FLAG) != 0;
- return bWakeLock;
- }
-
- /**
- * @return true if Phone is in Call
- */
- public boolean isPhoneInCall()
- {
-
- boolean bPhoneInCall = (m_statesValue & STATE_PHONE_IN_CALL_FLAG) != 0;
-
- return bPhoneInCall;
- }
-
- /**
- * @return true if Phone is Scanning
- */
- public boolean isPhoneScanning()
- {
- boolean bPhoneScanning = (m_statesValue & STATE_PHONE_SCANNING_FLAG) != 0;
-
- return bPhoneScanning;
- }
-
- /**
- * @return the true if bluetooth is on
- */
- public boolean isBluetoothOn()
- {
- boolean bBluetoothOn = (m_statesValue & STATE_BLUETOOTH_ON_FLAG) != 0;
-
- return bBluetoothOn;
- }
-
-
- public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[]
- {
- new BitDescription(STATE_BATTERY_PLUGGED_FLAG, "plugged"),
- new BitDescription(STATE_SCREEN_ON_FLAG, "screen"),
- new BitDescription(STATE_GPS_ON_FLAG, "gps"),
- new BitDescription(STATE_PHONE_IN_CALL_FLAG, "phone_in_call"),
- new BitDescription(STATE_PHONE_SCANNING_FLAG, "phone_scanning"),
- new BitDescription(STATE_WIFI_ON_FLAG, "wifi"),
- new BitDescription(STATE_WIFI_RUNNING_FLAG, "wifi_running"),
- new BitDescription(STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock"),
- new BitDescription(STATE_WIFI_SCAN_FLAG, "wifi_scan"),
- new BitDescription(STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast"),
- new BitDescription(STATE_BLUETOOTH_ON_FLAG, "bluetooth"),
- new BitDescription(STATE_AUDIO_ON_FLAG, "audio"),
- new BitDescription(STATE_VIDEO_ON_FLAG, "video"),
- new BitDescription(STATE_WAKE_LOCK_FLAG, "wake_lock"),
- new BitDescription(STATE_SENSOR_ON_FLAG, "sensor"),
- new BitDescription(STATE_BRIGHTNESS_MASK, HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", SCREEN_BRIGHTNESS_NAMES),
- new BitDescription(STATE_SIGNAL_STRENGTH_MASK, HistoryItem.STATE_SIGNAL_STRENGTH_SHIFT, "signal_strength", SIGNAL_STRENGTH_NAMES),
- new BitDescription(STATE_PHONE_STATE_MASK, HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", new String[] {"in", "out", "emergency", "off"}),
- new BitDescription(STATE_DATA_CONNECTION_MASK, STATE_DATA_CONNECTION_SHIFT, "data_conn", DATA_CONNECTION_NAMES),
- };
-
- String printBitDescriptions(int oldval, int newval)
- {
- String ret = "";
- int diff = oldval ^ newval;
- if (diff == 0) return ret;
- for (int i=0; i < HISTORY_STATE_DESCRIPTIONS.length; i++)
- {
- BitDescription bd = HISTORY_STATE_DESCRIPTIONS[i];
- if ((diff&bd.mask) != 0)
- {
- if (bd.shift < 0)
- {
- ret += (newval&bd.mask) != 0 ? " +" : " -";
- ret += bd.name;
- }
- else
- {
- ret += " " + bd.name + "=";
- int val = (newval&bd.mask)>>bd.shift;
- if (bd.values != null && val >= 0 && val < bd.values.length)
- {
- ret += bd.values[val];
- }
- else
- {
- ret += val;
- }
- }
- }
- }
-
- return ret;
- }
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/HistoryItemLolipop.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/HistoryItemLolipop.java
deleted file mode 100644
index a21b2f4..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/HistoryItemLolipop.java
+++ /dev/null
@@ -1,176 +0,0 @@
-package com.asksven.android.common.privateapiproxies;
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-import android.os.Parcelable;
-
-import java.io.Serializable;
-
-/**
- * ICS specific Value holder for BatteryStats$HistoryItem
- * @author sven
- *
- */
-public class HistoryItemLolipop extends HistoryItem implements Serializable, Parcelable
-{
-
- public static final byte CMD_UPDATE = 0; // These can be written as deltas
- public static final byte CMD_NULL = -1;
- public static final byte CMD_START = 4;
- public static final byte CMD_CURRENT_TIME = 5;
- public static final byte CMD_OVERFLOW = 6;
- public static final byte CMD_RESET = 7;
-
- public byte cmd = CMD_NULL;
-
- public byte batteryLevel;
- public byte batteryStatus;
- public byte batteryHealth;
- public byte batteryPlugType;
-
- public short batteryTemperature;
- public char batteryVoltage;
-
- // Constants from SCREEN_BRIGHTNESS_*
- public static final int STATE_BRIGHTNESS_SHIFT = 0;
- public static final int STATE_BRIGHTNESS_MASK = 0x7;
- // Constants from SIGNAL_STRENGTH_*
- public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
- public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
- // Constants from ServiceState.STATE_*
- public static final int STATE_PHONE_STATE_SHIFT = 6;
- public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
- // Constants from DATA_CONNECTION_*
- public static final int STATE_DATA_CONNECTION_SHIFT = 9;
- public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
-
- // These states always appear directly in the first int token
- // of a delta change; they should be ones that change relatively
- // frequently.
- public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
- public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
- public static final int STATE_GPS_ON_FLAG = 1<<29;
- public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
- public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
- public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<26;
- public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
- // These are on the lower bits used for the command; if they change
- // we need to write another int of data.
- public static final int STATE_SENSOR_ON_FLAG = 1<<23;
- public static final int STATE_AUDIO_ON_FLAG = 1<<22;
- public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
- public static final int STATE_SCREEN_ON_FLAG = 1<<20;
- public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19;
- public static final int STATE_PHONE_IN_CALL_FLAG = 1<<18;
- public static final int STATE_BLUETOOTH_ON_FLAG = 1<<16;
- public static final int MOST_INTERESTING_STATES =
- STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG
- | STATE_PHONE_IN_CALL_FLAG | STATE_BLUETOOTH_ON_FLAG;
-
- public HistoryItemLolipop(Long time, Byte cmd, Byte batteryLevel, Byte batteryStatusValue,
- Byte batteryHealthValue, Byte batteryPlugTypeValue,
- String batteryTemperatureValue, String batteryVoltageValue,
- Integer statesValue)
- {
- super(time, cmd, batteryLevel, batteryStatusValue,
- batteryHealthValue, batteryPlugTypeValue,
- batteryTemperatureValue, batteryVoltageValue,
- statesValue);
- }
-
-
-
- /**
- * @return true is phone is charging
- */
- public boolean isCharging()
- {
- boolean bCharging = (m_statesValue & STATE_BATTERY_PLUGGED_FLAG) != 0;
-
- return bCharging;
- }
-
- /**
- * @return true if screen is on
- */
- public boolean isScreenOn()
- {
- boolean bScreenOn = (m_statesValue & STATE_SCREEN_ON_FLAG) != 0;
- return bScreenOn;
- }
-
- /**
- * @return true is GPS is on
- */
- public boolean isGpsOn()
- {
- boolean bGpsOn = (m_statesValue & STATE_GPS_ON_FLAG) != 0;
- return bGpsOn;
- }
-
- /**
- * @return true is wifi is running
- */
- public boolean isWifiRunning()
- {
- boolean bWifiRunning = (m_statesValue & STATE_WIFI_RUNNING_FLAG) != 0;
- return bWifiRunning;
- }
-
- /**
- * @return true is a wakelock is present
- */
- public boolean isWakeLock()
- {
- boolean bWakeLock = (m_statesValue & STATE_WAKE_LOCK_FLAG) != 0;
- return bWakeLock;
- }
-
- /**
- * @return true if Phone is in Call
- */
- public boolean isPhoneInCall()
- {
-
- boolean bPhoneInCall = (m_statesValue & STATE_PHONE_IN_CALL_FLAG) != 0;
-
- return bPhoneInCall;
- }
-
- /**
- * @return true if Phone is Scanning
- */
- public boolean isPhoneScanning()
- {
- boolean bPhoneScanning = (m_statesValue & STATE_PHONE_SCANNING_FLAG) != 0;
-
- return bPhoneScanning;
- }
-
- /**
- * @return the true if bluetooth is on
- */
- public boolean isBluetoothOn()
- {
- boolean bBluetoothOn = (m_statesValue & STATE_BLUETOOTH_ON_FLAG) != 0;
-
- return bBluetoothOn;
- }
-
-
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/KernelWakelock.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/KernelWakelock.java
deleted file mode 100644
index ea3d768..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/KernelWakelock.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.privateapiproxies;
-
-import android.util.Log;
-
-import com.google.gson.annotations.SerializedName;
-
-import java.io.Serializable;
-import java.util.Comparator;
-import java.util.List;
-
-
-/**
- * @author sven
- *
- */
-public class KernelWakelock extends StatElement implements Comparable, Serializable
-{
- /**
- * the tag for logging
- */
- private static transient final String TAG = "KernelWakelock";
-
- /**
- * the name of the wakelock holder
- */
- @SerializedName("name")
- private String m_name;
-
- /**
- * the duration in ms
- */
- @SerializedName("duration_ms")
- private long m_duration;
-
- /**
- * the count
- */
- @SerializedName("count")
- private int m_count;
-
- /**
- * Creates a wakelock instance
- * @param wakeType the type of wakelock (partial or full)
- * @param name the speaking name
- * @param duration the duration the wakelock was held
- * @param time the battery realtime
- * @param count the number of time the wakelock was active
- */
- public KernelWakelock(String name, long duration, long time, int count)
- {
- m_name = name;
- m_duration = duration;
- setTotal(time);
- m_count = count;
- }
-
- /**
- * Substracts the values from a previous object
- * found in myList from the current Process
- * in order to obtain an object containing only the data since a referenc
- * @param myList
- */
- public void substractFromRef(List myList )
- {
- if (myList != null)
- {
- for (int i = 0; i < myList.size(); i++)
- {
- try
- {
- KernelWakelock myRef = (KernelWakelock) myList.get(i);
- if ( (this.getName().equals(myRef.getName())) && (this.getuid() == myRef.getuid()) )
- {
- this.m_duration -= myRef.getDuration();
- this.setTotal( this.getTotal() - myRef.getTotal());
- this.m_count -= myRef.getCount();
-
- if ((m_count < 0) || (m_duration < 0) || (this.getTotal() < 0))
- {
- Log.e(TAG, "substractFromRef generated negative values (" + this.toString() + " - " + myRef.toString() + ")");
- }
- break;
- }
- }
- catch (ClassCastException e)
- {
- // just log as it is no error not to change the process
- // being substracted from to do nothing
- Log.e(TAG, "substractFromRef was called with a wrong list type");
- }
-
- }
- }
- }
-
-
- /**
- * @return the name
- */
- public String getName()
- {
- return m_name;
- }
-
- /**
- * @return the duration
- */
- public long getDuration()
- {
- return m_duration;
- }
-
- /**
- * @return the count
- */
- public int getCount()
- {
- return m_count;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString()
- {
- return "Kernel Wakelock [m_name=" + m_name
- + ", m_duration=" + m_duration
- + ", m_count=" + m_count+ "]";
- }
-
- /**
- * Compare a given Wakelock with this object.
- * If the duration of this object is
- * greater than the received object,
- * then this object is greater than the other.
- */
- public int compareTo(KernelWakelock o)
- {
- // we want to sort in descending order
- return ((int)(o.getDuration() - this.getDuration()));
- }
-
- /**
- * returns a string representation of the data
- */
- public String getData(long totalTime)
- {
- return this.formatDuration(getDuration())
- + " (" + getDuration()/1000 + " s)"
- + " Count:" + getCount()
- + " " + this.formatRatio(getDuration(), totalTime);
- }
-
- /**
- * returns the values of the data
- */
- public double[] getValues()
- {
- double[] retVal = new double[2];
- retVal[0] = getDuration();
- return retVal;
- }
-
- public static class CountComparator implements Comparator
- {
- public int compare(KernelWakelock a, KernelWakelock b)
- {
- return ((int)(b.getCount() - a.getCount()));
- }
- }
-
- public static class TimeComparator implements Comparator
- {
- public int compare(KernelWakelock a, KernelWakelock b)
- {
- return ((int)(b.getDuration() - a.getDuration()));
- }
- }
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/Misc.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/Misc.java
deleted file mode 100644
index ac476ba..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/Misc.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.asksven.android.common.privateapiproxies;
-
-import android.util.Log;
-
-import com.asksven.android.common.dto.MiscDto;
-import com.google.gson.annotations.SerializedName;
-
-import java.io.Serializable;
-import java.util.List;
-
-/**
- * @author sven
- *
- */
-public class Misc extends StatElement implements Comparable, Serializable
-{
-
- /**
- * the tag for logging
- */
- private static transient final String TAG = "Misc";
-
- /**
- * the name of the object
- */
- @SerializedName("name")
- private String m_name;
-
- /**
- * the time on in ms
- */
- @SerializedName("time_on_ms")
- private long m_timeOn;
-
- /**
- * the time running in ms
- */
- @SerializedName("time_runing_ms")
- private long m_timeRunning;
-
- /**
- * Constructor
- * @param name
- * @param timeOn
- * @param ratio
- */
- public Misc(String name, long timeOn, long timeRunning)
- {
-
- m_name = name;
- m_timeOn = timeOn;
- m_timeRunning = timeRunning;
- }
-
- public Misc(MiscDto source)
- {
-
- this.setUid(source.m_uid);
- this.m_name = source.m_name;
- this.m_timeOn = source.m_timeOn;
- this.m_timeRunning = source.m_timeRunning;
- this.setTotal(source.m_total);
- }
-
- public MiscDto toDto()
- {
- MiscDto ret = new MiscDto();
- ret.m_uid = this.getuid();
- ret.m_timeOn = this.m_timeOn;
- ret.m_timeRunning = this.m_timeRunning;
- ret.m_total = this.getTotal();
- ret.m_name = this.m_name;
-
- return ret;
- }
-
- public Misc clone()
- {
- Misc clone = new Misc(m_name, m_timeOn, m_timeRunning);
- clone.setTotal(this.getTotal());
- return clone;
- }
-
- /**
- * Substracts the values from a previous object
- * found in myList from the current Process
- * in order to obtain an object containing only the data since a referenc
- * @param myList
- */
- public void substractFromRef(List myList )
- {
- if (myList != null)
- {
- for (int i = 0; i < myList.size(); i++)
- {
- try
- {
- Misc myRef = (Misc) myList.get(i);
- if ( (this.getName().equals(myRef.getName())) && (this.getuid() == myRef.getuid()) )
- {
-// Log.d(TAG, "Substracting " + myRef.getName() + " " + myRef.getVals()
-// + " from " + this.getName() + " " + this.getVals());
-
- this.m_timeOn -= myRef.getTimeOn();
- this.m_timeRunning -= myRef.getTimeRunning();
- this.setTotal(this.m_timeRunning);
-
- if (this.m_timeOn > this.m_timeRunning)
- {
- Log.i(TAG, "Fixed rounding difference: " + this.m_timeOn + " -> " + this.m_timeRunning);
- this.m_timeOn = this.m_timeRunning;
- }
-
- if ((m_timeOn < 0) || (m_timeRunning < 0))
- {
- Log.e(TAG, "substractFromRef generated negative values (" + this.toString() + " - " + myRef.toString() + ")");
- }
- break;
- }
- }
- catch (ClassCastException e)
- {
- // just log as it is no error not to change the process
- // being substracted from to do nothing
- Log.e(TAG, "substractFromRef was called with a wrong list type");
- }
-
- }
- }
- }
-
- /**
- * @return the name
- */
- public String getName()
- {
- return m_name;
- }
-
- /**
- * @return the time on
- */
- public long getTimeOn()
- {
- return m_timeOn;
- }
-
- /**
- * @return the time running
- */
- public long getTimeRunning()
- {
- return m_timeRunning;
- }
-
- /**
- * Compare a given Wakelock with this object.
- * If the duration of this object is
- * greater than the received object,
- * then this object is greater than the other.
- */
- public int compareTo(Misc o)
- {
- // we want to sort in descending order
- return (int)( o.getTimeOn() - this.getTimeOn());
- }
-
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "Misc [m_name=" + m_name + ", m_timeOn=" + formatDuration(getTimeOn())
- + ", m_timeRunning=" + formatDuration(getTimeRunning()) + "]";
- }
-
- /**
- * returns a string representation of the data
- */
- public String getData(long totalTime)
- {
-
- if (totalTime < getTimeOn())
- {
- totalTime = getTimeOn();
- }
- return this.formatDuration(getTimeOn())
- + " " + formatRatio(getTimeOn(), totalTime);
- }
-
- /**
- * returns a string representation of the data
- */
- public String getVals()
- {
-
- return m_name + " " + this.formatDuration(getTimeOn()) + " (" + getTimeOn()/1000 + " s)"
- + " in " + this.formatDuration(getTimeRunning()) + " (" + getTimeRunning()/1000 + " s)"
- + " Ratio: " + formatRatio(getTimeOn(), getTimeRunning());
- }
-
- /**
- * returns the values of the data
- */
- public double[] getValues()
- {
- double[] retVal = new double[2];
- retVal[0] = getTimeOn();
- return retVal;
- }
-
- public double getMaxValue()
- {
- return getTimeOn();
- }
-
-}
-
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/NativeKernelWakelock.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/NativeKernelWakelock.java
deleted file mode 100644
index 766ac00..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/NativeKernelWakelock.java
+++ /dev/null
@@ -1,433 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.privateapiproxies;
-
-import android.util.Log;
-
-import com.asksven.android.common.dto.NativeKernelWakelockDto;
-import com.asksven.android.common.nameutils.UidNameResolver;
-import com.asksven.android.common.utils.StringUtils;
-import com.google.gson.annotations.SerializedName;
-
-import java.io.Serializable;
-import java.util.Comparator;
-import java.util.List;
-
-//import android.content.Context;
-
-/**
- * @author sven
- *
- */
-public class NativeKernelWakelock extends StatElement implements Comparable, Serializable
-{
-
- // a kernel wakelock from /proc/wakelocks is of the format
- // [name, count, expire_count, wake_count, active_since, total_time, sleep_time, max_time, last_change]
-
- /**
- * the tag for logging
- */
- private static transient final String TAG = "NativeKernelWakelock";
-
- /**
- * the name of the wakelock holder
- */
- @SerializedName("name")
- private String m_name;
-
- /**
- * the details (packages) for that wakelock (if any
- */
- @SerializedName("details")
- private String m_details;
-
- /**
- * the count
- */
- @SerializedName("count")
- private int m_count;
-
- /**
- * the expire count
- */
- @SerializedName("expire_count")
- private int m_expireCount;
-
- /**
- * the wake count
- */
- @SerializedName("wake_count")
- private int m_wakeCount;
-
- /**
- * the active_since time
- */
- @SerializedName("active_since")
- private long m_activeSince;
-
- /**
- * the total_time
- */
- @SerializedName("total_time")
- private long m_ttlTime;
-
- /**
- * the sleep time
- */
- @SerializedName("sleep_time")
- private long m_sleepTime;
-
- /**
- * the max time
- */
- @SerializedName("max_time")
- private long m_maxTime;
-
- /**
- * the last change
- */
- @SerializedName("last_change")
- private long m_lastChange;
-
- public NativeKernelWakelock()
- {
-
- }
-
- /**
- * Creates a wakelock instance
- * @param wakeType the type of wakelock (partial or full)
- * @param name the speaking name
- * @param duration the duration the wakelock was held
- * @param time the battery realtime
- * @param count the number of time the wakelock was active
- */
- public NativeKernelWakelock(String name, String details, int count, int expire_count, int wake_count, long active_since, long total_time, long sleep_time, long max_time, long last_change, long time)
- {
- // hack: remove "deleted: " from wakelock label (Siyah 1.5b6)
- if (name.startsWith("\"deleted: "))
- {
- m_name = "\"" + name.split(" ")[1];
- }
- else
- {
- m_name = name;
- }
- m_details = details;
- m_count = count;
- m_expireCount = expire_count;
- m_wakeCount = wake_count;
- m_activeSince = active_since;
- m_ttlTime = total_time;
- m_sleepTime = sleep_time;
- m_maxTime = max_time;
- m_lastChange = last_change;
- setTotal(time);
- }
-
- public NativeKernelWakelock(NativeKernelWakelockDto source)
- {
-
- this.setUid(source.m_uid);
- this.m_activeSince = source.m_activeSince;
- this.m_count = source.m_count;
- this.m_details = source.m_details;
- this.m_expireCount = source.m_expireCount;
- this.m_lastChange = source.m_lastChange;
- this.m_maxTime = source.m_maxTime;
- this.m_name = source.m_name;
- this.m_sleepTime = source.m_sleepTime;
- this.m_ttlTime = source.m_ttlTime;
- this.m_wakeCount = source.m_wakeCount;
- this.setTotal(source.m_total);
-
- }
-
- public NativeKernelWakelockDto toDto()
- {
- NativeKernelWakelockDto ret = new NativeKernelWakelockDto();
- ret.m_uid = this.getuid();
- ret.m_activeSince = this.m_activeSince;
- ret.m_count = this.m_count;
- ret.m_details = this.m_details;
- ret.m_expireCount = this.m_expireCount;
- ret.m_lastChange = this.m_lastChange;
- ret.m_maxTime = this.m_maxTime;
- ret.m_name = this.m_name;
- ret.m_sleepTime = this.m_sleepTime;
- ret.m_ttlTime = this.m_ttlTime;
- ret.m_wakeCount = this.m_wakeCount;
- ret.m_total = this.getTotal();
-
- return ret;
- }
-
- public NativeKernelWakelock clone()
- {
- NativeKernelWakelock clone = new NativeKernelWakelock(m_name, m_details, m_count, m_expireCount, m_wakeCount, m_activeSince, m_ttlTime,
- m_sleepTime, m_maxTime, m_lastChange, getTotal());
- clone.m_icon = m_icon;
- clone.m_uidInfo = m_uidInfo;
- clone.setUid(getuid());
-
- return clone;
- }
-
- /**
- * Substracts the values from a previous object
- * found in myList from the current Process
- * in order to obtain an object containing only the data since a referenc
- * @param myList
- */
- public void substractFromRef(List myList )
- {
- if (myList != null)
- {
- for (int i = 0; i < myList.size(); i++)
- {
- try
- {
- NativeKernelWakelock myRef = (NativeKernelWakelock) myList.get(i);
- if ( (this.getName().equals(myRef.getName())) && (this.getuid() == myRef.getuid()) )
- {
-// Log.i(TAG, "Substracting " + myRef.toString() + " from " + this.toString());
- this.m_count -= myRef.m_count;
- this.m_expireCount -= myRef.m_expireCount;
- this.m_wakeCount -= myRef.m_wakeCount;
- this.m_activeSince -= myRef.m_activeSince;
- this.m_ttlTime -= myRef.m_ttlTime;
- this.m_sleepTime -= myRef.m_sleepTime;
- this.m_maxTime -= myRef.m_maxTime;
- this.m_lastChange = Math.max(this.m_lastChange, myRef.m_lastChange);
- this.setTotal( this.getTotal() - myRef.getTotal() );
-
- // for kernel wakelocks we need to merge the package list (aka. fqn)
- // we don't care about double entries here, this must be handeled in getFqn
- if (!myRef.m_details.equals(""))
- {
- if (!this.m_details.equals(""))
- {
- this.m_details += ", " + myRef.m_details;
- }
- else
- {
- this.m_details = myRef.m_details;
- }
- }
-
-// Log.i(TAG, "Result: " + this.toString());
-
- if ((m_count < 0) || (m_sleepTime < 0) || (this.getTotal() < 0))
- {
- Log.e(TAG, "substractFromRef generated negative values (" + this.toString() + " - " + myRef.toString() + ")");
-// this.m_count = Math.max(0, this.m_count);
-// this.m_expireCount = Math.max(0, this.m_expireCount);
-// this.m_wakeCount = Math.max(0, this.m_wakeCount);
-// this.m_activeSince = Math.max(0, this.m_activeSince);
-// this.m_ttlTime = Math.max(0, this.m_ttlTime);
-// this.m_sleepTime = Math.max(0, this.m_sleepTime);
-// this.m_maxTime = Math.max(0, this.m_maxTime);
- }
- }
- }
- catch (ClassCastException e)
- {
- // just log as it is no error not to change the process
- // being substracted from to do nothing
- Log.e(TAG, "substractFromRef was called with a wrong list type");
- }
-
- }
- }
- }
-
-
- /**
- * @return the name
- */
- public String getName()
- {
- return m_name;
- }
-
- /**
- * @return the duration
- */
- public long getDuration()
- {
- return m_sleepTime;
- }
-
- /**
- * @return the count
- */
- public int getCount()
- {
- return m_count;
- }
-
- /**
- * the expire count
- */
- public int getExpireCount()
- {
- return m_expireCount;
- }
-
- /**
- * the wake count
- */
- public int getWakeCount()
- {
- return m_wakeCount;
- }
-
- /**
- * the active_since time
- */
- public long getActiveSince()
- {
- return m_activeSince;
- }
-
- /**
- * the total_time
- */
- public long getTtlTime()
- {
- return m_ttlTime;
- }
-
- /**
- * the sleep time
- */
- public long getSleepTime()
- {
- return m_sleepTime;
- }
-
- /**
- * the max time
- */
- public long getMaxTime()
- {
- return m_maxTime;
- }
-
- /**
- * the last change
- */
- public long getLastChange()
- {
- return m_lastChange;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString()
- {
- return getName() + " ["
- + "m_name=" + m_name + ", "
- + "m_count=" + m_count + ", "
- + "m_expire_count=" + m_expireCount + ", "
- + "m_wake_count=" + m_wakeCount + ", "
- + "m_active_since="+ m_activeSince + ", "
- + "m_total_time="+ m_ttlTime + ", "
- + "m_sleep_time=" + m_sleepTime + ", "
- + "m_max_time=" + m_maxTime + ", "
- + "m_last_change=" + m_lastChange + ", "
- + "]";
- }
-
- /**
- * Compare a given Wakelock with this object.
- * If the duration of this object is
- * greater than the received object,
- * then this object is greater than the other.
- */
- public int compareTo(NativeKernelWakelock o)
- {
- // we want to sort in descending order
- return ((int)(o.getDuration() - this.getDuration()));
- }
-
- /**
- * Returns the full qualified name (default, can be overwritten)
- * @return the full qualified name
- */
- public String getFqn(UidNameResolver resolver)
- {
- // we need to do some formating here as m_details may be of the form "a, b, a, c, b"
- if (m_details.equals(""))
- {
- return m_details;
- }
- else
- {
- // remove any left over "(" and ")"
- m_details.replace("(", "");
- m_details.replace(")", "");
-
- // merge
- String[] splitArray = m_details.split(", ");
-
- m_details = StringUtils.join(splitArray, ", ", true);
- return m_details;
- }
-
- }
-
- /**
- * returns a string representation of the data
- */
- public String getData(long totalTime)
- {
- return this.formatDuration(getDuration())
- + " Cnt:(c/wc/ec)" + getCount() + "/" + m_wakeCount + "/" + m_expireCount
- + " " + this.formatRatio(getDuration(), totalTime);
- }
-
- /**
- * returns the values of the data
- */
- public double[] getValues()
- {
- double[] retVal = new double[2];
- retVal[0] = getDuration();
- return retVal;
- }
-
- public static class CountComparator implements Comparator
- {
- public int compare(NativeKernelWakelock a, NativeKernelWakelock b)
- {
- return ((int)(b.getCount() - a.getCount()));
- }
- }
-
- public static class TimeComparator implements Comparator
- {
- public int compare(NativeKernelWakelock a, NativeKernelWakelock b)
- {
- return ((int)(b.getDuration() - a.getDuration()));
- }
- }
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/NetworkQueryProxy.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/NetworkQueryProxy.java
deleted file mode 100644
index ae5692c..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/NetworkQueryProxy.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.privateapiproxies;
-
-
-import android.content.Context;
-import android.content.Intent;
-import android.os.IBinder;
-import android.util.Log;
-import android.util.SparseArray;
-
-import com.asksven.android.common.nameutils.UidNameResolver;
-
-import java.lang.reflect.Method;
-
-
-
-/**
- * A proxy to the non-public API BatteryStats
- * http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3.3_r1/android/os/BatteryStats.java/?v=source
- * @author sven
- *
- */
-public class NetworkQueryProxy
-{
- /*
- * Instance of the BatteryStatsImpl
- */
- private Object m_Instance = null;
- @SuppressWarnings("rawtypes")
- private Class m_ClassDefinition = null;
-
- private static final String TAG = "NetworkQueryProxy";
- /*
- * The UID stats are kept here as their methods / data can not be accessed
- * outside of this class due to non-public types (Uid, Proc, etc.)
- */
- private SparseArray extends Object> m_uidStats = null;
-
- /**
- * An instance to the UidNameResolver
- */
- private UidNameResolver m_nameResolver;
-
- /**
- * Default cctor
- */
- public NetworkQueryProxy(Context context)
- {
-
- try
- {
- ClassLoader cl = context.getClassLoader();
-
-// ActivityManager am = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
-// am.restartPackage("com.android.phone");
- Class networkQueryServiceClassDefinition = cl.loadClass("com.android.phone.NetworkQueryService");
-
- // get the IBinder to the "batteryinfo" service
- @SuppressWarnings("rawtypes")
- Class serviceManagerClass = cl.loadClass("android.os.ServiceManager");
-
- // parameter types
- @SuppressWarnings("rawtypes")
- Class[] paramTypesGetService= new Class[1];
- paramTypesGetService[0]= String.class;
-
- @SuppressWarnings("unchecked")
- Method methodGetService = serviceManagerClass.getMethod("getService", paramTypesGetService);
-
- // parameters
- Object[] paramsGetService= new Object[1];
- paramsGetService[0] = "networkquery";
-
- IBinder serviceBinder = (IBinder) methodGetService.invoke(serviceManagerClass, paramsGetService);
-
- context.startService(new Intent(context, networkQueryServiceClassDefinition));
- if (serviceBinder == null)
- {
- Log.e(TAG, "no binder to networkquery found");
-
- }
- else
- {
- Log.e(TAG, "binder to networkquery acquired");
- }
-// // now we have a binder. Let's us that on IBatteryStats.Stub.asInterface
-// // to get an IBatteryStats
-// // Note the $-syntax here as Stub is a nested class
-// @SuppressWarnings("rawtypes")
-// Class iBatteryStatsStub = cl.loadClass("com.android.internal.app.IBatteryStats$Stub");
-//
-// //Parameters Types
-// @SuppressWarnings("rawtypes")
-// Class[] paramTypesAsInterface= new Class[1];
-// paramTypesAsInterface[0]= IBinder.class;
-//
-// @SuppressWarnings("unchecked")
-// Method methodAsInterface = iBatteryStatsStub.getMethod("asInterface", paramTypesAsInterface);
-//
-// // Parameters
-// Object[] paramsAsInterface= new Object[1];
-// paramsAsInterface[0] = serviceBinder;
-//
-// Object iBatteryStatsInstance = methodAsInterface.invoke(iBatteryStatsStub, paramsAsInterface);
-//
-// // and finally we call getStatistics from that IBatteryStats to obtain a Parcel
-// @SuppressWarnings("rawtypes")
-// Class iBatteryStats = cl.loadClass("com.android.internal.app.IBatteryStats");
-//
-// @SuppressWarnings("unchecked")
-// Method methodGetStatistics = iBatteryStats.getMethod("getStatistics");
-// byte[] data = (byte[]) methodGetStatistics.invoke(iBatteryStatsInstance);
-//
-// Parcel parcel = Parcel.obtain();
-// parcel.unmarshall(data, 0, data.length);
-// parcel.setDataPosition(0);
-//
-// @SuppressWarnings("rawtypes")
-// Class batteryStatsImpl = cl.loadClass("com.android.internal.os.BatteryStatsImpl");
-// Field creatorField = batteryStatsImpl.getField("CREATOR");
-//
-// // From here on we don't need reflection anymore
-// @SuppressWarnings("rawtypes")
-// Parcelable.Creator batteryStatsImpl_CREATOR = (Parcelable.Creator) creatorField.get(batteryStatsImpl);
-//
-// m_Instance = batteryStatsImpl_CREATOR.createFromParcel(parcel);
- }
- catch( Exception e )
- {
- Log.e("TAG", "An exception occured in NetworkQueryProxy(). Message: " + e.getMessage() + ", cause: " + e.getCause().getMessage());
- m_Instance = null;
- }
- }
-
-
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/NetworkUsage.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/NetworkUsage.java
deleted file mode 100644
index 40a53ac..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/NetworkUsage.java
+++ /dev/null
@@ -1,365 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.privateapiproxies;
-
-import android.graphics.drawable.Drawable;
-import android.util.Log;
-
-import com.asksven.android.common.dto.NetworkUsageDto;
-import com.asksven.android.common.nameutils.UidInfo;
-import com.asksven.android.common.nameutils.UidNameResolver;
-import com.google.gson.annotations.SerializedName;
-
-import org.codehaus.jackson.annotate.JsonIgnore;
-import org.codehaus.jackson.annotate.JsonProperty;
-
-import java.io.Serializable;
-import java.util.List;
-
-//import android.content.Context;
-//import android.graphics.drawable.Drawable;
-
-public class NetworkUsage extends StatElement implements Comparable, Serializable
-{
- /**
- * the tag for logging
- */
- private static transient final String TAG = "NetworkUsage";
-
-
- /**
- * tcpBytes received by the program
- */
- @SerializedName("bytes_received")
- @JsonProperty("bytes_received")
- private long m_bytesReceived=0;
-
- /**
- * tcpBytes sent by the program
- */
- @SerializedName("bytes_sent")
- @JsonProperty("bytes_sent")
- private long m_bytesSent=0;
-
- /**
- * the interface
- */
- @SerializedName("iface")
- @JsonProperty("iface")
- private String m_iface = "";
-
-
- public NetworkUsage()
- {
-
- }
-
- /**
- *
- * @param uid
- * @param iface
- * @param bytesReceived
- * @param bytesSent
- */
- public NetworkUsage(int uid, String iface, long bytesReceived, long bytesSent)
- {
- super.setUid(uid);
- m_iface = iface;
- m_bytesReceived = bytesReceived;
- m_bytesSent = bytesSent;
- }
-
- public NetworkUsage clone()
- {
- NetworkUsage clone = new NetworkUsage(getuid(), m_iface, m_bytesReceived, m_bytesSent);
- return clone;
- }
-
- public NetworkUsage(NetworkUsageDto source)
- {
-
- this.setUid(source.m_uid);
- this.m_bytesReceived = source.m_bytesReceived;
- this.m_bytesSent = source.m_bytesSent;
- this.m_iface = source.m_iface;
-
- }
-
- public NetworkUsageDto toDto()
- {
- NetworkUsageDto ret = new NetworkUsageDto();
- ret.m_uid = this.getuid();
- ret.m_bytesReceived = this.m_bytesReceived;
- ret.m_bytesSent = this.m_bytesSent;
- ret.m_iface = this.m_iface;
-
- return ret;
- }
-
- /**
- *
- * @param uid
- * @param bytesReceived
- * @param bytesSent
- */
- public NetworkUsage(int uid, long bytesReceived, long bytesSent)
- {
- super.setUid(uid);
- m_iface = "";
- m_bytesReceived = bytesReceived;
- m_bytesSent = bytesSent;
- }
-
- /**
- * Creates an Object by passing its name
- * @param name
- * @param uid
- * @param bytesReceived
- * @param bytesSent
- */
- public NetworkUsage(String name, int uid, long bytesReceived, long bytesSent)
- {
- m_uidInfo = new UidInfo();
- m_uidInfo.setName(name);
- m_uidInfo.setUid(uid);
- super.setUid(uid);
- m_bytesReceived = bytesReceived;
- m_bytesSent = bytesSent;
- }
- /**
- * Substracts the values from a previous object
- * found in myList from the current Process
- * in order to obtain an object containing only the data since a referenc
- * @param myList
- */
- public void substractFromRef(List myList )
- {
- if (myList != null)
- {
- for (int i = 0; i < myList.size(); i++)
- {
- try
- {
- NetworkUsage myRef = (NetworkUsage) myList.get(i);
- if ( (this.getInterface().equals(myRef.getInterface()))
- && (this.getuid() == myRef.getuid()) )
- {
- this.m_bytesReceived -= myRef.getBytesReceived();
- this.m_bytesSent -= myRef.getBytesSent();
-
- if ((m_bytesReceived < 0) || (m_bytesSent < 0))
- {
- Log.e(TAG, "substractFromRef generated negative values (" + this.toString() + " - " + myRef.toString() + ")");
- }
- break;
- }
- }
- catch (ClassCastException e)
- {
- // just log as it is no error not to change the process
- // being substracted from to do nothing
- Log.e(TAG, "substractFromRef was called with a wrong list type");
- }
- }
- }
- }
-
-
- /**
- * @return the interface
- */
- @JsonProperty("iface")
- public String getInterface()
- {
- String ret = "";
- if (m_iface.startsWith("wlan"))
- {
- ret = "Wifi";
- }
- else if (m_iface.startsWith("rmnet"))
- {
- ret = "Mobile";
- }
- else if (m_iface.startsWith("lo"))
- {
- ret = "Mobile";
- }
- else if (m_iface.startsWith("bnep"))
- {
- ret = "Bluetooth";
- }
- else
- {
- ret = m_iface;
- }
-
- return ret;
- }
-
-
- /**
- * @return the bytes received
- */
- @JsonProperty("bytes_received")
- public long getBytesReceived()
- {
- return m_bytesReceived;
- }
-
- public void addBytesReceived(long bytes)
- {
- m_bytesReceived += bytes;
- }
-
- public void addBytesSent(long bytes)
- {
- m_bytesSent += bytes;
- }
- /**
- * @return the bytes sent
- */
- @JsonProperty("bytes_sent")
- public long getBytesSent()
- {
- return m_bytesSent;
- }
-
- /**
- * @return the total bytes sent and received
- */
- @JsonIgnore
- public long getTotalBytes()
- {
- return m_bytesSent + m_bytesReceived;
- }
-
- /**
- * Compare a given NetworkUsage with this object.
- * If the duration of this object is
- * greater than the received object,
- * then this object is greater than the other.
- */
- public int compareTo(NetworkUsage o)
- {
- // we want to sort in descending order
- return ((int)((o.getBytesReceived() + o.getBytesSent()) - (this.getBytesReceived() + this.getBytesSent())));
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "NetworkUsage [m_uid=" + super.getuid() + ", m_bytesReceived="
- + m_bytesReceived + ", m_bytesSent=" + m_bytesSent + "]";
- }
-
- /**
- * Network Stats do not have a speaking name, just the UID
- */
- @JsonIgnore
- public String getName()
- {
- return String.valueOf(super.getuid() + " (" + getInterface() + ")");
- }
-
- /**
- * returns a string representation of the data
- */
- @JsonIgnore
- public String getData(long totalTime)
- {
- return formatVolume(getTotalBytes()) + " " + this.formatRatio(getTotalBytes(), getTotal());
- }
-
- /**
- * returns the values of the data
- */
- @JsonIgnore
- public double[] getValues()
- {
- double[] retVal = new double[2];
- retVal[0] = getBytesReceived() + getBytesSent();
-// retVal[1] = getBytesReceived() + getBytesSent();
- return retVal;
- }
-
- /**
- * Formats data volumes
- * @param bytes
- * @return the formated string
- */
- public static String formatVolume(double bytes)
- {
- String ret = "";
-
- double kB = Math.floor(bytes / 1024);
- double mB = Math.floor(bytes / 1024 / 1024);
- double gB = Math.floor(bytes / 1024 / 1024 / 1024);
- double tB = Math.floor(bytes / 1024 / 1024 / 1024 / 1024);
-
- if (tB > 0)
- {
- ret = tB + " TBytes";
- }
- else if ( gB > 0)
- {
- ret = gB + " GBytes";
- }
- else if ( mB > 0)
- {
- ret = mB + " MBytes";
- }
- else if ( kB > 0)
- {
- ret = kB + " KBytes";
- }
- else
- {
- ret = bytes + " Bytes";
- }
- return ret;
- }
-
- @JsonIgnore
- public String getPackageName()
- {
- if (m_uidInfo != null)
- {
- return m_uidInfo.getNamePackage();
- }
- else
- {
- return "";
- }
- }
-
- public Drawable getIcon(UidNameResolver resolver)
- {
- if (m_icon == null)
- {
- // retrieve and store the icon for that package
- String myPackage = m_uidInfo.getNamePackage();
- if (!myPackage.equals(""))
- {
- m_icon = resolver.getIcon(myPackage);
- }
- }
- return m_icon;
- }
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/Notification.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/Notification.java
deleted file mode 100644
index 0392885..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/Notification.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Copyright (C) 2014 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.asksven.android.common.privateapiproxies;
-
-import com.asksven.android.common.dto.MiscDto;
-import com.google.gson.annotations.SerializedName;
-
-import java.io.Serializable;
-
-/**
- * @author sven
- *
- */
-public class Notification extends StatElement implements Comparable, Serializable
-{
-
- /**
- * the tag for logging
- */
- private static transient final String TAG = "Notification";
-
- /**
- * the name of the object
- */
- @SerializedName("name")
- private String m_name;
-
- /**
- * the time on in ms
- */
- @SerializedName("time_on_ms")
- private long m_timeOn;
-
- /**
- * the time running in ms
- */
- @SerializedName("time_runing_ms")
- private long m_timeRunning;
-
- /**
- * Constructor
- * @param name
- * @param timeOn
- * @param ratio
- */
- public Notification(String name)
- {
-
- m_name = name;
- m_timeOn = 0;
- m_timeRunning = 0;
- }
-
- public Notification(MiscDto source)
- {
-
- this.setUid(source.m_uid);
- this.m_name = source.m_name;
- this.m_timeOn = source.m_timeOn;
- this.m_timeRunning = source.m_timeRunning;
- this.setTotal(source.m_total);
- }
-
- public MiscDto toDto()
- {
- MiscDto ret = new MiscDto();
- ret.m_uid = this.getuid();
- ret.m_timeOn = this.m_timeOn;
- ret.m_timeRunning = this.m_timeRunning;
- ret.m_total = this.getTotal();
- ret.m_name = this.m_name;
-
- return ret;
- }
-
- public Notification clone()
- {
- Notification clone = new Notification(m_name);
- clone.setTotal(0);
- return clone;
- }
-
-
- /**
- * @return the name
- */
- public String getName()
- {
- return m_name;
- }
-
- /**
- * @return the time on
- */
- public long getTimeOn()
- {
- return m_timeOn;
- }
-
- /**
- * @return the time running
- */
- public long getTimeRunning()
- {
- return m_timeRunning;
- }
-
- /**
- * Compare a given Wakelock with this object.
- * If the duration of this object is
- * greater than the received object,
- * then this object is greater than the other.
- */
- public int compareTo(Notification o)
- {
- // we want to sort in descending order
- return (int)( o.getTimeOn() - this.getTimeOn());
- }
-
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "Notification [m_name=" + m_name + "]";
- }
-
- /**
- * returns a string representation of the data
- */
- public String getData(long totalTime)
- {
-
- if (totalTime < getTimeOn())
- {
- totalTime = getTimeOn();
- }
- return this.formatDuration(getTimeOn())
- + " " + formatRatio(getTimeOn(), totalTime);
- }
-
- /**
- * returns a string representation of the data
- */
- public String getVals()
- {
-
- return m_name;
- }
-
- /**
- * returns the values of the data
- */
- public double[] getValues()
- {
- double[] retVal = new double[2];
- retVal[0] = getTimeOn();
- return retVal;
- }
-
- public double getMaxValue()
- {
- return getTimeOn();
- }
-
-}
-
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/PackageElement.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/PackageElement.java
deleted file mode 100644
index 65ece90..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/PackageElement.java
+++ /dev/null
@@ -1,335 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.asksven.android.common.privateapiproxies;
-
-import android.graphics.drawable.Drawable;
-import android.util.Log;
-
-import com.asksven.android.common.nameutils.UidNameResolver;
-import com.google.gson.annotations.SerializedName;
-
-import java.io.Serializable;
-import java.util.Comparator;
-import java.util.List;
-
-//import android.content.Context;
-
-/**
- * @author sven
- *
- */
-public class PackageElement extends StatElement implements Comparable, Serializable
-{
- /**
- * the tag for logging
- */
- private static transient final String TAG = "Package";
-
- /**
- * the package name of the wakelock holder
- */
- @SerializedName("package_name")
- private String m_packageName;
-
- /**
- * the name of the wakelock holder
- */
- @SerializedName("name")
- private String m_name;
-
- /**
- * the duration in ms
- */
- @SerializedName("duration_ms")
- private long m_duration;
-
-
-
- /**
- * the count
- */
- @SerializedName("count")
- private int m_count;
-
- /**
- * the number of wakeups
- */
- @SerializedName("wakeups")
- private long m_wakeups;
-
- /**
- * the total data transfer
- */
- @SerializedName("rxtx")
- private long m_rxtx;
-
- /**
- * Creates a package instance
- * @param name the speaking name
- * @param duration the duration the wakelock was held
- * @param time the battery realtime
- * @param count the number of time the wakelock was active
- */
- public PackageElement(String packageName, String name, int uid, long duration, long time, int count, long wakeups, long rxtx)
- {
- m_packageName = packageName;
- m_name = name;
- m_duration = duration;
- setTotal(time);
- m_count = count;
- m_wakeups = wakeups;
- m_rxtx = rxtx;
- super.setUid(uid);
- }
-
-
- public PackageElement clone()
- {
- PackageElement clone = new PackageElement(m_packageName, m_name, getuid(), m_duration, getTotal(), m_count, m_wakeups, m_rxtx);
-
- // Overwrite name to avoid multiple hashes
- clone.m_name = m_name;
-
- clone.m_icon = m_icon;
- clone.m_uidInfo = m_uidInfo;
- clone.setUid(getuid());
-
- return clone;
- }
-
- /**
- * Substracts the values from a previous object
- * found in myList from the current Process
- * in order to obtain an object containing only the data since a referenc
- * @param myList
- */
- public void substractFromRef(List myList )
- {
- if (myList != null)
- {
- for (int i = 0; i < myList.size(); i++)
- {
- try
- {
- PackageElement myRef = (PackageElement) myList.get(i);
- if ( (this.getName().equals(myRef.getName())) && (this.getuid() == myRef.getuid()) )
- {
- Log.i(TAG, "Substraction " + myRef.toString() + " from " + this.toString());
- this.m_duration -= myRef.getDuration();
- this.setTotal( getTotal() - myRef.getTotal());
- this.m_count -= myRef.getCount();
- this.m_wakeups -= myRef.m_wakeups;
- this.m_rxtx -= myRef.m_rxtx;
- Log.i(TAG, "Result: " + this.toString());
- if ((m_count < 0) || (m_duration < 0) || (getTotal() < 0))
- {
- Log.e(TAG, "substractFromRef generated negative values (" + this.toString() + " - " + myRef.toString() + ")");
- }
- break;
- }
- }
- catch (ClassCastException e)
- {
- // just log as it is no error not to change the process
- // being substracted from to do nothing
- Log.e(TAG, "substractFromRef was called with a wrong list type");
- }
-
- }
- }
- }
-
-
- public void add(StatElement element)
- {
- if (element instanceof Wakelock)
- {
- m_duration += ((Wakelock) element).getDuration();
- m_count += ((Wakelock) element).getCount();
- }
- else if (element instanceof Alarm)
- {
- m_wakeups += ((Alarm) element).getWakeups();
- }
- else if (element instanceof NetworkUsage)
- {
- m_rxtx += ((NetworkUsage) element).getTotalBytes();
- }
-
- else
- {
- Log.d(TAG, "element "+ element.toString() + " was not added.");
- }
- }
-
- /**
- * @return the name
- */
- public String getName() {
- return m_name;
- }
-
- /**
- * @return the duration
- */
- public long getDuration() {
- return m_duration;
- }
-
- /**
- * @return the number of wakeups
- */
- public long getWakeups() {
- return m_wakeups;
- }
-
- /**
- * @return the data volume
- */
- public long getDataVolume() {
- return m_rxtx;
- }
-
- /**
- * @return the count
- */
- public int getCount() {
- return m_count;
- }
-
- /**
- * Compare a given Wakelock with this object.
- * If the duration of this object is
- * greater than the received object,
- * then this object is greater than the other.
- */
- public int compareTo(PackageElement o)
- {
- // we want to sort in descending order
- return ((int)(o.getDuration() - this.getDuration()));
- }
-
- /**
- * returns a string representation of the data
- */
- public String getData(long totalTime)
- {
- return this.formatDuration(getDuration())
- + " Wakeups:" + m_wakeups
- + " Data:" + formatVolume(m_rxtx)
- + " " + this.formatRatio(getDuration(), totalTime);
- }
-
- /**
- * Formats data volumes
- * @param bytes
- * @return the formated string
- */
- public static String formatVolume(double bytes)
- {
- String ret = "";
-
- double kB = Math.floor(bytes / 1024);
- double mB = Math.floor(bytes / 1024 / 1024);
- double gB = Math.floor(bytes / 1024 / 1024 / 1024);
- double tB = Math.floor(bytes / 1024 / 1024 / 1024 / 1024);
-
- if (tB > 0)
- {
- ret = tB + " TBytes";
- }
- else if ( gB > 0)
- {
- ret = gB + " GBytes";
- }
- else if ( mB > 0)
- {
- ret = mB + " MBytes";
- }
- else if ( kB > 0)
- {
- ret = kB + " KBytes";
- }
- else
- {
- ret = bytes + " Bytes";
- }
- return ret;
- }
-
- /**
- * returns the values of the data
- */
- public double[] getValues()
- {
- double[] retVal = new double[2];
- retVal[0] = getDuration();
- return retVal;
- }
-
- public static class WakelockCountComparator implements Comparator
- {
- public int compare(PackageElement a, PackageElement b)
- {
- return ((int)(b.getCount() - a.getCount()));
- }
- }
-
- public static class WakelockTimeComparator implements Comparator
- {
- public int compare(PackageElement a, PackageElement b)
- {
- return ((int)(b.getDuration() - a.getDuration()));
- }
- }
-
- public Drawable getIcon(UidNameResolver resolver)
- {
- if (m_icon == null)
- {
- // retrieve and store the icon for that package
- String myPackage = m_packageName;
- m_icon = resolver.getIcon(m_packageName);
- }
- return m_icon;
- }
-
- public String getPackageName()
- {
- if (m_uidInfo != null)
- {
- return m_uidInfo.getNamePackage();
- }
- else
- {
- return "";
- }
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString()
- {
- return "PackageElement [m_name=" + m_name + ", m_packageName=" + m_packageName + ", m_uid=" + getuid() + ", m_duration=" + m_duration
- + ", m_count=" + m_count + ", m_rxtx=" + m_rxtx + ", m_wakeups=" + m_wakeups +"]";
- }
-
-
-
-}
diff --git a/app/src/main/java/com/asksven/android/common/privateapiproxies/Process.java b/app/src/main/java/com/asksven/android/common/privateapiproxies/Process.java
deleted file mode 100644
index d0e4973..0000000
--- a/app/src/main/java/com/asksven/android/common/privateapiproxies/Process.java
+++ /dev/null
@@ -1,277 +0,0 @@
-/*
- * Copyright (C) 2011 asksven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.asksven.android.common.privateapiproxies;
-
-import android.graphics.drawable.Drawable;
-import android.util.Log;
-
-import com.asksven.android.common.dto.ProcessDto;
-import com.asksven.android.common.nameutils.UidNameResolver;
-import com.google.gson.annotations.SerializedName;
-
-import java.io.Serializable;
-import java.util.Comparator;
-import java.util.List;
-
-//import android.content.Context;
-//import android.content.pm.PackageManager;
-
-/**
- * @author sven
- *
- */
-public class Process extends StatElement implements Comparable, Serializable
-{
- /**
- * the tag for logging
- */
- private transient static final String TAG = "Process";
-
- /**
- * the name of the process
- */
- @SerializedName("name")
- private String m_name;
-
- /**
- * the system time in ms
- */
- @SerializedName("system_time")
- private long m_systemTime;
-
- /**
- * the user time in ms
- */
- @SerializedName("user_time")
- private long m_userTime;
-
- /**
- * the number of starts
- */
- @SerializedName("starts")
- private int m_starts;
-
- /**
- * Constructor
- * @param name
- * @param userTime
- * @param systemTime
- * @param starts
- */
- public Process(String name, long userTime, long systemTime, int starts)
- {
-
- m_name = name;
- m_userTime = userTime;
- m_systemTime = systemTime;
- m_starts = starts;
- }
-
- public Process(ProcessDto source)
- {
-
- this.setUid(source.m_uid);
- this.m_name = source.m_name;
- this.m_starts = source.m_starts;
- this.m_systemTime = source.m_systemTime;
- this.m_userTime = source.m_userTime;
- this.setTotal(source.m_total);
- }
-
- public ProcessDto toDto()
- {
- ProcessDto ret = new ProcessDto();
- ret.m_uid = this.getuid();
- ret.m_name = this.m_name;
- ret.m_starts = this.m_starts;
- ret.m_systemTime = this.m_systemTime;
- ret.m_userTime = this.m_userTime;
-
- return ret;
- }
-
- public Process clone()
- {
- Process clone = new Process(m_name, m_userTime, m_systemTime, m_starts);
- clone.setUid(getuid());
- clone.setUidInfo(getUidInfo());
- return clone;
- }
-
- /**
- * Substracts the values from a previous object
- * found in myList from the current Process
- * in order to obtain an object containing only the data since a referenc
- * @param myList
- */
- public void substractFromRef(List myList )
- {
- if (myList != null)
- {
- for (int i = 0; i < myList.size(); i++)
- {
- try
- {
- Process myRef = (Process) myList.get(i);
- if ( (this.getName().equals(myRef.getName())) && (this.getuid() == myRef.getuid()) )
- {
- this.m_userTime -= myRef.getUserTime();
- this.m_systemTime -= myRef.getSystemTime();
- this.m_starts -= myRef.getStarts();
- if ((m_userTime < 0) || (m_systemTime < 0) || (m_starts < 0))
- {
- Log.e(TAG, "substractFromRef generated negative values (" + this.toString() + " - " + myRef.toString() + ")");
- }
- break;
- }
- }
- catch (ClassCastException e)
- {
- // just log as it is no error not to change the process
- // being substracted from to do nothing
- Log.e(TAG, "substractFromRef was called with a wrong list type");
- }
-
- }
- }
- }
-
- /**
- * @return the name
- */
- public String getName()
- {
- return m_name;
- }
-
- /**
- * @return the system time
- */
- public long getSystemTime()
- {
- return m_systemTime;
- }
-
- /**
- * @return the user time
- */
- public long getUserTime()
- {
- return m_userTime;
- }
-
- /**
- * @return the number of starts
- */
- public int getStarts()
- {
- return m_starts;
- }
-
- /**
- * Compare a given Wakelock with this object.
- * If the duration of this object is
- * greater than the received object,
- * then this object is greater than the other.
- */
- public int compareTo(Process o)
- {
- // we want to sort in descending order
- return ((int)( (o.getSystemTime() + o.getUserTime()) - (this.getSystemTime() + this.getUserTime())));
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString()
- {
- return "Process [m_name=" + m_name + ", m_systemTime=" + m_systemTime
- + ", m_userTime=" + m_userTime + ", m_starts=" + m_starts + "]";
- }
-
- /**
- * returns a string representation of the data
- */
- public String getData(long totalTime)
- {
- return "Uid: " + this.getuid() + " Sys: " + this.formatDuration(getSystemTime())
- + " Us: " + this.formatDuration(getUserTime())
- + " Starts: " + String.valueOf(getStarts());
- }
-
- /**
- * returns the values of the data
- */
-
- public double[] getValues()
- {
- double[] retVal = new double[2];
- retVal[0] = getUserTime();
- retVal[1] = getUserTime() + getSystemTime();
- return retVal;
- }
-
- public static class ProcessCountComparator implements Comparator