diff --git a/app/app.iml b/app/app.iml index ef183c6ccb732537ca6b5e7ea9d2a19e86193816..f36de1906719a71a357c1f627683fe377dc6f4ae 100644 --- a/app/app.iml +++ b/app/app.iml @@ -67,14 +67,6 @@ <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" /> - <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" /> - <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" /> - <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" /> - <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" /> - <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" /> - <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" /> - <sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" /> @@ -83,6 +75,14 @@ <sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" /> + <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" /> + <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" /> + <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/23.4.0/jars" /> diff --git a/app/src/main/java/info/nightscout/android/medtronic/GetHmacAndKeyActivity.java b/app/src/main/java/info/nightscout/android/medtronic/GetHmacAndKeyActivity.java index e8f955ec544a63b405f3cbd9e1fb9b8f0b767317..691bef277c5cb0fbc6a5f4ff2ce963974416d74e 100644 --- a/app/src/main/java/info/nightscout/android/medtronic/GetHmacAndKeyActivity.java +++ b/app/src/main/java/info/nightscout/android/medtronic/GetHmacAndKeyActivity.java @@ -71,6 +71,7 @@ public class GetHmacAndKeyActivity extends AppCompatActivity implements LoaderCa // UI references. private EditText mUsernameView; private EditText mPasswordView; + private EditText mHostnameView; private View mProgressView; private View mLoginFormView; private TextView mRegisteredStickView; @@ -99,6 +100,16 @@ public class GetHmacAndKeyActivity extends AppCompatActivity implements LoaderCa } }); + mHostnameView = (EditText) findViewById(R.id.hostname); + mHostnameView.setOnEditorActionListener(new TextView.OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { + attemptLogin(); + return true; + } + }); + + mLoginFormView = findViewById(R.id.login_form); mProgressView = findViewById(R.id.login_progress); mRegisteredStickView = (TextView) findViewById(R.id.registered_usb_devices); @@ -148,10 +159,12 @@ public class GetHmacAndKeyActivity extends AppCompatActivity implements LoaderCa // Reset errors. mUsernameView.setError(null); mPasswordView.setError(null); + mHostnameView.setError(null); // Store values at the time of the login attempt. String username = mUsernameView.getText().toString(); String password = mPasswordView.getText().toString(); + String hostname = mHostnameView.getText().toString(); boolean cancel = false; View focusView = null; @@ -170,6 +183,11 @@ public class GetHmacAndKeyActivity extends AppCompatActivity implements LoaderCa cancel = true; } + // Check for a carelink server hostname (this is optional for a user to define) + if (TextUtils.isEmpty(hostname)) { + hostname = getString(R.string.server_hostname); // default + } + if (cancel) { // There was an error; don't attempt login and focus the first // form field with an error. @@ -178,7 +196,7 @@ public class GetHmacAndKeyActivity extends AppCompatActivity implements LoaderCa // Show a progress spinner, and kick off a background task to // perform the user login attempt. showProgress(true); - mHmacAndKeyTask = new GetHmacAndKey(username, password); + mHmacAndKeyTask = new GetHmacAndKey(username, password, hostname); mHmacAndKeyTask.execute((Void) null); } } @@ -280,6 +298,7 @@ public class GetHmacAndKeyActivity extends AppCompatActivity implements LoaderCa private final String mUsername; private final String mPassword; + private final String mHostname; // Note: if AsyncTask declaration can be located and changed, // then we can pass status to onPostExecute() in return value @@ -287,22 +306,24 @@ public class GetHmacAndKeyActivity extends AppCompatActivity implements LoaderCa // and not have to store it this way. private String mStatus = "success"; - GetHmacAndKey(String username, String password) { + GetHmacAndKey(String username, String password, String hostname) { mUsername = username; mPassword = password; + mHostname = hostname; } @Override protected Boolean doInBackground(final Void... params) { + HttpResponse response; try { DefaultHttpClient client = new DefaultHttpClient(); - HttpPost loginPost = new HttpPost("https://carelink.minimed.eu/patient/j_security_check"); + HttpPost loginPost = new HttpPost(mHostname + "/patient/j_security_check"); List<NameValuePair> nameValuePairs = new ArrayList<>(); nameValuePairs.add(new BasicNameValuePair("j_username", mUsername)); nameValuePairs.add(new BasicNameValuePair("j_password", mPassword)); nameValuePairs.add(new BasicNameValuePair("j_character_encoding", "UTF-8")); loginPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")); - HttpResponse response = client.execute(loginPost); + response = client.execute(loginPost); if (response.getStatusLine().getStatusCode() == 200) { // Get the HMAC/keys for every serial we have seen @@ -317,7 +338,7 @@ public class GetHmacAndKeyActivity extends AppCompatActivity implements LoaderCa hmacRequest.writeInt(0x1c); hmacRequest.writeObject(longSerial.replaceAll("\\d+-", "")); - HttpPost hmacPost = new HttpPost("https://carelink.minimed.eu/patient/secure/SnapshotServer/"); + HttpPost hmacPost = new HttpPost(mHostname + "/patient/secure/SnapshotServer/"); hmacPost.setEntity(new ByteArrayEntity(buffer.toByteArray())); hmacPost.setHeader("Content-type", "application/octet-stream"); response = client.execute(hmacPost); @@ -335,7 +356,7 @@ public class GetHmacAndKeyActivity extends AppCompatActivity implements LoaderCa keyRequest.writeInt(0x1f); keyRequest.writeObject(longSerial); - HttpPost keyPost = new HttpPost("https://carelink.minimed.eu/patient/secure/SnapshotServer/"); + HttpPost keyPost = new HttpPost(mHostname + "/patient/secure/SnapshotServer/"); keyPost.setEntity(new ByteArrayEntity(buffer.toByteArray())); keyPost.setHeader("Content-type", "application/octet-stream"); response = client.execute(keyPost); @@ -364,7 +385,12 @@ public class GetHmacAndKeyActivity extends AppCompatActivity implements LoaderCa mStatus = getString(R.string.error_class_not_found_exception); return false; } +<<<<<<< HEAD mStatus = getString(R.string.error_http_response); +======= + + mStatus = getString(R.string.error_http_response) + "http response: " + response.getStatusLine(); +>>>>>>> specify_hostname return false; } @@ -392,4 +418,4 @@ public class GetHmacAndKeyActivity extends AppCompatActivity implements LoaderCa showProgress(false); } } -} \ No newline at end of file +} diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 56ac4a9c6e3a449922fac8c1bcedbd368be5f4a1..462badee54883bc0f801bacf05107482d57e99b6 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -62,6 +62,16 @@ android:maxLines="1" android:singleLine="true"/> + <AutoCompleteTextView + android:id="@+id/hostname" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:hint="Carelink hostname (optional)" + android:imeOptions="actionDone" + android:inputType="text" + android:maxLines="1"/> + + </LinearLayout> <LinearLayout diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dc91b9c4764555dea4163d421b67d1132fc329b7..00a255b85ec633800300f0bd6f93fbc4b81ae25c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -19,6 +19,7 @@ <string name="title_activity_login">CareLink login</string> <!-- Strings related to login --> + <string name="server_hostname">https://carelink.minimed.eu</string> <string name="prompt_username">CareLink Username</string> <string name="prompt_password">Password</string> <string name="action_sign_in">Retrieve keys for USB</string>