1 /* 2 * Copyright (C) 2024 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 package com.android.nfc.utils; 17 18 import android.nfc.cardemulation.PollingFrame; 19 20 import com.google.android.mobly.snippet.SnippetObjectConverter; 21 22 import org.json.JSONException; 23 import org.json.JSONObject; 24 25 import java.lang.reflect.Type; 26 27 public class PollingFrameConverter implements SnippetObjectConverter { 28 @Override serialize(Object object)29 public JSONObject serialize(Object object) throws JSONException { 30 JSONObject result = new JSONObject(); 31 if (object instanceof PollingFrame) { 32 PollingFrame frame = (PollingFrame) object; 33 result.put("type", Character.toString(frame.getType())); 34 result.put("vendorSpecificGain", frame.getVendorSpecificGain()); 35 result.put("timestamp", frame.getTimestamp()); 36 result.put("data", HceUtils.getHexBytes(null, frame.getData()).replaceAll("\\s+", "")); 37 result.put("triggeredAutoTransact", frame.getTriggeredAutoTransact()); 38 return result; 39 } 40 return null; 41 } 42 43 @Override deserialize(JSONObject jsonObject, Type type)44 public Object deserialize(JSONObject jsonObject, Type type) throws JSONException { 45 // Not implemented 46 return null; 47 } 48 } 49