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

Commit 6e191ea8 authored by Ben Miles's avatar Ben Miles
Browse files

Improve debug store logging for enhanced ANR actionability

- Adds debug store logging for job service lifecycle events
- Adds debug store logging for application binding
- Add some more debug store events for service lifecycle
- Some minor tweaks/cleanup for consistency

The rationale for these new events is to make ANRs (especially job service and service exec ANRs) more debuggable.

Bug: 409760497
Flag: com.android.internal.os.debug_store_enabled
Change-Id: Icb499776da4ece4a5e9a5a72783f014980ba995f
parent 787addce
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.os.Message;
import android.os.RemoteException;
import android.util.Log;

import com.android.internal.os.DebugStore;
import com.android.internal.os.SomeArgs;

import java.lang.ref.WeakReference;
@@ -79,6 +80,9 @@ public abstract class JobServiceEngine {
    /** Message that the network to use has changed. */
    private static final int MSG_INFORM_OF_NETWORK_CHANGE = 8;

    private static final boolean DEBUG_STORE_ENABLED =
            com.android.internal.os.Flags.debugStoreEnabled();

    private final IJobService mBinder;

    /**
@@ -125,6 +129,12 @@ public abstract class JobServiceEngine {
            JobServiceEngine service = mService.get();
            if (service != null) {
                Message m = Message.obtain(service.mHandler, MSG_EXECUTE_JOB, jobParams);
                if (DEBUG_STORE_ENABLED) {
                    DebugStore.recordScheduleStartJob(
                            System.identityHashCode(m.obj),
                            jobParams.getJobId(),
                            jobParams.getJobNamespace());
                }
                m.sendToTarget();
            }
        }
@@ -144,6 +154,12 @@ public abstract class JobServiceEngine {
            JobServiceEngine service = mService.get();
            if (service != null) {
                Message m = Message.obtain(service.mHandler, MSG_STOP_JOB, jobParams);
                if (DEBUG_STORE_ENABLED) {
                    DebugStore.recordScheduleStopJob(
                            System.identityHashCode(m.obj),
                            jobParams.getJobId(),
                            jobParams.getJobNamespace());
                }
                m.sendToTarget();
            }
        }
@@ -164,6 +180,11 @@ public abstract class JobServiceEngine {
            switch (msg.what) {
                case MSG_EXECUTE_JOB: {
                    final JobParameters params = (JobParameters) msg.obj;
                    long debugStoreId = -1;
                    if (DEBUG_STORE_ENABLED) {
                            debugStoreId =
                                    DebugStore.recordStartJob(System.identityHashCode(params));
                    }
                    try {
                        params.enableCleaner();
                        boolean workOngoing = JobServiceEngine.this.onStartJob(params);
@@ -174,17 +195,29 @@ public abstract class JobServiceEngine {
                    } catch (Exception e) {
                        Log.e(TAG, "Error while executing job: " + params.getJobId());
                        throw new RuntimeException(e);
                    } finally {
                        if (DEBUG_STORE_ENABLED) {
                            DebugStore.recordEventEnd(debugStoreId);
                        }
                    }
                    break;
                }
                case MSG_STOP_JOB: {
                    final JobParameters params = (JobParameters) msg.obj;
                    long debugStoreId = -1;
                    if (DEBUG_STORE_ENABLED) {
                        debugStoreId = DebugStore.recordStopJob(System.identityHashCode(params));
                    }
                    try {
                        boolean ret = JobServiceEngine.this.onStopJob(params);
                        ackStopMessage(params, ret);
                    } catch (Exception e) {
                        Log.e(TAG, "Application unable to handle onStopJob.", e);
                        throw new RuntimeException(e);
                    } finally {
                        if (DEBUG_STORE_ENABLED) {
                            DebugStore.recordEventEnd(debugStoreId);
                        }
                    }
                    break;
                }
+31 −28
Original line number Diff line number Diff line
@@ -1151,19 +1151,15 @@ public final class ActivityThread extends ClientTransactionHandler
                CompatibilityInfo compatInfo, int resultCode, String data, Bundle extras,
                boolean ordered, boolean assumeDelivered, int sendingUser, int processState,
                int sendingUid, String sendingPackage) {
            long debugStoreId = -1;
            if (DEBUG_STORE_ENABLED) {
                debugStoreId = DebugStore.recordScheduleReceiver();
            }
            updateProcessState(processState, false);
            ReceiverData r = new ReceiverData(intent, resultCode, data, extras,
                    ordered, false, assumeDelivered, mAppThread.asBinder(), sendingUser,
                    sendingUid, sendingPackage);
            r.info = info;
            sendMessage(H.RECEIVER, r);
            if (DEBUG_STORE_ENABLED) {
                DebugStore.recordEventEnd(debugStoreId);
                DebugStore.recordScheduleBroadcastReceive(System.identityHashCode(r), intent);
            }
            sendMessage(H.RECEIVER, r);
        }

        public final void scheduleReceiverList(List<ReceiverInfo> info) throws RemoteException {
@@ -1213,6 +1209,9 @@ public final class ActivityThread extends ClientTransactionHandler
                Trace.instant(Trace.TRACE_TAG_ACTIVITY_MANAGER, "scheduleCreateService. token="
                        + token);
            }
            if (DEBUG_STORE_ENABLED) {
                DebugStore.recordScheduleServiceCreate(System.identityHashCode(s), info);
            }
            sendMessage(H.CREATE_SERVICE, s);
        }

@@ -1233,6 +1232,9 @@ public final class ActivityThread extends ClientTransactionHandler
                Trace.instant(Trace.TRACE_TAG_ACTIVITY_MANAGER, "scheduleBindService. token="
                        + token + " bindSeq=" + bindSeq);
            }
            if (DEBUG_STORE_ENABLED) {
                DebugStore.recordScheduleServiceBind(System.identityHashCode(s), s.intent);
            }
            sendMessage(H.BIND_SERVICE, s);
        }

@@ -1265,6 +1267,9 @@ public final class ActivityThread extends ClientTransactionHandler
                    Trace.instant(Trace.TRACE_TAG_ACTIVITY_MANAGER, "scheduleServiceArgs. token="
                            + token + " startId=" + s.startId);
                }
                if (DEBUG_STORE_ENABLED) {
                    DebugStore.recordScheduleServiceStart(System.identityHashCode(s), s.args);
                }
                sendMessage(H.SERVICE_ARGS, s);
            }
        }
@@ -1332,6 +1337,9 @@ public final class ActivityThread extends ClientTransactionHandler
                FileDescriptor applicationSharedMemoryFd,
                long startRequestedElapsedTime,
                long startRequestedUptime) {
            if (DEBUG_STORE_ENABLED) {
                DebugStore.recordScheduleBindApplication();
            }
            if (services != null) {
                if (false) {
                    // Test code to make sure the app could see the passed-in services.
@@ -1509,10 +1517,6 @@ public final class ActivityThread extends ClientTransactionHandler
                boolean sticky, boolean assumeDelivered, int sendingUser, int processState,
                int sendingUid, String sendingPackage)
                throws RemoteException {
            long debugStoreId = -1;
            if (DEBUG_STORE_ENABLED) {
                debugStoreId = DebugStore.recordScheduleRegisteredReceiver();
            }
            updateProcessState(processState, false);

            // We can't modify IIntentReceiver due to UnsupportedAppUsage, so
@@ -1537,9 +1541,6 @@ public final class ActivityThread extends ClientTransactionHandler
                receiver.performReceive(intent, resultCode, dataStr, extras, ordered, sticky,
                        sendingUser);
            }
            if (DEBUG_STORE_ENABLED) {
                DebugStore.recordEventEnd(debugStoreId);
            }
        }

        @Override
@@ -2539,7 +2540,7 @@ public final class ActivityThread extends ClientTransactionHandler
                    Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "bindApplication");
                    if (DEBUG_STORE_ENABLED) {
                        debugStoreId =
                                DebugStore.recordHandleBindApplication();
                                DebugStore.recordBindApplication();
                    }
                    AppBindData data = (AppBindData)msg.obj;
                    handleBindApplication(data);
@@ -2566,20 +2567,10 @@ public final class ActivityThread extends ClientTransactionHandler
                        }
                    }
                    ReceiverData receiverData = (ReceiverData) msg.obj;
                    if (DEBUG_STORE_ENABLED) {
                        debugStoreId =
                            DebugStore.recordBroadcastReceive(
                                receiverData.intent, System.identityHashCode(receiverData));
                    }

                    try {
                        handleReceiver(receiverData);
                    } finally {
                        Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
                        if (DEBUG_STORE_ENABLED) {
                            DebugStore.recordEventEnd(debugStoreId);
                            shouldLogLongMessage = false;
                        }
                    }
                    break;
                case CREATE_SERVICE:
@@ -2589,7 +2580,9 @@ public final class ActivityThread extends ClientTransactionHandler
                    }
                    CreateServiceData createServiceData = (CreateServiceData) msg.obj;
                    if (DEBUG_STORE_ENABLED) {
                        debugStoreId = DebugStore.recordServiceCreate(createServiceData.info);
                        debugStoreId =
                                DebugStore.recordServiceCreate(
                                        System.identityHashCode(msg.obj));
                    }

                    try {
@@ -2610,7 +2603,8 @@ public final class ActivityThread extends ClientTransactionHandler
                    BindServiceData bindData = (BindServiceData) msg.obj;
                    if (DEBUG_STORE_ENABLED) {
                        debugStoreId =
                                DebugStore.recordServiceBind(bindData.rebind, bindData.intent);
                                DebugStore.recordServiceBind(
                                        System.identityHashCode(msg.obj));
                    }
                    try {
                        handleBindService(bindData);
@@ -2638,8 +2632,9 @@ public final class ActivityThread extends ClientTransactionHandler
                    }
                    ServiceArgsData serviceData = (ServiceArgsData) msg.obj;
                    if (DEBUG_STORE_ENABLED) {
                        debugStoreId = DebugStore.recordServiceOnStart(serviceData.startId,
                                serviceData.flags, serviceData.args);
                        debugStoreId =
                                DebugStore.recordServiceStart(
                                        System.identityHashCode(msg.obj));
                    }

                    try {
@@ -5021,6 +5016,11 @@ public final class ActivityThread extends ClientTransactionHandler
                + ": " + e.toString(), e);
        }

        long debugStoreId = -1;
        if(DEBUG_STORE_ENABLED) {
            debugStoreId = DebugStore.recordBroadcastReceive(System.identityHashCode(data),
                receiver.getClass().getSimpleName());
        }
        try {
            if (localLOGV) Slog.v(
                TAG, "Performing receive of " + data.intent
@@ -5045,6 +5045,9 @@ public final class ActivityThread extends ClientTransactionHandler
            }
        } finally {
            sCurrentBroadcastIntent.set(null);
            if(DEBUG_STORE_ENABLED) {
                DebugStore.recordEventEnd(debugStoreId);
            }
        }

        if (receiver.getPendingResult() != null) {
+6 −1
Original line number Diff line number Diff line
@@ -1828,7 +1828,8 @@ public final class LoadedApk {
                    if (DEBUG_STORE_ENABLED) {
                        debugStoreId =
                                DebugStore.recordBroadcastReceiveReg(
                                        intent, System.identityHashCode(this));
                                    System.identityHashCode(this),
                                    receiver.getClass().getName());
                    }

                    try {
@@ -1934,6 +1935,10 @@ public final class LoadedApk {
                            + " seq=" + seq + " to " + mReceiver);
                }
            }

            if (DEBUG_STORE_ENABLED) {
                DebugStore.recordScheduleBroadcastReceiveReg(System.identityHashCode(args), intent);
            }
            if (intent == null || !mActivityThread.post(args.getRunnable())) {
                IActivityManager mgr = ActivityManager.getService();
                if (ActivityThread.DEBUG_BROADCAST) Slog.i(ActivityThread.TAG,
+248 −116

File changed.

Preview size limit exceeded, changes collapsed.

+247 −164

File changed.

Preview size limit exceeded, changes collapsed.