Skip to content

Commit cf4eb86

Browse files
committed
Modified a logic of start EmailSyncService. | #67.
1 parent 2cef68c commit cf4eb86

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

FlowCrypt/src/main/java/com/flowcrypt/email/service/EmailSyncService.java

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import android.text.TextUtils;
2121
import android.util.Log;
2222

23-
import com.flowcrypt.email.BuildConfig;
2423
import com.flowcrypt.email.api.email.FoldersManager;
2524
import com.flowcrypt.email.api.email.JavaEmailConstants;
2625
import com.flowcrypt.email.api.email.gmail.GmailConstants;
@@ -85,8 +84,6 @@ public class EmailSyncService extends Service implements SyncListener {
8584
public static final int MESSAGE_GET_ACTIVE_ACCOUNT = 11;
8685
public static final int MESSAGE_SEND_MESSAGE_WITH_BACKUP = 12;
8786

88-
public static final String EXTRA_KEY_GMAIL_ACCOUNT = BuildConfig.APPLICATION_ID
89-
+ ".EXTRA_KEY_GMAIL_ACCOUNT";
9087
private static final String TAG = EmailSyncService.class.getSimpleName();
9188
/**
9289
* This {@link Messenger} is responsible for the receive intents from other client and
@@ -113,15 +110,10 @@ public EmailSyncService() {
113110
* This method can bu used to start {@link EmailSyncService}.
114111
*
115112
* @param context Interface to global information about an application environment.
116-
* @param account The user {@link Account}
117113
*/
118-
public static void startEmailSyncService(Context context, Account account) {
119-
if (account != null) {
120-
Intent startEmailServiceIntent = new Intent(context, EmailSyncService.class);
121-
startEmailServiceIntent.putExtra(EmailSyncService.EXTRA_KEY_GMAIL_ACCOUNT,
122-
account);
123-
context.startService(startEmailServiceIntent);
124-
} else throw new NullPointerException("The account is null");
114+
public static void startEmailSyncService(Context context) {
115+
Intent startEmailServiceIntent = new Intent(context, EmailSyncService.class);
116+
context.startService(startEmailServiceIntent);
125117
}
126118

127119
@Override
@@ -136,16 +128,13 @@ public void onCreate() {
136128

137129
@Override
138130
public int onStartCommand(Intent intent, int flags, int startId) {
139-
Log.d(TAG, "onStartCommand |intent =" + intent + "|flags = " + flags + "|startId = " +
140-
startId);
131+
Log.d(TAG, "onStartCommand |intent =" + intent + "|flags = " + flags + "|startId = " + startId);
141132
isServiceStarted = true;
142-
if (intent != null) {
143-
account = intent.getParcelableExtra(EXTRA_KEY_GMAIL_ACCOUNT);
144-
if (account != null) {
145-
gmailSynsManager.beginSync(false);
146-
} else {
147-
//todo-denbond7 handle this error;
148-
}
133+
this.account = new AccountDaoSource().getActiveAccountInformation(this).getAccount();
134+
if (account != null) {
135+
gmailSynsManager.beginSync(false);
136+
} else {
137+
//todo-denbond7 handle this error;
149138
}
150139

151140
return super.onStartCommand(intent, flags, startId);
@@ -184,7 +173,7 @@ public IBinder onBind(Intent intent) {
184173
account = accountDao.getAccount();
185174

186175
if (account != null && !isServiceStarted) {
187-
EmailSyncService.startEmailSyncService(getContext(), account);
176+
EmailSyncService.startEmailSyncService(getContext());
188177
}
189178
}
190179
} else {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
108108
case REQUEST_CODE_IMPORT_ACTIVITY:
109109
switch (resultCode) {
110110
case Activity.RESULT_OK:
111-
EmailSyncService.startEmailSyncService(this, account);
111+
EmailSyncService.startEmailSyncService(this);
112112
EmailManagerActivity.runEmailManagerActivity(this, account);
113113
finish();
114114
break;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
163163
case REQUEST_CODE_CHECK_PRIVATE_KEYS_FROM_GMAIL:
164164
switch (resultCode) {
165165
case Activity.RESULT_OK:
166-
EmailSyncService.startEmailSyncService(this, account);
166+
EmailSyncService.startEmailSyncService(this);
167167
EmailManagerActivity.runEmailManagerActivity(this, account);
168168
finish();
169169
break;
@@ -271,7 +271,7 @@ private void handleSignInResult(GoogleSignInResult googleSignInResult) {
271271
}
272272

273273
if (SecurityUtils.isBackupKeysExist(this)) {
274-
EmailSyncService.startEmailSyncService(this, account);
274+
EmailSyncService.startEmailSyncService(this);
275275
EmailManagerActivity.runEmailManagerActivity(this, account);
276276
finish();
277277
} else {

0 commit comments

Comments
 (0)