From c1c677e16178a15738c8ce918b751142a6016601 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sun, 12 May 2019 19:45:07 +0200 Subject: [PATCH] Removed old database helper --- .../magisk/data/database/MagiskDB.java | 213 ------------------ .../com/topjohnwu/magisk/di/DatabaseModule.kt | 1 - 2 files changed, 214 deletions(-) delete mode 100644 app/src/main/java/com/topjohnwu/magisk/data/database/MagiskDB.java diff --git a/app/src/main/java/com/topjohnwu/magisk/data/database/MagiskDB.java b/app/src/main/java/com/topjohnwu/magisk/data/database/MagiskDB.java deleted file mode 100644 index 0426a49f7..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/data/database/MagiskDB.java +++ /dev/null @@ -1,213 +0,0 @@ -package com.topjohnwu.magisk.data.database; - -import android.content.ContentValues; -import android.content.Context; -import android.content.pm.PackageManager; -import android.text.TextUtils; - -import com.topjohnwu.magisk.Config; -import com.topjohnwu.magisk.Const; -import com.topjohnwu.magisk.model.entity.Policy; -import com.topjohnwu.magisk.model.entity.SuLogEntry; -import com.topjohnwu.magisk.utils.LocaleManager; -import com.topjohnwu.magisk.utils.Utils; -import com.topjohnwu.superuser.Shell; - -import java.text.DateFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import kotlin.DeprecationLevel; - -@Deprecated -@kotlin.Deprecated(message = "", level = DeprecationLevel.ERROR) -public class MagiskDB { - - private static final String POLICY_TABLE = "policies"; - private static final String LOG_TABLE = "logs"; - private static final String SETTINGS_TABLE = "settings"; - private static final String STRINGS_TABLE = "strings"; - - private final PackageManager pm; - - @Deprecated - public MagiskDB(Context context) { - pm = context.getPackageManager(); - } - - @Deprecated - public void deletePolicy(Policy policy) { - deletePolicy(policy.uid); - } - - @Deprecated - private List rawSQL(String fmt, Object... args) { - return Shell.su("magisk --sqlite '" + Utils.fmt(fmt, args) + "'").exec().getOut(); - } - - @Deprecated - private List SQL(String fmt, Object... args) { - List list = new ArrayList<>(); - for (String raw : rawSQL(fmt, args)) { - ContentValues values = new ContentValues(); - String[] cols = raw.split("\\|"); - for (String col : cols) { - String[] pair = col.split("=", 2); - if (pair.length != 2) - continue; - values.put(pair[0], pair[1]); - } - list.add(values); - } - return list; - } - - @Deprecated - private String toSQL(ContentValues values) { - StringBuilder keys = new StringBuilder(), vals = new StringBuilder(); - keys.append('('); - vals.append("VALUES("); - boolean first = true; - for (Map.Entry entry : values.valueSet()) { - if (!first) { - keys.append(','); - vals.append(','); - } else { - first = false; - } - keys.append(entry.getKey()); - vals.append('"'); - vals.append(entry.getValue()); - vals.append('"'); - } - keys.append(')'); - vals.append(')'); - keys.append(vals); - return keys.toString(); - } - - @Deprecated - public void clearOutdated() { - rawSQL( - "DELETE FROM %s WHERE until > 0 AND until < %d;" + - "DELETE FROM %s WHERE time < %d", - POLICY_TABLE, System.currentTimeMillis() / 1000, - LOG_TABLE, System.currentTimeMillis() - Config.suLogTimeout * 86400000 - ); - } - - @Deprecated - public void deletePolicy(String pkg) { - rawSQL("DELETE FROM %s WHERE package_name=\"%s\"", POLICY_TABLE, pkg); - } - - @Deprecated - public void deletePolicy(int uid) { - rawSQL("DELETE FROM %s WHERE uid=%d", POLICY_TABLE, uid); - } - - @Deprecated - public Policy getPolicy(int uid) { - List res = - SQL("SELECT * FROM %s WHERE uid=%d", POLICY_TABLE, uid); - if (!res.isEmpty()) { - try { - return new Policy(res.get(0), pm); - } catch (PackageManager.NameNotFoundException e) { - deletePolicy(uid); - } - } - return null; - } - - @Deprecated - public void updatePolicy(Policy policy) { - rawSQL("REPLACE INTO %s %s", POLICY_TABLE, toSQL(policy.getContentValues())); - } - - @Deprecated - public List getPolicyList() { - List list = new ArrayList<>(); - for (ContentValues values : SQL("SELECT * FROM %s WHERE uid/100000=%d", POLICY_TABLE, Const.USER_ID)) { - try { - list.add(new Policy(values, pm)); - } catch (PackageManager.NameNotFoundException e) { - deletePolicy(values.getAsInteger("uid")); - } - } - Collections.sort(list); - return list; - } - - @Deprecated - public List> getLogs() { - List> ret = new ArrayList<>(); - List list = null; - String dateString = null, newString; - for (ContentValues values : SQL("SELECT * FROM %s ORDER BY time DESC", LOG_TABLE)) { - Date date = new Date(values.getAsLong("time")); - newString = DateFormat.getDateInstance(DateFormat.MEDIUM, LocaleManager.getLocale()).format(date); - if (!TextUtils.equals(dateString, newString)) { - dateString = newString; - list = new ArrayList<>(); - ret.add(list); - } - list.add(new SuLogEntry(values)); - } - return ret; - } - - @Deprecated - public void addLog(SuLogEntry log) { - rawSQL("INSERT INTO %s %s", LOG_TABLE, toSQL(log.getContentValues())); - } - - @Deprecated - public void clearLogs() { - rawSQL("DELETE FROM %s", LOG_TABLE); - } - - @Deprecated - public void rmSettings(String key) { - rawSQL("DELETE FROM %s WHERE key=\"%s\"", SETTINGS_TABLE, key); - } - - @Deprecated - public void setSettings(String key, int value) { - ContentValues data = new ContentValues(); - data.put("key", key); - data.put("value", value); - rawSQL("REPLACE INTO %s %s", SETTINGS_TABLE, toSQL(data)); - } - - @Deprecated - public int getSettings(String key, int defaultValue) { - List res = SQL("SELECT value FROM %s WHERE key=\"%s\"", SETTINGS_TABLE, key); - if (res.isEmpty()) - return defaultValue; - return res.get(0).getAsInteger("value"); - } - - @Deprecated - public void setStrings(String key, String value) { - if (value == null) { - rawSQL("DELETE FROM %s WHERE key=\"%s\"", STRINGS_TABLE, key); - return; - } - ContentValues data = new ContentValues(); - data.put("key", key); - data.put("value", value); - rawSQL("REPLACE INTO %s %s", STRINGS_TABLE, toSQL(data)); - } - - @Deprecated - public String getStrings(String key, String defaultValue) { - List res = SQL("SELECT value FROM %s WHERE key=\"%s\"", STRINGS_TABLE, key); - if (res.isEmpty()) - return defaultValue; - return res.get(0).getAsString("value"); - } -} diff --git a/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt index 4248a82ad..9a07cac38 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt @@ -7,7 +7,6 @@ import org.koin.dsl.module val databaseModule = module { - //single { MagiskDB(get().protectedContext) } single { createDatabase(get()) } single { LogDao() } single { PolicyDao(get()) }