Warn users of Telechips devices that app will crash with their broken libc

This commit is contained in:
pelya
2011-06-22 16:43:22 +03:00
parent 4e214b0ffd
commit 819febb3af
10 changed files with 107 additions and 11 deletions

View File

@@ -661,7 +661,7 @@ mv -f project/src/Globals.java.1 project/src/Globals.java
echo Patching project/jni/Settings.mk
echo '# DO NOT EDIT THIS FILE - it is automatically generated, edit file SettingsTemplate.mk' > project/jni/Settings.mk
cat project/jni/SettingsTemplate.mk | \
sed "s/APP_MODULES := .*/APP_MODULES := application sdl-$LibSdlVersion sdl_main stlport jpeg png ogg flac vorbis freetype $CompiledLibraries/" | \
sed "s/APP_MODULES := .*/APP_MODULES := application sdl-$LibSdlVersion sdl_main stlport jpeg png ogg flac vorbis freetype stdout-test $CompiledLibraries/" | \
sed "s/APP_ABI := .*/APP_ABI := $MultiABI/" | \
sed "s/SDL_JAVA_PACKAGE_PATH := .*/SDL_JAVA_PACKAGE_PATH := $AppFullNameUnderscored/" | \
sed "s^SDL_CURDIR_PATH := .*^SDL_CURDIR_PATH := $DataPath^" | \
@@ -718,6 +718,7 @@ if [ -d "project/jni/application/src/AndroidData" ] ; then
fi
done
cp project/jni/application/src/AndroidData/* project/assets/
ln -s ../libs/armeabi/stdout-test project/assets/
fi
echo Done

View File

@@ -85,4 +85,5 @@ class Globals {
public static String DataDir = new String("");
public static boolean SmoothVideo = false;
public static boolean MultiThreadedVideo = false;
public static boolean BrokenLibCMessageShown = false;
}

View File

@@ -613,12 +613,7 @@ public class MainActivity extends Activity {
out.flush();
out.close();
try {
(new ProcessBuilder().command("/system/bin/chmod", "0755", path).start()).waitFor();
} catch ( Exception eeee ) {}
try {
(new ProcessBuilder().command("/system/xbin/chmod", "0755", path).start()).waitFor();
} catch ( Exception eeeee ) {}
Settings.nativeChmod(path, 0755);
}
}
catch ( Exception eee )

View File

@@ -149,6 +149,7 @@ class Settings
out.writeInt(Globals.OptionalDataDownload.length);
for(int i = 0; i < Globals.OptionalDataDownload.length; i++)
out.writeBoolean(Globals.OptionalDataDownload[i]);
out.writeBoolean(Globals.BrokenLibCMessageShown);
out.close();
settingsLoaded = true;
@@ -283,6 +284,7 @@ class Settings
Globals.OptionalDataDownload = new boolean[settingsFile.readInt()];
for(int i = 0; i < Globals.OptionalDataDownload.length; i++)
Globals.OptionalDataDownload[i] = settingsFile.readBoolean();
Globals.BrokenLibCMessageShown = settingsFile.readBoolean();
settingsLoaded = true;
@@ -394,9 +396,67 @@ class Settings
static ArrayList<Menu> menuStack = new ArrayList<Menu> ();
public static void showConfig(final MainActivity p, boolean firstStart)
public static void showConfig(final MainActivity p, final boolean firstStart)
{
settingsChanged = true;
if( !Globals.BrokenLibCMessageShown )
{
Globals.BrokenLibCMessageShown = true;
try {
InputStream in = p.getAssets().open("stdout-test");
File outDir = p.getFilesDir();
try {
outDir.mkdirs();
} catch( SecurityException ee ) { };
byte[] buf = new byte[16384];
OutputStream out = null;
String path = outDir.getAbsolutePath() + "/" + "stdout-test";
out = new FileOutputStream( path );
int len = in.read(buf);
while (len >= 0)
{
if(len > 0)
out.write(buf, 0, len);
len = in.read(buf);
}
out.flush();
out.close();
Settings.nativeChmod(path, 0755);
if( (new ProcessBuilder().command(path).start()).waitFor() != 42 )
{
System.out.println("libSDL: stdout-test FAILED, your libc is broken");
AlertDialog.Builder builder = new AlertDialog.Builder(p);
builder.setTitle(p.getResources().getString(R.string.broken_libc_title));
builder.setMessage(p.getResources().getString(R.string.broken_libc_text));
builder.setPositiveButton(p.getResources().getString(R.string.ok), new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int item)
{
dialog.dismiss();
showConfig(p, firstStart);
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener()
{
public void onCancel(DialogInterface dialog)
{
dialog.dismiss();
showConfig(p, firstStart);
}
});
AlertDialog alert = builder.create();
alert.setOwnerActivity(p);
alert.show();
return;
}
System.out.println("libSDL: stdout-test passed, your libc seems to be good");
} catch ( Exception eeee ) {
System.out.println("libSDL: Cannot run stdout-test: " + eeee.toString());
}
}
if( Globals.OptionalDataDownload == null )
{
@@ -2401,5 +2461,6 @@ class Settings
private static native void nativeSetMultitouchGestureSensitivity(int sensitivity);
private static native void nativeSetTouchscreenCalibration(int x1, int y1, int x2, int y2);
public static native void nativeSetEnv(final String name, final String value);
public static native int nativeChmod(final String name, int mode);
}

View File

@@ -151,5 +151,7 @@
<string name="display_size_small">Small (phone)</string>
<string name="display_size_tiny">Tiny (Xperia Mini)</string>
<string name="show_more_options">Show more options</string>
<string name="broken_libc_title">Broken OS detected</string>
<string name="broken_libc_text">Your device has broken system libraries, this application will most probably crash. Please install a system update, or flash a custom ROM, or copy file /system/lib/libc.so from another device (experts only!)</string>
</resources>

View File

@@ -25,8 +25,8 @@ RedefinedKeysScreenKb="LCTRL M T H E C SPACE C S L"
StartupMenuButtonTimeout=3000
HiddenMenuOptions='KeyboardConfigMainMenu ScreenKeyboardThemeConfig ScreenKeyboardTransparencyConfig'
MultiABI=n
AppVersionCode=238815
AppVersionName="2388.15"
AppVersionCode=239115
AppVersionName="2391.15"
CompiledLibraries="sdl_net sdl_mixer sdl_image sdl_ttf png intl"
CustomBuildScript=n
AppCflags='-finline-functions -O2 -DWITH_ZLIB -DWITH_MIXER -DWITH_XML -DWITH_IMAGE -DWITH_TTF -DWITH_AI=simple -DWITH_NET'

View File

@@ -1 +1 @@
vcmi
fheroes2

View File

@@ -803,3 +803,13 @@ int SDLCALL SDL_ANDROID_GetScreenKeyboardTextInput(char * textBuf, int textBufSi
return 1;
};
// That's probably not the right file to put this func
JNIEXPORT jint JNICALL
JAVA_EXPORT_NAME(Settings_nativeChmod) ( JNIEnv* env, jobject thiz, jstring j_name, jint mode )
{
jboolean iscopy;
const char *name = (*env)->GetStringUTFChars(env, j_name, &iscopy);
int ret = chmod(name, mode);
(*env)->ReleaseStringUTFChars(env, j_name, name);
return (ret == 0);
};

View File

@@ -0,0 +1,8 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := stdout-test
LOCAL_SRC_FILES = stdout-test.c
include $(BUILD_EXECUTABLE)

View File

@@ -0,0 +1,18 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
extern int main(int argc, char *argv[]);
int main(int argc, char *argv[])
{
// Numerous Telechips devices will crash this simple Posix-compatibility test
printf("printf()\n");
fprintf(stdout, "fprintf(stdout)\n");
fflush(stdout);
fprintf(stderr, "fprintf(stderr)\n");
fflush(stderr);
write(STDOUT_FILENO, "write(1)\n", strlen("write(1)\n"));
write(STDERR_FILENO, "write(2)\n", strlen("write(2)\n"));
return 42;
}