Repository: aggresss/PHDemo Branch: master Commit: 9108e3c9a665 Files: 64 Total size: 322.9 KB Directory structure: gitextract_w6gyuez1/ ├── .gitignore ├── Code/ │ ├── device/ │ │ └── test/ │ │ └── myproduct/ │ │ ├── AndroidProducts.mk │ │ ├── myproduct.mk │ │ ├── phdemo/ │ │ │ ├── AndroidBoard.mk │ │ │ ├── BoardConfig.mk │ │ │ └── system.prop │ │ └── vendorsetup.sh │ ├── hello_APP/ │ │ └── Hello/ │ │ ├── Android.mk │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── phdemo/ │ │ │ └── myapplication/ │ │ │ └── MainActivity.java │ │ └── res/ │ │ ├── layout/ │ │ │ └── activity_main.xml │ │ ├── values/ │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ └── strings.xml │ │ └── values-w820dp/ │ │ └── dimens.xml │ ├── hello_Execute/ │ │ ├── Android.mk │ │ └── hello.c │ ├── hello_Framework/ │ │ ├── HelloService.java │ │ ├── IHelloService.aidl │ │ └── sepolicy/ │ │ ├── device.te │ │ ├── file_contexts │ │ ├── service.te │ │ ├── service_contexts │ │ └── system_server.te │ ├── hello_HAL/ │ │ ├── Android.mk │ │ ├── hello.c │ │ └── hello.h │ ├── hello_JNI/ │ │ └── com_android_server_HelloService.cpp │ └── hello_KernelDriver/ │ ├── Kconfig │ ├── Makefile │ ├── hello.c │ └── hello.h ├── README.md ├── Tools/ │ ├── 51-android.rules │ ├── cancro/ │ │ └── proprietary-files.txt │ └── sdat2img.py └── VirtualPosition/ ├── Modification/ │ └── com_android_server_location_GpsLocationProvider.cpp ├── vp_APP/ │ └── VirtualPosition/ │ ├── Android.mk │ ├── AndroidManifest.xml │ ├── java/ │ │ └── com/ │ │ └── example/ │ │ └── phdemo/ │ │ └── myapplication/ │ │ └── MainActivity.java │ └── res/ │ ├── layout/ │ │ └── activity_main.xml │ ├── values/ │ │ ├── colors.xml │ │ ├── dimens.xml │ │ └── strings.xml │ └── values-w820dp/ │ └── dimens.xml ├── vp_Framework/ │ ├── IVirtualPositionService.aidl │ ├── SystemServer.java │ ├── VirtualPositionService.java │ └── sepolicy/ │ ├── device.te │ ├── file_contexts │ ├── service.te │ ├── service_contexts │ └── system_server.te ├── vp_HAL/ │ ├── vp/ │ │ ├── Android.mk │ │ └── vp.c │ └── vp.h ├── vp_JNI/ │ ├── Android.mk │ ├── com_android_server_VirtualPositionService.cpp │ └── onload.cpp └── vp_KernelDriver/ ├── cyanogen_cancro_defconfig └── vp/ ├── Kconfig ├── Makefile ├── vp.c └── vp.h ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ *.o *.order *.o.cmd *~ ================================================ FILE: Code/device/test/myproduct/AndroidProducts.mk ================================================ PRODUCT_MAKEFILES := \ $(LOCAL_DIR)/myproduct.mk ================================================ FILE: Code/device/test/myproduct/myproduct.mk ================================================ # This is a build configuration for a full-featured build of the # Open-Source part of the tree. It's geared toward a US-centric # build quite specifically for the emulator, and might not be # entirely appropriate to inherit from for on-device configurations. $(call inherit-product, $(SRC_TARGET_DIR)/product/aosp_base_telephony.mk) $(call inherit-product, $(SRC_TARGET_DIR)/board/generic/device.mk) include $(SRC_TARGET_DIR)/product/emulator.mk # Overrides PRODUCT_NAME := myproduct PRODUCT_DEVICE := phdemo PRODUCT_BRAND := Android_phdemo PRODUCT_MODEL := phdemo AOSP on ARM Emulator ================================================ FILE: Code/device/test/myproduct/phdemo/AndroidBoard.mk ================================================ LOCAL_PATH := $(call my-dir) ================================================ FILE: Code/device/test/myproduct/phdemo/BoardConfig.mk ================================================ # config.mk # # Product-specific compile-time definitions. # # The generic product target doesn't have any hardware-specific pieces. TARGET_NO_BOOTLOADER := true TARGET_NO_KERNEL := true TARGET_ARCH := arm # Note: we build the platform images for ARMv7-A _without_ NEON. # # Technically, the emulator supports ARMv7-A _and_ NEON instructions, but # emulated NEON code paths typically ends up 2x slower than the normal C code # it is supposed to replace (unlike on real devices where it is 2x to 3x # faster). # # What this means is that the platform image will not use NEON code paths # that are slower to emulate. On the other hand, it is possible to emulate # application code generated with the NDK that uses NEON in the emulator. # TARGET_ARCH_VARIANT := armv7-a TARGET_CPU_VARIANT := generic TARGET_CPU_ABI := armeabi-v7a TARGET_CPU_ABI2 := armeabi HAVE_HTC_AUDIO_DRIVER := true BOARD_USES_GENERIC_AUDIO := true # no hardware camera USE_CAMERA_STUB := true # Enable dex-preoptimization to speed up the first boot sequence # of an SDK AVD. Note that this operation only works on Linux for now ifeq ($(HOST_OS),linux) ifeq ($(WITH_DEXPREOPT),) WITH_DEXPREOPT := true endif endif # Build OpenGLES emulation guest and host libraries BUILD_EMULATOR_OPENGL := true # Build and enable the OpenGL ES View renderer. When running on the emulator, # the GLES renderer disables itself if host GL acceleration isn't available. USE_OPENGL_RENDERER := true # Set the phase offset of the system's vsync event relative to the hardware # vsync. The system's vsync event drives Choreographer and SurfaceFlinger's # rendering. This value is the number of nanoseconds after the hardware vsync # that the system vsync event will occur. # # This phase offset allows adjustment of the minimum latency from application # wake-up (by Choregographer) time to the time at which the resulting window # image is displayed. This value may be either positive (after the HW vsync) # or negative (before the HW vsync). Setting it to 0 will result in a # minimum latency of two vsync periods because the app and SurfaceFlinger # will run just after the HW vsync. Setting it to a positive number will # result in the minimum latency being: # # (2 * VSYNC_PERIOD - (vsyncPhaseOffsetNs % VSYNC_PERIOD)) # # Note that reducing this latency makes it more likely for the applications # to not have their window content image ready in time. When this happens # the latency will end up being an additional vsync period, and animations # will hiccup. Therefore, this latency should be tuned somewhat # conservatively (or at least with awareness of the trade-off being made). VSYNC_EVENT_PHASE_OFFSET_NS := 0 TARGET_USERIMAGES_USE_EXT4 := true BOARD_SYSTEMIMAGE_PARTITION_SIZE := 1610612736 BOARD_USERDATAIMAGE_PARTITION_SIZE := 576716800 BOARD_CACHEIMAGE_PARTITION_SIZE := 69206016 BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4 BOARD_FLASH_BLOCK_SIZE := 512 TARGET_USERIMAGES_SPARSE_EXT_DISABLED := true BOARD_SEPOLICY_DIRS += build/target/board/generic/sepolicy ifeq ($(TARGET_PRODUCT),sdk) # include an expanded selection of fonts for the SDK. EXTENDED_FONT_FOOTPRINT := true endif ================================================ FILE: Code/device/test/myproduct/phdemo/system.prop ================================================ # # system.prop for generic sdk # rild.libpath=/system/lib/libreference-ril.so rild.libargs=-d /dev/ttyS0 ================================================ FILE: Code/device/test/myproduct/vendorsetup.sh ================================================ add_lunch_combo myproduct-eng ================================================ FILE: Code/hello_APP/Hello/Android.mk ================================================ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := $(call all-subdir-java-files) LOCAL_PACKAGE_NAME := Hello include $(BUILD_PACKAGE) ================================================ FILE: Code/hello_APP/Hello/AndroidManifest.xml ================================================ ================================================ FILE: Code/hello_APP/Hello/java/com/example/phdemo/myapplication/MainActivity.java ================================================ package com.example.phdemo.myapplication; import android.os.RemoteException; import android.app.Activity; import android.os.ServiceManager; import android.os.Bundle; import android.os.IHelloService; import android.os.RemoteException; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity implements View.OnClickListener { private final static String LOG_TAG = "shy.luo.renju.Hello"; private IHelloService helloService = null; private EditText valueText = null; private Button readButton = null; private Button writeButton = null; private Button clearButton = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); helloService = IHelloService.Stub.asInterface( ServiceManager.getService("hello")); valueText = (EditText)findViewById(R.id.edit_value); readButton = (Button)findViewById(R.id.button_read); writeButton = (Button)findViewById(R.id.button_write); clearButton = (Button)findViewById(R.id.button_clear); readButton.setOnClickListener(this); writeButton.setOnClickListener(this); clearButton.setOnClickListener(this); Log.i(LOG_TAG, "Hello Activity Created"); } @Override public void onClick(View v) { if(v.equals(readButton)) { try { int val = helloService.getVal(); String text = String.valueOf(val); valueText.setText(text); } catch (RemoteException e) { Log.e(LOG_TAG, "Remote Exception while reading value from device."); } } else if(v.equals(writeButton)) { try { String text = valueText.getText().toString(); int val = Integer.parseInt(text); helloService.setVal(val); } catch (RemoteException e) { Log.e(LOG_TAG, "Remote Exception while writing value to device."); } } else if(v.equals(clearButton)) { String text = ""; valueText.setText(text); } } } ================================================ FILE: Code/hello_APP/Hello/res/layout/activity_main.xml ================================================ ================================================ FILE: Code/hello_APP/Hello/res/values/colors.xml ================================================ #3F51B5 #303F9F #FF4081 ================================================ FILE: Code/hello_APP/Hello/res/values/dimens.xml ================================================ 16dp 16dp ================================================ FILE: Code/hello_APP/Hello/res/values/strings.xml ================================================ Hello Value Please input a value... Read Write Clear ================================================ FILE: Code/hello_APP/Hello/res/values-w820dp/dimens.xml ================================================ 64dp ================================================ FILE: Code/hello_Execute/Android.mk ================================================ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_MODULE := hello LOCAL_SRC_FILES := $(call all-subdir-c-files) include $(BUILD_EXECUTABLE) ================================================ FILE: Code/hello_Execute/hello.c ================================================ #include #include #include #define DEVICE_NAME "/dev/hello" int main(int argc, char** argv) { int fd = -1; int val = 0; fd = open(DEVICE_NAME, O_RDWR); if(fd == -1) { printf("Failed to open device %s.\n", DEVICE_NAME); return -1; } printf("Read original value:\n"); read(fd, &val, sizeof(val)); printf("%d.\n\n", val); val = 5; printf("Write value %d to %s.\n\n", val, DEVICE_NAME); write(fd, &val, sizeof(val)); printf("Read the value again:\n"); read(fd, &val, sizeof(val)); printf("%d.\n\n", val); close(fd); return 0; } ================================================ FILE: Code/hello_Framework/HelloService.java ================================================ package com.android.server; import android.content.Context; import android.os.IHelloService; import android.util.Slog; public class HelloService extends IHelloService.Stub { private static final String TAG = "HelloService"; HelloService() { init_native(); } public void setVal(int val) { setVal_native(val); } public int getVal() { return getVal_native(); } private static native boolean init_native(); private static native void setVal_native(int val); private static native int getVal_native(); }; ================================================ FILE: Code/hello_Framework/IHelloService.aidl ================================================ package android.os; interface IHelloService { void setVal(int val); int getVal(); } ================================================ FILE: Code/hello_Framework/sepolicy/device.te ================================================ # Device types type device, dev_type, fs_type; type alarm_device, dev_type, mlstrustedobject; type adb_device, dev_type; type ashmem_device, dev_type, mlstrustedobject; type audio_device, dev_type; type binder_device, dev_type, mlstrustedobject; type block_device, dev_type; type camera_device, dev_type; type dm_device, dev_type; type loop_device, dev_type; type pmsg_device, dev_type, mlstrustedobject; type radio_device, dev_type; type ram_device, dev_type; type rtc_device, dev_type; type vold_device, dev_type; type console_device, dev_type; type cpuctl_device, dev_type; type fscklogs, dev_type; type full_device, dev_type; # GPU (used by most UI apps) type gpu_device, dev_type, mlstrustedobject; type graphics_device, dev_type; type hw_random_device, dev_type; type input_device, dev_type; type kmem_device, dev_type; type log_device, dev_type, mlstrustedobject; type mtd_device, dev_type; type mtp_device, dev_type, mlstrustedobject; type nfc_device, dev_type; type ptmx_device, dev_type, mlstrustedobject; type kmsg_device, dev_type; type null_device, dev_type, mlstrustedobject; type random_device, dev_type, mlstrustedobject; type sensors_device, dev_type; type serial_device, dev_type; type socket_device, dev_type; type owntty_device, dev_type, mlstrustedobject; type tty_device, dev_type; type urandom_device, dev_type, mlstrustedobject; type video_device, dev_type; type vcs_device, dev_type; type zero_device, dev_type, mlstrustedobject; type fuse_device, dev_type; type iio_device, dev_type; type ion_device, dev_type, mlstrustedobject; type gps_device, dev_type; type qtaguid_device, dev_type; type watchdog_device, dev_type; type uhid_device, dev_type; type uio_device, dev_type; type tun_device, dev_type, mlstrustedobject; type usbaccessory_device, dev_type, mlstrustedobject; type usb_device, dev_type, mlstrustedobject; type klog_device, dev_type; type properties_device, dev_type; # All devices have a uart for the hci # attach service. The uart dev node # varies per device. This type # is used in per device policy type hci_attach_dev, dev_type; # All devices have a rpmsg device for # achieving remoteproc and rpmsg modules type rpmsg_device, dev_type; # Partition layout block device type root_block_device, dev_type; # factory reset protection block device type frp_block_device, dev_type; # System block device mounted on /system. type system_block_device, dev_type; # Recovery block device. type recovery_block_device, dev_type; # boot block device. type boot_block_device, dev_type; # Userdata block device mounted on /data. type userdata_block_device, dev_type; # Cache block device mounted on /cache. type cache_block_device, dev_type; # Block device for any swap partition. type swap_block_device, dev_type; # Metadata block device used for encryption metadata. # Assign this type to the partition specified by the encryptable= # mount option in your fstab file in the entry for userdata. type metadata_block_device, dev_type; #add by aggresss type hello_device, dev_type; ================================================ FILE: Code/hello_Framework/sepolicy/file_contexts ================================================ ########################################### # Root / u:object_r:rootfs:s0 # Data files /adb_keys u:object_r:adb_keys_file:s0 /default\.prop u:object_r:rootfs:s0 /fstab\..* u:object_r:rootfs:s0 /init\..* u:object_r:rootfs:s0 /res(/.*)? u:object_r:rootfs:s0 /ueventd\..* u:object_r:rootfs:s0 # Executables /charger u:object_r:rootfs:s0 /init u:object_r:init_exec:s0 /sbin(/.*)? u:object_r:rootfs:s0 # Empty directories /lost\+found u:object_r:rootfs:s0 /proc u:object_r:rootfs:s0 # SELinux policy files /file_contexts u:object_r:rootfs:s0 /property_contexts u:object_r:rootfs:s0 /seapp_contexts u:object_r:rootfs:s0 /sepolicy u:object_r:rootfs:s0 ########################## # Devices # /dev(/.*)? u:object_r:device:s0 /dev/akm8973.* u:object_r:sensors_device:s0 /dev/accelerometer u:object_r:sensors_device:s0 /dev/adf[0-9]* u:object_r:graphics_device:s0 /dev/adf-interface[0-9]*\.[0-9]* u:object_r:graphics_device:s0 /dev/adf-overlay-engine[0-9]*\.[0-9]* u:object_r:graphics_device:s0 /dev/alarm u:object_r:alarm_device:s0 /dev/android_adb.* u:object_r:adb_device:s0 /dev/ashmem u:object_r:ashmem_device:s0 /dev/audio.* u:object_r:audio_device:s0 /dev/binder u:object_r:binder_device:s0 /dev/block(/.*)? u:object_r:block_device:s0 /dev/block/dm-[0-9]+ u:object_r:dm_device:s0 /dev/block/loop[0-9]* u:object_r:loop_device:s0 /dev/block/vold/.+ u:object_r:vold_device:s0 /dev/block/ram[0-9]* u:object_r:ram_device:s0 /dev/bus/usb(.*)? u:object_r:usb_device:s0 /dev/cam u:object_r:camera_device:s0 /dev/console u:object_r:console_device:s0 /dev/cpuctl(/.*)? u:object_r:cpuctl_device:s0 /dev/device-mapper u:object_r:dm_device:s0 /dev/eac u:object_r:audio_device:s0 /dev/fscklogs(/.*)? u:object_r:fscklogs:s0 /dev/full u:object_r:full_device:s0 /dev/fuse u:object_r:fuse_device:s0 /dev/graphics(/.*)? u:object_r:graphics_device:s0 /dev/hw_random u:object_r:hw_random_device:s0 /dev/input(/.*) u:object_r:input_device:s0 /dev/iio:device[0-9]+ u:object_r:iio_device:s0 /dev/ion u:object_r:ion_device:s0 /dev/kmem u:object_r:kmem_device:s0 /dev/log(/.*)? u:object_r:log_device:s0 /dev/mem u:object_r:kmem_device:s0 /dev/modem.* u:object_r:radio_device:s0 /dev/mpu u:object_r:gps_device:s0 /dev/mpuirq u:object_r:gps_device:s0 /dev/mtd(/.*)? u:object_r:mtd_device:s0 /dev/mtp_usb u:object_r:mtp_device:s0 /dev/pmsg0 u:object_r:pmsg_device:s0 /dev/pn544 u:object_r:nfc_device:s0 /dev/ppp u:object_r:ppp_device:s0 /dev/ptmx u:object_r:ptmx_device:s0 /dev/pvrsrvkm u:object_r:gpu_device:s0 /dev/kmsg u:object_r:kmsg_device:s0 /dev/null u:object_r:null_device:s0 /dev/nvhdcp1 u:object_r:video_device:s0 /dev/random u:object_r:random_device:s0 /dev/rpmsg-omx[0-9] u:object_r:rpmsg_device:s0 /dev/rproc_user u:object_r:rpmsg_device:s0 /dev/rtc[0-9] u:object_r:rtc_device:s0 /dev/snd(/.*)? u:object_r:audio_device:s0 /dev/socket(/.*)? u:object_r:socket_device:s0 /dev/socket/adbd u:object_r:adbd_socket:s0 /dev/socket/sap_uim_socket[0-9] u:object_r:sap_uim_socket:s0 /dev/socket/cryptd u:object_r:vold_socket:s0 /dev/socket/dnsproxyd u:object_r:dnsproxyd_socket:s0 /dev/socket/dumpstate u:object_r:dumpstate_socket:s0 /dev/socket/fwmarkd u:object_r:fwmarkd_socket:s0 /dev/socket/gps u:object_r:gps_socket:s0 /dev/socket/installd u:object_r:installd_socket:s0 /dev/socket/lmkd u:object_r:lmkd_socket:s0 /dev/socket/logd u:object_r:logd_socket:s0 /dev/socket/logdr u:object_r:logdr_socket:s0 /dev/socket/logdw u:object_r:logdw_socket:s0 /dev/socket/mdns u:object_r:mdns_socket:s0 /dev/socket/mdnsd u:object_r:mdnsd_socket:s0 /dev/socket/mtpd u:object_r:mtpd_socket:s0 /dev/socket/netd u:object_r:netd_socket:s0 /dev/socket/property_service u:object_r:property_socket:s0 /dev/socket/racoon u:object_r:racoon_socket:s0 /dev/socket/rild u:object_r:rild_socket:s0 /dev/socket/rild-debug u:object_r:rild_debug_socket:s0 /dev/socket/vold u:object_r:vold_socket:s0 /dev/socket/wpa_eth[0-9] u:object_r:wpa_socket:s0 /dev/socket/wpa_wlan[0-9] u:object_r:wpa_socket:s0 /dev/socket/zygote u:object_r:zygote_socket:s0 /dev/socket/zygote_secondary u:object_r:zygote_socket:s0 /dev/spdif_out.* u:object_r:audio_device:s0 /dev/tegra.* u:object_r:video_device:s0 /dev/tf_driver u:object_r:tee_device:s0 /dev/tty u:object_r:owntty_device:s0 /dev/tty[0-9]* u:object_r:tty_device:s0 /dev/ttyS[0-9]* u:object_r:serial_device:s0 /dev/tun u:object_r:tun_device:s0 /dev/uhid u:object_r:uhid_device:s0 /dev/uinput u:object_r:uhid_device:s0 /dev/uio[0-9]* u:object_r:uio_device:s0 /dev/urandom u:object_r:urandom_device:s0 /dev/usb_accessory u:object_r:usbaccessory_device:s0 /dev/vcs[0-9a-z]* u:object_r:vcs_device:s0 /dev/video[0-9]* u:object_r:video_device:s0 /dev/watchdog u:object_r:watchdog_device:s0 /dev/xt_qtaguid u:object_r:qtaguid_device:s0 /dev/zero u:object_r:zero_device:s0 /dev/__kmsg__ u:object_r:klog_device:s0 /dev/__properties__ u:object_r:properties_device:s0 #add by aggresss /dev/hello u:object_r:hello_device:s0 ############################# # System files # /system(/.*)? u:object_r:system_file:s0 /system/bin/e2fsck -- u:object_r:fsck_exec:s0 /system/bin/fsck\.f2fs -- u:object_r:fsck_exec:s0 /system/bin/fsck_msdos -- u:object_r:fsck_exec:s0 /system/bin/toolbox -- u:object_r:toolbox_exec:s0 /system/bin/toybox -- u:object_r:toolbox_exec:s0 /system/bin/logcat -- u:object_r:logcat_exec:s0 /system/bin/sh -- u:object_r:shell_exec:s0 /system/bin/run-as -- u:object_r:runas_exec:s0 /system/bin/bootanimation u:object_r:bootanim_exec:s0 /system/bin/app_process32 u:object_r:zygote_exec:s0 /system/bin/app_process64 u:object_r:zygote_exec:s0 /system/bin/servicemanager u:object_r:servicemanager_exec:s0 /system/bin/surfaceflinger u:object_r:surfaceflinger_exec:s0 /system/bin/drmserver u:object_r:drmserver_exec:s0 /system/bin/dumpstate u:object_r:dumpstate_exec:s0 /system/bin/vold u:object_r:vold_exec:s0 /system/bin/netd u:object_r:netd_exec:s0 /system/bin/rild u:object_r:rild_exec:s0 /system/bin/mediaserver u:object_r:mediaserver_exec:s0 /system/bin/mdnsd u:object_r:mdnsd_exec:s0 /system/bin/installd u:object_r:installd_exec:s0 /system/bin/keystore u:object_r:keystore_exec:s0 /system/bin/fingerprintd u:object_r:fingerprintd_exec:s0 /system/bin/gatekeeperd u:object_r:gatekeeperd_exec:s0 /system/bin/debuggerd u:object_r:debuggerd_exec:s0 /system/bin/debuggerd64 u:object_r:debuggerd_exec:s0 /system/bin/wpa_supplicant u:object_r:wpa_exec:s0 /system/bin/sdcard u:object_r:sdcardd_exec:s0 /system/bin/dhcpcd u:object_r:dhcp_exec:s0 /system/bin/mtpd u:object_r:mtp_exec:s0 /system/bin/pppd u:object_r:ppp_exec:s0 /system/bin/tf_daemon u:object_r:tee_exec:s0 /system/bin/racoon u:object_r:racoon_exec:s0 /system/xbin/su u:object_r:su_exec:s0 /system/xbin/procrank u:object_r:procrank_exec:s0 /system/xbin/perfprofd u:object_r:perfprofd_exec:s0 /system/xbin/simpleperf u:object_r:system_file:s0 /system/vendor/bin/gpsd u:object_r:gpsd_exec:s0 /system/bin/dnsmasq u:object_r:dnsmasq_exec:s0 /system/bin/hostapd u:object_r:hostapd_exec:s0 /system/bin/clatd u:object_r:clatd_exec:s0 /system/bin/lmkd u:object_r:lmkd_exec:s0 /system/bin/inputflinger u:object_r:inputflinger_exec:s0 /system/bin/logd u:object_r:logd_exec:s0 /system/bin/uncrypt u:object_r:uncrypt_exec:s0 /system/bin/logwrapper u:object_r:system_file:s0 /system/bin/vdc u:object_r:vdc_exec:s0 /system/bin/install-recovery.sh u:object_r:install_recovery_exec:s0 /system/bin/dex2oat u:object_r:dex2oat_exec:s0 # patchoat executable has (essentially) the same requirements as dex2oat. /system/bin/patchoat u:object_r:dex2oat_exec:s0 /system/bin/sgdisk u:object_r:sgdisk_exec:s0 /system/bin/blkid u:object_r:blkid_exec:s0 /system/bin/tzdatacheck u:object_r:tzdatacheck_exec:s0 ############################# # Vendor files # /vendor(/.*)? u:object_r:system_file:s0 /vendor/bin/gpsd u:object_r:gpsd_exec:s0 ############################# # OEM and ODM files # /odm(/.*)? u:object_r:system_file:s0 /oem(/.*)? u:object_r:oemfs:s0 ############################# # Data files # # NOTE: When modifying existing label rules, changes may also need to # propagate to the "Expanded data files" section. # /data(/.*)? u:object_r:system_data_file:s0 /data/.layout_version u:object_r:install_data_file:s0 /data/unencrypted(/.*)? u:object_r:unencrypted_data_file:s0 /data/backup(/.*)? u:object_r:backup_data_file:s0 /data/secure/backup(/.*)? u:object_r:backup_data_file:s0 /data/security(/.*)? u:object_r:security_file:s0 /data/system/ndebugsocket u:object_r:system_ndebug_socket:s0 /data/drm(/.*)? u:object_r:drm_data_file:s0 /data/gps(/.*)? u:object_r:gps_data_file:s0 /data/resource-cache(/.*)? u:object_r:resourcecache_data_file:s0 /data/dalvik-cache(/.*)? u:object_r:dalvikcache_data_file:s0 /data/dalvik-cache/profiles(/.*)? u:object_r:dalvikcache_profiles_data_file:s0 /data/adb(/.*)? u:object_r:adb_data_file:s0 /data/anr(/.*)? u:object_r:anr_data_file:s0 /data/app(/.*)? u:object_r:apk_data_file:s0 /data/app/[^/]+/oat(/.*)? u:object_r:dalvikcache_data_file:s0 /data/app/vmdl[^/]+\.tmp(/.*)? u:object_r:apk_tmp_file:s0 /data/app/vmdl[^/]+\.tmp/oat(/.*)? u:object_r:dalvikcache_data_file:s0 /data/app-private(/.*)? u:object_r:apk_private_data_file:s0 /data/app-private/vmdl.*\.tmp(/.*)? u:object_r:apk_private_tmp_file:s0 /data/tombstones(/.*)? u:object_r:tombstone_data_file:s0 /data/local/tmp(/.*)? u:object_r:shell_data_file:s0 /data/media(/.*)? u:object_r:media_rw_data_file:s0 /data/mediadrm(/.*)? u:object_r:media_data_file:s0 /data/property(/.*)? u:object_r:property_data_file:s0 # Misc data /data/misc/adb(/.*)? u:object_r:adb_keys_file:s0 /data/misc/audio(/.*)? u:object_r:audio_data_file:s0 /data/misc/bluetooth(/.*)? u:object_r:bluetooth_data_file:s0 /data/misc/bluedroid(/.*)? u:object_r:bluetooth_data_file:s0 /data/misc/bluedroid/\.a2dp_ctrl u:object_r:bluetooth_socket:s0 /data/misc/bluedroid/\.a2dp_data u:object_r:bluetooth_socket:s0 /data/misc/camera(/.*)? u:object_r:camera_data_file:s0 /data/misc/dhcp(/.*)? u:object_r:dhcp_data_file:s0 /data/misc/gatekeeper(/.*)? u:object_r:gatekeeper_data_file:s0 /data/misc/keychain(/.*)? u:object_r:keychain_data_file:s0 /data/misc/keystore(/.*)? u:object_r:keystore_data_file:s0 /data/misc/logd(/.*)? u:object_r:misc_logd_file:s0 /data/misc/media(/.*)? u:object_r:media_data_file:s0 /data/misc/net(/.*)? u:object_r:net_data_file:s0 /data/misc/shared_relro(/.*)? u:object_r:shared_relro_file:s0 /data/misc/sms(/.*)? u:object_r:radio_data_file:s0 /data/misc/systemkeys(/.*)? u:object_r:systemkeys_data_file:s0 /data/misc/user(/.*)? u:object_r:misc_user_data_file:s0 /data/misc/vpn(/.*)? u:object_r:vpn_data_file:s0 /data/misc/wifi(/.*)? u:object_r:wifi_data_file:s0 /data/misc/wifi/sockets(/.*)? u:object_r:wpa_socket:s0 /data/misc/wifi/sockets/wpa_ctrl.* u:object_r:system_wpa_socket:s0 /data/misc/wifi/hostapd(/.*)? u:object_r:wpa_socket:s0 /data/misc/zoneinfo(/.*)? u:object_r:zoneinfo_data_file:s0 /data/misc/vold(/.*)? u:object_r:vold_data_file:s0 /data/misc/perfprofd(/.*)? u:object_r:perfprofd_data_file:s0 /data/system/heapdump(/.*)? u:object_r:heapdump_data_file:s0 # Fingerprint data /data/system/users/[0-9]+/fpdata(/.*)? u:object_r:fingerprintd_data_file:s0 # Bootchart data /data/bootchart(/.*)? u:object_r:bootchart_data_file:s0 ############################# # Expanded data files # /mnt/expand(/.*)? u:object_r:mnt_expand_file:s0 /mnt/expand/[^/]+(/.*)? u:object_r:system_data_file:s0 /mnt/expand/[^/]+/app(/.*)? u:object_r:apk_data_file:s0 /mnt/expand/[^/]+/app/[^/]+/oat(/.*)? u:object_r:dalvikcache_data_file:s0 /mnt/expand/[^/]+/app/vmdl[^/]+\.tmp(/.*)? u:object_r:apk_tmp_file:s0 /mnt/expand/[^/]+/app/vmdl[^/]+\.tmp/oat(/.*)? u:object_r:dalvikcache_data_file:s0 /mnt/expand/[^/]+/local/tmp(/.*)? u:object_r:shell_data_file:s0 /mnt/expand/[^/]+/media(/.*)? u:object_r:media_rw_data_file:s0 /mnt/expand/[^/]+/misc/vold(/.*)? u:object_r:vold_data_file:s0 # coredump directory for userdebug/eng devices /cores(/.*)? u:object_r:coredump_file:s0 # Wallpaper file for other users /data/system/users/[0-9]+/wallpaper u:object_r:wallpaper_file:s0 ############################# # efs files # /efs(/.*)? u:object_r:efs_file:s0 ############################# # Cache files # /cache(/.*)? u:object_r:cache_file:s0 /cache/.*\.data u:object_r:cache_backup_file:s0 /cache/.*\.restore u:object_r:cache_backup_file:s0 # LocalTransport (backup) uses this directory /cache/backup(/.*)? u:object_r:cache_backup_file:s0 ############################# # sysfs files # /sys/devices/platform/nfc-power/nfc_power -- u:object_r:sysfs_nfc_power_writable:s0 /sys/devices/system/cpu(/.*)? u:object_r:sysfs_devices_system_cpu:s0 /sys/power/wake_lock -- u:object_r:sysfs_wake_lock:s0 /sys/power/wake_unlock -- u:object_r:sysfs_wake_lock:s0 /sys/kernel/uevent_helper -- u:object_r:usermodehelper:s0 /sys/module/lowmemorykiller(/.*)? -- u:object_r:sysfs_lowmemorykiller:s0 ############################# # asec containers /mnt/asec(/.*)? u:object_r:asec_apk_file:s0 /mnt/asec/[^/]+/[^/]+\.zip u:object_r:asec_public_file:s0 /mnt/asec/[^/]+/lib(/.*)? u:object_r:asec_public_file:s0 /data/app-asec(/.*)? u:object_r:asec_image_file:s0 ############################# # external storage /mnt/media_rw(/.*)? u:object_r:mnt_media_rw_file:s0 /mnt/user(/.*)? u:object_r:mnt_user_file:s0 /mnt/runtime(/.*)? u:object_r:storage_file:s0 /storage(/.*)? u:object_r:storage_file:s0 ================================================ FILE: Code/hello_Framework/sepolicy/service.te ================================================ type bluetooth_service, service_manager_type; type default_android_service, service_manager_type; type drmserver_service, service_manager_type; type gatekeeper_service, app_api_service, service_manager_type; type fingerprintd_service, service_manager_type; type healthd_service, service_manager_type; type inputflinger_service, service_manager_type; type keystore_service, service_manager_type; type mediaserver_service, service_manager_type; type nfc_service, service_manager_type; type radio_service, service_manager_type; type surfaceflinger_service, service_manager_type; type system_app_service, service_manager_type; # system_server_services broken down type accessibility_service, app_api_service, system_server_service, service_manager_type; type account_service, app_api_service, system_server_service, service_manager_type; type activity_service, app_api_service, system_server_service, service_manager_type; type alarm_service, app_api_service, system_server_service, service_manager_type; type appops_service, app_api_service, system_server_service, service_manager_type; type appwidget_service, app_api_service, system_server_service, service_manager_type; type assetatlas_service, app_api_service, system_server_service, service_manager_type; type audio_service, app_api_service, system_server_service, service_manager_type; type backup_service, app_api_service, system_server_service, service_manager_type; type batterystats_service, app_api_service, system_server_service, service_manager_type; type battery_service, system_server_service, service_manager_type; type bluetooth_manager_service, system_api_service, system_server_service, service_manager_type; type cameraproxy_service, system_server_service, service_manager_type; type clipboard_service, app_api_service, system_server_service, service_manager_type; type IProxyService_service, system_api_service, system_server_service, service_manager_type; type commontime_management_service, system_server_service, service_manager_type; type connectivity_service, app_api_service, system_server_service, service_manager_type; type consumer_ir_service, app_api_service, system_server_service, service_manager_type; type content_service, app_api_service, system_server_service, service_manager_type; type country_detector_service, system_api_service, system_server_service, service_manager_type; type cpuinfo_service, system_api_service, system_server_service, service_manager_type; type dbinfo_service, system_api_service, system_server_service, service_manager_type; type device_policy_service, app_api_service, system_server_service, service_manager_type; type deviceidle_service, system_api_service, system_server_service, service_manager_type; type devicestoragemonitor_service, system_server_service, service_manager_type; type diskstats_service, system_api_service, system_server_service, service_manager_type; type display_service, app_api_service, system_server_service, service_manager_type; type DockObserver_service, system_server_service, service_manager_type; type dreams_service, system_api_service, system_server_service, service_manager_type; type dropbox_service, app_api_service, system_server_service, service_manager_type; type ethernet_service, app_api_service, system_server_service, service_manager_type; type fingerprint_service, app_api_service, system_server_service, service_manager_type; type gfxinfo_service, system_api_service, system_server_service, service_manager_type; type graphicsstats_service, app_api_service, system_server_service, service_manager_type; type hardware_service, system_server_service, service_manager_type; type hdmi_control_service, system_api_service, system_server_service, service_manager_type; type input_method_service, app_api_service, system_server_service, service_manager_type; type input_service, app_api_service, system_server_service, service_manager_type; type imms_service, app_api_service, system_server_service, service_manager_type; type jobscheduler_service, app_api_service, system_server_service, service_manager_type; type launcherapps_service, app_api_service, system_server_service, service_manager_type; type location_service, app_api_service, system_server_service, service_manager_type; type lock_settings_service, system_api_service, system_server_service, service_manager_type; type media_projection_service, app_api_service, system_server_service, service_manager_type; type media_router_service, app_api_service, system_server_service, service_manager_type; type media_session_service, app_api_service, system_server_service, service_manager_type; type meminfo_service, system_api_service, system_server_service, service_manager_type; type midi_service, app_api_service, system_server_service, service_manager_type; type mount_service, app_api_service, system_server_service, service_manager_type; type netpolicy_service, app_api_service, system_server_service, service_manager_type; type netstats_service, system_api_service, system_server_service, service_manager_type; type network_management_service, system_api_service, system_server_service, service_manager_type; type network_score_service, system_api_service, system_server_service, service_manager_type; type notification_service, app_api_service, system_server_service, service_manager_type; type package_service, app_api_service, system_server_service, service_manager_type; type permission_service, app_api_service, system_server_service, service_manager_type; type persistent_data_block_service, system_api_service, system_server_service, service_manager_type; type power_service, app_api_service, system_server_service, service_manager_type; type print_service, app_api_service, system_server_service, service_manager_type; type processinfo_service, system_server_service, service_manager_type; type procstats_service, app_api_service, system_server_service, service_manager_type; type registry_service, app_api_service, system_server_service, service_manager_type; type restrictions_service, app_api_service, system_server_service, service_manager_type; type rttmanager_service, app_api_service, system_server_service, service_manager_type; type samplingprofiler_service, system_server_service, service_manager_type; type scheduling_policy_service, system_server_service, service_manager_type; type search_service, app_api_service, system_server_service, service_manager_type; type sensorservice_service, app_api_service, system_server_service, service_manager_type; type serial_service, system_api_service, system_server_service, service_manager_type; type servicediscovery_service, app_api_service, system_server_service, service_manager_type; type statusbar_service, app_api_service, system_server_service, service_manager_type; type task_service, system_server_service, service_manager_type; type textservices_service, app_api_service, system_server_service, service_manager_type; type telecom_service, app_api_service, system_server_service, service_manager_type; type trust_service, system_api_service, system_server_service, service_manager_type; type tv_input_service, app_api_service, system_server_service, service_manager_type; type uimode_service, app_api_service, system_server_service, service_manager_type; type updatelock_service, system_api_service, system_server_service, service_manager_type; type usagestats_service, app_api_service, system_server_service, service_manager_type; type usb_service, app_api_service, system_server_service, service_manager_type; type user_service, app_api_service, system_server_service, service_manager_type; type vibrator_service, app_api_service, system_server_service, service_manager_type; type voiceinteraction_service, app_api_service, system_server_service, service_manager_type; type wallpaper_service, app_api_service, system_server_service, service_manager_type; type webviewupdate_service, system_api_service, system_server_service, service_manager_type; type wifip2p_service, app_api_service, system_server_service, service_manager_type; type wifiscanner_service, system_api_service, system_server_service, service_manager_type; type wifi_service, app_api_service, system_server_service, service_manager_type; type window_service, system_api_service, system_server_service, service_manager_type; #add by aggresss type hello_service, system_api_service, system_server_service, service_manager_type; ================================================ FILE: Code/hello_Framework/sepolicy/service_contexts ================================================ accessibility u:object_r:accessibility_service:s0 account u:object_r:account_service:s0 activity u:object_r:activity_service:s0 alarm u:object_r:alarm_service:s0 android.security.keystore u:object_r:keystore_service:s0 android.service.gatekeeper.IGateKeeperService u:object_r:gatekeeper_service:s0 appops u:object_r:appops_service:s0 appwidget u:object_r:appwidget_service:s0 assetatlas u:object_r:assetatlas_service:s0 audio u:object_r:audio_service:s0 backup u:object_r:backup_service:s0 batteryproperties u:object_r:healthd_service:s0 batterypropreg u:object_r:healthd_service:s0 batterystats u:object_r:batterystats_service:s0 battery u:object_r:battery_service:s0 bluetooth_manager u:object_r:bluetooth_manager_service:s0 bluetooth u:object_r:bluetooth_service:s0 carrier_config u:object_r:radio_service:s0 clipboard u:object_r:clipboard_service:s0 com.android.net.IProxyService u:object_r:IProxyService_service:s0 commontime_management u:object_r:commontime_management_service:s0 common_time.clock u:object_r:mediaserver_service:s0 common_time.config u:object_r:mediaserver_service:s0 connectivity u:object_r:connectivity_service:s0 consumer_ir u:object_r:consumer_ir_service:s0 content u:object_r:content_service:s0 country_detector u:object_r:country_detector_service:s0 cpuinfo u:object_r:cpuinfo_service:s0 dbinfo u:object_r:dbinfo_service:s0 device_policy u:object_r:device_policy_service:s0 deviceidle u:object_r:deviceidle_service:s0 devicestoragemonitor u:object_r:devicestoragemonitor_service:s0 diskstats u:object_r:diskstats_service:s0 display.qservice u:object_r:surfaceflinger_service:s0 display u:object_r:display_service:s0 DockObserver u:object_r:DockObserver_service:s0 dreams u:object_r:dreams_service:s0 drm.drmManager u:object_r:drmserver_service:s0 dropbox u:object_r:dropbox_service:s0 ethernet u:object_r:ethernet_service:s0 fingerprint u:object_r:fingerprint_service:s0 android.hardware.fingerprint.IFingerprintDaemon u:object_r:fingerprintd_service:s0 gfxinfo u:object_r:gfxinfo_service:s0 graphicsstats u:object_r:graphicsstats_service:s0 hardware u:object_r:hardware_service:s0 hdmi_control u:object_r:hdmi_control_service:s0 inputflinger u:object_r:inputflinger_service:s0 input_method u:object_r:input_method_service:s0 input u:object_r:input_service:s0 iphonesubinfo_msim u:object_r:radio_service:s0 iphonesubinfo2 u:object_r:radio_service:s0 iphonesubinfo u:object_r:radio_service:s0 ims u:object_r:radio_service:s0 imms u:object_r:imms_service:s0 isms_msim u:object_r:radio_service:s0 isms2 u:object_r:radio_service:s0 isms u:object_r:radio_service:s0 isub u:object_r:radio_service:s0 jobscheduler u:object_r:jobscheduler_service:s0 launcherapps u:object_r:launcherapps_service:s0 location u:object_r:location_service:s0 lock_settings u:object_r:lock_settings_service:s0 media.audio_flinger u:object_r:mediaserver_service:s0 media.audio_policy u:object_r:mediaserver_service:s0 media.camera u:object_r:mediaserver_service:s0 media.camera.proxy u:object_r:cameraproxy_service:s0 media.log u:object_r:mediaserver_service:s0 media.player u:object_r:mediaserver_service:s0 media.resource_manager u:object_r:mediaserver_service:s0 media.radio u:object_r:mediaserver_service:s0 media.sound_trigger_hw u:object_r:mediaserver_service:s0 media_projection u:object_r:media_projection_service:s0 media_router u:object_r:media_router_service:s0 media_session u:object_r:media_session_service:s0 meminfo u:object_r:meminfo_service:s0 midi u:object_r:midi_service:s0 mount u:object_r:mount_service:s0 netpolicy u:object_r:netpolicy_service:s0 netstats u:object_r:netstats_service:s0 network_management u:object_r:network_management_service:s0 network_score u:object_r:network_score_service:s0 nfc u:object_r:nfc_service:s0 notification u:object_r:notification_service:s0 package u:object_r:package_service:s0 permission u:object_r:permission_service:s0 persistent_data_block u:object_r:persistent_data_block_service:s0 phone_msim u:object_r:radio_service:s0 phone1 u:object_r:radio_service:s0 phone2 u:object_r:radio_service:s0 phone u:object_r:radio_service:s0 power u:object_r:power_service:s0 print u:object_r:print_service:s0 processinfo u:object_r:processinfo_service:s0 procstats u:object_r:procstats_service:s0 radio.phonesubinfo u:object_r:radio_service:s0 radio.phone u:object_r:radio_service:s0 radio.sms u:object_r:radio_service:s0 restrictions u:object_r:restrictions_service:s0 rttmanager u:object_r:rttmanager_service:s0 samplingprofiler u:object_r:samplingprofiler_service:s0 scheduling_policy u:object_r:scheduling_policy_service:s0 search u:object_r:search_service:s0 sensorservice u:object_r:sensorservice_service:s0 serial u:object_r:serial_service:s0 servicediscovery u:object_r:servicediscovery_service:s0 simphonebook_msim u:object_r:radio_service:s0 simphonebook2 u:object_r:radio_service:s0 simphonebook u:object_r:radio_service:s0 sip u:object_r:radio_service:s0 statusbar u:object_r:statusbar_service:s0 SurfaceFlinger u:object_r:surfaceflinger_service:s0 task u:object_r:task_service:s0 telecom u:object_r:telecom_service:s0 telephony.registry u:object_r:registry_service:s0 textservices u:object_r:textservices_service:s0 trust u:object_r:trust_service:s0 tv_input u:object_r:tv_input_service:s0 uimode u:object_r:uimode_service:s0 updatelock u:object_r:updatelock_service:s0 usagestats u:object_r:usagestats_service:s0 usb u:object_r:usb_service:s0 user u:object_r:user_service:s0 vibrator u:object_r:vibrator_service:s0 voiceinteraction u:object_r:voiceinteraction_service:s0 wallpaper u:object_r:wallpaper_service:s0 webviewupdate u:object_r:webviewupdate_service:s0 wifip2p u:object_r:wifip2p_service:s0 wifiscanner u:object_r:wifiscanner_service:s0 wifi u:object_r:wifi_service:s0 window u:object_r:window_service:s0 #add by aggresss hello u:object_r:hello_service:s0 * u:object_r:default_android_service:s0 ================================================ FILE: Code/hello_Framework/sepolicy/system_server.te ================================================ # # System Server aka system_server spawned by zygote. # Most of the framework services run in this process. # type system_server, domain, mlstrustedsubject; # Define a type for tmpfs-backed ashmem regions. tmpfs_domain(system_server) # Dalvik Compiler JIT Mapping. allow system_server self:process execmem; allow system_server ashmem_device:chr_file execute; allow system_server system_server_tmpfs:file execute; # For art. allow system_server dalvikcache_data_file:file execute; allow system_server dalvikcache_data_file:dir r_dir_perms; # /data/resource-cache allow system_server resourcecache_data_file:file r_file_perms; allow system_server resourcecache_data_file:dir r_dir_perms; # ptrace to processes in the same domain for debugging crashes. allow system_server self:process ptrace; # Child of the zygote. allow system_server zygote:fd use; allow system_server zygote:process sigchld; allow system_server zygote_tmpfs:file read; # May kill zygote on crashes. allow system_server zygote:process sigkill; # Read /system/bin/app_process. allow system_server zygote_exec:file r_file_perms; # Needed to close the zygote socket, which involves getopt / getattr allow system_server zygote:unix_stream_socket { getopt getattr }; # system server gets network and bluetooth permissions. net_domain(system_server) bluetooth_domain(system_server) # These are the capabilities assigned by the zygote to the # system server. allow system_server self:capability { kill net_admin net_bind_service net_broadcast net_raw sys_boot sys_nice sys_resource sys_time sys_tty_config }; wakelock_use(system_server) # Triggered by /proc/pid accesses, not allowed. dontaudit system_server self:capability sys_ptrace; # Trigger module auto-load. allow system_server kernel:system module_request; # Use netlink uevent sockets. allow system_server self:netlink_kobject_uevent_socket create_socket_perms; # Use generic netlink sockets. allow system_server self:netlink_socket create_socket_perms; # Set and get routes directly via netlink. allow system_server self:netlink_route_socket nlmsg_write; # Kill apps. allow system_server appdomain:process { sigkill signal }; # Set scheduling info for apps. allow system_server appdomain:process { getsched setsched }; allow system_server mediaserver:process { getsched setsched }; # Read /proc/pid data for all domains. This is used by ProcessCpuTracker # within system_server to keep track of memory and CPU usage for # all processes on the device. r_dir_file(system_server, domain) # Read/Write to /proc/net/xt_qtaguid/ctrl and and /dev/xt_qtaguid. allow system_server qtaguid_proc:file rw_file_perms; allow system_server qtaguid_device:chr_file rw_file_perms; # Read /proc/uid_cputime/show_uid_stat. allow system_server proc_uid_cputime_showstat:file r_file_perms; # Write /proc/uid_cputime/remove_uid_range. allow system_server proc_uid_cputime_removeuid:file { w_file_perms getattr }; # Write to /proc/sysrq-trigger. allow system_server proc_sysrq:file rw_file_perms; # Read /sys/kernel/debug/wakeup_sources. allow system_server debugfs:file r_file_perms; # The DhcpClient and WifiWatchdog use packet_sockets allow system_server self:packet_socket create_socket_perms; # NetworkDiagnostics requires explicit bind() calls to ping sockets. These aren't actually the same # as raw sockets, but the kernel doesn't yet distinguish between the two. allow system_server node:rawip_socket node_bind; # 3rd party VPN clients require a tun_socket to be created allow system_server self:tun_socket create_socket_perms; # Notify init of death. allow system_server init:process sigchld; # Talk to init and various daemons via sockets. unix_socket_connect(system_server, installd, installd) unix_socket_connect(system_server, lmkd, lmkd) unix_socket_connect(system_server, mtpd, mtp) unix_socket_connect(system_server, netd, netd) unix_socket_connect(system_server, vold, vold) unix_socket_connect(system_server, zygote, zygote) unix_socket_connect(system_server, gps, gpsd) unix_socket_connect(system_server, racoon, racoon) unix_socket_send(system_server, wpa, wpa) # Communicate over a socket created by surfaceflinger. allow system_server surfaceflinger:unix_stream_socket { read write setopt }; # Perform Binder IPC. binder_use(system_server) binder_call(system_server, binderservicedomain) binder_call(system_server, gatekeeperd) binder_call(system_server, fingerprintd) binder_call(system_server, appdomain) binder_call(system_server, dumpstate) binder_service(system_server) # Ask debuggerd to dump backtraces for native stacks of interest. allow system_server { mediaserver sdcardd surfaceflinger inputflinger }:debuggerd dump_backtrace; # Read /proc/pid files for dumping stack traces of native processes. r_dir_file(system_server, mediaserver) r_dir_file(system_server, sdcardd) r_dir_file(system_server, surfaceflinger) r_dir_file(system_server, inputflinger) # Use sockets received over binder from various services. allow system_server mediaserver:tcp_socket rw_socket_perms; allow system_server mediaserver:udp_socket rw_socket_perms; # Check SELinux permissions. selinux_check_access(system_server) # XXX Label sysfs files with a specific type? allow system_server sysfs:file rw_file_perms; allow system_server sysfs_nfc_power_writable:file rw_file_perms; allow system_server sysfs_devices_system_cpu:file w_file_perms; # Access devices. allow system_server device:dir r_dir_perms; allow system_server mdns_socket:sock_file rw_file_perms; allow system_server alarm_device:chr_file rw_file_perms; allow system_server gpu_device:chr_file rw_file_perms; allow system_server iio_device:chr_file rw_file_perms; allow system_server input_device:dir r_dir_perms; allow system_server input_device:chr_file rw_file_perms; allow system_server radio_device:chr_file r_file_perms; allow system_server tty_device:chr_file rw_file_perms; allow system_server usbaccessory_device:chr_file rw_file_perms; allow system_server video_device:dir r_dir_perms; allow system_server video_device:chr_file rw_file_perms; allow system_server adbd_socket:sock_file rw_file_perms; allow system_server rtc_device:chr_file rw_file_perms; allow system_server audio_device:dir r_dir_perms; # write access needed for MIDI allow system_server audio_device:chr_file rw_file_perms; # tun device used for 3rd party vpn apps allow system_server tun_device:chr_file rw_file_perms; # Manage system data files. allow system_server system_data_file:dir create_dir_perms; allow system_server system_data_file:notdevfile_class_set create_file_perms; allow system_server keychain_data_file:dir create_dir_perms; allow system_server keychain_data_file:file create_file_perms; # Manage /data/app. allow system_server apk_data_file:dir create_dir_perms; allow system_server apk_data_file:file { create_file_perms link }; allow system_server apk_tmp_file:dir create_dir_perms; allow system_server apk_tmp_file:file create_file_perms; # Manage /data/app-private. allow system_server apk_private_data_file:dir create_dir_perms; allow system_server apk_private_data_file:file create_file_perms; allow system_server apk_private_tmp_file:dir create_dir_perms; allow system_server apk_private_tmp_file:file create_file_perms; # Manage files within asec containers. allow system_server asec_apk_file:dir create_dir_perms; allow system_server asec_apk_file:file create_file_perms; allow system_server asec_public_file:file create_file_perms; # Manage /data/anr. allow system_server anr_data_file:dir create_dir_perms; allow system_server anr_data_file:file create_file_perms; # Manage /data/backup. allow system_server backup_data_file:dir create_dir_perms; allow system_server backup_data_file:file create_file_perms; # Read from /data/dalvik-cache/profiles allow system_server dalvikcache_profiles_data_file:dir rw_dir_perms; allow system_server dalvikcache_profiles_data_file:file create_file_perms; # Write to /data/system/heapdump allow system_server heapdump_data_file:dir rw_dir_perms; allow system_server heapdump_data_file:file create_file_perms; # Manage /data/misc/adb. allow system_server adb_keys_file:dir create_dir_perms; allow system_server adb_keys_file:file create_file_perms; # Manage /data/misc/sms. # TODO: Split into a separate type? allow system_server radio_data_file:dir create_dir_perms; allow system_server radio_data_file:file create_file_perms; # Manage /data/misc/systemkeys. allow system_server systemkeys_data_file:dir create_dir_perms; allow system_server systemkeys_data_file:file create_file_perms; # Access /data/tombstones. allow system_server tombstone_data_file:dir r_dir_perms; allow system_server tombstone_data_file:file r_file_perms; # Manage /data/misc/vpn. allow system_server vpn_data_file:dir create_dir_perms; allow system_server vpn_data_file:file create_file_perms; # Manage /data/misc/wifi. allow system_server wifi_data_file:dir create_dir_perms; allow system_server wifi_data_file:file create_file_perms; # Manage /data/misc/zoneinfo. allow system_server zoneinfo_data_file:dir create_dir_perms; allow system_server zoneinfo_data_file:file create_file_perms; # Walk /data/data subdirectories. # Types extracted from seapp_contexts type= fields. allow system_server { system_app_data_file bluetooth_data_file nfc_data_file radio_data_file shell_data_file app_data_file }:dir { getattr read search }; # Also permit for unlabeled /data/data subdirectories and # for unlabeled asec containers on upgrades from 4.2. allow system_server unlabeled:dir r_dir_perms; # Read pkg.apk file before it has been relabeled by vold. allow system_server unlabeled:file r_file_perms; # Populate com.android.providers.settings/databases/settings.db. allow system_server system_app_data_file:dir create_dir_perms; allow system_server system_app_data_file:file create_file_perms; # Receive and use open app data files passed over binder IPC. # Types extracted from seapp_contexts type= fields. allow system_server { system_app_data_file bluetooth_data_file nfc_data_file radio_data_file shell_data_file app_data_file }:file { getattr read write }; # Receive and use open /data/media files passed over binder IPC. allow system_server media_rw_data_file:file { getattr read write }; # Read /file_contexts and /data/security/file_contexts security_access_policy(system_server) # Relabel apk files. allow system_server { apk_tmp_file apk_private_tmp_file }:{ dir file } { relabelfrom relabelto }; allow system_server { apk_data_file apk_private_data_file }:{ dir file } { relabelfrom relabelto }; # Relabel wallpaper. allow system_server system_data_file:file relabelfrom; allow system_server wallpaper_file:file relabelto; allow system_server wallpaper_file:file { rw_file_perms unlink }; # Relabel /data/anr. allow system_server system_data_file:dir relabelfrom; allow system_server anr_data_file:dir relabelto; # Property Service write set_prop(system_server, system_prop) set_prop(system_server, dhcp_prop) set_prop(system_server, net_radio_prop) set_prop(system_server, system_radio_prop) set_prop(system_server, debug_prop) set_prop(system_server, powerctl_prop) set_prop(system_server, fingerprint_prop) # ctl interface set_prop(system_server, ctl_default_prop) set_prop(system_server, ctl_dhcp_pan_prop) set_prop(system_server, ctl_bugreport_prop) # Create a socket for receiving info from wpa. type_transition system_server wifi_data_file:sock_file system_wpa_socket; type_transition system_server wpa_socket:sock_file system_wpa_socket; allow system_server wpa_socket:dir rw_dir_perms; allow system_server system_wpa_socket:sock_file create_file_perms; # Remove sockets created by wpa_supplicant allow system_server wpa_socket:sock_file unlink; # Create a socket for connections from debuggerd. type_transition system_server system_data_file:sock_file system_ndebug_socket "ndebugsocket"; allow system_server system_ndebug_socket:sock_file create_file_perms; # Manage cache files. allow system_server cache_file:dir { relabelfrom create_dir_perms }; allow system_server cache_file:file { relabelfrom create_file_perms }; allow system_server cache_file:fifo_file create_file_perms; # Run system programs, e.g. dexopt. allow system_server system_file:file x_file_perms; # LocationManager(e.g, GPS) needs to read and write # to uart driver and ctrl proc entry allow system_server gps_device:chr_file rw_file_perms; allow system_server gps_control:file rw_file_perms; # Allow system_server to use app-created sockets and pipes. allow system_server appdomain:{ tcp_socket udp_socket } { getattr getopt setopt read write shutdown }; allow system_server appdomain:{ fifo_file unix_stream_socket } { getattr read write }; # Allow abstract socket connection allow system_server rild:unix_stream_socket connectto; # BackupManagerService lets PMS create a data backup file allow system_server cache_backup_file:file create_file_perms; # Relabel /data/backup allow system_server backup_data_file:dir { relabelto relabelfrom }; # Relabel /cache/.*\.{data|restore} allow system_server cache_backup_file:file { relabelto relabelfrom }; # LocalTransport creates and relabels /cache/backup allow system_server cache_backup_file:dir { relabelto relabelfrom create_dir_perms }; # Allow system to talk to usb device allow system_server usb_device:chr_file rw_file_perms; allow system_server usb_device:dir r_dir_perms; # Allow system to talk to sensors allow system_server sensors_device:chr_file rw_file_perms; # Read from HW RNG (needed by EntropyMixer). allow system_server hw_random_device:chr_file r_file_perms; # Read and delete files under /dev/fscklogs. r_dir_file(system_server, fscklogs) allow system_server fscklogs:dir { write remove_name }; allow system_server fscklogs:file unlink; # For SELinuxPolicyInstallReceiver selinux_manage_policy(system_server) # logd access, system_server inherit logd write socket # (urge is to deprecate this long term) allow system_server zygote:unix_dgram_socket write; # Read from log daemon. read_logd(system_server) # Be consistent with DAC permissions. Allow system_server to write to # /sys/module/lowmemorykiller/parameters/adj # /sys/module/lowmemorykiller/parameters/minfree allow system_server sysfs_lowmemorykiller:file { getattr w_file_perms }; # Read /sys/fs/pstore/console-ramoops # Don't worry about overly broad permissions for now, as there's # only one file in /sys/fs/pstore allow system_server pstorefs:dir r_dir_perms; allow system_server pstorefs:file r_file_perms; allow system_server drmserver_service:service_manager find; allow system_server healthd_service:service_manager find; allow system_server keystore_service:service_manager find; allow system_server gatekeeper_service:service_manager find; allow system_server fingerprintd_service:service_manager find; allow system_server mediaserver_service:service_manager find; allow system_server nfc_service:service_manager find; allow system_server radio_service:service_manager find; allow system_server system_server_service:service_manager { add find }; allow system_server surfaceflinger_service:service_manager find; allow system_server keystore:keystore_key { get_state get insert delete exist list reset password lock unlock is_empty sign verify grant duplicate clear_uid add_auth user_changed }; # Allow system server to search and write to the persistent factory reset # protection partition. This block device does not get wiped in a factory reset. allow system_server block_device:dir search; allow system_server frp_block_device:blk_file rw_file_perms; # Clean up old cgroups allow system_server cgroup:dir { remove_name rmdir }; # /oem access r_dir_file(system_server, oemfs) # Allow resolving per-user storage symlinks allow system_server { mnt_user_file storage_file }:dir { getattr search }; allow system_server { mnt_user_file storage_file }:lnk_file { getattr read }; # Allow statfs() on storage devices, which happens fast enough that # we shouldn't be killed during unsafe removal allow system_server sdcard_type:dir { getattr search }; # Traverse into expanded storage allow system_server mnt_expand_file:dir r_dir_perms; # Allow system process to relabel the fingerprint directory after mkdir allow system_server fingerprintd_data_file:dir {r_dir_perms relabelto}; ### ### Neverallow rules ### ### system_server should NEVER do any of this # Do not allow opening files from external storage as unsafe ejection # could cause the kernel to kill the system_server. neverallow system_server sdcard_type:dir { open read write }; neverallow system_server sdcard_type:file rw_file_perms; # system server should never be opening zygote spawned app data # files directly. Rather, they should always be passed via a # file descriptor. # Types extracted from seapp_contexts type= fields, excluding # those types that system_server needs to open directly. neverallow system_server { bluetooth_data_file nfc_data_file shell_data_file app_data_file }:file open; # system_server should never be executing dex2oat. This is either # a bug (for example, bug 16317188), or represents an attempt by # system server to dynamically load a dex file, something we do not # want to allow. neverallow system_server dex2oat_exec:file no_x_file_perms; # The only block device system_server should be accessing is # the frp_block_device. This helps avoid a system_server to root # escalation by writing to raw block devices. neverallow system_server { dev_type -frp_block_device }:blk_file no_rw_file_perms; #add by aggresss allow system_server hello_device:chr_file rw_file_perms; ================================================ FILE: Code/hello_HAL/Android.mk ================================================ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_PRELINK_MODULE := false LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw LOCAL_SHARED_LIBRARIES := liblog LOCAL_SRC_FILES := hello.c LOCAL_MODULE := hello.default include $(BUILD_SHARED_LIBRARY) ================================================ FILE: Code/hello_HAL/hello.c ================================================ #define LOG_TAG "HelloStub" #include #include #include #include #include #include #define DEVICE_NAME "/dev/hello" #define MODULE_NAME "Hello" #define MODULE_AUTHOR "shyluo@gmail.com" /*设备打开和关闭接口*/ static int hello_device_open(const struct hw_module_t* module, const char* name, struct hw_device_t** device); static int hello_device_close(struct hw_device_t* device); /*设备访问接口*/ static int hello_set_val(struct hello_device_t* dev, int val); static int hello_get_val(struct hello_device_t* dev, int* val); /*模块方法表*/ static struct hw_module_methods_t hello_module_methods = { open: hello_device_open }; /*模块实例变量*/ struct hello_module_t HAL_MODULE_INFO_SYM = { common: { tag: HARDWARE_MODULE_TAG, version_major: 1, version_minor: 0, id: HELLO_HARDWARE_MODULE_ID, name: MODULE_NAME, author: MODULE_AUTHOR, methods: &hello_module_methods, } }; static int hello_device_open(const struct hw_module_t* module, const char* name, struct hw_device_t** device) { struct hello_device_t* dev;dev = (struct hello_device_t*)malloc(sizeof(struct hello_device_t)); if(!dev) { ALOGE("Hello Stub: failed to alloc space"); return -EFAULT; } memset(dev, 0, sizeof(struct hello_device_t)); dev->common.tag = HARDWARE_DEVICE_TAG; dev->common.version = 0; dev->common.module = (hw_module_t*)module; dev->common.close = hello_device_close; dev->set_val = hello_set_val;dev->get_val = hello_get_val; if((dev->fd = open(DEVICE_NAME, O_RDWR)) == -1) { ALOGE("Hello Stub: failed to open /dev/hello -- %s.", strerror(errno));free(dev); return -EFAULT; } *device = &(dev->common); ALOGI("Hello Stub: open /dev/hello successfully."); return 0; } static int hello_device_close(struct hw_device_t* device) { struct hello_device_t* hello_device = (struct hello_device_t*)device; if(hello_device) { close(hello_device->fd); free(hello_device); } return 0; } static int hello_set_val(struct hello_device_t* dev, int val) { ALOGI("Hello Stub: set value %d to device.", val); write(dev->fd, &val, sizeof(val)); return 0; } static int hello_get_val(struct hello_device_t* dev, int* val) { if(!val) { ALOGE("Hello Stub: error val pointer"); return -EFAULT; } read(dev->fd, val, sizeof(*val)); ALOGI("Hello Stub: get value %d from device", *val); return 0; } ================================================ FILE: Code/hello_HAL/hello.h ================================================ #ifndef ANDROID_HELLO_INTERFACE_H #define ANDROID_HELLO_INTERFACE_H #include __BEGIN_DECLS /*定义模块ID*/ #define HELLO_HARDWARE_MODULE_ID "hello" /*硬件模块结构体*/ struct hello_module_t { struct hw_module_t common; }; /*硬件接口结构体*/ struct hello_device_t { struct hw_device_t common; int fd; int (*set_val)(struct hello_device_t* dev, int val); int (*get_val)(struct hello_device_t* dev, int* val); }; __END_DECLS #endif ================================================ FILE: Code/hello_JNI/com_android_server_HelloService.cpp ================================================ #define LOG_TAG "HelloService" #include "jni.h" #include "JNIHelp.h" #include "android_runtime/AndroidRuntime.h" #include #include #include #include #include namespace android { /*在硬件抽象层中定义的硬件访问结构体,参考*/ struct hello_device_t* hello_device = NULL; /*通过硬件抽象层定义的硬件访问接口设置硬件寄存器val的值*/ static void hello_setVal(JNIEnv* env, jobject clazz, jint value) { int val = value; ALOGI("Hello JNI: set value %d to device.", val); if(!hello_device) { ALOGI("Hello JNI: device is not open."); return; } hello_device->set_val(hello_device, val); } /*通过硬件抽象层定义的硬件访问接口读取硬件寄存器val的值*/ static jint hello_getVal(JNIEnv* env, jobject clazz) { int val = 0; if(!hello_device) { ALOGI("Hello JNI: device is not open."); return val; } hello_device->get_val(hello_device, &val); ALOGI("Hello JNI: get value %d from device.", val); return val; } /*通过硬件抽象层定义的硬件模块打开接口打开硬件设备*/ static inline int hello_device_open(const hw_module_t* module, struct hello_device_t** device) { return module->methods->open(module, HELLO_HARDWARE_MODULE_ID, (struct hw_device_t**)device); } /*通过硬件模块ID来加载指定的硬件抽象层模块并打开硬件*/ static jboolean hello_init(JNIEnv* env, jclass clazz) { hello_module_t* module; ALOGI("Hello JNI: initializing......"); if(hw_get_module(HELLO_HARDWARE_MODULE_ID, (const struct hw_module_t**)&module) == 0) { ALOGI("Hello JNI: hello Stub found."); if(hello_device_open(&(module->common), &hello_device) == 0) { ALOGI("Hello JNI: hello device is open."); return 0; } ALOGE("Hello JNI: failed to open hello device."); return -1; } ALOGE("Hello JNI: failed to get hello stub module."); return -1; } /*JNI方法表*/ static const JNINativeMethod method_table[] = { {"init_native", "()Z", (void*)hello_init}, {"setVal_native", "(I)V", (void*)hello_setVal}, {"getVal_native", "()I", (void*)hello_getVal}, }; /*注册JNI方法*/ int register_android_server_HelloService(JNIEnv *env) { return jniRegisterNativeMethods(env, "com/android/server/HelloService", method_table, NELEM(method_table)); } }; ================================================ FILE: Code/hello_KernelDriver/Kconfig ================================================ config HELLO tristate "First Android Driver" default n help This is the first android driver. ================================================ FILE: Code/hello_KernelDriver/Makefile ================================================ obj-$(CONFIG_HELLO) += hello.o ================================================ FILE: Code/hello_KernelDriver/hello.c ================================================ /******************************************* *include file and define functions *******************************************/ #include #include #include #include #include #include #include #include "hello.h" /*主设备和从设备号变量*/ static int hello_major = 0; static int hello_minor = 0; /*设备类别和设备变量*/ static struct class* hello_class = NULL; static struct hello_android_dev* hello_dev = NULL; /*传统的设备文件操作方法*/ static int hello_open(struct inode* inode, struct file* filp); static int hello_release(struct inode* inode, struct file* filp); static ssize_t hello_read(struct file* filp, char __user *buf, size_t count, loff_t* f_pos); static ssize_t hello_write(struct file* filp, const char __user *buf, size_t count, loff_t* f_pos); /*设备文件操作方法表*/ static struct file_operations hello_fops = { .owner = THIS_MODULE, .open = hello_open, .release = hello_release, .read = hello_read, .write = hello_write, }; /*访问设置属性方法*/ static ssize_t hello_val_show(struct device* dev, struct device_attribute* attr, char* buf); static ssize_t hello_val_store(struct device* dev, struct device_attribute* attr, const char* buf, size_t count); /*定义设备属性*/ static DEVICE_ATTR(val, S_IRUGO | S_IWUSR, hello_val_show, hello_val_store); /******************************************* *define traditional file access *******************************************/ /*打开设备方法*/ static int hello_open(struct inode* inode, struct file* filp) { struct hello_android_dev* dev; /*将自定义设备结构体保存在文件指针的私有数据域中,以便访问设备时拿来用*/ dev = container_of(inode->i_cdev, struct hello_android_dev, dev); filp->private_data = dev; return 0; } /*设备文件释放时调用,空实现*/ static int hello_release(struct inode* inode, struct file* filp) { return 0; } /*读取设备的寄存器val的值*/ static ssize_t hello_read(struct file* filp, char __user *buf, size_t count, loff_t* f_pos) { ssize_t err = 0; struct hello_android_dev* dev = filp->private_data; /*同步访问*/ if(down_interruptible(&(dev->sem))) { return -ERESTARTSYS; } if(count < sizeof(dev->val)) { goto out; } /*将寄存器val的值拷贝到用户提供的缓冲区*/ if(copy_to_user(buf, &(dev->val), sizeof(dev->val))) { err = -EFAULT; goto out; } err = sizeof(dev->val); out: up(&(dev->sem)); return err; } /*写设备的寄存器值val*/ static ssize_t hello_write(struct file* filp, const char __user *buf, size_t count, loff_t* f_pos) { struct hello_android_dev* dev = filp->private_data; ssize_t err = 0; /*同步访问*/ if(down_interruptible(&(dev->sem))) { return -ERESTARTSYS; } if(count != sizeof(dev->val)) { goto out; } /*将用户提供的缓冲区的值写到设备寄存器去*/ if(copy_from_user(&(dev->val), buf, count)) { err = -EFAULT; goto out; } err = sizeof(dev->val); out: up(&(dev->sem)); return err; } /******************************************* *define devfs access *******************************************/ /*读取寄存器val的值到缓冲区buf中,内部使用*/ static ssize_t __hello_get_val(struct hello_android_dev* dev, char* buf) { int val = 0; /*同步访问*/ if(down_interruptible(&(dev->sem))) { return -ERESTARTSYS; } val = dev->val; up(&(dev->sem)); return snprintf(buf, PAGE_SIZE, "%d\n", val); } /*把缓冲区buf的值写到设备寄存器val中去,内部使用*/ static ssize_t __hello_set_val(struct hello_android_dev* dev, const char* buf, size_t count) { int val = 0; /*将字符串转换成数字*/ val = simple_strtol(buf, NULL, 10); /*同步访问*/ if(down_interruptible(&(dev->sem))) { return -ERESTARTSYS; } dev->val = val; up(&(dev->sem)); return count; } /*读取设备属性val*/ static ssize_t hello_val_show(struct device* dev, struct device_attribute* attr, char* buf) { struct hello_android_dev* hdev = (struct hello_android_dev*)dev_get_drvdata(dev); return __hello_get_val(hdev, buf); } /*写设备属性val*/ static ssize_t hello_val_store(struct device* dev, struct device_attribute* attr, const char* buf, size_t count) { struct hello_android_dev* hdev = (struct hello_android_dev*)dev_get_drvdata(dev); return __hello_set_val(hdev, buf, count); } /******************************************* *define proc access *******************************************/ /*读取设备寄存器val的值,保存在page缓冲区中*/ static ssize_t hello_proc_read(char* page, char** start, off_t off, int count, int* eof, void* data) { if(off > 0) { *eof = 1; return 0; } return __hello_get_val(hello_dev, page); } /*把缓冲区的值buff保存到设备寄存器val中去*/ static ssize_t hello_proc_write(struct file* filp, const char __user *buff, unsigned long len, void* data) { int err = 0; char* page = NULL; if(len > PAGE_SIZE) { printk(KERN_ALERT"The buff is too large: %lu.\n", len); return -EFAULT; } page = (char*)__get_free_page(GFP_KERNEL); if(!page) { printk(KERN_ALERT"Failed to alloc page.\n"); return -ENOMEM; } /*先把用户提供的缓冲区值拷贝到内核缓冲区中去*/ if(copy_from_user(page, buff, len)) { printk(KERN_ALERT"Failed to copy buff from user.\n"); err = -EFAULT; goto out; } err = __hello_set_val(hello_dev, page, len); out: free_page((unsigned long)page); return err; } /*创建/proc/hello文件*/ static void hello_create_proc(void) { struct proc_dir_entry *entry; entry = create_proc_entry(HELLO_DEVICE_PROC_NAME, 0, NULL); if(entry) { entry->read_proc = hello_proc_read; entry->write_proc = hello_proc_write; } } /*删除/proc/hello文件*/ static void hello_remove_proc(void) { remove_proc_entry(HELLO_DEVICE_PROC_NAME, NULL); } /******************************************* *define load and remove function *******************************************/ /*初始化设备*/ static int __hello_setup_dev(struct hello_android_dev* dev) { int err; dev_t devno = MKDEV(hello_major, hello_minor); memset(dev, 0, sizeof(struct hello_android_dev)); cdev_init(&(dev->dev), &hello_fops); dev->dev.owner = THIS_MODULE; dev->dev.ops = &hello_fops; /*注册字符设备*/ err = cdev_add(&(dev->dev),devno, 1); if(err) { return err; } /*初始化信号量和寄存器val的值*/ sema_init(&(dev->sem), 1); dev->val = 0; return 0; } /*模块加载方法*/ static int __init hello_init(void){ int err = -1; dev_t dev = 0; struct device* temp = NULL; printk(KERN_ALERT"Initializing hello device.\n"); /*动态分配主设备和从设备号*/ err = alloc_chrdev_region(&dev, 0, 1, HELLO_DEVICE_NODE_NAME); if(err < 0) { printk(KERN_ALERT"Failed to alloc char dev region.\n"); goto fail; } hello_major = MAJOR(dev); hello_minor = MINOR(dev); /*分配helo设备结构体变量*/ hello_dev = kmalloc(sizeof(struct hello_android_dev), GFP_KERNEL); if(!hello_dev) { err = -ENOMEM; printk(KERN_ALERT"Failed to alloc hello_dev.\n"); goto unregister; } /*初始化设备*/ err = __hello_setup_dev(hello_dev); if(err) { printk(KERN_ALERT"Failed to setup dev: %d.\n", err); goto cleanup; } /*在/sys/class/目录下创建设备类别目录hello*/ hello_class = class_create(THIS_MODULE, HELLO_DEVICE_CLASS_NAME); if(IS_ERR(hello_class)) { err = PTR_ERR(hello_class); printk(KERN_ALERT"Failed to create hello class.\n"); goto destroy_cdev; } /*在/dev/目录和/sys/class/hello目录下分别创建设备文件hello*/ temp = device_create(hello_class, NULL, dev, "%s", HELLO_DEVICE_FILE_NAME); if(IS_ERR(temp)) { err = PTR_ERR(temp); printk(KERN_ALERT"Failed to create hello device."); goto destroy_class; } /*在/sys/class/hello/hello目录下创建属性文件val*/ err = device_create_file(temp, &dev_attr_val); if(err < 0) { printk(KERN_ALERT"Failed to create attribute val."); goto destroy_device; } dev_set_drvdata(temp, hello_dev); /*创建/proc/hello文件*/ hello_create_proc(); printk(KERN_ALERT"Succedded to initialize hello device.\n"); return 0; destroy_device: device_destroy(hello_class, dev); destroy_class: class_destroy(hello_class); destroy_cdev: cdev_del(&(hello_dev->dev)); cleanup: kfree(hello_dev); unregister: unregister_chrdev_region(MKDEV(hello_major, hello_minor), 1); fail: return err; } /*模块卸载方法*/ static void __exit hello_exit(void) { dev_t devno = MKDEV(hello_major, hello_minor); printk(KERN_ALERT"Destroy hello device.\n"); /*删除/proc/hello文件*/ hello_remove_proc(); /*销毁设备类别和设备*/ if(hello_class) { device_destroy(hello_class, MKDEV(hello_major, hello_minor)); class_destroy(hello_class); } /*删除字符设备和释放设备内存*/ if(hello_dev) { cdev_del(&(hello_dev->dev)); kfree(hello_dev); } /*释放设备号*/ unregister_chrdev_region(devno, 1); } MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("First Android Driver"); module_init(hello_init); module_exit(hello_exit); ================================================ FILE: Code/hello_KernelDriver/hello.h ================================================ #ifndef _HELLO_ANDROID_H_ #define _HELLO_ANDROID_H_ #include #include #define HELLO_DEVICE_NODE_NAME "hello" #define HELLO_DEVICE_FILE_NAME "hello" #define HELLO_DEVICE_PROC_NAME "hello" #define HELLO_DEVICE_CLASS_NAME "hello" struct hello_android_dev { int val; struct semaphore sem; struct cdev dev; }; #endif ================================================ FILE: README.md ================================================ # PHDemo #### 《手机就是开发板》 目录 ##### 第一期 前言 http://blog.csdn.net/aggresss/article/details/53364324 ##### 第二期 AOSP 环境搭建、下载和编译 http://blog.csdn.net/aggresss/article/details/53393511 ##### 第三期 Android Kernel 下载和编译 http://blog.csdn.net/aggresss/article/details/53461464 ##### 第四期 Android Studio 开发环境搭建和Helloworld演示 http://blog.csdn.net/aggresss/article/details/53525468 ##### 第五期 基于模拟器上的实践和学习规划 http://blog.csdn.net/aggresss/article/details/53538575 ##### 第六期 基于模拟器的Helloworld 内核驱动 http://blog.csdn.net/aggresss/article/details/53557699 ##### 第七期 基于模拟器的Helloworld 可执行程序 http://blog.csdn.net/aggresss/article/details/53561241 ##### 第八期 基于模拟器的Helloworld HAL接口 http://blog.csdn.net/aggresss/article/details/53571487 ##### 第九期 基于模拟器的Helloworld JNI方法 http://blog.csdn.net/aggresss/article/details/53575075 ##### 第十期 基于模拟器的Helloworld Framework接口 http://blog.csdn.net/aggresss/article/details/53576022 ##### 第十一期 基于模拟器的Helloworld APP 访问硬件服务 http://blog.csdn.net/aggresss/article/details/53580520 ##### 第十二期 Android ROM结构分析 http://blog.csdn.net/aggresss/article/details/53955998 ##### 第十三期 AOSP 编译环境初始化过程分析 http://blog.csdn.net/aggresss/article/details/53968884 ##### 第十四期 AOSP 编译系统分析 http://blog.csdn.net/aggresss/article/details/53976626 ##### 第十五期 在AOSP上建立一个新产品 http://blog.csdn.net/aggresss/article/details/53985084 ##### 第十六期 CyanogenMod 小米3W刷机 http://blog.csdn.net/aggresss/article/details/53998257 ##### 第十七期 CyanogenMod 编译小米3W http://blog.csdn.net/aggresss/article/details/53999626 ##### 第十八期 Android GPS原理分析 http://blog.csdn.net/aggresss/article/details/54318662 ##### 第十九期 Android中修改GPS数据实验 http://blog.csdn.net/aggresss/article/details/54318905 ##### 第二十期 在Android中修改GPS定位数据的完整方案 http://blog.csdn.net/aggresss/article/details/54323034 ================================================ FILE: Tools/51-android.rules ================================================ #Mi3W normal mode SUBSYSTEM=="usb",ATTR{idVendor}=="2717",ATTR{idProduct}=="0360",MODE="0666" #Mi3W developer mode SUBSYSTEM=="usb",ATTR{idVendor}=="2717",ATTR{idProduct}=="0368",MODE="0666" #Mi3W fastboot mode SUBSYSTEM=="usb",ATTR{idVendor}=="18d1",ATTR{idProduct}=="d00d",MODE="0666" #cyanogenmod recovry mode SUBSYSTEM=="usb",ATTR{idVendor}=="18d1",ATTR{idProduct}=="d001",MODE="0666" ================================================ FILE: Tools/cancro/proprietary-files.txt ================================================ etc/sdm_200_HOG3x3_Grid3x3_bin5_noproj_zero_reduced.bin.pca etc/android_model_faceg.dat etc/permissions/qcrilhook.xml etc/permissions/qcnvitems.xml etc/android_model_facea.dat etc/firmware/wcnss.b08 etc/firmware/wcnss.b06 etc/firmware/wcnss.mdt etc/firmware/wcnss.b09 etc/firmware/a330_pm4.fw etc/firmware/wcnss.b07 etc/firmware/wcnss.b00 etc/firmware/venus.b04 etc/firmware/a330_pfp.fw etc/firmware/venus.b02 etc/firmware/wcnss.b02 etc/firmware/venus.mdt etc/firmware/wcnss.b04 etc/firmware/cpp_firmware_v1_2_0.fw etc/firmware/cpp_firmware_v1_1_6.fw etc/firmware/cpp_firmware_v1_1_1.fw etc/firmware/venus.b00 etc/firmware/venus.b01 etc/firmware/venus.mbn etc/firmware/wcnss.b01 etc/firmware/venus.b03 etc/sensor_def_qcomdev.conf etc/data/dsi_config.xml etc/data/netmgr_config.xml etc/data/qmi_config.xml etc/sdm_200_HOG3x3_Grid3x3_bin5_noproj_zero_reduced.bin priv-app/qcrilmsgtunnel/qcrilmsgtunnel.apk lib/libdrmfs.so lib/libdrmdiag.so lib/libqomx_core.so lib/libchromatix_imx226_liveshot.so lib/hw/activity_recognition.msm8974.so lib/hw/gps.msm8974.so lib/hw/camera.vendor.msm8974.so lib/hw/consumerir.msm8974.so lib/libchromatix_imx214_liveshot.so lib/libqminvapi.so lib/libchromatix_imx219_liveshot.so lib/libchromatix_imx224_liveshot.so lib/libc2dcolorconvert.so lib/libchromatix_imx135_liveshot.so lib/libmmjpeg_interface.so lib/libloc_core.so lib/libloc_eng.so lib/libloc_ds_api.so lib/libchromatix_s5k3m2_liveshot.so lib/libgps.utils.so lib/libdrmtime.so lib/libmmcamera_interface.so lib/libstm-log.so lib/libloc_api_v02.so lib/libchromatix_imx225_liveshot.so lib/librpmb.so lib/libmdmdetect.so lib/drm/libdrmwvmplugin.so lib/libQSEEComAPI.so lib/libchromatix_imx215_liveshot.so lib/libOmxVenc.so lib/libRecoFace.so lib/libssd.so lib/libjhead.so lib/libjhead_jni.so lib/rfsa/adsp/libdspCV_skel.so lib/rfsa/adsp/libapps_mem_heap.so lib/rfsa/adsp/libfastcvadsp.so lib/rfsa/adsp/libfastcvadsp_skel.so lib/rfsa/adsp/libscveT2T_skel.so framework/qti-telephony-common.jar framework/qcnvitems.jar framework/qcrilhook.jar bin/rmt_storage bin/time_daemon bin/irsc_util bin/qmuxd bin/sensors.qcom bin/hvdcp bin/radish bin/mm-qcamera-daemon bin/lowi-server bin/qseecomd bin/xtwifi-client bin/charger_monitor bin/xtwifi-inet-agent bin/btnvtool bin/wcnss_filter bin/quipc_main bin/quipc_igsn bin/mpdecision bin/fm_qsoc_patches bin/netmgrd bin/rfs_access bin/wcnss_service bin/qosmgr bin/adsprpcd vendor/lib/libadreno_utils.so vendor/lib/libmmcamera2_vpe_module.so vendor/lib/libTimeService.so vendor/lib/libchromatix_imx132_default_video.so vendor/lib/libchromatix_imx215_preview.so vendor/lib/libchromatix_s5k3l1yx_hfr_120fps.so vendor/lib/libchromatix_imx226_common.so vendor/lib/libmmcamera2_cpp_module.so vendor/lib/libchromatix_s5k3m2_video_uhd.so vendor/lib/libmmcamera_hi256.so vendor/lib/libchromatix_s5k3m2_snapshot_hdr.so vendor/lib/libmm-hdcpmgr.so vendor/lib/libchromatix_skuf_ov12830_p12v01c_zsl.so vendor/lib/libchromatix_imx225_snapshot.so vendor/lib/libfastcvopt.so vendor/lib/libmmcamera_SKUAA_ST_gc0339.so vendor/lib/libchromatix_ov5648_oty5f03_common.so vendor/lib/libmmcamera2_frame_algorithm.so vendor/lib/libquipc_os_api.so vendor/lib/libchromatix_skuf_ov12830_p12v01c_default_video.so vendor/lib/libchromatix_ov8825_liveshot_hd.so vendor/lib/libcneapiclient.so vendor/lib/libchromatix_s5k3l1yx_hfr_90fps.so vendor/lib/libchromatix_ov5648_oty5f03_snapshot.so vendor/lib/libchromatix_imx224_snapshot_w.so vendor/lib/libjpegdhw.so vendor/lib/libacdbloader.so vendor/lib/libchromatix_ov9724_preview.so vendor/lib/libFaceProc.so vendor/lib/libchromatix_imx224_hfr_120.so vendor/lib/libchromatix_SKUAB_ST_s5k4e1_video_hd.so vendor/lib/libmm-abl.so vendor/lib/libchromatix_imx214_snapshot_w.so vendor/lib/libactuator_rohm_bu64243gwz_camcorder.so vendor/lib/libmmcamera_sunny_p12v01m_eeprom.so vendor/lib/libchromatix_s5k3l1yx_liveshot.so vendor/lib/libc2d30-a4xx.so vendor/lib/libsrsprocessing.so vendor/lib/libqct_resampler.so vendor/lib/libactuator_ov8825_camcorder.so vendor/lib/libchromatix_ov8825_preview.so vendor/lib/libchromatix_ov2720_default_video.so vendor/lib/libchromatix_imx215_video_hdr_uhd.so vendor/lib/libactuator_bu6313_camcorder.so vendor/lib/libchromatix_skuf_ov12830_p12v01c_video_hd.so vendor/lib/libactuator_dw9716_camera.so vendor/lib/libchromatix_ov8825_snapshot_hd.so vendor/lib/hw/sensors.msm8974.so vendor/lib/hw/flp.default.so vendor/lib/libchromatix_skuf_ov12830_p12v01c_hfr_60fps.so vendor/lib/libmmcamera_imx135.so vendor/lib/libchromatix_imx226_snapshot_hdr.so vendor/lib/libchromatix_imx215_snapshot_w.so vendor/lib/libWVStreamControlAPI_L1.so vendor/lib/libacdbrtac.so vendor/lib/mediadrm/libdrmclearkeyplugin.so vendor/lib/mediadrm/libwvdrmengine.so vendor/lib/libmmcamera_imx219.so vendor/lib/libRSDriver_adreno.so vendor/lib/libactuator_ad5823_camera.so vendor/lib/libchromatix_ov8825_snapshot.so vendor/lib/libdiag.so vendor/lib/libactuator_iu074_camera.so vendor/lib/libchromatix_ov4688_preview.so vendor/lib/libC2D2.so vendor/lib/libchromatix_imx215_snapshot_hdr.so vendor/lib/libchromatix_ov8865_q8v18a_zsl.so vendor/lib/libchromatix_imx214_snapshot.so vendor/lib/libacdbmapper.so vendor/lib/libchromatix_ov8865_q8v18a_video_hd.so vendor/lib/libchromatix_imx134_preview.so vendor/lib/libchromatix_ov5648_oty5f03_default_video.so vendor/lib/libsmemlog.so vendor/lib/liboemcamera.so vendor/lib/libchromatix_imx134_snapshot.so vendor/lib/libchromatix_imx224_video_uhd.so vendor/lib/libchromatix_skuf_ov5648_p5v23c_common.so vendor/lib/libchromatix_imx215_video_hdr.so vendor/lib/libchromatix_imx132_preview.so vendor/lib/libqcci_legacy.so vendor/lib/libactuator_dw9716.so vendor/lib/libchromatix_imx225_common.so vendor/lib/libchromatix_skuf_ov12830_p12v01c_hfr_90fps.so vendor/lib/libchromatix_imx214_snapshot_hdr.so vendor/lib/libchromatix_imx135_hfr_60.so vendor/lib/libxtwifi_ulp_adaptor.so vendor/lib/libchromatix_ov5648_oty5f03_zsl.so vendor/lib/libchromatix_SKUAA_ST_gc0339_default_video.so vendor/lib/libchromatix_ov8865_q8v18a_liveshot.so vendor/lib/lib-dplmedia.so vendor/lib/libchromatix_ov5648_oty5f03_preview.so vendor/lib/libtime_genoff.so vendor/lib/libmmcamera_imx226.so vendor/lib/liblocationservice.so vendor/lib/libactuator_ov12830_camera.so vendor/lib/libchromatix_ov8825_hfr_60fps.so vendor/lib/libchromatix_imx224_snapshot_hdr.so vendor/lib/libmmcamera_skuf_ov12830_p12v01c.so vendor/lib/libgeofence.so vendor/lib/libasn1crtx.so vendor/lib/librs_adreno_sha1.so vendor/lib/libchromatix_skuab_shinetech_gc0339_common.so vendor/lib/libmmcamera_ubifocus_lib.so vendor/lib/libchromatix_ov8865_q8v18a_default_video.so vendor/lib/libmmcamera2_iface_modules.so vendor/lib/libmmcamera_ov9724.so vendor/lib/libchromatix_imx214_video_hdr.so vendor/lib/libchromatix_SKUAB_ST_s5k4e1_snapshot.so vendor/lib/libchromatix_imx215_default_video.so vendor/lib/libactuator_ak7345.so vendor/lib/libchromatix_skuab_shinetech_gc0339_snapshot.so vendor/lib/libchromatix_ov8825_preview_hd.so vendor/lib/libchromatix_imx224_snapshot.so vendor/lib/libmmcamera_x5_imx214_eeprom.so vendor/lib/libmmcamera_chromaflash_lib.so vendor/lib/libchromatix_imx224_common.so vendor/lib/libchromatix_skuf_ov5648_p5v23c_default_video.so vendor/lib/liblbs_core.so vendor/lib/libchromatix_s5k3m2_video_hdr.so vendor/lib/libchromatix_imx219_common.so vendor/lib/libchromatix_skuf_ov12830_p12v01c_snapshot.so vendor/lib/libchromatix_imx226_video_hdr.so vendor/lib/libmmcamera_ov2720.so vendor/lib/libchromatix_imx226_snapshot_w.so vendor/lib/libqmi.so vendor/lib/libchromatix_imx214_video_uhd.so vendor/lib/libqmi_csvt_srvc.so vendor/lib/libchromatix_imx225_video_uhd.so vendor/lib/libchromatix_s5k3l1yx_default_video.so vendor/lib/libchromatix_ov8865_q8v18a_hfr_120fps.so vendor/lib/libCB.so vendor/lib/libchromatix_imx214_preview.so vendor/lib/libchromatix_skuab_shinetech_gc0339_default_video.so vendor/lib/libSHIMDivxDrm.so vendor/lib/libactuator_ov8825_camera.so vendor/lib/libchromatix_ov4688_zsl.so vendor/lib/libchromatix_SKUAA_ST_gc0339_common.so vendor/lib/libmmcamera2_sensor_modules.so vendor/lib/libaudioalsa.so vendor/lib/libchromatix_imx214_video_hdr_uhd.so vendor/lib/libchromatix_imx214_common.so vendor/lib/librs_adreno.so vendor/lib/libchromatix_SKUAB_ST_s5k4e1_default_video.so vendor/lib/libchromatix_imx134_hfr_60.so vendor/lib/libulp2.so vendor/lib/libchromatix_imx224_video_hdr.so vendor/lib/libril-qc-qmi-1.so vendor/lib/libmmcamera_truly_cm7700_eeprom.so vendor/lib/libchromatix_s5k3m2_hfr_120fps.so vendor/lib/libNimsWrap.so vendor/lib/libchromatix_ov4689_preview.so vendor/lib/libbccQTI.so vendor/lib/libmmcamera_tintless_bg_pca_algo.so vendor/lib/libqomx_jpegenc.so vendor/lib/libbtnv.so vendor/lib/libchromatix_imx219_default_video.so vendor/lib/libmmcamera2_is.so vendor/lib/libactuator_ad5823.so vendor/lib/libgsl.so vendor/lib/libchromatix_skuf_ov5648_p5v23c_snapshot.so vendor/lib/libmmcamera_SKUAB_ST_s5k4e1.so vendor/lib/libmmqjpeg_codec.so vendor/lib/libchromatix_s5k3l1yx_video_hd.so vendor/lib/libactuator_rohm_bu64243gwz_camera.so vendor/lib/libchromatix_skuf_ov12830_p12v01c_hfr_120fps.so vendor/lib/libchromatix_s5k3m2_snapshot_w.so vendor/lib/libchromatix_ov8825_video_hd.so vendor/lib/libchromatix_imx135_preview.so vendor/lib/libarcsoft_beauty_shot.so vendor/lib/libmmcamera_ov4688.so vendor/lib/libactuator_bu6313_camera.so vendor/lib/libchromatix_s5k3l1yx_zsl.so vendor/lib/libsensor_test.so vendor/lib/libmmcamera2_q3a_special.so vendor/lib/libmmcamera_ov4689.so vendor/lib/libchromatix_ov4689_common.so vendor/lib/libqti-perfd-client.so vendor/lib/lib-rtpsl.so vendor/lib/libmmcamera_imx225.so vendor/lib/libchromatix_ov8825_common.so vendor/lib/libmmcamera2_stats_algorithm.so vendor/lib/libchromatix_imx134_hfr_120.so vendor/lib/lib-rtpdaemoninterface.so vendor/lib/libactuator_bu6313.so vendor/lib/libchromatix_ov4689_zsl.so vendor/lib/libOpenCL.so vendor/lib/libmmcamera_imx224.so vendor/lib/libchromatix_skuf_ov12830_p12v01c_common.so vendor/lib/libchromatix_SKUAB_ST_s5k4e1_liveshot.so vendor/lib/libsensor_reg.so vendor/lib/libasn1crt.so vendor/lib/libmmcamera2_pproc_modules.so vendor/lib/libt2tmanager.so vendor/lib/libchromatix_imx225_preview.so vendor/lib/libchromatix_s5k3m2_preview.so vendor/lib/libactuator_iu074.so vendor/lib/libchromatix_SKUAA_ST_gc0339_preview.so vendor/lib/libchromatix_imx132_snapshot.so vendor/lib/libchromatix_ov8865_q8v18a_preview.so vendor/lib/libchromaflash.so vendor/lib/libjpegehw.so vendor/lib/libqmi_client_qmux.so vendor/lib/libfastcvadsp_stub.so vendor/lib/libc2d30-a3xx.so vendor/lib/soundfx/libqcbassboost.so vendor/lib/soundfx/libqcreverb.so vendor/lib/soundfx/libqcvirt.so vendor/lib/soundfx/libdirac.so vendor/lib/libchromatix_imx224_video_hdr_uhd.so vendor/lib/libmmipl.so vendor/lib/libqmi_common_so.so vendor/lib/libmm-abl-oem.so vendor/lib/libchromatix_s5k3m2_default_video.so vendor/lib/libchromatix_ov9724_default_video.so vendor/lib/libmmQSM.so vendor/lib/libchromatix_imx225_video_hdr_uhd.so vendor/lib/libactuator_ad5823_camcorder.so vendor/lib/libWVphoneAPI.so vendor/lib/libaudcal.so vendor/lib/libchromatix_imx219_snapshot.so vendor/lib/libmmcamera_skuab_shinetech_gc0339.so vendor/lib/libizat_core.so vendor/lib/libactuator_rohm_bu64243gwz.so vendor/lib/libdsutils.so vendor/lib/libchromatix_imx215_hfr_120.so vendor/lib/libchromatix_imx226_hfr_120.so vendor/lib/libactuator_ak7345_camcorder.so vendor/lib/libchromatix_ov2720_liveshot.so vendor/lib/libwvdrm_L1.so vendor/lib/libactuator_lc8214_camera.so vendor/lib/libmmcamera2_wnr_module.so vendor/lib/libmmcamera_imglib.so vendor/lib/libquipc_ulp_adapter.so vendor/lib/libmmcamera_faceproc.so vendor/lib/libchromatix_ov4688_hfr.so vendor/lib/libasn1cper.so vendor/lib/libchromatix_imx214_hfr_120.so vendor/lib/libmmcamera_s5k3m2.so vendor/lib/libchromatix_ov9724_liveshot.so vendor/lib/libmmjpeg.so vendor/lib/libchromatix_imx214_default_video.so vendor/lib/libmmcamera2_stats_modules.so vendor/lib/libnetmgr.so vendor/lib/libchromatix_imx219_preview.so vendor/lib/libmmcamera_sunny_q8v18a_eeprom.so vendor/lib/libscve.so vendor/lib/libchromatix_ov8825_default_video.so vendor/lib/libchromatix_ov2720_hfr.so vendor/lib/libchromatix_ov4688_liveshot.so vendor/lib/libmmcamera2_c2d_module.so vendor/lib/libactuator_lc8214_camcorder.so vendor/lib/libchromatix_skuab_shinetech_gc0339_liveshot.so vendor/lib/libchromatix_s5k3l1yx_preview.so vendor/lib/libmmcamera_sunny_p5v23c_eeprom.so vendor/lib/libI420colorconvert.so vendor/lib/libchromatix_skuab_shinetech_gc0339_preview.so vendor/lib/libsensor_user_cal.so vendor/lib/libDivxDrm.so vendor/lib/libDiracAPI_SHARED.so vendor/lib/libchromatix_ov4688_common.so vendor/lib/libchromatix_imx225_default_video.so vendor/lib/libqdp.so vendor/lib/libchromatix_ov8825_hfr_120fps.so vendor/lib/libchromatix_imx226_video_hdr_uhd.so vendor/lib/libHevcSwDecoder.so vendor/lib/libchromatix_ov2720_common.so vendor/lib/libchromatix_ov4689_hfr.so vendor/lib/libchromatix_ov9724_common.so vendor/lib/libmmcamera_wavelet_lib.so vendor/lib/libchromatix_imx226_default_video.so vendor/lib/libmmcamera_mt9m114.so vendor/lib/libchromatix_ov8825_hfr_90fps.so vendor/lib/libqmi_cci.so vendor/lib/libchromatix_imx224_preview.so vendor/lib/libchromatix_imx225_snapshot_hdr.so vendor/lib/libchromatix_skuab_shinetech_gc0339_zsl.so vendor/lib/libscve_stub.so vendor/lib/libactuator_dw9714_camera.so vendor/lib/libchromatix_imx215_snapshot.so vendor/lib/egl/eglsubAndroid.so vendor/lib/egl/libq3dtools_adreno.so vendor/lib/egl/libEGL_adreno.so vendor/lib/egl/libGLESv1_CM_adreno.so vendor/lib/egl/libGLESv2_adreno.so vendor/lib/libmmosal.so vendor/lib/libsc-a2xx.so vendor/lib/libchromatix_s5k3l1yx_hfr_60fps.so vendor/lib/libconfigdb.so vendor/lib/libchromatix_SKUAB_ST_s5k4e1_zsl.so vendor/lib/libmmcamera_imx214.so vendor/lib/libmmcamera2_imglib_modules.so vendor/lib/libchromatix_ov8825_zsl.so vendor/lib/libchromatix_imx215_video_uhd.so vendor/lib/libactuator_ov12830_camcorder.so vendor/lib/libchromatix_ov4689_default_video.so vendor/lib/libmmcamera_ov5648_oty5f03.so vendor/lib/libsystem_health_mon.so vendor/lib/libqmi_csi.so vendor/lib/libxtadapter.so vendor/lib/libchromatix_imx226_snapshot.so vendor/lib/libmmcamera_imx134.so vendor/lib/libmmcamera2_isp_modules.so vendor/lib/libchromatix_skuf_ov12830_p12v01c_preview.so vendor/lib/libmmcamera_tintless_algo.so vendor/lib/libmmcamera_imx132.so vendor/lib/libchromatix_skuf_ov5648_p5v23c_preview.so vendor/lib/libchromatix_s5k3m2_common.so vendor/lib/libchromatix_SKUAB_ST_s5k4e1_common.so vendor/lib/libchromatix_imx135_hfr_90.so vendor/lib/libchromatix_SKUAB_ST_s5k4e1_hfr_90fps.so vendor/lib/libxtwifi_zpp_adaptor.so vendor/lib/libchromatix_s5k3l1yx_snapshot.so vendor/lib/libmm-color-convertor.so vendor/lib/libactuator_lc8214.so vendor/lib/libmmcamera_hdr_gb_lib.so vendor/lib/lib-rtpcommon.so vendor/lib/libchromatix_ov8865_q8v18a_snapshot.so vendor/lib/libchromatix_SKUAB_ST_s5k4e1_hfr_60fps.so vendor/lib/libperipheral_client.so vendor/lib/libsc-a3xx.so vendor/lib/libchromatix_ov4688_default_video.so vendor/lib/libchromatix_imx135_common.so vendor/lib/libchromatix_SKUAB_ST_s5k4e1_hfr_120fps.so vendor/lib/libchromatix_ov8825_liveshot.so vendor/lib/libmmcamera_skuf_ov5648_p5v23c.so vendor/lib/libactuator_dw9716_camcorder.so vendor/lib/libmmcamera_ov8865_q8v18a.so vendor/lib/libchromatix_s5k3m2_snapshot.so vendor/lib/libmmcamera_s5k3l1yx.so vendor/lib/libchromatix_SKUAB_ST_s5k4e1_preview.so vendor/lib/libmmcamera_hdr_lib.so vendor/lib/libqomx_jpegdec.so vendor/lib/libchromatix_imx134_common.so vendor/lib/libchromatix_imx215_common.so vendor/lib/liboemcrypto.so vendor/lib/libmmcamera_imx215.so vendor/lib/libsensor1.so vendor/lib/libllvm-qcom.so vendor/lib/libactuator_iu074_camcorder.so vendor/lib/libchromatix_ov4689_liveshot.so vendor/lib/libchromatix_imx134_default_video.so vendor/lib/libadsprpc.so vendor/lib/libchromatix_imx225_snapshot_w.so vendor/lib/libril-qcril-hook-oem.so vendor/lib/libdsi_netctrl.so vendor/lib/libscale.so vendor/lib/libchromatix_s5k3m2_video_hdr_uhd.so vendor/lib/libchromatix_imx135_hfr_120.so vendor/lib/libadiertac.so vendor/lib/libactuator_ov8825.so vendor/lib/libchromatix_imx226_video_uhd.so vendor/lib/libactuator_dw9714.so vendor/lib/libdisp-aba.so vendor/lib/libAKM8963.so vendor/lib/libchromatix_ov8865_q8v18a_hfr_90fps.so vendor/lib/libwifiscanner.so vendor/lib/libactuator_ov12830.so vendor/lib/libchromatix_imx132_common.so vendor/lib/libwvm.so vendor/lib/libchromatix_imx226_preview.so vendor/lib/libchromatix_ov2720_preview.so vendor/lib/libchromatix_imx225_video_hdr.so vendor/lib/libqmiservices.so vendor/lib/libmmcamera_ofilm_oty5f03_eeprom.so vendor/lib/libqmi_encdec.so vendor/lib/libchromatix_imx225_hfr_120.so vendor/lib/libmmcamera_x4_s5k3m2_eeprom.so vendor/lib/libchromatix_ov8865_q8v18a_common.so vendor/lib/libxml.so vendor/lib/libchromatix_ov2720_zsl.so vendor/lib/libmmcamera_ov8825.so vendor/lib/libchromatix_imx135_default_video.so vendor/lib/libactuator_ak7345_camera.so vendor/lib/libchromatix_imx132_liveshot.so vendor/lib/lib-rtpcore.so vendor/lib/libchromatix_imx135_snapshot.so vendor/lib/libchromatix_s5k3l1yx_common.so vendor/lib/libqdi.so vendor/lib/libidl.so vendor/lib/libactuator_dw9714_camcorder.so vendor/lib/libchromatix_imx224_default_video.so vendor/lib/libmmcamera_sp1628.so vendor/lib/libchromatix_imx135_video_hd.so vendor/lib/libchromatix_ov8865_q8v18a_hfr_60fps.so vendor/lib/libdrmdecrypt.so vendor/firmware/keymaster/keymaster.b01 vendor/firmware/keymaster/keymaster.b02 vendor/firmware/keymaster/keymaster.b00 vendor/firmware/keymaster/keymaster.b03 vendor/firmware/keymaster/keymaster.mdt vendor/firmware/bcm2079x-b5_pre_firmware.ncd vendor/firmware/bcm2079x-b5_firmware.ncd app/Snap/Snap.apk app/TimeService/TimeService.apk app/shutdownlistener/shutdownlistener.apk ../sbin/e2fsck_static ../sbin/chargeonlymode ================================================ FILE: Tools/sdat2img.py ================================================ #!/usr/bin/env python # -*- coding: utf-8 -*- #==================================================== # FILE: sdat2img.py # AUTHORS: xpirt - luxi78 - howellzhu # DATE: 2016-11-23 16:20:11 CST #==================================================== import sys, os, errno __version__ = '1.0' if sys.hexversion < 0x02070000: print >> sys.stderr, "Python 2.7 or newer is required." try: input = raw_input except NameError: pass input('Press ENTER to exit...') sys.exit(1) else: print('sdat2img binary - version: %s\n' % __version__) try: TRANSFER_LIST_FILE = str(sys.argv[1]) NEW_DATA_FILE = str(sys.argv[2]) except IndexError: print('\nUsage: sdat2img.py [system_img]\n') print(' : transfer list file') print(' : system new dat file') print(' [system_img]: output system image\n\n') print('Visit xda thread for more information.\n') try: input = raw_input except NameError: pass input('Press ENTER to exit...') sys.exit() try: OUTPUT_IMAGE_FILE = str(sys.argv[3]) except IndexError: OUTPUT_IMAGE_FILE = 'system.img' BLOCK_SIZE = 4096 def rangeset(src): src_set = src.split(',') num_set = [int(item) for item in src_set] if len(num_set) != num_set[0]+1: print('Error on parsing following data to rangeset:\n%s' % src) sys.exit(1) return tuple ([ (num_set[i], num_set[i+1]) for i in range(1, len(num_set), 2) ]) def parse_transfer_list_file(path): trans_list = open(TRANSFER_LIST_FILE, 'r') # First line in transfer list is the version number version = int(trans_list.readline()) # Second line in transfer list is the total number of blocks we expect to write new_blocks = int(trans_list.readline()) if version >= 2: # Third line is how many stash entries are needed simultaneously trans_list.readline() # Fourth line is the maximum number of blocks that will be stashed simultaneously trans_list.readline() # Subsequent lines are all individual transfer commands commands = [] for line in trans_list: line = line.split(' ') cmd = line[0] if cmd in ['erase', 'new', 'zero']: commands.append([cmd, rangeset(line[1])]) else: # Skip lines starting with numbers, they are not commands anyway if not cmd[0].isdigit(): print('Command "%s" is not valid.' % cmd) trans_list.close() sys.exit(1) trans_list.close() return version, new_blocks, commands def main(argv): version, new_blocks, commands = parse_transfer_list_file(TRANSFER_LIST_FILE) if version == 1: print('Android Lollipop 5.0 detected!\n') elif version == 2: print('Android Lollipop 5.1 detected!\n') elif version == 3: print('Android Marshmallow 6.0 detected!\n') elif version == 4: print('Android Nougat 7.0 detected!\n') else: print('Unknown Android version!\n') # Don't clobber existing files to avoid accidental data loss try: output_img = open(OUTPUT_IMAGE_FILE, 'wb') except IOError as e: if e.errno == errno.EEXIST: print('Error: the output file "{}" already exists'.format(e.filename)) print('Remove it, rename it, or choose a different file name.') sys.exit(e.errno) else: raise new_data_file = open(NEW_DATA_FILE, 'rb') all_block_sets = [i for command in commands for i in command[1]] max_file_size = max(pair[1] for pair in all_block_sets)*BLOCK_SIZE for command in commands: if command[0] == 'new': for block in command[1]: begin = block[0] end = block[1] block_count = end - begin print('Copying {} blocks into position {}...'.format(block_count, begin)) # Position output file output_img.seek(begin*BLOCK_SIZE) # Copy one block at a time while(block_count > 0): output_img.write(new_data_file.read(BLOCK_SIZE)) block_count -= 1 else: print('Skipping command %s...' % command[0]) # Make file larger if necessary if(output_img.tell() < max_file_size): output_img.truncate(max_file_size) output_img.close() new_data_file.close() print('Done! Output image: %s' % os.path.realpath(output_img.name)) if __name__ == '__main__': main(sys.argv) ================================================ FILE: VirtualPosition/Modification/com_android_server_location_GpsLocationProvider.cpp ================================================ /* * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "GpsLocationProvider" #define LOG_NDEBUG 0 #include "JNIHelp.h" #include "jni.h" #include "hardware/hardware.h" #include "hardware/gps.h" #include "hardware/vp.h" #include "hardware_legacy/power.h" #include "utils/Log.h" #include "utils/misc.h" #include "android_runtime/AndroidRuntime.h" #include "android_runtime/Log.h" #include #include #include #include #include #include static jobject mCallbacksObj = NULL; static jmethodID method_reportLocation; static jmethodID method_reportStatus; static jmethodID method_reportSvStatus; static jmethodID method_reportAGpsStatus; static jmethodID method_reportNmea; static jmethodID method_setEngineCapabilities; static jmethodID method_xtraDownloadRequest; static jmethodID method_reportNiNotification; static jmethodID method_requestRefLocation; static jmethodID method_requestSetID; static jmethodID method_requestUtcTime; static jmethodID method_reportGeofenceTransition; static jmethodID method_reportGeofenceStatus; static jmethodID method_reportGeofenceAddStatus; static jmethodID method_reportGeofenceRemoveStatus; static jmethodID method_reportGeofencePauseStatus; static jmethodID method_reportGeofenceResumeStatus; static jmethodID method_reportMeasurementData; static jmethodID method_reportNavigationMessages; static const GpsInterface* sGpsInterface = NULL; static const GpsXtraInterface* sGpsXtraInterface = NULL; static const AGpsInterface* sAGpsInterface = NULL; static const GpsNiInterface* sGpsNiInterface = NULL; static const GpsDebugInterface* sGpsDebugInterface = NULL; static const AGpsRilInterface* sAGpsRilInterface = NULL; static const GpsGeofencingInterface* sGpsGeofencingInterface = NULL; static const GpsMeasurementInterface* sGpsMeasurementInterface = NULL; static const GpsNavigationMessageInterface* sGpsNavigationMessageInterface = NULL; static const GnssConfigurationInterface* sGnssConfigurationInterface = NULL; // temporary storage for GPS callbacks static GpsSvStatus sGpsSvStatus; static const char* sNmeaString; static int sNmeaStringLength; #define WAKE_LOCK_NAME "GPS" namespace android { // add by aggresss static int vp_fd = open("/dev/vp", O_RDWR); static VirtualPosition vp_val; static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) { if (env->ExceptionCheck()) { ALOGE("An exception was thrown by callback '%s'.", methodName); LOGE_EX(env); env->ExceptionClear(); } } static void location_callback(GpsLocation* location) { JNIEnv* env = AndroidRuntime::getJNIEnv(); //add by aggresss read(vp_fd, &vp_val, sizeof(VirtualPosition)); if(vp_val.toggle == 1){ env->CallVoidMethod(mCallbacksObj, method_reportLocation, location->flags, (jdouble)vp_val.virtual_latitude, (jdouble)vp_val.virtual_longitude, (jdouble)location->altitude, (jfloat)location->speed, (jfloat)location->bearing, (jfloat)location->accuracy, (jlong)location->timestamp); checkAndClearExceptionFromCallback(env, __FUNCTION__); } else{ env->CallVoidMethod(mCallbacksObj, method_reportLocation, location->flags, (jdouble)location->latitude, (jdouble)location->longitude, (jdouble)location->altitude, (jfloat)location->speed, (jfloat)location->bearing, (jfloat)location->accuracy, (jlong)location->timestamp); checkAndClearExceptionFromCallback(env, __FUNCTION__); } } static void status_callback(GpsStatus* status) { JNIEnv* env = AndroidRuntime::getJNIEnv(); env->CallVoidMethod(mCallbacksObj, method_reportStatus, status->status); checkAndClearExceptionFromCallback(env, __FUNCTION__); } static void sv_status_callback(GpsSvStatus* sv_status) { JNIEnv* env = AndroidRuntime::getJNIEnv(); memcpy(&sGpsSvStatus, sv_status, sizeof(sGpsSvStatus)); env->CallVoidMethod(mCallbacksObj, method_reportSvStatus); checkAndClearExceptionFromCallback(env, __FUNCTION__); } static void nmea_callback(GpsUtcTime timestamp, const char* nmea, int length) { JNIEnv* env = AndroidRuntime::getJNIEnv(); // The Java code will call back to read these values // We do this to avoid creating unnecessary String objects sNmeaString = nmea; sNmeaStringLength = length; env->CallVoidMethod(mCallbacksObj, method_reportNmea, timestamp); checkAndClearExceptionFromCallback(env, __FUNCTION__); } static void set_capabilities_callback(uint32_t capabilities) { ALOGD("set_capabilities_callback: %du\n", capabilities); JNIEnv* env = AndroidRuntime::getJNIEnv(); env->CallVoidMethod(mCallbacksObj, method_setEngineCapabilities, capabilities); checkAndClearExceptionFromCallback(env, __FUNCTION__); } static void acquire_wakelock_callback() { acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME); } static void release_wakelock_callback() { release_wake_lock(WAKE_LOCK_NAME); } static void request_utc_time_callback() { JNIEnv* env = AndroidRuntime::getJNIEnv(); env->CallVoidMethod(mCallbacksObj, method_requestUtcTime); checkAndClearExceptionFromCallback(env, __FUNCTION__); } static pthread_t create_thread_callback(const char* name, void (*start)(void *), void* arg) { return (pthread_t)AndroidRuntime::createJavaThread(name, start, arg); } GpsCallbacks sGpsCallbacks = { sizeof(GpsCallbacks), location_callback, status_callback, sv_status_callback, nmea_callback, set_capabilities_callback, acquire_wakelock_callback, release_wakelock_callback, create_thread_callback, request_utc_time_callback, }; static void xtra_download_request_callback() { JNIEnv* env = AndroidRuntime::getJNIEnv(); env->CallVoidMethod(mCallbacksObj, method_xtraDownloadRequest); checkAndClearExceptionFromCallback(env, __FUNCTION__); } GpsXtraCallbacks sGpsXtraCallbacks = { xtra_download_request_callback, create_thread_callback, }; static jbyteArray convert_to_ipv4(uint32_t ip, bool net_order) { if (INADDR_NONE == ip) { return NULL; } JNIEnv* env = AndroidRuntime::getJNIEnv(); jbyteArray byteArray = env->NewByteArray(4); if (byteArray == NULL) { ALOGE("Unable to allocate byte array for IPv4 address"); return NULL; } jbyte ipv4[4]; if (net_order) { ALOGV("Converting IPv4 address(net_order) %x", ip); memcpy(ipv4, &ip, sizeof(ipv4)); } else { ALOGV("Converting IPv4 address(host_order) %x", ip); //endianess transparent conversion from int to char[] ipv4[0] = (jbyte) (ip & 0xFF); ipv4[1] = (jbyte)((ip>>8) & 0xFF); ipv4[2] = (jbyte)((ip>>16) & 0xFF); ipv4[3] = (jbyte) (ip>>24); } env->SetByteArrayRegion(byteArray, 0, 4, (const jbyte*) ipv4); return byteArray; } static void agps_status_callback(AGpsStatus* agps_status) { JNIEnv* env = AndroidRuntime::getJNIEnv(); jbyteArray byteArray = NULL; bool isSupported = false; size_t status_size = agps_status->size; if (status_size == sizeof(AGpsStatus_v3)) { ALOGV("AGpsStatus is V3: %zd", status_size); switch (agps_status->addr.ss_family) { case AF_INET: { struct sockaddr_in *in = (struct sockaddr_in*)&(agps_status->addr); uint32_t ipAddr = *(uint32_t*)&(in->sin_addr); byteArray = convert_to_ipv4(ipAddr, true /* net_order */); if (ipAddr == INADDR_NONE || byteArray != NULL) { isSupported = true; } IF_ALOGD() { // log the IP for reference in case there is a bogus value pushed by HAL char str[INET_ADDRSTRLEN]; inet_ntop(AF_INET, &(in->sin_addr), str, INET_ADDRSTRLEN); ALOGD("AGPS IP is v4: %s", str); } } break; case AF_INET6: { struct sockaddr_in6 *in6 = (struct sockaddr_in6*)&(agps_status->addr); byteArray = env->NewByteArray(16); if (byteArray != NULL) { env->SetByteArrayRegion(byteArray, 0, 16, (const jbyte *)&(in6->sin6_addr)); isSupported = true; } else { ALOGE("Unable to allocate byte array for IPv6 address."); } IF_ALOGD() { // log the IP for reference in case there is a bogus value pushed by HAL char str[INET6_ADDRSTRLEN]; inet_ntop(AF_INET6, &(in6->sin6_addr), str, INET6_ADDRSTRLEN); ALOGD("AGPS IP is v6: %s", str); } } break; default: ALOGE("Invalid ss_family found: %d", agps_status->addr.ss_family); break; } } else if (status_size >= sizeof(AGpsStatus_v2)) { ALOGV("AGpsStatus is V2+: %zd", status_size); // for back-compatibility reasons we check in v2 that the data structure size is greater or // equal to the declared size in gps.h uint32_t ipaddr = agps_status->ipaddr; ALOGV("AGPS IP is v4: %x", ipaddr); byteArray = convert_to_ipv4(ipaddr, false /* net_order */); if (ipaddr == INADDR_NONE || byteArray != NULL) { isSupported = true; } } else if (status_size >= sizeof(AGpsStatus_v1)) { ALOGV("AGpsStatus is V1+: %zd", status_size); // because we have to check for >= with regards to v2, we also need to relax the check here // and only make sure that the size is at least what we expect isSupported = true; } else { ALOGE("Invalid size of AGpsStatus found: %zd.", status_size); } if (isSupported) { jsize byteArrayLength = byteArray != NULL ? env->GetArrayLength(byteArray) : 0; ALOGV("Passing AGPS IP addr: size %d", byteArrayLength); env->CallVoidMethod(mCallbacksObj, method_reportAGpsStatus, agps_status->type, agps_status->status, byteArray); checkAndClearExceptionFromCallback(env, __FUNCTION__); } else { ALOGD("Skipping calling method_reportAGpsStatus."); } if (byteArray) { env->DeleteLocalRef(byteArray); } } AGpsCallbacks sAGpsCallbacks = { agps_status_callback, create_thread_callback, }; static void gps_ni_notify_callback(GpsNiNotification *notification) { ALOGD("gps_ni_notify_callback\n"); JNIEnv* env = AndroidRuntime::getJNIEnv(); jstring requestor_id = env->NewStringUTF(notification->requestor_id); jstring text = env->NewStringUTF(notification->text); jstring extras = env->NewStringUTF(notification->extras); if (requestor_id && text && extras) { env->CallVoidMethod(mCallbacksObj, method_reportNiNotification, notification->notification_id, notification->ni_type, notification->notify_flags, notification->timeout, notification->default_response, requestor_id, text, notification->requestor_id_encoding, notification->text_encoding, extras); } else { ALOGE("out of memory in gps_ni_notify_callback\n"); } if (requestor_id) env->DeleteLocalRef(requestor_id); if (text) env->DeleteLocalRef(text); if (extras) env->DeleteLocalRef(extras); checkAndClearExceptionFromCallback(env, __FUNCTION__); } GpsNiCallbacks sGpsNiCallbacks = { gps_ni_notify_callback, create_thread_callback, }; static void agps_request_set_id(uint32_t flags) { JNIEnv* env = AndroidRuntime::getJNIEnv(); env->CallVoidMethod(mCallbacksObj, method_requestSetID, flags); checkAndClearExceptionFromCallback(env, __FUNCTION__); } static void agps_request_ref_location(uint32_t flags) { JNIEnv* env = AndroidRuntime::getJNIEnv(); env->CallVoidMethod(mCallbacksObj, method_requestRefLocation, flags); checkAndClearExceptionFromCallback(env, __FUNCTION__); } AGpsRilCallbacks sAGpsRilCallbacks = { agps_request_set_id, agps_request_ref_location, create_thread_callback, }; static void gps_geofence_transition_callback(int32_t geofence_id, GpsLocation* location, int32_t transition, GpsUtcTime timestamp) { JNIEnv* env = AndroidRuntime::getJNIEnv(); env->CallVoidMethod(mCallbacksObj, method_reportGeofenceTransition, geofence_id, location->flags, (jdouble)location->latitude, (jdouble)location->longitude, (jdouble)location->altitude, (jfloat)location->speed, (jfloat)location->bearing, (jfloat)location->accuracy, (jlong)location->timestamp, transition, timestamp); checkAndClearExceptionFromCallback(env, __FUNCTION__); }; static void gps_geofence_status_callback(int32_t status, GpsLocation* location) { JNIEnv* env = AndroidRuntime::getJNIEnv(); jint flags = 0; jdouble latitude = 0; jdouble longitude = 0; jdouble altitude = 0; jfloat speed = 0; jfloat bearing = 0; jfloat accuracy = 0; jlong timestamp = 0; if (location != NULL) { flags = location->flags; latitude = location->latitude; longitude = location->longitude; altitude = location->altitude; speed = location->speed; bearing = location->bearing; accuracy = location->accuracy; timestamp = location->timestamp; } env->CallVoidMethod(mCallbacksObj, method_reportGeofenceStatus, status, flags, latitude, longitude, altitude, speed, bearing, accuracy, timestamp); checkAndClearExceptionFromCallback(env, __FUNCTION__); }; static void gps_geofence_add_callback(int32_t geofence_id, int32_t status) { JNIEnv* env = AndroidRuntime::getJNIEnv(); if (status != GPS_GEOFENCE_OPERATION_SUCCESS) { ALOGE("Error in geofence_add_callback: %d\n", status); } env->CallVoidMethod(mCallbacksObj, method_reportGeofenceAddStatus, geofence_id, status); checkAndClearExceptionFromCallback(env, __FUNCTION__); }; static void gps_geofence_remove_callback(int32_t geofence_id, int32_t status) { JNIEnv* env = AndroidRuntime::getJNIEnv(); if (status != GPS_GEOFENCE_OPERATION_SUCCESS) { ALOGE("Error in geofence_remove_callback: %d\n", status); } env->CallVoidMethod(mCallbacksObj, method_reportGeofenceRemoveStatus, geofence_id, status); checkAndClearExceptionFromCallback(env, __FUNCTION__); }; static void gps_geofence_resume_callback(int32_t geofence_id, int32_t status) { JNIEnv* env = AndroidRuntime::getJNIEnv(); if (status != GPS_GEOFENCE_OPERATION_SUCCESS) { ALOGE("Error in geofence_resume_callback: %d\n", status); } env->CallVoidMethod(mCallbacksObj, method_reportGeofenceResumeStatus, geofence_id, status); checkAndClearExceptionFromCallback(env, __FUNCTION__); }; static void gps_geofence_pause_callback(int32_t geofence_id, int32_t status) { JNIEnv* env = AndroidRuntime::getJNIEnv(); if (status != GPS_GEOFENCE_OPERATION_SUCCESS) { ALOGE("Error in geofence_pause_callback: %d\n", status); } env->CallVoidMethod(mCallbacksObj, method_reportGeofencePauseStatus, geofence_id, status); checkAndClearExceptionFromCallback(env, __FUNCTION__); }; GpsGeofenceCallbacks sGpsGeofenceCallbacks = { gps_geofence_transition_callback, gps_geofence_status_callback, gps_geofence_add_callback, gps_geofence_remove_callback, gps_geofence_pause_callback, gps_geofence_resume_callback, create_thread_callback, }; static void android_location_GpsLocationProvider_class_init_native(JNIEnv* env, jclass clazz) { int err; hw_module_t* module; method_reportLocation = env->GetMethodID(clazz, "reportLocation", "(IDDDFFFJ)V"); method_reportStatus = env->GetMethodID(clazz, "reportStatus", "(I)V"); method_reportSvStatus = env->GetMethodID(clazz, "reportSvStatus", "()V"); method_reportAGpsStatus = env->GetMethodID(clazz, "reportAGpsStatus", "(II[B)V"); method_reportNmea = env->GetMethodID(clazz, "reportNmea", "(J)V"); method_setEngineCapabilities = env->GetMethodID(clazz, "setEngineCapabilities", "(I)V"); method_xtraDownloadRequest = env->GetMethodID(clazz, "xtraDownloadRequest", "()V"); method_reportNiNotification = env->GetMethodID(clazz, "reportNiNotification", "(IIIIILjava/lang/String;Ljava/lang/String;IILjava/lang/String;)V"); method_requestRefLocation = env->GetMethodID(clazz,"requestRefLocation","(I)V"); method_requestSetID = env->GetMethodID(clazz,"requestSetID","(I)V"); method_requestUtcTime = env->GetMethodID(clazz,"requestUtcTime","()V"); method_reportGeofenceTransition = env->GetMethodID(clazz,"reportGeofenceTransition", "(IIDDDFFFJIJ)V"); method_reportGeofenceStatus = env->GetMethodID(clazz,"reportGeofenceStatus", "(IIDDDFFFJ)V"); method_reportGeofenceAddStatus = env->GetMethodID(clazz,"reportGeofenceAddStatus", "(II)V"); method_reportGeofenceRemoveStatus = env->GetMethodID(clazz,"reportGeofenceRemoveStatus", "(II)V"); method_reportGeofenceResumeStatus = env->GetMethodID(clazz,"reportGeofenceResumeStatus", "(II)V"); method_reportGeofencePauseStatus = env->GetMethodID(clazz,"reportGeofencePauseStatus", "(II)V"); method_reportMeasurementData = env->GetMethodID( clazz, "reportMeasurementData", "(Landroid/location/GpsMeasurementsEvent;)V"); method_reportNavigationMessages = env->GetMethodID( clazz, "reportNavigationMessage", "(Landroid/location/GpsNavigationMessageEvent;)V"); err = hw_get_module(GPS_HARDWARE_MODULE_ID, (hw_module_t const**)&module); if (err == 0) { hw_device_t* device; err = module->methods->open(module, GPS_HARDWARE_MODULE_ID, &device); if (err == 0) { gps_device_t* gps_device = (gps_device_t *)device; sGpsInterface = gps_device->get_gps_interface(gps_device); } } if (sGpsInterface) { sGpsXtraInterface = (const GpsXtraInterface*)sGpsInterface->get_extension(GPS_XTRA_INTERFACE); sAGpsInterface = (const AGpsInterface*)sGpsInterface->get_extension(AGPS_INTERFACE); sGpsNiInterface = (const GpsNiInterface*)sGpsInterface->get_extension(GPS_NI_INTERFACE); sGpsDebugInterface = (const GpsDebugInterface*)sGpsInterface->get_extension(GPS_DEBUG_INTERFACE); sAGpsRilInterface = (const AGpsRilInterface*)sGpsInterface->get_extension(AGPS_RIL_INTERFACE); sGpsGeofencingInterface = (const GpsGeofencingInterface*)sGpsInterface->get_extension(GPS_GEOFENCING_INTERFACE); sGpsMeasurementInterface = (const GpsMeasurementInterface*)sGpsInterface->get_extension(GPS_MEASUREMENT_INTERFACE); sGpsNavigationMessageInterface = (const GpsNavigationMessageInterface*)sGpsInterface->get_extension( GPS_NAVIGATION_MESSAGE_INTERFACE); sGnssConfigurationInterface = (const GnssConfigurationInterface*)sGpsInterface->get_extension( GNSS_CONFIGURATION_INTERFACE); } } static jboolean android_location_GpsLocationProvider_is_supported( JNIEnv* /* env */, jclass /* clazz */) { return (sGpsInterface != NULL) ? JNI_TRUE : JNI_FALSE; } static jboolean android_location_GpsLocationProvider_is_agps_ril_supported( JNIEnv* /* env */, jclass /* clazz */) { return (sAGpsRilInterface != NULL) ? JNI_TRUE : JNI_FALSE; } static jboolean android_location_gpsLocationProvider_is_gnss_configuration_supported( JNIEnv* /* env */, jclass /* jclazz */) { return (sGnssConfigurationInterface != NULL) ? JNI_TRUE : JNI_FALSE; } static jboolean android_location_GpsLocationProvider_init(JNIEnv* env, jobject obj) { // this must be set before calling into the HAL library if (!mCallbacksObj) mCallbacksObj = env->NewGlobalRef(obj); // fail if the main interface fails to initialize if (!sGpsInterface || sGpsInterface->init(&sGpsCallbacks) != 0) return JNI_FALSE; // if XTRA initialization fails we will disable it by sGpsXtraInterface to NULL, // but continue to allow the rest of the GPS interface to work. if (sGpsXtraInterface && sGpsXtraInterface->init(&sGpsXtraCallbacks) != 0) sGpsXtraInterface = NULL; if (sAGpsInterface) sAGpsInterface->init(&sAGpsCallbacks); if (sGpsNiInterface) sGpsNiInterface->init(&sGpsNiCallbacks); if (sAGpsRilInterface) sAGpsRilInterface->init(&sAGpsRilCallbacks); if (sGpsGeofencingInterface) sGpsGeofencingInterface->init(&sGpsGeofenceCallbacks); return JNI_TRUE; } static void android_location_GpsLocationProvider_cleanup(JNIEnv* /* env */, jobject /* obj */) { if (sGpsInterface) sGpsInterface->cleanup(); } static jboolean android_location_GpsLocationProvider_set_position_mode(JNIEnv* /* env */, jobject /* obj */, jint mode, jint recurrence, jint min_interval, jint preferred_accuracy, jint preferred_time) { if (sGpsInterface) { if (sGpsInterface->set_position_mode(mode, recurrence, min_interval, preferred_accuracy, preferred_time) == 0) { return JNI_TRUE; } else { return JNI_FALSE; } } else return JNI_FALSE; } static jboolean android_location_GpsLocationProvider_start(JNIEnv* /* env */, jobject /* obj */) { if (sGpsInterface) { if (sGpsInterface->start() == 0) { return JNI_TRUE; } else { return JNI_FALSE; } } else return JNI_FALSE; } static jboolean android_location_GpsLocationProvider_stop(JNIEnv* /* env */, jobject /* obj */) { if (sGpsInterface) { if (sGpsInterface->stop() == 0) { return JNI_TRUE; } else { return JNI_FALSE; } } else return JNI_FALSE; } static void android_location_GpsLocationProvider_delete_aiding_data(JNIEnv* /* env */, jobject /* obj */, jint flags) { if (sGpsInterface) sGpsInterface->delete_aiding_data(flags); } static jint android_location_GpsLocationProvider_read_sv_status(JNIEnv* env, jobject /* obj */, jintArray prnArray, jfloatArray snrArray, jfloatArray elevArray, jfloatArray azumArray, jintArray maskArray) { // this should only be called from within a call to reportSvStatus jint* prns = env->GetIntArrayElements(prnArray, 0); jfloat* snrs = env->GetFloatArrayElements(snrArray, 0); jfloat* elev = env->GetFloatArrayElements(elevArray, 0); jfloat* azim = env->GetFloatArrayElements(azumArray, 0); jint* mask = env->GetIntArrayElements(maskArray, 0); int num_svs = sGpsSvStatus.num_svs; for (int i = 0; i < num_svs; i++) { prns[i] = sGpsSvStatus.sv_list[i].prn; snrs[i] = sGpsSvStatus.sv_list[i].snr; elev[i] = sGpsSvStatus.sv_list[i].elevation; azim[i] = sGpsSvStatus.sv_list[i].azimuth; } mask[0] = sGpsSvStatus.ephemeris_mask; mask[1] = sGpsSvStatus.almanac_mask; mask[2] = sGpsSvStatus.used_in_fix_mask; env->ReleaseIntArrayElements(prnArray, prns, 0); env->ReleaseFloatArrayElements(snrArray, snrs, 0); env->ReleaseFloatArrayElements(elevArray, elev, 0); env->ReleaseFloatArrayElements(azumArray, azim, 0); env->ReleaseIntArrayElements(maskArray, mask, 0); return (jint) num_svs; } static void android_location_GpsLocationProvider_agps_set_reference_location_cellid( JNIEnv* /* env */, jobject /* obj */, jint type, jint mcc, jint mnc, jint lac, jint cid, jint psc) { AGpsRefLocation location; if (!sAGpsRilInterface) { ALOGE("no AGPS RIL interface in agps_set_reference_location_cellid"); return; } switch(type) { case AGPS_REF_LOCATION_TYPE_GSM_CELLID: case AGPS_REF_LOCATION_TYPE_UMTS_CELLID: location.type = type; location.u.cellID.mcc = mcc; location.u.cellID.mnc = mnc; location.u.cellID.lac = lac; #ifdef AGPS_USE_PSC location.u.cellID.psc = psc; #else (void)psc; #endif location.u.cellID.cid = cid; break; default: ALOGE("Neither a GSM nor a UMTS cellid (%s:%d).",__FUNCTION__,__LINE__); return; break; } sAGpsRilInterface->set_ref_location(&location, sizeof(location)); } static void android_location_GpsLocationProvider_agps_send_ni_message(JNIEnv* env, jobject /* obj */, jbyteArray ni_msg, jint size) { size_t sz; if (!sAGpsRilInterface) { ALOGE("no AGPS RIL interface in send_ni_message"); return; } if (size < 0) return; sz = (size_t)size; jbyte* b = env->GetByteArrayElements(ni_msg, 0); sAGpsRilInterface->ni_message((uint8_t *)b,sz); env->ReleaseByteArrayElements(ni_msg,b,0); } static void android_location_GpsLocationProvider_agps_set_id(JNIEnv *env, jobject /* obj */, jint type, jstring setid_string) { if (!sAGpsRilInterface) { ALOGE("no AGPS RIL interface in agps_set_id"); return; } const char *setid = env->GetStringUTFChars(setid_string, NULL); sAGpsRilInterface->set_set_id(type, setid); env->ReleaseStringUTFChars(setid_string, setid); } static jint android_location_GpsLocationProvider_read_nmea(JNIEnv* env, jobject /* obj */, jbyteArray nmeaArray, jint buffer_size) { // this should only be called from within a call to reportNmea jbyte* nmea = (jbyte *)env->GetPrimitiveArrayCritical(nmeaArray, 0); int length = sNmeaStringLength; if (length > buffer_size) length = buffer_size; memcpy(nmea, sNmeaString, length); env->ReleasePrimitiveArrayCritical(nmeaArray, nmea, JNI_ABORT); return (jint) length; } static void android_location_GpsLocationProvider_inject_time(JNIEnv* /* env */, jobject /* obj */, jlong time, jlong timeReference, jint uncertainty) { if (sGpsInterface) sGpsInterface->inject_time(time, timeReference, uncertainty); } static void android_location_GpsLocationProvider_inject_location(JNIEnv* /* env */, jobject /* obj */, jdouble latitude, jdouble longitude, jfloat accuracy) { if (sGpsInterface) sGpsInterface->inject_location(latitude, longitude, accuracy); } static jboolean android_location_GpsLocationProvider_supports_xtra( JNIEnv* /* env */, jobject /* obj */) { return (sGpsXtraInterface != NULL) ? JNI_TRUE : JNI_FALSE; } static void android_location_GpsLocationProvider_inject_xtra_data(JNIEnv* env, jobject /* obj */, jbyteArray data, jint length) { if (!sGpsXtraInterface) { ALOGE("no XTRA interface in inject_xtra_data"); return; } jbyte* bytes = (jbyte *)env->GetPrimitiveArrayCritical(data, 0); sGpsXtraInterface->inject_xtra_data((char *)bytes, length); env->ReleasePrimitiveArrayCritical(data, bytes, JNI_ABORT); } static void android_location_GpsLocationProvider_agps_data_conn_open( JNIEnv* env, jobject /* obj */, jstring apn, jint apnIpType) { if (!sAGpsInterface) { ALOGE("no AGPS interface in agps_data_conn_open"); return; } if (apn == NULL) { jniThrowException(env, "java/lang/IllegalArgumentException", NULL); return; } const char *apnStr = env->GetStringUTFChars(apn, NULL); size_t interface_size = sAGpsInterface->size; if (interface_size == sizeof(AGpsInterface_v2)) { sAGpsInterface->data_conn_open_with_apn_ip_type(apnStr, apnIpType); } else if (interface_size == sizeof(AGpsInterface_v1)) { sAGpsInterface->data_conn_open(apnStr); } else { ALOGE("Invalid size of AGpsInterface found: %zd.", interface_size); } env->ReleaseStringUTFChars(apn, apnStr); } static void android_location_GpsLocationProvider_agps_data_conn_closed(JNIEnv* /* env */, jobject /* obj */) { if (!sAGpsInterface) { ALOGE("no AGPS interface in agps_data_conn_closed"); return; } sAGpsInterface->data_conn_closed(); } static void android_location_GpsLocationProvider_agps_data_conn_failed(JNIEnv* /* env */, jobject /* obj */) { if (!sAGpsInterface) { ALOGE("no AGPS interface in agps_data_conn_failed"); return; } sAGpsInterface->data_conn_failed(); } static void android_location_GpsLocationProvider_set_agps_server(JNIEnv* env, jobject /* obj */, jint type, jstring hostname, jint port) { if (!sAGpsInterface) { ALOGE("no AGPS interface in set_agps_server"); return; } const char *c_hostname = env->GetStringUTFChars(hostname, NULL); sAGpsInterface->set_server(type, c_hostname, port); env->ReleaseStringUTFChars(hostname, c_hostname); } static void android_location_GpsLocationProvider_send_ni_response(JNIEnv* /* env */, jobject /* obj */, jint notifId, jint response) { if (!sGpsNiInterface) { ALOGE("no NI interface in send_ni_response"); return; } sGpsNiInterface->respond(notifId, response); } static jstring android_location_GpsLocationProvider_get_internal_state(JNIEnv* env, jobject /* obj */) { jstring result = NULL; if (sGpsDebugInterface) { const size_t maxLength = 2047; char buffer[maxLength+1]; size_t length = sGpsDebugInterface->get_internal_state(buffer, maxLength); if (length > maxLength) length = maxLength; buffer[length] = 0; result = env->NewStringUTF(buffer); } return result; } static void android_location_GpsLocationProvider_update_network_state(JNIEnv* env, jobject /* obj */, jboolean connected, jint type, jboolean roaming, jboolean available, jstring extraInfo, jstring apn) { if (sAGpsRilInterface && sAGpsRilInterface->update_network_state) { if (extraInfo) { const char *extraInfoStr = env->GetStringUTFChars(extraInfo, NULL); sAGpsRilInterface->update_network_state(connected, type, roaming, extraInfoStr); env->ReleaseStringUTFChars(extraInfo, extraInfoStr); } else { sAGpsRilInterface->update_network_state(connected, type, roaming, NULL); } // update_network_availability callback was not included in original AGpsRilInterface if (sAGpsRilInterface->size >= sizeof(AGpsRilInterface) && sAGpsRilInterface->update_network_availability) { const char *c_apn = env->GetStringUTFChars(apn, NULL); sAGpsRilInterface->update_network_availability(available, c_apn); env->ReleaseStringUTFChars(apn, c_apn); } } } static jboolean android_location_GpsLocationProvider_is_geofence_supported( JNIEnv* /* env */, jobject /* obj */) { return (sGpsGeofencingInterface != NULL) ? JNI_TRUE : JNI_FALSE; } static jboolean android_location_GpsLocationProvider_add_geofence(JNIEnv* /* env */, jobject /* obj */, jint geofence_id, jdouble latitude, jdouble longitude, jdouble radius, jint last_transition, jint monitor_transition, jint notification_responsiveness, jint unknown_timer) { if (sGpsGeofencingInterface != NULL) { sGpsGeofencingInterface->add_geofence_area(geofence_id, latitude, longitude, radius, last_transition, monitor_transition, notification_responsiveness, unknown_timer); return JNI_TRUE; } else { ALOGE("Geofence interface not available"); } return JNI_FALSE; } static jboolean android_location_GpsLocationProvider_remove_geofence(JNIEnv* /* env */, jobject /* obj */, jint geofence_id) { if (sGpsGeofencingInterface != NULL) { sGpsGeofencingInterface->remove_geofence_area(geofence_id); return JNI_TRUE; } else { ALOGE("Geofence interface not available"); } return JNI_FALSE; } static jboolean android_location_GpsLocationProvider_pause_geofence(JNIEnv* /* env */, jobject /* obj */, jint geofence_id) { if (sGpsGeofencingInterface != NULL) { sGpsGeofencingInterface->pause_geofence(geofence_id); return JNI_TRUE; } else { ALOGE("Geofence interface not available"); } return JNI_FALSE; } static jboolean android_location_GpsLocationProvider_resume_geofence(JNIEnv* /* env */, jobject /* obj */, jint geofence_id, jint monitor_transition) { if (sGpsGeofencingInterface != NULL) { sGpsGeofencingInterface->resume_geofence(geofence_id, monitor_transition); return JNI_TRUE; } else { ALOGE("Geofence interface not available"); } return JNI_FALSE; } static jobject translate_gps_clock(JNIEnv* env, GpsClock* clock) { const char* doubleSignature = "(D)V"; const char* longSignature = "(J)V"; jclass gpsClockClass = env->FindClass("android/location/GpsClock"); jmethodID gpsClockCtor = env->GetMethodID(gpsClockClass, "", "()V"); jobject gpsClockObject = env->NewObject(gpsClockClass, gpsClockCtor); GpsClockFlags flags = clock->flags; if (flags & GPS_CLOCK_HAS_LEAP_SECOND) { jmethodID setterMethod = env->GetMethodID(gpsClockClass, "setLeapSecond", "(S)V"); env->CallVoidMethod(gpsClockObject, setterMethod, clock->leap_second); } jmethodID typeSetterMethod = env->GetMethodID(gpsClockClass, "setType", "(B)V"); env->CallVoidMethod(gpsClockObject, typeSetterMethod, clock->type); jmethodID setterMethod = env->GetMethodID(gpsClockClass, "setTimeInNs", longSignature); env->CallVoidMethod(gpsClockObject, setterMethod, clock->time_ns); if (flags & GPS_CLOCK_HAS_TIME_UNCERTAINTY) { jmethodID setterMethod = env->GetMethodID(gpsClockClass, "setTimeUncertaintyInNs", doubleSignature); env->CallVoidMethod(gpsClockObject, setterMethod, clock->time_uncertainty_ns); } if (flags & GPS_CLOCK_HAS_FULL_BIAS) { jmethodID setterMethod = env->GetMethodID(gpsClockClass, "setFullBiasInNs", longSignature); env->CallVoidMethod(gpsClockObject, setterMethod, clock->full_bias_ns); } if (flags & GPS_CLOCK_HAS_BIAS) { jmethodID setterMethod = env->GetMethodID(gpsClockClass, "setBiasInNs", doubleSignature); env->CallVoidMethod(gpsClockObject, setterMethod, clock->bias_ns); } if (flags & GPS_CLOCK_HAS_BIAS_UNCERTAINTY) { jmethodID setterMethod = env->GetMethodID(gpsClockClass, "setBiasUncertaintyInNs", doubleSignature); env->CallVoidMethod(gpsClockObject, setterMethod, clock->bias_uncertainty_ns); } if (flags & GPS_CLOCK_HAS_DRIFT) { jmethodID setterMethod = env->GetMethodID(gpsClockClass, "setDriftInNsPerSec", doubleSignature); env->CallVoidMethod(gpsClockObject, setterMethod, clock->drift_nsps); } if (flags & GPS_CLOCK_HAS_DRIFT_UNCERTAINTY) { jmethodID setterMethod = env->GetMethodID(gpsClockClass, "setDriftUncertaintyInNsPerSec", doubleSignature); env->CallVoidMethod(gpsClockObject, setterMethod, clock->drift_uncertainty_nsps); } env->DeleteLocalRef(gpsClockClass); return gpsClockObject; } static jobject translate_gps_measurement(JNIEnv* env, GpsMeasurement* measurement) { const char* byteSignature = "(B)V"; const char* shortSignature = "(S)V"; const char* intSignature = "(I)V"; const char* longSignature = "(J)V"; const char* floatSignature = "(F)V"; const char* doubleSignature = "(D)V"; jclass gpsMeasurementClass = env->FindClass("android/location/GpsMeasurement"); jmethodID gpsMeasurementCtor = env->GetMethodID(gpsMeasurementClass, "", "()V"); jobject gpsMeasurementObject = env->NewObject(gpsMeasurementClass, gpsMeasurementCtor); GpsMeasurementFlags flags = measurement->flags; jmethodID prnSetterMethod = env->GetMethodID(gpsMeasurementClass, "setPrn", byteSignature); env->CallVoidMethod(gpsMeasurementObject, prnSetterMethod, measurement->prn); jmethodID timeOffsetSetterMethod = env->GetMethodID(gpsMeasurementClass, "setTimeOffsetInNs", doubleSignature); env->CallVoidMethod( gpsMeasurementObject, timeOffsetSetterMethod, measurement->time_offset_ns); jmethodID stateSetterMethod = env->GetMethodID(gpsMeasurementClass, "setState", shortSignature); env->CallVoidMethod(gpsMeasurementObject, stateSetterMethod, measurement->state); jmethodID receivedGpsTowSetterMethod = env->GetMethodID(gpsMeasurementClass, "setReceivedGpsTowInNs", longSignature); env->CallVoidMethod( gpsMeasurementObject, receivedGpsTowSetterMethod, measurement->received_gps_tow_ns); jmethodID receivedGpsTowUncertaintySetterMethod = env->GetMethodID( gpsMeasurementClass, "setReceivedGpsTowUncertaintyInNs", longSignature); env->CallVoidMethod( gpsMeasurementObject, receivedGpsTowUncertaintySetterMethod, measurement->received_gps_tow_uncertainty_ns); jmethodID cn0SetterMethod = env->GetMethodID(gpsMeasurementClass, "setCn0InDbHz", doubleSignature); env->CallVoidMethod(gpsMeasurementObject, cn0SetterMethod, measurement->c_n0_dbhz); jmethodID pseudorangeRateSetterMethod = env->GetMethodID( gpsMeasurementClass, "setPseudorangeRateInMetersPerSec", doubleSignature); env->CallVoidMethod( gpsMeasurementObject, pseudorangeRateSetterMethod, measurement->pseudorange_rate_mps); jmethodID pseudorangeRateUncertaintySetterMethod = env->GetMethodID( gpsMeasurementClass, "setPseudorangeRateUncertaintyInMetersPerSec", doubleSignature); env->CallVoidMethod( gpsMeasurementObject, pseudorangeRateUncertaintySetterMethod, measurement->pseudorange_rate_uncertainty_mps); jmethodID accumulatedDeltaRangeStateSetterMethod = env->GetMethodID(gpsMeasurementClass, "setAccumulatedDeltaRangeState", shortSignature); env->CallVoidMethod( gpsMeasurementObject, accumulatedDeltaRangeStateSetterMethod, measurement->accumulated_delta_range_state); jmethodID accumulatedDeltaRangeSetterMethod = env->GetMethodID( gpsMeasurementClass, "setAccumulatedDeltaRangeInMeters", doubleSignature); env->CallVoidMethod( gpsMeasurementObject, accumulatedDeltaRangeSetterMethod, measurement->accumulated_delta_range_m); jmethodID accumulatedDeltaRangeUncertaintySetterMethod = env->GetMethodID( gpsMeasurementClass, "setAccumulatedDeltaRangeUncertaintyInMeters", doubleSignature); env->CallVoidMethod( gpsMeasurementObject, accumulatedDeltaRangeUncertaintySetterMethod, measurement->accumulated_delta_range_uncertainty_m); if (flags & GPS_MEASUREMENT_HAS_PSEUDORANGE) { jmethodID setterMethod = env->GetMethodID(gpsMeasurementClass, "setPseudorangeInMeters", doubleSignature); env->CallVoidMethod(gpsMeasurementObject, setterMethod, measurement->pseudorange_m); } if (flags & GPS_MEASUREMENT_HAS_PSEUDORANGE_UNCERTAINTY) { jmethodID setterMethod = env->GetMethodID( gpsMeasurementClass, "setPseudorangeUncertaintyInMeters", doubleSignature); env->CallVoidMethod( gpsMeasurementObject, setterMethod, measurement->pseudorange_uncertainty_m); } if (flags & GPS_MEASUREMENT_HAS_CODE_PHASE) { jmethodID setterMethod = env->GetMethodID(gpsMeasurementClass, "setCodePhaseInChips", doubleSignature); env->CallVoidMethod(gpsMeasurementObject, setterMethod, measurement->code_phase_chips); } if (flags & GPS_MEASUREMENT_HAS_CODE_PHASE_UNCERTAINTY) { jmethodID setterMethod = env->GetMethodID( gpsMeasurementClass, "setCodePhaseUncertaintyInChips", doubleSignature); env->CallVoidMethod( gpsMeasurementObject, setterMethod, measurement->code_phase_uncertainty_chips); } if (flags & GPS_MEASUREMENT_HAS_CARRIER_FREQUENCY) { jmethodID setterMethod = env->GetMethodID(gpsMeasurementClass, "setCarrierFrequencyInHz", floatSignature); env->CallVoidMethod( gpsMeasurementObject, setterMethod, measurement->carrier_frequency_hz); } if (flags & GPS_MEASUREMENT_HAS_CARRIER_CYCLES) { jmethodID setterMethod = env->GetMethodID(gpsMeasurementClass, "setCarrierCycles", longSignature); env->CallVoidMethod(gpsMeasurementObject, setterMethod, measurement->carrier_cycles); } if (flags & GPS_MEASUREMENT_HAS_CARRIER_PHASE) { jmethodID setterMethod = env->GetMethodID(gpsMeasurementClass, "setCarrierPhase", doubleSignature); env->CallVoidMethod(gpsMeasurementObject, setterMethod, measurement->carrier_phase); } if (flags & GPS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY) { jmethodID setterMethod = env->GetMethodID( gpsMeasurementClass, "setCarrierPhaseUncertainty", doubleSignature); env->CallVoidMethod( gpsMeasurementObject, setterMethod, measurement->carrier_phase_uncertainty); } jmethodID lossOfLockSetterMethod = env->GetMethodID(gpsMeasurementClass, "setLossOfLock", byteSignature); env->CallVoidMethod(gpsMeasurementObject, lossOfLockSetterMethod, measurement->loss_of_lock); if (flags & GPS_MEASUREMENT_HAS_BIT_NUMBER) { jmethodID setterMethod = env->GetMethodID(gpsMeasurementClass, "setBitNumber", intSignature); env->CallVoidMethod(gpsMeasurementObject, setterMethod, measurement->bit_number); } if (flags & GPS_MEASUREMENT_HAS_TIME_FROM_LAST_BIT) { jmethodID setterMethod = env->GetMethodID(gpsMeasurementClass, "setTimeFromLastBitInMs", shortSignature); env->CallVoidMethod( gpsMeasurementObject, setterMethod, measurement->time_from_last_bit_ms); } if (flags & GPS_MEASUREMENT_HAS_DOPPLER_SHIFT) { jmethodID setterMethod = env->GetMethodID(gpsMeasurementClass, "setDopplerShiftInHz", doubleSignature); env->CallVoidMethod(gpsMeasurementObject, setterMethod, measurement->doppler_shift_hz); } if (flags & GPS_MEASUREMENT_HAS_DOPPLER_SHIFT_UNCERTAINTY) { jmethodID setterMethod = env->GetMethodID( gpsMeasurementClass, "setDopplerShiftUncertaintyInHz", doubleSignature); env->CallVoidMethod( gpsMeasurementObject, setterMethod, measurement->doppler_shift_uncertainty_hz); } jmethodID multipathIndicatorSetterMethod = env->GetMethodID(gpsMeasurementClass, "setMultipathIndicator", byteSignature); env->CallVoidMethod( gpsMeasurementObject, multipathIndicatorSetterMethod, measurement->multipath_indicator); if (flags & GPS_MEASUREMENT_HAS_SNR) { jmethodID setterMethod = env->GetMethodID(gpsMeasurementClass, "setSnrInDb", doubleSignature); env->CallVoidMethod(gpsMeasurementObject, setterMethod, measurement->snr_db); } if (flags & GPS_MEASUREMENT_HAS_ELEVATION) { jmethodID setterMethod = env->GetMethodID(gpsMeasurementClass, "setElevationInDeg", doubleSignature); env->CallVoidMethod(gpsMeasurementObject, setterMethod, measurement->elevation_deg); } if (flags & GPS_MEASUREMENT_HAS_ELEVATION_UNCERTAINTY) { jmethodID setterMethod = env->GetMethodID(gpsMeasurementClass, "setElevationUncertaintyInDeg", doubleSignature); env->CallVoidMethod( gpsMeasurementObject, setterMethod, measurement->elevation_uncertainty_deg); } if (flags & GPS_MEASUREMENT_HAS_AZIMUTH) { jmethodID setterMethod = env->GetMethodID(gpsMeasurementClass, "setAzimuthInDeg", doubleSignature); env->CallVoidMethod(gpsMeasurementObject, setterMethod, measurement->azimuth_deg); } if (flags & GPS_MEASUREMENT_HAS_AZIMUTH_UNCERTAINTY) { jmethodID setterMethod = env->GetMethodID( gpsMeasurementClass, "setAzimuthUncertaintyInDeg", doubleSignature); env->CallVoidMethod( gpsMeasurementObject, setterMethod, measurement->azimuth_uncertainty_deg); } jmethodID usedInFixSetterMethod = env->GetMethodID(gpsMeasurementClass, "setUsedInFix", "(Z)V"); env->CallVoidMethod( gpsMeasurementObject, usedInFixSetterMethod, (flags & GPS_MEASUREMENT_HAS_USED_IN_FIX) && measurement->used_in_fix); env->DeleteLocalRef(gpsMeasurementClass); return gpsMeasurementObject; } static jobjectArray translate_gps_measurements(JNIEnv* env, GpsData* data) { size_t measurementCount = data->measurement_count; if (measurementCount == 0) { return NULL; } jclass gpsMeasurementClass = env->FindClass("android/location/GpsMeasurement"); jobjectArray gpsMeasurementArray = env->NewObjectArray( measurementCount, gpsMeasurementClass, NULL /* initialElement */); GpsMeasurement* gpsMeasurements = data->measurements; for (uint16_t i = 0; i < measurementCount; ++i) { jobject gpsMeasurement = translate_gps_measurement(env, &gpsMeasurements[i]); env->SetObjectArrayElement(gpsMeasurementArray, i, gpsMeasurement); env->DeleteLocalRef(gpsMeasurement); } env->DeleteLocalRef(gpsMeasurementClass); return gpsMeasurementArray; } static void measurement_callback(GpsData* data) { JNIEnv* env = AndroidRuntime::getJNIEnv(); if (data == NULL) { ALOGE("Invalid data provided to gps_measurement_callback"); return; } if (data->size == sizeof(GpsData)) { jobject gpsClock = translate_gps_clock(env, &data->clock); jobjectArray measurementArray = translate_gps_measurements(env, data); jclass gpsMeasurementsEventClass = env->FindClass("android/location/GpsMeasurementsEvent"); jmethodID gpsMeasurementsEventCtor = env->GetMethodID( gpsMeasurementsEventClass, "", "(Landroid/location/GpsClock;[Landroid/location/GpsMeasurement;)V"); jobject gpsMeasurementsEvent = env->NewObject( gpsMeasurementsEventClass, gpsMeasurementsEventCtor, gpsClock, measurementArray); env->CallVoidMethod(mCallbacksObj, method_reportMeasurementData, gpsMeasurementsEvent); checkAndClearExceptionFromCallback(env, __FUNCTION__); env->DeleteLocalRef(gpsClock); env->DeleteLocalRef(measurementArray); env->DeleteLocalRef(gpsMeasurementsEventClass); env->DeleteLocalRef(gpsMeasurementsEvent); } else { ALOGE("Invalid GpsData size found in gps_measurement_callback, size=%zd", data->size); } } GpsMeasurementCallbacks sGpsMeasurementCallbacks = { sizeof(GpsMeasurementCallbacks), measurement_callback, }; static jboolean android_location_GpsLocationProvider_is_measurement_supported( JNIEnv* env, jclass clazz) { if (sGpsMeasurementInterface != NULL) { return JNI_TRUE; } return JNI_FALSE; } static jboolean android_location_GpsLocationProvider_start_measurement_collection( JNIEnv* env, jobject obj) { if (sGpsMeasurementInterface == NULL) { ALOGE("Measurement interface is not available."); return JNI_FALSE; } int result = sGpsMeasurementInterface->init(&sGpsMeasurementCallbacks); if (result != GPS_GEOFENCE_OPERATION_SUCCESS) { ALOGE("An error has been found on GpsMeasurementInterface::init, status=%d", result); return JNI_FALSE; } return JNI_TRUE; } static jboolean android_location_GpsLocationProvider_stop_measurement_collection( JNIEnv* env, jobject obj) { if (sGpsMeasurementInterface == NULL) { ALOGE("Measurement interface not available"); return JNI_FALSE; } sGpsMeasurementInterface->close(); return JNI_TRUE; } static jobject translate_gps_navigation_message(JNIEnv* env, GpsNavigationMessage* message) { size_t dataLength = message->data_length; uint8_t* data = message->data; if (dataLength == 0 || data == NULL) { ALOGE("Invalid Navigation Message found: data=%p, length=%zd", data, dataLength); return NULL; } jclass navigationMessageClass = env->FindClass("android/location/GpsNavigationMessage"); jmethodID navigationMessageCtor = env->GetMethodID(navigationMessageClass, "", "()V"); jobject navigationMessageObject = env->NewObject(navigationMessageClass, navigationMessageCtor); jmethodID setTypeMethod = env->GetMethodID(navigationMessageClass, "setType", "(B)V"); env->CallVoidMethod(navigationMessageObject, setTypeMethod, message->type); jmethodID setPrnMethod = env->GetMethodID(navigationMessageClass, "setPrn", "(B)V"); env->CallVoidMethod(navigationMessageObject, setPrnMethod, message->prn); jmethodID setMessageIdMethod = env->GetMethodID(navigationMessageClass, "setMessageId", "(S)V"); env->CallVoidMethod(navigationMessageObject, setMessageIdMethod, message->message_id); jmethodID setSubmessageIdMethod = env->GetMethodID(navigationMessageClass, "setSubmessageId", "(S)V"); env->CallVoidMethod(navigationMessageObject, setSubmessageIdMethod, message->submessage_id); jbyteArray dataArray = env->NewByteArray(dataLength); env->SetByteArrayRegion(dataArray, 0, dataLength, (jbyte*) data); jmethodID setDataMethod = env->GetMethodID(navigationMessageClass, "setData", "([B)V"); env->CallVoidMethod(navigationMessageObject, setDataMethod, dataArray); env->DeleteLocalRef(navigationMessageClass); env->DeleteLocalRef(dataArray); return navigationMessageObject; } static void navigation_message_callback(GpsNavigationMessage* message) { JNIEnv* env = AndroidRuntime::getJNIEnv(); if (message == NULL) { ALOGE("Invalid Navigation Message provided to callback"); return; } if (message->size == sizeof(GpsNavigationMessage)) { jobject navigationMessage = translate_gps_navigation_message(env, message); jclass navigationMessageEventClass = env->FindClass("android/location/GpsNavigationMessageEvent"); jmethodID navigationMessageEventCtor = env->GetMethodID( navigationMessageEventClass, "", "(Landroid/location/GpsNavigationMessage;)V"); jobject navigationMessageEvent = env->NewObject( navigationMessageEventClass, navigationMessageEventCtor, navigationMessage); env->CallVoidMethod(mCallbacksObj, method_reportNavigationMessages, navigationMessageEvent); checkAndClearExceptionFromCallback(env, __FUNCTION__); env->DeleteLocalRef(navigationMessage); env->DeleteLocalRef(navigationMessageEventClass); env->DeleteLocalRef(navigationMessageEvent); } else { ALOGE("Invalid GpsNavigationMessage size found: %zd", message->size); } } GpsNavigationMessageCallbacks sGpsNavigationMessageCallbacks = { sizeof(GpsNavigationMessageCallbacks), navigation_message_callback, }; static jboolean android_location_GpsLocationProvider_is_navigation_message_supported( JNIEnv* env, jclass clazz) { if(sGpsNavigationMessageInterface != NULL) { return JNI_TRUE; } return JNI_FALSE; } static jboolean android_location_GpsLocationProvider_start_navigation_message_collection( JNIEnv* env, jobject obj) { if (sGpsNavigationMessageInterface == NULL) { ALOGE("Navigation Message interface is not available."); return JNI_FALSE; } int result = sGpsNavigationMessageInterface->init(&sGpsNavigationMessageCallbacks); if (result != GPS_NAVIGATION_MESSAGE_OPERATION_SUCCESS) { ALOGE("An error has been found in %s: %d", __FUNCTION__, result); return JNI_FALSE; } return JNI_TRUE; } static jboolean android_location_GpsLocationProvider_stop_navigation_message_collection( JNIEnv* env, jobject obj) { if (sGpsNavigationMessageInterface == NULL) { ALOGE("Navigation Message interface is not available."); return JNI_FALSE; } sGpsNavigationMessageInterface->close(); return JNI_TRUE; } static void android_location_GpsLocationProvider_configuration_update(JNIEnv* env, jobject obj, jstring config_content) { if (!sGnssConfigurationInterface) { ALOGE("no GPS configuration interface in configuraiton_update"); return; } const char *data = env->GetStringUTFChars(config_content, NULL); ALOGD("GPS configuration:\n %s", data); sGnssConfigurationInterface->configuration_update( data, env->GetStringUTFLength(config_content)); env->ReleaseStringUTFChars(config_content, data); } static JNINativeMethod sMethods[] = { /* name, signature, funcPtr */ {"class_init_native", "()V", (void *)android_location_GpsLocationProvider_class_init_native}, {"native_is_supported", "()Z", (void*)android_location_GpsLocationProvider_is_supported}, {"native_is_agps_ril_supported", "()Z", (void*)android_location_GpsLocationProvider_is_agps_ril_supported}, {"native_is_gnss_configuration_supported", "()Z", (void*)android_location_gpsLocationProvider_is_gnss_configuration_supported}, {"native_init", "()Z", (void*)android_location_GpsLocationProvider_init}, {"native_cleanup", "()V", (void*)android_location_GpsLocationProvider_cleanup}, {"native_set_position_mode", "(IIIII)Z", (void*)android_location_GpsLocationProvider_set_position_mode}, {"native_start", "()Z", (void*)android_location_GpsLocationProvider_start}, {"native_stop", "()Z", (void*)android_location_GpsLocationProvider_stop}, {"native_delete_aiding_data", "(I)V", (void*)android_location_GpsLocationProvider_delete_aiding_data}, {"native_read_sv_status", "([I[F[F[F[I)I", (void*)android_location_GpsLocationProvider_read_sv_status}, {"native_read_nmea", "([BI)I", (void*)android_location_GpsLocationProvider_read_nmea}, {"native_inject_time", "(JJI)V", (void*)android_location_GpsLocationProvider_inject_time}, {"native_inject_location", "(DDF)V", (void*)android_location_GpsLocationProvider_inject_location}, {"native_supports_xtra", "()Z", (void*)android_location_GpsLocationProvider_supports_xtra}, {"native_inject_xtra_data", "([BI)V", (void*)android_location_GpsLocationProvider_inject_xtra_data}, {"native_agps_data_conn_open", "(Ljava/lang/String;I)V", (void*)android_location_GpsLocationProvider_agps_data_conn_open}, {"native_agps_data_conn_closed", "()V", (void*)android_location_GpsLocationProvider_agps_data_conn_closed}, {"native_agps_data_conn_failed", "()V", (void*)android_location_GpsLocationProvider_agps_data_conn_failed}, {"native_agps_set_id", "(ILjava/lang/String;)V", (void*)android_location_GpsLocationProvider_agps_set_id}, {"native_agps_set_ref_location_cellid", "(IIIIII)V", (void*)android_location_GpsLocationProvider_agps_set_reference_location_cellid}, {"native_set_agps_server", "(ILjava/lang/String;I)V", (void*)android_location_GpsLocationProvider_set_agps_server}, {"native_send_ni_response", "(II)V", (void*)android_location_GpsLocationProvider_send_ni_response}, {"native_agps_ni_message", "([BI)V", (void *)android_location_GpsLocationProvider_agps_send_ni_message}, {"native_get_internal_state", "()Ljava/lang/String;", (void*)android_location_GpsLocationProvider_get_internal_state}, {"native_update_network_state", "(ZIZZLjava/lang/String;Ljava/lang/String;)V", (void*)android_location_GpsLocationProvider_update_network_state }, {"native_is_geofence_supported", "()Z", (void*) android_location_GpsLocationProvider_is_geofence_supported}, {"native_add_geofence", "(IDDDIIII)Z", (void *)android_location_GpsLocationProvider_add_geofence}, {"native_remove_geofence", "(I)Z", (void *)android_location_GpsLocationProvider_remove_geofence}, {"native_pause_geofence", "(I)Z", (void *)android_location_GpsLocationProvider_pause_geofence}, {"native_resume_geofence", "(II)Z", (void *)android_location_GpsLocationProvider_resume_geofence}, {"native_is_measurement_supported", "()Z", (void*) android_location_GpsLocationProvider_is_measurement_supported}, {"native_start_measurement_collection", "()Z", (void*) android_location_GpsLocationProvider_start_measurement_collection}, {"native_stop_measurement_collection", "()Z", (void*) android_location_GpsLocationProvider_stop_measurement_collection}, {"native_is_navigation_message_supported", "()Z", (void*) android_location_GpsLocationProvider_is_navigation_message_supported}, {"native_start_navigation_message_collection", "()Z", (void*) android_location_GpsLocationProvider_start_navigation_message_collection}, {"native_stop_navigation_message_collection", "()Z", (void*) android_location_GpsLocationProvider_stop_navigation_message_collection}, {"native_configuration_update", "(Ljava/lang/String;)V", (void*)android_location_GpsLocationProvider_configuration_update}, }; int register_android_server_location_GpsLocationProvider(JNIEnv* env) { return jniRegisterNativeMethods( env, "com/android/server/location/GpsLocationProvider", sMethods, NELEM(sMethods)); } } /* namespace android */ ================================================ FILE: VirtualPosition/vp_APP/VirtualPosition/Android.mk ================================================ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := $(call all-subdir-java-files) LOCAL_PACKAGE_NAME := VirtualPosition include $(BUILD_PACKAGE) ================================================ FILE: VirtualPosition/vp_APP/VirtualPosition/AndroidManifest.xml ================================================ ================================================ FILE: VirtualPosition/vp_APP/VirtualPosition/java/com/example/phdemo/myapplication/MainActivity.java ================================================ package com.example.phdemo.myapplication; import android.os.RemoteException; import android.app.Activity; import android.os.ServiceManager; import android.os.Bundle; import android.widget.CompoundButton; import android.os.IVirtualPositionService; import android.os.RemoteException; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.ToggleButton; import android.widget.CompoundButton.OnCheckedChangeListener; public class MainActivity extends Activity implements View.OnClickListener { private final static String LOG_TAG = "com.example.phdemo.virtualposition"; private IVirtualPositionService virtualpositionService = null; private ToggleButton toggleButton = null; private EditText altitudeValueText = null; private EditText longitudeValueText = null; private Button getButton = null; private Button setButton = null; private Button clearButton = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); virtualpositionService = IVirtualPositionService.Stub.asInterface( ServiceManager.getService("virtualposition")); toggleButton=(ToggleButton)findViewById(R.id.toggleButton); altitudeValueText = (EditText)findViewById(R.id.altitude_value); longitudeValueText = (EditText)findViewById(R.id.longitude_value); getButton = (Button)findViewById(R.id.button_get); setButton = (Button)findViewById(R.id.button_set); clearButton = (Button)findViewById(R.id.button_clear); getButton.setOnClickListener(this); setButton.setOnClickListener(this); clearButton.setOnClickListener(this); try{ int val_tog = virtualpositionService.getVirtualToggle(); if(val_tog == 1){ toggleButton.setChecked(true); }else{ toggleButton.setChecked(false); } } catch (Exception e) {} toggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener(){ public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) { toggleButton.setChecked(isChecked); try{ virtualpositionService.setVirtualToggle(isChecked?1:0); }catch(Exception e){} } }); Log.i(LOG_TAG, "VirtualPosition Activity Created"); } @Override public void onClick(View v) { if(v.equals(getButton)) { try { double val_altitude = virtualpositionService.getVirtualLatitude(); String text_altitude = String.valueOf(val_altitude); altitudeValueText.setText(text_altitude); double val_longitude = virtualpositionService.getVirtualLongitude(); String text_longitude = String.valueOf(val_longitude); longitudeValueText.setText(text_longitude); int val_tog = virtualpositionService.getVirtualToggle(); if(val_tog == 1){ toggleButton.setChecked(true); }else{ toggleButton.setChecked(false); } } catch (Exception e) { Log.e(LOG_TAG, "Remote Exception while reading value from GpsLocationProvider."); } } else if(v.equals(setButton)) { try { String text_altitude = altitudeValueText.getText().toString(); String text_longitude = longitudeValueText.getText().toString(); double val_altitude = Double.parseDouble(text_altitude); double val_longitude = Double.parseDouble(text_longitude); virtualpositionService.setVirtualLatitude(val_altitude); virtualpositionService.setVirtualLongitude(val_longitude); } catch (Exception e) { Log.e(LOG_TAG, "Remote Exception while writing value to GpsLocationProvider."); } } else if(v.equals(clearButton)) { String text = ""; altitudeValueText.setText(text); longitudeValueText.setText(text); } } } ================================================ FILE: VirtualPosition/vp_APP/VirtualPosition/res/layout/activity_main.xml ================================================ ================================================ FILE: VirtualPosition/vp_APP/VirtualPosition/res/values/colors.xml ================================================ #3F51B5 #303F9F #FF4081 ================================================ FILE: VirtualPosition/vp_APP/VirtualPosition/res/values/dimens.xml ================================================ 16dp 16dp ================================================ FILE: VirtualPosition/vp_APP/VirtualPosition/res/values/strings.xml ================================================ VirtualPosition _altitude_ longitude toggle Input altitude Input longitude GET SET CLEAR ================================================ FILE: VirtualPosition/vp_APP/VirtualPosition/res/values-w820dp/dimens.xml ================================================ 64dp ================================================ FILE: VirtualPosition/vp_Framework/IVirtualPositionService.aidl ================================================ package android.os; interface IVirtualPositionService { void setVirtualToggle(int tog); int getVirtualToggle(); void setVirtualLatitude(double vlat); double getVirtualLatitude(); void setVirtualLongitude(double vlon); double getVirtualLongitude(); } ================================================ FILE: VirtualPosition/vp_Framework/SystemServer.java ================================================ /* * Copyright (C) 2006 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server; import android.app.ActivityManagerNative; import android.app.ActivityThread; import android.app.IActivityManager; import android.app.IAlarmManager; import android.app.INotificationManager; import android.app.usage.UsageStatsManagerInternal; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.pm.IPackageManager; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.content.res.Resources.Theme; import android.database.ContentObserver; import android.os.Build; import android.os.Environment; import android.os.FactoryTest; import android.os.IPowerManager; import android.os.Looper; import android.os.RemoteException; import android.os.ServiceManager; import android.os.StrictMode; import android.os.SystemClock; import android.os.SystemProperties; import android.os.UserHandle; import android.os.storage.IMountService; import android.util.DisplayMetrics; import android.util.EventLog; import android.util.Slog; import android.view.WindowManager; import android.webkit.WebViewFactory; import com.android.internal.R; import com.android.internal.os.BinderInternal; import com.android.internal.os.SamplingProfilerIntegration; import com.android.server.accessibility.AccessibilityManagerService; import com.android.server.accounts.AccountManagerService; import com.android.server.am.ActivityManagerService; import com.android.server.audio.AudioService; import com.android.server.camera.CameraService; import com.android.server.clipboard.ClipboardService; import com.android.server.content.ContentService; import com.android.server.devicepolicy.DevicePolicyManagerService; import com.android.server.display.DisplayManagerService; import com.android.server.dreams.DreamManagerService; import com.android.server.fingerprint.FingerprintService; import com.android.server.hdmi.HdmiControlService; import com.android.server.gesture.GestureService; import com.android.server.input.InputManagerService; import com.android.server.job.JobSchedulerService; import com.android.server.lights.LightsService; import com.android.server.media.MediaRouterService; import com.android.server.media.MediaSessionService; import com.android.server.media.projection.MediaProjectionManagerService; import com.android.server.net.NetworkPolicyManagerService; import com.android.server.net.NetworkStatsService; import com.android.server.notification.NotificationManagerService; import com.android.server.os.SchedulingPolicyService; import com.android.server.pm.BackgroundDexOptService; import com.android.server.pm.Installer; import com.android.server.pm.LauncherAppsService; import com.android.server.pm.PackageManagerService; import com.android.server.pm.UserManagerService; import com.android.server.power.PowerManagerService; import com.android.server.power.ShutdownThread; import com.android.server.restrictions.RestrictionsManagerService; import com.android.server.search.SearchManagerService; import com.android.server.statusbar.StatusBarManagerService; import com.android.server.storage.DeviceStorageMonitorService; import com.android.server.telecom.TelecomLoaderService; import com.android.server.trust.TrustManagerService; import com.android.server.tv.TvInputManagerService; import com.android.server.twilight.TwilightService; import com.android.server.usage.UsageStatsService; import com.android.server.usb.UsbService; import com.android.server.wallpaper.WallpaperManagerService; import com.android.server.webkit.WebViewUpdateService; import com.android.server.wm.WindowManagerService; import cyanogenmod.providers.CMSettings; import dalvik.system.VMRuntime; import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Locale; import java.util.Timer; import java.util.TimerTask; public final class SystemServer { private static final String TAG = "SystemServer"; private static final String ENCRYPTING_STATE = "trigger_restart_min_framework"; private static final String ENCRYPTED_STATE = "1"; private static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr // The earliest supported time. We pick one day into 1970, to // give any timezone code room without going into negative time. private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000; /* * Implementation class names. TODO: Move them to a codegen class or load * them from the build system somehow. */ private static final String BACKUP_MANAGER_SERVICE_CLASS = "com.android.server.backup.BackupManagerService$Lifecycle"; private static final String APPWIDGET_SERVICE_CLASS = "com.android.server.appwidget.AppWidgetService"; private static final String VOICE_RECOGNITION_MANAGER_SERVICE_CLASS = "com.android.server.voiceinteraction.VoiceInteractionManagerService"; private static final String PRINT_MANAGER_SERVICE_CLASS = "com.android.server.print.PrintManagerService"; private static final String USB_SERVICE_CLASS = "com.android.server.usb.UsbService$Lifecycle"; private static final String MIDI_SERVICE_CLASS = "com.android.server.midi.MidiService$Lifecycle"; private static final String WIFI_SERVICE_CLASS = "com.android.server.wifi.WifiService"; private static final String WIFI_P2P_SERVICE_CLASS = "com.android.server.wifi.p2p.WifiP2pService"; private static final String ETHERNET_SERVICE_CLASS = "com.android.server.ethernet.EthernetService"; private static final String JOB_SCHEDULER_SERVICE_CLASS = "com.android.server.job.JobSchedulerService"; private static final String MOUNT_SERVICE_CLASS = "com.android.server.MountService$Lifecycle"; private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst"; private final int mFactoryTestMode; private Timer mProfilerSnapshotTimer; private Context mSystemContext; private SystemServiceManager mSystemServiceManager; // TODO: remove all of these references by improving dependency resolution and boot phases private PowerManagerService mPowerManagerService; private ActivityManagerService mActivityManagerService; private DisplayManagerService mDisplayManagerService; private PackageManagerService mPackageManagerService; private PackageManager mPackageManager; private ContentResolver mContentResolver; private boolean mOnlyCore; private boolean mFirstBoot; /** * Start the sensor service. */ private static native void startSensorService(); /** * The main entry point from zygote. */ public static void main(String[] args) { new SystemServer().run(); } public SystemServer() { // Check for factory test mode. mFactoryTestMode = FactoryTest.getMode(); } private class AdbPortObserver extends ContentObserver { public AdbPortObserver() { super(null); } @Override public void onChange(boolean selfChange) { int adbPort = CMSettings.Secure.getInt(mContentResolver, CMSettings.Secure.ADB_PORT, 0); // setting this will control whether ADB runs on TCP/IP or USB SystemProperties.set("adb.network.port", Integer.toString(adbPort)); } } private void run() { // If a device's clock is before 1970 (before 0), a lot of // APIs crash dealing with negative numbers, notably // java.io.File#setLastModified, so instead we fake it and // hope that time from cell towers or NTP fixes it shortly. if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) { Slog.w(TAG, "System clock is before 1970; setting to 1970."); SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME); } // If the system has "persist.sys.language" and friends set, replace them with // "persist.sys.locale". Note that the default locale at this point is calculated // using the "-Duser.locale" command line flag. That flag is usually populated by // AndroidRuntime using the same set of system properties, but only the system_server // and system apps are allowed to set them. // // NOTE: Most changes made here will need an equivalent change to // core/jni/AndroidRuntime.cpp if (!SystemProperties.get("persist.sys.language").isEmpty()) { final String languageTag = Locale.getDefault().toLanguageTag(); SystemProperties.set("persist.sys.locale", languageTag); SystemProperties.set("persist.sys.language", ""); SystemProperties.set("persist.sys.country", ""); SystemProperties.set("persist.sys.localevar", ""); } // Here we go! Slog.i(TAG, "Entered the Android system server!"); EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN, SystemClock.uptimeMillis()); // In case the runtime switched since last boot (such as when // the old runtime was removed in an OTA), set the system // property so that it is in sync. We can't do this in // libnativehelper's JniInvocation::Init code where we already // had to fallback to a different runtime because it is // running as root and we need to be the system user to set // the property. http://b/11463182 SystemProperties.set("persist.sys.dalvik.vm.lib.2", VMRuntime.getRuntime().vmLibrary()); // Enable the sampling profiler. if (SamplingProfilerIntegration.isEnabled()) { SamplingProfilerIntegration.start(); mProfilerSnapshotTimer = new Timer(); mProfilerSnapshotTimer.schedule(new TimerTask() { @Override public void run() { SamplingProfilerIntegration.writeSnapshot("system_server", null); } }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL); } // Mmmmmm... more memory! VMRuntime.getRuntime().clearGrowthLimit(); // The system server has to run all of the time, so it needs to be // as efficient as possible with its memory usage. VMRuntime.getRuntime().setTargetHeapUtilization(0.8f); // Some devices rely on runtime fingerprint generation, so make sure // we've defined it before booting further. Build.ensureFingerprintProperty(); // Within the system server, it is an error to access Environment paths without // explicitly specifying a user. Environment.setUserRequired(true); // Ensure binder calls into the system always run at foreground priority. BinderInternal.disableBackgroundScheduling(true); // Prepare the main looper thread (this thread). android.os.Process.setThreadPriority( android.os.Process.THREAD_PRIORITY_FOREGROUND); android.os.Process.setCanSelfBackground(false); Looper.prepareMainLooper(); // Initialize native services. System.loadLibrary("android_servers"); // Check whether we failed to shut down last time we tried. // This call may not return. performPendingShutdown(); // Initialize the system context. createSystemContext(); // Create the system service manager. mSystemServiceManager = new SystemServiceManager(mSystemContext); LocalServices.addService(SystemServiceManager.class, mSystemServiceManager); // Start services. try { startBootstrapServices(); startCoreServices(); startOtherServices(); } catch (Throwable ex) { Slog.e("System", "******************************************"); Slog.e("System", "************ Failure starting system services", ex); throw ex; } // For debug builds, log event loop stalls to dropbox for analysis. if (StrictMode.conditionallyEnableDebugLogging()) { Slog.i(TAG, "Enabled StrictMode for system server main thread."); } // Loop forever. Looper.loop(); throw new RuntimeException("Main thread loop unexpectedly exited"); } private void reportWtf(String msg, Throwable e) { Slog.w(TAG, "***********************************************"); Slog.wtf(TAG, "BOOT FAILURE " + msg, e); } private void performPendingShutdown() { final String shutdownAction = SystemProperties.get( ShutdownThread.SHUTDOWN_ACTION_PROPERTY, ""); if (shutdownAction != null && shutdownAction.length() > 0) { boolean reboot = (shutdownAction.charAt(0) == '1'); final String reason; if (shutdownAction.length() > 1) { reason = shutdownAction.substring(1, shutdownAction.length()); } else { reason = null; } ShutdownThread.rebootOrShutdown(null, reboot, reason); } } private void createSystemContext() { ActivityThread activityThread = ActivityThread.systemMain(); mSystemContext = activityThread.getSystemContext(); mSystemContext.setTheme(com.android.internal.R.style.Theme_Power_Dialog); } /** * Starts the small tangle of critical services that are needed to get * the system off the ground. These services have complex mutual dependencies * which is why we initialize them all in one place here. Unless your service * is also entwined in these dependencies, it should be initialized in one of * the other functions. */ private void startBootstrapServices() { // Wait for installd to finish starting up so that it has a chance to // create critical directories such as /data/user with the appropriate // permissions. We need this to complete before we initialize other services. Installer installer = mSystemServiceManager.startService(Installer.class); // Activity manager runs the show. mActivityManagerService = mSystemServiceManager.startService( ActivityManagerService.Lifecycle.class).getService(); mActivityManagerService.setSystemServiceManager(mSystemServiceManager); mActivityManagerService.setInstaller(installer); // Power manager needs to be started early because other services need it. // Native daemons may be watching for it to be registered so it must be ready // to handle incoming binder calls immediately (including being able to verify // the permissions for those calls). mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class); // Now that the power manager has been started, let the activity manager // initialize power management features. mActivityManagerService.initPowerManagement(); // Manages LEDs and display backlight so we need it to bring up the display. mSystemServiceManager.startService(LightsService.class); // Display manager is needed to provide display metrics before package manager // starts up. mDisplayManagerService = mSystemServiceManager.startService(DisplayManagerService.class); // We need the default display before we can initialize the package manager. mSystemServiceManager.startBootPhase(SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY); // Only run "core" apps if we're encrypting the device. String cryptState = SystemProperties.get("vold.decrypt"); if (ENCRYPTING_STATE.equals(cryptState)) { Slog.w(TAG, "Detected encryption in progress - only parsing core apps"); mOnlyCore = true; } else if (ENCRYPTED_STATE.equals(cryptState)) { Slog.w(TAG, "Device encrypted - only parsing core apps"); mOnlyCore = true; } // Start the package manager. Slog.i(TAG, "Package Manager"); mPackageManagerService = PackageManagerService.main(mSystemContext, installer, mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF, mOnlyCore); mFirstBoot = mPackageManagerService.isFirstBoot(); mPackageManager = mSystemContext.getPackageManager(); Slog.i(TAG, "User Service"); ServiceManager.addService(Context.USER_SERVICE, UserManagerService.getInstance()); // Initialize attribute cache used to cache resources from packages. AttributeCache.init(mSystemContext); // Set up the Application instance for the system process and get started. mActivityManagerService.setSystemProcess(); // The sensor service needs access to package manager service, app ops // service, and permissions service, therefore we start it after them. startSensorService(); } /** * Starts some essential services that are not tangled up in the bootstrap process. */ private void startCoreServices() { // Tracks the battery level. Requires LightService. mSystemServiceManager.startService(BatteryService.class); // Tracks application usage stats. mSystemServiceManager.startService(UsageStatsService.class); mActivityManagerService.setUsageStatsManager( LocalServices.getService(UsageStatsManagerInternal.class)); // Update after UsageStatsService is available, needed before performBootDexOpt. mPackageManagerService.getUsageStatsIfNoPackageUsageInfo(); // Tracks whether the updatable WebView is in a ready state and watches for update installs. mSystemServiceManager.startService(WebViewUpdateService.class); } /** * Starts a miscellaneous grab bag of stuff that has yet to be refactored * and organized. */ private void startOtherServices() { final Context context = mSystemContext; AccountManagerService accountManager = null; ContentService contentService = null; VibratorService vibrator = null; IAlarmManager alarm = null; IMountService mountService = null; NetworkManagementService networkManagement = null; NetworkStatsService networkStats = null; NetworkPolicyManagerService networkPolicy = null; ConnectivityService connectivity = null; NetworkScoreService networkScore = null; NsdService serviceDiscovery= null; WindowManagerService wm = null; UsbService usb = null; SerialService serial = null; NetworkTimeUpdateService networkTimeUpdater = null; CommonTimeManagementService commonTimeMgmtService = null; InputManagerService inputManager = null; TelephonyRegistry telephonyRegistry = null; ConsumerIrService consumerIr = null; AudioService audioService = null; MmsServiceBroker mmsService = null; EntropyMixer entropyMixer = null; CameraService cameraService = null; boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false); boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false); boolean disableLocation = SystemProperties.getBoolean("config.disable_location", false); boolean disableSystemUI = SystemProperties.getBoolean("config.disable_systemui", false); boolean disableNonCoreServices = SystemProperties.getBoolean("config.disable_noncore", false); boolean disableNetwork = SystemProperties.getBoolean("config.disable_network", false); boolean disableNetworkTime = SystemProperties.getBoolean("config.disable_networktime", false); boolean isEmulator = SystemProperties.get("ro.kernel.qemu").equals("1"); String externalServer = context.getResources().getString( org.cyanogenmod.platform.internal.R.string.config_externalSystemServer); boolean disableAtlas = SystemProperties.getBoolean("config.disable_atlas", false); try { Slog.i(TAG, "Reading configuration..."); SystemConfig.getInstance(); Slog.i(TAG, "Scheduling Policy"); ServiceManager.addService("scheduling_policy", new SchedulingPolicyService()); mSystemServiceManager.startService(TelecomLoaderService.class); Slog.i(TAG, "Telephony Registry"); telephonyRegistry = new TelephonyRegistry(context); ServiceManager.addService("telephony.registry", telephonyRegistry); Slog.i(TAG, "Entropy Mixer"); entropyMixer = new EntropyMixer(context); mContentResolver = context.getContentResolver(); Slog.i(TAG, "Camera Service"); mSystemServiceManager.startService(CameraService.class); // The AccountManager must come before the ContentService try { // TODO: seems like this should be disable-able, but req'd by ContentService Slog.i(TAG, "Account Manager"); accountManager = new AccountManagerService(context); ServiceManager.addService(Context.ACCOUNT_SERVICE, accountManager); } catch (Throwable e) { Slog.e(TAG, "Failure starting Account Manager", e); } Slog.i(TAG, "Content Manager"); contentService = ContentService.main(context, mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL); Slog.i(TAG, "System Content Providers"); mActivityManagerService.installSystemProviders(); Slog.i(TAG, "Vibrator Service"); vibrator = new VibratorService(context); ServiceManager.addService("vibrator", vibrator); Slog.i(TAG, "Consumer IR Service"); consumerIr = new ConsumerIrService(context); ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr); mSystemServiceManager.startService(AlarmManagerService.class); alarm = IAlarmManager.Stub.asInterface( ServiceManager.getService(Context.ALARM_SERVICE)); Slog.i(TAG, "Init Watchdog"); final Watchdog watchdog = Watchdog.getInstance(); watchdog.init(context, mActivityManagerService); Slog.i(TAG, "Input Manager"); inputManager = new InputManagerService(context); Slog.i(TAG, "Window Manager"); wm = WindowManagerService.main(context, inputManager, mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL, true, mOnlyCore); ServiceManager.addService(Context.WINDOW_SERVICE, wm); ServiceManager.addService(Context.INPUT_SERVICE, inputManager); mActivityManagerService.setWindowManager(wm); inputManager.setWindowManagerCallbacks(wm.getInputMonitor()); inputManager.start(); // TODO: Use service dependencies instead. mDisplayManagerService.windowManagerAndInputReady(); // Skip Bluetooth if we have an emulator kernel // TODO: Use a more reliable check to see if this product should // support Bluetooth - see bug 988521 if (isEmulator) { Slog.i(TAG, "No Bluetooh Service (emulator)"); } else if (mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL) { Slog.i(TAG, "No Bluetooth Service (factory test)"); } else if (!context.getPackageManager().hasSystemFeature (PackageManager.FEATURE_BLUETOOTH)) { Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)"); } else if (disableBluetooth) { Slog.i(TAG, "Bluetooth Service disabled by config"); } else { Slog.i(TAG, "Bluetooth Service"); mSystemServiceManager.startService(BluetoothService.class); } } catch (RuntimeException e) { Slog.e("System", "******************************************"); Slog.e("System", "************ Failure starting core service", e); } StatusBarManagerService statusBar = null; INotificationManager notification = null; InputMethodManagerService imm = null; WallpaperManagerService wallpaper = null; LocationManagerService location = null; CountryDetectorService countryDetector = null; TextServicesManagerService tsms = null; LockSettingsService lockSettings = null; AssetAtlasService atlas = null; MediaRouterService mediaRouter = null; GestureService gestureService = null; // Bring up services needed for UI. if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) { try { Slog.i(TAG, "Input Method Service"); imm = new InputMethodManagerService(context, wm); ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm); } catch (Throwable e) { reportWtf("starting Input Manager Service", e); } try { Slog.i(TAG, "Accessibility Manager"); ServiceManager.addService(Context.ACCESSIBILITY_SERVICE, new AccessibilityManagerService(context)); } catch (Throwable e) { reportWtf("starting Accessibility Manager", e); } } try { wm.displayReady(); } catch (Throwable e) { reportWtf("making display ready", e); } if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) { if (!disableStorage && !"0".equals(SystemProperties.get("system_init.startmountservice"))) { try { /* * NotificationManagerService is dependant on MountService, * (for media / usb notifications) so we must start MountService first. */ mSystemServiceManager.startService(MOUNT_SERVICE_CLASS); mountService = IMountService.Stub.asInterface( ServiceManager.getService("mount")); } catch (Throwable e) { reportWtf("starting Mount Service", e); } } } // We start this here so that we update our configuration to set watch or television // as appropriate. mSystemServiceManager.startService(UiModeManagerService.class); try { mPackageManagerService.performBootDexOpt(); } catch (Throwable e) { reportWtf("performing boot dexopt", e); } try { ActivityManagerNative.getDefault().updateBootProgress( IActivityManager.BOOT_STAGE_STARTING_APPS, null, 0, 0, false); } catch (RemoteException e) { } if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) { if (!disableNonCoreServices) { try { Slog.i(TAG, "LockSettingsService"); lockSettings = new LockSettingsService(context); ServiceManager.addService("lock_settings", lockSettings); } catch (Throwable e) { reportWtf("starting LockSettingsService service", e); } if (!SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("")) { mSystemServiceManager.startService(PersistentDataBlockService.class); } mSystemServiceManager.startService(DeviceIdleController.class); // Always start the Device Policy Manager, so that the API is compatible with // API8. mSystemServiceManager.startService(DevicePolicyManagerService.Lifecycle.class); } if (!disableSystemUI) { try { Slog.i(TAG, "Status Bar"); statusBar = new StatusBarManagerService(context, wm); ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar); } catch (Throwable e) { reportWtf("starting StatusBarManagerService", e); } } if (!disableNonCoreServices) { try { Slog.i(TAG, "Clipboard Service"); ServiceManager.addService(Context.CLIPBOARD_SERVICE, new ClipboardService(context)); } catch (Throwable e) { reportWtf("starting Clipboard Service", e); } } if (!disableNetwork) { try { Slog.i(TAG, "NetworkManagement Service"); networkManagement = NetworkManagementService.create(context); ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement); } catch (Throwable e) { reportWtf("starting NetworkManagement Service", e); } } if (!disableNonCoreServices) { try { Slog.i(TAG, "Text Service Manager Service"); tsms = new TextServicesManagerService(context); ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms); } catch (Throwable e) { reportWtf("starting Text Service Manager Service", e); } } if (!disableNetwork) { try { Slog.i(TAG, "Network Score Service"); networkScore = new NetworkScoreService(context); ServiceManager.addService(Context.NETWORK_SCORE_SERVICE, networkScore); } catch (Throwable e) { reportWtf("starting Network Score Service", e); } try { Slog.i(TAG, "NetworkStats Service"); networkStats = new NetworkStatsService(context, networkManagement, alarm); ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats); } catch (Throwable e) { reportWtf("starting NetworkStats Service", e); } try { Slog.i(TAG, "NetworkPolicy Service"); networkPolicy = new NetworkPolicyManagerService( context, mActivityManagerService, (IPowerManager)ServiceManager.getService(Context.POWER_SERVICE), networkStats, networkManagement); ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy); } catch (Throwable e) { reportWtf("starting NetworkPolicy Service", e); } mSystemServiceManager.startService(WIFI_P2P_SERVICE_CLASS); mSystemServiceManager.startService(WIFI_SERVICE_CLASS); mSystemServiceManager.startService( "com.android.server.wifi.WifiScanningService"); mSystemServiceManager.startService("com.android.server.wifi.RttService"); if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_ETHERNET) || mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)) { mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS); } try { Slog.i(TAG, "Connectivity Service"); connectivity = new ConnectivityService( context, networkManagement, networkStats, networkPolicy); ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity); networkStats.bindConnectivityManager(connectivity); networkPolicy.bindConnectivityManager(connectivity); } catch (Throwable e) { reportWtf("starting Connectivity Service", e); } try { Slog.i(TAG, "Network Service Discovery Service"); serviceDiscovery = NsdService.create(context); ServiceManager.addService( Context.NSD_SERVICE, serviceDiscovery); } catch (Throwable e) { reportWtf("starting Service Discovery Service", e); } } if (!disableNonCoreServices) { try { Slog.i(TAG, "UpdateLock Service"); ServiceManager.addService(Context.UPDATE_LOCK_SERVICE, new UpdateLockService(context)); } catch (Throwable e) { reportWtf("starting UpdateLockService", e); } } /* * MountService has a few dependencies: Notification Manager and * AppWidget Provider. Make sure MountService is completely started * first before continuing. */ if (mountService != null && !mOnlyCore) { try { mountService.waitForAsecScan(); } catch (RemoteException ignored) { } } try { if (accountManager != null) accountManager.systemReady(); } catch (Throwable e) { reportWtf("making Account Manager Service ready", e); } try { if (contentService != null) contentService.systemReady(); } catch (Throwable e) { reportWtf("making Content Service ready", e); } mSystemServiceManager.startService(NotificationManagerService.class); notification = INotificationManager.Stub.asInterface( ServiceManager.getService(Context.NOTIFICATION_SERVICE)); networkPolicy.bindNotificationManager(notification); mSystemServiceManager.startService(DeviceStorageMonitorService.class); if (!disableLocation) { try { Slog.i(TAG, "Location Manager"); location = new LocationManagerService(context); ServiceManager.addService(Context.LOCATION_SERVICE, location); } catch (Throwable e) { reportWtf("starting Location Manager", e); } try { Slog.i(TAG, "Country Detector"); countryDetector = new CountryDetectorService(context); ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector); } catch (Throwable e) { reportWtf("starting Country Detector", e); } } if (!disableNonCoreServices) { try { Slog.i(TAG, "Search Service"); ServiceManager.addService(Context.SEARCH_SERVICE, new SearchManagerService(context)); } catch (Throwable e) { reportWtf("starting Search Service", e); } } try { Slog.i(TAG, "DropBox Service"); ServiceManager.addService(Context.DROPBOX_SERVICE, new DropBoxManagerService(context, new File("/data/system/dropbox"))); } catch (Throwable e) { reportWtf("starting DropBoxManagerService", e); } if (!disableNonCoreServices && context.getResources().getBoolean( R.bool.config_enableWallpaperService)) { try { Slog.i(TAG, "Wallpaper Service"); wallpaper = new WallpaperManagerService(context); ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper); } catch (Throwable e) { reportWtf("starting Wallpaper Service", e); } } try { Slog.i(TAG, "Audio Service"); audioService = new AudioService(context); ServiceManager.addService(Context.AUDIO_SERVICE, audioService); } catch (Throwable e) { reportWtf("starting Audio Service", e); } if (!disableNonCoreServices) { mSystemServiceManager.startService(DockObserver.class); if (context.getPackageManager().hasSystemFeature (PackageManager.FEATURE_WATCH)) { mSystemServiceManager.startService(ThermalObserver.class); } } try { Slog.i(TAG, "Wired Accessory Manager"); // Listen for wired headset changes inputManager.setWiredAccessoryCallbacks( new WiredAccessoryManager(context, inputManager)); } catch (Throwable e) { reportWtf("starting WiredAccessoryManager", e); } if (!disableNonCoreServices) { if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_MIDI)) { // Start MIDI Manager service mSystemServiceManager.startService(MIDI_SERVICE_CLASS); } if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST) || mPackageManager.hasSystemFeature( PackageManager.FEATURE_USB_ACCESSORY)) { // Manage USB host and device support mSystemServiceManager.startService(USB_SERVICE_CLASS); } try { Slog.i(TAG, "Serial Service"); // Serial port support serial = new SerialService(context); ServiceManager.addService(Context.SERIAL_SERVICE, serial); } catch (Throwable e) { Slog.e(TAG, "Failure starting SerialService", e); } } mSystemServiceManager.startService(TwilightService.class); mSystemServiceManager.startService(JobSchedulerService.class); if (!disableNonCoreServices) { if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_BACKUP)) { mSystemServiceManager.startService(BACKUP_MANAGER_SERVICE_CLASS); } if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS)) { mSystemServiceManager.startService(APPWIDGET_SERVICE_CLASS); } if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_VOICE_RECOGNIZERS)) { mSystemServiceManager.startService(VOICE_RECOGNITION_MANAGER_SERVICE_CLASS); } if (GestureLauncherService.isGestureLauncherEnabled(context.getResources())) { Slog.i(TAG, "Gesture Launcher Service"); mSystemServiceManager.startService(GestureLauncherService.class); } } try { Slog.i(TAG, "DiskStats Service"); ServiceManager.addService("diskstats", new DiskStatsService(context)); } catch (Throwable e) { reportWtf("starting DiskStats Service", e); } try { Slog.i(TAG, "VirtualPosition Service"); ServiceManager.addService("virtualposition", new VirtualPositionService()); } catch (Throwable e) { reportWtf("starting VirtualPosition Service", e); } try { // need to add this service even if SamplingProfilerIntegration.isEnabled() // is false, because it is this service that detects system property change and // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work, // there is little overhead for running this service. Slog.i(TAG, "SamplingProfiler Service"); ServiceManager.addService("samplingprofiler", new SamplingProfilerService(context)); } catch (Throwable e) { reportWtf("starting SamplingProfiler Service", e); } if (!disableNetwork && !disableNetworkTime) { try { Slog.i(TAG, "NetworkTimeUpdateService"); networkTimeUpdater = new NetworkTimeUpdateService(context); } catch (Throwable e) { reportWtf("starting NetworkTimeUpdate service", e); } } try { Slog.i(TAG, "CommonTimeManagementService"); commonTimeMgmtService = new CommonTimeManagementService(context); ServiceManager.addService("commontime_management", commonTimeMgmtService); } catch (Throwable e) { reportWtf("starting CommonTimeManagementService service", e); } if (!disableNetwork) { try { Slog.i(TAG, "CertBlacklister"); CertBlacklister blacklister = new CertBlacklister(context); } catch (Throwable e) { reportWtf("starting CertBlacklister", e); } } if (!disableNonCoreServices) { // Dreams (interactive idle-time views, a/k/a screen savers, and doze mode) mSystemServiceManager.startService(DreamManagerService.class); } if (!disableNonCoreServices && !disableAtlas) { try { Slog.i(TAG, "Assets Atlas Service"); atlas = new AssetAtlasService(context); ServiceManager.addService(AssetAtlasService.ASSET_ATLAS_SERVICE, atlas); } catch (Throwable e) { reportWtf("starting AssetAtlasService", e); } } if (!disableNonCoreServices) { ServiceManager.addService(GraphicsStatsService.GRAPHICS_STATS_SERVICE, new GraphicsStatsService(context)); } if (context.getResources().getBoolean( com.android.internal.R.bool.config_enableGestureService)) { try { Slog.i(TAG, "Gesture Sensor Service"); gestureService = new GestureService(context, inputManager); ServiceManager.addService("gesture", gestureService); } catch (Throwable e) { Slog.e(TAG, "Failure starting Gesture Sensor Service", e); } } if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PRINTING)) { mSystemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS); } mSystemServiceManager.startService(RestrictionsManagerService.class); mSystemServiceManager.startService(MediaSessionService.class); if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_HDMI_CEC)) { mSystemServiceManager.startService(HdmiControlService.class); } if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LIVE_TV)) { mSystemServiceManager.startService(TvInputManagerService.class); } if (!disableNonCoreServices) { try { Slog.i(TAG, "Media Router Service"); mediaRouter = new MediaRouterService(context); ServiceManager.addService(Context.MEDIA_ROUTER_SERVICE, mediaRouter); } catch (Throwable e) { reportWtf("starting MediaRouterService", e); } mSystemServiceManager.startService(TrustManagerService.class); mSystemServiceManager.startService(FingerprintService.class); try { Slog.i(TAG, "BackgroundDexOptService"); BackgroundDexOptService.schedule(context, 0); } catch (Throwable e) { reportWtf("starting BackgroundDexOptService", e); } } mSystemServiceManager.startService(LauncherAppsService.class); } if (!disableNonCoreServices) { mSystemServiceManager.startService(MediaProjectionManagerService.class); } // make sure the ADB_ENABLED setting value matches the secure property value CMSettings.Secure.putInt(mContentResolver, CMSettings.Secure.ADB_PORT, Integer.parseInt(SystemProperties.get("service.adb.tcp.port", "-1"))); // register observer to listen for settings changes mContentResolver.registerContentObserver( CMSettings.Secure.getUriFor(CMSettings.Secure.ADB_PORT), false, new AdbPortObserver()); // Before things start rolling, be sure we have decided whether // we are in safe mode. final boolean safeMode = wm.detectSafeMode(); if (safeMode) { mActivityManagerService.enterSafeMode(); // Disable the JIT for the system_server process VMRuntime.getRuntime().disableJitCompilation(); } else { // Enable the JIT for the system_server process VMRuntime.getRuntime().startJitCompilation(); } // MMS service broker mmsService = mSystemServiceManager.startService(MmsServiceBroker.class); final Class serverClazz; try { serverClazz = Class.forName(externalServer); final Constructor constructor = serverClazz.getDeclaredConstructor(Context.class); constructor.setAccessible(true); final Object baseObject = constructor.newInstance(mSystemContext); final Method method = baseObject.getClass().getDeclaredMethod("run"); method.setAccessible(true); method.invoke(baseObject); } catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | InstantiationException | NoSuchMethodException e) { Slog.wtf(TAG, "Unable to start " + externalServer); Slog.wtf(TAG, e); } // It is now time to start up the app processes... try { vibrator.systemReady(); } catch (Throwable e) { reportWtf("making Vibrator Service ready", e); } if (lockSettings != null) { try { lockSettings.systemReady(); } catch (Throwable e) { reportWtf("making Lock Settings Service ready", e); } } // Needed by DevicePolicyManager for initialization mSystemServiceManager.startBootPhase(SystemService.PHASE_LOCK_SETTINGS_READY); mSystemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY); try { wm.systemReady(); } catch (Throwable e) { reportWtf("making Window Manager Service ready", e); } if (safeMode) { mActivityManagerService.showSafeModeOverlay(); } // Update the configuration for this context by hand, because we're going // to start using it before the config change done in wm.systemReady() will // propagate to it. Configuration config = wm.computeNewConfiguration(); DisplayMetrics metrics = new DisplayMetrics(); WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); w.getDefaultDisplay().getMetrics(metrics); context.getResources().updateConfiguration(config, metrics); // The system context's theme may be configuration-dependent. final Theme systemTheme = context.getTheme(); if (systemTheme.getChangingConfigurations() != 0) { systemTheme.rebase(); } try { // TODO: use boot phase mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService()); } catch (Throwable e) { reportWtf("making Power Manager Service ready", e); } try { mPackageManagerService.systemReady(); } catch (Throwable e) { reportWtf("making Package Manager Service ready", e); } try { // TODO: use boot phase and communicate these flags some other way mDisplayManagerService.systemReady(safeMode, mOnlyCore); } catch (Throwable e) { reportWtf("making Display Manager Service ready", e); } if (gestureService != null) { try { gestureService.systemReady(); } catch (Throwable e) { reportWtf("making Gesture Sensor Service ready", e); } } // These are needed to propagate to the runnable below. final NetworkManagementService networkManagementF = networkManagement; final NetworkStatsService networkStatsF = networkStats; final NetworkPolicyManagerService networkPolicyF = networkPolicy; final ConnectivityService connectivityF = connectivity; final NetworkScoreService networkScoreF = networkScore; final WallpaperManagerService wallpaperF = wallpaper; final InputMethodManagerService immF = imm; final LocationManagerService locationF = location; final CountryDetectorService countryDetectorF = countryDetector; final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater; final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService; final TextServicesManagerService textServiceManagerServiceF = tsms; final StatusBarManagerService statusBarF = statusBar; final AssetAtlasService atlasF = atlas; final InputManagerService inputManagerF = inputManager; final TelephonyRegistry telephonyRegistryF = telephonyRegistry; final MediaRouterService mediaRouterF = mediaRouter; final AudioService audioServiceF = audioService; final MmsServiceBroker mmsServiceF = mmsService; // We now tell the activity manager it is okay to run third party // code. It will call back into us once it has gotten to the state // where third party code can really run (but before it has actually // started launching the initial applications), for us to complete our // initialization. mActivityManagerService.systemReady(new Runnable() { @Override public void run() { Slog.i(TAG, "Making services ready"); mSystemServiceManager.startBootPhase( SystemService.PHASE_ACTIVITY_MANAGER_READY); try { mActivityManagerService.startObservingNativeCrashes(); } catch (Throwable e) { reportWtf("observing native crashes", e); } Slog.i(TAG, "WebViewFactory preparation"); WebViewFactory.prepareWebViewInSystemServer(); try { startSystemUi(context); } catch (Throwable e) { reportWtf("starting System UI", e); } try { if (networkScoreF != null) networkScoreF.systemReady(); } catch (Throwable e) { reportWtf("making Network Score Service ready", e); } try { if (networkManagementF != null) networkManagementF.systemReady(); } catch (Throwable e) { reportWtf("making Network Managment Service ready", e); } try { if (networkStatsF != null) networkStatsF.systemReady(); } catch (Throwable e) { reportWtf("making Network Stats Service ready", e); } try { if (networkPolicyF != null) networkPolicyF.systemReady(); } catch (Throwable e) { reportWtf("making Network Policy Service ready", e); } try { if (connectivityF != null) connectivityF.systemReady(); } catch (Throwable e) { reportWtf("making Connectivity Service ready", e); } try { if (audioServiceF != null) audioServiceF.systemReady(); } catch (Throwable e) { reportWtf("Notifying AudioService running", e); } Watchdog.getInstance().start(); // It is now okay to let the various system services start their // third party code... mSystemServiceManager.startBootPhase( SystemService.PHASE_THIRD_PARTY_APPS_CAN_START); try { if (wallpaperF != null) wallpaperF.systemRunning(); } catch (Throwable e) { reportWtf("Notifying WallpaperService running", e); } try { if (immF != null) immF.systemRunning(statusBarF); } catch (Throwable e) { reportWtf("Notifying InputMethodService running", e); } try { if (locationF != null) locationF.systemRunning(); } catch (Throwable e) { reportWtf("Notifying Location Service running", e); } try { if (countryDetectorF != null) countryDetectorF.systemRunning(); } catch (Throwable e) { reportWtf("Notifying CountryDetectorService running", e); } try { if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemRunning(); } catch (Throwable e) { reportWtf("Notifying NetworkTimeService running", e); } try { if (commonTimeMgmtServiceF != null) { commonTimeMgmtServiceF.systemRunning(); } } catch (Throwable e) { reportWtf("Notifying CommonTimeManagementService running", e); } try { if (textServiceManagerServiceF != null) textServiceManagerServiceF.systemRunning(); } catch (Throwable e) { reportWtf("Notifying TextServicesManagerService running", e); } try { if (atlasF != null) atlasF.systemRunning(); } catch (Throwable e) { reportWtf("Notifying AssetAtlasService running", e); } try { // TODO(BT) Pass parameter to input manager if (inputManagerF != null) inputManagerF.systemRunning(); } catch (Throwable e) { reportWtf("Notifying InputManagerService running", e); } try { if (telephonyRegistryF != null) telephonyRegistryF.systemRunning(); } catch (Throwable e) { reportWtf("Notifying TelephonyRegistry running", e); } try { if (mediaRouterF != null) mediaRouterF.systemRunning(); } catch (Throwable e) { reportWtf("Notifying MediaRouterService running", e); } try { if (mmsServiceF != null) mmsServiceF.systemRunning(); } catch (Throwable e) { reportWtf("Notifying MmsService running", e); } } }); } static final void startSystemUi(Context context) { Intent intent = new Intent(); intent.setComponent(new ComponentName("com.android.systemui", "com.android.systemui.SystemUIService")); //Slog.d(TAG, "Starting service: " + intent); context.startServiceAsUser(intent, UserHandle.OWNER); } } ================================================ FILE: VirtualPosition/vp_Framework/VirtualPositionService.java ================================================ package com.android.server; import android.content.Context; import android.os.IVirtualPositionService; import android.util.Slog; public class VirtualPositionService extends IVirtualPositionService.Stub { private static final String TAG = "VirtualPositionService"; VirtualPositionService() { init_native(); } public void setVirtualToggle(int tog) { native_set_virtual_toggle(tog); } public int getVirtualToggle(){ return native_get_virtual_toggle(); } public void setVirtualLatitude(double vlat) { native_set_virtual_latitude(vlat); } public double getVirtualLatitude(){ return native_get_virtual_latitude(); } public void setVirtualLongitude(double vlon) { native_set_virtual_longitude(vlon); } public double getVirtualLongitude() { return native_get_virtual_longitude(); } private static native boolean init_native(); private static native void native_set_virtual_toggle(int tog); private static native int native_get_virtual_toggle(); private static native void native_set_virtual_latitude(double vlat); private static native double native_get_virtual_latitude(); private static native void native_set_virtual_longitude(double vlon); private static native double native_get_virtual_longitude(); }; ================================================ FILE: VirtualPosition/vp_Framework/sepolicy/device.te ================================================ # Device types type device, dev_type, fs_type; type alarm_device, dev_type, mlstrustedobject; type adb_device, dev_type; type ashmem_device, dev_type, mlstrustedobject; type audio_device, dev_type; type binder_device, dev_type, mlstrustedobject; type block_device, dev_type; type camera_device, dev_type; type dm_device, dev_type; type loop_device, dev_type; type pmsg_device, dev_type, mlstrustedobject; type radio_device, dev_type; type ram_device, dev_type; type rtc_device, dev_type; type vold_device, dev_type; type console_device, dev_type; type cpuctl_device, dev_type; type fscklogs, dev_type; type full_device, dev_type; # GPU (used by most UI apps) type gpu_device, dev_type, mlstrustedobject; type graphics_device, dev_type; type hw_random_device, dev_type; type input_device, dev_type; type kmem_device, dev_type; type log_device, dev_type, mlstrustedobject; type mtd_device, dev_type; type mtp_device, dev_type, mlstrustedobject; type nfc_device, dev_type; type ptmx_device, dev_type, mlstrustedobject; type kmsg_device, dev_type; type null_device, dev_type, mlstrustedobject; type random_device, dev_type, mlstrustedobject; type sensors_device, dev_type; type serial_device, dev_type; type socket_device, dev_type; type owntty_device, dev_type, mlstrustedobject; type tty_device, dev_type; type urandom_device, dev_type, mlstrustedobject; type video_device, dev_type; type vcs_device, dev_type; type zero_device, dev_type, mlstrustedobject; type fuse_device, dev_type; type iio_device, dev_type; type ion_device, dev_type, mlstrustedobject; type gps_device, dev_type; type qtaguid_device, dev_type; type watchdog_device, dev_type; type uhid_device, dev_type; type uio_device, dev_type; type tun_device, dev_type, mlstrustedobject; type usbaccessory_device, dev_type, mlstrustedobject; type usb_device, dev_type, mlstrustedobject; type klog_device, dev_type; type properties_device, dev_type; # All devices have a uart for the hci # attach service. The uart dev node # varies per device. This type # is used in per device policy type hci_attach_dev, dev_type; # All devices have a rpmsg device for # achieving remoteproc and rpmsg modules type rpmsg_device, dev_type; # Partition layout block device type root_block_device, dev_type; # factory reset protection block device type frp_block_device, dev_type; # System block device mounted on /system. type system_block_device, dev_type; # Recovery block device. type recovery_block_device, dev_type; # boot block device. type boot_block_device, dev_type; # Userdata block device mounted on /data. type userdata_block_device, dev_type; # Cache block device mounted on /cache. type cache_block_device, dev_type; # Block device for any swap partition. type swap_block_device, dev_type; # Metadata block device used for encryption metadata. # Assign this type to the partition specified by the encryptable= # mount option in your fstab file in the entry for userdata. type metadata_block_device, dev_type; # add by aggresss type vp_device, dev_type; ================================================ FILE: VirtualPosition/vp_Framework/sepolicy/file_contexts ================================================ ########################################### # Root / u:object_r:rootfs:s0 # Data files /adb_keys u:object_r:adb_keys_file:s0 /default\.prop u:object_r:rootfs:s0 /fstab\..* u:object_r:rootfs:s0 /init\..* u:object_r:rootfs:s0 /res(/.*)? u:object_r:rootfs:s0 /ueventd\..* u:object_r:rootfs:s0 # Executables /charger u:object_r:rootfs:s0 /init u:object_r:init_exec:s0 /sbin(/.*)? u:object_r:rootfs:s0 # Empty directories /lost\+found u:object_r:rootfs:s0 /proc u:object_r:rootfs:s0 # SELinux policy files /file_contexts u:object_r:rootfs:s0 /property_contexts u:object_r:rootfs:s0 /seapp_contexts u:object_r:rootfs:s0 /sepolicy u:object_r:rootfs:s0 ########################## # Devices # /dev(/.*)? u:object_r:device:s0 /dev/akm8973.* u:object_r:sensors_device:s0 /dev/accelerometer u:object_r:sensors_device:s0 /dev/adf[0-9]* u:object_r:graphics_device:s0 /dev/adf-interface[0-9]*\.[0-9]* u:object_r:graphics_device:s0 /dev/adf-overlay-engine[0-9]*\.[0-9]* u:object_r:graphics_device:s0 /dev/alarm u:object_r:alarm_device:s0 /dev/android_adb.* u:object_r:adb_device:s0 /dev/ashmem u:object_r:ashmem_device:s0 /dev/audio.* u:object_r:audio_device:s0 /dev/binder u:object_r:binder_device:s0 /dev/block(/.*)? u:object_r:block_device:s0 /dev/block/dm-[0-9]+ u:object_r:dm_device:s0 /dev/block/loop[0-9]* u:object_r:loop_device:s0 /dev/block/vold/.+ u:object_r:vold_device:s0 /dev/block/ram[0-9]* u:object_r:ram_device:s0 /dev/bus/usb(.*)? u:object_r:usb_device:s0 /dev/cam u:object_r:camera_device:s0 /dev/console u:object_r:console_device:s0 /dev/cpuctl(/.*)? u:object_r:cpuctl_device:s0 /dev/device-mapper u:object_r:dm_device:s0 /dev/eac u:object_r:audio_device:s0 /dev/fscklogs(/.*)? u:object_r:fscklogs:s0 /dev/full u:object_r:full_device:s0 /dev/fuse u:object_r:fuse_device:s0 /dev/graphics(/.*)? u:object_r:graphics_device:s0 /dev/hw_random u:object_r:hw_random_device:s0 /dev/input(/.*) u:object_r:input_device:s0 /dev/iio:device[0-9]+ u:object_r:iio_device:s0 /dev/ion u:object_r:ion_device:s0 /dev/kmem u:object_r:kmem_device:s0 /dev/log(/.*)? u:object_r:log_device:s0 /dev/mem u:object_r:kmem_device:s0 /dev/modem.* u:object_r:radio_device:s0 /dev/mpu u:object_r:gps_device:s0 /dev/mpuirq u:object_r:gps_device:s0 /dev/mtd(/.*)? u:object_r:mtd_device:s0 /dev/mtp_usb u:object_r:mtp_device:s0 /dev/pmsg0 u:object_r:pmsg_device:s0 /dev/pn544 u:object_r:nfc_device:s0 /dev/ppp u:object_r:ppp_device:s0 /dev/ptmx u:object_r:ptmx_device:s0 /dev/pvrsrvkm u:object_r:gpu_device:s0 /dev/kmsg u:object_r:kmsg_device:s0 /dev/null u:object_r:null_device:s0 /dev/nvhdcp1 u:object_r:video_device:s0 /dev/random u:object_r:random_device:s0 /dev/rpmsg-omx[0-9] u:object_r:rpmsg_device:s0 /dev/rproc_user u:object_r:rpmsg_device:s0 /dev/rtc[0-9] u:object_r:rtc_device:s0 /dev/snd(/.*)? u:object_r:audio_device:s0 /dev/socket(/.*)? u:object_r:socket_device:s0 /dev/socket/adbd u:object_r:adbd_socket:s0 /dev/socket/sap_uim_socket[0-9] u:object_r:sap_uim_socket:s0 /dev/socket/cryptd u:object_r:vold_socket:s0 /dev/socket/dnsproxyd u:object_r:dnsproxyd_socket:s0 /dev/socket/dumpstate u:object_r:dumpstate_socket:s0 /dev/socket/fwmarkd u:object_r:fwmarkd_socket:s0 /dev/socket/gps u:object_r:gps_socket:s0 /dev/socket/installd u:object_r:installd_socket:s0 /dev/socket/lmkd u:object_r:lmkd_socket:s0 /dev/socket/logd u:object_r:logd_socket:s0 /dev/socket/logdr u:object_r:logdr_socket:s0 /dev/socket/logdw u:object_r:logdw_socket:s0 /dev/socket/mdns u:object_r:mdns_socket:s0 /dev/socket/mdnsd u:object_r:mdnsd_socket:s0 /dev/socket/mtpd u:object_r:mtpd_socket:s0 /dev/socket/netd u:object_r:netd_socket:s0 /dev/socket/property_service u:object_r:property_socket:s0 /dev/socket/racoon u:object_r:racoon_socket:s0 /dev/socket/rild u:object_r:rild_socket:s0 /dev/socket/rild-debug u:object_r:rild_debug_socket:s0 /dev/socket/vold u:object_r:vold_socket:s0 /dev/socket/wpa_eth[0-9] u:object_r:wpa_socket:s0 /dev/socket/wpa_wlan[0-9] u:object_r:wpa_socket:s0 /dev/socket/zygote u:object_r:zygote_socket:s0 /dev/socket/zygote_secondary u:object_r:zygote_socket:s0 /dev/spdif_out.* u:object_r:audio_device:s0 /dev/tegra.* u:object_r:video_device:s0 /dev/tf_driver u:object_r:tee_device:s0 /dev/tty u:object_r:owntty_device:s0 /dev/tty[0-9]* u:object_r:tty_device:s0 /dev/ttyS[0-9]* u:object_r:serial_device:s0 /dev/tun u:object_r:tun_device:s0 /dev/uhid u:object_r:uhid_device:s0 /dev/uinput u:object_r:uhid_device:s0 /dev/uio[0-9]* u:object_r:uio_device:s0 /dev/urandom u:object_r:urandom_device:s0 /dev/usb_accessory u:object_r:usbaccessory_device:s0 /dev/vcs[0-9a-z]* u:object_r:vcs_device:s0 /dev/video[0-9]* u:object_r:video_device:s0 /dev/watchdog u:object_r:watchdog_device:s0 /dev/xt_qtaguid u:object_r:qtaguid_device:s0 /dev/zero u:object_r:zero_device:s0 /dev/__kmsg__ u:object_r:klog_device:s0 /dev/__properties__ u:object_r:properties_device:s0 # add by aggresss /dev/vp u:object_r:vp_device:s0 ############################# # System files # /system(/.*)? u:object_r:system_file:s0 /system/bin/e2fsck -- u:object_r:fsck_exec:s0 /system/bin/fsck\.f2fs -- u:object_r:fsck_exec:s0 /system/bin/fsck_msdos -- u:object_r:fsck_exec:s0 /system/bin/toolbox -- u:object_r:toolbox_exec:s0 /system/bin/toybox -- u:object_r:toolbox_exec:s0 /system/bin/logcat -- u:object_r:logcat_exec:s0 /system/bin/sh -- u:object_r:shell_exec:s0 /system/bin/run-as -- u:object_r:runas_exec:s0 /system/bin/bootanimation u:object_r:bootanim_exec:s0 /system/bin/app_process32 u:object_r:zygote_exec:s0 /system/bin/app_process64 u:object_r:zygote_exec:s0 /system/bin/servicemanager u:object_r:servicemanager_exec:s0 /system/bin/surfaceflinger u:object_r:surfaceflinger_exec:s0 /system/bin/drmserver u:object_r:drmserver_exec:s0 /system/bin/dumpstate u:object_r:dumpstate_exec:s0 /system/bin/vold u:object_r:vold_exec:s0 /system/bin/netd u:object_r:netd_exec:s0 /system/bin/rild u:object_r:rild_exec:s0 /system/bin/mediaserver u:object_r:mediaserver_exec:s0 /system/bin/mdnsd u:object_r:mdnsd_exec:s0 /system/bin/installd u:object_r:installd_exec:s0 /system/bin/keystore u:object_r:keystore_exec:s0 /system/bin/fingerprintd u:object_r:fingerprintd_exec:s0 /system/bin/gatekeeperd u:object_r:gatekeeperd_exec:s0 /system/bin/debuggerd u:object_r:debuggerd_exec:s0 /system/bin/debuggerd64 u:object_r:debuggerd_exec:s0 /system/bin/wpa_supplicant u:object_r:wpa_exec:s0 /system/bin/sdcard u:object_r:sdcardd_exec:s0 /system/bin/dhcpcd u:object_r:dhcp_exec:s0 /system/bin/mtpd u:object_r:mtp_exec:s0 /system/bin/pppd u:object_r:ppp_exec:s0 /system/bin/tf_daemon u:object_r:tee_exec:s0 /system/bin/racoon u:object_r:racoon_exec:s0 /system/xbin/su u:object_r:su_exec:s0 /system/xbin/procrank u:object_r:procrank_exec:s0 /system/xbin/perfprofd u:object_r:perfprofd_exec:s0 /system/xbin/simpleperf u:object_r:system_file:s0 /system/vendor/bin/gpsd u:object_r:gpsd_exec:s0 /system/bin/dnsmasq u:object_r:dnsmasq_exec:s0 /system/bin/hostapd u:object_r:hostapd_exec:s0 /system/bin/clatd u:object_r:clatd_exec:s0 /system/bin/lmkd u:object_r:lmkd_exec:s0 /system/bin/inputflinger u:object_r:inputflinger_exec:s0 /system/bin/logd u:object_r:logd_exec:s0 /system/bin/uncrypt u:object_r:uncrypt_exec:s0 /system/bin/logwrapper u:object_r:system_file:s0 /system/bin/vdc u:object_r:vdc_exec:s0 /system/bin/install-recovery.sh u:object_r:install_recovery_exec:s0 /system/bin/dex2oat u:object_r:dex2oat_exec:s0 # patchoat executable has (essentially) the same requirements as dex2oat. /system/bin/patchoat u:object_r:dex2oat_exec:s0 /system/bin/sgdisk u:object_r:sgdisk_exec:s0 /system/bin/blkid u:object_r:blkid_exec:s0 /system/bin/tzdatacheck u:object_r:tzdatacheck_exec:s0 ############################# # Vendor files # /vendor(/.*)? u:object_r:system_file:s0 /vendor/bin/gpsd u:object_r:gpsd_exec:s0 ############################# # OEM and ODM files # /odm(/.*)? u:object_r:system_file:s0 /oem(/.*)? u:object_r:oemfs:s0 ############################# # Data files # # NOTE: When modifying existing label rules, changes may also need to # propagate to the "Expanded data files" section. # /data(/.*)? u:object_r:system_data_file:s0 /data/.layout_version u:object_r:install_data_file:s0 /data/unencrypted(/.*)? u:object_r:unencrypted_data_file:s0 /data/backup(/.*)? u:object_r:backup_data_file:s0 /data/secure/backup(/.*)? u:object_r:backup_data_file:s0 /data/security(/.*)? u:object_r:security_file:s0 /data/system/ndebugsocket u:object_r:system_ndebug_socket:s0 /data/drm(/.*)? u:object_r:drm_data_file:s0 /data/gps(/.*)? u:object_r:gps_data_file:s0 /data/resource-cache(/.*)? u:object_r:resourcecache_data_file:s0 /data/dalvik-cache(/.*)? u:object_r:dalvikcache_data_file:s0 /data/dalvik-cache/profiles(/.*)? u:object_r:dalvikcache_profiles_data_file:s0 /data/adb(/.*)? u:object_r:adb_data_file:s0 /data/anr(/.*)? u:object_r:anr_data_file:s0 /data/app(/.*)? u:object_r:apk_data_file:s0 /data/app/[^/]+/oat(/.*)? u:object_r:dalvikcache_data_file:s0 /data/app/vmdl[^/]+\.tmp(/.*)? u:object_r:apk_tmp_file:s0 /data/app/vmdl[^/]+\.tmp/oat(/.*)? u:object_r:dalvikcache_data_file:s0 /data/app-private(/.*)? u:object_r:apk_private_data_file:s0 /data/app-private/vmdl.*\.tmp(/.*)? u:object_r:apk_private_tmp_file:s0 /data/tombstones(/.*)? u:object_r:tombstone_data_file:s0 /data/local/tmp(/.*)? u:object_r:shell_data_file:s0 /data/media(/.*)? u:object_r:media_rw_data_file:s0 /data/mediadrm(/.*)? u:object_r:media_data_file:s0 /data/property(/.*)? u:object_r:property_data_file:s0 # Misc data /data/misc/adb(/.*)? u:object_r:adb_keys_file:s0 /data/misc/audio(/.*)? u:object_r:audio_data_file:s0 /data/misc/bluetooth(/.*)? u:object_r:bluetooth_data_file:s0 /data/misc/bluedroid(/.*)? u:object_r:bluetooth_data_file:s0 /data/misc/bluedroid/\.a2dp_ctrl u:object_r:bluetooth_socket:s0 /data/misc/bluedroid/\.a2dp_data u:object_r:bluetooth_socket:s0 /data/misc/camera(/.*)? u:object_r:camera_data_file:s0 /data/misc/dhcp(/.*)? u:object_r:dhcp_data_file:s0 /data/misc/gatekeeper(/.*)? u:object_r:gatekeeper_data_file:s0 /data/misc/keychain(/.*)? u:object_r:keychain_data_file:s0 /data/misc/keystore(/.*)? u:object_r:keystore_data_file:s0 /data/misc/logd(/.*)? u:object_r:misc_logd_file:s0 /data/misc/media(/.*)? u:object_r:media_data_file:s0 /data/misc/net(/.*)? u:object_r:net_data_file:s0 /data/misc/shared_relro(/.*)? u:object_r:shared_relro_file:s0 /data/misc/sms(/.*)? u:object_r:radio_data_file:s0 /data/misc/systemkeys(/.*)? u:object_r:systemkeys_data_file:s0 /data/misc/user(/.*)? u:object_r:misc_user_data_file:s0 /data/misc/vpn(/.*)? u:object_r:vpn_data_file:s0 /data/misc/wifi(/.*)? u:object_r:wifi_data_file:s0 /data/misc/wifi/sockets(/.*)? u:object_r:wpa_socket:s0 /data/misc/wifi/sockets/wpa_ctrl.* u:object_r:system_wpa_socket:s0 /data/misc/wifi/hostapd(/.*)? u:object_r:wpa_socket:s0 /data/misc/zoneinfo(/.*)? u:object_r:zoneinfo_data_file:s0 /data/misc/vold(/.*)? u:object_r:vold_data_file:s0 /data/misc/perfprofd(/.*)? u:object_r:perfprofd_data_file:s0 /data/system/heapdump(/.*)? u:object_r:heapdump_data_file:s0 # Fingerprint data /data/system/users/[0-9]+/fpdata(/.*)? u:object_r:fingerprintd_data_file:s0 # Bootchart data /data/bootchart(/.*)? u:object_r:bootchart_data_file:s0 ############################# # Expanded data files # /mnt/expand(/.*)? u:object_r:mnt_expand_file:s0 /mnt/expand/[^/]+(/.*)? u:object_r:system_data_file:s0 /mnt/expand/[^/]+/app(/.*)? u:object_r:apk_data_file:s0 /mnt/expand/[^/]+/app/[^/]+/oat(/.*)? u:object_r:dalvikcache_data_file:s0 /mnt/expand/[^/]+/app/vmdl[^/]+\.tmp(/.*)? u:object_r:apk_tmp_file:s0 /mnt/expand/[^/]+/app/vmdl[^/]+\.tmp/oat(/.*)? u:object_r:dalvikcache_data_file:s0 /mnt/expand/[^/]+/local/tmp(/.*)? u:object_r:shell_data_file:s0 /mnt/expand/[^/]+/media(/.*)? u:object_r:media_rw_data_file:s0 /mnt/expand/[^/]+/misc/vold(/.*)? u:object_r:vold_data_file:s0 # coredump directory for userdebug/eng devices /cores(/.*)? u:object_r:coredump_file:s0 # Wallpaper file for other users /data/system/users/[0-9]+/wallpaper u:object_r:wallpaper_file:s0 ############################# # efs files # /efs(/.*)? u:object_r:efs_file:s0 ############################# # Cache files # /cache(/.*)? u:object_r:cache_file:s0 /cache/.*\.data u:object_r:cache_backup_file:s0 /cache/.*\.restore u:object_r:cache_backup_file:s0 # LocalTransport (backup) uses this directory /cache/backup(/.*)? u:object_r:cache_backup_file:s0 ############################# # sysfs files # /sys/devices/platform/nfc-power/nfc_power -- u:object_r:sysfs_nfc_power_writable:s0 /sys/devices/system/cpu(/.*)? u:object_r:sysfs_devices_system_cpu:s0 /sys/power/wake_lock -- u:object_r:sysfs_wake_lock:s0 /sys/power/wake_unlock -- u:object_r:sysfs_wake_lock:s0 /sys/kernel/uevent_helper -- u:object_r:usermodehelper:s0 /sys/module/lowmemorykiller(/.*)? -- u:object_r:sysfs_lowmemorykiller:s0 ############################# # asec containers /mnt/asec(/.*)? u:object_r:asec_apk_file:s0 /mnt/asec/[^/]+/[^/]+\.zip u:object_r:asec_public_file:s0 /mnt/asec/[^/]+/lib(/.*)? u:object_r:asec_public_file:s0 /data/app-asec(/.*)? u:object_r:asec_image_file:s0 ############################# # external storage /mnt/media_rw(/.*)? u:object_r:mnt_media_rw_file:s0 /mnt/user(/.*)? u:object_r:mnt_user_file:s0 /mnt/runtime(/.*)? u:object_r:storage_file:s0 /storage(/.*)? u:object_r:storage_file:s0 ================================================ FILE: VirtualPosition/vp_Framework/sepolicy/service.te ================================================ type bluetooth_service, service_manager_type; type default_android_service, service_manager_type; type drmserver_service, service_manager_type; type gatekeeper_service, app_api_service, service_manager_type; type fingerprintd_service, service_manager_type; type healthd_service, service_manager_type; type inputflinger_service, service_manager_type; type keystore_service, service_manager_type; type mediaserver_service, service_manager_type; type nfc_service, service_manager_type; type radio_service, service_manager_type; type surfaceflinger_service, service_manager_type; type system_app_service, service_manager_type; # system_server_services broken down type accessibility_service, app_api_service, system_server_service, service_manager_type; type account_service, app_api_service, system_server_service, service_manager_type; type activity_service, app_api_service, system_server_service, service_manager_type; type alarm_service, app_api_service, system_server_service, service_manager_type; type appops_service, app_api_service, system_server_service, service_manager_type; type appwidget_service, app_api_service, system_server_service, service_manager_type; type assetatlas_service, app_api_service, system_server_service, service_manager_type; type audio_service, app_api_service, system_server_service, service_manager_type; type backup_service, app_api_service, system_server_service, service_manager_type; type batterystats_service, app_api_service, system_server_service, service_manager_type; type battery_service, system_server_service, service_manager_type; type bluetooth_manager_service, system_api_service, system_server_service, service_manager_type; type cameraproxy_service, system_server_service, service_manager_type; type clipboard_service, app_api_service, system_server_service, service_manager_type; type IProxyService_service, system_api_service, system_server_service, service_manager_type; type commontime_management_service, system_server_service, service_manager_type; type connectivity_service, app_api_service, system_server_service, service_manager_type; type consumer_ir_service, app_api_service, system_server_service, service_manager_type; type content_service, app_api_service, system_server_service, service_manager_type; type country_detector_service, system_api_service, system_server_service, service_manager_type; type cpuinfo_service, system_api_service, system_server_service, service_manager_type; type dbinfo_service, system_api_service, system_server_service, service_manager_type; type device_policy_service, app_api_service, system_server_service, service_manager_type; type deviceidle_service, system_api_service, system_server_service, service_manager_type; type devicestoragemonitor_service, system_server_service, service_manager_type; type diskstats_service, system_api_service, system_server_service, service_manager_type; type display_service, app_api_service, system_server_service, service_manager_type; type DockObserver_service, system_server_service, service_manager_type; type dreams_service, system_api_service, system_server_service, service_manager_type; type dropbox_service, app_api_service, system_server_service, service_manager_type; type ethernet_service, app_api_service, system_server_service, service_manager_type; type fingerprint_service, app_api_service, system_server_service, service_manager_type; type gfxinfo_service, system_api_service, system_server_service, service_manager_type; type graphicsstats_service, app_api_service, system_server_service, service_manager_type; type hardware_service, system_server_service, service_manager_type; type hdmi_control_service, system_api_service, system_server_service, service_manager_type; type input_method_service, app_api_service, system_server_service, service_manager_type; type input_service, app_api_service, system_server_service, service_manager_type; type imms_service, app_api_service, system_server_service, service_manager_type; type jobscheduler_service, app_api_service, system_server_service, service_manager_type; type launcherapps_service, app_api_service, system_server_service, service_manager_type; type location_service, app_api_service, system_server_service, service_manager_type; type lock_settings_service, system_api_service, system_server_service, service_manager_type; type media_projection_service, app_api_service, system_server_service, service_manager_type; type media_router_service, app_api_service, system_server_service, service_manager_type; type media_session_service, app_api_service, system_server_service, service_manager_type; type meminfo_service, system_api_service, system_server_service, service_manager_type; type midi_service, app_api_service, system_server_service, service_manager_type; type mount_service, app_api_service, system_server_service, service_manager_type; type netpolicy_service, app_api_service, system_server_service, service_manager_type; type netstats_service, system_api_service, system_server_service, service_manager_type; type network_management_service, system_api_service, system_server_service, service_manager_type; type network_score_service, system_api_service, system_server_service, service_manager_type; type notification_service, app_api_service, system_server_service, service_manager_type; type package_service, app_api_service, system_server_service, service_manager_type; type permission_service, app_api_service, system_server_service, service_manager_type; type persistent_data_block_service, system_api_service, system_server_service, service_manager_type; type power_service, app_api_service, system_server_service, service_manager_type; type print_service, app_api_service, system_server_service, service_manager_type; type processinfo_service, system_server_service, service_manager_type; type procstats_service, app_api_service, system_server_service, service_manager_type; type registry_service, app_api_service, system_server_service, service_manager_type; type restrictions_service, app_api_service, system_server_service, service_manager_type; type rttmanager_service, app_api_service, system_server_service, service_manager_type; type samplingprofiler_service, system_server_service, service_manager_type; type scheduling_policy_service, system_server_service, service_manager_type; type search_service, app_api_service, system_server_service, service_manager_type; type sensorservice_service, app_api_service, system_server_service, service_manager_type; type serial_service, system_api_service, system_server_service, service_manager_type; type servicediscovery_service, app_api_service, system_server_service, service_manager_type; type statusbar_service, app_api_service, system_server_service, service_manager_type; type task_service, system_server_service, service_manager_type; type textservices_service, app_api_service, system_server_service, service_manager_type; type telecom_service, app_api_service, system_server_service, service_manager_type; type trust_service, system_api_service, system_server_service, service_manager_type; type tv_input_service, app_api_service, system_server_service, service_manager_type; type uimode_service, app_api_service, system_server_service, service_manager_type; type updatelock_service, system_api_service, system_server_service, service_manager_type; type usagestats_service, app_api_service, system_server_service, service_manager_type; type usb_service, app_api_service, system_server_service, service_manager_type; type user_service, app_api_service, system_server_service, service_manager_type; type vibrator_service, app_api_service, system_server_service, service_manager_type; type voiceinteraction_service, app_api_service, system_server_service, service_manager_type; type wallpaper_service, app_api_service, system_server_service, service_manager_type; type webviewupdate_service, system_api_service, system_server_service, service_manager_type; type wifip2p_service, app_api_service, system_server_service, service_manager_type; type wifiscanner_service, system_api_service, system_server_service, service_manager_type; type wifi_service, app_api_service, system_server_service, service_manager_type; type window_service, system_api_service, system_server_service, service_manager_type; # add by aggresss type virtualposition_service, system_api_service, system_server_service, service_manager_type; ================================================ FILE: VirtualPosition/vp_Framework/sepolicy/service_contexts ================================================ accessibility u:object_r:accessibility_service:s0 account u:object_r:account_service:s0 activity u:object_r:activity_service:s0 alarm u:object_r:alarm_service:s0 android.security.keystore u:object_r:keystore_service:s0 android.service.gatekeeper.IGateKeeperService u:object_r:gatekeeper_service:s0 appops u:object_r:appops_service:s0 appwidget u:object_r:appwidget_service:s0 assetatlas u:object_r:assetatlas_service:s0 audio u:object_r:audio_service:s0 backup u:object_r:backup_service:s0 batteryproperties u:object_r:healthd_service:s0 batterypropreg u:object_r:healthd_service:s0 batterystats u:object_r:batterystats_service:s0 battery u:object_r:battery_service:s0 bluetooth_manager u:object_r:bluetooth_manager_service:s0 bluetooth u:object_r:bluetooth_service:s0 carrier_config u:object_r:radio_service:s0 clipboard u:object_r:clipboard_service:s0 com.android.net.IProxyService u:object_r:IProxyService_service:s0 commontime_management u:object_r:commontime_management_service:s0 common_time.clock u:object_r:mediaserver_service:s0 common_time.config u:object_r:mediaserver_service:s0 connectivity u:object_r:connectivity_service:s0 consumer_ir u:object_r:consumer_ir_service:s0 content u:object_r:content_service:s0 country_detector u:object_r:country_detector_service:s0 cpuinfo u:object_r:cpuinfo_service:s0 dbinfo u:object_r:dbinfo_service:s0 device_policy u:object_r:device_policy_service:s0 deviceidle u:object_r:deviceidle_service:s0 devicestoragemonitor u:object_r:devicestoragemonitor_service:s0 diskstats u:object_r:diskstats_service:s0 display.qservice u:object_r:surfaceflinger_service:s0 display u:object_r:display_service:s0 DockObserver u:object_r:DockObserver_service:s0 dreams u:object_r:dreams_service:s0 drm.drmManager u:object_r:drmserver_service:s0 dropbox u:object_r:dropbox_service:s0 ethernet u:object_r:ethernet_service:s0 fingerprint u:object_r:fingerprint_service:s0 android.hardware.fingerprint.IFingerprintDaemon u:object_r:fingerprintd_service:s0 gfxinfo u:object_r:gfxinfo_service:s0 graphicsstats u:object_r:graphicsstats_service:s0 hardware u:object_r:hardware_service:s0 hdmi_control u:object_r:hdmi_control_service:s0 inputflinger u:object_r:inputflinger_service:s0 input_method u:object_r:input_method_service:s0 input u:object_r:input_service:s0 iphonesubinfo_msim u:object_r:radio_service:s0 iphonesubinfo2 u:object_r:radio_service:s0 iphonesubinfo u:object_r:radio_service:s0 ims u:object_r:radio_service:s0 imms u:object_r:imms_service:s0 isms_msim u:object_r:radio_service:s0 isms2 u:object_r:radio_service:s0 isms u:object_r:radio_service:s0 isub u:object_r:radio_service:s0 jobscheduler u:object_r:jobscheduler_service:s0 launcherapps u:object_r:launcherapps_service:s0 location u:object_r:location_service:s0 lock_settings u:object_r:lock_settings_service:s0 media.audio_flinger u:object_r:mediaserver_service:s0 media.audio_policy u:object_r:mediaserver_service:s0 media.camera u:object_r:mediaserver_service:s0 media.camera.proxy u:object_r:cameraproxy_service:s0 media.log u:object_r:mediaserver_service:s0 media.player u:object_r:mediaserver_service:s0 media.resource_manager u:object_r:mediaserver_service:s0 media.radio u:object_r:mediaserver_service:s0 media.sound_trigger_hw u:object_r:mediaserver_service:s0 media_projection u:object_r:media_projection_service:s0 media_router u:object_r:media_router_service:s0 media_session u:object_r:media_session_service:s0 meminfo u:object_r:meminfo_service:s0 midi u:object_r:midi_service:s0 mount u:object_r:mount_service:s0 netpolicy u:object_r:netpolicy_service:s0 netstats u:object_r:netstats_service:s0 network_management u:object_r:network_management_service:s0 network_score u:object_r:network_score_service:s0 nfc u:object_r:nfc_service:s0 notification u:object_r:notification_service:s0 package u:object_r:package_service:s0 permission u:object_r:permission_service:s0 persistent_data_block u:object_r:persistent_data_block_service:s0 phone_msim u:object_r:radio_service:s0 phone1 u:object_r:radio_service:s0 phone2 u:object_r:radio_service:s0 phone u:object_r:radio_service:s0 power u:object_r:power_service:s0 print u:object_r:print_service:s0 processinfo u:object_r:processinfo_service:s0 procstats u:object_r:procstats_service:s0 radio.phonesubinfo u:object_r:radio_service:s0 radio.phone u:object_r:radio_service:s0 radio.sms u:object_r:radio_service:s0 restrictions u:object_r:restrictions_service:s0 rttmanager u:object_r:rttmanager_service:s0 samplingprofiler u:object_r:samplingprofiler_service:s0 scheduling_policy u:object_r:scheduling_policy_service:s0 search u:object_r:search_service:s0 sensorservice u:object_r:sensorservice_service:s0 serial u:object_r:serial_service:s0 servicediscovery u:object_r:servicediscovery_service:s0 simphonebook_msim u:object_r:radio_service:s0 simphonebook2 u:object_r:radio_service:s0 simphonebook u:object_r:radio_service:s0 sip u:object_r:radio_service:s0 statusbar u:object_r:statusbar_service:s0 SurfaceFlinger u:object_r:surfaceflinger_service:s0 task u:object_r:task_service:s0 telecom u:object_r:telecom_service:s0 telephony.registry u:object_r:registry_service:s0 textservices u:object_r:textservices_service:s0 trust u:object_r:trust_service:s0 tv_input u:object_r:tv_input_service:s0 uimode u:object_r:uimode_service:s0 updatelock u:object_r:updatelock_service:s0 usagestats u:object_r:usagestats_service:s0 usb u:object_r:usb_service:s0 user u:object_r:user_service:s0 vibrator u:object_r:vibrator_service:s0 voiceinteraction u:object_r:voiceinteraction_service:s0 wallpaper u:object_r:wallpaper_service:s0 webviewupdate u:object_r:webviewupdate_service:s0 wifip2p u:object_r:wifip2p_service:s0 wifiscanner u:object_r:wifiscanner_service:s0 wifi u:object_r:wifi_service:s0 window u:object_r:window_service:s0 # add by aggresss virtualposition u:object_r:virtualposition_service:s0 * u:object_r:default_android_service:s0 ================================================ FILE: VirtualPosition/vp_Framework/sepolicy/system_server.te ================================================ # # System Server aka system_server spawned by zygote. # Most of the framework services run in this process. # type system_server, domain, mlstrustedsubject; # Define a type for tmpfs-backed ashmem regions. tmpfs_domain(system_server) # Dalvik Compiler JIT Mapping. allow system_server self:process execmem; allow system_server ashmem_device:chr_file execute; allow system_server system_server_tmpfs:file execute; # For art. allow system_server dalvikcache_data_file:file execute; allow system_server dalvikcache_data_file:dir r_dir_perms; # /data/resource-cache allow system_server resourcecache_data_file:file r_file_perms; allow system_server resourcecache_data_file:dir r_dir_perms; # ptrace to processes in the same domain for debugging crashes. allow system_server self:process ptrace; # Child of the zygote. allow system_server zygote:fd use; allow system_server zygote:process sigchld; allow system_server zygote_tmpfs:file read; # May kill zygote on crashes. allow system_server zygote:process sigkill; # Read /system/bin/app_process. allow system_server zygote_exec:file r_file_perms; # Needed to close the zygote socket, which involves getopt / getattr allow system_server zygote:unix_stream_socket { getopt getattr }; # system server gets network and bluetooth permissions. net_domain(system_server) bluetooth_domain(system_server) # These are the capabilities assigned by the zygote to the # system server. allow system_server self:capability { kill net_admin net_bind_service net_broadcast net_raw sys_boot sys_nice sys_resource sys_time sys_tty_config }; wakelock_use(system_server) # Triggered by /proc/pid accesses, not allowed. dontaudit system_server self:capability sys_ptrace; # Trigger module auto-load. allow system_server kernel:system module_request; # Use netlink uevent sockets. allow system_server self:netlink_kobject_uevent_socket create_socket_perms; # Use generic netlink sockets. allow system_server self:netlink_socket create_socket_perms; # Set and get routes directly via netlink. allow system_server self:netlink_route_socket nlmsg_write; # Kill apps. allow system_server appdomain:process { sigkill signal }; # Set scheduling info for apps. allow system_server appdomain:process { getsched setsched }; allow system_server mediaserver:process { getsched setsched }; # Read /proc/pid data for all domains. This is used by ProcessCpuTracker # within system_server to keep track of memory and CPU usage for # all processes on the device. r_dir_file(system_server, domain) # Read/Write to /proc/net/xt_qtaguid/ctrl and and /dev/xt_qtaguid. allow system_server qtaguid_proc:file rw_file_perms; allow system_server qtaguid_device:chr_file rw_file_perms; # Read /proc/uid_cputime/show_uid_stat. allow system_server proc_uid_cputime_showstat:file r_file_perms; # Write /proc/uid_cputime/remove_uid_range. allow system_server proc_uid_cputime_removeuid:file { w_file_perms getattr }; # Write to /proc/sysrq-trigger. allow system_server proc_sysrq:file rw_file_perms; # Read /sys/kernel/debug/wakeup_sources. allow system_server debugfs:file r_file_perms; # The DhcpClient and WifiWatchdog use packet_sockets allow system_server self:packet_socket create_socket_perms; # NetworkDiagnostics requires explicit bind() calls to ping sockets. These aren't actually the same # as raw sockets, but the kernel doesn't yet distinguish between the two. allow system_server node:rawip_socket node_bind; # 3rd party VPN clients require a tun_socket to be created allow system_server self:tun_socket create_socket_perms; # Notify init of death. allow system_server init:process sigchld; # Talk to init and various daemons via sockets. unix_socket_connect(system_server, installd, installd) unix_socket_connect(system_server, lmkd, lmkd) unix_socket_connect(system_server, mtpd, mtp) unix_socket_connect(system_server, netd, netd) unix_socket_connect(system_server, vold, vold) unix_socket_connect(system_server, zygote, zygote) unix_socket_connect(system_server, gps, gpsd) unix_socket_connect(system_server, racoon, racoon) unix_socket_send(system_server, wpa, wpa) # Communicate over a socket created by surfaceflinger. allow system_server surfaceflinger:unix_stream_socket { read write setopt }; # Perform Binder IPC. binder_use(system_server) binder_call(system_server, binderservicedomain) binder_call(system_server, gatekeeperd) binder_call(system_server, fingerprintd) binder_call(system_server, appdomain) binder_call(system_server, bootanim) binder_call(system_server, dumpstate) binder_service(system_server) # Ask debuggerd to dump backtraces for native stacks of interest. allow system_server { mediaserver sdcardd surfaceflinger inputflinger }:debuggerd dump_backtrace; # Read /proc/pid files for dumping stack traces of native processes. r_dir_file(system_server, mediaserver) r_dir_file(system_server, sdcardd) r_dir_file(system_server, surfaceflinger) r_dir_file(system_server, inputflinger) # Use sockets received over binder from various services. allow system_server mediaserver:tcp_socket rw_socket_perms; allow system_server mediaserver:udp_socket rw_socket_perms; # Check SELinux permissions. selinux_check_access(system_server) # XXX Label sysfs files with a specific type? allow system_server sysfs:file rw_file_perms; allow system_server sysfs_nfc_power_writable:file rw_file_perms; allow system_server sysfs_devices_system_cpu:file w_file_perms; # Access devices. allow system_server device:dir r_dir_perms; allow system_server mdns_socket:sock_file rw_file_perms; allow system_server alarm_device:chr_file rw_file_perms; allow system_server gpu_device:chr_file rw_file_perms; allow system_server iio_device:chr_file rw_file_perms; allow system_server input_device:dir r_dir_perms; allow system_server input_device:chr_file rw_file_perms; allow system_server radio_device:chr_file r_file_perms; allow system_server tty_device:chr_file rw_file_perms; allow system_server usbaccessory_device:chr_file rw_file_perms; allow system_server video_device:dir r_dir_perms; allow system_server video_device:chr_file rw_file_perms; allow system_server adbd_socket:sock_file rw_file_perms; allow system_server rtc_device:chr_file rw_file_perms; allow system_server audio_device:dir r_dir_perms; # write access needed for MIDI allow system_server audio_device:chr_file rw_file_perms; # tun device used for 3rd party vpn apps allow system_server tun_device:chr_file rw_file_perms; # Manage system data files. allow system_server system_data_file:dir create_dir_perms; allow system_server system_data_file:notdevfile_class_set create_file_perms; allow system_server keychain_data_file:dir create_dir_perms; allow system_server keychain_data_file:file create_file_perms; # Manage /data/app. allow system_server apk_data_file:dir create_dir_perms; allow system_server apk_data_file:file { create_file_perms link }; allow system_server apk_tmp_file:dir create_dir_perms; allow system_server apk_tmp_file:file create_file_perms; # Manage /data/app-private. allow system_server apk_private_data_file:dir create_dir_perms; allow system_server apk_private_data_file:file create_file_perms; allow system_server apk_private_tmp_file:dir create_dir_perms; allow system_server apk_private_tmp_file:file create_file_perms; # Manage files within asec containers. allow system_server asec_apk_file:dir create_dir_perms; allow system_server asec_apk_file:file create_file_perms; allow system_server asec_public_file:file create_file_perms; # Manage /data/anr. allow system_server anr_data_file:dir create_dir_perms; allow system_server anr_data_file:file create_file_perms; # Manage /data/backup. allow system_server backup_data_file:dir create_dir_perms; allow system_server backup_data_file:file create_file_perms; # Read from /data/dalvik-cache/profiles allow system_server dalvikcache_profiles_data_file:dir rw_dir_perms; allow system_server dalvikcache_profiles_data_file:file create_file_perms; # Write to /data/system/heapdump allow system_server heapdump_data_file:dir rw_dir_perms; allow system_server heapdump_data_file:file create_file_perms; # Manage /data/misc/adb. allow system_server adb_keys_file:dir create_dir_perms; allow system_server adb_keys_file:file create_file_perms; # Manage /data/misc/sms. # TODO: Split into a separate type? allow system_server radio_data_file:dir create_dir_perms; allow system_server radio_data_file:file create_file_perms; # Manage /data/misc/systemkeys. allow system_server systemkeys_data_file:dir create_dir_perms; allow system_server systemkeys_data_file:file create_file_perms; # Access /data/tombstones. allow system_server tombstone_data_file:dir r_dir_perms; allow system_server tombstone_data_file:file r_file_perms; # Manage /data/misc/vpn. allow system_server vpn_data_file:dir create_dir_perms; allow system_server vpn_data_file:file create_file_perms; # Manage /data/misc/wifi. allow system_server wifi_data_file:dir create_dir_perms; allow system_server wifi_data_file:file create_file_perms; # Manage /data/misc/zoneinfo. allow system_server zoneinfo_data_file:dir create_dir_perms; allow system_server zoneinfo_data_file:file create_file_perms; # Walk /data/data subdirectories. # Types extracted from seapp_contexts type= fields. allow system_server { system_app_data_file bluetooth_data_file nfc_data_file radio_data_file shell_data_file app_data_file }:dir { getattr read search }; # Also permit for unlabeled /data/data subdirectories and # for unlabeled asec containers on upgrades from 4.2. allow system_server unlabeled:dir r_dir_perms; # Read pkg.apk file before it has been relabeled by vold. allow system_server unlabeled:file r_file_perms; # Populate com.android.providers.settings/databases/settings.db. allow system_server system_app_data_file:dir create_dir_perms; allow system_server system_app_data_file:file create_file_perms; # Receive and use open app data files passed over binder IPC. # Types extracted from seapp_contexts type= fields. allow system_server { system_app_data_file bluetooth_data_file nfc_data_file radio_data_file shell_data_file app_data_file }:file { getattr read write }; # Receive and use open /data/media files passed over binder IPC. allow system_server media_rw_data_file:file { getattr read write }; # Read /file_contexts and /data/security/file_contexts security_access_policy(system_server) # Relabel apk files. allow system_server { apk_tmp_file apk_private_tmp_file }:{ dir file } { relabelfrom relabelto }; allow system_server { apk_data_file apk_private_data_file }:{ dir file } { relabelfrom relabelto }; # Relabel wallpaper. allow system_server system_data_file:file relabelfrom; allow system_server wallpaper_file:file relabelto; allow system_server wallpaper_file:file { rw_file_perms unlink }; # Relabel /data/anr. allow system_server system_data_file:dir relabelfrom; allow system_server anr_data_file:dir relabelto; # Property Service write set_prop(system_server, system_prop) set_prop(system_server, dhcp_prop) set_prop(system_server, net_radio_prop) set_prop(system_server, system_radio_prop) set_prop(system_server, debug_prop) set_prop(system_server, powerctl_prop) set_prop(system_server, fingerprint_prop) # ctl interface allow system_server ctl_bootanim_prop:property_service set; # Use open file provided by bootanim. allow system_server bootanim:fd use; set_prop(system_server, ctl_default_prop) set_prop(system_server, ctl_dhcp_pan_prop) set_prop(system_server, ctl_bugreport_prop) # Create a socket for receiving info from wpa. type_transition system_server wifi_data_file:sock_file system_wpa_socket; type_transition system_server wpa_socket:sock_file system_wpa_socket; allow system_server wpa_socket:dir rw_dir_perms; allow system_server system_wpa_socket:sock_file create_file_perms; # Remove sockets created by wpa_supplicant allow system_server wpa_socket:sock_file unlink; # Create a socket for connections from debuggerd. type_transition system_server system_data_file:sock_file system_ndebug_socket "ndebugsocket"; allow system_server system_ndebug_socket:sock_file create_file_perms; # Manage cache files. allow system_server cache_file:dir { relabelfrom create_dir_perms }; allow system_server cache_file:file { relabelfrom create_file_perms }; allow system_server cache_file:fifo_file create_file_perms; # Run system programs, e.g. dexopt. allow system_server system_file:file x_file_perms; # LocationManager(e.g, GPS) needs to read and write # to uart driver and ctrl proc entry allow system_server gps_device:chr_file rw_file_perms; allow system_server gps_control:file rw_file_perms; # Allow system_server to use app-created sockets and pipes. allow system_server appdomain:{ tcp_socket udp_socket } { getattr getopt setopt read write shutdown }; allow system_server appdomain:{ fifo_file unix_stream_socket } { getattr read write }; # Allow abstract socket connection allow system_server rild:unix_stream_socket connectto; # BackupManagerService lets PMS create a data backup file allow system_server cache_backup_file:file create_file_perms; # Relabel /data/backup allow system_server backup_data_file:dir { relabelto relabelfrom }; # Relabel /cache/.*\.{data|restore} allow system_server cache_backup_file:file { relabelto relabelfrom }; # LocalTransport creates and relabels /cache/backup allow system_server cache_backup_file:dir { relabelto relabelfrom create_dir_perms }; # Allow system to talk to usb device allow system_server usb_device:chr_file rw_file_perms; allow system_server usb_device:dir r_dir_perms; # Allow system to talk to sensors allow system_server sensors_device:chr_file rw_file_perms; # Read from HW RNG (needed by EntropyMixer). allow system_server hw_random_device:chr_file r_file_perms; # Read and delete files under /dev/fscklogs. r_dir_file(system_server, fscklogs) allow system_server fscklogs:dir { write remove_name }; allow system_server fscklogs:file unlink; # For SELinuxPolicyInstallReceiver selinux_manage_policy(system_server) # logd access, system_server inherit logd write socket # (urge is to deprecate this long term) allow system_server zygote:unix_dgram_socket write; # Read from log daemon. read_logd(system_server) # Be consistent with DAC permissions. Allow system_server to write to # /sys/module/lowmemorykiller/parameters/adj # /sys/module/lowmemorykiller/parameters/minfree allow system_server sysfs_lowmemorykiller:file { getattr w_file_perms }; # Read /sys/fs/pstore/console-ramoops # Don't worry about overly broad permissions for now, as there's # only one file in /sys/fs/pstore allow system_server pstorefs:dir r_dir_perms; allow system_server pstorefs:file r_file_perms; allow system_server drmserver_service:service_manager find; allow system_server healthd_service:service_manager find; allow system_server keystore_service:service_manager find; allow system_server gatekeeper_service:service_manager find; allow system_server fingerprintd_service:service_manager find; allow system_server mediaserver_service:service_manager find; allow system_server nfc_service:service_manager find; allow system_server radio_service:service_manager find; allow system_server system_server_service:service_manager { add find }; allow system_server surfaceflinger_service:service_manager find; allow system_server keystore:keystore_key { get_state get insert delete exist list reset password lock unlock is_empty sign verify grant duplicate clear_uid add_auth user_changed }; # Allow system server to search and write to the persistent factory reset # protection partition. This block device does not get wiped in a factory reset. allow system_server block_device:dir search; allow system_server frp_block_device:blk_file rw_file_perms; # Clean up old cgroups allow system_server cgroup:dir { remove_name rmdir }; # /oem access r_dir_file(system_server, oemfs) # Allow resolving per-user storage symlinks allow system_server { mnt_user_file storage_file }:dir { getattr search }; allow system_server { mnt_user_file storage_file }:lnk_file { getattr read }; # Allow statfs() on storage devices, which happens fast enough that # we shouldn't be killed during unsafe removal allow system_server sdcard_type:dir { getattr search }; # Traverse into expanded storage allow system_server mnt_expand_file:dir r_dir_perms; # Allow system process to relabel the fingerprint directory after mkdir # and delete the directory and files when no longer needed allow system_server fingerprintd_data_file:dir { r_dir_perms remove_name rmdir relabelto write }; allow system_server fingerprintd_data_file:file { getattr unlink }; # For configuring sdcardfs allow system_server configfs:dir { create_dir_perms }; allow system_server configfs:file { getattr open unlink write }; ### ### Neverallow rules ### ### system_server should NEVER do any of this # Do not allow opening files from external storage as unsafe ejection # could cause the kernel to kill the system_server. neverallow system_server sdcard_type:dir { open read write }; neverallow system_server sdcard_type:file rw_file_perms; # system server should never be opening zygote spawned app data # files directly. Rather, they should always be passed via a # file descriptor. # Types extracted from seapp_contexts type= fields, excluding # those types that system_server needs to open directly. neverallow system_server { bluetooth_data_file nfc_data_file shell_data_file app_data_file }:file open; # system_server should never be executing dex2oat. This is either # a bug (for example, bug 16317188), or represents an attempt by # system server to dynamically load a dex file, something we do not # want to allow. ifelse(shipping_build, `true', `neverallow system_server dex2oat_exec:file no_x_file_perms;' , ) # The only block device system_server should be accessing is # the frp_block_device. This helps avoid a system_server to root # escalation by writing to raw block devices. neverallow system_server { dev_type -frp_block_device }:blk_file no_rw_file_perms; # add by aggresss allow system_server vp_device:chr_file rw_file_perms; ================================================ FILE: VirtualPosition/vp_HAL/vp/Android.mk ================================================ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_PRELINK_MODULE := false LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw LOCAL_SHARED_LIBRARIES := liblog LOCAL_SRC_FILES := vp.c LOCAL_MODULE := vp.default include $(BUILD_SHARED_LIBRARY) ================================================ FILE: VirtualPosition/vp_HAL/vp/vp.c ================================================ #define LOG_TAG "VpStub" #include #include #include #include #include #include #define DEVICE_NAME "/dev/vp" #define MODULE_NAME "Vp" #define MODULE_AUTHOR "aggresss@163.com" /*设备打开和关闭接口*/ static int vp_device_open(const struct hw_module_t* module, const char* name, struct hw_device_t** device); static int vp_device_close(struct hw_device_t* device); /*设备访问接口*/ static int vp_set_val(struct vp_device_t* dev, VirtualPosition val); static int vp_get_val(struct vp_device_t* dev, VirtualPosition* val); /*模块方法表*/ static struct hw_module_methods_t vp_module_methods = { open: vp_device_open }; /*模块实例变量*/ struct vp_module_t HAL_MODULE_INFO_SYM = { common: { tag: HARDWARE_MODULE_TAG, version_major: 1, version_minor: 0, id: VP_HARDWARE_MODULE_ID, name: MODULE_NAME, author: MODULE_AUTHOR, methods: &vp_module_methods, } }; static int vp_device_open(const struct hw_module_t* module, const char* name, struct hw_device_t** device) { struct vp_device_t* dev;dev = (struct vp_device_t*)malloc(sizeof(struct vp_device_t)); if(!dev) { ALOGE("Vp Stub: failed to alloc space"); return -EFAULT; } memset(dev, 0, sizeof(struct vp_device_t)); dev->common.tag = HARDWARE_DEVICE_TAG; dev->common.version = 0; dev->common.module = (hw_module_t*)module; dev->common.close = vp_device_close; dev->set_val = vp_set_val;dev->get_val = vp_get_val; if((dev->fd = open(DEVICE_NAME, O_RDWR)) == -1) { ALOGE("Vp Stub: failed to open /dev/vp -- %s.", strerror(errno));free(dev); return -EFAULT; } *device = &(dev->common); ALOGI("Vp Stub: open /dev/vp successfully."); return 0; } static int vp_device_close(struct hw_device_t* device) { struct vp_device_t* vp_device = (struct vp_device_t*)device; if(vp_device) { close(vp_device->fd); free(vp_device); } return 0; } static int vp_set_val(struct vp_device_t* dev, VirtualPosition val) { ALOGI("Vp Stub: set value %d to device.", val); write(dev->fd, &val, sizeof(val)); return 0; } static int vp_get_val(struct vp_device_t* dev, VirtualPosition* val) { if(!val) { ALOGE("Vp Stub: error val pointer"); return -EFAULT; } read(dev->fd, val, sizeof(*val)); ALOGI("Vp Stub: get value %d from device", *val); return 0; } ================================================ FILE: VirtualPosition/vp_HAL/vp.h ================================================ #ifndef ANDROID_VP_INTERFACE_H #define ANDROID_VP_INTERFACE_H #include __BEGIN_DECLS /*定义模块ID*/ #define VP_HARDWARE_MODULE_ID "vp" //typedef enum{false, true} bool; /*define virtual position structrue*/ typedef struct { int toggle; double virtual_latitude; double virtual_longitude; } VirtualPosition; /*硬件模块结构体*/ struct vp_module_t { struct hw_module_t common; }; /*硬件接口结构体*/ struct vp_device_t { struct hw_device_t common; int fd; int (*set_val)(struct vp_device_t* dev, VirtualPosition val); int (*get_val)(struct vp_device_t* dev, VirtualPosition* val); }; __END_DECLS #endif ================================================ FILE: VirtualPosition/vp_JNI/Android.mk ================================================ # This file is included by the top level services directory to collect source # files LOCAL_REL_DIR := core/jni LOCAL_CFLAGS += -Wall -Werror -Wno-unused-parameter ifneq ($(ENABLE_CPUSETS),) ifneq ($(ENABLE_SCHED_BOOST),) LOCAL_CFLAGS += -DUSE_SCHED_BOOST endif endif LOCAL_SRC_FILES += \ $(LOCAL_REL_DIR)/com_android_server_AlarmManagerService.cpp \ $(LOCAL_REL_DIR)/com_android_server_am_BatteryStatsService.cpp \ $(LOCAL_REL_DIR)/com_android_server_am_ActivityManagerService.cpp \ $(LOCAL_REL_DIR)/com_android_server_AssetAtlasService.cpp \ $(LOCAL_REL_DIR)/com_android_server_connectivity_Vpn.cpp \ $(LOCAL_REL_DIR)/com_android_server_ConsumerIrService.cpp \ $(LOCAL_REL_DIR)/com_android_server_hdmi_HdmiCecController.cpp \ $(LOCAL_REL_DIR)/com_android_server_input_InputApplicationHandle.cpp \ $(LOCAL_REL_DIR)/com_android_server_input_InputManagerService.cpp \ $(LOCAL_REL_DIR)/com_android_server_input_InputWindowHandle.cpp \ $(LOCAL_REL_DIR)/com_android_server_lights_LightsService.cpp \ $(LOCAL_REL_DIR)/com_android_server_location_GpsLocationProvider.cpp \ $(LOCAL_REL_DIR)/com_android_server_location_FlpHardwareProvider.cpp \ $(LOCAL_REL_DIR)/com_android_server_power_PowerManagerService.cpp \ $(LOCAL_REL_DIR)/com_android_server_SerialService.cpp \ $(LOCAL_REL_DIR)/com_android_server_SystemServer.cpp \ $(LOCAL_REL_DIR)/com_android_server_tv_TvInputHal.cpp \ $(LOCAL_REL_DIR)/com_android_server_UsbDeviceManager.cpp \ $(LOCAL_REL_DIR)/com_android_server_UsbMidiDevice.cpp \ $(LOCAL_REL_DIR)/com_android_server_UsbHostManager.cpp \ $(LOCAL_REL_DIR)/com_android_server_VibratorService.cpp \ $(LOCAL_REL_DIR)/com_android_server_PersistentDataBlockService.cpp \ $(LOCAL_REL_DIR)/com_android_server_VirtualPositionService.cpp \ $(LOCAL_REL_DIR)/onload.cpp LOCAL_C_INCLUDES += \ $(JNI_H_INCLUDE) \ frameworks/base/services \ frameworks/base/libs \ frameworks/base/libs/hwui \ frameworks/base/core/jni \ frameworks/native/services \ libcore/include \ libcore/include/libsuspend \ system/security/keystore/include \ $(call include-path-for, libhardware)/hardware \ $(call include-path-for, libhardware_legacy)/hardware_legacy \ LOCAL_SHARED_LIBRARIES += \ libandroid_runtime \ libandroidfw \ libbinder \ libcutils \ liblog \ libhardware \ libhardware_legacy \ libkeystore_binder \ libnativehelper \ libutils \ libui \ libinput \ libinputflinger \ libinputservice \ libsensorservice \ libskia \ libgui \ libusbhost \ libsuspend \ libEGL \ libGLESv2 \ libnetutils \ ifeq ($(BOARD_USES_QC_TIME_SERVICES),true) LOCAL_CFLAGS += -DHAVE_QC_TIME_SERVICES=1 LOCAL_SHARED_LIBRARIES += libtime_genoff $(shell mkdir -p $(OUT)/obj/SHARED_LIBRARIES/libtime_genoff_intermediates/) $(shell touch $(OUT)/obj/SHARED_LIBRARIES/libtime_genoff_intermediates/export_includes) endif ================================================ FILE: VirtualPosition/vp_JNI/com_android_server_VirtualPositionService.cpp ================================================ #define LOG_TAG "VirtualPositionService" #include "jni.h" #include "JNIHelp.h" #include "android_runtime/AndroidRuntime.h" #include #include #include #include #include namespace android { VirtualPosition virtual_position = {1, 0.0, 0.0}; /*在硬件抽象层中定义的硬件访问结构体,参考*/ struct vp_device_t* vp_device = NULL; /*通过硬件抽象层定义的硬件访问接口设置硬件寄存器val的值*/ static void vp_setVal() { ALOGI("VirtualPosition JNI: set value to device."); if(!vp_device) { ALOGI("VirtualPosition JNI: device is not open."); return; } vp_device->set_val(vp_device, virtual_position); } /*通过硬件抽象层定义的硬件访问接口读取硬件寄存器val的值*/ static void vp_getVal() { if(!vp_device) { ALOGI("VirtualPosition JNI: device is not open."); } vp_device->get_val(vp_device, &virtual_position); ALOGI("VirtualPosition JNI: get value from device."); } /*通过硬件抽象层定义的硬件模块打开接口打开硬件设备*/ static inline int vp_device_open(const hw_module_t* module, struct vp_device_t** device) { return module->methods->open(module, VP_HARDWARE_MODULE_ID, (struct hw_device_t**)device); } /*通过硬件模块ID来加载指定的硬件抽象层模块并打开硬件*/ static jboolean vp_init(JNIEnv* env, jclass clazz) { vp_module_t* module; ALOGI("VirtualPosition JNI: initializing......"); if(hw_get_module(VP_HARDWARE_MODULE_ID, (const struct hw_module_t**)&module) == 0) { ALOGI("VirtualPosition JNI: vp Stub found."); if(vp_device_open(&(module->common), &vp_device) == 0) { ALOGI("VirtualPosition JNI: vp device is open."); return 0; } ALOGE("VirtualPosition JNI: failed to open vp device."); return -1; } ALOGE("VirtualPosition JNI: failed to get vp stub module."); return -1; } static void android_server_VirtualPositionService_set_virtual_toggle(JNIEnv* env, jclass clazz, jint tog) { virtual_position.toggle = tog; vp_setVal(); } static jint android_server_VirtualPositionService_get_virtual_toggle(JNIEnv* env, jclass clazz) { vp_getVal(); return virtual_position.toggle; } static void android_server_VirtualPositionService_set_virtual_latitude(JNIEnv* env, jclass clazz, jdouble vlat) { virtual_position.virtual_latitude = vlat; vp_setVal(); } static jdouble android_server_VirtualPositionService_get_virtual_latitude(JNIEnv* env, jclass clazz) { vp_getVal(); return virtual_position.virtual_latitude; } static void android_server_VirtualPositionService_set_virtual_longitude(JNIEnv* env, jclass clazz, jdouble vlon) { virtual_position.virtual_longitude = vlon; vp_setVal(); } static jdouble android_server_VirtualPositionService_get_virtual_longitude(JNIEnv* env, jclass clazz) { vp_getVal(); return virtual_position.virtual_longitude; } /*JNI方法表*/ static const JNINativeMethod method_table[] = { {"init_native", "()Z", (void*)vp_init}, {"native_set_virtual_toggle", "(I)V", (void*)android_server_VirtualPositionService_set_virtual_toggle}, {"native_get_virtual_toggle", "()I", (void*)android_server_VirtualPositionService_get_virtual_toggle}, {"native_set_virtual_latitude", "(D)V", (void*)android_server_VirtualPositionService_set_virtual_latitude}, {"native_get_virtual_latitude", "()D", (void*)android_server_VirtualPositionService_get_virtual_latitude}, {"native_set_virtual_longitude", "(D)V", (void*)android_server_VirtualPositionService_set_virtual_longitude}, {"native_get_virtual_longitude", "()D", (void*)android_server_VirtualPositionService_get_virtual_longitude}, }; /*注册JNI方法*/ int register_android_server_VirtualPositionService(JNIEnv *env) { return jniRegisterNativeMethods(env, "com/android/server/VirtualPositionService", method_table, NELEM(method_table)); } }; ================================================ FILE: VirtualPosition/vp_JNI/onload.cpp ================================================ /* * Copyright (C) 2009 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "JNIHelp.h" #include "jni.h" #include "utils/Log.h" #include "utils/misc.h" namespace android { int register_android_server_ActivityManagerService(JNIEnv* env); int register_android_server_AlarmManagerService(JNIEnv* env); int register_android_server_AssetAtlasService(JNIEnv* env); int register_android_server_BatteryStatsService(JNIEnv* env); int register_android_server_ConsumerIrService(JNIEnv *env); int register_android_server_InputApplicationHandle(JNIEnv* env); int register_android_server_InputWindowHandle(JNIEnv* env); int register_android_server_InputManager(JNIEnv* env); int register_android_server_LightsService(JNIEnv* env); int register_android_server_PowerManagerService(JNIEnv* env); int register_android_server_SerialService(JNIEnv* env); int register_android_server_SystemServer(JNIEnv* env); int register_android_server_UsbDeviceManager(JNIEnv* env); int register_android_server_UsbMidiDevice(JNIEnv* env); int register_android_server_UsbHostManager(JNIEnv* env); int register_android_server_VibratorService(JNIEnv* env); int register_android_server_location_GpsLocationProvider(JNIEnv* env); int register_android_server_location_FlpHardwareProvider(JNIEnv* env); int register_android_server_connectivity_Vpn(JNIEnv* env); int register_android_server_hdmi_HdmiCecController(JNIEnv* env); int register_android_server_tv_TvInputHal(JNIEnv* env); int register_android_server_PersistentDataBlockService(JNIEnv* env); int register_android_server_Watchdog(JNIEnv* env); int register_android_server_VirtualPositionService(JNIEnv* env); }; using namespace android; extern "C" jint JNI_OnLoad(JavaVM* vm, void* /* reserved */) { JNIEnv* env = NULL; jint result = -1; if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { ALOGE("GetEnv failed!"); return result; } ALOG_ASSERT(env, "Could not retrieve the env!"); register_android_server_ActivityManagerService(env); register_android_server_PowerManagerService(env); register_android_server_SerialService(env); register_android_server_InputApplicationHandle(env); register_android_server_InputWindowHandle(env); register_android_server_InputManager(env); register_android_server_LightsService(env); register_android_server_AlarmManagerService(env); register_android_server_UsbDeviceManager(env); register_android_server_UsbMidiDevice(env); register_android_server_UsbHostManager(env); register_android_server_VibratorService(env); register_android_server_SystemServer(env); register_android_server_location_GpsLocationProvider(env); register_android_server_location_FlpHardwareProvider(env); register_android_server_connectivity_Vpn(env); register_android_server_AssetAtlasService(env); register_android_server_ConsumerIrService(env); register_android_server_BatteryStatsService(env); register_android_server_hdmi_HdmiCecController(env); register_android_server_tv_TvInputHal(env); register_android_server_PersistentDataBlockService(env); register_android_server_Watchdog(env); register_android_server_VirtualPositionService(env); return JNI_VERSION_1_4; } ================================================ FILE: VirtualPosition/vp_KernelDriver/cyanogen_cancro_defconfig ================================================ # CONFIG_ARM_PATCH_PHYS_VIRT is not set CONFIG_EXPERIMENTAL=y CONFIG_LOCALVERSION="-cyanogenmod" CONFIG_KERNEL_LZMA=y CONFIG_SYSVIPC=y CONFIG_AUDIT=y CONFIG_RCU_FAST_NO_HZ=y CONFIG_LOG_BUF_SHIFT=21 CONFIG_CGROUPS=y CONFIG_CGROUP_DEBUG=y CONFIG_CGROUP_FREEZER=y CONFIG_CGROUP_CPUACCT=y CONFIG_RESOURCE_COUNTERS=y CONFIG_CGROUP_SCHED=y CONFIG_RT_GROUP_SCHED=y CONFIG_NAMESPACES=y # CONFIG_UTS_NS is not set # CONFIG_IPC_NS is not set # CONFIG_USER_NS is not set # CONFIG_PID_NS is not set CONFIG_RELAY=y CONFIG_BLK_DEV_INITRD=y CONFIG_RD_BZIP2=y CONFIG_RD_LZMA=y CONFIG_CC_OPTIMIZE_FOR_SIZE=y CONFIG_PANIC_TIMEOUT=5 CONFIG_KALLSYMS_ALL=y CONFIG_EMBEDDED=y # CONFIG_SLUB_DEBUG is not set CONFIG_PROFILING=y CONFIG_OPROFILE=y CONFIG_MODULES=y CONFIG_MODULE_UNLOAD=y CONFIG_MODULE_FORCE_UNLOAD=y CONFIG_MODVERSIONS=y CONFIG_PARTITION_ADVANCED=y CONFIG_EFI_PARTITION=y # CONFIG_IOSCHED_TEST is not set CONFIG_IOSCHED_BFQ=y CONFIG_CGROUP_BFQIO=y CONFIG_DEFAULT_BFQ=y CONFIG_ARCH_MSM=y CONFIG_ARCH_MSM8974=y CONFIG_ARCH_MSMSAMARIUM=y CONFIG_MSM_KRAIT_TBB_ABORT_HANDLER=y # CONFIG_MSM_STACKED_MEMORY is not set CONFIG_CPU_HAS_L2_PMU=y # CONFIG_MSM_FIQ_SUPPORT is not set # CONFIG_MSM_PROC_COMM is not set CONFIG_MSM_SMD=y CONFIG_MSM_SMD_PKG4=y CONFIG_MSM_BAM_DMUX=y CONFIG_MSM_SMP2P=y CONFIG_MSM_SMP2P_TEST=y # CONFIG_MSM_RESET_MODEM is not set CONFIG_MSM_IPC_LOGGING=y CONFIG_MSM_IPC_ROUTER=y CONFIG_MSM_IPC_ROUTER_SMD_XPRT=y CONFIG_MSM_IPC_ROUTER_SECURITY=y CONFIG_MSM_QMI_INTERFACE=y # CONFIG_MSM_DMA_TEST is not set CONFIG_MSM_SUBSYSTEM_RESTART=y CONFIG_MSM_SYSMON_COMM=y CONFIG_MSM_PIL_LPASS_QDSP6V5=y CONFIG_MSM_PIL_MSS_QDSP6V5=y CONFIG_MSM_PIL_VENUS=y CONFIG_MSM_PIL_PRONTO=y CONFIG_MSM_TZ_LOG=y CONFIG_MSM_RPM_RBCPR_STATS_V2_LOG=y CONFIG_MSM_DIRECT_SCLK_ACCESS=y CONFIG_MSM_EVENT_TIMER=y CONFIG_MSM_BUS_SCALING=y CONFIG_MSM_WATCHDOG_V2=y CONFIG_MSM_MEMORY_DUMP=y # CONFIG_MSM_DLOAD_MODE is not set CONFIG_MSM_JTAG=y CONFIG_MSM_ADSP_LOADER=y CONFIG_MSM_OCMEM=y CONFIG_MSM_OCMEM_LOCAL_POWER_CTRL=y CONFIG_MSM_OCMEM_DEBUG=y CONFIG_SENSORS_ADSP=y CONFIG_MSM_CACHE_ERP=y CONFIG_MSM_L1_ERR_PANIC=y CONFIG_MSM_L1_ERR_LOG=y CONFIG_MSM_L2_ERP_PRINT_ACCESS_ERRORS=y CONFIG_MSM_L2_ERP_PORT_PANIC=y CONFIG_MSM_L2_ERP_2BIT_PANIC=y CONFIG_MSM_CACHE_DUMP=y CONFIG_MSM_CACHE_DUMP_ON_PANIC=y CONFIG_MSM_ENABLE_WDOG_DEBUG_CONTROL=y CONFIG_MSM_BOOT_STATS=y CONFIG_MSM_XPU_ERR_FATAL=y CONFIG_HAS_MACH_MEMUTILS=y CONFIG_STRICT_MEMORY_RWX=y CONFIG_NO_HZ=y CONFIG_HIGH_RES_TIMERS=y CONFIG_SMP=y # CONFIG_SMP_ON_UP is not set CONFIG_SCHED_MC=y CONFIG_ARM_ARCH_TIMER=y CONFIG_PREEMPT=y CONFIG_AEABI=y CONFIG_HIGHMEM=y CONFIG_COMPACTION=y CONFIG_KSM=y CONFIG_ENABLE_VMALLOC_SAVING=y CONFIG_CC_STACKPROTECTOR=y CONFIG_CP_ACCESS=y CONFIG_USE_OF=y CONFIG_BUILD_ARM_APPENDED_DTB_IMAGE=y CONFIG_CPU_FREQ=y CONFIG_CPU_FREQ_GOV_ONDEMAND=y CONFIG_CPU_FREQ_GOV_INTERACTIVE=y CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y CONFIG_CPU_BOOST=y CONFIG_CPU_IDLE=y CONFIG_VFP=y CONFIG_NEON=y CONFIG_KERNEL_MODE_NEON=y # CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set CONFIG_PM_AUTOSLEEP=y CONFIG_PM_WAKELOCKS=y CONFIG_PM_WAKELOCKS_LIMIT=0 # CONFIG_PM_WAKELOCKS_GC is not set CONFIG_PM_RUNTIME=y CONFIG_PM_DEBUG=y CONFIG_SUSPEND_TIME=y CONFIG_NET=y CONFIG_PACKET=y CONFIG_UNIX=y CONFIG_XFRM_USER=y CONFIG_NET_KEY=y CONFIG_INET=y CONFIG_IP_ADVANCED_ROUTER=y CONFIG_IP_MULTIPLE_TABLES=y CONFIG_IP_ROUTE_VERBOSE=y CONFIG_IP_PNP=y CONFIG_IP_PNP_DHCP=y CONFIG_INET_AH=y CONFIG_INET_ESP=y # CONFIG_INET_XFRM_MODE_BEET is not set # CONFIG_INET_LRO is not set CONFIG_IPV6=y CONFIG_IPV6_PRIVACY=y CONFIG_IPV6_ROUTER_PREF=y CONFIG_IPV6_ROUTE_INFO=y CONFIG_IPV6_OPTIMISTIC_DAD=y CONFIG_INET6_AH=y CONFIG_INET6_ESP=y CONFIG_INET6_IPCOMP=y CONFIG_IPV6_MIP6=y CONFIG_IPV6_MULTIPLE_TABLES=y CONFIG_IPV6_SUBTREES=y CONFIG_NETFILTER=y CONFIG_NF_CONNTRACK=y CONFIG_NF_CONNTRACK_SECMARK=y CONFIG_NF_CONNTRACK_EVENTS=y CONFIG_NF_CT_PROTO_DCCP=y CONFIG_NF_CT_PROTO_SCTP=y CONFIG_NF_CT_PROTO_UDPLITE=y CONFIG_NF_CONNTRACK_AMANDA=y CONFIG_NF_CONNTRACK_FTP=y CONFIG_NF_CONNTRACK_H323=y CONFIG_NF_CONNTRACK_IRC=y CONFIG_NF_CONNTRACK_NETBIOS_NS=y CONFIG_NF_CONNTRACK_PPTP=y CONFIG_NF_CONNTRACK_SANE=y CONFIG_NF_CONNTRACK_TFTP=y CONFIG_NF_CT_NETLINK=y CONFIG_NETFILTER_TPROXY=y CONFIG_NETFILTER_XT_TARGET_CLASSIFY=y CONFIG_NETFILTER_XT_TARGET_CONNMARK=y CONFIG_NETFILTER_XT_TARGET_CONNSECMARK=y CONFIG_NETFILTER_XT_TARGET_IDLETIMER=y CONFIG_NETFILTER_XT_TARGET_LOG=y CONFIG_NETFILTER_XT_TARGET_MARK=y CONFIG_NETFILTER_XT_TARGET_NFLOG=y CONFIG_NETFILTER_XT_TARGET_NFQUEUE=y CONFIG_NETFILTER_XT_TARGET_NOTRACK=y CONFIG_NETFILTER_XT_TARGET_TEE=y CONFIG_NETFILTER_XT_TARGET_TPROXY=y CONFIG_NETFILTER_XT_TARGET_TRACE=y CONFIG_NETFILTER_XT_TARGET_SECMARK=y CONFIG_NETFILTER_XT_TARGET_TCPMSS=y CONFIG_NETFILTER_XT_MATCH_COMMENT=y CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=y CONFIG_NETFILTER_XT_MATCH_CONNMARK=y CONFIG_NETFILTER_XT_MATCH_CONNTRACK=y CONFIG_NETFILTER_XT_MATCH_DSCP=y CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=y CONFIG_NETFILTER_XT_MATCH_HELPER=y CONFIG_NETFILTER_XT_MATCH_IPRANGE=y CONFIG_NETFILTER_XT_MATCH_LENGTH=y CONFIG_NETFILTER_XT_MATCH_LIMIT=y CONFIG_NETFILTER_XT_MATCH_MAC=y CONFIG_NETFILTER_XT_MATCH_MARK=y CONFIG_NETFILTER_XT_MATCH_MULTIPORT=y CONFIG_NETFILTER_XT_MATCH_POLICY=y CONFIG_NETFILTER_XT_MATCH_PKTTYPE=y CONFIG_NETFILTER_XT_MATCH_QTAGUID=y CONFIG_NETFILTER_XT_MATCH_QUOTA=y CONFIG_NETFILTER_XT_MATCH_QUOTA2=y CONFIG_NETFILTER_XT_MATCH_QUOTA2_LOG=y CONFIG_NETFILTER_XT_MATCH_SOCKET=y CONFIG_NETFILTER_XT_MATCH_STATE=y CONFIG_NETFILTER_XT_MATCH_STATISTIC=y CONFIG_NETFILTER_XT_MATCH_STRING=y CONFIG_NETFILTER_XT_MATCH_TIME=y CONFIG_NETFILTER_XT_MATCH_U32=y CONFIG_NF_CONNTRACK_IPV4=y CONFIG_IP_NF_IPTABLES=y CONFIG_IP_NF_MATCH_AH=y CONFIG_IP_NF_MATCH_ECN=y CONFIG_IP_NF_MATCH_TTL=y CONFIG_IP_NF_FILTER=y CONFIG_IP_NF_TARGET_REJECT=y CONFIG_IP_NF_TARGET_REJECT_SKERR=y CONFIG_NF_NAT=y CONFIG_IP_NF_TARGET_MASQUERADE=y CONFIG_IP_NF_TARGET_NETMAP=y CONFIG_IP_NF_TARGET_REDIRECT=y CONFIG_IP_NF_MANGLE=y CONFIG_IP_NF_RAW=y CONFIG_IP_NF_SECURITY=y CONFIG_IP_NF_ARPTABLES=y CONFIG_IP_NF_ARPFILTER=y CONFIG_IP_NF_ARP_MANGLE=y CONFIG_NF_CONNTRACK_IPV6=y CONFIG_IP6_NF_IPTABLES=y CONFIG_IP6_NF_FILTER=y CONFIG_IP6_NF_TARGET_REJECT=y CONFIG_IP6_NF_TARGET_REJECT_SKERR=y CONFIG_IP6_NF_MANGLE=y CONFIG_IP6_NF_RAW=y CONFIG_BRIDGE_NF_EBTABLES=y CONFIG_BRIDGE_EBT_BROUTE=y CONFIG_BRIDGE=y CONFIG_NET_SCHED=y CONFIG_NET_SCH_HTB=y CONFIG_NET_SCH_PRIO=y CONFIG_NET_CLS_FW=y CONFIG_NET_CLS_U32=y CONFIG_CLS_U32_MARK=y CONFIG_NET_CLS_FLOW=y CONFIG_NET_EMATCH=y CONFIG_NET_EMATCH_CMP=y CONFIG_NET_EMATCH_NBYTE=y CONFIG_NET_EMATCH_U32=y CONFIG_NET_EMATCH_META=y CONFIG_NET_EMATCH_TEXT=y CONFIG_NET_CLS_ACT=y CONFIG_BT=y CONFIG_BT_RFCOMM=y CONFIG_BT_RFCOMM_TTY=y CONFIG_BT_BNEP=y CONFIG_BT_BNEP_MC_FILTER=y CONFIG_BT_BNEP_PROTO_FILTER=y CONFIG_BT_HCISMD=y CONFIG_BT_HCIUART=y CONFIG_BT_HCIUART_ATH3K=y CONFIG_MSM_BT_POWER=y CONFIG_CFG80211=y CONFIG_NL80211_TESTMODE=y CONFIG_CFG80211_INTERNAL_REGDB=y CONFIG_RFKILL=y CONFIG_NFC=y CONFIG_NFC_LLCP=y CONFIG_BCM2079X_NFC=y CONFIG_GENLOCK=y CONFIG_GENLOCK_MISCDEVICE=y CONFIG_CMA=y CONFIG_BLK_DEV_LOOP=y CONFIG_BLK_DEV_RAM=y CONFIG_BLK_DEV_RAM_SIZE=8192 CONFIG_UID_STAT=y CONFIG_QSEECOM=y CONFIG_QPNP_MISC=y CONFIG_USB_HSIC_SMSC_HUB=y CONFIG_STM32_FW_UPDATER=y CONFIG_UID_CPUTIME=y CONFIG_SCSI=y CONFIG_SCSI_TGT=y CONFIG_BLK_DEV_SD=y CONFIG_CHR_DEV_SG=y CONFIG_CHR_DEV_SCH=y CONFIG_SCSI_MULTI_LUN=y CONFIG_SCSI_CONSTANTS=y CONFIG_SCSI_LOGGING=y CONFIG_SCSI_SCAN_ASYNC=y CONFIG_MD=y CONFIG_BLK_DEV_DM=y CONFIG_DM_CRYPT=y CONFIG_DM_REQ_CRYPT=y CONFIG_DM_UEVENT=y CONFIG_DM_VERITY=y CONFIG_NETDEVICES=y CONFIG_DUMMY=y CONFIG_TUN=y # CONFIG_MSM_RMNET is not set CONFIG_MSM_RMNET_BAM=y CONFIG_PPP=y CONFIG_PPP_BSDCOMP=y CONFIG_PPP_DEFLATE=y CONFIG_PPP_FILTER=y CONFIG_PPP_MPPE=y CONFIG_PPPOLAC=y CONFIG_PPPOPNS=y CONFIG_PPP_ASYNC=y CONFIG_PPP_SYNC_TTY=y CONFIG_SLIP=y CONFIG_SLIP_COMPRESSED=y CONFIG_SLIP_MODE_SLIP6=y CONFIG_USB_USBNET=y CONFIG_WCNSS_CORE=y CONFIG_WCNSS_CORE_PRONTO=y CONFIG_WCNSS_MEM_PRE_ALLOC=y CONFIG_WCNSS_REGISTER_DUMP_ON_BITE=y CONFIG_INPUT_EVDEV=y CONFIG_INPUT_KEYRESET=y # CONFIG_KEYBOARD_ATKBD is not set CONFIG_KEYBOARD_GPIO=y # CONFIG_INPUT_MOUSE is not set CONFIG_INPUT_JOYSTICK=y CONFIG_JOYSTICK_XPAD=y CONFIG_JOYSTICK_XPAD_FF=y CONFIG_JOYSTICK_XPAD_LEDS=y CONFIG_INPUT_TABLET=y CONFIG_TABLET_USB_ACECAD=y CONFIG_TABLET_USB_AIPTEK=y CONFIG_TABLET_USB_GTCO=y CONFIG_TABLET_USB_HANWANG=y CONFIG_TABLET_USB_KBTAB=y CONFIG_TABLET_USB_WACOM=y CONFIG_INPUT_TOUCHSCREEN=y CONFIG_TOUCHSCREEN_SYNAPTICS_DSX_I2C=y CONFIG_TOUCHSCREEN_SYNAPTICS_DSX_I2C_INCELL=y CONFIG_TOUCHSCREEN_SYNAPTICS_DSX_CORE=y CONFIG_TOUCHSCREEN_SYNAPTICS_DSX_CORE_INCELL=y CONFIG_TOUCHSCREEN_SYNAPTICS_DSX_RMI_DEV=y CONFIG_TOUCHSCREEN_SYNAPTICS_DSX_RMI_DEV_INCELL=y CONFIG_TOUCHSCREEN_SYNAPTICS_DSX_FW_UPDATE=y CONFIG_TOUCHSCREEN_SYNAPTICS_DSX_FW_UPDATE_INCELL=y CONFIG_TOUCHSCREEN_SYNAPTICS_DSX_TEST_REPORTING_INCELL=y CONFIG_TOUCHSCREEN_ATMEL_MXT=y CONFIG_TOUCHSCREEN_ATMEL_640T=y CONFIG_TOUCHSCREEN_ST_FTS=y CONFIG_TOUCHSCREEN_CYTTSP_BUTTON=y CONFIG_TOUCHSCREEN_GEN_VKEYS=y CONFIG_SECURE_TOUCH=y CONFIG_INPUT_MISC=y CONFIG_INPUT_HBTP_INPUT=y CONFIG_INPUT_KEYCHORD=y CONFIG_INPUT_UINPUT=y CONFIG_INPUT_GPIO=y CONFIG_SERIO_LIBPS2=y # CONFIG_VT is not set # CONFIG_LEGACY_PTYS is not set # CONFIG_DEVMEM is not set # CONFIG_DEVKMEM is not set CONFIG_SERIAL_MSM_HS=y CONFIG_SERIAL_MSM_HSL=y CONFIG_DIAG_CHAR=y CONFIG_HW_RANDOM=y CONFIG_HW_RANDOM_MSM=y CONFIG_MSM_ADSPRPC=y CONFIG_I2C=y CONFIG_I2C_CHARDEV=y CONFIG_I2C_QUP=y CONFIG_SPI=y CONFIG_SPI_QUP=y CONFIG_SPMI=y CONFIG_SPMI_MSM_PMIC_ARB=y CONFIG_MSM_QPNP_INT=y CONFIG_SLIMBUS_MSM_NGD=y CONFIG_DEBUG_GPIO=y CONFIG_GPIO_SYSFS=y CONFIG_GPIO_QPNP_PIN=y CONFIG_GPIO_QPNP_PIN_DEBUG=y CONFIG_SMB350_CHARGER=y CONFIG_BATTERY_BQ28400=y CONFIG_QPNP_CHARGER=y CONFIG_BATTERY_BCL=y CONFIG_QPNP_BMS=y CONFIG_SENSORS_EPM_ADC=y CONFIG_SENSORS_QPNP_ADC_VOLTAGE=y CONFIG_SENSORS_QPNP_ADC_CURRENT=y CONFIG_THERMAL=y CONFIG_THERMAL_TSENS8974=y CONFIG_THERMAL_QPNP=y CONFIG_THERMAL_QPNP_ADC_TM=y CONFIG_THERMAL_MONITOR_SIMPLE=y CONFIG_WCD9320_CODEC=y CONFIG_REGULATOR_FIXED_VOLTAGE=y CONFIG_REGULATOR_STUB=y CONFIG_REGULATOR_QPNP=y CONFIG_MEDIA_SUPPORT=y CONFIG_MEDIA_CONTROLLER=y CONFIG_VIDEO_DEV=y CONFIG_VIDEO_V4L2_SUBDEV_API=y # CONFIG_IR_MCE_KBD_DECODER is not set CONFIG_IR_PWM=y # CONFIG_MSM_CAMERA is not set CONFIG_MSMB_CAMERA=y CONFIG_MSM_CAMERA_SENSOR=y CONFIG_MSM_CPP=y CONFIG_MSM_CCI=y CONFIG_MSM_CSI30_HEADER=y CONFIG_MSM_CSIPHY=y CONFIG_MSM_CSID=y CONFIG_MSM_EEPROM=y CONFIG_MSM_ISPIF=y CONFIG_S5K3M2=y CONFIG_IMX214=y CONFIG_IMX135=y CONFIG_IMX219=y CONFIG_IMX132=y CONFIG_OV4688=y CONFIG_MSMB_JPEG=y CONFIG_MSM_VIDC_V4L2=y CONFIG_MSM_WFD=y # CONFIG_MEDIA_TUNER_SIMPLE is not set # CONFIG_MEDIA_TUNER_TDA8290 is not set # CONFIG_MEDIA_TUNER_TDA827X is not set # CONFIG_MEDIA_TUNER_TDA18271 is not set # CONFIG_MEDIA_TUNER_TDA9887 is not set # CONFIG_MEDIA_TUNER_TEA5761 is not set # CONFIG_MEDIA_TUNER_TEA5767 is not set # CONFIG_MEDIA_TUNER_MT20XX is not set # CONFIG_MEDIA_TUNER_MT2060 is not set # CONFIG_MEDIA_TUNER_MT2063 is not set # CONFIG_MEDIA_TUNER_MT2266 is not set # CONFIG_MEDIA_TUNER_MT2131 is not set # CONFIG_MEDIA_TUNER_QT1010 is not set # CONFIG_MEDIA_TUNER_XC2028 is not set # CONFIG_MEDIA_TUNER_XC5000 is not set # CONFIG_MEDIA_TUNER_XC4000 is not set # CONFIG_MEDIA_TUNER_MXL5005S is not set # CONFIG_MEDIA_TUNER_MXL5007T is not set # CONFIG_MEDIA_TUNER_MC44S803 is not set # CONFIG_MEDIA_TUNER_MAX2165 is not set # CONFIG_MEDIA_TUNER_TDA18218 is not set # CONFIG_MEDIA_TUNER_TDA18212 is not set CONFIG_VIDEOBUF2_MSM_MEM=y CONFIG_USB_VIDEO_CLASS=y # CONFIG_USB_GSPCA is not set CONFIG_V4L_PLATFORM_DRIVERS=y CONFIG_RADIO_IRIS=y CONFIG_RADIO_IRIS_TRANSPORT=y CONFIG_ION=y CONFIG_ION_MSM=y CONFIG_MSM_KGSL=y CONFIG_KGSL_PER_PROCESS_PAGE_TABLE=y CONFIG_FB=y CONFIG_FB_MSM=y # CONFIG_FB_MSM_BACKLIGHT is not set CONFIG_FB_MSM_MDSS=y CONFIG_FB_MSM_MDSS_WRITEBACK=y CONFIG_BACKLIGHT_LCD_SUPPORT=y # CONFIG_LCD_CLASS_DEVICE is not set CONFIG_BACKLIGHT_CLASS_DEVICE=y # CONFIG_BACKLIGHT_GENERIC is not set CONFIG_SOUND=y CONFIG_SND=y CONFIG_SND_USB_AUDIO=y CONFIG_SND_SOC=y CONFIG_SND_SOC_MSM8974=y CONFIG_SND_SOC_TPA6130A2=y CONFIG_HIDRAW=y CONFIG_UHID=y CONFIG_HID_A4TECH=y CONFIG_HID_ACRUX=y CONFIG_HID_ACRUX_FF=y CONFIG_HID_APPLE=y CONFIG_HID_BELKIN=y CONFIG_HID_CHERRY=y CONFIG_HID_CHICONY=y CONFIG_HID_PRODIKEYS=y CONFIG_HID_CYPRESS=y CONFIG_HID_DRAGONRISE=y CONFIG_DRAGONRISE_FF=y CONFIG_HID_EMS_FF=y CONFIG_HID_ELECOM=y CONFIG_HID_EZKEY=y CONFIG_HID_HOLTEK=y CONFIG_HID_KEYTOUCH=y CONFIG_HID_KYE=y CONFIG_HID_UCLOGIC=y CONFIG_HID_WALTOP=y CONFIG_HID_GYRATION=y CONFIG_HID_TWINHAN=y CONFIG_HID_KENSINGTON=y CONFIG_HID_LCPOWER=y CONFIG_HID_LOGITECH=y CONFIG_HID_LOGITECH_DJ=y CONFIG_LOGITECH_FF=y CONFIG_LOGIRUMBLEPAD2_FF=y CONFIG_LOGIG940_FF=y CONFIG_HID_MAGICMOUSE=y CONFIG_HID_MICROSOFT=y CONFIG_HID_MONTEREY=y CONFIG_HID_MULTITOUCH=y CONFIG_HID_NTRIG=y CONFIG_HID_ORTEK=y CONFIG_HID_PANTHERLORD=y CONFIG_PANTHERLORD_FF=y CONFIG_HID_PETALYNX=y CONFIG_HID_PICOLCD=y CONFIG_HID_PRIMAX=y CONFIG_HID_ROCCAT=y CONFIG_HID_SAITEK=y CONFIG_HID_SAMSUNG=y CONFIG_HID_SONY=y CONFIG_HID_SPEEDLINK=y CONFIG_HID_SUNPLUS=y CONFIG_HID_GREENASIA=y CONFIG_GREENASIA_FF=y CONFIG_HID_SMARTJOYPLUS=y CONFIG_SMARTJOYPLUS_FF=y CONFIG_HID_TIVO=y CONFIG_HID_TOPSEED=y CONFIG_HID_THRUSTMASTER=y CONFIG_HID_WACOM=y CONFIG_HID_WIIMOTE=y CONFIG_HID_ZEROPLUS=y CONFIG_HID_ZYDACRON=y CONFIG_HID_SENSOR_HUB=y CONFIG_USB_HIDDEV=y CONFIG_I2C_HID=y CONFIG_USB_ANNOUNCE_NEW_DEVICES=y CONFIG_USB_SUSPEND=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_EHSET=y CONFIG_USB_EHCI_MSM=y CONFIG_USB_EHCI_MSM_HSIC=y CONFIG_USB_ACM=y CONFIG_USB_STORAGE=y CONFIG_USB_STORAGE_DATAFAB=y CONFIG_USB_STORAGE_FREECOM=y CONFIG_USB_STORAGE_ISD200=y CONFIG_USB_STORAGE_USBAT=y CONFIG_USB_STORAGE_SDDR09=y CONFIG_USB_STORAGE_SDDR55=y CONFIG_USB_STORAGE_JUMPSHOT=y CONFIG_USB_STORAGE_ALAUDA=y CONFIG_USB_STORAGE_ONETOUCH=y CONFIG_USB_STORAGE_KARMA=y CONFIG_USB_STORAGE_CYPRESS_ATACB=y CONFIG_USB_STORAGE_ENE_UB6250=y CONFIG_USB_EHSET_TEST_FIXTURE=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_DEBUG_FILES=y CONFIG_USB_CI13XXX_MSM=y CONFIG_USB_DWC3_MSM=y CONFIG_USB_G_ANDROID=y CONFIG_MMC=y CONFIG_MMC_PERF_PROFILING=y CONFIG_MMC_UNSAFE_RESUME=y CONFIG_MMC_CLKGATE=y CONFIG_MMC_PARANOID_SD_INIT=y CONFIG_MMC_BLOCK_MINORS=32 # CONFIG_MMC_BLOCK_BOUNCE is not set CONFIG_MMC_SDHCI=y CONFIG_MMC_SDHCI_PLTFM=y CONFIG_MMC_MSM=y CONFIG_MMC_SDHCI_MSM=y CONFIG_MMC_MSM_SPS_SUPPORT=y CONFIG_LEDS_GPIO=y CONFIG_LEDS_QPNP=y CONFIG_LEDS_TRIGGERS=y CONFIG_LEDS_TRIGGER_BACKLIGHT=y CONFIG_LEDS_TRIGGER_DEFAULT_ON=y CONFIG_SWITCH=y CONFIG_RTC_CLASS=y # CONFIG_RTC_DRV_MSM is not set CONFIG_RTC_DRV_QPNP=y CONFIG_UIO=y CONFIG_UIO_MSM_SHAREDMEM=y CONFIG_STAGING=y CONFIG_ANDROID=y CONFIG_ANDROID_BINDER_IPC=y CONFIG_ASHMEM=y CONFIG_ANDROID_RAM_CONSOLE=y CONFIG_ANDROID_TIMED_GPIO=y CONFIG_ANDROID_LOW_MEMORY_KILLER=y CONFIG_PRONTO_WLAN=y CONFIG_PRIMA_WLAN_LFR=y CONFIG_PRIMA_WLAN_OKC=y CONFIG_PRIMA_WLAN_11AC_HIGH_TP=y CONFIG_WLAN_FEATURE_11W=y CONFIG_QCOM_VOWIFI_11R=y CONFIG_ENABLE_LINUX_REG=y CONFIG_QCOM_TDLS=y CONFIG_SPS=y CONFIG_USB_BAM=y CONFIG_SPS_SUPPORT_BAMDMA=y CONFIG_SPS_SUPPORT_NDP_BAM=y CONFIG_QPNP_PWM=y CONFIG_QPNP_POWER_ON=y CONFIG_QPNP_CLKDIV=y CONFIG_QPNP_REVID=y CONFIG_QPNP_COINCELL=y CONFIG_MSM_AVTIMER=y CONFIG_MSM_IOMMU_V1=y CONFIG_MSM_IOMMU_PMON=y CONFIG_IOMMU_PGTABLES_L2=y CONFIG_MSM_IOMMU_VBIF_CHECK=y # CONFIG_ADRENO_IDLER is not set CONFIG_BIF=y CONFIG_BIF_QPNP=y CONFIG_IIO=y CONFIG_HID_SENSOR_ACCEL_3D=y CONFIG_HID_SENSOR_MOTION_DETECTOR=y CONFIG_HID_SENSOR_CUSTOM=y CONFIG_HID_SENSOR_GYRO_3D=y CONFIG_HID_SENSOR_INCLI_3D=y CONFIG_CM36686=y CONFIG_HID_SENSOR_MAGNETOMETER_3D=y CONFIG_HID_SENSOR_ORIENTATION=y CONFIG_HID_SENSOR_DISTANCE=y CONFIG_BMP280=y CONFIG_BMP280_I2C=y CONFIG_EXT4_FS=y CONFIG_EXT4_FS_SECURITY=y CONFIG_FUSE_FS=y CONFIG_MSDOS_FS=y CONFIG_VFAT_FS=y CONFIG_EXFAT_FS=y CONFIG_TMPFS=y CONFIG_TMPFS_POSIX_ACL=y CONFIG_ECRYPT_FS=y CONFIG_CIFS=y CONFIG_CONFIGFS_FS=y CONFIG_SDCARD_FS=y CONFIG_NLS_CODEPAGE_437=y CONFIG_NLS_CODEPAGE_936=y CONFIG_NLS_CODEPAGE_950=y CONFIG_NLS_ASCII=y CONFIG_NLS_ISO8859_1=y CONFIG_NLS_UTF8=y CONFIG_PRINTK_TIME=y CONFIG_MAGIC_SYSRQ=y # CONFIG_SCHED_DEBUG is not set CONFIG_SCHEDSTATS=y CONFIG_TIMER_STATS=y # CONFIG_DEBUG_PREEMPT is not set CONFIG_DEBUG_INFO=y CONFIG_FAULT_INJECTION=y CONFIG_CPU_FREQ_SWITCH_PROFILER=y CONFIG_DYNAMIC_DEBUG=y CONFIG_PANIC_ON_DATA_CORRUPTION=y CONFIG_PID_IN_CONTEXTIDR=y CONFIG_KEYS=y CONFIG_SECURITY_PERF_EVENTS_RESTRICT=y CONFIG_SECURITY=y CONFIG_SECURITY_NETWORK=y CONFIG_LSM_MMAP_MIN_ADDR=4096 CONFIG_SECURITY_SELINUX=y CONFIG_CRYPTO_NULL=y CONFIG_CRYPTO_XCBC=y CONFIG_CRYPTO_SHA1_ARM_NEON=y CONFIG_CRYPTO_SHA512_ARM_NEON=y CONFIG_CRYPTO_AES_ARM_BS=y CONFIG_CRYPTO_TWOFISH=y # CONFIG_CRYPTO_ANSI_CPRNG is not set CONFIG_CRYPTO_DEV_QCRYPTO=y CONFIG_CRYPTO_DEV_QCE=y CONFIG_CRYPTO_DEV_QCEDEV=y # CONFIG_VP CONFIG_VP=y ================================================ FILE: VirtualPosition/vp_KernelDriver/vp/Kconfig ================================================ config VP tristate "Virtual Position Driver" default n help This is the virtual position driver. ================================================ FILE: VirtualPosition/vp_KernelDriver/vp/Makefile ================================================ obj-$(CONFIG_VP) += vp.o ================================================ FILE: VirtualPosition/vp_KernelDriver/vp/vp.c ================================================ /******************************************* *include file and define functions *******************************************/ #include #include #include #include #include #include #include #include "vp.h" /*主设备和从设备号变量*/ static int vp_major = 0; static int vp_minor = 0; /*设备类别和设备变量*/ static struct class* vp_class = NULL; static struct vp_android_dev* vp_dev = NULL; /*传统的设备文件操作方法*/ static int vp_open(struct inode* inode, struct file* filp); static int vp_release(struct inode* inode, struct file* filp); static ssize_t vp_read(struct file* filp, char __user *buf, size_t count, loff_t* f_pos); static ssize_t vp_write(struct file* filp, const char __user *buf, size_t count, loff_t* f_pos); /*设备文件操作方法表*/ static struct file_operations vp_fops = { .owner = THIS_MODULE, .open = vp_open, .release = vp_release, .read = vp_read, .write = vp_write, }; /*访问设置属性方法*/ static ssize_t vp_lamp_show(struct device* dev, struct device_attribute* attr, char* buf); static ssize_t vp_lamp_store(struct device* dev, struct device_attribute* attr, const char* buf, size_t count); /*定义设备属性*/ static DEVICE_ATTR(val, S_IRUGO | S_IWUSR, vp_lamp_show, vp_lamp_store); /******************************************* *define traditional file access *******************************************/ /*打开设备方法*/ static int vp_open(struct inode* inode, struct file* filp) { struct vp_android_dev* dev; /*将自定义设备结构体保存在文件指针的私有数据域中,以便访问设备时拿来用*/ dev = container_of(inode->i_cdev, struct vp_android_dev, dev); filp->private_data = dev; return 0; } /*设备文件释放时调用,空实现*/ static int vp_release(struct inode* inode, struct file* filp) { return 0; } /*读取设备的寄存器val的值*/ static ssize_t vp_read(struct file* filp, char __user *buf, size_t count, loff_t* f_pos) { ssize_t err = 0; struct vp_android_dev* dev = filp->private_data; /*同步访问*/ if(down_interruptible(&(dev->sem))) { return -ERESTARTSYS; } if(count < sizeof(dev->val)) { goto out; } /*将寄存器val的值拷贝到用户提供的缓冲区*/ if(copy_to_user(buf, &(dev->val), sizeof(dev->val))) { err = -EFAULT; goto out; } err = sizeof(dev->val); out: up(&(dev->sem)); return err; } /*写设备的寄存器值val*/ static ssize_t vp_write(struct file* filp, const char __user *buf, size_t count, loff_t* f_pos) { struct vp_android_dev* dev = filp->private_data; ssize_t err = 0; /*同步访问*/ if(down_interruptible(&(dev->sem))) { return -ERESTARTSYS; } if(count != sizeof(dev->val)) { goto out; } /*将用户提供的缓冲区的值写到设备寄存器去*/ if(copy_from_user(&(dev->val), buf, count)) { err = -EFAULT; goto out; } err = sizeof(dev->val); out: up(&(dev->sem)); return err; } /******************************************* *define devfs access *******************************************/ /*读取寄存器lamp的值到缓冲区buf中,内部使用*/ static ssize_t __vp_get_lamp(struct vp_android_dev* dev, char* buf) { int lamp = 0; /*同步访问*/ if(down_interruptible(&(dev->sem))) { return -ERESTARTSYS; } lamp = dev->lamp; up(&(dev->sem)); return snprintf(buf, PAGE_SIZE, "%d\n", lamp); } /*把缓冲区buf的值写到设备寄存器lamp中去,内部使用*/ static ssize_t __vp_set_lamp(struct vp_android_dev* dev, const char* buf, size_t count) { int lamp = 0; /*将字符串转换成数字*/ lamp = simple_strtol(buf, NULL, 10); /*同步访问*/ if(down_interruptible(&(dev->sem))) { return -ERESTARTSYS; } dev->lamp = lamp; up(&(dev->sem)); return count; } /*读取设备属性lamp*/ static ssize_t vp_lamp_show(struct device* dev, struct device_attribute* attr, char* buf) { struct vp_android_dev* hdev = (struct vp_android_dev*)dev_get_drvdata(dev); return __vp_get_lamp(hdev, buf); } /*写设备属性lamp*/ static ssize_t vp_lamp_store(struct device* dev, struct device_attribute* attr, const char* buf, size_t count) { struct vp_android_dev* hdev = (struct vp_android_dev*)dev_get_drvdata(dev); return __vp_set_lamp(hdev, buf, count); } /******************************************* *define proc access *******************************************/ /*读取设备寄存器lamp的值,保存在page缓冲区中*/ static ssize_t vp_proc_read(char* page, char** start, off_t off, int count, int* eof, void* data) { if(off > 0) { *eof = 1; return 0; } return __vp_get_lamp(vp_dev, page); } /*把缓冲区的值buff保存到设备寄存器lamp中去*/ static ssize_t vp_proc_write(struct file* filp, const char __user *buff, unsigned long len, void* data) { int err = 0; char* page = NULL; if(len > PAGE_SIZE) { printk(KERN_ALERT"The buff is too large: %lu.\n", len); return -EFAULT; } page = (char*)__get_free_page(GFP_KERNEL); if(!page) { printk(KERN_ALERT"Failed to alloc page.\n"); return -ENOMEM; } /*先把用户提供的缓冲区值拷贝到内核缓冲区中去*/ if(copy_from_user(page, buff, len)) { printk(KERN_ALERT"Failed to copy buff from user.\n"); err = -EFAULT; goto out; } err = __vp_set_lamp(vp_dev, page, len); out: free_page((unsigned long)page); return err; } /*创建/proc/vp文件*/ static void vp_create_proc(void) { struct proc_dir_entry *entry; entry = create_proc_entry(VP_DEVICE_PROC_NAME, 0, NULL); if(entry) { entry->read_proc = vp_proc_read; entry->write_proc = vp_proc_write; } } /*删除/proc/vp文件*/ static void vp_remove_proc(void) { remove_proc_entry(VP_DEVICE_PROC_NAME, NULL); } /******************************************* *define load and remove function *******************************************/ /*初始化设备*/ static int __vp_setup_dev(struct vp_android_dev* dev) { int err; dev_t devno = MKDEV(vp_major, vp_minor); memset(dev, 0, sizeof(struct vp_android_dev)); cdev_init(&(dev->dev), &vp_fops); dev->dev.owner = THIS_MODULE; dev->dev.ops = &vp_fops; /*注册字符设备*/ err = cdev_add(&(dev->dev),devno, 1); if(err) { return err; } /*初始化信号量和寄存器lamp, val的值*/ sema_init(&(dev->sem), 1); dev->lamp = 7777; dev->val.toggle = 1; dev->val.virtual_latitude = 45.104108; dev->val.virtual_longitude = 130.816878; return 0; } /*模块加载方法*/ static int __init vp_init(void){ int err = -1; dev_t dev = 0; struct device* temp = NULL; printk(KERN_ALERT"Initializing vp device.\n"); /*动态分配主设备和从设备号*/ err = alloc_chrdev_region(&dev, 0, 1, VP_DEVICE_NODE_NAME); if(err < 0) { printk(KERN_ALERT"Failed to alloc char dev region.\n"); goto fail; } vp_major = MAJOR(dev); vp_minor = MINOR(dev); /*分配helo设备结构体变量*/ vp_dev = kmalloc(sizeof(struct vp_android_dev), GFP_KERNEL); if(!vp_dev) { err = -ENOMEM; printk(KERN_ALERT"Failed to alloc vp_dev.\n"); goto unregister; } /*初始化设备*/ err = __vp_setup_dev(vp_dev); if(err) { printk(KERN_ALERT"Failed to setup dev: %d.\n", err); goto cleanup; } /*在/sys/class/目录下创建设备类别目录vp*/ vp_class = class_create(THIS_MODULE, VP_DEVICE_CLASS_NAME); if(IS_ERR(vp_class)) { err = PTR_ERR(vp_class); printk(KERN_ALERT"Failed to create vp class.\n"); goto destroy_cdev; } /*在/dev/目录和/sys/class/vp目录下分别创建设备文件vp*/ temp = device_create(vp_class, NULL, dev, "%s", VP_DEVICE_FILE_NAME); if(IS_ERR(temp)) { err = PTR_ERR(temp); printk(KERN_ALERT"Failed to create vp device."); goto destroy_class; } /*在/sys/class/vp/vp目录下创建属性文件val*/ err = device_create_file(temp, &dev_attr_val); if(err < 0) { printk(KERN_ALERT"Failed to create attribute val."); goto destroy_device; } dev_set_drvdata(temp, vp_dev); /*创建/proc/vp文件*/ vp_create_proc(); printk(KERN_ALERT"Succedded to initialize vp device.\n"); return 0; destroy_device: device_destroy(vp_class, dev); destroy_class: class_destroy(vp_class); destroy_cdev: cdev_del(&(vp_dev->dev)); cleanup: kfree(vp_dev); unregister: unregister_chrdev_region(MKDEV(vp_major, vp_minor), 1); fail: return err; } /*模块卸载方法*/ static void __exit vp_exit(void) { dev_t devno = MKDEV(vp_major, vp_minor); printk(KERN_ALERT"Destroy vp device.\n"); /*删除/proc/vp文件*/ vp_remove_proc(); /*销毁设备类别和设备*/ if(vp_class) { device_destroy(vp_class, MKDEV(vp_major, vp_minor)); class_destroy(vp_class); } /*删除字符设备和释放设备内存*/ if(vp_dev) { cdev_del(&(vp_dev->dev)); kfree(vp_dev); } /*释放设备号*/ unregister_chrdev_region(devno, 1); } MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Virtualposition Driver"); module_init(vp_init); module_exit(vp_exit); ================================================ FILE: VirtualPosition/vp_KernelDriver/vp/vp.h ================================================ #ifndef _VP_ANDROID_H_ #define _VP_ANDROID_H_ #include #include #define VP_DEVICE_NODE_NAME "vp" #define VP_DEVICE_FILE_NAME "vp" #define VP_DEVICE_PROC_NAME "vp" #define VP_DEVICE_CLASS_NAME "vp" typedef struct { int toggle; double virtual_latitude; double virtual_longitude; } VirtualPosition; struct vp_android_dev { int lamp; VirtualPosition val; struct semaphore sem; struct cdev dev; }; #endif