mirror of https://github.com/axmolengine/axmol.git
84 lines
3.3 KiB
C++
84 lines
3.3 KiB
C++
/****************************************************************************
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
THE SOFTWARE.
|
|
****************************************************************************/
|
|
#include "ccdandroidUtils.h"
|
|
#include "cocos2d.h"
|
|
|
|
#include <jni.h>
|
|
#include <android/log.h>
|
|
#include "jni/JniHelper.h"
|
|
|
|
USING_NS_CC;
|
|
|
|
namespace CocosDenshion {
|
|
namespace android {
|
|
|
|
#define I9100_MODEL "GT-I9100"
|
|
#define LOG_TAG "Device Model"
|
|
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
|
#define CLASS_NAME "org/cocos2dx/lib/Cocos2dxHelper"
|
|
#define METHOD_NAME "getDeviceModel"
|
|
|
|
bool is_buggy_device(void) {
|
|
JniMethodInfo methodInfo;
|
|
jstring jstr;
|
|
if (JniHelper::getStaticMethodInfo(methodInfo,
|
|
CLASS_NAME,
|
|
METHOD_NAME,
|
|
"()Ljava/lang/String;")) {
|
|
jstr = (jstring)methodInfo.env->CallStaticObjectMethod(methodInfo.classID,
|
|
methodInfo.methodID);
|
|
}
|
|
|
|
const char* deviceModel = methodInfo.env->GetStringUTFChars(jstr, NULL);
|
|
if (NULL == deviceModel) {
|
|
return false;
|
|
}
|
|
|
|
LOGD("deviceModel = %s", deviceModel);
|
|
methodInfo.env->ReleaseStringUTFChars(jstr, deviceModel);
|
|
methodInfo.env->DeleteLocalRef(jstr);
|
|
|
|
if (strcmp(I9100_MODEL, deviceModel) == 0) {
|
|
LOGD("i9100 model\nSwitch to OpenSLES");
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
std::string getFullPathWithoutAssetsPrefix(const char* pszFilename) {
|
|
// Changing file path to full path
|
|
std::string fullPath = cocos2d::FileUtils::getInstance()->fullPathForFilename(pszFilename);
|
|
// Removing `assets` since it isn't needed for the API of playing sound.
|
|
size_t pos = fullPath.find("assets/");
|
|
if (pos == 0)
|
|
{
|
|
fullPath = fullPath.substr(strlen("assets/"));
|
|
}
|
|
return fullPath;
|
|
}
|
|
}
|
|
}
|