Wednesday 7 September 2016

Identify Mobile Operating System using Python and ADB


Q:Write a Python/Java/C+ program to verify the operating system name and version of Mobile devices.


Note: This program will only work for android devices. (Since Iphones do not have anything equivalent to adb. )No wonder android is the favorite platform when it comes to app development. Android market is also more developer friendly as compared to its ios counterpart.

Errors: In case you get an error about insufficient permission, either edit udev rules or borrow a phone from your friend, having a well known global manufacturer.

OS:Fedora 20 64 bit
Phone: Sony Xperia
Language: Python
Dependencies: Just adb package,No need for sdk
fedora:               <yum install adb>
ubuntu:              <apt-get install adb>


Code


#Author:Abhishek Munagekar for Prgwonders- prgwonders.blogspot.in
#Title: Android OS version and name
import os
import subprocess
codename=["Error","Not-named","Not-named","Cupcake","Donut","Eclair","Eclair","Eclair",
"Froyo","Gingerbread","Gingerbread","Honeycomb","Honeycomb","Honeycomb","ICS","ICS",
"Jelly Bean","Jelly Bean","Jelly Bean","Kitkat","Kitkat","Lollipop","Lollipop",
"Marshmallow","Nougat"]
api = subprocess.check_output("adb shell getprop|grep -m 1 \"build.version.sdk\"
|cut -d \" \" -f 2", shell=True)
version = subprocess.check_output("adb shell getprop|grep -m 1 \"build.version.release\"
|cut -d \" \" -f 2", shell=True)
api=api.translate(None, '[]')
version=version.translate(None, '[]')
print "The version of OS is\t",version
print "Android SDK version is\t",api
print "OS name is \t",codename[int(api)]


Output 



[te@dbsl2 3101]$ python osversion.py
The version of OS is    5.1.1

Android SDK version is    22

OS name is     Lollipop

No comments:

Post a Comment