1 /* 2 * Copyright 2016 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 #include "hal_light.h" 18 19 #include <stdlib.h> 20 21 #include <iostream> 22 23 #include <hardware/lights.h> 24 25 #include "test/vts/proto/ComponentSpecificationMessage.pb.h" 26 27 #include "vts_datatype.h" 28 29 using namespace std; 30 31 namespace android { 32 namespace vts { 33 GenerateLightState()34light_state_t* GenerateLightState() { 35 if (RandomBool()) { 36 return NULL; 37 } else { 38 light_state_t* state = (light_state_t*)malloc(sizeof(light_state_t)); 39 40 state->color = RandomUint32(); 41 state->flashMode = RandomInt32(); 42 state->flashOnMS = RandomInt32(); 43 state->flashOffMS = RandomInt32(); 44 if (RandomBool()) { // normal values 45 if (RandomBool()) { 46 state->brightnessMode = BRIGHTNESS_MODE_USER; 47 } else { 48 state->brightnessMode = BRIGHTNESS_MODE_SENSOR; 49 } 50 } else { // abnormal values 51 state->brightnessMode = RandomInt32(); 52 } 53 54 return state; 55 } 56 } 57 GenerateLightStateUsingMessage(const VariableSpecificationMessage & msg)58light_state_t* GenerateLightStateUsingMessage( 59 const VariableSpecificationMessage& msg) { 60 cout << __func__ << " entry" << endl; 61 light_state_t* state = (light_state_t*)malloc(sizeof(light_state_t)); 62 63 // TODO: use a dict in the proto and handle when the key is missing (i.e., 64 // randomly generate that). 65 state->color = msg.struct_value(0).scalar_value().uint32_t(); 66 cout << __func__ << " color " << state->color << endl; 67 state->flashMode = msg.struct_value(1).scalar_value().int32_t(); 68 cout << __func__ << " flashMode " << state->flashMode << endl; 69 state->flashOnMS = msg.struct_value(2).scalar_value().int32_t(); 70 cout << __func__ << " flashOnMS " << state->flashOnMS << endl; 71 state->flashOffMS = msg.struct_value(3).scalar_value().int32_t(); 72 cout << __func__ << " flashOffMS " << state->flashOffMS << endl; 73 state->brightnessMode = msg.struct_value(4).scalar_value().int32_t(); 74 cout << __func__ << " brightnessMode " << state->brightnessMode << endl; 75 76 return state; 77 } 78 79 } // namespace vts 80 } // namespace android 81