Commit 21814725 authored by y0no's avatar y0no
Browse files

Now load signatures from file when app is launched

parent 461cd126
......@@ -43,14 +43,6 @@ public class FingerprintMgr {
}
private static HashMap<String, DeviceSignature> m_oSignatures = new HashMap<>();
public static boolean isKnown(String address) {
for (Map.Entry<String, DeviceSignature> entry: m_oSignatures.entrySet()) {
if (entry.getValue().mName == address)
return true;
}
return false;
}
public static void addSignature(String name, DeviceSignature signature) {
m_oSignatures.put(name, signature);
......@@ -98,4 +90,13 @@ public class FingerprintMgr {
}
return type_found;
}
public static void loadSignatures() {
ArrayList<String> lines = FileLog.read("signature.txt", NewBtLE.getContext());
for (String line: lines) {
String[] splitted = line.split(";");
m_oSignatures.put(splitted[0], new DeviceSignature(DEVICE_TYPE.valueOf(splitted[1]), splitted[2]));
Log.d(TAG, "Load signature for " + splitted[2]);
}
}
}
......@@ -63,6 +63,8 @@ public class NewBtLE extends AppCompatActivity {
}
private void startScan() {
FingerprintMgr.loadSignatures();
m_oBtScanner = new BtScanner(m_oStatus, m_oList);
if (m_oBtScanner.enableAdapter() && !m_bScanning && m_bPermissions) {
m_oBtScanner.startScan();
......
......@@ -3,9 +3,13 @@ package fr.y0no.newbtle.utils;
import android.content.Context;
import android.util.Log;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
/**
* Created by y0no on 08/07/16.
......@@ -26,4 +30,25 @@ public class FileLog {
Log.e("Exception", "File write failed: " + e.toString());
}
}
public static ArrayList<String> read(String filename, Context context) {
ArrayList<String> strings = new ArrayList<>();
try {
File path = context.getExternalFilesDir(null);
File file = new File(path, filename);
if (!file.exists())
file.createNewFile();
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while((line = br.readLine()) !=null) {
strings.add(line);
}
} catch (FileNotFoundException e) {
Log.e("Exception", "File '"+ filename + "' not found");
} catch (IOException e) {
Log.e("Exception", "File read failed: " + e.toString());
}
return strings;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment