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

Commit 5249bb11 authored by Andrii Kulian's avatar Andrii Kulian
Browse files

Revert "Fix object pool for lifecycler"

This reverts commit 1c110302.

Reason for revert: Trying to recycle already recycled item on rotation.

Change-Id: I1ae8337da28aa0923cc1d77a23f2ab5e42957495
parent 1c110302
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -1650,9 +1650,7 @@ public final class ActivityThread extends ClientTransactionHandler {
                            (String[]) ((SomeArgs) msg.obj).arg2);
                    break;
                case EXECUTE_TRANSACTION:
                    final ClientTransaction transaction = (ClientTransaction) msg.obj;
                    mTransactionExecutor.execute(transaction);
                    transaction.recycle();
                    mTransactionExecutor.execute(((ClientTransaction) msg.obj));
                    break;
            }
            Object obj = msg.obj;
+0 −5
Original line number Diff line number Diff line
@@ -54,11 +54,6 @@ public class ClientTransaction implements Parcelable, ObjectPoolItem {
    /** Target client activity. Might be null if the entire transaction is targeting an app. */
    private IBinder mActivityToken;

    /** Get the target client of the transaction. */
    public IApplicationThread getClient() {
        return mClient;
    }

    /**
     * Add a message to the end of the sequence of callbacks.
     * @param activityCallback A single message that can contain a lifecycle request/callback.
+9 −13
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@

package android.app.servertransaction;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

/**
@@ -27,7 +27,7 @@ import java.util.Map;
class ObjectPool {

    private static final Object sPoolSync = new Object();
    private static final Map<Class, ArrayList<? extends ObjectPoolItem>> sPoolMap =
    private static final Map<Class, LinkedList<? extends ObjectPoolItem>> sPoolMap =
            new HashMap<>();

    private static final int MAX_POOL_SIZE = 50;
@@ -40,9 +40,9 @@ class ObjectPool {
    public static <T extends ObjectPoolItem> T obtain(Class<T> itemClass) {
        synchronized (sPoolSync) {
            @SuppressWarnings("unchecked")
            final ArrayList<T> itemPool = (ArrayList<T>) sPoolMap.get(itemClass);
            LinkedList<T> itemPool = (LinkedList<T>) sPoolMap.get(itemClass);
            if (itemPool != null && !itemPool.isEmpty()) {
                return itemPool.remove(itemPool.size() - 1);
                return itemPool.poll();
            }
            return null;
        }
@@ -56,20 +56,16 @@ class ObjectPool {
    public static <T extends ObjectPoolItem> void recycle(T item) {
        synchronized (sPoolSync) {
            @SuppressWarnings("unchecked")
            ArrayList<T> itemPool = (ArrayList<T>) sPoolMap.get(item.getClass());
            LinkedList<T> itemPool = (LinkedList<T>) sPoolMap.get(item.getClass());
            if (itemPool == null) {
                itemPool = new ArrayList<>();
                itemPool = new LinkedList<>();
                sPoolMap.put(item.getClass(), itemPool);
            }
            // Check if the item is already in the pool
            final int size = itemPool.size();
            for (int i = 0; i < size; i++) {
                if (itemPool.get(i) == item) {
            if (itemPool.contains(item)) {
                throw new IllegalStateException("Trying to recycle already recycled item");
            }
            }

            if (size < MAX_POOL_SIZE) {
            if (itemPool.size() < MAX_POOL_SIZE) {
                itemPool.add(item);
            }
        }
+2 −1
Original line number Diff line number Diff line
@@ -42,7 +42,8 @@ import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
@SmallTest
@Presubmit
// TODO: b/70616950
//@Presubmit
public class ObjectPoolTests {

    // 1. Check if two obtained objects from pool are not the same.
+2 −7
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.app.IApplicationThread;
import android.app.servertransaction.ClientTransaction;
import android.app.servertransaction.ClientTransactionItem;
import android.app.servertransaction.ActivityLifecycleItem;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;

@@ -44,12 +43,8 @@ class ClientLifecycleManager {
     */
    void scheduleTransaction(ClientTransaction transaction) throws RemoteException {
        transaction.schedule();
        if (!(transaction.getClient() instanceof Binder)) {
            // If client is not an instance of Binder - it's a remote call and at this point it is
            // safe to recycle the object. All objects used for local calls will be recycled after
            // the transaction is executed on client in ActivityThread.
            transaction.recycle();
        }
        // TODO: b/70616950
        //transaction.recycle();
    }

    /**