没有android swt.os.iswtledservice

Android ANR错误 讲解-android100学习网
Android ANR错误 讲解
Android ANR这个错误大家并不陌生,但是从Android 2.2开始出错的ANR信息会自动上传给Google进行系统分析改进,当然了你的应用ANR错误其实保存在一个文件中,在/data/anr /traces.txt文件中,如果你的Android设......
Android ANR这个错误大家并不陌生,但是从Android 2.2开始出错的ANR信息会自动上传给Google进行系统分析改进,当然了你的应用ANR错误其实保存在一个文件中,在/data/anr /traces.txt文件中,如果你的Android设备没有Root越狱过,可以将你的软件装在模拟器上分析,模拟器可以直接使用Eclipse中的 DDMS里的File Explorer来打开,如下图:
虽然traces.txt是一个文本文件,不过使用windows上的记事本打开可能无法正常处理linux的换行符,这里Android建议你使用 ultra edit查看,当然了使用Windows自带的写字板也是不错的。下面一起来分析下错误吧,第一行为出错的时间,第二行都会写上发生ANR的 package Name,下文是com.android.systemui这个包,里面的部分线程出了问题,通过下面的的xxx方法以及对应的java文件,后面的数字 为xxx.java文件的第几行,是不是很方便呢?
01----- pid 125 at
05:18:01 -----
02Cmd line: com.android.systemui
04DALVIK THREADS:
05(mutexes: tll=0 tsl=0 tscl=0 ghl=0 hwl=0 hwll=0)
06&main& prio=5 tid=1 NATIVE
07 | group=&main& sCount=1 dsCount=0 obj=0x self=0xce48
08 | sysTid=125 nice=0 sched=0/0 cgrp=default handle=-
09 | schedstat=(
10 at android.os.BinderProxy.transact(Native Method)
11 at android.os.storage.IMountService$Stub$Proxy.isUsbMassStorageConnected(IMountService.java:95)
12 at android.os.storage.StorageManager.isUsbMassStorageConnected(StorageManager.java:385)
13 at com.android.systemui.usb.StorageNotification.(StorageNotification.java:71)
14 at com.android.systemui.statusbar.policy.StatusBarPolicy.(StatusBarPolicy.java:412)
15 at com.android.systemui.statusbar.StatusBarService.onCreate(StatusBarService.java:239)
16 at android.app.ActivityThread.handleCreateService(ActivityThread.java:1920)
17 at android.app.ActivityThread.access$2500(ActivityThread.java:117)
18 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:982)
19 at android.os.Handler.dispatchMessage(Handler.java:99)
20 at android.os.Looper.loop(Looper.java:123)
21 at android.app.ActivityThread.main(ActivityThread.java:3647)
22 at java.lang.reflect.Method.invokeNative(Native Method)
23 at java.lang.reflect.Method.invoke(Method.java:507)
24 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
25 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
26 at dalvik.system.NativeStart.main(Native Method)
28&Binder Thread #2& prio=5 tid=8 NATIVE
29 | group=&main& sCount=1 dsCount=0 obj=0x self=0x1c1100
30 | sysTid=153 nice=0 sched=0/0 cgrp=default handle=1141608
31 | schedstat=( 08345 5 )
32 at dalvik.system.NativeStart.run(Native Method)
34&Binder Thread #1& prio=5 tid=7 NATIVE
35 | group=&main& sCount=1 dsCount=0 obj=0x self=0x1349c8
36 | sysTid=152 nice=0 sched=0/0 cgrp=default handle=1264008
37 | schedstat=( 84459 5 )
38 at dalvik.system.NativeStart.run(Native Method)
40&Compiler& daemon prio=5 tid=6 VMWAIT
41 | group=&system& sCount=1 dsCount=0 obj=0x4050dd10 self=0x116538
42 | sysTid=144 nice=0 sched=0/0 cgrp=default handle=982520
43 | schedstat=(
44 at dalvik.system.NativeStart.run(Native Method)
46&JDWP& daemon prio=5 tid=5 VMWAIT
47 | group=&system& sCount=1 dsCount=0 obj=0x4050dc60 self=0x116400
48 | sysTid=142 nice=0 sched=0/0 cgrp=default handle=986536
49 | schedstat=(
50 at dalvik.system.NativeStart.run(Native Method)
52&Signal Catcher& daemon prio=5 tid=4 RUNNABLE
53 | group=&system& sCount=0 dsCount=0 obj=0x4050dba0 self=0x253ab0
54 | sysTid=141 nice=0 sched=0/0 cgrp=default handle=2439792
55 | schedstat=(
56 at dalvik.system.NativeStart.run(Native Method)
58&GC& daemon prio=5 tid=3 VMWAIT
59 | group=&system& sCount=1 dsCount=0 obj=0x4050daf8 self=0x8fd40
60 | sysTid=128 nice=0 sched=0/0 cgrp=default handle=2439592
61 | schedstat=(
62 at dalvik.system.NativeStart.run(Native Method)
64&HeapWorker& daemon prio=5 tid=2 VMWAIT
65 | group=&system& sCount=1 dsCount=0 obj=0x4050da40 self=0xf0c70
66 | sysTid=127 nice=0 sched=0/0 cgrp=default handle=2439528
67 | schedstat=(
68 at dalvik.system.NativeStart.run(Native Method)6036人阅读
Android 移植(3)
同前一篇文章类似,此文旨在简单介绍一下如何在
java层添加自己的服务,相关的理论网上已经有很多文章,在此不在详述。
Java层服务顾名思义即为从
Java层提供的服务,它与
C++层的服务不同之处在于其服务进程的运行由系统(
ServiceManager)统一维护。在文件
中我们可以看到以下代码:
这个操作在系统启动时完成,由
ServiceManager
负责创建服务进程并运行之。所以我们要做的事就是实现一个
服务,并将其添加到这里并由系统运行起来,以下是具体实现步骤:
实现自己的
frameworks/base/core/java/android/os中增加自己的
AIDL文件用来申明服务:
BelyService.aidl:
package android.
interface IBelyService {
int calculateSqu(int value);
frameworks/base/services/java/com/android/server增加
service的实现文件:
BelyService.java:
package com.android.
import android.content.C
import android.os.IBelyS
public class BelyService extends IBelyService.Stub {
BelyService(Context context){
&&&&&&&&&&&&&&&
int calculateSqu(int val){
&&&&&&&&&&&&&&&
return val*
java服务添加到
ServiceManager中:
BelyService bs = new BelyService(context);
ServiceManager.addService(&BelyService&,
自此,重新编译
Android并运行,我们所创建的服务即可访问,下面是演示如何调用:
package/apps下任意创建一个应用,调用服务的方法如下:
import android.os.ServiceM
import android.os.IBelyS
IBelyService bs =
IBelyService.Stub.asInterface(ServiceManager.getService(&BelyService&));
int ret = bs.calculateSqu(9);
上面我们使用的是
Android内部的方法来获取服务,当然也可以使用公开的
context.getSystemService来获取。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:95043次
积分:1412
积分:1412
排名:千里之外
原创:42篇
评论:21条
(1)(4)(1)(1)(1)(1)(1)(2)(2)(1)(2)(2)(1)(1)(5)(1)(1)(2)(2)(2)(3)(4)(8)君,已阅读到文档的结尾了呢~~
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
android2.3.3源码-android.os.INetworkManagementService.aidl
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口2202人阅读
其他(21)
很久以前,因为要买手机,并且是要买千元的智能机,所以关注国内手机各大生产商很久。当然,首当其冲是小米,当时小米的性价比无线高,可以秒杀国内各大品牌手机。正当自己要入手的时候,突然发现有更多的选择,什么大黄蜂小黄蜂,再后来就是特供机,再再后来就有了小辣椒之类的,价钱甚至是小米的零头。当时对于大黄蜂搭载的阿里云OS,潜意识的就是跟MIUI是一伙的,都是一路货色,就是基于android的二次开发版本,并且里面也跟MIUI内置米聊,金山网盘一样,内嵌了很多的taobao,或者是阿里的各种应用在里面,这一点很多人不会怀疑。
& & & & 但是前段时间听到说,阿里云OS是阿里人自己开发的基于linux的手机操作系统,跟android没有直接的关系,于是,本人有点蒙,还专门baidu了一下阿里云OS是什么系统,你能看到的所有的百度知道里都说阿里云是基于android2.1或多少版本的一个系统。所有的it人,除了阿里的人,都会说阿里云是android系统的一个分支,这点似乎毫无疑问。
& & & & 然而,最近的一系列的报道,让我们对之前的认识有了一定的怀疑,似乎阿里云OS跟android没有一毛钱的关系,只是为了兼容android应用,所以实现了一个java虚拟机来达到目的,并不是我们想想的那样。我没有用过阿里云OS,并不了解阿里云OS跟其他的android系统有什么区别,或者对用户来说根本就是一模一样,没啥区别。但是根据阿里官方的说法,阿里云是阿里独立开发的基于linux的全新的系统,他有理由不兼容android的应用,或者不使用google的内置服务,并且可以自己像google那样打造一个属于阿里的操作系统生态圈。这似乎触犯了google的核心利益,让google感到很不爽,于是google对阿里发出了警告。从各路媒体我们可以了解到:阿里云是阿里人历时3年时间打造的一个开放的操作系统。然后很多的IT评论人员就对此表示怀疑,说:操作系统是一个系统级别的活,不是一般人说搞就能搞的来的,在操作系统领域,国内与国外的差距至少5-10年。其实我认为国内在操作系统领域的人才还是不少的,并且完全有能力在linux的基础上开发一款出色的手机OS。我们都知道,开发一款系统需要很大的人力物力财力,但是我觉得阿里在这方面的储备都有,并不逊色与其他大公司,如果说三年的时间,还不能完全脱胎于android的话,希望阿里可以继续花2-3年时间,开发出一款出色的手机OS。
& & & & 我们都知道,自从google收购moto之后,很多的手机厂商都不淡定了。我们都知道不能把鸡蛋都放在一个篮子里面,于是人们纷纷支持win。其实我觉得这个时候,如果有个别的公司能够适时的去做一些其他人不敢做的事情,去做一款国产手机OS,还是很值得为之鼓掌的。我们都清楚,其实早晚android都会封闭的,到时候,各大手机厂商还不得向google乖乖付钱,与其如此还不如支持国产。希望阿里云能够一直存在着。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:151661次
积分:2259
积分:2259
排名:第13587名
原创:48篇
转载:42篇
译文:11篇
评论:56条
(3)(1)(2)(4)(7)(1)(4)(5)(1)(2)(2)(4)(4)(4)(6)(21)(13)(1)(2)(3)(5)(1)(1)(6)(1)Android下点亮LED_Android_第七城市
Android下点亮LED
手上有一个android开发平台,于是想在底层加个自己的硬件模块然后通过Android的HAL方式向上封装出底层驱动供JAVA APP调用。既然是刚上手,那就用led灯来做为先导开发走走流程吧,至少得把从内核到应用层的流程走通才行。&总体思路从底层到上层一共分成四个阶段& & & & & & & & & & & & & &&1:&内核硬件驱动层2: HAL(硬件抽象层)3: 框架层(framework,包含JNI和实现硬件服务的JAVA接口)4: JAVA应用层我们从第4层往第一层倒着来说一,应用层(APP) & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &&&1,为了方便,使用Eclipse编写一个简单的控制灯的应用,添加四个button,分配控制灯1亮,灯1灭,灯2亮,灯2灭,Activity代码如下&pre name=&code& class=&java&&package com.android.import android.app.Aimport android.os.Bimport android.os.ISwtledSimport android.os.ServiceMimport android.util.Limport android.view.Vimport android.view.View.OnClickLimport android.widget.Bimport android.os.RemoteE public class swtled extends Activity {
private static final String LOG_TAG = &com.android.swtled&;
private ISwtledService swtledService =
private Button setOnLight1Button =
private Button setOffLight1Button =
private Button setOnLight2Button =
private Button setOffLight2Button =
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
swtledService = ISwtledService.Stub.asInterface(ServiceManager.getService(&swtled&));
setOnLight1Button = (Button)findViewById(R.id.button_seton_light1);
setOffLight1Button = (Button)findViewById(R.id.button_setoff_light1);
setOnLight2Button = (Button)findViewById(R.id.button_seton_light2);
setOffLight2Button = (Button)findViewById(R.id.button_setoff_light2);
setOnLight1Button.setOnClickListener(new OnClickListener()
public void onClick(View v) {
// TODO Auto-generated method stub
swtledService.setOn(1);
}catch(RemoteException e)
Log.e(LOG_TAG, &Exception while setOn Light.&);
setOffLight1Button.setOnClickListener(new OnClickListener()
public void onClick(View v) {
// TODO Auto-generated method stub
swtledService.setOff(1);
}catch(RemoteException e)
Log.e(LOG_TAG, &Exception while setOn Light.&);
setOnLight2Button.setOnClickListener(new OnClickListener()
public void onClick(View v) {
// TODO Auto-generated method stub
swtledService.setOn(2);
}catch(RemoteException e)
Log.e(LOG_TAG, &Exception while setOn Light.&);
setOffLight2Button.setOnClickListener(new OnClickListener()
public void onClick(View v) {
// TODO Auto-generated method stub
swtledService.setOff(2);
}catch(RemoteException e)
Log.e(LOG_TAG, &Exception while setOn Light.&);
}}2, AndroidManifest.xml脚本&?xml version=&1.0& encoding=&utf-8&?&&manifest xmlns:android=&/apk/res/android&
package=&com.android.swtled&
android:versionCode=&1&
android:versionName=&1.0&&
&application android:icon=&@drawable/icon& android:label=&@string/app_name&&
&activity android:name=&.swtled&
android:label=&@string/app_name&&
&intent-filter&
&action android:name=&android.intent.action.MAIN& /&
&category android:name=&android.intent.category.LAUNCHER& /&
&/intent-filter&
&/activity&
&/application&&/manifest3,字符串文件res/values/strings.xml&?xml version=&1.0& encoding=&utf-8&?&&resources&
&string name=&hello&&Hello World, swtled!&/STRING&
&string name=&app_name&&swtled&/string&
&string name=&seton_light1&&&/string&
&string name=&setoff_light1&&&/string&
&string name=&seton_light2&&&/string&
&string name=&setoff_light2&&&/string&&/resources&4,布局文件脚本main.xml&?xml version=&1.0& encoding=&utf-8&?&&LinearLayout xmlns:android=&/apk/res/android&
android:orientation=&vertical&
android:layout_width=&fill_parent&
android:layout_height=&fill_parent&
android:layout_width=&fill_parent&
android:layout_height=&wrap_content&
android:text=&@string/hello&
&LinearLayout
android:layout_width=&fill_parent&
android:layout_height=&wrap_content&
android:orientation=&horizontal&
android:gravity=&center&&
android:id=&@+id/button_seton_light1&
android:layout_width = &wrap_content&
android:layout_height = &wrap_content&
android:text = &@string/seton_light1&
android:id = &@+id/button_setoff_light1&
android:layout_width = &wrap_content&
android:layout_height = &wrap_content&
android:text = &@string/setoff_light1&
android:id=&@+id/button_seton_light2&
android:layout_width = &wrap_content&
android:layout_height = &wrap_content&
android:text = &@string/seton_light2&
android:id = &@+id/button_setoff_light2&
android:layout_width = &wrap_content&
android:layout_height = &wrap_content&
android:text = &@string/setoff_light2&
&/LinearLayout&&/LinearLayout&5,由于是编译器是Eclipse,但实际编译却是要在android源代码环境下编译,于是,将工程目录的三个文件& src,res以及AndroidManifest.xml复制到gingerbread源码目录的package/experimental/swtled下,其中& swtled文件是需要自己新建的,复制完成之后,进入编译阶段&6,编译app并生成apk文件& (1) mmm package/experimental/swtled& 编译成功后,便可以在out/target/product/generic/system/app目录下看到swtled.apk文件& (2) 重新打包系统镜像文件system.img&&&make snod&7,开机测试&&8,注意事项:在工程中需要import两个包是&import android.os.ISwtledS&import android.os.ServiceM程序通过ServiceManager.getService(&swtled&)来获得SwtledService,接着通过ISwtledService.Stub.asInterface函数转换为ISwtledService接口。其中,服务名字“swtled”是系统启动时加载SwtledService时指定的,而ISwtledService接口定义在android.os.ISwtledService中需要注意的是,虽然用Eclipse编译这个应用,但是无法用Eclipse编译,最后还是需要将工程中res,src以及AndroidManifest.xml三个文件copy到gingerbread/package/experimental/swtled,swtled是自己再新建的文件夹,&然后使用&mmm package/experimental/swtled编译,如果正确,最后会生成.apk文件。&二,框架层(framework)& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &&&这里主要实现两部分(1: 为Android HAL编写JNI方法,以便使得上层的APP能够使用下层提供的硬件服务(2: 在Android系统的框架层提供Java接口的硬件服务1,在frameworks/base/services/jni中新建com_android_server_swtled.cpp#define LOG_TAG &SwtledService&#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/swtled.h&#include &stdio.h&namespace android{
struct swtled_device_t* swtled_device = NULL;
static void swtled_set_on(JNIEnv* env, jobject clazz,jint number)
LOGI(&Swtled JNI: select lighton is %d&,num);
if (!swtled_device)
LOGI(&Swtled JNI:device is not open.&);
swtled_device-&set_on(swtled_device,num);
static void swtled_set_off(JNIEnv* env, jobject clazz,jint number)
LOGI(&Swtled JNI: select lightoff is %d&,num);
if (!swtled_device)
LOGI(&Swtled JNI:device is not open.&);
swtled_device-&set_off(swtled_device,num);
static inline int swtled_device_open(hw_module_t* module,swtled_device_t** device)
return module-&methods-&open(module,SWTLED_HARDWARE_MODULE_ID,(hw_device_t**)device);
static jboolean swtled_init(JNIEnv* env,jclass clazz)
swtled_module_t*
LOGI(&Swtled JNI: initializing...&);
if (hw_get_module(SWTLED_HARDWARE_MODULE_ID,(const struct hw_module_t**)&swtledmodule)==0)
LOGI(&Swtled JNI: swtled stub be found.&);
if (swtled_device_open(&(swtledmodule-&common),&swtled_device) == 0)
LOGI(&Swtled JNI: swtled device open successful.&);
LOGI(&Swtled JNI: failed to open swtled device.&);
return -1;
LOGI(&Swtled JNI: failed to get swtled stub module.&);
return -1;
static const JNINativeMethod method_table[] =
{&init_native&, &()Z&, (void*)swtled_init},
{&setOn_native&,&(I)V&,(void*)swtled_set_on},
{&setOff_native&,&(I)V&,(void*)swtled_set_off},
int register_android_server_SwtledService(JNIEnv* env)
return jniRegisterNativeMethods(env,&com/android/server/SwtledService&,method_table,NELEM(method_table));
}}修改同级目录下的Android.mk和Onload.cpp文件在Android.mk的LOCAL_SRC_FILES:=下添加LOCAL_SRC_FILES:= /....com_android_server_swtled.cpp /在Onload.cpp中的namespace android {& 下加入int register_android_server_SwtledService(JNIEnv* env);同时在JNI_OnLoad函数下加入register_android_server_SwtledService(env);2,编译&& (1,执行mmm framework/base/services/jni&&&(2,make snod3,在frameworks/base/core/java/android/os 新建ISwtledService.aidl,代码如下package android.interface ISwtledService {
void setOn(int number);
void setOff(int number);}返回到frameworks/base目录,打开Android.mk文件,修改LOCAL_SRC_FILES变量的值,增加&ISwtledService.aidl源文件LOCAL_SRC_FILES += /....................................................................core/java/android/os/IVibratorService.aidl /core/java/android/os/ISwtledService.aidl /core/java/android/service/urlrenderer/IUrlRendererService.aidl /4,编译ISwtledService接口&&mmm framework/base,如果正确,那么会根据ISwtledService.aidl生成对应的ISwtledService.Stub接口&5,进入到frameworks/base/services/java/com/android/server目录,新增ISwtledService.java文件:package com.android.import android.content.Cimport android.os.ISwtledSimport android.util.Spublic class SwtledService extends ISwtledService.Stub {
private static final String TAG = &SwtledService&;
SwtledService()
init_native();
public void setOn(int number)
setOn_native(number);
public void setOff(int number)
setOff_native(number);
private static native boolean init_native();
private static native void setOn_native(int number);
private static native void setOff_native(int number);};6,修改同目录下的SystemServer.java文件,在ServerThread::run方法里加入try{
Slog.i(TAG, &Swtled Service&);
ServiceManager.addService(&swtled&, new SwtledService());
} catch (Throwable e) {
Slog.e(TAG, &Failure starting Swtled Service&, e);
}7,编译SwtledService.java并打包进system.img&& (1)mmm framework/base/services/java&&&(2)make snod三,硬件抽象层& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &&1,在hardware/libhardware/include/hardware下新建swtled.h文件swtled.h#ifndef ANDROID_SWTLED_INTERFACE_H#define ANDROID_SWTLED_INTERFACE_H#include &hardware/hardware.h&__BEGIN_DECLS//module interfacestruct swtled_module_t{
struct hw_module_};//device interfacestruct swtled_device_t{
struct hw_device_
int (*set_on)(struct swtled_device_t* dev,int number);
int (*set_off)(struct swtled_device_t* dev,int number);};#define SWTLED_HARDWARE_MODULE_ID &swtled&__END_DECLS#endif2:在hardware/libhardware/module下新建swtled文件夹并新建swtled.c#define LOG_TAG &swtledStub&#include &hardware/hardware.h&#include &hardware/swtled.h&#include &fcntl.h&#include &errno.h&#include &cutils/log.h&#include &cutils/atomic.h&#include &string.h&#include &sys/types.h&#include &sys/stat.h&#include &sys/ioctl.h&#define LED_ON _IO('k',1)#define LED_OFF _IO('k',2)#define DEVICE_NAME &/dev/swt_led&#define MODULE_NAME &swtled&#define MODULE_AUTHOR &zc&//open or close device interfacestatic int swtled_device_open(const struct hw_module_t* module,const char* name, struct hw_device_t** device);static int swtled_device_close(struct hw_device_t* device);//light-on light-offstatic int swtled_set_on(struct swtled_device_t* dev,int number);static int swtled_set_off(struct swtled_device_t* dev,int number);static int swtled_device_open(const struct hw_module_t* module,const char* name, struct hw_device_t** device){
struct swtled_device_t *
dev = (struct swtled_device_t*)malloc(sizeof(struct swtled_device_t));
LOGE(&Swtled Stub:failed to alloc space&);
return -EFAULT;
memset(dev,0,sizeof(struct swtled_device_t));
dev-&common.tag = HARDWARE_DEVICE_TAG;
dev-&common.version = 0;
dev-&common.module = (hw_module_t*)
dev-&common.close = swtled_device_
dev-&set_on = swtled_set_
dev-&set_off = swtled_set_
if ((dev-&fd = open(DEVICE_NAME,O_RDWR)) == -1)
LOGE(&Swtled Stub:failed to open /dev/swt_led -- %s.&,strerror(errno));
free(dev);
return -EFAULT;
*device = &(dev-&common);
LOGI(&Swtled Stub: open /dev/swt_led successfully&);
return 0;}static int swtled_device_close(struct hw_device_t* device){
struct swtled_device_t* swtled_device = (struct swtled_device_t*)
if (swtled_device)
close(swtled_device-&fd);
free(swtled_device);
return 0;}//------------------------------------------------------------------------------//number: 1: light one 2:light two//------------------------------------------------------------------------------static int swtled_set_on(struct swtled_device_t* device,int number){
ioctl(device-&fd,LED_ON,number);
return 0;}//------------------------------------------------------------------------------//number: 1: light one 2:light two//------------------------------------------------------------------------------static int swtled_set_off(struct swtled_device_t* device,int number){
ioctl(device-&fd,LED_OFF,number);
return 0;}//module method tablestatic struct hw_module_methods_t swtled_module_methods ={
open: swtled_device_open};const struct swtled_module_t HAL_MODULE_INFO_SYM = {
tag: HARDWARE_MODULE_TAG,
version_major: 1,
version_minor: 0,
id: SWTLED_HARDWARE_MODULE_ID,
name:MODULE_NAME,
author: MODULE_AUTHOR,
methods: &swtled_module_methods,
};这里主要是通过hw_module_t和hw_device_t结构体形式将内核中led的驱动封装一层,导出set_on和set_off接口,到时供JNI层的CPP调用。由于权限问题,应用层在打开dev时可能提示permission deny,所以需要修改system/core/rootdir下的ueventd.rc文件,在其中添加一句/dev/swt_led 0666 root root3,在同目录下添加Android.mkLOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE_TAGS := optionalLOCAL_PRELINK_MODULE := falseLOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hwLOCAL_SHARED_LIBRARIES := liblogLOCAL_SRC_FILES := swtled.cLOCAL_MODULE := swtled.defaultinclude $(BUILD_SHARED_LIBRARY)4,编译&(1 进入到gingerbread目录下,执行mmm hardware/libhardware/modules/swtled会&&& 编译成功后,就可以在out/target/product/generic/system/lib/hw目录下看到swtled.default.so文件了&&(2 再执行make snod,使system.img镜像文件中包名硬件抽象模块swtled.default.so四,第一层,内核硬件驱动层 & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &&&在kernel/driver/下新建一个目录swt,在swt下再新建led文件夹,并新建swtled.c swtled.h,通过注册模块方式,实现ioctl,write,read接口。之后通过设备名给上层访问。&swtled.c部分#include &linux/kernel.h& #include &linux/sched.h& #include &linux/timer.h& #include &linux/init.h&#include &linux/module.h& #include &linux/uaccess.h&#include &linux/gpio.h& #include &linux/cdev.h& #include &linux/fs.h&#include &linux/device.h& #include &linux/miscdevice.h&#include &linux/watchdog.h&#include &linux/fs.h&#include &asm/io.h&#include &mach/gpio.h&#include &asm/uaccess.h&#define LED_ON _IO ('k',1)#define LED_OFF _IO ('k',2)struct light_dev {
};static struct light_dev *light_ static struct class * light_class = NULL; int light_major = 250;#if 0static ssize_t light_val_show(struct device* dev, struct device_attribute* attr, char* buf){
return 0;}static ssize_t light_val_store(struct device* dev, struct device_attribute* attr, const char* buf, size_t count){
return 0;}static DEVICE_ATTR(val, S_IRUGO | S_IWUSR, light_val_show, light_val_store); #endifvoid led_off(int arg){
switch(arg)
case 1: gpio_set_value(RK29_PIN6_PB3,GPIO_LOW); //GPIO8
case 2: gpio_set_value(RK29_PIN6_PC2,GPIO_LOW); //GPIO10
}}void led_on(int arg){
switch(arg)
case 1: gpio_set_value(RK29_PIN6_PB3,GPIO_HIGH);
case 2: gpio_set_value(RK29_PIN6_PC2,GPIO_HIGH);
}}int light_open(struct inode *inode, struct file *filp) {
struct light_dev *
int ret = 0;
printk(KERN_ALERT&light_open()&);
dev = container_of(inode-&i_cdev, struct light_dev, cdev);
filp-&private_data =
ret = gpio_request(RK29_PIN6_PB3, NULL);
if(ret != 0)
gpio_free(RK29_PIN6_PB3);
gpio_direction_output(RK29_PIN6_PB3, 0);
ret = gpio_request(RK29_PIN6_PC2, NULL);
if(ret != 0)
gpio_free(RK29_PIN6_PC2);
gpio_direction_output(RK29_PIN6_PC2, 0);
return 0; } int light_release(struct inode *inode, struct file *filp) {
printk(KERN_ALERT&light_release()&);
return 0;}ssize_t light_read(struct file *filp, char __user *buf, size_t count, loff_t*f_pos) {
struct light_dev *dev = filp-&private_
printk(KERN_ALERT&light_read()&);
if (copy_to_user(buf, &(dev-&value), 1))
return -EFAULT;
return 1; }ssize_t light_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos) {
struct light_dev *dev = filp-&private_
printk(KERN_ALERT&light_write()&);
if (copy_from_user(&(dev-&value), buf, 1))
return -EFAULT;
if (dev-&value == 1)
printk(KERN_ALERT&LED on&);
printk(KERN_ALERT&LED off&);
return 1; } int light_ioctl(struct inode
*inode, struct file *filp, unsigned int cmd, unsigned long arg) {
struct light_dev *dev = filp-&private_
printk(KERN_ALERT&light_ioctl(cmd = %d)&, cmd);
switch (cmd)
case LED_ON:
led_on(arg);
case LED_OFF:
led_off(arg);
return 0; } struct file_operations light_fops = {
.owner = THIS_MODULE,
.read = light_read,
.write = light_write,
.ioctl = light_ioctl,
.open = light_open,
.release = light_release,};static int light_setup_cdev(struct light_dev *dev, int index) {
int err, devno = MKDEV(light_major, index);
cdev_init(&dev-&cdev, &light_fops);
dev-&cdev.owner = THIS_MODULE;
dev-&cdev.ops = &light_
dev-&value = 0;
err = cdev_add(&dev-&cdev, devno, 1);} int light_init(void) {
int result = 0;
struct device * temp = NULL;
dev_t dev = MKDEV(light_major, 0);
printk(KERN_ALERT&light_init()&);
if (light_major) {
result = register_chrdev_region(dev, 1, &LED&);
result = alloc_chrdev_region(&dev, 0, 1, &LED&);
light_major = MAJOR(dev);
if (result & 0) {
light_devp = kmalloc(sizeof(struct light_dev), GFP_KERNEL);
if (!light_devp){
result = -ENOMEM;
memset(light_devp, 0, sizeof(struct light_dev));
result = light_setup_cdev(light_devp, 0);
if(result) {
light_class = class_create(THIS_MODULE, &led&);
if(IS_ERR(light_class)) {
printk(KERN_ALERT&Failed to create light class./n&);
goto destroy_
temp = device_create(light_class, NULL, dev, &%s&, &swtled&);
if(IS_ERR(temp)) {
printk(KERN_ALERT&Failed to create hello device.&);
goto destroy_
result = device_create_file(temp, &dev_attr_val);
if(result & 0) {
printk(KERN_ALERT&Failed to create attribute val.&);
goto destroy_
dev_set_drvdata(temp, light_devp);#endif
return 0;destroy_device:
device_destroy(light_class, dev);
destroy_class:
class_destroy(light_class);
destroy_cdev:
cdev_del(&(light_devp-&cdev)); cleanup:
kfree(light_devp);
unregister:
unregister_chrdev_region(dev, 1);
printk(KERN_ALERT&light_init failed.&);
} void light_cleanup(void) {
printk(KERN_ALERT&light_cleanup()&);
if(light_class) {
device_destroy(light_class, MKDEV(light_major, 0));
class_destroy(light_class);
if(light_devp) {
cdev_del(&light_devp-&cdev);
kfree(light_devp);
unregister_chrdev_region(MKDEV(light_major, 0), 1);
} module_init(light_init); module_exit(light_cleanup);MODULE_LICENSE(&GPL&); MODULE_DESCRIPTION(&led driver&); MODULE_ALIAS(&led module&);led文件夹中Kconfig文件config SWT_XXX_LED
bool &swt led&
This compiles in support for the led of xxx.led文件夹中MakeFile文件obj-$(CONFIG_SWT_XXX_LED)+=swt_led.oswtled文件中Kconfig文件menu &swtled Drivers&source &drivers/swt/led/Kconfig&endmenuswtled文件夹中MakeFile文件obj-y += led/接下来,就要修改kernel/driver下的MakeFile和Kconfig文件了,在分别其中添加一句MakeFile文件obj-y += swt/Kconfig文件source &drivers/swt/Kconfig&保存所有之后,执行make编译成功后,就可以在swt/led目录下看到swtled.o文件了,这时候编译出来的img已经包含了swtled驱动了9,结束以上四篇文章记录了在android平台下使用硬件led灯实现从java应用层控制灯的四个实现阶段,这个主要是记录自己的一些心得,在开发阶段也借鉴参考了一些网友的文章,在此表示感谢。(转:http://blog.chinaunix.net/uid--id-3361037.html&)
最新教程周点击榜
微信扫一扫}

我要回帖

更多关于 android swt 是什么 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信