Delete PCs by UUID instead of name

This commit is contained in:
Cameron Gutman 2019-07-16 20:35:18 -07:00
parent dc97adc7a1
commit 1d76536e31
3 changed files with 10 additions and 22 deletions

View File

@ -585,7 +585,6 @@ public class PcView extends Activity implements AdapterFragmentCallbacks {
Toast.makeText(PcView.this, getResources().getString(R.string.error_manager_not_running), Toast.LENGTH_LONG).show(); Toast.makeText(PcView.this, getResources().getString(R.string.error_manager_not_running), Toast.LENGTH_LONG).show();
return; return;
} }
managerBinder.removeComputer(computer.details.name);
removeComputer(computer.details); removeComputer(computer.details);
} }
}, null); }, null);
@ -630,6 +629,8 @@ public class PcView extends Activity implements AdapterFragmentCallbacks {
} }
private void removeComputer(ComputerDetails details) { private void removeComputer(ComputerDetails details) {
managerBinder.removeComputer(details);
for (int i = 0; i < pcGridAdapter.getCount(); i++) { for (int i = 0; i < pcGridAdapter.getCount(); i++) {
ComputerObject computer = (ComputerObject) pcGridAdapter.getItem(i); ComputerObject computer = (ComputerObject) pcGridAdapter.getItem(i);

View File

@ -65,8 +65,8 @@ public class ComputerDatabaseManager {
} }
} }
public void deleteComputer(String name) { public void deleteComputer(ComputerDetails details) {
computerDb.delete(COMPUTER_TABLE_NAME, COMPUTER_NAME_COLUMN_NAME+"=?", new String[]{name}); computerDb.delete(COMPUTER_TABLE_NAME, COMPUTER_UUID_COLUMN_NAME+"=?", new String[]{details.uuid});
} }
public boolean updateComputer(ComputerDetails details) { public boolean updateComputer(ComputerDetails details) {
@ -140,14 +140,7 @@ public class ComputerDatabaseManager {
Cursor c = computerDb.rawQuery("SELECT * FROM "+COMPUTER_TABLE_NAME, null); Cursor c = computerDb.rawQuery("SELECT * FROM "+COMPUTER_TABLE_NAME, null);
LinkedList<ComputerDetails> computerList = new LinkedList<>(); LinkedList<ComputerDetails> computerList = new LinkedList<>();
while (c.moveToNext()) { while (c.moveToNext()) {
ComputerDetails details = getComputerFromCursor(c); computerList.add(getComputerFromCursor(c));
// If a critical field is corrupt or missing, skip the database entry
if (details.uuid == null) {
continue;
}
computerList.add(details);
} }
c.close(); c.close();
@ -166,12 +159,6 @@ public class ComputerDatabaseManager {
ComputerDetails details = getComputerFromCursor(c); ComputerDetails details = getComputerFromCursor(c);
c.close(); c.close();
// If a critical field is corrupt or missing, delete the database entry
if (details.uuid == null) {
deleteComputer(details.name);
return null;
}
return details; return details;
} }
} }

View File

@ -225,8 +225,8 @@ public class ComputerManagerService extends Service {
return ComputerManagerService.this.addComputerBlocking(fakeDetails); return ComputerManagerService.this.addComputerBlocking(fakeDetails);
} }
public void removeComputer(String name) { public void removeComputer(ComputerDetails computer) {
ComputerManagerService.this.removeComputer(name); ComputerManagerService.this.removeComputer(computer);
} }
public void stopPolling() { public void stopPolling() {
@ -402,18 +402,18 @@ public class ComputerManagerService extends Service {
} }
} }
public void removeComputer(String name) { public void removeComputer(ComputerDetails computer) {
if (!getLocalDatabaseReference()) { if (!getLocalDatabaseReference()) {
return; return;
} }
// Remove it from the database // Remove it from the database
dbManager.deleteComputer(name); dbManager.deleteComputer(computer);
synchronized (pollingTuples) { synchronized (pollingTuples) {
// Remove the computer from the computer list // Remove the computer from the computer list
for (PollingTuple tuple : pollingTuples) { for (PollingTuple tuple : pollingTuples) {
if (tuple.computer.name.equals(name)) { if (tuple.computer.uuid.equals(computer.uuid)) {
if (tuple.thread != null) { if (tuple.thread != null) {
// Interrupt the thread on this entry // Interrupt the thread on this entry
tuple.thread.interrupt(); tuple.thread.interrupt();