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

Commit ca35025c authored by Dhavalkumar Chaudhary's avatar Dhavalkumar Chaudhary Committed by Android (Google) Code Review
Browse files

Merge "Skip refContentProvider calls for unstable connections and PERSISTENT apps" into main

parents f91b3dd6 f1196a6b
Loading
Loading
Loading
Loading
+26 −4
Original line number Diff line number Diff line
@@ -8301,8 +8301,19 @@ public final class ActivityThread extends ClientTransactionHandler
                            Slog.v(TAG, "incProviderRef: Now unstable - "
                                    + prc.holder.info.name);
                        }
                        if (Flags.skipRefContentProvider()) {
                            // If the provider is persistent process and has unstable
                            // connection, then we don't need to increment the ref count
                            // in the activity manager.
                            if (prc != null && prc.holder != null
                                        && !prc.holder.noReleaseNeededIfUnstable) {
                                ActivityManager.getService().refContentProvider(
                                        prc.holder.connection, 0, 1);
                            }
                        } else {
                            ActivityManager.getService().refContentProvider(
                                        prc.holder.connection, 0, 1);
                        }
                    } catch (RemoteException e) {
                        //do nothing content provider object is dead any way
                    }
@@ -8401,8 +8412,19 @@ public final class ActivityThread extends ClientTransactionHandler
                                Slog.v(TAG, "releaseProvider: No longer unstable - "
                                        + prc.holder.info.name);
                            }
                            if (Flags.skipRefContentProvider()) {
                                // If the provider is persistent process and has unstable
                                // connection, then we don't need to decrement the ref count
                                // in the activity manager.
                                if (prc != null && prc.holder != null
                                        && !prc.holder.noReleaseNeededIfUnstable) {
                                    ActivityManager.getService().refContentProvider(
                                            prc.holder.connection, 0, -1);
                                }
                            } else {
                                ActivityManager.getService().refContentProvider(
                                        prc.holder.connection, 0, -1);
                            }
                        } catch (RemoteException e) {
                            //do nothing content provider object is dead any way
                        }
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ public class ContentProviderHolder implements Parcelable {
    public IBinder connection;
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    public boolean noReleaseNeeded;
    public boolean noReleaseNeededIfUnstable;

    /**
     * Whether the provider here is a local provider or not.
+8 −0
Original line number Diff line number Diff line
@@ -197,3 +197,11 @@ flag {
     description: "Enable ProcessObserver's onProcessStarted callbacks."
     bug: "323959187"
}

flag {
     namespace: "backstage_power"
     name: "skip_ref_content_provider"
     description: "Skip refContentProvider calls for unstable connections"
     bug: "395544023"
     is_fixed_read_only: true
}
+4 −0
Original line number Diff line number Diff line
@@ -912,6 +912,10 @@ public class ContentProviderHelper {
                (conn.provider != null && conn.provider.info != null
                ? conn.provider.info.authority : ""));
        try {
            if (android.app.Flags.skipRefContentProvider()
                    && unstable <= 0 && conn.unstableCount() <= 0) {
                return false;
            }
            conn.adjustCounts(stable, unstable);
            return !conn.dead;
        } finally {
+14 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.server.am;

import static android.app.ActivityManager.PROCESS_STATE_PERSISTENT;
import static android.app.ActivityManager.PROCESS_STATE_PERSISTENT_UI;

import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;

import android.app.ContentProviderHolder;
@@ -92,6 +95,17 @@ final class ContentProviderRecord implements ComponentName.WithComponentName {
        holder.noReleaseNeeded = noReleaseNeeded;
        holder.connection = conn;
        holder.mLocal = local;

        if (android.app.Flags.skipRefContentProvider()) {
            if (conn == null || conn.provider == null || conn.provider.proc == null) {
                return holder;
            }
            final int procState = conn.provider.proc.getCurProcState();
            if (procState == PROCESS_STATE_PERSISTENT || procState == PROCESS_STATE_PERSISTENT_UI) {
                holder.noReleaseNeededIfUnstable = true;
            }
        }

        return holder;
    }