Toggle gps on root devices on Android -


starting android version (i think 2.3.x), cannot turn on/off gps via api, no matter permissions app has. in past, possible exploiting bug in power control widget (see here ), it's fixed.

suppose have root access, how can turn gps on , off?


edit: this how permission read logs on jelly bean , not allowed normal apps anymore . i've tried use similar solution write_secure_settings permission in order toggle gps , didn't work.


edit: far , i've found 1 solution worked : converting app system app (a working solution can found here , works on android 4.2.1 ) . however, i've thought of using root bypass beginning, root permission can according know.

i looked little bit in android source code , found following code

 public static final boolean islocationproviderenabled(contentresolver cr, string provider) { string allowedproviders = settings.secure.getstring(cr, location_providers_allowed); return textutils.delimitedstringcontains(allowedproviders, ',', provider); } /** * thread-safe method enabling or disabling single location provider. * @param cr content resolver use * @param provider location provider enable or disable * @param enabled true if provider should enabled */ public static final void setlocationproviderenabled(contentresolver cr, string provider, boolean enabled) { // ensure thread safety, write provider name '+' or '-' // , let settingsprovider handle rather reading , modifying // list of enabled providers. if (enabled) { provider = "+" + provider; } else { provider = "-" + provider; } putstring(cr, settings.secure.location_providers_allowed, provider); } 

i believe, if have root access can both read , write settings.secure. way should able control gps (setlocationproviderenabled).

however, understand won't turn off gps hardware, ignore location provider.

i not aware of interfaces talk gps , turn off hardware. however, option have disable kernel module responsible gps (i not aware of it's name).

update 1

i checked how write_secure_settions defined in android (4.1). here is

 <permission android:name="android.permission.write_secure_settings" android:permissiongroup="android.permission-group.development_tools" android:protectionlevel="signature|system|development" android:label="@string/permlab_writesecuresettings" android:description="@string/permdesc_writesecuresettings" /> 

based on "system" level. add manifest of application, copy application system image (you need mount writable) , should go.

and 1 more thing. uid shell has permission.

 <assign-permission name="android.permission.write_secure_settings" uid="shell" /> 

i don't remember exactly, there way temporary change uid (if root). somewhere in android code. so, can change uid shell, , change back.

update 2

i found method of chaing uid.

if download aosp, can find how used in native library in coulpe of places

./base/cmds/screenshot/screenshot.c

it setuid(aid_shell);

./native/cmds/dumpstate/dumpstate.c

setuid(aid_shell)

and in couple of other places.

i think should experiment aid_shell group has write_secure_settings permission.

update 3

i not sure details. believe there should native driver , unix device gps hardware. however, named differently on different devices.

you can try use rmmod linux command remove module. believe should disable gps.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -