diff options
Diffstat (limited to 'src')
8 files changed, 86 insertions, 85 deletions
diff --git a/src/com/android/bluetooth/btservice/AdapterService.java b/src/com/android/bluetooth/btservice/AdapterService.java index ca2ff19c7..7567442a7 100644 --- a/src/com/android/bluetooth/btservice/AdapterService.java +++ b/src/com/android/bluetooth/btservice/AdapterService.java @@ -509,6 +509,8 @@ public class AdapterService extends Service { private static final int MESSAGE_PROFILE_CONNECTION_STATE_CHANGED=20; private static final int MESSAGE_CONNECT_OTHER_PROFILES = 30; private static final int MESSAGE_PROFILE_INIT_PRIORITIES=40; + private static final int MESSAGE_SET_WAKE_ALARM = 100; + private static final int MESSAGE_RELEASE_WAKE_ALARM = 110; private static final int CONNECT_OTHER_PROFILES_TIMEOUT= 6000; private final Handler mHandler = new Handler() { @@ -542,6 +544,17 @@ public class AdapterService extends Service { processConnectOtherProfiles((BluetoothDevice) msg.obj,msg.arg1); } break; + case MESSAGE_SET_WAKE_ALARM: { + debugLog( "handleMessage() - MESSAGE_SET_WAKE_ALARM"); + processSetWakeAlarm((Long) msg.obj, msg.arg1); + } + break; + case MESSAGE_RELEASE_WAKE_ALARM: { + debugLog( "handleMessage() - MESSAGE_RELEASE_WAKE_ALARM"); + mPendingAlarm = null; + alarmFiredNative(); + } + break; } } }; @@ -1755,24 +1768,30 @@ public class AdapterService extends Service { } // This function is called from JNI. It allows native code to set a single wake - // alarm. If an alarm is already pending and a new request comes in, the alarm - // will be rescheduled (i.e. the previously set alarm will be cancelled). + // alarm. private boolean setWakeAlarm(long delayMillis, boolean shouldWake) { - synchronized (this) { - if (mPendingAlarm != null) { - mAlarmManager.cancel(mPendingAlarm); - } + Message m = mHandler.obtainMessage(MESSAGE_SET_WAKE_ALARM); + m.obj = new Long(delayMillis); + // alarm type + m.arg1 = shouldWake ? AlarmManager.ELAPSED_REALTIME_WAKEUP + : AlarmManager.ELAPSED_REALTIME; + mHandler.sendMessage(m); - long wakeupTime = SystemClock.elapsedRealtime() + delayMillis; - int type = shouldWake - ? AlarmManager.ELAPSED_REALTIME_WAKEUP - : AlarmManager.ELAPSED_REALTIME; + return true; + } - Intent intent = new Intent(ACTION_ALARM_WAKEUP); - mPendingAlarm = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); - mAlarmManager.setExact(type, wakeupTime, mPendingAlarm); - return true; + // If an alarm is already pending and a new request comes in, the alarm + // will be rescheduled (i.e. the previously set alarm will be cancelled). + private void processSetWakeAlarm(long delayMillis, int alarmType) { + if (mPendingAlarm != null) { + mAlarmManager.cancel(mPendingAlarm); } + + long wakeupTime = SystemClock.elapsedRealtime() + delayMillis; + + Intent intent = new Intent(ACTION_ALARM_WAKEUP); + mPendingAlarm = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); + mAlarmManager.setExact(alarmType, wakeupTime, mPendingAlarm); } // This function is called from JNI. It allows native code to acquire a single wake lock. @@ -1850,10 +1869,7 @@ public class AdapterService extends Service { private final BroadcastReceiver mAlarmBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - synchronized (AdapterService.this) { - mPendingAlarm = null; - alarmFiredNative(); - } + mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_RELEASE_WAKE_ALARM)); } }; diff --git a/src/com/android/bluetooth/gatt/ContextMap.java b/src/com/android/bluetooth/gatt/ContextMap.java index 65f8dce89..bdb82b5d8 100644 --- a/src/com/android/bluetooth/gatt/ContextMap.java +++ b/src/com/android/bluetooth/gatt/ContextMap.java @@ -291,28 +291,23 @@ import java.util.UUID; /** * Logs debug information. */ - void dump() { - StringBuilder b = new StringBuilder(); - b.append( "-------------- GATT Context Map ----------------"); - b.append("\nEntries: " + mApps.size()); + void dump(StringBuilder sb) { + sb.append(" Entries: " + mApps.size() + "\n"); Iterator<App> i = mApps.iterator(); while(i.hasNext()) { App entry = i.next(); List<Connection> connections = getConnectionByApp(entry.id); - b.append("\n\nApplication Id: " + entry.id); - b.append("\nUUID: " + entry.uuid); - b.append("\nConnections: " + connections.size()); + sb.append("\n Application Id: " + entry.id + "\n"); + sb.append(" UUID: " + entry.uuid + "\n"); + sb.append(" Connections: " + connections.size() + "\n"); Iterator<Connection> ii = connections.iterator(); while(ii.hasNext()) { Connection connection = ii.next(); - b.append("\n " + connection.connId + ": " + connection.address); + sb.append(" " + connection.connId + ": " + connection.address + "\n"); } } - - b.append("\n------------------------------------------------"); - Log.d(TAG, b.toString()); } } diff --git a/src/com/android/bluetooth/gatt/GattDebugUtils.java b/src/com/android/bluetooth/gatt/GattDebugUtils.java index 5c42db6a2..a1b37a2ba 100644 --- a/src/com/android/bluetooth/gatt/GattDebugUtils.java +++ b/src/com/android/bluetooth/gatt/GattDebugUtils.java @@ -28,13 +28,6 @@ import java.util.UUID; private static final String TAG = GattServiceConfig.TAG_PREFIX + "DebugUtils"; private static final boolean DEBUG_ADMIN = GattServiceConfig.DEBUG_ADMIN; - private static final String ACTION_DEBUG_DUMP_CLIENTMAP = - "android.bluetooth.action.DEBUG_DUMP_CLIENTMAP"; - private static final String ACTION_DEBUG_DUMP_SERVERMAP = - "android.bluetooth.action.DEBUG_DUMP_SERVERMAP"; - private static final String ACTION_DEBUG_DUMP_HANDLEMAP = - "android.bluetooth.action.DEBUG_DUMP_HANDLEMAP"; - private static final String ACTION_GATT_PAIRING_CONFIG = "android.bluetooth.action.GATT_PAIRING_CONFIG"; @@ -82,23 +75,10 @@ import java.util.UUID; Log.d(TAG, "handleDebugAction() action=" + action); /* - * Debug log functinos - */ - - if (ACTION_DEBUG_DUMP_CLIENTMAP.equals(action)) { - svc.mClientMap.dump(); - - } else if (ACTION_DEBUG_DUMP_SERVERMAP.equals(action)) { - svc.mServerMap.dump(); - - } else if (ACTION_DEBUG_DUMP_HANDLEMAP.equals(action)) { - svc.mHandleMap.dump(); - - /* * PTS test commands */ - } else if (ACTION_GATT_TEST_USAGE.equals(action)) { + if (ACTION_GATT_TEST_USAGE.equals(action)) { logUsageInfo(); } else if (ACTION_GATT_TEST_ENABLE.equals(action)) { diff --git a/src/com/android/bluetooth/gatt/GattService.java b/src/com/android/bluetooth/gatt/GattService.java index f67daf8a6..9347b24a7 100644 --- a/src/com/android/bluetooth/gatt/GattService.java +++ b/src/com/android/bluetooth/gatt/GattService.java @@ -1688,9 +1688,6 @@ public class GattService extends ProfileService { HandleMap.Entry entry = mHandleMap.getByHandle(attrHandle); if (entry == null) return; - if (DBG) Log.d(TAG, "onAttributeRead() UUID=" + entry.uuid - + ", serverIf=" + entry.serverIf + ", type=" + entry.type); - mHandleMap.addRequest(transId, attrHandle); ServerMap.App app = mServerMap.getById(entry.serverIf); @@ -1738,9 +1735,6 @@ public class GattService extends ProfileService { HandleMap.Entry entry = mHandleMap.getByHandle(attrHandle); if (entry == null) return; - if (DBG) Log.d(TAG, "onAttributeWrite() UUID=" + entry.uuid - + ", serverIf=" + entry.serverIf + ", type=" + entry.type); - mHandleMap.addRequest(transId, attrHandle); ServerMap.App app = mServerMap.getById(entry.serverIf); @@ -1793,7 +1787,7 @@ public class GattService extends ProfileService { } void onNotificationSent(int connId, int status) throws RemoteException { - if (DBG) Log.d(TAG, "onNotificationSent() connId=" + connId + ", status=" + status); + if (VDBG) Log.d(TAG, "onNotificationSent() connId=" + connId + ", status=" + status); String address = mServerMap.addressByConnId(connId); if (address == null) return; @@ -1825,6 +1819,18 @@ public class GattService extends ProfileService { } } + void onMtuChanged(int connId, int mtu) throws RemoteException { + if (DBG) Log.d(TAG, "onMtuChanged() - connId=" + connId + ", mtu=" + mtu); + + String address = mServerMap.addressByConnId(connId); + if (address == null) return; + + ServerMap.App app = mServerMap.getByConnId(connId); + if (app == null) return; + + app.callback.onMtuChanged(address, mtu); + } + /************************************************************************** * GATT Service functions - SERVER *************************************************************************/ @@ -2197,6 +2203,15 @@ public class GattService extends ProfileService { println(sb, " " + declaration); } println(sb, "mMaxScanFilters: " + mMaxScanFilters); + + sb.append("\nGATT Client Map\n"); + mClientMap.dump(sb); + + sb.append("\nGATT Server Map\n"); + mServerMap.dump(sb); + + sb.append("\nGATT Handle Map\n"); + mHandleMap.dump(sb); } /************************************************************************** diff --git a/src/com/android/bluetooth/gatt/HandleMap.java b/src/com/android/bluetooth/gatt/HandleMap.java index 187625a43..4a2063984 100644 --- a/src/com/android/bluetooth/gatt/HandleMap.java +++ b/src/com/android/bluetooth/gatt/HandleMap.java @@ -196,31 +196,28 @@ class HandleMap { /** * Logs debug information. */ - void dump() { - StringBuilder b = new StringBuilder(); - b.append( "-------------- GATT Handle Map -----------------"); - b.append("\nEntries: " + mEntries.size()); - b.append("\nRequests: " + mRequestMap.size()); + void dump(StringBuilder sb) { + sb.append(" Entries: " + mEntries.size() + "\n"); + sb.append(" Requests: " + mRequestMap.size() + "\n"); for (Entry entry : mEntries) { - b.append("\n" + entry.serverIf + ": [" + entry.handle + "] "); + sb.append(" " + entry.serverIf + ": [" + entry.handle + "] "); switch(entry.type) { case TYPE_SERVICE: - b.append("Service " + entry.uuid); - b.append(", started " + entry.started); + sb.append("Service " + entry.uuid); + sb.append(", started " + entry.started); break; case TYPE_CHARACTERISTIC: - b.append(" Characteristic " + entry.uuid); + sb.append(" Characteristic " + entry.uuid); break; case TYPE_DESCRIPTOR: - b.append(" Descriptor " + entry.uuid); + sb.append(" Descriptor " + entry.uuid); break; } - } - b.append("\n------------------------------------------------"); - Log.d(TAG, b.toString()); + sb.append("\n"); + } } } diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java index 5bd54af36..bf6a6fa02 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java +++ b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java @@ -276,7 +276,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen boolean needConfirm = true; /** It's not first put if !serverBlocking, so we auto accept it */ - if (!mServerBlocking) { + if (!mServerBlocking && mAccepted == BluetoothShare.USER_CONFIRMATION_CONFIRMED) { values.put(BluetoothShare.USER_CONFIRMATION, BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED); needConfirm = false; diff --git a/src/com/android/bluetooth/opp/BluetoothOppService.java b/src/com/android/bluetooth/opp/BluetoothOppService.java index 9b8a5f4c8..f952beca3 100755 --- a/src/com/android/bluetooth/opp/BluetoothOppService.java +++ b/src/com/android/bluetooth/opp/BluetoothOppService.java @@ -704,7 +704,7 @@ public class BluetoothOppService extends Service { info.mDestination = stringFromCursor(info.mDestination, cursor, BluetoothShare.DESTINATION); int newVisibility = cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare.VISIBILITY)); - boolean confirmed = false; + boolean confirmUpdated = false; int newConfirm = cursor.getInt(cursor .getColumnIndexOrThrow(BluetoothShare.USER_CONFIRMATION)); @@ -717,10 +717,8 @@ public class BluetoothOppService extends Service { info.mVisibility = newVisibility; if (info.mConfirm == BluetoothShare.USER_CONFIRMATION_PENDING - && (newConfirm == BluetoothShare.USER_CONFIRMATION_CONFIRMED || - newConfirm == BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED || - newConfirm == BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED)) { - confirmed = true; + && newConfirm != BluetoothShare.USER_CONFIRMATION_PENDING) { + confirmUpdated = true; } info.mConfirm = cursor.getInt(cursor .getColumnIndexOrThrow(BluetoothShare.USER_CONFIRMATION)); @@ -738,14 +736,14 @@ public class BluetoothOppService extends Service { info.mTimestamp = cursor.getInt(cursor.getColumnIndexOrThrow(BluetoothShare.TIMESTAMP)); info.mMediaScanned = (cursor.getInt(cursor.getColumnIndexOrThrow(Constants.MEDIA_SCANNED)) != Constants.MEDIA_SCANNED_NOT_SCANNED); - if (confirmed) { - if (V) Log.v(TAG, "Service handle info " + info.mId + " confirmed"); - /* Inbounds transfer get user confirmation, so we start it */ + if (confirmUpdated) { + if (V) Log.v(TAG, "Service handle info " + info.mId + " confirmation updated"); + /* Inbounds transfer user confirmation status changed, update the session server */ int i = findBatchWithTimeStamp(info.mTimestamp); if (i != -1) { BluetoothOppBatch batch = mBatchs.get(i); if (mServerTransfer != null && batch.mId == mServerTransfer.getBatchId()) { - mServerTransfer.setConfirmed(); + mServerTransfer.confirmStatusChanged(); } //TODO need to think about else } } @@ -872,7 +870,7 @@ public class BluetoothOppService extends Service { mServerTransfer.start(); if (nextBatch.getPendingShare().mConfirm == BluetoothShare.USER_CONFIRMATION_CONFIRMED) { - mServerTransfer.setConfirmed(); + mServerTransfer.confirmStatusChanged(); } return; } diff --git a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java index 2dbed4992..6c883d2ae 100755 --- a/src/com/android/bluetooth/opp/BluetoothOppTransfer.java +++ b/src/com/android/bluetooth/opp/BluetoothOppTransfer.java @@ -462,7 +462,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch if (V) Log.v(TAG, "processCurrentShare" + mCurrentShare.mId); mSession.addShare(mCurrentShare); if (mCurrentShare.mConfirm == BluetoothShare.USER_CONFIRMATION_HANDOVER_CONFIRMED) { - setConfirmed(); + confirmStatusChanged(); } } @@ -470,7 +470,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch * Set transfer confirmed status. It should only be called for inbound * transfer */ - public void setConfirmed() { + public void confirmStatusChanged() { /* unblock server session */ final Thread notifyThread = new Thread("Server Unblock thread") { public void run() { @@ -480,7 +480,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch } } }; - if (V) Log.v(TAG, "setConfirmed to unblock mSession" + mSession.toString()); + if (V) Log.v(TAG, "confirmStatusChanged to unblock mSession" + mSession.toString()); notifyThread.start(); } @@ -711,7 +711,7 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch if (V) Log.v(TAG, "Transfer continue session for info " + mCurrentShare.mId + " from batch " + mBatch.mId); processCurrentShare(); - setConfirmed(); + confirmStatusChanged(); } } } |