Skip to content

Commit 6915f3f

Browse files
authored
Merge pull request #173 from FlowCrypt/0.4.1
0.4.1: Exceptions
2 parents c004a26 + b1f255c commit 6915f3f

File tree

10 files changed

+92
-26
lines changed

10 files changed

+92
-26
lines changed

FlowCrypt/src/main/java/com/flowcrypt/email/database/FlowCryptSQLiteOpenHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ private void upgradeDatabaseFrom3To4Version(SQLiteDatabase sqLiteDatabase) {
150150
sqLiteDatabase.beginTransaction();
151151
try {
152152
sqLiteDatabase.execSQL("ALTER TABLE " + AccountDaoSource.TABLE_NAME_ACCOUNTS +
153-
" ADD COLUMN " + AccountDaoSource.COL_USERNAME + " TEXT NOT NULL DEFAULT 'user';");
153+
" ADD COLUMN " + AccountDaoSource.COL_USERNAME + " TEXT NOT NULL DEFAULT '';");
154154
sqLiteDatabase.execSQL("ALTER TABLE " + AccountDaoSource.TABLE_NAME_ACCOUNTS +
155-
" ADD COLUMN " + AccountDaoSource.COL_PASSWORD + " TEXT NOT NULL DEFAULT 'password';");
155+
" ADD COLUMN " + AccountDaoSource.COL_PASSWORD + " TEXT NOT NULL DEFAULT '';");
156156
sqLiteDatabase.execSQL("ALTER TABLE " + AccountDaoSource.TABLE_NAME_ACCOUNTS +
157-
" ADD COLUMN " + AccountDaoSource.COL_IMAP_SERVER + " TEXT NOT NULL DEFAULT 'example.com';");
157+
" ADD COLUMN " + AccountDaoSource.COL_IMAP_SERVER + " TEXT NOT NULL DEFAULT '';");
158158
sqLiteDatabase.execSQL("ALTER TABLE " + AccountDaoSource.TABLE_NAME_ACCOUNTS +
159159
" ADD COLUMN " + AccountDaoSource.COL_IMAP_PORT + " INTEGER DEFAULT 143;");
160160
sqLiteDatabase.execSQL("ALTER TABLE " + AccountDaoSource.TABLE_NAME_ACCOUNTS +
@@ -164,7 +164,7 @@ private void upgradeDatabaseFrom3To4Version(SQLiteDatabase sqLiteDatabase) {
164164
sqLiteDatabase.execSQL("ALTER TABLE " + AccountDaoSource.TABLE_NAME_ACCOUNTS +
165165
" ADD COLUMN " + AccountDaoSource.COL_IMAP_AUTH_MECHANISMS + " TEXT;");
166166
sqLiteDatabase.execSQL("ALTER TABLE " + AccountDaoSource.TABLE_NAME_ACCOUNTS +
167-
" ADD COLUMN " + AccountDaoSource.COL_SMTP_SERVER + " TEXT NOT NULL DEFAULT 'example.com';");
167+
" ADD COLUMN " + AccountDaoSource.COL_SMTP_SERVER + " TEXT NOT NULL DEFAULT '';");
168168
sqLiteDatabase.execSQL("ALTER TABLE " + AccountDaoSource.TABLE_NAME_ACCOUNTS +
169169
" ADD COLUMN " + AccountDaoSource.COL_SMTP_PORT + " INTEGER DEFAULT 25;");
170170
sqLiteDatabase.execSQL("ALTER TABLE " + AccountDaoSource.TABLE_NAME_ACCOUNTS +

FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/source/AccountDaoSource.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,17 @@ public static AuthCredentials getCurrentAuthCredentialsFromCursor(KeyStoreCrypto
162162
smtpSecurityTypeOption = SecurityType.Option.STARTLS;
163163
}
164164

165+
String originalPassword = cursor.getString(cursor.getColumnIndex(COL_PASSWORD));
166+
167+
//fixed a bug when try to decrypting the template password.
168+
// See https://github.com/FlowCrypt/flowcrypt-android/issues/168
169+
if (originalPassword.equalsIgnoreCase("password")) {
170+
originalPassword = "";
171+
}
172+
165173
return new AuthCredentials.Builder().setEmail(cursor.getString(cursor.getColumnIndex(COL_EMAIL)))
166174
.setUsername(cursor.getString(cursor.getColumnIndex(COL_USERNAME)))
167-
.setPassword(keyStoreCryptoManager.decryptWithRSA(
168-
cursor.getString(cursor.getColumnIndex(COL_PASSWORD))))
175+
.setPassword(keyStoreCryptoManager.decryptWithRSA(originalPassword))
169176
.setImapServer(cursor.getString(cursor.getColumnIndex(COL_IMAP_SERVER)))
170177
.setImapPort(cursor.getInt(cursor.getColumnIndex(COL_IMAP_PORT)))
171178
.setImapSecurityTypeOption(imapSecurityTypeOption)

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/AddNewAccountActivity.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
106106
switch (resultCode) {
107107
case RESULT_OK:
108108
try {
109-
AuthCredentials authCredentials = data.getParcelableExtra(AddNewAccountManuallyActivity
110-
.KEY_EXTRA_AUTH_CREDENTIALS);
109+
AuthCredentials authCredentials = data.getParcelableExtra(
110+
AddNewAccountManuallyActivity.KEY_EXTRA_AUTH_CREDENTIALS);
111111
AccountDaoSource accountDaoSource = new AccountDaoSource();
112112
accountDaoSource.addRow(this, authCredentials);
113113
accountDaoSource.setActiveAccount(this, authCredentials.getEmail());
@@ -123,6 +123,10 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
123123
Toast.makeText(this, R.string.unknown_error, Toast.LENGTH_SHORT).show();
124124
}
125125
break;
126+
127+
case AddNewAccountManuallyActivity.RESULT_CODE_CONTINUE_WITH_GMAIL:
128+
super.onActivityResult(requestCode, resultCode, data);
129+
break;
126130
}
127131
break;
128132

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/AddNewAccountManuallyActivity.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import com.flowcrypt.email.Constants;
2929
import com.flowcrypt.email.R;
30+
import com.flowcrypt.email.api.email.gmail.GmailConstants;
3031
import com.flowcrypt.email.api.email.model.AuthCredentials;
3132
import com.flowcrypt.email.api.email.model.SecurityType;
3233
import com.flowcrypt.email.database.dao.source.AccountDao;
@@ -47,6 +48,8 @@
4748

4849
import java.util.ArrayList;
4950

51+
import javax.mail.AuthenticationFailedException;
52+
5053
/**
5154
* This activity describes a logic of adding a new account of other email providers.
5255
*
@@ -59,6 +62,8 @@
5962
public class AddNewAccountManuallyActivity extends BaseActivity implements CompoundButton.OnCheckedChangeListener,
6063
AdapterView.OnItemSelectedListener, View.OnClickListener, TextWatcher,
6164
LoaderManager.LoaderCallbacks<LoaderResult> {
65+
public static final int RESULT_CODE_CONTINUE_WITH_GMAIL = 101;
66+
6267
public static final String KEY_EXTRA_AUTH_CREDENTIALS =
6368
GeneralUtil.generateUniqueExtraKey("KEY_EXTRA_AUTH_CREDENTIALS", ImportPublicKeyActivity.class);
6469

@@ -309,6 +314,28 @@ public void handleSuccessLoaderResult(int loaderId, Object result) {
309314
public void handleFailureLoaderResult(int loaderId, Exception e) {
310315
switch (loaderId) {
311316
case R.id.loader_id_check_email_settings:
317+
UIUtil.exchangeViewVisibility(this, false, progressView, contentView);
318+
Throwable original = e != null ? e.getCause() : null;
319+
if (original != null && original instanceof AuthenticationFailedException) {
320+
if (editTextImapServer.getText().toString().equalsIgnoreCase(GmailConstants.GMAIL_IMAP_SERVER)) {
321+
showSnackbar(getRootView(), getString(R.string.less_secure_login_is_not_allowed),
322+
getString(android.R.string.ok), Snackbar.LENGTH_LONG, new View.OnClickListener() {
323+
@Override
324+
public void onClick(View v) {
325+
setResult(RESULT_CODE_CONTINUE_WITH_GMAIL);
326+
finish();
327+
}
328+
});
329+
} else {
330+
showInfoSnackbar(getRootView(), !TextUtils.isEmpty(e.getMessage()) ? e.getMessage()
331+
: getString(R.string.unknown_error), Snackbar.LENGTH_LONG);
332+
}
333+
} else {
334+
showInfoSnackbar(getRootView(), e != null && !TextUtils.isEmpty(e.getMessage()) ? e.getMessage()
335+
: getString(R.string.unknown_error), Snackbar.LENGTH_LONG);
336+
}
337+
break;
338+
312339
case R.id.loader_id_load_private_key_backups_from_email:
313340
UIUtil.exchangeViewVisibility(this, false, progressView, contentView);
314341
showInfoSnackbar(getRootView(), e != null && !TextUtils.isEmpty(e.getMessage()) ? e.getMessage()

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/SplashActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
164164
.EXTRA_KEY_ACCOUNT_DAO));
165165
}
166166
break;
167+
168+
case AddNewAccountManuallyActivity.RESULT_CODE_CONTINUE_WITH_GMAIL:
169+
super.onActivityResult(requestCode, resultCode, data);
170+
break;
167171
}
168172
break;
169173

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/base/BaseSignInActivity.java

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public abstract class BaseSignInActivity extends BaseActivity implements View.On
3838
* The main entry point for Google Play services integration.
3939
*/
4040
protected GoogleApiClient googleApiClient;
41+
protected boolean isRunSignInWithGmailNeeded;
4142

4243
@Override
4344
public void onCreate(@Nullable Bundle savedInstanceState) {
@@ -46,21 +47,27 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
4647
initViews();
4748
}
4849

50+
@Override
51+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
52+
switch (requestCode) {
53+
case REQUEST_CODE_ADD_OTHER_ACCOUNT:
54+
switch (resultCode) {
55+
case AddNewAccountManuallyActivity.RESULT_CODE_CONTINUE_WITH_GMAIL:
56+
this.isRunSignInWithGmailNeeded = true;
57+
break;
58+
}
59+
break;
60+
61+
default:
62+
super.onActivityResult(requestCode, resultCode, data);
63+
}
64+
}
65+
4966
@Override
5067
public void onClick(View v) {
5168
switch (v.getId()) {
5269
case R.id.buttonSignInWithGmail:
53-
if (GeneralUtil.isInternetConnectionAvailable(this)) {
54-
if (googleApiClient != null && googleApiClient.isConnected()) {
55-
googleApiClient.clearDefaultAccountAndReconnect();
56-
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
57-
startActivityForResult(signInIntent, REQUEST_CODE_SIGN_IN);
58-
} else {
59-
showInfoSnackbar(getRootView(), getString(R.string.google_api_is_not_available));
60-
}
61-
} else {
62-
showInfoSnackbar(getRootView(), getString(R.string.internet_connection_is_not_available));
63-
}
70+
signInWithGmailUsingOAuth2();
6471
break;
6572

6673
case R.id.buttonOtherEmailProvider:
@@ -76,7 +83,10 @@ public void onClick(View v) {
7683

7784
@Override
7885
public void onConnected(@Nullable Bundle bundle) {
79-
86+
if (this.isRunSignInWithGmailNeeded) {
87+
this.isRunSignInWithGmailNeeded = false;
88+
signInWithGmailUsingOAuth2();
89+
}
8090
}
8191

8292
@Override
@@ -89,6 +99,23 @@ public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
8999
showInfoSnackbar(getRootView(), connectionResult.getErrorMessage());
90100
}
91101

102+
/**
103+
* Do sign in with Gmail account using OAuth2 mechanism.
104+
*/
105+
protected void signInWithGmailUsingOAuth2() {
106+
if (GeneralUtil.isInternetConnectionAvailable(this)) {
107+
if (googleApiClient != null && googleApiClient.isConnected()) {
108+
googleApiClient.clearDefaultAccountAndReconnect();
109+
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
110+
startActivityForResult(signInIntent, REQUEST_CODE_SIGN_IN);
111+
} else {
112+
showInfoSnackbar(getRootView(), getString(R.string.google_api_is_not_available));
113+
}
114+
} else {
115+
showInfoSnackbar(getRootView(), getString(R.string.internet_connection_is_not_available));
116+
}
117+
}
118+
92119
protected void initGoogleApiClient() {
93120
googleApiClient = GoogleApiClientHelper.generateGoogleApiClient(this, this, this, this, GoogleApiClientHelper
94121
.generateGoogleSignInOptions());

FlowCrypt/src/main/java/com/flowcrypt/email/ui/loader/CheckEmailSettingsAsyncTaskLoader.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import com.flowcrypt.email.api.email.protocol.PropertiesHelper;
1616
import com.flowcrypt.email.model.results.LoaderResult;
1717

18-
import org.acra.ACRA;
19-
2018
import javax.mail.Folder;
2119
import javax.mail.MessagingException;
2220
import javax.mail.Session;
@@ -59,7 +57,6 @@ public LoaderResult loadInBackground() {
5957
testImapConnection(session);
6058
} catch (MessagingException e) {
6159
e.printStackTrace();
62-
ACRA.getErrorReporter().handleException(e);
6360
Exception exception = new Exception("IMAP: " + e.getMessage(), e);
6461
return new LoaderResult(null, exception);
6562
}
@@ -68,7 +65,6 @@ public LoaderResult loadInBackground() {
6865
testSmtpConnection(session);
6966
} catch (MessagingException e) {
7067
e.printStackTrace();
71-
ACRA.getErrorReporter().handleException(e);
7268
Exception exception = new Exception("SMTP: " + e.getMessage(), e);
7369
return new LoaderResult(null, exception);
7470
}

FlowCrypt/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,5 @@
240240
<string name="select_keys">Select key(s):</string>
241241
<string name="your_public_key_will_be_appended">Your public key will be appended to the reply message</string>
242242
<string name="error_occured_try_again_later">An error occurred. Please try again later.</string>
243+
<string name="less_secure_login_is_not_allowed">Less secure login is not allowed on your Gmail account. Switching to secure login.</string>
243244
</resources>

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1818
# org.gradle.parallel=true
1919

20-
APP_VERSION_CODE=40
21-
APP_VERSION_NAME=0.4.0
20+
APP_VERSION_CODE=41
21+
APP_VERSION_NAME=0.4.1
2222
BUILD_TOOLS_VERSION=27.0.0
2323
COMPILE_SDK_VERSION=26
2424
TARGET_SDK_VERSION=26
14.1 MB
Binary file not shown.

0 commit comments

Comments
 (0)