Skip to content

Commit 81bef72

Browse files
committed
Remember file permissions on selection of extension
- Fix fr3ts0n#253
1 parent f4c6029 commit 81bef72

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

androbd/src/main/java/com/fr3ts0n/ecu/gui/androbd/SettingsActivity.java

+21-6
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
package com.fr3ts0n.ecu.gui.androbd;
2121

22+
import android.annotation.SuppressLint;
2223
import android.app.Activity;
2324
import android.content.Intent;
2425
import android.content.SharedPreferences;
26+
import android.os.Build;
2527
import android.os.Bundle;
2628
import android.preference.EditTextPreference;
2729
import android.preference.ListPreference;
@@ -36,6 +38,7 @@
3638
import com.fr3ts0n.ecu.prot.obd.ObdProt;
3739

3840
import java.util.HashSet;
41+
import java.util.Objects;
3942
import java.util.Vector;
4043
import java.util.logging.Level;
4144
import java.util.logging.Logger;
@@ -108,7 +111,8 @@ protected void onCreate(Bundle savedInstanceState)
108111
new PrefsFragment()).commit();
109112
}
110113

111-
public static class PrefsFragment
114+
@SuppressLint("ValidFragment")
115+
public class PrefsFragment
112116
extends PreferenceFragment
113117
implements Preference.OnPreferenceClickListener,
114118
SharedPreferences.OnSharedPreferenceChangeListener
@@ -135,7 +139,7 @@ public void onCreate(Bundle savedInstanceState)
135139
// set up ELM command selection
136140
setupElmCmdSelection();
137141
// set up ELM adaptive timing mode selection
138-
setupElmTimingSelection();
142+
setupElmTimingSelection();
139143
// set up selectable PID list
140144
setupPidSelection();
141145
// update network selection fields
@@ -181,11 +185,11 @@ void setupElmTimingSelection()
181185
int i = 0;
182186
for (ElmProt.AdaptTimingMode mode : values)
183187
{
184-
titles[i] = mode.toString();
185-
keys[i] = mode.toString();
186-
i++;
188+
titles[i] = mode.toString();
189+
keys[i] = mode.toString();
190+
i++;
187191
}
188-
// set enries and keys
192+
// set entries and keys
189193
pref.setEntries(titles);
190194
pref.setEntryValues(keys);
191195
pref.setDefaultValue(titles[0]);
@@ -374,6 +378,17 @@ public void onActivityResult(int requestCode, int resultCode, Intent data)
374378
{
375379
ed.putString(key, value);
376380
pref.setSummary(value != null ? value : getString(R.string.select_extension));
381+
382+
if(value != null)
383+
{
384+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
385+
{
386+
/* Remember persistent read permission for selected file,
387+
otherwise we will NOT be allowed to load it on startup ... ;( */
388+
getContentResolver().takePersistableUriPermission(Objects.requireNonNull(data.getData()),
389+
Intent.FLAG_GRANT_READ_URI_PERMISSION);
390+
}
391+
}
377392
}
378393
}
379394

0 commit comments

Comments
 (0)