Skip to content

Commit e7ac9fa

Browse files
committed
Tidepool: update handling
1 parent 10d2d9d commit e7ac9fa

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

app/src/main/java/com/eveningoutpost/dexdrip/tidepool/AuthFlowIn.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,45 @@ public class AuthFlowIn extends AppCompatActivity {
3838
private static final String PREF_TIDEPOOL_USER_NAME = "tidepool_username";
3939
private static final String PREF_TIDEPOOL_SUB_NAME = "tidepool_subname";
4040

41+
private static final boolean DEBUG = false;
42+
4143
final AtomicReference<JSONObject> userInfo = new AtomicReference<>();
4244

4345
public void onCreate(final Bundle savedInstanceBundle) {
4446
super.onCreate(savedInstanceBundle);
47+
val intent = getIntent();
4548
Log.d(TAG, "Got response");
46-
Inevitable.task("tidepool-process-auth", 10, () -> processIntent(getIntent()));
49+
if (DEBUG) {
50+
val extras = intent.getExtras();
51+
if (extras != null) {
52+
for (String key : extras.keySet()) {
53+
Object value = extras.get(key);
54+
Log.d(TAG, key + " = " + value + " (" + (value != null ? value.getClass().getName() : "null") + ")");
55+
}
56+
} else {
57+
Log.d(TAG, "No extras found in intent.");
58+
}
59+
}
60+
Inevitable.task("tidepool-process-auth", 10, () -> processIntent(intent));
4761
this.finish();
4862
}
4963

5064
private void processIntent(final Intent intent) {
65+
if (intent == null) {
66+
Log.wtf(TAG, "Intent is null when trying to process intent");
67+
return;
68+
}
5169
val authorizationResponse = AuthorizationResponse.fromIntent(intent);
5270
val authorizationException = AuthorizationException.fromIntent(intent);
5371
val state = AuthFlowOut.getAuthState();
5472
if (state == null) {
5573
Log.wtf(TAG, "Could not get auth state");
5674
return;
5775
}
76+
if (authorizationResponse == null && authorizationException == null) {
77+
Log.wtf(TAG, "Both response and exception are null when processing intent?");
78+
return;
79+
}
5880
state.update(authorizationResponse, authorizationException);
5981
if (authorizationException != null) {
6082
Log.d(TAG, "Got authorization error - resetting state: " + authorizationException);

app/src/main/java/com/eveningoutpost/dexdrip/tidepool/AuthFlowOut.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import android.content.Intent;
66
import android.net.Uri;
77
import android.util.Base64;
8-
import android.util.Log;
8+
import com.eveningoutpost.dexdrip.models.UserError.Log;
99

1010
import com.eveningoutpost.dexdrip.models.JoH;
1111
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
@@ -159,11 +159,16 @@ public static void doTidePoolInitialLogin(boolean full) {
159159
val authRequest = authRequestBuilder.build();
160160

161161
Log.d(TAG, "Firing off request");
162-
getAuthService().performAuthorizationRequest(
163-
authRequest,
164-
// TODO will need mutability flag in later target sdk versions
165-
PendingIntent.getActivity(context, 0, new Intent(context, AuthFlowIn.class), 0),
166-
PendingIntent.getActivity(context, 0, new Intent(context, AuthFlowIn.class), 0));
162+
try {
163+
getAuthService().performAuthorizationRequest(
164+
authRequest,
165+
PendingIntent.getActivity(context, 0, new Intent(context, AuthFlowIn.class), PendingIntent.FLAG_MUTABLE),
166+
PendingIntent.getActivity(context, 0, new Intent(context, AuthFlowIn.class), PendingIntent.FLAG_MUTABLE));
167+
} catch (Exception e) {
168+
val msg = "Tidepool: exception when trying to perform authorization. Is Chrome installed? "+e;
169+
Log.wtf(TAG, msg);
170+
JoH.static_toast_long(msg);
171+
}
167172
});
168173
}
169174
}

0 commit comments

Comments
 (0)