Skip to content

CrashHandler bug fix #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-debug-apk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- dev
jobs:
build:
name: Build debug apk
Expand Down
159 changes: 159 additions & 0 deletions app/build/bin/injected/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="io.github.ratul.topactivity"
android:versionCode="18"
android:versionName="1.5.8">

<uses-sdk
android:minSdkVersion="24"
android:targetSdkVersion="28"/>

<uses-permission
android:name="android.permission.GET_TASKS"/>

<uses-permission
android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<uses-permission
android:name="android.permission.PACKAGE_USAGE_STATS"/>

<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"/>

<queries>

<intent>

<action
android:name="android.accessibilityservice.AccessibilityService"/>

</intent>

</queries>

<application
android:name=".App"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme"
android:allowBackup="true"
android:supportsPictureInPicture="true"
android:resizeableActivity="true"
android:roundIcon="@drawable/ic_launcher_round">

<activity
android:name=".ui.MainActivity"
android:label="@string/app_name"
android:exported="true"
android:configChanges="orientation|screenSize|keyboardHidden|smallestScreenSize|screenLayout"
android:hardwareAccelerated="true"
android:screenOrientation="portrait"
android:launchMode="singleTask"
android:maxRecents="1">

<intent-filter>

<action
android:name="android.intent.action.MAIN"/>

<category
android:name="android.intent.category.LAUNCHER"/>

</intent-filter>

<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/app_shortcuts"/>

</activity>

<activity
android:configChanges="orientation|screenSize|keyboardHidden|smallestScreenSize|screenLayout"
android:hardwareAccelerated="true"
android:screenOrientation="portrait"
android:launchMode="singleTask"
android:name=".ui.CrashActivity"
android:maxRecents="1"
android:label="@string/app_name"
android:exported="true"/>

<activity
android:name=".ui.ShortcutHandlerActivity"
android:excludeFromRecents="true"
android:enabled="true"
android:exported="true"
android:theme="@style/TransparentTheme"/>

<activity
android:name=".ui.BackgroundActivity"
android:excludeFromRecents="true"
android:enabled="true"
android:exported="true"
android:theme="@style/TransparentTheme"/>

<service
android:name=".service.MonitoringService"
android:enabled="true"
android:exported="true"/>

<service
android:name=".service.AccessibilityMonitoringService"
android:label="@string/app_name"
android:description="@string/accessibility_permission"
android:enabled="true"
android:exported="true"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">

<intent-filter>

<action
android:name="android.accessibilityservice.AccessibilityService"/>

</intent-filter>

<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibility"/>

</service>

<service
android:name=".service.QuickSettingsService"
android:enabled="@bool/quick_settings_availability"
android:icon="@drawable/ic_launcher_foreground"
android:label="@string/app_name"
android:exported="true"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">

<intent-filter>

<action
android:name="android.service.quicksettings.action.QS_TILE"/>

</intent-filter>

<meta-data
android:name="android.service.quicksettings.ACTIVE_TILE"
android:value="true"/>

</service>

<receiver
android:name=".model.NotificationMonitor"
android:exported="false"
android:enabled="true">

<intent-filter>

<action
android:name="io.github.ratul.topactivity.ACTION_NOTIFICATION_RECEIVER"/>

</intent-filter>

</receiver>

</application>

</manifest>

130 changes: 130 additions & 0 deletions app/build/bin/merged/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.github.ratul.topactivity"
android:versionCode="18"
android:versionName="1.5.8" >

<uses-sdk
android:minSdkVersion="24"
android:targetSdkVersion="28" />

<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

<queries>
<intent>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent>
</queries>

<application
android:name="io.github.ratul.topactivity.App"
android:allowBackup="true"
android:appComponentFactory="androidx.core.app.CoreComponentFactory"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:resizeableActivity="true"
android:roundIcon="@drawable/ic_launcher_round"
android:supportsPictureInPicture="true"
android:theme="@style/AppTheme" >
<activity
android:name="io.github.ratul.topactivity.ui.MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden|smallestScreenSize|screenLayout"
android:exported="true"
android:hardwareAccelerated="true"
android:label="@string/app_name"
android:launchMode="singleTask"
android:maxRecents="1"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/app_shortcuts" />
</activity>
<activity
android:name="io.github.ratul.topactivity.ui.CrashActivity"
android:configChanges="orientation|screenSize|keyboardHidden|smallestScreenSize|screenLayout"
android:exported="true"
android:hardwareAccelerated="true"
android:label="@string/app_name"
android:launchMode="singleTask"
android:maxRecents="1"
android:screenOrientation="portrait" />
<activity
android:name="io.github.ratul.topactivity.ui.ShortcutHandlerActivity"
android:enabled="true"
android:excludeFromRecents="true"
android:exported="true"
android:theme="@style/TransparentTheme" />
<activity
android:name="io.github.ratul.topactivity.ui.BackgroundActivity"
android:enabled="true"
android:excludeFromRecents="true"
android:exported="true"
android:theme="@style/TransparentTheme" />

<service
android:name="io.github.ratul.topactivity.service.MonitoringService"
android:enabled="true"
android:exported="true" />
<service
android:name="io.github.ratul.topactivity.service.AccessibilityMonitoringService"
android:description="@string/accessibility_permission"
android:enabled="true"
android:exported="true"
android:label="@string/app_name"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE" >
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>

<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibility" />
</service>
<service
android:name="io.github.ratul.topactivity.service.QuickSettingsService"
android:enabled="@bool/quick_settings_availability"
android:exported="true"
android:icon="@drawable/ic_launcher_foreground"
android:label="@string/app_name"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE" >
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>

<meta-data
android:name="android.service.quicksettings.ACTIVE_TILE"
android:value="true" />
</service>

<receiver
android:name="io.github.ratul.topactivity.model.NotificationMonitor"
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="io.github.ratul.topactivity.ACTION_NOTIFICATION_RECEIVER" />
</intent-filter>
</receiver>

<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="io.github.ratul.topactivity.androidx-startup"
android:exported="false" >
<meta-data
android:name="androidx.emoji2.text.EmojiCompatInitializer"
android:value="androidx.startup" />
<meta-data
android:name="androidx.lifecycle.ProcessLifecycleInitializer"
android:value="androidx.startup" />
</provider>
</application>

</manifest>
3 changes: 1 addition & 2 deletions app/src/main/java/io/github/ratul/topactivity/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@
import android.os.Environment;

public class App extends Application {

private static App sApp;

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
sApp = this;
CrashHandler.getInstance(getApp()).init();
Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,19 @@ public CrashHandler(App app) {
versionCode = Build.VERSION.SDK_INT >= 28 ? packageInfo.getLongVersionCode() : packageInfo.versionCode;
} catch (PackageManager.NameNotFoundException ignored) {
ignored.printStackTrace();
versionName = "unknown";
}
}

public void init() {
Thread.setDefaultUncaughtExceptionHandler(this);
}

@Override
public void uncaughtException(Thread main, Throwable mThrowable) {
if (tryUncaughtException(main, mThrowable) || DEFAULT == null) {
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
android.os.Process.sendSignal(android.os.Process.myPid(), android.os.Process.SIGNAL_KILL);
}
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
} else {
DEFAULT.uncaughtException(main, mThrowable);
}
Expand Down Expand Up @@ -102,6 +98,9 @@ public void run() {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
throwable.printStackTrace(pw);
Throwable cause = throwable.getCause();
if (cause != null)
cause.printStackTrace(pw);
fullStackTrace = sw.toString();
pw.close();

Expand Down Expand Up @@ -142,10 +141,10 @@ private void writeFile(File file, String content) throws IOException {
parentFile.mkdirs();
}
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
fos.write(content.getBytes());
try {
fos.close();
FileWriter writer = new FileWriter(file);
writer.write(content);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
Expand Down