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

Commit 6b9d3a14 authored by Andrii Kulian's avatar Andrii Kulian
Browse files

Add transaction unit tests

Bug: 64797980
Test: android.app.servertransaction.ClientTransactionTests
Test: android.app.servertransaction.TransactionParcelTests
Change-Id: I108bacc819e9d43d0a2f5a30338ae88674a53239
parent 446e824e
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.Parcelable;
import android.util.Slog;

import java.io.IOException;
import java.util.Objects;

/**
 * System private API for passing profiler settings.
@@ -132,4 +133,32 @@ public class ProfilerInfo implements Parcelable {
        streamingOutput = in.readInt() != 0;
        agent = in.readString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        final ProfilerInfo other = (ProfilerInfo) o;
        // TODO: Also check #profileFd for equality.
        return Objects.equals(profileFile, other.profileFile)
                && autoStopProfiler == other.autoStopProfiler
                && samplingInterval == other.samplingInterval
                && streamingOutput == other.streamingOutput
                && Objects.equals(agent, other.agent);
    }

    @Override
    public int hashCode() {
        int result = 17;
        result = 31 * result + Objects.hashCode(profileFile);
        result = 31 * result + samplingInterval;
        result = 31 * result + (autoStopProfiler ? 1 : 0);
        result = 31 * result + (streamingOutput ? 1 : 0);
        result = 31 * result + Objects.hashCode(agent);
        return result;
    }
}
+27 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.Objects;

/**
 * {@hide}
 */
@@ -79,4 +81,29 @@ public class ResultInfo implements Parcelable {
            mData = null;
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null || !(obj instanceof ResultInfo)) {
            return false;
        }
        final ResultInfo other = (ResultInfo) obj;
        final boolean intentsEqual = mData == null ? (other.mData == null)
                : mData.filterEquals(other.mData);
        return intentsEqual && Objects.equals(mResultWho, other.mResultWho)
                && mResultCode == other.mResultCode
                && mRequestCode == other.mRequestCode;
    }

    @Override
    public int hashCode() {
        int result = 17;
        result = 31 * result + mRequestCode;
        result = 31 * result + mResultCode;
        result = 31 * result + Objects.hashCode(mResultWho);
        if (mData != null) {
            result = 31 * result + mData.filterHashCode();
        }
        return result;
    }
}
+17 −0
Original line number Diff line number Diff line
@@ -68,4 +68,21 @@ public class ActivityConfigurationChangeItem extends ClientTransactionItem {
            return new ActivityConfigurationChangeItem[size];
        }
    };

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        final ActivityConfigurationChangeItem other = (ActivityConfigurationChangeItem) o;
        return mConfiguration.equals(other.mConfiguration);
    }

    @Override
    public int hashCode() {
        return mConfiguration.hashCode();
    }
}
+17 −0
Original line number Diff line number Diff line
@@ -75,4 +75,21 @@ public class ActivityResultItem extends ClientTransactionItem {
            return new ActivityResultItem[size];
        }
    };

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        final ActivityResultItem other = (ActivityResultItem) o;
        return mResultInfoList.equals(other.mResultInfoList);
    }

    @Override
    public int hashCode() {
        return mResultInfoList.hashCode();
    }
}
+30 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.app.servertransaction;

import android.app.ClientTransactionHandler;
import android.app.IApplicationThread;
import android.os.IBinder;
import android.os.Parcel;
@@ -24,6 +25,7 @@ import android.os.RemoteException;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * A container that holds a sequence of messages, which may be sent to a client.
@@ -112,11 +114,12 @@ public class ClientTransaction implements Parcelable {
    /**
     * Schedule the transaction after it was initialized. It will be send to client and all its
     * individual parts will be applied in the following sequence:
     * 1. The client calls {@link #prepare()}, which triggers all work that needs to be done before
     *    actually scheduling the transaction for callbacks and lifecycle state request.
     * 1. The client calls {@link #prepare(ClientTransactionHandler)}, which triggers all work that
     *    needs to be done before actually scheduling the transaction for callbacks and lifecycle
     *    state request.
     * 2. The transaction message is scheduled.
     * 3. The client calls {@link #execute()}, which executes all callbacks and necessary lifecycle
     *    transitions.
     * 3. The client calls {@link #execute(ClientTransactionHandler)}, which executes all callbacks
     *    and necessary lifecycle transitions.
     */
    public void schedule() throws RemoteException {
        mClient.scheduleTransaction(this);
@@ -172,4 +175,27 @@ public class ClientTransaction implements Parcelable {
    public int describeContents() {
        return 0;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        final ClientTransaction other = (ClientTransaction) o;
        return Objects.equals(mActivityCallbacks, other.mActivityCallbacks)
                && Objects.equals(mLifecycleStateRequest, other.mLifecycleStateRequest)
                && mClient == other.mClient
                && mActivityToken == other.mActivityToken;
    }

    @Override
    public int hashCode() {
        int result = 17;
        result = 31 * result + Objects.hashCode(mActivityCallbacks);
        result = 31 * result + Objects.hashCode(mLifecycleStateRequest);
        return result;
    }
}
Loading