From 4ff00c89f6e79ac3c9dd970351c9386639fb8304 Mon Sep 17 00:00:00 2001 From: Francisco Franco Date: Thu, 21 May 2020 02:52:38 +0100 Subject: [PATCH] 8.2 Signed-off-by: Francisco Franco --- app/build.gradle | 19 ++-- .../java/simple/reboot/com/MainActivity.java | 89 ++++++++++--------- app/src/main/res/layout/activity_main.xml | 19 +++- app/src/main/res/values/strings.xml | 1 + build.gradle | 2 +- gradle.properties | 1 - gradle/wrapper/gradle-wrapper.properties | 2 +- 7 files changed, 70 insertions(+), 63 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 58262ff..8a6c12e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,14 +2,15 @@ apply plugin: 'com.android.application' android { compileSdkVersion 29 - buildToolsVersion "29.0.1" + buildToolsVersion "29.0.3" + viewBinding.enabled = true defaultConfig { applicationId 'simple.reboot.com' minSdkVersion 21 targetSdkVersion 29 - versionCode 1803261729 - versionName "8.1" + versionCode 1803261730 + versionName "8.2" } compileOptions { @@ -26,11 +27,9 @@ android { signingConfigs { debug { - } release { - } } @@ -50,12 +49,6 @@ android { } dependencies { - implementation 'com.google.android.material:material:1.1.0-alpha08' - if (properties.containsKey('android.injected.invoked.from.ide')) { - implementation 'com.jakewharton:butterknife-reflect:10.1.0' - } else { - implementation 'com.jakewharton:butterknife-runtime:10.1.0' - annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0' - } - implementation 'com.github.topjohnwu.libsu:core:2.5.0' + implementation 'com.google.android.material:material:1.2.0-alpha06' + implementation 'com.github.topjohnwu.libsu:core:2.5.1' } diff --git a/app/src/main/java/simple/reboot/com/MainActivity.java b/app/src/main/java/simple/reboot/com/MainActivity.java index fd75295..6da4172 100644 --- a/app/src/main/java/simple/reboot/com/MainActivity.java +++ b/app/src/main/java/simple/reboot/com/MainActivity.java @@ -4,24 +4,21 @@ import android.animation.AnimatorListenerAdapter; import android.os.Bundle; import android.view.View; -import android.view.ViewGroup; -import android.view.ViewTreeObserver; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; -import androidx.coordinatorlayout.widget.CoordinatorLayout; import com.google.android.material.snackbar.Snackbar; import com.topjohnwu.superuser.Shell; -import butterknife.BindView; -import butterknife.OnClick; +import java.util.List; +import java.util.Locale; + +import simple.reboot.com.databinding.ActivityMainBinding; + public class MainActivity extends AppCompatActivity { - @BindView(R.id.coordinator) - protected CoordinatorLayout coordinatorLayout; - @BindView(R.id.container) - protected ViewGroup container; + private ActivityMainBinding b; // just for safe measure, we don't want any data corruption, right? private static String[] SHUTDOWN_BROADCAST() { @@ -46,50 +43,45 @@ private static String[] SHUTDOWN_BROADCAST() { private static final String REBOOT_BOOTLOADER_CMD = "reboot bootloader"; private static final String[] REBOOT_SAFE_MODE = new String[]{"setprop persist.sys.safemode 1", REBOOT_SOFT_REBOOT_CMD}; + private static final String REBOOT_SYSTEMUI_CMD = "kill %d"; + private static final String PKG_SYSTEMUI = "com.android.systemui"; + private static final String PIDOF_SYSTEMUI = "pidof " + PKG_SYSTEMUI; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - new MainActivity_ViewBinding(this); + b = ActivityMainBinding.inflate(getLayoutInflater()); + setContentView(b.getRoot()); Shell.getShell(shell -> { if (!shell.isRoot()) { - if (coordinatorLayout != null) { - Snackbar.make(coordinatorLayout, R.string.root_status_no, + if (b != null) { + Snackbar.make(b.coordinator, R.string.root_status_no, Snackbar.LENGTH_INDEFINITE) .setAction(R.string.close, view -> finishAnimation()).show(); } } }); - container.getViewTreeObserver() - .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - if (container != null) { - container.getViewTreeObserver().removeOnGlobalLayoutListener(this); - - container.setTranslationY(coordinatorLayout.getHeight() >> 2); - container.setTranslationX(container.getWidth()); - container.animate().cancel(); - container.animate().translationX(0f).setStartDelay(100) - .setListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationStart(Animator animation) { - container.setVisibility(View.VISIBLE); - } - }) - .start(); + b.container.post(() -> { + b.container.setTranslationY(b.coordinator.getHeight() >> 2); + b.container.setTranslationX(b.container.getWidth()); + b.container.animate().cancel(); + b.container.animate().translationX(0f).setStartDelay(100) + .setListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationStart(Animator animation) { + b.container.setVisibility(View.VISIBLE); } - } - }); + }) + .start(); + }); } private void finishAnimation() { - if (container != null) { - container.animate().cancel(); - container.animate().translationX(container.getWidth()) + if (b != null) { + b.container.animate().cancel(); + b.container.animate().translationX(b.container.getWidth()) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { @@ -110,22 +102,18 @@ private void runCmdWithCallback(Shell.ResultCallback callback, @NonNull final St Shell.su(cmd).submit(callback); } - @OnClick(R.id.coordinator) - protected void onParentClick() { + public void onParentClick(View view) { onBackPressed(); } - @OnClick(R.id.shutdown) public void onShutdownClick(View view) { runCmd(SHUTDOWN); } - @OnClick(R.id.reboot) public void onRebootClick(View view) { runCmd(REBOOT_CMD); } - @OnClick(R.id.soft_reboot) public void onSoftRebootClick(View view) { runCmdWithCallback(out -> { if (out.isSuccess()) { @@ -134,7 +122,6 @@ public void onSoftRebootClick(View view) { }, SHUTDOWN_BROADCAST()); } - @OnClick(R.id.reboot_recovery) public void onRebootRecoveryClick(View view) { runCmdWithCallback(out -> { if (out.isSuccess()) { @@ -143,7 +130,6 @@ public void onRebootRecoveryClick(View view) { }, SHUTDOWN_BROADCAST()); } - @OnClick(R.id.reboot_bootloader) public void onRebootBootloaderClick(View view) { runCmdWithCallback(out -> { if (out.isSuccess()) { @@ -152,7 +138,6 @@ public void onRebootBootloaderClick(View view) { }, SHUTDOWN_BROADCAST()); } - @OnClick(R.id.reboot_safe_mode) public void onRebootSafeModeClick(View view) { runCmdWithCallback(out -> { if (out.isSuccess()) { @@ -161,6 +146,22 @@ public void onRebootSafeModeClick(View view) { }, SHUTDOWN_BROADCAST()); } + public void onRebootSystemUi(View view) { + runCmdWithCallback(out -> { + if (out.isSuccess()) { + List result = out.getOut(); + + if (result.size() == 1) { + // pidof returns only one line anyway, guard just for safe measures + String stdout = result.get(0).trim(); + int pid = Integer.parseInt(stdout); + + runCmd(String.format(Locale.getDefault(), REBOOT_SYSTEMUI_CMD, pid)); + } + } + }, PIDOF_SYSTEMUI); + } + @Override public void onBackPressed() { finishAnimation(); diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 5e11696..5103a26 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -4,7 +4,8 @@ xmlns:tools="http://schemas.android.com/tools" android:id="@+id/coordinator" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:onClick="onParentClick"> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 205de9e..6c650fd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -9,4 +9,5 @@ Restart to safe mode Power off Close + Restart SystemUi diff --git a/build.gradle b/build.gradle index a077751..cf27549 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.2' + classpath 'com.android.tools.build:gradle:3.6.3' } } diff --git a/gradle.properties b/gradle.properties index 4c38726..03d635a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,6 @@ org.gradle.daemon=true android.enableBuildCache=true org.gradle.parallel=true -android.enableR8=true org.gradle.caching=true android.useAndroidX=true android.enableJetifier=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index de68bf1..1bec275 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip