[1725] | 1 | package de.ugoe.cs.autoquest.androidmonitor;
|
---|
| 2 |
|
---|
| 3 | import java.io.File;
|
---|
[1726] | 4 | import java.io.FileOutputStream;
|
---|
[1725] | 5 | import java.io.StringWriter;
|
---|
| 6 |
|
---|
| 7 | import org.xmlpull.v1.XmlSerializer;
|
---|
| 8 |
|
---|
| 9 | import android.util.Log;
|
---|
| 10 | import android.util.Xml;
|
---|
| 11 |
|
---|
[1726] | 12 | public class AndroidmonitorLogFile {
|
---|
| 13 |
|
---|
[1725] | 14 | private String name;
|
---|
| 15 |
|
---|
[1726] | 16 | public AndroidmonitorLogFile(String appName, File dir) {
|
---|
| 17 | this.name = "android_" + appName + "_LogFile.xml";
|
---|
[1725] | 18 |
|
---|
| 19 | try {
|
---|
[1726] | 20 | // prove if file exists
|
---|
[1725] | 21 | File file = new File(dir, this.name);
|
---|
[1726] | 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();
|
---|
[1725] | 39 | try {
|
---|
[1726] | 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());
|
---|
[1725] | 45 | }
|
---|
| 46 |
|
---|
| 47 | }
|
---|
| 48 | } catch (Exception e) {
|
---|
| 49 | e.printStackTrace();
|
---|
[1726] | 50 | Log.e("file", "file: " + e.getMessage());
|
---|
[1725] | 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 | }
|
---|
[1726] | 68 |
|
---|
| 69 | private String getDeviceInformation() {
|
---|
| 70 | String deviceInformation = "";
|
---|
| 71 | XmlSerializer serializer = Xml.newSerializer();
|
---|
| 72 | StringWriter writer = new StringWriter();
|
---|
[1725] | 73 | try {
|
---|
[1726] | 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();
|
---|
[1725] | 102 |
|
---|
[1726] | 103 | deviceInformation = writer.toString();
|
---|
| 104 |
|
---|
[1725] | 105 | } catch (Exception e) {
|
---|
[1726] | 106 | Log.e("xml", e.getMessage());
|
---|
[1725] | 107 | }
|
---|
[1726] | 108 |
|
---|
[1725] | 109 | return deviceInformation;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
[1726] | 112 | public void addComponent() {
|
---|
| 113 | // add component to file
|
---|
[1725] | 114 | }
|
---|
[1726] | 115 |
|
---|
| 116 | public void addEvent() {
|
---|
| 117 | // add event to file
|
---|
[1725] | 118 | }
|
---|
[1726] | 119 |
|
---|
[1725] | 120 | }
|
---|