Repository: tarkah/tickrs (language: rust)

Issue:
Charts don't load on Android
**Issue:** 
After "add a ticker" with a valid ticker it just repeats "..." indefinitely and never loads the chart. 
The rest of the key commands and the tui app all appear to work fine.

**Install:** cargo install tickrs

**System info:**

$ cargo -V
cargo 1.50.0

$  uname -a
Linux localhost 4.14.113-20606106 #1 SMP PREEMPT Mon Feb 1 10:40:43 KST 2021 aarch64 Android

$ termux-info
Packages CPU architecture:
aarch64
Android version:
11
Device manufacturer:
samsung
Device model:
SM-N975F


Thanks for any support you can provide! 


Discussion / hints:
What is the ticker?
AMZN
GE
SPY
TLSA

Tried many...

Can you try these links directly and see if they resolve?

https://query1.finance.yahoo.com/v8/finance/chart/AMZN?range=1d&interval=1m&includePrePost=true
https://query1.finance.yahoo.com/v8/finance/chart/SPY?range=1d&interval=1m&includePrePost=true
https://query1.finance.yahoo.com/v10/finance/quoteSummary/AMZN?modules=price,assetProfile
https://query1.finance.yahoo.com/v10/finance/quoteSummary/SPY?modules=price,assetProfile
I just noticed you're trying to run this from an Android phone... I have NO idea if the `aarch64-unknown-linux-gnu` binary would work there. I'm pretty sure I'd have to target `aarch64-linux-android` specifically to get things working 100%, but I haven't really ever looked into this.
Here's a version I built for android, test this out and let me know if it works

[tickrs-v0.14.2-aarch64-linux-android.tar.gz](https://github.com/tarkah/tickrs/files/6143056/tickrs-v0.14.2-aarch64-linux-android.tar.gz)

Thanks for all the support.

The URLs load fine. I tried curl from the (termux) shell to retrieve w/ no issues.

I had tried the aarch64-unknown-linux-gnu binary previously but it did not run on this hardware.

Thanks for the binary. It runs. However, it has the same "..." indefintely w/ no chart loading. (Same issue as noted in the original post.) The rest of the program runs properly (renders, keyboard commands, etc).

I should note originally - I did build for android via the "cargo install tickrs". It compiles &builds completely on my setup. However, it has the same results as the version you compiled.

Where to go from here? How can we extract some debug info? Is there helpful switches for build output information or debug hooks we could put in the source? 

Let me know how to continue to debug and help. I am anxious to use this and help pave the way for all android termux users.

Yeah, lets get this figured out! It's got to be one of the dependencies that "compiles" properly for that target, but doesn't work. My guess would be the curl dependency I use, `isahc`. Let's start by researching that dependency and any sub-deps of that to make sure it all supports the `aarch64-linux-android` target.

As far as debugging... I have 0 debug lines or logging anywhere in the program currently. We can pepper in some, disable the raw mode I set the terminal in, and disable drawing the UI so we can just see the output of those messages. I'm 99% sure it's networking related and probably due to the `isahc` / static curl that is built not working properly. But some debug messages around that would definitely help. 
### Comment out these lines

https://github.com/tarkah/tickrs/blob/ab76c6bde42bf4799b99b112ecc6d27ebe0ed082/src/main.rs#L119
https://github.com/tarkah/tickrs/blob/ab76c6bde42bf4799b99b112ecc6d27ebe0ed082/src/main.rs#L130
https://github.com/tarkah/tickrs/blob/ab76c6bde42bf4799b99b112ecc6d27ebe0ed082/src/main.rs#L198

### Add debugging on the Err(error) of the API requests here

https://github.com/tarkah/tickrs/blob/ab76c6bde42bf4799b99b112ecc6d27ebe0ed082/src/task/prices.rs#L41-L44
https://github.com/tarkah/tickrs/blob/ab76c6bde42bf4799b99b112ecc6d27ebe0ed082/src/task/company.rs#L34
https://github.com/tarkah/tickrs/blob/ab76c6bde42bf4799b99b112ecc6d27ebe0ed082/src/task/current_price.rs#L33
Another thought.... you can also run `cargo test --target aarch64-linux-android --workspace -- --nocapture` and I have some tests in the `API` crate that do http requests. You can see if that succeeds or not.
You can also try removing the static curl / static openssl that gets built and see if linked one works:

Change this:

https://github.com/tarkah/tickrs/blob/ab76c6bde42bf4799b99b112ecc6d27ebe0ed082/api/Cargo.toml#L21-L22

To this:

```
 curl = { version = "0.4" } 
 isahc = { version = "0.8", default-features = false, features = ["http2", "text-decoding"] }
```
So I added some debugging and I'm getting the following error:

`BadClientCertificate(None)` so I don't think there are ssl certs installed w/ termux so the ssl/tls requests are failing. Let me see if there's an easy fix for this.
I think we need a way to specify the openssl directory so it can find the certs shipped with termux

`$TERMUX_PREFIX/etc/tls`
It works!

![](https://i.imgur.com/QvmHYQE.png)
I disabled ssl cert validation, I didn't know how to fix it otherwise... Don't think there is really much of a risk here, plus it'll only be disabled for Android.

```diff
diff --git a/api/src/client.rs b/api/src/client.rs
index 069aeb1..ed9dbfb 100644
--- a/api/src/client.rs
+++ b/api/src/client.rs
@@ -3,7 +3,7 @@ use std::collections::HashMap;
 use anyhow::{bail, Context, Result};
 use futures::AsyncReadExt;
 use http::Uri;
-use isahc::HttpClient;
+use isahc::prelude::*;
 use serde::de::DeserializeOwned;

 use crate::model::{Chart, ChartData, Company, CompanyData, Options, OptionsHeader};
@@ -182,7 +182,17 @@ impl Client {

 impl Default for Client {
     fn default() -> Client {
-        let client = HttpClient::new().unwrap();
+        #[allow(unused_mut)]
+        let mut builder = HttpClient::builder();
+
+        #[cfg(target_os = "android")]
+        {
+            use isahc::config::SslOption;
+
+            builder = builder.ssl_options(SslOption::DANGER_ACCEPT_INVALID_CERTS);
+        }
+
+        let client = builder.build().unwrap();

         let base = String::from("https://query1.finance.yahoo.com");
```

Fix patch:
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index a1b2575..24ebb4d 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -49,6 +49,10 @@ jobs:
             os: ubuntu-latest
             cross: true
             binary_path: target/aarch64-unknown-linux-gnu/release/tickrs
+          - target: aarch64-linux-android
+            os: ubuntu-latest
+            cross: true
+            binary_path: target/aarch64-linux-android/release/tickrs
 
     runs-on: ${{ matrix.target.os }}
     steps:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2258340..96e970b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,10 @@ and `Removed`.
 
 ## [Unreleased]
 
+### Packaging
+
+- Add support and releases for Android (aarch64-linux-android)
+
 ## [0.14.3] - 2021-03-15
 
 ### Changed
diff --git a/api/src/client.rs b/api/src/client.rs
index 069aeb1..ed9dbfb 100644
--- a/api/src/client.rs
+++ b/api/src/client.rs
@@ -3,7 +3,7 @@ use std::collections::HashMap;
 use anyhow::{bail, Context, Result};
 use futures::AsyncReadExt;
 use http::Uri;
-use isahc::HttpClient;
+use isahc::prelude::*;
 use serde::de::DeserializeOwned;
 
 use crate::model::{Chart, ChartData, Company, CompanyData, Options, OptionsHeader};
@@ -182,7 +182,17 @@ impl Client {
 
 impl Default for Client {
     fn default() -> Client {
-        let client = HttpClient::new().unwrap();
+        #[allow(unused_mut)]
+        let mut builder = HttpClient::builder();
+
+        #[cfg(target_os = "android")]
+        {
+            use isahc::config::SslOption;
+
+            builder = builder.ssl_options(SslOption::DANGER_ACCEPT_INVALID_CERTS);
+        }
+
+        let client = builder.build().unwrap();
 
         let base = String::from("https://query1.finance.yahoo.com");
 


Test patch: