Skip to content

Commit

Permalink
Remember file permissions on selection of extension
Browse files Browse the repository at this point in the history
- Fix #253
  • Loading branch information
fr3ts0n committed Mar 27, 2024
1 parent f4c6029 commit 81bef72
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@

package com.fr3ts0n.ecu.gui.androbd;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
Expand All @@ -36,6 +38,7 @@
import com.fr3ts0n.ecu.prot.obd.ObdProt;

import java.util.HashSet;
import java.util.Objects;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -108,7 +111,8 @@ protected void onCreate(Bundle savedInstanceState)
new PrefsFragment()).commit();
}

public static class PrefsFragment
@SuppressLint("ValidFragment")
public class PrefsFragment
extends PreferenceFragment
implements Preference.OnPreferenceClickListener,
SharedPreferences.OnSharedPreferenceChangeListener
Expand All @@ -135,7 +139,7 @@ public void onCreate(Bundle savedInstanceState)
// set up ELM command selection
setupElmCmdSelection();
// set up ELM adaptive timing mode selection
setupElmTimingSelection();
setupElmTimingSelection();
// set up selectable PID list
setupPidSelection();
// update network selection fields
Expand Down Expand Up @@ -181,11 +185,11 @@ void setupElmTimingSelection()
int i = 0;
for (ElmProt.AdaptTimingMode mode : values)
{
titles[i] = mode.toString();
keys[i] = mode.toString();
i++;
titles[i] = mode.toString();
keys[i] = mode.toString();
i++;
}
// set enries and keys
// set entries and keys
pref.setEntries(titles);
pref.setEntryValues(keys);
pref.setDefaultValue(titles[0]);
Expand Down Expand Up @@ -374,6 +378,17 @@ public void onActivityResult(int requestCode, int resultCode, Intent data)
{
ed.putString(key, value);
pref.setSummary(value != null ? value : getString(R.string.select_extension));

if(value != null)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
{
/* Remember persistent read permission for selected file,
otherwise we will NOT be allowed to load it on startup ... ;( */
getContentResolver().takePersistableUriPermission(Objects.requireNonNull(data.getData()),
Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
}
}

Expand Down

0 comments on commit 81bef72

Please sign in to comment.