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.
17 package com.android.ddmlib;
19 import java.io.IOException;
20 import java.nio.ByteBuffer;
23 * Handle the "app name" chunk (APNM).
25 final class HandleAppName extends ChunkHandler {
27 public static final int CHUNK_APNM = ChunkHandler.type("APNM");
29 private static final HandleAppName mInst = new HandleAppName();
32 private HandleAppName() {}
35 * Register for the packets we expect to get from the client.
37 public static void register(MonitorThread mt) {
38 mt.registerChunkHandler(CHUNK_APNM, mInst);
45 public void clientReady(Client client) throws IOException {}
51 public void clientDisconnected(Client client) {}
54 * Chunk handler entry point.
57 public void handleChunk(Client client, int type, ByteBuffer data,
58 boolean isReply, int msgId) {
60 Log.d("ddm-appname", "handling " + ChunkHandler.name(type));
62 if (type == CHUNK_APNM) {
64 handleAPNM(client, data);
66 handleUnknownChunk(client, type, data, isReply, msgId);
71 * Handle a reply to our APNM message.
73 private static void handleAPNM(Client client, ByteBuffer data) {
77 appNameLen = data.getInt();
78 appName = getString(data, appNameLen);
80 Log.d("ddm-appname", "APNM: app='" + appName + "'");
82 ClientData cd = client.getClientData();
84 cd.setClientDescription(appName);
87 client = checkDebuggerPortForAppName(client, appName);
90 client.update(Client.CHANGE_NAME);