|
4 | 4 | import android.content.Context;
|
5 | 5 | import android.content.SharedPreferences;
|
6 | 6 | import android.database.Cursor;
|
| 7 | +import android.database.SQLException; |
7 | 8 | import android.database.sqlite.SQLiteDatabase;
|
8 | 9 | import android.database.sqlite.SQLiteOpenHelper;
|
9 | 10 | import android.preference.PreferenceManager;
|
@@ -84,12 +85,21 @@ public void insert(int uid, int toUid, String cmd, int allow) {
|
84 | 85 | values.put(Apps.ALLOW, allow);
|
85 | 86 | values.put(Apps.PACKAGE, Util.getAppPackage(mContext, uid));
|
86 | 87 | 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 | + } |
93 | 103 | }
|
94 | 104 | }
|
95 | 105 |
|
|
0 commit comments