Java Code Examples for android.net.vpn.L2tpProfile

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project android-vpn-settings, under directory /src/com/android/settings/vpn/.

Source file: L2tpEditor.java

  23 
vote

@Override protected void loadExtraPreferencesTo(PreferenceGroup subpanel){
  Context c=subpanel.getContext();
  subpanel.addPreference(createSecretPreference(c));
  subpanel.addPreference(createSecretStringPreference(c));
  L2tpProfile profile=(L2tpProfile)getProfile();
}
 

Example 2

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/vpn/.

Source file: L2tpEditor.java

  23 
vote

@Override protected void loadExtraPreferencesTo(PreferenceGroup subpanel){
  Context c=subpanel.getContext();
  subpanel.addPreference(createSecretPreference(c));
  subpanel.addPreference(createSecretStringPreference(c));
  L2tpProfile profile=(L2tpProfile)getProfile();
}
 

Example 3

From project android-vpn-server, under directory /src/android/net/vpn/.

Source file: VpnTest.java

  21 
vote

@SmallTest public void testGetType(){
  assertEquals(VpnType.L2TP,new L2tpProfile().getType());
  assertEquals(VpnType.L2TP_IPSEC,new L2tpIpsecProfile().getType());
  assertEquals(VpnType.L2TP_IPSEC_PSK,new L2tpIpsecPskProfile().getType());
  assertEquals(VpnType.PPTP,new PptpProfile().getType());
}
 

Example 4

From project android-vpn-server, under directory /src/android/net/vpn/.

Source file: VpnTest.java

  21 
vote

private VpnProfile createTestProfile(VpnState state){
  VpnProfile p=new L2tpProfile();
  p.setName(NAME);
  p.setServerName(SERVER_NAME);
  p.setId(ID);
  p.setDomainSuffices(SUFFICES);
  p.setRouteList(ROUTES);
  p.setSavedUsername(SAVED_NAME);
  p.setState(state);
  return p;
}
 

Example 5

From project android-vpn-settings, under directory /src/android/net/vpn/.

Source file: VpnTest.java

  21 
vote

@SmallTest public void testGetType(){
  assertEquals(VpnType.L2TP,new L2tpProfile().getType());
  assertEquals(VpnType.L2TP_IPSEC,new L2tpIpsecProfile().getType());
  assertEquals(VpnType.L2TP_IPSEC_PSK,new L2tpIpsecPskProfile().getType());
  assertEquals(VpnType.PPTP,new PptpProfile().getType());
}
 

Example 6

From project android-vpn-settings, under directory /src/android/net/vpn/.

Source file: VpnTest.java

  21 
vote

private VpnProfile createTestProfile(VpnState state){
  VpnProfile p=new L2tpProfile();
  p.setName(NAME);
  p.setServerName(SERVER_NAME);
  p.setId(ID);
  p.setDomainSuffices(SUFFICES);
  p.setRouteList(ROUTES);
  p.setSavedUsername(SAVED_NAME);
  p.setState(state);
  return p;
}
 

Example 7

From project android-vpn-settings, under directory /src/com/android/settings/vpn/.

Source file: L2tpEditor.java

  21 
vote

private Preference createSecretPreference(Context c){
  final L2tpProfile profile=(L2tpProfile)getProfile();
  CheckBoxPreference secret=mSecret=new CheckBoxPreference(c);
  boolean enabled=profile.isSecretEnabled();
  setCheckBoxTitle(secret,R.string.vpn_l2tp_secret);
  secret.setChecked(enabled);
  setSecretSummary(secret,enabled);
  secret.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener(){
    public boolean onPreferenceChange(    Preference pref,    Object newValue){
      boolean enabled=(Boolean)newValue;
      profile.setSecretEnabled(enabled);
      mSecretHandler.getPreference().setEnabled(enabled);
      setSecretSummary(mSecret,enabled);
      return true;
    }
  }
);
  return secret;
}
 

Example 8

From project android-vpn-settings, under directory /src/com/android/settings/vpn/.

Source file: VpnSettings.java

  21 
vote

private boolean needKeyStoreToSave(VpnProfile p){
switch (p.getType()) {
case L2TP_IPSEC_PSK:
    L2tpIpsecPskProfile pskProfile=(L2tpIpsecPskProfile)p;
  String presharedKey=pskProfile.getPresharedKey();
if (!TextUtils.isEmpty(presharedKey)) return true;
case L2TP:
L2tpProfile l2tpProfile=(L2tpProfile)p;
if (l2tpProfile.isSecretEnabled() && !TextUtils.isEmpty(l2tpProfile.getSecretString())) {
return true;
}
default :
return false;
}
}
 

Example 9

From project android-vpn-settings, under directory /src/com/android/settings/vpn/.

Source file: VpnSettings.java

  21 
vote

private void processSecrets(VpnProfile p){
switch (p.getType()) {
case L2TP_IPSEC_PSK:
    L2tpIpsecPskProfile pskProfile=(L2tpIpsecPskProfile)p;
  String presharedKey=pskProfile.getPresharedKey();
String key=KEY_PREFIX_IPSEC_PSK + p.getId();
if (!TextUtils.isEmpty(presharedKey) && !mKeyStore.put(key,presharedKey)) {
Log.e(TAG,"keystore write failed: key=" + key);
}
pskProfile.setPresharedKey(key);
case L2TP_IPSEC:
case L2TP:
L2tpProfile l2tpProfile=(L2tpProfile)p;
key=KEY_PREFIX_L2TP_SECRET + p.getId();
if (l2tpProfile.isSecretEnabled()) {
String secret=l2tpProfile.getSecretString();
if (!TextUtils.isEmpty(secret) && !mKeyStore.put(key,secret)) {
Log.e(TAG,"keystore write failed: key=" + key);
}
l2tpProfile.setSecretString(key);
}
 else {
mKeyStore.delete(key);
}
break;
}
}
 

Example 10

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/vpn/.

Source file: L2tpEditor.java

  21 
vote

private Preference createSecretPreference(Context c){
  final L2tpProfile profile=(L2tpProfile)getProfile();
  CheckBoxPreference secret=mSecret=new CheckBoxPreference(c);
  boolean enabled=profile.isSecretEnabled();
  setCheckBoxTitle(secret,R.string.vpn_l2tp_secret);
  secret.setChecked(enabled);
  setSecretSummary(secret,enabled);
  secret.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener(){
    public boolean onPreferenceChange(    Preference pref,    Object newValue){
      boolean enabled=(Boolean)newValue;
      profile.setSecretEnabled(enabled);
      mSecretHandler.getPreference().setEnabled(enabled);
      setSecretSummary(mSecret,enabled);
      return true;
    }
  }
);
  return secret;
}
 

Example 11

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/vpn/.

Source file: VpnSettings.java

  21 
vote

private boolean needKeyStoreToSave(VpnProfile p){
switch (p.getType()) {
case L2TP_IPSEC_PSK:
    L2tpIpsecPskProfile pskProfile=(L2tpIpsecPskProfile)p;
  String presharedKey=pskProfile.getPresharedKey();
if (!TextUtils.isEmpty(presharedKey)) return true;
case L2TP:
L2tpProfile l2tpProfile=(L2tpProfile)p;
if (l2tpProfile.isSecretEnabled() && !TextUtils.isEmpty(l2tpProfile.getSecretString())) {
return true;
}
default :
return false;
}
}
 

Example 12

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/vpn/.

Source file: VpnSettings.java

  21 
vote

private void processSecrets(VpnProfile p){
switch (p.getType()) {
case L2TP_IPSEC_PSK:
    L2tpIpsecPskProfile pskProfile=(L2tpIpsecPskProfile)p;
  String presharedKey=pskProfile.getPresharedKey();
String key=KEY_PREFIX_IPSEC_PSK + p.getId();
if (!TextUtils.isEmpty(presharedKey) && !mKeyStore.put(key,presharedKey)) {
Log.e(TAG,"keystore write failed: key=" + key);
}
pskProfile.setPresharedKey(key);
case L2TP_IPSEC:
case L2TP:
L2tpProfile l2tpProfile=(L2tpProfile)p;
key=KEY_PREFIX_L2TP_SECRET + p.getId();
if (l2tpProfile.isSecretEnabled()) {
String secret=l2tpProfile.getSecretString();
if (!TextUtils.isEmpty(secret) && !mKeyStore.put(key,secret)) {
Log.e(TAG,"keystore write failed: key=" + key);
}
l2tpProfile.setSecretString(key);
}
 else {
mKeyStore.delete(key);
}
break;
}
}
 

Example 13

From project android-vpn-server, under directory /src/com/android/server/vpn/.

Source file: VpnServiceBinder.java

  19 
vote

private VpnService<? extends VpnProfile> createService(VpnProfile p){
switch (p.getType()) {
case L2TP:
    L2tpService l2tp=new L2tpService();
  l2tp.setContext(this,(L2tpProfile)p);
return l2tp;
case PPTP:
PptpService pptp=new PptpService();
pptp.setContext(this,(PptpProfile)p);
return pptp;
case L2TP_IPSEC_PSK:
L2tpIpsecPskService psk=new L2tpIpsecPskService();
psk.setContext(this,(L2tpIpsecPskProfile)p);
return psk;
case L2TP_IPSEC:
L2tpIpsecService l2tpIpsec=new L2tpIpsecService();
l2tpIpsec.setContext(this,(L2tpIpsecProfile)p);
return l2tpIpsec;
default :
return null;
}
}
 

Example 14

From project android-vpn-server, under directory /VpnServices/src/com/android/server/vpn/.

Source file: VpnServiceBinder.java

  19 
vote

private VpnService<? extends VpnProfile> createService(VpnProfile p){
switch (p.getType()) {
case L2TP:
    L2tpService l2tp=new L2tpService();
  l2tp.setContext(this,(L2tpProfile)p);
return l2tp;
case PPTP:
PptpService pptp=new PptpService();
pptp.setContext(this,(PptpProfile)p);
return pptp;
case L2TP_IPSEC_PSK:
L2tpIpsecPskService psk=new L2tpIpsecPskService();
psk.setContext(this,(L2tpIpsecPskProfile)p);
return psk;
case L2TP_IPSEC:
L2tpIpsecService l2tpIpsec=new L2tpIpsecService();
l2tpIpsec.setContext(this,(L2tpIpsecProfile)p);
return l2tpIpsec;
default :
return null;
}
}
 

Example 15

From project android-vpn-settings, under directory /src/com/android/settings/vpn/.

Source file: L2tpEditor.java

  19 
vote

private Preference createSecretStringPreference(Context c){
  SecretHandler sHandler=mSecretHandler=new SecretHandler(c,R.string.vpn_l2tp_secret_string_title,R.string.vpn_l2tp_secret){
    @Override protected String getSecretFromProfile(){
      return ((L2tpProfile)getProfile()).getSecretString();
    }
    @Override protected void saveSecretToProfile(    String secret){
      ((L2tpProfile)getProfile()).setSecretString(secret);
    }
  }
;
  Preference pref=sHandler.getPreference();
  pref.setEnabled(mSecret.isChecked());
  return pref;
}
 

Example 16

From project android-vpn-settings, under directory /src/com/android/settings/vpn/.

Source file: VpnEditor.java

  19 
vote

private VpnProfileEditor getEditor(VpnProfile p){
switch (p.getType()) {
case L2TP_IPSEC:
    return new L2tpIpsecEditor((L2tpIpsecProfile)p);
case L2TP_IPSEC_PSK:
  return new L2tpIpsecPskEditor((L2tpIpsecPskProfile)p);
case L2TP:
return new L2tpEditor((L2tpProfile)p);
case PPTP:
return new PptpEditor((PptpProfile)p);
default :
return new VpnProfileEditor(p);
}
}
 

Example 17

From project android-vpn-settings, under directory /src/com/android/settings/vpn/.

Source file: VpnSettings.java

  19 
vote

private boolean needKeyStoreToConnect(VpnProfile p){
switch (p.getType()) {
case L2TP_IPSEC:
case L2TP_IPSEC_PSK:
    return true;
case L2TP:
  return ((L2tpProfile)p).isSecretEnabled();
default :
return false;
}
}
 

Example 18

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/vpn/.

Source file: L2tpEditor.java

  19 
vote

private Preference createSecretStringPreference(Context c){
  SecretHandler sHandler=mSecretHandler=new SecretHandler(c,R.string.vpn_l2tp_secret_string_title,R.string.vpn_l2tp_secret){
    @Override protected String getSecretFromProfile(){
      return ((L2tpProfile)getProfile()).getSecretString();
    }
    @Override protected void saveSecretToProfile(    String secret){
      ((L2tpProfile)getProfile()).setSecretString(secret);
    }
  }
;
  Preference pref=sHandler.getPreference();
  pref.setEnabled(mSecret.isChecked());
  return pref;
}
 

Example 19

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/vpn/.

Source file: VpnEditor.java

  19 
vote

private VpnProfileEditor getEditor(VpnProfile p){
switch (p.getType()) {
case L2TP_IPSEC:
    return new L2tpIpsecEditor((L2tpIpsecProfile)p);
case L2TP_IPSEC_PSK:
  return new L2tpIpsecPskEditor((L2tpIpsecPskProfile)p);
case L2TP:
return new L2tpEditor((L2tpProfile)p);
case PPTP:
return new PptpEditor((PptpProfile)p);
default :
return new VpnProfileEditor(p);
}
}
 

Example 20

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/vpn/.

Source file: VpnSettings.java

  19 
vote

private boolean needKeyStoreToConnect(VpnProfile p){
switch (p.getType()) {
case L2TP_IPSEC:
case L2TP_IPSEC_PSK:
    return true;
case L2TP:
  return ((L2tpProfile)p).isSecretEnabled();
default :
return false;
}
}