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

Commit b6bb7059 authored by Brint E. Kriebel's avatar Brint E. Kriebel
Browse files

Revert "Revert "PackageManager: Fix reconnection logic in Installer.""

This reverts commit 96bdd7ad.

Conflicts:
	services/java/com/android/server/pm/Installer.java

Change-Id: I7e471f20e64f6e9e65770f0697b891fc0cbc76ac
parent b72d619f
Loading
Loading
Loading
Loading
+58 −13
Original line number Diff line number Diff line
@@ -146,22 +146,67 @@ public final class Installer {
        return true;
    }

    private synchronized String transaction(String cmd) {

    private String transaction(String cmd) {
        int transactionId;
        synchronized (mTransactionIdLock) {
            transactionId = mLastTransactionId++;
            if (mLastTransactionId < 0) {
                mLastTransactionId = 0;
            }
        }

        try {
            synchronized (mResponses) {
                long startWaitTime = System.currentTimeMillis();
                while(mResponses.get(transactionId) == null) {
                    synchronized (mPendingRequests) {
                        if (!mPendingRequests.contains(transactionId)) {
                            if (!connect()) {
                                Slog.e(TAG, "connection failed");
                                return "-1";
                            }

        if (!writeCommand(cmd)) {
                            if (!writeCommand(cmd, transactionId)) {
                                /*
                                 * If installd died and restarted in the background (unlikely but
                                 * possible) we'll fail on the next write (this one). Try to
                                 * reconnect and write the command one more time before giving up.
                                 */
                                Slog.e(TAG, "write command failed? reconnect!");
            if (!connect() || !writeCommand(cmd)) {
                                if (!connect() || !writeCommand(cmd, transactionId)) {
                                    return "-1";
                                }
                            }
                            if (LOCAL_DEBUG) {
                                Slog.i(TAG, "send ["+transactionId+"]: '" + cmd + "'");
                            }
                            mPendingRequests.add(transactionId);
                            checkPoller();
                        }
                    }
                    final long timeToWait = startWaitTime - System.currentTimeMillis() + 100000;
                    if (timeToWait > 0) {
                        mResponses.wait(100000);
                    } else {
                        Slog.e(TAG, "timeout wating for response");
                        break;
                    }
                }
            }
        } catch (InterruptedException e) {
            return "-1";
        }

        synchronized (mPendingRequests) {
            mPendingRequests.remove(new Integer(transactionId));
        }
        checkPoller();

        String s;
        synchronized (mResponses) {
            s = mResponses.get(transactionId);
            mResponses.remove(transactionId);
        }
        if (LOCAL_DEBUG) {
            Slog.i(TAG, "send: '" + cmd + "'");