Added warning dialog if no root permissions, work around dialogs being shown more than once.

This commit is contained in:
Felix Ableitner 2014-07-24 16:41:25 +02:00
parent 95b26b80d4
commit 6f935dc672
2 changed files with 50 additions and 21 deletions

View file

@ -8,6 +8,8 @@ import android.widget.ListView;
import java.util.List;
import eu.chainfire.libsuperuser.Shell;
public class MainActivity extends ListActivity {
private ListView mListView;
@ -18,6 +20,10 @@ public class MainActivity extends ListActivity {
private MovedCertificatesStorage mMovedCertificatesStorage;
private AlertDialog mNoRootDialog;
private AlertDialog mMoveCertificatesDialog;
/**
* Sets up ListView showing all certificates.
*/
@ -33,6 +39,37 @@ public class MainActivity extends ListActivity {
mCertificateAdapter.onCertificateChanged();
mCertificateManager.setOnCertificateChangedListener(mCertificateAdapter);
mListView.setAdapter(mCertificateAdapter);
mMoveCertificatesDialog = new AlertDialog.Builder(this)
.setTitle(R.string.dialog_move_certs_title)
.setMessage(R.string.dialog_move_certs_message)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new Thread(new Runnable() {
@Override
public void run() {
for (Certificate c : mCertificateManager.getCertificates(false)) {
c = mCertificateManager.moveCertificateToSystem(c);
mMovedCertificatesStorage.insert(c);
}
}
}).start();
}
})
.setNegativeButton(android.R.string.no, null)
.create();
mNoRootDialog = new AlertDialog.Builder(this)
.setTitle(R.string.dialog_no_root_title)
.setMessage(R.string.dialog_no_root_message)
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.create();
}
/**
@ -42,28 +79,16 @@ public class MainActivity extends ListActivity {
protected void onResume() {
super.onResume();
// Make sure the list is updated in case of external changes.
mCertificateAdapter.onCertificateChanged();
final List<Certificate> list = mCertificateManager.getCertificates(false);
if (!list.isEmpty()) {
new AlertDialog.Builder(this)
.setTitle(R.string.dialog_move_certs_title)
.setMessage(R.string.dialog_move_certs_message)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new Thread(new Runnable() {
@Override
public void run() {
for (Certificate c : list) {
c = mCertificateManager.moveCertificateToSystem(c);
mMovedCertificatesStorage.insert(c);
}
}
}).start();
}
})
.setNegativeButton(android.R.string.no, null)
.show();
if (!Shell.SU.available()) {
mNoRootDialog.show();
return;
}
if (!mCertificateManager.getCertificates(false).isEmpty()) {
mMoveCertificatesDialog.show();
}
}
}

View file

@ -11,4 +11,8 @@
<string name="delete">Delete</string>
<string name="dialog_no_root_title">No root permissions</string>
<string name="dialog_no_root_message">This app requires root access to work. Make sure your device is rooted and try again.</string>
</resources>