Skip to content

Commit

Permalink
Merge pull request google#830 from cco3/soterfindbugs
Browse files Browse the repository at this point in the history
Fix findbugs errors
  • Loading branch information
cco3 authored Sep 19, 2016
2 parents 1872553 + 2cf0cf2 commit 2093759
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
8 changes: 8 additions & 0 deletions android/PhysicalWeb/app/config/findbugs/exclude-filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@
<Match>
<Class name="org.physical_web.physicalweb.ble.ScanRecord"/>
</Match>
<Match>
<Class name="org.physical_web.demos.FatBeaconHelloWorld"/>
<Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD"/>
</Match>
<Match>
<Class name="org.physical_web.demos.WifiDirectHelloWorld"/>
<Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD"/>
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.UUID;

/**
Expand Down Expand Up @@ -116,7 +117,7 @@ public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic
&& characteristic.getValue().length < transferRate) {
Log.i(TAG, "onCharacteristicRead successful: small packet");
// Transfer is complete
html.append(new String(characteristic.getValue()));
html.append(new String(characteristic.getValue(), Charset.forName("UTF-8")));
close();
File websiteDir = new File(activity.getFilesDir(), "Websites");
websiteDir.mkdir();
Expand All @@ -128,7 +129,7 @@ public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic
} else if (status == BluetoothGatt.GATT_SUCCESS) {
Log.i(TAG, "onCharacteristicRead successful: full packet");
// Full packet received, check for more data
html.append(new String(characteristic.getValue()));
html.append(new String(characteristic.getValue(), Charset.forName("UTF-8")));
gatt.readCharacteristic(this.characteristic);
} else {
Log.i(TAG, "onCharacteristicRead unsuccessful: " + status);
Expand Down Expand Up @@ -208,7 +209,7 @@ private void writeToFile(File file) {
try {
outputStream = new FileOutputStream(file);
try {
outputStream.write(html.toString().getBytes());
outputStream.write(html.toString().getBytes("UTF-8"));
} catch (IOException e) {
Log.e(TAG, "Failed to write to file");
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import android.widget.Toast;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.UUID;

Expand Down Expand Up @@ -253,12 +254,17 @@ public void onStartFailure(int result) {

// Broadcast via bluetooth the stored URL
private void broadcastUrl() {
final AdvertiseData advertisementData = AdvertiseDataUtils
.getFatBeaconAdvertisementData(mDisplayInfo.getBytes());
final AdvertiseSettings advertiseSettings = AdvertiseDataUtils.getAdvertiseSettings(true);
byte[] bytes = null;
try {
bytes = mDisplayInfo.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Could not encode URL", e);
return;
}
AdvertiseData advertiseData = AdvertiseDataUtils.getFatBeaconAdvertisementData(bytes);
AdvertiseSettings advertiseSettings = AdvertiseDataUtils.getAdvertiseSettings(true);
mBluetoothLeAdvertiser.stopAdvertising(mAdvertiseCallback);
mBluetoothLeAdvertiser.startAdvertising(advertiseSettings,
advertisementData, mAdvertiseCallback);
mBluetoothLeAdvertiser.startAdvertising(advertiseSettings, advertiseData, mAdvertiseCallback);
}

// Turn off URL broadcasting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ public void onStartFailure(int result) {

// Broadcast via bluetooth the stored URL
private void broadcastUrl() {
Log.d(TAG, "broadcastUrl: " + mShareUrl);
final AdvertiseData advertisementData = AdvertiseDataUtils.getAdvertisementData(mShareUrl);
final AdvertiseSettings advertiseSettings = AdvertiseDataUtils.getAdvertiseSettings(false);
mBluetoothLeAdvertiser.stopAdvertising(mAdvertiseCallback);
Expand Down

0 comments on commit 2093759

Please sign in to comment.