Fixed crash when rapidly moving multiple certificates using list buttons.
This commit is contained in:
parent
200fefe9c3
commit
2ccda3cb3f
2 changed files with 29 additions and 5 deletions
|
@ -4,9 +4,11 @@ import android.test.AndroidTestCase;
|
|||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.nutomic.zertman.Certificate;
|
||||
import com.nutomic.zertman.CertificateManager;
|
||||
import com.nutomic.zertman.test.R;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataInputStream;
|
||||
|
@ -132,6 +134,23 @@ public class CertificateManagerTest extends AndroidTestCase {
|
|||
assertReadOnly();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testGetDescription() {
|
||||
Certificate cert = copyCertificate(false);
|
||||
Pair<String, String> desc = CertificateManager.getDescription(cert);
|
||||
assertFalse(desc.first.isEmpty());
|
||||
assertNotSame(desc.first, desc.second);
|
||||
mCertificateManager.deleteCertificate(cert);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testGetDescriptionNonExistant() {
|
||||
Pair<String, String> desc =
|
||||
CertificateManager.getDescription(new Certificate("does-not-exist", false));
|
||||
assertNotNull(desc);
|
||||
assertFalse(desc.first.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that /system is properly remounted as read only.
|
||||
*/
|
||||
|
|
|
@ -13,8 +13,10 @@ import java.security.cert.CertificateException;
|
|||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import eu.chainfire.libsuperuser.Shell;
|
||||
|
||||
|
@ -44,7 +46,8 @@ public class CertificateManager {
|
|||
/**
|
||||
* Contains all certificates that are currently being moved from user to system storage.
|
||||
*/
|
||||
private LinkedList<Certificate> mCurrentlyMoving = new LinkedList<Certificate>();
|
||||
private Set<Certificate> mCurrentlyMoving =
|
||||
Collections.newSetFromMap(new ConcurrentHashMap<Certificate, Boolean>());
|
||||
|
||||
private OnCertificateChangedListener mOnCertificateChangedListener;
|
||||
|
||||
|
@ -143,12 +146,14 @@ public class CertificateManager {
|
|||
is = new BufferedInputStream(new FileInputStream(cert.getFile()));
|
||||
cert2 = (X509Certificate) factory.generateCertificate(is);
|
||||
} catch (IOException | CertificateException e) {
|
||||
return null;
|
||||
Log.w(TAG, "Failed to read certificate description");
|
||||
return new Pair<>(cert.getFile().getName(), "");
|
||||
} finally {
|
||||
try {
|
||||
// TODO: crash here
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
Log.w(TAG, "Failed to close stream", e);
|
||||
}
|
||||
|
|
Reference in a new issue