Skip to content

Commit

Permalink
all: less logs is more (fixes #2013) (#2014)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored May 29, 2024
1 parent a8c7f7b commit 06271d8
Show file tree
Hide file tree
Showing 47 changed files with 50 additions and 219 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
track: internal
releaseName: "${{ env.VERSION }}"
status: completed
#changesNotSentForReview: true
changesNotSentForReview: true

# - name: mobile security framework
# run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import io.treehouses.remote.ui.home.HomeFragment
import io.treehouses.remote.ui.network.NetworkFragment
import io.treehouses.remote.ui.services.ServicesFragment
import io.treehouses.remote.ui.status.StatusFragment
import io.treehouses.remote.utils.LogUtils
import io.treehouses.remote.utils.SettingsUtils
import io.treehouses.remote.utils.logD

open class BaseInitialActivity: PermissionActivity(), NavigationView.OnNavigationItemSelectedListener, HomeInteractListener, NotificationCallback {
protected var validBluetoothConnection = false
Expand Down Expand Up @@ -57,10 +55,8 @@ open class BaseInitialActivity: PermissionActivity(), NavigationView.OnNavigatio

override fun sendMessage(s: String) {
// Check that we're actually connected before trying anything
logD(s)
if (mChatService.state != Constants.STATE_CONNECTED) {
Toast.makeText(this@BaseInitialActivity, R.string.not_connected, Toast.LENGTH_SHORT).show()
LogUtils.mIdle()
return
}

Expand Down Expand Up @@ -93,7 +89,6 @@ open class BaseInitialActivity: PermissionActivity(), NavigationView.OnNavigatio
// save the connected device's name
mConnectedDeviceName = msg.data.getString(Constants.DEVICE_NAME)
if (mConnectedDeviceName != "" || mConnectedDeviceName != null) {
logD("DEVICE$mConnectedDeviceName")
checkStatusNow()
}
}
Expand All @@ -104,19 +99,15 @@ open class BaseInitialActivity: PermissionActivity(), NavigationView.OnNavigatio
fun checkStatusNow() {
validBluetoothConnection = when (mChatService.state) {
Constants.STATE_CONNECTED -> {
LogUtils.mConnect()
true
}
Constants.STATE_NONE -> {
LogUtils.mOffline()
false
}
else -> {
LogUtils.mIdle()
false
}
}
logD("BOOLEAN $validBluetoothConnection")
}

override fun onNavigationItemSelected(item: MenuItem): Boolean {
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/kotlin/io/treehouses/remote/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import androidx.preference.PreferenceManager
import com.parse.Parse
import io.treehouses.remote.network.BluetoothChatService
import io.treehouses.remote.utils.SaveUtils
import io.treehouses.remote.utils.logD
import io.treehouses.remote.utils.logE

class MainApplication : Application() {
var logSent = false
Expand All @@ -42,15 +40,13 @@ class MainApplication : Application() {

override fun onServiceConnected(className: ComponentName, service: IBinder) {
// We've bound to LocalService, cast the IBinder and get LocalService instance
logD("Bluetooth Service CONNECTED")
val binder = service as BluetoothChatService.LocalBinder
mChatService = binder.service
// sendBroadcast(Intent().setAction(BLUETOOTH_SERVICE_CONNECTED))
}

override fun onServiceDisconnected(arg0: ComponentName) {
mChatService = null
logE("Bluetooth Service DISCONNECTED")
}
}

Expand All @@ -64,7 +60,6 @@ class MainApplication : Application() {

fun stopBluetoothService() {
if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.KEEP_BLUETOOTH_ALIVE, false)) {
logE("Unbinding Service Bluetooth Service")
try {unbindService(connection)} catch (e: Exception) {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.preference.PreferenceManager
import io.treehouses.remote.utils.SaveUtils
import io.treehouses.remote.utils.logD


class SplashScreenActivity : AppCompatActivity() {
Expand Down Expand Up @@ -87,7 +86,6 @@ class SplashScreenActivity : AppCompatActivity() {

private fun fontSize(): Int
{
logD("FONT SIZE " + PreferenceManager.getDefaultSharedPreferences(this).getInt("font_size", 18).toString())
return PreferenceManager.getDefaultSharedPreferences(this).getInt("font_size", 18)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import android.widget.TextView
import androidx.core.content.ContextCompat
import io.treehouses.remote.R
import io.treehouses.remote.pojo.ServiceInfo
import io.treehouses.remote.utils.logE
import java.util.*

class ServicesListAdapter //private Button start, install, restart, link, info;
Expand Down Expand Up @@ -93,7 +92,7 @@ class ServicesListAdapter //private Button start, install, restart, link, info;
name!!.text = data[position].name
setStatus(data[position].serviceStatus)
} catch (exception: java.lang.IndexOutOfBoundsException) {
logE("Error $exception")
exception.printStackTrace()
}
return convertView
}
Expand All @@ -102,7 +101,7 @@ class ServicesListAdapter //private Button start, install, restart, link, info;
try {
return data[position].serviceStatus != ServiceInfo.SERVICE_HEADER_AVAILABLE && data[position].serviceStatus != ServiceInfo.SERVICE_HEADER_INSTALLED
} catch (exception: IndexOutOfBoundsException) {
logE("Error $exception")
exception.printStackTrace()
}
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import io.treehouses.remote.Constants
import io.treehouses.remote.R
import io.treehouses.remote.callback.HomeInteractListener
import io.treehouses.remote.network.BluetoothChatService
import io.treehouses.remote.utils.logD

class ViewHolderBlocker internal constructor(v: View, context: Context?, listener: HomeInteractListener) {
private val blockerBar: SeekBar = v.findViewById(R.id.blockerBar)
Expand All @@ -34,7 +33,6 @@ class ViewHolderBlocker internal constructor(v: View, context: Context?, listene
when (msg.what) {
Constants.MESSAGE_READ -> {
readMessage = msg.obj as String
logD("readMessage = $readMessage")
updateSelection(readMessage)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import io.treehouses.remote.Constants
import io.treehouses.remote.callback.HomeInteractListener
import io.treehouses.remote.network.BluetoothChatService
import io.treehouses.remote.utils.DialogUtils
import io.treehouses.remote.utils.logE

open class BaseFragment : Fragment() {
var lastMessage = " "
Expand Down Expand Up @@ -66,7 +65,7 @@ open class BaseFragment : Fragment() {
Toast.makeText(activity, "Bluetooth disconnected", Toast.LENGTH_LONG).show()
listener.redirectHome()
} catch (exception:NullPointerException){
logE("Error $exception")
exception.printStackTrace()
}
}
else -> getMessage(msg)
Expand Down
8 changes: 1 addition & 7 deletions app/src/main/kotlin/io/treehouses/remote/bases/BaseSSH.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import io.treehouses.remote.ssh.terminal.TerminalManager
import io.treehouses.remote.ssh.beans.HostBean
import io.treehouses.remote.ssh.beans.PubKeyBean
import io.treehouses.remote.utils.KeyUtils
import io.treehouses.remote.utils.logD
import io.treehouses.remote.utils.logE
import net.i2p.crypto.eddsa.EdDSAPrivateKey
import net.i2p.crypto.eddsa.EdDSAPublicKey
import java.io.IOException
Expand Down Expand Up @@ -134,7 +132,6 @@ open class BaseSSH : ConnectionMonitor, InteractiveCallback, AuthAgentCallback {

// read in all known hosts from hostdb
val hosts = KeyUtils.getAllKnownHosts(manager!!.applicationContext)
logD("ALL HOSTS $hosts")
val matchName = String.format(Locale.US, "%s:%d", hostname, port)
val print = KnownHosts.createHexFingerprint(serverHostKeyAlgorithm, serverHostKey)
val algo: String = if ("ssh-rsa" == serverHostKeyAlgorithm) "RSA" else if ("ssh-dss" == serverHostKeyAlgorithm) "DSA" else if (serverHostKeyAlgorithm.startsWith("ecdsa-")) "EC" else if ("ssh-ed25519" == serverHostKeyAlgorithm) "Ed25519" else serverHostKeyAlgorithm
Expand Down Expand Up @@ -207,7 +204,6 @@ open class BaseSSH : ConnectionMonitor, InteractiveCallback, AuthAgentCallback {

override fun removeServerHostKey(host: String, port: Int, algorithm: String, hostKey: ByteArray) {
KeyUtils.removeKnownHost(manager!!.applicationContext, "$host:$port")
logD("REMOVING HOST KEY For: $host:$port with algorithm: $algorithm")
}

override fun addServerHostKey(host: String, port: Int, algorithm: String, hostKey: ByteArray) {
Expand All @@ -233,7 +229,6 @@ open class BaseSSH : ConnectionMonitor, InteractiveCallback, AuthAgentCallback {
*/
protected fun finishConnection() {
authenticated = true
logD("SHOULD BE AUTHENTICATED HERE")

// for (PortForwardBean portForward : portForwards) {
// try {
Expand Down Expand Up @@ -262,7 +257,7 @@ open class BaseSSH : ConnectionMonitor, InteractiveCallback, AuthAgentCallback {
isSessionOpen = true
bridge!!.onConnected()
} catch (e1: IOException) {
logE("Problem while trying to create PTY in finishConnection() $e1")
e1.printStackTrace()
}
}

Expand Down Expand Up @@ -488,7 +483,6 @@ open class BaseSSH : ConnectionMonitor, InteractiveCallback, AuthAgentCallback {
override fun getKeyPair(publicKey: ByteArray): KeyPair? {
val nickname = manager!!.getKeyNickname(publicKey) ?: return null
if (useAuthAgent == "no") {
logD(TAG)
return null
} else if (useAuthAgent == "confirm" ||
manager!!.loadedKeypairs[nickname]!!.bean!!.isConfirmUse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import io.treehouses.remote.callback.RVButtonClickListener
import io.treehouses.remote.databinding.DialogSshBinding
import io.treehouses.remote.databinding.RowSshBinding
import io.treehouses.remote.utils.SaveUtils
import io.treehouses.remote.utils.logD
import java.lang.Exception
import java.util.regex.Pattern

Expand Down Expand Up @@ -87,7 +86,7 @@ open class BaseSSHConfig: BaseFragment(), RVButtonClickListener, OnHostStatusCha

override fun onStop() {
super.onStop()
try {activity?.unbindService(connection)} catch (e: Exception) {logD("SSHConfig $e")}
try {activity?.unbindService(connection)} catch (e: Exception) {e.printStackTrace()}
}

override fun onButtonClick(position: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import io.treehouses.remote.ssh.interfaces.FontSizeChangedListener
import io.treehouses.remote.views.terminal.VDUBuffer
import io.treehouses.remote.views.terminal.VDUDisplay
import io.treehouses.remote.views.terminal.vt320
import io.treehouses.remote.utils.logD
import io.treehouses.remote.utils.logE
import java.io.IOException

open class BaseTerminalBridge : VDUDisplay {
Expand Down Expand Up @@ -135,9 +133,6 @@ open class BaseTerminalBridge : VDUDisplay {
* Should never be called once the session is established.
*/
fun outputLine(output: String) {
if (transport != null && transport!!.isSessionOpen) {
logD("Session established, cannot use outputLine! ${IOException("outputLine call traceback")}")
}
synchronized(localOutput) {
for (line in output.split("\n".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()) {
var line = line
Expand Down Expand Up @@ -321,7 +316,7 @@ open class BaseTerminalBridge : VDUDisplay {
try {
transport!!.write(string.toByteArray(charset(host!!.encoding)))
} catch (e: Exception) {
logE("Couldn't inject string to remote host: $e")
e.printStackTrace()
}
}
injectStringThread.name = "InjectString"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import io.treehouses.remote.databinding.ActivityTerminalFragmentBinding
import io.treehouses.remote.pojo.CommandsList
import io.treehouses.remote.utils.RESULTS
import io.treehouses.remote.utils.Utils.copyToClipboard
import io.treehouses.remote.utils.logD
import io.treehouses.remote.utils.match
import org.json.JSONException
import org.json.JSONObject
Expand Down Expand Up @@ -51,7 +50,6 @@ open class BaseTerminalFragment : BaseFragment() {
// construct a string from the buffer
val writeMessage = String(writeBuf)
if (match(writeMessage) != RESULTS.PING_OUTPUT && !jsonSent) {
logD( "writeMessage = $writeMessage")
mConversationArrayAdapter?.add("\nCommand: $writeMessage")
}
return writeMessage
Expand Down Expand Up @@ -186,7 +184,6 @@ open class BaseTerminalFragment : BaseFragment() {
}
for (i in data.commands!!.indices) {
val s = getRootCommand(data.commands!![i]).trim { it <= ' ' }
logD( "updateArrayAdapters: $s")
if (!inSecondLevel!!.contains(s)) {
arrayAdapter2?.add(s)
inSecondLevel?.add(s)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import io.treehouses.remote.PreferenceConstants
import io.treehouses.remote.ssh.terminal.TerminalBridge
import io.treehouses.remote.ssh.terminal.TerminalManager
import io.treehouses.remote.ssh.beans.SelectionArea
import io.treehouses.remote.utils.logD
import io.treehouses.remote.utils.logE
import java.io.IOException

/**
Expand Down Expand Up @@ -211,11 +209,10 @@ open class BaseTerminalKeyListener(var manager: TerminalManager?,
}

fun handleProblem(e: IOException) {
logD("message $e")
try {
bridge.transport!!.flush()
} catch (ioe: IOException) {
logE("Our transport was closed, dispatching disconnect event")
ioe.printStackTrace()
bridge.dispatchDisconnect(false)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import android.provider.Settings
import android.text.ClipboardManager
import io.treehouses.remote.ssh.terminal.PatternHolder
import io.treehouses.remote.ssh.terminal.TerminalView
import io.treehouses.remote.utils.logD
import io.treehouses.remote.utils.logE
import java.util.*
import kotlin.math.ceil

Expand Down Expand Up @@ -56,7 +54,6 @@ open class DerivedTerminalBridge : BaseTerminalBridge() {
@Synchronized
fun parentChanged(parent: TerminalView) {
if (manager != null && !manager!!.isResizeAllowed) {
logD("Resize is not allowed now")
return
}
this.parent = parent
Expand Down Expand Up @@ -105,7 +102,7 @@ open class DerivedTerminalBridge : BaseTerminalBridge() {
synchronized(vDUBuffer!!) { vDUBuffer!!.setScreenSize(columns, rows, true) }
if (transport != null) transport!!.setDimensions(columns, rows, width, height)
} catch (e: Exception) {
logE("Problem while trying to resize screen or PTY $e")
e.printStackTrace()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import io.treehouses.remote.Constants
import io.treehouses.remote.MainApplication
import io.treehouses.remote.R
import io.treehouses.remote.network.BluetoothChatService
import io.treehouses.remote.utils.logE

open class FragmentViewModel(application: Application) : AndroidViewModel(application) {
/**
Expand Down Expand Up @@ -45,9 +44,8 @@ open class FragmentViewModel(application: Application) : AndroidViewModel(applic
Constants.MESSAGE_STATE_CHANGE -> {
if (msg.arg1 == Constants.STATE_NONE) {
try { Toast.makeText(application, "Bluetooth disconnected", Toast.LENGTH_LONG).show() }
catch (exception: NullPointerException) { logE("Error $exception") }
catch (exception: NullPointerException) { exception.printStackTrace() }
}
logE("RECEIVED, CONNECTION ${msg.arg1}")
_connectionStatus.value= msg.arg1
}
Constants.MESSAGE_WRITE -> onWrite(String(msg.obj as ByteArray))
Expand Down Expand Up @@ -99,7 +97,6 @@ open class FragmentViewModel(application: Application) : AndroidViewModel(applic
* @param toSend : String = A string to send to the Raspberry Pi
*/
fun sendMessage(toSend: String) {
logE("SENDING $toSend")
lastCommand = toSend
if (_connectionStatus.value != Constants.STATE_CONNECTED) {
Toast.makeText(getApplication(), "Not Connected to Bluetooth", Toast.LENGTH_LONG).show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import io.treehouses.remote.bases.BaseFragment
import io.treehouses.remote.databinding.ActivityDiscoverFragmentBinding
import io.treehouses.remote.fragments.dialogfragments.RPIDialogFragment
import io.treehouses.remote.interfaces.FragmentDialogInterface
import io.treehouses.remote.utils.logD
import io.treehouses.remote.utils.logE
import kotlin.math.PI
import kotlin.math.cos
import kotlin.math.sin
Expand All @@ -45,13 +43,12 @@ class DiscoverFragment : BaseFragment(), FragmentDialogInterface {
}

private fun requestNetworkInfo() {
logD("$TAG, Requesting Network Information")
try {
listener.sendMessage(getString(R.string.TREEHOUSES_DISCOVER_GATEWAY_LIST))
listener.sendMessage(getString(R.string.TREEHOUSES_DISCOVER_GATEWAY))
listener.sendMessage(getString(R.string.TREEHOUSES_DISCOVER_SELF))
} catch (e: Exception) {
logE("Error Requesting Network Information")
e.printStackTrace()
}
}

Expand Down Expand Up @@ -212,11 +209,9 @@ class DiscoverFragment : BaseFragment(), FragmentDialogInterface {
when (msg.what) {
Constants.MESSAGE_WRITE -> {
val writeMsg = String((msg.obj as ByteArray))
logD("WRITE $writeMsg")
}
Constants.MESSAGE_READ -> {
val readMessage = msg.obj as String
logD("$TAG, READ = $readMessage")

if(!addDevices(readMessage))
if(!updateGatewayInfo(readMessage))
Expand Down
Loading

0 comments on commit 06271d8

Please sign in to comment.