Skip to content

Commit f83abc9

Browse files
committed
Fix for permissions not being remembered in some cases
1 parent 518e3f5 commit f83abc9

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/com/noshufou/android/su/DBHelper.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.Context;
55
import android.content.SharedPreferences;
66
import android.database.Cursor;
7+
import android.database.SQLException;
78
import android.database.sqlite.SQLiteDatabase;
89
import android.database.sqlite.SQLiteOpenHelper;
910
import android.preference.PreferenceManager;
@@ -84,12 +85,21 @@ public void insert(int uid, int toUid, String cmd, int allow) {
8485
values.put(Apps.ALLOW, allow);
8586
values.put(Apps.PACKAGE, Util.getAppPackage(mContext, uid));
8687
values.put(Apps.NAME, Util.getAppName(mContext, uid, false));
87-
long id = this.mDB.insert(APPS_TABLE, null, values);
88-
values.clear();
89-
90-
if (id > 0) {
91-
addLog(id, System.currentTimeMillis(), LogType.CREATE);
92-
addLog(id, System.currentTimeMillis(), (allow==AppDetails.ALLOW)?LogType.ALLOW:LogType.DENY);
88+
long id = 0;
89+
try {
90+
id = this.mDB.insertOrThrow(APPS_TABLE, null, values);
91+
} catch (SQLException e) {
92+
// There was an old, probably stagnant, row in the table
93+
// Delete it and try again
94+
deleteByUid(uid);
95+
id = this.mDB.insert(APPS_TABLE, null, values);
96+
} finally {
97+
values.clear();
98+
99+
if (id > 0) {
100+
addLog(id, System.currentTimeMillis(), LogType.CREATE);
101+
addLog(id, System.currentTimeMillis(), (allow==AppDetails.ALLOW)?LogType.ALLOW:LogType.DENY);
102+
}
93103
}
94104
}
95105

0 commit comments

Comments
 (0)