From 28a3ab151819db1ce7f3c2217c8acdcce1f679aa Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Sun, 16 Aug 2020 22:50:03 +0200 Subject: [PATCH] Huami: save raw summary data in new binary blob column for later interpretation --- .../gadgetbridge/daogen/GBDaoGenerator.java | 3 +- .../schema/GadgetbridgeUpdate_30.java | 38 +++++++++++++++++++ .../FetchSportsSummaryOperation.java | 1 + build.gradle | 2 +- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/GadgetbridgeUpdate_30.java diff --git a/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java b/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java index 53707c79b..ff9fe81a6 100644 --- a/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java +++ b/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java @@ -43,7 +43,7 @@ public class GBDaoGenerator { public static void main(String[] args) throws Exception { - Schema schema = new Schema(29, MAIN_PACKAGE + ".entities"); + Schema schema = new Schema(30, MAIN_PACKAGE + ".entities"); Entity userAttributes = addUserAttributes(schema); Entity user = addUserInfo(schema, userAttributes); @@ -508,6 +508,7 @@ public class GBDaoGenerator { Property userId = summary.addLongProperty("userId").notNull().codeBeforeGetter(OVERRIDE).getProperty(); summary.addToOne(user, userId); summary.addStringProperty("summaryData"); + summary.addByteArrayProperty("rawSummaryData"); } private static Property findProperty(Entity entity, String propertyName) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/GadgetbridgeUpdate_30.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/GadgetbridgeUpdate_30.java new file mode 100644 index 000000000..41fb5cee8 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/GadgetbridgeUpdate_30.java @@ -0,0 +1,38 @@ +/* Copyright (C) 2017-2020 Andreas Shimokawa, protomors + + This file is part of Gadgetbridge. + + Gadgetbridge is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Gadgetbridge is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ +package nodomain.freeyourgadget.gadgetbridge.database.schema; + +import android.database.sqlite.SQLiteDatabase; + +import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; +import nodomain.freeyourgadget.gadgetbridge.database.DBUpdateScript; +import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummaryDao; + +public class GadgetbridgeUpdate_30 implements DBUpdateScript { + @Override + public void upgradeSchema(SQLiteDatabase db) { + if (!DBHelper.existsColumn(BaseActivitySummaryDao.TABLENAME, BaseActivitySummaryDao.Properties.RawSummaryData.columnName, db)) { + String ADD_COLUMN_RAW_SUMMARY_DATA = "ALTER TABLE " + BaseActivitySummaryDao.TABLENAME + " ADD COLUMN " + + BaseActivitySummaryDao.Properties.RawSummaryData.columnName + " BLOB"; + db.execSQL(ADD_COLUMN_RAW_SUMMARY_DATA); + } + } + + @Override + public void downgradeSchema(SQLiteDatabase db) { + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchSportsSummaryOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchSportsSummaryOperation.java index e395a5945..3a87ac017 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchSportsSummaryOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchSportsSummaryOperation.java @@ -98,6 +98,7 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation { User user = DBHelper.getUser(session); summary.setDevice(device); summary.setUser(user); + summary.setRawSummaryData(buffer.toByteArray()); session.getBaseActivitySummaryDao().insertOrReplace(summary); } catch (Exception ex) { GB.toast(getContext(), "Error saving activity summary", Toast.LENGTH_LONG, GB.ERROR, ex); diff --git a/build.gradle b/build.gradle index b4e031e32..7f21fe3e0 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { } } dependencies { - classpath 'com.android.tools.build:gradle:4.0.0' + classpath 'com.android.tools.build:gradle:4.0.1' classpath 'gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:2.0.0' // NOTE: Do not place your application dependencies here; they belong