Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #75 from g-ortuno/read-write-lock-errors
Browse files Browse the repository at this point in the history
Read write lock errors
  • Loading branch information
schilit committed Dec 2, 2014
2 parents 4d94f1b + 470ddff commit 63c2b81
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

public class ConfigUriBeacon extends UriBeacon {
private static final String TAG = ConfigUriBeacon.class.getCanonicalName();
// This error should be defined in the BluetoothGatt library but it isn't.
public static final int INSUFFICIENT_AUTHORIZATION = 8;
public static final int PERIOD_NONE = -1;
public static final byte POWER_MODE_NONE = -1;
public static final byte POWER_MODE_ULTRA_LOW = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,44 @@ public class ConfigActivity extends Activity implements PasswordDialogFragment.P
private final UriBeaconCallback mUriBeaconCallback = new UriBeaconCallback() {
@Override
public void onUriBeaconRead(ConfigUriBeacon configUriBeacon, int status) {
checkRequest(status);
updateInputFields(configUriBeacon);
if (status == BluetoothGatt.GATT_SUCCESS) {
updateInputFields(configUriBeacon);
} else if (status == BluetoothGatt.GATT_FAILURE) {
Toast.makeText(ConfigActivity.this, R.string.failed_to_read, Toast.LENGTH_SHORT).show();
finish();
} else {
Toast.makeText(ConfigActivity.this, getString(R.string.failed_with_code) + status, Toast.LENGTH_SHORT).show();
finish();
}
}

@Override
public void onUriBeaconWrite(int status) {
checkRequest(status);
mUriBeaconConfig.closeUriBeacon();
finish();
}

private void checkRequest(int status) {
if (status == BluetoothGatt.GATT_FAILURE) {
Toast.makeText(ConfigActivity.this, "Failed to update the beacon", Toast.LENGTH_SHORT)
.show();
if (status == BluetoothGatt.GATT_SUCCESS) {
mUriBeaconConfig.closeUriBeacon();
finish();
} else if (status == BluetoothGatt.GATT_FAILURE) {
Toast.makeText(ConfigActivity.this, R.string.failed_to_write, Toast.LENGTH_SHORT).show();
} else if (status == ConfigUriBeacon.INSUFFICIENT_AUTHORIZATION) {
Toast.makeText(ConfigActivity.this, R.string.wrong_password, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(ConfigActivity.this, getString(R.string.failed_with_code) + status, Toast.LENGTH_SHORT).show();
}
enableUi(true);
}
};

private void blockUi() {
mSchema.setEnabled(false);
mUriValue.setEnabled(false);
mFlagsValue.setEnabled(false);
private void enableUi(boolean block) {
mSchema.setEnabled(block);
mUriValue.setEnabled(block);
mFlagsValue.setEnabled(block);
for (EditText txCal : mAdvertisedTxPowerLevels) {
txCal.setEnabled(false);
txCal.setEnabled(block);
}
mTxPowerMode.setEnabled(false);
mBeaconPeriod.setEnabled(false);
mLockState.setEnabled(false);
mTxPowerMode.setEnabled(block);
mBeaconPeriod.setEnabled(block);
mLockState.setEnabled(block);
}

public void saveConfigBeacon(MenuItem menu) {
try {
if (mUriBeaconConfig.getVersion().equals(ProtocolV2.CONFIG_SERVICE_UUID)) {
Expand All @@ -114,7 +120,7 @@ public void saveConfigBeacon(MenuItem menu) {
}
}
else {
blockUi();
enableUi(false);
ConfigUriBeacon configUriBeacon = new ConfigUriBeacon.Builder()
.uriString(getUri())
.txPowerLevel(DEFAULT_TX_POWER)
Expand All @@ -136,6 +142,7 @@ public void onResetClicked(MenuItem menu) {
}
private void resetConfigBeacon(byte[] key) {
try {
enableUi(false);
ConfigUriBeacon configUriBeacon = new ConfigUriBeacon.Builder()
.key(key)
.reset(true)
Expand All @@ -146,7 +153,7 @@ private void resetConfigBeacon(byte[] key) {
}
}
private void writeUriBeaconV2(byte[] key) throws URISyntaxException {
blockUi();
enableUi(false);
ConfigUriBeacon.Builder builder = new ConfigUriBeacon.Builder()
.key(key)
.lockState(mLockState.isChecked())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@
<string name="reset_failed">Could not reset UriBeacon to its default values</string>
<string name="no_password">Please enter a password</string>
<string name="password_missmatch">Passwords don\'t match</string>
<string name="failed_to_read">Failed to read beacon</string>
<string name="failed_with_code">Failed with code:</string>
<string name="wrong_password">Wrong password please try again...</string>
<string name="failed_to_write">Failed to update beacon</string>
</resources>

0 comments on commit 63c2b81

Please sign in to comment.