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

Commit

Permalink
Add extra logging for database upgrades
Browse files Browse the repository at this point in the history
Refs #1466
  • Loading branch information
M66B committed Feb 27, 2014
1 parent 7e03ea0 commit e7389e9
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/biz/bokhorst/xprivacy/PrivacyService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package biz.bokhorst.xprivacy;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -309,6 +312,8 @@ private void setRestrictionInternal(PRestriction restriction) throws RemoteExcep

try {
SQLiteDatabase db = getDb();
if (db == null)
return;
// 0 not restricted, ask
// 1 restricted, ask
// 2 not restricted, asked
Expand Down Expand Up @@ -451,6 +456,8 @@ public PRestriction getRestriction(final PRestriction restriction, boolean usage

// No permissions required
SQLiteDatabase db = getDb();
if (db == null)
return mresult;

// Precompile statement when needed
if (stmtGetRestriction == null) {
Expand Down Expand Up @@ -592,6 +599,8 @@ public void run() {
try {
if (XActivityManagerService.canWriteUsageData()) {
SQLiteDatabase dbUsage = getDbUsage();
if (dbUsage == null)
return;

mLockUsage.writeLock().lock();
dbUsage.beginTransaction();
Expand Down Expand Up @@ -665,6 +674,8 @@ public void deleteRestrictions(int uid, String restrictionName) throws RemoteExc
try {
enforcePermission();
SQLiteDatabase db = getDb();
if (db == null)
return;

mLock.writeLock().lock();
db.beginTransaction();
Expand Down Expand Up @@ -857,6 +868,8 @@ public void setSetting(PSetting setting) throws RemoteException {
private void setSettingInternal(PSetting setting) throws RemoteException {
try {
SQLiteDatabase db = getDb();
if (db == null)
return;

mLock.writeLock().lock();
db.beginTransaction();
Expand Down Expand Up @@ -947,6 +960,8 @@ public PSetting getSetting(PSetting setting) throws RemoteException {

// No persmissions required
SQLiteDatabase db = getDb();
if (db == null)
return result;

// Fallback
if (!PrivacyManager.cSettingMigrated.equals(setting.name)
Expand Down Expand Up @@ -1014,6 +1029,8 @@ public List<PSetting> getSettingList(int uid) throws RemoteException {
try {
enforcePermission();
SQLiteDatabase db = getDb();
if (db == null)
return listSetting;

mLock.readLock().lock();
db.beginTransaction();
Expand Down Expand Up @@ -1051,6 +1068,8 @@ public void deleteSettings(int uid) throws RemoteException {
try {
enforcePermission();
SQLiteDatabase db = getDb();
if (db == null)
return;

mLock.writeLock().lock();
db.beginTransaction();
Expand Down Expand Up @@ -1084,6 +1103,8 @@ public void clear() throws RemoteException {
enforcePermission();
SQLiteDatabase db = getDb();
SQLiteDatabase dbUsage = getDbUsage();
if (db == null || dbUsage == null)
return;

mLock.writeLock().lock();
db.beginTransaction();
Expand Down Expand Up @@ -2042,6 +2063,17 @@ private SQLiteDatabase getDb() {
} catch (Throwable ex) {
mDb = null; // retry
Util.bug(null, ex);
try {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(
"/cache/xprivacy.log", true));
outputStreamWriter.write(ex.toString());
outputStreamWriter.write("\n");
outputStreamWriter.write(Log.getStackTraceString(ex));
outputStreamWriter.write("\n");
outputStreamWriter.close();
} catch (IOException exex) {
Util.bug(null, exex);
}
}

return mDb;
Expand Down

0 comments on commit e7389e9

Please sign in to comment.