关于Android的根设备切换GPS [英] Toggle gps on root devices on Android

查看:139
本文介绍了关于Android的根设备切换GPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与一些Android版本(我想2.3.x)开始,您无法通过API开启/关闭GPS,不管是什么权限的应用程序了。在过去,有可能通过利用功率控制部件的错误(见的此处),但现在它的固定。

Starting with some Android version (I think 2.3.x), you cannot turn on/off the GPS via the API, no matter what permissions the app has. In the past, it was possible by exploiting a bug in the power control widget (see here ), but now it's fixed.

假设我有一个root权限,我怎么可以把GPS和关闭?

Suppose I have a root access, how can I turn GPS on and off?

编辑: 是你如何去阅读果冻豆日志权限,这是不允许的正常应用程序了。我试图使用的WRITE_SECURE_SETTINGS允许类似的解决方案,以切换GPS,但没有奏效。

this is how you get a permission to read logs on jelly bean , which is not allowed for normal apps anymore . I've tried to use a similar solution for the WRITE_SECURE_SETTINGS permission in order to toggle the gps , but it didn't work.

编辑:到目前为止,我发现,工作只有一个解决办法:将应用程序是一个系统应用程序(一个可行的解决方案,可以发现的此处,即使工作在Android 4.2.1)。然而,我所想到的是使用root从一开始就绕过它,因为root权限可以根据我所知道做的一切。

so far , i've found only one solution that worked : converting the app to be a system app (a working solution can be found here , works even on android 4.2.1 ) . However, what i've thought of is using the root to bypass it from the beginning, as root permission can do everything according to what i know.

推荐答案

我看着Android源$ C ​​$ C一点点,发现以下code

I looked a little bit in Android source code and 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 for enabling or disabling a single location provider.
   * @param cr the content resolver to use
   * @param provider the location provider to enable or disable
   * @param enabled true if the provider should be enabled
   */
        public static final void setLocationProviderEnabled(ContentResolver cr,
                String provider, boolean enabled) {
            // to ensure thread safety, we write the provider name with a '+' or '-'
            // and let the SettingsProvider handle it rather than reading and modifying
            // the list of enabled providers.
            if (enabled) {
                provider = "+" + provider;
            } else {
                provider = "-" + provider;
            }
            putString(cr, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, provider);
        }       

我相信,如果你有root权限,你可以读取和写入Settings.Secure。这样一来,你应该能够控制全球定位系统(setLocationProviderEnabled)。

I believe, if you have root access then you can both read and write Settings.Secure. this way you should be able to control GPS (setLocationProviderEnabled).

不过,据我所知将不会关闭一个GPS硬件,只是会忽略这个位置提供。

However, as I understand it won't turn off a GPS hardware, just will ignore this location provider.

我不知道的接口,该接口会跟GPS和关闭硬件。但是,你有另一种选择是禁用负责GPS内核模块(我不知道它的名字)。

I am not aware of interfaces which will talk to GPS and turn off hardware. However, another option which you have is to disable kernel module responsible for GPS (I am not aware of it's name).

更新1

我查WRITE_SECURE_SETTIONS是如何在安卓(4.1)中定义。这是

I checked how WRITE_SECURE_SETTIONS is defined in Android (4.1). Here it 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 it to the manifest of your application, copy this application to the system image (you will need to mount it as writable) and you should be good to go.

还有一件事。 UID外壳有此权限。

And one more thing. uid shell has this permission.

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

我不记得确切,但有一些方法来临时更改UID(如果你是root)。 我是它的地方在Android的code。所以,你可以更改uid壳,做一些事情,它改回来。

I don't remember exactly, but there is some way to temporary change uid (if you are root). I was it somewhere in Android code. So, you can change uid to shell, do something and change it back.

更新2

我发现chaing UID的这个方法。

I found this method of chaing uid.

如果您下载 AOSP ,你可以找到如何使用本机库的地方coulpe

If you download AOSP, you can find how it used in native library in coulpe of places

./基地/命令/截图/ screenshot.c

./base/cmds/screenshot/screenshot.c

它的setuid(AID_SHELL);

It does setuid(AID_SHELL);

./本地/命令/ dumpstate / dumpstate.c

./native/cmds/dumpstate/dumpstate.c

的setuid(AID_SHELL)

setuid(AID_SHELL)

和在其他几个地方吧。

我觉得你应该用它来进行试验,以获得AID_SHELL组有WRITE_SECURE_SETTINGS权限。

I think you should experiment with it to get AID_SHELL group which has WRITE_SECURE_SETTINGS permission.

更新3

我不知道的细节。我认为应该有一个本地驱动程序和UNIX设备的GPS硬件。但是,它可以在不同的设备有不同的名称。

I am not sure about the details. I believe there should a native driver and unix device for gps hardware. However, it could be named differently on different devices.

您可以尝试使用 rmmod的 linux命令删除某些模块。我认为它应该关闭GPS。

You can try to use rmmod linux command to remove some module. I believe it should disable gps.

这篇关于关于Android的根设备切换GPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆