Program: 8354
Project: 8354
Buggy source:
/** 
 * The IntentService calls this method from the default worker thread with the intent that started the service. When this method returns, IntentService stops the service, as appropriate.
 */
@Override protected void onHandleIntent(Intent intent){
  mActionCanceled.set(false);
  Bundle extras=intent.getExtras();
  if (extras == null) {
    Log.e(Constants.TAG,"String_Node_Str");
    return;
  }
  if (!(extras.containsKey(EXTRA_MESSENGER) || extras.containsKey(EXTRA_DATA) || (intent.getAction() == null))) {
    Log.e(Constants.TAG,"String_Node_Str");
    return;
  }
  Uri dataUri=intent.getData();
  mMessenger=(Messenger)extras.get(EXTRA_MESSENGER);
  Bundle data=extras.getBundle(EXTRA_DATA);
  if (data == null) {
    Log.e(Constants.TAG,"String_Node_Str");
    return;
  }
  OtherHelper.logDebugBundle(data,"String_Node_Str");
  String action=intent.getAction();
  if (ACTION_ENCRYPT_SIGN.equals(action)) {
    try {
      int source=data.get(SOURCE) != null ? data.getInt(SOURCE) : data.getInt(TARGET);
      Bundle resultData=new Bundle();
      long sigMasterKeyId=data.getLong(ENCRYPT_SIGNATURE_MASTER_ID);
      String symmetricPassphrase=data.getString(ENCRYPT_SYMMETRIC_PASSPHRASE);
      boolean useAsciiArmor=data.getBoolean(ENCRYPT_USE_ASCII_ARMOR);
      long encryptionKeyIds[]=data.getLongArray(ENCRYPT_ENCRYPTION_KEYS_IDS);
      int compressionId=data.getInt(ENCRYPT_COMPRESSION_ID);
      int urisCount=data.containsKey(ENCRYPT_INPUT_URIS) ? data.getParcelableArrayList(ENCRYPT_INPUT_URIS).size() : 1;
      for (int i=0; i < urisCount; i++) {
        data.putInt(SELECTED_URI,i);
        InputData inputData=createEncryptInputData(data);
        OutputStream outStream=createCryptOutputStream(data);
        String originalFilename=getOriginalFilename(data);
        PgpSignEncrypt.Builder builder=new PgpSignEncrypt.Builder(new ProviderHelper(this),inputData,outStream);
        builder.setProgressable(this).setEnableAsciiArmorOutput(useAsciiArmor).setVersionHeader(PgpHelper.getVersionForHeader(this)).setCompressionId(compressionId).setSymmetricEncryptionAlgorithm(Preferences.getPreferences(this).getDefaultEncryptionAlgorithm()).setEncryptionMasterKeyIds(encryptionKeyIds).setSymmetricPassphrase(symmetricPassphrase).setOriginalFilename(originalFilename);
        try {
          CachedPublicKeyRing signingRing=new ProviderHelper(this).getCachedPublicKeyRing(sigMasterKeyId);
          long sigSubKeyId=signingRing.getSignId();
          String passphrase=PassphraseCacheService.getCachedPassphrase(this,sigSubKeyId);
          builder.setSignatureMasterKeyId(sigMasterKeyId).setSignatureSubKeyId(sigSubKeyId).setSignaturePassphrase(passphrase).setSignatureHashAlgorithm(Preferences.getPreferences(this).getDefaultHashAlgorithm()).setAdditionalEncryptId(sigMasterKeyId);
        }
 catch (        PgpGeneralException e) {
        }
        if (source == IO_BYTES) {
          builder.setCleartextInput(true);
        }
        builder.build().execute();
        outStream.close();
        finalizeEncryptOutputStream(data,resultData,outStream);
      }
      OtherHelper.logDebugBundle(resultData,"String_Node_Str");
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,resultData);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_DECRYPT_VERIFY.equals(action)) {
    try {
      String passphrase=data.getString(DECRYPT_PASSPHRASE);
      InputData inputData=createDecryptInputData(data);
      OutputStream outStream=createCryptOutputStream(data);
      Bundle resultData=new Bundle();
      PgpDecryptVerify.Builder builder=new PgpDecryptVerify.Builder(new ProviderHelper(this),new PgpDecryptVerify.PassphraseCache(){
        @Override public String getCachedPassphrase(        long masterKeyId){
          try {
            return PassphraseCacheService.getCachedPassphrase(KeychainIntentService.this,masterKeyId);
          }
 catch (          PassphraseCacheService.KeyNotFoundException e) {
            return null;
          }
        }
      }
,inputData,outStream);
      builder.setProgressable(this).setAllowSymmetricDecryption(true).setPassphrase(passphrase);
      DecryptVerifyResult decryptVerifyResult=builder.build().execute();
      outStream.close();
      resultData.putParcelable(RESULT_DECRYPT_VERIFY_RESULT,decryptVerifyResult);
      finalizeDecryptOutputStream(data,resultData,outStream);
      OtherHelper.logDebugBundle(resultData,"String_Node_Str");
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,resultData);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_DECRYPT_METADATA.equals(action)) {
    try {
      String passphrase=data.getString(DECRYPT_PASSPHRASE);
      InputData inputData=createDecryptInputData(data);
      Bundle resultData=new Bundle();
      PgpDecryptVerify.Builder builder=new PgpDecryptVerify.Builder(new ProviderHelper(this),new PgpDecryptVerify.PassphraseCache(){
        @Override public String getCachedPassphrase(        long masterKeyId) throws PgpDecryptVerify.NoSecretKeyException {
          try {
            return PassphraseCacheService.getCachedPassphrase(KeychainIntentService.this,masterKeyId);
          }
 catch (          PassphraseCacheService.KeyNotFoundException e) {
            throw new PgpDecryptVerify.NoSecretKeyException();
          }
        }
      }
,inputData,null);
      builder.setProgressable(this).setAllowSymmetricDecryption(true).setPassphrase(passphrase).setDecryptMetadataOnly(true);
      DecryptVerifyResult decryptVerifyResult=builder.build().execute();
      resultData.putParcelable(RESULT_DECRYPT_VERIFY_RESULT,decryptVerifyResult);
      OtherHelper.logDebugBundle(resultData,"String_Node_Str");
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,resultData);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_EDIT_KEYRING.equals(action)) {
    try {
      SaveKeyringParcel saveParcel=data.getParcelable(EDIT_KEYRING_PARCEL);
      if (saveParcel == null) {
        Log.e(Constants.TAG,"String_Node_Str");
        return;
      }
      PgpKeyOperation keyOperations=new PgpKeyOperation(new ProgressScaler(this,10,60,100),mActionCanceled);
      EditKeyResult modifyResult;
      if (saveParcel.mMasterKeyId != null) {
        String passphrase=data.getString(EDIT_KEYRING_PASSPHRASE);
        CanonicalizedSecretKeyRing secRing=new ProviderHelper(this).getCanonicalizedSecretKeyRing(saveParcel.mMasterKeyId);
        modifyResult=keyOperations.modifySecretKeyRing(secRing,saveParcel,passphrase);
      }
 else {
        modifyResult=keyOperations.createSecretKeyRing(saveParcel);
      }
      if (!modifyResult.success()) {
        SaveKeyringResult saveResult=new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR,modifyResult.getLog(),null);
        sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,saveResult);
        return;
      }
      UncachedKeyRing ring=modifyResult.getRing();
      if (mActionCanceled.get()) {
        OperationLog log=modifyResult.getLog();
        if (!modifyResult.cancelled()) {
          log.add(LogLevel.CANCELLED,LogType.MSG_OPERATION_CANCELLED,0);
        }
        SaveKeyringResult saveResult=new SaveKeyringResult(SaveKeyringResult.RESULT_CANCELLED,log,null);
        sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,saveResult);
        return;
      }
      SaveKeyringResult saveResult=new ProviderHelper(this,modifyResult.getLog()).saveSecretKeyRing(ring,new ProgressScaler(this,60,95,100));
      if (!saveResult.success()) {
        sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,saveResult);
        return;
      }
      if (saveParcel.mNewPassphrase != null) {
        PassphraseCacheService.addCachedPassphrase(this,ring.getMasterKeyId(),saveParcel.mNewPassphrase,ring.getPublicKey().getPrimaryUserIdWithFallback());
      }
      setProgress(R.string.progress_done,100,100);
      ContactSyncAdapterService.requestSync();
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,saveResult);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_DELETE_FILE_SECURELY.equals(action)) {
    try {
      String deleteFile=data.getString(DELETE_FILE);
      try {
        PgpHelper.deleteFileSecurely(this,this,new File(deleteFile));
      }
 catch (      FileNotFoundException e) {
        throw new PgpGeneralException(getString(R.string.error_file_not_found,deleteFile));
      }
catch (      IOException e) {
        throw new PgpGeneralException(getString(R.string.error_file_delete_failed,deleteFile));
      }
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_IMPORT_KEYRING.equals(action)) {
    try {
      List<ParcelableKeyRing> entries;
      if (data.containsKey(IMPORT_KEY_LIST)) {
        entries=data.getParcelableArrayList(IMPORT_KEY_LIST);
      }
 else {
        ParcelableFileCache<ParcelableKeyRing> cache=new ParcelableFileCache<ParcelableKeyRing>(this,"String_Node_Str");
        entries=cache.readCacheIntoList();
      }
      ProviderHelper providerHelper=new ProviderHelper(this);
      PgpImportExport pgpImportExport=new PgpImportExport(this,providerHelper,this,mActionCanceled);
      ImportKeyResult result=pgpImportExport.importKeyRings(entries);
      if (result.mSecret > 0) {
        sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_PREVENT_CANCEL);
        providerHelper.consolidateDatabaseStep1(this);
      }
      ContactSyncAdapterService.requestSync();
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,result);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_EXPORT_KEYRING.equals(action)) {
    try {
      boolean exportSecret=data.getBoolean(EXPORT_SECRET,false);
      long[] masterKeyIds=data.getLongArray(EXPORT_KEY_RING_MASTER_KEY_ID);
      String outputFile=data.getString(EXPORT_FILENAME);
      Uri outputUri=data.getParcelable(EXPORT_URI);
      boolean exportAll=data.getBoolean(EXPORT_ALL);
      if (outputFile != null) {
        if (!FileHelper.isStorageMounted(outputFile)) {
          throw new PgpGeneralException(getString(R.string.error_external_storage_not_ready));
        }
      }
      ArrayList<Long> publicMasterKeyIds=new ArrayList<Long>();
      ArrayList<Long> secretMasterKeyIds=new ArrayList<Long>();
      String selection=null;
      if (!exportAll) {
        selection=KeychainDatabase.Tables.KEYS + "String_Node_Str" + KeyRings.MASTER_KEY_ID+ "String_Node_Str";
        for (        long l : masterKeyIds) {
          selection+=Long.toString(l) + "String_Node_Str";
        }
        selection=selection.substring(0,selection.length() - 1) + "String_Node_Str";
      }
      Cursor cursor=getContentResolver().query(KeyRings.buildUnifiedKeyRingsUri(),new String[]{KeyRings.MASTER_KEY_ID,KeyRings.HAS_ANY_SECRET},selection,null,null);
      try {
        if (cursor != null && cursor.moveToFirst())         do {
          publicMasterKeyIds.add(cursor.getLong(0));
          if (exportSecret && cursor.getInt(1) != 0)           secretMasterKeyIds.add(cursor.getLong(0));
        }
 while (cursor.moveToNext());
      }
  finally {
        if (cursor != null) {
          cursor.close();
        }
      }
      OutputStream outStream;
      if (outputFile != null) {
        outStream=new FileOutputStream(outputFile);
      }
 else {
        outStream=getContentResolver().openOutputStream(outputUri);
      }
      PgpImportExport pgpImportExport=new PgpImportExport(this,new ProviderHelper(this),this);
      Bundle resultData=pgpImportExport.exportKeyRings(publicMasterKeyIds,secretMasterKeyIds,outStream);
      if (mActionCanceled.get() && outputFile != null) {
        new File(outputFile).delete();
      }
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,resultData);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_UPLOAD_KEYRING.equals(action)) {
    try {
      String keyServer=data.getString(UPLOAD_KEY_SERVER);
      HkpKeyserver server=new HkpKeyserver(keyServer);
      ProviderHelper providerHelper=new ProviderHelper(this);
      CanonicalizedPublicKeyRing keyring=providerHelper.getCanonicalizedPublicKeyRing(dataUri);
      PgpImportExport pgpImportExport=new PgpImportExport(this,new ProviderHelper(this),this);
      try {
        pgpImportExport.uploadKeyRingToServer(server,keyring);
      }
 catch (      Keyserver.AddKeyException e) {
        throw new PgpGeneralException("String_Node_Str");
      }
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_DOWNLOAD_AND_IMPORT_KEYS.equals(action) || ACTION_IMPORT_KEYBASE_KEYS.equals(action)) {
    try {
      ArrayList<ImportKeysListEntry> entries=data.getParcelableArrayList(DOWNLOAD_KEY_LIST);
      String keyServer=data.getString(DOWNLOAD_KEY_SERVER);
      ArrayList<ParcelableKeyRing> keyRings=new ArrayList<ParcelableKeyRing>(entries.size());
      for (      ImportKeysListEntry entry : entries) {
        Keyserver server;
        if (entry.getOrigin() == null) {
          server=new HkpKeyserver(keyServer);
        }
 else         if (KeybaseKeyserver.ORIGIN.equals(entry.getOrigin())) {
          server=new KeybaseKeyserver();
        }
 else {
          server=new HkpKeyserver(entry.getOrigin());
        }
        byte[] downloadedKeyBytes;
        if (KeybaseKeyserver.ORIGIN.equals(entry.getOrigin())) {
          downloadedKeyBytes=server.get(entry.getExtraData()).getBytes();
        }
 else         if (entry.getFingerprintHex() != null) {
          downloadedKeyBytes=server.get("String_Node_Str" + entry.getFingerprintHex()).getBytes();
        }
 else {
          downloadedKeyBytes=server.get(entry.getKeyIdHex()).getBytes();
        }
        keyRings.add(new ParcelableKeyRing(downloadedKeyBytes,entry.getFingerprintHex()));
      }
      Intent importIntent=new Intent(this,KeychainIntentService.class);
      importIntent.setAction(ACTION_IMPORT_KEYRING);
      Bundle importData=new Bundle();
      importData.putParcelableArrayList(IMPORT_KEY_LIST,keyRings);
      importIntent.putExtra(EXTRA_DATA,importData);
      importIntent.putExtra(EXTRA_MESSENGER,mMessenger);
      onHandleIntent(importIntent);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_CERTIFY_KEYRING.equals(action)) {
    try {
      long masterKeyId=data.getLong(CERTIFY_KEY_MASTER_KEY_ID);
      long pubKeyId=data.getLong(CERTIFY_KEY_PUB_KEY_ID);
      ArrayList<String> userIds=data.getStringArrayList(CERTIFY_KEY_UIDS);
      String signaturePassphrase=PassphraseCacheService.getCachedPassphrase(this,masterKeyId);
      if (signaturePassphrase == null) {
        throw new PgpGeneralException("String_Node_Str");
      }
      ProviderHelper providerHelper=new ProviderHelper(this);
      CanonicalizedPublicKeyRing publicRing=providerHelper.getCanonicalizedPublicKeyRing(pubKeyId);
      CanonicalizedSecretKeyRing secretKeyRing=providerHelper.getCanonicalizedSecretKeyRing(masterKeyId);
      CanonicalizedSecretKey certificationKey=secretKeyRing.getSecretKey();
      if (!certificationKey.unlock(signaturePassphrase)) {
        throw new PgpGeneralException("String_Node_Str");
      }
      UncachedKeyRing newRing=certificationKey.certifyUserIds(publicRing,userIds,null,null);
      providerHelper.savePublicKeyRing(newRing);
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_DELETE.equals(action)) {
    try {
      long[] masterKeyIds=data.getLongArray(DELETE_KEY_LIST);
      boolean isSecret=data.getBoolean(DELETE_IS_SECRET);
      if (masterKeyIds.length == 0) {
        throw new PgpGeneralException("String_Node_Str");
      }
      if (isSecret && masterKeyIds.length > 1) {
        throw new PgpGeneralException("String_Node_Str");
      }
      boolean success=false;
      for (      long masterKeyId : masterKeyIds) {
        int count=getContentResolver().delete(KeyRingData.buildPublicKeyRingUri(masterKeyId),null,null);
        success|=count > 0;
      }
      if (isSecret && success) {
        new ProviderHelper(this).consolidateDatabaseStep1(this);
      }
      if (success) {
        ContactSyncAdapterService.requestSync();
        sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY);
      }
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_CONSOLIDATE.equals(action)) {
    ConsolidateResult result;
    if (data.containsKey(CONSOLIDATE_RECOVERY) && data.getBoolean(CONSOLIDATE_RECOVERY)) {
      result=new ProviderHelper(this).consolidateDatabaseStep2(this);
    }
 else {
      result=new ProviderHelper(this).consolidateDatabaseStep1(this);
    }
    sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,result);
  }
}

Fixed version (ground truth):
/** 
 * The IntentService calls this method from the default worker thread with the intent that started the service. When this method returns, IntentService stops the service, as appropriate.
 */
@Override protected void onHandleIntent(Intent intent){
  mActionCanceled.set(false);
  Bundle extras=intent.getExtras();
  if (extras == null) {
    Log.e(Constants.TAG,"String_Node_Str");
    return;
  }
  if (!(extras.containsKey(EXTRA_MESSENGER) || extras.containsKey(EXTRA_DATA) || (intent.getAction() == null))) {
    Log.e(Constants.TAG,"String_Node_Str");
    return;
  }
  Uri dataUri=intent.getData();
  mMessenger=(Messenger)extras.get(EXTRA_MESSENGER);
  Bundle data=extras.getBundle(EXTRA_DATA);
  if (data == null) {
    Log.e(Constants.TAG,"String_Node_Str");
    return;
  }
  OtherHelper.logDebugBundle(data,"String_Node_Str");
  String action=intent.getAction();
  if (ACTION_ENCRYPT_SIGN.equals(action)) {
    try {
      int source=data.get(SOURCE) != null ? data.getInt(SOURCE) : data.getInt(TARGET);
      Bundle resultData=new Bundle();
      long sigMasterKeyId=data.getLong(ENCRYPT_SIGNATURE_MASTER_ID);
      String symmetricPassphrase=data.getString(ENCRYPT_SYMMETRIC_PASSPHRASE);
      boolean useAsciiArmor=data.getBoolean(ENCRYPT_USE_ASCII_ARMOR);
      long encryptionKeyIds[]=data.getLongArray(ENCRYPT_ENCRYPTION_KEYS_IDS);
      int compressionId=data.getInt(ENCRYPT_COMPRESSION_ID);
      int urisCount=data.containsKey(ENCRYPT_INPUT_URIS) ? data.getParcelableArrayList(ENCRYPT_INPUT_URIS).size() : 1;
      for (int i=0; i < urisCount; i++) {
        data.putInt(SELECTED_URI,i);
        InputData inputData=createEncryptInputData(data);
        OutputStream outStream=createCryptOutputStream(data);
        String originalFilename=getOriginalFilename(data);
        PgpSignEncrypt.Builder builder=new PgpSignEncrypt.Builder(new ProviderHelper(this),inputData,outStream);
        builder.setProgressable(this).setEnableAsciiArmorOutput(useAsciiArmor).setVersionHeader(PgpHelper.getVersionForHeader(this)).setCompressionId(compressionId).setSymmetricEncryptionAlgorithm(Preferences.getPreferences(this).getDefaultEncryptionAlgorithm()).setEncryptionMasterKeyIds(encryptionKeyIds).setSymmetricPassphrase(symmetricPassphrase).setOriginalFilename(originalFilename);
        try {
          CachedPublicKeyRing signingRing=new ProviderHelper(this).getCachedPublicKeyRing(sigMasterKeyId);
          long sigSubKeyId=signingRing.getSignId();
          String passphrase=PassphraseCacheService.getCachedPassphrase(this,sigSubKeyId);
          builder.setSignatureMasterKeyId(sigMasterKeyId).setSignatureSubKeyId(sigSubKeyId).setSignaturePassphrase(passphrase).setSignatureHashAlgorithm(Preferences.getPreferences(this).getDefaultHashAlgorithm()).setAdditionalEncryptId(sigMasterKeyId);
        }
 catch (        PgpGeneralException e) {
        }
        if (source == IO_BYTES) {
          builder.setCleartextInput(true);
        }
        builder.build().execute();
        outStream.close();
        finalizeEncryptOutputStream(data,resultData,outStream);
      }
      OtherHelper.logDebugBundle(resultData,"String_Node_Str");
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,resultData);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_DECRYPT_VERIFY.equals(action)) {
    try {
      String passphrase=data.getString(DECRYPT_PASSPHRASE);
      InputData inputData=createDecryptInputData(data);
      OutputStream outStream=createCryptOutputStream(data);
      Bundle resultData=new Bundle();
      PgpDecryptVerify.Builder builder=new PgpDecryptVerify.Builder(new ProviderHelper(this),new PgpDecryptVerify.PassphraseCache(){
        @Override public String getCachedPassphrase(        long masterKeyId){
          try {
            return PassphraseCacheService.getCachedPassphrase(KeychainIntentService.this,masterKeyId);
          }
 catch (          PassphraseCacheService.KeyNotFoundException e) {
            return null;
          }
        }
      }
,inputData,outStream);
      builder.setProgressable(this).setAllowSymmetricDecryption(true).setPassphrase(passphrase);
      DecryptVerifyResult decryptVerifyResult=builder.build().execute();
      outStream.close();
      resultData.putParcelable(RESULT_DECRYPT_VERIFY_RESULT,decryptVerifyResult);
      finalizeDecryptOutputStream(data,resultData,outStream);
      OtherHelper.logDebugBundle(resultData,"String_Node_Str");
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,resultData);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_DECRYPT_METADATA.equals(action)) {
    try {
      String passphrase=data.getString(DECRYPT_PASSPHRASE);
      InputData inputData=createDecryptInputData(data);
      Bundle resultData=new Bundle();
      PgpDecryptVerify.Builder builder=new PgpDecryptVerify.Builder(new ProviderHelper(this),new PgpDecryptVerify.PassphraseCache(){
        @Override public String getCachedPassphrase(        long masterKeyId) throws PgpDecryptVerify.NoSecretKeyException {
          try {
            return PassphraseCacheService.getCachedPassphrase(KeychainIntentService.this,masterKeyId);
          }
 catch (          PassphraseCacheService.KeyNotFoundException e) {
            throw new PgpDecryptVerify.NoSecretKeyException();
          }
        }
      }
,inputData,null);
      builder.setProgressable(this).setAllowSymmetricDecryption(true).setPassphrase(passphrase).setDecryptMetadataOnly(true);
      DecryptVerifyResult decryptVerifyResult=builder.build().execute();
      resultData.putParcelable(RESULT_DECRYPT_VERIFY_RESULT,decryptVerifyResult);
      OtherHelper.logDebugBundle(resultData,"String_Node_Str");
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,resultData);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_EDIT_KEYRING.equals(action)) {
    try {
      SaveKeyringParcel saveParcel=data.getParcelable(EDIT_KEYRING_PARCEL);
      if (saveParcel == null) {
        Log.e(Constants.TAG,"String_Node_Str");
        return;
      }
      PgpKeyOperation keyOperations=new PgpKeyOperation(new ProgressScaler(this,10,60,100),mActionCanceled);
      EditKeyResult modifyResult;
      if (saveParcel.mMasterKeyId != null) {
        String passphrase=data.getString(EDIT_KEYRING_PASSPHRASE);
        CanonicalizedSecretKeyRing secRing=new ProviderHelper(this).getCanonicalizedSecretKeyRing(saveParcel.mMasterKeyId);
        modifyResult=keyOperations.modifySecretKeyRing(secRing,saveParcel,passphrase);
      }
 else {
        modifyResult=keyOperations.createSecretKeyRing(saveParcel);
      }
      if (!modifyResult.success()) {
        SaveKeyringResult saveResult=new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR,modifyResult.getLog(),null);
        sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,saveResult);
        return;
      }
      UncachedKeyRing ring=modifyResult.getRing();
      if (mActionCanceled.get()) {
        OperationLog log=modifyResult.getLog();
        if (!modifyResult.cancelled()) {
          log.add(LogLevel.CANCELLED,LogType.MSG_OPERATION_CANCELLED,0);
        }
        SaveKeyringResult saveResult=new SaveKeyringResult(SaveKeyringResult.RESULT_CANCELLED,log,null);
        sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,saveResult);
        return;
      }
      SaveKeyringResult saveResult=new ProviderHelper(this,modifyResult.getLog()).saveSecretKeyRing(ring,new ProgressScaler(this,60,95,100));
      if (!saveResult.success()) {
        sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,saveResult);
        return;
      }
      if (saveParcel.mNewPassphrase != null) {
        PassphraseCacheService.addCachedPassphrase(this,ring.getMasterKeyId(),saveParcel.mNewPassphrase,ring.getPublicKey().getPrimaryUserIdWithFallback());
      }
      setProgress(R.string.progress_done,100,100);
      ContactSyncAdapterService.requestSync();
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,saveResult);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_DELETE_FILE_SECURELY.equals(action)) {
    try {
      String deleteFile=data.getString(DELETE_FILE);
      try {
        PgpHelper.deleteFileSecurely(this,this,new File(deleteFile));
      }
 catch (      FileNotFoundException e) {
        throw new PgpGeneralException(getString(R.string.error_file_not_found,deleteFile));
      }
catch (      IOException e) {
        throw new PgpGeneralException(getString(R.string.error_file_delete_failed,deleteFile));
      }
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_IMPORT_KEYRING.equals(action)) {
    try {
      List<ParcelableKeyRing> entries;
      if (data.containsKey(IMPORT_KEY_LIST)) {
        entries=data.getParcelableArrayList(IMPORT_KEY_LIST);
      }
 else {
        ParcelableFileCache<ParcelableKeyRing> cache=new ParcelableFileCache<ParcelableKeyRing>(this,"String_Node_Str");
        entries=cache.readCacheIntoList();
      }
      ProviderHelper providerHelper=new ProviderHelper(this);
      PgpImportExport pgpImportExport=new PgpImportExport(this,providerHelper,this,mActionCanceled);
      ImportKeyResult result=pgpImportExport.importKeyRings(entries);
      if (result.mSecret > 0) {
        sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_PREVENT_CANCEL);
        providerHelper.consolidateDatabaseStep1(this);
      }
      ContactSyncAdapterService.requestSync();
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,result);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_EXPORT_KEYRING.equals(action)) {
    try {
      boolean exportSecret=data.getBoolean(EXPORT_SECRET,false);
      long[] masterKeyIds=data.getLongArray(EXPORT_KEY_RING_MASTER_KEY_ID);
      String outputFile=data.getString(EXPORT_FILENAME);
      Uri outputUri=data.getParcelable(EXPORT_URI);
      boolean exportAll=data.getBoolean(EXPORT_ALL);
      if (outputFile != null) {
        if (!FileHelper.isStorageMounted(outputFile)) {
          throw new PgpGeneralException(getString(R.string.error_external_storage_not_ready));
        }
      }
      ArrayList<Long> publicMasterKeyIds=new ArrayList<Long>();
      ArrayList<Long> secretMasterKeyIds=new ArrayList<Long>();
      String selection=null;
      if (!exportAll) {
        selection=KeychainDatabase.Tables.KEYS + "String_Node_Str" + KeyRings.MASTER_KEY_ID+ "String_Node_Str";
        for (        long l : masterKeyIds) {
          selection+=Long.toString(l) + "String_Node_Str";
        }
        selection=selection.substring(0,selection.length() - 1) + "String_Node_Str";
      }
      Cursor cursor=getContentResolver().query(KeyRings.buildUnifiedKeyRingsUri(),new String[]{KeyRings.MASTER_KEY_ID,KeyRings.HAS_ANY_SECRET},selection,null,null);
      try {
        if (cursor != null && cursor.moveToFirst())         do {
          publicMasterKeyIds.add(cursor.getLong(0));
          if (exportSecret && cursor.getInt(1) != 0)           secretMasterKeyIds.add(cursor.getLong(0));
        }
 while (cursor.moveToNext());
      }
  finally {
        if (cursor != null) {
          cursor.close();
        }
      }
      OutputStream outStream;
      if (outputFile != null) {
        outStream=new FileOutputStream(outputFile);
      }
 else {
        outStream=getContentResolver().openOutputStream(outputUri);
      }
      PgpImportExport pgpImportExport=new PgpImportExport(this,new ProviderHelper(this),this);
      Bundle resultData=pgpImportExport.exportKeyRings(publicMasterKeyIds,secretMasterKeyIds,outStream);
      if (mActionCanceled.get() && outputFile != null) {
        new File(outputFile).delete();
      }
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,resultData);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_UPLOAD_KEYRING.equals(action)) {
    try {
      String keyServer=data.getString(UPLOAD_KEY_SERVER);
      HkpKeyserver server=new HkpKeyserver(keyServer);
      ProviderHelper providerHelper=new ProviderHelper(this);
      CanonicalizedPublicKeyRing keyring=providerHelper.getCanonicalizedPublicKeyRing(dataUri);
      PgpImportExport pgpImportExport=new PgpImportExport(this,new ProviderHelper(this),this);
      try {
        pgpImportExport.uploadKeyRingToServer(server,keyring);
      }
 catch (      Keyserver.AddKeyException e) {
        throw new PgpGeneralException("String_Node_Str");
      }
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_DOWNLOAD_AND_IMPORT_KEYS.equals(action) || ACTION_IMPORT_KEYBASE_KEYS.equals(action)) {
    ArrayList<ImportKeysListEntry> entries=data.getParcelableArrayList(DOWNLOAD_KEY_LIST);
    String keyServer=data.getString(DOWNLOAD_KEY_SERVER);
    ArrayList<ParcelableKeyRing> keyRings=new ArrayList<ParcelableKeyRing>(entries.size());
    for (    ImportKeysListEntry entry : entries) {
      try {
        Keyserver server;
        if (entry.getOrigin() == null) {
          server=new HkpKeyserver(keyServer);
        }
 else         if (KeybaseKeyserver.ORIGIN.equals(entry.getOrigin())) {
          server=new KeybaseKeyserver();
        }
 else {
          server=new HkpKeyserver(entry.getOrigin());
        }
        byte[] downloadedKeyBytes;
        if (KeybaseKeyserver.ORIGIN.equals(entry.getOrigin())) {
          downloadedKeyBytes=server.get(entry.getExtraData()).getBytes();
        }
 else         if (entry.getFingerprintHex() != null) {
          downloadedKeyBytes=server.get("String_Node_Str" + entry.getFingerprintHex()).getBytes();
        }
 else {
          downloadedKeyBytes=server.get(entry.getKeyIdHex()).getBytes();
        }
        keyRings.add(new ParcelableKeyRing(downloadedKeyBytes,entry.getFingerprintHex()));
      }
 catch (      Exception e) {
        sendErrorToHandler(e);
      }
    }
    Intent importIntent=new Intent(this,KeychainIntentService.class);
    importIntent.setAction(ACTION_IMPORT_KEYRING);
    Bundle importData=new Bundle();
    importData.putParcelableArrayList(IMPORT_KEY_LIST,keyRings);
    importIntent.putExtra(EXTRA_DATA,importData);
    importIntent.putExtra(EXTRA_MESSENGER,mMessenger);
    onHandleIntent(importIntent);
  }
 else   if (ACTION_CERTIFY_KEYRING.equals(action)) {
    try {
      long masterKeyId=data.getLong(CERTIFY_KEY_MASTER_KEY_ID);
      long pubKeyId=data.getLong(CERTIFY_KEY_PUB_KEY_ID);
      ArrayList<String> userIds=data.getStringArrayList(CERTIFY_KEY_UIDS);
      String signaturePassphrase=PassphraseCacheService.getCachedPassphrase(this,masterKeyId);
      if (signaturePassphrase == null) {
        throw new PgpGeneralException("String_Node_Str");
      }
      ProviderHelper providerHelper=new ProviderHelper(this);
      CanonicalizedPublicKeyRing publicRing=providerHelper.getCanonicalizedPublicKeyRing(pubKeyId);
      CanonicalizedSecretKeyRing secretKeyRing=providerHelper.getCanonicalizedSecretKeyRing(masterKeyId);
      CanonicalizedSecretKey certificationKey=secretKeyRing.getSecretKey();
      if (!certificationKey.unlock(signaturePassphrase)) {
        throw new PgpGeneralException("String_Node_Str");
      }
      UncachedKeyRing newRing=certificationKey.certifyUserIds(publicRing,userIds,null,null);
      providerHelper.savePublicKeyRing(newRing);
      sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY);
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_DELETE.equals(action)) {
    try {
      long[] masterKeyIds=data.getLongArray(DELETE_KEY_LIST);
      boolean isSecret=data.getBoolean(DELETE_IS_SECRET);
      if (masterKeyIds.length == 0) {
        throw new PgpGeneralException("String_Node_Str");
      }
      if (isSecret && masterKeyIds.length > 1) {
        throw new PgpGeneralException("String_Node_Str");
      }
      boolean success=false;
      for (      long masterKeyId : masterKeyIds) {
        int count=getContentResolver().delete(KeyRingData.buildPublicKeyRingUri(masterKeyId),null,null);
        success|=count > 0;
      }
      if (isSecret && success) {
        new ProviderHelper(this).consolidateDatabaseStep1(this);
      }
      if (success) {
        ContactSyncAdapterService.requestSync();
        sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY);
      }
    }
 catch (    Exception e) {
      sendErrorToHandler(e);
    }
  }
 else   if (ACTION_CONSOLIDATE.equals(action)) {
    ConsolidateResult result;
    if (data.containsKey(CONSOLIDATE_RECOVERY) && data.getBoolean(CONSOLIDATE_RECOVERY)) {
      result=new ProviderHelper(this).consolidateDatabaseStep2(this);
    }
 else {
      result=new ProviderHelper(this).consolidateDatabaseStep1(this);
    }
    sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY,result);
  }
}