├── .gitignore ├── README.md ├── build.gradle └── src └── main ├── AndroidManifest.xml ├── java └── com │ └── boxcryptor2 │ └── android │ └── ei │ └── sample │ ├── Constants.java │ └── MainActivity.java └── res ├── drawable-hdpi └── ic_launcher.png ├── drawable-mdpi └── ic_launcher.png ├── drawable-xhdpi └── ic_launcher.png ├── drawable-xxhdpi └── ic_launcher.png ├── layout └── main.xml └── values ├── strings.xml └── styles.xml /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | **/build 6 | .DS_Store 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Boxcryptor for Android Encryption Interface Sample 2 | =============================== 3 | 4 | This sample shows how to use the Boxcryptor for Android Encryption Interface. 5 | 6 | A detailed documentation can be found here. 7 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | buildscript { 4 | repositories { 5 | mavenCentral() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:0.12.+' 9 | } 10 | } 11 | 12 | android { 13 | compileSdkVersion 20 14 | buildToolsVersion "20.0.0" 15 | 16 | defaultConfig { 17 | minSdkVersion 8 18 | targetSdkVersion 20 19 | versionCode 1 20 | versionName "1.0" 21 | } 22 | buildTypes { 23 | release { 24 | runProguard false 25 | } 26 | } 27 | } 28 | 29 | dependencies { 30 | compile 'com.android.support:appcompat-v7:20.+' 31 | } 32 | -------------------------------------------------------------------------------- /src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/main/java/com/boxcryptor2/android/ei/sample/Constants.java: -------------------------------------------------------------------------------- 1 | package com.boxcryptor2.android.ei.sample; 2 | 3 | public class Constants { 4 | 5 | //encryption service connection 6 | static final String START_PERMISSION_ACTIVITY = "com.boxcryptor2.android.START_APP_PERMISSION"; 7 | static final String START_ENCRYPTION_SERVICE = "com.boxcryptor2.android.START_ENCRYPTION_SERVICE"; 8 | 9 | //encryption service communication 10 | static final int MSG_REGISTER_WITH_SERVICE = 0; 11 | static final int MSG_REGISTER_WITH_SERVICE_RESPONSE = 1; 12 | static final int MSG_ENCRYPT_FILE = 10; 13 | static final int MSG_ENCRYPT_FILE_RESPONSE = 11; 14 | static final int MSG_ENCRYPT_FILE_PROGRESS = 12; 15 | static final int MSG_DECRYPT_FILE = 20; 16 | static final int MSG_DECRYPT_FILE_RESPONSE = 21; 17 | static final int MSG_DECRYPT_FILE_PROGRESS = 22; 18 | static final int MSG_ABORT_FILE_ENCRYPTION = 30; 19 | static final int MSG_ABORT_FILE_ENCRYPTION_RESPONSE = 31; 20 | static final int MSG_ABORT_FILE_DECRYPTION = 40; 21 | static final int MSG_ABORT_FILE_DECRYPTION_RESPONSE = 41; 22 | static final int MSG_ENCRYPT_FILENAME = 50; 23 | static final int MSG_ENCRYPT_FILENAME_RESPONSE = 51; 24 | static final int MSG_DECRYPT_FILENAME = 60; 25 | static final int MSG_DECRYPT_FILENAME_RESPONSE = 61; 26 | static final int MSG_ENCRYPT_FOLDERNAME = 70; 27 | static final int MSG_ENCRYPT_FOLDERNAME_RESPONSE = 71; 28 | static final int MSG_DECRYPT_FOLDERNAME = 80; 29 | static final int MSG_DECRYPT_FOLDERNAME_RESPONSE = 81; 30 | static final int MSG_NO_ACCESS_RESPONSE = -1; 31 | static final String PROCESS_TOKEN = "PROCESS_TOKEN"; 32 | static final String FILENAME = "FILENAME"; 33 | static final String FOLDERNAME = "FOLDERNAME"; 34 | 35 | //encryption service information exchange 36 | static final String STATUS = "STATUS"; 37 | static final String PROGRESS = "PROGRESS"; 38 | static final String IS_TRUSTED = "IS_TRUSTED"; 39 | static final String SOURCE_FILE_PATH = "SOURCE_FILE_PATH"; 40 | static final String TARGET_FOLDER_PATH = "TARGET_FOLDER_PATH"; 41 | 42 | //permission activity information exchange 43 | static final String ACCESS_TOKEN = "ACCESS_TOKEN"; 44 | static final String NO_ACCESS = "NO_ACCESS"; 45 | static final int GET_PERMISSION_REQUEST = 1; 46 | static final int IS_TRUSTED_REQUEST = 2; 47 | 48 | //error codes 49 | static final String ERROR_CODE = "ERROR_CODE"; 50 | static final int ERROR_INPUT = 91; 51 | static final int ERROR_SESSION = 92; 52 | static final int ERROR_PASSWORD_REQUIRED = 93; 53 | static final int ERROR_FILENAME = 94; 54 | static final int ERROR_ENCRYPTION = 95; 55 | static final int ERROR_DECRYPTION = 96; 56 | static final int ERROR_ACCESS_DENIED = 97; 57 | static final int ERROR_UNKNOWN = 98; 58 | 59 | //internal constants 60 | static final String APP_DATA = "APP_DATA"; 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/boxcryptor2/android/ei/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.boxcryptor2.android.ei.sample; 2 | 3 | import android.app.Activity; 4 | import android.content.ComponentName; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.content.ServiceConnection; 8 | import android.content.SharedPreferences; 9 | import android.os.Bundle; 10 | import android.os.Handler; 11 | import android.os.IBinder; 12 | import android.os.Message; 13 | import android.os.Messenger; 14 | import android.os.RemoteException; 15 | import android.util.Log; 16 | import android.view.View; 17 | import android.view.View.OnClickListener; 18 | import android.widget.Button; 19 | import android.widget.EditText; 20 | 21 | import java.util.UUID; 22 | 23 | public class MainActivity extends Activity { 24 | 25 | //service connection fields 26 | private final Messenger incomingMessenger = new Messenger(new IncomingHandler()); 27 | private Messenger outgoingMessenger = null; 28 | private boolean hasServiceConnection = false; 29 | private String accessToken; 30 | private ServiceConnection serviceConnection = new ServiceConnection() { 31 | @Override 32 | public void onServiceConnected(ComponentName componentName, IBinder binder) { 33 | hasServiceConnection = true; 34 | outgoingMessenger = new Messenger(binder); 35 | 36 | registerAppWithService(); 37 | } 38 | 39 | @Override 40 | public void onServiceDisconnected(ComponentName arg0) { 41 | hasServiceConnection = false; 42 | outgoingMessenger = null; 43 | accessToken = Constants.NO_ACCESS; 44 | } 45 | }; 46 | 47 | //ui 48 | private EditText sourceFilePathEditText; 49 | private EditText targetFolderPathEditText; 50 | private EditText decryptedFilenameEditText; 51 | private EditText encryptedFilenameEditText; 52 | private EditText decryptedFoldernameEditText; 53 | private EditText encryptedFoldernameEditText; 54 | private Button encryptButton; 55 | private Button encryptAbortButton; 56 | private Button decryptButton; 57 | private Button decryptAbortButton; 58 | private Button encryptFilenameButton; 59 | private Button decryptFilenameButton; 60 | private Button encryptFoldernameButton; 61 | private Button decryptFoldernameButton; 62 | 63 | @Override 64 | protected void onCreate(Bundle savedInstanceState) { 65 | super.onCreate(savedInstanceState); 66 | setContentView(R.layout.main); 67 | 68 | connectToService(); 69 | 70 | sourceFilePathEditText = (EditText) findViewById(R.id.source_file_path_edittext); 71 | sourceFilePathEditText.setEnabled(false); 72 | 73 | targetFolderPathEditText = (EditText) findViewById(R.id.target_folder_path_edittext); 74 | targetFolderPathEditText.setEnabled(false); 75 | 76 | decryptedFilenameEditText = (EditText) findViewById(R.id.decrypted_filename_edittext); 77 | decryptedFilenameEditText.setEnabled(false); 78 | 79 | encryptedFilenameEditText = (EditText) findViewById(R.id.encrypted_filename_edittext); 80 | encryptedFilenameEditText.setEnabled(false); 81 | 82 | decryptedFoldernameEditText = (EditText) findViewById(R.id.decrypted_foldername_edittext); 83 | decryptedFoldernameEditText.setEnabled(false); 84 | 85 | encryptedFoldernameEditText = (EditText) findViewById(R.id.encrypted_foldername_edittext); 86 | encryptedFoldernameEditText.setEnabled(false); 87 | 88 | encryptButton = (Button) findViewById(R.id.encrypt_button); 89 | encryptButton.setEnabled(false); 90 | encryptButton.setOnClickListener(new OnClickListener() { 91 | 92 | @Override 93 | public void onClick(View v) { 94 | encryptFile(sourceFilePathEditText.getText().toString(), targetFolderPathEditText.getText().toString()); 95 | } 96 | }); 97 | 98 | decryptButton = (Button) findViewById(R.id.decrypt_button); 99 | decryptButton.setEnabled(false); 100 | decryptButton.setOnClickListener(new OnClickListener() { 101 | 102 | @Override 103 | public void onClick(View v) { 104 | decryptFile(sourceFilePathEditText.getText().toString(), targetFolderPathEditText.getText().toString()); 105 | } 106 | }); 107 | 108 | encryptAbortButton = (Button) findViewById(R.id.encrypt_abort_button); 109 | encryptAbortButton.setEnabled(false); 110 | encryptAbortButton.setOnClickListener(new OnClickListener() { 111 | 112 | @Override 113 | public void onClick(View v) { 114 | abortFileEncryption(); 115 | } 116 | }); 117 | 118 | decryptAbortButton = (Button) findViewById(R.id.decrypt_abort_button); 119 | decryptAbortButton.setEnabled(false); 120 | decryptAbortButton.setOnClickListener(new OnClickListener() { 121 | 122 | @Override 123 | public void onClick(View v) { 124 | abortFileDecryption(); 125 | } 126 | }); 127 | 128 | encryptFilenameButton = (Button) findViewById(R.id.encrypt_filename_button); 129 | encryptFilenameButton.setEnabled(false); 130 | encryptFilenameButton.setOnClickListener(new OnClickListener() { 131 | 132 | @Override 133 | public void onClick(View v) { 134 | encryptFileName(decryptedFilenameEditText.getText().toString()); 135 | } 136 | }); 137 | 138 | decryptFilenameButton = (Button) findViewById(R.id.decrypt_filename_button); 139 | decryptFilenameButton.setEnabled(false); 140 | decryptFilenameButton.setOnClickListener(new OnClickListener() { 141 | 142 | @Override 143 | public void onClick(View v) { 144 | decryptFileName(encryptedFilenameEditText.getText().toString()); 145 | } 146 | }); 147 | 148 | encryptFoldernameButton = (Button) findViewById(R.id.encrypt_foldername_button); 149 | encryptFoldernameButton.setEnabled(false); 150 | encryptFoldernameButton.setOnClickListener(new OnClickListener() { 151 | 152 | @Override 153 | public void onClick(View v) { 154 | encryptFolderName(decryptedFoldernameEditText.getText().toString()); 155 | } 156 | }); 157 | 158 | decryptFoldernameButton = (Button) findViewById(R.id.decrypt_foldername_button); 159 | decryptFoldernameButton.setEnabled(false); 160 | decryptFoldernameButton.setOnClickListener(new OnClickListener() { 161 | 162 | @Override 163 | public void onClick(View v) { 164 | decryptFolderName(encryptedFoldernameEditText.getText().toString()); 165 | } 166 | }); 167 | } 168 | 169 | @Override 170 | protected void onDestroy() { 171 | unbindFromService(); 172 | super.onDestroy(); 173 | } 174 | 175 | @Override 176 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 177 | if (requestCode == Constants.IS_TRUSTED_REQUEST && resultCode == RESULT_OK) { 178 | accessToken = loadAccessToken(); 179 | if (data.getBooleanExtra(Constants.IS_TRUSTED, false) && !Constants.NO_ACCESS.equals(accessToken)) { 180 | bindToService(); 181 | } 182 | else { 183 | getPermission(); 184 | } 185 | } 186 | else if (requestCode == Constants.GET_PERMISSION_REQUEST && resultCode == RESULT_OK) { 187 | accessToken = data.getStringExtra(Constants.ACCESS_TOKEN); 188 | saveAccessToken(accessToken); 189 | if (!Constants.NO_ACCESS.equals(accessToken)) { 190 | bindToService(); 191 | } 192 | } 193 | super.onActivityResult(requestCode, resultCode, data); 194 | } 195 | 196 | private class IncomingHandler extends Handler { 197 | 198 | @Override 199 | public void handleMessage(Message incomingMessage) { 200 | Bundle dataBundle = incomingMessage.getData(); 201 | switch (incomingMessage.what) { 202 | case Constants.MSG_REGISTER_WITH_SERVICE_RESPONSE: 203 | if (dataBundle.getBoolean(Constants.STATUS)) { 204 | Log.i(this.getClass().getName(), "registration successful"); 205 | sourceFilePathEditText.setEnabled(true); 206 | targetFolderPathEditText.setEnabled(true); 207 | decryptedFilenameEditText.setEnabled(true); 208 | encryptedFilenameEditText.setEnabled(true); 209 | decryptedFoldernameEditText.setEnabled(true); 210 | encryptedFoldernameEditText.setEnabled(true); 211 | encryptButton.setEnabled(true); 212 | encryptAbortButton.setEnabled(true); 213 | decryptButton.setEnabled(true); 214 | decryptAbortButton.setEnabled(true); 215 | encryptFilenameButton.setEnabled(true); 216 | decryptFilenameButton.setEnabled(true); 217 | encryptFoldernameButton.setEnabled(true); 218 | decryptFoldernameButton.setEnabled(true); 219 | } 220 | break; 221 | case Constants.MSG_ENCRYPT_FILE_RESPONSE: 222 | if (dataBundle.getBoolean(Constants.STATUS)) { 223 | Log.i(this.getClass().getName(), "encryption successful"); 224 | } 225 | else { 226 | Log.i(this.getClass().getName(), "encryption not successful: " + dataBundle.getInt(Constants.ERROR_CODE)); 227 | } 228 | removeCurrentProcessToken(); 229 | break; 230 | case Constants.MSG_ENCRYPT_FILE_PROGRESS: 231 | Log.i(this.getClass().getName(), "encryption process: " + dataBundle.getString(Constants.PROCESS_TOKEN) + " done: " + dataBundle.getLong(Constants.PROGRESS)); 232 | break; 233 | case Constants.MSG_ABORT_FILE_ENCRYPTION_RESPONSE: 234 | if (dataBundle.getBoolean(Constants.STATUS)) { 235 | Log.i(this.getClass().getName(), "successfully aborted encryption"); 236 | } 237 | removeCurrentProcessToken(); 238 | break; 239 | case Constants.MSG_DECRYPT_FILE_RESPONSE: 240 | if (dataBundle.getBoolean(Constants.STATUS)) { 241 | Log.i(this.getClass().getName(), "decryption successful"); 242 | } 243 | else { 244 | Log.i(this.getClass().getName(), "decryption not successful: " + dataBundle.getInt(Constants.ERROR_CODE)); 245 | } 246 | removeCurrentProcessToken(); 247 | break; 248 | case Constants.MSG_DECRYPT_FILE_PROGRESS: 249 | Log.i(this.getClass().getName(), "decryption process: " + dataBundle.getString(Constants.PROCESS_TOKEN) + " done: " + dataBundle.getLong(Constants.PROGRESS)); 250 | break; 251 | case Constants.MSG_ABORT_FILE_DECRYPTION_RESPONSE: 252 | if (dataBundle.getBoolean(Constants.STATUS)) { 253 | Log.i(this.getClass().getName(), "successfully aborted decryption"); 254 | } 255 | removeCurrentProcessToken(); 256 | break; 257 | case Constants.MSG_ENCRYPT_FILENAME_RESPONSE: 258 | if (dataBundle.getBoolean(Constants.STATUS)) { 259 | Log.i(this.getClass().getName(), "filename encryption successful"); 260 | encryptedFilenameEditText.setText(dataBundle.getString(Constants.FILENAME)); 261 | } 262 | else { 263 | Log.i(this.getClass().getName(), "filename encryption not successful: " + dataBundle.getInt(Constants.ERROR_CODE)); 264 | } 265 | removeCurrentProcessToken(); 266 | break; 267 | case Constants.MSG_DECRYPT_FILENAME_RESPONSE: 268 | if (dataBundle.getBoolean(Constants.STATUS)) { 269 | Log.i(this.getClass().getName(), "filename decryption successful"); 270 | decryptedFilenameEditText.setText(dataBundle.getString(Constants.FILENAME)); 271 | } 272 | else { 273 | Log.i(this.getClass().getName(), "filename decryption not successful: " + dataBundle.getInt(Constants.ERROR_CODE)); 274 | } 275 | removeCurrentProcessToken(); 276 | break; 277 | case Constants.MSG_ENCRYPT_FOLDERNAME_RESPONSE: 278 | if (dataBundle.getBoolean(Constants.STATUS)) { 279 | Log.i(this.getClass().getName(), "foldername encryption successful"); 280 | encryptedFoldernameEditText.setText(dataBundle.getString(Constants.FOLDERNAME)); 281 | } 282 | else { 283 | Log.i(this.getClass().getName(), "foldername encryption not successful: " + dataBundle.getInt(Constants.ERROR_CODE)); 284 | } 285 | removeCurrentProcessToken(); 286 | break; 287 | case Constants.MSG_DECRYPT_FOLDERNAME_RESPONSE: 288 | if (dataBundle.getBoolean(Constants.STATUS)) { 289 | Log.i(this.getClass().getName(), "foldername decryption successful"); 290 | decryptedFoldernameEditText.setText(dataBundle.getString(Constants.FOLDERNAME)); 291 | } 292 | else { 293 | Log.i(this.getClass().getName(), "foldername decryption not successful: " + dataBundle.getInt(Constants.ERROR_CODE)); 294 | } 295 | removeCurrentProcessToken(); 296 | break; 297 | case Constants.MSG_NO_ACCESS_RESPONSE: 298 | Log.i(this.getClass().getName(), "no access"); 299 | removeCurrentProcessToken(); 300 | break; 301 | default: 302 | super.handleMessage(incomingMessage); 303 | } 304 | } 305 | } 306 | 307 | private void connectToService() { 308 | try { 309 | Intent intent = new Intent(); 310 | intent.setAction(Constants.START_PERMISSION_ACTIVITY); 311 | intent.putExtra(Constants.IS_TRUSTED, Constants.IS_TRUSTED_REQUEST); 312 | 313 | startActivityForResult(intent, Constants.IS_TRUSTED_REQUEST); 314 | } 315 | catch (Exception e) { 316 | //is Boxcryptor installed? 317 | Log.e(this.getClass().getName(), e.getMessage(), e); 318 | } 319 | } 320 | 321 | private void getPermission() { 322 | try { 323 | Intent intent = new Intent(); 324 | intent.setAction(Constants.START_PERMISSION_ACTIVITY); 325 | 326 | startActivityForResult(intent, Constants.GET_PERMISSION_REQUEST); 327 | } 328 | catch (Exception e) { 329 | Log.e(this.getClass().getName(), e.getMessage(), e); 330 | } 331 | } 332 | 333 | private void bindToService() { 334 | if (!hasServiceConnection) { 335 | Intent intent = new Intent(Constants.START_ENCRYPTION_SERVICE); 336 | bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE); 337 | } 338 | } 339 | 340 | private void registerAppWithService() { 341 | Bundle dataBundle = new Bundle(); 342 | dataBundle.putString(Constants.ACCESS_TOKEN, accessToken); 343 | 344 | sendMessageToService(dataBundle, Constants.MSG_REGISTER_WITH_SERVICE); 345 | } 346 | 347 | private void sendMessageToService(Bundle data, int message) { 348 | if (hasServiceConnection && !Constants.NO_ACCESS.equals(accessToken)) { 349 | try { 350 | Message outgoingMessage = Message.obtain(null, message); 351 | outgoingMessage.setData(data); 352 | outgoingMessage.replyTo = incomingMessenger; 353 | 354 | outgoingMessenger.send(outgoingMessage); 355 | } 356 | catch (RemoteException e) { 357 | Log.e(this.getClass().getName(), e.getMessage(), e); 358 | } 359 | } 360 | } 361 | 362 | private void encryptFile(String sourcePath, String targetPath) { 363 | if (loadCurrentProcessToken() != null) { 364 | return; 365 | } 366 | 367 | String processToken = UUID.randomUUID().toString(); 368 | 369 | Bundle dataBundle = new Bundle(); 370 | dataBundle.putString(Constants.ACCESS_TOKEN, accessToken); 371 | dataBundle.putString(Constants.PROCESS_TOKEN, processToken); 372 | dataBundle.putString(Constants.SOURCE_FILE_PATH, sourcePath); 373 | dataBundle.putString(Constants.TARGET_FOLDER_PATH, targetPath); 374 | 375 | saveCurrentProcessToken(processToken); 376 | 377 | sendMessageToService(dataBundle, Constants.MSG_ENCRYPT_FILE); 378 | } 379 | 380 | private void decryptFile(String sourcePath, String targetPath) { 381 | if (loadCurrentProcessToken() != null) { 382 | return; 383 | } 384 | 385 | String processToken = UUID.randomUUID().toString(); 386 | 387 | Bundle dataBundle = new Bundle(); 388 | dataBundle.putString(Constants.ACCESS_TOKEN, accessToken); 389 | dataBundle.putString(Constants.PROCESS_TOKEN, processToken); 390 | dataBundle.putString(Constants.SOURCE_FILE_PATH, sourcePath); 391 | dataBundle.putString(Constants.TARGET_FOLDER_PATH, targetPath); 392 | 393 | saveCurrentProcessToken(processToken); 394 | 395 | sendMessageToService(dataBundle, Constants.MSG_DECRYPT_FILE); 396 | } 397 | 398 | private void abortFileEncryption() { 399 | String currentProcessToken = loadCurrentProcessToken(); 400 | 401 | if (currentProcessToken == null) { 402 | return; 403 | } 404 | 405 | Bundle dataBundle = new Bundle(); 406 | dataBundle.putString(Constants.ACCESS_TOKEN, accessToken); 407 | dataBundle.putString(Constants.PROCESS_TOKEN, currentProcessToken); 408 | 409 | sendMessageToService(dataBundle, Constants.MSG_ABORT_FILE_ENCRYPTION); 410 | } 411 | 412 | private void abortFileDecryption() { 413 | String currentProcessToken = loadCurrentProcessToken(); 414 | 415 | if (currentProcessToken == null) { 416 | return; 417 | } 418 | 419 | Bundle dataBundle = new Bundle(); 420 | dataBundle.putString(Constants.ACCESS_TOKEN, accessToken); 421 | dataBundle.putString(Constants.PROCESS_TOKEN, currentProcessToken); 422 | 423 | sendMessageToService(dataBundle, Constants.MSG_ABORT_FILE_DECRYPTION); 424 | } 425 | 426 | private void encryptFileName(String filename) { 427 | if (loadCurrentProcessToken() != null) { 428 | return; 429 | } 430 | 431 | String processToken = UUID.randomUUID().toString(); 432 | 433 | Bundle dataBundle = new Bundle(); 434 | dataBundle.putString(Constants.ACCESS_TOKEN, accessToken); 435 | dataBundle.putString(Constants.PROCESS_TOKEN, processToken); 436 | dataBundle.putString(Constants.FILENAME, filename); 437 | 438 | saveCurrentProcessToken(processToken); 439 | 440 | sendMessageToService(dataBundle, Constants.MSG_ENCRYPT_FILENAME); 441 | } 442 | 443 | private void decryptFileName(String filename) { 444 | if (loadCurrentProcessToken() != null) { 445 | return; 446 | } 447 | 448 | String processToken = UUID.randomUUID().toString(); 449 | 450 | Bundle dataBundle = new Bundle(); 451 | dataBundle.putString(Constants.ACCESS_TOKEN, accessToken); 452 | dataBundle.putString(Constants.PROCESS_TOKEN, processToken); 453 | dataBundle.putString(Constants.FILENAME, filename); 454 | 455 | saveCurrentProcessToken(processToken); 456 | 457 | sendMessageToService(dataBundle, Constants.MSG_DECRYPT_FILENAME); 458 | } 459 | 460 | private void encryptFolderName(String foldername) { 461 | if (loadCurrentProcessToken() != null) { 462 | return; 463 | } 464 | 465 | String processToken = UUID.randomUUID().toString(); 466 | 467 | Bundle dataBundle = new Bundle(); 468 | dataBundle.putString(Constants.ACCESS_TOKEN, accessToken); 469 | dataBundle.putString(Constants.PROCESS_TOKEN, processToken); 470 | dataBundle.putString(Constants.FOLDERNAME, foldername); 471 | 472 | saveCurrentProcessToken(processToken); 473 | 474 | sendMessageToService(dataBundle, Constants.MSG_ENCRYPT_FOLDERNAME); 475 | } 476 | 477 | private void decryptFolderName(String foldername) { 478 | if (loadCurrentProcessToken() != null) { 479 | return; 480 | } 481 | 482 | String processToken = UUID.randomUUID().toString(); 483 | 484 | Bundle dataBundle = new Bundle(); 485 | dataBundle.putString(Constants.ACCESS_TOKEN, accessToken); 486 | dataBundle.putString(Constants.PROCESS_TOKEN, processToken); 487 | dataBundle.putString(Constants.FOLDERNAME, foldername); 488 | 489 | saveCurrentProcessToken(processToken); 490 | 491 | sendMessageToService(dataBundle, Constants.MSG_DECRYPT_FOLDERNAME); 492 | } 493 | 494 | private void unbindFromService() { 495 | if (hasServiceConnection) { 496 | unbindService(serviceConnection); 497 | hasServiceConnection = false; 498 | outgoingMessenger = null; 499 | serviceConnection = null; 500 | } 501 | } 502 | 503 | private void saveAccessToken(String accessToken) { 504 | SharedPreferences appData = getSharedPreferences(Constants.APP_DATA, MODE_PRIVATE); 505 | SharedPreferences.Editor editor = appData.edit(); 506 | 507 | editor.putString(Constants.ACCESS_TOKEN, accessToken); 508 | editor.commit(); 509 | } 510 | 511 | private String loadAccessToken() { 512 | SharedPreferences appData = getSharedPreferences(Constants.APP_DATA, MODE_PRIVATE); 513 | if (appData != null) { 514 | return appData.getString(Constants.ACCESS_TOKEN, Constants.NO_ACCESS); 515 | } 516 | return Constants.NO_ACCESS; 517 | } 518 | 519 | private void saveCurrentProcessToken(String processToken) { 520 | SharedPreferences appData = getSharedPreferences(Constants.APP_DATA, MODE_PRIVATE); 521 | SharedPreferences.Editor editor = appData.edit(); 522 | 523 | editor.putString(Constants.PROCESS_TOKEN, processToken); 524 | editor.commit(); 525 | } 526 | 527 | private void removeCurrentProcessToken() { 528 | SharedPreferences appData = getSharedPreferences(Constants.APP_DATA, MODE_PRIVATE); 529 | SharedPreferences.Editor editor = appData.edit(); 530 | 531 | editor.remove(Constants.PROCESS_TOKEN); 532 | editor.commit(); 533 | } 534 | 535 | private String loadCurrentProcessToken() { 536 | SharedPreferences appData = getSharedPreferences(Constants.APP_DATA, 0); 537 | if (appData != null) { 538 | return appData.getString(Constants.PROCESS_TOKEN, null); 539 | } 540 | return null; 541 | } 542 | 543 | } 544 | -------------------------------------------------------------------------------- /src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secomba/bca-encryption-interface-sample/1223bf7f3ce3253f6ae17a17825dc03d25467235/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secomba/bca-encryption-interface-sample/1223bf7f3ce3253f6ae17a17825dc03d25467235/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secomba/bca-encryption-interface-sample/1223bf7f3ce3253f6ae17a17825dc03d25467235/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secomba/bca-encryption-interface-sample/1223bf7f3ce3253f6ae17a17825dc03d25467235/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /src/main/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 15 | 16 | 17 | 22 | 23 | 28 | 29 | 30 | 35 | 36 |