[8379cd8] | 1 | /* |
---|
| 2 | Tibisay Movil |
---|
| 3 | |
---|
| 4 | Copyright (C) 2013 Antonio Araujo (aaraujo@cenditel.gob.ve), Jose Ruiz |
---|
| 5 | (jruiz@cenditel.gob.ve), Fundacion Centro Nacional de Desarrollo e |
---|
| 6 | Investigacion en Tecnologias Libres - CENDITEL. |
---|
| 7 | |
---|
| 8 | La Fundación CENDITEL concede permiso para usar, copiar, distribuir y/o |
---|
| 9 | modificar este programa, reconociendo el derecho que la humanidad posee al |
---|
| 10 | libre acceso al conocimiento, bajo los términos de la licencia de software |
---|
| 11 | GPL versión 2.0 de la Free Software Foundation. |
---|
| 12 | |
---|
| 13 | Este programa se distribuye con la esperanza de que sea util, pero SIN |
---|
| 14 | NINGUNA GARANTIA; tampoco las implicitas garantias de MERCANTILIDAD o |
---|
| 15 | ADECUACION A UN PROPOSITO PARTICULAR. |
---|
| 16 | |
---|
| 17 | Para mayor información sobre los términos de la licencia ver el archivo |
---|
| 18 | llamado "gpl-2.0.txt" en ingles. |
---|
| 19 | */ |
---|
| 20 | |
---|
[4528953] | 21 | package ve.gob.cenditel.tibisaymovil; |
---|
| 22 | |
---|
| 23 | import java.io.BufferedInputStream; |
---|
| 24 | import java.io.File; |
---|
| 25 | import java.io.FileInputStream; |
---|
| 26 | import java.io.FileNotFoundException; |
---|
| 27 | import java.io.IOException; |
---|
| 28 | import java.io.InputStream; |
---|
| 29 | import java.security.cert.Certificate; |
---|
| 30 | import java.security.cert.CertificateException; |
---|
| 31 | import java.security.cert.CertificateFactory; |
---|
| 32 | import java.security.cert.X509Certificate; |
---|
| 33 | import java.util.ArrayList; |
---|
| 34 | import java.util.HashMap; |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | import ee.sk.digidoc.DigiDocException; |
---|
| 39 | import ee.sk.digidoc.SignedDoc; |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | import android.os.Bundle; |
---|
| 44 | import android.os.Environment; |
---|
[ba6bc7c] | 45 | import android.annotation.SuppressLint; |
---|
[4528953] | 46 | import android.app.Activity; |
---|
| 47 | import android.app.AlertDialog; |
---|
| 48 | import android.content.Context; |
---|
| 49 | import android.content.DialogInterface; |
---|
| 50 | import android.content.Intent; |
---|
| 51 | import android.util.Log; |
---|
| 52 | import android.view.LayoutInflater; |
---|
| 53 | import android.view.Menu; |
---|
| 54 | import android.view.View; |
---|
| 55 | import android.view.ViewGroup; |
---|
| 56 | import android.view.Window; |
---|
| 57 | import android.view.View.OnClickListener; |
---|
| 58 | import android.widget.AdapterView; |
---|
| 59 | import android.widget.BaseAdapter; |
---|
| 60 | import android.widget.ImageView; |
---|
| 61 | import android.widget.LinearLayout; |
---|
| 62 | import android.widget.ListView; |
---|
| 63 | import android.widget.RadioButton; |
---|
| 64 | import android.widget.TextView; |
---|
| 65 | import android.widget.Toast; |
---|
| 66 | import android.widget.AdapterView.OnItemClickListener; |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | // activity para gestionar los certificados de destinatarios disponibles para cifrar |
---|
| 72 | // un archivo |
---|
| 73 | public class EncryptionCertificatesActivity extends Activity { |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | // layout del boton agregar certificado |
---|
| 77 | private LinearLayout button_add; |
---|
| 78 | |
---|
| 79 | // layout del boton eliminar certificado |
---|
| 80 | private LinearLayout button_remove; |
---|
| 81 | |
---|
| 82 | // ListView que mantiene la lista de certificados |
---|
| 83 | private ListView certificate_list; |
---|
| 84 | |
---|
| 85 | // ruta del directorio que almancena los certificados de destinatarios |
---|
| 86 | String certificatesDir; |
---|
| 87 | |
---|
| 88 | // id de certificado seleccionado |
---|
| 89 | int certificateSelectedIndex = -1; |
---|
| 90 | |
---|
| 91 | // lista de rutas absolutas de archivos de certificados |
---|
| 92 | HashMap<String, String> certificatesPathHashMap = null; |
---|
| 93 | |
---|
[fd4a5b9] | 94 | |
---|
| 95 | // intent para relanzar al momento de eliminar un certificado |
---|
| 96 | Intent starterIntent = null; |
---|
| 97 | |
---|
[4528953] | 98 | @Override |
---|
| 99 | protected void onCreate(Bundle savedInstanceState) { |
---|
| 100 | |
---|
[d5ab40f] | 101 | |
---|
[4528953] | 102 | //Estilando la barra de titulo |
---|
| 103 | final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); |
---|
| 104 | |
---|
| 105 | super.onCreate(savedInstanceState); |
---|
| 106 | setContentView(R.layout.activity_encryption_certificates); |
---|
| 107 | |
---|
| 108 | //Estilando Barra de titulo |
---|
| 109 | if(customTitleSupported) |
---|
| 110 | getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); |
---|
[d5ab40f] | 111 | |
---|
[4528953] | 112 | button_remove = (LinearLayout) this.findViewById(R.id.button_remove_certificate_zone); |
---|
| 113 | button_add = (LinearLayout) this.findViewById(R.id.button_add_certificate_zone); |
---|
| 114 | |
---|
| 115 | final TextView labelRemoveCertificate = (TextView) this.findViewById(R.id.label_certificate_to_remove); |
---|
| 116 | labelRemoveCertificate.setVisibility(View.GONE); |
---|
| 117 | |
---|
| 118 | final LinearLayout layoutCertificateToRemove = (LinearLayout) this.findViewById(R.id.layout_certificate_to_remove); |
---|
| 119 | layoutCertificateToRemove.setVisibility(View.GONE); |
---|
| 120 | |
---|
| 121 | final TextView certificateToRemove = (TextView) this.findViewById(R.id.filename_text); |
---|
| 122 | |
---|
[fd4a5b9] | 123 | starterIntent = getIntent(); |
---|
[4528953] | 124 | |
---|
| 125 | // lista de certificados |
---|
| 126 | final ArrayList<RecipientCertificate> certificates = new ArrayList<RecipientCertificate>(); |
---|
| 127 | |
---|
[d5ab40f] | 128 | // asignar ruta de certificados de destinatarios |
---|
| 129 | certificatesDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + |
---|
| 130 | getResources().getString(R.string.app_name) + "/" + |
---|
| 131 | getResources().getString(R.string.certificates_dir) + "/"; |
---|
| 132 | //Toast.makeText(getApplicationContext(), "certificatesDir: "+ certificatesDir, Toast.LENGTH_SHORT).show(); |
---|
| 133 | |
---|
[4528953] | 134 | // chequear disponibilidad de directorio de certificados |
---|
| 135 | if (!checkCertificatesDirectoryAvailability()){ |
---|
| 136 | return; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | // Leer el contenido del directorio de certificados |
---|
| 140 | // Crea un arreglo con las lista de archivos contenidos en el directorio cwd |
---|
[d5ab40f] | 141 | File f = new File(certificatesDir); |
---|
[4528953] | 142 | File[] ls = f.listFiles(); |
---|
| 143 | |
---|
| 144 | if (ls != null) { |
---|
| 145 | //Toast.makeText(getApplicationContext(), "numero de archivos: " +Integer.toString(ls.length), Toast.LENGTH_SHORT).show(); |
---|
| 146 | |
---|
| 147 | certificatesPathHashMap = new HashMap<String, String>(); |
---|
| 148 | |
---|
| 149 | String recipient = null; |
---|
| 150 | // iterar sobre todos los archivos de certificados |
---|
| 151 | // en el KeyStore |
---|
| 152 | for (File iFile : ls) { |
---|
| 153 | |
---|
| 154 | try { |
---|
| 155 | X509Certificate recvCert = SignedDoc.readCertificate(new File(iFile.getAbsolutePath())); |
---|
| 156 | |
---|
| 157 | recipient = SignedDoc.getCommonName(recvCert.getSubjectDN().getName()); |
---|
| 158 | //Toast.makeText(getApplicationContext(), "Destinatario: "+ recipient,Toast.LENGTH_SHORT).show(); |
---|
| 159 | |
---|
| 160 | certificates.add(new RecipientCertificate(recipient)); |
---|
| 161 | |
---|
| 162 | certificatesPathHashMap.put(recipient, iFile.getAbsolutePath()); |
---|
| 163 | |
---|
| 164 | } catch (DigiDocException e) { |
---|
| 165 | Toast.makeText(getApplicationContext(), "DigiDocException: "+ e.getMessage(), Toast.LENGTH_SHORT).show(); |
---|
| 166 | } |
---|
| 167 | }// fin de la iteracion sobre iFile |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | // se crea el adaptador para mostrar los certificados de destinatarios |
---|
| 174 | final RecipientCertificateAdapter certificateAdapter = new RecipientCertificateAdapter(EncryptionCertificatesActivity.this, certificates); |
---|
| 175 | final ListView certificateListView = (ListView) findViewById(R.id.certificate_list); |
---|
| 176 | certificateListView.setAdapter(certificateAdapter); |
---|
| 177 | certificateListView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { |
---|
| 178 | @Override |
---|
| 179 | public void onItemClick(AdapterView<?> parent, View view, |
---|
| 180 | int position, long id) { |
---|
| 181 | |
---|
| 182 | Object o = certificateListView.getItemAtPosition(position); |
---|
| 183 | RecipientCertificate c = (RecipientCertificate) o; |
---|
| 184 | |
---|
| 185 | certificateSelectedIndex = position; |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | labelRemoveCertificate.setVisibility(View.VISIBLE); |
---|
| 189 | layoutCertificateToRemove.setVisibility(View.VISIBLE); |
---|
| 190 | |
---|
| 191 | certificateToRemove.setText(c.getName()); |
---|
[d5ab40f] | 192 | |
---|
| 193 | //Toast.makeText(getApplicationContext(), "click sobre certificado"+ c.getName(), Toast.LENGTH_SHORT).show(); |
---|
[4528953] | 194 | |
---|
| 195 | } |
---|
| 196 | }); |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | |
---|
| 200 | |
---|
| 201 | // habilita el click sobre la acción para agregar un certificado nuevo |
---|
| 202 | button_add.setOnClickListener(new OnClickListener() |
---|
| 203 | { |
---|
| 204 | public void onClick(View v) |
---|
| 205 | { |
---|
| 206 | |
---|
| 207 | //Intent oIntent = new Intent(BDOCVerifyResultActivity.this, TibisayMovilActivity.class); |
---|
| 208 | //oIntent.setAction(Intent.ACTION_VIEW); |
---|
| 209 | //oIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
---|
| 210 | //startActivity(oIntent); |
---|
| 211 | |
---|
| 212 | //finish(); |
---|
[ba6bc7c] | 213 | //Toast.makeText(getApplicationContext(), "Se debe agregar un certificado", Toast.LENGTH_SHORT).show(); |
---|
[d5ab40f] | 214 | |
---|
| 215 | // llamar a función para cargar certificado |
---|
| 216 | loadNewCertificate(); |
---|
| 217 | |
---|
[4528953] | 218 | } |
---|
| 219 | }); |
---|
| 220 | |
---|
| 221 | // habilita el click sobre la acción eliminar el certificado seleccionado |
---|
| 222 | button_remove.setOnClickListener(new OnClickListener() |
---|
| 223 | { |
---|
| 224 | public void onClick(View v) |
---|
| 225 | { |
---|
| 226 | //shareIt(); |
---|
| 227 | |
---|
[ba6bc7c] | 228 | //Toast.makeText(getApplicationContext(), "eliminar un certificado", Toast.LENGTH_SHORT).show(); |
---|
[4528953] | 229 | |
---|
| 230 | if (certificateSelectedIndex == -1){ |
---|
| 231 | // 1. Instantiate an AlertDialog.Builder with its constructor |
---|
| 232 | AlertDialog.Builder builder = new AlertDialog.Builder(EncryptionCertificatesActivity.this); |
---|
| 233 | |
---|
| 234 | // 2. Chain together various setter methods to set the dialog characteristics |
---|
| 235 | builder.setMessage("Debe seleccionar un certificado para eliminarlo.") |
---|
| 236 | .setTitle("Información:"); |
---|
| 237 | |
---|
| 238 | builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { |
---|
| 239 | public void onClick(DialogInterface dialog, int id) { |
---|
| 240 | // User clicked OK button |
---|
[ba6bc7c] | 241 | //Toast.makeText(getApplicationContext(), "User clicked OK button", Toast.LENGTH_LONG).show(); |
---|
[4528953] | 242 | } |
---|
| 243 | }); |
---|
| 244 | |
---|
| 245 | // 3. Get the AlertDialog from create() |
---|
| 246 | AlertDialog dialog = builder.create(); |
---|
| 247 | dialog.show(); |
---|
| 248 | }else{ |
---|
| 249 | // 1. Instantiate an AlertDialog.Builder with its constructor |
---|
| 250 | AlertDialog.Builder builder = new AlertDialog.Builder(EncryptionCertificatesActivity.this); |
---|
| 251 | |
---|
| 252 | // 2. Chain together various setter methods to set the dialog characteristics |
---|
| 253 | builder.setMessage("¿Está seguro de eliminar el certificado?.") |
---|
| 254 | .setTitle("Información:"); |
---|
| 255 | |
---|
| 256 | builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { |
---|
[ba6bc7c] | 257 | @SuppressLint("NewApi") |
---|
| 258 | public void onClick(DialogInterface dialog, int id) { |
---|
[4528953] | 259 | // User clicked OK button |
---|
[ba6bc7c] | 260 | //Toast.makeText(getApplicationContext(), "User clicked OK button", Toast.LENGTH_LONG).show(); |
---|
[4528953] | 261 | |
---|
| 262 | // funcion para eliminar el certificado |
---|
| 263 | // ... |
---|
| 264 | String pathToErase = certificatesPathHashMap.get(certificateToRemove.getText()); |
---|
| 265 | |
---|
| 266 | File file = new File(pathToErase); |
---|
| 267 | boolean deleted = file.delete(); |
---|
[fd4a5b9] | 268 | |
---|
[4528953] | 269 | //actualizar la lista de certificados en ListView |
---|
| 270 | certificateAdapter.notifyDataSetChanged(); |
---|
| 271 | |
---|
[fd4a5b9] | 272 | labelRemoveCertificate.setVisibility(View.GONE); |
---|
| 273 | layoutCertificateToRemove.setVisibility(View.GONE); |
---|
| 274 | |
---|
| 275 | // la funcion recreate esta disponible a partir del api 11 |
---|
| 276 | if (android.os.Build.VERSION.SDK_INT >= 11) |
---|
| 277 | { |
---|
| 278 | EncryptionCertificatesActivity.this.recreate(); |
---|
| 279 | } |
---|
| 280 | else |
---|
| 281 | { |
---|
| 282 | startActivity(starterIntent); |
---|
| 283 | finish(); |
---|
| 284 | } |
---|
[4528953] | 285 | |
---|
[ba6bc7c] | 286 | //Toast.makeText(getApplicationContext(), "**archivo a borrar: "+pathToErase, Toast.LENGTH_LONG).show(); |
---|
[4528953] | 287 | |
---|
| 288 | |
---|
[fd4a5b9] | 289 | |
---|
[4528953] | 290 | } |
---|
| 291 | }); |
---|
| 292 | |
---|
| 293 | builder.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() { |
---|
| 294 | public void onClick(DialogInterface dialog, int id) { |
---|
| 295 | // User cancelled the dialog |
---|
[ba6bc7c] | 296 | //Toast.makeText(getApplicationContext(), "User clicked Cancel button", Toast.LENGTH_LONG).show(); |
---|
[4528953] | 297 | |
---|
| 298 | labelRemoveCertificate.setVisibility(View.GONE); |
---|
| 299 | layoutCertificateToRemove.setVisibility(View.GONE); |
---|
| 300 | } |
---|
| 301 | }); |
---|
| 302 | // 3. Get the AlertDialog from create() |
---|
| 303 | AlertDialog dialog = builder.create(); |
---|
| 304 | dialog.show(); |
---|
| 305 | } |
---|
| 306 | } |
---|
| 307 | }); |
---|
| 308 | |
---|
| 309 | |
---|
| 310 | |
---|
| 311 | } // fin de funcion onCreate() |
---|
| 312 | |
---|
| 313 | @Override |
---|
| 314 | public boolean onCreateOptionsMenu(Menu menu) { |
---|
| 315 | // Inflate the menu; this adds items to the action bar if it is present. |
---|
| 316 | getMenuInflater().inflate(R.menu.encryption_certificates, menu); |
---|
| 317 | return true; |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | |
---|
[d5ab40f] | 321 | /** |
---|
| 322 | * Carga un nuevo certificado al lanzar CertificateToLoadActivity. |
---|
| 323 | * @return void |
---|
| 324 | */ |
---|
| 325 | public void loadNewCertificate() { |
---|
| 326 | Intent intent = new Intent(this, CertificateToLoadActivity.class); |
---|
| 327 | startActivity(intent); |
---|
| 328 | finish(); |
---|
| 329 | |
---|
| 330 | } |
---|
| 331 | |
---|
[4528953] | 332 | |
---|
| 333 | // clase que abstrae un certificado de destinatario |
---|
| 334 | // se utiliza para mostrar en la interfaz grafica cada certificado |
---|
| 335 | // de destinatario almancenado por la aplicacion |
---|
| 336 | public class RecipientCertificate { |
---|
| 337 | private String mName; |
---|
| 338 | |
---|
| 339 | public RecipientCertificate(String name){ |
---|
| 340 | mName = name; |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | public void setName(String name) { |
---|
| 344 | this.mName = name; |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | public String getName() { |
---|
| 348 | return mName; |
---|
| 349 | } |
---|
| 350 | } // fin de clase RecipientCertificate |
---|
| 351 | |
---|
| 352 | // clase que abstrae el adaptador para llenar el ListView de documentos que |
---|
| 353 | // se encuentran dentro del contenedor BDOC |
---|
| 354 | private class RecipientCertificateAdapter extends BaseAdapter { |
---|
| 355 | |
---|
| 356 | private ArrayList<RecipientCertificate> mRecipientCertificateList; |
---|
| 357 | private LayoutInflater lInflater; |
---|
| 358 | |
---|
| 359 | private RecipientCertificateAdapter(Context context, ArrayList<RecipientCertificate> certificates) { |
---|
| 360 | this.lInflater = LayoutInflater.from(context); |
---|
| 361 | this.mRecipientCertificateList = certificates; |
---|
| 362 | |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | |
---|
| 366 | @Override |
---|
| 367 | public int getCount() { |
---|
| 368 | return mRecipientCertificateList.size(); |
---|
| 369 | } |
---|
| 370 | |
---|
| 371 | @Override |
---|
| 372 | public Object getItem(int position) { |
---|
| 373 | return mRecipientCertificateList.get(position); |
---|
| 374 | } |
---|
| 375 | |
---|
| 376 | @Override |
---|
| 377 | public long getItemId(int position) { |
---|
| 378 | return position; |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | @Override |
---|
| 382 | public View getView(int position, View convertView, ViewGroup parent) { |
---|
| 383 | ViewHolder container = null; |
---|
| 384 | |
---|
| 385 | if (convertView == null){ |
---|
| 386 | container = new ViewHolder(); |
---|
| 387 | convertView = lInflater.inflate(R.layout.recipient_certificate_info, null); |
---|
| 388 | |
---|
| 389 | container.filename_text = (TextView) convertView.findViewById(R.id.filename_text); |
---|
| 390 | //container.filename_modified = (TextView) convertView.findViewById(R.id.filename_modified); |
---|
| 391 | container.type_image = (ImageView) convertView.findViewById(R.id.type_image); |
---|
| 392 | convertView.setTag(container); |
---|
| 393 | }else{ |
---|
| 394 | container = (ViewHolder) convertView.getTag(); |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | RecipientCertificate certificate = (RecipientCertificate) getItem(position); |
---|
| 398 | container.filename_text.setText(certificate.getName()); |
---|
| 399 | //container.filename_modified.setText(certificate.getName()); |
---|
| 400 | container.type_image.setImageResource(R.drawable.ic_archivo); |
---|
| 401 | |
---|
| 402 | return convertView; |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | |
---|
| 406 | class ViewHolder{ |
---|
| 407 | TextView filename_text; |
---|
| 408 | //TextView filename_modified; |
---|
| 409 | ImageView type_image; |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | } // fin de la clase RecipientCertificateAdapter |
---|
| 413 | |
---|
| 414 | |
---|
| 415 | |
---|
| 416 | |
---|
| 417 | /** |
---|
| 418 | * Prepara directorio |
---|
| 419 | * @return boolean |
---|
| 420 | */ |
---|
| 421 | boolean prepareDirectory(String dir) |
---|
| 422 | { |
---|
| 423 | try |
---|
| 424 | { |
---|
| 425 | if (makedirs(dir)) |
---|
| 426 | { |
---|
| 427 | return true; |
---|
| 428 | } else { |
---|
| 429 | return false; |
---|
| 430 | } |
---|
| 431 | } catch (Exception e) |
---|
| 432 | { |
---|
| 433 | e.printStackTrace(); |
---|
[ba6bc7c] | 434 | //Toast.makeText(this, "Could not initiate File System.. Is Sdcard mounted properly?", Toast.LENGTH_LONG).show(); |
---|
| 435 | Toast.makeText(this, "No se pudo iniciar el sistema de archivos. ¿Está la SDCARD montada?", Toast.LENGTH_LONG).show(); |
---|
[4528953] | 436 | return false; |
---|
| 437 | } |
---|
| 438 | } |
---|
| 439 | |
---|
| 440 | /** |
---|
| 441 | * Crea directorio utilizando la variable tmpDir |
---|
| 442 | * @return boolean |
---|
| 443 | */ |
---|
| 444 | private boolean makedirs(String dir) |
---|
| 445 | { |
---|
| 446 | //File tempdir = new File(extractedDirFiles); |
---|
| 447 | File tempdir = new File(dir); |
---|
| 448 | if (!tempdir.exists()) |
---|
| 449 | tempdir.mkdirs(); |
---|
| 450 | return (tempdir.isDirectory()); |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | /** |
---|
| 454 | * Chequea la disponibilidad del directorio de /TibisayMovil/CertificatesToEncrypt |
---|
| 455 | * @return boolean |
---|
| 456 | */ |
---|
| 457 | private boolean checkCertificatesDirectoryAvailability() { |
---|
| 458 | // verificar acceso al directorio /mnt/sdcard/TibisayMovil/CertificatesToEncrypt |
---|
| 459 | boolean mExternalStorageAvailable = false; |
---|
| 460 | boolean mExternalStorageWriteable = false; |
---|
| 461 | String state = Environment.getExternalStorageState(); |
---|
| 462 | |
---|
| 463 | AlertDialog.Builder builder = new AlertDialog.Builder(EncryptionCertificatesActivity.this); |
---|
| 464 | |
---|
| 465 | |
---|
| 466 | if (Environment.MEDIA_MOUNTED.equals(state)) { |
---|
| 467 | // We can read and write the media |
---|
| 468 | mExternalStorageAvailable = mExternalStorageWriteable = true; |
---|
[ba6bc7c] | 469 | //Toast.makeText(getApplicationContext(), "We can read and write the media", Toast.LENGTH_SHORT).show(); |
---|
[4528953] | 470 | |
---|
| 471 | // Crear directorio CertificatesToEncrypt donde se almacenan los certificados de |
---|
| 472 | // destinatarios para cifrado |
---|
[d5ab40f] | 473 | /* |
---|
| 474 | String certificatesDir = Environment.getExternalStorageDirectory() + "/" + |
---|
[4528953] | 475 | getResources().getString(R.string.app_name) + "/" + |
---|
[d5ab40f] | 476 | getResources().getString(R.string.certificates_dir) + "/"; |
---|
| 477 | */ |
---|
[4528953] | 478 | if (prepareDirectory(certificatesDir)){ |
---|
| 479 | return true; |
---|
| 480 | }else{ |
---|
| 481 | builder.setMessage("No existe el directorio "+certificatesDir+" para almacenar certificados.").setTitle("Error:"); |
---|
| 482 | |
---|
| 483 | } |
---|
| 484 | |
---|
| 485 | } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { |
---|
| 486 | // We can only read the media |
---|
| 487 | mExternalStorageAvailable = true; |
---|
| 488 | mExternalStorageWriteable = false; |
---|
[ba6bc7c] | 489 | //Toast.makeText(getApplicationContext(), "We can only read the media", Toast.LENGTH_SHORT).show(); |
---|
[4528953] | 490 | |
---|
| 491 | builder.setMessage("Directorio "+certificatesDir+ " montado de solo lectura. No se pueden almancenar certificados.").setTitle("Error:"); |
---|
| 492 | |
---|
| 493 | |
---|
| 494 | } else { |
---|
| 495 | // Something else is wrong. It may be one of many other states, but all we need |
---|
| 496 | // to know is we can neither read nor write |
---|
| 497 | mExternalStorageAvailable = mExternalStorageWriteable = false; |
---|
[ba6bc7c] | 498 | //Toast.makeText(getApplicationContext(), "we can neither read nor write", Toast.LENGTH_SHORT).show(); |
---|
[4528953] | 499 | |
---|
| 500 | builder.setMessage("Directorio "+certificatesDir+ " no está disponible. No se pueden almancenar certificados.").setTitle("Error:"); |
---|
| 501 | |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | |
---|
| 505 | builder.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() { |
---|
| 506 | public void onClick(DialogInterface dialog, int id) { |
---|
| 507 | // User cancelled the dialog |
---|
| 508 | EncryptionCertificatesActivity.this.finish(); |
---|
| 509 | } |
---|
| 510 | }); |
---|
| 511 | AlertDialog dialog = builder.create(); |
---|
| 512 | dialog.show(); |
---|
| 513 | return false; |
---|
| 514 | } |
---|
| 515 | |
---|
| 516 | |
---|
| 517 | |
---|
| 518 | |
---|
| 519 | } // fin de la activity |
---|