1/* 2 * Copyright (C) 2013 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 17package com.android.exchange.eas; 18 19import com.android.exchange.EasResponse; 20import com.android.exchange.adapter.Serializer; 21import com.android.exchange.adapter.SettingsParser; 22import com.android.exchange.adapter.Tags; 23 24import org.apache.http.HttpEntity; 25 26import java.io.IOException; 27 28/** 29 * Performs an Exchange Settings request to the server to communicate our device information. 30 * While the settings command can be used for all sorts of things, we currently only use it to 31 * notify the server of our device information after a Provision command, and only for certain 32 * versions of the protocol (12.1 and 14.0; versions after 14.0 instead specify the device info 33 * in the provision command). 34 * 35 * See http://msdn.microsoft.com/en-us/library/ee202944(v=exchg.80).aspx for details on the Settings 36 * command in general. 37 * See http://msdn.microsoft.com/en-us/library/gg675476(v=exchg.80).aspx for details on the 38 * requirement for communicating device info for some versions of Exchange. 39 */ 40public class EasSettings extends EasOperation { 41 42 43 /** Result code indicating the Settings command succeeded. */ 44 private static final int RESULT_OK = 1; 45 46 public EasSettings(final EasOperation parentOperation) { 47 super(parentOperation); 48 } 49 50 public boolean sendDeviceInformation() { 51 return performOperation() == RESULT_OK; 52 } 53 54 @Override 55 protected String getCommand() { 56 return "Settings"; 57 } 58 59 @Override 60 protected HttpEntity getRequestEntity() throws IOException { 61 final Serializer s = new Serializer(); 62 s.start(Tags.SETTINGS_SETTINGS); 63 addDeviceInformationToSerializer(s); 64 s.end().done(); 65 return makeEntity(s); 66 } 67 68 @Override 69 protected int handleResponse(final EasResponse response) throws IOException { 70 return new SettingsParser(response.getInputStream()).parse() 71 ? RESULT_OK : RESULT_OTHER_FAILURE; 72 } 73 74} 75