Home | History | Annotate | Download | only in adapter
      1 /* Copyright (C) 2011 The Android Open Source Project.
      2  *
      3  * Licensed under the Apache License, Version 2.0 (the "License");
      4  * you may not use this file except in compliance with the License.
      5  * You may obtain a copy of the License at
      6  *
      7  *      http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software
     10  * distributed under the License is distributed on an "AS IS" BASIS,
     11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12  * See the License for the specific language governing permissions and
     13  * limitations under the License.
     14  */
     15 
     16 package com.android.exchange.adapter;
     17 
     18 import com.android.exchange.Eas;
     19 import com.android.mail.utils.LogUtils;
     20 
     21 import java.io.IOException;
     22 import java.io.InputStream;
     23 
     24 /**
     25  * Parse the result of a Settings command.
     26  *
     27  * We only send the Settings command in EAS 14.0 after sending a Provision command for the first
     28  * time.  parse() returns true in the normal case; false if access to the account is denied due
     29  * to the actual settings (e.g. if a particular device type isn't allowed by the server)
     30  */
     31 public class SettingsParser extends Parser {
     32 
     33     private static final String TAG = Eas.LOG_TAG;
     34 
     35     public SettingsParser(InputStream in) throws IOException {
     36         super(in);
     37     }
     38 
     39     @Override
     40     public boolean parse() throws IOException {
     41         boolean res = false;
     42         if (nextTag(START_DOCUMENT) != Tags.SETTINGS_SETTINGS) {
     43             throw new IOException();
     44         }
     45         while (nextTag(START_DOCUMENT) != END_DOCUMENT) {
     46             if (tag == Tags.SETTINGS_STATUS) {
     47                 int status = getValueInt();
     48                 LogUtils.d(TAG, "Settings status = %d", status);
     49                 if (status == 1) {
     50                     res = true;
     51                 } else {
     52                     // Access denied = 3; others should never be seen
     53                     res = false;
     54                 }
     55             } else if (tag == Tags.SETTINGS_DEVICE_INFORMATION) {
     56                 parseDeviceInformation();
     57             } else {
     58                 skipTag();
     59             }
     60         }
     61         return res;
     62     }
     63 
     64     public void parseDeviceInformation() throws IOException {
     65         while (nextTag(Tags.SETTINGS_DEVICE_INFORMATION) != END) {
     66             if (tag == Tags.SETTINGS_SET) {
     67                 parseSet();
     68             } else {
     69                 skipTag();
     70             }
     71         }
     72     }
     73 
     74     public void parseSet() throws IOException {
     75         while (nextTag(Tags.SETTINGS_SET) != END) {
     76             if (tag == Tags.SETTINGS_STATUS) {
     77                 LogUtils.d(TAG, "Set status = %d", getValueInt());
     78             } else {
     79                 skipTag();
     80             }
     81         }
     82     }
     83 }
     84