[Q][SOLVED] Locking on 3G/2G (or: accessing com.android.internal from application) - Android Software Development

Hello everyone,
I'm writing an android application that needs to swap between 2G/3G networks.
I wasn't able to find any suitable function in the SDK documentation.
I tried "digging" into the android code to see how other activities (such as Settings.ACTION_WIRELESS_SETTINGS, the Phone Information technician code [*#*#4636#*#*]) implement it and came across com.android.internal.telephony.Phone which is in charge of the switching.
I guess the device has to be rooted to perform this (and of course, my application needs root privileges), however, I can't change the android code on the device.
So, my question is: How do I access com.android.internal.telephony.Phone from my application without changing the android code?
Many thanks,
Omri.

Anyone has an idea?
Thank you

CDMA or GSM?
And a lot of the telephony is private.
Sent from my iPhone with the bigger GeeBees.

I have good news: I got it working and I wanted to share on how.
I had a few problems on the way, but I faced them all.
First of all, being able to access com.android.internal.* from the SDK (with ADT) wasn't that comfortable before I ran into this guide, which lets you include all the hidden & internal APIs in your android.jar library and override the access rules limiting you not to access them in ADT.
After that was done, I thought I'm done, but I was wrong.
To switch from 2G to 3G you need to invoke setPreferredNetworkType() method on the Phone object (com.android.internal.telephony).
To get the Phone object, you'll need to invoke the getDefaultPhone() method on PhoneFactory (com.android.internal.telephony).
But, of course, nothing will be simple, this method only runs when your manifest inclues android:sharedUserId="android.uid.system" (aka, your process runs as system user).
Your process won't be able to run with the android.uid.system UID without your package being signed with the platform certificate.
To sign your package with the platform certificate, you need signapk.jar, platform certificate (platform.x509.pem) and platform key (platform.pk8).
Because I'm using CyanogenMod I was able to put my hands on the platform cert&key pair without recompiling android. (available here)
Once you have these, the rest is pretty simple:
Sign your APK with signapk.jar:
Code:
java -jar signapk.jar platform.x509.pem platform.pk8 Application.apk Application-signed.apk
Because this is a system package, you won't be able to install it with "adb install Application.apk", we'll have to use a different method.
Upload your APK to the /system/app folder (don't forget to mount /system for read-write before you do that):
Code:
adb push Application-signed.apk /system/app/Application.apk
The next thing to do is launch your activity:
Code:
adb shell am start -a android.intent.action.MAIN -n com.your.package/.YourActivity
That's it!
You got it working!
Good luck to whoever runs into this post
Cheers,
Omri.

Related

[Q] Developing on Device

I have programmed in java for quite some time, and am decent at android apps.
However, i have two questions about developing on my device (rooted samsung captivate).
First, how can i get dev tools to run correctly on my phone. I have installed it as stated in "developer.android com/guide/developing/debug-tasks html#additionaldebugging". However, when clicking on Dev Settings it crashed with HARDWARE_TEST security exception. I have read that you need to sign/run it as system.
Is it possible to run it on my rooted captivate? if so how do i install it as system or find the system signature to sign it.
My other question is about programing, compiling, and running android applications from a device. I can take my .apk and unzip it. Then edit any resource files. Then rezip and sign it. However if i want to replace the actual code i need to compile it. I can use an online java compiler but i need to convert it to android format.
I know that dx.bat does this by using dx.jar . I can add dx.jar to the referenced libraries of my app. However i cant figure out what to do past there. Is what i am attempting even possible?
Thanks for your help.
There's a couple threads in this forum from folks like me who want to do this. Perhaps you can help us figure it out
Step one is I think to get an java compiler running on the phone. Then to make a version of DX that can run on the phone to convert the class to .apk
Thanks. in normal java programs you can use "com.sun.tools.javac.Main.compile( new String[] {args} );" found in the "<sdk>/lib/tools.jar" to compile a program. And dx.jar is what is used to covert it to android, however i do not know what to call in it.
We just need to find a way to get these jars to work on android.

[UPDATED][INFO] ROM 101 + CWM Errors Solutions

Parts of a ROM
i. The kernel.
Android (like many other Smartphone operating systems) runs on the Linux kernel. The Linux kernel was created in the early 1990’s by a gentleman named Linus Torvalds in Helsinki, Finland. It’s incredibly stable, incredibly friendly, and incredibly difficult for the layman to understand and modify. Thankfully it’s also very popular so it has been ported on to a multitude of hardware, including our Android devices.
Think of the kernel as an interface layer between the hardware and software on your device. The kernel decides when things happen, such as the LED indicator gets lit or when the soft button's LED gets lit. An application sends a request to the operating system to blink the LED. The operating system then sends the request to the kernel, which makes the light flash for the amount of time requested by the OS.
What sounds like a round-about way to get things done is also what makes the system so scalable and robust. Application developers only have to code in a way the operating system understands and the kernel makes it work on the hardware. This also keeps the application running in it’s own user-space and separate from the kernel. That means when you run the latest uber-cool app that wasn’t designed for your particular OS version, or is still very beta and it crashes, the kernel gives you the option to Force Close the application and the kernel can run untouched.
In a standard Android ROM (we will leave developer images and the like for another discussion) the kernel is bundled along with a set of instructions that tell the device how to load the kernel and the OS during boot. This is the boot.img that you see inside a zipped ROM that your not able to easily open. The device knows to extract this image to internal memory (the ramdisk) and follow a series of scripts (init scripts) to load the kernel and then the other portions of the OS. That’s what’s happening while you’re watching the boot animation. Interestingly enough this is done the same way for a PC, your smartphone, an Android tablet, or even a smart Linux powered toaster. If you’re feeling exceptionally geeky, plug your Android phone into the USB port on your PC and let the PC boot from the USB device. No, it doesn’t actually load, but you can watch the animation while it tries to match up the hardware support with what’s inside your PC. As I said, Linux is amazingly scalable and as a result so is Android.
What is a kernel? If you spend any time reading Android forums, blogs, how-to posts or online discussion you'll soon hear people talking about the kernel. A kernel isn't something unique to Android -- iOS and MacOS have one, Windows has one, BlackBerry's QNX has one, in fact all high level operating systems have one. The one we're interested in is Linux, as it's the one Android uses. Let's try to break down what it is and what it does.
Android devices use the Linux kernel, but it's not the exact same kernel other Linux-based operating systems use. There's a lot of Android specific code built in, and Google's Android kernel maintainers have their work cut out for them. OEMs have to contribute as well, because they need to develop hardware drivers for the parts they're using for the kernel version they're using. This is why it takes a while for independent Android developers and hackers to port new versions to older devices and get everything working. Drivers written to work with the Gingerbread kernel on a phone won't necessarily work with the Ice Cream Sandwich kernel. And that's important, because one of the kernel's main functions is to control the hardware. It's a whole lot of source code, with more options while building it than you can imagine, but in the end it's just the intermediary between the hardware and the software.
When software needs the hardware to do anything, it sends a request to the kernel. And when we say anything, we mean anything. From the brightness of the screen, to the volume level, to initiating a call through the radio, even what's drawn on the display is ultimately controlled by the kernel. For example -- when you tap the search button on your phone, you tell the software to open the search application. What happens is that you touched a certain point on the digitizer, which tells the software that you've touched the screen at those coordinates. The software knows that when that particular spot is touched, the search dialog is supposed to open. The kernel is what tells the digitizer to look (or listen, events are "listened" for) for touches, helps figure out where you touched, and tells the system you touched it. In turn, when the system receives a touch event at a specific point from the kernel (through the driver) it knows what to draw on your screen. Both the hardware and the software communicate both ways with the kernel, and that's how your phone knows when to do something. Input from one side is sent as output to the other, whether it's you playing Angry Birds, or connecting to your car's Bluetooth.
It sounds complicated, and it is. But it's also pretty standard computer logic -- there's an action of some sort generated for every event. Without the kernel to accept and send information, developers would have to write code for every single event for every single piece of hardware in your device. With the kernel, all they have to do is communicate with it through the Android system API's, and hardware developers only have to make the device hardware communicate with the kernel. The good thing is that you don't need to know exactly how or why the kernel does what it does, just understanding that it's the go-between from software to hardware gives you a pretty good grasp of what's happening under the glass. Sort of gives a whole new outlook towards those fellows who stay up all night to work on kernels for your phone, doesn't it?
Click to expand...
Click to collapse
ii. The operating system.
Once the kernel is loaded, the init scripts tell the Operating System to load. Android is the user interface for a custom built Java virtual machine called Dalvik. Dalvik was written by Dan Bornstein, who named it after the fishing village of Dalvik in Iceland, where his family originated from. The debate of which Java VM is superior is best left for another discussion, so I’ll simply say that DalvikVM is a register-based machine versus true JavaVMs which are stack based.
The Dalvik machine creates executable files (.dex files) which can be interpreted by the OS and run by the end user. These .dex files are OS version dependant. That simply means that applications and core functions built to work with one version of Android may or may not work well with other versions. Google provides the tools through it’s Software Development Kit (SDK) for applications to communicate with the OS.
Click to expand...
Click to collapse
iii. Core functions.
No smartphone would be complete without a set of functions that allow the device to be used as intended. Things like the phone and dialer interface, the calendar, the messaging system are core functions of the Operating System. In Android, these are run on top of the kernel as separate applications. The merits (or lack of) of providing these needed functions as separate applications is once again best left for another discussion, but this is what allows developers like HTC or Motorola to replace the standard functions with alternatives that provide a different look and feel from stock. HTC’s onscreen keyboard or Motorola’s MotoBlur contact list are great examples of this. The “little guy” isn’t left out of the mix either. Handcent SMS or Chomp SMS can integrate into the OS very well, as most of us already know.
An additional set of Core Functions are provided by Google. Popularly called GoogleBits, things like Gmail, sync, Gtalk and the Android Market are applications written by Google that give an extra set of useful functions to the OS. You’ll find these on all smartphones, as well as many other Android devices.
Click to expand...
Click to collapse
iv. Optional applications.
These are applications provided by the manufacturer to give the device even more usability. Things like the Amazon MP3 store, PDF readers, Corporate Calendar etc. allow you to do even more with your device. Remember - Droid Does
Click to expand...
Click to collapse
B. How is a ROM packaged?
In most cases a ROM will come packaged in a .zip file. The recovery image’s kernel (yes, it has one too!) has the ability to unzip and copy the contents into the correct place. Inside this zip file is a folder (META-INF\com\google\android\) that contains a script prepared by the ROM “cooker” (another of those techie terms - it means the person(s) who developed the ROM) that tells the system what to format, what to copy and where, and any file operations that need to be done. Each device does things a bit differently, but this script is where it all gets done. More on this folder later.
You’ll also see a /system folder. This is the meat of the ROM. It has the necessary OS files, the Core functions, and any optional applications the cooker decided to include. The folder is structured the same way it is on your device - /system/app, /system/framework, etc. The whole tree is usually copied over and the existing /system folder is overwritten. The cooker uses the script to tell the kernel to erase the existing system folder, copy the new folder over, and set the file permissions.
Sometimes you will also see a data folder. This usually is space set up for optional applications, including optional system tools like busybox or SuperUser white list. These applications could be placed in the /system folder, but placing them in the data folder makes it easier for the end user (you and I) to remove or update them as needed.
You’ll also notice a META-INF folder. This contains the update script we talked about earlier, as well as secure keys that need to be provided so the device knows the update can be trusted. A special note needs made here. Trusted means that the update is trusted to be in the correct form to load the device. It in no way means the ROM is safe from malicious code. Anyone is able to use a set of test keys and create a ROM that will flash and run your device - even those people with bad intentions. Flashing and running a custom 3rd party ROM is putting faith in the cooker that he or she not only knows what they are doing, but are honest as well. Also, some Motorola custom ROMs will have a small update.zip stored inside this folder to be run on first boot of the device.
Finally we are left with the boot.img file. This is the kernel and ramdisk image we discussed earlier. Your phone copies this over to be decompressed and run when the device boots.
Click to expand...
Click to collapse
2. How do I install a ROM?
In this section we’re discussing how to install a custom 3rd party ROM. ROMs from the manufacturer usually have a utility that runs on your PC to flash and load the new image.
A. Got Root???
What is Root?
Android rooting is the process of allowing users of smartphones, tablets, and other devices running the Android mobile operating system to attain privileged control (known as "root access") within Android's subsystem.
Rooting is often performed with the goal of overcoming limitations that carriers and hardware manufacturers put on some devices, resulting in the ability to alter or replace system applications and settings, run specialized apps that require administrator-level permissions, or perform other operations that are otherwise inaccessible to a normal Android user. On Android, rooting can also facilitate the complete removal and replacement of the device's operating system, usually with a more recent release of its current operating system.
As Android derives from the Linux kernel, rooting an Android device is similar to accessing administrative permissions on Linux or any other Unix-like operating system such as FreeBSD or OS X.
The process of rooting varies widely by device, but usually includes exploiting a security bug(s) in the firmware (i.e. in Android) of the device, and then copying the su binary to a location in the current process's PATH (e.g. /system/xbin/su) and granting it executable permissions with the chmod command. A supervisor application like SuperUser or SuperSU can regulate and log elevated permission requests from other applications. Many guides, tutorials, and automatic processes exist for popular Android devices facilitating a fast and easy rooting process.
For example, shortly after the HTC Dream was released, it was quickly discovered that anything typed using the keyboard was being interpreted as a command in a privileged (root) shell. Although Google quickly released a patch to fix this, a signed image of the old firmware leaked, which gave users the ability to downgrade and use the original exploit to gain root access. Once an exploit is discovered, a custom recovery image that skips the digital signature check of a firmware update package can be flashed. In turn, using the custom recovery, a modified firmware update can be installed that typically includes the utilities (for example the Superuser app) needed to run apps as root.
The Google-branded Android phones, the Nexus One, Nexus S, Galaxy Nexus and Nexus 4, as well as their tablet counterparts, the Nexus 7 and Nexus 10, can be boot-loader unlocked by simply connecting the device to a computer while in boot-loader mode and running the Fastboot program with the command "fastboot oem unlock".[9] After accepting a warning, the boot-loader is unlocked, so a new system image can be written directly to flash without the need for an exploit.
Recently, Motorola, LG Electronics and HTC added security features to their devices at the hardware level in an attempt to prevent users from rooting retail Android devices.[citation needed] For instance, the Motorola Droid X has a security boot-loader that puts the phone in "recovery mode" if a user loads unsigned firmware onto the device, and the Samsung Galaxy S II displays a yellow triangle indicator if the device firmware has been modified.
Click to expand...
Click to collapse
Yes ?:good:!!!
Custom ROM’s simply will not load on devices that aren’t rooted. In theory, it may be possible to sign a 3rd party ROM with the keys that the stock recovery image will flash, but for the most part you need to have flashed a custom recovery image before you can change your device’s ROM. Instructions and tutorials on how to root your device are all over the internet. Some are good, some are bad. The hacking forum is a great place to go and learn more about rooting and how to successfully get it done on your device.
Click to expand...
Click to collapse
B. Recovery
Most Android devices have had a custom recovery image written for them. This will overwrite the stock recovery image, allowing you to flash 3rd party ROMs as well as giving extra functionality. Help with finding and flashing the custom recovery image for your device can also be found in the hacking forum. The installation of a custom recovery image also allows for a very important function. Backup and restore.
Click to expand...
Click to collapse
.C. Nandroid
Nandroid is a set of bash scripts and code written by that copies the state of your system and stores it in a folder on your SD card. You can then use the restore function of Nandroid to restore to this point at any time. This is a priceless feature and reason enough to root your phone. It’s included by default in most custom recovery images, and the code is freely available to use if you’re inclined to write your own recovery image.
Click to expand...
Click to collapse
In most situations, using Nandroid to back everything up is easy:
1. Verify you have a memory card with enough free space (~300MB to backup, ~500MB to restore).
2. Reboot your device into recovery. It’s slightly different for each device, once again hacking forum FTW!
3. Navigate through the menu and select the Nandroid Backup function.
4. Apply your choice and wait for the device to tell you it’s finished.
It’s always good practice to copy the entire nandroid folder from your SD card to a safe place. You can then copy it back to the SD card if the card is ever damaged, lost or erased.
D. Copy and Flash
You’re rooted, have downloaded a custom ROM, have your system backed up and are now ready to flash your device. This is not nearly as scary as it sounds.
1. Mount your SD card to your PC, and copy the .zip file to the root folder of the card. Don’t unzip the file, and don’t look for a folder called root. The root folder in this case means the base folder, what you will see when you mount your card to a PC or the device.
2. Reboot your phone into recovery.
3. Navigate through the recovery menu and select the flash update option. Depending on your recovery image, the file may need to be named update.zip, or you may be able to select any zip file on your card as long as it’s the correct format. The cooker knows this as well and if the ROM needs to be named update.zip it will be.
4. Apply your choice and wait for your device to tell you it’s finished.
5. Reboot.
Click to expand...
Click to collapse
It’s worth noting that many times a new ROM will require that you wipe and factory reset your devices data. While inconvenient, it’s often necessary to get rid of the old data as it may be incompatible. As long as you’re using the cloud for calendar and contacts, they will be re- downloaded and stored back on your device automatically.
Dirty flash and Clean flash
A dirty flash is only wiping cache and davlik then flashing your ROM....
a Clean flash is at LEAST factory reset/data wipe + wiping davlik(factory wipe takes care of /cache also)... Maybe doing a format /system also.
ERRORS encountered in CWM Recovery
.
What is CWM Recovery ?
ClockworkMod Recovery is a custom recovery for many Android devices. It is considered to be the most popular recovery for Android due to its easily-ported nature, and integration with ClockworkMod ROM Manager by Koush(Koushik Dutta). The easiest way to recognize it is by the printed name when it first starts, and the background logo of a gear and hat.
Click to expand...
Click to collapse
ERROR STATUS 6
This is usually caused by CR/LF EOL(Windows style End Of Line) in updater-script. Change it to LF EOL(Unix Style EOL) using Linux command: dos2unix updater-script, then re-signing the ZIP, will usually fix this error.
Click to expand...
Click to collapse
ERROR STATUS 7
This is usually caused by a corrupt download, or bad file signature. Re-downloading (or re-signing) the ZIP will usually fix this.
Click to expand...
Click to collapse
We have been consistently seen and heard people facing error “Status 7″ error while trying to flash or install
custom ROMs or firmware packages on their Android smart phones or tablets with ClockworkMod Recovery. Many
of the users are nowadays facing this problem with CWM Recovery while flashing .zip files of modded or custom
Ice Cream Sandwich (ICS) or Jelly Bean (JB) ROMs on their devices. So, you have also downloaded a custom ROM,
placed its .zip file in your phone’s or tablet’s SD card, booted into ClockworkMod Recovery, selected – “install zip
from sdcard” and then chosen the .zip file of the ROM to get it installed on your device. But instead of getting
flashed successfully, if you are facing the issue mentioned below, then just keep reading this article to find out
what’s wrong and fix up the problem :
Finding update package…
Opening update package…
Installing update…
Error in /sdcard/custom-jelly-bean-rom.zip (Status 7)
Installation aborted
Click to expand...
Click to collapse
or the following error right after CWM recovery shows –
Installing update…
assert failed: getprop(“ro.product.device”) == “I9103″ || getprop(“ro.build.product”) == “I9103″ || getprop
(“ro.product.board”) == “I9103″
Error in /sdcard/android-4-1-1-ics-rom-latest.zip (status 7)
Click to expand...
Click to collapse
So, if you are facing any of these errors while trying to install the desired custom ROM package on your Android
phone or tab, then you may try a various things or steps which may turn out to be the workaround of this
problem. Here are a few tips to get this “Status 7” error fixed in ClockworkMod Recovery and flash the ROM
successfully on your device :
(1) First of all, make sure your device’s bootloader is unlocked. If it is already unlocked but you are still
not able to flash the ROM, then just extract the .zip file of the ROM into a new folder, find the boot.img file from
that directory and flash it up on your phone or tablet via fastboot on your PC.
(2) Make sure that you are having the appropriate Radio or Baseband version installed on your device which is
supported by the custom ROM you are trying to flash. Most of the ROMs requires the latest version of Baseband, so
just update or upgrade your device to the latest Baseband version and then try to install the ROM once again.
(3) Update your device to the supported / latest build of official firmware before trying to install the ROM. You can
do it from – Settings > About Phone / Device > Software Update.
(4) Make sure you are having the supported or required kernel installed on your phone or tab. If it’s not, then flash
a new kernel right away and try to install your custom ROM once again.
(5) Is the ROM which you are trying to flash really works ? Find out whether it is working for other users or not.
Click to expand...
Click to collapse
Error Status 0
Well sometimes while flashing some ROMs especially the cooked ones we get Error status 0 in the CWM Recovery
this error is an indicator of Wrong Update Binary.This is usually caused by an incompatible update-binary in edify ZIPs. Replacing it with a compatible one, then re-signing the ZIP, will usually fix this error.
Click to expand...
Click to collapse
Now it's time for the partitions :good:
Let’s start with a list of standard internal memory partitions on Android phones and tablets. These are:
/boot
/system
/recovery
/data
/cache
/misc
In addition, there are the SD card partitions.
/sdcard
/sd-ext
Note that only /sdcard is found in all Android devices and the rest are present only in select devices. Let’s now take a look at the purpose and contents of each of these partitions.
/boot
This is the partition that enables the phone to boot, as the name suggests. It includes the kernel and the ramdisk. Without this partition, the device will simply not be able to boot. Wiping this partition from recovery should only be done if absolutely required and once done, the device must NOT be rebooted before installing a new one, which can be done by installing a ROM that includes a /boot partition.
/system
This partition basically contains the entire operating system, other than the kernel and the ramdisk. This includes the Android user interface as well as all the system applications that come pre-installed on the device. Wiping this partition will remove Android from the device without rendering it unbootable, and you will still be able to put the phone into recovery or bootloader mode to install a new ROM.
/recovery
The recovery partition can be considered as an alternative boot partition that lets you boot the device into a recovery console for performing advanced recovery and maintenance operations on it. To learn more about this partition and its contents, see the ‘About Android Recovery’ section of our guide to ClockworkMod recovery.
/data
Also called userdata, the data partition contains the user’s data – this is where your contacts, messages, settings and apps that you have installed go. Wiping this partition essentially performs a factory reset on your device, restoring it to the way it was when you first booted it, or the way it was after the last official or custom ROM installation. When you perform a wipe data/factory reset from recovery, it is this partition that you are wiping.
/cache
This is the partition where Android stores frequently accessed data and app components. Wiping the cache doesn’t effect your personal data but simply gets rid of the existing data there, which gets automatically rebuilt as you continue using the device.
/misc
This partition contains miscellaneous system settings in form of on/off switches. These settings may include CID (Carrier or Region ID), USB configuration and certain hardware settings etc. This is an important partition and if it is corrupt or missing, several of the device’s features will will not function normally.
/sdcard
This is not a partition on the internal memory of the device but rather the SD card. In terms of usage, this is your storage space to use as you see fit, to store your media, documents, ROMs etc. on it. Wiping it is perfectly safe as long as you backup all the data you require from it, to your computer first. Though several user-installed apps save their data and settings on the SD card and wiping this partition will make you lose all that data.
On devices with both an internal and an external SD card – devices like the Samsung Galaxy S and several tablets – the /sdcard partition is always used to refer to the internal SD card. For the external SD card – if present – an alternative partition is used, which differs from device to device. In case of Samsung Galaxy S series devices, it is /sdcard/sd while in many other devices, it is /sdcard2. Unlike /sdcard, no system or app data whatsoever is stored automatically on this external SD card and everything present on it has been added there by the user. You can safely wipe it after backing up any data from it that you need to save.
/sd-ext
This is not a standard Android partition, but has become popular in the custom ROM scene. It is basically an additional partition on your SD card that acts as the /data partition when used with certain ROMs that have special features called APP2SD+ or data2ext enabled. It is especially useful on devices with little internal memory allotted to the /data partition. Thus, users who want to install more programs than the internal memory allows can make this partition and use it with a custom ROM that supports this feature, to get additional storage for installing their apps. Wiping this partition is essentially the same as wiping the /data partition – you lose your contacts, SMS, market apps and settings.
With this, we conclude our tour of Android partitions. Now whenever you install a ROM or mod that requires you to wipe certain partitions before the installation, you should be in a better position to know what you’re losing and what not and thus, you’ll know what to backup and what not.
ADB-Android Debugging 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.
You can find the adb tool in <sdk>/platform-tools/.
When you start an adb client, the client first checks whether there is an adb server process already running. If there isn't, it starts the server process. When the server starts, it binds to local TCP port 5037 and listens for commands sent from adb clients—all adb clients use port 5037 to communicate with the adb server.
Click to expand...
Click to collapse
The server then sets up connections to all running emulator/device instances. It locates emulator/device instances by scanning odd-numbered ports in the range 5555 to 5585, the range used by emulators/devices. Where the server finds an adb daemon, it sets up a connection to that port. Note that each emulator/device instance acquires a pair of sequential ports — an even-numbered port for console connections and an odd-numbered port for adb connections. For example:
Emulator 1, console: 5554
Emulator 1, adb: 5555
Emulator 2, console: 5556
Emulator 2, adb: 5557
and so on...
As shown, the emulator instance connected to adb on port 5555 is the same as the instance whose console listens on port 5554.
Once the server has set up connections to all emulator instances, you can use adb commands to access those instances. Because the server manages connections to emulator/device instances and handles commands from multiple adb clients, you can control any emulator/device instance from any client (or from a script).
Note: When you connect a device running Android 4.2.2 or higher to your computer, the system shows a dialog asking whether to accept an RSA key that allows debugging through this computer. This security mechanism protects user devices because it ensures that USB debugging and other adb commands cannot be executed unless you're able to unlock the device and acknowledge the dialog. This requires that you have adb version 1.0.31 (available with SDK Platform-tools r16.0.1 and higher) in order to debug on a device running Android 4.2.2 or higher.
Syntax
You can issue adb commands from a command line on your development machine or from a script. The usage is:
adb [-d|-e|-s <serialNumber>] <command>
If there's only one emulator running or only one device connected, the adb command is sent to that device by default. If multiple emulators are running and/or multiple devices are attached, you need to use the -d, -e, or -s option to specify the target device to which the command should be directed.
LOGCAT
The Android logging system provides a mechanism for collecting and viewing system debug output. Logs from various applications and portions of the system are collected in a series of circular buffers, which then can be viewed and filtered by the logcat command. You can use logcat from an ADB shell to view the log messages.
-b <buffer> Loads an alternate log buffer for viewing, such as event or radio. The main buffer is used by default. See Viewing Alternative Log Buffers.
-c Clears (flushes) the entire log and exits.
-d Dumps the log to the screen and exits.
-f <filename> Writes log message output to <filename>. The default is stdout.
-g Prints the size of the specified log buffer and exits.
-n <count> Sets the maximum number of rotated logs to <count>. The default value is 4. Requires the -r option.
-r <kbytes> Rotates the log file every <kbytes> of output. The default value is 16. Requires the -f option.
-s Sets the default filter spec to silent.
-v <format> Sets the output format for log messages. The default is brief format. For a list of supported formats, see Controlling Log Output Format.
awesome thread to learn everything in a quick while
Again.? :good:
But highlight the Status error with big & bold font.
Disturbed™ said:
Again.? :good:
But highlight the Status error with big & bold font.
Click to expand...
Click to collapse
I think he's trying to take over XDA
But just to keep this on topic, great thread for those who are learning and aren't sure what certain things are for.
I guess I'll have to make another thread in this forum just so other RCs don't take all the ideas
SGS2 FAQ | HTC One FAQ
KidCarter93 said:
I think he's trying to take over XDA
But just to keep this on topic, great thread for those who are learning and aren't sure what certain things are for.
I guess I'll have to make another thread in this forum just so other RCs don't take all the ideas
SGS2 FAQ | HTC One FAQ
Click to expand...
Click to collapse
Lolzzz.. Yes buddy. He is something else.
Collecting Informations & useful stuff for all users. May be in near future, he will take over XDA.
It's all your love guys. Sometimes even my guides correct my mistakes!
Started from the bottom
Guys if you like this thread please press the tip us button so that more and more people who are willing to learn about android phone and how they work can get help.
I will be grateful to you all.
Started from the bottom
Very nice write up TechnoCrat :good::good::good:
TEAM MiK
MikROMs Since 3/13/11
Long way to go mate!
Congo! This thread got featured on XDA Portal
http://www.xda-developers.com/android/android-101-how-it-all-fits-together/
Thank you very much. I needed this definition thread. I kinda understand but it'd nice to hear official language that's understandable.
Sent from that FBI van parked down the street.
Thanks for the CWM errors write up and another bookmark.
Tha TechnoCrat said:
i. The kernel.
If you’re feeling exceptionally geeky, plug your Android phone into the USB port on your PC and let the PC boot from the USB device. No, it doesn’t actually load, but you can watch the animation while it tries to match up the hardware support with what’s inside your PC
Click to expand...
Click to collapse
What. The. Hell. Are you talking about?
If you mean booting the device's kernel on the PC, unless the device uses an x86 processor, it flat out will not boot, let alone mount the device's system, to display the bootanimation.zip
/snarkieness
Sorry, I had to let that out.
Also, init is called/started after the kernel has started, and generally after it has setup most of the hardware.
so I’ll simply say that DalvikVM is a register-based machine versus true JavaVMs which are stack based.
Click to expand...
Click to collapse
I don't even truly understand that, so could add a little more detail, or remove it?
I'm speaking mostly from my implied knowledge, gained from tinkering with android/linux for a few years.
ADB and Logcat added
Hey, Thanks for the article. Can you talk about root? There is some mis-leading information and I really want to learn about it. Thanks again.
ak700 said:
Hey, Thanks for the article. Can you talk about root? There is some mis-leading information and I really want to learn about it. Thanks again.
Click to expand...
Click to collapse
Okay buddy
Editone! !!
"Thanks button is just to avoid "THANKS" posts in threads. Nothing more than that. Don't ask in signature or post for it and defeat the purpose why it was introduced"
Bump to update newbies
"Thanks button is just to avoid "THANKS" posts in threads. Nothing more than that. Don't ask in signature or post for it and defeat the purpose why it was introduced"

Java for the command line?

A little background info:
I got SL4A and Py4A and then ran the standalone script to run python from the command line over adb or ssh, but the Android api's wouldn't work. Cause, SL4A server needs to be running and python needs to be able to send info to the server via AP_PORT and AP_HOST with a socket. I don't like the normal "remoting" that is used, ie only the Android APIs gets sent over to android and the rest of python is running on my pc.
What I did to work around was export AP_PORT(54326) and AP_HOST(127.0.0.1) on Androids shell over ADB, then I use "am" to start the server activity from the command line specifying the port(54326), then I started adbd on my phone, and finally I executed python. From python (on the actual device) I imported android and asigned droid = you know the drill, and next (this would usually fail if the previous steps were not done) I did a "droid.makeToast("Hello from Montey!" ) and the toast appeared. The reason for wanting to do it this way is that you dont need to run scripts with Py4A's terminal, the scripts can now be run directly from Android's command line over adb or ssh. It may not appeal to you but it does to me.​
What I want to do:
I want to cherry pick the Java code for the server activity and the facade classes/functions that give python access to the Android api's, and I want to compile them into a form ( I think it would be a dex file) that I could execute from Android's command line and would use shared memory instead of a socket to share data. This way, I would not have to start a gui activity or adbd.​
So how do I go about this, I have the source code, I see how it works and what I need to pick from it, how would I compile this so that is would run on the dalvikvm as a command line app?
I found this amongst a bunch of stuff on dex2jar but all that is the opposite of what I wanted.
http://www.cs.duke.edu/~schfan/blog/blog/2013/09/19/executing-dex-file-in-android/
So I will do hello world as java to dex and see if it works on the cmd-line. If yes, then proceed to try and use Android's api's as a regular Java project (I hate xml, it's a great concept, but it just bugs out my projects, almost gave up Android dev because of xml glitches, but Android is really the only thing worth programming to me at the moment, sensors and all that.), build, if success then to dex.
I will try vanilla at first, with very little mods, then I will switch to ashmem if that works it's much better since I am not expecting to send this data remotely, but it should stay on the phone unless I have a good reason to send it to another machine, I can, and do, always remote to my phone itself.
Then I will try to get the camera to work, I have had the issue that only the interactive facade works with python, I want to use OpenCV and have a go at object recongnition. I will probably translate it all to C/C++ after I see the concepts working with python (purely for performance reasons, my application will have approxamatly 16 milliseconds (or less) to respond to events, so it better tick quick, I m using 60 frames per second model, but I don't need to render anything, I just need to store the data of the objects it detects in a database.).
Edge-Case said:
I found this amongst a bunch of stuff on dex2jar but all that is the opposite of what I wanted.
http://www.cs.duke.edu/~schfan/blog/blog/2013/09/19/executing-dex-file-in-android/
So I will do hello world as java to dex and see if it works on the cmd-line. If yes, then proceed to try and use Android's api's as a regular Java project (I hate xml, it's a great concept, but it just bugs out my projects, almost gave up Android dev because of xml glitches, but Android is really the only thing worth programming to me at the moment, sensors and all that.), build, if success then to dex.
I will try vanilla at first, with very little mods, then I will switch to ashmem if that works it's much better since I am not expecting to send this data remotely, but it should stay on the phone unless I have a good reason to send it to another machine, I can, and do, always remote to my phone itself.
Then I will try to get the camera to work, I have had the issue that only the interactive facade works with python, I want to use OpenCV and have a go at object recongnition. I will probably translate it all to C/C++ after I see the concepts working with python (purely for performance reasons, my application will have approxamatly 16 milliseconds (or less) to respond to events, so it better tick quick, I m using 60 frames per second model, but I don't need to render anything, I just need to store the data of the objects it detects in a database.).
Click to expand...
Click to collapse
Please report if you are successful.
(You can also design UIs in Java. It takes very much time though.)
nikwen said:
Please report if you are successful.
(You can also design UIs in Java. It takes very much time though.)
Click to expand...
Click to collapse
Absolutly. I am using FreeBSD now insead of Linux, that being said their is near zero support for Android development on Unix OS's as of yet, which really makes no ****ing sense, why try hard as hell to use BSD/Apache2 liscenced code only to build it with GNU and GPL style licenced tools? Makes no ****ing sense, as far as I know, some gpl's require byproducts of their code to also be gpl licenced. Anyways... I am building eclipse right now, I downloaded the Android SDK for linux so I try and use the dx executable but it wasn't there and when I attempted to update the sdk, it said "platform-tools" unavailable. So thats that unless it gets ported to FreeBSD. I may be able to do it on my phone though, but please be patient, it may take till tomorrow or later tonight, thank go some-one ported adb to FreeBSD though, well, there is always ssh and sftp.
UpDate:
TerminalIDE has dx, so I can just add that /data/data/com.sparti******/bin directory to my path and I may be able to develope directly on my device, though I here the C/C++ compiler that is there doesn't work properly, maybe it's ok and I wont need what doesn't work.
Edge-Case said:
Absolutly. I am using FreeBSD now insead of Linux, that being said their is near zero support for Android development on Unix OS's as of yet, which really makes no ****ing sense, why try hard as hell to use BSD/Apache2 liscenced code only to build it with GNU and GPL style licenced tools? Makes no ****ing sense, as far as I know, some gpl's require byproducts of their code to also be gpl licenced. Anyways... I am building eclipse right now, I downloaded the Android SDK for linux so I try and use the dx executable but it wasn't there and when I attempted to update the sdk, it said "platform-tools" unavailable. So thats that unless it gets ported to FreeBSD. I may be able to do it on my phone though, but please be patient, it may take till tomorrow or later tonight, thank go some-one ported adb to FreeBSD though, well, there is always ssh and sftp.
UpDate:
TerminalIDE has dx, so I can just add that /data/data/com.sparti******/bin directory to my path and I may be able to develope directly on my device, though I here the C/C++ compiler that is there doesn't work properly, maybe it's ok and I wont need what doesn't work.
Click to expand...
Click to collapse
Why FreeBSD instead of Linux? (Feeling like these Windows guys who always ask "Why Linux instead of Windows?" :laugh
nikwen said:
Why FreeBSD instead of Linux? (Feeling like these Windows guys who always ask "Why Linux instead of Windows?" :laugh
Click to expand...
Click to collapse
Because I like little devils.
I rebooted to Linux, just now Figure better not torture myself just yet.
Update:
Code:
[email protected]:~/Projects/Java-stuff/drd-hello-cmdln$ adb shell ANDROID\_DATA=/sdcard dalvikvm -cp /sdcard/HelloWorld.zip HelloWorld
Hello World!
hmmm, but I shelled in with adb and realized I need to do some more studying...
This is just a bit of me fiddling around with the HelloWorld.zip and the resulting cache...
Code:
[email protected]:/data/local/mi/dalvik-cache # ll
-rwxr-xr-x root sdcard_rw 1768 2013-11-23 14:52 [email protected]@classes.dex
[email protected] <
./[email protected]@classes.dex[1]: dey: not found
./[email protected]@classes.dex[2]: syntax error: '�' unexpected
[email protected] <
Dalvik VM unable to locate class '[email protected]/[email protected]/dex'
java.lang.NoClassDefFoundError: [email protected]/[email protected]/dex
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "[email protected]@classes.dex" on path: .
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
... 1 more
1|[email protected]:/data/local/mi/dalvik-cache # dalvikvm ./[email protected]>
Dalvik VM unable to locate class '//[email protected]/[email protected]/dex'
java.lang.NoClassDefFoundError: //[email protected]/[email protected]/dex
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "[email protected]@classes.dex" on path: .
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
... 1 more
1|[email protected]:/data/local/mi/dalvik-cache # cd /sdcard/
[email protected]:/sdcard # dalvikvm ./HelloWorld.zip
Dalvik VM unable to locate class '//HelloWorld/zip'
java.lang.NoClassDefFoundError: //HelloWorld/zip
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "..HelloWorld.zip" on path: .
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
... 1 more
I am more or less after an executable that can serve the Android API and be ran from the command-line in the background...
perhaps JNI and NDK is what I need....i dunno...
Maybe at that point, python itself might be able to be modified to access the API via JNI?
Update:
Perhaps, I need to try this without changing the default DATA variable, perhaps then the cached thing will be in the path and executable. If the cached thing is executable and functions as expected, eg echos "Hello World", then maybe I can create a symbolic link to the cached executable.... ( I am just shooting blind here ).
Update:
I tried TerminalIDE's method for compiling the java code and running it on the command line, it works just fine. So now I will try to use that method to convert the facade rpc server into a command line application, I am thinking that I will write a shell script that calls it in the right way with the right flags and just name it facaded or something and put that in /system/xbin/ . For now it will still need to use sockets and adbd, because using ashmem in a service requires it to be noted as a line of code in the service manger's source and then baked into the rom.

AppcertDLLs do not work in GUI apps

Hi, I was trying to automatically inject a dll to every process (including GUI) whenever it is started by a user . My DLL hooks DoDragDrop method of winapi and communicates with server to decide allow or disallow the drag & drop process. I use easyhook (particularly [this] for hooking part. I created a gist for my code : [Gist]
In [this ]url it says: Doesn’t work reliably against GUI applications. Stick to console apps. No wonder it didn't work in microsoft edge, and chrome.
I also tried code parts in these urls:
[first]
[second]
Finally , I already [certificated ]my dll.
Is there any other way apart from appcertdlls? Thank you in advance.
Edit: I can't use appinitdlls, some users might have secure boot enabled.
Edit2: Seems like dlls in some tutorials is under system32 ([this], and [this]) , and I moved mine under system32 too, but it did
work.

Enable KVM on Oneplus 5 ?

Hi all,
I'm currently in front of a problem, and after a lot of tries and readings I decided to ask people.
As I'm a beginner, let me know if I'm not posting on the right place or if I'm saying stupidities.
My final goal is to install Home Assistant Operating System on my old Oneplus 5 phone.
This is the kind of stuff you usually do on a Raspberry, but I wanted to find a new usage of my phone.
Long story short, I've installed via Userland app Ubuntu 20.04 in order to create a VM on KVM as it seemed to be a good option to achieve my goal.
(I've also tried Termux but didn't seem to be as complete as Userland)
I ran a command to know if my CPU would support virtualization (kvm-ok) and I had this error :
Code:
INFO: /dev/kvm does not exist
HINT: sudo modprobe kvm
modprobe: FATAL: Module msr not found in directory /lib/modules/4.4.302-perf+
From what I understood, this issue comes from the fact that most phones do not have kvm enabled by constructors.
I wondered if the solution would be to modify the kernel ?
I found this but I'm not sure : https://github.com/android-linux-stable/op5
If someone has ever encountered this kind of problematic let me know.
If you have any other alternative, don't hesitate to share.
Some details about the device :
LineageOS 19-20221205-NIGHTLY-cheeseburger
custom BL TWRP
Magisk installed
For those who know Home Assistant, I succeeded to follow this tutorial, but it doesn't install a full version of it I wanted to try to install the OS.
Home Assistant Core on Android Tablet
You need install rust and cargo first: pip install rust pip install cargo run: rustc -vV | sed -n 's|host: ||p' it returns target system, something like: armv7-linux-androideabi copy it and set to cargo running: export CARGO_BUILD_TARGET=armv7-linux-androideabi then run: pip install...
community.home-assistant.io
Thanks !
cooldino said:
Hi all,
I'm currently in front of a problem, and after a lot of tries and readings I decided to ask people.
As I'm a beginner, let me know if I'm not posting on the right place or if I'm saying stupidities.
My final goal is to install Home Assistant Operating System on my old Oneplus 5 phone.
This is the kind of stuff you usually do on a Raspberry, but I wanted to find a new usage of my phone.
Long story short, I've installed via Userland app Ubuntu 20.04 in order to create a VM on KVM as it seemed to be a good option to achieve my goal.
(I've also tried Termux but didn't seem to be as complete as Userland)
I ran a command to know if my CPU would support virtualization (kvm-ok) and I had this error :
Code:
INFO: /dev/kvm does not exist
HINT: sudo modprobe kvm
modprobe: FATAL: Module msr not found in directory /lib/modules/4.4.302-perf+
From what I understood, this issue comes from the fact that most phones do not have kvm enabled by constructors.
I wondered if the solution would be to modify the kernel ?
I found this but I'm not sure : https://github.com/android-linux-stable/op5
If someone has ever encountered this kind of problematic let me know.
If you have any other alternative, don't hesitate to share.
Some details about the device :
LineageOS 19-20221205-NIGHTLY-cheeseburger
custom BL TWRP
Magisk installed
For those who know Home Assistant, I succeeded to follow this tutorial, but it doesn't install a full version of it I wanted to try to install the OS.
Home Assistant Core on Android Tablet
You need install rust and cargo first: pip install rust pip install cargo run: rustc -vV | sed -n 's|host: ||p' it returns target system, something like: armv7-linux-androideabi copy it and set to cargo running: export CARGO_BUILD_TARGET=armv7-linux-androideabi then run: pip install...
community.home-assistant.io
Thanks !
Click to expand...
Click to collapse
To install Home Assistant Operating System (HASSIO) on your Oneplus 5 phone, you will need to follow these steps:
First, make sure that your phone is rooted. Rooting your phone will allow you to install custom operating systems on it. There are various tutorials and tools available online that can help you root your Oneplus 5 phone.
Once your phone is rooted, you will need to install a custom recovery such as TWRP (TeamWin Recovery Project). This will allow you to boot into a custom recovery environment and install HASSIO on your phone.
Download the HASSIO image file for your phone from the Home Assistant website or from a third-party source.
Hamzagujjar said:
To install Home Assistant Operating System (HASSIO) on your Oneplus 5 phone, you will need to follow these steps:
First, make sure that your phone is rooted. Rooting your phone will allow you to install custom operating systems on it. There are various tutorials and tools available online that can help you root your Oneplus 5 phone.
Once your phone is rooted, you will need to install a custom recovery such as TWRP (TeamWin Recovery Project). This will allow you to boot into a custom recovery environment and install HASSIO on your phone.
Download the HASSIO image file for your phone from the Home Assistant website or from a third-party source.
Click to expand...
Click to collapse
My phone is rooted and I've already installed TWRP.
I think there is no HASSIO image file for phones in general.
Could you detail this part ?
Thanks

Categories

Resources