Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Broadcast intent if the database could not be read
Browse files Browse the repository at this point in the history
Fixes #2081
  • Loading branch information
M66B committed Dec 10, 2014
1 parent dbf79ba commit 214971a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ See for more information about XPrivacy 3 [this FAQ](https://github.com/M66B/XPr

**Next release**

* ...
* Broadcast *biz.bokhorst.xprivacy.action.EXCEPTION* if the database could not be read ([issue](/../../issues/2081))

[Open issues](https://github.com/M66B/XPrivacy/issues?state=open)

Expand Down
46 changes: 46 additions & 0 deletions src/biz/bokhorst/xprivacy/PrivacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
import java.util.concurrent.locks.ReentrantReadWriteLock;

import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
Expand All @@ -44,6 +47,7 @@
import android.os.StrictMode;
import android.os.SystemClock;
import android.os.StrictMode.ThreadPolicy;
import android.support.v4.app.NotificationCompat;
import android.text.TextUtils;
import android.util.Log;
import android.util.Patterns;
Expand Down Expand Up @@ -82,6 +86,7 @@ public class PrivacyService extends IPrivacyService.Stub {
private static final String cServiceName = "xprivacy453";

private boolean mCorrupt = false;
private boolean mNotified = false;
private SQLiteDatabase mDb = null;
private SQLiteDatabase mDbUsage = null;
private SQLiteStatement stmtGetRestriction = null;
Expand Down Expand Up @@ -628,6 +633,8 @@ else if (slash > 0) // Domain name
if (usage && hook != null)
storeUsageData(restriction, secret, mresult);

} catch (SQLiteException ex) {
notifyException(ex);
} catch (Throwable ex) {
Util.bug(null, ex);
} finally {
Expand Down Expand Up @@ -1208,6 +1215,9 @@ public PSetting getSetting(PSetting setting) throws RemoteException {
// Default value
if (result.value == null)
result.value = setting.value;

} catch (SQLiteException ex) {
notifyException(ex);
} catch (Throwable ex) {
Util.bug(null, ex);
} finally {
Expand Down Expand Up @@ -2176,6 +2186,42 @@ public void run() {
});
}

private void notifyException(Throwable ex) {
Util.bug(null, ex);

if (mNotified)
return;

Context context = getContext();
if (context == null)
return;

try {
Intent intent = new Intent("biz.bokhorst.xprivacy.action.EXCEPTION");
intent.putExtra("Message", ex.toString());
context.sendBroadcast(intent);

NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);

// Build notification
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
notificationBuilder.setSmallIcon(R.drawable.ic_launcher);
notificationBuilder.setContentTitle(context.getString(R.string.app_name));
notificationBuilder.setContentText(ex.toString());
notificationBuilder.setWhen(System.currentTimeMillis());
notificationBuilder.setAutoCancel(true);
Notification notification = notificationBuilder.build();

// Display notification
notificationManager.notify(Util.NOTIFY_CORRUPT, notification);

mNotified = true;
} catch (Throwable exex) {
Util.bug(null, exex);
}
}

private boolean getSettingBool(int uid, String name, boolean defaultValue) throws RemoteException {
return getSettingBool(uid, "", name, defaultValue);
}
Expand Down

0 comments on commit 214971a

Please sign in to comment.