Full Code of aggresss/PHDemo for AI

master 9108e3c9a665 cached
64 files
322.9 KB
83.1k tokens
223 symbols
1 requests
Download .txt
Showing preview only (347K chars total). Download the full file or copy to clipboard to get everything.
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
================================================
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.phdemo.myapplication">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


================================================
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
================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="center">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:text="@string/value"
        android:textSize="50dp">
    </TextView>
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/edit_value"
        android:hint="@string/hint">
    </EditText>
</LinearLayout>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center">
    <Button
        android:id="@+id/button_read"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/read">
    </Button>
    <Button
        android:id="@+id/button_write"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/write">
    </Button>
    <Button
        android:id="@+id/button_clear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/clear">
    </Button>
</LinearLayout>
</LinearLayout>

================================================
FILE: Code/hello_APP/Hello/res/values/colors.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
</resources>


================================================
FILE: Code/hello_APP/Hello/res/values/dimens.xml
================================================
<resources>
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
</resources>


================================================
FILE: Code/hello_APP/Hello/res/values/strings.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Hello</string>
    <string name="value">Value</string>
    <string name="hint">Please input a value...</string>
    <string name="read">Read</string>
    <string name="write">Write</string>
    <string name="clear">Clear</string>
</resources>

================================================
FILE: Code/hello_APP/Hello/res/values-w820dp/dimens.xml
================================================
<resources>
    <!-- Example customization of dimensions originally defined in res/values/dimens.xml
         (such as screen margins) for screens with more than 820dp of available width. This
         would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
    <dimen name="activity_horizontal_margin">64dp</dimen>
</resources>


================================================
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 <stdio.h>  
#include <stdlib.h>  
#include <fcntl.h>  
#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 <hardware/hardware.h>  
#include <hardware/hello.h>  
#include <fcntl.h>  
#include <errno.h>  
#include <cutils/log.h>  
#include <cutils/atomic.h>  
  
#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 <hardware/hardware.h>  
  
__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 <utils/misc.h>  
#include <utils/Log.h>  
#include <hardware/hardware.h>  
#include <hardware/hello.h>  
#include <stdio.h>  

namespace android  
{  
    /*在硬件抽象层中定义的硬件访问结构体,参考<hardware/hello.h>*/  
        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 <linux/init.h>  
#include <linux/module.h>  
#include <linux/types.h>  
#include <linux/fs.h>  
#include <linux/proc_fs.h>  
#include <linux/device.h>  
#include <asm/uaccess.h>  
  
#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 <linux/cdev.h>  
#include <linux/semaphore.h>  
  
#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 <transfer_list> <system_new_file> [system_img]\n')
    print('    <transfer_list>: transfer list file')
    print('    <system_new_file>: 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 <fcntl.h>  
#include <arpa/inet.h>
#include <string.h>
#include <pthread.h>
#include <linux/in.h>
#include <linux/in6.h>

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, "<init>", "()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, "<init>", "()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,
                "<init>",
                "(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, "<init>", "()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,
                "<init>",
                "(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
================================================
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.phdemo.myapplication">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


================================================
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
================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:text="@string/toggle"
            android:textSize="40dp">

        </TextView>
        <ToggleButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/toggle"
            android:id="@+id/toggleButton"
            android:layout_gravity="center_horizontal" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:text="@string/altitude"
            android:textSize="40dp">

        </TextView>

        <EditText
            android:id="@+id/altitude_value"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_altitude">

        </EditText>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:text="@string/longitude"
            android:textSize="40dp">

        </TextView>

        <EditText
            android:id="@+id/longitude_value"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_longitude">

        </EditText>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">

        <Button
            android:id="@+id/button_get"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/get">

        </Button>

        <Button
            android:id="@+id/button_set"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/set">

        </Button>

        <Button
            android:id="@+id/button_clear"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/clear">

        </Button>
    </LinearLayout>
</LinearLayout>


================================================
FILE: VirtualPosition/vp_APP/VirtualPosition/res/values/colors.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
</resources>


================================================
FILE: VirtualPosition/vp_APP/VirtualPosition/res/values/dimens.xml
================================================
<resources>
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
</resources>


================================================
FILE: VirtualPosition/vp_APP/VirtualPosition/res/values/strings.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">VirtualPosition</string>
    <string name="altitude">_altitude_</string>
    <string name="longitude">longitude</string>
    <string name="toggle">toggle</string>
    <string name="hint_altitude">Input altitude</string>
    <string name="hint_longitude">Input longitude</string>
    <string name="get">GET</string>
    <string name="set">SET</string>
    <string name="clear">CLEAR</string>
</resources>


================================================
FILE: VirtualPosition/vp_APP/VirtualPosition/res/values-w820dp/dimens.xml
================================================
<resources>
    <!-- Example customization of dimensions originally defined in res/values/dimens.xml
         (such as screen margins) for screens with more than 820dp of available width. This
         would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
    <dimen name="activity_horizontal_margin">64dp</dimen>
</resources>


================================================
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.
Download .txt
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
Download .txt
SYMBOL INDEX (223 symbols across 19 files)

FILE: Code/hello_APP/Hello/java/com/example/phdemo/myapplication/MainActivity.java
  class MainActivity (line 15) | public class MainActivity extends Activity implements View.OnClickListen...
    method onCreate (line 27) | @Override
    method onClick (line 47) | @Override

FILE: Code/hello_Execute/hello.c
  function main (line 5) | int main(int argc, char** argv)

FILE: Code/hello_Framework/HelloService.java
  class HelloService (line 6) | public class HelloService extends IHelloService.Stub {
    method HelloService (line 8) | HelloService() {
    method setVal (line 11) | public void setVal(int val) {
    method getVal (line 14) | public int getVal() {
    method init_native (line 18) | private static native boolean init_native();
    method setVal_native (line 19) | private static native void setVal_native(int val);
    method getVal_native (line 20) | private static native int getVal_native();

FILE: Code/hello_HAL/hello.c
  type hw_module_t (line 15) | struct hw_module_t
  type hw_device_t (line 15) | struct hw_device_t
  type hw_device_t (line 16) | struct hw_device_t
  type hello_device_t (line 19) | struct hello_device_t
  type hello_device_t (line 20) | struct hello_device_t
  type hw_module_methods_t (line 23) | struct hw_module_methods_t
  type hello_module_t (line 28) | struct hello_module_t
  function hello_device_open (line 41) | static int hello_device_open(const struct hw_module_t* module, const cha...
  function hello_device_close (line 67) | static int hello_device_close(struct hw_device_t* device) {
  function hello_set_val (line 78) | static int hello_set_val(struct hello_device_t* dev, int val) {
  function hello_get_val (line 86) | static int hello_get_val(struct hello_device_t* dev, int* val) {

FILE: Code/hello_HAL/hello.h
  type hello_module_t (line 11) | struct hello_module_t {
  type hello_device_t (line 16) | struct hello_device_t {

FILE: Code/hello_JNI/com_android_server_HelloService.cpp
  type android (line 11) | namespace android
    type hello_device_t (line 14) | struct hello_device_t
    function hello_setVal (line 16) | static void hello_setVal(JNIEnv* env, jobject clazz, jint value) {
    function jint (line 27) | static jint hello_getVal(JNIEnv* env, jobject clazz) {
    function hello_device_open (line 40) | static inline int hello_device_open(const hw_module_t* module, struct ...
    function jboolean (line 44) | static jboolean hello_init(JNIEnv* env, jclass clazz) {
    function register_android_server_HelloService (line 67) | int register_android_server_HelloService(JNIEnv *env) {

FILE: Code/hello_KernelDriver/hello.c
  type class (line 19) | struct class
  type hello_android_dev (line 20) | struct hello_android_dev
  type inode (line 23) | struct inode
  type file (line 23) | struct file
  type inode (line 24) | struct inode
  type file (line 24) | struct file
  type file (line 25) | struct file
  type file (line 26) | struct file
  type file_operations (line 29) | struct file_operations
  type device (line 38) | struct device
  type device_attribute (line 38) | struct device_attribute
  type device (line 39) | struct device
  type device_attribute (line 39) | struct device_attribute
  function hello_open (line 48) | static int hello_open(struct inode* inode, struct file* filp) {
  function hello_release (line 59) | static int hello_release(struct inode* inode, struct file* filp) {
  function hello_read (line 64) | static ssize_t hello_read(struct file* filp, char __user *buf, size_t co...
  function hello_write (line 91) | static ssize_t hello_write(struct file* filp, const char __user *buf, si...
  function __hello_get_val (line 121) | static ssize_t __hello_get_val(struct hello_android_dev* dev, char* buf) {
  function __hello_set_val (line 136) | static ssize_t __hello_set_val(struct hello_android_dev* dev, const char...
  function hello_val_show (line 154) | static ssize_t hello_val_show(struct device* dev, struct device_attribut...
  function hello_val_store (line 161) | static ssize_t hello_val_store(struct device* dev, struct device_attribu...
  function hello_proc_read (line 171) | static ssize_t hello_proc_read(char* page, char** start, off_t off, int ...
  function hello_proc_write (line 181) | static ssize_t hello_proc_write(struct file* filp, const char __user *bu...
  function hello_create_proc (line 211) | static void hello_create_proc(void) {
  function hello_remove_proc (line 222) | static void hello_remove_proc(void) {
  function __hello_setup_dev (line 230) | static int  __hello_setup_dev(struct hello_android_dev* dev) {
  function hello_init (line 254) | static int __init hello_init(void){
  function hello_exit (line 337) | static void __exit hello_exit(void) {

FILE: Code/hello_KernelDriver/hello.h
  type hello_android_dev (line 12) | struct hello_android_dev {

FILE: Tools/sdat2img.py
  function rangeset (line 45) | def rangeset(src):
  function parse_transfer_list_file (line 54) | def parse_transfer_list_file(path):
  function main (line 86) | def main(argv):

FILE: VirtualPosition/Modification/com_android_server_location_GpsLocationProvider.cpp
  type android (line 78) | namespace android {
    function checkAndClearExceptionFromCallback (line 85) | static void checkAndClearExceptionFromCallback(JNIEnv* env, const char...
    function location_callback (line 93) | static void location_callback(GpsLocation* location)
    function status_callback (line 116) | static void status_callback(GpsStatus* status)
    function sv_status_callback (line 123) | static void sv_status_callback(GpsSvStatus* sv_status)
    function nmea_callback (line 131) | static void nmea_callback(GpsUtcTime timestamp, const char* nmea, int ...
    function set_capabilities_callback (line 142) | static void set_capabilities_callback(uint32_t capabilities)
    function acquire_wakelock_callback (line 150) | static void acquire_wakelock_callback()
    function release_wakelock_callback (line 155) | static void release_wakelock_callback()
    function request_utc_time_callback (line 160) | static void request_utc_time_callback()
    function pthread_t (line 167) | static pthread_t create_thread_callback(const char* name, void (*start...
    function xtra_download_request_callback (line 185) | static void xtra_download_request_callback()
    function jbyteArray (line 197) | static jbyteArray convert_to_ipv4(uint32_t ip, bool net_order)
    function agps_status_callback (line 227) | static void agps_status_callback(AGpsStatus* agps_status)
    function gps_ni_notify_callback (line 316) | static void gps_ni_notify_callback(GpsNiNotification *notification)
    function agps_request_set_id (line 349) | static void agps_request_set_id(uint32_t flags)
    function agps_request_ref_location (line 356) | static void agps_request_ref_location(uint32_t flags)
    function gps_geofence_transition_callback (line 369) | static void gps_geofence_transition_callback(int32_t geofence_id,  Gps...
    function gps_geofence_status_callback (line 383) | static void gps_geofence_status_callback(int32_t status, GpsLocation* ...
    function gps_geofence_add_callback (line 410) | static void gps_geofence_add_callback(int32_t geofence_id, int32_t sta...
    function gps_geofence_remove_callback (line 420) | static void gps_geofence_remove_callback(int32_t geofence_id, int32_t ...
    function gps_geofence_resume_callback (line 430) | static void gps_geofence_resume_callback(int32_t geofence_id, int32_t ...
    function gps_geofence_pause_callback (line 440) | static void gps_geofence_pause_callback(int32_t geofence_id, int32_t s...
    function android_location_GpsLocationProvider_class_init_native (line 460) | static void android_location_GpsLocationProvider_class_init_native(JNI...
    function jboolean (line 530) | static jboolean android_location_GpsLocationProvider_is_supported(
    function jboolean (line 536) | static jboolean android_location_GpsLocationProvider_is_agps_ril_suppo...
    function jboolean (line 542) | static jboolean android_location_gpsLocationProvider_is_gnss_configura...
    function jboolean (line 548) | static jboolean android_location_GpsLocationProvider_init(JNIEnv* env,...
    function android_location_GpsLocationProvider_cleanup (line 574) | static void android_location_GpsLocationProvider_cleanup(JNIEnv* /* en...
    function jboolean (line 580) | static jboolean android_location_GpsLocationProvider_set_position_mode...
    function jboolean (line 596) | static jboolean android_location_GpsLocationProvider_start(JNIEnv* /* ...
    function jboolean (line 609) | static jboolean android_location_GpsLocationProvider_stop(JNIEnv* /* e...
    function android_location_GpsLocationProvider_delete_aiding_data (line 622) | static void android_location_GpsLocationProvider_delete_aiding_data(JN...
    function jint (line 630) | static jint android_location_GpsLocationProvider_read_sv_status(JNIEnv...
    function android_location_GpsLocationProvider_agps_set_reference_location_cellid (line 661) | static void android_location_GpsLocationProvider_agps_set_reference_lo...
    function android_location_GpsLocationProvider_agps_send_ni_message (line 693) | static void android_location_GpsLocationProvider_agps_send_ni_message(...
    function android_location_GpsLocationProvider_agps_set_id (line 710) | static void android_location_GpsLocationProvider_agps_set_id(JNIEnv *e...
    function jint (line 723) | static jint android_location_GpsLocationProvider_read_nmea(JNIEnv* env...
    function android_location_GpsLocationProvider_inject_time (line 736) | static void android_location_GpsLocationProvider_inject_time(JNIEnv* /...
    function android_location_GpsLocationProvider_inject_location (line 743) | static void android_location_GpsLocationProvider_inject_location(JNIEn...
    function jboolean (line 750) | static jboolean android_location_GpsLocationProvider_supports_xtra(
    function android_location_GpsLocationProvider_inject_xtra_data (line 756) | static void android_location_GpsLocationProvider_inject_xtra_data(JNIE...
    function android_location_GpsLocationProvider_agps_data_conn_open (line 769) | static void android_location_GpsLocationProvider_agps_data_conn_open(
    function android_location_GpsLocationProvider_agps_data_conn_closed (line 795) | static void android_location_GpsLocationProvider_agps_data_conn_closed...
    function android_location_GpsLocationProvider_agps_data_conn_failed (line 805) | static void android_location_GpsLocationProvider_agps_data_conn_failed...
    function android_location_GpsLocationProvider_set_agps_server (line 815) | static void android_location_GpsLocationProvider_set_agps_server(JNIEn...
    function android_location_GpsLocationProvider_send_ni_response (line 827) | static void android_location_GpsLocationProvider_send_ni_response(JNIE...
    function jstring (line 838) | static jstring android_location_GpsLocationProvider_get_internal_state...
    function android_location_GpsLocationProvider_update_network_state (line 852) | static void android_location_GpsLocationProvider_update_network_state(...
    function jboolean (line 875) | static jboolean android_location_GpsLocationProvider_is_geofence_suppo...
    function jboolean (line 881) | static jboolean android_location_GpsLocationProvider_add_geofence(JNIE...
    function jboolean (line 896) | static jboolean android_location_GpsLocationProvider_remove_geofence(J...
    function jboolean (line 907) | static jboolean android_location_GpsLocationProvider_pause_geofence(JN...
    function jboolean (line 918) | static jboolean android_location_GpsLocationProvider_resume_geofence(J...
    function jobject (line 929) | static jobject translate_gps_clock(JNIEnv* env, GpsClock* clock) {
    function jobject (line 988) | static jobject translate_gps_measurement(JNIEnv* env, GpsMeasurement* ...
    function jobjectArray (line 1235) | static jobjectArray translate_gps_measurements(JNIEnv* env, GpsData* d...
    function measurement_callback (line 1258) | static void measurement_callback(GpsData* data) {
    function jboolean (line 1298) | static jboolean android_location_GpsLocationProvider_is_measurement_su...
    function jboolean (line 1307) | static jboolean android_location_GpsLocationProvider_start_measurement...
    function jboolean (line 1324) | static jboolean android_location_GpsLocationProvider_stop_measurement_...
    function jobject (line 1336) | static jobject translate_gps_navigation_message(JNIEnv* env, GpsNaviga...
    function navigation_message_callback (line 1371) | static void navigation_message_callback(GpsNavigationMessage* message) {
    function jboolean (line 1408) | static jboolean android_location_GpsLocationProvider_is_navigation_mes...
    function jboolean (line 1417) | static jboolean android_location_GpsLocationProvider_start_navigation_...
    function jboolean (line 1434) | static jboolean android_location_GpsLocationProvider_stop_navigation_m...
    function android_location_GpsLocationProvider_configuration_update (line 1446) | static void android_location_GpsLocationProvider_configuration_update(...
    function register_android_server_location_GpsLocationProvider (line 1556) | int register_android_server_location_GpsLocationProvider(JNIEnv* env)

FILE: VirtualPosition/vp_APP/VirtualPosition/java/com/example/phdemo/myapplication/MainActivity.java
  class MainActivity (line 18) | public class MainActivity extends Activity implements View.OnClickListen...
    method onCreate (line 31) | @Override
    method onClick (line 70) | @Override

FILE: VirtualPosition/vp_Framework/SystemServer.java
  class SystemServer (line 110) | public final class SystemServer {
    method startSensorService (line 170) | private static native void startSensorService();
    method main (line 175) | public static void main(String[] args) {
    method SystemServer (line 179) | public SystemServer() {
    class AdbPortObserver (line 184) | private class AdbPortObserver extends ContentObserver {
      method AdbPortObserver (line 185) | public AdbPortObserver() {
      method onChange (line 188) | @Override
    method run (line 197) | private void run() {
    method reportWtf (line 308) | private void reportWtf(String msg, Throwable e) {
    method performPendingShutdown (line 313) | private void performPendingShutdown() {
    method createSystemContext (line 330) | private void createSystemContext() {
    method startBootstrapServices (line 343) | private void startBootstrapServices() {
    method startCoreServices (line 409) | private void startCoreServices() {
    method startOtherServices (line 428) | private void startOtherServices() {
    method startSystemUi (line 1311) | static final void startSystemUi(Context context) {

FILE: VirtualPosition/vp_Framework/VirtualPositionService.java
  class VirtualPositionService (line 6) | public class VirtualPositionService extends IVirtualPositionService.Stub {
    method VirtualPositionService (line 8) | VirtualPositionService() {
    method setVirtualToggle (line 11) | public void setVirtualToggle(int tog) {
    method getVirtualToggle (line 15) | public int getVirtualToggle(){
    method setVirtualLatitude (line 19) | public void setVirtualLatitude(double vlat) {
    method getVirtualLatitude (line 23) | public double getVirtualLatitude(){
    method setVirtualLongitude (line 27) | public void setVirtualLongitude(double vlon) {
    method getVirtualLongitude (line 31) | public double getVirtualLongitude() {
    method init_native (line 35) | private static native boolean init_native();
    method native_set_virtual_toggle (line 36) | private static native void native_set_virtual_toggle(int tog);
    method native_get_virtual_toggle (line 37) | private static native int native_get_virtual_toggle();
    method native_set_virtual_latitude (line 38) | private static native void native_set_virtual_latitude(double vlat);
    method native_get_virtual_latitude (line 39) | private static native double native_get_virtual_latitude();
    method native_set_virtual_longitude (line 40) | private static native void native_set_virtual_longitude(double vlon);
    method native_get_virtual_longitude (line 41) | private static native double native_get_virtual_longitude();

FILE: VirtualPosition/vp_HAL/vp.h
  type VirtualPosition (line 12) | typedef struct {
  type vp_module_t (line 21) | struct vp_module_t {
  type vp_device_t (line 26) | struct vp_device_t {

FILE: VirtualPosition/vp_HAL/vp/vp.c
  type hw_module_t (line 15) | struct hw_module_t
  type hw_device_t (line 15) | struct hw_device_t
  type hw_device_t (line 16) | struct hw_device_t
  type vp_device_t (line 19) | struct vp_device_t
  type vp_device_t (line 20) | struct vp_device_t
  type hw_module_methods_t (line 23) | struct hw_module_methods_t
  type vp_module_t (line 28) | struct vp_module_t
  function vp_device_open (line 41) | static int vp_device_open(const struct hw_module_t* module, const char* ...
  function vp_device_close (line 67) | static int vp_device_close(struct hw_device_t* device) {
  function vp_set_val (line 78) | static int vp_set_val(struct vp_device_t* dev, VirtualPosition val) {
  function vp_get_val (line 86) | static int vp_get_val(struct vp_device_t* dev, VirtualPosition* val) {

FILE: VirtualPosition/vp_JNI/com_android_server_VirtualPositionService.cpp
  type android (line 11) | namespace android
    type vp_device_t (line 16) | struct vp_device_t
    function vp_setVal (line 18) | static void vp_setVal() {
    function vp_getVal (line 28) | static void vp_getVal() {
    function vp_device_open (line 37) | static inline int vp_device_open(const hw_module_t* module, struct vp_...
    function jboolean (line 41) | static jboolean vp_init(JNIEnv* env, jclass clazz) {
    function android_server_VirtualPositionService_set_virtual_toggle (line 58) | static void android_server_VirtualPositionService_set_virtual_toggle(J...
    function jint (line 64) | static jint android_server_VirtualPositionService_get_virtual_toggle(J...
    function android_server_VirtualPositionService_set_virtual_latitude (line 70) | static void android_server_VirtualPositionService_set_virtual_latitude...
    function jdouble (line 76) | static jdouble android_server_VirtualPositionService_get_virtual_latit...
    function android_server_VirtualPositionService_set_virtual_longitude (line 82) | static void android_server_VirtualPositionService_set_virtual_longitud...
    function jdouble (line 88) | static jdouble android_server_VirtualPositionService_get_virtual_longi...
    function register_android_server_VirtualPositionService (line 122) | int register_android_server_VirtualPositionService(JNIEnv *env) {

FILE: VirtualPosition/vp_JNI/onload.cpp
  type android (line 22) | namespace android {
  function jint (line 51) | jint JNI_OnLoad(JavaVM* vm, void* /* reserved */)

FILE: VirtualPosition/vp_KernelDriver/vp/vp.c
  type class (line 19) | struct class
  type vp_android_dev (line 20) | struct vp_android_dev
  type inode (line 23) | struct inode
  type file (line 23) | struct file
  type inode (line 24) | struct inode
  type file (line 24) | struct file
  type file (line 25) | struct file
  type file (line 26) | struct file
  type file_operations (line 29) | struct file_operations
  type device (line 38) | struct device
  type device_attribute (line 38) | struct device_attribute
  type device (line 39) | struct device
  type device_attribute (line 39) | struct device_attribute
  function vp_open (line 48) | static int vp_open(struct inode* inode, struct file* filp) {
  function vp_release (line 59) | static int vp_release(struct inode* inode, struct file* filp) {
  function vp_read (line 64) | static ssize_t vp_read(struct file* filp, char __user *buf, size_t count...
  function vp_write (line 91) | static ssize_t vp_write(struct file* filp, const char __user *buf, size_...
  function __vp_get_lamp (line 121) | static ssize_t __vp_get_lamp(struct vp_android_dev* dev, char* buf) {
  function __vp_set_lamp (line 136) | static ssize_t __vp_set_lamp(struct vp_android_dev* dev, const char* buf...
  function vp_lamp_show (line 154) | static ssize_t vp_lamp_show(struct device* dev, struct device_attribute*...
  function vp_lamp_store (line 161) | static ssize_t vp_lamp_store(struct device* dev, struct device_attribute...
  function vp_proc_read (line 171) | static ssize_t vp_proc_read(char* page, char** start, off_t off, int cou...
  function vp_proc_write (line 181) | static ssize_t vp_proc_write(struct file* filp, const char __user *buff,...
  function vp_create_proc (line 211) | static void vp_create_proc(void) {
  function vp_remove_proc (line 222) | static void vp_remove_proc(void) {
  function __vp_setup_dev (line 230) | static int  __vp_setup_dev(struct vp_android_dev* dev) {
  function vp_init (line 257) | static int __init vp_init(void){
  function vp_exit (line 340) | static void __exit vp_exit(void) {

FILE: VirtualPosition/vp_KernelDriver/vp/vp.h
  type VirtualPosition (line 12) | typedef struct {
  type vp_android_dev (line 19) | struct vp_android_dev {
Condensed preview — 64 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (349K chars).
[
  {
    "path": ".gitignore",
    "chars": 23,
    "preview": "*.o\n*.order\n*.o.cmd\n*~\n"
  },
  {
    "path": "Code/device/test/myproduct/AndroidProducts.mk",
    "chars": 50,
    "preview": "PRODUCT_MAKEFILES := \\\n\t$(LOCAL_DIR)/myproduct.mk\n"
  },
  {
    "path": "Code/device/test/myproduct/myproduct.mk",
    "chars": 591,
    "preview": "# This is a build configuration for a full-featured build of the\n# Open-Source part of the tree. It's geared toward a US"
  },
  {
    "path": "Code/device/test/myproduct/phdemo/AndroidBoard.mk",
    "chars": 29,
    "preview": "LOCAL_PATH := $(call my-dir)\n"
  },
  {
    "path": "Code/device/test/myproduct/phdemo/BoardConfig.mk",
    "chars": 3173,
    "preview": "# config.mk\n#\n# Product-specific compile-time definitions.\n#\n\n# The generic product target doesn't have any hardware-spe"
  },
  {
    "path": "Code/device/test/myproduct/phdemo/system.prop",
    "chars": 108,
    "preview": "#\n# system.prop for generic sdk \n#\n\nrild.libpath=/system/lib/libreference-ril.so\nrild.libargs=-d /dev/ttyS0\n"
  },
  {
    "path": "Code/device/test/myproduct/vendorsetup.sh",
    "chars": 30,
    "preview": "add_lunch_combo myproduct-eng\n"
  },
  {
    "path": "Code/hello_APP/Hello/Android.mk",
    "chars": 182,
    "preview": "LOCAL_PATH:= $(call my-dir)\ninclude $(CLEAR_VARS)\nLOCAL_MODULE_TAGS := optional\nLOCAL_SRC_FILES := $(call all-subdir-jav"
  },
  {
    "path": "Code/hello_APP/Hello/AndroidManifest.xml",
    "chars": 633,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    package="
  },
  {
    "path": "Code/hello_APP/Hello/java/com/example/phdemo/myapplication/MainActivity.java",
    "chars": 2388,
    "preview": "package com.example.phdemo.myapplication;\n\nimport android.os.RemoteException;\nimport android.app.Activity;\nimport androi"
  },
  {
    "path": "Code/hello_APP/Hello/res/layout/activity_main.xml",
    "chars": 1529,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\nandroid:"
  },
  {
    "path": "Code/hello_APP/Hello/res/values/colors.xml",
    "chars": 208,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <color name=\"colorPrimary\">#3F51B5</color>\n    <color name=\"color"
  },
  {
    "path": "Code/hello_APP/Hello/res/values/dimens.xml",
    "chars": 211,
    "preview": "<resources>\n    <!-- Default screen margins, per the Android Design guidelines. -->\n    <dimen name=\"activity_horizontal"
  },
  {
    "path": "Code/hello_APP/Hello/res/values/strings.xml",
    "chars": 321,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <string name=\"app_name\">Hello</string>\n    <string name=\"value\">V"
  },
  {
    "path": "Code/hello_APP/Hello/res/values-w820dp/dimens.xml",
    "chars": 358,
    "preview": "<resources>\n    <!-- Example customization of dimensions originally defined in res/values/dimens.xml\n         (such as s"
  },
  {
    "path": "Code/hello_Execute/Android.mk",
    "chars": 177,
    "preview": "LOCAL_PATH := $(call my-dir)\ninclude $(CLEAR_VARS)\nLOCAL_MODULE_TAGS := optional\nLOCAL_MODULE := hello\nLOCAL_SRC_FILES :"
  },
  {
    "path": "Code/hello_Execute/hello.c",
    "chars": 711,
    "preview": "#include <stdio.h>  \n#include <stdlib.h>  \n#include <fcntl.h>  \n#define DEVICE_NAME \"/dev/hello\"  \nint main(int argc, ch"
  },
  {
    "path": "Code/hello_Framework/HelloService.java",
    "chars": 617,
    "preview": "package com.android.server;  \nimport android.content.Context;  \nimport android.os.IHelloService;  \nimport android.util.S"
  },
  {
    "path": "Code/hello_Framework/IHelloService.aidl",
    "chars": 106,
    "preview": "package android.os;  \n   \ninterface IHelloService {  \n    void setVal(int val);  \n    int getVal();  \n}  \n"
  },
  {
    "path": "Code/hello_Framework/sepolicy/device.te",
    "chars": 3021,
    "preview": "# Device types\ntype device, dev_type, fs_type;\ntype alarm_device, dev_type, mlstrustedobject;\ntype adb_device, dev_type;"
  },
  {
    "path": "Code/hello_Framework/sepolicy/file_contexts",
    "chars": 13968,
    "preview": "###########################################\n# Root\n/\t\t\tu:object_r:rootfs:s0\n\n# Data files\n/adb_keys\t\tu:object_r:adb_keys"
  },
  {
    "path": "Code/hello_Framework/sepolicy/service.te",
    "chars": 8477,
    "preview": "type bluetooth_service,         service_manager_type;\ntype default_android_service,   service_manager_type;\ntype drmserv"
  },
  {
    "path": "Code/hello_Framework/sepolicy/service_contexts",
    "chars": 9781,
    "preview": "accessibility                             u:object_r:accessibility_service:s0\naccount                                   "
  },
  {
    "path": "Code/hello_Framework/sepolicy/system_server.te",
    "chars": 17640,
    "preview": "#\n# System Server aka system_server spawned by zygote.\n# Most of the framework services run in this process.\n#\ntype syst"
  },
  {
    "path": "Code/hello_HAL/Android.mk",
    "chars": 296,
    "preview": "LOCAL_PATH := $(call my-dir)\n\tinclude $(CLEAR_VARS)\n\tLOCAL_MODULE_TAGS := optional\n\tLOCAL_PRELINK_MODULE := false\n\tLOCAL"
  },
  {
    "path": "Code/hello_HAL/hello.c",
    "chars": 2766,
    "preview": "#define LOG_TAG \"HelloStub\"  \n  \n#include <hardware/hardware.h>  \n#include <hardware/hello.h>  \n#include <fcntl.h>  \n#in"
  },
  {
    "path": "Code/hello_HAL/hello.h",
    "chars": 508,
    "preview": " #ifndef ANDROID_HELLO_INTERFACE_H  \n#define ANDROID_HELLO_INTERFACE_H  \n#include <hardware/hardware.h>  \n  \n__BEGIN_DEC"
  },
  {
    "path": "Code/hello_JNI/com_android_server_HelloService.cpp",
    "chars": 2646,
    "preview": "#define LOG_TAG \"HelloService\"  \n#include \"jni.h\"  \n#include \"JNIHelp.h\"  \n#include \"android_runtime/AndroidRuntime.h\"  "
  },
  {
    "path": "Code/hello_KernelDriver/Kconfig",
    "chars": 139,
    "preview": " config HELLO\n           tristate \"First Android Driver\"\n           default n\n           help\n           This is the fir"
  },
  {
    "path": "Code/hello_KernelDriver/Makefile",
    "chars": 31,
    "preview": "obj-$(CONFIG_HELLO) += hello.o\n"
  },
  {
    "path": "Code/hello_KernelDriver/hello.c",
    "chars": 9995,
    "preview": "/*******************************************\n*include file and define functions\n****************************************"
  },
  {
    "path": "Code/hello_KernelDriver/hello.h",
    "chars": 402,
    "preview": "#ifndef _HELLO_ANDROID_H_  \n#define _HELLO_ANDROID_H_  \n  \n#include <linux/cdev.h>  \n#include <linux/semaphore.h>  \n  \n#"
  },
  {
    "path": "README.md",
    "chars": 1730,
    "preview": "# PHDemo\n#### 《手机就是开发板》 目录\n##### 第一期 前言 http://blog.csdn.net/aggresss/article/details/53364324\n##### 第二期 AOSP 环境搭建、下载和编译"
  },
  {
    "path": "Tools/51-android.rules",
    "chars": 390,
    "preview": "#Mi3W normal mode\nSUBSYSTEM==\"usb\",ATTR{idVendor}==\"2717\",ATTR{idProduct}==\"0360\",MODE=\"0666\"\n#Mi3W developer mode\nSUBSY"
  },
  {
    "path": "Tools/cancro/proprietary-files.txt",
    "chars": 17791,
    "preview": "etc/sdm_200_HOG3x3_Grid3x3_bin5_noproj_zero_reduced.bin.pca\netc/android_model_faceg.dat\netc/permissions/qcrilhook.xml\net"
  },
  {
    "path": "Tools/sdat2img.py",
    "chars": 4654,
    "preview": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#====================================================\n#          FILE: sda"
  },
  {
    "path": "VirtualPosition/Modification/com_android_server_location_GpsLocationProvider.cpp",
    "chars": 60263,
    "preview": "/*\n * Copyright (C) 2008 The Android Open Source Project\n *\n * Licensed under the Apache License, Version 2.0 (the \"Lice"
  },
  {
    "path": "VirtualPosition/vp_APP/VirtualPosition/Android.mk",
    "chars": 192,
    "preview": "LOCAL_PATH:= $(call my-dir)\ninclude $(CLEAR_VARS)\nLOCAL_MODULE_TAGS := optional\nLOCAL_SRC_FILES := $(call all-subdir-jav"
  },
  {
    "path": "VirtualPosition/vp_APP/VirtualPosition/AndroidManifest.xml",
    "chars": 633,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    package="
  },
  {
    "path": "VirtualPosition/vp_APP/VirtualPosition/java/com/example/phdemo/myapplication/MainActivity.java",
    "chars": 4393,
    "preview": "package com.example.phdemo.myapplication;\r\n\r\nimport android.os.RemoteException;\r\nimport android.app.Activity;\r\nimport an"
  },
  {
    "path": "VirtualPosition/vp_APP/VirtualPosition/res/layout/activity_main.xml",
    "chars": 3050,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    andr"
  },
  {
    "path": "VirtualPosition/vp_APP/VirtualPosition/res/values/colors.xml",
    "chars": 208,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <color name=\"colorPrimary\">#3F51B5</color>\n    <color name=\"color"
  },
  {
    "path": "VirtualPosition/vp_APP/VirtualPosition/res/values/dimens.xml",
    "chars": 211,
    "preview": "<resources>\n    <!-- Default screen margins, per the Android Design guidelines. -->\n    <dimen name=\"activity_horizontal"
  },
  {
    "path": "VirtualPosition/vp_APP/VirtualPosition/res/values/strings.xml",
    "chars": 483,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <string name=\"app_name\">VirtualPosition</string>\n    <string name"
  },
  {
    "path": "VirtualPosition/vp_APP/VirtualPosition/res/values-w820dp/dimens.xml",
    "chars": 358,
    "preview": "<resources>\n    <!-- Example customization of dimensions originally defined in res/values/dimens.xml\n         (such as s"
  },
  {
    "path": "VirtualPosition/vp_Framework/IVirtualPositionService.aidl",
    "chars": 275,
    "preview": "package android.os;\n\ninterface IVirtualPositionService {\n    void setVirtualToggle(int tog);\n    int getVirtualToggle();"
  },
  {
    "path": "VirtualPosition/vp_Framework/SystemServer.java",
    "chars": 57786,
    "preview": "/*\n * Copyright (C) 2006 The Android Open Source Project\n *\n * Licensed under the Apache License, Version 2.0 (the \"Lice"
  },
  {
    "path": "VirtualPosition/vp_Framework/VirtualPositionService.java",
    "chars": 1376,
    "preview": "package com.android.server;  \nimport android.content.Context;  \nimport android.os.IVirtualPositionService;  \nimport andr"
  },
  {
    "path": "VirtualPosition/vp_Framework/sepolicy/device.te",
    "chars": 3019,
    "preview": "# Device types\ntype device, dev_type, fs_type;\ntype alarm_device, dev_type, mlstrustedobject;\ntype adb_device, dev_type;"
  },
  {
    "path": "VirtualPosition/vp_Framework/sepolicy/file_contexts",
    "chars": 13975,
    "preview": "###########################################\n# Root\n/\t\t\tu:object_r:rootfs:s0\n\n# Data files\n/adb_keys\t\tu:object_r:adb_keys"
  },
  {
    "path": "VirtualPosition/vp_Framework/sepolicy/service.te",
    "chars": 8487,
    "preview": "type bluetooth_service,         service_manager_type;\ntype default_android_service,   service_manager_type;\ntype drmserv"
  },
  {
    "path": "VirtualPosition/vp_Framework/sepolicy/service_contexts",
    "chars": 9822,
    "preview": "accessibility                             u:object_r:accessibility_service:s0\naccount                                   "
  },
  {
    "path": "VirtualPosition/vp_Framework/sepolicy/system_server.te",
    "chars": 18152,
    "preview": "#\n# System Server aka system_server spawned by zygote.\n# Most of the framework services run in this process.\n#\ntype syst"
  },
  {
    "path": "VirtualPosition/vp_HAL/vp/Android.mk",
    "chars": 290,
    "preview": "LOCAL_PATH := $(call my-dir)\n\tinclude $(CLEAR_VARS)\n\tLOCAL_MODULE_TAGS := optional\n\tLOCAL_PRELINK_MODULE := false\n\tLOCAL"
  },
  {
    "path": "VirtualPosition/vp_HAL/vp/vp.c",
    "chars": 2688,
    "preview": "#define LOG_TAG \"VpStub\"  \n  \n#include <hardware/hardware.h>  \n#include <hardware/vp.h>  \n#include <fcntl.h>  \n#include "
  },
  {
    "path": "VirtualPosition/vp_HAL/vp.h",
    "chars": 690,
    "preview": " #ifndef ANDROID_VP_INTERFACE_H  \n#define ANDROID_VP_INTERFACE_H  \n#include <hardware/hardware.h>  \n__BEGIN_DECLS  \n  \n/"
  },
  {
    "path": "VirtualPosition/vp_JNI/Android.mk",
    "chars": 3001,
    "preview": "# This file is included by the top level services directory to collect source\n# files\nLOCAL_REL_DIR := core/jni\n\nLOCAL_C"
  },
  {
    "path": "VirtualPosition/vp_JNI/com_android_server_VirtualPositionService.cpp",
    "chars": 4481,
    "preview": "#define LOG_TAG \"VirtualPositionService\"  \n#include \"jni.h\"  \n#include \"JNIHelp.h\"  \n#include \"android_runtime/AndroidRu"
  },
  {
    "path": "VirtualPosition/vp_JNI/onload.cpp",
    "chars": 3796,
    "preview": "/*\n * Copyright (C) 2009 The Android Open Source Project\n *\n * Licensed under the Apache License, Version 2.0 (the \"Lice"
  },
  {
    "path": "VirtualPosition/vp_KernelDriver/cyanogen_cancro_defconfig",
    "chars": 16884,
    "preview": "# CONFIG_ARM_PATCH_PHYS_VIRT is not set\nCONFIG_EXPERIMENTAL=y\nCONFIG_LOCALVERSION=\"-cyanogenmod\"\nCONFIG_KERNEL_LZMA=y\nCO"
  },
  {
    "path": "VirtualPosition/vp_KernelDriver/vp/Kconfig",
    "chars": 142,
    "preview": " config VP\n           tristate \"Virtual Position Driver\"\n           default n\n           help\n           This is the vir"
  },
  {
    "path": "VirtualPosition/vp_KernelDriver/vp/Makefile",
    "chars": 25,
    "preview": "obj-$(CONFIG_VP) += vp.o\n"
  },
  {
    "path": "VirtualPosition/vp_KernelDriver/vp/vp.c",
    "chars": 9819,
    "preview": "/*******************************************\n*include file and define functions\n****************************************"
  },
  {
    "path": "VirtualPosition/vp_KernelDriver/vp/vp.h",
    "chars": 506,
    "preview": "#ifndef _VP_ANDROID_H_  \n#define _VP_ANDROID_H_  \n  \n#include <linux/cdev.h>  \n#include <linux/semaphore.h>  \n  \n#define"
  }
]

About this extraction

This page contains the full source code of the aggresss/PHDemo GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 64 files (322.9 KB), approximately 83.1k tokens, and a symbol index with 223 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!