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

Commit ee8fc547 authored by Vairavan Srinivasan's avatar Vairavan Srinivasan Committed by Gerrit Code Review
Browse files

ContentProviderRecord: Remove external process reference when finalized

ContentProviderRecords is removed from provider map by activity manager service
when the process hosting the content providers terminates and this causes GC
to free the content provider records but the reference to external process
using the content provider isn't cleared. Fix is to clear the reference and
unlink for death notification.

Change-Id: I67fd10cee57b02257792d0c9b4569fe11dea7648
parent 0509374f
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;

class ContentProviderRecord {
    final ActivityManagerService service;
@@ -210,6 +211,21 @@ class ContentProviderRecord {
        return shortStringName = sb.toString();
    }

    protected void finalize() throws Throwable {
        try {
            synchronized (service) {
                if (externalProcessTokenToHandle != null) {
                    Iterator iterator = externalProcessTokenToHandle.keySet().iterator();
                    while (iterator.hasNext()) {
                         removeExternalProcessHandleInternalLocked((IBinder)iterator.next());
                    }
                }
            }
        } finally {
             super.finalize();
        }
    }

    // This class represents a handle from an external process to a provider.
    private class ExternalProcessHandle implements DeathRecipient {
        private static final String LOG_TAG = "ExternalProcessHanldle";