+1 логгер
- boolean isDebuggable = false;
- try {
- PackageManager pm = getPackageManager();
- isDebuggable = (0 != (pm.getApplicationInfo(this.getPackageName(),
- PackageManager.GET_META_DATA).flags & ApplicationInfo.FLAG_DEBUGGABLE));
- PackageInfo pinfo = pm.getPackageInfo(this.getPackageName(),
- PackageManager.GET_SIGNATURES);
- Signature signatures[] = pinfo.signatures;
- CertificateFactory cf = CertificateFactory.getInstance("X.509");
- for (int i = 0; i < signatures.length; i++) {
- ByteArrayInputStream stream = new ByteArrayInputStream(
- signatures[i].toByteArray());
- X509Certificate cert = (X509Certificate) cf
- .generateCertificate(stream);
- isDebuggable = cert.getSubjectX500Principal().equals(
- new X500Principal("CN=Android Debug,O=Android,C=US"));
- if (isDebuggable)
- break;
- }
- } catch (Throwable ex) {
- isDebuggable = true;
- }
- if (isDebuggable) {
- try {
- String path = Environment.getExternalStoragePublicDirectory(
- Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
- java.io.File f = new java.io.File(path);
- if (!f.exists())
- if (!f.mkdirs()) {
- path = Environment.getExternalStorageDirectory()
- .getAbsolutePath();
- }
- if (!path.endsWith("/"))
- path = path + "/";
- String[] commands = {
- "dumpstate > " + path + "dumpstate.txt",
- "dumpsys > " + path + "dumpsys.txt",
- "logcat -d > " + path + "log.txt",
- "cat " + path + "dumpstate.txt " + path
- + "dumpsys.txt " + path + "log.txt > " + path
- + "bugreport.rtf" };
- Process p = Runtime.getRuntime().exec("/system/bin/sh -");
- DataOutputStream os = new DataOutputStream(p.getOutputStream());
- for (String tmpCmd : commands) {
- os.writeBytes(tmpCmd + "\n");
- }
- System.out.println("Start logging...");
- } catch (Throwable e) {
- e.printStackTrace();
- }
- }
Проверят если в DEBUG собрано приложение (значит отлаживаемся и тестим), то начинает сохранять в "Загрузки" дампы и логкат. Если RELEASE то ничего не делает