1 /* 2 * Copyright (C) 2007 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 android.ddm; 18 19 import android.util.Log; 20 21 import org.apache.harmony.dalvik.ddmc.Chunk; 22 import org.apache.harmony.dalvik.ddmc.ChunkHandler; 23 import org.apache.harmony.dalvik.ddmc.DdmServer; 24 25 import java.nio.ByteBuffer; 26 27 /** 28 * Handle an EXIT chunk. 29 */ 30 public class DdmHandleExit extends DdmHandle { 31 32 public static final int CHUNK_EXIT = ChunkHandler.type("EXIT"); 33 34 private static DdmHandleExit mInstance = new DdmHandleExit(); 35 36 37 /* singleton, do not instantiate */ DdmHandleExit()38 private DdmHandleExit() {} 39 40 /** 41 * Register for the messages we're interested in. 42 */ register()43 public static void register() { 44 DdmServer.registerHandler(CHUNK_EXIT, mInstance); 45 } 46 47 /** 48 * Called when the DDM server connects. The handler is allowed to 49 * send messages to the server. 50 */ onConnected()51 public void onConnected() {} 52 53 /** 54 * Called when the DDM server disconnects. Can be used to disable 55 * periodic transmissions or clean up saved state. 56 */ onDisconnected()57 public void onDisconnected() {} 58 59 /** 60 * Handle a chunk of data. We're only registered for "EXIT". 61 */ handleChunk(Chunk request)62 public Chunk handleChunk(Chunk request) { 63 if (false) 64 Log.v("ddm-exit", "Handling " + name(request.type) + " chunk"); 65 66 /* 67 * Process the request. 68 */ 69 ByteBuffer in = wrapChunk(request); 70 71 int statusCode = in.getInt(); 72 73 Runtime.getRuntime().halt(statusCode); 74 75 // if that doesn't work, return an empty message 76 return null; 77 } 78 } 79 80