Merge branch 'remove-first-run' into 'master'

Remove first-time dialogs for extension installer

The root mechanism will not be useful in 5.1 and later and has been shown to be error prone.

See merge request !330
This commit is contained in:
Daniel Martí 2016-06-09 13:00:43 +00:00
commit abb7db0bc2
4 changed files with 14 additions and 157 deletions

View File

@ -48,7 +48,6 @@ import org.fdroid.fdroid.compat.TabManager;
import org.fdroid.fdroid.compat.UriCompat;
import org.fdroid.fdroid.data.AppProvider;
import org.fdroid.fdroid.data.NewRepoConfig;
import org.fdroid.fdroid.privileged.install.InstallExtensionDialogActivity;
import org.fdroid.fdroid.views.AppListFragmentPagerAdapter;
import org.fdroid.fdroid.views.ManageReposActivity;
import org.fdroid.fdroid.views.swap.SwapWorkflowActivity;
@ -112,8 +111,6 @@ public class FDroid extends AppCompatActivity implements SearchView.OnQueryTextL
Uri uri = AppProvider.getContentUri();
getContentResolver().registerContentObserver(uri, true, new AppObserver());
InstallExtensionDialogActivity.firstTime(this);
// Re-enable once it can be disabled via a setting
// See https://gitlab.com/fdroid/fdroidclient/issues/435
//

View File

@ -66,7 +66,6 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
public static final String PREF_PROXY_HOST = "proxyHost";
public static final String PREF_PROXY_PORT = "proxyPort";
public static final String PREF_SHOW_NFC_DURING_SWAP = "showNfcDuringSwap";
public static final String PREF_FIRST_TIME = "firstTime";
public static final String PREF_POST_PRIVILEGED_INSTALL = "postPrivilegedInstall";
private static final boolean DEFAULT_ROOTED = true;
@ -84,7 +83,6 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
public static final String DEFAULT_PROXY_HOST = "127.0.0.1";
public static final int DEFAULT_PROXY_PORT = 8118;
private static final boolean DEFAULT_SHOW_NFC_DURING_SWAP = true;
private static final boolean DEFAULT_FIRST_TIME = true;
private static final boolean DEFAULT_POST_PRIVILEGED_INSTALL = false;
public enum Theme {
@ -124,14 +122,6 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
preferences.edit().putBoolean(PREF_PRIVILEGED_INSTALLER, enable).apply();
}
public boolean isFirstTime() {
return preferences.getBoolean(PREF_FIRST_TIME, DEFAULT_FIRST_TIME);
}
public void setFirstTime(boolean firstTime) {
preferences.edit().putBoolean(PREF_FIRST_TIME, firstTime).apply();
}
public boolean isPostPrivilegedInstall() {
return preferences.getBoolean(PREF_POST_PRIVILEGED_INSTALL, DEFAULT_POST_PRIVILEGED_INSTALL);
}

View File

@ -20,24 +20,18 @@
package org.fdroid.fdroid.privileged.install;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AlertDialog;
import android.text.Html;
import android.util.Log;
import android.view.ContextThemeWrapper;
import org.fdroid.fdroid.AppDetails;
import org.fdroid.fdroid.FDroid;
import org.fdroid.fdroid.FDroidApp;
import org.fdroid.fdroid.Preferences;
@ -59,7 +53,6 @@ public class InstallExtensionDialogActivity extends FragmentActivity {
public static final String ACTION_UNINSTALL = "uninstall";
public static final String ACTION_POST_INSTALL = "post_install";
public static final String ACTION_FIRST_TIME = "first_time";
private String apkPath;
@ -88,125 +81,12 @@ public class InstallExtensionDialogActivity extends FragmentActivity {
case ACTION_INSTALL:
askBeforeInstall();
break;
case ACTION_FIRST_TIME:
checkRootTask.execute();
break;
case ACTION_POST_INSTALL:
postInstall();
break;
}
}
public static void firstTime(final Context context) {
if (Preferences.get().isFirstTime()) {
Preferences.get().setFirstTime(false);
int isInstalledCorrectly = PrivilegedInstaller.isExtensionInstalledCorrectly(context);
switch (isInstalledCorrectly) {
case PrivilegedInstaller.IS_EXTENSION_INSTALLED_YES:
Preferences.get().setPrivilegedInstallerEnabled(true);
break;
case PrivilegedInstaller.IS_EXTENSION_INSTALLED_NO:
runFirstTime(context);
break;
case PrivilegedInstaller.IS_EXTENSION_INSTALLED_SIGNATURE_PROBLEM:
default:
// do nothing
}
}
}
private static void runFirstTime(final Context context) {
// don't do a "real" root access, just look up if "su" is present and has a version!
// a real check would annoy the user
AsyncTask<Void, Void, Boolean> checkRoot = new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... params) {
return Shell.SU.version(true) != null;
}
@Override
protected void onPostExecute(Boolean probablyRoot) {
super.onPostExecute(probablyRoot);
// TODO: remove false condition once the install into system
// process is stable - #294, #346, #347, #348
if (false && probablyRoot) {
// looks like we have root, at least su has a version number and is present
Intent installIntent = new Intent(context, InstallExtensionDialogActivity.class);
installIntent.setAction(InstallExtensionDialogActivity.ACTION_FIRST_TIME);
installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
context,
0,
installIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
NotificationCompat.Builder builder =
new NotificationCompat.Builder(context)
.setContentIntent(resultPendingIntent)
.setSmallIcon(R.drawable.ic_stat_notify)
.setContentTitle(context.getString(R.string.system_install_first_time_notification))
.setContentText(context.getString(R.string.system_install_first_time_notification_message_short))
.setDefaults(Notification.DEFAULT_LIGHTS)
.setAutoCancel(true)
/*
* Sets the big view "big text" style and supplies the
* text (the user's reminder message) that will be displayed
* in the detail area of the expanded notification.
* These calls are ignored by the support library for
* pre-4.1 devices.
*/
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(context.getString(R.string.system_install_first_time_notification_message)));
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(42, builder.build());
}
}
};
checkRoot.execute();
}
/**
* first time
*/
private void firstTime() {
// hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay
ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());
String message = getString(R.string.system_install_first_time_message) + "<br/><br/>"
+ getString(R.string.system_install_question);
AlertDialog.Builder builder = new AlertDialog.Builder(theme)
.setMessage(Html.fromHtml(message))
.setPositiveButton(R.string.system_install_button_open, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// Open details of F-Droid Privileged
Intent intent = new Intent(InstallExtensionDialogActivity.this, AppDetails.class);
intent.putExtra(AppDetails.EXTRA_APPID,
PrivilegedInstaller.PRIVILEGED_EXTENSION_PACKAGE_NAME);
startActivity(intent);
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
InstallExtensionDialogActivity.this.setResult(Activity.RESULT_CANCELED);
InstallExtensionDialogActivity.this.finish();
}
});
builder.create().show();
}
private void askBeforeInstall() {
// hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay
ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());
@ -288,30 +168,24 @@ public class InstallExtensionDialogActivity extends FragmentActivity {
case ACTION_INSTALL:
installTask.execute();
break;
case ACTION_FIRST_TIME:
firstTime();
break;
}
} else {
// root access denied
// hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay
ContextThemeWrapper theme = new ContextThemeWrapper(InstallExtensionDialogActivity.this,
FDroidApp.getCurThemeResId());
if (!ACTION_FIRST_TIME.equals(getIntent().getAction())) {
// hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay
ContextThemeWrapper theme = new ContextThemeWrapper(InstallExtensionDialogActivity.this,
FDroidApp.getCurThemeResId());
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(theme)
.setTitle(R.string.root_access_denied_title)
.setMessage(getString(R.string.root_access_denied_body))
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
InstallExtensionDialogActivity.this.setResult(Activity.RESULT_CANCELED);
InstallExtensionDialogActivity.this.finish();
}
});
alertBuilder.create().show();
}
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(theme)
.setTitle(R.string.root_access_denied_title)
.setMessage(getString(R.string.root_access_denied_body))
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
InstallExtensionDialogActivity.this.setResult(Activity.RESULT_CANCELED);
InstallExtensionDialogActivity.this.finish();
}
});
alertBuilder.create().show();
}
}
};

View File

@ -275,9 +275,6 @@
<string name="system_install_denied_permissions">The privileged permissions have not been granted to the extension! Please create a bug report!</string>
<string name="system_install_button_install">Install</string>
<string name="system_install_button_open">Open Extension</string>
<string name="system_install_first_time_notification">Install F-Droid Privileged Extension?</string>
<string name="system_install_first_time_notification_message_short">Touch for more information.</string>
<string name="system_install_first_time_notification_message">Touch to install F-Droid Privileged Extension, tightly coupled with the Android operating system. This allows F-Droid to install, upgrade and uninstall apps on its own.\nYou can also do this later from F-Droid\'s settings.</string>
<string name="system_install_post_success">Successfully installed F-Droid Privileged Extension</string>
<string name="system_install_post_fail">Installation of F-Droid Privileged Extension failed</string>
<string name="system_install_post_success_message">F-Droid Privileged Extension has been successfully installed. This allows F-Droid to install, upgrade and uninstall apps on its own.</string>
@ -288,7 +285,6 @@
<string name="system_install_question">Do you want to install F-Droid Privileged Extension?</string>
<string name="system_install_warning">This takes up to 10 seconds.</string>
<string name="system_install_warning_lollipop">This takes up to 10 seconds and the device will be &lt;b>rebooted&lt;/b> afterwards.</string>
<string name="system_install_first_time_message">Looks like you have root access on your device. You can now install F-Droid Privileged Extension, tightly coupled with the Android operating system. This allows F-Droid to install, upgrade and uninstall apps on its own.</string>
<string name="system_uninstall">Do you want to uninstall F-Droid Privileged Extension?</string>
<string name="system_uninstall_button">Uninstall</string>
<string name="system_install_not_supported">Installation of F-Droid Privileged Extension is currently not supported on Android 5.1 or later.</string>