blob: e03ac5398b91d7c3af7f790f5a69ec01227cf156 [file] [log] [blame]
Alexandre Lisionc9c30b72013-11-18 16:27:26 -05001/*
Alexandre Lisionc1024c02014-01-06 11:12:53 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
Alexandre Lisionc9c30b72013-11-18 16:27:26 -05003 *
4 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Additional permission under GNU GPL version 3 section 7:
21 *
22 * If you modify this program, or any covered work, by linking or
23 * combining it with the OpenSSL project's OpenSSL library (or a
24 * modified version of that library), containing parts covered by the
25 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
26 * grants you additional permission to convey the resulting work.
27 * Corresponding Source for a non-source form of such a combination
28 * shall include the source code for the parts of OpenSSL used as well
29 * as that of the covered work.
30 */
31
Alexandre Lisiona3650992013-11-13 14:19:35 -050032package org.sflphone.fragments;
33
Alexandre Lision6a13ac02014-02-04 15:58:20 -050034import android.content.Intent;
Alexandre Lision509a7552014-03-04 13:37:50 -050035import android.os.RemoteException;
Alexandre Lisiona3650992013-11-13 14:19:35 -050036import org.sflphone.R;
Alexandre Lisiondcff8982014-07-22 14:24:20 -040037import org.sflphone.model.account.CredentialsManager;
38import org.sflphone.model.account.SRTPManager;
39import org.sflphone.model.account.TLSManager;
40import org.sflphone.model.account.Account;
Alexandre Lisiona3650992013-11-13 14:19:35 -050041
42import android.app.Activity;
43import android.os.Bundle;
Alexandre Lisiona3650992013-11-13 14:19:35 -050044import android.preference.PreferenceFragment;
Alexandre Lision3b7148e2013-11-13 17:23:06 -050045import android.view.LayoutInflater;
Alexandre Lision3cefec22013-11-14 17:26:35 -050046import android.view.Menu;
47import android.view.MenuInflater;
Alexandre Lision3b7148e2013-11-13 17:23:06 -050048import android.view.View;
49import android.view.ViewGroup;
Alexandre Lision509a7552014-03-04 13:37:50 -050050import org.sflphone.service.ISipService;
51
52import java.util.ArrayList;
Alexandre Lisiona3650992013-11-13 14:19:35 -050053
54public class NestedSettingsFragment extends PreferenceFragment {
55
Alexandre Lisionf30ff852013-12-09 17:08:40 -050056 @SuppressWarnings("unused")
Alexandre Lisiona3650992013-11-13 14:19:35 -050057 private static final String TAG = AdvancedAccountFragment.class.getSimpleName();
58
Alexandre Lisiona3650992013-11-13 14:19:35 -050059 private Callbacks mCallbacks = sDummyCallbacks;
Alexandre Lision3cefec22013-11-14 17:26:35 -050060
61 CredentialsManager mCredsManager;
Alexandre Lisionc9c30b72013-11-18 16:27:26 -050062 SRTPManager mSrtpManager;
Alexandre Lisionc9c30b72013-11-18 16:27:26 -050063 TLSManager mTlsManager;
Alexandre Lision3cefec22013-11-14 17:26:35 -050064
Alexandre Lisiona3650992013-11-13 14:19:35 -050065 private static Callbacks sDummyCallbacks = new Callbacks() {
66
67 @Override
68 public Account getAccount() {
69 return null;
70 }
71
Alexandre Lision509a7552014-03-04 13:37:50 -050072 @Override
73 public ISipService getService() {
74 return null;
75 }
76
Alexandre Lisiona3650992013-11-13 14:19:35 -050077 };
78
Alexandre Lision509a7552014-03-04 13:37:50 -050079 public String[] getTlsMethods() {
80 ArrayList<String> methods = null;
81 try {
82 methods = (ArrayList<String>) mCallbacks.getService().getTlsSupportedMethods();
83 } catch (RemoteException e) {
84 e.printStackTrace();
85 }
86 String[] results = new String[methods.size()];
87 methods.toArray(results);
88 return results;
89 }
90
Alexandre Lision1e61e302014-04-10 15:05:03 -040091 public boolean checkCertificate(String crt) {
92 try {
93 return mCallbacks.getService().checkCertificateValidity(crt);
94 } catch (RemoteException e) {
95 e.printStackTrace();
96 }
97 return false;
98 }
99
Alexandre Lision056c4942014-04-11 12:42:12 -0400100 public boolean findRSAKey(String pemPath) {
101 try {
102 return mCallbacks.getService().checkForPrivateKey(pemPath);
103 } catch (RemoteException e) {
104 e.printStackTrace();
105 }
106 return false;
107 }
108
Alexandre Lisiona3650992013-11-13 14:19:35 -0500109 public interface Callbacks {
110
111 public Account getAccount();
112
Alexandre Lision509a7552014-03-04 13:37:50 -0500113 public ISipService getService();
114
Alexandre Lisiona3650992013-11-13 14:19:35 -0500115 }
116
117 @Override
118 public void onAttach(Activity activity) {
119 super.onAttach(activity);
120 if (!(activity instanceof Callbacks)) {
121 throw new IllegalStateException("Activity must implement fragment's callbacks.");
122 }
Alexandre Lisiona3650992013-11-13 14:19:35 -0500123 mCallbacks = (Callbacks) activity;
124 }
125
126 @Override
127 public void onDetach() {
128 super.onDetach();
129 mCallbacks = sDummyCallbacks;
130 }
131
132 @Override
133 public void onCreate(Bundle savedInstanceState) {
134 super.onCreate(savedInstanceState);
135
Alexandre Lision3cefec22013-11-14 17:26:35 -0500136 setHasOptionsMenu(true);
137
Alexandre Lisiona3650992013-11-13 14:19:35 -0500138 // Load the preferences from an XML resource
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500139 switch (getArguments().getInt("MODE")) {
Alexandre Lision509a7552014-03-04 13:37:50 -0500140 case 0: // Credentials
141 addPreferencesFromResource(R.xml.account_credentials);
142 mCredsManager = new CredentialsManager();
143 mCredsManager.onCreate(getActivity(), getPreferenceScreen(), mCallbacks.getAccount());
144 mCredsManager.reloadCredentials();
145 mCredsManager.setAddCredentialListener();
146 break;
147 case 1: // SRTP
148 mSrtpManager = new SRTPManager();
149 if (mCallbacks.getAccount().hasSDESEnabled()) { // SDES
150 addPreferencesFromResource(R.xml.account_sdes);
151 mSrtpManager.onCreate(getPreferenceScreen(), mCallbacks.getAccount());
152 mSrtpManager.setSDESListener();
153 } else { // ZRTP
154 addPreferencesFromResource(R.xml.account_zrtp);
155 mSrtpManager.onCreate(getPreferenceScreen(), mCallbacks.getAccount());
156 mSrtpManager.setZRTPListener();
157 }
158 break;
159 case 2:
160 addPreferencesFromResource(R.xml.account_tls);
161 mTlsManager = new TLSManager();
162 mTlsManager.onCreate(this, getPreferenceScreen(), mCallbacks.getAccount());
163 mTlsManager.setTLSListener();
164 break;
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500165 }
166
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500167 }
168
Alexandre Lision3cefec22013-11-14 17:26:35 -0500169 @Override
170 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
171 super.onCreateOptionsMenu(menu, inflater);
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500172 }
173
174 @Override
175 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
176 View view = super.onCreateView(inflater, container, savedInstanceState);
177 view.setBackgroundColor(getResources().getColor(android.R.color.white));
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500178 return view;
Alexandre Lisiona3650992013-11-13 14:19:35 -0500179 }
180
Alexandre Lision6a13ac02014-02-04 15:58:20 -0500181 @Override
182 public void onActivityResult(int requestCode, int resultCode, Intent data) {
183 super.onActivityResult(requestCode, resultCode, data);
184
Alexandre Lision509a7552014-03-04 13:37:50 -0500185 if (mTlsManager != null) {
Alexandre Lision6a13ac02014-02-04 15:58:20 -0500186 mTlsManager.onActivityResult(requestCode, resultCode, data);
187 }
188
189 }
190
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500191
Alexandre Lisiona3650992013-11-13 14:19:35 -0500192}