aboutsummaryrefslogtreecommitdiffstats
path: root/src/frontends
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2012-08-10 16:33:05 +0200
committerTobias Brunner <tobias@strongswan.org>2012-08-13 11:22:21 +0200
commitc3afe9d35bca41a71aee40b2e4ab26c41bd7d965 (patch)
tree7fba45fa8dca79771d0b6f532b7296a4b7a4288a /src/frontends
parentae10e8c458cd87b5bbcf1e40e1ce430335c9bb65 (diff)
downloadstrongswan-c3afe9d35bca41a71aee40b2e4ab26c41bd7d965.tar.bz2
strongswan-c3afe9d35bca41a71aee40b2e4ab26c41bd7d965.tar.xz
Add ContentProvider to access log file from other applications
Diffstat (limited to 'src/frontends')
-rw-r--r--src/frontends/android/AndroidManifest.xml5
-rw-r--r--src/frontends/android/src/org/strongswan/android/data/LogContentProvider.java117
2 files changed, 122 insertions, 0 deletions
diff --git a/src/frontends/android/AndroidManifest.xml b/src/frontends/android/AndroidManifest.xml
index 62fc6a135..1b1aabac4 100644
--- a/src/frontends/android/AndroidManifest.xml
+++ b/src/frontends/android/AndroidManifest.xml
@@ -58,6 +58,11 @@
<action android:name="org.strongswan.android.logic.CharonVpnService" />
</intent-filter>
</service>
+
+ <provider
+ android:name=".data.LogContentProvider"
+ android:authorities="org.strongswan.android.content.log" >
+ </provider>
</application>
</manifest>
diff --git a/src/frontends/android/src/org/strongswan/android/data/LogContentProvider.java b/src/frontends/android/src/org/strongswan/android/data/LogContentProvider.java
new file mode 100644
index 000000000..7225ca4ef
--- /dev/null
+++ b/src/frontends/android/src/org/strongswan/android/data/LogContentProvider.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2012 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+package org.strongswan.android.data;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+
+import org.strongswan.android.logic.CharonVpnService;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.database.MatrixCursor;
+import android.net.Uri;
+import android.os.ParcelFileDescriptor;
+import android.provider.OpenableColumns;
+
+public class LogContentProvider extends ContentProvider
+{
+ private static final String AUTHORITY = "org.strongswan.android.content.log";
+ private File mLogFile;
+
+ public LogContentProvider()
+ {
+ }
+
+ @Override
+ public boolean onCreate()
+ {
+ mLogFile = new File(getContext().getFilesDir(), CharonVpnService.LOG_FILE);
+ return true;
+ }
+
+ /**
+ * The log file can only be accessed by Uris created with this method
+ * @return null if failed to create the Uri
+ */
+ public static Uri createContentUri()
+ {
+ Uri uri = Uri.parse("content://"+ AUTHORITY + "/" + CharonVpnService.LOG_FILE);
+ return uri;
+ }
+
+ @Override
+ public String getType(Uri uri)
+ {
+ /* MIME type for our log file */
+ return "text/plain";
+ }
+
+ @Override
+ public Cursor query(Uri uri, String[] projection, String selection,
+ String[] selectionArgs, String sortOrder)
+ {
+ /* this is called by apps to find out the name and size of the file.
+ * since we only provide a single file this is simple to implement */
+ if (projection == null || projection.length < 1)
+ {
+ return null;
+ }
+ MatrixCursor cursor = new MatrixCursor(projection, 1);
+ if (OpenableColumns.DISPLAY_NAME.equals(cursor.getColumnName(0)))
+ {
+ cursor.newRow().add(CharonVpnService.LOG_FILE);
+ }
+ else if (OpenableColumns.SIZE.equals(cursor.getColumnName(0)))
+ {
+ cursor.newRow().add(mLogFile.length());
+ }
+ else
+ {
+ return null;
+ }
+ return cursor;
+ }
+
+ @Override
+ public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException
+ {
+ return ParcelFileDescriptor.open(mLogFile, ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_READ_ONLY);
+ }
+
+ @Override
+ public Uri insert(Uri uri, ContentValues values)
+ {
+ /* not supported */
+ return null;
+ }
+
+ @Override
+ public int delete(Uri uri, String selection, String[] selectionArgs)
+ {
+ /* not supported */
+ return 0;
+ }
+
+ @Override
+ public int update(Uri uri, ContentValues values, String selection,
+ String[] selectionArgs)
+ {
+ /* not supported */
+ return 0;
+ }
+}