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

Commit 86c3009d authored by Joanne Chung's avatar Joanne Chung Committed by Automerger Merge Worker
Browse files

Merge "Revert "Rebind ContentCaptureService when the binderDied."" into tm-dev...

Merge "Revert "Rebind ContentCaptureService when the binderDied."" into tm-dev am: aa6bb0ad am: 94e6aba3

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18596156



Change-Id: I9ae333665599639b3b74bbf38171b289c6d35aa9
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 8bef222b 94e6aba3
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -223,7 +223,7 @@ public final class ContentCaptureManagerService extends
    @Override // from AbstractMasterSystemService
    @Override // from AbstractMasterSystemService
    protected ContentCapturePerUserService newServiceLocked(@UserIdInt int resolvedUserId,
    protected ContentCapturePerUserService newServiceLocked(@UserIdInt int resolvedUserId,
            boolean disabled) {
            boolean disabled) {
        return new ContentCapturePerUserService(this, mLock, disabled, resolvedUserId, mHandler);
        return new ContentCapturePerUserService(this, mLock, disabled, resolvedUserId);
    }
    }


    @Override // from SystemService
    @Override // from SystemService
+6 −55
Original line number Original line Diff line number Diff line
@@ -46,7 +46,6 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ServiceInfo;
import android.content.pm.ServiceInfo;
import android.os.Binder;
import android.os.Binder;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder;
import android.os.UserHandle;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Settings;
@@ -76,7 +75,6 @@ import com.android.server.contentcapture.RemoteContentCaptureService.ContentCapt
import com.android.server.infra.AbstractPerUserSystemService;
import com.android.server.infra.AbstractPerUserSystemService;


import java.io.PrintWriter;
import java.io.PrintWriter;
import java.time.Instant;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;


@@ -90,10 +88,6 @@ final class ContentCapturePerUserService


    private static final String TAG = ContentCapturePerUserService.class.getSimpleName();
    private static final String TAG = ContentCapturePerUserService.class.getSimpleName();


    private static final int MAX_REBIND_COUNTS = 5;
    // 5 minutes
    private static final long REBIND_DURATION_MS = 5 * 60 * 1_000;

    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private final SparseArray<ContentCaptureServerSession> mSessions = new SparseArray<>();
    private final SparseArray<ContentCaptureServerSession> mSessions = new SparseArray<>();


@@ -127,18 +121,11 @@ final class ContentCapturePerUserService
    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private ContentCaptureServiceInfo mInfo;
    private ContentCaptureServiceInfo mInfo;


    private Instant mLastRebindTime;
    private int mRebindCount;
    private final Handler mHandler;

    private final Runnable mReBindServiceRunnable = new RebindServiceRunnable();

    // TODO(b/111276913): add mechanism to prune stale sessions, similar to Autofill's
    // TODO(b/111276913): add mechanism to prune stale sessions, similar to Autofill's


    ContentCapturePerUserService(@NonNull ContentCaptureManagerService master,
    ContentCapturePerUserService(@NonNull ContentCaptureManagerService master,
            @NonNull Object lock, boolean disabled, @UserIdInt int userId, Handler handler) {
            @NonNull Object lock, boolean disabled, @UserIdInt int userId) {
        super(master, lock, userId);
        super(master, lock, userId);
        mHandler = handler;
        updateRemoteServiceLocked(disabled);
        updateRemoteServiceLocked(disabled);
    }
    }


@@ -203,44 +190,10 @@ final class ContentCapturePerUserService
        Slog.w(TAG, "remote service died: " + service);
        Slog.w(TAG, "remote service died: " + service);
        synchronized (mLock) {
        synchronized (mLock) {
            mZombie = true;
            mZombie = true;
            // Reset rebindCount if over 12 hours mLastRebindTime
            if (mLastRebindTime != null && Instant.now().isAfter(
                    mLastRebindTime.plusMillis(12 * 60 * 60 * 1000))) {
                if (mMaster.debug) {
                    Slog.i(TAG, "The current rebind count " + mRebindCount + " is reset.");
                }
                mRebindCount = 0;
            }
            if (mRebindCount >= MAX_REBIND_COUNTS) {
            writeServiceEvent(
            writeServiceEvent(
                    FrameworkStatsLog.CONTENT_CAPTURE_SERVICE_EVENTS__EVENT__ON_REMOTE_SERVICE_DIED,
                    FrameworkStatsLog.CONTENT_CAPTURE_SERVICE_EVENTS__EVENT__ON_REMOTE_SERVICE_DIED,
                    getServiceComponentName());
                    getServiceComponentName());
        }
        }
            if (mRebindCount < MAX_REBIND_COUNTS) {
                mHandler.removeCallbacks(mReBindServiceRunnable);
                mHandler.postDelayed(mReBindServiceRunnable, REBIND_DURATION_MS);
            }
        }
    }

    private void updateRemoteServiceAndResurrectSessionsLocked() {
        boolean disabled = !isEnabledLocked();
        updateRemoteServiceLocked(disabled);
        resurrectSessionsLocked();
    }

    private final class RebindServiceRunnable implements Runnable{

        @Override
        public void run() {
            synchronized (mLock) {
                if (mZombie) {
                    mLastRebindTime = Instant.now();
                    mRebindCount++;
                    updateRemoteServiceAndResurrectSessionsLocked();
                }
            }
        }
    }
    }


    /**
    /**
@@ -287,8 +240,8 @@ final class ContentCapturePerUserService
    }
    }


    void onPackageUpdatedLocked() {
    void onPackageUpdatedLocked() {
        mRebindCount = 0;
        updateRemoteServiceLocked(!isEnabledLocked());
        updateRemoteServiceAndResurrectSessionsLocked();
        resurrectSessionsLocked();
    }
    }


    @GuardedBy("mLock")
    @GuardedBy("mLock")
@@ -602,8 +555,6 @@ final class ContentCapturePerUserService
            mInfo.dump(prefix2, pw);
            mInfo.dump(prefix2, pw);
        }
        }
        pw.print(prefix); pw.print("Zombie: "); pw.println(mZombie);
        pw.print(prefix); pw.print("Zombie: "); pw.println(mZombie);
        pw.print(prefix); pw.print("Rebind count: "); pw.println(mRebindCount);
        pw.print(prefix); pw.print("Last rebind: "); pw.println(mLastRebindTime);


        if (mRemoteService != null) {
        if (mRemoteService != null) {
            pw.print(prefix); pw.println("remote service:");
            pw.print(prefix); pw.println("remote service:");