Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Plugins/NotificationsPlugin/AppDatabase.java
Show All 34 Lines | 33 | class AppDatabase { | |||
---|---|---|---|---|---|
35 | static final private HashSet<String> disabledByDefault = new HashSet<>(); | 35 | static final private HashSet<String> disabledByDefault = new HashSet<>(); | ||
36 | static { | 36 | static { | ||
37 | disabledByDefault.add("com.google.android.googlequicksearchbox"); //Google Now notifications re-spawn every few minutes | 37 | disabledByDefault.add("com.google.android.googlequicksearchbox"); //Google Now notifications re-spawn every few minutes | ||
38 | } | 38 | } | ||
39 | 39 | | |||
40 | private static final String SETTINGS_NAME = "app_database"; | 40 | private static final String SETTINGS_NAME = "app_database"; | ||
41 | private static final String SETTINGS_KEY_ALL_ENABLED = "all_enabled"; | 41 | private static final String SETTINGS_KEY_ALL_ENABLED = "all_enabled"; | ||
42 | 42 | | |||
43 | private static final int DATABASE_VERSION = 4; | 43 | private static final int DATABASE_VERSION = 5; | ||
44 | private static final String DATABASE_NAME = "Applications"; | 44 | private static final String DATABASE_NAME = "Applications"; | ||
45 | private static final String TABLE_ENABLED = "Applications"; | 45 | private static final String TABLE_ENABLED = "Applications"; | ||
46 | private static final String TABLE_PRIVACY = "PrivacyOpts"; | 46 | private static final String TABLE_PRIVACY = "PrivacyOpts"; | ||
47 | private static final String KEY_PACKAGE_NAME = "packageName"; | 47 | private static final String KEY_PACKAGE_NAME = "packageName"; | ||
48 | private static final String KEY_IS_ENABLED = "isEnabled"; | 48 | private static final String KEY_IS_ENABLED = "isEnabled"; | ||
49 | private static final String KEY_PRIVACY_OPTIONS = "privacyOptions"; | 49 | private static final String KEY_PRIVACY_OPTIONS = "privacyOptions"; | ||
50 | 50 | | |||
51 | 51 | | |||
52 | private static final String DATABASE_CREATE_ENABLED = "CREATE TABLE " | ||||
53 | + TABLE_ENABLED + "(" + KEY_PACKAGE_NAME + " TEXT PRIMARY KEY NOT NULL, " | ||||
54 | + KEY_IS_ENABLED + " INTEGER NOT NULL ); "; | ||||
55 | private static final String DATABASE_CREATE_PRIVACY_OPTS = "CREATE TABLE " | ||||
56 | + TABLE_PRIVACY + "(" + KEY_PACKAGE_NAME + " TEXT PRIMARY KEY NOT NULL, " | ||||
57 | + KEY_PRIVACY_OPTIONS + " INTEGER NOT NULL); "; | ||||
58 | | ||||
59 | | ||||
52 | private SQLiteDatabase ourDatabase; | 60 | private SQLiteDatabase ourDatabase; | ||
53 | private DbHelper ourHelper; | 61 | private DbHelper ourHelper; | ||
54 | private SharedPreferences prefs; | 62 | private SharedPreferences prefs; | ||
55 | 63 | | |||
56 | AppDatabase(Context context, boolean readonly) { | 64 | AppDatabase(Context context, boolean readonly) { | ||
57 | ourHelper = new DbHelper(context); | 65 | ourHelper = new DbHelper(context); | ||
58 | prefs = context.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE); | 66 | prefs = context.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE); | ||
59 | if (readonly) { | 67 | if (readonly) { | ||
Show All 12 Lines | |||||
72 | private static class DbHelper extends SQLiteOpenHelper { | 80 | private static class DbHelper extends SQLiteOpenHelper { | ||
73 | 81 | | |||
74 | DbHelper(Context context) { | 82 | DbHelper(Context context) { | ||
75 | super(context, DATABASE_NAME, null, DATABASE_VERSION); | 83 | super(context, DATABASE_NAME, null, DATABASE_VERSION); | ||
76 | } | 84 | } | ||
77 | 85 | | |||
78 | @Override | 86 | @Override | ||
79 | public void onCreate(SQLiteDatabase db) { | 87 | public void onCreate(SQLiteDatabase db) { | ||
80 | db.execSQL("CREATE TABLE " + TABLE_ENABLED + | 88 | db.execSQL(DATABASE_CREATE_ENABLED); | ||
81 | "(" + KEY_PACKAGE_NAME + " TEXT PRIMARY KEY NOT NULL, " + | 89 | db.execSQL(DATABASE_CREATE_PRIVACY_OPTS); | ||
82 | KEY_IS_ENABLED + " INTEGER NOT NULL ); "); | | |||
83 | db.execSQL("CREATE TABLE " + TABLE_PRIVACY + | | |||
84 | "(" + KEY_PACKAGE_NAME + " TEXT PRIMARY KEY NOT NULL, " + | | |||
85 | KEY_PRIVACY_OPTIONS + " INTEGER NOT NULL); "); | | |||
86 | } | 90 | } | ||
87 | 91 | | |||
88 | @Override | 92 | @Override | ||
89 | public void onUpgrade(SQLiteDatabase db, int i, int i2) { | 93 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | ||
90 | db.execSQL("DROP TABLE IF EXISTS " + TABLE_ENABLED); | 94 | if (oldVersion < 5) { | ||
91 | onCreate(db); | 95 | db.execSQL(DATABASE_CREATE_PRIVACY_OPTS); | ||
96 | } | ||||
92 | } | 97 | } | ||
93 | 98 | | |||
94 | } | 99 | } | ||
95 | 100 | | |||
96 | void setEnabled(String packageName, boolean isEnabled) { | 101 | void setEnabled(String packageName, boolean isEnabled) { | ||
97 | String[] columns = new String[]{KEY_IS_ENABLED}; | 102 | String[] columns = new String[]{KEY_IS_ENABLED}; | ||
98 | try (Cursor res = ourDatabase.query(TABLE_ENABLED, columns, KEY_PACKAGE_NAME + " =? ", new String[]{packageName}, null, null, null)) { | 103 | try (Cursor res = ourDatabase.query(TABLE_ENABLED, columns, KEY_PACKAGE_NAME + " =? ", new String[]{packageName}, null, null, null)) { | ||
99 | ContentValues cv = new ContentValues(); | 104 | ContentValues cv = new ContentValues(); | ||
▲ Show 20 Lines • Show All 113 Lines • Show Last 20 Lines |