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

Commit cb21d8ff authored by riddle_hsu's avatar riddle_hsu Committed by Steve Kondik
Browse files

[ActivityManager] Avoid unnecessary restart provider process

Caller C accesses provider P. Both processes of C and P died
before P publishes, P will still be restarted even there is
no connection because P is in mLaunchingProviders.
When device is low memory, the restarting provider process
may be killed easily before publish because no caller to raise
its oom-adj. Then device will busy keeping restart it.

Solution:
If there is no connection to the provider, do not restart it.

Change-Id: If6f2d2258d78b6c0989c6e5f3e0cad14db821464
(cherry picked from commit fb90eb27)
parent 7dc2cd92
Loading
Loading
Loading
Loading
+11 −15
Original line number Diff line number Diff line
@@ -15046,7 +15046,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            }
        }
        for (int i=0; i<cpr.connections.size(); i++) {
        for (int i = cpr.connections.size() - 1; i >= 0; i--) {
            ContentProviderConnection conn = cpr.connections.get(i);
            if (conn.waiting) {
                // If this connection is waiting for the provider, then we don't
@@ -15141,7 +15141,8 @@ public final class ActivityManagerService extends ActivityManagerNative
        for (int i = app.pubProviders.size() - 1; i >= 0; i--) {
            ContentProviderRecord cpr = app.pubProviders.valueAt(i);
            final boolean always = app.bad || !allowRestart;
            if (removeDyingProviderLocked(app, cpr, always) || always) {
            boolean inLaunching = removeDyingProviderLocked(app, cpr, always);
            if ((inLaunching || always) && !cpr.connections.isEmpty()) {
                // We left the provider in the launching list, need to
                // restart it.
                restart = true;
@@ -15159,7 +15160,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        // Unregister from connected content providers.
        if (!app.conProviders.isEmpty()) {
            for (int i=0; i<app.conProviders.size(); i++) {
            for (int i = app.conProviders.size() - 1; i >= 0; i--) {
                ContentProviderConnection conn = app.conProviders.get(i);
                conn.provider.connections.remove(conn);
                stopAssociationLocked(app.uid, app.processName, conn.provider.uid,
@@ -15174,9 +15175,8 @@ public final class ActivityManagerService extends ActivityManagerNative
        // XXX Commented out for now.  Trying to figure out a way to reproduce
        // the actual situation to identify what is actually going on.
        if (false) {
            for (int i=0; i<mLaunchingProviders.size(); i++) {
                ContentProviderRecord cpr = (ContentProviderRecord)
                        mLaunchingProviders.get(i);
            for (int i = mLaunchingProviders.size() - 1; i >= 0; i--) {
                ContentProviderRecord cpr = mLaunchingProviders.get(i);
                if (cpr.connections.size() <= 0 && !cpr.hasExternalProcessHandles()) {
                    synchronized (cpr) {
                        cpr.launchingApp = null;
@@ -15282,18 +15282,14 @@ public final class ActivityManagerService extends ActivityManagerNative
        // and if any run in this process then either schedule a restart of
        // the process or kill the client waiting for it if this process has
        // gone bad.
        int NL = mLaunchingProviders.size();
        boolean restart = false;
        for (int i=0; i<NL; i++) {
        for (int i = mLaunchingProviders.size() - 1; i >= 0; i--) {
            ContentProviderRecord cpr = mLaunchingProviders.get(i);
            if (cpr.launchingApp == app) {
                if (!alwaysBad && !app.bad) {
                if (!alwaysBad && !app.bad && !cpr.connections.isEmpty()) {
                    restart = true;
                } else {
                    removeDyingProviderLocked(app, cpr, true);
                    // cpr should have been removed from mLaunchingProviders
                    NL = mLaunchingProviders.size();
                    i--;
                }
            }
        }