Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some null pointer exceptions #130

Merged
merged 5 commits into from
Jul 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import butterknife.OnClick;
import es.wolfi.app.passman.R;
import es.wolfi.app.passman.SettingValues;
import es.wolfi.app.passman.SettingsCache;
import es.wolfi.app.passman.SingleTon;
import es.wolfi.passman.API.Core;
import es.wolfi.utils.KeyStoreUtils;
Expand Down Expand Up @@ -69,7 +70,8 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_login);
ButterKnife.bind(this);

settings = PreferenceManager.getDefaultSharedPreferences(this);
new SettingsCache().loadSharedPreferences(getBaseContext());
settings = SettingsCache.getSharedPreferences();
KeyStoreUtils.initialize(settings);
ton = SingleTon.getTon();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,10 @@ public void run() {
}

// Update the vault record to avoid future loads
((HashMap<String, Vault>) ton.getExtra(SettingValues.VAULTS.toString())).put(result.guid, result);
HashMap<String, Vault> vaults = (HashMap<String, Vault>) ton.getExtra(SettingValues.VAULTS.toString());
if (vaults != null) {
vaults.put(result.guid, result);
}

ton.addExtra(SettingValues.ACTIVE_VAULT.toString(), result);
showActiveVault();
Expand All @@ -354,7 +357,7 @@ void showUnlockVault() {
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_out_left, R.anim.slide_out_left)
.replace(R.id.content_password_list, new VaultLockScreenFragment(), "vault")
.replace(R.id.content_password_list, VaultLockScreenFragment.newInstance(v), "vault")
.addToBackStack(null)
.commit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,13 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
enable_credential_list_icons_switch.setChecked(settings.getBoolean(SettingValues.ENABLE_CREDENTIAL_LIST_ICONS.toString(), true));
enable_offline_cache_switch.setChecked(settings.getBoolean(SettingValues.ENABLE_OFFLINE_CACHE.toString(), true));

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
Set<Map.Entry<String, Vault>> vaults = getVaultsEntrySet();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O && vaults != null) {
String last_selected_guid = "";
if (settings.getString(SettingValues.AUTOFILL_VAULT_GUID.toString(), null) != null) {
last_selected_guid = settings.getString(SettingValues.AUTOFILL_VAULT_GUID.toString(), null);
}
Set<Map.Entry<String, Vault>> vaults = getVaultsEntrySet();

String[] vault_names = new String[vaults.size() + 1];
vault_names[0] = getContext().getString(R.string.automatically);
int i = 1;
Expand Down Expand Up @@ -215,7 +216,7 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

private Set<Map.Entry<String, Vault>> getVaultsEntrySet() {
HashMap<String, Vault> vaults = (HashMap<String, Vault>) SingleTon.getTon().getExtra(SettingValues.VAULTS.toString());
return vaults.entrySet();
return vaults != null ? vaults.entrySet() : null;
}

@Override
Expand Down Expand Up @@ -265,22 +266,24 @@ public void onClick(View view) {
settings.edit().putString(SettingValues.AUTOFILL_VAULT_GUID.toString(), "").commit();
} else {
Set<Map.Entry<String, Vault>> vaults = getVaultsEntrySet();
for (Map.Entry<String, Vault> vault_entry : vaults) {
if (vault_entry.getValue().name.equals(default_autofill_vault.getSelectedItem().toString())) {
ton.addExtra(SettingValues.AUTOFILL_VAULT_GUID.toString(), vault_entry.getValue().guid);
settings.edit().putString(SettingValues.AUTOFILL_VAULT_GUID.toString(), vault_entry.getValue().guid).commit();

Vault.getVault(getContext(), vault_entry.getValue().guid, new FutureCallback<Vault>() {
@Override
public void onCompleted(Exception e, Vault result) {
if (e != null) {
return;
if (vaults != null) {
for (Map.Entry<String, Vault> vault_entry : vaults) {
if (vault_entry.getValue().name.equals(default_autofill_vault.getSelectedItem().toString())) {
ton.addExtra(SettingValues.AUTOFILL_VAULT_GUID.toString(), vault_entry.getValue().guid);
settings.edit().putString(SettingValues.AUTOFILL_VAULT_GUID.toString(), vault_entry.getValue().guid).commit();

Vault.getVault(getContext(), vault_entry.getValue().guid, new FutureCallback<Vault>() {
@Override
public void onCompleted(Exception e, Vault result) {
if (e != null) {
return;
}
Vault.updateAutofillVault(result, settings);
}
Vault.updateAutofillVault(result, settings);
}
});
});

break;
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
}

HashMap<String, Vault> vaults = (HashMap<String, Vault>) SingleTon.getTon().getExtra(SettingValues.VAULTS.toString());
ArrayList<Vault> l = new ArrayList<Vault>(vaults.values());
ArrayList<Vault> l = new ArrayList<Vault>();
if (vaults != null) {
l = new ArrayList<Vault>(vaults.values());
}
recyclerView.setAdapter(new VaultViewAdapter(l, mListener, getParentFragmentManager()));

view.findViewById(R.id.add_vault_button).setOnClickListener(new View.OnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public void onAttach(Context context) {
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(this, view);
vault = (Vault) SingleTon.getTon().getExtra(SettingValues.ACTIVE_VAULT.toString());
Log.e("VaultLockScreenFragment", "Vault guid: ".concat(vault.guid));
vault_name.setText(vault.name);
}
Expand Down
30 changes: 22 additions & 8 deletions app/src/main/java/es/wolfi/passman/API/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ public static void requestInternalAPIGET(Context c, String endpoint, final Futur
client.setResponseTimeout(getResponseTimeout(c));
client.setMaxRetriesAndTimeout(getConnectRetries(c), getConnectTimeout(c));
client.addHeader("Content-Type", JSON_CONTENT_TYPE);
client.get(host_internal.concat(endpoint), responseHandler);

try {
client.get(host_internal.concat(endpoint), responseHandler);
} catch (Exception e) {
responseHandler.onFailure(0, null, null, e);
}
}

public static void requestAPIGET(Context c, String endpoint, final FutureCallback<String> callback) {
Expand All @@ -122,7 +127,12 @@ public static void requestAPIGET(Context c, String endpoint, final FutureCallbac
client.setResponseTimeout(getResponseTimeout(c));
client.setMaxRetriesAndTimeout(getConnectRetries(c), getConnectTimeout(c));
client.addHeader("Content-Type", JSON_CONTENT_TYPE);
client.get(host.concat(endpoint), responseHandler);

try {
client.get(host.concat(endpoint), responseHandler);
} catch (Exception e) {
responseHandler.onFailure(0, null, null, e);
}
}

public static void requestAPI(Context c, String endpoint, JSONObject jsonPostData, String requestType, final AsyncHttpResponseHandler responseHandler)
Expand All @@ -139,12 +149,16 @@ public static void requestAPI(Context c, String endpoint, JSONObject jsonPostDat

StringEntity entity = new StringEntity(jsonPostData.toString());

if (requestType.equals("POST")) {
client.post(c, url.toString(), entity, JSON_CONTENT_TYPE, responseHandler);
} else if (requestType.equals("PATCH")) {
client.patch(c, url.toString(), entity, JSON_CONTENT_TYPE, responseHandler);
} else if (requestType.equals("DELETE")) {
client.delete(c, url.toString(), entity, JSON_CONTENT_TYPE, responseHandler);
try {
if (requestType.equals("POST")) {
client.post(c, url.toString(), entity, JSON_CONTENT_TYPE, responseHandler);
} else if (requestType.equals("PATCH")) {
client.patch(c, url.toString(), entity, JSON_CONTENT_TYPE, responseHandler);
} else if (requestType.equals("DELETE")) {
client.delete(c, url.toString(), entity, JSON_CONTENT_TYPE, responseHandler);
}
} catch (Exception e) {
responseHandler.onFailure(0, null, null, e);
}
}

Expand Down