framework添加自己的服务
来源:互联网 发布:易建联篮网数据 编辑:程序博客网 时间:2024/05/22 07:50
http://www.360doc.com/content/12/0719/19/87000_225297295.shtml 借鉴
1 frameworks/base/core/java/android/os 中添加Ismackserviec.aidl
package android.os;interface Ismackservice{ boolean seton();}
2 修改/frameworks/base/Android.mk 添加 core/java/android/os/Ismackservice.aidl ,使其得到编译
3 frameworks/base/services/java/com/android/server 中添加smack_service.java
package com.android.server;import android.content.Context;import android.os.Ismackservice;import java.io.IOException;import android.util.Log;import java.io.BufferedReader;import java.io.InputStreamReader;public final class smack_service extends Ismackservice.Stub{ public static final String TAG = "smack_service"; smack_service(Context context){ Log.i(TAG,"GET smack_service_stub"); } public boolean set_net_on(){ Log.i(TAG,"set net on"); set_net_on_jni();/* String s = "\n"; try{ Process p =Runtime.getRuntime().exec("echo ^ > /smack/ambient"); BufferedReader in = new BufferedReader( new InputStreamReader(p.getErrorStream())); String line = null; while ((line = in.readLine()) != null) { s += line + "\n"; } Log.i(TAG,s); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ return true; } public boolean set_net_off(){ Log.i(TAG,"set net off"); set_net_off_jni(); return true; } private static native void set_net_on_jni(); private static native void set_net_off_jni();}
4 修改frameworks/base/services/java/com/android/server/SystemServer.java 注册smack_service
Slog.i(TAG, "smack_service");
ServiceManager.addService(Context.SMACK_SERVICE,new smack_service(context));
修改 frameworks/base/core/java/android/content/Context.java
public static final String SMACK_SERVICE = "smack";//xiayu fix
5 make_updata-api mmm framework/base/services/java m
6 编写测试apk , 在eclipse中,右键-》Buid Path->Configure Build Path->Libraries->Add External Jars
out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar
自己编的jni
#include "jni.h"#include "JNIHelp.h"#include "android_runtime/AndroidRuntime.h"#include <utils/misc.h>#include <utils/Log.h>#include <fcntl.h>#include <errno.h>#include <stdlib.h>#include <stdio.h>#include <unistd.h>#include <sys/time.h>#include <time.h>#include <errno.h>#include <string.h>#include <sys/stat.h>#include <sys/types.h>#include <dirent.h>#include <hardware/smack.h>#define LOG_TAG "smack_service-JNI"namespace android{static inline int smack_control_open(const struct hw_module_t* module, struct smack_control_device_t** device) { return module->methods->open(module, SMACK_HARDWARE_MODULE_ID, (struct hw_device_t**)device);}static void set_net_on_jni(JNIEnv *env, jobject clazz){ smack_module_t* module;struct smack_control_device_t *smackDevice; LOGE("xiayu set_net_on jni\n"); if (hw_get_module(SMACK_HARDWARE_MODULE_ID, (const hw_module_t**)&module) == 0) { LOGI("SMACKService JNI: SMACK Stub found."); if (smack_control_open(&module->common, &smackDevice) == 0) { LOGI("LedService JNI: Got Stub operations."); } } char *st="hao"; char buf[10]; int fd3=open("/sys/power/wake_lock",O_RDWR); LOGE("xiayu open wrong error fd3 =%d ,errno =%d",fd3, errno); int tt= write(fd3,st,3); LOGE("xiayu write wrong error =%d uid=%d pid=%d tt=%d",errno,getuid(),getpid(),tt); int yy=read(fd3,buf,3); LOGE("xiayu read error=%d buf[]=%c yy=%d",errno,buf[0],yy); close(fd3); smackDevice->set_net_on(smackDevice, 2);}static void set_net_off_jni(JNIEnv *env, jobject clazz){LOGE("xiayu set_net_off jni\n"); int fd = open("/smack", O_WRONLY); if(fd<0){ LOGE("xiayu off wrong error=%d",errno); //perror("xiayu"); }}static JNINativeMethod method_table[] = { { "set_net_on_jni", "()V", (void*)set_net_on_jni }, { "set_net_off_jni", "()V", (void*)set_net_off_jni },};int register_android_server_smack_service(JNIEnv *env){ return jniRegisterNativeMethods(env, "com/android/server/smack_service", method_table, NELEM(method_table));}}
- framework添加自己的服务
- 添加自己的Web服务
- framework添加服务(实例)
- android framework添加系统服务
- android framework 添加系统服务
- 创建自己的framework
- 创建自己的framework
- 进程间通信 binder机制-添加自己的系统服务
- Android5.1 在init.rc 中添加自己的服务
- Andrioid Framework中添加系统服务
- 对于framework的目录结构分析以及简单的添加一个java层服务
- EALayout 第八节 如何在自己的工程里添加EALayout.framework
- Android5.1 FrameWork添加自己的SystemService提供API给APP
- 在framework当中添加一个系统自定义服务,权限的问题
- Android 6.0 如何添加完整的系统服务(app-framework-kernel)
- 创建自己的cocoa framework。
- 创建自己的cocoa framework
- ios 制作自己的framework
- spring3.0包介绍
- cocos2d-x视频教程跨平台游戏开发
- ScaleType的用法
- 一台机器安装运行多个ArcSDE数据库
- php+apache配置注意的一些细节
- framework添加自己的服务
- PHP 操作ACCES 插入记录
- csapp2e 家庭作业 2.72
- js 取整数
- USB如何检测到设备的插入-usb技术入门教程1
- 后可视化编程
- 表数据和索引数据分开独立表空间存储优点
- 古堡算式--蓝桥杯
- 环球投资旅行:穿越六大洲的投资奇遇