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

Commit 3615cee5 authored by Sergey Poromov's avatar Sergey Poromov Committed by android-build-merger
Browse files

Merge "Use long for preflight check size in BackupManagerService." into nyc-dev

am: 19ff7804

* commit '19ff7804':
  Use long for preflight check size in BackupManagerService.
parents 86dd0f2a 19ff7804
Loading
Loading
Loading
Loading
+15 −13
Original line number Original line Diff line number Diff line
@@ -87,6 +87,7 @@ import android.util.ArrayMap;
import android.util.AtomicFile;
import android.util.AtomicFile;
import android.util.EventLog;
import android.util.EventLog;
import android.util.Log;
import android.util.Log;
import android.util.Pair;
import android.util.Slog;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseArray;
import android.util.StringBuilderPrinter;
import android.util.StringBuilderPrinter;
@@ -142,6 +143,7 @@ import java.util.TreeMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.zip.Deflater;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
import java.util.zip.InflaterInputStream;
@@ -786,8 +788,9 @@ public class BackupManagerService {
            case MSG_OP_COMPLETE:
            case MSG_OP_COMPLETE:
            {
            {
                try {
                try {
                    BackupRestoreTask task = (BackupRestoreTask) msg.obj;
                    Pair<BackupRestoreTask, Long> taskWithResult =
                    task.operationComplete(msg.arg1);
                            (Pair<BackupRestoreTask, Long>) msg.obj;
                    taskWithResult.first.operationComplete(taskWithResult.second);
                } catch (ClassCastException e) {
                } catch (ClassCastException e) {
                    Slog.e(TAG, "Invalid completion in flight, obj=" + msg.obj);
                    Slog.e(TAG, "Invalid completion in flight, obj=" + msg.obj);
                }
                }
@@ -2460,7 +2463,7 @@ public class BackupManagerService {
        void execute();
        void execute();


        // An operation that wanted a callback has completed
        // An operation that wanted a callback has completed
        void operationComplete(int result);
        void operationComplete(long result);


        // An operation that wanted a callback has timed out
        // An operation that wanted a callback has timed out
        void handleTimeout();
        void handleTimeout();
@@ -3095,7 +3098,7 @@ public class BackupManagerService {
        }
        }


        @Override
        @Override
        public void operationComplete(int unusedResult) {
        public void operationComplete(long unusedResult) {
            // The agent reported back to us!
            // The agent reported back to us!


            if (mBackupData == null) {
            if (mBackupData == null) {
@@ -4532,7 +4535,7 @@ public class BackupManagerService {
        // a standalone thread.  The  runner owns this half of the pipe, and closes
        // a standalone thread.  The  runner owns this half of the pipe, and closes
        // it to indicate EOD to the other end.
        // it to indicate EOD to the other end.
        class SinglePackageBackupPreflight implements BackupRestoreTask, FullBackupPreflight {
        class SinglePackageBackupPreflight implements BackupRestoreTask, FullBackupPreflight {
            final AtomicInteger mResult = new AtomicInteger();
            final AtomicLong mResult = new AtomicLong();
            final CountDownLatch mLatch = new CountDownLatch(1);
            final CountDownLatch mLatch = new CountDownLatch(1);
            final IBackupTransport mTransport;
            final IBackupTransport mTransport;


@@ -4554,10 +4557,10 @@ public class BackupManagerService {


                    // now wait to get our result back
                    // now wait to get our result back
                    mLatch.await();
                    mLatch.await();
                    int totalSize = mResult.get();
                    long totalSize = mResult.get();
                    // If preflight timeouted, mResult will contain error code.
                    // If preflight timeouted, mResult will contain error code as int.
                    if (totalSize < 0) {
                    if (totalSize < 0) {
                        return totalSize;
                        return (int) totalSize;
                    }
                    }
                    if (MORE_DEBUG) {
                    if (MORE_DEBUG) {
                        Slog.v(TAG, "Got preflight response; size=" + totalSize);
                        Slog.v(TAG, "Got preflight response; size=" + totalSize);
@@ -4585,7 +4588,7 @@ public class BackupManagerService {
            }
            }


            @Override
            @Override
            public void operationComplete(int result) {
            public void operationComplete(long result) {
                // got the callback, and our preflightFullBackup() method is waiting for the result
                // got the callback, and our preflightFullBackup() method is waiting for the result
                if (MORE_DEBUG) {
                if (MORE_DEBUG) {
                    Slog.i(TAG, "Preflight op complete, result=" + result);
                    Slog.i(TAG, "Preflight op complete, result=" + result);
@@ -8562,7 +8565,7 @@ if (MORE_DEBUG) Slog.v(TAG, " + got " + nRead + "; now wanting " + (size - soF
        }
        }


        @Override
        @Override
        public void operationComplete(int unusedResult) {
        public void operationComplete(long unusedResult) {
            if (MORE_DEBUG) {
            if (MORE_DEBUG) {
                Slog.i(TAG, "operationComplete() during restore: target="
                Slog.i(TAG, "operationComplete() during restore: target="
                        + mCurrentPackage.packageName
                        + mCurrentPackage.packageName
@@ -9647,9 +9650,8 @@ if (MORE_DEBUG) Slog.v(TAG, " + got " + nRead + "; now wanting " + (size - soF


        // The completion callback, if any, is invoked on the handler
        // The completion callback, if any, is invoked on the handler
        if (op != null && op.callback != null) {
        if (op != null && op.callback != null) {
            Message msg = mBackupHandler.obtainMessage(MSG_OP_COMPLETE, op.callback);
            Pair<BackupRestoreTask, Long> callbackAndResult = Pair.create(op.callback, result);
            // NB: this cannot distinguish between results > 2 gig
            Message msg = mBackupHandler.obtainMessage(MSG_OP_COMPLETE, callbackAndResult);
            msg.arg1 = (result > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) result;
            mBackupHandler.sendMessage(msg);
            mBackupHandler.sendMessage(msg);
        }
        }
    }
    }