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

Commit

Permalink
Add extra to database and usage data
Browse files Browse the repository at this point in the history
  • Loading branch information
M66B committed Feb 17, 2014
1 parent d392bce commit 5e8c13a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changelog

* Fixed function name overlapping information icon
* Clear all data will also clear local caches
* Show parameters in usage data

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

Expand Down
6 changes: 5 additions & 1 deletion src/biz/bokhorst/xprivacy/ActivityUsage.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,11 @@ public View getView(int position, View convertView, ViewGroup parent) {
holder.imgIcon.setVisibility(View.INVISIBLE);
holder.imgRestricted.setVisibility(usageData.restricted ? View.VISIBLE : View.INVISIBLE);
holder.tvApp.setText(Integer.toString(usageData.uid));
holder.tvRestriction.setText(String.format("%s/%s", usageData.restrictionName, usageData.methodName));
if (usageData.extra == null)
holder.tvRestriction.setText(String.format("%s/%s", usageData.restrictionName, usageData.methodName));
else
holder.tvRestriction.setText(String.format("%s/%s(%s)", usageData.restrictionName,
usageData.methodName, usageData.extra));

// Async update
new HolderTask(position, holder, usageData).executeOnExecutor(mExecutor, (Object) null);
Expand Down
23 changes: 21 additions & 2 deletions src/biz/bokhorst/xprivacy/PrivacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ public void run() {
values.put("method", restriction.methodName);
values.put("restricted", mresult.restricted);
values.put("time", new Date().getTime());
values.put("extra", restriction.extra);
db.insertWithOnConflict(cTableUsage, null, values,
SQLiteDatabase.CONFLICT_REPLACE);

Expand Down Expand Up @@ -755,10 +756,11 @@ public List<PRestriction> getUsageList(int uid) throws RemoteException {
Cursor cursor;
if (uid == 0)
cursor = db.query(cTableUsage, new String[] { "uid", "restriction", "method", "restricted",
"time" }, null, new String[] {}, null, null, "time DESC LIMIT " + cMaxUsageData);
"time", "extra" }, null, new String[] {}, null, null, "time DESC LIMIT "
+ cMaxUsageData);
else
cursor = db.query(cTableUsage, new String[] { "uid", "restriction", "method", "restricted",
"time" }, "uid=?", new String[] { Integer.toString(uid) }, null, null,
"time", "extra" }, "uid=?", new String[] { Integer.toString(uid) }, null, null,
"time DESC LIMIT " + cMaxUsageData);
if (cursor == null)
Util.log(null, Log.WARN, "Database cursor null (usage data)");
Expand All @@ -771,6 +773,7 @@ public List<PRestriction> getUsageList(int uid) throws RemoteException {
data.methodName = cursor.getString(2);
data.restricted = (cursor.getInt(3) > 0);
data.time = cursor.getLong(4);
data.extra = cursor.getString(5);
result.add(data);
}
} finally {
Expand Down Expand Up @@ -1722,6 +1725,22 @@ private SQLiteDatabase getDatabase() {
}
}

if (db.needUpgrade(7)) {
mLock.writeLock().lock();
db.beginTransaction();
try {
db.execSQL("ALTER TABLE usage ADD COLUMN extra TEXT");
db.setVersion(7);
db.setTransactionSuccessful();
} finally {
try {
db.endTransaction();
} finally {
mLock.writeLock().unlock();
}
}
}

Util.log(null, Log.WARN, "Database version=" + db.getVersion());
mDatabase = db;
} catch (Throwable ex) {
Expand Down

0 comments on commit 5e8c13a

Please sign in to comment.