2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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;
28 * Track our app name. We don't (currently) handle any inbound packets.
30 public class DdmHandleAppName extends ChunkHandler {
32 public static final int CHUNK_APNM = type("APNM");
34 private volatile static String mAppName = "";
36 private static DdmHandleAppName mInstance = new DdmHandleAppName();
39 /* singleton, do not instantiate */
40 private DdmHandleAppName() {}
43 * Register for the messages we're interested in.
45 public static void register() {}
48 * Called when the DDM server connects. The handler is allowed to
49 * send messages to the server.
51 public void connected() {}
54 * Called when the DDM server disconnects. Can be used to disable
55 * periodic transmissions or clean up saved state.
57 public void disconnected() {}
60 * Handle a chunk of data.
62 public Chunk handleChunk(Chunk request) {
69 * Set the application name. Called when we get named, which may be
70 * before or after DDMS connects. For the latter we need to send up
73 public static void setAppName(String name) {
74 if (name == null || name.length() == 0)
79 // if DDMS is already connected, send the app name up
83 public static String getAppName() {
88 * Send an APNM (APplication NaMe) chunk.
90 private static void sendAPNM(String appName) {
92 Log.v("ddm", "Sending app name");
94 ByteBuffer out = ByteBuffer.allocate(4 + appName.length()*2);
95 out.order(ChunkHandler.CHUNK_ORDER);
96 out.putInt(appName.length());
97 putString(out, appName);
99 Chunk chunk = new Chunk(CHUNK_APNM, out);
100 DdmServer.sendChunk(chunk);