Android from hardware to application: Step by Step 5-add hardware services to the Frameworks Layer

Source: Internet
Author: User

Android from hardware to application: Step by Step 5-add hardware services to the Frameworks Layer

The Android Frameworks layer provides hardware services. Android apps can call these hardware services to implement hardware control and functions. Next, in the previous article, this article will provide the java interface hardware service for the application at the frameworks layer. Cd to the frameworks/base/core/java/android/OS directory, add IGpioService. aidl:

package android.os;  interface IGpioService {  void setVal(int val);  int getVal();  }  
We use setVal to set the LED light-off. getVal is always omitted.

Open Android. mk under frameworks/base, modify LOCAL_SRC_FILES, and add:

core/java/android/os/IGpioService.aidl \
Compile the IGpioService. aidl interface: (if the source code is compiled successfully)

mmm frameworks/base

Generation:

Install: out/target/product/generic/system/framework/framework.odexInstall: out/target/product/generic/system/framework/framework.jar
After successful cd, go to the frameworks/base/services/java/com/android/server Directory and add the GpioService. java file:

package com.android.server;  import android.content.Context;  import android.os.IGpioService;  import android.util.Slog;  public class GpioService extends IGpioService.Stub {  private static final String TAG = "GpioService";  GpioService() {      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();  };  
Modify the SystemServer. java file in the current directory and add GpioService in ServerThread: run:

            try {                Slog.i(TAG, "Recognition Service");                recognition = new RecognitionManagerService(context);            } catch (Throwable e) {                reportWtf("starting Recognition Service", e);            }            try {                Slog.i(TAG, "DiskStats Service");                ServiceManager.addService("diskstats", new DiskStatsService(context));            } catch (Throwable e) {                reportWtf("starting DiskStats Service", e);            }            try {                Slog.i(TAG, "Gpio Service");                ServiceManager.addService("gpio", new GpioService());            } catch (Throwable e) {                Slog.e(TAG, "Failure starting Gpio Service", e);            }
Compile GpioService:

mmm frameworks/base/services/java

Generation:

Install: out/target/product/generic/system/framework/services.odexInstall: out/target/product/generic/system/framework/services.jar
The Frameworks layer already contains the hardware services we have compiled. Applications can access the hardware services through these java interfaces.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.