1 /*
2  * Copyright (C) 2023 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.os;
18 
19 import android.os.DdmSyncState.Stage;
20 import android.util.Slog;
21 
22 import org.apache.harmony.dalvik.ddmc.Chunk;
23 import org.apache.harmony.dalvik.ddmc.ChunkHandler;
24 import org.apache.harmony.dalvik.ddmc.DdmServer;
25 
26 import java.nio.ByteBuffer;
27 
28 /**
29  * @hide
30  */
31 // Making it public so ActivityThread can access it.
32 public class DdmSyncStageUpdater {
33 
34     private static final String TAG = "DdmSyncStageUpdater";
35 
36     private static final int CHUNK_STAGE = ChunkHandler.type("STAG");
37 
38     /**
39      * @hide
40      */
DdmSyncStageUpdater()41     public DdmSyncStageUpdater() {
42     }
43 
44     /**
45      * @hide
46      */
47     // Making it public so ActivityThread can access it.
next(Stage stage)48     public synchronized void next(Stage stage) {
49         try {
50             DdmSyncState.next(stage);
51 
52             // Request DDMServer to send a STAG chunk
53             ByteBuffer data = ByteBuffer.allocate(Integer.BYTES);
54             data.putInt(stage.toInt());
55             Chunk stagChunk = new Chunk(CHUNK_STAGE, data);
56             DdmServer.sendChunk(stagChunk);
57         } catch (Exception e) {
58             // Catch everything to make sure we don't impact ActivityThread
59             Slog.w(TAG, "Unable to go to next stage" + stage, e);
60         }
61     }
62 
63 }
64