Pages

Showing posts with label virtual. Show all posts
Showing posts with label virtual. Show all posts

Friday, April 15, 2016

The Android ION Memory Manager

Lately theres been quite a bit of discussions about Android "ION". What exactly is ION? Is it just some fancy name or is there more to it?

Lets talk about some history of Android first.

Since the very beginning, vendors of Android devices like HTC, Samsung or Motorola all use different System on a Chip (SoC) solutions from Qualcomm (MSM/Snapdragon), Nvidia (Tegra) and TI (OMAP). Each SoC has its own kernel drivers for managing memory buffers (chunks of scratchpad memory) used by Graphic Processing Unit (GPU), Audio processing, and Camera Stills and Video processing.

Every vendor had their own version of memory management, such as PMEM for Qualcomm, NVMAP for Nvidia and CMEM for TI - private memory not shared with anyone else. Each Android graphics, audio and camera libraries had to be customized to work with each of the SoCs own flavour of memory management, which makes it a nightmare for the Android Maintainers to maintain the fragmentation and compatibility issues abound. However, this was the case for all pre-Ice Cream Sandwich OS like Froyo, Gingerbread or even Honeycomb.

For Android 4.0 (aka Ice Cream Sandwich), Google was finally fed up with the private memory manager structure and decreed that all newer devices with Android 4.0 native should use the new, so called "ION" memory manager.

So what is exactly the Android ION?

In a simple words, Android ION removes ARM specific dependencies. The ION memory manager provides a common structure for how memory will be managed and used by GPU, Audio and Camera drivers. Common functions are:

  • memory allocation / de-allocation
  • Direct Memory Access Pools
  • user-space (Android libraries) memory passing to/from kernel space

With these common functions and structures defined, kernel drivers from each SoC manufacturer needed to rewrite their drivers to be compatible with Ice Cream Sandwich. Once the drivers adopted to the new common structure, the graphics, audio and camera libraries can now be more generic and could care less about the nitty-gritty details of how different SoC vendors drivers worked.

It was painful at first, but it was a necessary move for Google to impose to all the SoC vendors. Now looking back, this new ION manager enabled manufactures and third party Android projects (like Cyanogen-mod) to quickly bring up newer Android releases for various devices and also reduce the "hidden" Android fragmentation.

If you want to take a look at the code of the ION memory manager, please visit faux123 github - MSM ION

I hope you enjoyed my first Kernel GeekTalk series... more to come soon!

Have any questions or comments? Feel free to share! Also, if you like this article, please use the media sharing buttons (Twitter, G+, Facebook) under this post!
Read More..

Thursday, April 14, 2016

Virtual SD card on Android


Since Android Honeycomb, Google changed the way to manage internal memory on Android devices. Before Honeycomb, every user had one separate partition on his device called userdata (/data), where he could install applications and where all user settings were stored (home screens, applications data, contacts, and all the rest you loose after doing so called "full wipe" on your device). Apart of userdata partition, all Android devices had microSD card slot to save pictures, movies, backups etc.. Now it looks completely different, but lets start from the beginning. There are several approaches to this subject, Ill present here all those I am aware of.


  • userdata partition + microSD card

This is the mentioned above pre-Honeycomb approach. There is userdata partition, where you can install all your applications and you also have a possibility to insert microSD card. Nothing more to explain. Only devices running Android Gingerbread and older versions have such configuration, so its getting less and less popular.


  • userdata partition + virtual SD card on userdata partition

This is the new approach presented for the first time in Honeycomb. Instead of having /data partition together with expandable microSD card slot of any capacity, Google decided for something different. Instead, /data partition became very large (16/32/64 GB) and inside you can find /data/media folder that contains all the files you can see as your SD card content. How does it work? Without too much technical explanations, there is so called fuse tool which emulates media folder inside userdata partition as a separate storage device. As a result, after connecting smartphone to the PC you can browse the content of /data/media location, so if it was a microSD card. The biggest downside of such approach is a high risk of loosing all your virtual SD card content in case of any serious /data partition failure. Also, such partition cant be formatted with mkfs.ext4 without loosing content of virtual SD card, because you cant format device partition just partially. You can use e2fsck tool to check for potential errors, but sometimes partition format is the only way out. How does "full wipe" work then? Well, its a little bit complicated. First of all, you cant format mounted (in use) partition. You need to unmount it first. Once unmounted userdata partition, you cant flash any ZIP file from inside recovery, because ZIPs files are stored on virtual SD card (/data/media) and remember that userdata partition is currently unmounted, because we want to format it. There is a workaround for it - you can run mkfs.ext4 from inside /cache partition or you can use command prompt. Now, what if you need to remove the whole content of your userdata partition, but you want to keep virtual SD card content at the same time? There is a workaround for this as well, but instead of formatting entire partition, you need to remove all files excluding /data/media location. Example:

#!/tmp/bash
# Remove content of /data partition excluding data/media files
cd /data
FILES=(*)
for i in *; do
if [ "$i" != "media" ]
then rm -R "$i"
fi
done


This way you can sort of wipe userdata, but it doesnt format the partition, so you cant fix broken file-system with it.  Why this point is the longest one? Because it took me quite a few words to explain the relation between virtual SD card and media folder on userdata partition (/data/media). So basically, what you read here applies to every configuration with virtual SD card emulated on userdata partition.


  • userdata partition + virtual SD card on a separate partition

This approach is not very popular, and its a shame because it seems to be much more practical rather than the previous one. Instead of emulating SD card from userdata partition, there is a separate, large partition with vFAT file-system. That means you can format your userdata partition anytime you want without loosing content of your virtual SD card, or from inside custom ROM, because userdata can be freely unmounted. The only device Ive seen so far with this approach was HTC One X.


  • userdata partition + virtual SD card on userdata partition + microSD card

This seems to be the most desirable solution for many Android users. It works similar to approach described in the second point, so everything I wrote about /data/media is valid here as well. However, every user have the ability to insert extra microSD card inside his device, so he can easily backup virtual SD card to microSD card or format userdata partition without loosing all pictures etc. (if previously stored on microSD card). This is the most common configuration for Samsung devices. But having removable microSD card is not only an advantage. First of all, any kind of microSD card (even SDHC) will be always slower than internal eMMC memory. It depends on many factors like card speed (class 2, 4, 6, 8 or even 10), on-board controller, I/O scheduler and more. Secondly, microSD card damage risk is higher then damage risk of internal eMMC memory. Out of question is the benefit to expand the memory with 64 GB microSD card, but its definitely the minority of power users, who are buying large capacity cards. For the vast majority of users, internal memory with 32 GB capacity is more then enough to store their favorite music or pictures.


  • userdata partition + virtual SD card on a separate partition + microSD card

This approach is theoretically possible, but personally Ive never seen device with such combination. For me, this is the best combination. You have possibility to use external microSD card and virtual SD card is not a part of userdata partition, but it has its own, separate vFat partition. Such configuration gives you control over all your data and possibility to manage it however you want.

Do you have any questions or want to share some opinion? Please leave a comment below! Also, if you like this article, please use media sharing buttons (Twitter, G+, Facebook) down this post!



Read More..

Monday, March 21, 2016

Runtastic on Android Wear


By Austin Robison, Product Manager, Android Wear




Fitness apps make  great additions to Android Wear. Let’s take a look at one of our favorites, Runtastic. Runtastic is a fitness app that lets you track your walks, runs, bike rides and more. With Runtastic on Android Wear, youll see your time, distance, and calories burned at a glance on your wrist. You can also start, stop and pause your activity by touch. Tuck your phone away in a pocket or backpack and do everything on your watch.


Its challenging to build user experiences that really come alive on Android Wear because its such a new type of device. Runtastic does a great job of showing the right information and providing just the right controls on the screen on your wrist. Lets dig into some of the Android Wear platform features that Runtastic uses to make such a great user experience.

Voice Actions

Android Wear enables developers to launch their activities with voice. Runtastic responds to “Ok Google, start running” by beginning to track a session and displaying a card with your total time. This means you can start exercising without needing to pull your phone out of a pocket or arm strap. Android Wear is all about bringing you useful information just when you need it and enabling users to quickly and easily take action.


runtastic_01.png


Responding to platform voice intents on Wear is as simple as declaring a standard intent filter to start an activity.  For example, to launch your activity for the “start running” voice action, add the following to your activity’s entry in your AndroidManifest.xml:


<intent-filter>
   <action android_name="vnd.google.fitness.TRACK"/>
   <category android_name="android.intent.category.DEFAULT"/>
   <data android_mimeType="vnd.google.fitness.activity/running"/>
</intent-filter>


Custom Cards

Once a user has started a run, Runtastic inserts a card in the stream as an ongoing notification to ensure it is ranked near the top of the stream during the activity. This card uses the setDisplayIntent() function to display custom UI. It provides quick, glanceable information, showing your activity time. Cool!


When the user swipes to the right of the card to expose its actions, we see some quick and easy to understand options; following the Android Wear style guidelines means that Runtastic has a familiar UI and feels like a natural extension of the watch. There are actions for pausing, stopping, and an action to see more details on the run.  This action launches a full screen Activity where Runtastic draws a completely custom layout.




You’ll notice this data updates live; Runtastic makes use of the Wearable Data Layer API in Google Play Services to synchronize data between the phone and the watch. Its an easy to use API for syncing data between your devices.


Background Services

When a user finishes their run, Runtastic presents them with a special summary card that appears only on the watch. In this case, the notification is generated directly on the watch by a Service. This Service uses the Data Layer to receive information about the completed activity from the phone to the watch, including an image of a map of the user’s run generated through the Google Maps API.


To show that information, the app uses Android Wear’s NotificationManager, which functions just like the NotificationManager on a phone or tablet, except that instead of creating notifications in the pull-down shade, they appear in the stream.




Runtastics implementation on Android Wear is a perfect example of how to take advantage of wearables to make something truly useful for users. For more information on these and other great platform features, please see the developer documentation.


For more inspiring Android Wear user experiences, check out this collection on the Play Store!


Posted by Mano Marks, Google Developer Platform Team
Read More..

Saturday, February 20, 2016

How to Fix no access to the virtual SD card after Android Lollipop update


This solution is based on the experience with some HTC and Nexus devices, however it will work on any device running Android Lollipop or newer/older Android OS with SELinux (Security-Enhanced Linux) kernel security module.

Whats the problem? Sometimes you might not be able to access the content of the internal userdata memory, also known as "virtual SD card" - located as /data/media/0 on the userdata partition. The "bad" workaround is to boot the device in a recovery mode and gain the access to all files from there, but this doesnt solve the problem at all.

Repair Process
Note: root required!
  1. Download this mini-sdk package and extract it to c:mini-sdk
  2. Connect your device to the PC
  3. Start up the device normally, wait until system is fully loaded
  4. Open a command prompt on the PC (cmd.exe), type and confirm each command with ENTER:
  5. cd /d c:mini-sdk
  6. adb shell
  7. su
  8. restorecon -FR /data/media/0
  9. exit
Whats going to happen? Restorecon is a program used to restore file(s) default SELinux security contexts. It can be run at any time to correct errors or to add support for new policy. With a corrected SELinux security context for the /data/media/0 you will be able to access the content of the virtual SD card again.

Do you have any questions or comments? Feel free to share! Also, if you like this article, please use media sharing buttons (Twitter, G+, Facebook) below this post!


For latest news follow Android Revolution HD on popular social platforms:

Read More..