* #40232: Restore security ui.

Custom File Explorer dialog has been dropped, we will delegate this action to
third party app, or to the Storage Application Framework (new in API 19).
diff --git a/src/org/sflphone/account/TLSManager.java b/src/org/sflphone/account/TLSManager.java
index 36b9b86..090cfd6 100644
--- a/src/org/sflphone/account/TLSManager.java
+++ b/src/org/sflphone/account/TLSManager.java
@@ -31,8 +31,9 @@
 
 package org.sflphone.account;
 
-import org.sflphone.fragments.FileExplorerDFragment;
-import org.sflphone.fragments.FileExplorerDFragment.onFileSelectedListener;
+import android.app.Fragment;
+import android.content.Intent;
+import org.sflphone.fragments.NestedSettingsFragment;
 import org.sflphone.model.Account;
 
 import android.app.Activity;
@@ -43,12 +44,13 @@
 import android.preference.PreferenceScreen;
 import android.util.Log;
 
-public class TLSManager implements onFileSelectedListener {
+public class TLSManager {
     PreferenceScreen mScreen;
     private Account mAccount;
-    static Activity mContext;
+    private Fragment mContext;
+    private static final String TAG =  TLSManager.class.getSimpleName();
 
-    public void onCreate(Activity con, PreferenceScreen preferenceScreen, Account acc) {
+    public void onCreate(NestedSettingsFragment con, PreferenceScreen preferenceScreen, Account acc) {
         mContext = con;
         mScreen = preferenceScreen;
         mAccount = acc;
@@ -72,12 +74,14 @@
 
                 @Override
                 public boolean onPreferenceClick(Preference preference) {
-                    if (preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE)
-                            || preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE)
-                            || preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CERTIFICATE_FILE)) {
-                        FileExplorerDFragment dialog = FileExplorerDFragment.newInstance();
-                        dialog.show(mContext.getFragmentManager(), "explorerdialog");
-                        dialog.setOnFileSelectedListener(TLSManager.this, preference.getKey());
+                    if (preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE)){
+                        performFileSearch(SELECT_CA_LIST_RC);
+                    }
+                    if(preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE)){
+                        performFileSearch(SELECT_PRIVATE_KEY_RC);
+                    }
+                    if(preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CERTIFICATE_FILE)) {
+                        performFileSearch(SELECT_CERTIFICATE_RC);
                     }
 
                     return false;
@@ -103,11 +107,37 @@
         }
     };
 
-    @Override
-    public void onFileSelected(String path, String prefKey) {
-        mScreen.findPreference(prefKey).setSummary(path);
-        mAccount.getTlsDetails().setDetailString(prefKey, path);
-        mAccount.notifyObservers();
+//    @Override
+//    public void onFileSelected(String path, String prefKey) {
+//        mScreen.findPreference(prefKey).setSummary(path);
+//        mAccount.getTlsDetails().setDetailString(prefKey, path);
+//        mAccount.notifyObservers();
+//    }
+
+    private static final int SELECT_CA_LIST_RC = 42;
+    private static final int SELECT_PRIVATE_KEY_RC = 43;
+    private static final int SELECT_CERTIFICATE_RC = 44;
+
+    public void performFileSearch(int requestCodeToSet) {
+
+        // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file
+        // browser.
+        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
+
+        // Filter to only show results that can be "opened", such as a
+        // file (as opposed to a list of contacts or timezones)
+        intent.addCategory(Intent.CATEGORY_OPENABLE);
+
+        // Filter to show only images, using the image MIME data type.
+        // If one wanted to search for ogg vorbis files, the type would be "audio/ogg".
+        // To search for all documents available via installed storage providers,
+        // it would be "*/*".
+        intent.setType("*/*");
+        mContext.startActivityForResult(intent, requestCodeToSet);
     }
 
+    public void onActivityResult(int requestCode, int resultCode, Intent data) {
+        // TODO Extract returned filed for intent and populate correct preference
+        Log.i(TAG, "file selected");
+    }
 }
\ No newline at end of file
diff --git a/src/org/sflphone/client/AccountEditionActivity.java b/src/org/sflphone/client/AccountEditionActivity.java
index e634506..2c39ba5 100644
--- a/src/org/sflphone/client/AccountEditionActivity.java
+++ b/src/org/sflphone/client/AccountEditionActivity.java
@@ -72,7 +72,6 @@
         AdvancedAccountFragment.Callbacks, SecurityAccountFragment.Callbacks, NestedSettingsFragment.Callbacks {
     private static final String TAG = AccountEditionActivity.class.getSimpleName();
 
-    public static final String KEY_MODE = "mode";
     private boolean mBound = false;
     private ISipService service;
     private Account acc_selected;
@@ -205,6 +204,11 @@
         return true;
     }
 
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        super.onActivityResult(requestCode, resultCode, data);
+    }
+
     private void processAccount() {
         try {
             service.setCredentials(acc_selected.getAccountID(), acc_selected.getCredentialsHashMapList());
@@ -215,24 +219,6 @@
 
     }
 
-    public boolean validateAccountCreation(ArrayList<String> missingValue) {
-        boolean valid = true;
-        ArrayList<String> requiredFields = new ArrayList<String>();
-        requiredFields.add(AccountDetailBasic.CONFIG_ACCOUNT_ALIAS);
-        requiredFields.add(AccountDetailBasic.CONFIG_ACCOUNT_HOSTNAME);
-        requiredFields.add(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME);
-        requiredFields.add(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD);
-        for (String s : requiredFields) {
-
-            if (acc_selected.getBasicDetails().getDetailString(s).isEmpty()) {
-                valid = false;
-                missingValue.add(s);
-            }
-        }
-
-        return valid;
-    }
-
     private AlertDialog createDeleteDialog() {
         Activity ownerActivity = this;
         AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
diff --git a/src/org/sflphone/fragments/FileExplorerDFragment.java b/src/org/sflphone/fragments/FileExplorerDFragment.java
deleted file mode 100644
index e084fe0..0000000
--- a/src/org/sflphone/fragments/FileExplorerDFragment.java
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- *  Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
- *
- *  Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *  Additional permission under GNU GPL version 3 section 7:
- *
- *  If you modify this program, or any covered work, by linking or
- *  combining it with the OpenSSL project's OpenSSL library (or a
- *  modified version of that library), containing parts covered by the
- *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
- *  grants you additional permission to convey the resulting work.
- *  Corresponding Source for a non-source form of such a combination
- *  shall include the source code for the parts of OpenSSL used as well
- *  as that of the covered work.
- */
-package org.sflphone.fragments;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Locale;
-
-import org.sflphone.R;
-
-import android.app.DialogFragment;
-import android.os.Bundle;
-import android.os.Environment;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemClickListener;
-import android.widget.ArrayAdapter;
-import android.widget.Button;
-import android.widget.ListView;
-import android.widget.TextView;
-
-public class FileExplorerDFragment extends DialogFragment implements OnItemClickListener {
-
-    private String prefKey;
-
-    public interface onFileSelectedListener {
-        public void onFileSelected(String path, String key);
-    }
-
-    public static FileExplorerDFragment newInstance() {
-        FileExplorerDFragment f = new FileExplorerDFragment();
-        return f;
-    }
-
-    private List<String> item = null;
-    private List<String> path = null;
-    private String root;
-    private TextView myPath;
-    public onFileSelectedListener mDelegateListener;
-
-    private String currentPath;
-    Comparator<? super File> comparator;
-
-    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
-        super.onCreateView(inflater, container, savedInstanceState);
-        View rootView = inflater.inflate(R.layout.file_explorer_dfrag, container);
-        myPath = (TextView) rootView.findViewById(R.id.path);
-
-        getDialog().setTitle(getResources().getString(R.string.file_explorer_title));
-
-        comparator = filecomparatorByAlphabetically;
-        root = Environment.getExternalStorageDirectory().getPath();
-        getDir(root, rootView);
-
-        Button btnAlphabetically = (Button) rootView.findViewById(R.id.button_alphabetically);
-        btnAlphabetically.setOnClickListener(new OnClickListener() {
-
-            @Override
-            public void onClick(View arg0) {
-                comparator = filecomparatorByAlphabetically;
-                getDir(currentPath, getView());
-
-            }
-        });
-
-        Button btnLastDateModified = (Button) rootView.findViewById(R.id.button_lastDateModified);
-        btnLastDateModified.setOnClickListener(new OnClickListener() {
-
-            @Override
-            public void onClick(View arg0) {
-                comparator = filecomparatorByLastModified;
-                getDir(currentPath, getView());
-
-            }
-        });
-        return rootView;
-    }
-
-    private void getDir(String dirPath, View parent) {
-        currentPath = dirPath;
-
-        myPath.setText("Location: " + dirPath);
-        item = new ArrayList<String>();
-        path = new ArrayList<String>();
-        File f = new File(dirPath);
-        File[] files = f.listFiles();
-
-        if (!dirPath.equals(root)) {
-            item.add(root);
-            path.add(root);
-            item.add("../");
-            path.add(f.getParent());
-        }
-
-        Arrays.sort(files, comparator);
-
-        for (int i = 0; i < files.length; i++) {
-            File file = files[i];
-
-            if (!file.isHidden() && file.canRead()) {
-                path.add(file.getPath());
-                if (file.isDirectory()) {
-                    item.add(file.getName() + "/");
-                } else {
-                    item.add(file.getName());
-                }
-            }
-        }
-
-        ArrayAdapter<String> fileList = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, item);
-
-        ((ListView) parent.findViewById(android.R.id.list)).setAdapter(fileList);
-        ((ListView) parent.findViewById(android.R.id.list)).setOnItemClickListener(this);
-    }
-
-    Comparator<? super File> filecomparatorByLastModified = new Comparator<File>() {
-
-        public int compare(File file1, File file2) {
-
-            if (file1.isDirectory()) {
-                if (file2.isDirectory()) {
-                    return Long.valueOf(file1.lastModified()).compareTo(file2.lastModified());
-                } else {
-                    return -1;
-                }
-            } else {
-                if (file2.isDirectory()) {
-                    return 1;
-                } else {
-                    return Long.valueOf(file1.lastModified()).compareTo(file2.lastModified());
-                }
-            }
-
-        }
-    };
-
-    Comparator<? super File> filecomparatorByAlphabetically = new Comparator<File>() {
-
-        public int compare(File file1, File file2) {
-
-            if (file1.isDirectory()) {
-                if (file2.isDirectory()) {
-                    return String.valueOf(file1.getName().toLowerCase(Locale.getDefault())).compareTo(file2.getName().toLowerCase());
-                } else {
-                    return -1;
-                }
-            } else {
-                if (file2.isDirectory()) {
-                    return 1;
-                } else {
-                    return String.valueOf(file1.getName().toLowerCase(Locale.getDefault())).compareTo(file2.getName().toLowerCase());
-                }
-            }
-
-        }
-    };
-
-    public void setOnFileSelectedListener(onFileSelectedListener listener, String key) {
-        mDelegateListener = listener;
-        prefKey = key;
-    }
-
-    @Override
-    public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
-        File file = new File(path.get(pos));
-
-
-//        if (file.isDirectory()) {
-//                selectButton.setEnabled(false);
-//                if (file.canRead()) {
-//                        lastPositions.put(currentPath, position);
-//                        getDir(path.get(position));
-//                        if (canSelectDir) {
-//                                selectedFile = file;
-//                                v.setSelected(true);
-//                                selectButton.setEnabled(true);
-//                        }
-//                } else {
-//                        new AlertDialog.Builder(this).setIcon(R.drawable.icon)
-//                                        .setTitle("[" + file.getName() + "] " + getText(R.string.cant_read_folder))
-//                                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
-//
-//                                                @Override
-//                                                public void onClick(DialogInterface dialog, int which) {
-//
-//                                                }
-//                                        }).show();
-//                }
-//        } else {
-//                selectedFile = file;
-//                v.setSelected(true);
-//                selectButton.setEnabled(true);
-//        }
-//        
-        
-        
-        
-        if (mDelegateListener != null) {
-            mDelegateListener.onFileSelected((String) ((ListView) getView().findViewById(android.R.id.list)).getAdapter().getItem(pos), prefKey);
-        }
-    }
-}
diff --git a/src/org/sflphone/fragments/NestedSettingsFragment.java b/src/org/sflphone/fragments/NestedSettingsFragment.java
index 8bfd0b9..f128d6d 100644
--- a/src/org/sflphone/fragments/NestedSettingsFragment.java
+++ b/src/org/sflphone/fragments/NestedSettingsFragment.java
@@ -31,6 +31,7 @@
 
 package org.sflphone.fragments;
 
+import android.content.Intent;
 import org.sflphone.R;
 import org.sflphone.account.CredentialsManager;
 import org.sflphone.account.SRTPManager;
@@ -55,7 +56,6 @@
 
     CredentialsManager mCredsManager;
     SRTPManager mSrtpManager;
-
     TLSManager mTlsManager;
 
     private static Callbacks sDummyCallbacks = new Callbacks() {
@@ -118,7 +118,7 @@
         case 2:
             addPreferencesFromResource(R.xml.account_tls);
             mTlsManager = new TLSManager();
-            mTlsManager.onCreate(getActivity(), getPreferenceScreen(), mCallbacks.getAccount());
+            mTlsManager.onCreate(this, getPreferenceScreen(), mCallbacks.getAccount());
             mTlsManager.setTLSListener();
             break;
         }
@@ -137,6 +137,15 @@
         return view;
     }
 
-    
+    @Override
+    public void onActivityResult(int requestCode, int resultCode, Intent data) {
+        super.onActivityResult(requestCode, resultCode, data);
+
+        if(mTlsManager != null){
+            mTlsManager.onActivityResult(requestCode, resultCode, data);
+        }
+
+    }
+
 
 }
\ No newline at end of file
diff --git a/src/org/sflphone/fragments/SecurityAccountFragment.java b/src/org/sflphone/fragments/SecurityAccountFragment.java
index d58fc94..2b22846 100644
--- a/src/org/sflphone/fragments/SecurityAccountFragment.java
+++ b/src/org/sflphone/fragments/SecurityAccountFragment.java
@@ -118,8 +118,8 @@
 
             @Override
             public boolean onPreferenceClick(Preference preference) {
-                performFileSearch();
-                //mCallbacks.displayCredentialsScreen();
+
+                mCallbacks.displayCredentialsScreen();
                 return false;
             }
         });
@@ -138,26 +138,6 @@
 
     }
 
-    private static final int READ_REQUEST_CODE = 42;
-    public void performFileSearch() {
-
-        // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file
-        // browser.
-        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
-
-        // Filter to only show results that can be "opened", such as a
-        // file (as opposed to a list of contacts or timezones)
-        intent.addCategory(Intent.CATEGORY_OPENABLE);
-
-        // Filter to show only images, using the image MIME data type.
-        // If one wanted to search for ogg vorbis files, the type would be "audio/ogg".
-        // To search for all documents available via installed storage providers,
-        // it would be "*/*".
-        intent.setType("image/*");
-
-        startActivityForResult(intent, READ_REQUEST_CODE);
-    }
-
     public void setCredentialSummary() {
         findPreference("Credential.count").setSummary("" + mCallbacks.getAccount().getCredentials().size());
     }
diff --git a/src/org/sflphone/service/CallManagerCallBack.java b/src/org/sflphone/service/CallManagerCallBack.java
index 7cc6f4a..10d2e3b 100644
--- a/src/org/sflphone/service/CallManagerCallBack.java
+++ b/src/org/sflphone/service/CallManagerCallBack.java
@@ -294,4 +294,39 @@
         mService.sendBroadcast(intent);
     }
 
+    @Override
+    public void on_secure_sdes_on(String callID) {
+        Log.i(TAG, "on_secure_sdes_on");
+    }
+
+    @Override
+    public void on_secure_sdes_off(String callID) {
+        Log.i(TAG, "on_secure_sdes_off");
+    }
+
+    @Override
+    public void on_secure_zrtp_on(String callID, String cipher) {
+        Log.i(TAG, "on_secure_zrtp_on");
+    }
+
+    @Override
+    public void on_secure_zrtp_off(String callID) {
+        Log.i(TAG, "on_secure_zrtp_off");
+    }
+
+    @Override
+    public void on_show_sas(String callID, String sas, boolean verified) {
+        Log.i(TAG, "on_show_sas");
+    }
+
+    @Override
+    public void on_zrtp_not_supported(String callID) {
+        Log.i(TAG, "on_zrtp_not_supported");
+    }
+
+    @Override
+    public void on_zrtp_negociation_failed(String callID, String reason, String severity) {
+        Log.i(TAG, "on_zrtp_negociation_failed");
+    }
+
 }