android/connectivity-samples

Logic error in bit test operations in file DeviceControlActivity.java

billsims opened this issue · 0 comments

There are tests in lines 129 and 139 of DeviceControlActivity.java to see if specific bits in the int charaProp are set. The tests are written using the bitwise OR (|) operator. As written the tests will always be true independent of the value of charaProp as the values being or'ed with (i.e. PROPERTY_READ and PROPERTY_NOTIFY) are non-zero constants. To have the tests operate properly, the variable should be tested using the bitwise AND (&) operator in place of the or operator which will yield a true result only if the specific bit being tested is a one in charaProp.