-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
59 changed files
with
1,600 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/main/java/de/florianisme/wakeonlan/persistence/migrations/MigrationFrom3To4.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package de.florianisme.wakeonlan.persistence.migrations; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.room.migration.Migration; | ||
import androidx.sqlite.db.SupportSQLiteDatabase; | ||
|
||
public class MigrationFrom3To4 extends Migration { | ||
|
||
public MigrationFrom3To4() { | ||
super(3, 4); | ||
} | ||
|
||
@Override | ||
public void migrate(@NonNull SupportSQLiteDatabase database) { | ||
database.execSQL("ALTER TABLE 'Devices' ADD COLUMN 'enable_remote_shutdown' INTEGER DEFAULT 0 NOT NULL"); // Booleans are stored as Integer | ||
database.execSQL("ALTER TABLE 'Devices' ADD COLUMN 'ssh_address' TEXT"); | ||
database.execSQL("ALTER TABLE 'Devices' ADD COLUMN 'ssh_port' INTEGER"); | ||
database.execSQL("ALTER TABLE 'Devices' ADD COLUMN 'ssh_user' TEXT"); | ||
database.execSQL("ALTER TABLE 'Devices' ADD COLUMN 'ssh_password' TEXT"); | ||
database.execSQL("ALTER TABLE 'Devices' ADD COLUMN 'ssh_command' TEXT"); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/de/florianisme/wakeonlan/persistence/migrations/MigrationFrom4To5.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package de.florianisme.wakeonlan.persistence.migrations; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.room.migration.Migration; | ||
import androidx.sqlite.db.SupportSQLiteDatabase; | ||
|
||
public class MigrationFrom4To5 extends Migration { | ||
|
||
public MigrationFrom4To5() { | ||
super(4, 5); | ||
} | ||
|
||
@Override | ||
public void migrate(@NonNull SupportSQLiteDatabase database) { | ||
// Do nothing | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/src/main/java/de/florianisme/wakeonlan/shutdown/ShutdownExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package de.florianisme.wakeonlan.shutdown; | ||
|
||
import android.util.Log; | ||
|
||
import org.bouncycastle.jce.provider.BouncyCastleProvider; | ||
|
||
import java.security.Security; | ||
import java.util.Optional; | ||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.Executors; | ||
|
||
import de.florianisme.wakeonlan.persistence.models.Device; | ||
import de.florianisme.wakeonlan.shutdown.listener.IgnoringShutdownExecutorListener; | ||
import de.florianisme.wakeonlan.shutdown.listener.ShutdownExecutorListener; | ||
|
||
public class ShutdownExecutor { | ||
|
||
private static final Executor executor = Executors.newSingleThreadExecutor(); | ||
|
||
static { | ||
// Override Android's BC implementation with official BC Provider | ||
Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME); | ||
Security.insertProviderAt(new BouncyCastleProvider(), 1); | ||
} | ||
|
||
public static void shutdownDevice(Device device, ShutdownExecutorListener shutdownExecutorListener) { | ||
Optional<ShutdownModel> optionalShutdownModel = ShutdownModelFactory.fromDevice(device); | ||
|
||
if (!optionalShutdownModel.isPresent()) { | ||
Log.w(ShutdownExecutor.class.getSimpleName(), "Can not shutdown device. Not all required fields were set"); | ||
shutdownExecutorListener.onGeneralError(new IllegalArgumentException("Can not shutdown device. Not all required fields were set"), null); | ||
return; | ||
} | ||
|
||
ShutdownModel shutdownModel = optionalShutdownModel.get(); | ||
ShutdownRunnable shutdownRunnable = new ShutdownRunnable(shutdownModel, shutdownExecutorListener); | ||
|
||
executor.execute(shutdownRunnable); | ||
} | ||
|
||
public static void shutdownDevice(Device device) { | ||
shutdownDevice(device, new IgnoringShutdownExecutorListener()); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/de/florianisme/wakeonlan/shutdown/ShutdownModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package de.florianisme.wakeonlan.shutdown; | ||
|
||
public class ShutdownModel { | ||
|
||
private final String sshAddress; | ||
private final int sshPort; | ||
private final String username; | ||
private final String password; | ||
private final String command; | ||
|
||
public ShutdownModel(String sshAddress, int sshPort, String username, String password, String command) { | ||
this.sshAddress = sshAddress; | ||
this.sshPort = sshPort; | ||
this.username = username; | ||
this.password = password; | ||
this.command = command; | ||
} | ||
|
||
public String getSshAddress() { | ||
return sshAddress; | ||
} | ||
|
||
public int getSshPort() { | ||
return sshPort; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public String getCommand() { | ||
return command; | ||
} | ||
} |
Oops, something went wrong.