-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zjw
committed
Jul 1, 2022
1 parent
6aad7e2
commit e8a698f
Showing
33 changed files
with
575 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/build | ||
.idea | ||
.cxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/src/androidTest/java/com/example/ndk/ndkdemo/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/example/ndk/ndkdemo/MyApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.example.ndk.ndkdemo | ||
|
||
import android.app.Application | ||
import com.example.lib_signal.SignalConst | ||
import com.example.lib_signal.SignalController | ||
|
||
class MyApplication : Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
SignalController(this).initWithSignals(intArrayOf(SignalConst.SIGQUIT,SignalConst.SIGABRT)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.example.ndk.ndkdemo | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Build | ||
import android.os.Looper | ||
import android.os.Message | ||
import android.os.Process | ||
import android.os.SystemClock | ||
import android.util.Log | ||
import android.widget.Toast | ||
import androidx.annotation.RequiresApi | ||
import com.example.lib_signal.CallOnCatchSignal | ||
|
||
class MyHandler : CallOnCatchSignal { | ||
@RequiresApi(Build.VERSION_CODES.M) | ||
override fun onCatchSignal(signal: Int, context: Context) { | ||
// 自定义处理,比如弹出一个toast,或者更友好的交互 | ||
Log.i("hello", "custom onCatchSignal ") | ||
if (checkIsANR(signal, context)) { | ||
Toast.makeText(context, "自定义anr 处理", Toast.LENGTH_LONG).show() | ||
}else { | ||
Toast.makeText(context, "自定义native crash 处理", Toast.LENGTH_LONG).show() | ||
} | ||
val restart: Intent? = | ||
context.packageManager.getLaunchIntentForPackage(context.packageName) | ||
restart?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_CLEAR_TASK) | ||
restart?.action = "restart" | ||
context.startActivity(restart) | ||
Process.killProcess(Process.myPid()) | ||
System.exit(0) | ||
} | ||
|
||
// 判断是否是anr | ||
@SuppressLint("DiscouragedPrivateApi") | ||
@RequiresApi(Build.VERSION_CODES.M) | ||
private fun checkIsANR(signal: Int, context: Context): Boolean { | ||
// val systemService = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager | ||
// val currentPid = Process.myPid() | ||
// Log.i("hello", "systemService ${systemService}") | ||
|
||
try { | ||
val queue = Looper.getMainLooper().queue | ||
val field = queue.javaClass.getDeclaredField("mMessages") | ||
field.isAccessible = true | ||
val message = field.get(queue) as Message | ||
// 这里应该根据实际逻辑判断,比如在前台的话就相应的判断,比如超出5s,这里简单比较演示 | ||
return message.`when` < SystemClock.uptimeMillis() | ||
|
||
// 可以dump这些消息 | ||
// val processesInErrorStates = systemService.processesInErrorState | ||
// Log.i("hello", "processesInErrorStates ${processesInErrorStates}") | ||
// Log.i("hello", "checkIsANR") | ||
// Log.i("hello", "currentPid $currentPid") | ||
// | ||
// processesInErrorStates?.let { | ||
// it.forEach { info -> | ||
// Log.i("hello", "pid is ${info.pid} ========${info.condition}") | ||
// if (info.pid == currentPid && info.condition == ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING) { | ||
// Log.i("hello", "发生了anr") | ||
// return true | ||
// } | ||
// } | ||
// } | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
|
||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
app/src/main/resources/META-INF/services/com.example.lib_signal.CallOnCatchSignal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.example.ndk.ndkdemo.MyHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Sat Jul 06 14:09:41 GMT+08:00 2019 | ||
#Thu Jun 30 18:39:24 CST 2022 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip | ||
zipStoreBase=GRADLE_USER_HOME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Oops, something went wrong.