Skip to content

Commit

Permalink
Check shell value before setting it
Browse files Browse the repository at this point in the history
  • Loading branch information
dvhh committed Apr 14, 2015
1 parent 3db5b99 commit 8f152a1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
22 changes: 22 additions & 0 deletions term/src/main/java/jackpal/androidterm/TermPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,22 @@
import jackpal.androidterm.compat.ActionBarCompat;
import jackpal.androidterm.compat.ActivityCompat;
import jackpal.androidterm.compat.AndroidCompat;
import jackpal.androidterm.compat.FileCompat;

import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.view.MenuItem;

import java.io.File;


public class TermPreferences extends PreferenceActivity {
private static final String ACTIONBAR_KEY = "actionbar";
private static final String CATEGORY_SCREEN_KEY = "screen";
private static final String SHELL_KEY = "shell";

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -53,6 +60,21 @@ protected void onCreate(Bundle savedInstanceState) {
bar.setDisplayOptions(ActionBarCompat.DISPLAY_HOME_AS_UP, ActionBarCompat.DISPLAY_HOME_AS_UP);
}
}

EditTextPreference shellPreference=(EditTextPreference)findPreference(SHELL_KEY);
if(shellPreference != null) {
shellPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if(newValue instanceof String) {
String value=(String) newValue;
File check=new File(value);
return check.exists() && FileCompat.canExecute(check);
}
return false;
}
});
}
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions term/src/main/java/jackpal/androidterm/compat/FileCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@

package jackpal.androidterm.compat;

import android.annotation.TargetApi;

import java.io.File;

/**
* Compatibility class for java.io.File
*/
public class FileCompat {
@TargetApi(9)
private static class Api9OrLater {
public static boolean canExecute(File file) {
return file.canExecute();
Expand Down

0 comments on commit 8f152a1

Please sign in to comment.