Home | History | Annotate | Download | only in vpn
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.settings.vpn;
     18 
     19 import com.android.settings.R;
     20 
     21 import android.content.Context;
     22 import android.net.vpn.L2tpIpsecPskProfile;
     23 import android.preference.EditTextPreference;
     24 import android.preference.Preference;
     25 import android.preference.PreferenceGroup;
     26 
     27 /**
     28  * The class for editing {@link L2tpIpsecPskProfile}.
     29  */
     30 class L2tpIpsecPskEditor extends L2tpEditor {
     31     private EditTextPreference mPresharedKey;
     32     private SecretHandler mPskHandler;
     33 
     34     public L2tpIpsecPskEditor(L2tpIpsecPskProfile p) {
     35         super(p);
     36     }
     37 
     38     @Override
     39     protected void loadExtraPreferencesTo(PreferenceGroup subpanel) {
     40         Context c = subpanel.getContext();
     41         subpanel.addPreference(createPresharedKeyPreference(c));
     42         super.loadExtraPreferencesTo(subpanel);
     43     }
     44 
     45     @Override
     46     public String validate() {
     47         String result = super.validate();
     48 
     49         return ((result != null) ? result : mPskHandler.validate());
     50     }
     51 
     52     private Preference createPresharedKeyPreference(Context c) {
     53         SecretHandler pskHandler = mPskHandler = new SecretHandler(c,
     54                 R.string.vpn_ipsec_presharedkey_title,
     55                 R.string.vpn_ipsec_presharedkey) {
     56             @Override
     57             protected String getSecretFromProfile() {
     58                 return ((L2tpIpsecPskProfile) getProfile()).getPresharedKey();
     59             }
     60 
     61             @Override
     62             protected void saveSecretToProfile(String secret) {
     63                 ((L2tpIpsecPskProfile) getProfile()).setPresharedKey(secret);
     64             }
     65         };
     66         return pskHandler.getPreference();
     67     }
     68 }
     69