Mi Band 4/Amazfit Bip Lite: Display a toast and do not try to pair if there was no auth key supplied

This commit is contained in:
Andreas Shimokawa 2019-10-12 19:44:45 +02:00
parent 8fefd1b49e
commit 4bf37ea70f
23 changed files with 52 additions and 22 deletions

View File

@ -11,6 +11,7 @@
* Work around broken layout in database management activity * Work around broken layout in database management activity
* Show toast in case no app is installed which can handle GPX files * Show toast in case no app is installed which can handle GPX files
* Mi Band 4/Amazfit Bip Lite: Trim white spaces and new lines from auth key * Mi Band 4/Amazfit Bip Lite: Trim white spaces and new lines from auth key
* Mi Band 4/Amazfit Bip Lite: Display a toast and do not try to pair if there was no auth key supplied
#### Version 0.36.2 #### Version 0.36.2
* Amazfit Bip: Untested support for Lite variant * Amazfit Bip: Untested support for Lite variant

View File

@ -80,6 +80,7 @@ public class ConfigureAlarms extends AbstractGBActivity {
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQ_CONFIGURE_ALARM) { if (requestCode == REQ_CONFIGURE_ALARM) {
avoidSendAlarmsToDevice = false; avoidSendAlarmsToDevice = false;
updateAlarmsFromDB(); updateAlarmsFromDB();

View File

@ -35,6 +35,7 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -616,6 +617,17 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
stopDiscovery(); stopDiscovery();
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(deviceCandidate); DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(deviceCandidate);
LOG.info("Using device candidate " + deviceCandidate + " with coordinator: " + coordinator.getClass()); LOG.info("Using device candidate " + deviceCandidate + " with coordinator: " + coordinator.getClass());
if (coordinator.getBondingStyle() == DeviceCoordinator.BONDING_STYLE_REQUIRE_KEY) {
SharedPreferences sharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(deviceCandidate.getMacAddress());
String authKey = sharedPrefs.getString("authkey", null);
if (authKey == null || authKey.isEmpty() || authKey.getBytes().length < 34 || !authKey.substring(0, 2).equals("0x")) {
GB.toast(DiscoveryActivity.this, getString(R.string.discovery_need_to_enter_authkey), Toast.LENGTH_LONG, GB.WARN);
return;
}
}
Class<? extends Activity> pairingActivity = coordinator.getPairingActivity(); Class<? extends Activity> pairingActivity = coordinator.getPairingActivity();
if (pairingActivity != null) { if (pairingActivity != null) {
Intent intent = new Intent(this, pairingActivity); Intent intent = new Intent(this, pairingActivity);
@ -623,7 +635,7 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
startActivity(intent); startActivity(intent);
} else { } else {
GBDevice device = DeviceHelper.getInstance().toSupportedDevice(deviceCandidate); GBDevice device = DeviceHelper.getInstance().toSupportedDevice(deviceCandidate);
int bondingStyle = coordinator.getBondingStyle(device); int bondingStyle = coordinator.getBondingStyle();
if (bondingStyle == DeviceCoordinator.BONDING_STYLE_NONE) { if (bondingStyle == DeviceCoordinator.BONDING_STYLE_NONE) {
LOG.info("No bonding needed, according to coordinator, so connecting right away"); LOG.info("No bonding needed, according to coordinator, so connecting right away");
connectAndFinish(device); connectAndFinish(device);

View File

@ -136,7 +136,7 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
} }
@Override @Override
public int getBondingStyle(GBDevice device) { public int getBondingStyle() {
return BONDING_STYLE_ASK; return BONDING_STYLE_ASK;
} }
@ -159,6 +159,7 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
return false; return false;
} }
@NonNull
@Override @Override
public int[] getColorPresets() { public int[] getColorPresets() {
return new int[0]; return new int[0];

View File

@ -29,7 +29,6 @@ import java.util.Collection;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsFragment;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
@ -63,6 +62,11 @@ public interface DeviceCoordinator {
*/ */
int BONDING_STYLE_ASK = 2; int BONDING_STYLE_ASK = 2;
/**
* A secret key has to be entered before connecting
*/
int BONDING_STYLE_REQUIRE_KEY = 3;
/** /**
* Checks whether this coordinator handles the given candidate. * Checks whether this coordinator handles the given candidate.
* Returns the supported device type for the given candidate or * Returns the supported device type for the given candidate or
@ -224,9 +228,8 @@ public interface DeviceCoordinator {
/** /**
* Returns how/if the given device should be bonded before connecting to it. * Returns how/if the given device should be bonded before connecting to it.
* @param device
*/ */
int getBondingStyle(GBDevice device); int getBondingStyle();
/** /**
* Indicates whether the device has some kind of calender we can sync to. * Indicates whether the device has some kind of calender we can sync to.

View File

@ -93,6 +93,7 @@ public class UnknownDeviceCoordinator extends AbstractDeviceCoordinator {
sampleProvider = new UnknownSampleProvider(); sampleProvider = new UnknownSampleProvider();
} }
@NonNull
@Override @Override
public DeviceType getSupportedType(GBDeviceCandidate candidate) { public DeviceType getSupportedType(GBDeviceCandidate candidate) {
return DeviceType.UNKNOWN; return DeviceType.UNKNOWN;
@ -197,6 +198,7 @@ public class UnknownDeviceCoordinator extends AbstractDeviceCoordinator {
return false; return false;
} }
@NonNull
@Override @Override
public int[] getColorPresets() { public int[] getColorPresets() {
return new int[0]; return new int[0];

View File

@ -58,7 +58,7 @@ public class CasioGB6900DeviceCoordinator extends AbstractDeviceCoordinator {
} }
@Override @Override
public int getBondingStyle(GBDevice deviceCandidate){ public int getBondingStyle(){
return BONDING_STYLE_BOND; return BONDING_STYLE_BOND;
} }

View File

@ -84,7 +84,7 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
} }
@Override @Override
public int getBondingStyle(GBDevice deviceCandidate){ public int getBondingStyle(){
return BONDING_STYLE_NONE; return BONDING_STYLE_NONE;
} }

View File

@ -57,4 +57,9 @@ public class AmazfitBipLiteCoordinator extends AmazfitBipCoordinator {
public InstallHandler findInstallHandler(Uri uri, Context context) { public InstallHandler findInstallHandler(Uri uri, Context context) {
return null; return null;
} }
@Override
public int getBondingStyle() {
return BONDING_STYLE_REQUIRE_KEY;
}
} }

View File

@ -97,4 +97,9 @@ public class MiBand4Coordinator extends HuamiCoordinator {
R.xml.devicesettings_pairingkey R.xml.devicesettings_pairingkey
}; };
} }
@Override
public int getBondingStyle() {
return BONDING_STYLE_REQUIRE_KEY;
}
} }

View File

@ -66,7 +66,7 @@ public class ID115Coordinator extends AbstractDeviceCoordinator {
} }
@Override @Override
public int getBondingStyle(GBDevice deviceCandidate){ public int getBondingStyle(){
return BONDING_STYLE_NONE; return BONDING_STYLE_NONE;
} }

View File

@ -70,6 +70,7 @@ public class BFH16DeviceCoordinator extends AbstractDeviceCoordinator
return Collections.singletonList(filter); return Collections.singletonList(filter);
} }
@NonNull
@Override @Override
public DeviceType getSupportedType(GBDeviceCandidate candidate) { public DeviceType getSupportedType(GBDeviceCandidate candidate) {
@ -85,7 +86,7 @@ public class BFH16DeviceCoordinator extends AbstractDeviceCoordinator
} }
@Override @Override
public int getBondingStyle(GBDevice deviceCandidate){ public int getBondingStyle(){
return BONDING_STYLE_NONE; return BONDING_STYLE_NONE;
} }

View File

@ -82,7 +82,7 @@ public class TeclastH30Coordinator extends AbstractDeviceCoordinator {
} }
@Override @Override
public int getBondingStyle(GBDevice deviceCandidate){ public int getBondingStyle(){
return BONDING_STYLE_NONE; return BONDING_STYLE_NONE;
} }

View File

@ -19,7 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.makibeshr3;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
@ -162,7 +161,7 @@ public class MakibesHR3Coordinator extends AbstractDeviceCoordinator {
} }
@Override @Override
public int getBondingStyle(GBDevice deviceCandidate) { public int getBondingStyle() {
return BONDING_STYLE_NONE; return BONDING_STYLE_NONE;
} }

View File

@ -49,7 +49,7 @@ public class MijiaLywsd02Coordinator extends AbstractDeviceCoordinator {
} }
@Override @Override
public int getBondingStyle(GBDevice deviceCandidate) { public int getBondingStyle() {
return BONDING_STYLE_NONE; return BONDING_STYLE_NONE;
} }

View File

@ -85,7 +85,7 @@ public class MiScale2DeviceCoordinator extends AbstractDeviceCoordinator {
} }
@Override @Override
public int getBondingStyle(GBDevice device) { public int getBondingStyle() {
return super.BONDING_STYLE_NONE; return super.BONDING_STYLE_NONE;
} }

View File

@ -71,7 +71,7 @@ public class No1F1Coordinator extends AbstractDeviceCoordinator {
} }
@Override @Override
public int getBondingStyle(GBDevice deviceCandidate) { public int getBondingStyle() {
return BONDING_STYLE_NONE; return BONDING_STYLE_NONE;
} }

View File

@ -44,7 +44,7 @@ public abstract class RoidmiCoordinator extends AbstractDeviceCoordinator {
} }
@Override @Override
public int getBondingStyle(GBDevice device) { public int getBondingStyle() {
return BONDING_STYLE_BOND; return BONDING_STYLE_BOND;
} }
@ -133,6 +133,7 @@ public abstract class RoidmiCoordinator extends AbstractDeviceCoordinator {
return true; return true;
} }
@NonNull
@Override @Override
public int[] getColorPresets() { public int[] getColorPresets() {
return RoidmiConst.COLOR_PRESETS; return RoidmiConst.COLOR_PRESETS;

View File

@ -77,7 +77,7 @@ public class Watch9DeviceCoordinator extends AbstractDeviceCoordinator {
} }
@Override @Override
public int getBondingStyle(GBDevice deviceCandidate) { public int getBondingStyle() {
return BONDING_STYLE_NONE; return BONDING_STYLE_NONE;
} }

View File

@ -153,7 +153,7 @@ public class ZeTimeCoordinator extends AbstractDeviceCoordinator {
} }
@Override @Override
public int getBondingStyle(GBDevice device) { public int getBondingStyle() {
return BONDING_STYLE_NONE; return BONDING_STYLE_NONE;
} }

View File

@ -61,7 +61,7 @@ public class BluetoothPairingRequestReceiver extends BroadcastReceiver {
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice); DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice);
try { try {
if (coordinator.getBondingStyle(gbDevice) == DeviceCoordinator.BONDING_STYLE_NONE) { if (coordinator.getBondingStyle() == DeviceCoordinator.BONDING_STYLE_NONE) {
LOG.info("Aborting unwanted pairing request"); LOG.info("Aborting unwanted pairing request");
abortBroadcast(); abortBroadcast();
} }

View File

@ -20,8 +20,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
import java.io.IOException;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
public class AmazfitBipLiteSupport extends AmazfitBipSupport { public class AmazfitBipLiteSupport extends AmazfitBipSupport {
@ -37,7 +35,7 @@ public class AmazfitBipLiteSupport extends AmazfitBipSupport {
} }
@Override @Override
public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException { public HuamiFWHelper createFWHelper(Uri uri, Context context) {
return null; return null;
} }
} }

View File

@ -300,6 +300,7 @@
<string name="miband_pairing_tap_hint">When your Mi Band vibrates and blinks, tap it a few times in a row.</string> <string name="miband_pairing_tap_hint">When your Mi Band vibrates and blinks, tap it a few times in a row.</string>
<string name="appinstaller_install">Install</string> <string name="appinstaller_install">Install</string>
<string name="discovery_connected_devices_hint">Make your device discoverable. Currently connected devices will likely not be discovered. Activate location (e.g. GPS) on Android 6+. Disable Privacy Guard for Gadgetbridge, because it may crash and reboot your phone. If no device is found after a few minutes, try again after rebooting your mobile device.</string> <string name="discovery_connected_devices_hint">Make your device discoverable. Currently connected devices will likely not be discovered. Activate location (e.g. GPS) on Android 6+. Disable Privacy Guard for Gadgetbridge, because it may crash and reboot your phone. If no device is found after a few minutes, try again after rebooting your mobile device.</string>
<string name="discovery_need_to_enter_authkey">This device needs a secret auth key, long press on the device to enter it. Read the wiki.</string>
<string name="discovery_note">Note:</string> <string name="discovery_note">Note:</string>
<string name="candidate_item_device_image">Device image</string> <string name="candidate_item_device_image">Device image</string>
<string name="miband_prefs_alias">Name/Alias</string> <string name="miband_prefs_alias">Name/Alias</string>