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