mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 09:01:55 +01:00
Also export and import device specific preference files
This commit is contained in:
parent
5ecf3cadc8
commit
34b4943918
@ -6,9 +6,11 @@
|
||||
* Mi Band 3: Add Indonesian, Thai, Arabic, Vietnamese, Portuguese, Dutch, Turkish and Ukrainian to language settings
|
||||
* Mi Band 3: Support flashing latest Japanese-Korean font
|
||||
* Amazfit Cor 2: Inital experimental support (untested)
|
||||
* Pebble: Add pebblekit extension for reopening last app
|
||||
* Casio: Bugfixes and improvements
|
||||
* Lookup contacts also in work profile
|
||||
* Fix searching in application name when blacklisting
|
||||
* Remove misleading title from database management activity when no legacy database is available
|
||||
|
||||
#### Version 0.32.4
|
||||
* Make voip call support optional (disabled by default)
|
||||
|
@ -42,6 +42,8 @@ import android.provider.ContactsContract.PhoneLookup;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
@ -52,7 +54,6 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBOpenHelper;
|
||||
@ -622,6 +623,13 @@ public static String packageNameToPebbleMsgSender(String packageName) {
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static SharedPreferences getDeviceSpecificSharedPrefs(String deviceIdentifier) {
|
||||
if (deviceIdentifier == null || deviceIdentifier.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return context.getSharedPreferences("devicesettings_" + deviceIdentifier, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
public static void setLanguage(String lang) {
|
||||
if (lang.equals("default")) {
|
||||
language = Resources.getSystem().getConfiguration().locale;
|
||||
|
@ -36,11 +36,13 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.ImportExportSharedPreferences;
|
||||
@ -119,6 +121,23 @@ public class DbManagementActivity extends AbstractGBActivity {
|
||||
} catch (IOException ex) {
|
||||
GB.toast(this, getString(R.string.dbmanagementactivity_error_exporting_shared, ex.getMessage()), Toast.LENGTH_LONG, GB.ERROR, ex);
|
||||
}
|
||||
try (DBHandler lockHandler = GBApplication.acquireDB()) {
|
||||
List<Device> activeDevices = DBHelper.getActiveDevices(lockHandler.getDaoSession());
|
||||
for (Device dbDevice : activeDevices) {
|
||||
SharedPreferences deviceSharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(dbDevice.getIdentifier());
|
||||
if (sharedPrefs != null) {
|
||||
File myPath = FileUtils.getExternalFilesDir();
|
||||
File myFile = new File(myPath, "Export_preference_" + dbDevice.getIdentifier());
|
||||
try {
|
||||
ImportExportSharedPreferences.exportToFile(deviceSharedPrefs, myFile, null);
|
||||
} catch (Exception ignore) {
|
||||
// some devices no not have device specific preferences
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
GB.toast("Error exporting device specific preferences", Toast.LENGTH_SHORT, GB.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
private void importShared() {
|
||||
@ -129,6 +148,23 @@ public class DbManagementActivity extends AbstractGBActivity {
|
||||
} catch (Exception ex) {
|
||||
GB.toast(DbManagementActivity.this, getString(R.string.dbmanagementactivity_error_importing_db, ex.getMessage()), Toast.LENGTH_LONG, GB.ERROR, ex);
|
||||
}
|
||||
try (DBHandler lockHandler = GBApplication.acquireDB()) {
|
||||
List<Device> activeDevices = DBHelper.getActiveDevices(lockHandler.getDaoSession());
|
||||
for (Device dbDevice : activeDevices) {
|
||||
SharedPreferences deviceSharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(dbDevice.getIdentifier());
|
||||
if (sharedPrefs != null) {
|
||||
File myPath = FileUtils.getExternalFilesDir();
|
||||
File myFile = new File(myPath, "Export_preference_" + dbDevice.getIdentifier());
|
||||
try {
|
||||
ImportExportSharedPreferences.importFromFile(deviceSharedPrefs, myFile);
|
||||
} catch (Exception ignore) {
|
||||
// some devices no not have device specific preferences
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
GB.toast("Error importing device specific preferences", Toast.LENGTH_SHORT, GB.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
private void exportDB() {
|
||||
@ -152,7 +188,6 @@ public class DbManagementActivity extends AbstractGBActivity {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||
importShared();
|
||||
DBHelper helper = new DBHelper(DbManagementActivity.this);
|
||||
File dir = FileUtils.getExternalFilesDir();
|
||||
SQLiteOpenHelper sqLiteOpenHelper = dbHandler.getHelper();
|
||||
@ -163,6 +198,7 @@ public class DbManagementActivity extends AbstractGBActivity {
|
||||
} catch (Exception ex) {
|
||||
GB.toast(DbManagementActivity.this, getString(R.string.dbmanagementactivity_error_importing_db, ex.getMessage()), Toast.LENGTH_LONG, GB.ERROR, ex);
|
||||
}
|
||||
importShared();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
|
||||
|
@ -136,7 +136,7 @@ public class MiBandPairingActivity extends AbstractGBActivity {
|
||||
GBDevice device = DeviceHelper.getInstance().toSupportedDevice(deviceCandidate);
|
||||
|
||||
if (coordinator.supportsDeviceSpecificSettings(device)) {
|
||||
SharedPreferences sharedPrefs = getSharedPreferences("devicesettings_" + device.getAddress(), Context.MODE_PRIVATE);
|
||||
SharedPreferences sharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress());
|
||||
String authKey = sharedPrefs.getString("authkey", null);
|
||||
if (authKey == null || authKey.isEmpty()) {
|
||||
SharedPreferences.Editor editor = sharedPrefs.edit();
|
||||
|
@ -18,7 +18,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -38,6 +37,7 @@ import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEOperation;
|
||||
@ -83,8 +83,9 @@ public class InitOperation extends AbstractBTLEOperation<HuamiSupport> {
|
||||
private byte[] getSecretKey() {
|
||||
byte[] authKeyBytes = new byte[]{0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45};
|
||||
|
||||
SharedPreferences preferences = getContext().getSharedPreferences("devicesettings_" + getDevice().getAddress(),Context.MODE_PRIVATE);
|
||||
String authKey = preferences.getString("authkey", null);
|
||||
SharedPreferences sharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress());
|
||||
|
||||
String authKey = sharedPrefs.getString("authkey", null);
|
||||
if (authKey != null && !authKey.isEmpty()) {
|
||||
byte[] srcBytes = authKey.getBytes();
|
||||
System.arraycopy(srcBytes, 0, authKeyBytes, 0, Math.min(srcBytes.length,16));
|
||||
|
@ -86,14 +86,7 @@ public class ImportExportSharedPreferences {
|
||||
return importFromReader(sharedPreferences, new FileReader(inFile));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sharedPreferences
|
||||
* @param in
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static boolean importFromReader(SharedPreferences sharedPreferences, Reader in)
|
||||
private static boolean importFromReader(SharedPreferences sharedPreferences, Reader in)
|
||||
throws Exception {
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.clear();
|
||||
@ -124,27 +117,31 @@ public class ImportExportSharedPreferences {
|
||||
} else if (STRING.equals(name)) {
|
||||
editor.putString(key, text);
|
||||
} else if (HASHSET.equals(name)) {
|
||||
if (key.equals(GBPrefs.PACKAGE_BLACKLIST)) {
|
||||
Set<String> apps_blacklist = new HashSet<>();
|
||||
text=text.replace("[","").replace("]","");
|
||||
for (int z=0;z<text.split(",").length;z++){
|
||||
apps_blacklist.add(text.split(",")[z].trim());
|
||||
}
|
||||
GBApplication.setAppsNotifBlackList(apps_blacklist);
|
||||
} else if (key.equals(GBPrefs.PACKAGE_PEBBLEMSG_BLACKLIST)) { //TODO: untested
|
||||
Set<String> apps_pebble_blacklist = new HashSet<>();
|
||||
text=text.replace("[","").replace("]","");
|
||||
for (int z=0;z<text.split(",").length;z++){
|
||||
apps_pebble_blacklist.add(text.split(",")[z].trim());
|
||||
}
|
||||
GBApplication.setAppsPebbleBlackList(apps_pebble_blacklist);
|
||||
} else if (key.equals(GBPrefs.CALENDAR_BLACKLIST)) { //TODO: untested
|
||||
Set<String> calendars_blacklist = new HashSet<>();
|
||||
text = text.replace("[", "").replace("]", "");
|
||||
for (int z = 0; z < text.split(",").length; z++) {
|
||||
calendars_blacklist.add(text.split(",")[z].trim());
|
||||
}
|
||||
GBApplication.setCalendarsBlackList(calendars_blacklist);
|
||||
switch (key) {
|
||||
case GBPrefs.PACKAGE_BLACKLIST:
|
||||
Set<String> apps_blacklist = new HashSet<>();
|
||||
text = text.replace("[", "").replace("]", "");
|
||||
for (int z = 0; z < text.split(",").length; z++) {
|
||||
apps_blacklist.add(text.split(",")[z].trim());
|
||||
}
|
||||
GBApplication.setAppsNotifBlackList(apps_blacklist);
|
||||
break;
|
||||
case GBPrefs.PACKAGE_PEBBLEMSG_BLACKLIST: //TODO: untested
|
||||
Set<String> apps_pebble_blacklist = new HashSet<>();
|
||||
text = text.replace("[", "").replace("]", "");
|
||||
for (int z = 0; z < text.split(",").length; z++) {
|
||||
apps_pebble_blacklist.add(text.split(",")[z].trim());
|
||||
}
|
||||
GBApplication.setAppsPebbleBlackList(apps_pebble_blacklist);
|
||||
break;
|
||||
case GBPrefs.CALENDAR_BLACKLIST: //TODO: untested
|
||||
Set<String> calendars_blacklist = new HashSet<>();
|
||||
text = text.replace("[", "").replace("]", "");
|
||||
for (int z = 0; z < text.split(",").length; z++) {
|
||||
calendars_blacklist.add(text.split(",")[z].trim());
|
||||
}
|
||||
GBApplication.setCalendarsBlackList(calendars_blacklist);
|
||||
break;
|
||||
}
|
||||
} else if (!PREFERENCES.equals(name)) {
|
||||
throw new Exception("Unknown type " + name);
|
||||
|
Loading…
Reference in New Issue
Block a user