-
Notifications
You must be signed in to change notification settings - Fork 576
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed default payload size when a non-standard MTU was negotiated.
Summary: #161 Reviewers: pawel.urban Reviewed By: pawel.urban Differential Revision: https://phabricator.polidea.com/D2286
- Loading branch information
1 parent
30e8258
commit 88ee8c5
Showing
10 changed files
with
113 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
rxandroidble/src/main/java/com/polidea/rxandroidble/internal/connection/IntProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.polidea.rxandroidble.internal.connection; | ||
|
||
|
||
import android.support.annotation.RestrictTo; | ||
|
||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
public interface IntProvider { | ||
|
||
int getValue(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...c/main/java/com/polidea/rxandroidble/internal/connection/MaxWritePayloadSizeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.polidea.rxandroidble.internal.connection; | ||
|
||
|
||
import android.support.annotation.RestrictTo; | ||
|
||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
class MaxWritePayloadSizeProvider implements IntProvider { | ||
|
||
private final IntProvider mtuProvider; | ||
private final int gattWriteMtuOverhead; | ||
|
||
MaxWritePayloadSizeProvider(IntProvider mtuProvider, int gattWriteMtuOverhead) { | ||
this.mtuProvider = mtuProvider; | ||
this.gattWriteMtuOverhead = gattWriteMtuOverhead; | ||
} | ||
|
||
@Override | ||
public int getValue() { | ||
return mtuProvider.getValue() - gattWriteMtuOverhead; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...roovy/com/polidea/rxandroidble/internal/connection/MaxWritePayloadSizeProviderTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.polidea.rxandroidble.internal.connection | ||
|
||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
|
||
class MaxWritePayloadSizeProviderTest extends Specification { | ||
|
||
def mockMtuProvider = Mock IntProvider | ||
|
||
MaxWritePayloadSizeProvider objectUnderTest | ||
|
||
private void prepareObjectUnderTest(int gattWriteMtuOverhead) { | ||
objectUnderTest = new MaxWritePayloadSizeProvider(mockMtuProvider, gattWriteMtuOverhead) | ||
} | ||
|
||
@Unroll | ||
def "should return current MTU decreased by the write MTU overhead"() { | ||
|
||
given: | ||
prepareObjectUnderTest(gattWriteMtuOverhead) | ||
mockMtuProvider.getValue() >> currentMtu | ||
|
||
expect: | ||
objectUnderTest.getValue() == expectedValue | ||
|
||
where: | ||
currentMtu | gattWriteMtuOverhead | expectedValue | ||
10 | 2 | 8 | ||
2000 | 32 | 1968 | ||
} | ||
} |