diff --git a/app/build.gradle b/app/build.gradle index 042683e..98830e3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,14 +2,14 @@ apply plugin: 'com.android.application' android { compileSdkVersion 27 - buildToolsVersion '27.0.3' defaultConfig { applicationId "net.fengberd.minecraftpe_server" - minSdkVersion 14 + minSdkVersion 19 + //noinspection OldTargetApi targetSdkVersion 27 - versionCode 1096 - versionName "1.0.9.6" + versionCode 1100 + versionName "1.1.0.0" } buildTypes { diff --git a/app/src/main/java/moe/berd/pocket_server/activity/MainActivity.java b/app/src/main/java/moe/berd/pocket_server/activity/MainActivity.java index e954577..dad0468 100644 --- a/app/src/main/java/moe/berd/pocket_server/activity/MainActivity.java +++ b/app/src/main/java/moe/berd/pocket_server/activity/MainActivity.java @@ -7,6 +7,7 @@ import android.content.pm.*; import android.net.*; import android.os.*; +import android.support.annotation.*; import android.support.v4.app.*; import android.support.v4.content.*; import android.view.*; @@ -18,7 +19,7 @@ import java.io.*; import java.net.*; -import java.util.*; +import java.nio.charset.*; import moe.berd.pocket_server.exception.*; import moe.berd.pocket_server.fragment.*; @@ -90,7 +91,7 @@ public void onCreate(Bundle savedInstanceState) } catch(ABINotSupportedException e) { - alertABIWarning(e.binaryName,null,e.supportedABIS); + alertABIWarning(e.binaryName,null); } catch(Exception e) { @@ -113,16 +114,14 @@ public void onCreate(Bundle savedInstanceState) } @Override - public void onRequestPermissionsResult(int requestCode,String[] permissions,int[] grantResults) + public void onRequestPermissionsResult(int requestCode,@NonNull String[] permissions,@NonNull int[] grantResults) { - switch(requestCode) + if(requestCode==REQUEST_STORAGE) { - case REQUEST_STORAGE: if(grantResults.length==0 || grantResults[0]!=PackageManager.PERMISSION_GRANTED) { toast("The app won't work without storage permission"); } - break; } } @@ -317,13 +316,13 @@ public void reloadUrls() byte[] data=new byte[is.available()]; is.read(data); is.close(); - current_version=new JSONObject(new String(data,"UTF-8")).getInt("version"); + current_version=new JSONObject(new String(data,StandardCharsets.UTF_8)).getInt("version"); is=new FileInputStream(file); data=new byte[(int)file.length()]; is.read(data); is.close(); - JSONObject json=new JSONObject(new String(data,"UTF-8")); + JSONObject json=new JSONObject(new String(data,StandardCharsets.UTF_8)); if(!json.has("version") || json.getInt("version") supportedABIS) + public void alertABIWarning(final String name,final DialogInterface.OnClickListener onclick) { runOnUiThread(new Runnable() { @@ -644,19 +643,9 @@ public static void tryDismissDialog(Dialog dialog) Context context=((ContextWrapper)dialog.getContext()).getBaseContext(); if(context instanceof Activity) { - if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN_MR1) - { - if(!((Activity)context).isFinishing() && !((Activity)context).isDestroyed()) - { - dialog.dismiss(); - } - } - else + if(!((Activity)context).isFinishing() && !((Activity)context).isDestroyed()) { - if(!((Activity)context).isFinishing()) - { - dialog.dismiss(); - } + dialog.dismiss(); } } else diff --git a/app/src/main/java/moe/berd/pocket_server/exception/ABINotSupportedException.java b/app/src/main/java/moe/berd/pocket_server/exception/ABINotSupportedException.java index 4d402f2..eb160d9 100644 --- a/app/src/main/java/moe/berd/pocket_server/exception/ABINotSupportedException.java +++ b/app/src/main/java/moe/berd/pocket_server/exception/ABINotSupportedException.java @@ -1,15 +1,11 @@ package moe.berd.pocket_server.exception; -import java.util.*; - public class ABINotSupportedException extends RuntimeException { - public String binaryName=""; - public ArrayList supportedABIS=null; + public String binaryName; - public ABINotSupportedException(String binaryName,ArrayList supportedABIS) + public ABINotSupportedException(String binaryName) { this.binaryName=binaryName; - this.supportedABIS=supportedABIS; } } diff --git a/app/src/main/java/moe/berd/pocket_server/fragment/ConsoleFragment.java b/app/src/main/java/moe/berd/pocket_server/fragment/ConsoleFragment.java index 1bc4489..acdf8f7 100644 --- a/app/src/main/java/moe/berd/pocket_server/fragment/ConsoleFragment.java +++ b/app/src/main/java/moe/berd/pocket_server/fragment/ConsoleFragment.java @@ -1,6 +1,7 @@ package moe.berd.pocket_server.fragment; import android.app.*; +import android.content.ClipboardManager; import android.content.*; import android.os.*; import android.text.*; @@ -29,6 +30,8 @@ public class ConsoleFragment extends Fragment implements Handler.Callback public EditText edit_command=null; public ScrollView scroll_log=null; + public ClipboardManager clipboardManager = null; + public ConsoleFragment() { @@ -61,11 +64,13 @@ public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle save @Override public void onStart() { + super.onStart(); + logUpdateHandler=new Handler(this); - label_log=(TextView)main.findViewById(R.id.label_log); - label_current=(TextView)main.findViewById(R.id.label_current); - edit_command=(EditText)main.findViewById(R.id.edit_command); + label_log=main.findViewById(R.id.label_log); + label_current=main.findViewById(R.id.label_current); + edit_command=main.findViewById(R.id.edit_command); edit_command.setOnKeyListener(new View.OnKeyListener() { @Override @@ -79,8 +84,8 @@ public boolean onKey(View p1,int keyCode,KeyEvent p3) return false; } }); - scroll_log=(ScrollView)main.findViewById(R.id.logScrollView); - button_command=(Button)main.findViewById(R.id.button_send); + scroll_log=main.findViewById(R.id.logScrollView); + button_command=main.findViewById(R.id.button_send); button_command.setOnClickListener(new View.OnClickListener() { @Override @@ -96,7 +101,7 @@ public void onClick(View arg0) label_log.setText(currentLog); label_current.setText(currentLine); - super.onStart(); + clipboardManager = (ClipboardManager)main.getSystemService(Context.CLIPBOARD_SERVICE); } @Override @@ -132,8 +137,7 @@ public boolean onOptionsItemSelected(MenuItem item) label_current.setText(""); break; case R.id.menu_copy: - ((android.content.ClipboardManager)main.getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData - .newPlainText("PocketServer_ConsoleLog",currentLog)); + clipboardManager.setPrimaryClip(ClipData.newPlainText("PocketServer_ConsoleLog",currentLog)); main.toast(R.string.message_copied); break; default: @@ -177,7 +181,7 @@ private void sendCommand() edit_command.setText(""); } - public static boolean postAppend(CharSequence data) + public static void postAppend(CharSequence data) { if(logUpdateHandler!=null) { @@ -185,21 +189,17 @@ public static boolean postAppend(CharSequence data) msg.arg1=MESSAGE_APPEND; msg.obj=data; logUpdateHandler.sendMessage(msg); - return true; } - return false; } - public static boolean postNewLine() + public static void postNewLine() { if(logUpdateHandler!=null) { Message msg=new Message(); msg.arg1=MESSAGE_UPDATE_LINE; logUpdateHandler.sendMessage(msg); - return true; } - return false; } public static void logLine(String line) @@ -212,7 +212,7 @@ public static void logLine(String line) } if(ansiMode) { - int index=0; + int index; while((index=line.indexOf("\u001b[1G"))!=-1) { line=line.substring(index + 4); diff --git a/app/src/main/java/moe/berd/pocket_server/fragment/MainFragment.java b/app/src/main/java/moe/berd/pocket_server/fragment/MainFragment.java index 621da73..c29d4a9 100644 --- a/app/src/main/java/moe/berd/pocket_server/fragment/MainFragment.java +++ b/app/src/main/java/moe/berd/pocket_server/fragment/MainFragment.java @@ -61,19 +61,19 @@ public void onStart() { main.findViewById(R.id.label_copyright).setOnClickListener(this); - label_path_tip=(TextView)main.findViewById(R.id.label_path_tip); + label_path_tip=main.findViewById(R.id.label_path_tip); - button_stop=(Button)main.findViewById(R.id.button_stop); + button_stop=main.findViewById(R.id.button_stop); button_stop.setOnClickListener(this); - button_start=(Button)main.findViewById(R.id.button_start); + button_start=main.findViewById(R.id.button_start); button_start.setOnClickListener(this); - button_mount=(Button)main.findViewById(R.id.button_mount); + button_mount=main.findViewById(R.id.button_mount); button_mount.setOnClickListener(this); - radio_nukkit=(RadioButton)main.findViewById(R.id.radio_nukkit); + radio_nukkit=main.findViewById(R.id.radio_nukkit); radio_nukkit.setChecked(nukkitMode); radio_nukkit.setOnClickListener(this); - radio_pocketmine=(RadioButton)main.findViewById(R.id.radio_pocketmine); + radio_pocketmine=main.findViewById(R.id.radio_pocketmine); radio_pocketmine.setChecked(!nukkitMode); radio_pocketmine.setOnClickListener(this); @@ -182,7 +182,7 @@ public void onClick(View v) main.openUrlFromJson("source_code"); break; case R.id.button_start: - if(nukkitMode && ConfigProvider.getBoolean("AutoMountJava",false) && !ServerUtils.mountedJavaLibrary()) + if(nukkitMode && ConfigProvider.getBoolean("AutoMountJava",false) && ServerUtils.javaLibraryNotFound()) { processing_dialog.setCancelable(false); processing_dialog.setMessage(getString(R.string.message_running)); @@ -299,7 +299,7 @@ public void refreshElements() { running=true; } - else if(!ServerUtils.mountedJavaLibrary() && !ConfigProvider.getBoolean("AutoMountJava",false)) + else if(ServerUtils.javaLibraryNotFound() && !ConfigProvider.getBoolean("AutoMountJava",false)) { running=true; button_mount.setEnabled(true); diff --git a/app/src/main/java/moe/berd/pocket_server/fragment/SettingsFragment.java b/app/src/main/java/moe/berd/pocket_server/fragment/SettingsFragment.java index cb6e43d..cabac38 100644 --- a/app/src/main/java/moe/berd/pocket_server/fragment/SettingsFragment.java +++ b/app/src/main/java/moe/berd/pocket_server/fragment/SettingsFragment.java @@ -61,7 +61,7 @@ public void run() } catch(ABINotSupportedException e) { - main.alertABIWarning(e.binaryName,null,e.supportedABIS); + main.alertABIWarning(e.binaryName,null); } catch(Exception e) { diff --git a/app/src/main/java/moe/berd/pocket_server/service/ServerService.java b/app/src/main/java/moe/berd/pocket_server/service/ServerService.java index db5ebb2..219a1a4 100644 --- a/app/src/main/java/moe/berd/pocket_server/service/ServerService.java +++ b/app/src/main/java/moe/berd/pocket_server/service/ServerService.java @@ -3,7 +3,6 @@ import android.app.*; import android.content.*; import android.os.*; - import android.support.v4.app.*; import net.fengberd.minecraftpe_server.*; @@ -14,6 +13,7 @@ public class ServerService extends Service { @Override + @SuppressWarnings("ConstantConditions") public int onStartCommand(Intent intent,int flags,int startId) { String channelId = ""; @@ -22,8 +22,7 @@ public int onStartCommand(Intent intent,int flags,int startId) channelId = "running"; NotificationChannel channel=new NotificationChannel(channelId,"Server Running",NotificationManager.IMPORTANCE_LOW); channel.setDescription("Make sure the service won't die"); - NotificationManager notificationManager=getSystemService(NotificationManager.class); - notificationManager.createNotificationChannel(channel); + getSystemService(NotificationManager.class).createNotificationChannel(channel); } startForeground(1,new NotificationCompat.Builder(getApplicationContext(), channelId).setOngoing(true) .setSmallIcon(R.drawable.ic_launcher) diff --git a/app/src/main/java/moe/berd/pocket_server/utils/SeekBarPreference.java b/app/src/main/java/moe/berd/pocket_server/utils/SeekBarPreference.java index 365f182..b31bbec 100644 --- a/app/src/main/java/moe/berd/pocket_server/utils/SeekBarPreference.java +++ b/app/src/main/java/moe/berd/pocket_server/utils/SeekBarPreference.java @@ -9,6 +9,7 @@ import net.fengberd.minecraftpe_server.*; +@SuppressWarnings("WeakerAccess") public class SeekBarPreference extends Preference implements SeekBar.OnSeekBarChangeListener { private int progress; @@ -35,7 +36,7 @@ protected View onCreateView(ViewGroup parent) protected void onBindView(View view) { super.onBindView(view); - SeekBar seekbar=(SeekBar)view.findViewById(R.id.preference_seekbar_seekbar); + SeekBar seekbar=view.findViewById(R.id.preference_seekbar_seekbar); if(seekbar!=null) { seekbar.setProgress(progress); diff --git a/app/src/main/java/moe/berd/pocket_server/utils/ServerUtils.java b/app/src/main/java/moe/berd/pocket_server/utils/ServerUtils.java index 69b7471..327f0f2 100644 --- a/app/src/main/java/moe/berd/pocket_server/utils/ServerUtils.java +++ b/app/src/main/java/moe/berd/pocket_server/utils/ServerUtils.java @@ -8,6 +8,7 @@ import java.io.*; import java.lang.Process; import java.net.*; +import java.nio.charset.*; import java.security.cert.*; import java.util.*; @@ -31,7 +32,6 @@ public class ServerUtils private static long startTime=0; @SuppressLint("SdCardPath") - @SuppressWarnings("SpellCheckingInspection") public static void init(Context ctx) { appFilesDirectory=ctx.getFilesDir(); @@ -120,7 +120,7 @@ public static void runServer() ini.createNewFile(); FileOutputStream os=new FileOutputStream(ini); os.write(("zend.enable_gc=On\nzend.assertions=-1\n\nenable_dl=On\nallow_url_fopen=On\nmax_execution_time=0\nregister_argc_argv=On\n\nerror_reporting=-1\ndisplay_errors=stderr\ndisplay_startup_errors=On\n\ndefault_charset=\"UTF-8\"\n\nphar.readonly=Off\nphar.require_hash=On\n\nopcache.enable=1\nopcache.enable_cli=1\nopcache.save_comments=1\nopcache.load_comments=1\nopcache.fast_shutdown=0\nopcache.memory_consumption=128\nopcache.interned_strings_buffer=8\nopcache.max_accelerated_files=4000\nopcache.optimization_level=0xffffffff") - .getBytes("UTF8")); + .getBytes(StandardCharsets.UTF_8)); os.close(); } catch(Exception ignored) @@ -155,8 +155,8 @@ public static void runServer() { startTime=System.currentTimeMillis(); serverProcess=builder.start(); - stdout=new InputStreamReader(serverProcess.getInputStream(),"UTF-8"); - stdin=new OutputStreamWriter(serverProcess.getOutputStream(),"UTF-8"); + stdout=new InputStreamReader(serverProcess.getInputStream(),StandardCharsets.UTF_8); + stdin=new OutputStreamWriter(serverProcess.getOutputStream(),StandardCharsets.UTF_8); Thread tMonitor=new Thread() { public void run() @@ -349,7 +349,6 @@ public boolean verify(String hostname,SSLSession session) return connection; } - @SuppressWarnings("deprecation") public static void installBinary(File target,Context ctx,String filename,String friendlyName) throws Exception { AssetManager assets=ctx.getAssets(); @@ -366,7 +365,7 @@ public static void installBinary(File target,Context ctx,String filename,String ABIS.add(Build.CPU_ABI2); } } - Collections.addAll(supportedABIS,assets.list(filename)); + Collections.addAll(supportedABIS,Objects.requireNonNull(assets.list(filename))); InputStream data=null; boolean compressed=false; for(String ABI : ABIS) @@ -385,7 +384,7 @@ public static void installBinary(File target,Context ctx,String filename,String } if(data==null) { - throw new ABINotSupportedException(friendlyName,supportedABIS); + throw new ABINotSupportedException(friendlyName); } target.delete(); File writeTo=compressed ? new File(target + ".tar.xz") : target; @@ -428,7 +427,7 @@ public static void mountJavaLibrary() throws Exception Runtime.getRuntime() .exec(prefix + "mount -o bind " + ServerUtils.getAppDirectory() + "/java/lib /lib") .waitFor(); - if(!mountedJavaLibrary()) + if(javaLibraryNotFound()) { throw new RuntimeException("Mount failed."); } @@ -444,7 +443,7 @@ public static boolean installedJava() return new File(getAppDirectory(),"java/jre/bin/java").exists(); } - public static boolean mountedJavaLibrary() + public static boolean javaLibraryNotFound() { String[] list=new File("/lib").list(); if(list!=null) @@ -453,11 +452,11 @@ public static boolean mountedJavaLibrary() { if(f.contains("ld-linux.so")) { - return true; + return false; } } } - return false; + return true; } public static boolean installedServerSoftware() diff --git a/app/src/main/java/moe/berd/pocket_server/utils/TerminalColorConverter.java b/app/src/main/java/moe/berd/pocket_server/utils/TerminalColorConverter.java index 413148d..e145561 100644 --- a/app/src/main/java/moe/berd/pocket_server/utils/TerminalColorConverter.java +++ b/app/src/main/java/moe/berd/pocket_server/utils/TerminalColorConverter.java @@ -3,7 +3,7 @@ import java.util.*; import java.util.regex.*; -@SuppressWarnings("SpellCheckingInspection") +@SuppressWarnings({"WeakerAccess"}) public class TerminalColorConverter { public static Pattern pattern_SGR=Pattern.compile("\u001b\\[((\\d;?)*)m"); @@ -47,7 +47,7 @@ public class TerminalColorConverter "#bcbcbc","#c6c6c6","#d0d0d0","#dadada","#e4e4e4","#eeeeee" }; - @SuppressWarnings("ConstantConditions") + @SuppressWarnings({"UnusedAssignment","unused"}) public static String control2html(String input) { String foreground="", background=""; diff --git a/build.gradle b/build.gradle index 8054476..a61c5a6 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.4' + classpath 'com.android.tools.build:gradle:3.6.3' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ca526e3..9eb9f9a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Apr 05 12:00:13 CST 2018 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +#Sat Apr 18 16:26:00 CST 2020 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip