From 0310e8e9f19338f470031a737bfdaa6f848edcae Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Fri, 11 Sep 2015 13:09:13 -0700 Subject: Add interfaces for HostStorage and ColorStorage An attempt to help with testing. --- .../java/org/connectbot/data/ColorStorage.java | 31 ++++++++ .../main/java/org/connectbot/data/HostStorage.java | 89 ++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 app/src/main/java/org/connectbot/data/ColorStorage.java create mode 100644 app/src/main/java/org/connectbot/data/HostStorage.java (limited to 'app/src/main/java/org/connectbot/data') 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 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 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); +} -- cgit v1.2.3