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

Commit cad7d7fb authored by Yi Kong's avatar Yi Kong
Browse files

profcollect: Use postDelayed instead of starting a thread and sleep

Addresses follow-up comments from https://r.android.com/3115077.

Change-Id: I6abaee35a4797c4e0d43daffaf2ab49d650cd9cc
Test: presubmit
Bug: 319394981
parent b6c0fa01
Loading
Loading
Loading
Loading
+8 −11
Original line number Diff line number Diff line
@@ -323,16 +323,14 @@ public final class ProfcollectForwardingService extends SystemService {
                "dex2oat_trace_freq", 25);
        int randomNum = ThreadLocalRandom.current().nextInt(100);
        if (randomNum < traceFrequency) {
            BackgroundThread.get().getThreadHandler().post(() -> {
            // Dex2oat could take a while before it starts. Add a short delay before start tracing.
            BackgroundThread.get().getThreadHandler().postDelayed(() -> {
                try {
                    // Dex2oat could take a while before it starts. Add a short delay before start
                    // tracing.
                    Thread.sleep(1000);
                    mIProfcollect.trace_once("dex2oat");
                } catch (RemoteException | InterruptedException e) {
                } catch (RemoteException e) {
                    Log.e(LOG_TAG, "Failed to initiate trace: " + e.getMessage());
                }
            });
            }, 1000);
        }
    }

@@ -394,15 +392,14 @@ public final class ProfcollectForwardingService extends SystemService {
                if (randomNum >= traceFrequency) {
                    return;
                }
                BackgroundThread.get().getThreadHandler().post(() -> {
                // Wait for 1s before starting tracing.
                BackgroundThread.get().getThreadHandler().postDelayed(() -> {
                    try {
                        // Wait for a short time before starting tracing.
                        Thread.sleep(1000);
                        mIProfcollect.trace_once("camera");
                    } catch (RemoteException | InterruptedException e) {
                    } catch (RemoteException e) {
                        Log.e(LOG_TAG, "Failed to initiate trace: " + e.getMessage());
                    }
                });
                }, 1000);
            }
        }, null);
    }