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

Commit 8eb70f8b authored by Martijn Coenen's avatar Martijn Coenen
Browse files

Add OBEX object count support to Bluetooth.

To support Android Beam receiving information about
the number of files in a OPP transfer, add the Count
OBEX header. Also add a new intent to tell the handover
requested that a transfer has started, including the
count (if any).

Change-Id: Ib5e0e8dbc6c2e3259e0f732a507557c3688e168c
parent 34e323ba
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -187,6 +187,10 @@ public class BluetoothOppBatch {
        return (mShares.size() == 0);
    }

    public int getNumShares() {
        return mShares.size();
    }

    /**
     * Get the running status of the batch
     * @return
+9 −6
Original line number Diff line number Diff line
@@ -83,10 +83,10 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
        mTransport = transport;
    }

    public void start(Handler handler) {
    public void start(Handler handler, int numShares) {
        if (D) Log.d(TAG, "Start!");
        mCallback = handler;
        mThread = new ClientThread(mContext, mTransport);
        mThread = new ClientThread(mContext, mTransport, numShares);
        mThread.start();
    }

@@ -140,13 +140,15 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {

        private boolean mConnected = false;

        public ClientThread(Context context, ObexTransport transport) {
        private int mNumShares;

        public ClientThread(Context context, ObexTransport transport, int initialNumShares) {
            super("BtOpp ClientThread");
            mContext1 = context;
            mTransport1 = transport;
            waitingForShare = true;
            mWaitingForRemote = false;

            mNumShares = initialNumShares;
            PowerManager pm = (PowerManager)mContext1.getSystemService(Context.POWER_SERVICE);
            wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
        }
@@ -171,7 +173,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
                mInterrupted = true;
            }
            if (!mInterrupted) {
                connect();
                connect(mNumShares);
            }

            while (!mInterrupted) {
@@ -229,7 +231,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
            }
        }

        private void connect() {
        private void connect(int numShares) {
            if (D) Log.d(TAG, "Create ClientSession with transport " + mTransport1.toString());
            try {
                mCs = new ClientSession(mTransport1);
@@ -240,6 +242,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
            if (mConnected) {
                mConnected = false;
                HeaderSet hs = new HeaderSet();
                hs.setHeader(HeaderSet.COUNT, (long) numShares);
                synchronized (this) {
                    mWaitingForRemote = true;
                }
+25 −1
Original line number Diff line number Diff line
@@ -128,7 +128,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
    /**
     * Called from BluetoothOppTransfer to start the "Transfer"
     */
    public void start(Handler handler) {
    public void start(Handler handler, int numShares) {
        if (D) Log.d(TAG, "Start!");
        mCallback = handler;

@@ -286,6 +286,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
            values.put(BluetoothShare.USER_CONFIRMATION,
                    BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED);
            needConfirm = false;

        }

        Uri contentUri = mContext.getContentResolver().insert(BluetoothShare.CONTENT_URI, values);
@@ -539,16 +540,39 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen

        if (D) Log.d(TAG, "onConnect");
        if (V) Constants.logHeader(request);
        Long objectCount = null;
        try {
            byte[] uuid = (byte[])request.getHeader(HeaderSet.TARGET);
            if (V) Log.v(TAG, "onConnect(): uuid =" + Arrays.toString(uuid));
            if(uuid != null) {
                 return ResponseCodes.OBEX_HTTP_NOT_ACCEPTABLE;
            }

            objectCount = (Long) request.getHeader(HeaderSet.COUNT);
        } catch (IOException e) {
            Log.e(TAG, e.toString());
            return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR;
        }
        String destination;
        if (mTransport instanceof BluetoothOppRfcommTransport) {
            destination = ((BluetoothOppRfcommTransport)mTransport).getRemoteAddress();
        } else {
            destination = "FF:FF:FF:00:00:00";
        }
        boolean isHandover = BluetoothOppManager.getInstance(mContext).
                isWhitelisted(destination);
        if (isHandover) {
            // Notify the handover requester file transfer has started
            Intent intent = new Intent(Constants.ACTION_HANDOVER_STARTED);
            if (objectCount != null) {
                intent.putExtra(Constants.EXTRA_BT_OPP_OBJECT_COUNT, objectCount.intValue());
            } else {
                intent.putExtra(Constants.EXTRA_BT_OPP_OBJECT_COUNT,
                        Constants.COUNT_HEADER_UNAVAILABLE);
            }
            intent.putExtra(Constants.EXTRA_BT_OPP_ADDRESS, destination);
            mContext.sendBroadcast(intent, Constants.HANDOVER_STATUS_PERMISSION);
        }
        mTimestamp = System.currentTimeMillis();
        return ResponseCodes.OBEX_HTTP_OK;
    }
+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ public interface BluetoothOppObexSession {

    int SESSION_TIMEOUT = 50000;

    void start(Handler sessionHandler);
    void start(Handler sessionHandler, int numShares);

    void stop();

+1 −1
Original line number Diff line number Diff line
@@ -453,7 +453,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
            if (V) Log.v(TAG, "Transfer has Server session" + mSession.toString());
        }

        mSession.start(mSessionHandler);
        mSession.start(mSessionHandler, mBatch.getNumShares());
        processCurrentShare();
    }

Loading