android 模拟IR(续二)---框架

框架中的实现很简单,且千篇一律,这里直接给出patch内容。


Index: frameworks/base/Android.mk
===================================================================
--- frameworks/base/Android.mk	(revision 5203)
+++ frameworks/base/Android.mk	(working copy)
@@ -120,6 +120,7 @@
 	core/java/android/hardware/display/IDisplayManagerCallback.aidl  	core/java/android/hardware/input/IInputManager.aidl  	core/java/android/hardware/input/IInputDevicesChangedListener.aidl +	core/java/android/hardware/output/IIrSendManager.aidl  	core/java/android/hardware/usb/IUsbManager.aidl  	core/java/android/net/IConnectivityManager.aidl  	core/java/android/net/INetworkManagementEventObserver.aidl Index: frameworks/base/core/java/android/app/ContextImpl.java
===================================================================
--- frameworks/base/core/java/android/app/ContextImpl.java	(revision 5203)
+++ frameworks/base/core/java/android/app/ContextImpl.java	(working copy)
@@ -49,6 +49,8 @@
 import android.hardware.ISerialManager;
 import android.hardware.SensorManager;
 import android.hardware.SerialManager;
+import android.hardware.output.IrSendManager;
+import android.hardware.output.IIrSendManager;
 import android.hardware.SystemSensorManager;
 import android.hardware.display.DisplayManager;
 import android.hardware.input.IInputManager;
@@ -497,6 +499,14 @@
                     return new SerialManager(ctx, ISerialManager.Stub.asInterface(b));
                 }});
 
+		//yanxi for soniq irout
+		
+        registerService(IRSEND_SERVICE, new ServiceFetcher() {
+                public Object createService(ContextImpl ctx) {
+                    IBinder b = ServiceManager.getService(IRSEND_SERVICE);
+                    return new IrSendManager(ctx, IIrSendManager.Stub.asInterface(b));
+                }});		
+				
         registerService(VIBRATOR_SERVICE, new ServiceFetcher() {
                 public Object createService(ContextImpl ctx) {
                     return new SystemVibrator();
Index: frameworks/base/core/java/android/content/Context.java
===================================================================
--- frameworks/base/core/java/android/content/Context.java	(revision 5203)
+++ frameworks/base/core/java/android/content/Context.java	(working copy)
@@ -2207,6 +2207,19 @@
 
     /**
      * Use with {@link #getSystemService} to retrieve a {@link
+    /**
+     * Use with {@link #getSystemService} to retrieve a {@link
+     * android.hardware.IrSendManager} for access to IRSEND_SERVICE.
+     *
+     * @see #getSystemService
+     * @see  android.hardware.output.IrSendManager
+     *
+     * @hide
+     */
+    public static final String IRSEND_SERVICE = "irsend";
+
+	/**
+     * Use with {@link #getSystemService} to retrieve a {@link
      * android.hardware.SerialManager} for access to serial ports.
      *
      * @see #getSystemService
@@ -2215,7 +2228,6 @@
      * @hide
      */
     public static final String SERIAL_SERVICE = "serial";
-
     /**
      * Use with {@link #getSystemService} to retrieve a
      * {@link android.hardware.input.InputManager} for interacting with input devices.
Index: frameworks/base/core/java/android/hardware/output/IIrSendManager.aidl
===================================================================
--- frameworks/base/core/java/android/hardware/output/IIrSendManager.aidl	(revision 0)
+++ frameworks/base/core/java/android/hardware/output/IIrSendManager.aidl	(working copy)
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hardware.output;
+
+
+/** @hide */
+interface IIrSendManager
+{
+	boolean SendIR(int head, int scancode, boolean Outreverse);
+}
Index: frameworks/base/core/java/android/hardware/output/IrSendManager.java
===================================================================
--- frameworks/base/core/java/android/hardware/output/IrSendManager.java	(revision 0)
+++ frameworks/base/core/java/android/hardware/output/IrSendManager.java	(working copy)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2014 siviton msd6369
+ * yanxi 20140125 for soniq ir out function
+ */
+
+
+package android.hardware.output;
+
+import android.app.PendingIntent;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.ParcelFileDescriptor;
+import android.os.RemoteException;
+import android.os.SystemProperties;
+import android.util.Log;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+/**
+ * @hide
+ */
+public class IrSendManager {
+    private static final String TAG = "IrSendManager";
+
+    private final Context mContext;
+    private final IIrSendManager mService;
+
+    /**
+     * {@hide}
+     */
+    public IrSendManager(Context context, IIrSendManager service) {
+        mContext = context;
+        mService = service;
+		Log.d(TAG,"IrSendManager");
+    }
+
+	public boolean SendIR(int head, int scancode, boolean Outreverse) throws android.os.RemoteException{
+		Log.d(TAG,"scancode:"+scancode);
+		return mService.SendIR(head, scancode, Outreverse);
+	}
+}
Index: frameworks/base/services/java/com/android/server/IrSendService.java
===================================================================
--- frameworks/base/services/java/com/android/server/IrSendService.java	(revision 0)
+++ frameworks/base/services/java/com/android/server/IrSendService.java	(working copy)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2014 siviton msd6369
+ * yanxi 20140125 for soniq ir out function
+ */
+
+package com.android.server;
+
+import android.content.Context;
+import android.hardware.output.IIrSendManager;
+import android.util.Log;
+
+import java.io.File;
+import java.util.ArrayList;
+
+public class IrSendService extends IIrSendManager.Stub {
+    private static final String TAG = "IrSendManager";
+
+    private final Context mContext;
+    private int mIrSendFd = -1;
+
+    public IrSendService(Context context) {
+        mContext = context;
+		if(mIrSendFd == -1){
+        	mIrSendFd = native_open();
+			Log.d(TAG, "mIrSendFd:"+mIrSendFd);
+		}else
+			Log.d(TAG, "mIrSendFd1:"+mIrSendFd);
+
+    }
+
+	public boolean SendIR(int head, int scancode, boolean Outreverse){
+		if(mIrSendFd > 0)
+		{	
+			return native_irsend(head, scancode, Outreverse);
+		}
+		else {
+			return false;
+		}
+	}
+	
+    private native static int native_open();
+	private native static boolean native_close();
+	private native static boolean native_irsend(int head, int scancode, boolean Outreverse);
+
+}
Index: frameworks/base/services/java/com/android/server/SystemServer.java
===================================================================
--- frameworks/base/services/java/com/android/server/SystemServer.java	(revision 5203)
+++ frameworks/base/services/java/com/android/server/SystemServer.java	(working copy)
@@ -156,6 +156,7 @@
         // MStar Android Patch End
         UsbService usb = null;
         SerialService serial = null;
+		IrSendService IrSend = null;//yanxi 0125
         TwilightService twilight = null;
         UiModeManagerService uiMode = null;
         RecognitionManagerService recognition = null;
@@ -735,7 +736,18 @@
                 Slog.e(TAG, "Failure starting SerialService", e);
             }
 
+			//yanxi for soniq irout start
+			
             try {
+                Slog.i(TAG, "IrSend Service");
+                IrSend = new IrSendService(context);
+                ServiceManager.addService(Context.IRSEND_SERVICE, IrSend);
+            } catch (Throwable e) {
+                Slog.e(TAG, "Failure starting IrSend Service", e);
+            }
+            
+			//yanxi end
+            try {
                 Slog.i(TAG, "Twilight Service");
                 twilight = new TwilightService(context);
             } catch (Throwable e) {
Index: frameworks/base/services/jni/Android.mk
===================================================================
--- frameworks/base/services/jni/Android.mk	(revision 5203)
+++ frameworks/base/services/jni/Android.mk	(working copy)
@@ -16,6 +16,7 @@
     com_android_server_VibratorService.cpp      com_android_server_location_GpsLocationProvider.cpp      com_android_server_connectivity_Vpn.cpp +    com_android_server_IrSend.cpp      onload.cpp
 
 # MStar Android Patch Begin
Index: frameworks/base/services/jni/com_android_server_IrSend.cpp
===================================================================
--- frameworks/base/services/jni/com_android_server_IrSend.cpp	(revision 0)
+++ frameworks/base/services/jni/com_android_server_IrSend.cpp	(working copy)
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2014 siviton msd6369
+ * yanxi 20140125 for soniq ir out function
+ */
+
+#define LOG_TAG "IRSENDJNI"
+
+#include "utils/Log.h"
+#include "JNIHelp.h"
+#include "android_runtime/AndroidRuntime.h"
+#include <termios.h>
+#include <stdio.h>
+#include <linux/input.h>
+#include <linux/uinput.h>
+#include <time.h>
+#include <sys/time.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <stdlib.h>
+#include <jni.h> 
+
+namespace android{
+
+static int uIrSend_fd = -1;
+//static jfieldID field_context;
+struct IR_CODE
+{
+    unsigned short uHead;
+    unsigned char uScancode;
+	unsigned char bOutreverse;
+};
+typedef struct IR_CODE IR_CODE_t;
+
+/*
+ * Class:     android_server_IrSend_open
+ * Method:    open
+ * Signature: ()Z
+ */
+static jint android_server_IrSend_open(JNIEnv *evn, jclass thiz)
+{
+    // Open the input device
+    uIrSend_fd = open("/dev/Mstar-gpio", O_WRONLY | O_NDELAY);
+    if (uIrSend_fd == -1) {
+        ALOGE("android_server_IrSend_open uIrSend_fd:%d",uIrSend_fd);
+        return 0;
+    }
+    return uIrSend_fd;
+}
+
+/*
+ * Class:     android_server_IrSend_close
+ * Method:    close
+ * Signature: ()Z
+ */
+static jboolean android_server_IrSend_close(JNIEnv *env, jclass thiz)
+{ 	
+    close(uIrSend_fd);
+  	
+  	return 1;
+  	
+}
+
+/*
+ * Class:     android_server_IrSend_sendir
+ * Method:    sendir
+ * Signature: (CC)Z
+ */
+static jboolean android_server_IrSend_sendir(JNIEnv *env, jclass thiz, jint head, jint scancode, jboolean Outreverse)
+{
+	IR_CODE_t mIR_CODE_t;
+	mIR_CODE_t.uHead = (unsigned short)head;
+	mIR_CODE_t.uScancode = (unsigned char)scancode;
+	mIR_CODE_t.bOutreverse = (unsigned char)Outreverse;
+	//ioctl(uIrSend_fd,_IOW(‘g‘, 9, IR_CODE_t),mIR_CODE_t);
+	write(uIrSend_fd, &mIR_CODE_t, sizeof(IR_CODE_t));
+	return 1;
+}
+
+static JNINativeMethod method_table[] = {
+    {"native_open",             "()I",(void *)android_server_IrSend_open},
+    {"native_close",            "()Z",  (void *)android_server_IrSend_close},
+    {"native_irsend",       "(IIZ)Z",  (void *)android_server_IrSend_sendir},
+};
+
+int register_android_server_IrSend(JNIEnv *env)
+{
+    jclass clazz = env->FindClass("com/android/server/IrSendService");
+    if (clazz == NULL) {
+        ALOGE("Can‘t find com/android/server/IrSendService");
+        return -1;
+    }
+	
+    return jniRegisterNativeMethods(env, "com/android/server/IrSendService",
+            method_table, NELEM(method_table));
+}
+};
Index: frameworks/base/services/jni/onload.cpp
===================================================================
--- frameworks/base/services/jni/onload.cpp	(revision 5203)
+++ frameworks/base/services/jni/onload.cpp	(working copy)
@@ -34,6 +34,7 @@
 int register_android_server_SystemServer(JNIEnv* env);
 int register_android_server_location_GpsLocationProvider(JNIEnv* env);
 int register_android_server_connectivity_Vpn(JNIEnv* env);
+int register_android_server_IrSend(JNIEnv *env);//yanxi 140125
 };
 
 using namespace android;
@@ -51,6 +52,7 @@
 
     register_android_server_PowerManagerService(env);
     register_android_server_SerialService(env);
+    register_android_server_IrSend(env);
     register_android_server_InputApplicationHandle(env);
     register_android_server_InputWindowHandle(env);
     register_android_server_InputManager(env);


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。