Fixed storage path and other issues on Android

This commit is contained in:
Emil Romanus 2022-08-10 12:41:36 +02:00
commit 8cedd08518
11 changed files with 88 additions and 70 deletions

View file

@ -8,7 +8,7 @@ android {
defaultConfig {
applicationId "com.bithack.principia"
minSdk 15
minSdk 19
targetSdk 32
versionCode 36
versionName "1.6"

View file

@ -6,6 +6,7 @@ public class PrincipiaBackend
{
public static native int getLevelVersion();
public static native String getCookies();
public static native String getCommunityHost();
public static native void addAction(int id, String action_string);
public static native void addActionAsInt(int action_id, long action_data);

View file

@ -96,6 +96,10 @@ import android.media.*;
import android.hardware.*;
import android.widget.ArrayAdapter;
import androidx.core.view.WindowInsetsControllerCompat;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsCompat;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@ -186,11 +190,11 @@ public class SDLActivity extends Activity implements DialogInterface.OnDismissLi
// So we can call stuff from static callbacks
mSingleton = this;
// Keep track of the paused state
mSingleton.requestWindowFeature(Window.FEATURE_NO_TITLE);
mSingleton.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
enableImmersiveMode();
// Set up the surface
mSurface = new SDLSurface(getApplication());
setContentView(mSurface);
@ -207,6 +211,17 @@ public class SDLActivity extends Activity implements DialogInterface.OnDismissLi
QuickaddDialog.object_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line);
}
public void enableImmersiveMode()
{
WindowCompat.setDecorFitsSystemWindows(mSingleton.getWindow(), true);
WindowInsetsControllerCompat controller = new WindowInsetsControllerCompat(mSingleton.getWindow(), mSingleton.getWindow().getDecorView());
if (controller != null) {
controller.hide(WindowInsetsCompat.Type.statusBars() | WindowInsetsCompat.Type.navigationBars());
controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
}
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState)
{
@ -619,33 +634,18 @@ public class SDLActivity extends Activity implements DialogInterface.OnDismissLi
/* ----------------------------------------------------------------------------------------------------- TMS PRINCIPIA */
public static boolean has_external_storage()
{
String state = Environment.getExternalStorageState();
return Environment.MEDIA_MOUNTED.equals(state);
//String state = Environment.getExternalStorageState();
//return Environment.MEDIA_MOUNTED.equals(state);
return true;
}
public static String get_storage_path()
{
File file_path = Environment.getExternalStorageDirectory();
String path = file_path.getAbsolutePath() + "/Principia";
File file_path[] = SDLActivity.getContext().getExternalFilesDirs(null);
File f = new File(path);
if (!f.exists()) {
Log.v("Principia", "Creating storage directory: "+path);
if (!f.mkdir()) {
Log.e(TAG, "Unable to create storage directory: " + path);
String path = file_path[0].toString();
File data_f = SDLActivity.getContext().getFilesDir();
Log.e(TAG, "try this: " + data_f);
if (!data_f.exists()) {
Log.v(TAG, "Creating storage directory: "+ data_f);
if (!data_f.mkdir()) {
Log.e(TAG, "Unable to create data storage directory: " + data_f);
}
}
return data_f.getAbsolutePath();
}
}
Log.v("FilesDir", path);
return path;
}
@ -708,8 +708,9 @@ public class SDLActivity extends Activity implements DialogInterface.OnDismissLi
{
SDLActivity.mSingleton.runOnUiThread(new Runnable(){
public void run() {
String community_host = PrincipiaBackend.getCommunityHost();
if (SDLActivity.wv_cm != null) {
String cookie_data = SDLActivity.wv_cm.getCookie(".principiagame.com");
String cookie_data = SDLActivity.wv_cm.getCookie("."+community_host);
if (cookie_data != null) {
String[] prev_cookies = cookie_data.split("; ");
int uid = 1;
@ -735,9 +736,9 @@ public class SDLActivity extends Activity implements DialogInterface.OnDismissLi
if (u != 1 && u != 0 && k != null && sid != null) {
// we got relevant cookies from curl!
SDLActivity.wv_cm.setCookie(".principiagame.com", "phpbb_ziao2_u="+u);
SDLActivity.wv_cm.setCookie(".principiagame.com", "phpbb_ziao2_k="+k);
SDLActivity.wv_cm.setCookie(".principiagame.com", "phpbb_ziao2_sid="+sid);
SDLActivity.wv_cm.setCookie("."+community_host, "phpbb_ziao2_u="+u);
SDLActivity.wv_cm.setCookie("."+community_host, "phpbb_ziao2_k="+k);
SDLActivity.wv_cm.setCookie("."+community_host, "phpbb_ziao2_sid="+sid);
}
}
}
@ -786,7 +787,7 @@ public class SDLActivity extends Activity implements DialogInterface.OnDismissLi
Log.v("Principia", "set arg "+url);
PrincipiaBackend.setarg(url);
SDLActivity.wv_dialog.dismiss();
} else if (host.equals("test.sprfuppsala.se") || host.equals("principiagame.com") || host.equals("img.principiagame.com") || host.equals("www.principiagame.com") || host.equals("test.principiagame.com")) {
} else if (true) {
// FIXME: Also IF HOST CONTAINS QUERY ?printable=yes
Log.v("Principia", "Load url "+url);
view.stopLoading();
@ -1101,6 +1102,9 @@ public class SDLActivity extends Activity implements DialogInterface.OnDismissLi
{
SDLActivity.mSingleton.runOnUiThread(new Runnable(){
public void run() {
/* hack to prevent killing of immersive mode */
mSingleton.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
new AlertDialog.Builder(mSingleton.getContext())
.setMessage(text)
.setPositiveButton(mSingleton.getString(R.string.close), new DialogInterface.OnClickListener() {
@ -1110,6 +1114,9 @@ public class SDLActivity extends Activity implements DialogInterface.OnDismissLi
})
.setIcon(android.R.drawable.ic_dialog_info)
.show();
mSingleton.getWindow().getDecorView().setSystemUiVisibility(mSingleton.getWindow().getDecorView().getSystemUiVisibility());
mSingleton.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
}
});
}
@ -1202,9 +1209,9 @@ public class SDLActivity extends Activity implements DialogInterface.OnDismissLi
case 5: showDialog(DIALOG_PUBLISH); break;
case 6: showDialog(DIALOG_SETTINGS); break;
case 7: showDialog(DIALOG_LOGIN); break;
case 8: SDLActivity.open_url("http://principiagame.com/gettingstarted.php"); break;
case 9: SDLActivity.open_url("http://wiki.principiagame.com/wiki/Main_Page"); break;
case 10: SDLActivity.open_url("http://principiagame.com/"); break;
case 8: SDLActivity.open_url("https://principiagame.com/gettingstarted.php"); break;
case 9: SDLActivity.open_url("https://wiki.principiagame.com/wiki/Main_Page"); break;
case 10: SDLActivity.open_url("https://principiagame.com/"); break;
case 11: PrincipiaBackend.addActionAsInt(ACTION_GOTO_MAINMENU, 0); break;
case 12: SDLActivity.cleanQuit(); break;
}
@ -1532,6 +1539,8 @@ public class SDLActivity extends Activity implements DialogInterface.OnDismissLi
SDLActivity.num_dialogs = 0;
PrincipiaBackend.focusGL(true);
}
enableImmersiveMode();
}
public void onShow(DialogInterface dialog) {

View file

@ -8,4 +8,4 @@
# project structure.
# Project target.
target=android-17
target=android-19

View file

@ -312,7 +312,7 @@ FT_BEGIN_HEADER
FT_MulFix_arm( FT_Int32 a,
FT_Int32 b )
{
register FT_Int32 t, t2;
FT_Int32 t, t2;
__asm
@ -343,7 +343,7 @@ FT_BEGIN_HEADER
FT_MulFix_arm( FT_Int32 a,
FT_Int32 b )
{
register FT_Int32 t, t2;
FT_Int32 t, t2;
__asm__ __volatile__ (
@ -370,7 +370,7 @@ FT_BEGIN_HEADER
FT_MulFix_i386( FT_Int32 a,
FT_Int32 b )
{
register FT_Int32 result;
FT_Int32 result;
__asm__ __volatile__ (
@ -406,7 +406,7 @@ FT_BEGIN_HEADER
FT_MulFix_i386( FT_Int32 a,
FT_Int32 b )
{
register FT_Int32 result;
FT_Int32 result;
__asm
{

View file

@ -1444,7 +1444,7 @@ game::widget_clicked(principia_wdg *w, uint8_t button_id, int pid)
P.add_action(ACTION_AUTOSAVE, 0);
P.num_unread_messages = 0;
char tmp[256];
snprintf(tmp, 255, "http://%s/user/%s", P.community_host, P.username);
snprintf(tmp, 255, "https://%s/user/%s", P.community_host, P.username);
ui::open_url(tmp);
snprintf(tmp, 255, "%s", P.username);

View file

@ -1970,7 +1970,7 @@ _download_pkg(void *_p)
tms_debugf("save: %s", save_path);
char url[1024];
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/xxxx.php?i=%d",
snprintf(url, 1023, "https://%s/" COMMUNITY_SECRET "/xxxx.php?i=%d",
P.community_host,
_play_pkg_id);
//tms_infof("url: %s", url);
@ -2111,7 +2111,7 @@ _download_level(void *p)
char url[1024];
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/%s.php?i=%d&h=%u",
snprintf(url, 1023, "https://%s/" COMMUNITY_SECRET "/%s.php?i=%d&h=%u",
P.community_host,
_play_download_for_pkg ? "xxxxx" : (type == LEVEL_DB ? "x":(derive == true ? "xxx" : "xxxxxx")),
_play_id, r);
@ -2525,7 +2525,7 @@ _check_version_code(void *_unused)
init_curl_defaults(P.curl);
char url[1024];
snprintf(url, 1023, "http://%s/principia-version-code", P.community_host);
snprintf(url, 1023, "https://%s/principia-version-code", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);
curl_easy_setopt(P.curl, CURLOPT_WRITEFUNCTION, write_memory_cb);
@ -2629,9 +2629,9 @@ _get_featured_levels(void *_num)
char url[1024];
if (fl_fetch_time && file_exists(featured_data_path) && !ignore_fl_cache) {
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/get_feature.php?num=%" PRIu32 "&time=%d", P.community_host, num_featured_levels, fl_fetch_time);
snprintf(url, 1023, "https://%s/" COMMUNITY_SECRET "/get_feature.php?num=%" PRIu32 "&time=%d", P.community_host, num_featured_levels, fl_fetch_time);
} else {
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/get_feature.php?num=%" PRIu32, P.community_host, num_featured_levels);
snprintf(url, 1023, "https://%s/" COMMUNITY_SECRET "/get_feature.php?num=%" PRIu32, P.community_host, num_featured_levels);
}
curl_easy_setopt(P.curl, CURLOPT_URL, url);
@ -2973,7 +2973,7 @@ _publish_pkg(void *_unused)
init_curl_defaults(P.curl);
char url[1024];
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/upload_package.php", P.community_host);
snprintf(url, 1023, "https://%s/" COMMUNITY_SECRET "/upload_package.php", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);
curl_easy_setopt(P.curl, CURLOPT_HTTPPOST, formpost);
@ -3117,7 +3117,7 @@ _publish_level(void *p)
init_curl_defaults(P.curl);
char url[1024];
snprintf(url, 1023, "http://%s/upload.php", P.community_host);
snprintf(url, 1023, "https://%s/upload.php", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);
curl_easy_setopt(P.curl, CURLOPT_HTTPPOST, formpost);
@ -3309,7 +3309,7 @@ _submit_score(void *p)
init_curl_defaults(P.curl);
char url[1024];
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/submit_score.php", P.community_host);
snprintf(url, 1023, "https://%s/" COMMUNITY_SECRET "/submit_score.php", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);
curl_easy_setopt(P.curl, CURLOPT_WRITEHEADER, &hd);
@ -3394,7 +3394,7 @@ _ping(void *p)
init_curl_defaults(P.curl);
char url[1024];
snprintf(url, 1023, "http://%s/ping.php", P.community_host);
snprintf(url, 1023, "https://%s/ping.php", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);
curl_easy_setopt(P.curl, CURLOPT_WRITEFUNCTION, write_memory_cb);
@ -3470,7 +3470,7 @@ _login(void *p)
init_curl_defaults(P.curl);
char url[1024];
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/xx.php", P.community_host);
snprintf(url, 1023, "https://%s/" COMMUNITY_SECRET "/xx.php", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);
curl_easy_setopt(P.curl, CURLOPT_HTTPPOST, formpost);
@ -3588,7 +3588,7 @@ _register(void *p)
if (P.curl) {
init_curl_defaults(P.curl);
char url[1024];
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/" REGISTER_ANDROID_FILE ".php", P.community_host);
snprintf(url, 1023, "https://%s/" COMMUNITY_SECRET "/" REGISTER_ANDROID_FILE ".php", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);
curl_easy_setopt(P.curl, CURLOPT_HTTPPOST, formpost);
@ -3727,7 +3727,7 @@ _link_account(void *p)
init_curl_defaults(P.curl);
char url[1024];
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/" LINK_ACCOUNT_FILE ".php", P.community_host);
snprintf(url, 1023, "https://%s/" COMMUNITY_SECRET "/" LINK_ACCOUNT_FILE ".php", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);
curl_easy_setopt(P.curl, CURLOPT_HTTPPOST, formpost);
@ -4400,7 +4400,7 @@ P_get_cookie_data(char **u, char **k, char **sid, char **l)
init_curl_defaults(P.curl);
char url[1024];
snprintf(url, 1023, "http://%s/" COMMUNITY_SECRET "/xx.php", P.community_host);
snprintf(url, 1023, "https://%s/" COMMUNITY_SECRET "/xx.php", P.community_host);
curl_easy_setopt(P.curl, CURLOPT_URL, url);
struct curl_slist *cookies;

View file

@ -25,7 +25,7 @@ class pkginfo;
#define STR1(x) #x
#define STR(x) STR1(x)
#define UPDATE_URL "http://www.principiagame.com/download"
#define UPDATE_URL "https://www.principiagame.com/"
#if defined(TMS_BACKEND_WINDOWS)
#define OS_STRING "Windows"

View file

@ -33,7 +33,7 @@ menu_base::widget_clicked(principia_wdg *w, uint8_t button_id, int pid)
P.add_action(ACTION_REFRESH_WIDGETS, 0);
char tmp[1024];
snprintf(tmp, 1023, "http://%s/user/%s", P.community_host, P.username);
snprintf(tmp, 1023, "https://%s/user/%s", P.community_host, P.username);
ui::open_url(tmp);
} else {
ui::open_dialog(DIALOG_LOGIN);
@ -44,13 +44,13 @@ menu_base::widget_clicked(principia_wdg *w, uint8_t button_id, int pid)
case BTN_MESSAGE:
{
char url[1024];
snprintf(url, 1023, "http://%s/version-redir.php", P.community_host);
snprintf(url, 1023, "https://%s/version-redir.php", P.community_host);
ui::open_url(url);
}
break;
case BTN_BITHACK:
ui::open_url("http://bithack.com/");
ui::open_url("https://www.bithack.com/");
break;
case BTN_SETTINGS:
@ -61,7 +61,7 @@ menu_base::widget_clicked(principia_wdg *w, uint8_t button_id, int pid)
{
uint32_t id = VOID_TO_UINT32(w->data3);
char tmp[1024];
snprintf(tmp, 1023, "http://%s/level/%" PRIu32, P.community_host, id);
snprintf(tmp, 1023, "https://%s/level/%" PRIu32, P.community_host, id);
ui::open_url(tmp);
}
break;
@ -70,7 +70,7 @@ menu_base::widget_clicked(principia_wdg *w, uint8_t button_id, int pid)
{
uint32_t id = VOID_TO_UINT32(w->data3);
char tmp[1024];
snprintf(tmp, 1023, "http://%s/contest/%" PRIu32, P.community_host, id);
snprintf(tmp, 1023, "https://%s/contest/%" PRIu32, P.community_host, id);
ui::open_url(tmp);
}
break;
@ -117,7 +117,7 @@ menu_base::menu_base(bool _include_logo)
this->wdg_bithack = this->wm->create_widget(
this->get_surface(), TMS_WDG_BUTTON,
BTN_BITHACK, AREA_NOMARGIN_BOTTOM_LEFT,
gui_spritesheet::get_sprite(S_BITHACK));
gui_spritesheet::get_sprite(S_BITHACK), 0, 0.5f);
this->wdg_bithack->add();
this->wdg_settings = this->wm->create_widget(

File diff suppressed because one or more lines are too long

View file

@ -231,7 +231,7 @@ T_intercept_input(SDL_Event ev)
return T_OK;
}
static const char storage_path[1024];
static char storage_path[1024];
static const char*
_JNI_get_storage_path()
{
@ -244,6 +244,8 @@ _JNI_get_storage_path()
const char *tmp = (*mEnv)->GetStringUTFChars(mEnv, s, 0);
tms_infof("Storage path: %s", tmp ? tmp : "<NULL>");
strcpy(storage_path, tmp);
(*mEnv)->ReleaseStringUTFChars(mEnv, s, tmp);
@ -261,7 +263,7 @@ const char *tbackend_get_storage_path(void)
return _JNI_get_storage_path();
}
static const char device_info[1024];
static char device_info[1024];
static const char*
_JNI_get_device_info()
{