diff --git a/app/build.gradle b/app/build.gradle
index d27ed67e..4a9a0dad 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -10,6 +10,7 @@ android {
targetSdkVersion 29
versionCode 257
versionName "2.5.1"
+ vectorDrawables.useSupportLibrary true
}
buildTypes {
release {
@@ -33,4 +34,6 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.browser:browser:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+ implementation 'com.squareup.okhttp3:okhttp:4.3.1'
+ implementation 'androidx.preference:preference:1.1.0'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index ead33afa..19a178a1 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -22,13 +22,13 @@
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
+ android:targetActivity=".activity.MainActivity">
@@ -37,56 +37,56 @@
+ android:parentActivityName=".activity.MainActivity">
+ android:value=".activity.MainActivity" />
+ android:value=".activity.MainActivity" />
+ android:parentActivityName=".activity.MainActivity">
+ android:value=".activity.MainActivity" />
+ android:parentActivityName=".activity.MainActivity">
+ android:value=".activity.MainActivity" />
+ android:parentActivityName=".activity.PropertiesActivity">
+ android:value=".activity.PropertiesActivity" />
+ android:parentActivityName=".activity.MainActivity">
+ android:value=".activity.MainActivity" />
-
+
@@ -95,7 +95,7 @@
@@ -103,12 +103,12 @@
diff --git a/app/src/main/java/ru/meefik/linuxdeploy/AppCompatPreferenceActivity.java b/app/src/main/java/ru/meefik/linuxdeploy/AppCompatPreferenceActivity.java
deleted file mode 100644
index 47873ed0..00000000
--- a/app/src/main/java/ru/meefik/linuxdeploy/AppCompatPreferenceActivity.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ru.meefik.linuxdeploy;
-
-import android.content.res.Configuration;
-import android.os.Bundle;
-import android.preference.PreferenceActivity;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-
-import androidx.annotation.LayoutRes;
-import androidx.appcompat.app.ActionBar;
-import androidx.appcompat.app.AppCompatDelegate;
-import androidx.core.app.NavUtils;
-
-/**
- * A {@link PreferenceActivity} which implements and proxies the necessary calls
- * to be used with AppCompat.
- *
- * This technique can be used with an {@link android.app.Activity} class, not just
- * {@link PreferenceActivity}.
- */
-public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
- private AppCompatDelegate mDelegate;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- getDelegate().installViewFactory();
- getDelegate().onCreate(savedInstanceState);
- super.onCreate(savedInstanceState);
- }
-
- @Override
- protected void onPostCreate(Bundle savedInstanceState) {
- super.onPostCreate(savedInstanceState);
- getDelegate().onPostCreate(savedInstanceState);
- }
-
- public ActionBar getSupportActionBar() {
- return getDelegate().getSupportActionBar();
- }
-
- @Override
- public MenuInflater getMenuInflater() {
- return getDelegate().getMenuInflater();
- }
-
- @Override
- public void setContentView(@LayoutRes int layoutResID) {
- getDelegate().setContentView(layoutResID);
- }
-
- @Override
- public void setContentView(View view) {
- getDelegate().setContentView(view);
- }
-
- @Override
- public void setContentView(View view, ViewGroup.LayoutParams params) {
- getDelegate().setContentView(view, params);
- }
-
- @Override
- public void addContentView(View view, ViewGroup.LayoutParams params) {
- getDelegate().addContentView(view, params);
- }
-
- @Override
- protected void onPostResume() {
- super.onPostResume();
- getDelegate().onPostResume();
- }
-
- @Override
- protected void onTitleChanged(CharSequence title, int color) {
- super.onTitleChanged(title, color);
- getDelegate().setTitle(title);
- }
-
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- getDelegate().onConfigurationChanged(newConfig);
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- getDelegate().onStop();
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- getDelegate().onDestroy();
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- NavUtils.navigateUpFromSameTask(this);
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-
- @Override
- public void invalidateOptionsMenu() {
- getDelegate().invalidateOptionsMenu();
- }
-
- private AppCompatDelegate getDelegate() {
- if (mDelegate == null) {
- mDelegate = AppCompatDelegate.create(this, null);
- }
- return mDelegate;
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/ru/meefik/linuxdeploy/EnvUtils.java b/app/src/main/java/ru/meefik/linuxdeploy/EnvUtils.java
index f9349901..4aebff63 100644
--- a/app/src/main/java/ru/meefik/linuxdeploy/EnvUtils.java
+++ b/app/src/main/java/ru/meefik/linuxdeploy/EnvUtils.java
@@ -6,7 +6,6 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
-import java.io.Closeable;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
@@ -19,22 +18,7 @@
import java.util.ArrayList;
import java.util.List;
-class EnvUtils {
-
- /**
- * Closeable helper
- *
- * @param c closable object
- */
- private static void close(Closeable c) {
- if (c != null) {
- try {
- c.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
+public class EnvUtils {
/**
* Extract file to env directory
@@ -47,28 +31,22 @@ private static void close(Closeable c) {
*/
private static boolean extractFile(Context c, String target, String rootAsset, String path) {
AssetManager assetManager = c.getAssets();
- InputStream in = null;
- OutputStream out = null;
- boolean result = true;
- try {
- in = assetManager.open(rootAsset + path);
+
+ try (InputStream in = assetManager.open(rootAsset + path)) {
File fname = new File(target + path);
fname.delete();
- out = new FileOutputStream(fname);
- byte[] buffer = new byte[1024];
- int read;
- while ((read = in.read(buffer)) != -1) {
- out.write(buffer, 0, read);
+ try (OutputStream out = new FileOutputStream(fname)) {
+ byte[] buffer = new byte[1024];
+ int read;
+ while ((read = in.read(buffer)) != -1) {
+ out.write(buffer, 0, read);
+ }
+ out.flush();
}
- out.flush();
+ return true;
} catch (IOException e) {
- e.printStackTrace();
- result = false;
- } finally {
- close(in);
- close(out);
+ return false;
}
- return result;
}
/**
@@ -148,45 +126,20 @@ private static void setPermissions(File path, Boolean executable) {
* @return true if success
*/
private static boolean isRooted() {
- boolean result = false;
- OutputStream stdin = null;
- InputStream stdout = null;
- int n = 0;
try {
Process process = Runtime.getRuntime().exec("su");
- stdin = process.getOutputStream();
- stdout = process.getInputStream();
-
- DataOutputStream os = null;
- try {
- os = new DataOutputStream(stdin);
- os.writeBytes("ls /data\n");
- os.writeBytes("exit\n");
- os.flush();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- close(os);
- }
+ try (DataOutputStream stdin = new DataOutputStream(process.getOutputStream());
+ BufferedReader stdout = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new InputStreamReader(stdout));
- while (reader.readLine() != null) {
- n++;
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- close(reader);
+ stdin.writeBytes("ls /data\n");
+ stdin.writeBytes("exit\n");
+ stdin.flush();
+
+ return stdout.readLine() != null;
}
} catch (IOException e) {
- e.printStackTrace();
- } finally {
- close(stdout);
- close(stdin);
+ return false;
}
- return n > 0;
}
/**
@@ -196,19 +149,13 @@ private static boolean isRooted() {
* @return true if success
*/
private static boolean setVersion(Context c) {
- boolean result = false;
String f = PrefStore.getEnvDir(c) + "/version";
- BufferedWriter bw = null;
- try {
- bw = new BufferedWriter(new FileWriter(f));
- bw.write(PrefStore.getVersion(c));
- result = true;
+ try (BufferedWriter bw = new BufferedWriter(new FileWriter(f))) {
+ bw.write(PrefStore.getVersion());
+ return true;
} catch (IOException e) {
- e.printStackTrace();
- } finally {
- close(bw);
+ return false;
}
- return result;
}
/**
@@ -217,21 +164,16 @@ private static boolean setVersion(Context c) {
* @param c context
* @return true if success
*/
- static boolean isLatestVersion(Context c) {
+ public static boolean isLatestVersion(Context c) {
File f = new File(PrefStore.getEnvDir(c) + "/version");
if (!f.exists()) return false;
- boolean result = false;
- BufferedReader br = null;
- try {
- br = new BufferedReader(new FileReader(f));
+
+ try (BufferedReader br = new BufferedReader(new FileReader(f))) {
String line = br.readLine();
- if (PrefStore.getVersion(c).equals(line)) result = true;
+ return PrefStore.getVersion().equals(line);
} catch (IOException e) {
- e.printStackTrace();
- } finally {
- close(br);
+ return false;
}
- return result;
}
/**
@@ -246,14 +188,12 @@ public static boolean exec(final Context c, final String shell, final List protocol = new ArrayList<>();
private static char lastChar = '\n';
@@ -66,7 +68,7 @@ private static synchronized void appendMessage(Context c, final String msg) {
* @param c context
* @return true if success
*/
- static boolean clear(Context c) {
+ public static boolean clear(Context c) {
protocol.clear();
File logFile = new File(PrefStore.getLogFile(c));
return logFile.delete();
@@ -77,14 +79,14 @@ static boolean clear(Context c) {
*
* @return size
*/
- static int size() {
+ public static int size() {
return protocol.size();
}
/**
* Show log on main activity
*/
- static void show() {
+ public static void show() {
MainActivity.showLog(get());
}
@@ -129,10 +131,8 @@ private static void close(Closeable c) {
* @param stream stream
*/
static void log(Context c, InputStream stream) {
- BufferedReader reader = null;
FileWriter writer = null;
- try {
- reader = new BufferedReader(new InputStreamReader(stream));
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))){
if (PrefStore.isLogger(c)) {
writer = new FileWriter(PrefStore.getLogFile(c));
}
@@ -147,7 +147,6 @@ static void log(Context c, InputStream stream) {
e.printStackTrace();
} finally {
close(writer);
- close(reader);
close(stream);
}
}
diff --git a/app/src/main/java/ru/meefik/linuxdeploy/MountsActivity.java b/app/src/main/java/ru/meefik/linuxdeploy/MountsActivity.java
deleted file mode 100644
index e516aeff..00000000
--- a/app/src/main/java/ru/meefik/linuxdeploy/MountsActivity.java
+++ /dev/null
@@ -1,193 +0,0 @@
-package ru.meefik.linuxdeploy;
-
-import android.content.DialogInterface;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.ListView;
-import android.widget.TextView;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import androidx.appcompat.app.AlertDialog;
-import androidx.appcompat.app.AppCompatActivity;
-
-public class MountsActivity extends AppCompatActivity {
-
- private List listItems = new ArrayList<>();
- private ArrayAdapter adapter;
-
- private void addDialog() {
- LayoutInflater layoutInflater = LayoutInflater.from(this);
- View view = layoutInflater.inflate(R.layout.properties_mounts, null);
- final EditText inputSrc = view.findViewById(R.id.editTextSrc);
- final EditText inputTarget = view.findViewById(R.id.editTextTarget);
- new AlertDialog.Builder(this)
- .setTitle(R.string.new_mount_title)
- .setView(view)
- .setPositiveButton(android.R.string.ok,
- (dialog, whichButton) -> {
- String text = "";
- String src = inputSrc.getText().toString()
- .replaceAll("[ :]", "_");
- String target = inputTarget.getText().toString()
- .replaceAll("[ :]", "_");
- if (src.length() > 0) {
- text = src;
- if (target.length() > 0) {
- text = text + ":" + target;
- }
- }
- if (text.length() > 0) {
- listItems.add(text);
- adapter.notifyDataSetChanged();
- }
- }).setNegativeButton(android.R.string.cancel,
- (dialog, whichButton) -> dialog.cancel()).show();
- }
-
- private void editDialog(final int position) {
- LayoutInflater layoutInflater = LayoutInflater.from(this);
- View view = layoutInflater.inflate(R.layout.properties_mounts, null);
- final EditText inputSrc = view.findViewById(R.id.editTextSrc);
- final EditText inputTarget = view.findViewById(R.id.editTextTarget);
- if (position >= 0 && position < listItems.size()) {
- String text = listItems.get(position);
- final String[] arr = text.split(":", 2);
- try {
- inputSrc.setText(arr[0]);
- inputSrc.setSelection(arr[0].length());
-
- inputTarget.setText(arr[1]);
- inputTarget.setSelection(arr[1].length());
- } catch (IndexOutOfBoundsException ignored) {
- }
-
- new AlertDialog.Builder(this)
- .setTitle(R.string.edit_mount_title)
- .setView(view)
- .setPositiveButton(android.R.string.ok,
- (dialog, whichButton) -> {
- String text1 = "";
- String src = inputSrc.getText().toString()
- .replaceAll("[ :]", "_");
- String target = inputTarget.getText().toString()
- .replaceAll("[ :]", "_");
- if (src.length() > 0) {
- text1 = src;
- if (target.length() > 0) {
- text1 = text1 + ":" + target;
- }
- }
- if (text1.length() > 0) {
- listItems.set(position, text1);
- adapter.notifyDataSetChanged();
- }
- }).setNegativeButton(android.R.string.cancel,
- (dialog, whichButton) -> dialog.cancel()).show();
- }
- }
-
- private void deleteDialog(final int position) {
- if (position >= 0 && position < listItems.size()) {
- new AlertDialog.Builder(this)
- .setTitle(R.string.confirm_mount_discard_title)
- .setMessage(R.string.confirm_mount_discard_message)
- .setIcon(android.R.drawable.ic_dialog_alert)
- .setCancelable(false)
- .setPositiveButton(android.R.string.yes,
- (dialog, whichButton) -> {
- listItems.remove(position);
- adapter.notifyDataSetChanged();
- }).setNegativeButton(android.R.string.no,
- (dialog, whichButton) -> dialog.cancel()).show();
- }
- }
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- PrefStore.setLocale(this);
- setContentView(R.layout.activity_mounts);
-
- // ListView Adapter
- ListView listView = findViewById(R.id.mountsView);
- adapter = new ArrayAdapter(this, R.layout.mounts_row, R.id.mount_point, listItems) {
- @Override
- public View getView(final int position, View convertView, final ViewGroup parent) {
- View view = super.getView(position, convertView, parent);
- TextView tv = view.findViewById(R.id.mount_point);
- Button btn = view.findViewById(R.id.delete_mount);
-
- String item = getItem(position);
- tv.setText(item);
-
- tv.setOnClickListener(v -> {
- ((ListView) parent).performItemClick(v, position, 0); // Let the event be handled in onItemClick()
- });
-
- btn.setOnClickListener(v -> {
- ((ListView) parent).performItemClick(v, position, 0); // Let the event be handled in onItemClick()
- });
-
- return view;
- }
- };
- listView.setAdapter(adapter);
-
- // Click listener
- listView.setOnItemClickListener((parent, view, position, id) -> {
- long viewId = view.getId();
- if (viewId == R.id.delete_mount) deleteDialog(position);
- else editDialog(position);
- });
- }
-
- @Override
- public void setTheme(int resId) {
- super.setTheme(PrefStore.getTheme(this));
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- PrefStore.setLocale(this);
- getMenuInflater().inflate(R.menu.activity_mounts, menu);
- return super.onCreateOptionsMenu(menu);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.menu_add:
- addDialog();
- break;
- }
- return false;
- }
-
- @Override
- public void onResume() {
- super.onResume();
-
- String titleMsg = getString(R.string.title_activity_mounts) + ": "
- + PrefStore.getProfileName(this);
- setTitle(titleMsg);
-
- listItems.addAll(PrefStore.getMountsList(this));
- }
-
- @Override
- public void onPause() {
- super.onPause();
-
- PrefStore.setMountsList(this, listItems);
- }
-}
diff --git a/app/src/main/java/ru/meefik/linuxdeploy/NetworkReceiver.java b/app/src/main/java/ru/meefik/linuxdeploy/NetworkReceiver.java
deleted file mode 100644
index e557663a..00000000
--- a/app/src/main/java/ru/meefik/linuxdeploy/NetworkReceiver.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package ru.meefik.linuxdeploy;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
-
-public class NetworkReceiver extends BroadcastReceiver {
-
- @Override
- public void onReceive(final Context context, Intent intent) {
- if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
- ConnectivityManager cm =
- (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
-
- NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
- boolean isConnected = false;
- if (activeNetwork != null) isConnected = activeNetwork.isConnected();
- if (isConnected) {
- EnvUtils.execService(context, "start", "core/net");
- } else {
- EnvUtils.execService(context, "stop", "core/net");
- }
- }
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/ru/meefik/linuxdeploy/ParamUtils.java b/app/src/main/java/ru/meefik/linuxdeploy/ParamUtils.java
index 3cec7084..eaecae40 100644
--- a/app/src/main/java/ru/meefik/linuxdeploy/ParamUtils.java
+++ b/app/src/main/java/ru/meefik/linuxdeploy/ParamUtils.java
@@ -5,7 +5,6 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
-import java.io.Closeable;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
@@ -25,27 +24,11 @@ class ParamUtils {
this.params = Arrays.asList(params);
}
- /**
- * Closeable helper
- *
- * @param c closable object
- */
- private static void close(Closeable c) {
- if (c != null) {
- try {
- c.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
private static Map readConf(File confFile) {
TreeMap map = new TreeMap<>();
- BufferedReader br = null;
- String line;
- try {
- br = new BufferedReader(new FileReader(confFile));
+
+ try (BufferedReader br = new BufferedReader(new FileReader(confFile))) {
+ String line;
while ((line = br.readLine()) != null) {
if (!line.startsWith("#") && !line.isEmpty()) {
String[] pair = line.split("=");
@@ -54,32 +37,25 @@ private static Map readConf(File confFile) {
map.put(key, value.replaceAll("\"", ""));
}
}
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- close(br);
+ } catch (IOException e) {
+ // Error!
}
+
return map;
}
private static boolean writeConf(Map map, File confFile) {
- Boolean result = false;
- BufferedWriter bw = null;
- try {
- bw = new BufferedWriter(new FileWriter(confFile));
+ try (BufferedWriter bw = new BufferedWriter(new FileWriter(confFile))) {
for (Map.Entry entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
bw.write(key + "=\"" + value + "\"");
bw.newLine();
}
- result = true;
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- close(bw);
+ return true;
+ } catch (IOException e) {
+ return false;
}
- return result;
}
public String fixOutputParam(Context c, String key, String value) {
@@ -169,7 +145,8 @@ boolean restore(Context c, File f) {
void clear(Context c, boolean all) {
SharedPreferences pref = c.getSharedPreferences(this.name, Context.MODE_PRIVATE);
SharedPreferences.Editor prefEditor = pref.edit();
- if (all) prefEditor.clear();
+ if (all)
+ prefEditor.clear();
else {
for (Map.Entry entry : pref.getAll().entrySet()) {
String key = entry.getKey();
diff --git a/app/src/main/java/ru/meefik/linuxdeploy/PrefStore.java b/app/src/main/java/ru/meefik/linuxdeploy/PrefStore.java
index f068b3a6..b43c13d7 100644
--- a/app/src/main/java/ru/meefik/linuxdeploy/PrefStore.java
+++ b/app/src/main/java/ru/meefik/linuxdeploy/PrefStore.java
@@ -11,6 +11,9 @@
import android.view.Display;
import android.view.WindowManager;
+import androidx.core.app.NotificationCompat;
+import androidx.core.app.TaskStackBuilder;
+
import java.io.File;
import java.net.Inet4Address;
import java.net.InetAddress;
@@ -22,8 +25,7 @@
import java.util.List;
import java.util.Locale;
-import androidx.core.app.NotificationCompat;
-import androidx.core.app.TaskStackBuilder;
+import ru.meefik.linuxdeploy.activity.MainActivity;
import static ru.meefik.linuxdeploy.App.SERVICE_CHANNEL_ID;
@@ -36,10 +38,9 @@ public class PrefStore {
/**
* Get application version
*
- * @param c context
* @return version, format versionName-versionCode
*/
- static String getVersion(Context c) {
+ public static String getVersion() {
return BuildConfig.VERSION_NAME + "-" + BuildConfig.VERSION_CODE;
}
@@ -49,7 +50,7 @@ static String getVersion(Context c) {
* @param c context
* @return path, e.g. /data/data/package/files
*/
- static String getEnvDir(Context c) {
+ public static String getEnvDir(Context c) {
String envDir = SETTINGS.get(c, "env_dir");
if (envDir.isEmpty()) {
envDir = c.getFilesDir().getAbsolutePath();
@@ -103,7 +104,7 @@ static String getWebDir(Context c) {
* @param c context
* @return true if success
*/
- static boolean dumpSettings(Context c) {
+ public static boolean dumpSettings(Context c) {
return SETTINGS.dump(c, getSettingsConfFile(c));
}
@@ -113,7 +114,7 @@ static boolean dumpSettings(Context c) {
* @param c context
* @return true if success
*/
- static boolean restoreSettings(Context c) {
+ public static boolean restoreSettings(Context c) {
return SETTINGS.restore(c, getSettingsConfFile(c));
}
@@ -123,7 +124,7 @@ static boolean restoreSettings(Context c) {
* @param c context
* @return true if success
*/
- static boolean dumpProperties(Context c) {
+ public static boolean dumpProperties(Context c) {
return PROPERTIES.dump(c, getPropertiesConfFile(c));
}
@@ -133,7 +134,7 @@ static boolean dumpProperties(Context c) {
* @param c context
* @return true if success
*/
- static boolean restoreProperties(Context c) {
+ public static boolean restoreProperties(Context c) {
PROPERTIES.clear(c, true);
return PROPERTIES.restore(c, getPropertiesConfFile(c));
}
@@ -143,7 +144,7 @@ static boolean restoreProperties(Context c) {
*
* @return name
*/
- static String getSettingsSharedName() {
+ public static String getSettingsSharedName() {
return SettingsStore.name;
}
@@ -152,7 +153,7 @@ static String getSettingsSharedName() {
*
* @return name
*/
- static String getPropertiesSharedName() {
+ public static String getPropertiesSharedName() {
return PropertiesStore.name;
}
@@ -195,7 +196,7 @@ private static String getLanguage(Context c) {
* @param c context
* @return resource id
*/
- static int getTheme(Context c) {
+ public static int getTheme(Context c) {
String theme = SETTINGS.get(c, "theme");
int themeId = R.style.DarkTheme;
switch (theme) {
@@ -215,7 +216,7 @@ static int getTheme(Context c) {
* @param c context
* @return font size
*/
- static int getFontSize(Context c) {
+ public static int getFontSize(Context c) {
int fontSizeInt;
String fontSize = SETTINGS.get(c, "fontsize");
try {
@@ -293,7 +294,7 @@ static Boolean isLogger(Context c) {
* @param c context
* @return path
*/
- static String getLogFile(Context c) {
+ public static String getLogFile(Context c) {
String logFile = SETTINGS.get(c, "logfile");
if (!logFile.contains("/")) {
String storageDir = Environment.getExternalStorageDirectory().getAbsolutePath();
@@ -308,7 +309,7 @@ static String getLogFile(Context c) {
* @param c context
* @return true if enabled
*/
- static Boolean isScreenLock(Context c) {
+ public static Boolean isScreenLock(Context c) {
return SETTINGS.get(c, "screenlock").equals("true");
}
@@ -318,7 +319,7 @@ static Boolean isScreenLock(Context c) {
* @param c context
* @return true if enabled
*/
- static Boolean isWifiLock(Context c) {
+ public static Boolean isWifiLock(Context c) {
return SETTINGS.get(c, "wifilock").equals("true");
}
@@ -328,7 +329,7 @@ static Boolean isWifiLock(Context c) {
* @param c context
* @return true if enabled
*/
- static Boolean isWakeLock(Context c) {
+ public static Boolean isWakeLock(Context c) {
return SETTINGS.get(c, "wakelock").equals("true");
}
@@ -338,7 +339,7 @@ static Boolean isWakeLock(Context c) {
* @param c context
* @return true if enabled
*/
- static Boolean isAutostart(Context c) {
+ public static Boolean isAutostart(Context c) {
return SETTINGS.get(c, "autostart").equals("true");
}
@@ -348,7 +349,7 @@ static Boolean isAutostart(Context c) {
* @param c context
* @return Auto start delay in seconds
*/
- static Integer getAutostartDelay(Context c) {
+ public static Integer getAutostartDelay(Context c) {
try {
return Integer.parseInt(SETTINGS.get(c, "autostart_delay"));
} catch (Exception e) {
@@ -362,7 +363,7 @@ static Integer getAutostartDelay(Context c) {
* @param c context
* @return true if enabled
*/
- static Boolean isNetTrack(Context c) {
+ public static Boolean isNetTrack(Context c) {
return SETTINGS.get(c, "nettrack").equals("true");
}
@@ -372,7 +373,7 @@ static Boolean isNetTrack(Context c) {
* @param c context
* @return true if enabled
*/
- static Boolean isPowerTrack(Context c) {
+ public static Boolean isPowerTrack(Context c) {
return SETTINGS.get(c, "powertrack").equals("true");
}
@@ -392,7 +393,7 @@ private static Boolean isNotification(Context c) {
* @param c context
* @return true if enabled
*/
- static Boolean isStealth(Context c) {
+ public static Boolean isStealth(Context c) {
return SETTINGS.get(c, "stealth").equals("true");
}
@@ -431,7 +432,7 @@ static String getShell(Context c) {
* @param c context
* @return url
*/
- static String getRepositoryUrl(Context c) {
+ public static String getRepositoryUrl(Context c) {
return SETTINGS.get(c, "repository_url");
}
@@ -440,7 +441,7 @@ static String getRepositoryUrl(Context c) {
*
* @param c context
*/
- static void setRepositoryUrl(Context c, String url) {
+ public static void setRepositoryUrl(Context c, String url) {
SETTINGS.set(c, "repository_url", url);
}
@@ -490,7 +491,7 @@ static Boolean isHttp(Context c) {
* @param c context
* @return port
*/
- static String getHttpPort(Context c) {
+ public static String getHttpPort(Context c) {
return SETTINGS.get(c, "http_port");
}
@@ -500,7 +501,7 @@ static String getHttpPort(Context c) {
* @param c context
* @return authentication string, e.g. /:user:password (for crypt password use httpd -m password)
*/
- static String getHttpConf(Context c) {
+ public static String getHttpConf(Context c) {
String auth = SETTINGS.get(c, "http_conf");
if (auth.isEmpty()) auth = "/:android:" + generatePassword();
return auth;
@@ -512,7 +513,7 @@ static String getHttpConf(Context c) {
* @param c context
* @return true if enabled
*/
- static boolean isXserver(Context c) {
+ public static boolean isXserver(Context c) {
return PROPERTIES.get(c, "is_gui").equals("true") &&
PROPERTIES.get(c, "graphics").equals("x11");
}
@@ -523,7 +524,7 @@ static boolean isXserver(Context c) {
* @param c context
* @return true if enabled
*/
- static boolean isFramebuffer(Context c) {
+ public static boolean isFramebuffer(Context c) {
return PROPERTIES.get(c, "is_gui").equals("true") &&
PROPERTIES.get(c, "graphics").equals("fb");
}
@@ -534,7 +535,7 @@ static boolean isFramebuffer(Context c) {
* @param c context
* @return true if enabled
*/
- static boolean isXsdl(Context c) {
+ public static boolean isXsdl(Context c) {
return PROPERTIES.get(c, "x11_sdl").equals("true");
}
@@ -544,7 +545,7 @@ static boolean isXsdl(Context c) {
* @param c context
* @return delay in ms
*/
- static int getXsdlDelay(Context c) {
+ public static int getXsdlDelay(Context c) {
int deplayInt;
String delay = PROPERTIES.get(c, "x11_sdl_delay");
try {
@@ -583,7 +584,7 @@ static File getPropertiesConfFile(Context c) {
* @param c context
* @return profile
*/
- static String getProfileName(Context c) {
+ public static String getProfileName(Context c) {
return SETTINGS.get(c, "profile");
}
@@ -592,7 +593,7 @@ static String getProfileName(Context c) {
*
* @param c context
*/
- static void changeProfile(Context c, String profile) {
+ public static void changeProfile(Context c, String profile) {
SETTINGS.set(c, "profile", profile);
dumpSettings(c);
File confFile = getPropertiesConfFile(c);
@@ -607,7 +608,7 @@ static void changeProfile(Context c, String profile) {
*
* @param c context
*/
- static void setLocale(Context c) {
+ public static void setLocale(Context c) {
String language = getLanguage(c);
Locale locale = new Locale(language);
Locale.setDefault(locale);
@@ -622,7 +623,7 @@ static void setLocale(Context c) {
* @param c context
* @return list of mount points
*/
- static List getMountsList(Context c) {
+ public static List getMountsList(Context c) {
String str = PROPERTIES.get(c, "mounts");
List list = new ArrayList<>();
if (!str.isEmpty()) Collections.addAll(list, str.split(" "));
@@ -635,7 +636,7 @@ static List getMountsList(Context c) {
* @param c context
* @param list list of mount points
*/
- static void setMountsList(Context c, List list) {
+ public static void setMountsList(Context c, List list) {
PROPERTIES.set(c, "mounts", TextUtils.join(" ", list));
}
@@ -644,7 +645,7 @@ static void setMountsList(Context c, List list) {
*
* @return plain password
*/
- static String generatePassword() {
+ public static String generatePassword() {
return Long.toHexString(Double.doubleToLongBits(Math.random())).substring(8);
}
@@ -654,7 +655,7 @@ static String generatePassword() {
* @param arch unformated architecture
* @return arm, arm_64, x86, x86_64
*/
- static String getArch(String arch) {
+ public static String getArch(String arch) {
String march = "unknown";
if (arch.length() > 0) {
char a = arch.toLowerCase().charAt(0);
@@ -679,7 +680,7 @@ static String getArch(String arch) {
*
* @return arm, arm_64, x86, x86_64
*/
- static String getArch() {
+ public static String getArch() {
return getArch(System.getProperty("os.arch"));
}
@@ -689,14 +690,12 @@ static String getArch() {
* @param c context
* @return screen width
*/
- static Integer getScreenWidth(Context c) {
- int width;
+ static int getScreenWidth(Context c) {
WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
- width = size.x;
- return width;
+ return size.x;
}
/**
@@ -705,14 +704,12 @@ static Integer getScreenWidth(Context c) {
* @param c context
* @return screen height
*/
- static Integer getScreenHeight(Context c) {
- int height;
+ static int getScreenHeight(Context c) {
WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
- height = size.y;
- return height;
+ return size.y;
}
/**
@@ -720,7 +717,7 @@ static Integer getScreenHeight(Context c) {
*
* @return ip address
*/
- static String getLocalIpAddress() {
+ public static String getLocalIpAddress() {
String ip = "127.0.0.1";
try {
for (Enumeration en = NetworkInterface
@@ -748,7 +745,7 @@ static String getLocalIpAddress() {
* @param resourceType resource type
* @return resource id
*/
- static int getResourceId(Context c, String resourceName, String resourceType) {
+ public static int getResourceId(Context c, String resourceName, String resourceType) {
try {
return c.getResources().getIdentifier(resourceName, resourceType, c.getPackageName());
} catch (Exception e) {
@@ -762,12 +759,12 @@ static int getResourceId(Context c, String resourceName, String resourceType) {
* @param context context
* @param intent intent
*/
- static void showNotification(Context context, Intent intent) {
- NotificationManager mNotificationManager = (NotificationManager) context
+ public static void showNotification(Context context, Intent intent) {
+ NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
if (isNotification(context)) {
setLocale(context);
- NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, SERVICE_CHANNEL_ID)
+ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, SERVICE_CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(context.getString(R.string.app_name))
.setContentText(context.getString(R.string.notification_current_profile)
@@ -778,7 +775,7 @@ static void showNotification(Context context, Intent intent) {
stealthReceive.setAction("ru.meefik.linuxdeploy.BROADCAST_ACTION");
stealthReceive.putExtra("show", true);
PendingIntent pendingIntentStealth = PendingIntent.getBroadcast(context, 2, stealthReceive, PendingIntent.FLAG_UPDATE_CURRENT);
- mBuilder.setContentIntent(pendingIntentStealth);
+ notificationBuilder.setContentIntent(pendingIntentStealth);
} else {
Intent resultIntent = intent;
if (resultIntent == null) resultIntent = new Intent(context, MainActivity.class);
@@ -786,27 +783,25 @@ static void showNotification(Context context, Intent intent) {
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(1, PendingIntent.FLAG_UPDATE_CURRENT);
- mBuilder.setContentIntent(resultPendingIntent);
+ notificationBuilder.setContentIntent(resultPendingIntent);
Intent startReceive = new Intent();
startReceive.setAction("ru.meefik.linuxdeploy.BROADCAST_ACTION");
startReceive.putExtra("start", true);
PendingIntent pendingIntentStart = PendingIntent.getBroadcast(context, 3, startReceive, PendingIntent.FLAG_UPDATE_CURRENT);
- int startIcon = SETTINGS.get(context, "theme").equals("dark") ? R.drawable.ic_action_start_dark : R.drawable.ic_action_start_light;
- mBuilder.addAction(startIcon, context.getString(R.string.menu_start), pendingIntentStart);
+ notificationBuilder.addAction(R.drawable.ic_play_arrow_24dp, context.getString(R.string.menu_start), pendingIntentStart);
Intent stopReceive = new Intent();
stopReceive.setAction("ru.meefik.linuxdeploy.BROADCAST_ACTION");
stopReceive.putExtra("stop", true);
PendingIntent pendingIntentStop = PendingIntent.getBroadcast(context, 4, stopReceive, PendingIntent.FLAG_UPDATE_CURRENT);
- int stopIcon = SETTINGS.get(context, "theme").equals("dark") ? R.drawable.ic_action_stop_dark : R.drawable.ic_action_stop_light;
- mBuilder.addAction(stopIcon, context.getString(R.string.menu_stop), pendingIntentStop);
+ notificationBuilder.addAction(R.drawable.ic_stop_24dp, context.getString(R.string.menu_stop), pendingIntentStop);
}
- mBuilder.setOngoing(true);
- mBuilder.setWhen(0);
- mNotificationManager.notify(NOTIFY_ID, mBuilder.build());
+ notificationBuilder.setOngoing(true);
+ notificationBuilder.setWhen(0);
+ notificationManager.notify(NOTIFY_ID, notificationBuilder.build());
} else {
- mNotificationManager.cancel(NOTIFY_ID);
+ notificationManager.cancel(NOTIFY_ID);
}
}
@@ -815,9 +810,9 @@ static void showNotification(Context context, Intent intent) {
*
* @param context context
*/
- static void hideNotification(Context context) {
- NotificationManager mNotificationManager = (NotificationManager) context
+ public static void hideNotification(Context context) {
+ NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
- mNotificationManager.cancel(NOTIFY_ID);
+ notificationManager.cancel(NOTIFY_ID);
}
}
diff --git a/app/src/main/java/ru/meefik/linuxdeploy/RemoveEnvTask.java b/app/src/main/java/ru/meefik/linuxdeploy/RemoveEnvTask.java
index bb7dcafa..d212b717 100644
--- a/app/src/main/java/ru/meefik/linuxdeploy/RemoveEnvTask.java
+++ b/app/src/main/java/ru/meefik/linuxdeploy/RemoveEnvTask.java
@@ -6,12 +6,12 @@
import java.lang.ref.WeakReference;
-class RemoveEnvTask extends AsyncTask {
+public class RemoveEnvTask extends AsyncTask {
private ProgressDialog dialog;
private WeakReference contextWeakReference;
- RemoveEnvTask(Context c) {
+ public RemoveEnvTask(Context c) {
contextWeakReference = new WeakReference<>(c);
}
diff --git a/app/src/main/java/ru/meefik/linuxdeploy/RepositoryActivity.java b/app/src/main/java/ru/meefik/linuxdeploy/RepositoryActivity.java
deleted file mode 100644
index 24980324..00000000
--- a/app/src/main/java/ru/meefik/linuxdeploy/RepositoryActivity.java
+++ /dev/null
@@ -1,389 +0,0 @@
-package ru.meefik.linuxdeploy;
-
-import android.app.ProgressDialog;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.net.Uri;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
-import android.widget.EditText;
-import android.widget.ImageView;
-import android.widget.ListView;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import java.io.BufferedReader;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.lang.ref.WeakReference;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.zip.GZIPInputStream;
-
-import androidx.appcompat.app.AlertDialog;
-import androidx.appcompat.app.AppCompatActivity;
-
-public class RepositoryActivity extends AppCompatActivity {
-
- private List