1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 12:56:49 +01:00

Huami: Change default find band vibration pattern

The previous one was too long, now that we loop it.

This one should be a sane default, even for devices that do not support
it (eg. Bip), as the total time is 1.5s.
This commit is contained in:
José Rebelo 2022-09-26 18:20:12 +01:00
parent 2df6ce2aed
commit 43b43ab742
4 changed files with 42 additions and 16 deletions

View File

@ -114,7 +114,7 @@ public class GBApplication extends Application {
private static SharedPreferences sharedPrefs;
private static final String PREFS_VERSION = "shared_preferences_version";
//if preferences have to be migrated, increment the following and add the migration logic in migratePrefs below; see http://stackoverflow.com/questions/16397848/how-can-i-migrate-android-preferences-with-a-new-version
private static final int CURRENT_PREFS_VERSION = 17;
private static final int CURRENT_PREFS_VERSION = 18;
private static LimitedQueue mIDSenderLookup = new LimitedQueue(16);
private static Prefs prefs;
@ -1156,6 +1156,30 @@ public class GBApplication extends Application {
editor.remove(GBPrefs.CALENDAR_BLACKLIST);
}
if (oldVersion < 18) {
// Migrate the default value for Huami find band vibration pattern
try (DBHandler db = acquireDB()) {
final DaoSession daoSession = db.getDaoSession();
final List<Device> activeDevices = DBHelper.getActiveDevices(daoSession);
for (Device dbDevice : activeDevices) {
if (!dbDevice.getManufacturer().equals("Huami")) {
continue;
}
final SharedPreferences deviceSharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(dbDevice.getIdentifier());
final SharedPreferences.Editor deviceSharedPrefsEdit = deviceSharedPrefs.edit();
deviceSharedPrefsEdit.putString("huami_vibration_profile_find_band", "long");
deviceSharedPrefsEdit.putString("huami_vibration_count_find_band", "1");
deviceSharedPrefsEdit.apply();
}
} catch (Exception e) {
Log.w(TAG, "error acquiring DB lock");
}
}
editor.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION));
editor.apply();
}

View File

@ -197,7 +197,7 @@ public abstract class Huami2021Support extends HuamiSupport {
public void onTestNewFunction() {
try {
final TransactionBuilder builder = performInitialized("test");
findBandOneShot(builder);
builder.queue(getQueue());
} catch (final Exception e) {
LOG.error("Failed to test new function", e);
@ -213,19 +213,21 @@ public abstract class Huami2021Support extends HuamiSupport {
writeToChunked2021("ack find phone", CHUNKED2021_ENDPOINT_FIND_DEVICE, cmd, true);
}
protected void findBandOneShot(final TransactionBuilder builder) {
@Override
protected void sendFindDeviceCommand(boolean start) {
if (!start) {
return;
}
LOG.info("Sending one-shot find band");
writeToChunked2021(builder, CHUNKED2021_ENDPOINT_FIND_DEVICE, new byte[]{FIND_BAND_ONESHOT}, true);
}
@Override
public void onFindDevice(final boolean start) {
// FIXME: This does not work while band is in DND (#752)
final CallSpec callSpec = new CallSpec();
callSpec.command = start ? CallSpec.CALL_INCOMING : CallSpec.CALL_END;
callSpec.name = "Gadgetbridge";
onSetCallState(callSpec);
try {
final TransactionBuilder builder = performInitialized("find huami 2021");
writeToChunked2021(builder, CHUNKED2021_ENDPOINT_FIND_DEVICE, new byte[]{FIND_BAND_ONESHOT}, true);
builder.queue(getQueue());
} catch (IOException e) {
LOG.error("error while sending find Huami 2021 device command", e);
}
}
@Override

View File

@ -1598,7 +1598,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
return findDeviceInterval;
}
private void sendFindDeviceCommand(boolean start) {
protected void sendFindDeviceCommand(boolean start) {
BluetoothGattCharacteristic characteristic = getCharacteristic(UUID_CHARACTERISTIC_ALERT_LEVEL);
try {
TransactionBuilder builder = performInitialized("find huami");

View File

@ -229,7 +229,7 @@
<PreferenceCategory android:title="@string/pref_screen_notification_profile_find_device" />
<ListPreference
android:defaultValue="@string/p_ring"
android:defaultValue="@string/p_long"
android:entries="@array/vibration_profile"
android:entryValues="@array/vibration_profile_values"
android:key="huami_vibration_profile_find_band"
@ -237,7 +237,7 @@
android:summary="%s" />
<EditTextPreference
android:defaultValue="3"
android:defaultValue="1"
android:inputType="number"
android:key="huami_vibration_count_find_band"
android:maxLength="1"