From 5190233d197f1cee5e7d522bd7627dce48ccc0ab Mon Sep 17 00:00:00 2001 From: meefik Date: Mon, 21 Oct 2019 00:11:21 +0300 Subject: [PATCH] Improved power trigger --- CHANGELOG.md | 4 +++ app/build.gradle | 6 ++-- app/src/main/AndroidManifest.xml | 21 +++++------ app/src/main/assets/env | 2 +- .../ru/meefik/linuxdeploy/MainActivity.java | 36 ++++++++++++++----- .../ru/meefik/linuxdeploy/PowerReceiver.java | 6 +++- .../java/ru/meefik/linuxdeploy/PrefStore.java | 10 ++++++ app/src/main/res/values-ru/strings.xml | 4 +++ app/src/main/res/values/preferences.xml | 1 + app/src/main/res/values/strings.xml | 3 ++ app/src/main/res/xml/settings.xml | 5 +++ build.gradle | 2 +- 12 files changed, 73 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5063735..9dd01bd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [2.4.1] - 2019-10-20 +### Added +- Added power trigger + ## [2.4.0] - 2019-08-12 ### Added - Added support Alpine Linux diff --git a/app/build.gradle b/app/build.gradle index 5c747593..ca134683 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId 'ru.meefik.linuxdeploy' minSdkVersion 15 targetSdkVersion 28 - versionCode 251 - versionName "2.4.0" + versionCode 252 + versionName "2.4.1" } buildTypes { release { @@ -29,7 +29,7 @@ android { dependencies { implementation 'com.google.android.material:material:1.0.0' - implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.browser:browser:1.0.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 88577738..7c72f804 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ @@ -13,12 +14,12 @@ + android:usesCleartextTraffic="true" + tools:ignore="GoogleAppIndexingWarning"> - - - - - - + + diff --git a/app/src/main/assets/env b/app/src/main/assets/env index aba3b497..55de0755 160000 --- a/app/src/main/assets/env +++ b/app/src/main/assets/env @@ -1 +1 @@ -Subproject commit aba3b49756309c3bc3c1765481bc3b797c9a7f28 +Subproject commit 55de07554712f03aad96bbd4b5281a1aee3ec348 diff --git a/app/src/main/java/ru/meefik/linuxdeploy/MainActivity.java b/app/src/main/java/ru/meefik/linuxdeploy/MainActivity.java index 0d5f73d5..ed65a843 100644 --- a/app/src/main/java/ru/meefik/linuxdeploy/MainActivity.java +++ b/app/src/main/java/ru/meefik/linuxdeploy/MainActivity.java @@ -47,6 +47,7 @@ public class MainActivity extends AppCompatActivity implements private static PowerManager.WakeLock wakeLock; private NetworkReceiver networkReceiver; + private PowerReceiver powerReceiver; private NetworkReceiver getNetworkReceiver() { if (networkReceiver == null) @@ -55,6 +56,13 @@ private NetworkReceiver getNetworkReceiver() { return networkReceiver; } + private PowerReceiver getPowerReceiver() { + if (powerReceiver == null) + powerReceiver = new PowerReceiver(); + + return powerReceiver; + } + /** * Show message in TextView, used from Logger * @@ -80,7 +88,9 @@ public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); ActionBar actionBar = getSupportActionBar(); - actionBar.setDisplayHomeAsUpEnabled(true); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); + } DrawerLayout drawer = findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( @@ -113,6 +123,16 @@ public void onCreate(Bundle savedInstanceState) { unregisterReceiver(networkReceiver); } + // Power receiver + if (PrefStore.isPowerTrack(this)) { + IntentFilter filter = new IntentFilter(); + filter.addAction(Intent.ACTION_SCREEN_ON); + filter.addAction(Intent.ACTION_SCREEN_OFF); + registerReceiver(getPowerReceiver(), filter); + } else if (powerReceiver != null) { + unregisterReceiver(powerReceiver); + } + if (EnvUtils.isLatestVersion(this)) { // start services EnvUtils.execServices(getBaseContext(), new String[]{"telnetd", "httpd"}, "start"); @@ -269,7 +289,7 @@ public void onResume() { // Wake lock if (PrefStore.isWakeLock(this)) { - if (!wakeLock.isHeld()) wakeLock.acquire(); + if (!wakeLock.isHeld()) wakeLock.acquire(60*60*1000L /*60 minutes*/); } else { if (wakeLock.isHeld()) wakeLock.release(); } @@ -420,13 +440,11 @@ private void updateEnvWithRequestPermissions() { @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); - switch (requestCode) { - case REQUEST_WRITE_STORAGE: { - if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - new UpdateEnvTask(this).execute(); - } else { - Toast.makeText(this, getString(R.string.write_permissions_disallow), Toast.LENGTH_LONG).show(); - } + if (requestCode == REQUEST_WRITE_STORAGE) { + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + new UpdateEnvTask(this).execute(); + } else { + Toast.makeText(this, getString(R.string.write_permissions_disallow), Toast.LENGTH_LONG).show(); } } } diff --git a/app/src/main/java/ru/meefik/linuxdeploy/PowerReceiver.java b/app/src/main/java/ru/meefik/linuxdeploy/PowerReceiver.java index 5508d0ae..e5a55cf2 100644 --- a/app/src/main/java/ru/meefik/linuxdeploy/PowerReceiver.java +++ b/app/src/main/java/ru/meefik/linuxdeploy/PowerReceiver.java @@ -8,6 +8,10 @@ public class PowerReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, Intent intent) { - EnvUtils.execService(context, "start", "core/power"); + if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { + EnvUtils.execService(context, "stop", "core/power"); + } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { + EnvUtils.execService(context, "start", "core/power"); + } } } diff --git a/app/src/main/java/ru/meefik/linuxdeploy/PrefStore.java b/app/src/main/java/ru/meefik/linuxdeploy/PrefStore.java index 470bff17..40e508fb 100644 --- a/app/src/main/java/ru/meefik/linuxdeploy/PrefStore.java +++ b/app/src/main/java/ru/meefik/linuxdeploy/PrefStore.java @@ -371,6 +371,16 @@ static Boolean isNetTrack(Context c) { return SETTINGS.get(c, "nettrack").equals("true"); } + /** + * Track changes of the power status is enabled + * + * @param c context + * @return true if enabled + */ + static Boolean isPowerTrack(Context c) { + return SETTINGS.get(c, "powertrack").equals("true"); + } + /** * Show icon is enabled * diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 5c8b3da2..dd94bf50 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -247,5 +247,9 @@ Целевая (опционально) Путь к скрипту триггера Сетевой триггер + Путь к скрипту триггера + Триггер питания + Отслеживать изменения питания и обновлять контейнер + Отслеживать изменения питания diff --git a/app/src/main/res/values/preferences.xml b/app/src/main/res/values/preferences.xml index d25b9ac0..62e5b283 100644 --- a/app/src/main/res/values/preferences.xml +++ b/app/src/main/res/values/preferences.xml @@ -13,6 +13,7 @@ false 30 false + false http://hub.meefik.ru diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c19bff76..aa3c1b2d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -103,6 +103,9 @@ Track network changes Track changes of the network and update the container + + Track power changes + Track changes of the power and update the container Environment diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 45efa4a3..223ebc1e 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -85,6 +85,11 @@ android:key="nettrack" android:summary="@string/summary_nettrack_preference" android:title="@string/title_nettrack_preference" /> +