Skip to content

Commit

Permalink
Addressing lint warnings.
Browse files Browse the repository at this point in the history
Auto-reformatted code in several files.
Renamed several variables so acronyms use camel-case.
Broke some longer lines into multiple.
  • Loading branch information
Dave Viggiano committed Aug 23, 2023
1 parent 5f53442 commit 4bb727e
Show file tree
Hide file tree
Showing 39 changed files with 351 additions and 209 deletions.
2 changes: 1 addition & 1 deletion app/src/org/commcare/CommCareApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ public ModernHttpRequester buildHttpRequester(Context context, String url,
networkService = CommCareNetworkServiceGenerator.createNoAuthCommCareNetworkService();
} else if(authInfo instanceof AuthInfo.CurrentAuth) {
//Try to get SSO token
AuthInfo.TokenAuth tokenAuth = ConnectIDSSOHelper.acquireSSOTokenSync(context);
AuthInfo.TokenAuth tokenAuth = ConnectIDSSOHelper.acquireSsoTokenSync(context);
if(tokenAuth != null) {
authInfo = tokenAuth;
}
Expand Down
17 changes: 7 additions & 10 deletions app/src/org/commcare/activities/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent)
uiController.refreshForNewApp();
invalidateOptionsMenu();
usernameBeforeRotation = passwordOrPinBeforeRotation = null;
}
else {
} else {
ConnectIDManager.handleFinishedActivity(requestCode, resultCode, intent);
}

Expand Down Expand Up @@ -437,7 +436,7 @@ private void updateConnectButton() {
}

private void checkForSavedCredentials() {
if(ConnectIDManager.isUnlocked()) {
if (ConnectIDManager.isUnlocked()) {
int selectorIndex = uiController.getSelectedAppIndex();
String selectedAppId = appIdDropdownList.size() > 0 ? appIdDropdownList.get(selectorIndex) : "";
String seatedAppId = CommCareApplication.instance().getCurrentApp().getUniqueId();
Expand Down Expand Up @@ -611,7 +610,7 @@ protected boolean populateAppSpinner(ArrayList<ApplicationRecord> readyApps) {
appIdDropdownList.clear();

boolean includeDefault = ConnectIDManager.requiresUnlock();
if(includeDefault) {
if (includeDefault) {
appNames.add(Localization.get("login.app.direct"));
appIdDropdownList.add("");
}
Expand All @@ -624,10 +623,9 @@ protected boolean populateAppSpinner(ArrayList<ApplicationRecord> readyApps) {
// Want to set the spinner's selection to match whatever the currently seated app is
String currAppId = CommCareApplication.instance().getCurrentApp().getUniqueId();
int position = 0;
if(selectedAppIndex >= 0) {
if (selectedAppIndex >= 0) {
position = selectedAppIndex;
}
else if(!includeDefault) {
} else if (!includeDefault) {
position = appIdDropdownList.indexOf(currAppId);
}
uiController.setMultipleAppsUIState(appNames, position);
Expand All @@ -638,7 +636,7 @@ else if(!includeDefault) {

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(!ConnectIDManager.requiresUnlock() || position > 0) {
if (!ConnectIDManager.requiresUnlock() || position > 0) {
// Retrieve the app record corresponding to the app selected
selectedAppIndex = position;
String appId = appIdDropdownList.get(selectedAppIndex);
Expand All @@ -661,8 +659,7 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
checkForSavedCredentials();
}
}
}
else {
} else {
uiController.setLoginInputsVisibility(false);
}
}
Expand Down
15 changes: 7 additions & 8 deletions app/src/org/commcare/activities/LoginActivityUIController.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void refreshView() {
// Decide whether or not to show the app selection spinner based upon # of usable apps
ArrayList<ApplicationRecord> readyApps = MultipleAppsUtil.getUsableAppRecords();
boolean promptIncluded = false;
if (readyApps.size() == 1 && (!ConnectIDManager.isConnectIDIntroduced() || ConnectIDManager.isUnlocked())) {
if (readyApps.size() == 1 && (!ConnectIDManager.isConnectIdIntroduced() || ConnectIDManager.isUnlocked())) {
setLoginInputsVisibility(true);
// Set this app as the last selected app, for use in choosing what app to initialize
// on first startup
Expand All @@ -229,7 +229,7 @@ public void refreshView() {

setSingleAppUIState();

if(ConnectIDManager.isUnlocked()) {
if (ConnectIDManager.isUnlocked()) {
appLabel.setVisibility(View.VISIBLE);
appLabel.setText(r.getDisplayName());
}
Expand Down Expand Up @@ -260,7 +260,7 @@ public void refreshView() {
notificationButtonView.setVisibility(View.GONE);
}

if(ConnectIDManager.isConnectIDIntroduced()) {
if (ConnectIDManager.isConnectIdIntroduced()) {
setLoginInputsVisibility(!promptIncluded);
}
}
Expand All @@ -273,12 +273,11 @@ public void setLoginInputsVisibility(boolean visible) {

public void updateConnectLoginState() {
boolean emphasizeConnectSignin = false;
if(ConnectIDManager.isConnectIDIntroduced()) {
if (ConnectIDManager.isConnectIdIntroduced()) {
String welcomeText;
if(ConnectIDManager.isUnlocked()) {
if (ConnectIDManager.isUnlocked()) {
welcomeText = activity.getString(R.string.login_welcome_connect_signed_in, ConnectIDDatabaseHelper.getUser(activity).getName());
}
else {
} else {
welcomeText = activity.getString(R.string.login_welcome_connect_signed_out);
emphasizeConnectSignin = true;
}
Expand Down Expand Up @@ -478,7 +477,7 @@ protected boolean isAppSelectorVisible() {
}

protected int getSelectedAppIndex() {
return spinner.getSelectedItemPosition();
return spinner.getSelectedItemPosition();
}

protected void setPermissionsGrantedState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import org.commcare.interfaces.CommCareActivityUIController;
import org.commcare.interfaces.WithUIController;

/**
* @author dviggiano
*/
public class ConnectIDConsentActivity extends CommCareActivity<ConnectIDConsentActivity>
implements WithUIController {
private ConnectIDConsentActivityUIController uiController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import org.commcare.views.ManagedUi;
import org.commcare.views.UiElement;

/**
* @author dviggiano
*/
@ManagedUi(R.layout.screen_connect_consent)
public class ConnectIDConsentActivityUIController implements CommCareActivityUIController {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.commcare.activities.connect;

/**
* @author dviggiano
*/
public class ConnectIDConstants {
public static final int ConnectIDTaskIDOffset = 1000;
public static final String METHOD = "METHOD";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
import java.util.Date;
import java.util.Vector;

/**
* @author dviggiano
*/
public class ConnectIDDatabaseHelper {
private static final Object connectDbHandleLock = new Object();
private static SQLiteDatabase connectDatabase;

private static byte[] getConnectDBPassphrase(Context context) {
private static byte[] getConnectDbPassphrase(Context context) {
try {
for (ConnectKeyRecord r : CommCareApplication.instance().getGlobalStorage(ConnectKeyRecord.class)) {
return EncryptionUtils.decryptFromBase64String(context, r.getEncryptedPassphrase());
Expand All @@ -32,7 +35,8 @@ private static byte[] getConnectDBPassphrase(Context context) {
//If we get here, the passphrase hasn't been created yet
byte[] passphrase = EncryptionUtils.generatePassphrase();

ConnectKeyRecord record = new ConnectKeyRecord(EncryptionUtils.encryptToBase64String(context, passphrase));
String encoded = EncryptionUtils.encryptToBase64String(context, passphrase);
ConnectKeyRecord record = new ConnectKeyRecord(encoded);
CommCareApplication.instance().getGlobalStorage(ConnectKeyRecord.class).write(record);

return passphrase;
Expand All @@ -44,7 +48,7 @@ private static byte[] getConnectDBPassphrase(Context context) {

public static void init(Context context) {
synchronized (connectDbHandleLock) {
byte[] passphrase = getConnectDBPassphrase(context);
byte[] passphrase = getConnectDbPassphrase(context);
SQLiteDatabase database = new DatabaseConnectOpenHelper(context).getWritableDatabase(passphrase);
database.close();
}
Expand All @@ -56,7 +60,7 @@ private static <T extends Persistable> SqlStorage<T> getConnectStorage(Context c
public SQLiteDatabase getHandle() {
synchronized (connectDbHandleLock) {
if (connectDatabase == null || !connectDatabase.isOpen()) {
byte[] passphrase = getConnectDBPassphrase(context);
byte[] passphrase = getConnectDbPassphrase(context);

connectDatabase = new DatabaseConnectOpenHelper(this.c).getWritableDatabase(passphrase);
}
Expand Down Expand Up @@ -85,9 +89,10 @@ public static void forgetUser(Context context) {
}

public static ConnectLinkedAppRecord getAppData(Context context, String appId, String username) {
Vector<ConnectLinkedAppRecord> records = getConnectStorage(context, ConnectLinkedAppRecord.class).getRecordsForValues(
new String[]{ConnectLinkedAppRecord.META_APP_ID, ConnectLinkedAppRecord.META_USER_ID},
new Object[]{appId, username});
Vector<ConnectLinkedAppRecord> records = getConnectStorage(context, ConnectLinkedAppRecord.class)
.getRecordsForValues(
new String[]{ConnectLinkedAppRecord.META_APP_ID, ConnectLinkedAppRecord.META_USER_ID},
new Object[]{appId, username});
return records.isEmpty() ? null : records.firstElement();
}

Expand All @@ -96,10 +101,10 @@ public static void deleteAppData(Context context, ConnectLinkedAppRecord record)
storage.remove(record);
}

public static void storeApp(Context context, String appID, String userID, String passwordOrPin) {
ConnectLinkedAppRecord record = getAppData(context, appID, userID);
public static void storeApp(Context context, String appId, String userId, String passwordOrPin) {
ConnectLinkedAppRecord record = getAppData(context, appId, userId);
if (record == null) {
record = new ConnectLinkedAppRecord(appID, userID, passwordOrPin);
record = new ConnectLinkedAppRecord(appId, userId, passwordOrPin);
} else if (!record.getPassword().equals(passwordOrPin)) {
record.setPassword(passwordOrPin);
}
Expand All @@ -111,13 +116,13 @@ public static void storeApp(Context context, ConnectLinkedAppRecord record) {
getConnectStorage(context, ConnectLinkedAppRecord.class).write(record);
}

public static void storeHQToken(Context context, String appID, String userID, String token, Date expiration) {
ConnectLinkedAppRecord record = getAppData(context, appID, userID);
public static void storeHqToken(Context context, String appId, String userId, String token, Date expiration) {
ConnectLinkedAppRecord record = getAppData(context, appId, userId);
if (record == null) {
record = new ConnectLinkedAppRecord(appID, userID, "");
record = new ConnectLinkedAppRecord(appId, userId, "");
}

record.updateHQToken(token, expiration);
record.updateHqToken(token, expiration);

getConnectStorage(context, ConnectLinkedAppRecord.class).write(record);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import androidx.annotation.NonNull;
import androidx.biometric.BiometricManager;
import androidx.biometric.BiometricPrompt;
import androidx.core.content.ContextCompat;

import org.commcare.google.services.analytics.AnalyticsParamValue;
import org.commcare.google.services.analytics.FirebaseAnalyticsUtil;
Expand All @@ -22,6 +21,9 @@
import org.commcare.interfaces.CommCareActivityUIController;
import org.commcare.interfaces.WithUIController;

/**
* @author dviggiano
*/
public class ConnectIDLoginActivity extends CommCareActivity<ConnectIDLoginActivity>
implements WithUIController {
private BiometricPrompt.AuthenticationCallback biometricPromptCallbacks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import org.commcare.views.ManagedUi;
import org.commcare.views.UiElement;

/**
* @author dviggiano
*/
@ManagedUi(R.layout.screen_connect_login)
public class ConnectIDLoginActivityUIController implements CommCareActivityUIController {
@UiElement(value = R.id.connect_pin_button)
Expand Down
Loading

0 comments on commit 4bb727e

Please sign in to comment.