Menu option added to reload cached CA certificates
[strongswan.git] / src / frontends / android / src / org / strongswan / android / ui / MainActivity.java
1 /*
2 * Copyright (C) 2012 Tobias Brunner
3 * Copyright (C) 2012 Giuliano Grassi
4 * Copyright (C) 2012 Ralf Sager
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 package org.strongswan.android.ui;
19
20 import org.strongswan.android.R;
21 import org.strongswan.android.logic.TrustedCertificateManager;
22
23 import android.app.ActionBar;
24 import android.app.Activity;
25 import android.content.Intent;
26 import android.net.VpnService;
27 import android.os.Bundle;
28 import android.view.Menu;
29 import android.view.MenuInflater;
30 import android.view.MenuItem;
31 import android.view.Window;
32
33 public class MainActivity extends Activity
34 {
35 @Override
36 public void onCreate(Bundle savedInstanceState)
37 {
38 super.onCreate(savedInstanceState);
39 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
40 setContentView(R.layout.main);
41 startVpnService();
42
43 ActionBar bar = getActionBar();
44 bar.setDisplayShowTitleEnabled(false);
45
46 /* load CA certificates in a background thread */
47 setProgressBarIndeterminateVisibility(true);
48 new Thread(new Runnable() {
49 @Override
50 public void run()
51 {
52 TrustedCertificateManager.getInstance().load();
53 runOnUiThread(new Runnable() {
54 @Override
55 public void run()
56 {
57 setProgressBarIndeterminateVisibility(false);
58 }
59 });
60 }
61 }).start();
62 }
63
64 @Override
65 public boolean onCreateOptionsMenu(Menu menu)
66 {
67 MenuInflater inflater = getMenuInflater();
68 inflater.inflate(R.menu.main, menu);
69 return true;
70 }
71
72 @Override
73 public boolean onOptionsItemSelected(MenuItem item)
74 {
75 switch (item.getItemId())
76 {
77 case R.id.menu_reload_certs:
78 setProgressBarIndeterminateVisibility(true);
79 new Thread(new Runnable() {
80 @Override
81 public void run()
82 {
83 TrustedCertificateManager.getInstance().reload();
84 runOnUiThread(new Runnable() {
85 @Override
86 public void run()
87 {
88 setProgressBarIndeterminateVisibility(false);
89 }
90 });
91 }
92 }).start();
93 return true;
94 default:
95 return super.onOptionsItemSelected(item);
96 }
97 }
98
99 protected void prepareVpnService()
100 {
101 Intent intent = VpnService.prepare(this);
102 if (intent != null)
103 {
104 startActivityForResult(intent, 0);
105 }
106 else
107 {
108 onActivityResult(0, RESULT_OK, null);
109 }
110 }
111
112 @Override
113 protected void onActivityResult(int requestCode, int resultCode, Intent data)
114 {
115 if (resultCode == RESULT_OK)
116 {
117 Intent intent = new Intent(this, CharonVpnService.class);
118 startService(intent);
119 }
120 }
121 }