歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

Android APP 獲得system權限

1. 在應用程序的AndroidManifest.xml中的manifest節點中加入android:sharedUserId="android.uid.system"這個屬性。
2. 修改Android.mk文件,加入LOCAL_CERTIFICATE := platform這一行
3. 使用mm命令來編譯,生成的apk就有system權限了

將 工程目錄拷貝到:

packages/apps/

進入添加Android.mk文件

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_PACKAGE_NAME := Wifi_Test1
LOCAL_CERTIFICATE := platform

include $(BUILD_PACKAGE)

# Use the folloing include to make our test apk.

include $(call all-makefiles-under,$(LOCAL_PATH))

修改  AndroidManifest.xml

添加:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.wpstar.Wifi_Test1"
      android:versionCode="1"
      android:sharedUserId="android.uid.system"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />


目錄下運行  mm

則:

Copying: out/target/common/obj/APPS/Wifi_Test1_intermediates/classes-jarjar.jar
Copying: out/target/common/obj/APPS/Wifi_Test1_intermediates/emma_out/lib/classes-jarjar.jar
Copying: out/target/common/obj/APPS/Wifi_Test1_intermediates/classes.jar
Copying: out/target/common/obj/APPS/Wifi_Test1_intermediates/noproguard.classes.jar
target Dex: Wifi_Test1
Copying: out/target/common/obj/APPS/Wifi_Test1_intermediates/noproguard.classes.dex
target Package: Wifi_Test1 (out/target/product/generic/obj/APPS/Wifi_Test1_intermediates/package.apk)
Warning: AndroidManifest.xml already defines versionCode (in http://schemas.android.com/apk/res/android); using existing value in manifest.
Warning: AndroidManifest.xml already defines versionName (in http://schemas.android.com/apk/res/android); using existing value in manifest.
Warning: AndroidManifest.xml already defines minSdkVersion (in http://schemas.android.com/apk/res/android); using existing value in manifest.
 'out/target/common/obj/APPS/Wifi_Test1_intermediates//classes.dex' as 'classes.dex'...
Install: out/target/product/generic/system/app/Wifi_Test1.apk
安裝成功..

運行後:

查看進程::

system    1618  1134  72084  16956 ffffffff afd0c51c S com.wpstar.Wifi_Test1

Copyright © Linux教程網 All Rights Reserved