From 3a3ea52077a36c75abb2f3780022aabb8b524686 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Mon, 18 Aug 2014 23:33:18 +0930 Subject: [PATCH 1/2] Default AppDetails progress indicator to hidden. Fixes issue #75. Replaced progress indicator methods with their "support" equivalents. Also, it seems that on Android 4.0.4 and 4.0.3 if you request a progress indicator in your ActionBarActivity (from the support library), that it is set to visible to begin with. At least, that is the conclusion I have come to, seeing as the only places it is set to visible is on installApk() and removeApk(). Setting it to hidden in onCreate seemed to do the trick (Couldn't use onResume, because we come back from the "Request super user permissions" dialog, which causes onResume to be invoked). --- src/org/fdroid/fdroid/AppDetails.java | 62 ++++++++++++++++++--------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/src/org/fdroid/fdroid/AppDetails.java b/src/org/fdroid/fdroid/AppDetails.java index 8b331c65d..001763ae7 100644 --- a/src/org/fdroid/fdroid/AppDetails.java +++ b/src/org/fdroid/fdroid/AppDetails.java @@ -129,26 +129,32 @@ public class AppDetails extends ActionBarActivity implements ProgressListener, A // observer to update view when package has been installed/deleted AppObserver myAppObserver; + class AppObserver extends ContentObserver { - public AppObserver(Handler handler) { - super(handler); - } - @Override - public void onChange(boolean selfChange) { - this.onChange(selfChange, null); - } + public AppObserver(Handler handler) { + super(handler); + } - @Override - public void onChange(boolean selfChange, Uri uri) { - if (!reset(app.id)) { + @Override + public void onChange(boolean selfChange) { + onChange(selfChange, null); + } + + @Override + public void onChange(boolean selfChange, Uri uri) { + onChange(); + } + + public void onChange() { + if (!reset(app.id)) { AppDetails.this.finish(); return; - } + } - refreshApkList(); - supportInvalidateOptionsMenu(); - } + refreshApkList(); + supportInvalidateOptionsMenu(); + } } class ApkListAdapter extends ArrayAdapter { @@ -370,13 +376,16 @@ public class AppDetails extends ActionBarActivity implements ProgressListener, A @Override protected void onCreate(Bundle savedInstanceState) { - requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); fdroidApp = ((FDroidApp) getApplication()); fdroidApp.applyTheme(this); super.onCreate(savedInstanceState); + // Must be called *after* super.onCreate(), as that is where the action bar + // compat implementation is assigned in the ActionBarActivity base class. + supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); + if (getIntent().hasExtra(EXTRA_FROM)) { setTitle(getIntent().getStringExtra(EXTRA_FROM)); } @@ -425,6 +434,13 @@ public class AppDetails extends ActionBarActivity implements ProgressListener, A listFragment.removeSummaryHeader(); } + // Spinner seems to default to visible on Android 4.0.3 and 4.0.4 + // https://gitlab.com/fdroid/fdroidclient/issues/75 + // Can't put this in onResume(), because that is called on return from asking + // the user permission to use su (in which case we still want to show the + // progress indicator after returning from that prompt). + setSupportProgressBarIndeterminateVisibility(false); + } // The signature of the installed version. @@ -480,7 +496,6 @@ public class AppDetails extends ActionBarActivity implements ProgressListener, A */ private void downloadCompleteInstallApk() { if (downloadHandler != null) { - assert downloadHandler.isComplete(); installApk(downloadHandler.localFile(), downloadHandler.getApk().id); cleanUpFinishedDownload(); } @@ -855,23 +870,25 @@ public class AppDetails extends ActionBarActivity implements ProgressListener, A } private void installApk(File file, String packageName) { - setProgressBarIndeterminateVisibility(true); + setSupportProgressBarIndeterminateVisibility(true); try { installer.installPackage(file); } catch (AndroidNotCompatibleException e) { Log.e(TAG, "Android not compatible with this Installer!", e); + setSupportProgressBarIndeterminateVisibility(false); } } @Override public void removeApk(String packageName) { - setProgressBarIndeterminateVisibility(true); + setSupportProgressBarIndeterminateVisibility(true); try { installer.deletePackage(packageName); } catch (AndroidNotCompatibleException e) { Log.e(TAG, "Android not compatible with this Installer!", e); + setSupportProgressBarIndeterminateVisibility(false); } } @@ -886,7 +903,8 @@ public class AppDetails extends ActionBarActivity implements ProgressListener, A PackageManagerCompat.setInstaller(mPm, app.id); } - setProgressBarIndeterminateVisibility(false); + setSupportProgressBarIndeterminateVisibility(false); + myAppObserver.onChange(); } }); } @@ -897,14 +915,16 @@ public class AppDetails extends ActionBarActivity implements ProgressListener, A runOnUiThread(new Runnable() { @Override public void run() { - setProgressBarIndeterminateVisibility(false); + setSupportProgressBarIndeterminateVisibility(false); + myAppObserver.onChange(); } }); } else { runOnUiThread(new Runnable() { @Override public void run() { - setProgressBarIndeterminateVisibility(false); + setSupportProgressBarIndeterminateVisibility(false); + myAppObserver.onChange(); Log.e(TAG, "Installer aborted with errorCode: " + errorCode); From 82fed66a8a9c72de476d5a95e2cf3797a5195c7c Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Tue, 19 Aug 2014 08:12:47 +0930 Subject: [PATCH 2/2] Increase root installer timeout from 5 to 30s. Fixes Issue #74. The superuser shell has a timeout that can be specified. The timeout was set to 5 seconds, thus the exit code from the shell is -1 (a reserved exit code used by libsuperuse to indicate timeout). By my estimate, it is more likely that a user will hit this error message and get annoyed, compared to actually hitting a genuine timeout because of some issue with superuser. Especially when we factor in slow devices and large apps to install. Thus, the timeout has been bumped to a more generous 30 seconds. --- src/org/fdroid/fdroid/installer/RootInstaller.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/org/fdroid/fdroid/installer/RootInstaller.java b/src/org/fdroid/fdroid/installer/RootInstaller.java index ca6fb683b..dd8f6c009 100644 --- a/src/org/fdroid/fdroid/installer/RootInstaller.java +++ b/src/org/fdroid/fdroid/installer/RootInstaller.java @@ -19,15 +19,15 @@ package org.fdroid.fdroid.installer; -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import eu.chainfire.libsuperuser.Shell; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.util.Log; +import eu.chainfire.libsuperuser.Shell; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; /** * Installer using a root shell and "pm install", "pm uninstall" commands @@ -45,8 +45,8 @@ public class RootInstaller extends Installer { Shell.Builder shellBuilder = new Shell.Builder() .useSU() .setWantSTDERR(true) - .setWatchdogTimeout(5) - .setMinimalLogging(true); + .setWatchdogTimeout(30) + .setMinimalLogging(false); return shellBuilder; }