From fd340632dc9b72fa448cad2a05878120e6d625f6 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 13 Jun 2023 07:01:27 +0200 Subject: [PATCH] Added logging --- .../main/java/eu/faircode/email/FragmentSetup.java | 14 +++++++++----- .../java/eu/faircode/email/MicrosoftGraph.java | 3 +-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentSetup.java b/app/src/main/java/eu/faircode/email/FragmentSetup.java index 193e810530..13487d65e7 100644 --- a/app/src/main/java/eu/faircode/email/FragmentSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentSetup.java @@ -1268,8 +1268,8 @@ public class FragmentSetup extends FragmentBase implements SharedPreferences.OnS } private void handleImportGraphContacts(Bundle args) { + final Context context = getContext(); try { - final Context context = getContext(); long account = args.getLong("account"); String user = args.getString("user"); EmailProvider provider = EmailProvider.getProvider(context, "outlookgraph"); @@ -1296,16 +1296,18 @@ public class FragmentSetup extends FragmentBase implements SharedPreferences.OnS authRequestBuilder.setPrompt(provider.graph.prompt); Intent authIntent = authService.getAuthorizationRequestIntent(authRequestBuilder.build()); - Log.i("Graph/contacts intent=" + authIntent); + EntityLog.log(context, "Graph/contacts intent=" + authIntent); startActivityForResult(authIntent, ActivitySetup.REQUEST_GRAPH_CONTACTS_OAUTH); } catch (Throwable ex) { + EntityLog.log(context, "Graph/contacts ex=" + Log.formatThrowable(ex, false)); Log.unexpectedError(getParentFragmentManager(), ex); } } private void onHandleGraphContactsOAuth(@NonNull Intent data) { + final Context context = getContext(); try { - Log.i("Graph/contacts authorized"); + EntityLog.log(context, "Graph/contacts authorized"); AuthorizationResponse auth = AuthorizationResponse.fromIntent(data); if (auth == null) { @@ -1316,7 +1318,6 @@ public class FragmentSetup extends FragmentBase implements SharedPreferences.OnS throw ex; } - final Context context = getContext(); final EmailProvider provider = EmailProvider.getProvider(context, "outlookgraph"); AuthorizationService authService = new AuthorizationService(context); @@ -1352,7 +1353,7 @@ public class FragmentSetup extends FragmentBase implements SharedPreferences.OnS if (access == null || access.accessToken == null) throw new IllegalStateException("No access token"); - Log.i("Graph/contacts got token"); + EntityLog.log(context, "Graph/contacts got token"); int semi = auth.request.state.lastIndexOf(':'); long account = Long.parseLong(auth.request.state.substring(semi + 1)); @@ -1372,6 +1373,7 @@ public class FragmentSetup extends FragmentBase implements SharedPreferences.OnS @Override protected void onExecuted(Bundle args, @NonNull Integer count) { + EntityLog.log(context, "Graph/contacts count=" + count); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); prefs.edit().putBoolean("suggest_sent", true).apply(); @@ -1391,6 +1393,7 @@ public class FragmentSetup extends FragmentBase implements SharedPreferences.OnS @Override protected void onException(Bundle args, Throwable ex) { + EntityLog.log(context, "Graph/contacts ex=" + Log.formatThrowable(ex, false)); Log.unexpectedError(getParentFragmentManager(), ex); } }.execute(FragmentSetup.this, args, "graph:contacts"); @@ -1400,6 +1403,7 @@ public class FragmentSetup extends FragmentBase implements SharedPreferences.OnS } }); } catch (Throwable ex) { + EntityLog.log(context, "Graph/contacts ex=" + Log.formatThrowable(ex, false)); Log.unexpectedError(getParentFragmentManager(), ex); } } diff --git a/app/src/main/java/eu/faircode/email/MicrosoftGraph.java b/app/src/main/java/eu/faircode/email/MicrosoftGraph.java index cf5a03663c..47414e3b9d 100644 --- a/app/src/main/java/eu/faircode/email/MicrosoftGraph.java +++ b/app/src/main/java/eu/faircode/email/MicrosoftGraph.java @@ -136,7 +136,6 @@ public class MicrosoftGraph { connection.setConnectTimeout(GRAPH_TIMEOUT * 1000); ConnectionHelper.setUserAgent(context, connection); connection.setRequestProperty("Authorization", "Bearer " + accessToken); - connection.setRequestProperty("Content-Type", "text/plain"); connection.connect(); try { @@ -157,7 +156,7 @@ public class MicrosoftGraph { String email = jemail.optString("address"); if (!TextUtils.isEmpty(email)) { EntityContact contact = db.contact().getContact(account, EntityContact.TYPE_TO, email); - EntityLog.log(context, displayName + " <" + email + ">" + + EntityLog.log(context, "Graph/contacts " + displayName + " <" + email + ">" + " account=" + account + " exists=" + (contact != null)); if (contact == null) { contact = new EntityContact();