Compare commits
22 Commits
appbase-v1
...
appbase-v1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9c02f55e3 | ||
|
|
a9cb6b471b | ||
|
|
e694063867 | ||
|
|
0ee13986dc | ||
|
|
3239778922 | ||
|
|
13510f45cf | ||
|
|
49d300dd33 | ||
|
|
c42f677d48 | ||
|
|
9052a3924b | ||
|
|
9642ad1966 | ||
|
|
6686da0e8f | ||
|
|
9e7aff09d1 | ||
|
|
494b2b7fbc | ||
|
|
b1f9b74e28 | ||
|
|
32287e17c0 | ||
|
|
8a0605c12e | ||
|
|
5768881a47 | ||
|
|
6e02c130b2 | ||
|
|
fb9443bbc7 | ||
|
|
bfc1180822 | ||
|
|
ee52a6c28c | ||
|
|
2f72f1795e |
@@ -29,7 +29,7 @@ android {
|
|||||||
// versionName 更新后需要手动设置
|
// versionName 更新后需要手动设置
|
||||||
// .winboll/winbollBuildProps.properties 文件的 stageCount=0
|
// .winboll/winbollBuildProps.properties 文件的 stageCount=0
|
||||||
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
|
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
|
||||||
versionName "1.2"
|
versionName "1.4"
|
||||||
if(true) {
|
if(true) {
|
||||||
versionName = genVersionName("${versionName}")
|
versionName = genVersionName("${versionName}")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Sun Feb 09 11:40:48 HKT 2025
|
#Wed Feb 12 06:12:57 GMT 2025
|
||||||
stageCount=2
|
stageCount=0
|
||||||
libraryProject=libappbase
|
libraryProject=libappbase
|
||||||
baseVersion=1.2
|
baseVersion=1.4
|
||||||
publishVersion=1.2.1
|
publishVersion=1.4.0
|
||||||
buildCount=0
|
buildCount=1
|
||||||
baseBetaVersion=1.2.2
|
baseBetaVersion=1.4.1
|
||||||
|
|||||||
@@ -6,11 +6,18 @@ package cc.winboll.studio.appbase;
|
|||||||
* @Describe APPbase 应用类
|
* @Describe APPbase 应用类
|
||||||
*/
|
*/
|
||||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
public class App extends GlobalApplication {
|
public class App extends GlobalApplication {
|
||||||
|
|
||||||
public static final String TAG = "App";
|
public static final String TAG = "App";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
GlobalApplication.setIsDebuging(this, BuildConfig.DEBUG);
|
||||||
|
super.onCreate();
|
||||||
|
LogUtils.setLogLevel(LogUtils.LOG_LEVEL.Debug);
|
||||||
|
LogUtils.setALlTAGListEnable(true);
|
||||||
|
LogUtils.d(TAG, "LogUtils init");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package cc.winboll.studio.appbase;
|
package cc.winboll.studio.appbase;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
|
||||||
public class MainActivity extends Activity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
|
Toolbar toolbar = findViewById(R.id.activitymainToolbar1);
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
CheckBox cbIsDebugMode = findViewById(R.id.activitymainCheckBox1);
|
CheckBox cbIsDebugMode = findViewById(R.id.activitymainCheckBox1);
|
||||||
cbIsDebugMode.setChecked(GlobalApplication.isDebuging());
|
cbIsDebugMode.setChecked(GlobalApplication.isDebuging());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,31 +7,45 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:gravity="center">
|
android:gravity="center">
|
||||||
|
|
||||||
<TextView
|
<androidx.appcompat.widget.Toolbar
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Hello, WinBoll!"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="right|center_vertical">
|
android:id="@+id/activitymainToolbar1"/>
|
||||||
|
|
||||||
<CheckBox
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1.0"
|
||||||
|
android:gravity="center_horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Debug Mode"
|
android:text="Hello, WinBoll!"/>
|
||||||
android:layout_weight="1.0"
|
|
||||||
android:onClick="onSwitchDebugMode"
|
|
||||||
android:id="@+id/activitymainCheckBox1"/>
|
|
||||||
|
|
||||||
<Button
|
<LinearLayout
|
||||||
android:layout_width="wrap_content"
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Test Application CrashReport"
|
android:gravity="right|center_vertical">
|
||||||
android:textAllCaps="false"
|
|
||||||
android:onClick="onTestApplicationCrashReport"/>
|
<CheckBox
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Debug Mode"
|
||||||
|
android:layout_weight="1.0"
|
||||||
|
android:onClick="onSwitchDebugMode"
|
||||||
|
android:id="@+id/activitymainCheckBox1"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Test Application CrashReport"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:onClick="onTestApplicationCrashReport"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<color name="colorTextColor">#006D26C0</color>
|
<color name="colorPrimary">#005800FF</color>
|
||||||
<color name="colorPrimary">#001BDCC0</color>
|
<color name="colorPrimaryDark">#005800FF</color>
|
||||||
<color name="colorPrimaryDark">#0028C025</color>
|
<color name="colorAccent">#005800FF</color>
|
||||||
<color name="colorAccent">#002985CC</color>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<style name="AppTheme" parent="@android:style/Theme.Material.Light.DarkActionBar">
|
<style name="AppTheme" parent="APPBaseTheme">
|
||||||
|
<item name="themeGlobalCrashActivity">@style/MyGlobalCrashActivityTheme</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="MyGlobalCrashActivityTheme" parent="GlobalCrashActivityTheme">
|
||||||
|
<item name="colorTittle">#FFFFFFFF</item>
|
||||||
|
<item name="colorTittleBackgound">#FF00A4B3</item>
|
||||||
|
<item name="colorText">#FFFFFFFF</item>
|
||||||
|
<item name="colorTextBackgound">#FF000000</item>
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -26,5 +26,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
api 'androidx.appcompat:appcompat:1.0.0'
|
||||||
|
|
||||||
api fileTree(dir: 'libs', include: ['*.jar'])
|
api fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Sun Feb 09 11:40:48 HKT 2025
|
#Wed Feb 12 06:12:57 GMT 2025
|
||||||
stageCount=2
|
stageCount=0
|
||||||
libraryProject=libappbase
|
libraryProject=libappbase
|
||||||
baseVersion=1.2
|
baseVersion=1.4
|
||||||
publishVersion=1.2.1
|
publishVersion=1.4.0
|
||||||
buildCount=0
|
buildCount=1
|
||||||
baseBetaVersion=1.2.2
|
baseBetaVersion=1.4.1
|
||||||
|
|||||||
@@ -1,17 +1,25 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest
|
||||||
package="cc.winboll.studio.libappbase" >
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="cc.winboll.studio.libappbase">
|
||||||
|
|
||||||
|
<!-- 拥有完全的网络访问权限 -->
|
||||||
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
|
|
||||||
<application>
|
<application>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".CrashHandler$CrashActiviy"
|
android:name=".CrashHandler$CrashActivity"
|
||||||
android:label="CrashActiviy"
|
android:label="CrashActivity"
|
||||||
android:launchMode="standard"/>
|
android:launchMode="standard"/>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".CrashHandler$GlobalCrashActiviy"
|
android:name=".GlobalCrashActivity"
|
||||||
android:label="GlobalCrashActiviy"
|
android:label="GlobalCrashActivity"
|
||||||
android:launchMode="standard"/>
|
android:launchMode="standard"/>
|
||||||
|
|
||||||
|
<service android:name=".SimpleOperateSignalCenterService"/>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ public abstract class BaseBean<T extends BaseBean> {
|
|||||||
|
|
||||||
T beanTemp = clazz.newInstance();
|
T beanTemp = clazz.newInstance();
|
||||||
String szBeanSimpleName = beanTemp.getName();
|
String szBeanSimpleName = beanTemp.getName();
|
||||||
String szListJson = FileUtils.readStringFromFile(szFilePath);
|
String szListJson = UTF8FileUtils.readStringFromFile(szFilePath);
|
||||||
StringReader stringReader = new StringReader(szListJson);
|
StringReader stringReader = new StringReader(szListJson);
|
||||||
JsonReader jsonReader = new JsonReader(stringReader);
|
JsonReader jsonReader = new JsonReader(stringReader);
|
||||||
jsonReader.beginArray();
|
jsonReader.beginArray();
|
||||||
@@ -204,7 +204,7 @@ public abstract class BaseBean<T extends BaseBean> {
|
|||||||
try {
|
try {
|
||||||
File fTemp = new File(szFilePath);
|
File fTemp = new File(szFilePath);
|
||||||
if (fTemp.exists()) {
|
if (fTemp.exists()) {
|
||||||
T beanTemp = clazz.newInstance();String szJson = FileUtils.readStringFromFile(szFilePath);
|
T beanTemp = clazz.newInstance();String szJson = UTF8FileUtils.readStringFromFile(szFilePath);
|
||||||
return beanTemp.parseStringToBean(szJson, clazz);
|
return beanTemp.parseStringToBean(szJson, clazz);
|
||||||
}
|
}
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException e) {
|
||||||
@@ -226,7 +226,7 @@ public abstract class BaseBean<T extends BaseBean> {
|
|||||||
public static <T extends BaseBean> boolean saveBeanToFile(String szFilePath, T bean) {
|
public static <T extends BaseBean> boolean saveBeanToFile(String szFilePath, T bean) {
|
||||||
try {
|
try {
|
||||||
String szJson = bean.toString();
|
String szJson = bean.toString();
|
||||||
FileUtils.writeStringToFile(szFilePath, szJson);
|
UTF8FileUtils.writeStringToFile(szFilePath, szJson);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||||
@@ -248,7 +248,7 @@ public abstract class BaseBean<T extends BaseBean> {
|
|||||||
try {
|
try {
|
||||||
File fTemp = new File(szFilePath);
|
File fTemp = new File(szFilePath);
|
||||||
if (fTemp.exists()) {
|
if (fTemp.exists()) {
|
||||||
String szListJson = FileUtils.readStringFromFile(szFilePath);
|
String szListJson = UTF8FileUtils.readStringFromFile(szFilePath);
|
||||||
return parseStringToBeanList(szListJson, beanList, clazz);
|
return parseStringToBeanList(szListJson, beanList, clazz);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -272,7 +272,7 @@ public abstract class BaseBean<T extends BaseBean> {
|
|||||||
public static <T extends BaseBean> boolean saveBeanListToFile(String szFilePath, ArrayList<T> beanList) {
|
public static <T extends BaseBean> boolean saveBeanListToFile(String szFilePath, ArrayList<T> beanList) {
|
||||||
try {
|
try {
|
||||||
String szJson = toStringByBeanList(beanList);
|
String szJson = toStringByBeanList(beanList);
|
||||||
FileUtils.writeStringToFile(szFilePath, szJson);
|
UTF8FileUtils.writeStringToFile(szFilePath, szJson);
|
||||||
//LogUtils.d(TAG, "FileUtil.writeFile beanList.size() is " + Integer.toString(beanList.size()));
|
//LogUtils.d(TAG, "FileUtil.writeFile beanList.size() is " + Integer.toString(beanList.size()));
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import android.content.pm.PackageInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -50,11 +51,11 @@ import java.util.Locale;
|
|||||||
public final class CrashHandler {
|
public final class CrashHandler {
|
||||||
|
|
||||||
public static final String TAG = "CrashHandler";
|
public static final String TAG = "CrashHandler";
|
||||||
|
|
||||||
public static final String TITTLE = "CrashReport";
|
public static final String TITTLE = "CrashReport";
|
||||||
|
|
||||||
private static final String EXTRA_CRASH_INFO = "crashInfo";
|
public static final String EXTRA_CRASH_INFO = "crashInfo";
|
||||||
|
|
||||||
final static String PREFS = CrashHandler.class.getName() + "PREFS";
|
final static String PREFS = CrashHandler.class.getName() + "PREFS";
|
||||||
final static String PREFS_CRASHHANDLER_ISCRASHHAPPEN = "PREFS_CRASHHANDLER_ISCRASHHAPPEN";
|
final static String PREFS_CRASHHANDLER_ISCRASHHAPPEN = "PREFS_CRASHHANDLER_ISCRASHHAPPEN";
|
||||||
|
|
||||||
@@ -130,8 +131,7 @@ public final class CrashHandler {
|
|||||||
LogUtils.d(TAG, "gotoCrashActiviy: ");
|
LogUtils.d(TAG, "gotoCrashActiviy: ");
|
||||||
if (AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) {
|
if (AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) {
|
||||||
LogUtils.d(TAG, "gotoCrashActiviy: isAppCrashSafetyWireOK");
|
LogUtils.d(TAG, "gotoCrashActiviy: isAppCrashSafetyWireOK");
|
||||||
AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(app);
|
intent.setClass(app, GlobalCrashActivity.class);
|
||||||
intent.setClass(app, GlobalCrashActiviy.class);
|
|
||||||
intent.putExtra(EXTRA_CRASH_INFO, errorLog);
|
intent.putExtra(EXTRA_CRASH_INFO, errorLog);
|
||||||
// 如果发生了 CrashHandler 内部崩溃, 就调用基础的应用崩溃显示类
|
// 如果发生了 CrashHandler 内部崩溃, 就调用基础的应用崩溃显示类
|
||||||
// intent.setClass(app, GlobalCrashActiviy.class);
|
// intent.setClass(app, GlobalCrashActiviy.class);
|
||||||
@@ -139,12 +139,11 @@ public final class CrashHandler {
|
|||||||
} else {
|
} else {
|
||||||
LogUtils.d(TAG, "gotoCrashActiviy: else");
|
LogUtils.d(TAG, "gotoCrashActiviy: else");
|
||||||
// 正常状态调用进阶的应用崩溃显示页
|
// 正常状态调用进阶的应用崩溃显示页
|
||||||
intent.setClass(app, CrashActiviy.class);
|
intent.setClass(app, CrashActivity.class);
|
||||||
intent.putExtra(EXTRA_CRASH_INFO, errorLog);
|
intent.putExtra(EXTRA_CRASH_INFO, errorLog);
|
||||||
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// intent.setClass(app, CrashActiviy.class);
|
// intent.setClass(app, CrashActiviy.class);
|
||||||
// intent.putExtra(CrashActiviy.EXTRA_CRASH_INFO, errorLog);
|
// intent.putExtra(CrashActiviy.EXTRA_CRASH_INFO, errorLog);
|
||||||
@@ -265,22 +264,6 @@ public final class CrashHandler {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean resumeSafetyLevel() {
|
|
||||||
LogUtils.d(TAG, "resumeSafetyLevel()");
|
|
||||||
// 崩溃计数进入崩溃保险值
|
|
||||||
int safeLevel = loadCurrentSafetyLevel();
|
|
||||||
if (isSafetyWireWorking(safeLevel)) {
|
|
||||||
// 如果保险丝未熔断, 就增加一次熔断值
|
|
||||||
LogUtils.d(TAG, "resumeSafetyLevel() resume 1");
|
|
||||||
saveCurrentSafetyLevel(safeLevel + 1);
|
|
||||||
return isSafetyWireWorking(safeLevel + 1);
|
|
||||||
} else {
|
|
||||||
LogUtils.d(TAG, "resumeSafetyLevel() resume immediately");
|
|
||||||
resumeToMaximumImmediately();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isSafetyWireWorking(int safetyLevel) {
|
boolean isSafetyWireWorking(int safetyLevel) {
|
||||||
LogUtils.d(TAG, "isSafetyWireOK()");
|
LogUtils.d(TAG, "isSafetyWireOK()");
|
||||||
//safetyLevel = _MINI;
|
//safetyLevel = _MINI;
|
||||||
@@ -304,16 +287,6 @@ public final class CrashHandler {
|
|||||||
AppCrashSafetyWire.getInstance().saveCurrentSafetyLevel(_MAX);
|
AppCrashSafetyWire.getInstance().saveCurrentSafetyLevel(_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
// boolean resumeToMaximum(int safetyLevel) {
|
|
||||||
// if (safetyLevel + 1 < _MAX
|
|
||||||
// && safetyLevel >= _MINI
|
|
||||||
// && isSafetyWireWorking(safetyLevel + 1)) {
|
|
||||||
// AppCrashSafetyWire.getInstance().saveCurrentSafetyLevel(currentSafetyLevel + 1);
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
void off() {
|
void off() {
|
||||||
LogUtils.d(TAG, "off()");
|
LogUtils.d(TAG, "off()");
|
||||||
saveCurrentSafetyLevel(_MINI);
|
saveCurrentSafetyLevel(_MINI);
|
||||||
@@ -330,36 +303,20 @@ public final class CrashHandler {
|
|||||||
new Handler(Looper.getMainLooper()).postDelayed(new Runnable(){
|
new Handler(Looper.getMainLooper()).postDelayed(new Runnable(){
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// 进程持续运行时,恢复保险丝熔断值
|
LogUtils.d(TAG, "Handler run()");
|
||||||
//Resume to maximum
|
if (!AppCrashSafetyWire.getInstance().isSafetyWireWorking(currentSafetyLevel - 1)) {
|
||||||
resumeToMaximumImmediately();
|
// 如果下一次应用崩溃时,保险丝熔断,则先恢复保险丝满能状态
|
||||||
// LogUtils.d(TAG, "postCrashSafetyWire Resume to maximum");
|
// 进程持续运行时,恢复保险丝熔断值
|
||||||
// while (resumeToMaximum(currentSafetyLevel + 1)) {
|
//Resume to maximum
|
||||||
// try {
|
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
||||||
// Thread.sleep(1000);
|
LogUtils.d(TAG, "postResumeCrashSafetyWireHandler");
|
||||||
// } catch (InterruptedException e) {
|
}
|
||||||
// LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getAppName(Context context) {
|
|
||||||
PackageManager packageManager = context.getPackageManager();
|
|
||||||
try {
|
|
||||||
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(
|
|
||||||
context.getPackageName(), 0);
|
|
||||||
return (String) packageManager.getApplicationLabel(applicationInfo);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class CrashActiviy extends Activity implements MenuItem.OnMenuItemClickListener {
|
public static final class CrashActivity extends Activity implements MenuItem.OnMenuItemClickListener {
|
||||||
private static final int MENUITEM_COPY = 0;
|
private static final int MENUITEM_COPY = 0;
|
||||||
private static final int MENUITEM_RESTART = 1;
|
private static final int MENUITEM_RESTART = 1;
|
||||||
|
|
||||||
@@ -368,6 +325,7 @@ public final class CrashHandler {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(getApplicationContext());
|
||||||
|
|
||||||
mLog = getIntent().getStringExtra(EXTRA_CRASH_INFO);
|
mLog = getIntent().getStringExtra(EXTRA_CRASH_INFO);
|
||||||
setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar);
|
setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar);
|
||||||
@@ -388,7 +346,7 @@ public final class CrashHandler {
|
|||||||
contentView.addView(hw, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
contentView.addView(hw, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||||
setContentView(contentView);
|
setContentView(contentView);
|
||||||
getActionBar().setTitle(TITTLE);
|
getActionBar().setTitle(TITTLE);
|
||||||
getActionBar().setSubtitle("GlobalCrashActiviy Error");
|
getActionBar().setSubtitle(GlobalApplication.class.getSimpleName() + " Error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,147 +400,5 @@ public final class CrashHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class GlobalCrashActiviy extends Activity implements MenuItem.OnMenuItemClickListener {
|
|
||||||
|
|
||||||
private static final int MENUITEM_COPY = 0;
|
|
||||||
private static final int MENUITEM_RESTART = 1;
|
|
||||||
|
|
||||||
private String mLog;
|
|
||||||
int mTitleTextColor;
|
|
||||||
int mStartColor;
|
|
||||||
int mCenterColor;
|
|
||||||
int mEndColor;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
mLog = getIntent().getStringExtra(EXTRA_CRASH_INFO);
|
|
||||||
setTheme(android.R.style.Theme_DeviceDefault_NoActionBar);
|
|
||||||
// TypedArray a = obtainStyledAttributes(attrs, R.styleable.ASupportToolbar, R.attr.aSupportToolbar, 0);
|
|
||||||
// mTitleTextColor = a.getColor(R.style.AppTheme.attrs.colo, Color.GREEN);
|
|
||||||
// mStartColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarStartColor, Color.BLUE);
|
|
||||||
// mCenterColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarCenterColor, Color.RED);
|
|
||||||
// mEndColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarEndColor, Color.YELLOW);
|
|
||||||
// // 返回一个绑定资源结束的信号给资源
|
|
||||||
// a.recycle();
|
|
||||||
|
|
||||||
setContentView: {
|
|
||||||
// LinearLayout contentView = new LinearLayout(this);
|
|
||||||
// contentView.setOrientation(LinearLayout.VERTICAL);
|
|
||||||
// contentView.setBackgroundColor(Color.BLUE);
|
|
||||||
// LinearLayout llTitle = new LinearLayout(this);
|
|
||||||
// TextView title = new TextView(this); {
|
|
||||||
// int padding = dp2px(16);
|
|
||||||
// title.setPadding(padding, padding, padding, padding);
|
|
||||||
// title.setText("GlobalCrashActiviy");
|
|
||||||
// title.setTextColor(Color.WHITE);
|
|
||||||
// }
|
|
||||||
// llTitle.addView(title, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
||||||
// contentView.addView(llTitle, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
||||||
//
|
|
||||||
// ScrollView svContent = new ScrollView(this);
|
|
||||||
// svContent.setFillViewport(true);
|
|
||||||
//
|
|
||||||
// HorizontalScrollView hw = new HorizontalScrollView(this);
|
|
||||||
// hw.setBackgroundColor(Color.WHITE);
|
|
||||||
// TextView message = new TextView(this); {
|
|
||||||
// int padding = dp2px(16);
|
|
||||||
// message.setPadding(padding, padding, padding, padding);
|
|
||||||
// message.setText(mLog);
|
|
||||||
// message.setTextIsSelectable(true);
|
|
||||||
// }
|
|
||||||
// hw.addView(message);
|
|
||||||
// svContent.addView(hw, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
|
|
||||||
// contentView.addView(svContent, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
|
|
||||||
//
|
|
||||||
// setContentView(contentView);
|
|
||||||
setContentView(R.layout.activity_globalcrash);
|
|
||||||
LinearLayout llMain = findViewById(R.id.activityglobalcrashLinearLayout1);
|
|
||||||
llMain.setBackgroundColor(Color.GRAY);
|
|
||||||
Toolbar toolbar = findViewById(R.id.activityglobalcrashToolbar1);
|
|
||||||
toolbar.setBackgroundColor(Color.BLACK);
|
|
||||||
toolbar.setTitleTextColor(Color.WHITE);
|
|
||||||
toolbar.setSubtitleTextColor(Color.WHITE);
|
|
||||||
setActionBar(toolbar);
|
|
||||||
TextView tvLog = findViewById(R.id.activityglobalcrashTextView1);
|
|
||||||
tvLog.setText(mLog);
|
|
||||||
tvLog.setTextColor(Color.BLACK);
|
|
||||||
tvLog.setBackgroundColor(Color.GRAY);
|
|
||||||
// // 内部崩溃测试
|
|
||||||
// tvLog.setOnClickListener(new View.OnClickListener(){
|
|
||||||
// @Override
|
|
||||||
// public void onClick(View view) {
|
|
||||||
// for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; i++) {
|
|
||||||
// getString(i);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
getActionBar().setTitle(TITTLE);
|
|
||||||
getActionBar().setSubtitle(getAppName(getApplicationContext()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBackPressed() {
|
|
||||||
restart();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void restart() {
|
|
||||||
PackageManager pm = getPackageManager();
|
|
||||||
Intent intent = pm.getLaunchIntentForPackage(getPackageName());
|
|
||||||
if (intent != null) {
|
|
||||||
intent.addFlags(
|
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
|
||||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK
|
|
||||||
);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
finish();
|
|
||||||
android.os.Process.killProcess(android.os.Process.myPid());
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int dp2px(final float dpValue) {
|
|
||||||
final float scale = Resources.getSystem().getDisplayMetrics().density;
|
|
||||||
return (int) (dpValue * scale + 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case MENUITEM_COPY:
|
|
||||||
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
|
||||||
cm.setPrimaryClip(ClipData.newPlainText(getPackageName(), mLog));
|
|
||||||
Toast.makeText(getApplication(), "The text is copied.", Toast.LENGTH_SHORT).show();
|
|
||||||
break;
|
|
||||||
case MENUITEM_RESTART:
|
|
||||||
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
|
||||||
restart();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
|
||||||
menu.add(0, MENUITEM_COPY, 0, "Copy").setOnMenuItemClickListener(this)
|
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
|
||||||
menu.add(0, MENUITEM_RESTART, 0, "Restart").setOnMenuItemClickListener(this)
|
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
|
||||||
|
|
||||||
// 设置菜单文本颜色
|
|
||||||
for (int i = 0; i < menu.size(); i++) {
|
|
||||||
MenuItem item = menu.getItem(i);
|
|
||||||
SpannableString spanString = new SpannableString(item.getTitle().toString());
|
|
||||||
spanString.setSpan(new ForegroundColorSpan(Color.WHITE), 0, spanString.length(), 0);
|
|
||||||
item.setTitle(spanString);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,120 +0,0 @@
|
|||||||
package cc.winboll.studio.libappbase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author ZhanGSKen@QQ.COM
|
|
||||||
* @Date 2024/07/19 14:30:57
|
|
||||||
* @Describe 文件工具类
|
|
||||||
*/
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.AssetManager;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
public class FileUtils {
|
|
||||||
|
|
||||||
public static final String TAG = "FileUtils";
|
|
||||||
|
|
||||||
public static void copyAssetsToSD(Context context, String szSrcAssets, String szDstSD) {
|
|
||||||
LogUtils.d(TAG, "copyAssetsToSD [" + szSrcAssets + "] to [" + szDstSD + "]");
|
|
||||||
AssetManager assetManager = context.getAssets();
|
|
||||||
InputStream inputStream = null;
|
|
||||||
OutputStream outputStream = null;
|
|
||||||
try {
|
|
||||||
inputStream = assetManager.open(szSrcAssets);
|
|
||||||
File outputFile = new File(szDstSD);
|
|
||||||
outputStream = new FileOutputStream(outputFile);
|
|
||||||
byte[] buffer = new byte[1024];
|
|
||||||
int length = 0;
|
|
||||||
while ((length = inputStream.read(buffer)) > 0) {
|
|
||||||
outputStream.write(buffer, 0, length);
|
|
||||||
}
|
|
||||||
outputStream.flush();
|
|
||||||
LogUtils.d(TAG, "copyAssetsToSD done.");
|
|
||||||
} catch (IOException e) {
|
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
|
||||||
} finally {
|
|
||||||
if (inputStream != null) {
|
|
||||||
try {
|
|
||||||
inputStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (outputStream != null) {
|
|
||||||
try {
|
|
||||||
outputStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// 把字符串写入文件,指定 UTF-8 编码
|
|
||||||
//
|
|
||||||
public static void writeStringToFile(String szFilePath, String szContent) throws IOException {
|
|
||||||
File file = new File(szFilePath);
|
|
||||||
if (!file.getParentFile().exists()) {
|
|
||||||
file.getParentFile().mkdirs();
|
|
||||||
}
|
|
||||||
FileOutputStream outputStream = new FileOutputStream(file);
|
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
|
|
||||||
writer.write(szContent);
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// 读取文件到字符串,指定 UTF-8 编码
|
|
||||||
//
|
|
||||||
public static String readStringFromFile(String szFilePath) throws IOException {
|
|
||||||
File file = new File(szFilePath);
|
|
||||||
FileInputStream inputStream = new FileInputStream(file);
|
|
||||||
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
|
||||||
StringBuilder content = new StringBuilder();
|
|
||||||
int character;
|
|
||||||
while ((character = reader.read()) != -1) {
|
|
||||||
content.append((char) character);
|
|
||||||
}
|
|
||||||
reader.close();
|
|
||||||
return content.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean copyFile(File srcFile, File dstFile) {
|
|
||||||
if (!srcFile.exists()) {
|
|
||||||
LogUtils.d(TAG, "The original file does not exist.");
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
// 源文件路径
|
|
||||||
Path sourcePath = Paths.get(srcFile.getPath());
|
|
||||||
// 目标文件路径
|
|
||||||
Path destPath = Paths.get(dstFile.getPath());
|
|
||||||
// 建立目标父级文件夹
|
|
||||||
if (!dstFile.getParentFile().exists()) {
|
|
||||||
dstFile.getParentFile().mkdirs();
|
|
||||||
}
|
|
||||||
// 删除旧的目标文件
|
|
||||||
if (dstFile.exists()) {
|
|
||||||
dstFile.delete();
|
|
||||||
}
|
|
||||||
// 拷贝文件
|
|
||||||
Files.copy(sourcePath, destPath);
|
|
||||||
LogUtils.d(TAG, "File copy successfully.");
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,16 +8,10 @@ package cc.winboll.studio.libappbase;
|
|||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.Closeable;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public class GlobalApplication extends Application {
|
public class GlobalApplication extends Application {
|
||||||
|
|
||||||
@@ -60,13 +54,13 @@ public class GlobalApplication extends Application {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
GlobalApplication.isDebuging = true;
|
//GlobalApplication.isDebuging = true;
|
||||||
GlobalApplication.setIsDebuging(this, true);
|
//GlobalApplication.setIsDebuging(this, true);
|
||||||
LogUtils.init(this);
|
LogUtils.init(this);
|
||||||
LogUtils.setLogLevel(LogUtils.LOG_LEVEL.Debug);
|
//LogUtils.setLogLevel(LogUtils.LOG_LEVEL.Debug);
|
||||||
//LogUtils.setTAGListEnable(GlobalApplication.TAG, true);
|
//LogUtils.setTAGListEnable(GlobalApplication.TAG, true);
|
||||||
LogUtils.setALlTAGListEnable(true);
|
//LogUtils.setALlTAGListEnable(true);
|
||||||
LogUtils.d(TAG, "LogUtils init");
|
//LogUtils.d(TAG, "LogUtils init");
|
||||||
|
|
||||||
// 设置应用异常处理窗口
|
// 设置应用异常处理窗口
|
||||||
CrashHandler.init(this);
|
CrashHandler.init(this);
|
||||||
@@ -76,43 +70,16 @@ public class GlobalApplication extends Application {
|
|||||||
//GlobalApplication.isDebuging = sharedPreferences.getBoolean(PREFS_ISDEBUGING, GlobalApplication.isDebuging);
|
//GlobalApplication.isDebuging = sharedPreferences.getBoolean(PREFS_ISDEBUGING, GlobalApplication.isDebuging);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void write(InputStream input, OutputStream output) throws IOException {
|
public static String getAppName(Context context) {
|
||||||
byte[] buf = new byte[1024 * 8];
|
PackageManager packageManager = context.getPackageManager();
|
||||||
int len;
|
|
||||||
while ((len = input.read(buf)) != -1) {
|
|
||||||
output.write(buf, 0, len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write(File file, byte[] data) throws IOException {
|
|
||||||
File parent = file.getParentFile();
|
|
||||||
if (parent != null && !parent.exists()) parent.mkdirs();
|
|
||||||
|
|
||||||
ByteArrayInputStream input = new ByteArrayInputStream(data);
|
|
||||||
FileOutputStream output = new FileOutputStream(file);
|
|
||||||
try {
|
try {
|
||||||
write(input, output);
|
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(
|
||||||
} finally {
|
context.getPackageName(), 0);
|
||||||
closeIO(input, output);
|
return (String) packageManager.getApplicationLabel(applicationInfo);
|
||||||
}
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
|
|
||||||
public static String toString(InputStream input) throws IOException {
|
|
||||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
||||||
write(input, output);
|
|
||||||
try {
|
|
||||||
return output.toString("UTF-8");
|
|
||||||
} finally {
|
|
||||||
closeIO(input, output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void closeIO(Closeable... closeables) {
|
|
||||||
for (Closeable closeable : closeables) {
|
|
||||||
try {
|
|
||||||
if (closeable != null) closeable.close();
|
|
||||||
} catch (IOException ignored) {}
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen@AliYun.Com
|
||||||
|
* @Date 2025/02/11 00:14:05
|
||||||
|
*/
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.ClipData;
|
||||||
|
import android.content.ClipboardManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.SpannableString;
|
||||||
|
import android.text.style.ForegroundColorSpan;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import cc.winboll.studio.libappbase.R;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
public final class GlobalCrashActivity extends AppCompatActivity implements MenuItem.OnMenuItemClickListener {
|
||||||
|
|
||||||
|
private static final int MENUITEM_COPY = 0;
|
||||||
|
private static final int MENUITEM_RESTART = 1;
|
||||||
|
|
||||||
|
GlobalCrashReportView mGlobalCrashReportView;
|
||||||
|
String mLog;
|
||||||
|
|
||||||
|
|
||||||
|
public static final String TAG = "GlobalCrashActivity";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
CrashHandler.AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(getApplicationContext());
|
||||||
|
|
||||||
|
mLog = getIntent().getStringExtra(CrashHandler.EXTRA_CRASH_INFO);
|
||||||
|
//setTheme(android.R.style.Theme_Holo_Light_NoActionBar);
|
||||||
|
//setTheme(R.style.APPBaseTheme);
|
||||||
|
setContentView(R.layout.activity_globalcrash);
|
||||||
|
mGlobalCrashReportView = findViewById(R.id.activityglobalcrashGlobalCrashReportView1);
|
||||||
|
mGlobalCrashReportView.setReport(mLog);
|
||||||
|
setSupportActionBar(mGlobalCrashReportView.getToolbar());
|
||||||
|
|
||||||
|
getSupportActionBar().setTitle(CrashHandler.TITTLE);
|
||||||
|
getSupportActionBar().setSubtitle(GlobalApplication.getAppName(getApplicationContext()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void restart() {
|
||||||
|
PackageManager pm = getPackageManager();
|
||||||
|
Intent intent = pm.getLaunchIntentForPackage(getPackageName());
|
||||||
|
if (intent != null) {
|
||||||
|
intent.addFlags(
|
||||||
|
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
| Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
|
);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
finish();
|
||||||
|
android.os.Process.killProcess(android.os.Process.myPid());
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case MENUITEM_COPY:
|
||||||
|
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
cm.setPrimaryClip(ClipData.newPlainText(getPackageName(), mLog));
|
||||||
|
Toast.makeText(getApplication(), "The text is copied.", Toast.LENGTH_SHORT).show();
|
||||||
|
break;
|
||||||
|
case MENUITEM_RESTART:
|
||||||
|
CrashHandler.AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
||||||
|
restart();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
menu.add(0, MENUITEM_COPY, 0, "Copy").setOnMenuItemClickListener(this)
|
||||||
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||||
|
menu.add(0, MENUITEM_RESTART, 0, "Restart").setOnMenuItemClickListener(this)
|
||||||
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||||
|
|
||||||
|
// 更新菜单文字风格
|
||||||
|
mGlobalCrashReportView.updateMenuStyle();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void joinQQGroup(String key) {
|
||||||
|
// 创建Intent
|
||||||
|
Intent intent = new Intent();
|
||||||
|
// 设置动作
|
||||||
|
intent.setAction("android.intent.action.VIEW");
|
||||||
|
// 设置数据为网址的URI
|
||||||
|
Uri content_url = Uri.parse("https://www.winboll.cc");
|
||||||
|
intent.setData(content_url);
|
||||||
|
// 添加标志
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
// 设置类名和活动名
|
||||||
|
intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
|
||||||
|
// 启动Activity
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen@AliYun.Com
|
||||||
|
* @Date 2025/02/11 20:18:30
|
||||||
|
* @Describe 应用崩溃报告视图
|
||||||
|
*/
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.text.SpannableString;
|
||||||
|
import android.text.style.ForegroundColorSpan;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import cc.winboll.studio.libappbase.R;
|
||||||
|
|
||||||
|
public class GlobalCrashReportView extends LinearLayout {
|
||||||
|
|
||||||
|
public static final String TAG = "GlobalCrashReportView";
|
||||||
|
|
||||||
|
Context mContext;
|
||||||
|
Toolbar mToolbar;
|
||||||
|
int colorTittle;
|
||||||
|
int colorTittleBackground;
|
||||||
|
int colorText;
|
||||||
|
int colorTextBackground;
|
||||||
|
TextView mtvReport;
|
||||||
|
|
||||||
|
public GlobalCrashReportView(Context context) {
|
||||||
|
super(context);
|
||||||
|
mContext = context;
|
||||||
|
//initView();
|
||||||
|
}
|
||||||
|
|
||||||
|
public GlobalCrashReportView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
mContext = context;
|
||||||
|
initView(attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GlobalCrashReportView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
mContext = context;
|
||||||
|
//initView();
|
||||||
|
}
|
||||||
|
|
||||||
|
public GlobalCrashReportView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
mContext = context;
|
||||||
|
//initView();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorTittle(int colorTittle) {
|
||||||
|
this.colorTittle = colorTittle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColorTittle() {
|
||||||
|
return colorTittle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorTittleBackground(int colorTittleBackground) {
|
||||||
|
this.colorTittleBackground = colorTittleBackground;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColorTittleBackground() {
|
||||||
|
return colorTittleBackground;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorText(int colorText) {
|
||||||
|
this.colorText = colorText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColorText() {
|
||||||
|
return colorText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColorTextBackground(int colorTextBackground) {
|
||||||
|
this.colorTextBackground = colorTextBackground;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColorTextBackground() {
|
||||||
|
return colorTextBackground;
|
||||||
|
}
|
||||||
|
|
||||||
|
void initView(AttributeSet attrs) {
|
||||||
|
TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.GlobalCrashActivity, R.attr.themeGlobalCrashActivity, 0);
|
||||||
|
this.colorTittle = a.getColor(R.styleable.GlobalCrashActivity_colorTittle, Color.WHITE);
|
||||||
|
this.colorTittleBackground = a.getColor(R.styleable.GlobalCrashActivity_colorTittleBackgound, Color.BLACK);
|
||||||
|
this.colorText = a.getColor(R.styleable.GlobalCrashActivity_colorText, Color.BLACK);
|
||||||
|
this.colorTextBackground = a.getColor(R.styleable.GlobalCrashActivity_colorTextBackgound, Color.WHITE);
|
||||||
|
// 返回一个绑定资源结束的信号给资源
|
||||||
|
a.recycle();
|
||||||
|
|
||||||
|
/*this.colorTittle = Color.WHITE;
|
||||||
|
this.colorTittleBackground = Color.BLACK;
|
||||||
|
this.colorText = Color.BLACK;
|
||||||
|
this.colorTextBackground = Color.WHITE;
|
||||||
|
*/
|
||||||
|
|
||||||
|
inflate(mContext, R.layout.view_globalcrashreport, this);
|
||||||
|
|
||||||
|
LinearLayout llMain = findViewById(R.id.viewglobalcrashreportLinearLayout1);
|
||||||
|
llMain.setBackgroundColor(this.colorTextBackground);
|
||||||
|
mToolbar = findViewById(R.id.viewglobalcrashreportToolbar1);
|
||||||
|
mToolbar.setBackgroundColor(this.colorTittleBackground);
|
||||||
|
mToolbar.setTitleTextColor(this.colorTittle);
|
||||||
|
mToolbar.setSubtitleTextColor(this.colorTittle);
|
||||||
|
mtvReport = findViewById(R.id.viewglobalcrashreportTextView1);
|
||||||
|
mtvReport.setTextColor(this.colorText);
|
||||||
|
mtvReport.setBackgroundColor(this.colorTextBackground);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReport(String report) {
|
||||||
|
mtvReport.setText(report);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Toolbar getToolbar() {
|
||||||
|
return mToolbar;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 更新菜单文字风格
|
||||||
|
//
|
||||||
|
public void updateMenuStyle() {
|
||||||
|
// 设置菜单文本颜色
|
||||||
|
Menu menu = mToolbar.getMenu();
|
||||||
|
for (int i = 0; i < menu.size(); i++) {
|
||||||
|
MenuItem item = menu.getItem(i);
|
||||||
|
SpannableString spanString = new SpannableString(item.getTitle().toString());
|
||||||
|
spanString.setSpan(new ForegroundColorSpan(this.colorTittle), 0, spanString.length(), 0);
|
||||||
|
item.setTitle(spanString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -360,7 +360,7 @@ public class LogUtils {
|
|||||||
public static void cleanLog() {
|
public static void cleanLog() {
|
||||||
if (_mfLogCatchFile.exists()) {
|
if (_mfLogCatchFile.exists()) {
|
||||||
try {
|
try {
|
||||||
FileUtils.writeStringToFile(_mfLogCatchFile.getPath(), "");
|
UTF8FileUtils.writeStringToFile(_mfLogCatchFile.getPath(), "");
|
||||||
//LogUtils.d(TAG, "cleanLog");
|
//LogUtils.d(TAG, "cleanLog");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen@AliYun.Com
|
||||||
|
* @Date 2025/02/12 11:12:25
|
||||||
|
* @Describe 简单信号服务中心
|
||||||
|
*/
|
||||||
|
import android.app.Service;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.IBinder;
|
||||||
|
|
||||||
|
public class SimpleOperateSignalCenterService extends Service {
|
||||||
|
|
||||||
|
public static final String TAG = "SimpleOperateSignalCenterService";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBinder onBind(Intent intent) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package cc.winboll.studio.libappbase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen@QQ.COM
|
||||||
|
* @Date 2024/07/19 14:30:57
|
||||||
|
* @Describe UTF-8编码文件工具类
|
||||||
|
*/
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
public class UTF8FileUtils {
|
||||||
|
|
||||||
|
public static final String TAG = "FileUtils";
|
||||||
|
|
||||||
|
//
|
||||||
|
// 把字符串写入文件,指定 UTF-8 编码
|
||||||
|
//
|
||||||
|
public static void writeStringToFile(String szFilePath, String szContent) throws IOException {
|
||||||
|
File file = new File(szFilePath);
|
||||||
|
if (!file.getParentFile().exists()) {
|
||||||
|
file.getParentFile().mkdirs();
|
||||||
|
}
|
||||||
|
FileOutputStream outputStream = new FileOutputStream(file);
|
||||||
|
OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
|
||||||
|
writer.write(szContent);
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 读取文件到字符串,指定 UTF-8 编码
|
||||||
|
//
|
||||||
|
public static String readStringFromFile(String szFilePath) throws IOException {
|
||||||
|
File file = new File(szFilePath);
|
||||||
|
FileInputStream inputStream = new FileInputStream(file);
|
||||||
|
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||||
|
StringBuilder content = new StringBuilder();
|
||||||
|
int character;
|
||||||
|
while ((character = reader.read()) != -1) {
|
||||||
|
content.append((char) character);
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
return content.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,34 +2,14 @@
|
|||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:id="@+id/activityglobalcrashLinearLayout1">
|
|
||||||
|
|
||||||
<android.widget.Toolbar
|
<cc.winboll.studio.libappbase.GlobalCrashReportView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/activityglobalcrashToolbar1"/>
|
android:id="@+id/activityglobalcrashGlobalCrashReportView1"/>
|
||||||
|
|
||||||
<ScrollView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1.0">
|
|
||||||
|
|
||||||
<HorizontalScrollView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/activityglobalcrashTextView1"
|
|
||||||
android:background="#FFFFFFFF"/>
|
|
||||||
|
|
||||||
</HorizontalScrollView>
|
|
||||||
|
|
||||||
</ScrollView>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
35
libappbase/src/main/res/layout/view_globalcrashreport.xml
Normal file
35
libappbase/src/main/res/layout/view_globalcrashreport.xml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:id="@+id/viewglobalcrashreportLinearLayout1">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/viewglobalcrashreportToolbar1"/>
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1.0">
|
||||||
|
|
||||||
|
<HorizontalScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="#FFFFFFFF"
|
||||||
|
android:id="@+id/viewglobalcrashreportTextView1"/>
|
||||||
|
|
||||||
|
</HorizontalScrollView>
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<style name="AppTheme" parent="@android:style/Theme.Material.Light">
|
|
||||||
</style>
|
|
||||||
</resources>
|
|
||||||
@@ -1,7 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<attr name="attrTextColor" format="color" />
|
|
||||||
<attr name="attrPrimaryColor" format="color" />
|
<attr name="themeGlobalCrashActivity" format="reference"/>
|
||||||
<attr name="attrPrimaryDarkColor" format="color" />
|
|
||||||
<attr name="attrAccentColor" format="color" />
|
<declare-styleable name="GlobalCrashActivity">
|
||||||
|
<attr name="colorTittle" format="color" />
|
||||||
|
<attr name="colorTittleBackgound" format="color" />
|
||||||
|
<attr name="colorText" format="color" />
|
||||||
|
<attr name="colorTextBackgound" format="color" />
|
||||||
|
</declare-styleable>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<color name="colorPrimary">#FF03AB4E</color>
|
<color name="colorPrimary">#FFFFE200</color>
|
||||||
<color name="colorPrimaryDark">#FF027C39</color>
|
<color name="colorPrimaryDark">#FFFFE200</color>
|
||||||
<color name="colorAccent">#FF3DDC84</color>
|
<color name="colorAccent">#FFFFE200</color>
|
||||||
<color name="colorText">#FF000000</color>
|
<color name="colorText">#FFFFE200</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
|
|
||||||
<item name="attrTextColor">#FF000000</item>
|
<style name="APPBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||||
<item name="attrPrimaryColor">@color/colorPrimary</item>
|
<item name="themeGlobalCrashActivity">@style/GlobalCrashActivityTheme</item>
|
||||||
<item name="attrPrimaryDarkColor">@color/colorPrimaryDark</item>
|
</style>
|
||||||
<item name="attrAccentColor">@color/colorAccent</item>
|
|
||||||
|
<style name="GlobalCrashActivityTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
|
||||||
|
<item name="colorTittle">#FFFFF600</item>
|
||||||
|
<item name="colorTittleBackgound">#FF00B322</item>
|
||||||
|
<item name="colorText">#FF00B322</item>
|
||||||
|
<item name="colorTextBackgound">#FF000000</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user