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

Commit e9da8c28 authored by Yisroel Forta's avatar Yisroel Forta
Browse files

Catch exception for ProfilingServiceHelper#getInstance

ProfilingServiceHelper#getInstance can throw
IllegalStateException, as noted in JavaDoc, but callers are not
currently handling it. This happens when the Service is not
available, which is expected to occur if a trigger is sent
before ProfilingService starts up. Catch and ignore this
exception as there is nothing else to do, trigger will be lost.

- Catch exception in AMS#sendProfilingTrigger
- Update start trigger to use AMS#sendProfilingTrigger

Flag: EXEMPT - simple bugfix
Bug: 421357419
Test: presubmit
Change-Id: I23be1e4e8303651015ba38863ddb8d3388203225
parent 49dc70da
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -1112,7 +1112,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                    && startInfo != null
                    && startInfo.getStartType() == ApplicationStartInfo.START_TYPE_COLD
                    && startInfo.getPackageName() != null) {
                ProfilingServiceHelper.getInstance().onProfilingTriggerOccurred(
                sendProfilingTrigger(
                        startInfo.getRealUid(),
                        startInfo.getPackageName(),
                        ProfilingTrigger.TRIGGER_TYPE_APP_FULLY_DRAWN);
@@ -19671,11 +19671,16 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    /** Helper method for sending profiling triggers asynchronously. */
    private void sendProfilingTrigger(int uid, @NonNull String packageName, int triggerType) {
    public void sendProfilingTrigger(int uid, @NonNull String packageName, int triggerType) {
        mHandler.post(new Runnable() {
            @Override public void run() {
                try {
                    ProfilingServiceHelper.getInstance().onProfilingTriggerOccurred(
                            uid, packageName, triggerType);
                } catch (IllegalStateException e) {
                    // Service isn't set up yet, do nothing, trigger will not be sent.
                   Slog.d(TAG, "Profiling trigger not sent due to Service not running.", e);
                }
            }
        });
    }