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.EasSyncService;
     19 
     20 import java.io.IOException;
     21 import java.io.InputStream;
     22 
     23 /**
     24  * Parse the result of a Settings command.
     25  *
     26  * We only send the Settings command in EAS 14.0 after sending a Provision command for the first
     27  * time.  parse() returns true in the normal case; false if access to the account is denied due
     28  * to the actual settings (e.g. if a particular device type isn't allowed by the server)
     29  */
     30 public class SettingsParser extends Parser {
     31     private final EasSyncService mService;
     32 
     33     public SettingsParser(InputStream in, EasSyncService service) throws IOException {
     34         super(in);
     35         mService = service;
     36     }
     37 
     38     @Override
     39     public boolean parse() throws IOException {
     40         boolean res = false;
     41         if (nextTag(START_DOCUMENT) != Tags.SETTINGS_SETTINGS) {
     42             throw new IOException();
     43         }
     44         while (nextTag(START_DOCUMENT) != END_DOCUMENT) {
     45             if (tag == Tags.SETTINGS_STATUS) {
     46                 int status = getValueInt();
     47                 mService.userLog("Settings status = ", status);
     48                 if (status == 1) {
     49                     res = true;
     50                 } else {
     51                     // Access denied = 3; others should never be seen
     52                     res = false;
     53                 }
     54             } else if (tag == Tags.SETTINGS_DEVICE_INFORMATION) {
     55                 parseDeviceInformation();
     56             } else {
     57                 skipTag();
     58             }
     59         }
     60         return res;
     61     }
     62 
     63     public void parseDeviceInformation() throws IOException {
     64         while (nextTag(Tags.SETTINGS_DEVICE_INFORMATION) != END) {
     65             if (tag == Tags.SETTINGS_SET) {
     66                 parseSet();
     67             } else {
     68                 skipTag();
     69             }
     70         }
     71     }
     72 
     73     public void parseSet() throws IOException {
     74         while (nextTag(Tags.SETTINGS_SET) != END) {
     75             if (tag == Tags.SETTINGS_STATUS) {
     76                 mService.userLog("Set status = ", getValueInt());
     77             } else {
     78                 skipTag();
     79             }
     80         }
     81     }
     82 }
     83