Sunday, September 28, 2014

applications - Check what storage an app uses?


Is there a way to check what storage a third party application is using? i.e which of these it uses?




Answer



If you are rooted, this is quite easy to find out.


First you need to find the app's package name, e.g. com.swype.android.inputmethod for Swype, or com.google.android.apps.maps for Google Maps, for example. You can usually search for the app in Android Market, and the link will contain its package name, e.g. https://market.android.com/details?id=com.google.android.apps.maps would be the link to Google Maps. Usually the package names are descriptive enough that you can simply guess which app they represent just by looking at it.


You can do a few simple ls commands in Terminal Emulator or ADB shell to find out the app's name, and where it's stored. However, you will need to have root access to the device since app and data storage is protected.


Pre-installed apps are generally located in /system/app directory. Use the command ls -l /system/app/ to find how much space a particular system app is taking up:


ls -l /system/app/Browser.*
-rw-r--r-- root root 418098 2011-06-26 01:05 Browser.apk
-rw-r--r-- root root 472760 2011-06-26 01:05 Browser.odex

On most Stock ROMs you will see an .odex file along with a .apk file for each app - those are pre-compiled binaries optimized for your given device. You cannot remove them.



3rd-party apps are installed to /data/app or /data/app-private directories. Command ls -l /data/app/[package_name_here]* should return the amount of space taken up by this app on internal memory. For example, here's the output of looking at Google Maps apk:


# ls -l /data/app/com.google.android.apps.maps*
ls -l /data/app/com.google.android.apps.maps*
-rw-r--r-- system system 6330104 2012-02-04 09:01 com.google.android.apps.maps-2.apk

The app data and settings are located on /data/data/ partition. There you will find a directory for each installed app, e.g. /data/data/com.google.android.apps.maps/ for preferences and settings related to the Google Maps app. Again, ls -l /data/data/com.google.android.apps.maps/* will return a listing of all files with their sizes:


# ls -l /data/data/com.google.android.apps.maps/*
ls -l /data/data/com.google.android.apps.maps/*
-rw------- app_189 app_189 3783 2012-02-07 11:29 mobilemaps.clients.google.com.443
-rw------- app_189 app_189 37 2012-02-01 16:14 nlp_GlsPlatformKey

-rw------- app_189 app_189 208 2012-02-07 11:21 macs
drwxrwx--x app_189 app_189 2012-02-01 16:14 webviewCache
-rw------- app_189 app_189 2450 2012-02-07 11:21 nlp_state
drwx------ app_189 app_189 2012-02-01 16:14 selectors
-rw------- app_189 app_189 290 2012-02-07 11:21 nlp_devices
drwx------ app_189 app_189 2012-02-01 16:14 models
-rw-rw---- app_189 app_189 18432 2012-02-03 13:29 google_analytics.db
-rw-rw---- app_189 app_189 5120 2012-02-07 10:38 google_latitude.db
-rw-rw---- app_189 app_189 6144 2012-02-01 16:14 webviewCache.db
-rw-rw---- app_189 app_189 5120 2012-02-05 17:27 local_active_places.db

-rw-rw---- app_189 app_189 4096 2012-02-05 17:27 da_destination_history
-rw-rw---- app_189 app_189 5120 2012-02-05 17:49 LayerInfo
-rw-rw---- app_189 app_189 5120 2012-02-05 17:26 search_history.db
-rw-rw---- app_189 app_189 6144 2012-02-03 13:29 userfeedback.db
-rw-rw---- app_189 app_189 14336 2012-02-01 16:14 webview.db
-rw-rw---- app_189 app_189 38 2012-02-07 11:13 DATA_SYNC_DATA_LOCAL
-rw-rw---- app_189 app_189 26756 2012-02-01 16:31 DATA_PHOTO_145479516184369608
-rw-rw---- app_189 app_189 26756 2012-02-01 16:31 DATA_PHOTO_4406538396446325405
-rw-rw---- app_189 app_189 1813 2012-02-05 13:48 DATA_PROTO_CLIENT_SAVED_PHOTO_CACHE
-rw-rw---- app_189 app_189 338 2012-02-06 23:41 DATA_TILE_HISTORY

-rw-rw---- app_189 app_189 12 2012-02-05 17:49 DATA_SAVED_REMOTE_ICONS_DATA_BLOCK
-rw-rw---- app_189 app_189 36580 2012-02-01 16:14 DATA_RemoteStringsBlock_en
-rw-rw---- app_189 app_189 26756 2012-02-01 16:31 DATA_PHOTO_240647554975296207
-rw-rw---- app_189 app_189 26756 2012-02-01 16:31 DATA_PHOTO_443613581827136957
-rw-rw---- app_189 app_189 5620 2012-02-05 17:49 DATA_SAVED_BGFS_3
-rw-rw---- app_189 app_189 57 2012-02-05 17:49 DATA_STARRING
-rw-rw---- app_189 app_189 573 2012-02-05 10:04 NavZoomTables.data
-rw-rw---- app_189 app_189 26756 2012-02-01 16:31 DATA_PHOTO_-7991748045000310303
-rw-rw---- app_189 app_189 217 2012-02-05 15:29 DATA_LAYER_4
-rw-rw---- app_189 app_189 26756 2012-02-01 16:14 DATA_PHOTO_-4352347968798340772

-rw-rw---- app_189 app_189 26756 2012-02-01 16:31 DATA_PHOTO_-1960244636679913737
-rw-rw---- app_189 app_189 26756 2012-02-01 16:31 DATA_PHOTO_7546641620697631512
-rw------- app_189 app_189 34 2012-02-07 11:21 nlp_clts
-rw-rw---- app_189 app_189 2492 2012-02-07 11:30 DATA_location_history
-rw-rw---- app_189 app_189 11 2012-02-01 16:14 DATA_LAYER_0
-rw-rw---- app_189 app_189 1186 2012-02-01 16:14 ZoomTables.data
-rw-rw---- app_189 app_189 11 2012-02-05 17:49 DATA_SAVED_BGFS_EXTRA_3
-rw-rw---- app_189 app_189 18994 2012-02-05 17:49 DATA_PROTO_SAVED_CATEGORY_TREE_DB
-rw-rw---- app_189 app_189 247 2012-02-05 17:49 event_store_v2_driveabout
-rw-rw---- app_189 app_189 5294 2012-02-05 10:05 DA_LayerInfo

-rw-rw---- app_189 app_189 380 2012-02-05 16:23 DATA_LAYER_5
-rw-rw---- app_189 app_189 11387 2012-02-05 17:49 DATA_SYNC_DATA
-rw------- app_189 app_189 35 2012-02-07 11:21 cp_state
-rw-rw---- app_189 app_189 26756 2012-02-01 16:31 DATA_PHOTO_-6319433669272599441
-rw-rw---- app_189 app_189 76 2012-02-01 16:14 DATA_ServerControlledParametersManager.data
-rw-rw---- app_189 app_189 26756 2012-02-01 16:31 DATA_PHOTO_-4787236618283354619
-rw-rw---- app_189 app_189 57 2012-02-01 16:14 DATA_star_details_index
-rw-rw---- app_189 app_189 26756 2012-02-01 16:31 DATA_PHOTO_-7325828578927889496
-rw-rw---- app_189 app_189 76 2012-02-05 17:27 DATA_ServerControlledParametersManager_DA.data
-rw-rw---- app_189 app_189 26756 2012-02-01 16:31 DATA_PHOTO_-5041077772587057686

-rw-rw---- app_189 app_189 42 2012-02-05 17:26 DATA_PROTO_SAVED_RECENT_LAYERS
-rw-rw---- app_189 app_189 21 2012-02-05 10:04 DATA_SAVED_BGSF_
-rw-rw---- app_189 app_189 263 2012-02-05 11:30 DATA_LAYER_2
-rw-rw---- app_189 app_189 26 2012-02-01 16:14 NavigationParameters.data
-rw-rw---- app_189 app_189 330 2012-02-05 17:27 DA_DirOpt_en_US
-rw-rw---- app_189 app_189 26756 2012-02-01 16:31 DATA_PHOTO_-4817178430903221341
-rw-rw---- app_189 app_189 26756 2012-02-01 16:31 DATA_PHOTO_8476874153932292760
-rw-rw---- app_189 app_189 141298 2012-02-05 17:27 DATA_Restrictions
-rw-rw---- app_189 app_189 29 2012-02-05 17:49 DATA_PROTO_SAVED_LAYER_STATE
-rw------- app_189 app_189 61 2012-02-01 16:14 nlp_params

-rw-rw---- app_189 app_189 0 2012-02-05 17:27 DATA_Restrictions_lock
-rw-rw---- app_189 app_189 26756 2012-02-01 16:31 DATA_PHOTO_8041021750103678571
-rw-rw---- app_189 app_189 10237 2012-02-03 13:28 DATA_star_details_0
-rw-rw---- app_189 app_189 6 2012-02-05 17:49 DATA_RECENT
-rw-rw---- app_189 app_189 5048 2012-02-06 23:41 DATA_Preferences
-rw-rw---- app_189 app_189 65 2012-02-01 16:14 network_initiated_prefs.xml
-rw-rw---- app_189 app_189 65 2012-02-01 16:14 friends_app_widget_preferences.xml
-rw-rw---- app_189 app_189 1269 2012-02-01 16:14 ids.xml
-rw-rw---- app_189 app_189 250 2012-02-03 13:27 settings_preference.xml
-rw-rw---- app_189 app_189 65 2012-02-01 16:14 cache_settings_preference.xml

-rw-rw---- app_189 app_189 358 2012-02-07 11:28 checkin_notification_preferences.xml
-rw-rw---- app_189 app_189 119 2012-02-01 16:14 com.google.android.apps.maps_preferences.xml
-rw-rw---- app_189 app_189 345 2012-02-05 17:49 DriveAbout.xml
-rw-rw---- app_189 app_189 317 2012-02-07 10:38 LOCATION_REPORTING.xml

Android 2.2 (Froyo) introduced the ability to move apps to SD card (or "external storage" on some devices). This introduces a level of complexity since portions of the app get moved around. For every app that you move to SD Card/media area, the system creates a virtual mount point named /dev/block/dm-X, where "X" is a sequential number. It them moves the app's APK (Android package) file and some preferences there. You can view this by issuing a mount command in shell/terminal emulator. Along with other usual mounts, it should show which apps were moved to SD Card like in an example below:


/dev/block/dm-0 /mnt/asec/com.metago.astro-1 vfat ro,dirsync,nosuid,nodev,relatime,uid=1000,fmask=0222,dmask=0222,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
/dev/block/dm-1 /mnt/asec/com.a0soft.gphone.aTrackDog-1 vfat ro,dirsync,nosuid,nodev,relatime,uid=1000,fmask=0222,dmask=0222,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0

Here I moved Astro file manager and aTrackDog apps to the SD Card on my phone. Use ls /mnt/asec/ to view the directories created for the moved apps. Issuing command ls -l /mnt/asec/* will list the file sizes within those folders:



# ls -l -a /mnt/asec/*
ls -l -a /mnt/asec/*
-r-xr-xr-x system root 332826 2012-02-07 11:21 pkg.apk
dr-xr-xr-x system root 2012-02-07 11:21 lib
-r-xr-xr-x system root 2363522 2012-02-07 11:18 pkg.apk
dr-xr-xr-x system root 2012-02-07 11:18 lib

The wrapper for the virtual partition gets stored inside a hidden ".android_secure" folder of the SD Card:


# ls -a -l /mnt/sdcard/.android_secure
ls -a -l /mnt/sdcard/.android_secure

----rwxr-x system sdcard_rw 4290560 2012-02-07 11:18 com.metago.astro-1.asec
----rwxr-x system sdcard_rw 2161664 2012-02-07 11:21 com.a0soft.gphone.aTrackDog-1.asec

Once moved the app's APK will no longer be under /data/app/ or /data/app-private/ folders.


Another area of interest is Dalvik Cache - an area that contains cached data for each installed app. Upon first boot-up or new app installation the system generates a .dex file for each app that it uses for quicker start-up. These files are stored on /data/dalvik-cache/ partition. Command ls -l /data/dalvik-cache/*[package_name_here]* will return the space taken up by the app's Dalvik cache. For example, here's how much space is taken up by Google Maps app:


# ls -l /data/dalvik-cache/*com.google.android.apps.maps*
ls -l /data/dalvik-cache/*com.google.android.apps.maps*
-rw-r--r-- system app_189 4406016 2012-02-04 09:01 data@app@com.google.android.apps.maps-2.apk@classes.dex

Next, the /cache partition of the internal memory may be used by apps. The command ls -l /cache/ will show you all files stored there, along with sizes and owner information. For example, on my phone here's the output:



# ls -l /cache/
ls -l /cache/
-rw-r--r-- app_13 app_13 3640954 2012-02-07 09:16 downloadfile-1.apk
drwxrwx--- system cache 2011-12-31 21:03 recovery
drwxrwx--- root root 2011-12-31 21:00 lost+found

Besides the standard directories, there is a file named downloadfile-1.apk that belongs to something named "app_13". I can cross-reference this "app_13" name to the listing of ls -l /data/data/ to see that this file belongs to Android's built-in downloader:


# ls -l /data/data/
ls -l /data/data/
......

drwxr-x--x app_13 app_13 2011-12-31 21:02 com.android.providers.downloads.ui
......

Finally, apps can use the SD Card for their own purposes, and there is really no way to track this, unless the app names its folders something recognizable.


No comments:

Post a Comment

samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...