Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrency issue when decrypting/encrypting by keystore keys #46

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
.idea/modules
.idea/markdown-navigator.xml
.idea/modules.xml
.idea/**

# Gradle:
.idea/**/gradle.xml
Expand Down
12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
Expand All @@ -20,7 +22,7 @@ public class MainActivity extends AppCompatActivity {

EditText text1, number1, date1, text2, number2;

Button reloadButton, saveButton, imageDemoBtn;
Button reloadButton, saveButton, multiThreadingButton, imageDemoBtn;

String TEXT_1 = "text_short", TEXT_2 = "text_long", NUMBER_1 = "number_int", NUMBER_2 = "number_float", DATE_1 = "date_text", DATE_2 = "date_long";

Expand All @@ -38,6 +40,7 @@ protected void onCreate(Bundle savedInstanceState) {

reloadButton = (Button) findViewById(R.id.reload);
saveButton = (Button) findViewById(R.id.save);
multiThreadingButton = (Button) findViewById(R.id.multi_threading);
imageDemoBtn = findViewById(R.id.tryFile);

try {
Expand Down Expand Up @@ -79,6 +82,49 @@ public void onClick(View view) {
}
}
});
multiThreadingButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Runnable saveJob = new Runnable() {
@Override
public void run() {
Log.d("queen", Thread.currentThread().getName() + " gets started");
while(true) {
saveData();
reloadData();
}
}
};

new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
new Thread(saveJob).start();
}
});


imageDemoBtn.setOnClickListener(v -> {
Intent intent = new Intent(this, FileDemoActivity.class);
Expand Down Expand Up @@ -106,17 +152,22 @@ protected boolean recover(Exception e, KeyStore keyStore, List<String> keyAliase
void reloadData() {
SecuredPreferenceStore prefStore = SecuredPreferenceStore.getSharedInstance();

String textShort = prefStore.getString(TEXT_1, null);
String textLong = prefStore.getString(TEXT_2, null);
int numberInt = prefStore.getInt(NUMBER_1, 0);
float numberFloat = prefStore.getFloat(NUMBER_2, 0);
String dateText = prefStore.getString(DATE_1, null);

text1.setText(textShort);
text2.setText(textLong);
number1.setText(String.valueOf(numberInt));
number2.setText(String.valueOf(numberFloat));
date1.setText(dateText);
final String textShort = prefStore.getString(TEXT_1, null);
final String textLong = prefStore.getString(TEXT_2, null);
final int numberInt = prefStore.getInt(NUMBER_1, 0);
final float numberFloat = prefStore.getFloat(NUMBER_2, 0);
final String dateText = prefStore.getString(DATE_1, null);

new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
text1.setText(textShort);
text2.setText(textLong);
number1.setText(String.valueOf(numberInt));
number2.setText(String.valueOf(numberFloat));
date1.setText(dateText);
}
});
}

void saveData() {
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button
android:id="@+id/multi_threading"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="multi-threading" />
</LinearLayout>

<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -998,4 +998,4 @@ public InvalidMacException() {
super("Invalid Mac, failed to verify integrity.");
}
}
}
}
Loading