Skip to content

Commit

Permalink
opt: try catch db
Browse files Browse the repository at this point in the history
  • Loading branch information
Sevtinge committed Dec 17, 2024
1 parent 715e51e commit 9555dd2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class PreferenceHeader extends XmlPreference {
public static List<String> notInSelectedScope = new ArrayList<String>();

private static boolean isScopeGet = false;
private static boolean isScopeGetFailed = false;

public PreferenceHeader(@NonNull Context context) {
super(context);
Expand All @@ -68,7 +69,7 @@ public PreferenceHeader(@NonNull Context context, @Nullable AttributeSet attrs,

private void init(Context context) {
setLayoutResource(R.layout.preference_header);
if (!isScopeGet) if (getWhoAmI().equals("root")) getScope();
if (!isScopeGet && !isScopeGetFailed) if (getWhoAmI().equals("root")) getScope();
if (isUninstall(context)) {
mUninstallApp.add(" - " + getTitle() + " (" + getSummary() + ")");
setVisible(false);
Expand Down Expand Up @@ -103,9 +104,15 @@ private boolean isHidden(Context context) {
private void getScope() {
int userId = getCurrentUserId();

safeExecCommandWithRoot("mkdir -p /data/local/tmp/HyperCeiler/cache/ && cp -r /data/adb/lspd/config /data/local/tmp/HyperCeiler/cache/ && chmod -R 777 /data/local/tmp/HyperCeiler/cache/config");
DatabaseHelper dbHelper = null;

DatabaseHelper dbHelper = new DatabaseHelper(this.getContext(), "/data/local/tmp/HyperCeiler/cache/config/modules_config.db");
try {
safeExecCommandWithRoot("mkdir -p /data/local/tmp/HyperCeiler/cache/ && cp -r /data/adb/lspd/config /data/local/tmp/HyperCeiler/cache/ && chmod -R 777 /data/local/tmp/HyperCeiler/cache/config");
dbHelper = new DatabaseHelper(this.getContext(), "/data/local/tmp/HyperCeiler/cache/config/modules_config.db");
} catch (Exception ignore) {
isScopeGetFailed = true;
return;
}

String tableName = "modules";
String[] columns = {"mid"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

public class DatabaseHelper extends SQLiteOpenHelper {

/**
* 一定要使用try-catch块包围,因为永远不知道会出现什么奇奇怪怪的问题
*/
public DatabaseHelper(Context context, String databaseName) {
super(context, databaseName, null, getUserVersion(context, databaseName));
}
Expand Down

0 comments on commit 9555dd2

Please sign in to comment.