SlideShare uma empresa Scribd logo
1 de 64
Baixar para ler offline
(Presentation)     (Training)     (Lab)
•            Jollen’s Consulting

    • http://www.jollen.org/consulting
•                  3G
      www.moko365.com

•
moko365.com
                        	
     	
                                            	
  	
 
                              	
  	
  	
 
          	
                  	
      	
 

                                                                               	
 
                	
 
                                                         	
     	
 




Android                       Copyright (c) 2009 Jollen’s Consulting          . www.jollen.org/consulting
•   Moko365.com


•
moko365.com
                                                         	
 
          	
 




Android         Copyright (c) 2009 Jollen’s Consulting         . www.jollen.org/consulting
moko365.com



                /&)*!-*'$)&&



                    !"#$%&'




                ()*+)!,&-.$)




Android   Copyright (c) 2009 Jollen’s Consulting         . www.jollen.org/consulting
moko365.com


            /+0*'"0!.--!"$.4"'+



            /+0*'"0!1*.2)3'*(



                     !"#$%&'




                 ()*+)!,&-.$)




Android   Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
moko365.com
          	
 
                	
 




Android                     Copyright (c) 2009 Jollen’s Consulting         . www.jollen.org/consulting
Every Android application runs in its own                         moko365.com
      process, with its own instance of the Dalvik
      virtual machine. Dalvik has been written so
      that a device can run multiple VMs
      efficiently. The Dalvik VM executes files in
      the Dalvik Executable (.dex) format which
      is optimized for minimal memory footprint.
      The VM is register-based, and runs classes
      compiled by a Java language compiler that
      have been transformed into the .dex format
      by the included "dx" tool.

                                    --Android Dev Guide

Android           Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
moko365.com

                   -*'$)&&



          "+&/.+$)!'0!1.!2"(!34



                    !"#$%&'




                ()*+)!,&-.$)




Android    Copyright (c) 2009 Jollen’s Consulting         . www.jollen.org/consulting
moko365.com
          '$()*)(+       &%"*)$%                  "%$%)*%"    !"#*),%"


          !"#$%&&        !"#$%&&                  !"#$%&&     !"#$%&&




Android              Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
moko365.com
          '$()*)(+         &%"*)$%                 "%$%)*%"     !"#*),%"


                                       !"#$%&&




Android              Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
moko365.com




                        $#'!#(%()


                       '*+(!),"%*-


                          !"#$%&&




Android         Copyright (c) 2009 Jollen’s Consulting         . www.jollen.org/consulting
moko365.com
          	
                	
                 	
 
                      	
          	
                 	
 




Android                      Copyright (c) 2009 Jollen’s Consulting           . www.jollen.org/consulting
Android   Copyright (c) 2009 Jollen’s Consulting         . www.jollen.org/consulting
moko365.com
          	
               	
          	
 




Android               Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
moko365.com

                	
 




Android               Copyright (c) 2009 Jollen’s Consulting     . www.jollen.org/consulting
moko365.com
           	
 
                                          	
                      	
          	
 
           	
                 	
 
                 	
 
                          	
 
          	
                        	
                	
                	
 




Android                Copyright (c) 2009 Jollen’s Consulting                             . www.jollen.org/consulting
moko365.com
              !"#$%&&


              '()"*"(%&                                    User-space driver


                    '()$                                   Standard C Libraries
                                                                                          System Calls
          +%,($%!+"(,%"                                    Linux kernel




          *    : Jollen’s Consulting, for update see jollen.org/consulting


Android                    Copyright (c) 2009 Jollen’s Consulting            . www.jollen.org/consulting
moko365.com
              $#'!#(%()                                      API


              '*+(!),"%*-                                    Java Thread
                                                                                             JNI
                !"#$%&&                                      Dalvik VM


               ./0!1)23                                      *.so


                   4+3$                                      Standard C Libraries
                                                                                             System Calls
              -%5+$%!-"+5%"                                  Linux kernel


          *      : Jollen’s Consulting, for update see jollen.org/consulting


Android                     Copyright (c) 2009 Jollen’s Consulting             . www.jollen.org/consulting
moko365.com
              !"#$%&&                                      3.          API


              '()"*"(%&                                    2.          API      library


                '()$                                       Standard C Libraries


          +%,($%!+"(,%"                                    1.



          *




          *    : Jollen’s Consulting, for update see jollen.org/consulting


Android                   Copyright (c) 2009 Jollen’s Consulting             . www.jollen.org/consulting
*
                                                                                              moko365.com
         $#'!#(%()                                 API                           !"#$%&'"(


      '*+(!),"%*-                                  Dalvik
                                                                                 )#*+,(!-.!/
                                                                                 0'"%!1,2"#"3
          !"#$%&&                                  Core Libraries


          ./0!1)23                                 *.so                           451!6782


            4+3$                                   Standard C Libraries                *,29


     -%5+$%!-"+5%"                                 Linux kernel                  :%+,9%!:",+%"


              *    : Jollen’s Consulting, for update see jollen.org/consulting


Android                       Copyright (c) 2009 Jollen’s Consulting             . www.jollen.org/consulting
moko365.com
      !"#$%&'"(                                    2.          API        native function


                                                   3.          JNI method table
     )#*+,(!-.!/
     0'"%!1,2"#"3
                                                   5.          core libraries


          451!6782                                 4.          callback functions         supporting API


            *,29                                   Standard C Libraries


     :%+,9%!:",+%"                                 1.


             *     : Jollen’s Consulting, for update see jollen.org/consulting


Android                       Copyright (c) 2009 Jollen’s Consulting                . www.jollen.org/consulting
Android   Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
moko365.com
                                     	
             	
                	
          	
 
          	
           	
 




Android                      Copyright (c) 2009 Jollen’s Consulting          . www.jollen.org/consulting
moko365.com
          	
                	
                 	
 
                                  	
     	
              	
 
                	
 




Android         Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
moko365.com

                      	
                                               	
           	
 

                	
          	
         	
            	
                      	
 
                      	
                                   	
 
                                             	
            	
 




Android                       Copyright (c) 2009 Jollen’s Consulting                      . www.jollen.org/consulting
moko365.com
                 	
                            	
        	
 
                       	
          	
                    	
      	
                      	
 
          	
                 	
                	
  	
              	
 
                	
                               	
            	
 




Android                             Copyright (c) 2009 Jollen’s Consulting               . www.jollen.org/consulting
moko365.com
          int hw_get_module(const char *id, const struct hw_module_t **module)




                	
       	
                  	
 
                               	
      	
               	
 




Android                  Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
moko365.com
                                 Java Stub

                 Service/JNI
          framework/base/services/jni




                     HAL
             hardware/libhardware

                                 HAL Stub

                         sysfs
                         /sys




                  Kernel Modules




Android     Copyright (c) 2009 Jollen’s Consulting         . www.jollen.org/consulting
moko365.com




Android   Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
moko365.com
     class SensorService extends ISensorService.Stub {
         ...
         private static native int _sensors_control_init();
         private static native ParcelFileDescriptor _sensors_control_open();
         private static native boolean _sensors_control_activate(int sensor, boolean activate);
         private static native int _sensors_control_set_delay(int ms);
     }




at framework/base/services/java/SensorService.java

Android                 Copyright (c) 2009 Jollen’s Consulting         . www.jollen.org/consulting
moko365.com
    class SensorService extends ISensorService.Stub {
        ...
        public SensorService(Context context) {
            if (localLOGV) Log.d(TAG, "SensorService startup");
            _sensors_control_init();
            mNotificationManager = (NotificationManager)context.getSystemService
    (Context.NOTIFICATION_SERVICE);
            mContext = context;
        }
       ...
    }




at framework/base/services/java/SensorService.java

Android                Copyright (c) 2009 Jollen’s Consulting         . www.jollen.org/consulting
moko365.com
 static JNINativeMethod gMethods[] = {
     {"_sensors_control_init",     "()I",   (void*) android_init },
     {"_sensors_control_open",     "()Landroid/os/ParcelFileDescriptor;",
                                            (void*) android_open },
     {"_sensors_control_activate", "(IZ)Z", (void*) android_activate },
     {"_sensors_control_wake",     "()I", (void*) android_data_wake },
     {"_sensors_control_set_delay","(I)I", (void*) android_set_delay },
 };




at framework/base/services/jni/com_android_server_SensorService.cpp

Android               Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
moko365.com

static jint
android_init(JNIEnv *env, jclass clazz)
{
    sensors_module_t* module;
    if (hw_get_module(SENSORS_HARDWARE_MODULE_ID, (const hw_module_t**)&module) == 0) {
        if (sensors_control_open(&module->common, &sSensorDevice) == 0) {
            const struct sensor_t* list;
            int count = module->get_sensors_list(module, &list);
            return count;
        }
    }
    return 0;
}




 #define SENSORS_MODULE_ID “sensors”

Android                  Copyright (c) 2009 Jollen’s Consulting               . www.jollen.org/consulting
moko365.com

  /**
   * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
   * and the fields of this data structure must begin with hw_module_t
   * followed by module specific information.
   */
  struct sensors_module_t {
      struct hw_module_t common;

          /**
           * Enumerate all available sensors. The list is returned in "list".
           * @return number of sensors in the list
           */
          int (*get_sensors_list)(struct sensors_module_t* module,
                  struct sensor_t const** list);
  };

                                                              supporting API
                                                                HAL stub


Android                     Copyright (c) 2009 Jollen’s Consulting         . www.jollen.org/consulting
struct hw_module_t {
          /** tag must be initialized to HARDWARE_MODULE_TAG */
          uint32_t tag;

           /** major version number for the module */                          moko365.com
           uint16_t version_major;

           /** minor version number of the module */
           uint16_t version_minor;

           /** Identifier of module */
           const char *id;

           /** Name of this module */
           const char *name;

           /** Author/owner/implementor of the module */
           const char *author;

           /** Modules methods */
           struct hw_module_methods_t* methods;

           /** padding to 128 bytes, reserved for future use */
           uint32_t reserved[32-6];
      };




Android                 Copyright (c) 2009 Jollen’s Consulting    . www.jollen.org/consulting
moko365.com
  struct hw_module_methods_t {
      /** Open a specific device */
      int (*open)(const struct hw_module_t* module, const char* id,
              struct hw_device_t** device);
  };




Android                Copyright (c) 2009 Jollen’s Consulting               . www.jollen.org/consulting
moko365.com

    static inline int sensors_control_open(const struct hw_module_t* module,
            struct sensors_control_device_t** device) {
        return module->methods->open(module,
                SENSORS_HARDWARE_CONTROL, (struct hw_device_t**)device);
    }




at hardware/libhardware/include/hardware/sensors.h

Android                  Copyright (c) 2009 Jollen’s Consulting    . www.jollen.org/consulting
moko365.com




Android   Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
moko365.com


    static inline int sensors_control_open(const struct hw_module_t* module,
            struct sensors_control_device_t** device) {
        return module->methods->open(module,
                SENSORS_HARDWARE_CONTROL, (struct hw_device_t**)device);
    }




                      struct hw_module_methods_t {
                          /** Open a specific device */
                          int (*open)(const struct hw_module_t* module, const char* id,
                                  struct hw_device_t** device);
                      };




at hardware/libhardware/include/hardware/sensors.h

Android                    Copyright (c) 2009 Jollen’s Consulting      . www.jollen.org/consulting
moko365.com
 static JNINativeMethod gMethods[] = {
     {"_sensors_control_init",     "()I",   (void*) android_init },
     {"_sensors_control_open",     "()Landroid/os/ParcelFileDescriptor;",
                                            (void*) android_open },
     {"_sensors_control_activate", "(IZ)Z", (void*) android_activate },
     {"_sensors_control_wake",     "()I", (void*) android_data_wake },
     {"_sensors_control_set_delay","(I)I", (void*) android_set_delay },
 };




Android             Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
/**
     * Every device data structure must begin with hw_device_t
                                                                                 moko365.com
     * followed by module specific public methods and attributes.
     */
    struct sensors_control_device_t {
        struct hw_device_t common;

          /**
           * Returns the fd which will be the parameter to
           * sensors_data_device_t::open_data().
           * The caller takes ownership of this fd. This is intended to be
           * passed cross processes.
           *
           * @return a fd if successful, < 0 on error
           */
          int (*open_data_source)(struct sensors_control_device_t *dev);

          int (*activate)(struct sensors_control_device_t *dev,
                  int handle, int enabled);

          int (*set_delay)(struct sensors_control_device_t *dev, int32_t ms);

          int (*wake)(struct sensors_control_device_t *dev);
    };




Android                  Copyright (c) 2009 Jollen’s Consulting     . www.jollen.org/consulting
moko365.com




Android   Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
/**                                                                 moko365.com
           * Every device data structure must begin with hw_device_t
           * followed by module specific public methods and attributes.
           */
          struct hw_device_t {
              /** tag must be initialized to HARDWARE_DEVICE_TAG */
              uint32_t tag;

               /** version number for hw_device_t */
               uint32_t version;

               /** reference to the module this device belongs to */
               struct hw_module_t* module;

               /** padding reserved for future use */
               uint32_t reserved[12];

               /** Close this device */
               int (*close)(struct hw_device_t* device);
          };




Android                 Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
Android   Copyright (c) 2009 Jollen’s Consulting         . www.jollen.org/consulting
moko365.com




Android   Copyright (c) 2009 Jollen’s Consulting         . www.jollen.org/consulting
moko365.com

           	
 




Android   Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
moko365.com
          on boot
            setprop ro.product.board smdk6410
                                         varient key        prop




          /system/lib/hw/sensors.smdk6410.so
                                <MODULE_ID>.<prop>.so




           setprop <variant_key> <property>


Android            Copyright (c) 2009 Jollen’s Consulting          . www.jollen.org/consulting
!"#$%&


                                                                Manager
                                                                                moko365.com
                                                       framework/base/services/java


            Dalvik VM                                                 IStubService

                                                               Service/Java
                                                       framework/base/services/java

             register
                                               JNI Table
          Android server

                                                               Service/JNI
                                                        framework/base/services/jni




                                                                    HAL
                                                            hardware/libhardware

                                                                         HAL Stub

                                                                   sysfs
                                                                   /sys


                   VM Onload            App Onload

Android            Copyright (c) 2009 Jollen’s Consulting          . www.jollen.org/consulting
Android   Copyright (c) 2009 Jollen’s Consulting     . www.jollen.org/consulting
moko365.com




Android   Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
moko365.com




Android   Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
moko365.com




Android   Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
<?xml version="1.0" encoding="utf-8"?>
 <AbsoluteLayout
 android:id="@+id/widget0"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 xmlns:android="http://schemas.android.com/apk/res/android"              moko365 .com
 >
 <Button
 android:id="@+id/myButton1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:textSize="18sp"
 android:text="   LED"
 android:layout_x="70px"
 android:layout_y="88px"
 >
 </Button>
 <Button
 android:id="@+id/myButton2"                 <Button
 android:layout_width="wrap_content"         android:id="@+id/myButton3"
 android:layout_height="wrap_content"        android:layout_width="wrap_content"
 android:text="   LED"                       android:layout_height="wrap_content"
 android:textSize="18sp"                     android:textSize="18sp"
 android:layout_x="184px"                    android:text="Exit"
 android:layout_y="88px"                     android:layout_x="130px"
 >                                           android:layout_y="150px"
 </Button>                                   >
                                             </Button>
                                             </AbsoluteLayout>




Android            Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
/*      setOnClickListener        */
                                                                      mButton1.setOnClickListener(new Button.OnClickListener()
package led.com.cn;                                                   {
import android.app.Activity;                                             @Override
import android.os.Bundle;                                               /*      onClick          */
import android.view.View;
                                                                         public void onClick(View v)

                                                                                                     moko365.com
import android.widget.Button;
                                                                         {
                                                                            // TODO Auto-generated method stub
public class Led_control extends Activity {
    /** Called when the activity is first created. */                           setTitle("LED     !");
      /*     3 Button       private    */                                  /*        4 LED             */
      private Button mButton1;                                              Linuxc.send(num, led_on);
      private Button mButton2;
      private Button mButton3;                                          }
                                                                      });
     /*           LED      */
                                                                      mButton2.setOnClickListener(new Button.OnClickListener()
     public   int num = 4;
                                                                      {
     /* 1       */                                                      @Override
     public   int led_on = 1;                                           public void onClick(View v)
     /* 2       */                                                      {
     public   int led_off = 2;                                             // TODO Auto-generated method stub
     public   int fd = 0;                                                     setTitle("LED     !");
                                                                        /*         4 LED             */
    @Override
                                                                          Linuxc.send(num, led_off);
    public void onCreate(Bundle savedInstanceState) {
                                                                           }
        super.onCreate(savedInstanceState);
                                                                      });
        setContentView(R.layout.main);
                                                                      mButton3.setOnClickListener(new Button.OnClickListener()
        mButton1 =(Button) findViewById(R.id.myButton1);
                                                                      {
        mButton2 =(Button) findViewById(R.id.myButton2);
                                                                        @Override
        mButton3 =(Button) findViewById(R.id.myButton3);
                                                                        public void onClick(View v)
                                                                        {
       /*       led                      fd */                             // TODO Auto-generated method stub
       fd = Linuxc.openled();                                             /*            */
       if (fd < 0){                                                           Linuxc.closeled();
            setTitle("             ");
                                                                        /*              */
            finish();
                                                                              finish();
         /*                         */                                     }
       }                                                              });
       else {
            setTitle("              ");                           }
       }}                                                     }




 Android                         Copyright (c) 2009 Jollen’s Consulting                . www.jollen.org/consulting
package led.com.cn;

  import android.util.Log;
                                                                               moko365.com
  public class Linuxc {
     static {
       try {
          Log.i("JNI", "Trying to load libled.so");
             /*      libled.so */
          System.loadLibrary("led");
       }
       catch (UnsatisfiedLinkError ule) {
          Log.e("JNI", "WARNING: Could not load libled.so");
       }}
     /*       openled()               */
     public static native int openled();
     /*       closeled ()              */
     public static native int closeled();
     /*       send()               */
     public static native int send(int led_num, int on_off);

  }




Android                  Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
将                                                贝                          moko365.com
                                    录                         个


                                                                 头
                                     数声
                                                          	
 头


    $ mkdir led_test
    $ cd led_test
    ...
    $ /javah -classpath ~/Led_Control/bin/ led.com.cn.Linuxc



Android              Copyright (c) 2009 Jollen’s Consulting          . www.jollen.org/consulting
#include <stdio.h>
  #include <stdlib.h>                                                                      moko365.com
  #include <fcntl.h>
  #include <errno.h>
  #include <unistd.h>
  #include <sys/ioctl.h>

  #include "led_com_cn_Linuxc.h"
  #include "led.h"

  #define LED_TEST 3

  #define DEVICE_BLTEST "/dev/led"

  int fd;

  JNIEXPORT jint JNICALL Java_led_com_cn_Linuxc_openled
   (JNIEnv *env, jclass mc)
  {
   fd= open(DEVICE_BLTEST,O_RDONLY);
   return fd;
  }

  JNIEXPORT jint JNICALL Java_led_com_cn_Linuxc_closeled
   (JNIEnv *env, jclass mc)
  {
   close(fd);
  }

  JNIEXPORT jint JNICALL Java_led_com_cn_Linuxc_send
  (JNIEnv *env, jclass mc, jint a, jint b)
  {
   ioctl(fd,b,&a);
  }




Android                              Copyright (c) 2009 Jollen’s Consulting   . www.jollen.org/consulting
moko365.com
        $ arm-none-linux-gnueabi-gcc -I/home/online/jdk1.6.0_14/include -I/home/online/jdk1.6.0_14/
        include/linux -fpic -c led_com_cn_linuxc.c

        $arm-none-linux-gnueabi-ld-T /home/online/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-
        gnueabi/lib/ldscripts/armelf_linux_eabi.xsc -shared -o libled.so led_com_cn_linuxc.o




Android                   Copyright (c) 2009 Jollen’s Consulting       . www.jollen.org/consulting
www.moko365.com

Mais conteúdo relacionado

Mais procurados

Android audio system(audioplicy_service)
Android audio system(audioplicy_service)Android audio system(audioplicy_service)
Android audio system(audioplicy_service)
fefe7270
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Opersys inc.
 
Android audio system(audio_hardwareinterace)
Android audio system(audio_hardwareinterace)Android audio system(audio_hardwareinterace)
Android audio system(audio_hardwareinterace)
fefe7270
 

Mais procurados (20)

Deep Dive into the AOSP
Deep Dive into the AOSPDeep Dive into the AOSP
Deep Dive into the AOSP
 
Embedded Android : System Development - Part IV (Android System Services)
Embedded Android : System Development - Part IV (Android System Services)Embedded Android : System Development - Part IV (Android System Services)
Embedded Android : System Development - Part IV (Android System Services)
 
Inside Android's UI
Inside Android's UIInside Android's UI
Inside Android's UI
 
Android Audio System
Android Audio SystemAndroid Audio System
Android Audio System
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Android audio system(audioplicy_service)
Android audio system(audioplicy_service)Android audio system(audioplicy_service)
Android audio system(audioplicy_service)
 
Android studio ppt
Android studio pptAndroid studio ppt
Android studio ppt
 
Android JNI
Android JNIAndroid JNI
Android JNI
 
Android Architecture.pptx
Android Architecture.pptxAndroid Architecture.pptx
Android Architecture.pptx
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HAL
 
Introduction of android treble
Introduction of android trebleIntroduction of android treble
Introduction of android treble
 
Design and Concepts of Android Graphics
Design and Concepts of Android GraphicsDesign and Concepts of Android Graphics
Design and Concepts of Android Graphics
 
Android audio system(audio_hardwareinterace)
Android audio system(audio_hardwareinterace)Android audio system(audio_hardwareinterace)
Android audio system(audio_hardwareinterace)
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new Platforms
 
Android media framework overview
Android media framework overviewAndroid media framework overview
Android media framework overview
 
Basic android-ppt
Basic android-pptBasic android-ppt
Basic android-ppt
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Android : Deep dive into developing MobileApp using Android
Android : Deep dive into developing MobileApp using AndroidAndroid : Deep dive into developing MobileApp using Android
Android : Deep dive into developing MobileApp using Android
 
Android ppt
 Android ppt Android ppt
Android ppt
 

Destaque

Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
Kan-Ru Chen
 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debugging
Utkarsh Mankad
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Opersys inc.
 
ABI란 무엇인가요?
ABI란 무엇인가요?ABI란 무엇인가요?
ABI란 무엇인가요?
진상 문
 

Destaque (20)

Accessing Hardware on Android
Accessing Hardware on AndroidAccessing Hardware on Android
Accessing Hardware on Android
 
Learning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device DriverLearning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device Driver
 
Hardware Abstraction Layer
Hardware Abstraction LayerHardware Abstraction Layer
Hardware Abstraction Layer
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting Process
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
 
Diving inside Android Wifi
Diving inside Android WifiDiving inside Android Wifi
Diving inside Android Wifi
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
 
Android Custom Kernel/ROM design
Android Custom Kernel/ROM designAndroid Custom Kernel/ROM design
Android Custom Kernel/ROM design
 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debugging
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
 
Operating system
Operating systemOperating system
Operating system
 
Peno sensor
Peno sensorPeno sensor
Peno sensor
 
Android のusb support
Android のusb supportAndroid のusb support
Android のusb support
 
Android CTS training
Android CTS trainingAndroid CTS training
Android CTS training
 
Android usbの基本
Android usbの基本Android usbの基本
Android usbの基本
 
ABI란 무엇인가요?
ABI란 무엇인가요?ABI란 무엇인가요?
ABI란 무엇인가요?
 
基礎から学ぶ組み込みAndroid
基礎から学ぶ組み込みAndroid基礎から学ぶ組み込みAndroid
基礎から学ぶ組み込みAndroid
 
nl80211 and libnl
nl80211 and libnlnl80211 and libnl
nl80211 and libnl
 
Android Anatomy
Android  AnatomyAndroid  Anatomy
Android Anatomy
 
Debian & the BeagleBone Black
Debian & the BeagleBone BlackDebian & the BeagleBone Black
Debian & the BeagleBone Black
 

Mais de Jollen Chen

Startup eng-camp 3
Startup eng-camp 3Startup eng-camp 3
Startup eng-camp 3
Jollen Chen
 
讓 HTML5 走進 IPTV Framework
讓 HTML5 走進 IPTV Framework讓 HTML5 走進 IPTV Framework
讓 HTML5 走進 IPTV Framework
Jollen Chen
 
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)
Jollen Chen
 
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)
Jollen Chen
 

Mais de Jollen Chen (20)

Flowchain blockchain classroom at Taiwan Tech University
Flowchain blockchain classroom at Taiwan Tech UniversityFlowchain blockchain classroom at Taiwan Tech University
Flowchain blockchain classroom at Taiwan Tech University
 
Bitmark and Hyperledger Workshop: the Digital Assets and Property
Bitmark and Hyperledger Workshop: the Digital Assets and PropertyBitmark and Hyperledger Workshop: the Digital Assets and Property
Bitmark and Hyperledger Workshop: the Digital Assets and Property
 
Introducing the Blockchain and Distributed Ledger Technology
Introducing the Blockchain and  Distributed Ledger TechnologyIntroducing the Blockchain and  Distributed Ledger Technology
Introducing the Blockchain and Distributed Ledger Technology
 
Maker of Things - the open IoT cloud for makers chapter.
Maker of Things - the open IoT cloud for makers chapter.Maker of Things - the open IoT cloud for makers chapter.
Maker of Things - the open IoT cloud for makers chapter.
 
WoT.City and IoT Protocols Movement @ Taipei, Taiwan
WoT.City and IoT Protocols Movement @ Taipei, TaiwanWoT.City and IoT Protocols Movement @ Taipei, Taiwan
WoT.City and IoT Protocols Movement @ Taipei, Taiwan
 
IoT and Maker Crossover (IMCO) Conference 2015
IoT and Maker Crossover (IMCO) Conference 2015IoT and Maker Crossover (IMCO) Conference 2015
IoT and Maker Crossover (IMCO) Conference 2015
 
Open IoT Cloud Architecture, Web of Things, Shenzhen, China.
Open IoT Cloud Architecture, Web of Things, Shenzhen, China.Open IoT Cloud Architecture, Web of Things, Shenzhen, China.
Open IoT Cloud Architecture, Web of Things, Shenzhen, China.
 
Backbone.js and MVW 101
Backbone.js and MVW 101Backbone.js and MVW 101
Backbone.js and MVW 101
 
Single-Page Application Design Principles 101
Single-Page Application Design Principles 101Single-Page Application Design Principles 101
Single-Page Application Design Principles 101
 
MongoDB & NoSQL 101
 MongoDB & NoSQL 101 MongoDB & NoSQL 101
MongoDB & NoSQL 101
 
Mokoversity Course: Apple Swift 101 - Introduction
Mokoversity Course: Apple Swift 101 - IntroductionMokoversity Course: Apple Swift 101 - Introduction
Mokoversity Course: Apple Swift 101 - Introduction
 
Android Wear SDK: Level 101
Android Wear SDK: Level 101Android Wear SDK: Level 101
Android Wear SDK: Level 101
 
Startup eng-camp 3
Startup eng-camp 3Startup eng-camp 3
Startup eng-camp 3
 
讓 HTML5 走進 IPTV Framework
讓 HTML5 走進 IPTV Framework讓 HTML5 走進 IPTV Framework
讓 HTML5 走進 IPTV Framework
 
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(2)
 
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)
 
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(1)
 
Jollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-level
 
Embedded Linux: Introduction
Embedded Linux: IntroductionEmbedded Linux: Introduction
Embedded Linux: Introduction
 
Android Application: Introduction
Android Application: IntroductionAndroid Application: Introduction
Android Application: Introduction
 

Último

Último (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 

Android HAL Introduction: libhardware and its legacy

  • 1.
  • 2. (Presentation) (Training) (Lab)
  • 3. Jollen’s Consulting • http://www.jollen.org/consulting • 3G www.moko365.com •
  • 4. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 5. Moko365.com •
  • 6. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 7.
  • 8. moko365.com /&)*!-*'$)&& !"#$%&' ()*+)!,&-.$) Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 9. moko365.com /+0*'"0!.--!"$.4"'+ /+0*'"0!1*.2)3'*( !"#$%&' ()*+)!,&-.$) Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 10. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 11. Every Android application runs in its own moko365.com process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimized for minimal memory footprint. The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included "dx" tool. --Android Dev Guide Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 12. moko365.com -*'$)&& "+&/.+$)!'0!1.!2"(!34 !"#$%&' ()*+)!,&-.$) Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 13. moko365.com '$()*)(+ &%"*)$% "%$%)*%" !"#*),%" !"#$%&& !"#$%&& !"#$%&& !"#$%&& Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 14. moko365.com '$()*)(+ &%"*)$% "%$%)*%" !"#*),%" !"#$%&& Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 15. moko365.com $#'!#(%() '*+(!),"%*- !"#$%&& Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 16. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 17. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 18. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 19. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 20. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 21. moko365.com !"#$%&& '()"*"(%& User-space driver '()$ Standard C Libraries System Calls +%,($%!+"(,%" Linux kernel * : Jollen’s Consulting, for update see jollen.org/consulting Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 22. moko365.com $#'!#(%() API '*+(!),"%*- Java Thread JNI !"#$%&& Dalvik VM ./0!1)23 *.so 4+3$ Standard C Libraries System Calls -%5+$%!-"+5%" Linux kernel * : Jollen’s Consulting, for update see jollen.org/consulting Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 23. moko365.com !"#$%&& 3. API '()"*"(%& 2. API library '()$ Standard C Libraries +%,($%!+"(,%" 1. * * : Jollen’s Consulting, for update see jollen.org/consulting Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 24. * moko365.com $#'!#(%() API !"#$%&'"( '*+(!),"%*- Dalvik )#*+,(!-.!/ 0'"%!1,2"#"3 !"#$%&& Core Libraries ./0!1)23 *.so 451!6782 4+3$ Standard C Libraries *,29 -%5+$%!-"+5%" Linux kernel :%+,9%!:",+%" * : Jollen’s Consulting, for update see jollen.org/consulting Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 25. moko365.com !"#$%&'"( 2. API native function 3. JNI method table )#*+,(!-.!/ 0'"%!1,2"#"3 5. core libraries 451!6782 4. callback functions supporting API *,29 Standard C Libraries :%+,9%!:",+%" 1. * : Jollen’s Consulting, for update see jollen.org/consulting Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 26. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 27. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 28. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 29. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 30.
  • 31. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 32. moko365.com int hw_get_module(const char *id, const struct hw_module_t **module) Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 33. moko365.com Java Stub Service/JNI framework/base/services/jni HAL hardware/libhardware HAL Stub sysfs /sys Kernel Modules Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 34. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 35. moko365.com class SensorService extends ISensorService.Stub { ... private static native int _sensors_control_init(); private static native ParcelFileDescriptor _sensors_control_open(); private static native boolean _sensors_control_activate(int sensor, boolean activate); private static native int _sensors_control_set_delay(int ms); } at framework/base/services/java/SensorService.java Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 36. moko365.com class SensorService extends ISensorService.Stub { ... public SensorService(Context context) { if (localLOGV) Log.d(TAG, "SensorService startup"); _sensors_control_init(); mNotificationManager = (NotificationManager)context.getSystemService (Context.NOTIFICATION_SERVICE); mContext = context; } ... } at framework/base/services/java/SensorService.java Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 37. moko365.com static JNINativeMethod gMethods[] = { {"_sensors_control_init", "()I", (void*) android_init }, {"_sensors_control_open", "()Landroid/os/ParcelFileDescriptor;", (void*) android_open }, {"_sensors_control_activate", "(IZ)Z", (void*) android_activate }, {"_sensors_control_wake", "()I", (void*) android_data_wake }, {"_sensors_control_set_delay","(I)I", (void*) android_set_delay }, }; at framework/base/services/jni/com_android_server_SensorService.cpp Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 38. moko365.com static jint android_init(JNIEnv *env, jclass clazz) { sensors_module_t* module; if (hw_get_module(SENSORS_HARDWARE_MODULE_ID, (const hw_module_t**)&module) == 0) { if (sensors_control_open(&module->common, &sSensorDevice) == 0) { const struct sensor_t* list; int count = module->get_sensors_list(module, &list); return count; } } return 0; } #define SENSORS_MODULE_ID “sensors” Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 39. moko365.com /** * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM * and the fields of this data structure must begin with hw_module_t * followed by module specific information. */ struct sensors_module_t { struct hw_module_t common; /** * Enumerate all available sensors. The list is returned in "list". * @return number of sensors in the list */ int (*get_sensors_list)(struct sensors_module_t* module, struct sensor_t const** list); }; supporting API HAL stub Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 40. struct hw_module_t { /** tag must be initialized to HARDWARE_MODULE_TAG */ uint32_t tag; /** major version number for the module */ moko365.com uint16_t version_major; /** minor version number of the module */ uint16_t version_minor; /** Identifier of module */ const char *id; /** Name of this module */ const char *name; /** Author/owner/implementor of the module */ const char *author; /** Modules methods */ struct hw_module_methods_t* methods; /** padding to 128 bytes, reserved for future use */ uint32_t reserved[32-6]; }; Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 41. moko365.com struct hw_module_methods_t { /** Open a specific device */ int (*open)(const struct hw_module_t* module, const char* id, struct hw_device_t** device); }; Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 42. moko365.com static inline int sensors_control_open(const struct hw_module_t* module, struct sensors_control_device_t** device) { return module->methods->open(module, SENSORS_HARDWARE_CONTROL, (struct hw_device_t**)device); } at hardware/libhardware/include/hardware/sensors.h Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 43. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 44. moko365.com static inline int sensors_control_open(const struct hw_module_t* module, struct sensors_control_device_t** device) { return module->methods->open(module, SENSORS_HARDWARE_CONTROL, (struct hw_device_t**)device); } struct hw_module_methods_t { /** Open a specific device */ int (*open)(const struct hw_module_t* module, const char* id, struct hw_device_t** device); }; at hardware/libhardware/include/hardware/sensors.h Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 45. moko365.com static JNINativeMethod gMethods[] = { {"_sensors_control_init", "()I", (void*) android_init }, {"_sensors_control_open", "()Landroid/os/ParcelFileDescriptor;", (void*) android_open }, {"_sensors_control_activate", "(IZ)Z", (void*) android_activate }, {"_sensors_control_wake", "()I", (void*) android_data_wake }, {"_sensors_control_set_delay","(I)I", (void*) android_set_delay }, }; Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 46. /** * Every device data structure must begin with hw_device_t moko365.com * followed by module specific public methods and attributes. */ struct sensors_control_device_t { struct hw_device_t common; /** * Returns the fd which will be the parameter to * sensors_data_device_t::open_data(). * The caller takes ownership of this fd. This is intended to be * passed cross processes. * * @return a fd if successful, < 0 on error */ int (*open_data_source)(struct sensors_control_device_t *dev); int (*activate)(struct sensors_control_device_t *dev, int handle, int enabled); int (*set_delay)(struct sensors_control_device_t *dev, int32_t ms); int (*wake)(struct sensors_control_device_t *dev); }; Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 47. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 48. /** moko365.com * Every device data structure must begin with hw_device_t * followed by module specific public methods and attributes. */ struct hw_device_t { /** tag must be initialized to HARDWARE_DEVICE_TAG */ uint32_t tag; /** version number for hw_device_t */ uint32_t version; /** reference to the module this device belongs to */ struct hw_module_t* module; /** padding reserved for future use */ uint32_t reserved[12]; /** Close this device */ int (*close)(struct hw_device_t* device); }; Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 49. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 50. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 51. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 52. moko365.com on boot setprop ro.product.board smdk6410 varient key prop /system/lib/hw/sensors.smdk6410.so <MODULE_ID>.<prop>.so setprop <variant_key> <property> Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 53. !"#$%& Manager moko365.com framework/base/services/java Dalvik VM IStubService Service/Java framework/base/services/java register JNI Table Android server Service/JNI framework/base/services/jni HAL hardware/libhardware HAL Stub sysfs /sys VM Onload App Onload Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 54. Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 55. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 56. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 57. moko365.com Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 58. <?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout android:id="@+id/widget0" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" moko365 .com > <Button android:id="@+id/myButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:text=" LED" android:layout_x="70px" android:layout_y="88px" > </Button> <Button android:id="@+id/myButton2" <Button android:layout_width="wrap_content" android:id="@+id/myButton3" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text=" LED" android:layout_height="wrap_content" android:textSize="18sp" android:textSize="18sp" android:layout_x="184px" android:text="Exit" android:layout_y="88px" android:layout_x="130px" > android:layout_y="150px" </Button> > </Button> </AbsoluteLayout> Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 59. /* setOnClickListener */ mButton1.setOnClickListener(new Button.OnClickListener() package led.com.cn; { import android.app.Activity; @Override import android.os.Bundle; /* onClick */ import android.view.View; public void onClick(View v) moko365.com import android.widget.Button; { // TODO Auto-generated method stub public class Led_control extends Activity { /** Called when the activity is first created. */ setTitle("LED !"); /* 3 Button private */ /* 4 LED */ private Button mButton1; Linuxc.send(num, led_on); private Button mButton2; private Button mButton3; } }); /* LED */ mButton2.setOnClickListener(new Button.OnClickListener() public int num = 4; { /* 1 */ @Override public int led_on = 1; public void onClick(View v) /* 2 */ { public int led_off = 2; // TODO Auto-generated method stub public int fd = 0; setTitle("LED !"); /* 4 LED */ @Override Linuxc.send(num, led_off); public void onCreate(Bundle savedInstanceState) { } super.onCreate(savedInstanceState); }); setContentView(R.layout.main); mButton3.setOnClickListener(new Button.OnClickListener() mButton1 =(Button) findViewById(R.id.myButton1); { mButton2 =(Button) findViewById(R.id.myButton2); @Override mButton3 =(Button) findViewById(R.id.myButton3); public void onClick(View v) { /* led fd */ // TODO Auto-generated method stub fd = Linuxc.openled(); /* */ if (fd < 0){ Linuxc.closeled(); setTitle(" "); /* */ finish(); finish(); /* */ } } }); else { setTitle(" "); } }} } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 60. package led.com.cn; import android.util.Log; moko365.com public class Linuxc { static { try { Log.i("JNI", "Trying to load libled.so"); /* libled.so */ System.loadLibrary("led"); } catch (UnsatisfiedLinkError ule) { Log.e("JNI", "WARNING: Could not load libled.so"); }} /* openled() */ public static native int openled(); /* closeled () */ public static native int closeled(); /* send() */ public static native int send(int led_num, int on_off); } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 61. 贝 moko365.com 录 个 头 数声 头 $ mkdir led_test $ cd led_test ... $ /javah -classpath ~/Led_Control/bin/ led.com.cn.Linuxc Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 62. #include <stdio.h> #include <stdlib.h> moko365.com #include <fcntl.h> #include <errno.h> #include <unistd.h> #include <sys/ioctl.h> #include "led_com_cn_Linuxc.h" #include "led.h" #define LED_TEST 3 #define DEVICE_BLTEST "/dev/led" int fd; JNIEXPORT jint JNICALL Java_led_com_cn_Linuxc_openled (JNIEnv *env, jclass mc) { fd= open(DEVICE_BLTEST,O_RDONLY); return fd; } JNIEXPORT jint JNICALL Java_led_com_cn_Linuxc_closeled (JNIEnv *env, jclass mc) { close(fd); } JNIEXPORT jint JNICALL Java_led_com_cn_Linuxc_send (JNIEnv *env, jclass mc, jint a, jint b) { ioctl(fd,b,&a); } Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting
  • 63. moko365.com $ arm-none-linux-gnueabi-gcc -I/home/online/jdk1.6.0_14/include -I/home/online/jdk1.6.0_14/ include/linux -fpic -c led_com_cn_linuxc.c $arm-none-linux-gnueabi-ld-T /home/online/CodeSourcery/Sourcery_G++_Lite/arm-none-linux- gnueabi/lib/ldscripts/armelf_linux_eabi.xsc -shared -o libled.so led_com_cn_linuxc.o Android Copyright (c) 2009 Jollen’s Consulting . www.jollen.org/consulting