summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppBatch.java18
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppBtEnableActivity.java1
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivity.java11
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppBtErrorActivity.java1
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppIncomingFileConfirmActivity.java14
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java22
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppManager.java34
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppNotification.java14
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java94
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java128
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppPreference.java18
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppProvider.java42
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppReceiveFileInfo.java34
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppReceiver.java48
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java48
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppService.java148
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppTransfer.java171
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppTransferActivity.java22
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppUtility.java37
-rw-r--r--src/com/android/bluetooth/opp/Constants.java22
-rw-r--r--src/com/android/bluetooth/opp/TestTcpListener.java36
-rw-r--r--src/com/android/bluetooth/opp/TestTcpServer.java9
22 files changed, 292 insertions, 680 deletions
diff --git a/src/com/android/bluetooth/opp/BluetoothOppBatch.java b/src/com/android/bluetooth/opp/BluetoothOppBatch.java
index a11912211..62a8b5bde 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppBatch.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppBatch.java
@@ -60,7 +60,9 @@ import com.google.android.collect.Lists;
*/
public class BluetoothOppBatch {
- private static final String TAG = "BtOpp Batch";
+ private static final String TAG = "BtOppBatch";
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
public int mId;
public int mStatus;
@@ -111,9 +113,8 @@ public class BluetoothOppBatch {
mDestination = adapter.getRemoteDevice(info.mDestination);
mStatus = Constants.BATCH_STATUS_PENDING;
mShares.add(info);
- if (Constants.LOGVV) {
- Log.v(TAG, "New Batch created for info " + info.mId);
- }
+
+ if (V) Log.v(TAG, "New Batch created for info " + info.mId);
}
/**
@@ -158,9 +159,8 @@ public class BluetoothOppBatch {
* 3) update ContentProvider for these canceled transfer
*/
public void cancelBatch() {
- if (Constants.LOGVV) {
- Log.v(TAG, "batch " + this.mId + " is canceled");
- }
+ if (V) Log.v(TAG, "batch " + this.mId + " is canceled");
+
if (mListener != null) {
mListener.onBatchCanceled();
}
@@ -172,9 +172,7 @@ public class BluetoothOppBatch {
if (info.mDirection == BluetoothShare.DIRECTION_INBOUND && info.mFilename != null) {
new File(info.mFilename).delete();
}
- if (Constants.LOGVV) {
- Log.v(TAG, "Cancel batch for info " + info.mId);
- }
+ if (V) Log.v(TAG, "Cancel batch for info " + info.mId);
Constants.updateShareStatus(mContext, info.mId, BluetoothShare.STATUS_CANCELED);
}
diff --git a/src/com/android/bluetooth/opp/BluetoothOppBtEnableActivity.java b/src/com/android/bluetooth/opp/BluetoothOppBtEnableActivity.java
index 8b52993c1..8cb76bbcb 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppBtEnableActivity.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppBtEnableActivity.java
@@ -49,7 +49,6 @@ import com.android.internal.app.AlertController;
*/
public class BluetoothOppBtEnableActivity extends AlertActivity implements
DialogInterface.OnClickListener {
- private static final String TAG = "BluetoothOppBtEnableActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
diff --git a/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivity.java b/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivity.java
index 2f952e71e..819404a76 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivity.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppBtEnablingActivity.java
@@ -47,6 +47,9 @@ import com.android.internal.app.AlertController;
*/
public class BluetoothOppBtEnablingActivity extends AlertActivity {
private static final String TAG = "BluetoothOppEnablingActivity";
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -82,16 +85,12 @@ public class BluetoothOppBtEnablingActivity extends AlertActivity {
if (mOppManager.mSendingFlag) {
mOppManager.mSendingFlag = false;
mOppManager.disableBluetooth(); // can work? May not!
- if (Constants.LOGVV) {
- Log.v(TAG, "Disabling Bluetooth:! ");
- }
+ if (V) Log.v(TAG, "Disabling Bluetooth:! ");
}
// In this dialog, when press "back" key, will call
// AlertActivity.cancel() function - finish()
finish();
- if (Constants.LOGVV) {
- Log.v(TAG, "onPause(): finish() called");
- }
+ if (V) Log.v(TAG, "onPause(): finish() called");
}
}
diff --git a/src/com/android/bluetooth/opp/BluetoothOppBtErrorActivity.java b/src/com/android/bluetooth/opp/BluetoothOppBtErrorActivity.java
index 77d92805b..9fa6e1258 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppBtErrorActivity.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppBtErrorActivity.java
@@ -48,7 +48,6 @@ import com.android.internal.app.AlertController;
*/
public class BluetoothOppBtErrorActivity extends AlertActivity implements
DialogInterface.OnClickListener {
- private static final String TAG = "BluetoothOppBtErrorActivity";
private String mErrorContent;
diff --git a/src/com/android/bluetooth/opp/BluetoothOppIncomingFileConfirmActivity.java b/src/com/android/bluetooth/opp/BluetoothOppIncomingFileConfirmActivity.java
index b4a63cef2..0fd000432 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppIncomingFileConfirmActivity.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppIncomingFileConfirmActivity.java
@@ -54,6 +54,8 @@ import com.android.internal.app.AlertController;
public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity implements
DialogInterface.OnClickListener {
private static final String TAG = "BluetoothIncomingFileConfirmActivity";
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
private BluetoothOppTransferInfo mTransInfo;
@@ -72,9 +74,7 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity imple
mTransInfo = new BluetoothOppTransferInfo();
mTransInfo = BluetoothOppUtility.queryRecord(this, mUri);
if (mTransInfo == null) {
- if (Constants.LOGVV) {
- Log.e(TAG, "Error: Can not get data from db");
- }
+ if (V) Log.e(TAG, "Error: Can not get data from db");
finish();
return;
}
@@ -90,9 +90,7 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity imple
p.mNegativeButtonListener = this;
setupAlert();
- if (Constants.LOGVV) {
- Log.v(TAG, "BluetoothIncomingFileConfirmActivity: Got uri:" + mUri);
- }
+ if (V) Log.v(TAG, "BluetoothIncomingFileConfirmActivity: Got uri:" + mUri);
}
private View createView() {
@@ -143,9 +141,7 @@ public class BluetoothOppIncomingFileConfirmActivity extends AlertActivity imple
mUpdateValues = new ContentValues();
mUpdateValues.put(BluetoothShare.VISIBILITY, BluetoothShare.VISIBILITY_HIDDEN);
this.getContentResolver().update(mUri, mUpdateValues, null, null);
- if (Constants.LOGVV) {
- Log.v(TAG, "db updated: change to VISIBILITY_HIDDEN");
- }
+ if (V) Log.v(TAG, "db updated: change to VISIBILITY_HIDDEN");
Toast.makeText(this, getString(R.string.bt_toast_2), Toast.LENGTH_SHORT).show();
}
}
diff --git a/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java b/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java
index 0d78712a5..278c658de 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java
@@ -51,6 +51,8 @@ import android.provider.Settings;
*/
public class BluetoothOppLauncherActivity extends Activity {
private static final String TAG = "BluetoothLauncherActivity";
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -70,10 +72,8 @@ public class BluetoothOppLauncherActivity extends Activity {
String type = intent.getType();
Uri stream = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (stream != null && type != null) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Get ACTION_SEND intent: Uri = " + stream + "; mimetype = "
+ if (V) Log.v(TAG, "Get ACTION_SEND intent: Uri = " + stream + "; mimetype = "
+ type);
- }
// Save type/stream, will be used when adding transfer
// session to DB.
BluetoothOppManager.getInstance(this).saveSendingFileInfo(type,
@@ -88,10 +88,8 @@ public class BluetoothOppLauncherActivity extends Activity {
String mimeType = intent.getType();
uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (mimeType != null && uris != null) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Get ACTION_SHARE_MULTIPLE intent: uris " + uris + "\n Type= "
+ if (V) Log.v(TAG, "Get ACTION_SHARE_MULTIPLE intent: uris " + uris + "\n Type= "
+ mimeType);
- }
BluetoothOppManager.getInstance(this).saveSendingFileInfo(mimeType, uris);
} else {
Log.e(TAG, "type is null; or sending files URIs are null");
@@ -115,16 +113,12 @@ public class BluetoothOppLauncherActivity extends Activity {
// directly,
// and let DevicePickerActivity to handle Bluetooth Enable.
if (!BluetoothOppManager.getInstance(this).isEnabled()) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Prepare Enable BT!! ");
- }
+ if (V) Log.v(TAG, "Prepare Enable BT!! ");
Intent in = new Intent(this, BluetoothOppBtEnableActivity.class);
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(in);
} else {
- if (Constants.LOGVV) {
- Log.v(TAG, "BT already enabled!! ");
- }
+ if (V) Log.v(TAG, "BT already enabled!! ");
Intent in1 = new Intent(BluetoothIntent.DEVICE_PICKER_DEVICE_PICKER);
in1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//TODO modify to false after SDP query is ok
@@ -140,9 +134,7 @@ public class BluetoothOppLauncherActivity extends Activity {
}
} else if (action.equals(Constants.ACTION_OPEN)) {
Uri uri = getIntent().getData();
- if (Constants.LOGVV) {
- Log.v(TAG, "Get ACTION_OPEN intent: Uri = " + uri);
- }
+ if (V) Log.v(TAG, "Get ACTION_OPEN intent: Uri = " + uri);
Intent intent1 = new Intent();
intent1.setAction(action);
diff --git a/src/com/android/bluetooth/opp/BluetoothOppManager.java b/src/com/android/bluetooth/opp/BluetoothOppManager.java
index 769442077..4937bc695 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppManager.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppManager.java
@@ -52,6 +52,8 @@ import java.util.ArrayList;
*/
public class BluetoothOppManager {
private static final String TAG = "BluetoothOppManager";
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
private static BluetoothOppManager INSTANCE;
@@ -125,9 +127,7 @@ public class BluetoothOppManager {
mAdapter = (BluetoothAdapter) context.getSystemService(Context.BLUETOOTH_SERVICE);
if (mAdapter == null) {
- if (Constants.LOGVV) {
- Log.v(TAG, "BLUETOOTH_SERVICE is not started! ");
- }
+ if (V) Log.v(TAG, "BLUETOOTH_SERVICE is not started! ");
}
// Restore data from preference
@@ -148,10 +148,8 @@ public class BluetoothOppManager {
mMimeTypeOfSendigFiles = settings.getString(MIME_TYPE_MULTIPLE, null);
mMultipleFlag = settings.getBoolean(MULTIPLE_FLAG, false);
- if (Constants.LOGVV) {
- Log.v(TAG, "restoreApplicationData! " + mSendingFlag + mMultipleFlag
+ if (V) Log.v(TAG, "restoreApplicationData! " + mSendingFlag + mMultipleFlag
+ mMimeTypeOfSendigFile + mUriOfSendingFile);
- }
String strUris = settings.getString(FILE_URIS, null);
// TODO(Moto): restore mUrisOfSendingFiles from strUris.
@@ -177,9 +175,7 @@ public class BluetoothOppManager {
}
strUris = sb.toString();
editor.putString(FILE_URIS, strUris).commit();
- if (Constants.LOGVV) {
- Log.v(TAG, "finalize is called and application data saved by SharedPreference! ");
- }
+ if (V) Log.v(TAG, "finalize is called and application data saved by SharedPreference! ");
}
/**
@@ -215,9 +211,7 @@ public class BluetoothOppManager {
if (mAdapter != null) {
return mAdapter.isEnabled();
} else {
- if (Constants.LOGVV) {
- Log.v(TAG, "BLUETOOTH_SERVICE is not available! ");
- }
+ if (V) Log.v(TAG, "BLUETOOTH_SERVICE is not available! ");
return false;
}
}
@@ -269,9 +263,7 @@ public class BluetoothOppManager {
}
if (!mCanStartTransfer) {
- if (Constants.LOGVV) {
- Log.v(TAG, "No transfer info restored: fileType&fileName");
- }
+ if (V) Log.v(TAG, "No transfer info restored: fileType&fileName");
return;
}
@@ -284,9 +276,7 @@ public class BluetoothOppManager {
Uri fileUri = mUrisOfSendingFiles.get(i);
ContentResolver contentResolver = mContext.getContentResolver();
String contentType = contentResolver.getType(fileUri);
- if (Constants.LOGVV) {
- Log.v(TAG, "Got mimetype: " + contentType + " Got uri: " + fileUri);
- }
+ if (V) Log.v(TAG, "Got mimetype: " + contentType + " Got uri: " + fileUri);
ContentValues values = new ContentValues();
values.put(BluetoothShare.URI, fileUri.toString());
@@ -296,10 +286,8 @@ public class BluetoothOppManager {
final Uri contentUri = mContext.getContentResolver().insert(
BluetoothShare.CONTENT_URI, values);
- if (Constants.LOGVV) {
- Log.v(TAG, "Insert contentUri: " + contentUri + " to device: "
+ if (V) Log.v(TAG, "Insert contentUri: " + contentUri + " to device: "
+ getDeviceName(device));
- }
}
} else {
ContentValues values = new ContentValues();
@@ -309,10 +297,8 @@ public class BluetoothOppManager {
final Uri contentUri = mContext.getContentResolver().insert(BluetoothShare.CONTENT_URI,
values);
- if (Constants.LOGVV) {
- Log.v(TAG, "Insert contentUri: " + contentUri + " to device: "
+ if (V) Log.v(TAG, "Insert contentUri: " + contentUri + " to device: "
+ getDeviceName(device));
- }
}
// reset vars
diff --git a/src/com/android/bluetooth/opp/BluetoothOppNotification.java b/src/com/android/bluetooth/opp/BluetoothOppNotification.java
index 7147335f0..012079192 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppNotification.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppNotification.java
@@ -53,6 +53,8 @@ import java.util.HashMap;
*/
class BluetoothOppNotification {
private static final String TAG = "BluetoothOppNotification";
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
static final String status = "(" + BluetoothShare.STATUS + " == '192'" + ")";
@@ -201,19 +203,15 @@ class BluetoothOppNotification {
item.description = mContext
.getString(R.string.notification_receiving, fileName);
} else {
- if (Constants.LOGVV) {
- Log.v(TAG, "mDirection ERROR!");
- }
+ if (V) Log.v(TAG, "mDirection ERROR!");
}
item.totalCurrent = current;
item.totalTotal = total;
mNotifications.put(batchID, item);
- if (Constants.LOGVV) {
- Log.v(TAG, "ID=" + item.id + "; batchID=" + batchID + "; totoalCurrent"
+ if (V) Log.v(TAG, "ID=" + item.id + "; batchID=" + batchID + "; totoalCurrent"
+ item.totalCurrent + "; totalTotal=" + item.totalTotal);
- }
}
}
cursor.close();
@@ -242,9 +240,7 @@ class BluetoothOppNotification {
expandedView.setImageViewResource(R.id.appIcon,
android.R.drawable.stat_sys_download);
} else {
- if (Constants.LOGVV) {
- Log.v(TAG, "mDirection ERROR!");
- }
+ if (V) Log.v(TAG, "mDirection ERROR!");
}
n.flags |= Notification.FLAG_ONGOING_EVENT;
diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java
index 0464e6b8f..92305bd02 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java
@@ -60,6 +60,8 @@ import java.lang.Thread;
public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
private static final String TAG = "BtOpp ObexClient";
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
private ClientThread mThread;
@@ -82,31 +84,23 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
}
public void start(Handler handler) {
- if (Constants.LOGV) {
- Log.v(TAG, "Start!");
- }
+ if (D) Log.d(TAG, "Start!");
mCallback = handler;
mThread = new ClientThread(mContext, mTransport);
mThread.start();
}
public void stop() {
- if (Constants.LOGV) {
- Log.v(TAG, "Stop!");
- }
+ if (D) Log.d(TAG, "Stop!");
if (mThread != null) {
mInterrupted = true;
try {
mThread.interrupt();
- if (Constants.LOGVV) {
- Log.v(TAG, "waiting for thread to terminate");
- }
+ if (V) Log.v(TAG, "waiting for thread to terminate");
mThread.join();
mThread = null;
} catch (InterruptedException e) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Interrupted waiting for thread to join");
- }
+ if (V) Log.v(TAG, "Interrupted waiting for thread to join");
}
}
mCallback = null;
@@ -157,17 +151,13 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
- if (Constants.LOGVV) {
- Log.v(TAG, "acquire partial WakeLock");
- }
+ if (V) Log.v(TAG, "acquire partial WakeLock");
wakeLock.acquire();
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Client thread was interrupted (1), exiting");
- }
+ if (V) Log.v(TAG, "Client thread was interrupted (1), exiting");
mInterrupted = true;
}
if (!mInterrupted) {
@@ -179,10 +169,8 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
doSend();
} else {
try {
- if (Constants.LOGV) {
- Log.v(TAG, "Client thread waiting for next share, sleep for "
+ if (D) Log.d(TAG, "Client thread waiting for next share, sleep for "
+ sSleepTime);
- }
Thread.sleep(sSleepTime);
} catch (InterruptedException e) {
@@ -192,9 +180,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
disconnect();
if (wakeLock.isHeld()) {
- if (Constants.LOGVV) {
- Log.v(TAG, "release partial WakeLock");
- }
+ if (V) Log.v(TAG, "release partial WakeLock");
wakeLock.release();
}
Message msg = Message.obtain(mCallback);
@@ -210,22 +196,16 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
mCs.disconnect(null);
}
mCs = null;
- if (Constants.LOGV) {
- Log.v(TAG, "OBEX session disconnected");
- }
+ if (D) Log.d(TAG, "OBEX session disconnected");
} catch (IOException e) {
Log.w(TAG, "OBEX session disconnect error" + e);
}
try {
if (mCs != null) {
- if (Constants.LOGV) {
- Log.v(TAG, "OBEX session close mCs");
- }
+ if (D) Log.d(TAG, "OBEX session close mCs");
mCs.close();
- if (Constants.LOGV) {
- Log.v(TAG, "OBEX session closed");
+ if (D) Log.d(TAG, "OBEX session closed");
}
- }
} catch (IOException e) {
Log.w(TAG, "OBEX session close error" + e);
}
@@ -240,9 +220,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
}
private void connect() {
- if (Constants.LOGV) {
- Log.v(TAG, "Create ClientSession with transport " + mTransport1.toString());
- }
+ if (D) Log.d(TAG, "Create ClientSession with transport " + mTransport1.toString());
try {
mCs = new ClientSession(mTransport1);
mConnected = true;
@@ -257,9 +235,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
}
try {
mCs.connect(hs);
- if (Constants.LOGV) {
- Log.v(TAG, "OBEX session created");
- }
+ if (D) Log.d(TAG, "OBEX session created");
mConnected = true;
} catch (IOException e) {
Log.e(TAG, "OBEX session connect error");
@@ -317,20 +293,16 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
* Validate this ShareInfo
*/
private BluetoothOppSendFileInfo processShareInfo() {
- if (Constants.LOGVV) {
- Log.v(TAG, "Client thread processShareInfo() " + mInfo.mId);
- }
+ if (V) Log.v(TAG, "Client thread processShareInfo() " + mInfo.mId);
BluetoothOppSendFileInfo fileInfo = BluetoothOppSendFileInfo.generateFileInfo(
mContext1, mInfo.mUri, mInfo.mMimetype);
if (fileInfo.mFileName == null || fileInfo.mLength == 0) {
- if (Constants.LOGVV) {
- Log.v(TAG, "BluetoothOppSendFileInfo get invalid file");
+ if (V) Log.v(TAG, "BluetoothOppSendFileInfo get invalid file");
Constants.updateShareStatus(mContext1, mInfo.mId, fileInfo.mStatus);
- }
} else {
- if (Constants.LOGVV) {
+ if (V) {
Log.v(TAG, "Generate BluetoothOppSendFileInfo:");
Log.v(TAG, "filename :" + fileInfo.mFileName);
Log.v(TAG, "length :" + fileInfo.mLength);
@@ -372,9 +344,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
mWaitingForRemote = true;
}
try {
- if (Constants.LOGVV) {
- Log.v(TAG, "put headerset for " + fileInfo.mFileName);
- }
+ if (V) Log.v(TAG, "put headerset for " + fileInfo.mFileName);
putOperation = (ClientOperation)mCs.put(request);
} catch (IOException e) {
status = BluetoothShare.STATUS_OBEX_DATA_ERROR;
@@ -389,9 +359,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
if (!error) {
try {
- if (Constants.LOGVV) {
- Log.v(TAG, "openOutputStream " + fileInfo.mFileName);
- }
+ if (V) Log.v(TAG, "openOutputStream " + fileInfo.mFileName);
outputStream = putOperation.openOutputStream();
inputStream = putOperation.openInputStream();
} catch (IOException e) {
@@ -451,9 +419,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
if (responseCode == ResponseCodes.OBEX_HTTP_CONTINUE
|| responseCode == ResponseCodes.OBEX_HTTP_OK) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Remote accept");
- }
+ if (V) Log.v(TAG, "Remote accept");
okToProceed = true;
updateValues = new ContentValues();
updateValues.put(BluetoothShare.CURRENT_BYTES, position);
@@ -466,25 +432,21 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
while (!mInterrupted && okToProceed && (position != fileInfo.mLength)) {
{
- if (Constants.LOGVV) {
- timestamp = System.currentTimeMillis();
- }
+ if (V) timestamp = System.currentTimeMillis();
readLength = a.read(buffer, 0, outputBufferSize);
outputStream.write(buffer, 0, readLength);
/* check remote abort */
responseCode = putOperation.getResponseCode();
- if (Constants.LOGVV) {
- Log.v(TAG, "Response code is " + responseCode);
- }
+ if (V) Log.v(TAG, "Response code is " + responseCode);
if (responseCode != ResponseCodes.OBEX_HTTP_CONTINUE
&& responseCode != ResponseCodes.OBEX_HTTP_OK) {
/* abort happens */
okToProceed = false;
} else {
position += readLength;
- if (Constants.LOGVV) {
+ if (V) {
Log.v(TAG, "Sending file position = " + position
+ " readLength " + readLength + " bytes took "
+ (System.currentTimeMillis() - timestamp) + " ms");
@@ -529,9 +491,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
if (!error) {
responseCode = putOperation.getResponseCode();
if (responseCode != -1) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Get response code " + responseCode);
- }
+ if (V) Log.v(TAG, "Get response code " + responseCode);
if (responseCode != ResponseCodes.OBEX_HTTP_OK) {
Log.i(TAG, "Response error code is " + responseCode);
status = BluetoothShare.STATUS_UNHANDLED_OBEX_CODE;
@@ -569,9 +529,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
super.interrupt();
synchronized (this) {
if (mWaitingForRemote) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Interrupted when waitingForRemote");
- }
+ if (V) Log.v(TAG, "Interrupted when waitingForRemote");
try {
mTransport1.close();
} catch (IOException e) {
diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java
index f8a23627f..aa9e081b3 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java
@@ -63,7 +63,9 @@ import javax.obex.ServerSession;
public class BluetoothOppObexServerSession extends ServerRequestHandler implements
BluetoothOppObexSession {
- private static final String TAG = "BtOpp ObexServer";
+ private static final String TAG = "BtOppObexServer";
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
private ObexTransport mTransport;
@@ -123,14 +125,10 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
* Header then wait for user confirmation
*/
public void preStart() {
- if (Constants.LOGV) {
- Log.v(TAG, "acquire full WakeLock");
- }
+ if (D) Log.d(TAG, "acquire full WakeLock");
mWakeLock.acquire();
try {
- if (Constants.LOGV) {
- Log.v(TAG, "Create ServerSession with transport " + mTransport.toString());
- }
+ if (D) Log.d(TAG, "Create ServerSession with transport " + mTransport.toString());
mSession = new ServerSession(mTransport, this, null);
} catch (IOException e) {
Log.e(TAG, "Create server session error" + e);
@@ -141,9 +139,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
* Called from BluetoothOppTransfer to start the "Transfer"
*/
public void start(Handler handler) {
- if (Constants.LOGV) {
- Log.v(TAG, "Start!");
- }
+ if (D) Log.d(TAG, "Start!");
mCallback = handler;
}
@@ -157,9 +153,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
* TODO now we implement in a tough way, just close the socket.
* maybe need nice way
*/
- if (Constants.LOGV) {
- Log.v(TAG, "Stop!");
- }
+ if (D) Log.d(TAG, "Stop!");
mInterrupted = true;
if (mSession != null) {
try {
@@ -170,9 +164,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
}
}
mCallback = null;
- if (Constants.LOGVV) {
- Log.v(TAG, "release WakeLock");
- }
+ if (V) Log.v(TAG, "release WakeLock");
if (mWakeLock.isHeld()) {
mWakeLock.release();
}
@@ -183,18 +175,14 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
}
public void addShare(BluetoothOppShareInfo info) {
- if (Constants.LOGV) {
- Log.v(TAG, "addShare for id " + info.mId);
- }
+ if (D) Log.d(TAG, "addShare for id " + info.mId);
mInfo = info;
mFileInfo = processShareInfo();
}
@Override
public int onPut(Operation op) {
- if (Constants.LOGV) {
- Log.v(TAG, "onPut " + op.toString());
- }
+ if (D) Log.d(TAG, "onPut " + op.toString());
HeaderSet request;
String name, mimeType;
Long length;
@@ -212,25 +200,19 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
try {
boolean pre_reject = false;
request = op.getReceivedHeader();
- if (Constants.LOGVV) {
- Constants.logHeader(request);
- }
+ if (V) Constants.logHeader(request);
name = (String)request.getHeader(HeaderSet.NAME);
length = (Long)request.getHeader(HeaderSet.LENGTH);
mimeType = (String)request.getHeader(HeaderSet.TYPE);
if (length == 0) {
- if (Constants.LOGV) {
- Log.w(TAG, "length is 0, reject the transfer");
- }
+ if (D) Log.w(TAG, "length is 0, reject the transfer");
pre_reject = true;
obexResponse = ResponseCodes.OBEX_HTTP_LENGTH_REQUIRED;
}
if (name == null || name.equals("")) {
- if (Constants.LOGV) {
- Log.w(TAG, "name is null or empty, reject the transfer");
- }
+ if (D) Log.w(TAG, "name is null or empty, reject the transfer");
pre_reject = true;
obexResponse = ResponseCodes.OBEX_HTTP_BAD_REQUEST;
}
@@ -240,26 +222,20 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
String extension, type;
int dotIndex = name.indexOf('.');
if (dotIndex < 0) {
- if (Constants.LOGV) {
- Log.w(TAG, "There is no file extension, reject the transfer");
- }
+ if (D) Log.w(TAG, "There is no file extension, reject the transfer");
pre_reject = true;
obexResponse = ResponseCodes.OBEX_HTTP_BAD_REQUEST;
} else {
extension = name.substring(dotIndex + 1).toLowerCase();
MimeTypeMap map = MimeTypeMap.getSingleton();
type = map.getMimeTypeFromExtension(extension);
- if (Constants.LOGVV) {
- Log.v(TAG, "Mimetype guessed from extension " + extension + " is " + type);
- }
+ if (V) Log.v(TAG, "Mimetype guessed from extension " + extension + " is " + type);
if (type != null) {
mimeType = type;
} else {
if (mimeType == null) {
- if (Constants.LOGV) {
- Log.w(TAG, "Can't get mimetype, reject the transfer");
- }
+ if (D) Log.w(TAG, "Can't get mimetype, reject the transfer");
pre_reject = true;
obexResponse = ResponseCodes.OBEX_HTTP_UNSUPPORTED_TYPE;
}
@@ -273,9 +249,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
if (!pre_reject
&& (mimeType == null || Constants.mimeTypeMatches(mimeType,
Constants.UNACCEPTABLE_SHARE_INBOUND_TYPES))) {
- if (Constants.LOGV) {
- Log.w(TAG, "mimeType is null or in unacceptable list, reject the transfer");
- }
+ if (D) Log.w(TAG, "mimeType is null or in unacceptable list, reject the transfer");
pre_reject = true;
obexResponse = ResponseCodes.OBEX_HTTP_UNSUPPORTED_TYPE;
}
@@ -335,14 +309,10 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
mContext.sendBroadcast(in);
}
- if (Constants.LOGVV) {
- Log.v(TAG, "insert contentUri: " + contentUri);
+ if (V) Log.v(TAG, "insert contentUri: " + contentUri);
Log.v(TAG, "mLocalShareInfoId = " + mLocalShareInfoId);
- }
- if (Constants.LOGVV) {
- Log.v(TAG, "acquire partial WakeLock");
- }
+ if (V) Log.v(TAG, "acquire partial WakeLock");
if (mWakeLock.isHeld()) {
mPartialWakeLock.acquire();
mWakeLock.release();
@@ -360,20 +330,14 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
.obtainMessage(BluetoothOppObexSession.MSG_CONNECT_TIMEOUT),
BluetoothOppObexSession.SESSION_TIMEOUT);
mTimeoutMsgSent = true;
- if (Constants.LOGVV) {
- Log.v(TAG, "MSG_CONNECT_TIMEOUT sent");
- }
+ if (V) Log.v(TAG, "MSG_CONNECT_TIMEOUT sent");
}
}
} catch (InterruptedException e) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Interrupted in onPut blocking");
- }
+ if (V) Log.v(TAG, "Interrupted in onPut blocking");
}
}
- if (Constants.LOGV) {
- Log.v(TAG, "Server unblocked ");
- }
+ if (D) Log.d(TAG, "Server unblocked ");
if (mCallback != null && mTimeoutMsgSent) {
mCallback.removeMessages(BluetoothOppObexSession.MSG_CONNECT_TIMEOUT);
}
@@ -389,9 +353,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
}
mAccepted = mInfo.mConfirm;
- if (Constants.LOGVV) {
- Log.v(TAG, "after confirm: userAccepted=" + mAccepted);
- }
+ if (V) Log.v(TAG, "after confirm: userAccepted=" + mAccepted);
int status = BluetoothShare.STATUS_SUCCESS;
if (mAccepted == BluetoothShare.USER_CONFIRMATION_CONFIRMED
@@ -509,23 +471,19 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
try {
while ((!mInterrupted) && (position != fileInfo.mLength)) {
- if (Constants.LOGVV) {
- timestamp = System.currentTimeMillis();
- }
+ if (V) timestamp = System.currentTimeMillis();
readLength = is.read(b);
if (readLength == -1) {
- if (Constants.LOGV) {
- Log.v(TAG, "Receive file reached stream end at position" + position);
- }
+ if (D) Log.d(TAG, "Receive file reached stream end at position" + position);
break;
}
bos.write(b, 0, readLength);
position += readLength;
- if (Constants.LOGVV) {
+ if (V) {
Log.v(TAG, "Receive file position = " + position + " readLength "
+ readLength + " bytes took "
+ (System.currentTimeMillis() - timestamp) + " ms");
@@ -543,20 +501,14 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
}
if (mInterrupted) {
- if (Constants.LOGV) {
- Log.v(TAG, "receiving file interrupted by user.");
- }
+ if (D) Log.d(TAG, "receiving file interrupted by user.");
status = BluetoothShare.STATUS_CANCELED;
} else {
if (position == fileInfo.mLength) {
- if (Constants.LOGV) {
- Log.v(TAG, "Receiving file completed for " + fileInfo.mFileName);
- }
+ if (D) Log.d(TAG, "Receiving file completed for " + fileInfo.mFileName);
status = BluetoothShare.STATUS_SUCCESS;
} else {
- if (Constants.LOGV) {
- Log.v(TAG, "Reading file failed at " + position + " of " + fileInfo.mLength);
- }
+ if (D) Log.d(TAG, "Reading file failed at " + position + " of " + fileInfo.mLength);
if (status == -1) {
status = BluetoothShare.STATUS_UNKNOWN_ERROR;
}
@@ -574,12 +526,10 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
}
private BluetoothOppReceiveFileInfo processShareInfo() {
- if (Constants.LOGV) {
- Log.v(TAG, "processShareInfo() " + mInfo.mId);
- }
+ if (D) Log.d(TAG, "processShareInfo() " + mInfo.mId);
BluetoothOppReceiveFileInfo fileInfo = BluetoothOppReceiveFileInfo.generateFileInfo(
mContext, mInfo.mId);
- if (Constants.LOGVV) {
+ if (V) {
Log.v(TAG, "Generate BluetoothOppReceiveFileInfo:");
Log.v(TAG, "filename :" + fileInfo.mFileName);
Log.v(TAG, "length :" + fileInfo.mLength);
@@ -591,12 +541,8 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
@Override
public int onConnect(HeaderSet request, HeaderSet reply) {
- if (Constants.LOGV) {
- Log.v(TAG, "onConnect");
- }
- if (Constants.LOGVV) {
- Constants.logHeader(request);
- }
+ if (D) Log.d(TAG, "onConnect");
+ if (V) Constants.logHeader(request);
mTimestamp = System.currentTimeMillis();
return ResponseCodes.OBEX_HTTP_OK;
@@ -605,14 +551,10 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
@Override
public void onDisconnect(HeaderSet req, HeaderSet resp) {
- if (Constants.LOGV) {
- Log.v(TAG, "onDisconnect");
- }
+ if (D) Log.d(TAG, "onDisconnect");
resp.responseCode = ResponseCodes.OBEX_HTTP_OK;
- if (Constants.LOGV) {
- Log.v(TAG, "release WakeLock");
- }
+ if (D) Log.d(TAG, "release WakeLock");
if (mWakeLock.isHeld()) {
mWakeLock.release();
}
diff --git a/src/com/android/bluetooth/opp/BluetoothOppPreference.java b/src/com/android/bluetooth/opp/BluetoothOppPreference.java
index 4df43d25c..0c73c4ff3 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppPreference.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppPreference.java
@@ -46,6 +46,8 @@ import android.util.Log;
*/
public class BluetoothOppPreference {
private static final String TAG = "BluetoothOppPreference";
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
private static BluetoothOppPreference INSTANCE;
@@ -114,24 +116,18 @@ public class BluetoothOppPreference {
public int getChannel(BluetoothDevice remoteDevice, int uuid) {
String key = getChannelKey(remoteDevice, uuid);
- if (Constants.LOGVV) {
- Log.v(TAG, "getChannel " + key);
- }
+ if (V) Log.v(TAG, "getChannel " + key);
int channel = -1;
if (!mChannels.isEmpty()) {
channel = mChannels.get(key);
- if (Constants.LOGVV) {
- Log.v(TAG, "getChannel for " + remoteDevice + "_" + Integer.toHexString(uuid) +
+ if (V) Log.v(TAG, "getChannel for " + remoteDevice + "_" + Integer.toHexString(uuid) +
" as " + channel);
- }
}
return channel;
}
public void setName(BluetoothDevice remoteDevice, String name) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Setname for " + remoteDevice + " to " + name);
- }
+ if (V) Log.v(TAG, "Setname for " + remoteDevice + " to " + name);
if (!name.equals(getName(remoteDevice))) {
Editor ed = mNamePreference.edit();
ed.putString(remoteDevice.getAddress(), name);
@@ -141,10 +137,8 @@ public class BluetoothOppPreference {
}
public void setChannel(BluetoothDevice remoteDevice, int uuid, int channel) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Setchannel for " + remoteDevice + "_" + Integer.toHexString(uuid) + " to "
+ if (V) Log.v(TAG, "Setchannel for " + remoteDevice + "_" + Integer.toHexString(uuid) + " to "
+ channel);
- }
if (channel == getChannel(remoteDevice, uuid)) {
String key = getChannelKey(remoteDevice, uuid);
Editor ed = mChannelPreference.edit();
diff --git a/src/com/android/bluetooth/opp/BluetoothOppProvider.java b/src/com/android/bluetooth/opp/BluetoothOppProvider.java
index 76c8709d3..72dafc81f 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppProvider.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppProvider.java
@@ -54,7 +54,9 @@ import java.util.HashMap;
public final class BluetoothOppProvider extends ContentProvider {
- public static final String TAG = "BluetoothOppProvider";
+ private static final String TAG = "BluetoothOppProvider";
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
/** Database filename */
private static final String DB_NAME = "btopp.db";
@@ -124,9 +126,7 @@ public final class BluetoothOppProvider extends ContentProvider {
*/
@Override
public void onCreate(final SQLiteDatabase db) {
- if (Constants.LOGVV) {
- Log.v(TAG, "populating new database");
- }
+ if (V) Log.v(TAG, "populating new database");
createTable(db);
}
@@ -206,9 +206,7 @@ public final class BluetoothOppProvider extends ContentProvider {
return SHARE_TYPE;
}
default: {
- if (Constants.LOGV) {
- Log.v(TAG, "calling getType on an unknown URI: " + uri);
- }
+ if (D) Log.d(TAG, "calling getType on an unknown URI: " + uri);
throw new IllegalArgumentException("Unknown URI: " + uri);
}
}
@@ -233,9 +231,7 @@ public final class BluetoothOppProvider extends ContentProvider {
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
if (sURIMatcher.match(uri) != SHARES) {
- if (Constants.LOGV) {
- Log.d(TAG, "calling insert on an unknown/invalid URI: " + uri);
- }
+ if (D) Log.d(TAG, "calling insert on an unknown/invalid URI: " + uri);
throw new IllegalArgumentException("Unknown/Invalid URI " + uri);
}
@@ -288,10 +284,8 @@ public final class BluetoothOppProvider extends ContentProvider {
ret = Uri.parse(BluetoothShare.CONTENT_URI + "/" + rowID);
context.getContentResolver().notifyChange(uri, null);
} else {
- if (Constants.LOGV) {
- Log.d(TAG, "couldn't insert into btopp database");
+ if (D) Log.d(TAG, "couldn't insert into btopp database");
}
- }
return ret;
}
@@ -330,14 +324,12 @@ public final class BluetoothOppProvider extends ContentProvider {
break;
}
default: {
- if (Constants.LOGV) {
- Log.v(TAG, "querying unknown URI: " + uri);
- }
+ if (D) Log.d(TAG, "querying unknown URI: " + uri);
throw new IllegalArgumentException("Unknown URI: " + uri);
}
}
- if (Constants.LOGVV) {
+ if (V) {
java.lang.StringBuilder sb = new java.lang.StringBuilder();
sb.append("starting query, database is ");
if (db != null) {
@@ -383,14 +375,10 @@ public final class BluetoothOppProvider extends ContentProvider {
if (ret != null) {
ret.setNotificationUri(getContext().getContentResolver(), uri);
- if (Constants.LOGVV) {
- Log.v(TAG, "created cursor " + ret + " on behalf of ");// +
- }
+ if (V) Log.v(TAG, "created cursor " + ret + " on behalf of ");// +
} else {
- if (Constants.LOGV) {
- Log.v(TAG, "query failed in downloads database");
+ if (D) Log.d(TAG, "query failed in downloads database");
}
- }
return ret;
}
@@ -430,9 +418,7 @@ public final class BluetoothOppProvider extends ContentProvider {
break;
}
default: {
- if (Constants.LOGV) {
- Log.d(TAG, "updating unknown/invalid URI: " + uri);
- }
+ if (D) Log.d(TAG, "updating unknown/invalid URI: " + uri);
throw new UnsupportedOperationException("Cannot update URI: " + uri);
}
}
@@ -469,9 +455,7 @@ public final class BluetoothOppProvider extends ContentProvider {
break;
}
default: {
- if (Constants.LOGV) {
- Log.d(TAG, "deleting unknown/invalid URI: " + uri);
- }
+ if (D) Log.d(TAG, "deleting unknown/invalid URI: " + uri);
throw new UnsupportedOperationException("Cannot delete URI: " + uri);
}
}
diff --git a/src/com/android/bluetooth/opp/BluetoothOppReceiveFileInfo.java b/src/com/android/bluetooth/opp/BluetoothOppReceiveFileInfo.java
index 1c157d219..aa8684af5 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppReceiveFileInfo.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppReceiveFileInfo.java
@@ -54,6 +54,8 @@ import android.util.Log;
* name
*/
public class BluetoothOppReceiveFileInfo {
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
/** absolute store file name */
public String mFileName;
@@ -112,17 +114,13 @@ public class BluetoothOppReceiveFileInfo {
String root = Environment.getExternalStorageDirectory().getPath();
base = new File(root + Constants.DEFAULT_STORE_SUBDIR);
if (!base.isDirectory() && !base.mkdir()) {
- if (Constants.LOGV) {
- Log.v(Constants.TAG, "Receive File aborted - can't create base directory "
+ if (D) Log.d(Constants.TAG, "Receive File aborted - can't create base directory "
+ base.getPath());
- }
return new BluetoothOppReceiveFileInfo(BluetoothShare.STATUS_FILE_ERROR);
}
stat = new StatFs(base.getPath());
} else {
- if (Constants.LOGV) {
- Log.v(Constants.TAG, "Receive File aborted - no external storage");
- }
+ if (D) Log.d(Constants.TAG, "Receive File aborted - no external storage");
return new BluetoothOppReceiveFileInfo(BluetoothShare.STATUS_ERROR_NO_SDCARD);
}
@@ -132,9 +130,7 @@ public class BluetoothOppReceiveFileInfo {
* system by a few blocks).
*/
if (stat.getBlockSize() * ((long)stat.getAvailableBlocks() - 4) < length) {
- if (Constants.LOGV) {
- Log.v(Constants.TAG, "Receive File aborted - not enough free space");
- }
+ if (D) Log.d(Constants.TAG, "Receive File aborted - not enough free space");
return new BluetoothOppReceiveFileInfo(BluetoothShare.STATUS_ERROR_SDCARD_FULL);
}
@@ -151,9 +147,7 @@ public class BluetoothOppReceiveFileInfo {
filename = base.getPath() + File.separator + filename;
// Generate a unique filename, create the file, return it.
String fullfilename = chooseUniquefilename(filename, extension);
- if (Constants.LOGVV) {
- Log.v(Constants.TAG, "Generated received filename " + fullfilename);
- }
+ if (V) Log.v(Constants.TAG, "Generated received filename " + fullfilename);
if (fullfilename != null) {
try {
@@ -162,9 +156,7 @@ public class BluetoothOppReceiveFileInfo {
// update display name
if (index > 0) {
String displayName = fullfilename.substring(index);
- if (Constants.LOGVV) {
- Log.v(Constants.TAG, "New display name " + displayName);
- }
+ if (V) Log.v(Constants.TAG, "New display name " + displayName);
ContentValues updateValues = new ContentValues();
updateValues.put(BluetoothShare.FILENAME_HINT, displayName);
context.getContentResolver().update(contentUri, updateValues, null, null);
@@ -173,9 +165,7 @@ public class BluetoothOppReceiveFileInfo {
return new BluetoothOppReceiveFileInfo(fullfilename, length, new FileOutputStream(
fullfilename), 0);
} catch (IOException e) {
- if (Constants.LOGV) {
- Log.e(Constants.TAG, "Error when creating file " + fullfilename);
- }
+ if (D) Log.e(Constants.TAG, "Error when creating file " + fullfilename);
return new BluetoothOppReceiveFileInfo(BluetoothShare.STATUS_FILE_ERROR);
}
} else {
@@ -209,9 +199,7 @@ public class BluetoothOppReceiveFileInfo {
if (!new File(fullfilename).exists()) {
return fullfilename;
}
- if (Constants.LOGVV) {
- Log.v(Constants.TAG, "file with sequence number " + sequence + " exists");
- }
+ if (V) Log.v(Constants.TAG, "file with sequence number " + sequence + " exists");
sequence += rnd.nextInt(magnitude) + 1;
}
}
@@ -223,9 +211,7 @@ public class BluetoothOppReceiveFileInfo {
// First, try to use the hint from the application, if there's one
if (filename == null && hint != null && !hint.endsWith("/")) {
- if (Constants.LOGVV) {
- Log.v(Constants.TAG, "getting filename from hint");
- }
+ if (V) Log.v(Constants.TAG, "getting filename from hint");
int index = hint.lastIndexOf('/') + 1;
if (index > 0) {
filename = hint.substring(index);
diff --git a/src/com/android/bluetooth/opp/BluetoothOppReceiver.java b/src/com/android/bluetooth/opp/BluetoothOppReceiver.java
index d736b9078..cb663cf2b 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppReceiver.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppReceiver.java
@@ -55,6 +55,8 @@ import android.widget.Toast;
*/
public class BluetoothOppReceiver extends BroadcastReceiver {
private static final String TAG = "BluetoothOppReceiver";
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
@Override
public void onReceive(Context context, Intent intent) {
@@ -66,9 +68,7 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
} else if (action.equals(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION)) {
if (BluetoothAdapter.BLUETOOTH_STATE_ON == intent.getIntExtra(
BluetoothIntent.BLUETOOTH_STATE, BluetoothError.ERROR)) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Received BLUETOOTH_STATE_CHANGED_ACTION, BLUETOOTH_STATE_ON");
- }
+ if (V) Log.v(TAG, "Received BLUETOOTH_STATE_CHANGED_ACTION, BLUETOOTH_STATE_ON");
context.startService(new Intent(context, BluetoothOppService.class));
// If this is within a sending process, continue the handle
@@ -97,9 +97,7 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
BluetoothDevice remoteDevice = intent.getParcelableExtra(BluetoothIntent.DEVICE);
- if (Constants.LOGVV) {
- Log.v(TAG, "Received BT device selected intent, bt device: " + remoteDevice);
- }
+ if (V) Log.v(TAG, "Received BT device selected intent, bt device: " + remoteDevice);
// Insert transfer session record to database
mOppManager.startTransfer(remoteDevice);
@@ -115,9 +113,7 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
}
Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show();
} else if (action.equals(Constants.ACTION_INCOMING_FILE_CONFIRM)) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Receiver ACTION_INCOMING_FILE_CONFIRM");
- }
+ if (V) Log.v(TAG, "Receiver ACTION_INCOMING_FILE_CONFIRM");
Uri uri = intent.getData();
Intent in = new Intent(context, BluetoothOppIncomingFileConfirmActivity.class);
@@ -132,15 +128,13 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
Log.v(TAG, "notMgr.cancel called");
}
} else if (action.equals(BluetoothShare.INCOMING_FILE_CONFIRMATION_REQUEST_ACTION)) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Receiver INCOMING_FILE_NOTIFICATION");
- }
+ if (V) Log.v(TAG, "Receiver INCOMING_FILE_NOTIFICATION");
Toast.makeText(context, context.getString(R.string.incoming_file_toast_msg),
Toast.LENGTH_SHORT).show();
} else if (action.equals(Constants.ACTION_OPEN) || action.equals(Constants.ACTION_LIST)) {
- if (Constants.LOGVV) {
+ if (V) {
if (action.equals(Constants.ACTION_OPEN)) {
Log.v(TAG, "Receiver open for " + intent.getData());
} else {
@@ -152,9 +146,7 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
Uri uri = intent.getData();
transInfo = BluetoothOppUtility.queryRecord(context, uri);
if (transInfo == null) {
- if (Constants.LOGVV) {
- Log.e(TAG, "Error: Can not get data from db");
- }
+ if (V) Log.e(TAG, "Error: Can not get data from db");
return;
}
@@ -175,14 +167,10 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
.getSystemService(Context.NOTIFICATION_SERVICE);
if (notMgr != null) {
notMgr.cancel((int)ContentUris.parseId(intent.getData()));
- if (Constants.LOGVV) {
- Log.v(TAG, "notMgr.cancel called");
+ if (V) Log.v(TAG, "notMgr.cancel called");
}
- }
} else if (action.equals(Constants.ACTION_HIDE)) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Receiver hide for " + intent.getData());
- }
+ if (V) Log.v(TAG, "Receiver hide for " + intent.getData());
Cursor cursor = context.getContentResolver().query(intent.getData(), null, null, null,
null);
if (cursor != null) {
@@ -199,25 +187,19 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
ContentValues values = new ContentValues();
values.put(BluetoothShare.VISIBILITY, BluetoothShare.VISIBILITY_HIDDEN);
context.getContentResolver().update(intent.getData(), values, null, null);
- if (Constants.LOGVV) {
- Log.v(TAG, "Action_hide received and db updated");
+ if (V) Log.v(TAG, "Action_hide received and db updated");
}
- }
}
cursor.close();
}
} else if (action.equals(BluetoothShare.TRANSFER_COMPLETED_ACTION)) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Receiver Transfer Complete Intent for " + intent.getData());
- }
+ if (V) Log.v(TAG, "Receiver Transfer Complete Intent for " + intent.getData());
String toastMsg = null;
BluetoothOppTransferInfo transInfo = new BluetoothOppTransferInfo();
transInfo = BluetoothOppUtility.queryRecord(context, intent.getData());
if (transInfo == null) {
- if (Constants.LOGVV) {
- Log.e(TAG, "Error: Can not get data from db");
- }
+ if (V) Log.e(TAG, "Error: Can not get data from db");
return;
}
@@ -237,9 +219,7 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
toastMsg = context.getString(R.string.download_fail_line1);
}
}
- if (Constants.LOGVV) {
- Log.v(TAG, "Toast msg == " + toastMsg);
- }
+ if (V) Log.v(TAG, "Toast msg == " + toastMsg);
if (toastMsg != null) {
Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show();
}
diff --git a/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java b/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java
index 2a55f6001..b99c5b4c5 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppRfcommListener.java
@@ -48,7 +48,9 @@ import android.util.Log;
* This class listens on OPUSH channel for incoming connection
*/
public class BluetoothOppRfcommListener {
- private static final String TAG = "BtOpp RfcommListener";
+ private static final String TAG = "BtOppRfcommListener";
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
public static final int MSG_INCOMING_BTOPP_CONNECTION = 100;
@@ -87,10 +89,8 @@ public class BluetoothOppRfcommListener {
if (Constants.USE_TCP_DEBUG) {
ServerSocket mServerSocket = null;
try {
- if (Constants.LOGVV) {
- Log.v(TAG, "Create ServerSocket on port "
+ if (V) Log.v(TAG, "Create ServerSocket on port "
+ Constants.TCP_DEBUG_PORT);
- }
mServerSocket = new ServerSocket(Constants.TCP_DEBUG_PORT, 1);
@@ -104,13 +104,9 @@ public class BluetoothOppRfcommListener {
Socket clientSocket = mServerSocket.accept();
if (clientSocket == null) {
- if (Constants.LOGVV) {
- Log.v(TAG, "incomming connection time out");
- }
+ if (V) Log.v(TAG, "incomming connection time out");
} else {
- if (Constants.LOGV) {
- Log.v(TAG, "TCP Socket connected!");
- }
+ if (D) Log.d(TAG, "TCP Socket connected!");
Log.d(TAG, "remote addr is "
+ clientSocket.getRemoteSocketAddress());
TestTcpTransport transport = new TestTcpTransport(clientSocket);
@@ -121,18 +117,12 @@ public class BluetoothOppRfcommListener {
msg.sendToTarget();
}
} catch (SocketException e) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Error accept connection " + e);
- }
+ if (V) Log.v(TAG, "Error accept connection " + e);
} catch (IOException e) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Error accept connection " + e);
- }
+ if (V) Log.v(TAG, "Error accept connection " + e);
}
}
- if (Constants.LOGV) {
- Log.v(TAG, "TCP listen thread finished");
- }
+ if (D) Log.d(TAG, "TCP listen thread finished");
try {
mServerSocket.close();
} catch (IOException e) {
@@ -157,9 +147,7 @@ public class BluetoothOppRfcommListener {
if (!serverOK) {
synchronized (this) {
try {
- if (Constants.LOGVV) {
- Log.v(TAG, "wait 3 seconds");
- }
+ if (V) Log.v(TAG, "wait 3 seconds");
Thread.sleep(3000);
} catch (InterruptedException e) {
Log.e(TAG, "socketAcceptThread thread was interrupted (3)");
@@ -191,16 +179,12 @@ public class BluetoothOppRfcommListener {
msg.sendToTarget();
} catch (IOException e) {
//TODO later accept should not throw exception
- if (Constants.LOGVV) {
- //Log.v(TAG, "Error accept connection " + e);
- }
+ // if (V) Log.v(TAG, "Error accept connection " + e);
}
}
try {
if (mServerSocket != null) {
- if (Constants.LOGVV) {
- Log.v(TAG, "close mServerSocket");
- }
+ if (V) Log.v(TAG, "close mServerSocket");
mServerSocket.close();
}
} catch (IOException e) {
@@ -223,16 +207,12 @@ public class BluetoothOppRfcommListener {
mInterrupted = true;
try {
mSocketAcceptThread.interrupt();
- if (Constants.LOGVV) {
- Log.v(TAG, "waiting for thread to terminate");
- }
+ if (V) Log.v(TAG, "waiting for thread to terminate");
mSocketAcceptThread.join();
mSocketAcceptThread = null;
mCallback = null;
} catch (InterruptedException e) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Interrupted waiting for Accept Thread to join");
- }
+ if (V) Log.v(TAG, "Interrupted waiting for Accept Thread to join");
}
}
}
diff --git a/src/com/android/bluetooth/opp/BluetoothOppService.java b/src/com/android/bluetooth/opp/BluetoothOppService.java
index 424145c06..e946fd0df 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppService.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppService.java
@@ -70,6 +70,8 @@ import java.util.ArrayList;
*/
public class BluetoothOppService extends Service {
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
private boolean userAccepted = false;
@@ -81,9 +83,7 @@ public class BluetoothOppService extends Service {
@Override
public void onChange(boolean selfChange) {
- if (Constants.LOGVV) {
- Log.v(TAG, "ContentObserver received notification");
- }
+ if (V) Log.v(TAG, "ContentObserver received notification");
updateFromProvider();
}
}
@@ -149,9 +149,7 @@ public class BluetoothOppService extends Service {
@Override
public void onCreate() {
super.onCreate();
- if (Constants.LOGVV) {
- Log.v(TAG, "Service onCreate");
- }
+ if (V) Log.v(TAG, "Service onCreate");
mAdapter = (BluetoothAdapter) getSystemService(Context.BLUETOOTH_SERVICE);
mSocketListener = new BluetoothOppRfcommListener(mAdapter);
mShares = Lists.newArrayList();
@@ -176,18 +174,14 @@ public class BluetoothOppService extends Service {
startListenerDelayed();
}
}
- if (Constants.LOGVV) {
- BluetoothOppPreference.getInstance(this).dump();
- }
+ if (V) BluetoothOppPreference.getInstance(this).dump();
updateFromProvider();
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
- if (Constants.LOGVV) {
- Log.v(TAG, "Service onStart");
- }
+ if (V) Log.v(TAG, "Service onStart");
if (mAdapter == null) {
Log.w(TAG, "Local BT device is not enabled");
@@ -201,9 +195,7 @@ public class BluetoothOppService extends Service {
private void startListenerDelayed() {
if (!mListenStarted) {
if (mAdapter.isEnabled()) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Starting RfcommListener in 9 seconds");
- }
+ if (V) Log.v(TAG, "Starting RfcommListener in 9 seconds");
mHandler.sendMessageDelayed(mHandler.obtainMessage(START_LISTENER), 9000);
mListenStarted = true;
}
@@ -228,10 +220,8 @@ public class BluetoothOppService extends Service {
}
break;
case MEDIA_SCANNED:
- if (Constants.LOGVV) {
- Log.v(TAG, "Update mInfo.id " + msg.arg1 + " for data uri= "
+ if (V) Log.v(TAG, "Update mInfo.id " + msg.arg1 + " for data uri= "
+ msg.obj.toString());
- }
ContentValues updateValues = new ContentValues();
Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + msg.arg1);
updateValues.put(Constants.MEDIA_SCANNED, Constants.MEDIA_SCANNED_SCANNED_OK);
@@ -255,9 +245,7 @@ public class BluetoothOppService extends Service {
}
break;
case BluetoothOppRfcommListener.MSG_INCOMING_BTOPP_CONNECTION:
- if (Constants.LOGV) {
- Log.v(TAG, "Get incoming connection");
- }
+ if (D) Log.d(TAG, "Get incoming connection");
ObexTransport transport = (ObexTransport)msg.obj;
/*
* Strategy for incoming connections:
@@ -317,20 +305,14 @@ public class BluetoothOppService extends Service {
private void startSocketListener() {
- if (Constants.LOGVV) {
- Log.v(TAG, "start RfcommListener");
- }
+ if (V) Log.v(TAG, "start RfcommListener");
mSocketListener.start(mHandler);
- if (Constants.LOGVV) {
- Log.v(TAG, "RfcommListener started");
- }
+ if (V) Log.v(TAG, "RfcommListener started");
}
@Override
public void onDestroy() {
- if (Constants.LOGVV) {
- Log.v(TAG, "Service onDestroy");
- }
+ if (V) Log.v(TAG, "Service onDestroy");
super.onDestroy();
mNotifier.finishNotification();
getContentResolver().unregisterContentObserver(mObserver);
@@ -342,10 +324,8 @@ public class BluetoothOppService extends Service {
private void createServerSession(ObexTransport transport) {
mServerSession = new BluetoothOppObexServerSession(this, transport);
mServerSession.preStart();
- if (Constants.LOGV) {
- Log.v(TAG, "Get ServerSession " + mServerSession.toString()
+ if (D) Log.d(TAG, "Get ServerSession " + mServerSession.toString()
+ " for incoming connection" + transport.toString());
- }
}
private final BroadcastReceiver mBluetoothIntentReceiver = new BroadcastReceiver() {
@@ -356,16 +336,12 @@ public class BluetoothOppService extends Service {
if (action.equals(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION)) {
switch (intent.getIntExtra(BluetoothIntent.BLUETOOTH_STATE, BluetoothError.ERROR)) {
case BluetoothAdapter.BLUETOOTH_STATE_ON:
- if (Constants.LOGVV) {
- Log.v(TAG,
+ if (V) Log.v(TAG,
"Receiver BLUETOOTH_STATE_CHANGED_ACTION, BLUETOOTH_STATE_ON");
- }
startSocketListener();
break;
case BluetoothAdapter.BLUETOOTH_STATE_TURNING_OFF:
- if (Constants.LOGVV) {
- Log.v(TAG, "Receiver DISABLED_ACTION ");
- }
+ if (V) Log.v(TAG, "Receiver DISABLED_ACTION ");
mSocketListener.stop();
mListenStarted = false;
synchronized (BluetoothOppService.this) {
@@ -405,10 +381,8 @@ public class BluetoothOppService extends Service {
throw new IllegalStateException(
"multiple UpdateThreads in BluetoothOppService");
}
- if (Constants.LOGVV) {
- Log.v(TAG, "pendingUpdate is " + mPendingUpdate + " keepUpdateThread is "
+ if (V) Log.v(TAG, "pendingUpdate is " + mPendingUpdate + " keepUpdateThread is "
+ keepService + " sListenStarted is " + mListenStarted);
- }
if (!mPendingUpdate) {
mUpdateThread = null;
if (!keepService && !mListenStarted) {
@@ -456,10 +430,8 @@ public class BluetoothOppService extends Service {
// We're beyond the end of the cursor but there's still
// some
// stuff in the local array, which can only be junk
- if (Constants.LOGVV) {
- int arrayId = mShares.get(arrayPos).mId;
- Log.v(TAG, "Array update: trimming " + arrayId + " @ " + arrayPos);
- }
+ if (V) Log.v(TAG, "Array update: trimming " +
+ mShares.get(arrayPos).mId + " @ " + arrayPos);
if (shouldScanFile(arrayPos)) {
scanFile(null, arrayPos);
@@ -470,9 +442,7 @@ public class BluetoothOppService extends Service {
if (arrayPos == mShares.size()) {
insertShare(cursor, arrayPos);
- if (Constants.LOGVV) {
- Log.v(TAG, "Array update: inserting " + id + " @ " + arrayPos);
- }
+ if (V) Log.v(TAG, "Array update: inserting " + id + " @ " + arrayPos);
if (shouldScanFile(arrayPos) && (!scanFile(cursor, arrayPos))) {
keepService = true;
}
@@ -490,10 +460,8 @@ public class BluetoothOppService extends Service {
int arrayId = mShares.get(arrayPos).mId;
if (arrayId < id) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Array update: removing " + arrayId + " @ "
+ if (V) Log.v(TAG, "Array update: removing " + arrayId + " @ "
+ arrayPos);
- }
if (shouldScanFile(arrayPos)) {
scanFile(null, arrayPos);
}
@@ -518,9 +486,7 @@ public class BluetoothOppService extends Service {
} else {
// This cursor entry didn't exist in the stored
// array
- if (Constants.LOGVV) {
- Log.v(TAG, "Array update: appending " + id + " @ " + arrayPos);
- }
+ if (V) Log.v(TAG, "Array update: appending " + id + " @ " + arrayPos);
insertShare(cursor, arrayPos);
if (shouldScanFile(arrayPos) && (!scanFile(cursor, arrayPos))) {
@@ -565,7 +531,7 @@ public class BluetoothOppService extends Service {
cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare.TIMESTAMP)),
cursor.getInt(cursor.getColumnIndexOrThrow(Constants.MEDIA_SCANNED)) != Constants.MEDIA_SCANNED_NOT_SCANNED);
- if (Constants.LOGVV) {
+ if (V) {
Log.v(TAG, "Service adding new entry");
Log.v(TAG, "ID : " + info.mId);
// Log.v(TAG, "URI : " + ((info.mUri != null) ? "yes" : "no"));
@@ -621,55 +587,43 @@ public class BluetoothOppService extends Service {
mBatchId++;
mBatchs.add(newBatch);
if (info.mDirection == BluetoothShare.DIRECTION_OUTBOUND) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Service create new Batch " + newBatch.mId
+ if (V) Log.v(TAG, "Service create new Batch " + newBatch.mId
+ " for OUTBOUND info " + info.mId);
- }
mTransfer = new BluetoothOppTransfer(this, mPowerManager, newBatch);
} else if (info.mDirection == BluetoothShare.DIRECTION_INBOUND) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Service create new Batch " + newBatch.mId
+ if (V) Log.v(TAG, "Service create new Batch " + newBatch.mId
+ " for INBOUND info " + info.mId);
- }
mServerTransfer = new BluetoothOppTransfer(this, mPowerManager, newBatch,
mServerSession);
}
if (info.mDirection == BluetoothShare.DIRECTION_OUTBOUND && mTransfer != null) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Service start transfer new Batch " + newBatch.mId
+ if (V) Log.v(TAG, "Service start transfer new Batch " + newBatch.mId
+ " for info " + info.mId);
- }
mTransfer.start();
} else if (info.mDirection == BluetoothShare.DIRECTION_INBOUND
&& mServerTransfer != null) {
/*
* TODO investigate here later?
*/
- if (Constants.LOGVV) {
- Log.v(TAG, "Service start server transfer new Batch " + newBatch.mId
+ if (V) Log.v(TAG, "Service start server transfer new Batch " + newBatch.mId
+ " for info " + info.mId);
- }
mServerTransfer.start();
}
} else {
int i = findBatchWithTimeStamp(info.mTimestamp);
if (i != -1) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Service add info " + info.mId + " to existing batch "
+ if (V) Log.v(TAG, "Service add info " + info.mId + " to existing batch "
+ mBatchs.get(i).mId);
- }
mBatchs.get(i).addShare(info);
} else {
BluetoothOppBatch newBatch = new BluetoothOppBatch(this, info);
newBatch.mId = mBatchId;
mBatchId++;
mBatchs.add(newBatch);
- if (Constants.LOGVV) {
- Log.v(TAG, "Service add new Batch " + newBatch.mId + " for info "
+ if (V) Log.v(TAG, "Service add new Batch " + newBatch.mId + " for info "
+ info.mId);
- }
}
}
}
@@ -721,9 +675,7 @@ public class BluetoothOppService extends Service {
info.mMediaScanned = (cursor.getInt(cursor.getColumnIndexOrThrow(Constants.MEDIA_SCANNED)) != Constants.MEDIA_SCANNED_NOT_SCANNED);
if (confirmed) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Service handle info " + info.mId + " confirmed");
- }
+ if (V) Log.v(TAG, "Service handle info " + info.mId + " confirmed");
/* Inbounds transfer get user confirmation, so we start it */
int i = findBatchWithTimeStamp(info.mTimestamp);
BluetoothOppBatch batch = mBatchs.get(i);
@@ -736,9 +688,7 @@ public class BluetoothOppService extends Service {
BluetoothOppBatch batch = mBatchs.get(i);
if (batch.mStatus == Constants.BATCH_STATUS_FINISHED
|| batch.mStatus == Constants.BATCH_STATUS_FAILED) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Batch " + batch.mId + " is finished");
- }
+ if (V) Log.v(TAG, "Batch " + batch.mId + " is finished");
if (batch.mDirection == BluetoothShare.DIRECTION_OUTBOUND) {
if (mTransfer == null) {
Log.e(TAG, "Unexpected error! mTransfer is null");
@@ -780,15 +730,11 @@ public class BluetoothOppService extends Service {
if (i != -1) {
BluetoothOppBatch batch = mBatchs.get(i);
if (batch.hasShare(info)) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Service cancel batch for share " + info.mId);
- }
+ if (V) Log.v(TAG, "Service cancel batch for share " + info.mId);
batch.cancelBatch();
}
if (batch.isEmpty()) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Service remove batch " + batch.mId);
- }
+ if (V) Log.v(TAG, "Service remove batch " + batch.mId);
removeBatch(batch);
}
}
@@ -832,9 +778,7 @@ public class BluetoothOppService extends Service {
}
private int findBatchWithId(int id) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Service search batch for id " + id + " from " + mBatchs.size());
- }
+ if (V) Log.v(TAG, "Service search batch for id " + id + " from " + mBatchs.size());
for (int i = mBatchs.size() - 1; i >= 0; i--) {
if (mBatchs.get(i).mId == id) {
return i;
@@ -844,9 +788,7 @@ public class BluetoothOppService extends Service {
}
private void removeBatch(BluetoothOppBatch batch) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Remove batch " + batch.mId);
- }
+ if (V) Log.v(TAG, "Remove batch " + batch.mId);
mBatchs.remove(batch);
if (mBatchs.size() > 0) {
for (int i = 0; i < mBatchs.size(); i++) {
@@ -857,9 +799,7 @@ public class BluetoothOppService extends Service {
// Pending batch for inbound transfer is not supported
// just finish a transfer, start pending outbound transfer
if (mBatchs.get(i).mDirection == BluetoothShare.DIRECTION_OUTBOUND) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Start pending outbound batch " + mBatchs.get(i).mId);
- }
+ if (V) Log.v(TAG, "Start pending outbound batch " + mBatchs.get(i).mId);
mTransfer = new BluetoothOppTransfer(this, mPowerManager, mBatchs.get(i));
mTransfer.start();
return;
@@ -888,9 +828,7 @@ public class BluetoothOppService extends Service {
private boolean scanFile(Cursor cursor, int arrayPos) {
BluetoothOppShareInfo info = mShares.get(arrayPos);
synchronized (BluetoothOppService.this) {
- if (Constants.LOGV) {
- Log.v(TAG, "Scanning file " + info.mFilename);
- }
+ if (D) Log.d(TAG, "Scanning file " + info.mFilename);
if (!mMediaScanInProgress) {
mMediaScanInProgress = true;
new MediaScannerNotifier(this, info, mHandler);
@@ -948,22 +886,18 @@ public class BluetoothOppService extends Service {
mInfo = info;
mCallback = handler;
mConnection = new MediaScannerConnection(mContext, this);
- if (Constants.LOGVV) {
- Log.v(TAG, "Connecting to MediaScannerConnection ");
- }
+ if (V) Log.v(TAG, "Connecting to MediaScannerConnection ");
mConnection.connect();
}
public void onMediaScannerConnected() {
- if (Constants.LOGVV) {
- Log.v(TAG, "MediaScannerConnection onMediaScannerConnected");
- }
+ if (V) Log.v(TAG, "MediaScannerConnection onMediaScannerConnected");
mConnection.scanFile(mInfo.mFilename, mInfo.mMimetype);
}
public void onScanCompleted(String path, Uri uri) {
try {
- if (Constants.LOGVV) {
+ if (V) {
Log.v(TAG, "MediaScannerConnection onScanCompleted");
Log.v(TAG, "MediaScannerConnection path is " + path);
Log.v(TAG, "MediaScannerConnection Uri is " + uri);
@@ -985,9 +919,7 @@ public class BluetoothOppService extends Service {
} catch (Exception ex) {
Log.v(TAG, "!!!MediaScannerConnection exception: " + ex);
} finally {
- if (Constants.LOGVV) {
- Log.v(TAG, "MediaScannerConnection disconnect");
- }
+ if (V) Log.v(TAG, "MediaScannerConnection disconnect");
mConnection.disconnect();
}
}
diff --git a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java
index 3fd073f9e..80cf16da6 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java
@@ -60,7 +60,9 @@ import java.util.UUID;
* disconnect)
*/
public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatchListener {
- private static final String TAG = "BtOpp Transfer";
+ private static final String TAG = "BtOppTransfer";
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
public static final int RFCOMM_ERROR = 10;
@@ -133,10 +135,8 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
public void handleMessage(Message msg) {
switch (msg.what) {
case SDP_RESULT:
- if (Constants.LOGVV) {
- Log.v(TAG, "SDP request returned " + msg.arg1 + " ("
- + (System.currentTimeMillis() - mTimestamp + " ms)"));
- }
+ if (V) Log.v(TAG, "SDP request returned " + msg.arg1 + " (" +
+ (System.currentTimeMillis() - mTimestamp + " ms)"));
if (!((BluetoothDevice)msg.obj).equals(mBatch.mDestination)) {
return;
}
@@ -158,9 +158,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
* failed, and all shares in batch failed
*/
case RFCOMM_ERROR:
- if (Constants.LOGVV) {
- Log.v(TAG, "receive RFCOMM_ERROR msg");
- }
+ if (V) Log.v(TAG, "receive RFCOMM_ERROR msg");
mConnectThread = null;
markBatchFailed(BluetoothShare.STATUS_CONNECTION_ERROR);
mBatch.mStatus = Constants.BATCH_STATUS_FAILED;
@@ -171,9 +169,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
* BluetoothOppObexClientSession and start it
*/
case RFCOMM_CONNECTED:
- if (Constants.LOGVV) {
- Log.v(TAG, "Transfer receive RFCOMM_CONNECTED msg");
- }
+ if (V) Log.v(TAG, "Transfer receive RFCOMM_CONNECTED msg");
mConnectThread = null;
mTransport = (ObexTransport)msg.obj;
startObexSession();
@@ -188,24 +184,18 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
*/
case BluetoothOppObexSession.MSG_SHARE_COMPLETE:
BluetoothOppShareInfo info = (BluetoothOppShareInfo)msg.obj;
- if (Constants.LOGVV) {
- Log.v(TAG, "receive MSG_SHARE_COMPLETE for info " + info.mId);
- }
+ if (V) Log.v(TAG, "receive MSG_SHARE_COMPLETE for info " + info.mId);
if (mBatch.mDirection == BluetoothShare.DIRECTION_OUTBOUND) {
mCurrentShare = mBatch.getPendingShare();
if (mCurrentShare != null) {
/* we have additional share to process */
- if (Constants.LOGVV) {
- Log.v(TAG, "continue session for info " + mCurrentShare.mId
- + " from batch " + mBatch.mId);
- }
+ if (V) Log.v(TAG, "continue session for info " + mCurrentShare.mId +
+ " from batch " + mBatch.mId);
processCurrentShare();
} else {
/* for outbound transfer, all shares are processed */
- if (Constants.LOGVV) {
- Log.v(TAG, "Batch " + mBatch.mId + " is done");
- }
+ if (V) Log.v(TAG, "Batch " + mBatch.mId + " is done");
mSession.stop();
}
}
@@ -216,9 +206,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
*/
case BluetoothOppObexSession.MSG_SESSION_COMPLETE:
BluetoothOppShareInfo info1 = (BluetoothOppShareInfo)msg.obj;
- if (Constants.LOGVV) {
- Log.v(TAG, "receive MSG_SESSION_COMPLETE for batch " + mBatch.mId);
- }
+ if (V) Log.v(TAG, "receive MSG_SESSION_COMPLETE for batch " + mBatch.mId);
mBatch.mStatus = Constants.BATCH_STATUS_FINISHED;
/*
* trigger content provider again to know batch status change
@@ -228,9 +216,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
/* Handle the error state of an Obex session */
case BluetoothOppObexSession.MSG_SESSION_ERROR:
- if (Constants.LOGVV) {
- Log.v(TAG, "receive MSG_SESSION_ERROR for batch " + mBatch.mId);
- }
+ if (V) Log.v(TAG, "receive MSG_SESSION_ERROR for batch " + mBatch.mId);
BluetoothOppShareInfo info2 = (BluetoothOppShareInfo)msg.obj;
mSession.stop();
mBatch.mStatus = Constants.BATCH_STATUS_FAILED;
@@ -239,9 +225,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
break;
case BluetoothOppObexSession.MSG_SHARE_INTERRUPTED:
- if (Constants.LOGVV) {
- Log.v(TAG, "receive MSG_SHARE_INTERRUPTED for batch " + mBatch.mId);
- }
+ if (V) Log.v(TAG, "receive MSG_SHARE_INTERRUPTED for batch " + mBatch.mId);
BluetoothOppShareInfo info3 = (BluetoothOppShareInfo)msg.obj;
if (mBatch.mDirection == BluetoothShare.DIRECTION_OUTBOUND) {
try {
@@ -253,9 +237,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
} catch (IOException e) {
Log.e(TAG, "failed to close mTransport");
}
- if (Constants.LOGVV) {
- Log.v(TAG, "mTransport closed ");
- }
+ if (V) Log.v(TAG, "mTransport closed ");
}
mBatch.mStatus = Constants.BATCH_STATUS_FAILED;
if (info3 != null) {
@@ -267,9 +249,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
break;
case BluetoothOppObexSession.MSG_CONNECT_TIMEOUT:
- if (Constants.LOGVV) {
- Log.v(TAG, "receive MSG_CONNECT_TIMEOUT for batch " + mBatch.mId);
- }
+ if (V) Log.v(TAG, "receive MSG_CONNECT_TIMEOUT for batch " + mBatch.mId);
/* for outbound transfer, the block point is BluetoothSocket.write()
* The only way to unblock is to tear down lower transport
* */
@@ -283,9 +263,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
} catch (IOException e) {
Log.e(TAG, "failed to close mTransport");
}
- if (Constants.LOGVV) {
- Log.v(TAG, "mTransport closed ");
- }
+ if (V) Log.v(TAG, "mTransport closed ");
} else {
/* For inbound transfer, the block point is waiting for user confirmation
* we can interrupt it nicely
@@ -310,19 +288,13 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
try {
wait(1000);
} catch (InterruptedException e) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Interrupted waiting for markBatchFailed");
- }
+ if (V) Log.v(TAG, "Interrupted waiting for markBatchFailed");
}
}
- if (Constants.LOGV) {
- Log.v(TAG, "Mark all ShareInfo in the batch as failed");
- }
+ if (D) Log.d(TAG, "Mark all ShareInfo in the batch as failed");
if (mCurrentShare != null) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Current share has status " + mCurrentShare.mStatus);
- }
+ if (V) Log.v(TAG, "Current share has status " + mCurrentShare.mStatus);
if (BluetoothShare.isStatusError(mCurrentShare.mStatus)) {
failReason = mCurrentShare.mStatus;
}
@@ -400,9 +372,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
}
if (mHandlerThread == null) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Create handler thread for batch " + mBatch.mId);
- }
+ if (V) Log.v(TAG, "Create handler thread for batch " + mBatch.mId);
mHandlerThread = new HandlerThread("BtOpp Transfer Handler",
Process.THREAD_PRIORITY_BACKGROUND);
mHandlerThread.start();
@@ -425,27 +395,19 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
* Stop the transfer
*/
public void stop() {
- if (Constants.LOGVV) {
- Log.v(TAG, "stop");
- }
+ if (V) Log.v(TAG, "stop");
if (mConnectThread != null) {
try {
mConnectThread.interrupt();
- if (Constants.LOGVV) {
- Log.v(TAG, "waiting for connect thread to terminate");
- }
+ if (V) Log.v(TAG, "waiting for connect thread to terminate");
mConnectThread.join();
} catch (InterruptedException e) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Interrupted waiting for connect thread to join");
- }
+ if (V) Log.v(TAG, "Interrupted waiting for connect thread to join");
}
mConnectThread = null;
}
if (mSession != null) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Stop mSession");
- }
+ if (V) Log.v(TAG, "Stop mSession");
mSession.stop();
}
if (mHandlerThread != null) {
@@ -467,14 +429,11 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
Log.e(TAG, "Unexpected error happened !");
return;
}
- if (Constants.LOGVV) {
- Log.v(TAG, "Start session for info " + mCurrentShare.mId + " for batch " + mBatch.mId);
- }
+ if (V) Log.v(TAG, "Start session for info " + mCurrentShare.mId + " for batch " +
+ mBatch.mId);
if (mBatch.mDirection == BluetoothShare.DIRECTION_OUTBOUND) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Create Client session with transport " + mTransport.toString());
- }
+ if (V) Log.v(TAG, "Create Client session with transport " + mTransport.toString());
mSession = new BluetoothOppObexClientSession(mContext, mTransport);
} else if (mBatch.mDirection == BluetoothShare.DIRECTION_INBOUND) {
/*
@@ -489,9 +448,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
mBatch.mStatus = Constants.BATCH_STATUS_FAILED;
return;
}
- if (Constants.LOGVV) {
- Log.v(TAG, "Transfer has Server session" + mSession.toString());
- }
+ if (V) Log.v(TAG, "Transfer has Server session" + mSession.toString());
}
mSession.start(mSessionHandler);
@@ -500,9 +457,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
private void processCurrentShare() {
/* This transfer need user confirm */
- if (Constants.LOGVV) {
- Log.v(TAG, "processCurrentShare" + mCurrentShare.mId);
- }
+ if (V) Log.v(TAG, "processCurrentShare" + mCurrentShare.mId);
mSession.addShare(mCurrentShare);
}
@@ -520,9 +475,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
}
}
};
- if (Constants.LOGVV) {
- Log.v(TAG, "setConfirmed to unblock mSession" + mSession.toString());
- }
+ if (V) Log.v(TAG, "setConfirmed to unblock mSession" + mSession.toString());
notifyThread.start();
}
@@ -535,10 +488,8 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
int channel = BluetoothOppPreference.getInstance(mContext).getChannel(
mBatch.mDestination, OPUSH_UUID16);
if (channel != -1) {
- if (Constants.LOGV) {
- Log.v(TAG, "Get OPUSH channel " + channel + " from cache for "
- + mBatch.mDestination);
- }
+ if (D) Log.d(TAG, "Get OPUSH channel " + channel + " from cache for " +
+ mBatch.mDestination);
mTimestamp = System.currentTimeMillis();
mSessionHandler.obtainMessage(SDP_RESULT, channel, -1, mBatch.mDestination)
.sendToTarget();
@@ -557,9 +508,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
};
*/
private void doOpushSdp() {
- if (Constants.LOGVV) {
- Log.v(TAG, "Do Opush SDP request for address " + mBatch.mDestination);
- }
+ if (V) Log.v(TAG, "Do Opush SDP request for address " + mBatch.mDestination);
mTimestamp = System.currentTimeMillis();
//TODO this commented code is necessary after bluez4 has good SDP API
@@ -572,18 +521,14 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
}
*/
String[] uuids = mBatch.mDestination.getUuids();
- if (Constants.LOGVV) {
- Log.v(TAG, "After call getRemoteUuids for address " + mBatch.mDestination);
- }
+ if (V) Log.v(TAG, "After call getRemoteUuids for address " + mBatch.mDestination);
String savedUuid = null;
boolean isOpush = false;
int channel = -1;
if (uuids != null) {
for (String uuid : uuids) {
UUID remoteUuid = UUID.fromString(uuid);
- if (Constants.LOGVV) {
- Log.v(TAG, "SDP UUID: remoteUuid = " + remoteUuid);
- }
+ if (V) Log.v(TAG, "SDP UUID: remoteUuid = " + remoteUuid);
if (remoteUuid.equals(OPUSH_UUID128)) {
savedUuid = uuid;
isOpush = true;
@@ -592,10 +537,8 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
}
if (isOpush) {
channel = mBatch.mDestination.getServiceChannel(savedUuid);
- if (Constants.LOGV) {
- Log.v(TAG, "Get OPUSH channel " + channel + " from SDP for "
- + mBatch.mDestination);
- }
+ if (D) Log.d(TAG, "Get OPUSH channel " + channel + " from SDP for " +
+ mBatch.mDestination);
if (channel != -1) {
mConnectThread = new SocketConnectThread(mBatch.mDestination, channel);
mConnectThread.start();
@@ -670,9 +613,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
Log.e(TAG, "TCP socket connect failed ");
}
if (s.isConnected()) {
- if (Constants.LOGV) {
- Log.v(TAG, "TCP socket connected ");
- }
+ if (D) Log.d(TAG, "TCP socket connected ");
isConnected = true;
break;
}
@@ -688,10 +629,8 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
return;
}
- if (Constants.LOGVV) {
- Log.v(TAG, "TCP Socket connection attempt took "
- + (System.currentTimeMillis() - timestamp) + " ms");
- }
+ if (V) Log.v(TAG, "TCP Socket connection attempt took " +
+ (System.currentTimeMillis() - timestamp) + " ms");
TestTcpTransport transport;
transport = new TestTcpTransport(s);
@@ -708,9 +647,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
markConnectionFailed(s);
return;
} else {
- if (Constants.LOGV) {
- Log.v(TAG, "Send transport message " + transport.toString());
- }
+ if (D) Log.d(TAG, "Send transport message " + transport.toString());
mSessionHandler.obtainMessage(RFCOMM_CONNECTED, transport).sendToTarget();
}
} else {
@@ -732,10 +669,8 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
return;
}
- if (Constants.LOGVV) {
- Log.v(TAG, "Rfcomm socket connection attempt took "
- + (System.currentTimeMillis() - timestamp) + " ms");
- }
+ if (V) Log.v(TAG, "Rfcomm socket connection attempt took " +
+ (System.currentTimeMillis() - timestamp) + " ms");
BluetoothOppRfcommTransport transport;
transport = new BluetoothOppRfcommTransport(btSocket);
@@ -743,9 +678,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
channel);
BluetoothOppPreference.getInstance(mContext).setName(device, device.getName());
- if (Constants.LOGVV) {
- Log.v(TAG, "Send transport message " + transport.toString());
- }
+ if (V) Log.v(TAG, "Send transport message " + transport.toString());
mSessionHandler.obtainMessage(RFCOMM_CONNECTED, transport).sendToTarget();
}
@@ -764,9 +697,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
try {
s.close();
} catch (IOException e) {
- if (Constants.LOGVV) {
- Log.e(TAG, "Error when close socket");
- }
+ if (V) Log.e(TAG, "Error when close socket");
}
mSessionHandler.obtainMessage(RFCOMM_ERROR).sendToTarget();
return;
@@ -801,10 +732,8 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
if (mCurrentShare != null
&& mCurrentShare.mConfirm == BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED) {
/* have additional auto confirmed share to process */
- if (Constants.LOGVV) {
- Log.v(TAG, "Transfer continue session for info " + mCurrentShare.mId
- + " from batch " + mBatch.mId);
- }
+ if (V) Log.v(TAG, "Transfer continue session for info " + mCurrentShare.mId +
+ " from batch " + mBatch.mId);
processCurrentShare();
setConfirmed();
}
@@ -829,9 +758,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
* Process when current transfer is canceled
*/
public void onBatchCanceled() {
- if (Constants.LOGVV) {
- Log.v(TAG, "Transfer on Batch canceled");
- }
+ if (V) Log.v(TAG, "Transfer on Batch canceled");
this.stop();
mBatch.mStatus = Constants.BATCH_STATUS_FINISHED;
diff --git a/src/com/android/bluetooth/opp/BluetoothOppTransferActivity.java b/src/com/android/bluetooth/opp/BluetoothOppTransferActivity.java
index 666426c11..0d600bda7 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppTransferActivity.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppTransferActivity.java
@@ -67,6 +67,8 @@ import android.text.format.Formatter;
public class BluetoothOppTransferActivity extends AlertActivity implements
DialogInterface.OnClickListener {
private static final String TAG = "BluetoothOppTransferActivity";
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
private Uri mUri;
@@ -118,9 +120,7 @@ public class BluetoothOppTransferActivity extends AlertActivity implements
@Override
public void onChange(boolean selfChange) {
- if (Constants.LOGVV) {
- Log.v(TAG, "received db changes.");
- }
+ if (V) Log.v(TAG, "received db changes.");
updateProgressbar();
}
}
@@ -134,9 +134,7 @@ public class BluetoothOppTransferActivity extends AlertActivity implements
mTransInfo = new BluetoothOppTransferInfo();
mTransInfo = BluetoothOppUtility.queryRecord(this, mUri);
if (mTransInfo == null) {
- if (Constants.LOGVV) {
- Log.e(TAG, "Error: Can not get data from db");
- }
+ if (V) Log.e(TAG, "Error: Can not get data from db");
finish();
return;
}
@@ -165,9 +163,7 @@ public class BluetoothOppTransferActivity extends AlertActivity implements
@Override
protected void onDestroy() {
- if (Constants.LOGV) {
- Log.v(TAG, "onDestroy()");
- }
+ if (D) Log.d(TAG, "onDestroy()");
if (mObserver != null) {
getContentResolver().unregisterContentObserver(mObserver);
@@ -204,10 +200,8 @@ public class BluetoothOppTransferActivity extends AlertActivity implements
}
}
- if (Constants.LOGVV) {
- Log.v(TAG, " WhichDialog/dir/isComplete/failOrSuccess" + mWhichDialog + direction
+ if (V) Log.v(TAG, " WhichDialog/dir/isComplete/failOrSuccess" + mWhichDialog + direction
+ isComplete + isSuccess);
- }
}
private void setUpDialog() {
@@ -420,9 +414,7 @@ public class BluetoothOppTransferActivity extends AlertActivity implements
private void updateProgressbar() {
mTransInfo = BluetoothOppUtility.queryRecord(this, mUri);
if (mTransInfo == null) {
- if (Constants.LOGVV) {
- Log.e(TAG, "Error: Can not get data from db");
- }
+ if (V) Log.e(TAG, "Error: Can not get data from db");
return;
}
diff --git a/src/com/android/bluetooth/opp/BluetoothOppUtility.java b/src/com/android/bluetooth/opp/BluetoothOppUtility.java
index cb17030b9..505acb5ed 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppUtility.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppUtility.java
@@ -57,6 +57,8 @@ import java.util.List;
*/
public class BluetoothOppUtility {
private static final String TAG = "BluetoothOppUtility";
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
public static BluetoothOppTransferInfo queryRecord(Context context, Uri uri) {
BluetoothAdapter adapter =
@@ -106,17 +108,13 @@ public class BluetoothOppUtility {
info.mDeviceName =
BluetoothOppManager.getInstance(context).getDeviceName(remoteDevice);
- if (Constants.LOGVV) {
- Log.v(TAG, "Get data from db:" + info.mFileName + info.mFileType
+ if (V) Log.v(TAG, "Get data from db:" + info.mFileName + info.mFileType
+ info.mDestAddr);
- }
}
cursor.close();
} else {
info = null;
- if (Constants.LOGVV) {
- Log.v(TAG, "BluetoothOppManager Error: not got data from db for uri:" + uri);
- }
+ if (V) Log.v(TAG, "BluetoothOppManager Error: not got data from db for uri:" + uri);
}
return info;
}
@@ -146,9 +144,7 @@ public class BluetoothOppUtility {
path = Uri.fromFile(new File(fileName));
}
uris.add(path.toString());
- if (Constants.LOGVV) {
- Log.d(TAG, "Uri in this batch: " + path.toString());
- }
+ if (V) Log.d(TAG, "Uri in this batch: " + path.toString());
}
metadataCursor.close();
return uris;
@@ -187,14 +183,10 @@ public class BluetoothOppUtility {
activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
- if (Constants.LOGVV) {
- Log.d(TAG, "ACTION_VIEW intent sent out: " + path + " / " + mimetype);
- }
+ if (V) Log.d(TAG, "ACTION_VIEW intent sent out: " + path + " / " + mimetype);
context.startActivity(activityIntent);
} catch (ActivityNotFoundException ex) {
- if (Constants.LOGVV) {
- Log.d(TAG, "no activity for handling ACTION_VIEW intent: " + mimetype, ex);
- }
+ if (V) Log.d(TAG, "no activity for handling ACTION_VIEW intent: " + mimetype, ex);
}
} else {
Intent in = new Intent(context, BluetoothOppBtErrorActivity.class);
@@ -212,9 +204,7 @@ public class BluetoothOppUtility {
public static boolean isRecognizedFileType(Context context, Uri fileUri, String mimetype) {
boolean ret = true;
- if (Constants.LOGV) {
- Log.v(TAG, "RecognizedFileType() fileUri: " + fileUri + " mimetype: " + mimetype);
- }
+ if (D) Log.d(TAG, "RecognizedFileType() fileUri: " + fileUri + " mimetype: " + mimetype);
Intent mimetypeIntent = new Intent(Intent.ACTION_VIEW);
mimetypeIntent.setDataAndType(fileUri, mimetype);
@@ -222,9 +212,7 @@ public class BluetoothOppUtility {
PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() == 0) {
- if (Constants.LOGV) {
- Log.v(TAG, "NO application to handle MIME type " + mimetype);
- }
+ if (D) Log.d(TAG, "NO application to handle MIME type " + mimetype);
ret = false;
}
return ret;
@@ -301,11 +289,8 @@ public class BluetoothOppUtility {
final Uri contentUri = context.getContentResolver().insert(BluetoothShare.CONTENT_URI,
values);
- if (Constants.LOGVV) {
- Log
- .v(TAG, "Insert contentUri: " + contentUri + " to device: "
- + transInfo.mDeviceName);
- }
+ if (V) Log.v(TAG, "Insert contentUri: " + contentUri + " to device: " +
+ transInfo.mDeviceName);
}
}
diff --git a/src/com/android/bluetooth/opp/Constants.java b/src/com/android/bluetooth/opp/Constants.java
index 6511b0278..0e7e9d46b 100644
--- a/src/com/android/bluetooth/opp/Constants.java
+++ b/src/com/android/bluetooth/opp/Constants.java
@@ -49,7 +49,7 @@ import android.util.Log;
*/
public class Constants {
/** Tag used for debugging/logging */
- public static final String TAG = "BluetoothShareManager";
+ public static final String TAG = "BluetoothOpp";
/**
* The intent that gets sent when the service must wake up for a retry Note:
@@ -127,17 +127,19 @@ public class Constants {
public static final String DEFAULT_STORE_SUBDIR = "/bluetooth";
/**
- * Enable verbose logging - use with
- * "setprop log.tag.BluetoothShareManager VERBOSE"
+ * Debug level logging
+ * Enable by setting system property log.tag.BluetoothOpp=DEBUG
+ * STOPSHIP: set to false
*/
- private static final boolean LOCAL_LOGV = true;
+ public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
- public static final boolean LOGV = LOCAL_LOGV && Log.isLoggable(TAG, Log.VERBOSE);
-
- /** Enable super-verbose logging */
- private static final boolean LOCAL_LOGVV = true;
-
- public static final boolean LOGVV = LOCAL_LOGVV && LOGV;
+ /**
+ * Verbose level logging
+ * Enable by setting system property log.tag.BluetoothOpp=VERBOSE
+ * This also enables debug level logging
+ * STOPSHIP: set to false
+ */
+ public static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE);
/** use TCP socket instead of Rfcomm Socket to develop */
public static final boolean USE_TCP_DEBUG = false;
diff --git a/src/com/android/bluetooth/opp/TestTcpListener.java b/src/com/android/bluetooth/opp/TestTcpListener.java
index 8fa79bac7..36266169a 100644
--- a/src/com/android/bluetooth/opp/TestTcpListener.java
+++ b/src/com/android/bluetooth/opp/TestTcpListener.java
@@ -46,7 +46,9 @@ import android.util.Log;
*/
public class TestTcpListener {
- private static final String TAG = "BtOpp RfcommListener";
+ private static final String TAG = "BtOppRfcommListener";
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
private volatile boolean mInterrupted;
@@ -77,14 +79,10 @@ public class TestTcpListener {
ServerSocket mServerSocket;
public void run() {
- if (Constants.LOGV) {
- Log.v(TAG, "RfcommSocket listen thread starting");
- }
+ if (D) Log.d(TAG, "RfcommSocket listen thread starting");
try {
- if (Constants.LOGVV) {
- Log.v(TAG, "Create server RfcommSocket on channel"
+ if (V) Log.v(TAG, "Create server RfcommSocket on channel"
+ mBtOppRfcommChannel);
- }
mServerSocket = new ServerSocket(6500, 1);
} catch (IOException e) {
Log.e(TAG, "Error listing on channel" + mBtOppRfcommChannel);
@@ -95,13 +93,9 @@ public class TestTcpListener {
mServerSocket.setSoTimeout(ACCEPT_WAIT_TIMEOUT);
Socket clientSocket = mServerSocket.accept();
if (clientSocket == null) {
- if (Constants.LOGVV) {
- Log.v(TAG, "incomming connection time out");
- }
+ if (V) Log.v(TAG, "incomming connection time out");
} else {
- if (Constants.LOGV) {
- Log.v(TAG, "RfcommSocket connected!");
- }
+ if (D) Log.d(TAG, "RfcommSocket connected!");
Log.d(TAG, "remote addr is "
+ clientSocket.getRemoteSocketAddress());
TestTcpTransport transport = new TestTcpTransport(clientSocket);
@@ -121,10 +115,8 @@ public class TestTcpListener {
Log.e(TAG, "socketAcceptThread thread was interrupted (2), exiting");
}
}
- if (Constants.LOGV) {
- Log.v(TAG, "RfcommSocket listen thread finished");
+ if (D) Log.d(TAG, "RfcommSocket listen thread finished");
}
- }
};
mInterrupted = false;
mSocketAcceptThread.start();
@@ -136,22 +128,16 @@ public class TestTcpListener {
public synchronized void stop() {
if (mSocketAcceptThread != null) {
- if (Constants.LOGV) {
- Log.v(TAG, "stopping Connect Thread");
- }
+ if (D) Log.d(TAG, "stopping Connect Thread");
mInterrupted = true;
try {
mSocketAcceptThread.interrupt();
- if (Constants.LOGVV) {
- Log.v(TAG, "waiting for thread to terminate");
- }
+ if (V) Log.v(TAG, "waiting for thread to terminate");
mSocketAcceptThread.join();
mSocketAcceptThread = null;
mCallback = null;
} catch (InterruptedException e) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Interrupted waiting for Accept Thread to join");
- }
+ if (V) Log.v(TAG, "Interrupted waiting for Accept Thread to join");
}
}
}
diff --git a/src/com/android/bluetooth/opp/TestTcpServer.java b/src/com/android/bluetooth/opp/TestTcpServer.java
index 80b9014cb..4f0496a9c 100644
--- a/src/com/android/bluetooth/opp/TestTcpServer.java
+++ b/src/com/android/bluetooth/opp/TestTcpServer.java
@@ -43,13 +43,14 @@ import javax.obex.ServerSession;
import android.util.Log;
public class TestTcpServer extends ServerRequestHandler implements Runnable {
+ private static final String TAG = "ServerRequestHandler";
+ private static final boolean D = Constants.DEBUG;
+ private static final boolean V = Constants.VERBOSE;
private long connectionID;
static final int port = 6500;
- private static final String TAG = "ServerRequestHandler";
-
public boolean a = false;
// TextView serverStatus = null;
@@ -83,9 +84,7 @@ public class TestTcpServer extends ServerRequestHandler implements Runnable {
wait(500);
}
} catch (InterruptedException e) {
- if (Constants.LOGVV) {
- Log.v(TAG, "Interrupted waiting for markBatchFailed");
- }
+ if (V) Log.v(TAG, "Interrupted waiting for markBatchFailed");
}
}
updateStatus("[server:] we accpet the seesion");