diff --git a/res/drawable-hdpi/ic_drawer.png b/res/drawable-hdpi/ic_drawer.png deleted file mode 100644 index c59f601c..00000000 Binary files a/res/drawable-hdpi/ic_drawer.png and /dev/null differ diff --git a/res/drawable-mdpi/ic_drawer.png b/res/drawable-mdpi/ic_drawer.png deleted file mode 100644 index 1ed2c56e..00000000 Binary files a/res/drawable-mdpi/ic_drawer.png and /dev/null differ diff --git a/res/drawable-xhdpi/ic_drawer.png b/res/drawable-xhdpi/ic_drawer.png deleted file mode 100644 index a5fa74de..00000000 Binary files a/res/drawable-xhdpi/ic_drawer.png and /dev/null differ diff --git a/res/layout/activity_main.xml b/res/layout/activity_main.xml index 1a9f624b..ae1dc067 100644 --- a/res/layout/activity_main.xml +++ b/res/layout/activity_main.xml @@ -33,10 +33,10 @@ Copyright (C) 2012 James Roberts diff --git a/res/layout/drawer_item.xml b/res/layout/drawer_item.xml new file mode 100644 index 00000000..37424943 --- /dev/null +++ b/res/layout/drawer_item.xml @@ -0,0 +1,28 @@ + + diff --git a/res/layout/time_in_state.xml b/res/layout/time_in_state.xml index b6cf3e78..58ea2002 100644 --- a/res/layout/time_in_state.xml +++ b/res/layout/time_in_state.xml @@ -95,7 +95,6 @@ Copyright (C) 2012 James Roberts android:id="@+id/ui_states_warning" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="#551111" android:padding="15dp" android:text="@string/no_states_file_found" android:textSize="20sp" diff --git a/res/layout/wakelocks.xml b/res/layout/wakelocks.xml index ce3cefcb..e841229c 100644 --- a/res/layout/wakelocks.xml +++ b/res/layout/wakelocks.xml @@ -135,7 +135,6 @@ Copyright (C) 2012 James Roberts android:id="@+id/ui_kernel_wakelock_warning" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="#551111" android:padding="15dp" android:text="@string/no_kernel_wakelock_file_found" android:textSize="20sp" diff --git a/res/menu/menu_drawer.xml b/res/menu/menu_drawer.xml index 75c469f8..b94641f6 100644 --- a/res/menu/menu_drawer.xml +++ b/res/menu/menu_drawer.xml @@ -2,7 +2,7 @@ false - true + false diff --git a/res/values/strings.xml b/res/values/strings.xml index d38cfd9a..2966982c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -21,24 +21,15 @@ Copyright (C) 2012 James Roberts CPU Speed Battery - Memory Settings + Memory + Voltage Control + "Advanced" Time In State - Voltage Settings General Info Disk Info Tools Wakelocks - - CPU SPEED - BATTERY - MEMORY SETTINGS - VOLTAGE SETTINGS - "ADVANCED SETTINGS" - "TIME IN STATE" - GENERAL INFO - DISK INFO - TOOLS - WAKELOCKS + Tabs Refresh diff --git a/src/com/brewcrewfoo/performance/activities/FileChooser.java b/src/com/brewcrewfoo/performance/activities/FileChooser.java index 82300a39..14781b66 100644 --- a/src/com/brewcrewfoo/performance/activities/FileChooser.java +++ b/src/com/brewcrewfoo/performance/activities/FileChooser.java @@ -25,14 +25,8 @@ import android.widget.Button; import android.widget.ListView; import android.widget.Toast; - import com.brewcrewfoo.performance.R; -import com.brewcrewfoo.performance.util.ActivityThemeChangeInterface; -import com.brewcrewfoo.performance.util.Constants; -import com.brewcrewfoo.performance.util.FileArrayAdapter; -import com.brewcrewfoo.performance.util.Helpers; -import com.brewcrewfoo.performance.util.Item; -import com.brewcrewfoo.performance.util.UnzipUtility; +import com.brewcrewfoo.performance.util.*; import java.io.File; import java.sql.Date; @@ -41,7 +35,10 @@ import java.util.Collections; import java.util.List; -public class FileChooser extends ListActivity implements Constants, ActivityThemeChangeInterface { +import static com.brewcrewfoo.performance.util.Constants.PREF_USE_LIGHT_THEME; +import static com.brewcrewfoo.performance.util.Constants.TAG; + +public class FileChooser extends ListActivity implements ActivityThemeChangeInterface { final Context context = this; private File currentDir; SharedPreferences mPreferences; diff --git a/src/com/brewcrewfoo/performance/activities/FlasherActivity.java b/src/com/brewcrewfoo/performance/activities/FlasherActivity.java index 4bebd0f2..30042772 100644 --- a/src/com/brewcrewfoo/performance/activities/FlasherActivity.java +++ b/src/com/brewcrewfoo/performance/activities/FlasherActivity.java @@ -18,25 +18,24 @@ import android.view.View; import android.widget.Button; import android.widget.TextView; - import com.brewcrewfoo.performance.R; import com.brewcrewfoo.performance.util.ActivityThemeChangeInterface; -import com.brewcrewfoo.performance.util.Constants; - import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; +import static com.brewcrewfoo.performance.util.Constants.PREF_USE_LIGHT_THEME; +import static com.brewcrewfoo.performance.util.Constants.TAG; -public class FlasherActivity extends Activity implements Constants, ActivityThemeChangeInterface { +public class FlasherActivity extends Activity implements ActivityThemeChangeInterface { TextView flasherInfo; TextView deviceName; TextView deviceModel; diff --git a/src/com/brewcrewfoo/performance/activities/FreezerActivity.java b/src/com/brewcrewfoo/performance/activities/FreezerActivity.java index 91cf83e6..960c02c6 100644 --- a/src/com/brewcrewfoo/performance/activities/FreezerActivity.java +++ b/src/com/brewcrewfoo/performance/activities/FreezerActivity.java @@ -24,15 +24,15 @@ import android.widget.Button; import android.widget.LinearLayout; import android.widget.ListView; - import com.brewcrewfoo.performance.R; import com.brewcrewfoo.performance.util.ActivityThemeChangeInterface; import com.brewcrewfoo.performance.util.CMDProcessor; -import com.brewcrewfoo.performance.util.Constants; import com.brewcrewfoo.performance.util.PackAdapter; +import static com.brewcrewfoo.performance.util.Constants.PREF_USE_LIGHT_THEME; + -public class FreezerActivity extends Activity implements Constants, AdapterView.OnItemClickListener, ActivityThemeChangeInterface { +public class FreezerActivity extends Activity implements AdapterView.OnItemClickListener, ActivityThemeChangeInterface { final Context context = this; private boolean mIsLightTheme; diff --git a/src/com/brewcrewfoo/performance/activities/GovSetActivity.java b/src/com/brewcrewfoo/performance/activities/GovSetActivity.java index 2c9f09e9..82e97dc4 100644 --- a/src/com/brewcrewfoo/performance/activities/GovSetActivity.java +++ b/src/com/brewcrewfoo/performance/activities/GovSetActivity.java @@ -12,31 +12,20 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; -import android.widget.AdapterView; -import android.widget.Button; -import android.widget.CompoundButton; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.ListView; -import android.widget.RelativeLayout; -import android.widget.Switch; -import android.widget.TextView; - +import android.widget.*; import com.brewcrewfoo.performance.R; -import com.brewcrewfoo.performance.util.ActivityThemeChangeInterface; -import com.brewcrewfoo.performance.util.CMDProcessor; -import com.brewcrewfoo.performance.util.Constants; -import com.brewcrewfoo.performance.util.Helpers; -import com.brewcrewfoo.performance.util.Prop; -import com.brewcrewfoo.performance.util.PropAdapter; +import com.brewcrewfoo.performance.util.*; import java.util.ArrayList; import java.util.List; +import static com.brewcrewfoo.performance.util.Constants.*; + /** * Created by h0rn3t on 21.09.2013. */ -public class GovSetActivity extends Activity implements Constants, AdapterView.OnItemClickListener, ActivityThemeChangeInterface { + +public class GovSetActivity extends Activity implements AdapterView.OnItemClickListener, ActivityThemeChangeInterface { private boolean mIsLightTheme; SharedPreferences mPreferences; private final Context context = this; diff --git a/src/com/brewcrewfoo/performance/activities/KSMActivity.java b/src/com/brewcrewfoo/performance/activities/KSMActivity.java index 2df1b05f..0cabfb65 100644 --- a/src/com/brewcrewfoo/performance/activities/KSMActivity.java +++ b/src/com/brewcrewfoo/performance/activities/KSMActivity.java @@ -15,19 +15,19 @@ import android.widget.RelativeLayout; import android.widget.SeekBar; import android.widget.TextView; - import com.brewcrewfoo.performance.R; import com.brewcrewfoo.performance.util.ActivityThemeChangeInterface; import com.brewcrewfoo.performance.util.CMDProcessor; -import com.brewcrewfoo.performance.util.Constants; import com.brewcrewfoo.performance.util.Helpers; import java.io.File; +import static com.brewcrewfoo.performance.util.Constants.*; + /** * Created by h0rn3t on 11.09.2013. */ -public class KSMActivity extends Activity implements Constants, SeekBar.OnSeekBarChangeListener, ActivityThemeChangeInterface { +public class KSMActivity extends Activity implements SeekBar.OnSeekBarChangeListener, ActivityThemeChangeInterface { SharedPreferences mPreferences; private boolean mIsLightTheme; final Context context = this; diff --git a/src/com/brewcrewfoo/performance/activities/MainActivity.java b/src/com/brewcrewfoo/performance/activities/MainActivity.java index 12a56deb..a5f40ac8 100644 --- a/src/com/brewcrewfoo/performance/activities/MainActivity.java +++ b/src/com/brewcrewfoo/performance/activities/MainActivity.java @@ -18,6 +18,8 @@ package com.brewcrewfoo.performance.activities; +import static com.brewcrewfoo.performance.util.Constants.*; + import android.app.ActionBar; import android.app.AlertDialog; import android.app.Fragment; @@ -56,7 +58,6 @@ import com.brewcrewfoo.performance.fragments.OOMSettings; import com.brewcrewfoo.performance.fragments.TimeInState; import com.brewcrewfoo.performance.fragments.Tools; -import com.brewcrewfoo.performance.fragments.VM; import com.brewcrewfoo.performance.fragments.VoltageControlSettings; import com.brewcrewfoo.performance.fragments.Wakelocks; import com.brewcrewfoo.performance.util.ActivityThemeChangeInterface; @@ -64,20 +65,22 @@ import com.brewcrewfoo.performance.util.Helpers; import com.brewcrewfoo.performance.widgets.CustomDrawerLayout; +import java.util.List; +import java.util.ArrayList; -public class MainActivity extends Fragment implements Constants, ActivityThemeChangeInterface { +public class MainActivity extends Fragment implements ActivityThemeChangeInterface { - //================================== + // ================================== // Static Fields - //================================== + // ================================== private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position"; private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned"; private static final String PREF_IS_TABBED = "pref_is_tabbed"; private static final String TAG = "MainActivity"; - //================================== + // ================================== // Drawer - //================================== + // ================================== private ActionBarDrawerToggle mDrawerToggle; private CustomDrawerLayout mDrawerLayout; private ListView mDrawerListView; @@ -88,83 +91,72 @@ public class MainActivity extends Fragment implements Constants, ActivityThemeCh private Fragment mCurrentFragment; private View mFragmentContainer; - //================================== + // ================================== // Fields - //================================== - private static int DRAWER_MODE = 0; + // ================================== private static boolean mVoltageExists; private SharedPreferences mPreferences; - private boolean mIsTabbed = true; + private static boolean mLowmemExists; + private String[] mTitles; - //================================== + // ================================== // Overridden Methods - //================================== + // ================================== @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mVoltageExists = Helpers.voltageFileExists(); + mLowmemExists = Helpers.lowmemExists(); - mPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); - mUserLearnedDrawer = mPreferences.getBoolean(PREF_USER_LEARNED_DRAWER, false); - - if (getResources().getBoolean(R.bool.config_allow_toggle_tabbed)) - mIsTabbed = mPreferences.getBoolean(PREF_IS_TABBED, - getResources().getBoolean(R.bool.config_use_tabbed)); - else - mIsTabbed = getResources().getBoolean(R.bool.config_use_tabbed); + mPreferences = PreferenceManager + .getDefaultSharedPreferences(getActivity()); + mUserLearnedDrawer = mPreferences.getBoolean(PREF_USER_LEARNED_DRAWER, + false); + mTitles = getTitles(); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); if (savedInstanceState != null) { - mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION); + mCurrentSelectedPosition = savedInstanceState + .getInt(STATE_SELECTED_POSITION); mFromSavedInstanceState = true; } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + Bundle savedInstanceState) { ViewGroup rootView; - if (!mIsTabbed) { - rootView = (ViewGroup) inflater.inflate(R.layout.activity_main, container, false); - - mDrawerListView = (ListView) rootView.findViewById(R.id.pc_navigation_drawer); - mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - selectItem(position); - } - }); - - mDrawerListView.setAdapter(new ArrayAdapter( - getActionBar().getThemedContext(), - android.R.layout.simple_list_item_1, - android.R.id.text1, - getTitles())); - mDrawerListView.setItemChecked(mCurrentSelectedPosition, true); + rootView = (ViewGroup) inflater.inflate(R.layout.activity_main, + container, false); - mFragmentContainer = rootView.findViewById(R.id.pc_container); - setUpNavigationDrawer( - rootView.findViewById(R.id.pc_navigation_drawer), - (CustomDrawerLayout) rootView.findViewById(R.id.pc_drawer_layout)); + mDrawerListView = (ListView) rootView + .findViewById(R.id.pc_navigation_drawer); + mDrawerListView + .setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, + int position, long id) { - } else { - rootView = (ViewGroup) inflater.inflate(R.layout.activity_main_tabbed, container, false); + // xxx + selectItem(position); + } + }); - ViewPager mViewPager = (ViewPager) rootView.findViewById(R.id.viewpager); - TitleAdapter titleAdapter = new TitleAdapter(getFragmentManager()); - mViewPager.setAdapter(titleAdapter); - mViewPager.setCurrentItem(0); + mDrawerListView.setAdapter(new ArrayAdapter(getActionBar() + .getThemedContext(), R.layout.drawer_item, android.R.id.text1, + mTitles)); + mDrawerListView.setItemChecked(mCurrentSelectedPosition, true); - PagerTabStrip mPagerTabStrip = (PagerTabStrip) rootView.findViewById(R.id.pagerTabStrip); - mPagerTabStrip.setTabIndicatorColor(getResources().getColor(R.color.pc_blue)); - mPagerTabStrip.setDrawFullUnderline(false); - } + mFragmentContainer = rootView.findViewById(R.id.pc_container); + setUpNavigationDrawer(rootView.findViewById(R.id.pc_navigation_drawer), + (CustomDrawerLayout) rootView + .findViewById(R.id.pc_drawer_layout)); if (container instanceof PreferenceFrameLayout) { ((PreferenceFrameLayout.LayoutParams) rootView.getLayoutParams()).removeBorders = true; @@ -184,22 +176,18 @@ public void onActivityCreated(Bundle savedInstanceState) { @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - if (!mIsTabbed) { - mDrawerToggle.onConfigurationChanged(newConfig); - } + mDrawerToggle.onConfigurationChanged(newConfig); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - if (!mIsTabbed) { - outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition); - } + outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition); } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - inflater.inflate((mIsTabbed ? R.menu.menu_tabbed : R.menu.menu_drawer), menu); + inflater.inflate(R.menu.menu_drawer, menu); if (!getResources().getBoolean(R.bool.config_allow_toggle_tabbed)) { menu.removeItem(R.id.pc_action_tabbed); } @@ -209,79 +197,79 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { @Override public boolean onOptionsItemSelected(MenuItem item) { - if (!mIsTabbed) { - if (mDrawerToggle.onOptionsItemSelected(item)) { - return true; - } + if (mDrawerToggle.onOptionsItemSelected(item)) { + return true; } switch (item.getItemId()) { - case android.R.id.home: - Intent homeIntent = new Intent(); - homeIntent.setClassName("com.android.settings", "com.android.settings.Settings"); - homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(homeIntent); - return true; - case R.id.pc_toggle_drawer: - if (isDrawerOpen()) - mDrawerLayout.closeDrawer(mFragmentContainerView); - else - mDrawerLayout.openDrawer(mFragmentContainerView); - return true; - case R.id.pc_action_tabbed: - mIsTabbed = !mIsTabbed; - mPreferences.edit().putBoolean(PREF_IS_TABBED, mIsTabbed).commit(); - Helpers.restartPC(getActivity()); - return true; + case android.R.id.home: + Intent homeIntent = new Intent(); + homeIntent.setClassName("com.android.settings", + "com.android.settings.Settings"); + homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(homeIntent); + return true; + case R.id.pc_toggle_drawer: + if (isDrawerOpen()) + mDrawerLayout.closeDrawer(mFragmentContainerView); + else + mDrawerLayout.openDrawer(mFragmentContainerView); + return true; } return super.onOptionsItemSelected(item); } @Override public boolean isThemeChanged() { - /*final boolean is_light_theme = mPreferences.getBoolean(PREF_USE_LIGHT_THEME, false); - return is_light_theme != mIsLightTheme;*/ + /* + * final boolean is_light_theme = + * mPreferences.getBoolean(PREF_USE_LIGHT_THEME, false); return + * is_light_theme != mIsLightTheme; + */ return false; } @Override public void setTheme() { - /*final boolean is_light_theme = mPreferences.getBoolean(PREF_USE_LIGHT_THEME, false); - mIsLightTheme = mPreferences.getBoolean(PREF_USE_LIGHT_THEME, false); - setTheme(is_light_theme ? R.style.Theme_Light : R.style.Theme_Dark);*/ + /* + * final boolean is_light_theme = + * mPreferences.getBoolean(PREF_USE_LIGHT_THEME, false); mIsLightTheme = + * mPreferences.getBoolean(PREF_USE_LIGHT_THEME, false); + * setTheme(is_light_theme ? R.style.Theme_Light : R.style.Theme_Dark); + */ } @Override public void onResume() { super.onResume(); - //if (isThemeChanged()) { - // Helpers.restartPC(this); - //} + // if (isThemeChanged()) { + // Helpers.restartPC(this); + // } } - //================================== + // ================================== // Methods - //================================== + // ================================== /** - * Users of this fragment must call this method to set up the - * navigation menu_drawer interactions. - * - * @param fragmentContainerView The view of this fragment in its activity's layout. - * @param drawerLayout The DrawerLayout containing this fragment's UI. + * Users of this fragment must call this method to set up the navigation + * menu_drawer interactions. + * + * @param fragmentContainerView + * The view of this fragment in its activity's layout. + * @param drawerLayout + * The DrawerLayout containing this fragment's UI. */ - public void setUpNavigationDrawer(View fragmentContainerView, CustomDrawerLayout drawerLayout) { + public void setUpNavigationDrawer(View fragmentContainerView, + CustomDrawerLayout drawerLayout) { mFragmentContainerView = fragmentContainerView; mDrawerLayout = drawerLayout; - mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); + mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, + GravityCompat.START); - mDrawerToggle = new ActionBarDrawerToggle( - getActivity(), - mDrawerLayout, - R.drawable.ic_drawer, - R.string.navigation_drawer_open, - R.string.navigation_drawer_close - ) { + mDrawerToggle = new ActionBarDrawerToggle(getActivity(), mDrawerLayout, + R.drawable.ic_drawer, R.string.navigation_drawer_open, + R.string.navigation_drawer_close) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); @@ -289,7 +277,8 @@ public void onDrawerClosed(View drawerView) { return; } - getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() + getActivity().invalidateOptionsMenu(); // calls + // onPrepareOptionsMenu() } @Override @@ -301,14 +290,18 @@ public void onDrawerOpened(View drawerView) { if (!mUserLearnedDrawer) { mUserLearnedDrawer = true; - mPreferences.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).commit(); + mPreferences.edit() + .putBoolean(PREF_USER_LEARNED_DRAWER, true) + .commit(); } - getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() + getActivity().invalidateOptionsMenu(); // calls + // onPrepareOptionsMenu() } }; - // Remove or set it to true, if you want to use home to toggle the menu_drawer + // Remove or set it to true, if you want to use home to toggle the + // menu_drawer mDrawerToggle.setDrawerIndicatorEnabled(false); if (!mUserLearnedDrawer && !mFromSavedInstanceState) { @@ -328,7 +321,8 @@ public void run() { } public boolean isDrawerOpen() { - return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView); + return mDrawerLayout != null + && mDrawerLayout.isDrawerOpen(mFragmentContainerView); } /** @@ -357,7 +351,10 @@ private void selectItem(int position) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); - final int itemId = getPosition(position); + final int itemId = getPosition(mTitles[position]); + if (itemId == -1) { + return; + } if (mCurrentFragment != null) { transaction.detach(mCurrentFragment); @@ -380,209 +377,113 @@ private void selectItem(int position) { private static String makeFragmentName(int viewId, long id) { return "android:switcher:" + viewId + ":" + id; } + /** - * Depending on if the item is shown or not, it increases - * the position to make the activity load the right fragment. - * - * @param pos The selected position - * @return the modified position + * Gets the position of the item + * + * @param item + * The item + * @return the item position */ - public int getPosition(int pos) { - int position = pos; - switch (DRAWER_MODE) { - default: - case 0: - position = pos; - break; - case 1: - if (pos > 0) position = pos + 1; - break; - case 2: - if (pos > 3) position = pos + 1; - break; - case 3: - if (pos > 0) position = pos + 1; - if (pos >= 3) position = pos + 2; - break; + public int getPosition(String item) { + if (item.equals(getString(R.string.tab_cpu_settings))) { + return FRAGMENT_ID_CPUSETTINGS; + } + if (item.equals(getString(R.string.tab_battery_info))) { + return FRAGMENT_ID_BATTERYINFO; + } + if (item.equals(getString(R.string.tab_adv_settings))) { + return FRAGMENT_ID_ADVANCED; + } + if (item.equals(getString(R.string.tab_time_in_state))) { + return FRAGMENT_ID_TIMEINSTATE; } - return position; + if (item.equals(getString(R.string.tab_wakelocks))) { + return FRAGMENT_ID_WAKELOCKS; + } + if (item.equals(getString(R.string.tab_cpu_info))) { + return FRAGMENT_ID_CPUINFO; + } + if (item.equals(getString(R.string.tab_disk_info))) { + return FRAGMENT_ID_DISKINFO; + } + if (item.equals(getString(R.string.tab_volt_settings))) { + return FRAGMENT_ID_VOLTAGECONTROL; + } + if (item.equals(getString(R.string.tab_oom_settings))) { + return FRAGMENT_ID_OOMSETTINGS; + } + return -1; } /** * Get a list of titles for the tabstrip to display depending on if the - * voltage control fragment and battery fragment will be displayed. (Depends on the result of - * Helpers.voltageTableExists() & Helpers.showBattery() - * + * voltage control fragment and battery fragment will be displayed. (Depends + * on the result of Helpers.voltageTableExists() & Helpers.showBattery() + * * @return String[] containing titles */ private String[] getTitles() { - String titleString[]; + List titles = new ArrayList(); + titles.add(getString(R.string.tab_cpu_settings)); + titles.add(getString(R.string.tab_battery_info)); + titles.add(getString(R.string.tab_adv_settings)); + titles.add(getString(R.string.tab_time_in_state)); + titles.add(getString(R.string.tab_wakelocks)); + titles.add(getString(R.string.tab_cpu_info)); + titles.add(getString(R.string.tab_disk_info)); if (mVoltageExists) { - if (Helpers.showBattery()) { - if (getResources().getBoolean(R.bool.config_showPerformanceOnly)) { - DRAWER_MODE = 0; - titleString = new String[]{ - getString(R.string.t_cpu_settings), - getString(R.string.t_battery_info), - getString(R.string.t_oom_settings), - getString(R.string.prefcat_vm_settings), - getString(R.string.t_volt_settings), - getString(R.string.t_adv_settings), - getString(R.string.t_time_in_state), - getString(R.string.t_wakelocks), - getString(R.string.t_cpu_info), - getString(R.string.t_disk_info)}; - } else { - DRAWER_MODE = 0; - titleString = new String[]{ - getString(R.string.t_cpu_settings), - getString(R.string.t_battery_info), - getString(R.string.t_oom_settings), - getString(R.string.prefcat_vm_settings), - getString(R.string.t_volt_settings), - getString(R.string.t_adv_settings), - getString(R.string.t_time_in_state), - getString(R.string.t_wakelocks), - getString(R.string.t_cpu_info), - getString(R.string.t_disk_info), - getString(R.string.t_tools)}; - } - } else { - if (getResources().getBoolean(R.bool.config_showPerformanceOnly)) { - DRAWER_MODE = 1; - titleString = new String[]{ - getString(R.string.t_cpu_settings), - getString(R.string.t_oom_settings), - getString(R.string.prefcat_vm_settings), - getString(R.string.t_volt_settings), - getString(R.string.t_adv_settings), - getString(R.string.t_time_in_state), - getString(R.string.t_wakelocks), - getString(R.string.t_cpu_info), - getString(R.string.t_disk_info)}; - } else { - DRAWER_MODE = 1; - titleString = new String[]{ - getString(R.string.t_cpu_settings), - getString(R.string.t_oom_settings), - getString(R.string.prefcat_vm_settings), - getString(R.string.t_volt_settings), - getString(R.string.t_adv_settings), - getString(R.string.t_time_in_state), - getString(R.string.t_wakelocks), - getString(R.string.t_cpu_info), - getString(R.string.t_disk_info), - getString(R.string.t_tools)}; - } - } - } else { - if (Helpers.showBattery()) { - if (getResources().getBoolean(R.bool.config_showPerformanceOnly)) { - DRAWER_MODE = 2; - titleString = new String[]{ - getString(R.string.t_cpu_settings), - getString(R.string.t_battery_info), - getString(R.string.t_oom_settings), - getString(R.string.prefcat_vm_settings), - getString(R.string.t_adv_settings), - getString(R.string.t_time_in_state), - getString(R.string.t_wakelocks), - getString(R.string.t_cpu_info), - getString(R.string.t_disk_info)}; - } else { - DRAWER_MODE = 2; - titleString = new String[]{ - getString(R.string.t_cpu_settings), - getString(R.string.t_battery_info), - getString(R.string.t_oom_settings), - getString(R.string.prefcat_vm_settings), - getString(R.string.t_adv_settings), - getString(R.string.t_time_in_state), - getString(R.string.t_wakelocks), - getString(R.string.t_cpu_info), - getString(R.string.t_disk_info), - getString(R.string.t_tools)}; - } - } else { - if (getResources().getBoolean(R.bool.config_showPerformanceOnly)) { - DRAWER_MODE = 3; - titleString = new String[]{ - getString(R.string.t_cpu_settings), - getString(R.string.t_oom_settings), - getString(R.string.prefcat_vm_settings), - getString(R.string.t_adv_settings), - getString(R.string.t_time_in_state), - getString(R.string.t_wakelocks), - getString(R.string.t_cpu_info), - getString(R.string.t_disk_info)}; - } else { - DRAWER_MODE = 3; - titleString = new String[]{ - getString(R.string.t_cpu_settings), - getString(R.string.t_oom_settings), - getString(R.string.prefcat_vm_settings), - getString(R.string.t_adv_settings), - getString(R.string.t_time_in_state), - getString(R.string.t_wakelocks), - getString(R.string.t_cpu_info), - getString(R.string.t_disk_info), - getString(R.string.t_tools)}; - } - } + titles.add(getString(R.string.tab_volt_settings)); } - return titleString; + if (mLowmemExists) { + titles.add(getString(R.string.tab_oom_settings)); + } + return titles.toArray(new String[titles.size()]); } - //================================== + // ================================== // Internal Classes - //================================== + // ================================== /** - * Loads our Fragments. + * Loads oments. */ public static class PlaceholderFragment extends Fragment { /** - * Returns a new instance of this fragment for the given section - * number. + * Returns a new instance of this fragment for the given section number. */ public static Fragment newInstance(int fragmentId) { Fragment fragment; switch (fragmentId) { - default: - case FRAGMENT_ID_CPUSETTINGS: - fragment = new CPUSettings(); - break; - case FRAGMENT_ID_BATTERYINFO: - fragment = new BatteryInfo(); - break; - case FRAGMENT_ID_OOMSETTINGS: - fragment = new OOMSettings(); - break; - case FRAGMENT_ID_VM: - fragment = new VM(); - break; - case FRAGMENT_ID_VOLTAGECONROL: - fragment = new VoltageControlSettings(); - break; - case FRAGMENT_ID_ADVANCED: - fragment = new Advanced(); - break; - case FRAGMENT_ID_TIMEINSTATE: - fragment = new TimeInState(); - break; - case FRAGMENT_ID_CPUINFO: - fragment = new CPUInfo(); - break; - case FRAGMENT_ID_DISKINFO: - fragment = new DiskInfo(); - break; - case FRAGMENT_ID_TOOLS: - fragment = new Tools(); - break; - case FRAGMENT_ID_WAKELOCKS: - fragment = new Wakelocks(); - break; + default: + case FRAGMENT_ID_CPUSETTINGS: + fragment = new CPUSettings(); + break; + case FRAGMENT_ID_BATTERYINFO: + fragment = new BatteryInfo(); + break; + case FRAGMENT_ID_OOMSETTINGS: + fragment = new OOMSettings(); + break; + case FRAGMENT_ID_VOLTAGECONTROL: + fragment = new VoltageControlSettings(); + break; + case FRAGMENT_ID_ADVANCED: + fragment = new Advanced(); + break; + case FRAGMENT_ID_TIMEINSTATE: + fragment = new TimeInState(); + break; + case FRAGMENT_ID_CPUINFO: + fragment = new CPUInfo(); + break; + case FRAGMENT_ID_DISKINFO: + fragment = new DiskInfo(); + break; + case FRAGMENT_ID_WAKELOCKS: + fragment = new Wakelocks(); + break; } return fragment; @@ -593,93 +494,9 @@ public PlaceholderFragment() { } } - //================================== - // Adapters - //================================== - class TitleAdapter extends FragmentPagerAdapter { - String titles[] = getTitles(); - private Fragment frags[] = new Fragment[titles.length]; - - public TitleAdapter(FragmentManager fm) { - super(fm); - if (mVoltageExists) { - if (Helpers.showBattery()) { - frags[0] = new CPUSettings(); - frags[1] = new BatteryInfo(); - frags[2] = new OOMSettings(); - frags[3] = new VM(); - frags[4] = new VoltageControlSettings(); - frags[5] = new Advanced(); - frags[6] = new TimeInState(); - frags[7] = new Wakelocks(); - frags[8] = new CPUInfo(); - frags[9] = new DiskInfo(); - if (!getResources().getBoolean(R.bool.config_showPerformanceOnly)) { - frags[10] = new Tools(); - } - } else { - frags[0] = new CPUSettings(); - frags[1] = new OOMSettings(); - frags[2] = new VM(); - frags[3] = new VoltageControlSettings(); - frags[4] = new Advanced(); - frags[5] = new TimeInState(); - frags[6] = new Wakelocks(); - frags[7] = new CPUInfo(); - frags[8] = new DiskInfo(); - if (!getResources().getBoolean(R.bool.config_showPerformanceOnly)) { - frags[9] = new Tools(); - } - } - } else { - if (Helpers.showBattery()) { - frags[0] = new CPUSettings(); - frags[1] = new BatteryInfo(); - frags[2] = new OOMSettings(); - frags[3] = new VM(); - frags[4] = new Advanced(); - frags[5] = new TimeInState(); - frags[6] = new Wakelocks(); - frags[7] = new CPUInfo(); - frags[8] = new DiskInfo(); - if (!getResources().getBoolean(R.bool.config_showPerformanceOnly)) { - frags[9] = new Tools(); - } - } else { - frags[0] = new CPUSettings(); - frags[1] = new OOMSettings(); - frags[2] = new VM(); - frags[3] = new Advanced(); - frags[4] = new TimeInState(); - frags[5] = new Wakelocks(); - frags[6] = new CPUInfo(); - frags[7] = new DiskInfo(); - if (!getResources().getBoolean(R.bool.config_showPerformanceOnly)) { - frags[8] = new Tools(); - } - } - } - } - - @Override - public CharSequence getPageTitle(int position) { - return titles[position]; - } - - @Override - public Fragment getItem(int position) { - return frags[position]; - } - - @Override - public int getCount() { - return frags.length; - } - } - - //================================== + // ================================== // Dialogs - //================================== + // ================================== /** * Check if root access, and prompt the user to grant PC access @@ -690,7 +507,8 @@ private void checkForSu() { } boolean firstrun = mPreferences.getBoolean("firstrun", true); - boolean rootWasCanceled = mPreferences.getBoolean("rootcanceled", false); + boolean rootWasCanceled = mPreferences + .getBoolean("rootcanceled", false); if (firstrun || rootWasCanceled) { SharedPreferences.Editor e = mPreferences.edit(); @@ -716,9 +534,11 @@ private void launchFirstRunDialog() { .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override - public void onClick(DialogInterface dialog, int which) { + public void onClick(DialogInterface dialog, + int which) { String message = getString(R.string.su_cancel_message); - SharedPreferences.Editor e = mPreferences.edit(); + SharedPreferences.Editor e = mPreferences + .edit(); e.putBoolean("rootcanceled", true); e.commit(); suResultDialog(failedTitle, message); @@ -751,17 +571,19 @@ public void onClick(DialogInterface dialog, int which) { /** * Display the result of the check for root access so the user knows what to * expect in respect to functionality of the application. - * - * @param title Oops or OK depending on the result - * @param message Success or fail message + * + * @param title + * Oops or OK depending on the result + * @param message + * Success or fail message */ private void suResultDialog(String title, String message) { LayoutInflater factory = LayoutInflater.from(getActivity()); final View suResultDialog = factory.inflate(R.layout.su_dialog, null); TextView tv = (TextView) suResultDialog.findViewById(R.id.message); tv.setText(message); - new AlertDialog.Builder(getActivity()).setTitle(title).setView(suResultDialog) - .setCancelable(false) + new AlertDialog.Builder(getActivity()).setTitle(title) + .setView(suResultDialog).setCancelable(false) .setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -769,4 +591,3 @@ public void onClick(DialogInterface dialog, int which) { }).create().show(); } } - diff --git a/src/com/brewcrewfoo/performance/activities/PCSettings.java b/src/com/brewcrewfoo/performance/activities/PCSettings.java index 83815ddc..583ed90a 100644 --- a/src/com/brewcrewfoo/performance/activities/PCSettings.java +++ b/src/com/brewcrewfoo/performance/activities/PCSettings.java @@ -20,19 +20,16 @@ import android.content.SharedPreferences; import android.os.Bundle; -import android.preference.CheckBoxPreference; -import android.preference.Preference; +import android.preference.*; import android.preference.Preference.OnPreferenceChangeListener; -import android.preference.PreferenceActivity; -import android.preference.PreferenceManager; -import android.preference.PreferenceScreen; - import com.brewcrewfoo.performance.R; import com.brewcrewfoo.performance.util.ActivityThemeChangeInterface; -import com.brewcrewfoo.performance.util.Constants; import com.brewcrewfoo.performance.util.Helpers; -public class PCSettings extends PreferenceActivity implements Constants, ActivityThemeChangeInterface, OnPreferenceChangeListener { +import static com.brewcrewfoo.performance.util.Constants.PREF_USE_LIGHT_THEME; +import static com.brewcrewfoo.performance.util.Constants.VERSION_NUM; + +public class PCSettings extends PreferenceActivity implements ActivityThemeChangeInterface, OnPreferenceChangeListener { SharedPreferences mPreferences; private CheckBoxPreference mLightThemePref; diff --git a/src/com/brewcrewfoo/performance/activities/PackActivity.java b/src/com/brewcrewfoo/performance/activities/PackActivity.java index da23fb4d..b2f1809d 100644 --- a/src/com/brewcrewfoo/performance/activities/PackActivity.java +++ b/src/com/brewcrewfoo/performance/activities/PackActivity.java @@ -12,24 +12,20 @@ import android.os.Bundle; import android.preference.PreferenceManager; import android.view.View; -import android.widget.AdapterView; +import android.widget.*; import android.widget.AdapterView.OnItemClickListener; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.ListView; -import android.widget.TextView; - import com.brewcrewfoo.performance.R; import com.brewcrewfoo.performance.util.ActivityThemeChangeInterface; import com.brewcrewfoo.performance.util.CMDProcessor; -import com.brewcrewfoo.performance.util.Constants; import com.brewcrewfoo.performance.util.Helpers; import com.brewcrewfoo.performance.util.PackAdapter; import java.util.Arrays; +import static com.brewcrewfoo.performance.util.Constants.*; + -public class PackActivity extends Activity implements Constants, OnItemClickListener, ActivityThemeChangeInterface { +public class PackActivity extends Activity implements OnItemClickListener, ActivityThemeChangeInterface { PackageManager packageManager; diff --git a/src/com/brewcrewfoo/performance/activities/ResidualsActivity.java b/src/com/brewcrewfoo/performance/activities/ResidualsActivity.java index 9df5fb5d..e917022f 100644 --- a/src/com/brewcrewfoo/performance/activities/ResidualsActivity.java +++ b/src/com/brewcrewfoo/performance/activities/ResidualsActivity.java @@ -15,22 +15,18 @@ import android.widget.Button; import android.widget.LinearLayout; import android.widget.ListView; - import com.brewcrewfoo.performance.R; -import com.brewcrewfoo.performance.util.ActivityThemeChangeInterface; -import com.brewcrewfoo.performance.util.CMDProcessor; -import com.brewcrewfoo.performance.util.Constants; -import com.brewcrewfoo.performance.util.FileArrayAdapter; -import com.brewcrewfoo.performance.util.Helpers; -import com.brewcrewfoo.performance.util.Item; +import com.brewcrewfoo.performance.util.*; import java.util.ArrayList; import java.util.List; +import static com.brewcrewfoo.performance.util.Constants.*; + /** * Created by h0rn3t on 31.07.2013. */ -public class ResidualsActivity extends Activity implements Constants, AdapterView.OnItemClickListener, ActivityThemeChangeInterface { +public class ResidualsActivity extends Activity implements AdapterView.OnItemClickListener, ActivityThemeChangeInterface { SharedPreferences mPreferences; private boolean mIsLightTheme; private FileArrayAdapter adapter; diff --git a/src/com/brewcrewfoo/performance/activities/iResidualsActivity.java b/src/com/brewcrewfoo/performance/activities/iResidualsActivity.java index 8e729deb..8b1f970f 100644 --- a/src/com/brewcrewfoo/performance/activities/iResidualsActivity.java +++ b/src/com/brewcrewfoo/performance/activities/iResidualsActivity.java @@ -18,11 +18,9 @@ import android.widget.Button; import android.widget.LinearLayout; import android.widget.ListView; - import com.brewcrewfoo.performance.R; import com.brewcrewfoo.performance.util.ActivityThemeChangeInterface; import com.brewcrewfoo.performance.util.CMDProcessor; -import com.brewcrewfoo.performance.util.Constants; import com.brewcrewfoo.performance.util.FileArrayAdapter; import com.brewcrewfoo.performance.util.Item; @@ -30,10 +28,13 @@ import java.util.ArrayList; import java.util.List; +import static com.brewcrewfoo.performance.util.Constants.PREF_USE_LIGHT_THEME; +import static com.brewcrewfoo.performance.util.Constants.TAG; + /** * Created by h0rn3t on 31.07.2013. */ -public class iResidualsActivity extends Activity implements Constants, AdapterView.OnItemClickListener, ActivityThemeChangeInterface { +public class iResidualsActivity extends Activity implements AdapterView.OnItemClickListener, ActivityThemeChangeInterface { SharedPreferences mPreferences; private boolean mIsLightTheme; private FileArrayAdapter adapter; diff --git a/src/com/brewcrewfoo/performance/fragments/Advanced.java b/src/com/brewcrewfoo/performance/fragments/Advanced.java index 56fc697b..e8f7aec0 100644 --- a/src/com/brewcrewfoo/performance/fragments/Advanced.java +++ b/src/com/brewcrewfoo/performance/fragments/Advanced.java @@ -19,7 +19,6 @@ package com.brewcrewfoo.performance.fragments; import android.app.ActivityManager; -import android.os.SystemProperties; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; @@ -28,37 +27,27 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.res.Resources; import android.os.Bundle; -import android.preference.CheckBoxPreference; -import android.preference.ListPreference; -import android.preference.Preference; -import android.preference.PreferenceCategory; -import android.preference.PreferenceFragment; -import android.preference.PreferenceManager; -import android.preference.PreferenceScreen; +import android.os.SystemProperties; +import android.preference.*; import android.text.Editable; import android.text.TextWatcher; -import android.view.KeyEvent; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; +import android.view.*; import android.view.inputmethod.EditorInfo; import android.widget.EditText; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; - import com.brewcrewfoo.performance.R; import com.brewcrewfoo.performance.activities.PCSettings; import com.brewcrewfoo.performance.util.CMDProcessor; -import com.brewcrewfoo.performance.util.Constants; import com.brewcrewfoo.performance.util.Helpers; import java.io.File; +import static com.brewcrewfoo.performance.util.Constants.*; + public class Advanced extends PreferenceFragment - implements OnSharedPreferenceChangeListener, Constants { + implements OnSharedPreferenceChangeListener { private CheckBoxPreference mDsync; @@ -172,7 +161,7 @@ public void onCreate(Bundle savedInstanceState) { mDynamicWriteBackActive.setSummary(Helpers.readOneLine(DIRTY_WRITEBACK_ACTIVE_PATH)); mDynamicWriteBackSuspend.setSummary(Helpers.readOneLine(DIRTY_WRITEBACK_SUSPEND_PATH)); } - final String readahead = Helpers.readOneLine(READ_AHEAD_PATH); + final String readahead = Helpers.readOneLine(READ_AHEAD_PATH[0]); mReadAhead.setValue(readahead); mReadAhead.setSummary(getString(R.string.ps_read_ahead, readahead + " kb")); @@ -361,8 +350,19 @@ public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final SharedPreferences.Editor editor = sharedPreferences.edit(); if (key.equals(PREF_READ_AHEAD)) { final String values = mReadAhead.getValue(); - if (!values.equals(Helpers.readOneLine(READ_AHEAD_PATH))) { - new CMDProcessor().su.runWaitFor("busybox echo " + values + " > " + READ_AHEAD_PATH); + final StringBuilder sb = new StringBuilder(); + for (String aREAD_AHEAD_PATH : READ_AHEAD_PATH) { + if (new File(aREAD_AHEAD_PATH).exists()) { + if (Helpers.isSystemApp(getActivity())) { + Helpers.writeOneLine(aREAD_AHEAD_PATH, values); + } else { + sb.append("busybox echo ").append(values).append(" > ") + .append(aREAD_AHEAD_PATH).append(";\n"); + } + } + } + if (!Helpers.isSystemApp(getActivity())) { + Helpers.shExec(sb, context, true); } mReadAhead.setSummary(sreadahead + values + " kb"); } else if (key.equals(PREF_BLTIMEOUT)) { diff --git a/src/com/brewcrewfoo/performance/fragments/BatteryInfo.java b/src/com/brewcrewfoo/performance/fragments/BatteryInfo.java index e2c369a1..2fbef6c0 100644 --- a/src/com/brewcrewfoo/performance/fragments/BatteryInfo.java +++ b/src/com/brewcrewfoo/performance/fragments/BatteryInfo.java @@ -20,38 +20,23 @@ import android.app.AlertDialog; import android.app.Fragment; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.SharedPreferences; +import android.content.*; import android.os.BatteryManager; import android.os.Bundle; import android.preference.PreferenceManager; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CompoundButton; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.SeekBar; -import android.widget.Switch; -import android.widget.TextView; - +import android.view.*; +import android.widget.*; import com.brewcrewfoo.performance.R; import com.brewcrewfoo.performance.activities.PCSettings; import com.brewcrewfoo.performance.util.CMDProcessor; -import com.brewcrewfoo.performance.util.Constants; import com.brewcrewfoo.performance.util.Helpers; import java.io.File; +import static com.brewcrewfoo.performance.util.Constants.*; + public class BatteryInfo extends Fragment - implements SeekBar.OnSeekBarChangeListener, Constants { + implements SeekBar.OnSeekBarChangeListener { private TextView mbattery_percent; private TextView mbattery_volt; diff --git a/src/com/brewcrewfoo/performance/fragments/CPUInfo.java b/src/com/brewcrewfoo/performance/fragments/CPUInfo.java index 1d60bb35..435765bb 100644 --- a/src/com/brewcrewfoo/performance/fragments/CPUInfo.java +++ b/src/com/brewcrewfoo/performance/fragments/CPUInfo.java @@ -22,17 +22,10 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; +import android.view.*; import android.widget.TextView; - import com.brewcrewfoo.performance.R; import com.brewcrewfoo.performance.activities.PCSettings; -import com.brewcrewfoo.performance.util.Constants; import com.brewcrewfoo.performance.util.Helpers; import java.io.BufferedReader; @@ -40,7 +33,9 @@ import java.io.FileReader; import java.io.IOException; -public class CPUInfo extends Fragment implements Constants { +import static com.brewcrewfoo.performance.util.Constants.*; + +public class CPUInfo extends Fragment { private TextView mKernelInfo; private TextView mCPUInfo; diff --git a/src/com/brewcrewfoo/performance/fragments/CPUSettings.java b/src/com/brewcrewfoo/performance/fragments/CPUSettings.java index d1e308b9..92b5cfd2 100644 --- a/src/com/brewcrewfoo/performance/fragments/CPUSettings.java +++ b/src/com/brewcrewfoo/performance/fragments/CPUSettings.java @@ -18,6 +18,8 @@ package com.brewcrewfoo.performance.fragments; +import static com.brewcrewfoo.performance.util.Constants.*; + import android.app.Fragment; import android.content.Context; import android.content.Intent; @@ -46,7 +48,6 @@ import com.brewcrewfoo.performance.R; import com.brewcrewfoo.performance.activities.GovSetActivity; import com.brewcrewfoo.performance.activities.PCSettings; -import com.brewcrewfoo.performance.util.Constants; import com.brewcrewfoo.performance.util.Helpers; import java.io.File; @@ -55,8 +56,7 @@ import java.util.Comparator; import java.util.List; -public class CPUSettings extends Fragment - implements SeekBar.OnSeekBarChangeListener, Constants { +public class CPUSettings extends Fragment implements SeekBar.OnSeekBarChangeListener { private SeekBar mMaxSlider; private SeekBar mMinSlider; diff --git a/src/com/brewcrewfoo/performance/fragments/DiskInfo.java b/src/com/brewcrewfoo/performance/fragments/DiskInfo.java index 300a38c7..eb76c911 100644 --- a/src/com/brewcrewfoo/performance/fragments/DiskInfo.java +++ b/src/com/brewcrewfoo/performance/fragments/DiskInfo.java @@ -5,25 +5,18 @@ import android.content.Intent; import android.os.Bundle; import android.os.StatFs; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; +import android.view.*; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; - import com.brewcrewfoo.performance.R; import com.brewcrewfoo.performance.activities.PCSettings; import com.brewcrewfoo.performance.util.CMDProcessor; -import com.brewcrewfoo.performance.util.Constants; import com.brewcrewfoo.performance.util.Helpers; import java.io.File; -public class DiskInfo extends Fragment implements Constants { +public class DiskInfo extends Fragment { private RelativeLayout lsys; private RelativeLayout ldata; diff --git a/src/com/brewcrewfoo/performance/fragments/OOMSettings.java b/src/com/brewcrewfoo/performance/fragments/OOMSettings.java index 4b43449d..3f8088fa 100644 --- a/src/com/brewcrewfoo/performance/fragments/OOMSettings.java +++ b/src/com/brewcrewfoo/performance/fragments/OOMSettings.java @@ -26,39 +26,29 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.res.Resources; import android.os.Bundle; -import android.preference.CheckBoxPreference; -import android.preference.Preference; -import android.preference.PreferenceCategory; -import android.preference.PreferenceFragment; -import android.preference.PreferenceManager; -import android.preference.PreferenceScreen; +import android.preference.*; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; -import android.view.KeyEvent; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; +import android.view.*; import android.view.inputmethod.EditorInfo; import android.widget.EditText; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; - import com.brewcrewfoo.performance.R; import com.brewcrewfoo.performance.activities.KSMActivity; import com.brewcrewfoo.performance.activities.PCSettings; import com.brewcrewfoo.performance.activities.PackActivity; import com.brewcrewfoo.performance.util.CMDProcessor; -import com.brewcrewfoo.performance.util.Constants; import com.brewcrewfoo.performance.util.Helpers; import java.io.File; +import static com.brewcrewfoo.performance.util.Constants.*; + public class OOMSettings extends PreferenceFragment - implements OnSharedPreferenceChangeListener, Constants { + implements OnSharedPreferenceChangeListener { private SharedPreferences mPreferences; diff --git a/src/com/brewcrewfoo/performance/fragments/TimeInState.java b/src/com/brewcrewfoo/performance/fragments/TimeInState.java index 701fa95e..08e503f6 100644 --- a/src/com/brewcrewfoo/performance/fragments/TimeInState.java +++ b/src/com/brewcrewfoo/performance/fragments/TimeInState.java @@ -26,38 +26,22 @@ import android.os.AsyncTask; import android.os.Bundle; import android.preference.PreferenceManager; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.LinearLayout; -import android.widget.ProgressBar; -import android.widget.TextView; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.CompoundButton.OnCheckedChangeListener; -import android.widget.ShareActionProvider; -import android.widget.Spinner; -import android.widget.ArrayAdapter; -import android.widget.AdapterView; import android.util.Log; - +import android.view.*; +import android.widget.*; +import android.widget.CompoundButton.OnCheckedChangeListener; import com.brewcrewfoo.performance.R; -import com.brewcrewfoo.performance.activities.PCSettings; import com.brewcrewfoo.performance.util.CPUStateMonitor; import com.brewcrewfoo.performance.util.CPUStateMonitor.CPUStateMonitorException; import com.brewcrewfoo.performance.util.CPUStateMonitor.CpuState; -import com.brewcrewfoo.performance.util.Constants; import com.brewcrewfoo.performance.util.Helpers; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; -public class TimeInState extends Fragment implements Constants { +import static com.brewcrewfoo.performance.util.Constants.*; + +public class TimeInState extends Fragment { private LinearLayout mStatesView; private TextView mTotalStateTime; diff --git a/src/com/brewcrewfoo/performance/fragments/Tools.java b/src/com/brewcrewfoo/performance/fragments/Tools.java index 8e17ef61..165e8d62 100644 --- a/src/com/brewcrewfoo/performance/fragments/Tools.java +++ b/src/com/brewcrewfoo/performance/fragments/Tools.java @@ -31,35 +31,26 @@ import android.content.res.Resources; import android.os.AsyncTask; import android.os.Bundle; -import android.preference.Preference; -import android.preference.PreferenceCategory; -import android.preference.PreferenceFragment; -import android.preference.PreferenceManager; -import android.preference.PreferenceScreen; +import android.preference.*; import android.text.Editable; import android.text.TextWatcher; import android.text.format.DateUtils; -import android.view.KeyEvent; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; +import android.view.*; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; - import com.brewcrewfoo.performance.R; import com.brewcrewfoo.performance.activities.FlasherActivity; import com.brewcrewfoo.performance.activities.FreezerActivity; import com.brewcrewfoo.performance.activities.PCSettings; import com.brewcrewfoo.performance.activities.ResidualsActivity; import com.brewcrewfoo.performance.util.CMDProcessor; -import com.brewcrewfoo.performance.util.Constants; import com.brewcrewfoo.performance.util.Helpers; +import static com.brewcrewfoo.performance.util.Constants.*; + public class Tools extends PreferenceFragment implements - OnSharedPreferenceChangeListener, Constants { + OnSharedPreferenceChangeListener { private byte tip; private SharedPreferences mPreferences; diff --git a/src/com/brewcrewfoo/performance/fragments/VM.java b/src/com/brewcrewfoo/performance/fragments/VM.java index 82ed8db7..c3d1c927 100644 --- a/src/com/brewcrewfoo/performance/fragments/VM.java +++ b/src/com/brewcrewfoo/performance/fragments/VM.java @@ -17,26 +17,21 @@ import android.preference.PreferenceScreen; import android.text.Editable; import android.text.TextWatcher; -import android.view.KeyEvent; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; +import android.view.*; import android.view.inputmethod.EditorInfo; import android.widget.EditText; import android.widget.SeekBar; import android.widget.TextView; - import com.brewcrewfoo.performance.R; import com.brewcrewfoo.performance.activities.PCSettings; import com.brewcrewfoo.performance.util.CMDProcessor; -import com.brewcrewfoo.performance.util.Constants; import com.brewcrewfoo.performance.util.Helpers; import java.io.File; -public class VM extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener, Constants { +import static com.brewcrewfoo.performance.util.Constants.*; + +public class VM extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener { private Preference mDirtyRatio; private Preference mDirtyBackground; diff --git a/src/com/brewcrewfoo/performance/fragments/VoltageControlSettings.java b/src/com/brewcrewfoo/performance/fragments/VoltageControlSettings.java index 7b5958cc..ac5fd160 100644 --- a/src/com/brewcrewfoo/performance/fragments/VoltageControlSettings.java +++ b/src/com/brewcrewfoo/performance/fragments/VoltageControlSettings.java @@ -29,27 +29,13 @@ import android.text.Editable; import android.text.TextWatcher; import android.util.Log; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; +import android.view.*; import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.widget.AdapterView; +import android.widget.*; import android.widget.AdapterView.OnItemClickListener; -import android.widget.BaseAdapter; -import android.widget.CompoundButton; -import android.widget.EditText; -import android.widget.ListView; -import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; -import android.widget.Switch; -import android.widget.TextView; - import com.brewcrewfoo.performance.R; import com.brewcrewfoo.performance.activities.PCSettings; -import com.brewcrewfoo.performance.util.Constants; import com.brewcrewfoo.performance.util.Helpers; import com.brewcrewfoo.performance.util.Voltage; @@ -60,7 +46,9 @@ import java.util.ArrayList; import java.util.List; -public class VoltageControlSettings extends Fragment implements Constants { +import static com.brewcrewfoo.performance.util.Constants.*; + +public class VoltageControlSettings extends Fragment { public static final int DIALOG_EDIT_VOLT = 0; private List mVoltages; diff --git a/src/com/brewcrewfoo/performance/fragments/Wakelocks.java b/src/com/brewcrewfoo/performance/fragments/Wakelocks.java index 36ca7c65..ff371736 100644 --- a/src/com/brewcrewfoo/performance/fragments/Wakelocks.java +++ b/src/com/brewcrewfoo/performance/fragments/Wakelocks.java @@ -19,6 +19,8 @@ package com.brewcrewfoo.performance.fragments; +import static com.brewcrewfoo.performance.util.Constants.*; + import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; @@ -35,6 +37,7 @@ import java.util.HashSet; import java.util.Arrays; +import android.app.Activity; import android.app.Fragment; import android.app.SearchManager; import android.content.Context; @@ -73,6 +76,7 @@ import android.widget.TextView; import android.widget.PopupMenu; import android.widget.ImageView; +import android.widget.Toast; import android.content.ClipboardManager; import android.content.ClipData; import android.graphics.drawable.Drawable; @@ -84,7 +88,7 @@ import com.brewcrewfoo.performance.R; import com.brewcrewfoo.performance.util.Constants; -public class Wakelocks extends Fragment implements Constants { +public class Wakelocks extends Fragment { private static final String TAG = "Wakelocks"; private static String sRefFilename = "wakelockdata.ref"; private static String sUnplugFilename = "wakelockdata.unplug"; @@ -98,7 +102,7 @@ public class Wakelocks extends Fragment implements Constants { private TextView mTotalStateTime; private TextView mTotalWakelockTime; private TextView mKernelWakelockWarning; - private boolean mUpdatingData = false; + private boolean mUpdatingData; private Context mContext; private SharedPreferences mPreferences; private ShareActionProvider mProvider; @@ -128,12 +132,13 @@ public class Wakelocks extends Fragment implements Constants { private int mStateTimeMode; private Spinner mStateTimeSelect; private PopupMenu mPopup; - private static long sUnplugBatteryUptime; - private static long sUnplugBatteryRealtime; - private static int sUnplugBatteryLevel; - private static boolean sIsOnBattery; + private long mUnplugBatteryUptime; + private long mUnplugBatteryRealtime; + private int mUnplugBatteryLevel; + private boolean mIsOnBattery; private List mAppWakelockList = new ArrayList(); private static boolean sHasRefData; + private boolean mErrorLoadingStats; private static final int MENU_REFRESH = Menu.FIRST; private static final int MENU_SHARE = MENU_REFRESH + 1; @@ -190,6 +195,25 @@ public String toString() { return mType + "||" + mName + "||" + mCount + "||" + mTotalTime + "||" + mPreventSuspendTime; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + + if (!(o instanceof WakelockStats)) { + return false; + } + + WakelockStats lhs = (WakelockStats) o; + return mName.equals(lhs.mName) && mUid == lhs.mUid; + } + + @Override + public int hashCode() { + return mName.hashCode(); + } } static final class WakelockAppStats { @@ -233,7 +257,7 @@ public int hashCode() { @Override public String toString() { - return mUid + "||" + mAppWakelocks; + return mUid + "||" + mAppWakelocks; } } @@ -300,7 +324,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup root, mStatesView = (LinearLayout) view.findViewById(R.id.ui_states_view); mTimeView = (LinearLayout) view.findViewById(R.id.ui_state_time); - mStateTimeView = (LinearLayout) view.findViewById(R.id.state_time_select_group); + mStateTimeView = (LinearLayout) view + .findViewById(R.id.state_time_select_group); mTotalStateTime = (TextView) view .findViewById(R.id.ui_total_state_time); mTotalWakelockTime = (TextView) view @@ -308,7 +333,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup root, mPeriodTypeSelect = (Spinner) view .findViewById(R.id.period_type_select); ArrayAdapter adapter = ArrayAdapter.createFromResource( - mContext, R.array.wakelock_period_type_entries, R.layout.period_type_item); + mContext, R.array.wakelock_period_type_entries, + R.layout.period_type_item); mPeriodTypeSelect.setAdapter(adapter); mPeriodTypeSelect @@ -319,7 +345,7 @@ public void onItemSelected(AdapterView parent, mPeriodType = position; if (position == 0) { sWhich = TIME_PERIOD_RESET; - } else if (position == 1) { + } else if (position == 1) { sWhich = TIME_PERIOD_UNPLUG; } refreshData(); @@ -341,7 +367,8 @@ public void onNothingSelected(AdapterView arg0) { public void onItemSelected(AdapterView parent, View view, int position, long id) { mListType = position; - mStateTimeView.setVisibility(mListType == 0 ? View.GONE : View.VISIBLE); + mStateTimeView.setVisibility(mListType == 0 ? View.GONE + : View.VISIBLE); refreshData(); } @@ -351,8 +378,9 @@ public void onNothingSelected(AdapterView arg0) { }); mStateTimeSelect = (Spinner) view.findViewById(R.id.state_time_select); - ArrayAdapter adapter2 = ArrayAdapter.createFromResource( - mContext, R.array.state_time_entries, R.layout.period_type_item); + ArrayAdapter adapter2 = ArrayAdapter + .createFromResource(mContext, R.array.state_time_entries, + R.layout.period_type_item); mStateTimeSelect.setAdapter(adapter2); mStateTimeSelect @@ -391,8 +419,8 @@ public void onSaveInstanceState(Bundle outState) { @Override public void onResume() { - refreshData(); super.onResume(); + refreshData(); } @Override @@ -432,7 +460,7 @@ public boolean onOptionsItemSelected(MenuItem item) { refreshData(); break; case R.id.reset: - if (sIsOnBattery) { + if (mIsOnBattery) { saveWakelockRef(mContext); refreshData(); } @@ -443,7 +471,8 @@ public boolean onOptionsItemSelected(MenuItem item) { } private void updateView() { - //Log.d(TAG, "updateView " + sKernelWakelockData + " " + mUpdatingData); + // Log.d(TAG, "updateView " + sKernelWakelockData + " " + + // mUpdatingData); if (mUpdatingData) { return; } @@ -465,56 +494,67 @@ private void updateView() { mTotalWakelockTime.setText(""); if (sWhich == TIME_PERIOD_RESET) { - if (sIsOnBattery) { + if (mIsOnBattery) { if (sHasRefData) { - totalTimeInSecs = Math.max((rawRealtime - sRefRealTimestamp) / 1000, 0); - totalUptimeInSecs = Math.max((rawUptime - sRefUpTimestamp) / 1000, 0); + totalTimeInSecs = Math.max( + (rawRealtime - sRefRealTimestamp) / 1000, 0); + totalUptimeInSecs = Math.max( + (rawUptime - sRefUpTimestamp) / 1000, 0); if (sRefBatteryLevel != -1) { - int batteryLevelDiff = mBatteryLevel - sRefBatteryLevel; + int batteryLevelDiff = mBatteryLevel + - sRefBatteryLevel; if (batteryLevelDiff != 0) { float hours = (float) totalTimeInSecs / 3600; - batteryLevelText = String.valueOf(batteryLevelDiff) + batteryLevelText = String + .valueOf(batteryLevelDiff) + "% " - + String.format("%.2f", (float) batteryLevelDiff - / hours) + "%/h"; + + String.format("%.2f", + (float) batteryLevelDiff + / hours) + "%/h"; } else { batteryLevelText = "0% 0.00%/h"; } } - mTotalStateTime.setText(getResources().getString(R.string.total_time) - + " " + toString(totalTimeInSecs)); + mTotalStateTime.setText(getResources().getString( + R.string.total_time) + + " " + toString(totalTimeInSecs)); showStats = true; } else { totalTimeInSecs = 0; totalUptimeInSecs = 0; - mTotalStateTime.setText(getResources().getString(R.string.no_stat_because_reset)); + mTotalStateTime.setText(getResources().getString( + R.string.no_stat_because_reset)); } } else { totalTimeInSecs = 0; totalUptimeInSecs = 0; - mTotalStateTime.setText(getResources().getString(R.string.no_stat_because_plugged)); + mTotalStateTime.setText(getResources().getString( + R.string.no_stat_because_plugged)); } } else if (sWhich == TIME_PERIOD_UNPLUG) { - if (sIsOnBattery) { - totalTimeInSecs = microToSecs(sUnplugBatteryRealtime); - totalUptimeInSecs = microToSecs(sUnplugBatteryUptime); - int batteryLevelDiff = mBatteryLevel - sUnplugBatteryLevel; + if (mIsOnBattery) { + totalTimeInSecs = microToSecs(mUnplugBatteryRealtime); + totalUptimeInSecs = microToSecs(mUnplugBatteryUptime); + int batteryLevelDiff = mBatteryLevel - mUnplugBatteryLevel; if (batteryLevelDiff != 0) { float hours = (float) totalTimeInSecs / 3600; batteryLevelText = String.valueOf(batteryLevelDiff) + "% " - + String.format("%.2f", (float) batteryLevelDiff - / hours) + "%/h"; + + String.format("%.2f", + (float) batteryLevelDiff / hours) + + "%/h"; } else { batteryLevelText = "0% 0.00%/h"; } - mTotalStateTime.setText(getResources().getString(R.string.total_time) - + " " + toString(totalTimeInSecs)); + mTotalStateTime.setText(getResources().getString( + R.string.total_time) + + " " + toString(totalTimeInSecs)); showStats = true; } else { totalTimeInSecs = 0; totalUptimeInSecs = 0; - mTotalStateTime.setText(getResources().getString(R.string.no_stat_because_plugged)); + mTotalStateTime.setText(getResources().getString( + R.string.no_stat_because_plugged)); } } sleepTime = Math.max(totalTimeInSecs - totalUptimeInSecs, 0); @@ -522,8 +562,10 @@ private void updateView() { long kernelWakelockTime = getKernelWakelockSummaryTime(); long userWakelockTime = getUserWakelockSummaryTime(); - long kernelWakelockTimeInSecs = kernelWakelockTime > 0 ? kernelWakelockTime / 1000 : 0; - long userWakelockTimeInSecs = userWakelockTime > 0 ? userWakelockTime / 1000 : 0; + long kernelWakelockTimeInSecs = kernelWakelockTime > 0 ? kernelWakelockTime / 1000 + : 0; + long userWakelockTimeInSecs = userWakelockTime > 0 ? userWakelockTime / 1000 + : 0; if (mListType == 0 && showStats) { generateTimeRow(getResources().getString(R.string.awake_time), @@ -543,8 +585,11 @@ private void updateView() { getResources().getString(R.string.battery_change), batteryLevelText, mStatesView); } - mTotalWakelockTime.setText(getResources().getString(R.string.wakelock_time) - + " " + toString(kernelWakelockTimeInSecs + userWakelockTimeInSecs)); + mTotalWakelockTime.setText(getResources().getString( + R.string.wakelock_time) + + " " + + toString(kernelWakelockTimeInSecs + + userWakelockTimeInSecs)); } else if (mListType == 1 && showStats) { int i = 0; if (mStateTimeMode == 1) { @@ -559,18 +604,21 @@ private void updateView() { totalTimeInSecs, mStatesView, false); i++; if (!mShowAll && i >= MAX_KERNEL_LIST_ITEMS) { - generateMoreRow( - String.valueOf(mKernelWakelocks.size() - - i) - + " " - + getResources().getString( - R.string.more_line_text), - mStatesView); + int moreNum = mKernelWakelocks.size() - i; + if (moreNum > 0) { + generateMoreRow( + String.valueOf(moreNum) + + " " + + getResources().getString( + R.string.more_line_text), + mStatesView); + } break; } } - mTotalWakelockTime.setText(getResources().getString(R.string.wakelock_time) - + " " + toString(kernelWakelockTimeInSecs)); + mTotalWakelockTime.setText(getResources().getString( + R.string.wakelock_time) + + " " + toString(kernelWakelockTimeInSecs)); } else if (mListType == 2 && showStats) { int i = 0; if (mStateTimeMode == 1) { @@ -585,18 +633,21 @@ private void updateView() { totalTimeInSecs, mStatesView, true); i++; if (!mShowAll && i >= MAX_USER_LIST_ITEMS) { - generateMoreRow( - String.valueOf(mUserWakelocks.size() - - i) - + " " - + getResources().getString( - R.string.more_line_text), - mStatesView); + int moreNum = mUserWakelocks.size() - i; + if (moreNum > 0) { + generateMoreRow( + String.valueOf(moreNum) + + " " + + getResources().getString( + R.string.more_line_text), + mStatesView); + } break; } } - mTotalWakelockTime.setText(getResources().getString(R.string.wakelock_time) - + " " + toString(userWakelockTimeInSecs)); + mTotalWakelockTime.setText(getResources().getString( + R.string.wakelock_time) + + " " + toString(userWakelockTimeInSecs)); } else if (mListType == 3 && showStats) { boolean moreAdded = false; int j = 0; @@ -609,24 +660,28 @@ private void updateView() { WakelockAppStats entry = nextWakelock.next(); generateAppWakelockRow(entry, mStatesView, totalTimeInSecs); - Iterator nextAppWakelock = entry.getWakelocks() - .iterator(); + Iterator nextAppWakelock = entry + .getWakelocks().iterator(); while (nextAppWakelock.hasNext()) { WakelockStats appEntry = nextAppWakelock.next(); generateWakelockRow(appEntry, - appEntry.mPreventSuspendTime / 1000, appEntry.mCount, - totalTimeInSecs, mStatesView, false); + appEntry.mPreventSuspendTime / 1000, + appEntry.mCount, totalTimeInSecs, mStatesView, + false); j++; if (!mShowAll && j >= MAX_USER_LIST_ITEMS) { - generateMoreRow( - String.valueOf(mUserWakelocks.size() - - j) - + " " - + getResources().getString( - R.string.more_line_text), - mStatesView); - moreAdded = true; + int moreNum = mUserWakelocks.size() - j; + if (moreNum > 0) { + generateMoreRow( + String.valueOf(moreNum) + + " " + + getResources() + .getString( + R.string.more_line_text), + mStatesView); + moreAdded = true; + } break; } } @@ -634,17 +689,18 @@ private void updateView() { break; } } - mTotalWakelockTime.setText(getResources().getString(R.string.wakelock_time) - + " " + toString(userWakelockTimeInSecs)); + mTotalWakelockTime.setText(getResources().getString( + R.string.wakelock_time) + + " " + toString(userWakelockTimeInSecs)); } } - //Log.d(TAG, "updateView " + mShareData.length()); + // Log.d(TAG, "updateView " + mShareData.length()); updateShareIntent(mShareData.toString()); } public void refreshData() { - //Log.d(TAG, "refreshData " + mUpdatingData); + // Log.d(TAG, "refreshData " + mUpdatingData); if (!mUpdatingData) { new RefreshStateDataTask().execute((Void) null); @@ -688,7 +744,7 @@ protected void onPostExecute(Void v) { mStatesView.setVisibility(View.VISIBLE); mUpdatingData = false; updateView(); - } catch(Exception e) { + } catch (Exception e) { } } } @@ -756,8 +812,8 @@ private View generateTimeRow(String title, long duration, long totalTime, return view; } - private View generateWakelockRow(final WakelockStats entry, long duration, int count, - long totalTime, ViewGroup parent, boolean withMore) { + private View generateWakelockRow(final WakelockStats entry, long duration, + int count, long totalTime, ViewGroup parent, boolean withMore) { LayoutInflater inflater = LayoutInflater.from(mContext); final LinearLayout view = (LinearLayout) inflater.inflate( R.layout.wakelock_row, parent, false); @@ -792,10 +848,12 @@ private View generateWakelockRow(final WakelockStats entry, long duration, int c countText.setText(String.valueOf(count)); if (withMore) { - String[] packages = mContext.getPackageManager().getPackagesForUid(entry.mUid); + String[] packages = mContext.getPackageManager().getPackagesForUid( + entry.mUid); String rootPackage = getNormalizedRootPackage(packages); try { - ApplicationInfo ai = mContext.getPackageManager().getApplicationInfo(rootPackage, 0); + ApplicationInfo ai = mContext.getPackageManager() + .getApplicationInfo(rootPackage, 0); CharSequence label = ai.loadLabel(mContext.getPackageManager()); moreText.setVisibility(View.VISIBLE); if (label != null) { @@ -803,7 +861,7 @@ private View generateWakelockRow(final WakelockStats entry, long duration, int c } else { moreText.setText(rootPackage); } - } catch(android.content.pm.PackageManager.NameNotFoundException e) { + } catch (android.content.pm.PackageManager.NameNotFoundException e) { return null; } } @@ -819,7 +877,8 @@ public boolean onLongClick(View v) { return view; } - private View generateAppWakelockRow(final WakelockAppStats entry, ViewGroup parent, long totalTime) { + private View generateAppWakelockRow(final WakelockAppStats entry, + ViewGroup parent, long totalTime) { LayoutInflater inflater = LayoutInflater.from(mContext); final LinearLayout view = (LinearLayout) inflater.inflate( R.layout.wakelock_app_row, parent, false); @@ -846,33 +905,36 @@ private View generateAppWakelockRow(final WakelockAppStats entry, ViewGroup pare .findViewById(R.id.ui_percentage_text); ImageView appIcon = (ImageView) view.findViewById(R.id.ui_icon); - String[] packages = mContext.getPackageManager().getPackagesForUid(entry.mUid); + String[] packages = mContext.getPackageManager().getPackagesForUid( + entry.mUid); try { String rootPackage = getNormalizedRootPackage(packages); - ApplicationInfo ai = mContext.getPackageManager().getApplicationInfo(rootPackage, 0); + ApplicationInfo ai = mContext.getPackageManager() + .getApplicationInfo(rootPackage, 0); CharSequence label = ai.loadLabel(mContext.getPackageManager()); String packageName = rootPackage; String appName = rootPackage; if (label != null) { appName = label.toString(); } - Drawable appIconDrawable = ai.loadIcon(mContext.getPackageManager()); + Drawable appIconDrawable = ai + .loadIcon(mContext.getPackageManager()); text.setText(appName); moreText.setVisibility(View.VISIBLE); moreText.setText(packageName); perText.setText(sPer); durText.setText(sDur); appIcon.setImageDrawable(appIconDrawable); - } catch(android.content.pm.PackageManager.NameNotFoundException e) { + } catch (android.content.pm.PackageManager.NameNotFoundException e) { return null; } - /*view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - } - });*/ + /* + * view.setOnClickListener(new View.OnClickListener() { + * + * @Override public void onClick(View v) { } }); + */ if (packages != null && packages.length == 1) { view.setOnLongClickListener(new View.OnLongClickListener() { @@ -964,7 +1026,8 @@ public static void readKernelWakelockStats( } private static void parseProcWakelocks( - ArrayList wakelockList, byte[] wlBuffer, int len, boolean wakeup_sources) { + ArrayList wakelockList, byte[] wlBuffer, int len, + boolean wakeup_sources) { String name; int count; long totalTime; @@ -1002,15 +1065,15 @@ private static void parseProcWakelocks( wlBuffer[j] = (byte) '?'; } boolean parsed = Process.parseProcLine(wlBuffer, startIndex, - endIndex, wakeup_sources ? WAKEUP_SOURCES_FORMAT : - PROC_WAKELOCKS_FORMAT, - nameStringArray, wlData, null); + endIndex, wakeup_sources ? WAKEUP_SOURCES_FORMAT + : PROC_WAKELOCKS_FORMAT, nameStringArray, wlData, + null); name = nameStringArray[0]; count = (int) wlData[1]; if (wakeup_sources) { totalTime = wlData[2]; - preventSuspendTime = wlData[3]; + preventSuspendTime = wlData[2]; } else { totalTime = (wlData[2] + 500) / 1000000; preventSuspendTime = (wlData[3] + 500) / 1000000; @@ -1044,8 +1107,8 @@ private WakelockStats fromString(String line) { } } - public static void clearKernelWakelockStatus(Context context) { - Log.d(TAG, "clearKernelWakelockStatus"); + public static void clearStatus(Context context) { + Log.d(TAG, "clearStatus"); sRefKernelWakelocks.clear(); sRefUserWakelocks.clear(); sUnplugKernelWakelocks.clear(); @@ -1065,13 +1128,15 @@ public static void clearKernelWakelockStatus(Context context) { } public static void powerUnplugged(Context context) { - PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); - PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, + Log.d(TAG, "powerUnplugged"); + PowerManager pm = (PowerManager) context + .getSystemService(Context.POWER_SERVICE); + PowerManager.WakeLock wl = pm.newWakeLock( + PowerManager.PARTIAL_WAKE_LOCK, "PerformanceControl.powerUnplugged"); wl.acquire(); - Log.d(TAG, "powerUnplugged"); - clearKernelWakelockStatus(context); + clearStatus(context); readKernelWakelockStats(sUnplugKernelWakelocks); saveUnplugWakelockData(context, sUnplugFilename, sUnplugKernelWakelocks); @@ -1084,7 +1149,8 @@ public static void powerPlugged(Context context) { sUnplugKernelWakelocks.clear(); } - private static void saveWakelockList(BufferedWriter buf, ArrayList wlList) throws java.io.IOException { + private static void saveWakelockList(BufferedWriter buf, + ArrayList wlList) throws java.io.IOException { Iterator nextWakelock = wlList.iterator(); while (nextWakelock.hasNext()) { WakelockStats entry = nextWakelock.next(); @@ -1094,7 +1160,7 @@ private static void saveWakelockList(BufferedWriter buf, ArrayList kernelData, ArrayList userData) { try { @@ -1119,8 +1185,8 @@ private static void saveRefWakelockData(Context context, String fileName, } } - private static void saveUnplugWakelockData(Context context, String fileName, - ArrayList kernelData) { + private static void saveUnplugWakelockData(Context context, + String fileName, ArrayList kernelData) { try { File file = new File(context.getFilesDir(), fileName); BufferedWriter buf = new BufferedWriter(new FileWriter(file)); @@ -1134,31 +1200,17 @@ private static void saveUnplugWakelockData(Context context, String fileName, } } - private static void saveWakelockRef(Context context) { + private void saveWakelockRef(Context context) { sRefKernelWakelocks.clear(); sRefUserWakelocks.clear(); readKernelWakelockStats(sRefKernelWakelocks); + readUserWakelockStats(sBatteryStats, sRefUserWakelocks); - //try { - /*IBatteryStats stats = IBatteryStats.Stub.asInterface(ServiceManager - .getService(BatteryStats.SERVICE_NAME)); - byte[] data = stats.getStatistics(); - Parcel parcel = Parcel.obtain(); - parcel.unmarshall(data, 0, data.length); - parcel.setDataPosition(0); - BatteryStats sBatteryStats = com.android.internal.os.BatteryStatsImpl.CREATOR - .createFromParcel(parcel);*/ - - readUserWakelockStats(sBatteryStats, sRefUserWakelocks, false); - - sRefRealTimestamp = SystemClock.elapsedRealtime(); - sRefUpTimestamp = SystemClock.uptimeMillis(); - sRefBatteryLevel = sBatteryStats.getDischargeCurrentLevel(); - saveRefWakelockData(context, sRefFilename, sRefKernelWakelocks, + sRefRealTimestamp = SystemClock.elapsedRealtime(); + sRefUpTimestamp = SystemClock.uptimeMillis(); + sRefBatteryLevel = sBatteryStats.getDischargeCurrentLevel(); + saveRefWakelockData(context, sRefFilename, sRefKernelWakelocks, sRefUserWakelocks); - /*} catch (RemoteException e) { - Log.e(TAG, "RemoteException:", e); - }*/ } private void loadRefWakelockData(String fileName, @@ -1221,7 +1273,8 @@ private void loadUnplugWakelockData(String fileName, private void loadWakelockRef() { sRefKernelWakelocks.clear(); sRefUserWakelocks.clear(); - loadRefWakelockData(sRefFilename, sRefKernelWakelocks, sRefUserWakelocks); + loadRefWakelockData(sRefFilename, sRefKernelWakelocks, + sRefUserWakelocks); } private void loadWakelockUnplug() { @@ -1264,8 +1317,8 @@ private ArrayList diffToWakelockStatus( return diffWakelocks; } - private static void readUserWakelockStats(BatteryStats stats, - ArrayList userData, boolean unplug) { + private void readUserWakelockStats(BatteryStats stats, + ArrayList userData) { SparseArray uidStats = stats.getUidStats(); HashMap indexList = new HashMap(); @@ -1279,20 +1332,15 @@ private static void readUserWakelockStats(BatteryStats stats, for (Map.Entry ent : wakelocks .entrySet()) { BatteryStats.Uid.Wakelock wl = ent.getValue(); - // BatteryStats.Timer fullWakeTimer = - // wl.getWakeTime(WAKE_TYPE_FULL); BatteryStats.Timer partialWakeTimer = wl .getWakeTime(BatteryStats.WAKE_TYPE_PARTIAL); if (partialWakeTimer != null) { long totalTimeMillis = computeWakeLock( - partialWakeTimer, - unplug ? - sUnplugBatteryRealtime : - (SystemClock.elapsedRealtime() * 1000), - BatteryStats.STATS_SINCE_UNPLUGGED); - int count = partialWakeTimer.getCountLocked( - BatteryStats.STATS_SINCE_UNPLUGGED); + partialWakeTimer, rawRealtime * 1000, + BatteryStats.STATS_SINCE_UNPLUGGED); + int count = partialWakeTimer + .getCountLocked(BatteryStats.STATS_SINCE_UNPLUGGED); if (totalTimeMillis > 0 && count > 0) { WakelockStats foundEntry = indexList.get(ent .getKey()); @@ -1314,8 +1362,38 @@ private static void readUserWakelockStats(BatteryStats stats, } } + private void readKernelWakelockStats(BatteryStats stats, + ArrayList kernelData) { + Log.d(TAG, "readKernelWakelockStats"); + Map kernelWakelocks = stats + .getKernelWakelockStats(); + if (kernelWakelocks.size() > 0) { + for (Map.Entry ent : kernelWakelocks + .entrySet()) { + BatteryStats.Timer wl = ent.getValue(); + + long totalTimeMillis = microToMillis(wl.getTotalTimeLocked( + rawRealtime * 1000, BatteryStats.STATS_SINCE_UNPLUGGED)); + int count = wl + .getCountLocked(BatteryStats.STATS_SINCE_UNPLUGGED); + + if (totalTimeMillis > 0 && count > 0) { + WakelockStats entry = new WakelockStats(0, ent.getKey(), + count, totalTimeMillis, totalTimeMillis, 0); + Log.d(TAG, "readKernelWakelockStats A " + ent.getKey() + + " " + totalTimeMillis + " " + count); + kernelData.add(entry); + } else { + Log.d(TAG, "readKernelWakelockStats B " + ent.getKey() + + " " + totalTimeMillis + " " + count); + } + } + } + } + private void load() { - //Log.d(TAG, "load"); + // Log.d(TAG, "load"); + mErrorLoadingStats = false; try { mShowAll = false; mShareData = new StringBuffer(); @@ -1331,46 +1409,36 @@ private void load() { rawUptime = SystemClock.uptimeMillis(); rawRealtime = SystemClock.elapsedRealtime(); mBatteryLevel = sBatteryStats.getDischargeCurrentLevel(); - sUnplugBatteryLevel = sBatteryStats.getDischargeStartLevel(); + mUnplugBatteryLevel = sBatteryStats.getDischargeStartLevel(); - sIsOnBattery = sBatteryStats.getIsOnBattery(); - sUnplugBatteryUptime = sBatteryStats.computeBatteryUptime( + mUnplugBatteryUptime = sBatteryStats.computeBatteryUptime( rawUptime * 1000, BatteryStats.STATS_SINCE_UNPLUGGED); - sUnplugBatteryRealtime = sBatteryStats.computeBatteryRealtime( - rawRealtime * 1000, BatteryStats.STATS_SINCE_UNPLUGGED); - long totalRealtime = sBatteryStats.computeRealtime( + mUnplugBatteryRealtime = sBatteryStats.computeBatteryRealtime( rawRealtime * 1000, BatteryStats.STATS_SINCE_UNPLUGGED); - long totalUptime = sBatteryStats.computeUptime(rawUptime * 1000, - BatteryStats.STATS_SINCE_UNPLUGGED); - sIsOnBattery = sBatteryStats.getIsOnBattery(); - /*Log.d(TAG, "" + mBatteryLevel + " " - + toString(microToSecs(sUnplugBatteryUptime)) + " " - + toString(microToSecs(sUnplugBatteryRealtime)) + " " - + toString(microToSecs(totalRealtime)) + " " - + toString(microToSecs(totalUptime)));*/ + mIsOnBattery = sBatteryStats.getIsOnBattery(); mShareData.append("\n================\n"); mShareData.append("Kernel wakelocks\n"); mShareData.append("================\n"); ArrayList allKernelWakelocks = new ArrayList(); - readKernelWakelockStats(allKernelWakelocks); + readKernelWakelockStats(/* sBatteryStats, */allKernelWakelocks); // init ref data after unplug if (sRefBatteryLevel == -1) { sRefRealTimestamp = rawRealtime; sRefUpTimestamp = rawUptime; - sRefBatteryLevel = sUnplugBatteryLevel; + sRefBatteryLevel = mUnplugBatteryLevel; sRefKernelWakelocks.addAll(allKernelWakelocks); } mKernelWakelocks.clear(); if (sWhich == TIME_PERIOD_RESET) { - if (sIsOnBattery) { + if (mIsOnBattery) { mKernelWakelocks.addAll(diffToWakelockStatus( sRefKernelWakelocks, allKernelWakelocks)); } } else if (sWhich == TIME_PERIOD_UNPLUG) { - if (sIsOnBattery) { + if (mIsOnBattery) { mKernelWakelocks.addAll(diffToWakelockStatus( sUnplugKernelWakelocks, allKernelWakelocks)); } @@ -1384,16 +1452,16 @@ private void load() { mShareData.append("Wakelocks\n"); mShareData.append("================\n"); ArrayList allUserWakelocks = new ArrayList(); - readUserWakelockStats(sBatteryStats, allUserWakelocks, sWhich == TIME_PERIOD_UNPLUG); + readUserWakelockStats(sBatteryStats, allUserWakelocks); mUserWakelocks.clear(); if (sWhich == TIME_PERIOD_RESET) { - if (sIsOnBattery) { - mUserWakelocks.addAll(diffToWakelockStatus(sRefUserWakelocks, - allUserWakelocks)); + if (mIsOnBattery) { + mUserWakelocks.addAll(diffToWakelockStatus( + sRefUserWakelocks, allUserWakelocks)); } } else if (sWhich == TIME_PERIOD_UNPLUG) { - if (sIsOnBattery) { + if (mIsOnBattery) { mUserWakelocks.addAll(allUserWakelocks); } } else { @@ -1407,19 +1475,14 @@ private void load() { } catch (RemoteException e) { Log.e(TAG, "RemoteException:", e); - mTotalStateTime.post(new Runnable() { - public void run() { - mTotalStateTime.setText(getResources().getString(R.string.no_stat_because_error)); - } - }); + mErrorLoadingStats = true; } } private void buildAppWakelockList() { mAppWakelockList.clear(); - Iterator nextWakelock = mUserWakelocks - .iterator(); + Iterator nextWakelock = mUserWakelocks.iterator(); while (nextWakelock.hasNext()) { WakelockStats entry = nextWakelock.next(); WakelockAppStats appStats = new WakelockAppStats(entry.mUid); @@ -1435,8 +1498,7 @@ private void buildAppWakelockList() { private long getKernelWakelockSummaryTime() { long totalTime = 0; - Iterator nextWakelock = mKernelWakelocks - .iterator(); + Iterator nextWakelock = mKernelWakelocks.iterator(); while (nextWakelock.hasNext()) { WakelockStats entry = nextWakelock.next(); long mSecs = entry.mPreventSuspendTime; @@ -1447,8 +1509,7 @@ private long getKernelWakelockSummaryTime() { private long getUserWakelockSummaryTime() { long totalTime = 0; - Iterator nextWakelock = mUserWakelocks - .iterator(); + Iterator nextWakelock = mUserWakelocks.iterator(); while (nextWakelock.hasNext()) { WakelockStats entry = nextWakelock.next(); long mSecs = entry.mPreventSuspendTime; @@ -1468,14 +1529,16 @@ private void handleLongPress(final WakelockStats entry, View view) { popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { if (item.getItemId() == R.id.copy_as_text) { - ClipboardManager clipboard = (ClipboardManager) - mContext.getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText(wakeLockName, wakeLockName); + ClipboardManager clipboard = (ClipboardManager) mContext + .getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText(wakeLockName, + wakeLockName); clipboard.setPrimaryClip(clip); } else if (item.getItemId() == R.id.google_it) { try { Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); - intent.putExtra(SearchManager.QUERY, "wakelock " + wakeLockName); + intent.putExtra(SearchManager.QUERY, "wakelock " + + wakeLockName); startActivity(intent); } catch (Exception e) { } @@ -1502,7 +1565,8 @@ private void handleAppLongPress(final WakelockAppStats entry, View view) { popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { if (item.getItemId() == R.id.app_details) { - String[] packages = mContext.getPackageManager().getPackagesForUid(entry.mUid); + String[] packages = mContext.getPackageManager() + .getPackagesForUid(entry.mUid); if (packages != null && packages.length == 1) { Intent intent = new Intent(); intent.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); diff --git a/src/com/brewcrewfoo/performance/service/BootService.java b/src/com/brewcrewfoo/performance/service/BootService.java index 8b6ff3a7..45464557 100644 --- a/src/com/brewcrewfoo/performance/service/BootService.java +++ b/src/com/brewcrewfoo/performance/service/BootService.java @@ -27,18 +27,18 @@ import android.os.AsyncTask; import android.os.IBinder; import android.preference.PreferenceManager; - import com.brewcrewfoo.performance.R; import com.brewcrewfoo.performance.fragments.VoltageControlSettings; -import com.brewcrewfoo.performance.util.Constants; +import com.brewcrewfoo.performance.fragments.Wakelocks; import com.brewcrewfoo.performance.util.Helpers; import com.brewcrewfoo.performance.util.Voltage; -import com.brewcrewfoo.performance.fragments.Wakelocks; import java.io.File; import java.util.List; -public class BootService extends Service implements Constants { +import static com.brewcrewfoo.performance.util.Constants.*; + +public class BootService extends Service { public static boolean servicesStarted = false; Context context; @@ -74,7 +74,7 @@ protected Void doInBackground(Void... args) { SharedPreferences.Editor editor = preferences.edit(); editor.putString(PREF_OFFSETS, "").commit(); - Wakelocks.clearKernelWakelockStatus(c); + Wakelocks.clearStatus(c); final StringBuilder sb = new StringBuilder(); final String FASTCHARGE_PATH = Helpers.fastcharge_path(); @@ -145,10 +145,13 @@ protected Void doInBackground(Void... args) { if (preferences.getBoolean(PREF_READ_AHEAD_BOOT, false)) { final String values = preferences.getString( - PREF_READ_AHEAD, Helpers.readOneLine(READ_AHEAD_PATH)); - if (new File(READ_AHEAD_PATH).exists()) - sb.append("busybox echo ").append(values).append(" > ") - .append(READ_AHEAD_PATH).append(";\n"); + PREF_READ_AHEAD, Helpers.readOneLine(READ_AHEAD_PATH[0])); + for (String aREAD_AHEAD_PATH : READ_AHEAD_PATH) { + if (new File(aREAD_AHEAD_PATH).exists()) { + sb.append("busybox echo ").append(values).append(" > ") + .append(aREAD_AHEAD_PATH).append(";\n"); + } + } } if (FASTCHARGE_PATH != null) { diff --git a/src/com/brewcrewfoo/performance/util/CMDProcessor.java b/src/com/brewcrewfoo/performance/util/CMDProcessor.java index cf34e7fb..04cdead0 100644 --- a/src/com/brewcrewfoo/performance/util/CMDProcessor.java +++ b/src/com/brewcrewfoo/performance/util/CMDProcessor.java @@ -24,7 +24,9 @@ import java.io.DataOutputStream; import java.io.InputStream; -public class CMDProcessor implements Constants { +import static com.brewcrewfoo.performance.util.Constants.TAG; + +public class CMDProcessor { private Boolean can_su; public SH sh; diff --git a/src/com/brewcrewfoo/performance/util/CPUStateMonitor.java b/src/com/brewcrewfoo/performance/util/CPUStateMonitor.java index eed33572..b5e311e8 100644 --- a/src/com/brewcrewfoo/performance/util/CPUStateMonitor.java +++ b/src/com/brewcrewfoo/performance/util/CPUStateMonitor.java @@ -22,19 +22,13 @@ import android.os.SystemClock; import android.util.Log; -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -//@SuppressLint("UseSparseArrays") -public class CPUStateMonitor implements Constants { +import java.io.*; +import java.util.*; + +import static com.brewcrewfoo.performance.util.Constants.TIME_IN_STATE_OVERALL_PATH; +import static com.brewcrewfoo.performance.util.Constants.TIME_IN_STATE_PATH; + +public class CPUStateMonitor { private Map> mStates; private Map> mOffsets; diff --git a/src/com/brewcrewfoo/performance/util/Constants.java b/src/com/brewcrewfoo/performance/util/Constants.java index 1f83234a..072d181b 100644 --- a/src/com/brewcrewfoo/performance/util/Constants.java +++ b/src/com/brewcrewfoo/performance/util/Constants.java @@ -18,7 +18,7 @@ package com.brewcrewfoo.performance.util; -public interface Constants { +public class Constants { public static final String TAG = "PerformanceControl"; public static final String VERSION_NUM = "2.1.4-omni"; @@ -31,15 +31,13 @@ public interface Constants { public static final int FRAGMENT_ID_CPUSETTINGS = 0; public static final int FRAGMENT_ID_BATTERYINFO = 1; public static final int FRAGMENT_ID_OOMSETTINGS = 2; - public static final int FRAGMENT_ID_VM = 3; - public static final int FRAGMENT_ID_VOLTAGECONROL = 4; - public static final int FRAGMENT_ID_ADVANCED = 5; - public static final int FRAGMENT_ID_TIMEINSTATE = 6; - public static final int FRAGMENT_ID_WAKELOCKS = 7; - public static final int FRAGMENT_ID_CPUINFO = 8; - public static final int FRAGMENT_ID_DISKINFO = 9; - public static final int FRAGMENT_ID_TOOLS = 10; - + public static final int FRAGMENT_ID_ADVANCED = 3; + public static final int FRAGMENT_ID_TIMEINSTATE = 4; + public static final int FRAGMENT_ID_WAKELOCKS = 5; + public static final int FRAGMENT_ID_CPUINFO = 6; + public static final int FRAGMENT_ID_DISKINFO = 7; + public static final int FRAGMENT_ID_VOLTAGECONTROL = 8; + // CPU settings public static final String CPU_PATH = "/sys/devices/system/cpu/cpu"; public static final String CPU_FREQ_TAIL = "/cpufreq/scaling_cur_freq"; @@ -85,8 +83,7 @@ public interface Constants { // Other settings public static final String MINFREE_PATH = "/sys/module/lowmemorykiller/parameters/minfree"; public static final String MINFREE_ADJ_PATH = "/sys/module/lowmemorykiller/parameters/adj"; - public static final String READ_AHEAD_PATH = "/sys/block/mmcblk0/bdi/read_ahead_kb"; - //"/sys/devices/virtual/bdi/default/read_ahead_kb" + public static final String[] READ_AHEAD_PATH = {"/sys/block/mmcblk0/queue/read_ahead_kb", "/sys/block/mmcblk1/queue/read_ahead_kb"}; public static final String INTENT_ACTION_FASTCHARGE = "com.aokp.romcontrol.FCHARGE_CHANGED"; public static final String PREF_MINFREE = "pref_minfree"; diff --git a/src/com/brewcrewfoo/performance/util/Helpers.java b/src/com/brewcrewfoo/performance/util/Helpers.java index 01dfe230..ba1d813c 100644 --- a/src/com/brewcrewfoo/performance/util/Helpers.java +++ b/src/com/brewcrewfoo/performance/util/Helpers.java @@ -18,6 +18,8 @@ package com.brewcrewfoo.performance.util; +import static com.brewcrewfoo.performance.util.Constants.*; + import android.app.Activity; import android.content.Context; import android.content.res.AssetManager; @@ -40,7 +42,7 @@ import java.io.IOException; import java.io.InputStream; -public class Helpers implements Constants { +public class Helpers { private static String mVoltagePath; @@ -580,4 +582,8 @@ public static boolean isSystemApp(Context c) { public static boolean hasOverallStats() { return fileExists(TIME_IN_STATE_OVERALL_PATH); } + + public static boolean lowmemExists() { + return new File(MINFREE_PATH).exists(); + } } diff --git a/src/com/brewcrewfoo/performance/util/UnzipUtility.java b/src/com/brewcrewfoo/performance/util/UnzipUtility.java index da7ed981..04cc2cc6 100644 --- a/src/com/brewcrewfoo/performance/util/UnzipUtility.java +++ b/src/com/brewcrewfoo/performance/util/UnzipUtility.java @@ -1,17 +1,13 @@ package com.brewcrewfoo.performance.util; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; +import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; /** * Created by h0rn3t on 27.08.2013. */ -public class UnzipUtility implements Constants { +public class UnzipUtility { private static final int BUFFER_SIZE = 4096; public void unzipall(String zipFilePath, String destDirectory) throws IOException { diff --git a/src/com/brewcrewfoo/performance/util/Zram.java b/src/com/brewcrewfoo/performance/util/Zram.java index 98d6b9a5..1aa11952 100644 --- a/src/com/brewcrewfoo/performance/util/Zram.java +++ b/src/com/brewcrewfoo/performance/util/Zram.java @@ -1,9 +1,11 @@ package com.brewcrewfoo.performance.util; +import static com.brewcrewfoo.performance.util.Constants.*; + /** * Created by h0rn3t on 09.09.2013. */ -public class Zram implements Constants { +public class Zram { private int diskSize = 0; private int compressedDataSize = 0;