Open android app via ssh - android

I have SSHDroid installed on my Android Device, and I've been investigating how to launch an app via SSH.
I can't seem to find any solution, nor documentation that explain why shouldn't I be able to do such thing.
How can I achieve to launch an app via SSH (computer to android) not using ADB? Is it even possible?

I'm doing it in this way:
ssh mymobile /su/bin/su -c am start -a android.intent.action.VIEW -d http://www.stackoverflow.com
su is run because it sets proper environment. Without it, the am fails.
I'm running openssh server on my mobile and login as root.

Related

Is there a way to do --disable-web-security on android chrome

I'm developing a mobile web app where the content server is remote. I can do some basic testing on desktop Chrome with --disable-web-security option.
Is there a similar feature available on chrome on android? Or, any other browser on android?
UPDATE
I'm including these headers, Authorization, Access-Control-Allow-Origin, Access-Control-Allow-Credentials; but it seems to have no impact on the data server.
Am I missing any other settings?
The web app code resides on a local PC. Data on the remote hosts and the browser is on mobile in local LAN.
Actually, there is a way but it is a little hard, first, you should install adb on your system (Linux, Windows, macOS and etc) then restart adb server and at last plugin your Android device. check the adb connection with below command on your terminal/cmd:
$ adb list
When you see your device on the result of the above command, it is time to run the main command:
$ adb shell am start -n com.android.chrome/com.google.android.apps.chrome.Main
If the above command opens a Google Chrome tab or window, its time to disable security by your command order

Getting "error: closed" twice on "adb reverse"

I am trying to reverse-forward port through ADB, but it just returns cryptic error of error: closed. Normal forwarding works. Session snippet:
$ adb forward tcp:59778 tcp:59778
$ adb forward --list
015d2109ce0c1a0f tcp:59778 tcp:59778
$ adb forward --remove-all
$ adb forward --list
$ adb reverse --list
error: closed
error: closed
$ adb reverse tcp:59778 tcp:59778
error: closed
error: closed
I am connecting via USB to non-rooted Nexus 7 2012 Android 4.4.4 from Windows 7 Pro x64 on Boot Camp.
adb reverse was introduced in Android 5.0
Since adb reverse is not supported in Android versions lower than 5.0, you need to use an alternative method, for example connecting via Wi-Fi instead. If you are using React Native, Facebook has added official documentation to connect to the development server via Wi-Fi. Quoting the instructions for MacOS, but they also have them for Linux and Windows:
Method 2: Connect via Wi-Fi
You can also connect to the development server over Wi-Fi. You'll first need to install the app on your device using a USB cable, but once that has been done you can debug wirelessly by following these instructions. You'll need your development machine's current IP address before proceeding.
You can find the IP address in System Preferences → Network.
Make sure your laptop and your phone are on the same Wi-Fi network.
Open your React Native app on your device.
You'll see a red screen with an error. This is OK. The following steps will fix that.
Open the in-app Developer menu.
Go to Dev Settings → Debug server host for device.
Type in your machine's IP address and the port of the local dev server (e.g. 10.0.1.1:8081).
Go back to the Developer menu and select Reload JS.
Follow these steps carefully.
Note: All commands need to run inside a project only.
Run this command first:
npm react-native start
Open another window in the same project and run:
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
This will create index.android.bundle in the assets folder
Run:
npm react-native run-android
Now you can get apk in the build folder which will work fine.
adb reverse requires Android 5.0+. For devices previous to that, you'll need to use a workaround like so.
If you have busybox installed on your Android device (most Genymotion images do), you can emulate adb reverse using this incantation:
adb shell busybox nc -ll -p {guest port} -e busybox nc {host IP} {host port}
In this case, "guest" is the Android OS running in the emulator and "host" is the computer running the emulator.
cause of adb reverse isnt working on android prior 5 you could propably use adb forward with a service listening on android and tunneling other connections through this inbound connection. I am doing this mostly with ssh, but you would need an ssh server on android. you than can connect using ssh -R incommingreverseportonandroid:hostyouwanttoforwardto:portyouwanttoforwardto sshuseronandroid#localhost -p portyouhaveusedforadbforwaqrdtoaccessandroidssshserver
but i dont know how to enable an ssh server on android and maybe there is a better way cause ssh uses encryption which isnt needed over usb and using up cpu.
i am using this way with my server to share a service when i am forced behind a nat...
hope someone will find a way to bring this teoretical way into practical possibility
Just use 10.0.2.2 instead of localhost/127.0.0.1 for your hostname. It will directly try to connect to the port on the host machine (same affect as reverse).

run-as command in android

I am currently developing directly on my device using an ide app called AIDE. But after creating a DB I can't access it to check my data/app are working correctly.
I have managed to get run-as to work using adb with my phone plugged into my laptop, but I'd really like it to work straight off the phone so I can code, test and debug, all whilst on the move.
Using connectbot I can see the run-as command in system/bin/ but it has no executable access.
Any ideas?

What is the ADB?

I keep reading tutorials where I'm supposed to enter something into the ADB command line and that it's in my Android sdk/platform-tools. So I find it, click on it, and a black screen comes up for about 2 seconds and while it's up, it scrolls through a bunch of text. So how am I supposed to use this "adb"?
It is called the Android Debug Bridge, and the Android Developers Site documentation does a better job of explaining it than I can:
http://developer.android.com/guide/developing/tools/adb.html
If you are looking for the adb command line, navigate to <sdk>/platform-tools/ and run
adb.exe shell
from the command line.
Pretty sure that is well documented since day 1 on the Android Debug Bridge
Android Debug Bridge (adb) is a versatile command line tool that lets
you communicate with an emulator instance or connected Android-powered
device. It is a client-server program that includes three components:
A client, which runs on your development machine. You can invoke a
client from a shell by issuing an adb command. Other Android tools
such as the ADT plugin and DDMS also create adb clients. A server,
which runs as a background process on your development machine. The
server manages communication between the client and the adb daemon
running on an emulator or device. A daemon, which runs as a background
process on each emulator or device instance.
So plain old English, ADB can be found on %ANDROID_HOME%/platform-toos/, and it's this magical command line that allows you to comunicate with your mobile device, either a physical or a Virtual device (AVD), so whenever you deploy you are passing the application through the device thanks to the ADB on a specific client port on your computer to the daemon port on the device.
Interesting things you can do with it?
Logcat: ./adb logcat allows you to see the log trace of each proces.
Install: ./adb install allows you to install apk to the device.
Killing:./adb kill-sever
Starting:./adb stat-server
Enter SQLite3: adb -s your_device shell
Use the monkey: adb shell monkey -v -p your.app.package 500 to
generate random events
And a lot more! Read the documentation it's beatiful and self-explanatory.

Access a virtual host from the Android emulator

I'm developing a simple app that connects to a webservice configured as a virtualhost in Apache, so its URL is myapp.localhost
In my development machine (Mac OS X) I can access it, and also from the iPhone emulator.
But I'm having problems from the Android emulator, it just cannot reach that URL, because it's not using my /etc/hosts file to resolve the "myapp.localhost" domain name.
Since I'm using Appcelerator Titanium (appcelerator.com), I cannot use "adb" to inject a custom hosts file to the Android emulator.
Is there a DNS server or something similar I can install in my Mac OS X system to translate that virtual host for the Android emulator?
I suppose you eventually found how to solve the problem. Still, I will give a possible answer for those who seek around, struggling with the same problem we had once.
Since android devices are emulated and not simulated (as opposed to iOS devices), they indeed have their own kernels, configuration files... and their own /system/etc/hosts. But you can actually use adb with Titanium. You just need to be careful. Since Titanium use a custom-generated virtual device, based on tiapp.xml, you will have to run your application at least once before the virtual device shows up in the device list.
If you have more than on virtual device you first need to get the name of the device generated by Titanium (typically emulator-XXXX).
adb devices
Then you can mount it and use adb push and pull commands to get the /system/etc/hosts out of the emulator's system, edit it and push it back. -s emulator-XXXX specifies on which device these commands are meant to be executed. If there is only one device, you can skip this option. See adb doc for more informations.
adb -s emulator-XXXX remount
adb -s emulator-XXXX pull /system/etc/hosts /whatever/directory/
You can now edit /whatever/directory/hosts with you favorite editor and add the necessary host. If you need to access the localhost interface of your development machine, 10.0.2.2 is a link to the computer's loopback interface. Simply add 10.0.2.2 myapp.localhost to the host and push it back to the virtual device.
adb -s emulator-XXXX push /whatever/directory/hosts /system/etc/hosts
Relaunch the simulator with Titanium and it should do the trick!

Categories

Resources