diff --git a/cocos/cocos2d.h b/cocos/cocos2d.h index 2a8882ed3e..0c0beee7b3 100644 --- a/cocos/cocos2d.h +++ b/cocos/cocos2d.h @@ -198,6 +198,9 @@ THE SOFTWARE. #include "platform/android/CCGLViewImpl-android.h" #include "platform/android/CCGL-android.h" #include "platform/android/CCStdC-android.h" +//Enhance modification begin + #include "platform/android/CCEnhanceAPI-android.h" +//Enhance modification end #endif // CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID #if (CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY) diff --git a/cocos/platform/android/Android.mk b/cocos/platform/android/Android.mk index 3ff757e5bc..90324b197e 100644 --- a/cocos/platform/android/Android.mk +++ b/cocos/platform/android/Android.mk @@ -13,6 +13,7 @@ CCDevice-android.cpp \ CCGLViewImpl-android.cpp \ CCFileUtils-android.cpp \ javaactivity-android.cpp \ +CCEnhanceAPI-android.cpp \ jni/DPIJni.cpp \ jni/IMEJni.cpp \ jni/Java_org_cocos2dx_lib_Cocos2dxAccelerometer.cpp \ diff --git a/cocos/platform/android/CCEnhanceAPI-android.cpp b/cocos/platform/android/CCEnhanceAPI-android.cpp new file mode 100644 index 0000000000..424fc51e4a --- /dev/null +++ b/cocos/platform/android/CCEnhanceAPI-android.cpp @@ -0,0 +1,105 @@ +/**************************************************************************** + * Samsung API for cocos + * Developed by Game Engine part + * + * Copyright 2015 by Mobile Solution Lab, MSG, SRC-NJ. + * Wang Ying + * All rights reserved. + * + * This software is the confidential and proprietary information of + * Samsung Electronics, Inc. ("Confidential Information"). You + * Shall not disclose such Confidential Information and shall use + * it only in accordance with the terms of the license agreement + * you entered into with Samsung +****************************************************************************/ + + +#include "platform/CCPlatformConfig.h" +#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID + +#include "jni/JniHelper.h" +#include "CCEnhanceAPI-android.h" +#include +#include + +#define LOG_TAG "CCEnhanceAPI_android Debug" +#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) + +#define CLASS_NAME "org/cocos2dx/lib/Cocos2dxHelper" + +// FIXME: using ndk-r10c will cause the next function could not be found. It may be a bug of ndk-r10c. +// Here is the workaround method to fix the problem. +#ifdef __aarch64__ +extern "C" size_t __ctype_get_mb_cur_max(void) { + return (size_t) sizeof(wchar_t); +} +#endif + +NS_CC_BEGIN + +EnhanceAPI::EnhanceAPI() +{ +} + +EnhanceAPI::~EnhanceAPI() +{ +} + +int EnhanceAPI::setResolutionPercent(int n) +{ + JniMethodInfo t; + int ret = -1; + if(JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setResolutionPercent", "(I)I")) + { + ret = t.env->CallStaticIntMethod(t.classID, t.methodID, n); + } + return ret; +} + +int EnhanceAPI::setFPS(int fps) +{ + JniMethodInfo t; + int ret = -1; + if(JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setFPS", "(I)I")) + { + ret = t.env->CallStaticIntMethod(t.classID, t.methodID, fps); + } + return ret; +} + +int EnhanceAPI::fastLoading(int sec) +{ + JniMethodInfo t; + int ret = -1; + if(JniHelper::getStaticMethodInfo(t, CLASS_NAME, "fastLoading", "(I)I")) + { + ret = t.env->CallStaticIntMethod(t.classID, t.methodID, sec); + } + return ret; +} + +int EnhanceAPI::getTemperature() +{ + JniMethodInfo t; + int ret = -1; + if(JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getTemperature", "()I")) + { + ret = t.env->CallStaticIntMethod(t.classID, t.methodID); + } + return ret; +} + +int EnhanceAPI::setLowPowerMode(bool enable) +{ + JniMethodInfo t; + int ret = -1; + if(JniHelper::getStaticMethodInfo(t, CLASS_NAME, "fastLoading", "(Z)I")) + { + ret = t.env->CallStaticIntMethod(t.classID, t.methodID, enable); + } + return ret; +} +NS_CC_END + +#endif // CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID + diff --git a/cocos/platform/android/CCEnhanceAPI-android.h b/cocos/platform/android/CCEnhanceAPI-android.h new file mode 100644 index 0000000000..ebcee7dbfd --- /dev/null +++ b/cocos/platform/android/CCEnhanceAPI-android.h @@ -0,0 +1,84 @@ +/**************************************************************************** + * Samsung API for cocos + * Developed by Game Engine part + * + * Copyright 2015 by Mobile Solution Lab, MSG, SRC-NJ. + * Wang Ying + * All rights reserved. + * + * This software is the confidential and proprietary information of + * Samsung Electronics, Inc. ("Confidential Information"). You + * Shall not disclose such Confidential Information and shall use + * it only in accordance with the terms of the license agreement + * you entered into with Samsung +****************************************************************************/ + +#ifndef __CC_ENHANCEAPI_ANDROID_H__ +#define __CC_ENHANCEAPI_ANDROID_H__ + +#include "platform/CCPlatformConfig.h" +#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID + +#include "platform/CCCommon.h" +#include "platform/CCApplicationProtocol.h" + +NS_CC_BEGIN + +class CC_DLL EnhanceAPI +{ +public: + /** + * @js ctor + */ + EnhanceAPI(); + /** + * @js NA + * @lua NA + */ + virtual ~EnhanceAPI(); + + /** + @brief call gameservice setResolutionSize API. + @param the optimized percent value. + @return success: 0, fail: -1. + */ + static int setResolutionPercent(int n); + + /** + @brief call gameservice setFPS API. + @param the fps value. + @return success: 0, fail: -1. + */ + static int setFPS(int fps); + + /** + @brief call gameservice fastLoading API. + @param the fast loading seconds. + @return success: 0, fail: -1. + */ + static int fastLoading(int sec); + + /** + @brief call gameservice getTemperature API. + @return -1: fail to get temperature + 0: normal temperature + 1: high + 2,3: very high + */ + static int getTemperature(); + + /** + @brief call gameservice setLowPowerMode API. + @return -1: fail to get temperature + 0: normal temperature + 1: high + 2,3: very high + */ + static int setLowPowerMode(bool enable); +}; + +NS_CC_END + +#endif // CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID + +#endif // __CC_ENHANCEAPI_ANDROID_H__ \ No newline at end of file diff --git a/cocos/platform/android/java/src/com/enhance/gameservice/IGameTunningService.aidl b/cocos/platform/android/java/src/com/enhance/gameservice/IGameTunningService.aidl new file mode 100644 index 0000000000..6bce7eeaff --- /dev/null +++ b/cocos/platform/android/java/src/com/enhance/gameservice/IGameTunningService.aidl @@ -0,0 +1,10 @@ +package com.enhance.gameservice; + +interface IGameTunningService +{ + int setPreferredResolution(int resolution); + int setFramePerSecond(int fps); + int boostUp(int seconds); + int getAbstractTemperature(); + int setGamePowerSaving(boolean enable); +} \ No newline at end of file diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java index 9138e22b2d..a9a5923656 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java @@ -33,6 +33,7 @@ import java.lang.Runnable; import com.chukong.cocosplay.client.CocosPlayClient; import android.app.Activity; +import android.content.ComponentName; //Enhance API modification import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -40,18 +41,26 @@ import android.content.pm.ApplicationInfo; import android.content.res.AssetManager; import android.net.Uri; import android.os.Build; +import android.os.IBinder; //Enhance API modification import android.preference.PreferenceManager.OnActivityResultListener; import android.util.DisplayMetrics; +import android.util.Log; //Enhance API modification import android.view.Display; import android.view.WindowManager; +import android.content.ServiceConnection; //Enhance API modification + +import com.enhance.gameservice.IGameTunningService; //Enhance API modification public class Cocos2dxHelper { // =========================================================== // Constants // =========================================================== + //Enhance API modification begin + private final static String TAG = Cocos2dxHelper.class.getSimpleName(); + //Enhance API modification end private static final String PREFS_NAME = "Cocos2dxPrefsFile"; private static final int RUNNABLES_PER_FRAME = 5; - + // =========================================================== // Fields // =========================================================== @@ -67,7 +76,10 @@ public class Cocos2dxHelper { private static Activity sActivity = null; private static Cocos2dxHelperListener sCocos2dxHelperListener; private static Set onActivityResultListeners = new LinkedHashSet(); - + //Enhance API modification begin + private static IGameTunningService mGameServiceBinder = null; + private static final int BOOST_TIME = 7; + //Enhance API modification end // =========================================================== // Constructors @@ -104,10 +116,26 @@ public class Cocos2dxHelper { sActivity = activity; sInited = true; - + + //Enhance API modification begin + activity.getApplicationContext().bindService(new Intent(IGameTunningService.class.getName()), connection, Context.BIND_AUTO_CREATE); + //Enhance API modification end } } + //Enhance API modification begin + private static ServiceConnection connection = new ServiceConnection() { + public void onServiceConnected(ComponentName name, IBinder service) { + mGameServiceBinder = IGameTunningService.Stub.asInterface(service); + fastLoading(BOOST_TIME); + } + + public void onServiceDisconnected(ComponentName name) { + sActivity.getApplicationContext().unbindService(connection); + } + }; + //Enhance API modification end + public static Activity getActivity() { return sActivity; } @@ -424,4 +452,76 @@ public class Cocos2dxHelper { public void runOnGLThread(final Runnable pRunnable); } + + //Enhance API modification begin + public static int setResolutionPercent(int per) + { + try{ + if(mGameServiceBinder != null) + { + return mGameServiceBinder.setPreferredResolution(per); + } + return -1; + }catch (Exception e) { + e.printStackTrace(); + return -1; + } + } + + public static int setFPS(int fps) + { + try{ + if(mGameServiceBinder != null) + { + return mGameServiceBinder.setFramePerSecond(fps); + } + return -1; + }catch (Exception e) { + e.printStackTrace(); + return -1; + } + } + + public static int fastLoading(int sec) + { + try{ + if(mGameServiceBinder != null) + { + return mGameServiceBinder.boostUp(sec); + } + return -1; + }catch (Exception e) { + e.printStackTrace(); + return -1; + } + } + + public static int getTemperature() + { + try{ + if(mGameServiceBinder != null) + { + return mGameServiceBinder.getAbstractTemperature(); + } + return -1; + }catch (Exception e) { + e.printStackTrace(); + return -1; + } + } + + public static int setLowPowerMode(boolean enable) + { + try{ + if(mGameServiceBinder != null) + { + return mGameServiceBinder.setGamePowerSaving(enable); + } + return -1; + }catch (Exception e) { + e.printStackTrace(); + return -1; + } + } + //Enhance API modification end } diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index bdf6bb7b41..e0d6a98564 100644 --- a/templates/cocos2dx_files.json +++ b/templates/cocos2dx_files.json @@ -858,6 +858,7 @@ "cocos/platform/android/java/lint.xml", "cocos/platform/android/java/proguard-project.txt", "cocos/platform/android/java/project.properties", + "cocos/platform/android/java/src/com/enhance/gameservice/IGameTunningService.aidl", "cocos/platform/android/java/src/com/chukong/cocosplay/client/CocosPlayClient.java", "cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxAccelerometer.java", "cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java", @@ -884,6 +885,8 @@ "cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerDelegate.java", "cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerUtils.java", "cocos/platform/android/javaactivity-android.cpp", + "cocos/platform/android/CCEnhanceAPI-android.cpp", + "cocos/platform/android/CCEnhanceAPI-android.h", "cocos/platform/android/jni/CocosPlayClient.cpp", "cocos/platform/android/jni/CocosPlayClient.h", "cocos/platform/android/jni/DPIJni.cpp",