Added log collect feature

This commit is contained in:
Sylvain Berfini 2013-05-29 11:43:08 +02:00
parent 621eb9f5ec
commit 58c85d0675
4 changed files with 51 additions and 2 deletions

View file

@ -55,6 +55,7 @@
<bool name="hash_images_as_name_before_upload">true</bool> <bool name="hash_images_as_name_before_upload">true</bool>
<bool name="enable_log_collect">false</bool>
<bool name="disable_every_log">false</bool> <bool name="disable_every_log">false</bool>
<bool name="disable_all_security_features_for_markets">false</bool> <!-- Disable TLS/SRTP/ZRTP --> <bool name="disable_all_security_features_for_markets">false</bool> <!-- Disable TLS/SRTP/ZRTP -->
<bool name="disable_all_patented_codecs_for_markets">false</bool> <!-- Disable MPEG4/H264 --> <bool name="disable_all_patented_codecs_for_markets">false</bool> <!-- Disable MPEG4/H264 -->

View file

@ -69,7 +69,12 @@ public class AboutFragment extends Fragment implements OnClickListener {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (LinphoneActivity.isInstanciated()) { if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().exit();
if (getResources().getBoolean(R.bool.enable_log_collect)) {
LinphoneUtils.collectLogs(getString(R.string.app_name), getString(R.string.about_bugreport_email));
} else {
LinphoneActivity.instance().exit();
}
} }
} }
} }

View file

@ -192,6 +192,10 @@ public class LinphoneManager implements LinphoneCoreListener {
mConnectivityManager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); mConnectivityManager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
mR = c.getResources(); mR = c.getResources();
if (mR.getBoolean(R.bool.enable_log_collect)) {
LinphoneUtils.clearLogs();
}
chatStorage = new ChatStorage(mServiceContext); chatStorage = new ChatStorage(mServiceContext);
} }
@ -341,7 +345,7 @@ public class LinphoneManager implements LinphoneCoreListener {
Context c, LinphoneServiceListener listener) { Context c, LinphoneServiceListener listener) {
if (instance != null) if (instance != null)
throw new RuntimeException("Linphone Manager is already initialized"); throw new RuntimeException("Linphone Manager is already initialized");
instance = new LinphoneManager(c, listener); instance = new LinphoneManager(c, listener);
instance.startLibLinphone(c); instance.startLibLinphone(c);
TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);

View file

@ -21,8 +21,10 @@ package org.linphone;
import static android.view.View.GONE; import static android.view.View.GONE;
import static android.view.View.VISIBLE; import static android.view.View.VISIBLE;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
@ -325,5 +327,42 @@ public final class LinphoneUtils {
return false; return false;
} }
} }
public static void clearLogs() {
try {
Runtime.getRuntime().exec(new String[] { "logcat", "-c" });
} catch (IOException e) {
e.printStackTrace();
}
}
public static void collectLogs(String logTag, String email) {
BufferedReader br = null;
Process p = null;
StringBuilder sb = new StringBuilder();
try {
p = Runtime.getRuntime().exec(new String[] { "logcat", "-d", "|", "grep", "`adb shell ps | grep org.linphone | cut -c10-15`" });
br = new BufferedReader(new InputStreamReader(p.getInputStream()), 2048);
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
sb.append("\r\n");
}
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
i.putExtra(Intent.EXTRA_SUBJECT, "Linphone Logs");
i.putExtra(Intent.EXTRA_TEXT, sb.toString());
try {
LinphoneActivity.instance().startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
}
} catch (IOException e) {
e.printStackTrace();
}
}
} }