From 6240551eed8122aaafb3cb764373c056f309eae0 Mon Sep 17 00:00:00 2001 From: Pedro Veloso Date: Wed, 17 Oct 2012 11:30:59 +0100 Subject: [PATCH 1/3] proper package naming, some JavaDoc fixes and better AndroidVersion code --- .../common/CommonLogSettings.java | 12 +- .../common/contrib/Util.java | 95 +- .../common/kernelutils/AlarmsDumpsys.java | 319 +- .../android/common/kernelutils/Netstats.java | 219 +- .../common/kernelutils/RootDetection.java | 64 +- .../android/common/kernelutils/Wakelocks.java | 357 +-- .../privateapiproxies/BatteryStatsProxy.java | 2776 ++++++++--------- .../android/system/AndroidVersion.java | 85 +- 8 files changed, 1797 insertions(+), 2130 deletions(-) rename src/com/asksven/{andoid => android}/common/CommonLogSettings.java (74%) rename src/com/asksven/{andoid => android}/common/contrib/Util.java (63%) diff --git a/src/com/asksven/andoid/common/CommonLogSettings.java b/src/com/asksven/android/common/CommonLogSettings.java similarity index 74% rename from src/com/asksven/andoid/common/CommonLogSettings.java rename to src/com/asksven/android/common/CommonLogSettings.java index 68eb113..556a2c1 100644 --- a/src/com/asksven/andoid/common/CommonLogSettings.java +++ b/src/com/asksven/android/common/CommonLogSettings.java @@ -13,16 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.asksven.andoid.common; +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; +public class CommonLogSettings { + public static final String LOGGING_TAG = "AndroidCommon"; + public static boolean DEBUG = false; + public static boolean TRACE = false; } diff --git a/src/com/asksven/andoid/common/contrib/Util.java b/src/com/asksven/android/common/contrib/Util.java similarity index 63% rename from src/com/asksven/andoid/common/contrib/Util.java rename to src/com/asksven/android/common/contrib/Util.java index da2ecbc..2d37afe 100644 --- a/src/com/asksven/andoid/common/contrib/Util.java +++ b/src/com/asksven/android/common/contrib/Util.java @@ -1,68 +1,37 @@ /******************************************************************************* * Copyright (c) 2011 Adam Shanks (ChainsDD) - * + * * 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.andoid.common.contrib; - -import java.io.BufferedOutputStream; -import java.io.BufferedReader; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.List; +package com.asksven.android.common.contrib; -import android.app.Notification; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.content.ComponentName; import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -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 android.os.Build; -import android.preference.PreferenceManager; -import android.text.format.DateFormat; import android.util.Log; -import android.util.SparseArray; + +import java.io.*; +import java.util.ArrayList; public class Util { private static final String TAG = "Util"; - - - + public static ArrayList run(String command) { return run("/system/bin/sh", command); } public static ArrayList run(String shell, String command) { - return run(shell, new String[] { + return run(shell, new String[]{ command }); } @@ -134,29 +103,29 @@ public static boolean writeStoreFile(Context context, int uid, int execUid, Stri } return true; } - + public static boolean writeDetaultStoreFile(Context context, String action) { - File storedDir = new File(context.getFilesDir().getAbsolutePath() + File.separator + "stored"); - storedDir.mkdirs(); - File defFile = new File(storedDir.getAbsolutePath() + File.separator + "default"); - try { - OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(defFile.getAbsolutePath())); - if (action.equals("allow")) { - out.write("1"); - } else if (action.equals("deny")) { - out.write("0"); - } else { - out.write("-1"); - } - out.flush(); - out.close(); - } catch (FileNotFoundException e) { - Log.w(TAG, "Default file not written", e); - return false; - } catch (IOException e) { - Log.w(TAG, "Default file not written", e); - return false; - } - return true; + File storedDir = new File(context.getFilesDir().getAbsolutePath() + File.separator + "stored"); + storedDir.mkdirs(); + File defFile = new File(storedDir.getAbsolutePath() + File.separator + "default"); + try { + OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(defFile.getAbsolutePath())); + if (action.equals("allow")) { + out.write("1"); + } else if (action.equals("deny")) { + out.write("0"); + } else { + out.write("-1"); + } + out.flush(); + out.close(); + } catch (FileNotFoundException e) { + Log.w(TAG, "Default file not written", e); + return false; + } catch (IOException e) { + Log.w(TAG, "Default file not written", e); + return false; + } + return true; } } diff --git a/src/com/asksven/android/common/kernelutils/AlarmsDumpsys.java b/src/com/asksven/android/common/kernelutils/AlarmsDumpsys.java index 94f1529..f7b7f68 100644 --- a/src/com/asksven/android/common/kernelutils/AlarmsDumpsys.java +++ b/src/com/asksven/android/common/kernelutils/AlarmsDumpsys.java @@ -1,194 +1,161 @@ /** - * + * */ package com.asksven.android.common.kernelutils; +import android.util.Log; +import com.asksven.android.common.contrib.Util; +import com.asksven.android.common.privateapiproxies.Alarm; + import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; -import android.util.Log; - -import com.asksven.andoid.common.contrib.Util; -import com.asksven.android.common.privateapiproxies.Alarm; -import com.asksven.android.common.shellutils.Exec; -import com.asksven.android.common.shellutils.ExecResult; /** * 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"; - - /** - * Returns a list of alarm value objects - * @return - * @throws Exception - */ - public static ArrayList getAlarms() - { - ArrayList myAlarms = null; - long nTotalCount = 0; - // ExecResult res = Exec.execPrint(new String[]{"/system/bin/su", "-c", "/system/bin/dumpsys alarm"}); +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"; + + /** + * Returns a list of alarm value objects + * + * @return + * @throws Exception + */ + public static ArrayList getAlarms() { + ArrayList myAlarms = null; + long nTotalCount = 0; + // ExecResult res = Exec.execPrint(new String[]{"/system/bin/su", "-c", "/system/bin/dumpsys alarm"}); // ExecResult res = Exec.execPrint(new String[]{"su", "-c", "dumpsys alarm"}); - ArrayList res = Util.run("su", "dumpsys alarm"); + ArrayList res = Util.run("su", "dumpsys alarm"); // if (res.getSuccess()) - if (res.size() != 0) + if (res.size() != 0) - { + { // String strRes = res.getResultLine(); - if (true) //strRes.contains("Permission Denial")) - { - Pattern begin = Pattern.compile("Alarm Stats"); - boolean bParsing = false; + if (true) //strRes.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 - // ' - // '