blob: 956078772ca85d25937a68eb9e42fd44f7033b7b [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.ddm;
18
Mathew Inwood28451832018-08-01 15:35:51 +010019import android.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import org.apache.harmony.dalvik.ddmc.Chunk;
21import org.apache.harmony.dalvik.ddmc.ChunkHandler;
22import org.apache.harmony.dalvik.ddmc.DdmServer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.util.Log;
24import java.nio.ByteBuffer;
25
26
27/**
28 * Track our app name. We don't (currently) handle any inbound packets.
29 */
30public class DdmHandleAppName extends ChunkHandler {
31
32 public static final int CHUNK_APNM = type("APNM");
33
34 private volatile static String mAppName = "";
35
36 private static DdmHandleAppName mInstance = new DdmHandleAppName();
37
38
39 /* singleton, do not instantiate */
40 private DdmHandleAppName() {}
41
42 /**
43 * Register for the messages we're interested in.
44 */
45 public static void register() {}
46
47 /**
48 * Called when the DDM server connects. The handler is allowed to
49 * send messages to the server.
50 */
51 public void connected() {}
52
53 /**
54 * Called when the DDM server disconnects. Can be used to disable
55 * periodic transmissions or clean up saved state.
56 */
57 public void disconnected() {}
58
59 /**
60 * Handle a chunk of data.
61 */
62 public Chunk handleChunk(Chunk request) {
63 return null;
64 }
65
66
67
68 /**
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
71 * an APNM message.
72 */
Mathew Inwood28451832018-08-01 15:35:51 +010073 @UnsupportedAppUsage
Siva Velusamyd693dfa2012-09-10 14:36:58 -070074 public static void setAppName(String name, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 if (name == null || name.length() == 0)
76 return;
77
78 mAppName = name;
79
80 // if DDMS is already connected, send the app name up
Siva Velusamyd693dfa2012-09-10 14:36:58 -070081 sendAPNM(name, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 }
83
Mathew Inwood28451832018-08-01 15:35:51 +010084 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 public static String getAppName() {
86 return mAppName;
87 }
88
89 /*
90 * Send an APNM (APplication NaMe) chunk.
91 */
Siva Velusamyd693dfa2012-09-10 14:36:58 -070092 private static void sendAPNM(String appName, int userId) {
Joe Onorato43a17652011-04-06 19:22:23 -070093 if (false)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 Log.v("ddm", "Sending app name");
95
Siva Velusamyd693dfa2012-09-10 14:36:58 -070096 ByteBuffer out = ByteBuffer.allocate(
97 4 /* appName's length */
98 + appName.length()*2 /* appName */
99 + 4 /* userId */);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 out.order(ChunkHandler.CHUNK_ORDER);
101 out.putInt(appName.length());
102 putString(out, appName);
Siva Velusamyd693dfa2012-09-10 14:36:58 -0700103 out.putInt(userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104
105 Chunk chunk = new Chunk(CHUNK_APNM, out);
106 DdmServer.sendChunk(chunk);
107 }
108
109}
110