1 /* 2 * Copyright (C) 2021 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 com.googlecode.android_scripting.facade.uwb; 18 19 import com.googlecode.android_scripting.jsonrpc.JsonSerializable; 20 21 import org.json.JSONException; 22 import org.json.JSONObject; 23 24 /** 25 * Utility class for Uwb. 26 */ 27 public class UwbEvents { 28 29 /** 30 * Translates a UWB adapter state event to JSON. 31 */ 32 public static class UwbAdapterStateEvent implements JsonSerializable { 33 private String mId; 34 private String mUwbAdapterStateEvent; 35 UwbAdapterStateEvent(String id, String event)36 public UwbAdapterStateEvent(String id, String event) { 37 mId = id; 38 mUwbAdapterStateEvent = event; 39 } 40 41 /** 42 * Create a JSON data-structure. 43 */ toJSON()44 public JSONObject toJSON() throws JSONException { 45 JSONObject uwbAdapterState = new JSONObject(); 46 47 uwbAdapterState.put(UwbConstants.UwbAdapterStateContainer.ID, mId); 48 uwbAdapterState.put( 49 UwbConstants.UwbAdapterStateContainer.UWB_ADAPTER_STATE_EVENT, 50 mUwbAdapterStateEvent); 51 52 return uwbAdapterState; 53 } 54 } 55 56 57 /** 58 * Translates a UWB ranging session event to JSON. 59 */ 60 public static class RangingSessionEvent implements JsonSerializable { 61 private String mId; 62 private String mRangingSessionEvent; 63 RangingSessionEvent(String id, String event)64 public RangingSessionEvent(String id, String event) { 65 mId = id; 66 mRangingSessionEvent = event; 67 } 68 69 /** 70 * Create a JSON data-structure. 71 */ toJSON()72 public JSONObject toJSON() throws JSONException { 73 JSONObject rangingSession = new JSONObject(); 74 75 rangingSession.put(UwbConstants.RangingSessionContainer.ID, mId); 76 rangingSession.put( 77 UwbConstants.RangingSessionContainer.RANGING_SESSION_EVENT, 78 mRangingSessionEvent); 79 80 return rangingSession; 81 } 82 } 83 } 84