aboutsummaryrefslogtreecommitdiff
path: root/android/app/src/main/java/net
diff options
context:
space:
mode:
Diffstat (limited to 'android/app/src/main/java/net')
-rw-r--r--android/app/src/main/java/net/minetest/minetest/CustomEditText.java45
-rw-r--r--android/app/src/main/java/net/minetest/minetest/GameActivity.java207
-rw-r--r--android/app/src/main/java/net/minetest/minetest/MainActivity.java185
-rw-r--r--android/app/src/main/java/net/minetest/minetest/UnzipService.java259
-rw-r--r--android/app/src/main/java/net/minetest/minetest/Utils.java39
5 files changed, 0 insertions, 735 deletions
diff --git a/android/app/src/main/java/net/minetest/minetest/CustomEditText.java b/android/app/src/main/java/net/minetest/minetest/CustomEditText.java
deleted file mode 100644
index 8d0a503d0..000000000
--- a/android/app/src/main/java/net/minetest/minetest/CustomEditText.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-Minetest
-Copyright (C) 2014-2020 MoNTE48, Maksim Gamarnik <MoNTE48@mail.ua>
-Copyright (C) 2014-2020 ubulem, Bektur Mambetov <berkut87@gmail.com>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation; either version 2.1 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-package net.minetest.minetest;
-
-import android.content.Context;
-import android.view.KeyEvent;
-import android.view.inputmethod.InputMethodManager;
-
-import androidx.appcompat.widget.AppCompatEditText;
-
-import java.util.Objects;
-
-public class CustomEditText extends AppCompatEditText {
- public CustomEditText(Context context) {
- super(context);
- }
-
- @Override
- public boolean onKeyPreIme(int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_BACK) {
- InputMethodManager mgr = (InputMethodManager)
- getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- Objects.requireNonNull(mgr).hideSoftInputFromWindow(this.getWindowToken(), 0);
- }
- return false;
- }
-}
diff --git a/android/app/src/main/java/net/minetest/minetest/GameActivity.java b/android/app/src/main/java/net/minetest/minetest/GameActivity.java
deleted file mode 100644
index f5e9fd6d0..000000000
--- a/android/app/src/main/java/net/minetest/minetest/GameActivity.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
-Minetest
-Copyright (C) 2014-2020 MoNTE48, Maksim Gamarnik <MoNTE48@mail.ua>
-Copyright (C) 2014-2020 ubulem, Bektur Mambetov <berkut87@gmail.com>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation; either version 2.1 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-package net.minetest.minetest;
-
-import android.app.NativeActivity;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Build;
-import android.os.Bundle;
-import android.text.InputType;
-import android.util.Log;
-import android.view.KeyEvent;
-import android.view.View;
-import android.view.WindowManager;
-import android.view.inputmethod.InputMethodManager;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.LinearLayout;
-
-import androidx.annotation.Keep;
-import androidx.appcompat.app.AlertDialog;
-import androidx.core.content.FileProvider;
-
-import java.io.File;
-import java.util.Objects;
-
-// Native code finds these methods by name (see porting_android.cpp).
-// This annotation prevents the minifier/Proguard from mangling them.
-@Keep
-public class GameActivity extends NativeActivity {
- static {
- System.loadLibrary("c++_shared");
- System.loadLibrary("Minetest");
- }
-
- private int messageReturnCode = -1;
- private String messageReturnValue = "";
-
- public static native void putMessageBoxResult(String text);
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
- }
-
- private void makeFullScreen() {
- if (Build.VERSION.SDK_INT >= 19)
- this.getWindow().getDecorView().setSystemUiVisibility(
- View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
- View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
- View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
- }
-
- @Override
- public void onWindowFocusChanged(boolean hasFocus) {
- super.onWindowFocusChanged(hasFocus);
- if (hasFocus)
- makeFullScreen();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- makeFullScreen();
- }
-
- @Override
- public void onBackPressed() {
- // Ignore the back press so Minetest can handle it
- }
-
- public void showDialog(String acceptButton, String hint, String current, int editType) {
- runOnUiThread(() -> showDialogUI(hint, current, editType));
- }
-
- private void showDialogUI(String hint, String current, int editType) {
- final AlertDialog.Builder builder = new AlertDialog.Builder(this);
- LinearLayout container = new LinearLayout(this);
- container.setOrientation(LinearLayout.VERTICAL);
- builder.setView(container);
- AlertDialog alertDialog = builder.create();
- EditText editText;
- // For multi-line, do not close the dialog after pressing back button
- if (editType == 1) {
- editText = new EditText(this);
- } else {
- editText = new CustomEditText(this);
- }
- container.addView(editText);
- editText.setMaxLines(8);
- editText.requestFocus();
- editText.setHint(hint);
- editText.setText(current);
- final InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
- Objects.requireNonNull(imm).toggleSoftInput(InputMethodManager.SHOW_FORCED,
- InputMethodManager.HIDE_IMPLICIT_ONLY);
- if (editType == 1)
- editText.setInputType(InputType.TYPE_CLASS_TEXT |
- InputType.TYPE_TEXT_FLAG_MULTI_LINE);
- else if (editType == 3)
- editText.setInputType(InputType.TYPE_CLASS_TEXT |
- InputType.TYPE_TEXT_VARIATION_PASSWORD);
- else
- editText.setInputType(InputType.TYPE_CLASS_TEXT);
- editText.setSelection(editText.getText().length());
- editText.setOnKeyListener((view, keyCode, event) -> {
- // For multi-line, do not submit the text after pressing Enter key
- if (keyCode == KeyEvent.KEYCODE_ENTER && editType != 1) {
- imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
- messageReturnCode = 0;
- messageReturnValue = editText.getText().toString();
- alertDialog.dismiss();
- return true;
- }
- return false;
- });
- // For multi-line, add Done button since Enter key does not submit text
- if (editType == 1) {
- Button doneButton = new Button(this);
- container.addView(doneButton);
- doneButton.setText(R.string.ime_dialog_done);
- doneButton.setOnClickListener((view -> {
- imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
- messageReturnCode = 0;
- messageReturnValue = editText.getText().toString();
- alertDialog.dismiss();
- }));
- }
- alertDialog.show();
- alertDialog.setOnCancelListener(dialog -> {
- getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
- messageReturnValue = current;
- messageReturnCode = -1;
- });
- }
-
- public int getDialogState() {
- return messageReturnCode;
- }
-
- public String getDialogValue() {
- messageReturnCode = -1;
- return messageReturnValue;
- }
-
- public float getDensity() {
- return getResources().getDisplayMetrics().density;
- }
-
- public int getDisplayHeight() {
- return getResources().getDisplayMetrics().heightPixels;
- }
-
- public int getDisplayWidth() {
- return getResources().getDisplayMetrics().widthPixels;
- }
-
- public void openURI(String uri) {
- Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
- startActivity(browserIntent);
- }
-
- public String getUserDataPath() {
- return Utils.getUserDataDirectory(this).getAbsolutePath();
- }
-
- public String getCachePath() {
- return Utils.getCacheDirectory(this).getAbsolutePath();
- }
-
- public void shareFile(String path) {
- File file = new File(path);
- if (!file.exists()) {
- Log.e("GameActivity", "File " + file.getAbsolutePath() + " doesn't exist");
- return;
- }
-
- Uri fileUri = FileProvider.getUriForFile(this, "net.minetest.minetest.fileprovider", file);
-
- Intent intent = new Intent(Intent.ACTION_SEND, fileUri);
- intent.setDataAndType(fileUri, getContentResolver().getType(fileUri));
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- intent.putExtra(Intent.EXTRA_STREAM, fileUri);
-
- Intent shareIntent = Intent.createChooser(intent, null);
- startActivity(shareIntent);
- }
-}
diff --git a/android/app/src/main/java/net/minetest/minetest/MainActivity.java b/android/app/src/main/java/net/minetest/minetest/MainActivity.java
deleted file mode 100644
index b6567b4b7..000000000
--- a/android/app/src/main/java/net/minetest/minetest/MainActivity.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
-Minetest
-Copyright (C) 2014-2020 MoNTE48, Maksim Gamarnik <MoNTE48@mail.ua>
-Copyright (C) 2014-2020 ubulem, Bektur Mambetov <berkut87@gmail.com>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation; either version 2.1 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-package net.minetest.minetest;
-
-import android.Manifest;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.SharedPreferences;
-import android.content.pm.PackageManager;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.Environment;
-import android.view.View;
-import android.widget.ProgressBar;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.StringRes;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.core.app.ActivityCompat;
-import androidx.core.content.ContextCompat;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import static net.minetest.minetest.UnzipService.*;
-
-public class MainActivity extends AppCompatActivity {
- private final static int versionCode = BuildConfig.VERSION_CODE;
- private final static int PERMISSIONS = 1;
- private static final String[] REQUIRED_SDK_PERMISSIONS =
- new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};
- private static final String SETTINGS = "MinetestSettings";
- private static final String TAG_VERSION_CODE = "versionCode";
-
- private ProgressBar mProgressBar;
- private TextView mTextView;
- private SharedPreferences sharedPreferences;
-
- private final BroadcastReceiver myReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- int progress = 0;
- @StringRes int message = 0;
- if (intent != null) {
- progress = intent.getIntExtra(ACTION_PROGRESS, 0);
- message = intent.getIntExtra(ACTION_PROGRESS_MESSAGE, 0);
- }
-
- if (progress == FAILURE) {
- Toast.makeText(MainActivity.this, intent.getStringExtra(ACTION_FAILURE), Toast.LENGTH_LONG).show();
- finish();
- } else if (progress == SUCCESS) {
- startNative();
- } else {
- if (mProgressBar != null) {
- mProgressBar.setVisibility(View.VISIBLE);
- if (progress == INDETERMINATE) {
- mProgressBar.setIndeterminate(true);
- } else {
- mProgressBar.setIndeterminate(false);
- mProgressBar.setProgress(progress);
- }
- }
- mTextView.setVisibility(View.VISIBLE);
- if (message != 0)
- mTextView.setText(message);
- }
- }
- };
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- IntentFilter filter = new IntentFilter(ACTION_UPDATE);
- registerReceiver(myReceiver, filter);
- mProgressBar = findViewById(R.id.progressBar);
- mTextView = findViewById(R.id.textView);
- sharedPreferences = getSharedPreferences(SETTINGS, Context.MODE_PRIVATE);
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
- Build.VERSION.SDK_INT < Build.VERSION_CODES.R)
- checkPermission();
- else
- checkAppVersion();
- }
-
- private void checkPermission() {
- final List<String> missingPermissions = new ArrayList<>();
- for (final String permission : REQUIRED_SDK_PERMISSIONS) {
- final int result = ContextCompat.checkSelfPermission(this, permission);
- if (result != PackageManager.PERMISSION_GRANTED)
- missingPermissions.add(permission);
- }
- if (!missingPermissions.isEmpty()) {
- final String[] permissions = missingPermissions
- .toArray(new String[0]);
- ActivityCompat.requestPermissions(this, permissions, PERMISSIONS);
- } else {
- final int[] grantResults = new int[REQUIRED_SDK_PERMISSIONS.length];
- Arrays.fill(grantResults, PackageManager.PERMISSION_GRANTED);
- onRequestPermissionsResult(PERMISSIONS, REQUIRED_SDK_PERMISSIONS, grantResults);
- }
- }
-
- @Override
- public void onRequestPermissionsResult(int requestCode,
- @NonNull String[] permissions, @NonNull int[] grantResults) {
- if (requestCode == PERMISSIONS) {
- for (int grantResult : grantResults) {
- if (grantResult != PackageManager.PERMISSION_GRANTED) {
- Toast.makeText(this, R.string.not_granted, Toast.LENGTH_LONG).show();
- finish();
- return;
- }
- }
- checkAppVersion();
- }
- }
-
- private void checkAppVersion() {
- if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
- Toast.makeText(this, R.string.no_external_storage, Toast.LENGTH_LONG).show();
- finish();
- return;
- }
-
- if (UnzipService.getIsRunning()) {
- mProgressBar.setVisibility(View.VISIBLE);
- mProgressBar.setIndeterminate(true);
- mTextView.setVisibility(View.VISIBLE);
- } else if (sharedPreferences.getInt(TAG_VERSION_CODE, 0) == versionCode &&
- Utils.isInstallValid(this)) {
- startNative();
- } else {
- mProgressBar.setVisibility(View.VISIBLE);
- mProgressBar.setIndeterminate(true);
- mTextView.setVisibility(View.VISIBLE);
-
- Intent intent = new Intent(this, UnzipService.class);
- startService(intent);
- }
- }
-
- private void startNative() {
- sharedPreferences.edit().putInt(TAG_VERSION_CODE, versionCode).apply();
- Intent intent = new Intent(this, GameActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
- startActivity(intent);
- }
-
- @Override
- public void onBackPressed() {
- // Prevent abrupt interruption when copy game files from assets
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- unregisterReceiver(myReceiver);
- }
-}
diff --git a/android/app/src/main/java/net/minetest/minetest/UnzipService.java b/android/app/src/main/java/net/minetest/minetest/UnzipService.java
deleted file mode 100644
index a61a49139..000000000
--- a/android/app/src/main/java/net/minetest/minetest/UnzipService.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
-Minetest
-Copyright (C) 2014-2020 MoNTE48, Maksim Gamarnik <MoNTE48@mail.ua>
-Copyright (C) 2014-2020 ubulem, Bektur Mambetov <berkut87@gmail.com>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation; either version 2.1 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-package net.minetest.minetest;
-
-import android.app.IntentService;
-import android.app.Notification;
-import android.app.NotificationChannel;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Build;
-import android.os.Environment;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.annotation.RequiresApi;
-import androidx.annotation.StringRes;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-import java.util.zip.ZipInputStream;
-
-public class UnzipService extends IntentService {
- public static final String ACTION_UPDATE = "net.minetest.minetest.UPDATE";
- public static final String ACTION_PROGRESS = "net.minetest.minetest.PROGRESS";
- public static final String ACTION_PROGRESS_MESSAGE = "net.minetest.minetest.PROGRESS_MESSAGE";
- public static final String ACTION_FAILURE = "net.minetest.minetest.FAILURE";
- public static final int SUCCESS = -1;
- public static final int FAILURE = -2;
- public static final int INDETERMINATE = -3;
- private final int id = 1;
- private NotificationManager mNotifyManager;
- private boolean isSuccess = true;
- private String failureMessage;
-
- private static boolean isRunning = false;
- public static synchronized boolean getIsRunning() {
- return isRunning;
- }
- private static synchronized void setIsRunning(boolean v) {
- isRunning = v;
- }
-
- public UnzipService() {
- super("net.minetest.minetest.UnzipService");
- }
-
- @Override
- protected void onHandleIntent(Intent intent) {
- Notification.Builder notificationBuilder = createNotification();
- final File zipFile = new File(getCacheDir(), "Minetest.zip");
- try {
- setIsRunning(true);
- File userDataDirectory = Utils.getUserDataDirectory(this);
- if (userDataDirectory == null) {
- throw new IOException("Unable to find user data directory");
- }
-
- try (InputStream in = this.getAssets().open(zipFile.getName())) {
- try (OutputStream out = new FileOutputStream(zipFile)) {
- int readLen;
- byte[] readBuffer = new byte[16384];
- while ((readLen = in.read(readBuffer)) != -1) {
- out.write(readBuffer, 0, readLen);
- }
- }
- }
-
- migrate(notificationBuilder, userDataDirectory);
- unzip(notificationBuilder, zipFile, userDataDirectory);
- } catch (IOException e) {
- isSuccess = false;
- failureMessage = e.getLocalizedMessage();
- } finally {
- setIsRunning(false);
- zipFile.delete();
- }
- }
-
- private Notification.Builder createNotification() {
- String name = "net.minetest.minetest";
- String channelId = "Minetest channel";
- String description = "notifications from Minetest";
- Notification.Builder builder;
- if (mNotifyManager == null)
- mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- int importance = NotificationManager.IMPORTANCE_LOW;
- NotificationChannel mChannel = null;
- if (mNotifyManager != null)
- mChannel = mNotifyManager.getNotificationChannel(channelId);
- if (mChannel == null) {
- mChannel = new NotificationChannel(channelId, name, importance);
- mChannel.setDescription(description);
- // Configure the notification channel, NO SOUND
- mChannel.setSound(null, null);
- mChannel.enableLights(false);
- mChannel.enableVibration(false);
- mNotifyManager.createNotificationChannel(mChannel);
- }
- builder = new Notification.Builder(this, channelId);
- } else {
- builder = new Notification.Builder(this);
- }
-
- Intent notificationIntent = new Intent(this, MainActivity.class);
- notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
- | Intent.FLAG_ACTIVITY_SINGLE_TOP);
- PendingIntent intent = PendingIntent.getActivity(this, 0,
- notificationIntent, 0);
-
- builder.setContentTitle(getString(R.string.notification_title))
- .setSmallIcon(R.mipmap.ic_launcher)
- .setContentText(getString(R.string.notification_description))
- .setContentIntent(intent)
- .setOngoing(true)
- .setProgress(0, 0, true);
-
- mNotifyManager.notify(id, builder.build());
- return builder;
- }
-
- private void unzip(Notification.Builder notificationBuilder, File zipFile, File userDataDirectory) throws IOException {
- int per = 0;
-
- int size;
- try (ZipFile zipSize = new ZipFile(zipFile)) {
- size = zipSize.size();
- }
-
- int readLen;
- byte[] readBuffer = new byte[16384];
- try (FileInputStream fileInputStream = new FileInputStream(zipFile);
- ZipInputStream zipInputStream = new ZipInputStream(fileInputStream)) {
- ZipEntry ze;
- while ((ze = zipInputStream.getNextEntry()) != null) {
- if (ze.isDirectory()) {
- ++per;
- Utils.createDirs(userDataDirectory, ze.getName());
- continue;
- }
- publishProgress(notificationBuilder, R.string.loading, 100 * ++per / size);
- try (OutputStream outputStream = new FileOutputStream(
- new File(userDataDirectory, ze.getName()))) {
- while ((readLen = zipInputStream.read(readBuffer)) != -1) {
- outputStream.write(readBuffer, 0, readLen);
- }
- }
- }
- }
- }
-
- void moveFileOrDir(@NonNull File src, @NonNull File dst) throws IOException {
- try {
- Process p = new ProcessBuilder("/system/bin/mv",
- src.getAbsolutePath(), dst.getAbsolutePath()).start();
- int exitcode = p.waitFor();
- if (exitcode != 0)
- throw new IOException("Move failed with exit code " + exitcode);
- } catch (InterruptedException e) {
- throw new IOException("Move operation interrupted");
- }
- }
-
- boolean recursivelyDeleteDirectory(@NonNull File loc) {
- try {
- Process p = new ProcessBuilder("/system/bin/rm", "-rf",
- loc.getAbsolutePath()).start();
- return p.waitFor() == 0;
- } catch (IOException | InterruptedException e) {
- return false;
- }
- }
-
- /**
- * Migrates user data from deprecated external storage to app scoped storage
- */
- private void migrate(Notification.Builder notificationBuilder, File newLocation) throws IOException {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
- return;
- }
-
- File oldLocation = new File(Environment.getExternalStorageDirectory(), "Minetest");
- if (!oldLocation.isDirectory())
- return;
-
- publishProgress(notificationBuilder, R.string.migrating, 0);
- newLocation.mkdir();
-
- String[] dirs = new String[] { "worlds", "games", "mods", "textures", "client" };
- for (int i = 0; i < dirs.length; i++) {
- publishProgress(notificationBuilder, R.string.migrating, 100 * i / dirs.length);
- File dir = new File(oldLocation, dirs[i]), dir2 = new File(newLocation, dirs[i]);
- if (dir.isDirectory() && !dir2.isDirectory()) {
- moveFileOrDir(dir, dir2);
- }
- }
-
- for (String filename : new String[] { "minetest.conf" }) {
- File file = new File(oldLocation, filename), file2 = new File(newLocation, filename);
- if (file.isFile() && !file2.isFile()) {
- moveFileOrDir(file, file2);
- }
- }
-
- recursivelyDeleteDirectory(oldLocation);
- }
-
- private void publishProgress(@Nullable Notification.Builder notificationBuilder, @StringRes int message, int progress) {
- Intent intentUpdate = new Intent(ACTION_UPDATE);
- intentUpdate.putExtra(ACTION_PROGRESS, progress);
- intentUpdate.putExtra(ACTION_PROGRESS_MESSAGE, message);
- if (!isSuccess)
- intentUpdate.putExtra(ACTION_FAILURE, failureMessage);
- sendBroadcast(intentUpdate);
-
- if (notificationBuilder != null) {
- notificationBuilder.setContentText(getString(message));
- if (progress == INDETERMINATE) {
- notificationBuilder.setProgress(100, 50, true);
- } else {
- notificationBuilder.setProgress(100, progress, false);
- }
- mNotifyManager.notify(id, notificationBuilder.build());
- }
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- mNotifyManager.cancel(id);
- publishProgress(null, R.string.loading, isSuccess ? SUCCESS : FAILURE);
- }
-}
diff --git a/android/app/src/main/java/net/minetest/minetest/Utils.java b/android/app/src/main/java/net/minetest/minetest/Utils.java
deleted file mode 100644
index b2553c844..000000000
--- a/android/app/src/main/java/net/minetest/minetest/Utils.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package net.minetest.minetest;
-
-import android.content.Context;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import java.io.File;
-
-public class Utils {
- public static @NonNull File createDirs(File root, String dir) {
- File f = new File(root, dir);
- if (!f.isDirectory())
- f.mkdirs();
-
- return f;
- }
-
- public static @Nullable File getUserDataDirectory(Context context) {
- File extDir = context.getExternalFilesDir(null);
- if (extDir == null) {
- return null;
- }
-
- return createDirs(extDir, "Minetest");
- }
-
- public static @Nullable File getCacheDirectory(Context context) {
- return context.getCacheDir();
- }
-
- public static boolean isInstallValid(Context context) {
- File userDataDirectory = getUserDataDirectory(context);
- return userDataDirectory != null && userDataDirectory.isDirectory() &&
- new File(userDataDirectory, "games").isDirectory() &&
- new File(userDataDirectory, "builtin").isDirectory() &&
- new File(userDataDirectory, "client").isDirectory() &&
- new File(userDataDirectory, "textures").isDirectory();
- }
-}