diff options
author | Daniel Hillenbrand <daniel.hillenbrand@codeworkx.de> | 2012-07-25 04:32:16 +0200 |
---|---|---|
committer | Daniel Hillenbrand <daniel.hillenbrand@codeworkx.de> | 2012-07-25 04:32:16 +0200 |
commit | 51841ab0c58201c6c45ca22ceac30f1229213f7d (patch) | |
tree | a41a43753b458be8976d7684c2741b249d4fc33a /tvout | |
download | device_samsung_galaxys2-common-51841ab0c58201c6c45ca22ceac30f1229213f7d.zip device_samsung_galaxys2-common-51841ab0c58201c6c45ca22ceac30f1229213f7d.tar.gz device_samsung_galaxys2-common-51841ab0c58201c6c45ca22ceac30f1229213f7d.tar.bz2 |
initial commit
Diffstat (limited to 'tvout')
-rw-r--r-- | tvout/Android.mk | 16 | ||||
-rw-r--r-- | tvout/AndroidManifest.xml | 24 | ||||
-rw-r--r-- | tvout/proguard.flags | 1 | ||||
-rw-r--r-- | tvout/src/android/hardware/Tvout.java | 102 | ||||
-rw-r--r-- | tvout/src/com/teamhacksung/tvout/BootCompletedReceiver.java | 12 | ||||
-rw-r--r-- | tvout/src/com/teamhacksung/tvout/TvOutService.java | 116 |
6 files changed, 271 insertions, 0 deletions
diff --git a/tvout/Android.mk b/tvout/Android.mk new file mode 100644 index 0000000..c73e1cf --- /dev/null +++ b/tvout/Android.mk @@ -0,0 +1,16 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional + +LOCAL_PROGUARD_FLAG_FILES := proguard.flags + +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_PACKAGE_NAME := TvOut +LOCAL_CERTIFICATE := platform + +include $(BUILD_PACKAGE) + +# Use the folloing include to make our test apk. +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/tvout/AndroidManifest.xml b/tvout/AndroidManifest.xml new file mode 100644 index 0000000..79d5745 --- /dev/null +++ b/tvout/AndroidManifest.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.teamhacksung.tvout" android:versionCode="1" + android:versionName="1.0"> + + <application android:label="TvOut"> + + <service android:exported="false" android:enabled="true" + android:name=".TvOutService"> + </service> + + <receiver android:name=".BootCompletedReceiver"> + <intent-filter> + <action android:name="android.intent.action.BOOT_COMPLETED" /> + <category android:name="android.intent.category.DEFAULT" /> + </intent-filter> + </receiver> + + </application> + + <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission> + <uses-permission android:name="android.permission.BROADCAST_STICKY"></uses-permission> + <uses-permission android:name="android.permission.FACTORY_TEST"></uses-permission> +</manifest> diff --git a/tvout/proguard.flags b/tvout/proguard.flags new file mode 100644 index 0000000..3725966 --- /dev/null +++ b/tvout/proguard.flags @@ -0,0 +1 @@ +-dontshrink diff --git a/tvout/src/android/hardware/Tvout.java b/tvout/src/android/hardware/Tvout.java new file mode 100644 index 0000000..f2fc3a8 --- /dev/null +++ b/tvout/src/android/hardware/Tvout.java @@ -0,0 +1,102 @@ +package android.hardware; + +import android.util.Log; + +public class Tvout { + private static final String TAG = "Tvout_java"; + + static { + System.loadLibrary("tvout_jni"); + } + + public Tvout() { + Log.i(TAG, "Tvout Initializing"); + _native_setup(); + } + + private native boolean _TvoutGetCableStatus(); + + private native boolean _TvoutGetStatus(); + + private native boolean _TvoutGetSubtitleStatus(); + + private native boolean _TvoutGetSuspendStatus(); + + private native boolean _TvoutPostSubtitle(String string, int param); + + private native boolean _TvoutPostSuspend(String string); + + private native boolean _TvoutSetCableStatus(boolean connected); + + private native boolean _TvoutSetOutputMode(int mode); + + private native boolean _TvoutSetResolution(int resolution); + + private native boolean _TvoutSetStatus(boolean enabled); + + private native boolean _TvoutSetSubtitleStatus(boolean enabled); + + private native boolean _TvoutSetSuspendStatus(boolean enabled); + + private native boolean _TvoutSetDefaultString(String string); + + private final native void _native_setup(); + + private final native void _release(); + + public boolean getCableStatus() { + return _TvoutGetCableStatus(); + } + + public boolean getStatus() { + return _TvoutGetStatus(); + } + + public boolean getSubtitleStatus() { + return _TvoutGetSubtitleStatus(); + } + + public boolean getSuspendStatus() { + return _TvoutGetSuspendStatus(); + } + + public boolean postSubtitle(String string, int paramInt) { + return _TvoutPostSubtitle(string, paramInt); + } + + public boolean postSuspend(String string) { + return _TvoutPostSuspend(string); + } + + public boolean setCableStatus(boolean connected) { + return _TvoutSetCableStatus(connected); + } + + public boolean setOutputMode(int mode) { + return _TvoutSetOutputMode(mode); + } + + public boolean setResolution(int resolution) { + return _TvoutSetResolution(resolution); + } + + public boolean setStatus(boolean enabled) { + return _TvoutSetStatus(enabled); + } + + public boolean setSubtitleStatus(boolean enabled) { + return _TvoutSetSubtitleStatus(enabled); + } + + public boolean setSuspendStatus(boolean enabled) { + return _TvoutSetSuspendStatus(enabled); + } + + public boolean setDefaultString(String string) { + return _TvoutSetDefaultString(string); + } + + public void release() { + _release(); + } +} diff --git a/tvout/src/com/teamhacksung/tvout/BootCompletedReceiver.java b/tvout/src/com/teamhacksung/tvout/BootCompletedReceiver.java new file mode 100644 index 0000000..5ed6af6 --- /dev/null +++ b/tvout/src/com/teamhacksung/tvout/BootCompletedReceiver.java @@ -0,0 +1,12 @@ +package com.teamhacksung.tvout; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +public class BootCompletedReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + context.startService(new Intent(context, TvOutService.class)); + } +} diff --git a/tvout/src/com/teamhacksung/tvout/TvOutService.java b/tvout/src/com/teamhacksung/tvout/TvOutService.java new file mode 100644 index 0000000..b633b3d --- /dev/null +++ b/tvout/src/com/teamhacksung/tvout/TvOutService.java @@ -0,0 +1,116 @@ +package com.teamhacksung.tvout; + +import android.app.Service; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.hardware.Tvout; +import android.nfc.Tag; +import android.os.IBinder; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.util.Log; + +public class TvOutService extends Service { + + public static final String TAG = "TvOutService_java"; + + private Tvout mTvOut; + private boolean mWasOn = false; // For enabling on screen on + + private BroadcastReceiver mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (Intent.ACTION_HDMI_AUDIO_PLUG.equals(action)) { + getTvoutInstance(); + int state = intent.getIntExtra("state", 0); + if (state == 1 && !mTvOut.getStatus()) { + // Enable when cable is plugged + Log.i(TAG, "HDMI plugged"); + mWasOn = false; + enable(); + } else if (mTvOut.getStatus()) { + // Disable when cable is unplugged + Log.i(TAG, "HDMI unplugged"); + mWasOn = false; + disable(); + releaseTvout(); + } + } else if (Intent.ACTION_SCREEN_ON.equals(action)) { + if (mTvOut != null && mWasOn) { + Log.i(TAG, "Screen On - Resume TvOut stream"); + mWasOn = false; + mTvOut.setSuspendStatus(false); + } + } else if (Intent.ACTION_SCREEN_OFF.equals(action)) { + if (mTvOut != null && mTvOut.getStatus()) { + Log.i(TAG, "Screen Off - Pausing TvOut stream"); + mWasOn = true; + mTvOut.setSuspendStatus(true); + } + } + } + + }; + + @Override + public IBinder onBind(Intent intent) { + return null; + } + + @Override + public void onCreate() { + IntentFilter filter = new IntentFilter(Intent.ACTION_HDMI_AUDIO_PLUG); + filter.addAction(Intent.ACTION_SCREEN_OFF); + filter.addAction(Intent.ACTION_SCREEN_ON); + registerReceiver(mReceiver, filter); + Log.i(TAG, "Registered Receiver"); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + return START_STICKY; + } + + private boolean getTvoutInstance() { + if (mTvOut != null) return true; + + try { + mTvOut = new Tvout(); + } catch (Exception e) { + return false; + } + + return true; + } + + private void releaseTvout() { + if (mTvOut != null) { + mTvOut.release(); + mTvOut = null; + } + } + + @Override + public void onDestroy() { + unregisterReceiver(mReceiver); + releaseTvout(); + super.onDestroy(); + } + + private void enable() { + if (mTvOut == null) return; + mTvOut.setStatus(true); + mTvOut.setCableStatus(true); + mTvOut.setSuspendStatus(false); + } + + private void disable() { + if (mTvOut == null) return; + mTvOut.setStatus(false); + mTvOut.setCableStatus(false); + } + +} |