diff options
author | Sai Aitharaju <saia@codeaurora.org> | 2015-08-04 16:41:16 +0530 |
---|---|---|
committer | Matadeen Mishra <matade@codeaurora.org> | 2015-08-31 16:34:08 +0530 |
commit | 73a38875979d0642e25b25093da216b9f31da6ce (patch) | |
tree | 9c3dae42ef8cff9059c60630869f2446a9f3f562 /QLogging | |
parent | 49f1c98ea067422437338ff9c62ed9a144f6fd59 (diff) | |
download | android_packages_apps_BluetoothExt-73a38875979d0642e25b25093da216b9f31da6ce.tar.gz android_packages_apps_BluetoothExt-73a38875979d0642e25b25093da216b9f31da6ce.tar.bz2 android_packages_apps_BluetoothExt-73a38875979d0642e25b25093da216b9f31da6ce.zip |
BTLogKit: Added functionality to control BTLogSave
-- This patch enabled the BTLogKit app to start
the BTLogSave application which runs in the
background to capture logs.
Issue:
When BT is turned Off, BTLogKit application
stops as both BT and BTLogKit use the same
process id.
Fix:
With another background process BTLogSave,
controlled by BTLogKit, log capturing continues
independent of BT turn On/Off.
CRs-Fixed: 885022
Change-Id: I0fd01ec0d2cdbd4017df2683d8d01cc5ccbd6c0d
Diffstat (limited to 'QLogging')
-rw-r--r-- | QLogging/AndroidManifest.xml | 3 | ||||
-rw-r--r-- | QLogging/jni/com_android_qlogging_sendIntent.cpp | 23 | ||||
-rw-r--r-- | QLogging/res/menu/menu_main.xml | 36 | ||||
-rw-r--r-- | QLogging/res/values/dimens.xml | 1 | ||||
-rw-r--r-- | QLogging/res/values/strings.xml | 8 | ||||
-rw-r--r-- | QLogging/src/com/android/qlogging/BTStateReceiver.java | 252 | ||||
-rw-r--r-- | QLogging/src/com/android/qlogging/Main.java | 72 | ||||
-rw-r--r-- | QLogging/src/com/android/qlogging/StackOptionsView.java | 8 | ||||
-rw-r--r-- | QLogging/src/com/android/qlogging/Utils.java | 104 | ||||
-rw-r--r-- | QLogging/src/com/android/qlogging/getSecondoryOptions.java | 42 |
10 files changed, 249 insertions, 300 deletions
diff --git a/QLogging/AndroidManifest.xml b/QLogging/AndroidManifest.xml index d86c532..6abf32b 100644 --- a/QLogging/AndroidManifest.xml +++ b/QLogging/AndroidManifest.xml @@ -69,6 +69,9 @@ <intent-filter> <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" /> </intent-filter> + <intent-filter> + <action android:name="BTLogSaveIntent" /> + </intent-filter> </receiver> </application> diff --git a/QLogging/jni/com_android_qlogging_sendIntent.cpp b/QLogging/jni/com_android_qlogging_sendIntent.cpp index 7e11777..1b4ccc9 100644 --- a/QLogging/jni/com_android_qlogging_sendIntent.cpp +++ b/QLogging/jni/com_android_qlogging_sendIntent.cpp @@ -95,11 +95,11 @@ static void setLogging(JNIEnv* env, jclass clazz,jstring jlog_layer, jint log_le ALOGE("Error loading Stack Log Interface"); } else{ + uint8_t values[7] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06}; const char *log_layer = env->GetStringUTFChars(jlog_layer, 0); if ( module == 3 ) { ALOGD("Setting SOC log levels."); - uint8_t values[7] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06}; uint8_t set_level = 0x00; int index = log_layer[0]-'0'; if (log_level == 0) @@ -113,24 +113,27 @@ static void setLogging(JNIEnv* env, jclass clazz,jstring jlog_layer, jint log_le else if( module == 4) { ALOGD("Setting all SOC log levels."); - const char *log_level = env->GetStringUTFChars(jlog_layer,0); - uint8_t values[7] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06}; - if (log_level[0] == 'F')/* Setting All Levels to Off.*/ + uint8_t enable_SOC[5] = {0x10,0x03,0x00,0x00,0x01}; + uint8_t disable_SOC[5] = {0x10,0x02,0x00,0x00,0x01}; + const char *all_log_levels = env->GetStringUTFChars(jlog_layer,0); + if (all_log_levels[0] == 'F')/* Setting All Levels to Off.*/ { - uint8_t param[5] = {0x10,0x02,0x00,0x00,0x01}; - sBluetoothInterface->hci_cmd_send(HCI_OPCODE_PACK(0x3F,0x17),param,5); + sBluetoothInterface->hci_cmd_send(HCI_OPCODE_PACK(0x3F,0x17),disable_SOC,5); } - else{ - /* Setting each SOC Layer */ + else + { + /* Enable SOC Logs */ + sBluetoothInterface->hci_cmd_send(HCI_OPCODE_PACK(0x3F,0x17),enable_SOC,5); int index[7]; uint8_t param[15]; param[0]= 0x11; for(int i=0;i<7;i++){ - index[i]=log_level[i]-'0'; param[2*i+1] = values[i]; + index[i]=all_log_levels[i]-'0'; if (index[i] == 0) param[2*i+2] = 0xF; - param[2*i+2] = values[index[i]]; + else + param[2*i+2] = values[index[i]-1]; } sBluetoothInterface->hci_cmd_send(HCI_OPCODE_PACK(0x3F,0x17),param,15); } diff --git a/QLogging/res/menu/menu_main.xml b/QLogging/res/menu/menu_main.xml index d0594f4..1d4c9be 100644 --- a/QLogging/res/menu/menu_main.xml +++ b/QLogging/res/menu/menu_main.xml @@ -33,21 +33,29 @@ <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" - xmlns:tools="http://schemas.android.com/tools" tools:context=".Main"> +xmlns:tools="http://schemas.android.com/tools" tools:context=".Main"> <item - android:id="@+id/action_save_log_btn_start" - android:icon="@android:drawable/ic_media_play" - android:title="@string/log_save_start"/> + android:id="@+id/action_save_log_btn_start" + android:icon="@android:drawable/ic_media_play" + android:title="@string/log_save_start"/> <item - android:id="@+id/action_save_log_btn_stop" - android:icon="@android:drawable/ic_media_pause" - android:title="@string/log_save_stop"/> -<!-- <item - android:id="@+id/action_btlog_filter" - android:actionViewClass="android.widget.Switch" + android:id="@+id/action_save_log_btn_stop" + android:icon="@android:drawable/ic_media_pause" + android:title="@string/log_save_stop"/> + <item + android:id="@+id/action_log_file_title" + android:showAsAction="always" + android:actionViewClass="android.widget.TextView"/> + <item + android:id="@+id/action_log_file_size" + android:showAsAction="always" + android:actionViewClass="android.widget.Spinner"/> + <!-- <item + android:id="@+id/action_btlog_filter" + android:actionViewClass="android.widget.Switch" />--> <item android:id="@+id/action_settings" - android:title="@string/action_settings" - android:orderInCategory="100" /> -<!--app:showAsAction="never" />--> -</menu> + android:title="@string/action_settings" + android:orderInCategory="100" /> + <!--app:showAsAction="never" />--> + </menu> diff --git a/QLogging/res/values/dimens.xml b/QLogging/res/values/dimens.xml index 102b27d..7f6ac36 100644 --- a/QLogging/res/values/dimens.xml +++ b/QLogging/res/values/dimens.xml @@ -35,6 +35,7 @@ <!-- Default screen margins, per the Android Design guidelines. --> <dimen name="ring_radius">60dp</dimen> <dimen name="ring_thickness">1dp</dimen> + <dimen name="textsize_large">10sp</dimen> <dimen name="activity_horizontal_margin">16dp</dimen> <dimen name="activity_vertical_margin">16dp</dimen> </resources> diff --git a/QLogging/res/values/strings.xml b/QLogging/res/values/strings.xml index 627b8fd..d2c1670 100644 --- a/QLogging/res/values/strings.xml +++ b/QLogging/res/values/strings.xml @@ -130,7 +130,7 @@ <item>TRC_BTM</item> <item>TRC_HCI</item> <item>TRC_L2CAP</item> - <item>TRC_RFCOMM></item> + <item>TRC_RFCOMM</item> <item>TRC_AVCT</item> <item>TRC_AVDT</item> <item>TRC_AVRC</item> @@ -194,4 +194,10 @@ <item>2</item> </string-array> + <string-array name="log_file_size_options"> + <item>20</item> + <item>100</item> + <item>500</item> + </string-array> + </resources> diff --git a/QLogging/src/com/android/qlogging/BTStateReceiver.java b/QLogging/src/com/android/qlogging/BTStateReceiver.java index 3acec45..b9fe2be 100644 --- a/QLogging/src/com/android/qlogging/BTStateReceiver.java +++ b/QLogging/src/com/android/qlogging/BTStateReceiver.java @@ -43,193 +43,103 @@ import android.widget.Space; import android.widget.Spinner; import android.widget.Toast; import android.widget.ToggleButton; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.view.View; +import android.view.ViewGroup; +import android.os.Handler; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.lang.ProcessBuilder; +import java.lang.Exception; +import java.util.Scanner; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.lang.reflect.Field; +import java.lang.Runnable; import android.content.pm.PackageManager; public class BTStateReceiver extends BroadcastReceiver{ - @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); Toast toast; - if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { - final int btstate = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); - switch (btstate) { - case BluetoothAdapter.STATE_OFF: - break; - case BluetoothAdapter.STATE_TURNING_OFF: - //Utils.saveCurrentState(context); - break; - case BluetoothAdapter.STATE_ON: - Map map; - int counter = 0; - String[] profile_tags = context.getResources().getStringArray(R.array.profile_list_tags); - String[] stack_list_names = context.getResources().getStringArray(R.array.stack_list_names); - String[] stack_list_tags = context.getResources().getStringArray(R.array.stack_list_tags); - String[] soc_list_names = context.getResources().getStringArray(R.array.soc_list_names); - String[] soc_list_tags = context.getResources().getStringArray(R.array.soc_list_tags); + final int btstate = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); + switch (btstate) { + case BluetoothAdapter.STATE_OFF: + break; + case BluetoothAdapter.STATE_TURNING_OFF: + break; + case BluetoothAdapter.STATE_ON: + Map map; + int counter = 0; + Utils.setGlobalSettings(context); + String[] profile_tags = context.getResources().getStringArray(R.array.profile_list_tags); + String[] stack_list_names = context.getResources().getStringArray(R.array.stack_list_names); + String[] stack_list_tags = context.getResources().getStringArray(R.array.stack_list_tags); + String[] soc_list_names = context.getResources().getStringArray(R.array.soc_list_names); + String[] soc_list_tags = context.getResources().getStringArray(R.array.soc_list_tags); + map = Utils.getPreviousSettings(context, Main.STACK_MODULE_ID); + if (!map.isEmpty()) { + for (String stack : stack_list_names) { + Object state_obj = map.get(stack); + if (state_obj != null) { + String state = state_obj.toString(); + int presState = Character.getNumericValue(state.charAt(2)); + sendIntent.transmitIntent(context, presState, stack_list_tags[counter], Main.STACK_MODULE_ID); + counter++; + } + } + } + else + Log.d(Main.TAG,"Map empty for Stack"); - switch (getSecondoryOptions.selected) { - case 0: - Log.d(Main.TAG,"In Main activity,and BT turned on"); - /*map = Utils.getPreviousSettings(context, Main.PROFILE_MODULE_ID); - if (!map.isEmpty()) { - for (String profile : profile_tags) { - String state = map.get(profile).toString(); - int presState = Character.getNumericValue(state.charAt(1)); - sendIntent.transmitIntent(context, presState, profile, getSecondoryOptions.selected); - } - }*/ //TODO:send profiles states - map = Utils.getPreviousSettings(context, Main.STACK_MODULE_ID); - counter = 0; - if (!map.isEmpty()) { - for (String stack : stack_list_names) { - Object state_obj = map.get(stack); - if (state_obj != null) { - String state = state_obj.toString(); - int presState = Character.getNumericValue(state.charAt(2)); - sendIntent.transmitIntent(context, presState, stack_list_tags[counter], Main.STACK_MODULE_ID); - counter++; - } - } - } - map = Utils.getPreviousSettings(context, Main.SOC_MODULE_ID); - counter = 0; - getSecondoryOptions.SOC_levels=""; - if (!map.isEmpty()) { - for (String soc : soc_list_names) { - Object state_obj = map.get(soc); - if (state_obj != null) { - String state = state_obj.toString(); - int presState = Character.getNumericValue(state.charAt(2)); - getSecondoryOptions.SOC_levels+=String.valueOf(presState); - counter++; - }else{ - getSecondoryOptions.SOC_levels+=String.valueOf(0); - } - } - sendIntent.transmitIntent(context, Main.SOC_ALL_MODULE_ID, getSecondoryOptions.SOC_levels, Main.SOC_ALL_MODULE_ID); - }else{ - Log.d(Main.TAG,"Map empty for SOC"); - } - break; - case Main.PROFILE_MODULE_ID: - /*Log.d(Main.TAG,"In Main activity,and BT turned on"); - for (String profile : profile_tags) { - ProfileOptionsView profileOptionsView = (ProfileOptionsView) getSecondoryOptions.lv.findViewWithTag(profile); - int presState = profileOptionsView.state; - sendIntent.transmitIntent(context, presState, profile, getSecondoryOptions.selected); - }*///TODO:Sending Profiles state - map = Utils.getPreviousSettings(context, Main.STACK_MODULE_ID); - counter = 0; - if (!map.isEmpty()) { - for (String stack : stack_list_names) { - Object state_obj = map.get(stack); - if (state_obj != null) { - String state = state_obj.toString(); - int presState = Character.getNumericValue(state.charAt(2)); - sendIntent.transmitIntent(context, presState, stack_list_tags[counter], Main.STACK_MODULE_ID); - counter++; - } - } - } - map = Utils.getPreviousSettings(context, Main.SOC_MODULE_ID); - counter = 0; - getSecondoryOptions.SOC_levels=""; - if (!map.isEmpty()) { - for (String soc : soc_list_names) { - Object state_obj = map.get(soc); - if (state_obj != null) { - String state = state_obj.toString(); - int presState = Character.getNumericValue(state.charAt(2)); - getSecondoryOptions.SOC_levels+=String.valueOf(presState); - counter++; - }else{ - getSecondoryOptions.SOC_levels+=String.valueOf(0); - } - } - sendIntent.transmitIntent(context, Main.SOC_ALL_MODULE_ID, getSecondoryOptions.SOC_levels, Main.SOC_ALL_MODULE_ID); - } - break; - case Main.STACK_MODULE_ID: - /*Log.d(Main.TAG,"In Main activity,and BT turned on"); - map = Utils.getPreviousSettings(context, Main.PROFILE_MODULE_ID); - if (!map.isEmpty()) { - for (String profile : profile_tags) { - String state = map.get(profile).toString(); - int presState = Character.getNumericValue(state.charAt(1)); - sendIntent.transmitIntent(context, presState, profile, getSecondoryOptions.selected); - } - }*///TODO:Sending Profiles state - counter = 0; - for (String stack : stack_list_names) { - StackOptionsView stackOptionsView = (StackOptionsView) getSecondoryOptions.lv.findViewWithTag(stack_list_tags[counter]); - int presState = stackOptionsView.state; - sendIntent.transmitIntent(context, presState, stack_list_tags[counter], Main.STACK_MODULE_ID); - counter++; - } - map = Utils.getPreviousSettings(context, Main.SOC_MODULE_ID); - counter = 0; - getSecondoryOptions.SOC_levels=""; - if (!map.isEmpty()) { - for (String soc : soc_list_names) { - Object state_obj = map.get(soc); - if (state_obj != null) { - String state = state_obj.toString(); - int presState = Character.getNumericValue(state.charAt(2)); - getSecondoryOptions.SOC_levels+=String.valueOf(presState); - counter++; - }else{ - getSecondoryOptions.SOC_levels+=String.valueOf(0); - } - } - sendIntent.transmitIntent(context, Main.SOC_ALL_MODULE_ID, getSecondoryOptions.SOC_levels, Main.SOC_ALL_MODULE_ID); - } - break; - case Main.SOC_MODULE_ID: - /*Log.d(Main.TAG,"In Main activity,and BT turned on"); - map = Utils.getPreviousSettings(context, Main.PROFILE_MODULE_ID); - if (!map.isEmpty()) { - for (String profile : profile_tags) { - if (map.get(profile)) { - String state = map.get(profile).toString(); - int presState = Character.getNumericValue(state.charAt(1)); - sendIntent.transmitIntent(context, presState, profile, getSecondoryOptions.selected); - } - } - }*///TODO:Sending Profile State - map = Utils.getPreviousSettings(context, Main.STACK_MODULE_ID); - counter = 0; - if (!map.isEmpty()) { - for (String stack : stack_list_names) { - Object state_obj = map.get(stack); - if (state_obj != null) { - String state = state_obj.toString(); - int presState = Character.getNumericValue(state.charAt(2)); - sendIntent.transmitIntent(context, presState, stack_list_tags[counter], Main.STACK_MODULE_ID); - counter++; - } - } - } - counter = 0; - getSecondoryOptions.SOC_levels=""; - for (String soc : soc_list_names) { - StackOptionsView stackOptionsView = (StackOptionsView) getSecondoryOptions.lv.findViewWithTag(soc_list_tags[counter]); - int presState = stackOptionsView.state; - getSecondoryOptions.SOC_levels=String.valueOf(presState); + map = Utils.getPreviousSettings(context, Main.SOC_MODULE_ID); + if (!Main.soc_log_enabled) + { + sendIntent.transmitIntent(context, 0, "F", Main.SOC_ALL_MODULE_ID); + } + else + { + getSecondoryOptions.SOC_levels=""; + counter = 0; + if (!map.isEmpty()) + { + for (String soc : soc_list_names) + { + Object state_obj = map.get(soc); + if (state_obj != null) + { + String state = state_obj.toString(); + int presState = Character.getNumericValue(state.charAt(2)); + getSecondoryOptions.SOC_levels+=String.valueOf(presState); counter++; + }else{ + getSecondoryOptions.SOC_levels+=String.valueOf(0); } - sendIntent.transmitIntent(context, Main.SOC_ALL_MODULE_ID, getSecondoryOptions.SOC_levels, Main.SOC_ALL_MODULE_ID); - break; + } + sendIntent.transmitIntent(context, Main.SOC_ALL_MODULE_ID, getSecondoryOptions.SOC_levels, Main.SOC_ALL_MODULE_ID); } - break; - case BluetoothAdapter.STATE_TURNING_ON: - break; - } + else + Log.d(Main.TAG,"Map empty for SOC"); + } + break; + case BluetoothAdapter.STATE_TURNING_ON: + break; } } } diff --git a/QLogging/src/com/android/qlogging/Main.java b/QLogging/src/com/android/qlogging/Main.java index dab015a..3e18166 100644 --- a/QLogging/src/com/android/qlogging/Main.java +++ b/QLogging/src/com/android/qlogging/Main.java @@ -44,7 +44,12 @@ import android.view.View; import android.widget.Toast; import android.widget.Switch; import android.widget.CompoundButton; - +import android.content.pm.PackageManager; +import android.content.ComponentName; +import android.widget.TextView; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Spinner; public class Main extends Activity { /* Class to handle the Main activity @@ -52,18 +57,31 @@ Class to handle the Main activity public final static String TAG = "QLoggingDebug"; public static boolean isLogging=false; private Menu menu; - public static boolean stack_set_all=false; - public static boolean bt_log_filter=false; - public static boolean soc_log_enabled = true; - public final static int PROFILE_MODULE_ID=1; - public final static int STACK_MODULE_ID=2; - public final static int SOC_MODULE_ID=3; - public final static int SOC_ALL_MODULE_ID=4; + public static boolean stack_set_all = false; + public static boolean bt_log_filter = false; + public static boolean soc_log_enabled = false; + public final static int PROFILE_MODULE_ID = 1; + public final static int STACK_MODULE_ID = 2; + public final static int SOC_MODULE_ID = 3; + public final static int SOC_ALL_MODULE_ID = 4; + public static int log_file_size = 100; + public static int size_pos = 1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + if(!Utils.isAppRunning(getApplicationContext(),"org.codeaurora.bluetooth.btlogsave")){ + Log.d(TAG,"Opening BtLogSave app"); + Intent nextIntent = new Intent(Intent.ACTION_MAIN); + nextIntent.setComponent(new ComponentName("org.codeaurora.bluetooth.btlogsave","org.codeaurora.bluetooth.btlogsave.Main")); + startActivity(nextIntent); + Intent intent = new Intent(); + intent.setAction("BTLogSaveIntent"); + intent.putExtra(Intent.EXTRA_TEXT, "LOG_FILE_SIZE"); + intent.putExtra("FILE_SIZE", String.valueOf(log_file_size)); + sendBroadcast(intent); + } //If the app isnt already installed, create the default settings files //with the default log levels. SharedPreferences ratePrefs = getSharedPreferences("First Update", 0); @@ -115,6 +133,44 @@ Class to handle the Main activity }); log_filter_switch.setChecked(bt_log_filter);*/ + MenuItem menuItem_log_file_title = menu.findItem(R.id.action_log_file_title); + menuItem_log_file_title.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); + + TextView log_file_title = (TextView) menuItem_log_file_title.getActionView(); + log_file_title.setText("Size(MB):"); + + MenuItem menuItem_log_file_size = menu.findItem(R.id.action_log_file_size); + menuItem_log_file_size.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); + + Spinner spinner = (Spinner) menuItem_log_file_size.getActionView(); + + ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.log_file_size_options, R.layout.spinner_item); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + + spinner.setAdapter(adapter); + + spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { + Intent intent = new Intent(); + intent.setAction("BTLogSaveIntent"); + intent.putExtra(Intent.EXTRA_TEXT, "LOG_FILE_SIZE"); + intent.putExtra("FILE_SIZE", parent.getItemAtPosition(position).toString()); + getApplicationContext().sendBroadcast(intent); + log_file_size = Integer.valueOf(parent.getItemAtPosition(position).toString()); + size_pos = position; + Utils.saveGlobalState(getApplicationContext()); + } + + @Override + public void onNothingSelected(AdapterView<?> parent) { + + } + }); + + spinner.setSelection(size_pos); + + this.menu=menu; return true; } diff --git a/QLogging/src/com/android/qlogging/StackOptionsView.java b/QLogging/src/com/android/qlogging/StackOptionsView.java index 4479272..e5590ea 100644 --- a/QLogging/src/com/android/qlogging/StackOptionsView.java +++ b/QLogging/src/com/android/qlogging/StackOptionsView.java @@ -122,16 +122,15 @@ public class StackOptionsView extends LinearLayout { checkBox.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { + getSecondoryOptions.init_soc = 0; if (!checkBox.isChecked()) { prevState = state; state = 0; spinner.setSelection(0); - sendIntent.transmitIntent(getContext(), state, getTag().toString(), optionSelected); } else { //state = spinner.getSelectedItemPosition() + 1; state = prevState; spinner.setSelection(state); - sendIntent.transmitIntent(getContext(), state, getTag().toString(), optionSelected); } } }); @@ -144,9 +143,10 @@ public class StackOptionsView extends LinearLayout { prevState=state; checkBox.setChecked(false); } - state = position; - sendIntent.transmitIntent(getContext(), state, getTag().toString(), optionSelected); } + state = position; + if (getSecondoryOptions.init_soc == 0) + sendIntent.transmitIntent(getContext(), state, getTag().toString(), optionSelected); } @Override diff --git a/QLogging/src/com/android/qlogging/Utils.java b/QLogging/src/com/android/qlogging/Utils.java index 88b73f7..b637683 100644 --- a/QLogging/src/com/android/qlogging/Utils.java +++ b/QLogging/src/com/android/qlogging/Utils.java @@ -39,6 +39,7 @@ import android.util.Xml; import android.widget.LinearLayout; import android.widget.Toast; import android.view.View; +import android.content.Intent; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -70,32 +71,16 @@ public class Utils { private static String pid; private static String timestamp; private static String filesDir; + private static Intent intent; public static void startLogging(Context context){ + //Called when the start logging button is clicked - try{ - filesDir = context.getFilesDir().getAbsolutePath(); - String cmd_clear[] = {"/system/bin/sh", "-c", "logcat -c"}; - p = Runtime.getRuntime().exec(cmd_clear); - p.waitFor(); - p.destroy(); - if(Main.bt_log_filter){ - int bt_id = android.os.Process.myPid(); - //String cmd_start[] = {"/system/bin/sh", "-c", "logcat -v threadtime | grep "+String.valueOf(bt_id)+" | dd of="+filesDir+"/log.txt"}; - //p = Runtime.getRuntime().exec(cmd_start); - //ProcessBuilder builder = new ProcessBuilder("/system/bin/sh", "-c", "logcat -v threadtime | grep "+String.valueOf(bt_id)+" | dd of="+filesDir+"/log.txt"); - ProcessBuilder builder = new ProcessBuilder("/system/bin/sh", "-c", "logcat -v threadtime | grep "+String.valueOf(bt_id)+" > "+filesDir+"/log.txt"); - p = builder.start(); - Toast.makeText(context,String.valueOf(getPid(p)),Toast.LENGTH_LONG).show(); - }else{ - String cmd_start[] = {"/system/bin/sh", "-c", "logcat -v threadtime -f "+filesDir+"/log.txt"}; - p = Runtime.getRuntime().exec(cmd_start); - } - }catch(IOException e){ - Log.e(Main.TAG,e.toString()); - }catch(InterruptedException e){ - Log.e(Main.TAG,e.toString()); - } + + intent = new Intent(); + intent.setAction("BTLogSaveIntent"); + intent.putExtra(Intent.EXTRA_TEXT, "START"); + context.sendBroadcast(intent); } public static int getPid(Process process) { @@ -110,47 +95,13 @@ public class Utils { } public static void stopLogging(Context context){ + //Called when the stop logging button is clicked - try{ - filesDir = context.getFilesDir().getAbsolutePath(); - if(p!=null){ - p.destroy(); - Toast toast = Toast.makeText(context,"Log stored in "+filesDir,Toast.LENGTH_LONG); - toast.show(); - } - Calendar cal = Calendar.getInstance(); - DateFormat df = new SimpleDateFormat("MM-dd-HH-mm-ss-SSS"); - cal.setTimeInMillis(System.currentTimeMillis()); - timestamp = df.format(cal.getTime()); - process = Runtime.getRuntime().exec("mv "+filesDir+"/log.txt "+filesDir+"/"+timestamp+"_log.txt"); - process.waitFor(); - process.destroy(); - /*if(Main.bt_log_filter){ - int bt_id = android.os.Process.myPid(); - Toast toast = Toast.makeText(context,String.valueOf(bt_id),Toast.LENGTH_SHORT); - toast.show(); - Scanner scanner = new Scanner(filesDir+"/"+timestamp+"_log.txt"); - File filtered_file = new File(filesDir,timestamp+"_log_filtered.txt"); - FileOutputStream f = new FileOutputStream(filtered_file); - PrintWriter pw = new PrintWriter(f); - while(scanner.hasNextLine()){ - String newLine = scanner.nextLine(); - Log.e(Main.TAG,newLine); - if(newLine.contains(String.valueOf(bt_id))){ - pw.println(newLine); - } - } - pw.flush(); - pw.close(); - f.close(); - }*/ - }catch (FileNotFoundException e) { - Log.e(Main.TAG,e.toString()); - }catch(IOException e){ - Log.e(Main.TAG,e.toString()); - }catch(InterruptedException e){ - Log.e(Main.TAG,e.toString()); - } + + intent = new Intent(); + intent.setAction("BTLogSaveIntent"); + intent.putExtra(Intent.EXTRA_TEXT, "STOP"); + context.sendBroadcast(intent); } public static Map<String, String> parseXML(XmlPullParser parser) throws XmlPullParserException, IOException { @@ -163,7 +114,6 @@ public class Utils { switch (eventType) { case XmlPullParser.START_DOCUMENT: - Log.v(Main.TAG, "Start of the document"); break; case XmlPullParser.START_TAG: name = parser.getName(); @@ -174,7 +124,7 @@ public class Utils { prevState = parser.nextText(); } else if (name.equalsIgnoreCase("prevState2")) { prevState2 = parser.nextText(); - Log.v(Main.TAG, title + presState + prevState); + //Log.v(Main.TAG, title + presState + prevState); map.put(title, prevState + prevState2 + presState); } else { title = name; @@ -183,7 +133,6 @@ public class Utils { break; case XmlPullParser.END_TAG: name = parser.getName(); - Log.d(Main.TAG, "Reading document over"); } eventType = parser.next(); } @@ -273,7 +222,7 @@ public class Utils { } else { xmlSerializer.startTag(null, list_names[counter]); stackOptionsView = (StackOptionsView) lv.findViewWithTag(list_tags[counter]); - Log.v(Main.TAG, "XML----" + list_names[counter] + String.valueOf(stackOptionsView.prevState) + String.valueOf(stackOptionsView.prevState2) + String.valueOf(stackOptionsView.state)); + //Log.v(Main.TAG, "XML----" + list_names[counter] + String.valueOf(stackOptionsView.prevState) + String.valueOf(stackOptionsView.prevState2) + String.valueOf(stackOptionsView.state)); xmlSerializer.startTag(null, "presentState"); xmlSerializer.text(String.valueOf(stackOptionsView.state)); xmlSerializer.endTag(null, "presentState"); @@ -340,6 +289,9 @@ public class Utils { xmlSerializer.startTag(null,"Stack_all"); xmlSerializer.text(String.valueOf(Main.stack_set_all)); xmlSerializer.endTag(null,"Stack_all"); + xmlSerializer.startTag(null,"log_file_size_pos"); + xmlSerializer.text(String.valueOf(Main.size_pos)); + xmlSerializer.endTag(null,"log_file_size_pos"); xmlSerializer.startTag(null,"bt_log_filter"); xmlSerializer.text(String.valueOf(Main.bt_log_filter)); xmlSerializer.endTag(null,"bt_log_filter"); @@ -371,17 +323,13 @@ public class Utils { } } - public static boolean isAppRunning(Context context) { - String activity = Main.class.getName(); - ActivityManager activityManager = (ActivityManager) context. - getSystemService(Context.ACTIVITY_SERVICE); - - List<ActivityManager.RunningTaskInfo> tasks = activityManager. - getRunningTasks(Integer.MAX_VALUE); + public static boolean isAppRunning(Context context, String appName) { + ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); + List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses(); - for (ActivityManager.RunningTaskInfo task : tasks) { - if (activity.equals(task.baseActivity.getClassName())) { - return true; + for (int i = 0; i < runningAppProcessInfo.size(); i++) { + if(runningAppProcessInfo.get(i).processName.equals(appName)) { + return true; } } return false; @@ -416,6 +364,8 @@ public class Utils { Main.bt_log_filter = Boolean.valueOf(parser.nextText()); } else if (name.equalsIgnoreCase("Stack_all")) { Main.stack_set_all = Boolean.valueOf(parser.nextText()); + } else if (name.equalsIgnoreCase("log_file_size_pos")) { + Main.size_pos = Integer.valueOf(parser.nextText()); } } break; diff --git a/QLogging/src/com/android/qlogging/getSecondoryOptions.java b/QLogging/src/com/android/qlogging/getSecondoryOptions.java index 9dead5b..dbfe34a 100644 --- a/QLogging/src/com/android/qlogging/getSecondoryOptions.java +++ b/QLogging/src/com/android/qlogging/getSecondoryOptions.java @@ -59,7 +59,9 @@ public class getSecondoryOptions extends Activity{ */ private Menu menu; public static int selected=0; + public static int init_soc = 0; public static LinearLayout lv; + public static ScrollView sv; public static String SOC_levels=""; @Override @@ -67,12 +69,13 @@ public class getSecondoryOptions extends Activity{ super.onCreate(savedInstanceState); Intent intent = getIntent(); - String titlebarHeading = "Noting yet"; + String titlebarHeading = "Nothing yet"; selected = intent.getFlags(); setContentView(R.layout.activity_get_secondory_options); lv = (LinearLayout) findViewById(R.id.outer_box); + sv = (ScrollView) findViewById(R.id.outer_scroll_box); lv.setTag(selected); lv.removeAllViews(); @@ -91,7 +94,7 @@ public class getSecondoryOptions extends Activity{ int counter=0; for (String profile:profile_list) { ProfileOptionsView profileOptionsView = new ProfileOptionsView(this); - profileOptionsView.setTag(profile_tags[counter]); + profileOptionsView.setTag(profile_tags[counter]); CheckBox checkBox = (CheckBox) profileOptionsView.getChildAt(0); checkBox.setText(profile); if(!map.isEmpty()) { @@ -139,12 +142,11 @@ public class getSecondoryOptions extends Activity{ if (state_obj != null) { String state= state_obj.toString(); + init_soc = 1; stackOptionsView.setState(state); + init_soc = 0; int presState = Character.getNumericValue(state.charAt(2)); - Log.d(Main.TAG,"Sending present state in stack/SOC"); - if(selected==Main.STACK_MODULE_ID){ - sendIntent.transmitIntent(this, presState, list_tags[counter], selected); - }else{ + if(selected==Main.SOC_MODULE_ID){ SOC_levels+=String.valueOf(presState); } } @@ -160,7 +162,6 @@ public class getSecondoryOptions extends Activity{ }else if(selected==Main.SOC_MODULE_ID){ if(Main.soc_log_enabled){ lv.setVisibility(View.VISIBLE); - sendIntent.transmitIntent(this, 0, SOC_levels, Main.SOC_ALL_MODULE_ID); }else{ lv.setVisibility(View.GONE); sendIntent.transmitIntent(this, 0, "F", Main.SOC_ALL_MODULE_ID); @@ -205,21 +206,26 @@ public class getSecondoryOptions extends Activity{ Switch soc_switch = (Switch) menuItem_soc_enable.getActionView(); soc_switch.setTextOn("On"); soc_switch.setTextOff("Off"); + final TextView tv = new TextView(getApplicationContext()); + tv.setText("Enable SOC logging for options"); + tv.setTextSize(getResources().getDimension(R.dimen.textsize_large)); soc_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - TextView textView; + sv.removeAllViews(); if(isChecked){ lv.setVisibility(View.VISIBLE); + sv.addView(lv); Main.soc_log_enabled=true; Utils.saveGlobalState(getApplicationContext()); Toast.makeText(getApplicationContext(), "SOC logging turned on", Toast.LENGTH_SHORT).show(); sendIntent.transmitIntent(getApplicationContext(), 0, SOC_levels, Main.SOC_ALL_MODULE_ID); + init_soc = 1; }else{ Utils.saveCurrentState(getApplicationContext()); - textView = new TextView(getApplicationContext()); - textView.setText("SOC Logging is disabled, enable to see the log options"); lv.setVisibility(View.GONE); + sv.addView(tv); + tv.setVisibility(View.VISIBLE); Main.soc_log_enabled=false; Utils.saveGlobalState(getApplicationContext()); sendIntent.transmitIntent(getApplicationContext(), 0, "F", Main.SOC_ALL_MODULE_ID); @@ -227,6 +233,10 @@ public class getSecondoryOptions extends Activity{ } }); soc_switch.setChecked(Main.soc_log_enabled); + if(!Main.soc_log_enabled){ + sv.removeAllViews(); + sv.addView(tv); + } }else{ menuItem_soc_enable.setVisible(false); } @@ -243,7 +253,6 @@ public class getSecondoryOptions extends Activity{ this.menu=menu; return super.onCreateOptionsMenu(menu); - //return true; } @Override @@ -288,8 +297,6 @@ public class getSecondoryOptions extends Activity{ checkBox.setChecked(true); spinner.setSelection(stackOptionsView.state); } - sendIntent.transmitIntent(this, stackOptionsView.state, stack, selected); - Log.v(Main.TAG, "Revert----" + stack + String.valueOf(stackOptionsView.prevState) + String.valueOf(stackOptionsView.prevState2) + String.valueOf(stackOptionsView.state)); } Main.stack_set_all=false; Utils.saveGlobalState(getApplicationContext()); @@ -304,8 +311,6 @@ public class getSecondoryOptions extends Activity{ Spinner spinner = (Spinner) stackOptionsView.getChildAt(2); checkBox.setChecked(true); spinner.setSelection(6); - sendIntent.transmitIntent(this, stackOptionsView.state, stack, selected); - Log.v(Main.TAG, "Verbose----" + stack + String.valueOf(stackOptionsView.prevState) + String.valueOf(stackOptionsView.prevState2) + String.valueOf(stackOptionsView.state)); } Main.stack_set_all=true; Utils.saveGlobalState(getApplicationContext()); @@ -322,6 +327,13 @@ public class getSecondoryOptions extends Activity{ Utils.saveCurrentState(getApplicationContext()); selected=0; } + + @Override + public void onPause() { + super.onPause(); + Log.d(Main.TAG, "In getSecondaryOptions ONPAUSE"); + Utils.saveCurrentState(getApplicationContext()); + } } |