Gracefully handle missing directories.

Bug: 10295932
Change-Id: I9d18682d0ba57bf7f77d043ee8dab286ee80ba2a
This commit is contained in:
Jeff Sharkey
2013-08-15 11:50:02 -07:00
parent 2241d45c68
commit e0475c8287
2 changed files with 18 additions and 10 deletions

View File

@@ -175,16 +175,20 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback2,
? savedInstanceState.getByteArray(KEY_NATIVE_SAVED_STATE) : null;
mNativeHandle = loadNativeCode(path, funcname, Looper.myQueue(),
getFilesDir().getAbsolutePath(), getObbDir().getAbsolutePath(),
getExternalFilesDir(null).getAbsolutePath(),
Build.VERSION.SDK_INT, getAssets(), nativeSavedState);
getAbsolutePath(getFilesDir()), getAbsolutePath(getObbDir()),
getAbsolutePath(getExternalFilesDir(null)),
Build.VERSION.SDK_INT, getAssets(), nativeSavedState);
if (mNativeHandle == 0) {
throw new IllegalArgumentException("Unable to load native library: " + path);
}
super.onCreate(savedInstanceState);
}
private static String getAbsolutePath(File file) {
return (file != null) ? file.getAbsolutePath() : null;
}
@Override
protected void onDestroy() {
mDestroyed = true;

View File

@@ -306,19 +306,23 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
code->internalDataPath = code->internalDataPathObj.string();
env->ReleaseStringUTFChars(internalDataDir, dirStr);
dirStr = env->GetStringUTFChars(externalDataDir, NULL);
code->externalDataPathObj = dirStr;
if (externalDataDir != NULL) {
dirStr = env->GetStringUTFChars(externalDataDir, NULL);
code->externalDataPathObj = dirStr;
env->ReleaseStringUTFChars(externalDataDir, dirStr);
}
code->externalDataPath = code->externalDataPathObj.string();
env->ReleaseStringUTFChars(externalDataDir, dirStr);
code->sdkVersion = sdkVersion;
code->assetManager = assetManagerForJavaObject(env, jAssetMgr);
dirStr = env->GetStringUTFChars(obbDir, NULL);
code->obbPathObj = dirStr;
if (obbDir != NULL) {
dirStr = env->GetStringUTFChars(obbDir, NULL);
code->obbPathObj = dirStr;
env->ReleaseStringUTFChars(obbDir, dirStr);
}
code->obbPath = code->obbPathObj.string();
env->ReleaseStringUTFChars(obbDir, dirStr);
jbyte* rawSavedState = NULL;
jsize rawSavedSize = 0;