Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 641faf5d authored by d34d's avatar d34d Committed by Steve Kondik
Browse files

Themes: Watch all app crashes for problematic themes

Only watching for exceptions that occur during an apps launch may
not be sufficient to catch possible bad themes causing issues.
This patch monitors all app crashes and broadcasts that there was
a crash if either Resources.NotFoundException or InflateException
are thrown.  The remaining logic is the same as when an app launch
failure occurred.

We also display a notification to the user so that they know why
their theme was reset to the system theme.

Change-Id: I0761d02587b5b81deee4a31a89f515dbc7cc5fe6
parent 06ccd40f
Loading
Loading
Loading
Loading
+0 −17
Original line number Diff line number Diff line
@@ -2338,13 +2338,6 @@ public final class ActivityThread {

        } catch (Exception e) {
            if (!mInstrumentation.onException(activity, e)) {
                if (e instanceof InflateException) {
                    Log.e(TAG, "Failed to inflate", e);
                    sendAppLaunchFailureBroadcast(r);
                } else if (e instanceof Resources.NotFoundException) {
                    Log.e(TAG, "Failed to find resource", e);
                    sendAppLaunchFailureBroadcast(r);
                }
                throw new RuntimeException(
                    "Unable to start activity " + component
                    + ": " + e.toString(), e);
@@ -2354,16 +2347,6 @@ public final class ActivityThread {
        return activity;
    }

    private void sendAppLaunchFailureBroadcast(ActivityClientRecord r) {
        String pkg = null;
        if (r.packageInfo != null && !TextUtils.isEmpty(r.packageInfo.getPackageName())) {
            pkg = r.packageInfo.getPackageName();
        }
        Intent intent = new Intent(Intent.ACTION_APP_LAUNCH_FAILURE,
                (pkg != null)? Uri.fromParts("package", pkg, null) : null);
        getSystemContext().sendBroadcast(intent);
    }

    private Context createBaseContextForActivity(ActivityClientRecord r,
            final Activity activity) {
        ContextImpl appContext = ContextImpl.createActivityContext(this, r.packageInfo, r.token);
+4 −2
Original line number Diff line number Diff line
@@ -2689,13 +2689,15 @@ public class Intent implements Parcelable, Cloneable {
     * Could indicate that curently applied theme is malicious.
     * @hide
     */
    public static final String ACTION_APP_LAUNCH_FAILURE = "com.tmobile.intent.action.APP_LAUNCH_FAILURE";
    public static final String ACTION_APP_FAILURE =
            "com.tmobile.intent.action.APP_FAILURE";

    /**
     * Broadcast Action: Request to reset the unrecoverable errors count to 0.
     * @hide
     */
    public static final String ACTION_APP_LAUNCH_FAILURE_RESET = "com.tmobile.intent.action.APP_LAUNCH_FAILURE_RESET";
    public static final String ACTION_APP_FAILURE_RESET =
            "com.tmobile.intent.action.APP_FAILURE_RESET";

    /**
     * Activity Action: Shows the brightness setting dialog.
+3 −3
Original line number Diff line number Diff line
@@ -3181,10 +3181,10 @@
            </intent-filter>
        </receiver>

        <receiver android:name="com.android.server.AppsLaunchFailureReceiver" >
        <receiver android:name="com.android.server.AppsFailureReceiver" >
            <intent-filter>
                <action android:name="com.tmobile.intent.action.APP_LAUNCH_FAILURE" />
                <action android:name="com.tmobile.intent.action.APP_LAUNCH_FAILURE_RESET" />
                <action android:name="com.tmobile.intent.action.APP_FAILURE" />
                <action android:name="com.tmobile.intent.action.APP_FAILURE_RESET" />
                <action android:name="android.intent.action.PACKAGE_ADDED" />
                <action android:name="android.intent.action.PACKAGE_REMOVED" />
                <action android:name="org.cyanogenmod.intent.action.THEME_CHANGED" />
+3 −0
Original line number Diff line number Diff line
@@ -241,4 +241,7 @@
    <!-- Theme installation error notification -->
    <string name="theme_install_error_title">Failed to install theme</string>
    <string name="theme_install_error_message">%s failed to install</string>

    <string name="theme_reset_notification_title">Theme reset</string>
    <string name="theme_reset_notification_body">System theme restored due to multiple app crashes.</string>
</resources>
+5 −1
Original line number Diff line number Diff line
@@ -233,4 +233,8 @@
    <!-- First boot install dialog -->
    <java-symbol type="string" name="android_installing_apk" />
    <java-symbol type="string" name="android_installing_title" />

    <!-- Theme reset notification -->
    <java-symbol type="string" name="theme_reset_notification_title" />
    <java-symbol type="string" name="theme_reset_notification_body" />
</resources>
Loading