summaryrefslogtreecommitdiff
path: root/src/de/blinkt/openvpn/SendDumpActivity.java
blob: 74d1a2f816bab06b7e51a716cfd13d4920633d60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package de.blinkt.openvpn;

import java.io.File;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;

public class SendDumpActivity extends Activity {
	
	protected void onStart() {
		super.onStart();
		emailMiniDumps();
		finish();
	};
	
	public void emailMiniDumps()
	{
		//need to "send multiple" to get more than one attachment
		final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
		emailIntent.setType("*/*");
		emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
				new String[]{"Arne Schwabe <arne@rfc2549.org>"});
		
		String version;
    	String name="ics-openvpn";
		try {
			PackageInfo packageinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
			version = packageinfo.versionName;
			name = packageinfo.applicationInfo.name;
		} catch (NameNotFoundException e) {
			version = "error fetching version";
		}
		
		
		emailIntent.putExtra(Intent.EXTRA_SUBJECT, String.format("%s %s Minidump",name,version));

		emailIntent.putExtra(Intent.EXTRA_TEXT, "Please describe the issue you have experienced");

		ArrayList<Uri> uris = new ArrayList<Uri>();

		File ldump = getLastestDump(this);
		if(ldump==null) {
			OpenVPN.logError("No Minidump found!");
		}
		
		uris.add(Uri.parse("content://de.blinkt.openvpn.FileProvider/" + ldump.getName()));
		uris.add(Uri.parse("content://de.blinkt.openvpn.FileProvider/" + ldump.getName() + ".log"));

		emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
		emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
		startActivity(emailIntent);
	}

	static public File getLastestDump(Context c) {
		long newestDumpTime=0;
		File newestDumpFile=null;

		for(File f:c.getCacheDir().listFiles()) {
			if(!f.getName().endsWith(".dmp"))
				continue;

			if (newestDumpTime < f.lastModified()) {
				newestDumpTime = f.lastModified();
				newestDumpFile=f;
			}
		}
		return newestDumpFile;
	}
}