1 | package de.ugoe.cs.autoquest.androidmonitor;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.io.FileOutputStream;
|
---|
5 | import java.io.StringWriter;
|
---|
6 |
|
---|
7 | import org.xmlpull.v1.XmlSerializer;
|
---|
8 |
|
---|
9 | import android.util.Log;
|
---|
10 | import android.util.Xml;
|
---|
11 |
|
---|
12 | public class AndroidmonitorLogFile {
|
---|
13 |
|
---|
14 | private String name;
|
---|
15 |
|
---|
16 | public AndroidmonitorLogFile(String appName, File dir) {
|
---|
17 | this.name = "android_" + appName + "_LogFile.xml";
|
---|
18 |
|
---|
19 | try {
|
---|
20 | // prove if file exists
|
---|
21 | File file = new File(dir, this.name);
|
---|
22 | /*
|
---|
23 | * if file does not exists write device and app information to a new
|
---|
24 | * file. Otherwise use existing file and add activity information to
|
---|
25 | * file.
|
---|
26 | */
|
---|
27 | if (true) { //!file.exists()
|
---|
28 | /*
|
---|
29 | * create log file. Using method openFileOutput() does not work
|
---|
30 | * for this project due to the reason that this method would try
|
---|
31 | * to create the file in the directory of the non-existing
|
---|
32 | * directory de.ugoe.cs.androidmonitor. This directory does not
|
---|
33 | * exist due to the reason that this project is a library and
|
---|
34 | * the file has to be stored in the directory of the running
|
---|
35 | * application. Furthermore it would not be possible to write in
|
---|
36 | * another app directory as the own one.
|
---|
37 | */
|
---|
38 | String string = getDeviceInformation() + getAppInformation();
|
---|
39 | try {
|
---|
40 | FileOutputStream outputStream = new FileOutputStream(file);
|
---|
41 | outputStream.write(string.getBytes());
|
---|
42 | outputStream.close();
|
---|
43 | } catch (Exception e) {
|
---|
44 | Log.e("file", "outputstream: " + e.getMessage());
|
---|
45 | }
|
---|
46 |
|
---|
47 | }
|
---|
48 | } catch (Exception e) {
|
---|
49 | e.printStackTrace();
|
---|
50 | Log.e("file", "file: " + e.getMessage());
|
---|
51 | }
|
---|
52 |
|
---|
53 | }
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * get file name
|
---|
57 | *
|
---|
58 | * @return
|
---|
59 | */
|
---|
60 | public String getName() {
|
---|
61 | return this.name;
|
---|
62 | }
|
---|
63 |
|
---|
64 | private String getAppInformation() {
|
---|
65 | // app Name ...
|
---|
66 | return "";
|
---|
67 | }
|
---|
68 |
|
---|
69 | private String getDeviceInformation() {
|
---|
70 | String deviceInformation = "";
|
---|
71 | XmlSerializer serializer = Xml.newSerializer();
|
---|
72 | StringWriter writer = new StringWriter();
|
---|
73 | try {
|
---|
74 | serializer.setOutput(writer);
|
---|
75 | serializer.startDocument("UTF-8", true);
|
---|
76 | serializer.startTag("", "device");
|
---|
77 | serializer.startTag("", "param");
|
---|
78 | serializer.attribute("", "value", ""
|
---|
79 | + android.os.Build.VERSION.SDK_INT);
|
---|
80 | serializer.attribute("", "name", "sdk_version");
|
---|
81 | serializer.endTag("", "param");
|
---|
82 |
|
---|
83 | serializer.startTag("", "param");
|
---|
84 | serializer.attribute("", "value", android.os.Build.DEVICE);
|
---|
85 | serializer.attribute("", "name", "device");
|
---|
86 | serializer.endTag("", "param");
|
---|
87 |
|
---|
88 | serializer.startTag("", "param");
|
---|
89 | serializer.attribute("", "value", android.os.Build.MANUFACTURER);
|
---|
90 | serializer.attribute("", "name", "manufacturer");
|
---|
91 | serializer.endTag("", "param");
|
---|
92 |
|
---|
93 | serializer.startTag("", "param");
|
---|
94 | serializer.attribute("", "value", android.os.Build.MODEL);
|
---|
95 | serializer.attribute("", "name", "model");
|
---|
96 | serializer.endTag("", "param");
|
---|
97 |
|
---|
98 | // tbd get resolution ...
|
---|
99 |
|
---|
100 | serializer.endTag("", "device");
|
---|
101 | serializer.endDocument();
|
---|
102 |
|
---|
103 | deviceInformation = writer.toString();
|
---|
104 |
|
---|
105 | } catch (Exception e) {
|
---|
106 | Log.e("xml", e.getMessage());
|
---|
107 | }
|
---|
108 |
|
---|
109 | return deviceInformation;
|
---|
110 | }
|
---|
111 |
|
---|
112 | public void addComponent() {
|
---|
113 | // add component to file
|
---|
114 | }
|
---|
115 |
|
---|
116 | public void addEvent() {
|
---|
117 | // add event to file
|
---|
118 | }
|
---|
119 |
|
---|
120 | }
|
---|