Skip to content

Commit

Permalink
优化代码结构
Browse files Browse the repository at this point in the history
  • Loading branch information
Fan095 committed Jun 13, 2024
1 parent af9fc3c commit 4a92aaf
Show file tree
Hide file tree
Showing 17 changed files with 198 additions and 540 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ dependencies {
implementation(libs.vectordrawable.animated)
implementation(libs.customview)
implementation(libs.customview.poolingcontainer)
implementation(libs.constraintlayout)
implementation(libs.constraintlayout) {
exclude("androidx.appcompat", "appcompat")
}

//implementation(files(roots["animation"]))
implementation(files(roots["appcompat"]))
Expand Down
114 changes: 1 addition & 113 deletions app/src/main/java/com/sevtinge/hyperceiler/crash/CrashData.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
package com.sevtinge.hyperceiler.safe;

import static com.sevtinge.hyperceiler.utils.log.XposedLogUtils.logE;
package com.sevtinge.hyperceiler.crash;

import com.sevtinge.hyperceiler.callback.ITAG;
import com.sevtinge.hyperceiler.utils.PropUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -154,109 +148,3 @@ public static ArrayList<String> getReportCrashProp() {
return new ArrayList<>(Arrays.asList(sp));
}
}

/**
* 崩溃记录数据库
*/
class CrashRecord {
public static final String TAG = ITAG.TAG + ": CrashRecord";
// public String label;
public String pkg;
public long time;
public int count;

public CrashRecord(String p, long t, int c) {
// label = l;
pkg = p;
time = t;
count = c;
}

public JSONObject toJSON() {
JSONObject jsonObject = new JSONObject();
try {
// jsonObject.put("l", label);
jsonObject.put("p", pkg);
jsonObject.put("t", time);
jsonObject.put("c", count);
return jsonObject;
} catch (JSONException e) {
logE(TAG, "Failed to convert JSON!" + e);
}
return jsonObject;
}

public JSONObject toJSONSmall() {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("p", pkg);
jsonObject.put("c", count);
return jsonObject;
} catch (JSONException e) {
logE(TAG, "Failed to convert JSON!" + e);
}
return jsonObject;
}

/*public static String getLabel(JSONObject jsonObject) {
try {
return jsonObject.getString("l");
} catch (JSONException e) {
logE(TAG, "Failed to get name!" + e);
}
return "null";
}*/

public static String getPkg(JSONObject jsonObject) {
try {
return jsonObject.getString("p");
} catch (JSONException e) {
logE(TAG, "Failed to get package name!" + e);
}
return "null";
}

public static long getTime(JSONObject jsonObject) {
try {
return jsonObject.getLong("t");
} catch (JSONException e) {
logE(TAG, "Failed to get timestamp!" + e);
}
return -1L;
}

public static int getCount(JSONObject jsonObject) {
try {
return jsonObject.getInt("c");
} catch (JSONException e) {
logE(TAG, "Failed to get the number of times!" + e);
}
return -1;
}

public static JSONObject putParam(JSONObject jsonObject, long time, int count) {
try {
jsonObject.put("c", count);
jsonObject.put("t", time);
return jsonObject;
} catch (JSONException e) {
logE(TAG, "Failed to update data!" + e);
}
return null;
}

public static ArrayList<JSONObject> toArray(String json) {
try {
ArrayList<JSONObject> list = new ArrayList<>();
JSONArray jsonArray = new JSONArray(json);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject obj = jsonArray.getJSONObject(i);
list.add(obj);
}
return list;
} catch (Exception e) {
logE(TAG, "Failed to convert Array!" + e);
}
return new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
package com.sevtinge.hyperceiler.safe;
package com.sevtinge.hyperceiler.crash;

import android.app.ActivityOptions;
import android.app.ApplicationErrorReport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
package com.sevtinge.hyperceiler.safe;
package com.sevtinge.hyperceiler.crash.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
Expand All @@ -29,14 +29,15 @@
import androidx.annotation.Nullable;

import com.sevtinge.hyperceiler.R;
import com.sevtinge.hyperceiler.crash.CrashData;
import com.sevtinge.hyperceiler.utils.DialogHelper;
import com.sevtinge.hyperceiler.utils.shell.ShellInit;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

import moralnorm.appcompat.app.AppCompatActivity;
import fan.appcompat.app.AppCompatActivity;

public class CrashActivity extends AppCompatActivity {

Expand Down Expand Up @@ -96,7 +97,7 @@ private String getReportCrashPkg(String data) {
}

@Override
protected void onDestroy() {
public void onDestroy() {
ShellInit.destroy();
super.onDestroy();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.sevtinge.hyperceiler.crash.service;

import static com.sevtinge.hyperceiler.utils.log.XposedLogUtils.logE;

import com.sevtinge.hyperceiler.callback.ITAG;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

/**
* 崩溃记录数据库
*/
public class CrashRecord {
public static final String TAG = ITAG.TAG + ": CrashRecord";
// public String label;
public String pkg;
public long time;
public int count;

public CrashRecord(String p, long t, int c) {
// label = l;
pkg = p;
time = t;
count = c;
}

public JSONObject toJSON() {
JSONObject jsonObject = new JSONObject();
try {
// jsonObject.put("l", label);
jsonObject.put("p", pkg);
jsonObject.put("t", time);
jsonObject.put("c", count);
return jsonObject;
} catch (JSONException e) {
logE(TAG, "Failed to convert JSON!" + e);
}
return jsonObject;
}

public JSONObject toJSONSmall() {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("p", pkg);
jsonObject.put("c", count);
return jsonObject;
} catch (JSONException e) {
logE(TAG, "Failed to convert JSON!" + e);
}
return jsonObject;
}

/*public static String getLabel(JSONObject jsonObject) {
try {
return jsonObject.getString("l");
} catch (JSONException e) {
logE(TAG, "Failed to get name!" + e);
}
return "null";
}*/

public static String getPkg(JSONObject jsonObject) {
try {
return jsonObject.getString("p");
} catch (JSONException e) {
logE(TAG, "Failed to get package name!" + e);
}
return "null";
}

public static long getTime(JSONObject jsonObject) {
try {
return jsonObject.getLong("t");
} catch (JSONException e) {
logE(TAG, "Failed to get timestamp!" + e);
}
return -1L;
}

public static int getCount(JSONObject jsonObject) {
try {
return jsonObject.getInt("c");
} catch (JSONException e) {
logE(TAG, "Failed to get the number of times!" + e);
}
return -1;
}

public static JSONObject putParam(JSONObject jsonObject, long time, int count) {
try {
jsonObject.put("c", count);
jsonObject.put("t", time);
return jsonObject;
} catch (JSONException e) {
logE(TAG, "Failed to update data!" + e);
}
return null;
}

public static ArrayList<JSONObject> toArray(String json) {
try {
ArrayList<JSONObject> list = new ArrayList<>();
JSONArray jsonArray = new JSONArray(json);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject obj = jsonArray.getJSONObject(i);
list.add(obj);
}
return list;
} catch (Exception e) {
logE(TAG, "Failed to convert Array!" + e);
}
return new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.sevtinge.hyperceiler.crash.activity.CrashActivity;
import com.sevtinge.hyperceiler.utils.shell.ShellInit;

public class CrashService extends Service {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@

import androidx.annotation.CallSuper;

import com.sevtinge.hyperceiler.crash.CrashHook;
import com.sevtinge.hyperceiler.module.app.VariousSystemApps;
import com.sevtinge.hyperceiler.module.app.VariousThirdApps;
import com.sevtinge.hyperceiler.module.base.tool.ResourcesTool;
import com.sevtinge.hyperceiler.crash.CrashHook;
import com.sevtinge.hyperceiler.utils.api.ProjectApi;
import com.sevtinge.hyperceiler.utils.prefs.PrefsMap;
import com.sevtinge.hyperceiler.utils.prefs.PrefsUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
*/
package com.sevtinge.hyperceiler.ui.fragment;

import android.view.View;

import com.sevtinge.hyperceiler.R;
import com.sevtinge.hyperceiler.ui.base.BaseSettingsActivity;
import com.sevtinge.hyperceiler.ui.fragment.base.SettingsPreferenceFragment;

public class CalendarFragment extends SettingsPreferenceFragment {
Expand All @@ -30,12 +27,4 @@ public class CalendarFragment extends SettingsPreferenceFragment {
public int getContentResId() {
return R.xml.calendar;
}

@Override
public View.OnClickListener addRestartListener() {
return view -> ((BaseSettingsActivity)getActivity()).showRestartDialog(
getResources().getString(R.string.calendar),
"com.android.calendar"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,13 @@
import android.view.View;

import com.sevtinge.hyperceiler.R;
import com.sevtinge.hyperceiler.ui.base.BaseSettingsActivity;
import com.sevtinge.hyperceiler.ui.fragment.base.SettingsPreferenceFragment;

public class SecurityAddFragment extends SettingsPreferenceFragment {

@Override
public int getContentResId() {
return R.xml.securityadd;
}

@Override
public View.OnClickListener addRestartListener() {
return view -> ((BaseSettingsActivity) getActivity()).showRestartDialog(
getResources().getString(R.string.securityadd),
"com.miui.securityadd"
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.Context;

import com.sevtinge.hyperceiler.R;
import com.sevtinge.hyperceiler.expansionpacks.utils.SignUtils;
import com.sevtinge.hyperceiler.ui.MainActivityContextHelper;
import com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt;

Expand Down Expand Up @@ -36,7 +37,6 @@ public static boolean isOfficialRom() {
}

public static boolean isSignPass(Context context) {
MainActivityContextHelper helper = new MainActivityContextHelper(context);
return !helper.isSignCheckPass();
return !SignUtils.isSignCheckPass(context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void onCreate(Bundle savedInstanceState) {

@Override
protected int getPreferenceScreenResId() {
return R.xml.prefs_main;
return R.xml.xiaoai;
}

@Override
Expand Down
Loading

0 comments on commit 4a92aaf

Please sign in to comment.