Initially load CA certificates when the main Activity is created
[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.logic.TrustedCertificateManager;
21
22 import android.app.ActionBar;
23 import android.app.Activity;
24 import android.content.Intent;
25 import android.net.VpnService;
26 import android.os.Bundle;
27
28 public class MainActivity extends Activity
29 {
30 @Override
31 public void onCreate(Bundle savedInstanceState)
32 {
33 super.onCreate(savedInstanceState);
34 setContentView(R.layout.main);
35 startVpnService();
36
37 ActionBar bar = getActionBar();
38 bar.setDisplayShowTitleEnabled(false);
39
40 /* load CA certificates in a background thread */
41 new Thread(new Runnable() {
42 @Override
43 public void run()
44 {
45 TrustedCertificateManager.getInstance().load();
46 }
47 }).start();
48 }
49
50 private void startVpnService()
51 {
52 Intent intent = VpnService.prepare(this);
53 if (intent != null)
54 {
55 startActivityForResult(intent, 0);
56 }
57 else
58 {
59 onActivityResult(0, RESULT_OK, null);
60 }
61 }
62
63 @Override
64 protected void onActivityResult(int requestCode, int resultCode, Intent data)
65 {
66 if (resultCode == RESULT_OK)
67 {
68 Intent intent = new Intent(this, CharonVpnService.class);
69 startService(intent);
70 }
71 }
72 }