android: Reload CA certificates without AsyncTask
We already use loaders in the GUI that can handle this asynchronously.
This commit is contained in:
+12
@@ -123,6 +123,18 @@ public class TrustedCertificateListFragment extends ListFragment implements Load
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the loader of this list fragment
|
||||||
|
*/
|
||||||
|
public void reset()
|
||||||
|
{
|
||||||
|
if (isResumed())
|
||||||
|
{
|
||||||
|
setListShown(false);
|
||||||
|
}
|
||||||
|
getLoaderManager().restartLoader(0, null, this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Loader<List<TrustedCertificateEntry>> onCreateLoader(int id, Bundle args)
|
public Loader<List<TrustedCertificateEntry>> onCreateLoader(int id, Bundle args)
|
||||||
{ /* we don't need the id as we have only one loader */
|
{ /* we don't need the id as we have only one loader */
|
||||||
|
|||||||
+27
-26
@@ -27,11 +27,9 @@ import android.app.Activity;
|
|||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.Window;
|
|
||||||
|
|
||||||
public class TrustedCertificatesActivity extends Activity implements TrustedCertificateListFragment.OnTrustedCertificateSelectedListener
|
public class TrustedCertificatesActivity extends Activity implements TrustedCertificateListFragment.OnTrustedCertificateSelectedListener
|
||||||
{
|
{
|
||||||
@@ -42,25 +40,31 @@ public class TrustedCertificatesActivity extends Activity implements TrustedCert
|
|||||||
public void onCreate(Bundle savedInstanceState)
|
public void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
|
||||||
setContentView(R.layout.trusted_certificates_activity);
|
setContentView(R.layout.trusted_certificates_activity);
|
||||||
|
|
||||||
ActionBar actionBar = getActionBar();
|
ActionBar actionBar = getActionBar();
|
||||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||||
|
|
||||||
|
TrustedCertificatesTabListener listener;
|
||||||
|
listener = new TrustedCertificatesTabListener(this, "system", TrustedCertificateSource.SYSTEM);
|
||||||
actionBar.addTab(actionBar
|
actionBar.addTab(actionBar
|
||||||
.newTab()
|
.newTab()
|
||||||
.setText(R.string.system_tab)
|
.setText(R.string.system_tab)
|
||||||
.setTabListener(new TrustedCertificatesTabListener(this, "system", TrustedCertificateSource.SYSTEM)));
|
.setTag(listener)
|
||||||
|
.setTabListener(listener));
|
||||||
|
listener = new TrustedCertificatesTabListener(this, "user", TrustedCertificateSource.USER);
|
||||||
actionBar.addTab(actionBar
|
actionBar.addTab(actionBar
|
||||||
.newTab()
|
.newTab()
|
||||||
.setText(R.string.user_tab)
|
.setText(R.string.user_tab)
|
||||||
.setTabListener(new TrustedCertificatesTabListener(this, "user", TrustedCertificateSource.USER)));
|
.setTag(listener)
|
||||||
|
.setTabListener(listener));
|
||||||
|
listener = new TrustedCertificatesTabListener(this, "local", TrustedCertificateSource.LOCAL);
|
||||||
actionBar.addTab(actionBar
|
actionBar.addTab(actionBar
|
||||||
.newTab()
|
.newTab()
|
||||||
.setText(R.string.local_tab)
|
.setText(R.string.local_tab)
|
||||||
.setTabListener(new TrustedCertificatesTabListener(this, "local", TrustedCertificateSource.LOCAL)));
|
.setTag(listener)
|
||||||
|
.setTabListener(listener));
|
||||||
|
|
||||||
if (savedInstanceState != null)
|
if (savedInstanceState != null)
|
||||||
{
|
{
|
||||||
@@ -92,7 +96,7 @@ public class TrustedCertificatesActivity extends Activity implements TrustedCert
|
|||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_reload_certs:
|
case R.id.menu_reload_certs:
|
||||||
new ReloadCertificatesTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
reloadCertificates();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
@@ -111,6 +115,17 @@ public class TrustedCertificatesActivity extends Activity implements TrustedCert
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void reloadCertificates()
|
||||||
|
{
|
||||||
|
TrustedCertificateManager.getInstance().reset();
|
||||||
|
for (int i = 0; i < getActionBar().getTabCount(); i++)
|
||||||
|
{
|
||||||
|
Tab tab = getActionBar().getTabAt(i);
|
||||||
|
TrustedCertificatesTabListener listener = (TrustedCertificatesTabListener)tab.getTag();
|
||||||
|
listener.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class TrustedCertificatesTabListener implements ActionBar.TabListener
|
public static class TrustedCertificatesTabListener implements ActionBar.TabListener
|
||||||
{
|
{
|
||||||
private final String mTag;
|
private final String mTag;
|
||||||
@@ -164,27 +179,13 @@ public class TrustedCertificatesActivity extends Activity implements TrustedCert
|
|||||||
{
|
{
|
||||||
/* nothing to be done */
|
/* nothing to be done */
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public void reset()
|
||||||
* Class that reloads the cached CA certificates.
|
|
||||||
*/
|
|
||||||
private class ReloadCertificatesTask extends AsyncTask<Void, Void, TrustedCertificateManager>
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
protected void onPreExecute()
|
|
||||||
{
|
{
|
||||||
setProgressBarIndeterminateVisibility(true);
|
if (mFragment != null)
|
||||||
}
|
{
|
||||||
@Override
|
((TrustedCertificateListFragment)mFragment).reset();
|
||||||
protected TrustedCertificateManager doInBackground(Void... params)
|
}
|
||||||
{
|
|
||||||
return TrustedCertificateManager.getInstance().reset().load();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(TrustedCertificateManager result)
|
|
||||||
{
|
|
||||||
setProgressBarIndeterminateVisibility(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user