6.1 Lock/Unlock File

6.1.1 Lock File

T he lockFile method of BayunCore class locks a file with default encryption-policy and key-generation-policy dictated by server settings.

  • Parameters

    • filePath : Path of the file to be locked.

    • success : Success block to be executed after file is successfully locked.

    • failure : Failure block to be executed if locking fails, returns BayunError.

The file at the given file path is overwritten with the locked file. If file locking fails original file is not changed.

String fileURL = file.getAbsolutePath();

// Success Callback
Handler.Callback success = new Handler.Callback() {
    @Override
    public boolean handleMessage(Message message) {
        Log.d(TAG, "File locked successfully.");
        return false;
    }
}
// Failure Callback
Handler.Callback failure = new Handler.Callback() {
    @Override
    public boolean handleMessage(Message message) {
        String error = message.getData().getString("BayunError", "");
        Log.d(TAG, "Error locking file.");
        return false;
    }
};

bayunCore.lockFile(fileURL, success, failure);

6.1.2 Lock File with Encryption Policy, Key Generation Policy

The lockFile method with encryption policy, key generation policy as parameters locks file with the encryption key dictated by the policy.

  • Parameters

    • filePath : Path of the file to be locked.

    • encryptionPolicy : BayunEncryptionPolicy determines the key for locking.

    • keyGenerationPolicy : BayunKeyGenerationPolicy determines the policy to generate the data encryption key.

    • groupId : GroupId is required if encryptionPolicy is BayunEncryptionPolicyGroup.

    • success : Success block to be executed after file is successfully locked.

    • failure : Failure block to be executed if locking fails, returns BayunError.

String fileURL = file.getAbsolutePath();
int encryptionPolicy = BayunCore.ENCRYPTION_POLICY_COMPANY;
int keyGenerationPolicy = BayunCore.KEY_GENERATION_POLICY_ENVELOPE;
String groupId = "<groupId>";

// Success Callback
Handler.Callback success = new Handler.Callback() {
    @Override
    public boolean handleMessage(Message message) {
        Log.d(TAG, "File locked successfully.");
        return false;
    }
}
// Failure Callback
Handler.Callback failure = new Handler.Callback() {
    @Override
    public boolean handleMessage(Message message) {
        String error = message.getData().getString("BayunError", "");
        Log.d(TAG, "Error locking file.");
        return false;
    }
};

bayunCore.lockFile(fileURL, encryptionPolicy, keyGenerationPolicy, groupId, success, failure);

If encryption-policy is other than BayunEncryptionPolicyGroup then groupId should be null.

6.1.3 Unlock File

The unlockFile method of BayunCore class unlocks a locked file.

  • Parameters

    • filePath : Path of the file to be unlocked.

    • success : Success block to be executed after file is successfully unlocked.

    • failure : Failure block to be executed if unlocking fails, returns BayunError.

String fileURL = file.getAbsolutePath();

bayunCore.unlockFile(fileURL, success, failure);

// Success Callback
Handler.Callback success = new Handler.Callback() {
    @Override
    public boolean handleMessage(Message message) {
        Log.d(TAG, "File unlocked successfully.");
        return false;
    }
}
// Failure Callback
Handler.Callback failure = new Handler.Callback() {
    @Override
    public boolean handleMessage(Message message) {
        String error = message.getData().getString("BayunError", "");
        Log.d(TAG, "Error unlocking file.");
        }
        return false;
    }
};

bayunCore.unlockFile(fileURL, success, failure);

Last updated