mirror of
https://github.com/etesync/android
synced 2025-08-02 11:58:05 +00:00
Notification for external file logging
* Show notificatin when external file logging is active * Use column name constants for ServiceDB access
This commit is contained in:
parent
1786b73ac6
commit
51867c5f3f
@ -9,8 +9,20 @@
|
|||||||
package at.bitfire.davdroid;
|
package at.bitfire.davdroid;
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
|
import android.app.ActivityManager;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.*;
|
||||||
|
import android.os.Process;
|
||||||
|
import android.support.v4.app.ActivityManagerCompat;
|
||||||
|
import android.support.v7.app.NotificationCompat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||||
@ -98,23 +110,43 @@ public class App extends Application implements SharedPreferences.OnSharedPrefer
|
|||||||
// add logcat handler
|
// add logcat handler
|
||||||
log.addHandler(LogcatHandler.INSTANCE);
|
log.addHandler(LogcatHandler.INSTANCE);
|
||||||
|
|
||||||
|
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||||
// log to external file according to preferences
|
// log to external file according to preferences
|
||||||
if (logToFile) {
|
if (logToFile) {
|
||||||
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
|
||||||
|
builder .setSmallIcon(R.drawable.ic_sd_storage_light)
|
||||||
|
.setLargeIcon(((BitmapDrawable)getResources().getDrawable(R.drawable.ic_launcher)).getBitmap())
|
||||||
|
.setContentTitle(getString(R.string.logging_davdroid_file_logging))
|
||||||
|
.setLocalOnly(true);
|
||||||
|
|
||||||
File dir = getExternalFilesDir(null);
|
File dir = getExternalFilesDir(null);
|
||||||
if (dir != null)
|
if (dir != null)
|
||||||
try {
|
try {
|
||||||
String pattern = new File(dir, "davdroid%u-" + DateFormatUtils.format(System.currentTimeMillis(), "yyyyMMdd-HHmmss") + ".txt").toString();
|
String pattern = new File(dir, "davdroid%u-" + DateFormatUtils.format(System.currentTimeMillis(), "yyyyMMdd-HHmmss") + ".txt").toString();
|
||||||
log.info("Logging to external file: " + pattern);
|
|
||||||
|
|
||||||
FileHandler fileHandler = new FileHandler(pattern);
|
FileHandler fileHandler = new FileHandler(pattern);
|
||||||
fileHandler.setFormatter(PlainTextFormatter.DEFAULT);
|
fileHandler.setFormatter(PlainTextFormatter.DEFAULT);
|
||||||
log.addHandler(fileHandler);
|
log.addHandler(fileHandler);
|
||||||
|
builder .setContentText(dir.getPath())
|
||||||
|
.setSubText(getString(R.string.logging_to_external_storage_warning))
|
||||||
|
.setCategory(NotificationCompat.CATEGORY_STATUS)
|
||||||
|
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||||
|
.setStyle(new NotificationCompat.BigTextStyle()
|
||||||
|
.bigText(getString(R.string.logging_to_external_storage, dir.getPath())))
|
||||||
|
.setOngoing(true);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.log(Level.SEVERE, "Can't create external log file", e);
|
log.log(Level.SEVERE, "Couldn't create external log file", e);
|
||||||
|
|
||||||
|
builder .setContentText(getString(R.string.logging_couldnt_create_file, e.getLocalizedMessage()))
|
||||||
|
.setCategory(NotificationCompat.CATEGORY_ERROR);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
log.severe("No external media found, can't create external log file");
|
builder.setContentText(getString(R.string.logging_no_external_storage));
|
||||||
}
|
|
||||||
|
nm.notify(Constants.NOTIFICATION_EXTERNAL_FILE_LOGGING, builder.build());
|
||||||
|
} else
|
||||||
|
nm.cancel(Constants.NOTIFICATION_EXTERNAL_FILE_LOGGING);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,8 @@ public class Constants {
|
|||||||
|
|
||||||
// notification IDs
|
// notification IDs
|
||||||
public final static int
|
public final static int
|
||||||
NOTIFICATION_ANDROID_VERSION_UPDATED = 0,
|
NOTIFICATION_ACCOUNT_SETTINGS_UPDATED = 0,
|
||||||
NOTIFICATION_ACCOUNT_SETTINGS_UPDATED = 1,
|
NOTIFICATION_EXTERNAL_FILE_LOGGING = 1,
|
||||||
NOTIFICATION_CONTACTS_SYNC = 10,
|
NOTIFICATION_CONTACTS_SYNC = 10,
|
||||||
NOTIFICATION_CALENDAR_SYNC = 11,
|
NOTIFICATION_CALENDAR_SYNC = 11,
|
||||||
NOTIFICATION_TASK_SYNC = 12;
|
NOTIFICATION_TASK_SYNC = 12;
|
||||||
|
@ -28,8 +28,9 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
import at.bitfire.davdroid.App;
|
import at.bitfire.davdroid.App;
|
||||||
import at.bitfire.davdroid.model.CollectionInfo;
|
import at.bitfire.davdroid.model.CollectionInfo;
|
||||||
import at.bitfire.davdroid.model.ServiceDB;
|
import at.bitfire.davdroid.model.ServiceDB.Collections;
|
||||||
import at.bitfire.davdroid.model.ServiceDB.OpenHelper;
|
import at.bitfire.davdroid.model.ServiceDB.OpenHelper;
|
||||||
|
import at.bitfire.davdroid.model.ServiceDB.Services;
|
||||||
import at.bitfire.davdroid.resource.LocalCalendar;
|
import at.bitfire.davdroid.resource.LocalCalendar;
|
||||||
import at.bitfire.ical4android.CalendarStorageException;
|
import at.bitfire.ical4android.CalendarStorageException;
|
||||||
import lombok.Cleanup;
|
import lombok.Cleanup;
|
||||||
@ -117,16 +118,16 @@ public class CalendarsSyncAdapterService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
long getService(Account account) {
|
long getService(Account account) {
|
||||||
@Cleanup Cursor c = db.query(ServiceDB.Services._TABLE, new String[]{ServiceDB.Services.ID},
|
@Cleanup Cursor c = db.query(Services._TABLE, new String[]{ Services.ID },
|
||||||
ServiceDB.Services.ACCOUNT_NAME + "=? AND " + ServiceDB.Services.SERVICE + "=?", new String[]{account.name, ServiceDB.Services.SERVICE_CALDAV}, null, null, null);
|
Services.ACCOUNT_NAME + "=? AND " + Services.SERVICE + "=?", new String[]{account.name, Services.SERVICE_CALDAV}, null, null, null);
|
||||||
c.moveToNext();
|
c.moveToNext();
|
||||||
return c.getLong(0);
|
return c.getLong(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, CollectionInfo> remoteCalendars(long service) {
|
private Map<String, CollectionInfo> remoteCalendars(long service) {
|
||||||
Map<String, CollectionInfo> collections = new LinkedHashMap<>();
|
Map<String, CollectionInfo> collections = new LinkedHashMap<>();
|
||||||
@Cleanup Cursor cursor = db.query(ServiceDB.Collections._TABLE, ServiceDB.Collections._COLUMNS,
|
@Cleanup Cursor cursor = db.query(Collections._TABLE, Collections._COLUMNS,
|
||||||
ServiceDB.Collections.SERVICE_ID + "=? AND " + ServiceDB.Collections.SUPPORTS_VEVENT + "!=0 AND selected",
|
Collections.SERVICE_ID + "=? AND " + Collections.SUPPORTS_VEVENT + "!=0 AND " + Collections.SYNC,
|
||||||
new String[] { String.valueOf(service) }, null, null, null);
|
new String[] { String.valueOf(service) }, null, null, null);
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
|
@ -94,7 +94,7 @@ public class ContactsSyncAdapterService extends Service {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private CollectionInfo remoteAddressBook(long service) {
|
private CollectionInfo remoteAddressBook(long service) {
|
||||||
@Cleanup Cursor c = db.query(Collections._TABLE, Collections._COLUMNS,
|
@Cleanup Cursor c = db.query(Collections._TABLE, Collections._COLUMNS,
|
||||||
Collections.SERVICE_ID + "=? AND selected", new String[] { String.valueOf(service) }, null, null, null);
|
Collections.SERVICE_ID + "=? AND " + Collections.SYNC, new String[] { String.valueOf(service) }, null, null, null);
|
||||||
if (c.moveToNext()) {
|
if (c.moveToNext()) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
DatabaseUtils.cursorRowToContentValues(c, values);
|
DatabaseUtils.cursorRowToContentValues(c, values);
|
||||||
|
@ -125,7 +125,7 @@ public class TasksSyncAdapterService extends Service {
|
|||||||
|
|
||||||
long getService(Account account) {
|
long getService(Account account) {
|
||||||
@Cleanup Cursor c = db.query(Services._TABLE, new String[]{ Services.ID },
|
@Cleanup Cursor c = db.query(Services._TABLE, new String[]{ Services.ID },
|
||||||
Services.ACCOUNT_NAME + "=? AND " + Services.SERVICE + "=?", new String[]{ account.name, Services.SERVICE_CALDAV }, null, null, null);
|
Services.ACCOUNT_NAME + "=? AND " + Services.SERVICE + "=?", new String[] { account.name, Services.SERVICE_CALDAV }, null, null, null);
|
||||||
c.moveToNext();
|
c.moveToNext();
|
||||||
return c.getLong(0);
|
return c.getLong(0);
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ public class TasksSyncAdapterService extends Service {
|
|||||||
private Map<String, CollectionInfo> remoteTaskLists(long service) {
|
private Map<String, CollectionInfo> remoteTaskLists(long service) {
|
||||||
Map<String, CollectionInfo> collections = new LinkedHashMap<>();
|
Map<String, CollectionInfo> collections = new LinkedHashMap<>();
|
||||||
@Cleanup Cursor cursor = db.query(Collections._TABLE, Collections._COLUMNS,
|
@Cleanup Cursor cursor = db.query(Collections._TABLE, Collections._COLUMNS,
|
||||||
Collections.SERVICE_ID + "=? AND " + Collections.SUPPORTS_VTODO + "!=0 AND selected",
|
Collections.SERVICE_ID + "=? AND " + Collections.SUPPORTS_VTODO + "!=0 AND " + Collections.SYNC,
|
||||||
new String[] { String.valueOf(service) }, null, null, null);
|
new String[] { String.valueOf(service) }, null, null, null);
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
|
17
app/src/main/res/drawable/ic_sd_storage_light.xml
Normal file
17
app/src/main/res/drawable/ic_sd_storage_light.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<!--
|
||||||
|
~ Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
|
||||||
|
~ All rights reserved. This program and the accompanying materials
|
||||||
|
~ are made available under the terms of the GNU Public License v3.0
|
||||||
|
~ which accompanies this distribution, and is available at
|
||||||
|
~ http://www.gnu.org/licenses/gpl.html
|
||||||
|
-->
|
||||||
|
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFFFF"
|
||||||
|
android:pathData="M18,2h-8L4.02,8 4,20c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V4c0,-1.1 -0.9,-2 -2,-2zm-6,6h-2V4h2v4zm3,0h-2V4h2v4zm3,0h-2V4h2v4z"/>
|
||||||
|
</vector>
|
@ -36,6 +36,13 @@
|
|||||||
able to synchronize task lists. You may have to re-install DAVdroid and then add your accounts again after installing OpenTasks.</string>
|
able to synchronize task lists. You may have to re-install DAVdroid and then add your accounts again after installing OpenTasks.</string>
|
||||||
<string name="startup_opentasks_not_installed_install">Install OpenTasks</string>
|
<string name="startup_opentasks_not_installed_install">Install OpenTasks</string>
|
||||||
|
|
||||||
|
<!-- global settings -->
|
||||||
|
<string name="logging_davdroid_file_logging">DAVdroid file logging</string>
|
||||||
|
<string name="logging_to_external_storage">Logging to external storage: %s</string>
|
||||||
|
<string name="logging_to_external_storage_warning">Delete logs as soon as possible!</string>
|
||||||
|
<string name="logging_couldnt_create_file">Couldn\'t create external log file: %s</string>
|
||||||
|
<string name="logging_no_external_storage">External storage not found</string>
|
||||||
|
|
||||||
<!-- AccountsActivity -->
|
<!-- AccountsActivity -->
|
||||||
<string name="navigation_drawer_open">Open navigation drawer</string>
|
<string name="navigation_drawer_open">Open navigation drawer</string>
|
||||||
<string name="navigation_drawer_close">Close navigation drawer</string>
|
<string name="navigation_drawer_close">Close navigation drawer</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user