diff options
Diffstat (limited to 'app/src')
3 files changed, 123 insertions, 1 deletions
diff --git a/app/src/main/java/org/connectbot/data/ColorStorage.java b/app/src/main/java/org/connectbot/data/ColorStorage.java new file mode 100644 index 0000000..eb3d2d2 --- /dev/null +++ b/app/src/main/java/org/connectbot/data/ColorStorage.java @@ -0,0 +1,31 @@ +/* + * ConnectBot: simple, powerful, open-source SSH client for Android + * Copyright 2015 Kenny Root, Jeffrey Sharkey + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.connectbot.data; + +/** + * Created by kroot on 9/11/15. + */ +public interface ColorStorage { + public int[] getColorsForScheme(int colorScheme); + + public void setGlobalColor(int mCurrentColor, int value); + + public int[] getDefaultColorsForScheme(int colorScheme); + + public void setDefaultColorsForScheme(int mColorScheme, int mDefaultColor, int mDefaultColor1); +} diff --git a/app/src/main/java/org/connectbot/data/HostStorage.java b/app/src/main/java/org/connectbot/data/HostStorage.java new file mode 100644 index 0000000..9d4fc7d --- /dev/null +++ b/app/src/main/java/org/connectbot/data/HostStorage.java @@ -0,0 +1,89 @@ +/* + * ConnectBot: simple, powerful, open-source SSH client for Android + * Copyright 2015 Kenny Root, Jeffrey Sharkey + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.connectbot.data; + +import java.util.List; +import java.util.Map; + +import org.connectbot.bean.HostBean; +import org.connectbot.bean.PortForwardBean; + +import com.trilead.ssh2.KnownHosts; + +import android.support.annotation.VisibleForTesting; + +/** + * Interface that defines the operation used to interact with the storage layer. + */ +public interface HostStorage { + /** + * Resets the database during testing. + */ + @VisibleForTesting + void resetDatabase(); + + /** + * Finds the host that is represented by the given selection. + * @param selection all fields to be considered + * @return the matching host + */ + HostBean findHost(Map<String, String> selection); + + /** + * Deletes the given {@code host} from the storage layer. + */ + void deleteHost(HostBean host); + + /** + * Saves the given {@code host} to the storage layer. + */ + HostBean saveHost(HostBean host); + + /** + * Returns a list of all the hosts as a list of {@link HostBean}. + * @param sortedByColor if hosts should be grouped by color. + */ + List<HostBean> getHosts(boolean sortedByColor); + + /** + * Updates the last connected time for {@code host}. + */ + void touchHost(HostBean host); + + /** + * Finds a {@link HostBean} based on the given {@code hostId}. + */ + HostBean findHostById(long hostId); + + /** + * Returns the list of known hosts. + * + * @see #saveKnownHost(String, int, String, byte[]) + */ + KnownHosts getKnownHosts(); + + /** + * Adds a known host to the database for later retrieval using {@link #getKnownHosts()}. + */ + void saveKnownHost(String hostname, int port, String serverHostKeyAlgorithm, byte[] serverHostKey); + + /** + * Return all port forwards for the given {@code host}. + */ + PortForwardBean[] getPortForwardsForHost(HostBean host); +} diff --git a/app/src/main/java/org/connectbot/util/HostDatabase.java b/app/src/main/java/org/connectbot/util/HostDatabase.java index e8ced95..e077409 100644 --- a/app/src/main/java/org/connectbot/util/HostDatabase.java +++ b/app/src/main/java/org/connectbot/util/HostDatabase.java @@ -26,6 +26,8 @@ import java.util.Map.Entry; import org.connectbot.bean.HostBean; import org.connectbot.bean.PortForwardBean; +import org.connectbot.data.ColorStorage; +import org.connectbot.data.HostStorage; import android.content.ContentValues; import android.content.Context; @@ -43,7 +45,7 @@ import com.trilead.ssh2.KnownHosts; * * @author jsharkey */ -public class HostDatabase extends RobustSQLiteOpenHelper { +public class HostDatabase extends RobustSQLiteOpenHelper implements HostStorage, ColorStorage { public final static String TAG = "CB.HostDatabase"; |