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

Commit 5c5b4850 authored by Benedict Wong's avatar Benedict Wong
Browse files

Prevent concurrent modification exceptions in VcnManagementService

In order to prevent concurrent modifications from triggering an
exception in the dump, proxy it to the handler thread.

Adding locks was considered, but would require auditing all callbacks
and proxying them to the handler threads in order to ensure lock
inversion and deadlocks never occur.

Bug: 188840899
Test: FrameworksVcnTests
Test: adb shell dumpsys vcn_management
Change-Id: Ibcc4bdc06301dd77260adaa0c086529f8f524679
Merged-In: Ibcc4bdc06301dd77260adaa0c086529f8f524679
(cherry picked from commit f8ce665d)
parent 95590e1a
Loading
Loading
Loading
Loading
+34 −29
Original line number Diff line number Diff line
@@ -148,6 +148,7 @@ import java.util.concurrent.TimeUnit;
// TODO(b/180451994): ensure all incoming + outgoing calls have a cleared calling identity
public class VcnManagementService extends IVcnManagementService.Stub {
    @NonNull private static final String TAG = VcnManagementService.class.getSimpleName();
    private static final long DUMP_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(5);

    public static final boolean VDBG = false; // STOPSHIP: if true

@@ -1001,6 +1002,8 @@ public class VcnManagementService extends IVcnManagementService.Stub {

        final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");

        // Post to handler thread to prevent ConcurrentModificationExceptions, and avoid lock-hell.
        mHandler.runWithScissors(() -> {
            pw.println("VcnManagementService dump:");
            pw.increaseIndent();

@@ -1026,7 +1029,8 @@ public class VcnManagementService extends IVcnManagementService.Stub {
                pw.println("mConfigs:");
                pw.increaseIndent();
                for (Entry<ParcelUuid, VcnConfig> entry : mConfigs.entrySet()) {
                pw.println(entry.getKey() + ": " + entry.getValue().getProvisioningPackageName());
                    pw.println(entry.getKey() + ": "
                            + entry.getValue().getProvisioningPackageName());
                }
                pw.decreaseIndent();
                pw.println();
@@ -1041,6 +1045,7 @@ public class VcnManagementService extends IVcnManagementService.Stub {
            }

            pw.decreaseIndent();
        }, DUMP_TIMEOUT_MILLIS);
    }

    // TODO(b/180452282): Make name more generic and implement directly with VcnManagementService