mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-03 00:00:24 -04:00
android: Make selected apps read-only
Also prevent users from changing selected apps in read-only VPN profiles.
This commit is contained in:
parent
3391f7a465
commit
150dc5ab64
@ -49,6 +49,7 @@ public interface VpnProfileDataSource
|
||||
String KEY_IKE_PROPOSAL = "ike_proposal";
|
||||
String KEY_ESP_PROPOSAL = "esp_proposal";
|
||||
String KEY_DNS_SERVERS = "dns_servers";
|
||||
String KEY_READ_ONLY = "read_only";
|
||||
|
||||
/**
|
||||
* Open the VPN profile data source. The database is automatically created
|
||||
|
@ -60,9 +60,11 @@ public class SelectedApplicationsListFragment extends ListFragment implements Lo
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||
final boolean readOnly = getActivity().getIntent().getBooleanExtra(VpnProfileDataSource.KEY_READ_ONLY, false);
|
||||
getListView().setChoiceMode(readOnly ? ListView.CHOICE_MODE_NONE : ListView.CHOICE_MODE_MULTIPLE);
|
||||
|
||||
mAdapter = new SelectedApplicationsAdapter(getActivity());
|
||||
mAdapter.setReadOnly(readOnly);
|
||||
setListAdapter(mAdapter);
|
||||
setListShown(false);
|
||||
|
||||
@ -101,6 +103,11 @@ public class SelectedApplicationsListFragment extends ListFragment implements Lo
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id)
|
||||
{
|
||||
if (mAdapter.isReadOnly())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
super.onListItemClick(l, v, position, id);
|
||||
SelectedApplicationEntry item = (SelectedApplicationEntry)getListView().getItemAtPosition(position);
|
||||
item.setSelected(!item.isSelected());
|
||||
|
@ -377,6 +377,7 @@ public class VpnProfileDetailActivity extends AppCompatActivity
|
||||
{
|
||||
Intent intent = new Intent(VpnProfileDetailActivity.this, SelectedApplicationsActivity.class);
|
||||
intent.putExtra(VpnProfileDataSource.KEY_SELECTED_APPS_LIST, new ArrayList<>(mSelectedApps));
|
||||
intent.putExtra(VpnProfileDataSource.KEY_READ_ONLY, mProfile.isReadOnly());
|
||||
mSelectApplications.launch(intent);
|
||||
}
|
||||
});
|
||||
|
@ -35,11 +35,12 @@ import java.util.List;
|
||||
|
||||
public class SelectedApplicationsAdapter extends BaseAdapter implements Filterable
|
||||
{
|
||||
private Context mContext;
|
||||
private final Context mContext;
|
||||
private final Object mLock = new Object();
|
||||
private List<SelectedApplicationEntry> mData;
|
||||
private final List<SelectedApplicationEntry> mData;
|
||||
private List<SelectedApplicationEntry> mDataFiltered;
|
||||
private SelectedApplicationsFilter mFilter;
|
||||
private boolean mReadOnly;
|
||||
|
||||
public SelectedApplicationsAdapter(Context context)
|
||||
{
|
||||
@ -100,9 +101,10 @@ public class SelectedApplicationsAdapter extends BaseAdapter implements Filterab
|
||||
SelectedApplicationEntry item = getItem(position);
|
||||
CheckableLinearLayout checkable = (CheckableLinearLayout)view;
|
||||
checkable.setChecked(item.isSelected());
|
||||
ImageView icon = (ImageView)view.findViewById(R.id.app_icon);
|
||||
checkable.setEnabled(!mReadOnly);
|
||||
ImageView icon = view.findViewById(R.id.app_icon);
|
||||
icon.setImageDrawable(item.getIcon());
|
||||
TextView text = (TextView)view.findViewById(R.id.app_name);
|
||||
TextView text = view.findViewById(R.id.app_name);
|
||||
text.setText(item.toString());
|
||||
return view;
|
||||
}
|
||||
@ -117,6 +119,16 @@ public class SelectedApplicationsAdapter extends BaseAdapter implements Filterab
|
||||
return mFilter;
|
||||
}
|
||||
|
||||
public boolean isReadOnly()
|
||||
{
|
||||
return mReadOnly;
|
||||
}
|
||||
|
||||
public void setReadOnly(final boolean readOnly)
|
||||
{
|
||||
this.mReadOnly = readOnly;
|
||||
}
|
||||
|
||||
private class SelectedApplicationsFilter extends Filter
|
||||
{
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user