├── Android.mk ├── BoardConfig.mk ├── audio ├── Android.mk ├── audio_hw.c ├── audio_hw.h ├── ril_interface.c └── ril_interface.h ├── bluetooth └── bdroid_buildcfg.h ├── configs ├── gps.xml ├── nfcee_access.xml ├── nfcee_access_debug.xml └── tiny_hw.xml ├── extract-files.sh ├── gps_daemon.sh ├── i9300.mk ├── include └── telephony │ └── ril.h ├── keylayout └── sec_touchkey.kl ├── libsamsung_symbols ├── Android.mk └── samsung_ril.cpp ├── libsensors ├── AccelSensor.cpp ├── AccelSensor.h ├── AkmSensor.cpp ├── AkmSensor.h ├── Android.mk ├── GyroSensor.cpp ├── GyroSensor.h ├── InputEventReader.cpp ├── InputEventReader.h ├── LightSensor.cpp ├── LightSensor.h ├── MODULE_LICENSE_APACHE2 ├── PressureSensor.cpp ├── PressureSensor.h ├── ProximitySensor.cpp ├── ProximitySensor.h ├── SensorBase.cpp ├── SensorBase.h ├── ak8973b.h ├── sensors.cpp └── sensors.h ├── lineage.dependencies ├── lineage.mk ├── overlay ├── frameworks │ └── base │ │ ├── core │ │ └── res │ │ │ └── res │ │ │ ├── values │ │ │ └── config.xml │ │ │ └── xml │ │ │ └── power_profile.xml │ │ └── packages │ │ └── SystemUI │ │ └── res │ │ └── values │ │ └── config.xml ├── packages │ └── apps │ │ └── Settings │ │ └── res │ │ └── values │ │ ├── bools.xml │ │ └── config.xml └── vendor │ └── cmsdk │ └── cm │ └── res │ └── res │ └── values │ └── config.xml ├── power ├── Android.mk ├── power.c └── power.h ├── proprietary-files.txt ├── ril └── telephony │ └── java │ └── com │ └── android │ └── internal │ └── telephony │ └── SamsungExynos4RIL.java ├── rootdir ├── fstab.smdk4x12 └── init.target.rc ├── selinux ├── audioserver.te ├── bluetooth.te ├── cpboot-daemon.te ├── device.te ├── domain.te ├── file.te ├── file_contexts ├── gpsd.te ├── hostapd.te ├── init.te ├── log.te ├── mediaserver.te ├── netd.te ├── nfc.te ├── platform_app.te ├── recovery.te ├── rild.te ├── service_contexts ├── servicemanager.te ├── surfaceflinger.te ├── sysinit.te ├── system_app.te ├── system_server.te ├── ueventd.te ├── untrusted_app.te ├── vold.te ├── wpa_supplicant.te └── zygote.te ├── setup-makefiles.sh ├── shims ├── Android.mk ├── libgps-shim │ ├── Android.mk │ ├── gps.c │ └── gps.h └── libsecril-shim │ ├── Android.mk │ └── secril-shim.c └── system.prop /Android.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2012 The CyanogenMod 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 | LOCAL_PATH := $(call my-dir) 18 | 19 | ifeq ($(TARGET_DEVICE),i9300) 20 | 21 | include $(call all-makefiles-under,$(LOCAL_PATH)) 22 | 23 | endif 24 | -------------------------------------------------------------------------------- /BoardConfig.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2012 The CyanogenMod 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 | include device/samsung/smdk4412-common/BoardCommonConfig.mk 17 | 18 | # Wifi 19 | WIFI_DRIVER_MODULE_PATH := 20 | 21 | # Bionic 22 | MALLOC_SVELTE := true 23 | TARGET_NEEDS_PLATFORM_TEXT_RELOCATIONS := true 24 | LIBART_IMG_BASE := 0x30000000 25 | 26 | # RIL 27 | BOARD_PROVIDES_LIBRIL := true 28 | BOARD_MODEM_TYPE := xmm6262 29 | TARGET_SPECIFIC_HEADER_PATH += device/samsung/i9300/include 30 | BOARD_GLOBAL_CFLAGS += -DDISABLE_ASHMEM_TRACKING 31 | BOARD_RIL_CLASS := ../../../device/samsung/i9300/ril 32 | 33 | # Graphics 34 | TARGET_REQUIRES_SYNCHRONOUS_SETSURFACE := true 35 | 36 | TW_THEME := portrait_mdpi 37 | 38 | # Bluetooth 39 | BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR := device/samsung/i9300/bluetooth 40 | 41 | # Kernel 42 | TARGET_KERNEL_SOURCE := kernel/samsung/kona 43 | TARGET_KERNEL_CONFIG := lineageos_i9300_defconfig 44 | 45 | # Cache 46 | BOARD_CACHEIMAGE_PARTITION_SIZE := 1048576 47 | BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := f2fs 48 | 49 | # Recovery 50 | TARGET_RECOVERY_FSTAB := device/samsung/i9300/rootdir/fstab.smdk4x12 51 | TARGET_RECOVERY_DENSITY := mdpi 52 | TARGET_USERIMAGES_USE_F2FS := true 53 | RECOVERY_FSTAB_VERSION := 2 54 | 55 | # PowerHAL 56 | TARGET_POWERHAL_VARIANT := pegasusq 57 | 58 | # Selinux 59 | BOARD_SEPOLICY_DIRS += \ 60 | device/samsung/i9300/selinux 61 | 62 | # assert 63 | TARGET_OTA_ASSERT_DEVICE := m0,i9300,GT-I9300 64 | -------------------------------------------------------------------------------- /audio/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2011 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := audio.primary.$(TARGET_BOOTLOADER_BOARD_NAME) 20 | LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw 21 | LOCAL_MODULE_TAGS := optional 22 | 23 | LOCAL_SRC_FILES := audio_hw.c ril_interface.c 24 | 25 | LOCAL_C_INCLUDES += \ 26 | external/tinyalsa/include \ 27 | external/expat/lib \ 28 | $(call include-path-for, audio-utils) \ 29 | $(call include-path-for, audio-effects) 30 | 31 | LOCAL_SHARED_LIBRARIES := liblog libcutils libtinyalsa libaudioutils libdl libexpat 32 | 33 | include $(BUILD_SHARED_LIBRARY) 34 | -------------------------------------------------------------------------------- /audio/audio_hw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * Copyright (C) 2012 Wolfson Microelectronics plc 4 | * Copyright (C) 2012 The CyanogenMod Project 5 | * Daniel Hillenbrand 6 | * Guillaume "XpLoDWilD" Lesniak 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | /* ALSA cards for WM1811 */ 22 | #define CARD_DEFAULT 0 23 | 24 | #define PORT_PLAYBACK 0 25 | #define PORT_MODEM 1 26 | #define PORT_BT 2 27 | #define PORT_CAPTURE 3 28 | 29 | #define PCM_WRITE pcm_write 30 | 31 | #define PLAYBACK_PERIOD_SIZE 880 32 | #define PLAYBACK_PERIOD_COUNT 8 33 | #define PLAYBACK_SHORT_PERIOD_COUNT 2 34 | 35 | #define CAPTURE_PERIOD_SIZE 1024 36 | #define CAPTURE_PERIOD_COUNT 4 37 | 38 | #define SHORT_PERIOD_SIZE 192 39 | 40 | // 41 | // deep buffer 42 | // 43 | /* screen on */ 44 | #define DEEP_BUFFER_SHORT_PERIOD_SIZE 1056 45 | #define PLAYBACK_DEEP_BUFFER_SHORT_PERIOD_COUNT 4 46 | /* screen off */ 47 | #define DEEP_BUFFER_LONG_PERIOD_SIZE 880 48 | #define PLAYBACK_DEEP_BUFFER_LONG_PERIOD_COUNT 8 49 | 50 | 51 | /* minimum sleep time in out_write() when write threshold is not reached */ 52 | #define MIN_WRITE_SLEEP_US 5000 53 | 54 | #define RESAMPLER_BUFFER_FRAMES (PLAYBACK_PERIOD_SIZE * 2) 55 | #define RESAMPLER_BUFFER_SIZE (4 * RESAMPLER_BUFFER_FRAMES) 56 | 57 | #define DEFAULT_OUT_SAMPLING_RATE 44100 58 | #define MM_LOW_POWER_SAMPLING_RATE 44100 59 | #define MM_FULL_POWER_SAMPLING_RATE 44100 60 | #define DEFAULT_IN_SAMPLING_RATE 44100 61 | 62 | /* sampling rate when using VX port for narrow band */ 63 | #define VX_NB_SAMPLING_RATE 8000 64 | /* sampling rate when using VX port for wide band */ 65 | #define VX_WB_SAMPLING_RATE 16000 66 | 67 | /* product-specific defines */ 68 | #define PRODUCT_DEVICE_PROPERTY "ro.product.device" 69 | #define PRODUCT_NAME_PROPERTY "ro.product.name" 70 | 71 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) 72 | 73 | #define STRING_TO_ENUM(string) { #string, string } 74 | 75 | struct string_to_enum { 76 | const char *name; 77 | uint32_t value; 78 | }; 79 | 80 | const struct string_to_enum out_channels_name_to_enum_table[] = { 81 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_STEREO), 82 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_5POINT1), 83 | STRING_TO_ENUM(AUDIO_CHANNEL_OUT_7POINT1), 84 | }; 85 | 86 | enum pcm_type { 87 | PCM_NORMAL = 0, 88 | PCM_SPDIF, 89 | PCM_HDMI, 90 | PCM_TOTAL, 91 | }; 92 | 93 | enum output_type { 94 | OUTPUT_DEEP_BUF, // deep PCM buffers output stream 95 | OUTPUT_LOW_LATENCY, // low latency output stream 96 | OUTPUT_HDMI, 97 | OUTPUT_TOTAL 98 | }; 99 | 100 | struct route_setting 101 | { 102 | char *ctl_name; 103 | int intval; 104 | char *strval; 105 | }; 106 | 107 | struct route_setting voicecall_default[] = { 108 | { .ctl_name = "DAC1L Mixer AIF1.1 Switch", .intval = 1, }, 109 | { .ctl_name = "DAC1R Mixer AIF1.1 Switch", .intval = 1, }, 110 | { .ctl_name = "AIF2ADCL DRC Switch", .intval = 0, }, 111 | { .ctl_name = "AIF2DACL Source", .intval = 0, }, 112 | { .ctl_name = "AIF2DACR Source", .intval = 0, }, 113 | { .ctl_name = "AIF2 Mode", .intval = 0, }, 114 | { .ctl_name = "DAC1L Mixer AIF1.1 Switch", .intval = 1, }, 115 | { .ctl_name = "DAC1R Mixer AIF1.1 Switch", .intval = 1, }, 116 | { .ctl_name = "DAC1L Mixer AIF2 Switch", .intval = 1, }, 117 | { .ctl_name = "DAC1R Mixer AIF2 Switch", .intval = 1, }, 118 | { .ctl_name = "AIF2DAC Mux", .strval = "AIF2DACDAT", }, 119 | { .ctl_name = NULL, }, 120 | }; 121 | 122 | struct route_setting voicecall_default_disable[] = { 123 | { .ctl_name = "DAC1L Mixer AIF2 Switch", .intval = 0, }, 124 | { .ctl_name = "DAC1R Mixer AIF2 Switch", .intval = 0, }, 125 | { .ctl_name = "AIF2DAC Mux", .strval = "AIF3DACDAT", }, 126 | { .ctl_name = "AIF2 Mode", .intval = 1, }, 127 | { .ctl_name = NULL, }, 128 | }; 129 | 130 | struct route_setting default_input[] = { 131 | { .ctl_name = "Main Mic Switch", .intval = 1, }, 132 | { .ctl_name = "AIF1ADCL Source", .intval = 0, }, 133 | { .ctl_name = "AIF2ADCL Source", .intval = 0, }, 134 | { .ctl_name = "MIXINL IN1L Switch", .intval = 1, }, 135 | { .ctl_name = "IN1L Volume", .intval = 25, }, 136 | { .ctl_name = "MIXINL IN1L Volume", .intval = 0, }, 137 | { .ctl_name = "AIF2ADC Volume", .intval = 96, }, 138 | { .ctl_name = "AIF2ADCL DRC Switch", .intval = 0, }, 139 | { .ctl_name = NULL, }, 140 | }; 141 | 142 | struct route_setting default_input_disable[] = { 143 | { .ctl_name = "Main Mic Switch", .intval = 0, }, 144 | { .ctl_name = "MIXINL IN1L Switch", .intval = 0, }, 145 | { .ctl_name = NULL, }, 146 | }; 147 | 148 | struct route_setting noise_suppression[] = { 149 | { .ctl_name = "Sub Mic Switch", .intval = 1, }, 150 | { .ctl_name = "IN1R Volume", .intval = 25, }, 151 | { .ctl_name = "MIXINR IN1R Switch", .intval = 1, }, 152 | { .ctl_name = "MIXINR IN1R Volume", .intval = 0, }, 153 | { .ctl_name = "AIF1ADCR Source", .intval = 1, }, 154 | { .ctl_name = NULL, }, 155 | }; 156 | 157 | struct route_setting noise_suppression_disable[] = { 158 | { .ctl_name = "Sub Mic Switch", .intval = 0, }, 159 | { .ctl_name = "MIXINR IN1R Switch", .intval = 0, }, 160 | { .ctl_name = "MIXINR IN1R Volume", .intval = 0, }, 161 | { .ctl_name = NULL, }, 162 | }; 163 | 164 | struct route_setting headset_input[] = { 165 | { .ctl_name = "AIF2DAC2L Mixer AIF2 Switch", .intval = 0, }, 166 | { .ctl_name = "AIF2DAC2R Mixer AIF2 Switch", .intval = 0, }, 167 | { .ctl_name = "Headphone ZC Switch", .intval = 0, }, 168 | { .ctl_name = "AIF1DAC1 Volume", .intval = 96, }, 169 | { .ctl_name = "AIF2DAC Volume", .intval = 96, }, 170 | { .ctl_name = "AIF1 Boost Volume", .intval = 0, }, 171 | { .ctl_name = "AIF2 Boost Volume", .intval = 0, }, 172 | { .ctl_name = "DAC1 Volume", .intval = 96, }, 173 | { .ctl_name = "Headphone Volume", .intval = 49, }, 174 | { .ctl_name = "MIXINL IN1L Switch", .intval = 0, }, 175 | { .ctl_name = "MIXINR IN1R Switch", .intval = 0, }, 176 | { .ctl_name = "Headset Mic Switch", .intval = 1, }, 177 | { .ctl_name = "AIF1ADCL Source", .intval = 0, }, 178 | { .ctl_name = "AIF1ADCR Source", .intval = 0, }, 179 | { .ctl_name = "AIF2ADCL Source", .intval = 0, }, 180 | { .ctl_name = "MIXINL IN2L Switch", .intval = 1, }, 181 | { .ctl_name = "IN2L Volume", .intval = 28, }, 182 | { .ctl_name = "MIXINL IN2L Volume", .intval = 0, }, 183 | { .ctl_name = "DAC2 Left Sidetone Volume", .intval = 12, }, 184 | { .ctl_name = "AIF2ADC Volume", .intval = 96, }, 185 | { .ctl_name = "AIF2ADCL DRC Switch", .intval = 0, }, 186 | { .ctl_name = NULL, }, 187 | }; 188 | 189 | struct route_setting headset_input_disable[] = { 190 | { .ctl_name = "Headset Mic Switch", .intval = 0, }, 191 | { .ctl_name = "MIXINL IN2L Switch", .intval = 0, }, 192 | { .ctl_name = NULL, }, 193 | }; 194 | 195 | struct route_setting bt_output[] = { 196 | { .ctl_name = "AIF1DAC1 Volume", .intval = 96, }, 197 | { .ctl_name = "AIF1 Boost Volume", .intval = 0, }, 198 | { .ctl_name = "DAC2 Volume", .intval = 96, }, 199 | { .ctl_name = "AIF2ADC Volume", .intval = 96, }, 200 | { .ctl_name = "DAC1L Mixer AIF1.1 Switch", .intval = 1, }, 201 | { .ctl_name = "DAC1R Mixer AIF1.1 Switch", .intval = 1, }, 202 | { .ctl_name = "AIF3ADC Mux", .intval = 1, }, 203 | { .ctl_name = "AIF2DAC2L Mixer AIF1.1 Switch", .intval = 1, }, 204 | { .ctl_name = "AIF2DAC2R Mixer AIF1.1 Switch", .intval = 1, }, 205 | { .ctl_name = "AIF2DAC Volume", .intval = 96, }, 206 | { .ctl_name = "MIXINL IN1L Volume", .intval = 1, }, 207 | { .ctl_name = "IN1L Volume", .intval = 28, }, 208 | { .ctl_name = "IN1R Volume", .intval = 28, }, 209 | { .ctl_name = "LINEOUT1N Switch", .intval = 0, }, 210 | { .ctl_name = "LINEOUT1P Switch", .intval = 0, }, 211 | { .ctl_name = "AIF1ADC1 HPF Switch", .intval = 0, }, 212 | { .ctl_name = "AIF2ADC HPF Mode", .intval = 3, }, 213 | { .ctl_name = "AIF2ADC HPF Switch", .intval = 1, }, 214 | { .ctl_name = "AIF2DAC Mux", .strval = "AIF2DACDAT", }, 215 | { .ctl_name = "AIF2DAC2R Mixer AIF2 Switch", .intval = 1, }, 216 | { .ctl_name = "AIF2DAC2L Mixer AIF2 Switch", .intval = 1, }, 217 | { .ctl_name = NULL, }, 218 | }; 219 | 220 | struct route_setting bt_input[] = { 221 | { .ctl_name = "AIF2ADC Mux", .intval = 1, }, 222 | { .ctl_name = "AIF1ADCL Source", .intval = 0, }, 223 | { .ctl_name = "AIF1ADCR Source", .intval = 1, }, 224 | { .ctl_name = "DAC1L Mixer AIF2 Switch", .intval = 1, }, 225 | { .ctl_name = "DAC1R Mixer AIF2 Switch", .intval = 1, }, 226 | { .ctl_name = "AIF1ADC1R Mixer AIF2 Switch", .intval = 1, }, 227 | { .ctl_name = "AIF1ADC1L Mixer AIF2 Switch", .intval = 1, }, 228 | { .ctl_name = "AIF1ADC1 Volume", .intval = 96, }, 229 | { .ctl_name = "AIF2DAC Volume", .intval = 96, }, 230 | { .ctl_name = NULL, }, 231 | }; 232 | 233 | struct route_setting bt_disable[] = { 234 | { .ctl_name = "AIF1DAC1 Volume", .intval = 96, }, 235 | { .ctl_name = "AIF1 Boost Volume", .intval = 0, }, 236 | { .ctl_name = "DAC2 Volume", .intval = 96, }, 237 | { .ctl_name = "AIF2ADC Volume", .intval = 96, }, 238 | { .ctl_name = "AIF2ADC Mux", .intval = 0, }, 239 | { .ctl_name = "MIXINL IN2L Volume", .intval = 0, }, 240 | { .ctl_name = "LINEOUT1N Switch", .intval = 1, }, 241 | { .ctl_name = "LINEOUT1P Switch", .intval = 1, }, 242 | { .ctl_name = "AIF2ADC HPF Mode", .intval = 0, }, 243 | { .ctl_name = "AIF2ADC HPF Switch", .intval = 0, }, 244 | { .ctl_name = "AIF2DAC2R Mixer AIF2 Switch", .intval = 0, }, 245 | { .ctl_name = "AIF2DAC2L Mixer AIF2 Switch", .intval = 0, }, 246 | { .ctl_name = "AIF1ADC1R Mixer AIF2 Switch", .intval = 0, }, 247 | { .ctl_name = "AIF1ADC1L Mixer AIF2 Switch", .intval = 0, }, 248 | { .ctl_name = NULL, }, 249 | }; 250 | -------------------------------------------------------------------------------- /audio/ril_interface.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 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 | #define ALOG_TAG "audio_hw_primary" 18 | /*#define ALOG_NDEBUG 0*/ 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include "ril_interface.h" 27 | 28 | #define VOLUME_STEPS_DEFAULT "5" 29 | #define VOLUME_STEPS_PROPERTY "ro.config.vc_call_vol_steps" 30 | 31 | /* Function pointers */ 32 | void *(*_ril_open_client)(void); 33 | int (*_ril_close_client)(void *); 34 | int (*_ril_connect)(void *); 35 | int (*_ril_is_connected)(void *); 36 | int (*_ril_disconnect)(void *); 37 | int (*_ril_set_call_volume)(void *, enum ril_sound_type, int); 38 | int (*_ril_set_call_audio_path)(void *, enum ril_audio_path); 39 | int (*_ril_set_call_clock_sync)(void *, enum ril_clock_state); 40 | int (*_ril_set_two_mic_control)(void *, enum ril_two_mic_device, enum ril_two_mic_state); 41 | int (*_ril_set_mic_mute)(void *, enum ril_mic_mute); 42 | int (*_ril_register_unsolicited_handler)(void *, int, void *); 43 | int (*_ril_get_wb_amr)(void *, void *); 44 | 45 | /* Audio WB AMR callback */ 46 | void (*_audio_set_wb_amr_callback)(void *, int); 47 | void *callback_data = NULL; 48 | 49 | void ril_register_set_wb_amr_callback(void *function, void *data) 50 | { 51 | _audio_set_wb_amr_callback = function; 52 | callback_data = data; 53 | } 54 | 55 | /* This is the callback function that the RIL uses to 56 | set the wideband AMR state */ 57 | static int ril_set_wb_amr_callback(void *ril_client, 58 | const void *data, 59 | size_t datalen) 60 | { 61 | int enable = ((int *)data)[0]; 62 | 63 | if (!callback_data || !_audio_set_wb_amr_callback) 64 | return -1; 65 | 66 | _audio_set_wb_amr_callback(callback_data, enable); 67 | 68 | return 0; 69 | } 70 | 71 | static int ril_connect_if_required(struct ril_handle *ril) 72 | { 73 | if (_ril_is_connected(ril->client)) 74 | return 0; 75 | 76 | if (_ril_connect(ril->client) != RIL_CLIENT_ERR_SUCCESS) { 77 | ALOGE("ril_connect() failed"); 78 | return -1; 79 | } 80 | 81 | /* get wb amr status to set pcm samplerate depending on 82 | wb amr status when ril is connected. */ 83 | if(_ril_get_wb_amr) 84 | _ril_get_wb_amr(ril->client, ril_set_wb_amr_callback); 85 | 86 | return 0; 87 | } 88 | 89 | int ril_open(struct ril_handle *ril) 90 | { 91 | char property[PROPERTY_VALUE_MAX]; 92 | 93 | if (!ril) 94 | return -1; 95 | 96 | ril->handle = dlopen(RIL_CLIENT_LIBPATH, RTLD_NOW); 97 | 98 | if (!ril->handle) { 99 | ALOGE("Cannot open '%s'", RIL_CLIENT_LIBPATH); 100 | return -1; 101 | } 102 | 103 | _ril_open_client = dlsym(ril->handle, "OpenClient_RILD"); 104 | _ril_close_client = dlsym(ril->handle, "CloseClient_RILD"); 105 | _ril_connect = dlsym(ril->handle, "Connect_RILD"); 106 | _ril_is_connected = dlsym(ril->handle, "isConnected_RILD"); 107 | _ril_disconnect = dlsym(ril->handle, "Disconnect_RILD"); 108 | _ril_set_call_volume = dlsym(ril->handle, "SetCallVolume"); 109 | _ril_set_call_audio_path = dlsym(ril->handle, "SetCallAudioPath"); 110 | _ril_set_call_clock_sync = dlsym(ril->handle, "SetCallClockSync"); 111 | _ril_set_two_mic_control = dlsym(ril->handle, "SetTwoMicControl"); 112 | _ril_set_mic_mute = dlsym(ril->handle, "SetMute"); 113 | _ril_register_unsolicited_handler = dlsym(ril->handle, 114 | "RegisterUnsolicitedHandler"); 115 | /* since this function is not supported in all RILs, don't require it */ 116 | _ril_get_wb_amr = dlsym(ril->handle, "GetWB_AMR"); 117 | 118 | if (!_ril_open_client || !_ril_close_client || !_ril_connect || 119 | !_ril_is_connected || !_ril_disconnect || !_ril_set_call_volume || 120 | !_ril_set_call_audio_path || !_ril_set_two_mic_control || !_ril_set_mic_mute || 121 | !_ril_set_call_clock_sync || !_ril_register_unsolicited_handler) { 122 | ALOGE("Cannot get symbols from '%s'", RIL_CLIENT_LIBPATH); 123 | dlclose(ril->handle); 124 | return -1; 125 | } 126 | 127 | ril->client = _ril_open_client(); 128 | if (!ril->client) { 129 | ALOGE("ril_open_client() failed"); 130 | dlclose(ril->handle); 131 | return -1; 132 | } 133 | 134 | /* register the wideband AMR callback */ 135 | _ril_register_unsolicited_handler(ril->client, RIL_UNSOL_WB_AMR_STATE, 136 | ril_set_wb_amr_callback); 137 | 138 | property_get(VOLUME_STEPS_PROPERTY, property, VOLUME_STEPS_DEFAULT); 139 | ril->volume_steps_max = atoi(property); 140 | /* this catches the case where VOLUME_STEPS_PROPERTY does not contain 141 | an integer */ 142 | if (ril->volume_steps_max == 0) 143 | ril->volume_steps_max = atoi(VOLUME_STEPS_DEFAULT); 144 | 145 | return 0; 146 | } 147 | 148 | int ril_close(struct ril_handle *ril) 149 | { 150 | if (!ril || !ril->handle || !ril->client) 151 | return -1; 152 | 153 | if ((_ril_disconnect(ril->client) != RIL_CLIENT_ERR_SUCCESS) || 154 | (_ril_close_client(ril->client) != RIL_CLIENT_ERR_SUCCESS)) { 155 | ALOGE("ril_disconnect() or ril_close_client() failed"); 156 | return -1; 157 | } 158 | 159 | dlclose(ril->handle); 160 | return 0; 161 | } 162 | 163 | int ril_set_call_volume(struct ril_handle *ril, enum ril_sound_type sound_type, 164 | float volume) 165 | { 166 | if (ril_connect_if_required(ril)) 167 | return 0; 168 | 169 | return _ril_set_call_volume(ril->client, sound_type, 170 | (int)(volume * ril->volume_steps_max)); 171 | } 172 | 173 | int ril_set_call_audio_path(struct ril_handle *ril, enum ril_audio_path path) 174 | { 175 | if (ril_connect_if_required(ril)) 176 | return 0; 177 | 178 | return _ril_set_call_audio_path(ril->client, path); 179 | } 180 | 181 | int ril_set_call_clock_sync(struct ril_handle *ril, enum ril_clock_state state) 182 | { 183 | if (ril_connect_if_required(ril)) 184 | return 0; 185 | 186 | return _ril_set_call_clock_sync(ril->client, state); 187 | } 188 | 189 | int ril_set_two_mic_control(struct ril_handle *ril, enum ril_two_mic_device device, enum ril_two_mic_state state) 190 | { 191 | if (ril_connect_if_required(ril)) 192 | return 0; 193 | 194 | return _ril_set_two_mic_control(ril->client, device, state); 195 | } 196 | 197 | int ril_set_mic_mute(struct ril_handle *ril, enum ril_mic_mute state) 198 | { 199 | if (ril_connect_if_required(ril)) 200 | return 0; 201 | 202 | return _ril_set_mic_mute(ril->client, state); 203 | } 204 | -------------------------------------------------------------------------------- /audio/ril_interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 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 | #ifndef RIL_INTERFACE_H 18 | #define RIL_INTERFACE_H 19 | 20 | #define RIL_CLIENT_LIBPATH "libsecril-client.so" 21 | 22 | #define RIL_CLIENT_ERR_SUCCESS 0 23 | #define RIL_CLIENT_ERR_AGAIN 1 24 | #define RIL_CLIENT_ERR_INIT 2 // Client is not initialized 25 | #define RIL_CLIENT_ERR_INVAL 3 // Invalid value 26 | #define RIL_CLIENT_ERR_CONNECT 4 // Connection error 27 | #define RIL_CLIENT_ERR_IO 5 // IO error 28 | #define RIL_CLIENT_ERR_RESOURCE 6 // Resource not available 29 | #define RIL_CLIENT_ERR_UNKNOWN 7 30 | 31 | #define RIL_OEM_UNSOL_RESPONSE_BASE 11000 // RIL response base index 32 | #define RIL_UNSOL_WB_AMR_STATE \ 33 | (RIL_OEM_UNSOL_RESPONSE_BASE + 17) // RIL AMR state index 34 | 35 | struct ril_handle 36 | { 37 | void *handle; 38 | void *client; 39 | int volume_steps_max; 40 | }; 41 | 42 | enum ril_sound_type { 43 | SOUND_TYPE_VOICE, 44 | SOUND_TYPE_SPEAKER, 45 | SOUND_TYPE_HEADSET, 46 | SOUND_TYPE_BTVOICE 47 | }; 48 | 49 | enum ril_audio_path { 50 | SOUND_AUDIO_PATH_HANDSET, 51 | SOUND_AUDIO_PATH_HEADSET, 52 | SOUND_AUDIO_PATH_SPEAKER, 53 | SOUND_AUDIO_PATH_BLUETOOTH, 54 | SOUND_AUDIO_PATH_BLUETOOTH_NO_NR, 55 | SOUND_AUDIO_PATH_HEADPHONE 56 | }; 57 | 58 | enum ril_clock_state { 59 | SOUND_CLOCK_STOP, 60 | SOUND_CLOCK_START 61 | }; 62 | 63 | enum ril_two_mic_device { 64 | AUDIENCE, 65 | FORTEMEDIA 66 | }; 67 | 68 | enum ril_two_mic_state { 69 | TWO_MIC_SOLUTION_OFF, 70 | TWO_MIC_SOLUTION_ON 71 | }; 72 | 73 | enum ril_mic_mute { 74 | MIC_UNMUTE, 75 | MIC_MUTE 76 | }; 77 | 78 | /* Function prototypes */ 79 | int ril_open(struct ril_handle *ril); 80 | int ril_close(struct ril_handle *ril); 81 | int ril_set_call_volume(struct ril_handle *ril, enum ril_sound_type sound_type, 82 | float volume); 83 | int ril_set_call_audio_path(struct ril_handle *ril, enum ril_audio_path path); 84 | int ril_set_call_clock_sync(struct ril_handle *ril, enum ril_clock_state state); 85 | void ril_register_set_wb_amr_callback(void *function, void *data); 86 | int ril_set_two_mic_control(struct ril_handle *ril, enum ril_two_mic_device device, enum ril_two_mic_state state); 87 | int ril_set_mic_mute(struct ril_handle *ril, enum ril_mic_mute state); 88 | #endif 89 | 90 | -------------------------------------------------------------------------------- /bluetooth/bdroid_buildcfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * Copyright (C) 2012 The CyanogenMod Project 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef _BDROID_BUILDCFG_H 19 | #define _BDROID_BUILDCFG_H 20 | 21 | #define BTM_DEF_LOCAL_NAME "GT-I9300" 22 | 23 | /* Defined if the kernel does not have support for CLOCK_BOOTTIME_ALARM */ 24 | #define KERNEL_MISSING_CLOCK_BOOTTIME_ALARM TRUE 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /configs/gps.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 40 | 41 | 49 | 50 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /configs/nfcee_access.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /configs/nfcee_access_debug.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /configs/tiny_hw.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | -------------------------------------------------------------------------------- /extract-files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (C) 2016 The CyanogenMod Project 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | 19 | export VENDOR=samsung 20 | export DEVICE=i9300 21 | 22 | ./../smdk4412-common/extract-files.sh $@ 23 | -------------------------------------------------------------------------------- /gps_daemon.sh: -------------------------------------------------------------------------------- 1 | #shellscript as this is the only way selinux will allow this to proceed 2 | /system/bin/glgps -c /system/etc/gps.xml 3 | -------------------------------------------------------------------------------- /i9300.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2012 The CyanogenMod 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 | LOCAL_PATH := device/samsung/i9300 18 | 19 | # Overlay 20 | DEVICE_PACKAGE_OVERLAYS += $(LOCAL_PATH)/overlay 21 | 22 | # Screen density 23 | PRODUCT_AAPT_CONFIG := normal 24 | PRODUCT_AAPT_PREF_CONFIG := xhdpi 25 | 26 | # Init files 27 | PRODUCT_COPY_FILES += \ 28 | $(LOCAL_PATH)/rootdir/fstab.smdk4x12:root/fstab.smdk4x12 \ 29 | $(LOCAL_PATH)/rootdir/init.target.rc:root/init.target.rc 30 | 31 | # Audio 32 | PRODUCT_COPY_FILES += \ 33 | $(LOCAL_PATH)/configs/tiny_hw.xml:system/etc/sound/m0 34 | 35 | # Sensors 36 | PRODUCT_PACKAGES += \ 37 | sensors.smdk4x12 38 | 39 | # Power 40 | PRODUCT_PACKAGES += \ 41 | power.smdk4x12 42 | 43 | # Gps 44 | PRODUCT_COPY_FILES += \ 45 | $(LOCAL_PATH)/configs/gps.xml:system/etc/gps.xml \ 46 | $(LOCAL_PATH)/gps_daemon.sh:system/bin/gps_daemon.sh 47 | 48 | PRODUCT_PACKAGES += \ 49 | gps.smdk4x12 50 | 51 | # Keylayout 52 | PRODUCT_COPY_FILES += \ 53 | $(LOCAL_PATH)/keylayout/sec_touchkey.kl:system/usr/keylayout/sec_touchkey.kl 54 | 55 | # Product specific Packages 56 | PRODUCT_PACKAGES += \ 57 | libsecril-client \ 58 | libsecril-client-sap \ 59 | SamsungServiceMode \ 60 | tinyplay 61 | 62 | # RIL 63 | PRODUCT_PACKAGES += \ 64 | libsamsung_symbols \ 65 | libsecril-shim 66 | 67 | # NFC 68 | PRODUCT_PACKAGES += \ 69 | nfc.exynos4 \ 70 | libnfc \ 71 | libnfc_jni \ 72 | Nfc \ 73 | Tag 74 | 75 | # Camera 76 | PRODUCT_PACKAGES += \ 77 | camera.smdk4x12 78 | 79 | # f2fs 80 | PRODUCT_PACKAGES += \ 81 | fibmap.f2fs \ 82 | fsck.f2fs \ 83 | mkfs.f2fs 84 | 85 | PRODUCT_COPY_FILES += \ 86 | frameworks/base/nfc-extras/com.android.nfc_extras.xml:system/etc/permissions/com.android.nfc_extras.xml \ 87 | frameworks/native/data/etc/android.hardware.nfc.xml:system/etc/permissions/android.hardware.nfc.xml 88 | 89 | # NFCEE access control 90 | ifeq ($(TARGET_BUILD_VARIANT),user) 91 | NFCEE_ACCESS_PATH := $(LOCAL_PATH)/configs/nfcee_access.xml 92 | else 93 | NFCEE_ACCESS_PATH := $(LOCAL_PATH)/configs/nfcee_access_debug.xml 94 | endif 95 | 96 | PRODUCT_COPY_FILES += \ 97 | $(NFCEE_ACCESS_PATH):system/etc/nfcee_access.xml 98 | 99 | PRODUCT_PACKAGES += \ 100 | com.android.nfc_extras 101 | 102 | # RIL 103 | PRODUCT_PROPERTY_OVERRIDES += \ 104 | ro.telephony.ril_class=SamsungExynos4RIL \ 105 | ro.telephony.call_ring.multiple=false \ 106 | ro.telephony.call_ring.delay=3000 107 | 108 | # These are the hardware-specific features 109 | PRODUCT_COPY_FILES += \ 110 | frameworks/native/data/etc/handheld_core_hardware.xml:system/etc/permissions/handheld_core_hardware.xml \ 111 | frameworks/native/data/etc/android.hardware.telephony.gsm.xml:system/etc/permissions/android.hardware.telephony.gsm.xml 112 | 113 | $(call inherit-product-if-exists, vendor/samsung/i9300/i9300-vendor.mk) 114 | -------------------------------------------------------------------------------- /keylayout/sec_touchkey.kl: -------------------------------------------------------------------------------- 1 | key 158 BACK VIRTUAL 2 | key 139 APP_SWITCH VIRTUAL 3 | -------------------------------------------------------------------------------- /libsamsung_symbols/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2015 The CyanogenMod Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_SRC_FILES := \ 20 | samsung_ril.cpp 21 | 22 | LOCAL_SHARED_LIBRARIES := libbinder 23 | 24 | LOCAL_MODULE := libsamsung_symbols 25 | LOCAL_MODULE_TAGS := optional 26 | LOCAL_MODULE_CLASS := SHARED_LIBRARIES 27 | 28 | include $(BUILD_SHARED_LIBRARY) 29 | -------------------------------------------------------------------------------- /libsamsung_symbols/samsung_ril.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The CyanogenMod 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 | /* status_t Parcel::writeString16 */ 18 | extern "C" int _ZN7android6Parcel13writeString16EPKDsj(); 19 | extern "C" int _ZN7android6Parcel13writeString16EPKtj() { 20 | return _ZN7android6Parcel13writeString16EPKDsj(); 21 | } 22 | -------------------------------------------------------------------------------- /libsensors/AccelSensor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | 32 | #include "AccelSensor.h" 33 | 34 | #define LOGTAG "AccelerometerSensor" 35 | 36 | // ioctls 37 | #define LSM330DLC_ACCEL_IOCTL_BASE 'a' 38 | #define LSM330DLC_ACCEL_IOCTL_SET_ENABLE \ 39 | _IOW(LSM330DLC_ACCEL_IOCTL_BASE, 9, int) 40 | 41 | 42 | /*****************************************************************************/ 43 | AccelSensor::AccelSensor() 44 | : SensorBase("/dev/acceleration", "accelerometer_sensor"), 45 | mEnabled(0), 46 | mInputReader(4), 47 | mHasPendingEvent(false) 48 | { 49 | 50 | mPendingEvent.version = sizeof(sensors_event_t); 51 | mPendingEvent.sensor = ID_A; 52 | mPendingEvent.type = SENSOR_TYPE_ACCELEROMETER; 53 | memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); 54 | 55 | if (data_fd) { 56 | strcpy(input_sysfs_path, "/sys/class/input/"); 57 | strcat(input_sysfs_path, input_name); 58 | strcat(input_sysfs_path, "/device/"); 59 | input_sysfs_path_len = strlen(input_sysfs_path); 60 | } 61 | } 62 | 63 | AccelSensor::~AccelSensor() { 64 | 65 | // ALOGD("AccelSensor::~AccelSensor()"); 66 | if (mEnabled) { 67 | enable(0, 0); 68 | } 69 | } 70 | 71 | int AccelSensor::setInitialState() { 72 | return 0; 73 | } 74 | 75 | int AccelSensor::enable(int32_t handle, int en) { 76 | int flags = en ? 1 : 0; 77 | int fd; 78 | if (flags != mEnabled) { 79 | strcpy(&input_sysfs_path[input_sysfs_path_len], "enable"); 80 | fd = open(input_sysfs_path, O_RDWR); 81 | if (fd >= 0) { 82 | write(fd, en == 1 ? "1" : "0", 2); 83 | close(fd); 84 | mEnabled = flags; 85 | setInitialState(); 86 | return 0; 87 | } 88 | return -1; 89 | } 90 | return 0; 91 | } 92 | 93 | 94 | bool AccelSensor::hasPendingEvents() const { 95 | /* FIXME probably here should be returning mEnabled but instead 96 | mHasPendingEvents. It does not work, so we cheat.*/ 97 | //ALOGD("AccelSensor::~hasPendingEvents %d", mHasPendingEvent ? 1 : 0 ); 98 | return mHasPendingEvent; 99 | } 100 | 101 | 102 | int AccelSensor::setDelay(int32_t handle, int64_t ns) 103 | { 104 | int fd; 105 | 106 | if (ns < 10000000) { 107 | ns = 10000000; // Minimum on stock 108 | } 109 | 110 | strcpy(&input_sysfs_path[input_sysfs_path_len], "poll_delay"); 111 | fd = open(input_sysfs_path, O_RDWR); 112 | if (fd >= 0) { 113 | char buf[80]; 114 | sprintf(buf, "%lld", ns); 115 | write(fd, buf, strlen(buf)+1); 116 | close(fd); 117 | return 0; 118 | } 119 | return -1; 120 | } 121 | 122 | 123 | int AccelSensor::readEvents(sensors_event_t* data, int count) 124 | { 125 | if (count < 1) 126 | return -EINVAL; 127 | 128 | if (mHasPendingEvent) { 129 | mHasPendingEvent = false; 130 | mPendingEvent.timestamp = getTimestamp(); 131 | *data = mPendingEvent; 132 | return mEnabled ? 1 : 0; 133 | } 134 | 135 | ssize_t n = mInputReader.fill(data_fd); 136 | if (n < 0) 137 | return n; 138 | int numEventReceived = 0; 139 | input_event const* event; 140 | 141 | while (count && mInputReader.readEvent(&event)) { 142 | int type = event->type; 143 | if (type == EV_REL) { 144 | float value = event->value; 145 | if (event->code == EVENT_TYPE_ACCEL_X) { 146 | mPendingEvent.acceleration.x = value * CONVERT_A_X; 147 | } else if (event->code == EVENT_TYPE_ACCEL_Y) { 148 | mPendingEvent.acceleration.y = value * CONVERT_A_Y; 149 | } else if (event->code == EVENT_TYPE_ACCEL_Z) { 150 | mPendingEvent.acceleration.z = value * CONVERT_A_Z; 151 | } 152 | } else if (type == EV_SYN) { 153 | mPendingEvent.timestamp = timevalToNano(event->time); 154 | if (mEnabled) { 155 | *data++ = mPendingEvent; 156 | count--; 157 | numEventReceived++; 158 | } 159 | } else { 160 | ALOGE("%s: unknown event (type=%d, code=%d)", LOGTAG, 161 | type, event->code); 162 | } 163 | 164 | mInputReader.next(); 165 | } 166 | return numEventReceived++; 167 | 168 | } 169 | -------------------------------------------------------------------------------- /libsensors/AccelSensor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef ANDROID_SMB380_SENSOR_H 18 | #define ANDROID_SMB380_SENSOR_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "sensors.h" 26 | #include "SensorBase.h" 27 | #include "InputEventReader.h" 28 | 29 | /*****************************************************************************/ 30 | 31 | 32 | struct smb380acc_t { 33 | short x, /**< holds x-axis acceleration data sign extended. Range -512 to 511. */ 34 | y, /**< holds y-axis acceleration data sign extended. Range -512 to 511. */ 35 | z; /**< holds z-axis acceleration data sign extended. Range -512 to 511. */ 36 | } ; 37 | 38 | /* smb ioctl command label */ 39 | #define IOCTL_SMB_GET_ACC_VALUE 0 40 | #define DCM_IOC_MAGIC 's' 41 | #define IOC_SET_ACCELEROMETER _IO (DCM_IOC_MAGIC, 0x64) 42 | #define BMA150_CALIBRATION _IOWR(DCM_IOC_MAGIC,48,short) 43 | 44 | #define SMB_POWER_OFF 0 45 | #define SMB_POWER_ON 1 46 | 47 | struct input_event; 48 | 49 | class AccelSensor : public SensorBase { 50 | int mEnabled; 51 | InputEventCircularReader mInputReader; 52 | sensors_event_t mPendingEvent; 53 | bool mHasPendingEvent; 54 | char input_sysfs_path[PATH_MAX]; 55 | int input_sysfs_path_len; 56 | // int mUinputDevice; 57 | 58 | int setInitialState(); 59 | 60 | public: 61 | AccelSensor(); 62 | virtual ~AccelSensor(); 63 | // virtual int createUinput(); 64 | virtual int readEvents(sensors_event_t* data, int count); 65 | virtual bool hasPendingEvents() const; 66 | virtual int setDelay(int32_t handle, int64_t ns); 67 | virtual int enable(int32_t handle, int enabled); 68 | }; 69 | 70 | /*****************************************************************************/ 71 | 72 | #endif // ANDROID_GYRO_SENSOR_H 73 | -------------------------------------------------------------------------------- /libsensors/AkmSensor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "ak8973b.h" 28 | 29 | #include 30 | #include "AkmSensor.h" 31 | 32 | 33 | /*****************************************************************************/ 34 | 35 | int (*akm_is_sensor_enabled)(uint32_t sensor_type); 36 | int (*akm_enable_sensor)(uint32_t sensor_type); 37 | int (*akm_disable_sensor)(uint32_t sensor_type); 38 | int (*akm_set_delay)(uint32_t sensor_type, uint64_t delay); 39 | 40 | int stub_is_sensor_enabled(uint32_t sensor_type) { 41 | return 0; 42 | } 43 | 44 | int stub_enable_disable_sensor(uint32_t sensor_type) { 45 | return -ENODEV; 46 | } 47 | 48 | int stub_set_delay(uint32_t sensor_type, uint64_t delay) { 49 | return -ENODEV; 50 | } 51 | 52 | AkmSensor::AkmSensor() 53 | : SensorBase(NULL, NULL), 54 | mEnabled(0), 55 | mPendingMask(0), 56 | mInputReader(32) 57 | { 58 | /* Open the library before opening the input device. The library 59 | * creates a uinput device. 60 | */ 61 | if (loadAKMLibrary() == 0) { 62 | data_name = "compass_sensor"; 63 | data_fd = openInput("compass_sensor"); 64 | } 65 | 66 | memset(mPendingEvents, 0, sizeof(mPendingEvents)); 67 | 68 | mPendingEvents[Accelerometer].version = sizeof(sensors_event_t); 69 | mPendingEvents[Accelerometer].sensor = ID_A; 70 | mPendingEvents[Accelerometer].type = SENSOR_TYPE_ACCELEROMETER; 71 | mPendingEvents[Accelerometer].acceleration.status = SENSOR_STATUS_UNRELIABLE; 72 | 73 | mPendingEvents[MagneticField].version = sizeof(sensors_event_t); 74 | mPendingEvents[MagneticField].sensor = ID_M; 75 | mPendingEvents[MagneticField].type = SENSOR_TYPE_MAGNETIC_FIELD; 76 | mPendingEvents[MagneticField].magnetic.status = SENSOR_STATUS_UNRELIABLE; 77 | 78 | // read the actual value of all sensors if they're enabled already 79 | struct input_absinfo absinfo; 80 | short flags = 0; 81 | 82 | if (akm_is_sensor_enabled(SENSOR_TYPE_ACCELEROMETER)) { 83 | mEnabled |= 1<= numSensors) 128 | return -EINVAL; 129 | 130 | int newState = en ? 1 : 0; 131 | int err = 0; 132 | 133 | if ((uint32_t(newState)<type; 227 | if (type == EV_REL) { 228 | processEvent(event->code, event->value); 229 | mInputReader.next(); 230 | } else if (type == EV_SYN) { 231 | int64_t time = timevalToNano(event->time); 232 | for (int j=0 ; count && mPendingMask && jcode); 249 | mInputReader.next(); 250 | } 251 | } 252 | return numEventReceived; 253 | } 254 | 255 | void AkmSensor::processEvent(int code, int value) 256 | { 257 | switch (code) { 258 | case EVENT_TYPE_MAGV_X: 259 | ALOGV("AkmSensor: MAGV_X =>%d", value); 260 | mPendingMask |= 1<%d", value); 265 | mPendingMask |= 1<%d", value); 270 | mPendingMask |= 1<%d", value); 275 | mPendingMask |= 1< 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | #include "sensors.h" 27 | #include "SensorBase.h" 28 | #include "InputEventReader.h" 29 | 30 | /*****************************************************************************/ 31 | 32 | struct input_event; 33 | 34 | class AkmSensor : public SensorBase { 35 | public: 36 | AkmSensor(); 37 | virtual ~AkmSensor(); 38 | 39 | enum { 40 | Accelerometer = 0, 41 | MagneticField = 1, 42 | numSensors 43 | }; 44 | 45 | virtual int setDelay(int32_t handle, int64_t ns); 46 | virtual int enable(int32_t handle, int enabled); 47 | virtual int readEvents(sensors_event_t* data, int count); 48 | void processEvent(int code, int value); 49 | 50 | private: 51 | int loadAKMLibrary(); 52 | int update_delay(); 53 | void *mLibAKM; 54 | uint32_t mEnabled; 55 | uint32_t mPendingMask; 56 | InputEventCircularReader mInputReader; 57 | sensors_event_t mPendingEvents[numSensors]; 58 | uint64_t mDelays[numSensors]; 59 | }; 60 | 61 | /*****************************************************************************/ 62 | 63 | #endif // ANDROID_AKM_SENSOR_H 64 | -------------------------------------------------------------------------------- /libsensors/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2008 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | LOCAL_PATH := $(call my-dir) 17 | 18 | ifneq ($(TARGET_SIMULATOR),true) 19 | 20 | # HAL module implemenation, not prelinked, and stored in 21 | # hw/..so 22 | include $(CLEAR_VARS) 23 | 24 | LOCAL_MODULE := sensors.$(TARGET_BOOTLOADER_BOARD_NAME) 25 | 26 | LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw 27 | 28 | LOCAL_MODULE_TAGS := optional 29 | 30 | LOCAL_CFLAGS := -DLOG_TAG=\"sensorscpp\" 31 | LOCAL_SRC_FILES := \ 32 | sensors.cpp \ 33 | SensorBase.cpp \ 34 | LightSensor.cpp \ 35 | ProximitySensor.cpp \ 36 | AkmSensor.cpp \ 37 | GyroSensor.cpp \ 38 | InputEventReader.cpp \ 39 | AccelSensor.cpp \ 40 | PressureSensor.cpp 41 | 42 | LOCAL_SHARED_LIBRARIES := liblog libcutils libdl 43 | LOCAL_PRELINK_MODULE := false 44 | 45 | include $(BUILD_SHARED_LIBRARY) 46 | 47 | endif # !TARGET_SIMULATOR 48 | -------------------------------------------------------------------------------- /libsensors/GyroSensor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "GyroSensor.h" 28 | 29 | #define LOGTAG "GyroSensor" 30 | 31 | #define FETCH_FULL_EVENT_BEFORE_RETURN 1 32 | #define IGNORE_EVENT_TIME 350000000 33 | /*****************************************************************************/ 34 | 35 | GyroSensor::GyroSensor() 36 | : SensorBase(NULL, "gyro_sensor"), 37 | mEnabled(0), 38 | mInputReader(4), 39 | mHasPendingEvent(false), 40 | mEnabledTime(0) 41 | { 42 | mPendingEvent.version = sizeof(sensors_event_t); 43 | mPendingEvent.sensor = ID_GY; 44 | mPendingEvent.type = SENSOR_TYPE_GYROSCOPE; 45 | memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); 46 | 47 | if (data_fd) { 48 | strcpy(input_sysfs_path, "/sys/class/input/"); 49 | strcat(input_sysfs_path, input_name); 50 | strcat(input_sysfs_path, "/device/"); 51 | input_sysfs_path_len = strlen(input_sysfs_path); 52 | enable(0, 1); 53 | } 54 | } 55 | 56 | GyroSensor::~GyroSensor() { 57 | if (mEnabled) { 58 | enable(0, 0); 59 | } 60 | } 61 | 62 | int GyroSensor::setInitialState() { 63 | struct input_absinfo absinfo_x; 64 | struct input_absinfo absinfo_y; 65 | struct input_absinfo absinfo_z; 66 | float value; 67 | if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_GYRO_X), &absinfo_x) && 68 | !ioctl(data_fd, EVIOCGABS(EVENT_TYPE_GYRO_X), &absinfo_y) && 69 | !ioctl(data_fd, EVIOCGABS(EVENT_TYPE_GYRO_X), &absinfo_z)) { 70 | value = absinfo_x.value; 71 | mPendingEvent.data[0] = value * CONVERT_GYRO_X; 72 | value = absinfo_x.value; 73 | mPendingEvent.data[1] = value * CONVERT_GYRO_Y; 74 | value = absinfo_x.value; 75 | mPendingEvent.data[2] = value * CONVERT_GYRO_Z; 76 | mHasPendingEvent = true; 77 | } 78 | return 0; 79 | } 80 | 81 | int GyroSensor::enable(int32_t handle, int en) { 82 | int flags = en ? 1 : 0; 83 | int fd; 84 | if (flags != mEnabled) { 85 | strcpy(&input_sysfs_path[input_sysfs_path_len], "enable"); 86 | fd = open(input_sysfs_path, O_RDWR); 87 | if (fd >= 0){ 88 | write(fd, en == 1 ? "1" : "0", 2); 89 | close(fd); 90 | mEnabled = flags; 91 | setInitialState(); 92 | 93 | return 0; 94 | } 95 | return -1; 96 | } 97 | return 0; 98 | } 99 | 100 | bool GyroSensor::hasPendingEvents() const { 101 | return mHasPendingEvent; 102 | } 103 | 104 | int GyroSensor::setDelay(int32_t handle, int64_t ns) 105 | { 106 | int fd; 107 | 108 | strcpy(&input_sysfs_path[input_sysfs_path_len], "poll_delay"); 109 | fd = open(input_sysfs_path, O_RDWR); 110 | if (fd >= 0) { 111 | char buf[80]; 112 | sprintf(buf, "%lld", ns); 113 | write(fd, buf, strlen(buf)+1); 114 | close(fd); 115 | return 0; 116 | } 117 | return -1; 118 | } 119 | 120 | int GyroSensor::readEvents(sensors_event_t* data, int count) 121 | { 122 | if (count < 1) 123 | return -EINVAL; 124 | 125 | if (mHasPendingEvent) { 126 | mHasPendingEvent = false; 127 | mPendingEvent.timestamp = getTimestamp(); 128 | *data = mPendingEvent; 129 | return mEnabled ? 1 : 0; 130 | } 131 | 132 | ssize_t n = mInputReader.fill(data_fd); 133 | if (n < 0) 134 | return n; 135 | 136 | int numEventReceived = 0; 137 | input_event const* event; 138 | 139 | #if FETCH_FULL_EVENT_BEFORE_RETURN 140 | again: 141 | #endif 142 | while (count && mInputReader.readEvent(&event)) { 143 | int type = event->type; 144 | if (type == EV_REL) { 145 | float value = event->value; 146 | if (event->code == EVENT_TYPE_GYRO_X) { 147 | mPendingEvent.data[0] = value * CONVERT_GYRO_X; 148 | } else if (event->code == EVENT_TYPE_GYRO_Y) { 149 | mPendingEvent.data[1] = value * CONVERT_GYRO_Y; 150 | } else if (event->code == EVENT_TYPE_GYRO_Z) { 151 | mPendingEvent.data[2] = value * CONVERT_GYRO_Z; 152 | } 153 | } else if (type == EV_SYN) { 154 | mPendingEvent.timestamp = timevalToNano(event->time); 155 | if (mEnabled) { 156 | if (mPendingEvent.timestamp >= mEnabledTime) { 157 | *data++ = mPendingEvent; 158 | numEventReceived++; 159 | } 160 | count--; 161 | } 162 | } else { 163 | ALOGE("%s: unknown event (type=%d, code=%d)", LOGTAG, 164 | type, event->code); 165 | } 166 | mInputReader.next(); 167 | } 168 | 169 | #if FETCH_FULL_EVENT_BEFORE_RETURN 170 | /* if we didn't read a complete event, see if we can fill and 171 | try again instead of returning with nothing and redoing poll. */ 172 | if (numEventReceived == 0 && mEnabled == 1) { 173 | n = mInputReader.fill(data_fd); 174 | if (n) 175 | goto again; 176 | } 177 | #endif 178 | 179 | return numEventReceived; 180 | } 181 | 182 | -------------------------------------------------------------------------------- /libsensors/GyroSensor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef ANDROID_GYRO_SENSOR_H 18 | #define ANDROID_GYRO_SENSOR_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "sensors.h" 26 | #include "SensorBase.h" 27 | #include "InputEventReader.h" 28 | 29 | /*****************************************************************************/ 30 | 31 | struct input_event; 32 | 33 | class GyroSensor : public SensorBase { 34 | int mEnabled; 35 | InputEventCircularReader mInputReader; 36 | sensors_event_t mPendingEvent; 37 | bool mHasPendingEvent; 38 | char input_sysfs_path[PATH_MAX]; 39 | int input_sysfs_path_len; 40 | int64_t mEnabledTime; 41 | 42 | int setInitialState(); 43 | 44 | public: 45 | GyroSensor(); 46 | virtual ~GyroSensor(); 47 | virtual int readEvents(sensors_event_t* data, int count); 48 | virtual bool hasPendingEvents() const; 49 | virtual int setDelay(int32_t handle, int64_t ns); 50 | virtual int enable(int32_t handle, int enabled); 51 | }; 52 | 53 | /*****************************************************************************/ 54 | 55 | #endif // ANDROID_GYRO_SENSOR_H 56 | -------------------------------------------------------------------------------- /libsensors/InputEventReader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include 29 | 30 | #include "InputEventReader.h" 31 | 32 | /*****************************************************************************/ 33 | 34 | struct input_event; 35 | 36 | InputEventCircularReader::InputEventCircularReader(size_t numEvents) 37 | : mBuffer(new input_event[numEvents * 2]), 38 | mBufferEnd(mBuffer + numEvents), 39 | mHead(mBuffer), 40 | mCurr(mBuffer), 41 | mFreeSpace(numEvents) 42 | { 43 | } 44 | 45 | InputEventCircularReader::~InputEventCircularReader() 46 | { 47 | delete [] mBuffer; 48 | } 49 | 50 | ssize_t InputEventCircularReader::fill(int fd) 51 | { 52 | size_t numEventsRead = 0; 53 | if (mFreeSpace) { 54 | const ssize_t nread = read(fd, mHead, mFreeSpace * sizeof(input_event)); 55 | if (nread<0 || nread % sizeof(input_event)) { 56 | // we got a partial event!! 57 | return nread<0 ? -errno : -EINVAL; 58 | } 59 | 60 | numEventsRead = nread / sizeof(input_event); 61 | if (numEventsRead) { 62 | mHead += numEventsRead; 63 | mFreeSpace -= numEventsRead; 64 | if (mHead > mBufferEnd) { 65 | size_t s = mHead - mBufferEnd; 66 | memcpy(mBuffer, mBufferEnd, s * sizeof(input_event)); 67 | mHead = mBuffer + s; 68 | } 69 | } 70 | } 71 | 72 | return numEventsRead; 73 | } 74 | 75 | ssize_t InputEventCircularReader::readEvent(input_event const** events) 76 | { 77 | *events = mCurr; 78 | ssize_t available = (mBufferEnd - mBuffer) - mFreeSpace; 79 | return available ? 1 : 0; 80 | } 81 | 82 | void InputEventCircularReader::next() 83 | { 84 | mCurr++; 85 | mFreeSpace++; 86 | if (mCurr >= mBufferEnd) { 87 | mCurr = mBuffer; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /libsensors/InputEventReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef ANDROID_INPUT_EVENT_READER_H 18 | #define ANDROID_INPUT_EVENT_READER_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | /*****************************************************************************/ 26 | 27 | struct input_event; 28 | 29 | class InputEventCircularReader 30 | { 31 | struct input_event* const mBuffer; 32 | struct input_event* const mBufferEnd; 33 | struct input_event* mHead; 34 | struct input_event* mCurr; 35 | ssize_t mFreeSpace; 36 | 37 | public: 38 | InputEventCircularReader(size_t numEvents); 39 | ~InputEventCircularReader(); 40 | ssize_t fill(int fd); 41 | ssize_t readEvent(input_event const** events); 42 | void next(); 43 | }; 44 | 45 | /*****************************************************************************/ 46 | 47 | #endif // ANDROID_INPUT_EVENT_READER_H 48 | -------------------------------------------------------------------------------- /libsensors/LightSensor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include "LightSensor.h" 29 | 30 | #define LOGTAG "LightSensor" 31 | 32 | // #define ALOG_NDEBUG 0 33 | 34 | /*****************************************************************************/ 35 | 36 | LightSensor::LightSensor() 37 | : SensorBase(NULL, "light_sensor"), 38 | mEnabled(0), 39 | mInputReader(4), 40 | mHasPendingEvent(false) 41 | { 42 | mPendingEvent.version = sizeof(sensors_event_t); 43 | mPendingEvent.sensor = ID_L; 44 | mPendingEvent.type = SENSOR_TYPE_LIGHT; 45 | memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); 46 | 47 | if (data_fd) { 48 | strcpy(input_sysfs_path, "/sys/class/input/"); 49 | strcat(input_sysfs_path, input_name); 50 | strcat(input_sysfs_path, "/device/"); 51 | input_sysfs_path_len = strlen(input_sysfs_path); 52 | enable(0, 1); 53 | } 54 | } 55 | 56 | LightSensor::~LightSensor() { 57 | if (mEnabled) { 58 | enable(0, 0); 59 | } 60 | } 61 | 62 | int LightSensor::setInitialState() { 63 | struct input_absinfo absinfo; 64 | if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_LIGHT), &absinfo)) { 65 | // make sure to report an event immediately 66 | mHasPendingEvent = true; 67 | mPendingEvent.light = absinfo.value; 68 | } 69 | return 0; 70 | } 71 | 72 | int LightSensor::setDelay(int32_t handle, int64_t ns) 73 | { 74 | int fd; 75 | 76 | strcpy(&input_sysfs_path[input_sysfs_path_len], "poll_delay"); 77 | fd = open(input_sysfs_path, O_RDWR); 78 | if (fd >= 0) { 79 | char buf[80]; 80 | sprintf(buf, "%lld", ns); 81 | write(fd, buf, strlen(buf)+1); 82 | close(fd); 83 | return 0; 84 | } 85 | return -1; 86 | } 87 | 88 | int LightSensor::enable(int32_t handle, int en) 89 | { 90 | int flags = en ? 1 : 0; 91 | int err; 92 | int fd; 93 | if (flags != mEnabled) { 94 | strcpy(&input_sysfs_path[input_sysfs_path_len], "enable"); 95 | fd = open(input_sysfs_path, O_RDWR); 96 | if (fd >= 0) { 97 | write(fd, en == 1 ? "1" : "0", 2); 98 | close(fd); 99 | mEnabled = flags; 100 | setInitialState(); 101 | return 0; 102 | } 103 | return -1; 104 | } 105 | return 0; 106 | } 107 | 108 | bool LightSensor::hasPendingEvents() const { 109 | return mHasPendingEvent; 110 | } 111 | 112 | int LightSensor::readEvents(sensors_event_t* data, int count) 113 | { 114 | if (count < 1) 115 | return -EINVAL; 116 | 117 | if (mHasPendingEvent) { 118 | mHasPendingEvent = false; 119 | mPendingEvent.timestamp = getTimestamp(); 120 | *data = mPendingEvent; 121 | return mEnabled ? 1 : 0; 122 | } 123 | 124 | ssize_t n = mInputReader.fill(data_fd); 125 | if (n < 0) 126 | return n; 127 | 128 | int numEventReceived = 0; 129 | input_event const* event; 130 | 131 | while (count && mInputReader.readEvent(&event)) { 132 | int type = event->type; 133 | if (type == EV_REL) { 134 | if (event->code == EVENT_TYPE_LIGHT) { 135 | mPendingEvent.light = event->value; 136 | } 137 | } else if (type == EV_SYN) { 138 | mPendingEvent.timestamp = timevalToNano(event->time); 139 | if (mEnabled) { 140 | *data++ = mPendingEvent; 141 | count--; 142 | numEventReceived++; 143 | } 144 | } else { 145 | ALOGE("%s: unknown event (type=%d, code=%d)", LOGTAG, 146 | type, event->code); 147 | } 148 | mInputReader.next(); 149 | } 150 | 151 | return numEventReceived; 152 | } 153 | -------------------------------------------------------------------------------- /libsensors/LightSensor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef ANDROID_LIGHT_SENSOR_H 18 | #define ANDROID_LIGHT_SENSOR_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "sensors.h" 26 | #include "SensorBase.h" 27 | #include "InputEventReader.h" 28 | 29 | /*****************************************************************************/ 30 | 31 | struct input_event; 32 | 33 | class LightSensor : public SensorBase { 34 | int mEnabled; 35 | InputEventCircularReader mInputReader; 36 | sensors_event_t mPendingEvent; 37 | bool mHasPendingEvent; 38 | char input_sysfs_path[PATH_MAX]; 39 | int input_sysfs_path_len; 40 | 41 | float indexToValue(size_t index) const; 42 | int setInitialState(); 43 | 44 | public: 45 | LightSensor(); 46 | virtual ~LightSensor(); 47 | virtual int readEvents(sensors_event_t* data, int count); 48 | virtual bool hasPendingEvents() const; 49 | virtual int setDelay(int32_t handle, int64_t ns); 50 | virtual int enable(int32_t handle, int enabled); 51 | }; 52 | 53 | /*****************************************************************************/ 54 | 55 | #endif // ANDROID_LIGHT_SENSOR_H 56 | -------------------------------------------------------------------------------- /libsensors/MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeamWin/android_device_samsung_i9300/3d41acaeda176b6aeb6a3a351486b833e1461478/libsensors/MODULE_LICENSE_APACHE2 -------------------------------------------------------------------------------- /libsensors/PressureSensor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include "PressureSensor.h" 29 | 30 | #define LOGTAG "PressureSensor" 31 | 32 | #define PRESSURE_CONVERT(x) (x/4096.0f) 33 | 34 | /*****************************************************************************/ 35 | 36 | PressureSensor::PressureSensor() 37 | : SensorBase(NULL, "barometer_sensor"), 38 | mEnabled(0), 39 | mInputReader(4), 40 | mHasPendingEvent(false) 41 | { 42 | mPendingEvent.version = sizeof(sensors_event_t); 43 | mPendingEvent.sensor = ID_PR; 44 | mPendingEvent.type = SENSOR_TYPE_PRESSURE; 45 | memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); 46 | 47 | if (data_fd) { 48 | strcpy(input_sysfs_path, "/sys/class/input/"); 49 | strcat(input_sysfs_path, input_name); 50 | strcat(input_sysfs_path, "/device/"); 51 | input_sysfs_path_len = strlen(input_sysfs_path); 52 | enable(0, 1); 53 | } 54 | } 55 | 56 | PressureSensor::~PressureSensor() { 57 | if (mEnabled) { 58 | enable(0, 0); 59 | } 60 | } 61 | 62 | int PressureSensor::setInitialState() { 63 | struct input_absinfo absinfo; 64 | if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_PRESSURE), &absinfo)) { 65 | // make sure to report an event immediately 66 | mHasPendingEvent = true; 67 | mPendingEvent.pressure = PRESSURE_CONVERT(absinfo.value); 68 | } 69 | return 0; 70 | } 71 | 72 | int PressureSensor::enable(int32_t handle, int en) { 73 | int flags = en ? 1 : 0; 74 | int fd; 75 | if (flags != mEnabled) { 76 | strcpy(&input_sysfs_path[input_sysfs_path_len], "enable"); 77 | fd = open(input_sysfs_path, O_RDWR); 78 | if (fd >= 0) { 79 | write(fd, flags == 1 ? "1" : "0", 2); 80 | close(fd); 81 | mEnabled = flags; 82 | setInitialState(); 83 | return 0; 84 | } 85 | 86 | return -1; 87 | } 88 | return 0; 89 | } 90 | 91 | bool PressureSensor::hasPendingEvents() const { 92 | return mHasPendingEvent; 93 | } 94 | 95 | int PressureSensor::setDelay(int32_t handle, int64_t delay) 96 | { 97 | int fd; 98 | if (delay < 10000000) 99 | delay = 10; 100 | else 101 | delay = delay / 1000000; 102 | strcpy(&input_sysfs_path[input_sysfs_path_len], "poll_delay"); 103 | fd = open(input_sysfs_path, O_RDWR); 104 | if (fd >= 0) { 105 | char buf[80]; 106 | sprintf(buf, "%lld", delay); 107 | write(fd, buf, strlen(buf)+1); 108 | close(fd); 109 | return 0; 110 | } 111 | return -1; 112 | } 113 | 114 | 115 | int PressureSensor::readEvents(sensors_event_t* data, int count) 116 | { 117 | if (count < 1) 118 | return -EINVAL; 119 | 120 | if (mHasPendingEvent) { 121 | mHasPendingEvent = false; 122 | mPendingEvent.timestamp = getTimestamp(); 123 | *data = mPendingEvent; 124 | return mEnabled ? 1 : 0; 125 | } 126 | 127 | ssize_t n = mInputReader.fill(data_fd); 128 | if (n < 0) 129 | return n; 130 | 131 | int numEventReceived = 0; 132 | input_event const* event; 133 | 134 | while (count && mInputReader.readEvent(&event)) { 135 | int type = event->type; 136 | if (type == EV_REL) { 137 | if (event->code == REL_X) { 138 | mPendingEvent.pressure = PRESSURE_CONVERT(event->value); 139 | } 140 | } else if (type == EV_SYN) { 141 | mPendingEvent.timestamp = timevalToNano(event->time); 142 | if (mEnabled) { 143 | *data++ = mPendingEvent; 144 | count--; 145 | numEventReceived++; 146 | } 147 | } else { 148 | ALOGE("%s: unknown event (type=%d, code=%d)", LOGTAG, 149 | type, event->code); 150 | } 151 | mInputReader.next(); 152 | } 153 | 154 | return numEventReceived; 155 | } 156 | -------------------------------------------------------------------------------- /libsensors/PressureSensor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef ANDROID_PRESSURE_SENSOR_H 18 | #define ANDROID_PRESSURE_SENSOR_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "sensors.h" 26 | #include "SensorBase.h" 27 | #include "InputEventReader.h" 28 | 29 | /*****************************************************************************/ 30 | 31 | struct input_event; 32 | 33 | class PressureSensor : public SensorBase { 34 | int mEnabled; 35 | InputEventCircularReader mInputReader; 36 | sensors_event_t mPendingEvent; 37 | bool mHasPendingEvent; 38 | char input_sysfs_path[PATH_MAX]; 39 | int input_sysfs_path_len; 40 | 41 | int setInitialState(); 42 | 43 | public: 44 | PressureSensor(); 45 | virtual ~PressureSensor(); 46 | virtual int readEvents(sensors_event_t* data, int count); 47 | virtual bool hasPendingEvents() const; 48 | virtual int enable(int32_t handle, int enabled); 49 | virtual int setDelay(int32_t handle, int64_t ns); 50 | }; 51 | 52 | /*****************************************************************************/ 53 | 54 | #endif // ANDROID_PRESSURE_SENSOR_H 55 | -------------------------------------------------------------------------------- /libsensors/ProximitySensor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #define ALOG_NDEBUG 0 27 | #define LOG_NDEBUG 0 28 | #include 29 | 30 | #include "ProximitySensor.h" 31 | #include "SensorBase.h" 32 | 33 | #define LOGTAG "ProximitySensor" 34 | 35 | /*****************************************************************************/ 36 | 37 | ProximitySensor::ProximitySensor() 38 | : SensorBase(NULL, "proximity_sensor"), 39 | mEnabled(0), 40 | mInputReader(4), 41 | mHasPendingEvent(false) 42 | { 43 | mPendingEvent.version = sizeof(sensors_event_t); 44 | mPendingEvent.sensor = ID_P; 45 | mPendingEvent.type = SENSOR_TYPE_PROXIMITY; 46 | memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); 47 | 48 | if (data_fd) { 49 | ALOGE("%s: got input_name %s", LOGTAG, input_name); 50 | strcpy(input_sysfs_path, "/sys/class/input/"); 51 | strcat(input_sysfs_path, input_name); 52 | strcat(input_sysfs_path, "/device/"); 53 | input_sysfs_path_len = strlen(input_sysfs_path); 54 | enable(0, 1); 55 | } 56 | } 57 | 58 | ProximitySensor::~ProximitySensor() { 59 | if (mEnabled) { 60 | enable(0, 0); 61 | } 62 | } 63 | 64 | int ProximitySensor::setInitialState() { 65 | struct input_absinfo absinfo; 66 | if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_PROXIMITY), &absinfo)) { 67 | // make sure to report an event immediately 68 | mHasPendingEvent = true; 69 | mPendingEvent.distance = indexToValue(absinfo.value); 70 | } 71 | return 0; 72 | } 73 | 74 | int ProximitySensor::setDelay(int32_t handle, int64_t ns) 75 | { 76 | // unsupported 77 | return 0; 78 | } 79 | 80 | int ProximitySensor::enable(int32_t handle, int en) { 81 | int fd; 82 | int flags = en ? 1 : 0; 83 | int err; 84 | ALOGD("%s: Enable: %i", __func__, en); 85 | if (flags != mEnabled) { 86 | strcpy(&input_sysfs_path[input_sysfs_path_len], "enable"); 87 | fd = open(input_sysfs_path, O_RDWR); 88 | if (fd >= 0) { 89 | write(fd, en == 1 ? "1" : "0", 2); 90 | close(fd); 91 | mEnabled = flags; 92 | setInitialState(); 93 | return 0; 94 | } 95 | 96 | return -1; 97 | } 98 | return 0; 99 | } 100 | 101 | bool ProximitySensor::hasPendingEvents() const { 102 | return mHasPendingEvent; 103 | } 104 | 105 | int ProximitySensor::readEvents(sensors_event_t* data, int count) 106 | { 107 | if (count < 1) 108 | return -EINVAL; 109 | 110 | if (mHasPendingEvent) { 111 | mHasPendingEvent = false; 112 | mPendingEvent.timestamp = getTimestamp(); 113 | *data = mPendingEvent; 114 | return mEnabled ? 1 : 0; 115 | } 116 | 117 | ssize_t n = mInputReader.fill(data_fd); 118 | if (n < 0) 119 | return n; 120 | 121 | int numEventReceived = 0; 122 | input_event const* event; 123 | 124 | while (count && mInputReader.readEvent(&event)) { 125 | int type = event->type; 126 | if (type == EV_ABS) { 127 | if (event->code == EVENT_TYPE_PROXIMITY) { 128 | if (event->value != -1) { 129 | // FIXME: not sure why we're getting -1 sometimes 130 | mPendingEvent.distance = indexToValue(event->value); 131 | } 132 | } 133 | } else if (type == EV_SYN) { 134 | mPendingEvent.timestamp = timevalToNano(event->time); 135 | if (mEnabled) { 136 | *data++ = mPendingEvent; 137 | count--; 138 | numEventReceived++; 139 | } 140 | } else { 141 | ALOGE("%s: unknown event (type=%d, code=%d)",LOGTAG, 142 | type, event->code); 143 | } 144 | mInputReader.next(); 145 | } 146 | 147 | return numEventReceived; 148 | } 149 | 150 | float ProximitySensor::indexToValue(size_t index) const 151 | { 152 | ALOGV("%s: Index = %zu",LOGTAG, index); 153 | return index * PROXIMITY_THRESHOLD_CM; 154 | } 155 | -------------------------------------------------------------------------------- /libsensors/ProximitySensor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef ANDROID_PROXIMITY_SENSOR_H 18 | #define ANDROID_PROXIMITY_SENSOR_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "sensors.h" 26 | #include "SensorBase.h" 27 | #include "InputEventReader.h" 28 | 29 | /*****************************************************************************/ 30 | 31 | struct input_event; 32 | 33 | class ProximitySensor : public SensorBase { 34 | int mEnabled; 35 | InputEventCircularReader mInputReader; 36 | sensors_event_t mPendingEvent; 37 | bool mHasPendingEvent; 38 | char input_sysfs_path[PATH_MAX]; 39 | int input_sysfs_path_len; 40 | 41 | int setInitialState(); 42 | float indexToValue(size_t index) const; 43 | 44 | public: 45 | ProximitySensor(); 46 | virtual ~ProximitySensor(); 47 | virtual int readEvents(sensors_event_t* data, int count); 48 | virtual bool hasPendingEvents() const; 49 | virtual int enable(int32_t handle, int enabled); 50 | virtual int setDelay(int32_t handle, int64_t ns); 51 | }; 52 | 53 | /*****************************************************************************/ 54 | 55 | #endif // ANDROID_PROXIMITY_SENSOR_H 56 | -------------------------------------------------------------------------------- /libsensors/SensorBase.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include 30 | 31 | #include "SensorBase.h" 32 | 33 | /*****************************************************************************/ 34 | 35 | SensorBase::SensorBase( 36 | const char* dev_name, 37 | const char* data_name) 38 | : dev_name(dev_name), data_name(data_name), 39 | dev_fd(-1), data_fd(-1) 40 | { 41 | if (data_name) { 42 | data_fd = openInput(data_name); 43 | } 44 | } 45 | 46 | SensorBase::~SensorBase() { 47 | if (data_fd >= 0) { 48 | close(data_fd); 49 | } 50 | if (dev_fd >= 0) { 51 | close(dev_fd); 52 | } 53 | } 54 | 55 | int SensorBase::open_device() { 56 | if (dev_fd<0 && dev_name) { 57 | dev_fd = open(dev_name, O_RDONLY); 58 | ALOGE_IF(dev_fd<0, "Couldn't open %s (%s)", dev_name, strerror(errno)); 59 | } 60 | return 0; 61 | } 62 | 63 | int SensorBase::close_device() { 64 | if (dev_fd >= 0) { 65 | close(dev_fd); 66 | dev_fd = -1; 67 | } 68 | return 0; 69 | } 70 | 71 | int SensorBase::getFd() const { 72 | if (!data_name) { 73 | return dev_fd; 74 | } 75 | return data_fd; 76 | } 77 | 78 | int SensorBase::setDelay(int32_t handle, int64_t ns) { 79 | return 0; 80 | } 81 | 82 | bool SensorBase::hasPendingEvents() const { 83 | return false; 84 | } 85 | 86 | int64_t SensorBase::getTimestamp() { 87 | struct timespec t; 88 | t.tv_sec = t.tv_nsec = 0; 89 | clock_gettime(CLOCK_BOOTTIME, &t); 90 | return int64_t(t.tv_sec)*1000000000LL + t.tv_nsec; 91 | } 92 | 93 | int SensorBase::openInput(const char* inputName) { 94 | int fd = -1; 95 | const char *dirname = "/dev/input"; 96 | char devname[PATH_MAX]; 97 | char *filename; 98 | DIR *dir; 99 | struct dirent *de; 100 | dir = opendir(dirname); 101 | if(dir == NULL) 102 | return -1; 103 | strcpy(devname, dirname); 104 | filename = devname + strlen(devname); 105 | *filename++ = '/'; 106 | while((de = readdir(dir))) { 107 | if(de->d_name[0] == '.' && 108 | (de->d_name[1] == '\0' || 109 | (de->d_name[1] == '.' && de->d_name[2] == '\0'))) 110 | continue; 111 | strcpy(filename, de->d_name); 112 | fd = open(devname, O_RDONLY); 113 | if (fd>=0) { 114 | char name[80]; 115 | if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) { 116 | name[0] = '\0'; 117 | } 118 | if (!strcmp(name, inputName)) { 119 | strcpy(input_name, filename); 120 | break; 121 | } else { 122 | close(fd); 123 | fd = -1; 124 | } 125 | } 126 | } 127 | closedir(dir); 128 | ALOGE_IF(fd<0, "couldn't find '%s' input device", inputName); 129 | 130 | return fd; 131 | } 132 | 133 | int SensorBase::batch(int handle, int flags, int64_t period_ns, int64_t timeout) 134 | { 135 | return 0; 136 | } 137 | 138 | int SensorBase::flush(int handle) 139 | { 140 | return 0; 141 | } 142 | -------------------------------------------------------------------------------- /libsensors/SensorBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef ANDROID_SENSOR_BASE_H 18 | #define ANDROID_SENSOR_BASE_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "sensors.h" 26 | 27 | 28 | /*****************************************************************************/ 29 | 30 | struct sensors_event_t; 31 | 32 | class SensorBase { 33 | protected: 34 | const char* dev_name; 35 | const char* data_name; 36 | char input_name[PATH_MAX]; 37 | int dev_fd; 38 | int data_fd; 39 | 40 | int openInput(const char* inputName); 41 | static int64_t getTimestamp(); 42 | 43 | 44 | static int64_t timevalToNano(timeval const& t) { 45 | return t.tv_sec*1000000000LL + t.tv_usec*1000; 46 | } 47 | 48 | int open_device(); 49 | int close_device(); 50 | 51 | public: 52 | SensorBase( 53 | const char* dev_name, 54 | const char* data_name); 55 | 56 | virtual ~SensorBase(); 57 | 58 | virtual int readEvents(sensors_event_t* data, int count) = 0; 59 | virtual bool hasPendingEvents() const; 60 | virtual int getFd() const; 61 | virtual int setDelay(int32_t handle, int64_t ns); 62 | virtual int enable(int32_t handle, int enabled) = 0; 63 | virtual int batch(int handle, int flags, int64_t period_ns, int64_t timeout); 64 | virtual int flush(int handle); 65 | 66 | }; 67 | 68 | /*****************************************************************************/ 69 | 70 | #endif // ANDROID_SENSOR_BASE_H 71 | -------------------------------------------------------------------------------- /libsensors/ak8973b.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Definitions for akm8973 compass chip. 3 | */ 4 | #ifndef AKM8973_H 5 | #define AKM8973_H 6 | 7 | #include 8 | 9 | #define AKM8973_I2C_NAME "ak8973b" 10 | 11 | #define AKMIO 0xA1 12 | 13 | /* IOCTLs for AKM library */ 14 | #define ECS_IOCTL_WRITE _IOW(AKMIO, 0x01, char*) 15 | #define ECS_IOCTL_READ _IOWR(AKMIO, 0x02, char*) 16 | #define ECS_IOCTL_RESET _IO(AKMIO, 0x03) 17 | #define ECS_IOCTL_SET_MODE _IOW(AKMIO, 0x04, short) 18 | #define ECS_IOCTL_GETDATA _IOR(AKMIO, 0x05, char[SENSOR_DATA_SIZE]) 19 | #define ECS_IOCTL_SET_YPR _IOW(AKMIO, 0x06, short[12]) 20 | #define ECS_IOCTL_GET_OPEN_STATUS _IOR(AKMIO, 0x07, int) 21 | #define ECS_IOCTL_GET_CLOSE_STATUS _IOR(AKMIO, 0x08, int) 22 | #define ECS_IOCTL_GET_DELAY _IOR(AKMIO, 0x30, int64_t) 23 | #define ECS_IOCTL_GET_PROJECT_NAME _IOR(AKMIO, 0x0D, char[64]) 24 | #define ECS_IOCTL_GET_MATRIX _IOR(AKMIO, 0x0E, short [4][3][3]) 25 | 26 | /* IOCTLs for APPs */ 27 | #define ECS_IOCTL_APP_SET_MODE _IOW(AKMIO, 0x10, short) 28 | #define ECS_IOCTL_APP_SET_MFLAG _IOW(AKMIO, 0x11, short) 29 | #define ECS_IOCTL_APP_GET_MFLAG _IOW(AKMIO, 0x12, short) 30 | #define ECS_IOCTL_APP_SET_AFLAG _IOW(AKMIO, 0x13, short) 31 | #define ECS_IOCTL_APP_GET_AFLAG _IOR(AKMIO, 0x14, short) 32 | #define ECS_IOCTL_APP_SET_TFLAG _IOR(AKMIO, 0x15, short) 33 | #define ECS_IOCTL_APP_GET_TFLAG _IOR(AKMIO, 0x16, short) 34 | #define ECS_IOCTL_APP_RESET_PEDOMETER _IO(AKMIO, 0x17) 35 | #define ECS_IOCTL_APP_SET_DELAY _IOW(AKMIO, 0x18, int64_t) 36 | #define ECS_IOCTL_APP_GET_DELAY ECS_IOCTL_GET_DELAY 37 | 38 | /* Set raw magnetic vector flag */ 39 | #define ECS_IOCTL_APP_SET_MVFLAG _IOW(AKMIO, 0x19, short) 40 | 41 | /* Get raw magnetic vector flag */ 42 | #define ECS_IOCTL_APP_GET_MVFLAG _IOR(AKMIO, 0x1A, short) 43 | 44 | struct akm8973_platform_data { 45 | short layouts[4][3][3]; 46 | char project_name[64]; 47 | int gpio_RST; 48 | int gpio_INT; 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /libsensors/sensors.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #define ALOG_TAG "Sensors" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | #include "sensors.h" 35 | 36 | #include "LightSensor.h" 37 | #include "ProximitySensor.h" 38 | #include "AkmSensor.h" 39 | #include "GyroSensor.h" 40 | #include "AccelSensor.h" 41 | #include "PressureSensor.h" 42 | 43 | /*****************************************************************************/ 44 | 45 | #define DELAY_OUT_TIME 0x7FFFFFFF 46 | 47 | #define LIGHT_SENSOR_POLLTIME 2000000000 48 | 49 | 50 | #define SENSORS_ACCELERATION (1<getFd(); 195 | mPollFds[light].events = POLLIN; 196 | mPollFds[light].revents = 0; 197 | 198 | mSensors[proximity] = new ProximitySensor(); 199 | mPollFds[proximity].fd = mSensors[proximity]->getFd(); 200 | mPollFds[proximity].events = POLLIN; 201 | mPollFds[proximity].revents = 0; 202 | 203 | mSensors[akm] = new AkmSensor(); 204 | mPollFds[akm].fd = mSensors[akm]->getFd(); 205 | mPollFds[akm].events = POLLIN; 206 | mPollFds[akm].revents = 0; 207 | 208 | mSensors[gyro] = new GyroSensor(); 209 | mPollFds[gyro].fd = mSensors[gyro]->getFd(); 210 | mPollFds[gyro].events = POLLIN; 211 | mPollFds[gyro].revents = 0; 212 | 213 | mSensors[accel] = new AccelSensor(); 214 | mPollFds[accel].fd = mSensors[accel]->getFd(); 215 | mPollFds[accel].events = POLLIN; 216 | mPollFds[accel].revents = 0; 217 | 218 | mSensors[pressure] = new PressureSensor(); 219 | mPollFds[pressure].fd = mSensors[pressure]->getFd(); 220 | mPollFds[pressure].events = POLLIN; 221 | mPollFds[pressure].revents = 0; 222 | 223 | int wakeFds[2]; 224 | int result = pipe(wakeFds); 225 | ALOGE_IF(result<0, "error creating wake pipe (%s)", strerror(errno)); 226 | fcntl(wakeFds[0], F_SETFL, O_NONBLOCK); 227 | fcntl(wakeFds[1], F_SETFL, O_NONBLOCK); 228 | mWritePipeFd = wakeFds[1]; 229 | 230 | mPollFds[wake].fd = wakeFds[0]; 231 | mPollFds[wake].events = POLLIN; 232 | mPollFds[wake].revents = 0; 233 | mInitialized = true; 234 | } 235 | 236 | sensors_poll_context_t::~sensors_poll_context_t() { 237 | for (int i=0 ; ienable(handle, enabled); 251 | if (enabled && !err) { 252 | const char wakeMessage(WAKE_MESSAGE); 253 | int result = write(mWritePipeFd, &wakeMessage, 1); 254 | ALOGE_IF(result<0, "error sending wake message (%s)", strerror(errno)); 255 | } 256 | return err; 257 | } 258 | 259 | int sensors_poll_context_t::setDelay(int handle, int64_t ns) { 260 | 261 | int index = handleToDriver(handle); 262 | if (index < 0) return index; 263 | return mSensors[index]->setDelay(handle, ns); 264 | } 265 | 266 | int sensors_poll_context_t::pollEvents(sensors_event_t* data, int count) 267 | { 268 | int nbEvents = 0; 269 | int n = 0; 270 | 271 | do { 272 | // see if we have some leftover from the last poll() 273 | for (int i=0 ; count && ihasPendingEvents())) { 276 | int nb = sensor->readEvents(data, count); 277 | if (nb < count) { 278 | // no more data for this sensor 279 | mPollFds[i].revents = 0; 280 | } 281 | count -= nb; 282 | nbEvents += nb; 283 | data += nb; 284 | } 285 | } 286 | 287 | if (count) { 288 | // we still have some room, so try to see if we can get 289 | // some events immediately or just wait if we don't have 290 | // anything to return 291 | n = poll(mPollFds, numFds, nbEvents ? 0 : -1); 292 | if (n<0) { 293 | ALOGE("poll() failed (%s)", strerror(errno)); 294 | return -errno; 295 | } 296 | if (mPollFds[wake].revents & POLLIN) { 297 | char msg; 298 | int result = read(mPollFds[wake].fd, &msg, 1); 299 | ALOGE_IF(result<0, "error reading from wake pipe (%s)", strerror(errno)); 300 | ALOGE_IF(msg != WAKE_MESSAGE, "unknown message on wake queue (0x%02x)", int(msg)); 301 | mPollFds[wake].revents = 0; 302 | } 303 | } 304 | // if we have events and space, go read them 305 | } while (n && count); 306 | 307 | return nbEvents; 308 | } 309 | 310 | int sensors_poll_context_t::batch(int handle, int flags, int64_t period_ns, int64_t timeout) 311 | { 312 | int index = handleToDriver(handle); 313 | if (index < 0) return index; 314 | return mSensors[index]->batch(handle, flags, period_ns, timeout); 315 | } 316 | 317 | int sensors_poll_context_t::flush(int handle) 318 | { 319 | int index = handleToDriver(handle); 320 | if (index < 0) return index; 321 | return mSensors[index]->flush(handle); 322 | } 323 | 324 | /*****************************************************************************/ 325 | 326 | static int poll__close(struct hw_device_t *dev) 327 | { 328 | sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; 329 | if (ctx) { 330 | delete ctx; 331 | } 332 | return 0; 333 | } 334 | 335 | static int poll__activate(struct sensors_poll_device_t *dev, 336 | int handle, int enabled) { 337 | sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; 338 | return ctx->activate(handle, enabled); 339 | } 340 | 341 | static int poll__setDelay(struct sensors_poll_device_t *dev, 342 | int handle, int64_t ns) { 343 | sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; 344 | return ctx->setDelay(handle, ns); 345 | } 346 | 347 | static int poll__poll(struct sensors_poll_device_t *dev, 348 | sensors_event_t* data, int count) { 349 | sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; 350 | return ctx->pollEvents(data, count); 351 | } 352 | 353 | static int poll__batch(struct sensors_poll_device_1 *dev, 354 | int handle, int flags, int64_t period_ns, int64_t timeout) 355 | { 356 | sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; 357 | return ctx->batch(handle, flags, period_ns, timeout); 358 | } 359 | 360 | static int poll__flush(struct sensors_poll_device_1 *dev, 361 | int handle) 362 | { 363 | sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev; 364 | return ctx->flush(handle); 365 | } 366 | 367 | /*****************************************************************************/ 368 | 369 | /** Open a new instance of a sensor device using name */ 370 | static int open_sensors(const struct hw_module_t* module, const char* id, 371 | struct hw_device_t** device) 372 | { 373 | int status = -EINVAL; 374 | sensors_poll_context_t *dev = new sensors_poll_context_t(); 375 | 376 | memset(&dev->device, 0, sizeof(sensors_poll_device_1)); 377 | 378 | dev->device.common.tag = HARDWARE_DEVICE_TAG; 379 | dev->device.common.version = SENSORS_DEVICE_API_VERSION_1_0; 380 | dev->device.common.module = const_cast(module); 381 | dev->device.common.close = poll__close; 382 | dev->device.activate = poll__activate; 383 | dev->device.setDelay = poll__setDelay; 384 | dev->device.poll = poll__poll; 385 | 386 | /* Batch processing */ 387 | dev->device.batch = poll__batch; 388 | dev->device.flush = poll__flush; 389 | 390 | *device = &dev->device.common; 391 | status = 0; 392 | 393 | return status; 394 | } 395 | 396 | -------------------------------------------------------------------------------- /libsensors/sensors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef ANDROID_SENSORS_H 18 | #define ANDROID_SENSORS_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | __BEGIN_DECLS 31 | 32 | /*****************************************************************************/ 33 | 34 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 35 | 36 | #define LOG_TAG "sensorscpp" 37 | 38 | #define ID_A (0) 39 | #define ID_M (1) 40 | #define ID_O (2) 41 | #define ID_L (3) 42 | #define ID_P (4) 43 | #define ID_GY (5) 44 | #define ID_PR (6) 45 | 46 | /*****************************************************************************/ 47 | 48 | /* 49 | * The SENSORS Module 50 | */ 51 | 52 | /* the CM3663 is a binary proximity sensor that triggers around 6 cm on 53 | * this hardware */ 54 | #define PROXIMITY_THRESHOLD_CM 6.0f 55 | 56 | /*****************************************************************************/ 57 | 58 | #define EVENT_TYPE_ACCEL_X ABS_X //1 59 | #define EVENT_TYPE_ACCEL_Y ABS_Y //0 60 | #define EVENT_TYPE_ACCEL_Z ABS_Z //2 61 | 62 | #define EVENT_TYPE_YAW ABS_RX //3 63 | #define EVENT_TYPE_PITCH ABS_RY //4 64 | #define EVENT_TYPE_ROLL ABS_RZ //5 65 | #define EVENT_TYPE_ORIENT_STATUS ABS_WHEEL //8 66 | 67 | #define EVENT_TYPE_MAGV_X ABS_THROTTLE // 6 68 | #define EVENT_TYPE_MAGV_Y ABS_RUDDER // 7 69 | #define EVENT_TYPE_MAGV_Z ABS_GAS // 9 70 | #define EVENT_TYPE_MAGV_ACC ABS_WHEEL // 8 71 | 72 | #define EVENT_TYPE_TEMPERATURE ABS_THROTTLE 73 | #define EVENT_TYPE_STEP_COUNT ABS_GAS 74 | #define EVENT_TYPE_PROXIMITY ABS_DISTANCE 75 | #define EVENT_TYPE_LIGHT REL_MISC 76 | 77 | #define EVENT_TYPE_GYRO_X REL_RX 78 | #define EVENT_TYPE_GYRO_Y REL_RY 79 | #define EVENT_TYPE_GYRO_Z REL_RZ 80 | 81 | #define EVENT_TYPE_PRESSURE REL_X 82 | 83 | #define LSG (1000.0f) 84 | 85 | // conversion of acceleration data to SI units (m/s^2) 86 | #define RANGE_A (2*GRAVITY_EARTH) 87 | #define RESOLUTION_A (GRAVITY_EARTH / LSG) 88 | #define CONVERT_A (GRAVITY_EARTH / LSG) 89 | #define CONVERT_A_X (CONVERT_A) 90 | #define CONVERT_A_Y (CONVERT_A) 91 | #define CONVERT_A_Z (CONVERT_A) 92 | 93 | // conversion of magnetic data to uT units 94 | #define CONVERT_M (1.0f/16.0f) 95 | #define CONVERT_M_X (-CONVERT_M) 96 | #define CONVERT_M_Y (-CONVERT_M) 97 | #define CONVERT_M_Z (CONVERT_M) 98 | 99 | // conversion of gyro data to SI units (radian/sec) 100 | #define RANGE_GYRO (500.0f*(float)M_PI/180.0f) 101 | #define CONVERT_GYRO ((70.0f / 4000.0f) * ((float)M_PI / 180.0f)) 102 | #define CONVERT_GYRO_X (CONVERT_GYRO) 103 | #define CONVERT_GYRO_Y (CONVERT_GYRO) 104 | #define CONVERT_GYRO_Z (CONVERT_GYRO) 105 | 106 | #define SENSOR_STATE_MASK (0x7FFF) 107 | 108 | /*****************************************************************************/ 109 | 110 | __END_DECLS 111 | 112 | #endif // ANDROID_SENSORS_H 113 | -------------------------------------------------------------------------------- /lineage.dependencies: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "repository": "android_device_samsung_smdk4412-common", 4 | "target_path": "device/samsung/smdk4412-common" 5 | }, 6 | { 7 | "repository": "android_kernel_samsung_smdk4412", 8 | "target_path": "kernel/samsung/smdk4412" 9 | }, 10 | { 11 | "repository": "android_packages_apps_SamsungServiceMode", 12 | "target_path": "packages/apps/SamsungServiceMode" 13 | }, 14 | { 15 | "repository": "android_hardware_samsung", 16 | "target_path": "hardware/samsung" 17 | } 18 | ] 19 | -------------------------------------------------------------------------------- /lineage.mk: -------------------------------------------------------------------------------- 1 | # Release name 2 | PRODUCT_RELEASE_NAME := i9300 3 | 4 | # Inherit device configuration 5 | $(call inherit-product, device/samsung/smdk4412-common/common.mk) 6 | $(call inherit-product, device/samsung/i9300/i9300.mk) 7 | 8 | # Inherit from the common Open Source product configuration 9 | $(call inherit-product, $(SRC_TARGET_DIR)/product/aosp_base_telephony.mk) 10 | 11 | # Boot animation 12 | TARGET_SCREEN_HEIGHT := 1280 13 | TARGET_SCREEN_WIDTH := 720 14 | 15 | # Inherit some common stuff. 16 | $(call inherit-product, vendor/cm/config/common_full_phone.mk) 17 | 18 | # Device identifier. This must come after all inclusions 19 | PRODUCT_DEVICE := i9300 20 | PRODUCT_NAME := lineage_i9300 21 | PRODUCT_BRAND := samsung 22 | PRODUCT_MODEL := GT-I9300 23 | PRODUCT_MANUFACTURER := samsung 24 | 25 | # Set build fingerprint / ID / Product Name etc. 26 | PRODUCT_BUILD_PROP_OVERRIDES += \ 27 | PRODUCT_NAME=m0xx \ 28 | TARGET_DEVICE=m0 \ 29 | BUILD_FINGERPRINT="samsung/m0xx/m0:4.3/JSS15J/I9300XXUGMJ9:user/release-keys" \ 30 | PRIVATE_BUILD_DESC="m0xx-user 4.3 JSS15J I9300XXUGMJ9 release-keys" 31 | -------------------------------------------------------------------------------- /overlay/frameworks/base/core/res/res/values/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 22 | 23 | 24 | 26 | false 27 | 28 | 39 | 40 | 150 41 | 300 42 | 600 43 | 1000 44 | 3000 45 | 8000 46 | 15000 47 | 28000 48 | 41000 49 | 54000 50 | 67000 51 | 80000 52 | 100000 53 | 150000 54 | 200000 55 | 56 | 57 | 61 | 62 | 20 63 | 30 64 | 40 65 | 50 66 | 60 67 | 70 68 | 80 69 | 100 70 | 120 71 | 140 72 | 160 73 | 180 74 | 200 75 | 220 76 | 240 77 | 255 78 | 79 | 80 | 84 | 85 | 0 86 | 0 87 | 0 88 | 0 89 | 0 90 | 0 91 | 0 92 | 0 93 | 0 94 | 0 95 | 0 96 | 0 97 | 0 98 | 0 99 | 0 100 | 0 101 | 0 102 | 0 103 | 0 104 | 0 105 | 0 106 | 107 | 108 | 113 | 114 | 0 115 | 0 116 | 0 117 | 0 118 | 0 119 | 0 120 | 0 121 | 0 122 | 0 123 | 0 124 | 0 125 | 0 126 | 0 127 | 0 128 | 0 129 | 0 130 | 0 131 | 0 132 | 0 133 | 0 134 | 0 135 | 136 | 137 | 138 | 20 139 | 140 | 141 | com.android.systemui/com.android.systemui.doze.DozeService 142 | 143 | 145 | true 146 | 147 | 164 | true 165 | 166 | 174 | true 175 | 176 | 177 | false 178 | 179 | 181 | 184 | 185 | 186 | "wifi,1,1,1,-1,true" 187 | "mobile,0,0,0,-1,true" 188 | "mobile_mms,2,0,2,60000,true" 189 | "mobile_supl,3,0,2,60000,true" 190 | "mobile_dun,4,0,3,60000,true" 191 | "mobile_hipri,5,0,3,60000,true" 192 | "mobile_bluetooth,7,7,1,-1,true" 193 | "wifi_p2p,13,1,0,-1,true" 194 | 195 | 196 | 198 | 199 | "1,1" 200 | "0,1" 201 | "7,1" 202 | 203 | 204 | 207 | 208 | "rndis0" 209 | 210 | 211 | 212 | 214 | 215 | 0 216 | 1 217 | 5 218 | 7 219 | 220 | 221 | 222 | true 223 | 224 | 225 | pdp0 226 | 227 | 228 | true 229 | 230 | 231 | true 232 | 233 | 234 | #ffffffff 235 | 236 | 237 | 1000 238 | 239 | 240 | 9000 241 | 242 | 243 | true 244 | 245 | 257 | 83 258 | 259 | 271 | 65 272 | 273 | 283 | 1 284 | 285 | 286 | true 287 | 288 | 289 | 4 290 | 291 | 292 | true 293 | 294 | 306 | true 307 | 308 | 313 | GPRS|EDGE|WCDMA 314 | 315 | -------------------------------------------------------------------------------- /overlay/frameworks/base/core/res/res/xml/power_profile.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 0 23 | 49 24 | 142 25 | 0.3 26 | 35690 27 | 260 28 | 4 29 | 120 30 | 220 31 | 88 32 | 88 33 | 185 34 | 35 | 88 36 | 50 37 | 38 | 39 | 3.4 40 | 3.4 41 | 42 | 44 | 45 | 200000 46 | 500000 47 | 800000 48 | 1000000 49 | 1200000 50 | 1400000 51 | 1600000 52 | 53 | 54 | 1.4 55 | 56 | 44 57 | 58 | 59 | 55.4 60 | 82.1 61 | 113.7 62 | 140.0 63 | 170.0 64 | 200.0 65 | 230.0 66 | 67 | 68 | 2100 69 | 70 | -------------------------------------------------------------------------------- /overlay/frameworks/base/packages/SystemUI/res/values/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 22 | 23 | 24 | true 25 | 26 | 27 | true 28 | 29 | 30 | false 31 | 32 | 33 | -------------------------------------------------------------------------------- /overlay/packages/apps/Settings/res/values/bools.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | true 21 | 22 | -------------------------------------------------------------------------------- /overlay/packages/apps/Settings/res/values/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | true 21 | 22 | -------------------------------------------------------------------------------- /overlay/vendor/cmsdk/cm/res/res/values/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 31 | 11 32 | 33 | -------------------------------------------------------------------------------- /power/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2016 The CyanogenMod Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | ifeq ($(TARGET_POWERHAL_VARIANT),pegasusq) 18 | 19 | include $(CLEAR_VARS) 20 | 21 | LOCAL_CFLAGS += -DUSE_PEGASUSQ_BOOSTING 22 | 23 | LOCAL_MODULE := power.$(TARGET_BOOTLOADER_BOARD_NAME) 24 | LOCAL_MODULE_RELATIVE_PATH := hw 25 | LOCAL_SHARED_LIBRARIES := liblog libcutils 26 | LOCAL_SRC_FILES := power.c 27 | LOCAL_MODULE_TAGS := optional 28 | 29 | include $(BUILD_SHARED_LIBRARY) 30 | 31 | endif 32 | -------------------------------------------------------------------------------- /power/power.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The CyanogenMod Project 3 | * (C) 2017 The LineageOS Project 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #define LOG_TAG "PegasusPowerHAL" 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | //#define LOG_NDEBUG 0 32 | #include 33 | 34 | #include "power.h" 35 | 36 | #define PEGASUSQ_PATH "/sys/devices/system/cpu/cpufreq/pegasusq/" 37 | #define MINMAX_CPU_PATH "/sys/power/" 38 | 39 | #define US_TO_NS (1000L) 40 | 41 | static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; 42 | 43 | static int current_power_profile = -1; 44 | static bool is_low_power = false; 45 | static bool is_vsync_active = false; 46 | 47 | static int sysfs_write_str(char *path, char *s) { 48 | char buf[80]; 49 | int len; 50 | int ret = 0; 51 | int fd; 52 | 53 | fd = open(path, O_WRONLY); 54 | if (fd < 0) { 55 | strerror_r(errno, buf, sizeof(buf)); 56 | ALOGE("Error opening %s: %s\n", path, buf); 57 | return -1 ; 58 | } 59 | 60 | len = write(fd, s, strlen(s)); 61 | if (len < 0) { 62 | strerror_r(errno, buf, sizeof(buf)); 63 | ALOGE("Error writing to %s: %s\n", path, buf); 64 | ret = -1; 65 | } 66 | 67 | close(fd); 68 | 69 | return ret; 70 | } 71 | 72 | static int sysfs_write_int(char *path, int value) { 73 | char buf[80]; 74 | snprintf(buf, 80, "%d", value); 75 | return sysfs_write_str(path, buf); 76 | } 77 | 78 | static int sysfs_write_long(char *path, long value) { 79 | char buf[80]; 80 | snprintf(buf, 80, "%ld", value); 81 | return sysfs_write_str(path, buf); 82 | } 83 | 84 | #ifdef LOG_NDEBUG 85 | #define WRITE_PEGASUSQ_PARAM(profile, param) do { \ 86 | ALOGV("%s: WRITE_PEGASUSQ_PARAM(profile=%d, param=%s): new val => %d", __func__, profile, #param, profiles[profile].param); \ 87 | sysfs_write_int(PEGASUSQ_PATH #param, profiles[profile].param); \ 88 | } while (0) 89 | #define WRITE_LOW_POWER_PARAM(profile, param) do { \ 90 | ALOGV("%s: WRITE_LOW_POWER_PARAM(profile=%d, param=%s): new val => %d", \ 91 | __func__, profile, #param, profiles_low_power[profile].param); \ 92 | sysfs_write_int(PEGASUSQ_PATH #param, profiles_low_power[profile].param); \ 93 | } while (0) 94 | #define WRITE_PEGASUSQ_VALUE(param, value) do { \ 95 | ALOGV("%s: WRITE_PEGASUSQ_VALUE(param=%s, value=%d)", __func__, #param, value); \ 96 | sysfs_write_int(PEGASUSQ_PATH #param, value); \ 97 | } while (0) 98 | #define WRITE_MINMAX_CPU(param, value) do { \ 99 | ALOGV("%s: WRITE_MINMAX_CPU(param=%s, value=%d)", __func__, #param, value); \ 100 | sysfs_write_int(MINMAX_CPU_PATH #param, value); \ 101 | } while(0) 102 | #else 103 | #define WRITE_PEGASUSQ_PARAM(profile, param) sysfs_write_int(PEGASUSQ_PATH #param, profiles[profile].param) 104 | #define WRITE_LOW_POWER_PARAM(profile, param) sysfs_write_int(PEGASUSQ_PATH #param, profiles_low_power[profile].param) 105 | #define WRITE_PEGASUSQ_VALUE(param, value) sysfs_write_int(PEGASUSQ_PATH #param, value) 106 | #define WRITE_MINMAX_CPU(param, value) sysfs_write_int(MINMAX_CPU_PATH #param, value) 107 | #endif 108 | static bool check_governor() { 109 | struct stat s; 110 | int err = stat(PEGASUSQ_PATH, &s); 111 | if (err != 0) return false; 112 | return S_ISDIR(s.st_mode); 113 | } 114 | 115 | static bool is_profile_valid(int profile) { 116 | return profile >= 0 && profile < PROFILE_MAX; 117 | } 118 | 119 | static void set_power_profile(int profile) { 120 | if (!is_profile_valid(profile)) { 121 | ALOGE("%s: unknown profile: %d", __func__, profile); 122 | return; 123 | } 124 | 125 | if (!check_governor()) return; 126 | 127 | if (profile == current_power_profile) return; 128 | 129 | WRITE_PEGASUSQ_PARAM(profile, hotplug_freq_1_1); 130 | WRITE_PEGASUSQ_PARAM(profile, hotplug_freq_2_0); 131 | WRITE_PEGASUSQ_PARAM(profile, hotplug_freq_2_1); 132 | WRITE_PEGASUSQ_PARAM(profile, hotplug_freq_3_0); 133 | WRITE_PEGASUSQ_PARAM(profile, hotplug_freq_3_1); 134 | WRITE_PEGASUSQ_PARAM(profile, hotplug_freq_4_0); 135 | WRITE_PEGASUSQ_PARAM(profile, hotplug_rq_1_1); 136 | WRITE_PEGASUSQ_PARAM(profile, hotplug_rq_2_0); 137 | WRITE_PEGASUSQ_PARAM(profile, hotplug_rq_2_1); 138 | WRITE_PEGASUSQ_PARAM(profile, hotplug_rq_3_0); 139 | WRITE_PEGASUSQ_PARAM(profile, hotplug_rq_3_1); 140 | WRITE_PEGASUSQ_PARAM(profile, hotplug_rq_4_0); 141 | WRITE_MINMAX_CPU(cpufreq_max_limit, profiles[profile].max_freq); 142 | WRITE_MINMAX_CPU(cpufreq_min_limit, profiles[profile].min_freq); 143 | WRITE_PEGASUSQ_PARAM(profile, up_threshold); 144 | WRITE_PEGASUSQ_PARAM(profile, down_differential); 145 | WRITE_PEGASUSQ_PARAM(profile, min_cpu_lock); 146 | WRITE_PEGASUSQ_PARAM(profile, max_cpu_lock); 147 | WRITE_PEGASUSQ_PARAM(profile, cpu_down_rate); 148 | WRITE_PEGASUSQ_PARAM(profile, sampling_rate); 149 | WRITE_PEGASUSQ_PARAM(profile, io_is_busy); 150 | WRITE_PEGASUSQ_PARAM(profile, boost_freq); 151 | WRITE_PEGASUSQ_PARAM(profile, boost_mincpus); 152 | 153 | current_power_profile = profile; 154 | 155 | ALOGV("%s: %d", __func__, profile); 156 | 157 | } 158 | 159 | static void boost(long boost_time) { 160 | #ifdef USE_PEGASUSQ_BOOSTING 161 | if (is_vsync_active || !check_governor()) return; 162 | if (boost_time == -1) { 163 | sysfs_write_int(PEGASUSQ_PATH "boost_lock_time", -1); 164 | } else { 165 | sysfs_write_long(PEGASUSQ_PATH "boost_lock_time", boost_time); 166 | } 167 | #endif 168 | } 169 | 170 | static void end_boost() { 171 | #ifdef USE_PEGASUSQ_BOOSTING 172 | if (is_vsync_active || !check_governor()) return; 173 | sysfs_write_int(PEGASUSQ_PATH "boost_lock_time", 0); 174 | #endif 175 | } 176 | 177 | static void set_low_power(bool low_power) { 178 | if (!is_profile_valid(current_power_profile)) { 179 | ALOGV("%s: current_power_profile not set yet", __func__); 180 | return; 181 | } 182 | 183 | if (!check_governor()) return; 184 | 185 | if (is_low_power == low_power) return; 186 | 187 | if (low_power) { 188 | end_boost(); 189 | 190 | WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_freq_1_1); 191 | WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_freq_2_0); 192 | WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_freq_2_1); 193 | WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_freq_3_0); 194 | WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_freq_3_1); 195 | WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_freq_4_0); 196 | WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_rq_1_1); 197 | WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_rq_2_0); 198 | WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_rq_2_1); 199 | WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_rq_3_0); 200 | WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_rq_3_1); 201 | WRITE_LOW_POWER_PARAM(current_power_profile, hotplug_rq_4_0); 202 | WRITE_MINMAX_CPU(cpufreq_max_limit, profiles_low_power[current_power_profile].max_freq); 203 | WRITE_MINMAX_CPU(cpufreq_min_limit, profiles_low_power[current_power_profile].min_freq); 204 | WRITE_LOW_POWER_PARAM(current_power_profile, up_threshold); 205 | WRITE_LOW_POWER_PARAM(current_power_profile, down_differential); 206 | WRITE_LOW_POWER_PARAM(current_power_profile, min_cpu_lock); 207 | WRITE_LOW_POWER_PARAM(current_power_profile, max_cpu_lock); 208 | WRITE_LOW_POWER_PARAM(current_power_profile, cpu_down_rate); 209 | WRITE_LOW_POWER_PARAM(current_power_profile, sampling_rate); 210 | WRITE_LOW_POWER_PARAM(current_power_profile, io_is_busy); 211 | is_low_power = true; 212 | } else { 213 | WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_freq_1_1); 214 | WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_freq_2_0); 215 | WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_freq_2_1); 216 | WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_freq_3_0); 217 | WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_freq_3_1); 218 | WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_freq_4_0); 219 | WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_rq_1_1); 220 | WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_rq_2_0); 221 | WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_rq_2_1); 222 | WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_rq_3_0); 223 | WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_rq_3_1); 224 | WRITE_PEGASUSQ_PARAM(current_power_profile, hotplug_rq_4_0); 225 | WRITE_MINMAX_CPU(cpufreq_max_limit, profiles[current_power_profile].max_freq); 226 | WRITE_MINMAX_CPU(cpufreq_min_limit, profiles[current_power_profile].min_freq); 227 | WRITE_PEGASUSQ_PARAM(current_power_profile, up_threshold); 228 | WRITE_PEGASUSQ_PARAM(current_power_profile, down_differential); 229 | WRITE_PEGASUSQ_PARAM(current_power_profile, min_cpu_lock); 230 | WRITE_PEGASUSQ_PARAM(current_power_profile, max_cpu_lock); 231 | WRITE_PEGASUSQ_PARAM(current_power_profile, cpu_down_rate); 232 | WRITE_PEGASUSQ_PARAM(current_power_profile, sampling_rate); 233 | WRITE_PEGASUSQ_PARAM(current_power_profile, io_is_busy); 234 | WRITE_PEGASUSQ_PARAM(current_power_profile, boost_freq); 235 | WRITE_PEGASUSQ_PARAM(current_power_profile, boost_mincpus); 236 | 237 | is_low_power = false; 238 | } 239 | } 240 | 241 | 242 | 243 | /* 244 | * (*init)() performs power management setup actions at runtime 245 | * startup, such as to set default cpufreq parameters. This is 246 | * called only by the Power HAL instance loaded by 247 | * PowerManagerService. 248 | */ 249 | static void power_init(__attribute__((unused)) struct power_module *module) { 250 | set_power_profile(PROFILE_BALANCED); 251 | ALOGV("%s", __func__); 252 | } 253 | 254 | /* 255 | * The setInteractive function performs power management actions upon the 256 | * system entering interactive state (that is, the system is awake and ready 257 | * for interaction, often with UI devices such as display and touchscreen 258 | * enabled) or non-interactive state (the system appears asleep, display 259 | * usually turned off). The non-interactive state is usually entered after a 260 | * period of inactivity, in order to conserve battery power during such 261 | * inactive periods. 262 | * 263 | * Typical actions are to turn on or off devices and adjust cpufreq parameters. 264 | * This function may also call the appropriate interfaces to allow the kernel 265 | * to suspend the system to low-power sleep state when entering non-interactive 266 | * state, and to disallow low-power suspend when the system is in interactive 267 | * state. When low-power suspend state is allowed, the kernel may suspend the 268 | * system whenever no wakelocks are held. 269 | * 270 | * on is non-zero when the system is transitioning to an interactive / awake 271 | * state, and zero when transitioning to a non-interactive / asleep state. 272 | * 273 | * This function is called to enter non-interactive state after turning off the 274 | * screen (if present), and called to enter interactive state prior to turning 275 | * on the screen. 276 | */ 277 | static void power_set_interactive(__attribute__((unused)) struct power_module *module, int on) { 278 | if (!is_profile_valid(current_power_profile)) { 279 | ALOGD("%s: no power profile selected", __func__); 280 | return; 281 | } 282 | 283 | if (!check_governor()) return; 284 | ALOGV("%s: setting interactive => %d", __func__, on); 285 | pthread_mutex_lock(&lock); 286 | set_low_power(!on); 287 | pthread_mutex_unlock(&lock); 288 | } 289 | 290 | /* 291 | * The powerHint function is called to pass hints on power requirements, which 292 | * may result in adjustment of power/performance parameters of the cpufreq 293 | * governor and other controls. 294 | * 295 | * The possible hints are: 296 | * 297 | * POWER_HINT_VSYNC 298 | * 299 | * Foreground app has started or stopped requesting a VSYNC pulse 300 | * from SurfaceFlinger. If the app has started requesting VSYNC 301 | * then CPU and GPU load is expected soon, and it may be appropriate 302 | * to raise speeds of CPU, memory bus, etc. The data parameter is 303 | * non-zero to indicate VSYNC pulse is now requested, or zero for 304 | * VSYNC pulse no longer requested. 305 | * 306 | * POWER_HINT_INTERACTION 307 | * 308 | * User is interacting with the device, for example, touchscreen 309 | * events are incoming. CPU and GPU load may be expected soon, 310 | * and it may be appropriate to raise speeds of CPU, memory bus, 311 | * etc. The data parameter is unused. 312 | * 313 | * POWER_HINT_LOW_POWER 314 | * 315 | * Low power mode is activated or deactivated. Low power mode 316 | * is intended to save battery at the cost of performance. The data 317 | * parameter is non-zero when low power mode is activated, and zero 318 | * when deactivated. 319 | * 320 | * POWER_HINT_CPU_BOOST 321 | * 322 | * An operation is happening where it would be ideal for the CPU to 323 | * be boosted for a specific duration. The data parameter is an 324 | * integer value of the boost duration in microseconds. 325 | */ 326 | static void power_hint(__attribute__((unused)) struct power_module *module, power_hint_t hint, void *data) { 327 | int32_t val; 328 | 329 | if (hint == POWER_HINT_SET_PROFILE) { 330 | ALOGV("%s: set profile %d", __func__, *(int32_t *)data); 331 | pthread_mutex_lock(&lock); 332 | if (is_vsync_active) { 333 | is_vsync_active = false; 334 | end_boost(); 335 | } 336 | set_power_profile(*(int32_t *)data); 337 | pthread_mutex_unlock(&lock); 338 | } 339 | 340 | if (current_power_profile == PROFILE_POWER_SAVE) return; 341 | 342 | pthread_mutex_lock(&lock); 343 | 344 | switch (hint) { 345 | case POWER_HINT_INTERACTION: 346 | ALOGV("%s: interaction", __func__); 347 | if (data) { 348 | val = *(int32_t *)data; 349 | if (val > 0) { 350 | boost(val * US_TO_NS); 351 | } 352 | } else { 353 | boost(profiles[current_power_profile].interaction_boost_time); 354 | } 355 | break; 356 | case POWER_HINT_LAUNCH: 357 | ALOGV("%s: launch", __func__); 358 | boost(profiles[current_power_profile].launch_boost_time); 359 | break; 360 | /* case POWER_HINT_VSYNC: 361 | if (data) { 362 | ALOGV("%s: vsync", __func__); 363 | boost(-1); 364 | is_vsync_active = true; 365 | } else { 366 | is_vsync_active = false; 367 | end_boost(); 368 | } 369 | break;*/ 370 | case POWER_HINT_CPU_BOOST: 371 | ALOGV("%s: cpu_boost", __func__); 372 | boost((*(int32_t *)data) * US_TO_NS); 373 | break; 374 | } 375 | 376 | pthread_mutex_unlock(&lock); 377 | } 378 | 379 | /* 380 | * (*getFeature) is called to get the current value of a particular 381 | * feature or capability from the hardware or PowerHAL 382 | */ 383 | static int power_get_feature(__attribute__((unused)) struct power_module *module, feature_t feature) { 384 | ALOGV("%s: %d", __func__, feature); 385 | if (feature == POWER_FEATURE_SUPPORTED_PROFILES) { 386 | return PROFILE_MAX; 387 | } 388 | ALOGV("%s: unknown feature %d", __func__, feature); 389 | return -1; 390 | } 391 | 392 | static struct hw_module_methods_t power_module_methods = { 393 | .open = NULL, 394 | }; 395 | 396 | struct power_module HAL_MODULE_INFO_SYM = { 397 | .common = { 398 | .tag = HARDWARE_MODULE_TAG, 399 | .module_api_version = POWER_MODULE_API_VERSION_0_2, 400 | .hal_api_version = HARDWARE_HAL_API_VERSION, 401 | .id = POWER_HARDWARE_MODULE_ID, 402 | .name = "smdk4x12 Power HAL", 403 | .author = "The CyanogenMod Project", 404 | .methods = &power_module_methods, 405 | }, 406 | 407 | .init = power_init, 408 | .setInteractive = power_set_interactive, 409 | .powerHint = power_hint, 410 | .getFeature = power_get_feature 411 | }; 412 | -------------------------------------------------------------------------------- /power/power.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The CyanogenMod 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 | #define MS_TO_NS (1000000L) 18 | 19 | enum { 20 | PROFILE_POWER_SAVE = 0, 21 | PROFILE_BALANCED, 22 | PROFILE_PERFORMANCE, 23 | PROFILE_MAX 24 | }; 25 | 26 | typedef struct governor_settings { 27 | // freq values for core up/down 28 | int hotplug_freq_1_1; 29 | int hotplug_freq_2_0; 30 | int hotplug_freq_2_1; 31 | int hotplug_freq_3_0; 32 | int hotplug_freq_3_1; 33 | int hotplug_freq_4_0; 34 | // rq sizes for up/down 35 | int hotplug_rq_1_1; 36 | int hotplug_rq_2_0; 37 | int hotplug_rq_2_1; 38 | int hotplug_rq_3_0; 39 | int hotplug_rq_3_1; 40 | int hotplug_rq_4_0; 41 | // max/min freqs (-1 for default) 42 | int max_freq; 43 | int min_freq; 44 | // load at which to start scaling up 45 | int up_threshold; 46 | // higher down_differential == slower downscaling 47 | int down_differential; 48 | // min/max num of cpus to have online 49 | int min_cpu_lock; 50 | int max_cpu_lock; 51 | // wait sampling_rate * cpu_down_rate us before trying to downscale 52 | int cpu_down_rate; 53 | int sampling_rate; // in microseconds 54 | int io_is_busy; 55 | // boosting 56 | int boost_freq; 57 | int boost_mincpus; 58 | long interaction_boost_time; 59 | long launch_boost_time; 60 | } power_profile; 61 | 62 | static power_profile profiles[PROFILE_MAX] = { 63 | [PROFILE_POWER_SAVE] = { 64 | .hotplug_freq_1_1 = 800000, 65 | .hotplug_freq_2_0 = 700000, 66 | .hotplug_freq_2_1 = 1000000, 67 | .hotplug_freq_3_0 = 900000, 68 | .hotplug_freq_3_1 = 1200000, 69 | .hotplug_freq_4_0 = 1100000, 70 | .hotplug_rq_1_1 = 200, 71 | .hotplug_rq_2_0 = 200, 72 | .hotplug_rq_2_1 = 300, 73 | .hotplug_rq_3_0 = 300, 74 | .hotplug_rq_3_1 = 400, 75 | .hotplug_rq_4_0 = 400, 76 | .max_freq = 1000000, 77 | .min_freq = -1, 78 | .up_threshold = 95, 79 | .down_differential = 2, 80 | .min_cpu_lock = 0, 81 | .max_cpu_lock = 3, 82 | .cpu_down_rate = 5, 83 | .sampling_rate = 200000, 84 | .io_is_busy = 0, 85 | // nb: boosting power hints are ignored for PROFILE_POWER_SAVE 86 | .boost_freq = 0, 87 | .boost_mincpus = 0, 88 | .interaction_boost_time = 0, 89 | .launch_boost_time = 0, 90 | }, 91 | [PROFILE_BALANCED] = { 92 | .hotplug_freq_1_1 = 500000, 93 | .hotplug_freq_2_0 = 500000, 94 | .hotplug_freq_2_1 = 700000, 95 | .hotplug_freq_3_0 = 700000, 96 | .hotplug_freq_3_1 = 900000, 97 | .hotplug_freq_4_0 = 900000, 98 | .hotplug_rq_1_1 = 150, 99 | .hotplug_rq_2_0 = 150, 100 | .hotplug_rq_2_1 = 250, 101 | .hotplug_rq_3_0 = 250, 102 | .hotplug_rq_3_1 = 350, 103 | .hotplug_rq_4_0 = 350, 104 | .max_freq = -1, 105 | .min_freq = -1, 106 | .up_threshold = 90, 107 | .down_differential = 3, 108 | .min_cpu_lock = 0, 109 | .max_cpu_lock = 0, 110 | .cpu_down_rate = 10, 111 | .sampling_rate = 200000, 112 | .io_is_busy = 0, 113 | .boost_freq = 700000, 114 | .boost_mincpus = 0, 115 | .interaction_boost_time = 60 * (MS_TO_NS), 116 | .launch_boost_time = 2000 * (MS_TO_NS), 117 | }, 118 | [PROFILE_PERFORMANCE] = { 119 | .hotplug_freq_1_1 = 500000, 120 | .hotplug_freq_2_0 = 200000, 121 | .hotplug_freq_2_1 = 500000, 122 | .hotplug_freq_3_0 = 200000, 123 | .hotplug_freq_3_1 = 700000, 124 | .hotplug_freq_4_0 = 200000, 125 | .hotplug_rq_1_1 = 150, 126 | .hotplug_rq_2_0 = 100, 127 | .hotplug_rq_2_1 = 200, 128 | .hotplug_rq_3_0 = 150, 129 | .hotplug_rq_3_1 = 250, 130 | .hotplug_rq_4_0 = 200, 131 | .min_freq = -1, 132 | .max_freq = -1, 133 | .up_threshold = 80, 134 | .down_differential = 5, 135 | .min_cpu_lock = 0, 136 | .max_cpu_lock = 0, 137 | .cpu_down_rate = 20, 138 | .sampling_rate = 200000, 139 | .io_is_busy = 1, 140 | .boost_freq = 900000, 141 | .boost_mincpus = 2, 142 | .interaction_boost_time = 90 * (MS_TO_NS), 143 | .launch_boost_time = 3000 * (MS_TO_NS), 144 | }, 145 | }; 146 | 147 | // for non-interactive profiles we don't need to worry about 148 | // boosting as it (should) only occur while the screen is on 149 | static power_profile profiles_low_power[PROFILE_MAX] = { 150 | [PROFILE_POWER_SAVE] = { 151 | .hotplug_freq_1_1 = 800000, 152 | .hotplug_freq_2_0 = 800000, 153 | .hotplug_freq_2_1 = 900000, 154 | .hotplug_freq_3_0 = 900000, 155 | .hotplug_freq_3_1 = 1200000, 156 | .hotplug_freq_4_0 = 1100000, 157 | .hotplug_rq_1_1 = 200, 158 | .hotplug_rq_2_0 = 200, 159 | .hotplug_rq_2_1 = 300, 160 | .hotplug_rq_3_0 = 300, 161 | .hotplug_rq_3_1 = 400, 162 | .hotplug_rq_4_0 = 400, 163 | .max_freq = 900000, 164 | .min_freq = -1, 165 | .up_threshold = 95, 166 | .down_differential = 1, 167 | .min_cpu_lock = 0, 168 | .max_cpu_lock = 2, 169 | .cpu_down_rate = 5, 170 | .sampling_rate = 200000, 171 | .io_is_busy = 0, 172 | .boost_freq = 0, 173 | .boost_mincpus = 0, 174 | .interaction_boost_time = 0, 175 | .launch_boost_time = 0, 176 | }, 177 | [PROFILE_BALANCED] = { 178 | .hotplug_freq_1_1 = 700000, 179 | .hotplug_freq_2_0 = 700000, 180 | .hotplug_freq_2_1 = 900000, 181 | .hotplug_freq_3_0 = 900000, 182 | .hotplug_freq_3_1 = 1100000, 183 | .hotplug_freq_4_0 = 1100000, 184 | .hotplug_rq_1_1 = 150, 185 | .hotplug_rq_2_0 = 150, 186 | .hotplug_rq_2_1 = 250, 187 | .hotplug_rq_3_0 = 250, 188 | .hotplug_rq_3_1 = 350, 189 | .hotplug_rq_4_0 = 350, 190 | .max_freq = 1200000, 191 | .min_freq = -1, 192 | .up_threshold = 90, 193 | .down_differential = 2, 194 | .min_cpu_lock = 0, 195 | .max_cpu_lock = 0, 196 | .cpu_down_rate = 8, 197 | .sampling_rate = 200000, 198 | .io_is_busy = 0, 199 | .boost_freq = 0, 200 | .boost_mincpus = 0, 201 | .interaction_boost_time = 0, 202 | .launch_boost_time = 0, 203 | }, 204 | [PROFILE_PERFORMANCE] = { 205 | .hotplug_freq_1_1 = 800000, 206 | .hotplug_freq_2_0 = 500000, 207 | .hotplug_freq_2_1 = 800000, 208 | .hotplug_freq_3_0 = 500000, 209 | .hotplug_freq_3_1 = 1000000, 210 | .hotplug_freq_4_0 = 700000, 211 | .hotplug_rq_1_1 = 150, 212 | .hotplug_rq_2_0 = 100, 213 | .hotplug_rq_2_1 = 200, 214 | .hotplug_rq_3_0 = 150, 215 | .hotplug_rq_3_1 = 250, 216 | .hotplug_rq_4_0 = 200, 217 | .min_freq = -1, 218 | .max_freq = -1, 219 | .up_threshold = 85, 220 | .down_differential = 5, 221 | .min_cpu_lock = 0, 222 | .max_cpu_lock = 0, 223 | .cpu_down_rate = 15, 224 | .sampling_rate = 200000, 225 | .io_is_busy = 1, 226 | .boost_freq = 0, 227 | .boost_mincpus = 0, 228 | .interaction_boost_time = 0, 229 | .launch_boost_time = 0, 230 | }, 231 | }; 232 | 233 | -------------------------------------------------------------------------------- /proprietary-files.txt: -------------------------------------------------------------------------------- 1 | bin/glgps 2 | lib/hw/gps.exynos4.vendor.so 3 | lib/libakm.so 4 | lib/libsec-ril.so 5 | -------------------------------------------------------------------------------- /rootdir/fstab.smdk4x12: -------------------------------------------------------------------------------- 1 | # Android fstab file. 2 | # 3 | # The filesystem that contains the filesystem checker binary (typically /system) cannot 4 | # specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK 5 | /dev/block/platform/dw_mmc/by-name/EFS /efs ext4 noatime,nosuid,nodev,journal_async_commit,errors=panic wait 6 | /dev/block/platform/dw_mmc/by-name/SYSTEM /system ext4 ro,noatime wait 7 | /dev/block/platform/dw_mmc/by-name/CACHE /cache f2fs noatime,discard,inline_xattr,inline_data,nosuid,nodev wait 8 | /dev/block/platform/dw_mmc/by-name/CACHE /cache ext4 noatime,nosuid,nodev,journal_async_commit,errors=panic wait 9 | /dev/block/platform/dw_mmc/by-name/HIDDEN /preload ext4 noatime,nosuid,nodev,journal_async_commit wait 10 | /dev/block/platform/dw_mmc/by-name/USERDATA /data f2fs noatime,discard,inline_xattr,inline_data,nosuid,nodev wait,check,encryptable=footer 11 | /dev/block/platform/dw_mmc/by-name/USERDATA /data ext4 noatime,nosuid,nodev,noauto_da_alloc,journal_async_commit,errors=panic wait,check,encryptable=footer 12 | /dev/block/platform/dw_mmc/by-name/OTA /misc emmc defaults defaults 13 | 14 | # vold-managed volumes ("block device" is actually a sysfs devpath) 15 | /devices/platform/s3c-sdhci.2/mmc_host/mmc1* /storage/sdcard1 auto defaults voldmanaged=sdcard1:auto,encryptable=userdata 16 | /devices/platform/s5p-ehci* /storage/usbdisk0 auto defaults voldmanaged=usb:auto,noemulatesd 17 | 18 | # recovery 19 | /dev/block/platform/dw_mmc/by-name/BOOT /boot emmc defaults recoveryonly 20 | /dev/block/platform/dw_mmc/by-name/RECOVERY /recovery emmc defaults recoveryonly 21 | /dev/block/platform/dw_mmc/by-name/RADIO /modem emmc defaults recoveryonly 22 | 23 | # zram 24 | /dev/block/zram0 none swap defaults zramsize=419430400,zramstreams=2 25 | -------------------------------------------------------------------------------- /rootdir/init.target.rc: -------------------------------------------------------------------------------- 1 | on init 2 | export LD_SHIM_LIBS /system/lib/libsec-ril.so|libsamsung_symbols.so 3 | # ko files for FM Radio 4 | insmod /system/lib/modules/Si4709_driver.ko 5 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq 6 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/boost_freq 7 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/boost_lock_time 8 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/boost_mincpus 9 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/cpu_down_freq 10 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/cpu_down_rate 11 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/cpu_up_freq 12 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/cpu_up_rate 13 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/cpucore_table 14 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/down_differential 15 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/dvfs_debug 16 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/freq_step 17 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_1_1 18 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_2_0 19 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_2_1 20 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_3_0 21 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_3_1 22 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_freq_4_0 23 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_lock 24 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_1_1 25 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_2_0 26 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_2_1 27 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_3_0 28 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_3_1 29 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/hotplug_rq_4_0 30 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/ignore_nice_load 31 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/io_is_busy 32 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/up_threshold 33 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/min_cpu_lock 34 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/max_cpu_lock 35 | chown system system /sys/devices/system/cpu/cpufreq/pegasusq/sampling_rate 36 | 37 | on boot 38 | # Flash storage isn't a good entropy source, and only causes 39 | # locking overhead in the kernel. Turn it off. 40 | write /sys/block/mmcblk0/queue/add_random 0 41 | write /sys/block/mmcblk1/queue/add_random 0 42 | 43 | # KSM 44 | write /sys/kernel/mm/ksm/deferred_timer 1 45 | write /sys/kernel/mm/ksm/pages_to_scan 100 46 | write /sys/kernel/mm/ksm/sleep_millisecs 500 47 | write /sys/kernel/mm/ksm/run 0 48 | 49 | # Swapping 1 page at a time is ok 50 | write /proc/sys/vm/page-cluster 0 51 | 52 | write /proc/sys/vm/swappiness 100 53 | 54 | # increase read-ahead value to 256 kb 55 | write /sys/block/mmcblk0/queue/read_ahead_kb 256 56 | 57 | on post-fs-data 58 | # icd 59 | exec icd_check 60 | chown system system /dev/icd 61 | chmod 0644 /dev/icd 62 | write /dev/icdr 0 63 | chown system system /dev/icdr 64 | chmod 0644 /dev/icdr 65 | chown system system /dev/tzic 66 | 67 | # make param block device link for SysScope 68 | symlink /dev/block/mmcblk0p4 /dev/block/param 69 | 70 | # Restorecon 71 | restorecon_recursive /efs 72 | 73 | # GPS init 74 | mkdir /data/gps 75 | chown gps system /data/gps 76 | chmod 1770 /data/gps 77 | write /sys/class/sec/gps/GPS_PWR_EN/export 162 78 | write /sys/class/sec/gps/GPS_PWR_EN/value 0 79 | write /sys/class/sec/gps/GPS_PWR_EN/direction out 80 | chown gps system /sys/class/sec/gps/GPS_PWR_EN/value 81 | chmod 0664 /sys/class/sec/gps/GPS_PWR_EN/value 82 | chown gps system /dev/ttySAC1 83 | chmod 0660 /dev/ttySAC1 84 | restorecon /sys/class/sec/gps/export 85 | restorecon /sys/class/sec/gps/GPS_PWR_EN/value 86 | restorecon /sys/class/sec/gps/GPS_PWR_EN/direction 87 | 88 | write /data/.cid.info 0 89 | restorecon /data/.cid.info 90 | restorecon /data/ISP_CV 91 | 92 | on fs 93 | # zram 94 | swapon_all /fstab.smdk4x12 95 | 96 | on boot 97 | # cbd 98 | service cpboot-daemon /system/bin/cbd -d 99 | class main 100 | user root 101 | group radio cache inet misc audio sdcard_rw log 102 | seclabel u:r:cpboot-daemon:s0 103 | 104 | 105 | # Start GPS daemon 106 | service gps-daemon /system/bin/sh /system/bin/gps_daemon.sh 107 | class main 108 | socket gps seqpacket 0660 gps system 109 | user gps 110 | group system inet sdcard_rw gps 111 | seclabel u:r:glgps:s0 112 | -------------------------------------------------------------------------------- /selinux/audioserver.te: -------------------------------------------------------------------------------- 1 | allow audioserver rild:unix_stream_socket connectto; 2 | -------------------------------------------------------------------------------- /selinux/bluetooth.te: -------------------------------------------------------------------------------- 1 | allow bluetooth bluetooth_efs_file:dir search; 2 | allow bluetooth bluetooth_efs_file:file read; 3 | allow bluetooth firmware_exynos:dir { open read search }; 4 | allow bluetooth firmware_exynos:file { open read }; 5 | allow bluetooth sysfs:file write; 6 | allow bluetooth efs_device_file:dir search; 7 | allow bluetooth wifi_data_file:file r_file_perms; 8 | -------------------------------------------------------------------------------- /selinux/cpboot-daemon.te: -------------------------------------------------------------------------------- 1 | type cpboot-daemon, domain; 2 | type cpboot-daemon_exec, exec_type, file_type; 3 | init_daemon_domain(cpboot-daemon); 4 | 5 | permissive cpboot-daemon; 6 | 7 | allow cpboot-daemon cgroup:dir { create add_name }; 8 | allow cpboot-daemon device:dir { write remove_name add_name }; 9 | allow cpboot-daemon efs_block_device:blk_file { read open }; 10 | allow cpboot-daemon efs_device_file:dir search; 11 | allow cpboot-daemon efs_file:file { read write open }; 12 | allow cpboot-daemon init:unix_stream_socket connectto; 13 | allow cpboot-daemon log_device:chr_file { write open }; 14 | allow cpboot-daemon log_device:dir search; 15 | allow cpboot-daemon property_socket:sock_file write; 16 | allow cpboot-daemon radio_device:chr_file { read write ioctl open }; 17 | allow cpboot-daemon radio_prop:property_service set; 18 | allow cpboot-daemon self:capability { setuid }; 19 | allow cpboot-daemon sysfs_radio:file { read write open }; 20 | allow cpboot-daemon usbfs:dir search; 21 | allow cpboot-daemon self:capability dac_override; 22 | allow cpboot-daemon cbd_device:chr_file create_file_perms; 23 | 24 | # FIX ME 25 | # allow cpboot-daemon usbfs:filesystem mount; 26 | # allow cpboot-daemon self:capability { mknod }; 27 | 28 | -------------------------------------------------------------------------------- /selinux/device.te: -------------------------------------------------------------------------------- 1 | type rfkill_device, dev_type; 2 | type efs_block_device, dev_type; 3 | type hpd_device, dev_type; 4 | -------------------------------------------------------------------------------- /selinux/domain.te: -------------------------------------------------------------------------------- 1 | dontaudit domain kernel:system module_request; 2 | -------------------------------------------------------------------------------- /selinux/file.te: -------------------------------------------------------------------------------- 1 | type sensors_data_file, file_type, data_file_type; 2 | type sysfs_display, fs_type, sysfs_type; 3 | type sysfs_gps, fs_type, sysfs_type; 4 | 5 | type efs_device_file, file_type; 6 | type radio_data, file_type; 7 | type sysfs_radio, fs_type, sysfs_type; 8 | type sysfs_sensor, fs_type, sysfs_type; 9 | type cbd_device, dev_type; 10 | -------------------------------------------------------------------------------- /selinux/file_contexts: -------------------------------------------------------------------------------- 1 | # RIL 2 | /dev/link_pm u:object_r:radio_device:s0 3 | /dev/umts_boot0 u:object_r:radio_device:s0 4 | /dev/umts_boot1 u:object_r:radio_device:s0 5 | /dev/umts_ipc0 u:object_r:radio_device:s0 6 | /dev/umts_ramdump0 u:object_r:radio_device:s0 7 | /dev/umts_rfs0 u:object_r:radio_device:s0 8 | /dev/__cbd_msg_ u:object_r:cbd_device:s0 9 | /system/bin/cbd u:object_r:cpboot-daemon_exec:s0 10 | 11 | /efs u:object_r:efs_device_file:s0 12 | /data/misc/radio(/.*)? u:object_r:radio_data:s0 13 | /sys/devices/platform/s5p-ohci/ohci_power u:object_r:sysfs_radio:s0 14 | /sys/devices/platform/s5p-ehci/ehci_power u:object_r:sysfs_radio:s0 15 | 16 | # Partitions 17 | /dev/block/mmcblk0p7 u:object_r:efs_block_device:s0 18 | /dev/block/mmcblk0p9 u:object_r:system_block_device:s0 19 | /dev/block/mmcblk0p12 u:object_r:userdata_block_device:s0 20 | 21 | # Bluetooth 22 | /dev/ttySAC0 u:object_r:hci_attach_dev:s0 23 | /efs/bluetooth(/.*)? u:object_r:bluetooth_efs_file:s0 24 | 25 | # Display 26 | /sys/class/mdnie/mdnie(/.*)? u:object_r:sysfs_display:s0 27 | /sys/devices/platform/samsung-pd.2/mdnie/mdnie(/.*)? u:object_r:sysfs_display:s0 28 | 29 | # GPS 30 | /dev/ttySAC1 u:object_r:gps_device:s0 31 | /system/bin/gps_daemon.sh u:object_r:glgps_exec:s0 32 | /sys/devices/virtual/gpio/gpio128/value u:object_r:sysfs_gps:s0 33 | 34 | # Sensors 35 | /dev/akm8975 u:object_r:sensors_device:s0 36 | /efs/gyro_cal_data u:object_r:sensors_data_file:s0 37 | /efs/FactoryApp/baro_delta u:object_r:sensors_data_file:s0 38 | /sys/class/sensors/accelerometer_sensor u:object_r:sysfs_sensor:s0 39 | 40 | # Wifi 41 | /dev/rfkill u:object_r:rfkill_device:s0 42 | /data/.cid.info u:object_r:wifi_data_file:s0 43 | /efs/wifi/.mac.info u:object_r:wifi_data_file:s0 44 | 45 | # Vibrator 46 | /dev/tspdrv u:object_r:input_device:s0 47 | 48 | # Swap 49 | /dev/block/zram(.*) u:object_r:swap_block_device:s0 50 | 51 | # Misc 52 | /dev/HPD u:object_r:hpd_device:s0 53 | -------------------------------------------------------------------------------- /selinux/gpsd.te: -------------------------------------------------------------------------------- 1 | type glgps, domain; 2 | type glgps_exec, exec_type, file_type; 3 | 4 | init_daemon_domain(glgps) 5 | 6 | allow glgps shell_exec:file { rx_file_perms entrypoint }; 7 | 8 | #for text relocs & execution 9 | allow glgps system_file:file { execute_no_trans execmod }; 10 | allow glgps gps_device:chr_file { getattr setattr }; 11 | allow glgps gps_data_file:dir { search write add_name remove_name }; 12 | allow glgps gps_data_file:file { create rw_file_perms }; 13 | allow glgps gps_data_file:fifo_file { unlink create setattr getattr rw_file_perms }; 14 | 15 | allow glgps node:udp_socket { node_bind name_bind }; 16 | allow glgps port:tcp_socket name_connect; 17 | allow glgps self:tcp_socket { getopt write read }; 18 | 19 | allow glgps sysfs_gps:file rw_file_perms; 20 | allow glgps gps_device:chr_file { ioctl open read write }; 21 | allow glgps glgps:udp_socket { create bind }; 22 | allow glgps glgps:tcp_socket { create connect }; 23 | allow glgps fwmarkd_socket:sock_file write; 24 | allow glgps dnsproxyd_socket:sock_file write; 25 | allow glgps netd:unix_stream_socket connectto; 26 | -------------------------------------------------------------------------------- /selinux/hostapd.te: -------------------------------------------------------------------------------- 1 | allow hostapd rfkill_device:chr_file r_file_perms; 2 | -------------------------------------------------------------------------------- /selinux/init.te: -------------------------------------------------------------------------------- 1 | allow init wpa_socket:unix_dgram_socket { bind create }; 2 | allow init init:process { execmem }; 3 | allow init init:tcp_socket { create }; 4 | 5 | allow init sysfs_display:lnk_file { read setattr }; 6 | 7 | allow init tmpfs:lnk_file create; 8 | allow init sysfs_sensor:lnk_file { setattr read }; 9 | allow init sysfs_gps:file rw_file_perms; 10 | 11 | allow init rild:process noatsecure; 12 | 13 | domain_trans(init, rootfs, glgps) 14 | domain_trans(init, rootfs, cpboot-daemon) 15 | -------------------------------------------------------------------------------- /selinux/log.te: -------------------------------------------------------------------------------- 1 | allow domain log_device:chr_file { open write }; 2 | allow domain log_device:dir { search }; 3 | allow { shell debuggerd } log_device:chr_file { read }; 4 | -------------------------------------------------------------------------------- /selinux/mediaserver.te: -------------------------------------------------------------------------------- 1 | allow mediaserver { firmware_exynos }:file r_file_perms; 2 | allow mediaserver firmware_exynos:dir r_dir_perms; 3 | allow mediaserver camera_data_file:file rw_file_perms; 4 | allow mediaserver mfc_device:chr_file rw_file_perms; 5 | 6 | # Bluetooth audio 7 | allow mediaserver bluetooth:unix_stream_socket { connectto }; 8 | 9 | allow mediaserver { storage_file mnt_user_file }:dir { search read }; 10 | allow mediaserver storage_file:lnk_file read; 11 | allow mediaserver mnt_user_file:lnk_file read; 12 | -------------------------------------------------------------------------------- /selinux/netd.te: -------------------------------------------------------------------------------- 1 | allow netd init:tcp_socket { read write getopt }; 2 | allow netd glgps:fd use; 3 | allow netd glgps:tcp_socket { read write getopt setopt }; 4 | -------------------------------------------------------------------------------- /selinux/nfc.te: -------------------------------------------------------------------------------- 1 | allow nfc firmware_exynos:dir search; 2 | allow nfc log_device:chr_file write; 3 | -------------------------------------------------------------------------------- /selinux/platform_app.te: -------------------------------------------------------------------------------- 1 | allow platform_app nfc_service:service_manager find; 2 | -------------------------------------------------------------------------------- /selinux/recovery.te: -------------------------------------------------------------------------------- 1 | recovery_only(` 2 | 3 | # firmware files 4 | allow recovery firmware_exynos:dir { create setattr relabelto relabelfrom }; 5 | allow recovery firmware_exynos:file { create write open setattr relabelto relabelfrom }; 6 | allow recovery firmware_mfc:file { create write open setattr relabelto relabelfrom }; 7 | ') 8 | -------------------------------------------------------------------------------- /selinux/rild.te: -------------------------------------------------------------------------------- 1 | allow rild self:netlink_socket { create bind read write }; 2 | allow rild self:netlink_route_socket { write }; 3 | allow rild self:netlink_kobject_uevent_socket { create bind read write setopt }; 4 | allow rild rild:process { execmem }; 5 | allow rild toolbox_exec:file rx_file_perms; 6 | 7 | allow rild radio_data_file:dir setattr; 8 | allow rild unlabeled:dir search; 9 | 10 | allow radio log_device:chr_file w_file_perms; 11 | allow rild log_device:chr_file w_file_perms; 12 | allow rild system_file:file execmod; 13 | allow rild radio_data:file create_file_perms; 14 | allow rild radio_data:dir create_dir_perms; 15 | 16 | allow rild radio_device:chr_file rw_file_perms; 17 | allow rild efs_block_device:blk_file rw_file_perms; 18 | allow rild efs_file:file { read open write setattr }; 19 | 20 | allow rild efs_device_file:dir create_dir_perms; 21 | allow rild efs_device_file:file { setattr create create_file_perms }; 22 | -------------------------------------------------------------------------------- /selinux/service_contexts: -------------------------------------------------------------------------------- 1 | SecTVOutService u:object_r:surfaceflinger_service:s0 2 | Exynos.HWCService u:object_r:surfaceflinger_service:s0 3 | Exynos.IPService u:object_r:surfaceflinger_service:s0 4 | -------------------------------------------------------------------------------- /selinux/servicemanager.te: -------------------------------------------------------------------------------- 1 | allow servicemanager glgps:dir { search read write }; 2 | allow servicemanager glgps:file { open read write }; 3 | allow servicemanager glgps:process getattr; 4 | -------------------------------------------------------------------------------- /selinux/surfaceflinger.te: -------------------------------------------------------------------------------- 1 | allow surfaceflinger hpd_device:chr_file rw_file_perms; 2 | -------------------------------------------------------------------------------- /selinux/sysinit.te: -------------------------------------------------------------------------------- 1 | allow sysinit firmware_exynos:dir { read search open getattr }; 2 | allow sysinit firmware_exynos:dir { read search open getattr write remove_name add_name }; 3 | allow sysinit firmware_exynos:file { read open write getattr setattr create unlink }; 4 | allow sysinit sysinit:capability { dac_override chown fowner fsetid }; 5 | -------------------------------------------------------------------------------- /selinux/system_app.te: -------------------------------------------------------------------------------- 1 | allow system_app sysfs_display:{ file lnk_file } { getattr open read write }; 2 | allow system_app sysfs_display:dir { search }; 3 | -------------------------------------------------------------------------------- /selinux/system_server.te: -------------------------------------------------------------------------------- 1 | allow system_server input_device:chr_file { read ioctl write open }; 2 | allow system_server sensors_device:chr_file { read open }; 3 | allow system_server sensors_data_file:file r_file_perms; 4 | allow system_server wpa_socket:unix_dgram_socket sendto; 5 | 6 | allow system_server sysfs:file { read open write }; 7 | allow system_server sysfs_display:lnk_file rw_file_perms; 8 | allow system_server sysfs_display:dir rw_dir_perms; 9 | allow system_server sysfs_display:file rw_file_perms; 10 | allow system_server self:capability { sys_module }; 11 | 12 | allow system_server efs_file:dir search; 13 | allow system_server efs_file:file read; 14 | allow system_server efs_device_file:dir search; 15 | allow system_server uhid_device:chr_file { read ioctl write open }; 16 | allow system_server storage_stub_file:dir getattr; 17 | 18 | 19 | # for sensors, GPS 20 | allow system_server system_file:file execmod; 21 | 22 | # /efs/wifi/.mac.info 23 | allow system_server wifi_data_file:file { read open }; 24 | 25 | allow system_server radio_data:dir r_dir_perms; 26 | 27 | allow system_server glgps:binder transfer; 28 | type_transition system_server system_data_file:fifo_file gps_data_file ".gps.interface.pipe.to_jni"; 29 | 30 | # Access .gps.interface.pipe.to_gpsd. 31 | allow system_server gps_data_file:dir rw_dir_perms; 32 | allow system_server gps_data_file:fifo_file { setattr rw_file_perms create }; 33 | 34 | # Access /data/sensors/gps* socket 35 | allow system_server gps_data_file:sock_file create_file_perms; 36 | allow system_server gps_data_file:dir rw_dir_perms; 37 | allow system_server gps_data_file:file rw_file_perms; 38 | 39 | -------------------------------------------------------------------------------- /selinux/ueventd.te: -------------------------------------------------------------------------------- 1 | # Firmwares 2 | allow ueventd { firmware_mfc }:file r_file_perms; 3 | allow ueventd { firmware_exynos }:dir search; 4 | allow ueventd { firmware_exynos }:file { read getattr open }; 5 | allow ueventd sysfs_display:file { write open }; 6 | -------------------------------------------------------------------------------- /selinux/untrusted_app.te: -------------------------------------------------------------------------------- 1 | allow untrusted_app storage_stub_file:dir getattr; 2 | allow untrusted_app log_device:chr_file { read write }; 3 | allow untrusted_app self:udp_socket ioctl; 4 | allow untrusted_app app_data_file:file create_file_perms; 5 | allow untrusted_app app_data_file:dir create_dir_perms; 6 | -------------------------------------------------------------------------------- /selinux/vold.te: -------------------------------------------------------------------------------- 1 | allow vold kernel:process setsched; 2 | allow vold sdcardd_exec:file { read open execute execute_no_trans }; 3 | 4 | allow vold log_device:dir search; 5 | allow vold storage_stub_file:dir { read open search write add_name }; 6 | allow vold mnt_media_rw_stub_file:dir { read open }; 7 | allow vold blkid_exec:file { getattr execute read open execute_no_trans }; 8 | 9 | allow vold log_device:chr_file { write open }; 10 | 11 | allow vold efs_device_file:dir rw_file_perms; 12 | allow vold efs_device_file:file rw_file_perms; 13 | -------------------------------------------------------------------------------- /selinux/wpa_supplicant.te: -------------------------------------------------------------------------------- 1 | allow wpa init:unix_dgram_socket { read write }; 2 | 3 | # logwrapper used with wpa_supplicant 4 | allow wpa devpts:chr_file { read write }; 5 | allow wpa log_device:chr_file { write }; 6 | 7 | allow wpa wpa_socket:unix_dgram_socket { read write }; 8 | allow wpa_socket system_app:unix_dgram_socket sendto; 9 | 10 | allow wpa_socket wifi_data_file:sock_file unlink; 11 | 12 | allow wpa rfkill_device:chr_file rw_file_perms; 13 | -------------------------------------------------------------------------------- /selinux/zygote.te: -------------------------------------------------------------------------------- 1 | allow zygote log_device:dir search; 2 | -------------------------------------------------------------------------------- /setup-makefiles.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (C) 2017 The LineageOS Project 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | set -e 19 | export DEVICE=i9300 20 | export VENDOR=samsung 21 | ./../smdk4412-common/setup-makefiles.sh $@ 22 | -------------------------------------------------------------------------------- /shims/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2016 The CyanogenMod Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(call all-makefiles-under, $(LOCAL_PATH)) 18 | -------------------------------------------------------------------------------- /shims/libgps-shim/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2016 The CyanogenMod Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_SRC_FILES := gps.c 20 | 21 | LOCAL_SHARED_LIBRARIES := \ 22 | libcutils \ 23 | liblog 24 | 25 | LOCAL_MODULE := gps.$(TARGET_BOOTLOADER_BOARD_NAME) 26 | LOCAL_MODULE_RELATIVE_PATH := hw 27 | 28 | include $(BUILD_SHARED_LIBRARY) 29 | -------------------------------------------------------------------------------- /shims/libgps-shim/gps.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The CyanogenMod 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 | #define LOG_TAG "libgps-shim" 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "gps.h" 28 | #define REAL_GPS_PATH "/system/lib/hw/gps.exynos4.vendor.so" 29 | 30 | const GpsInterface* (*vendor_get_gps_interface)(struct gps_device_t* dev); 31 | const void* (*vendor_get_extension)(const char* name); 32 | void (*vendor_set_ref_location)(const AGpsRefLocationNoLTE *agps_reflocation, size_t sz_struct); 33 | 34 | void shim_set_ref_location(const AGpsRefLocation *agps_reflocation, size_t sz_struct) { 35 | // this is mildly ugly 36 | AGpsRefLocationNoLTE vendor_ref; 37 | if (sizeof(AGpsRefLocationNoLTE) < sz_struct) { 38 | ALOGE("%s: AGpsRefLocation is too small, bailing out!", __func__); 39 | return; 40 | } 41 | ALOGE("%s: shimming AGpsRefLocation", __func__); 42 | // the two structs are identical, so this is ok 43 | memcpy(&vendor_ref, agps_reflocation, sizeof(AGpsRefLocationNoLTE)); 44 | vendor_set_ref_location(&vendor_ref, sizeof(AGpsRefLocationNoLTE)); 45 | // copy it back 46 | memcpy(agps_reflocation, &vendor_ref, sizeof(AGpsRefLocationNoLTE)); 47 | } 48 | 49 | const void* shim_get_extension(const char* name) { 50 | ALOGE("%s(%s)", __func__, name); 51 | if (strcmp(name, AGPS_RIL_INTERFACE) == 0) { 52 | // RIL interface 53 | AGpsRilInterface *ril = (AGpsRilInterface*)vendor_get_extension(name); 54 | // now we shim the ref_location callback 55 | ALOGE("%s: shimming RIL ref_location callback", __func__); 56 | vendor_set_ref_location = ril->set_ref_location; 57 | ril->set_ref_location = shim_set_ref_location; 58 | return ril; 59 | } else { 60 | return vendor_get_extension(name); 61 | } 62 | } 63 | 64 | const GpsInterface* shim_get_gps_interface(struct gps_device_t* dev) { 65 | ALOGE("%s: shimming vendor get_extension", __func__); 66 | GpsInterface *halInterface = vendor_get_gps_interface(dev); 67 | 68 | vendor_get_extension = halInterface->get_extension; 69 | halInterface->get_extension = &shim_get_extension; 70 | 71 | return halInterface; 72 | } 73 | 74 | static int open_gps(const struct hw_module_t* module, char const* name, 75 | struct hw_device_t** device) { 76 | void *realGpsLib; 77 | int gpsHalResult; 78 | struct hw_module_t *realHalSym; 79 | 80 | struct gps_device_t **gps = (struct gps_device_t **)device; 81 | 82 | realGpsLib = dlopen(REAL_GPS_PATH, RTLD_LOCAL); 83 | if (!realGpsLib) { 84 | ALOGE("Failed to load real GPS HAL '" REAL_GPS_PATH "': %s", dlerror()); 85 | return -EINVAL; 86 | } 87 | 88 | realHalSym = (struct hw_module_t*)dlsym(realGpsLib, HAL_MODULE_INFO_SYM_AS_STR); 89 | if (!realHalSym) { 90 | ALOGE("Failed to locate the GPS HAL module sym: '" HAL_MODULE_INFO_SYM_AS_STR "': %s", dlerror()); 91 | goto dl_err; 92 | } 93 | 94 | int result = realHalSym->methods->open(realHalSym, name, device); 95 | if (result < 0) { 96 | ALOGE("Real GPS open method failed: %d", result); 97 | goto dl_err; 98 | } 99 | ALOGE("Successfully loaded real GPS hal, shimming get_gps_interface..."); 100 | // now, we shim hw_device_t 101 | vendor_get_gps_interface = (*gps)->get_gps_interface; 102 | (*gps)->get_gps_interface = &shim_get_gps_interface; 103 | 104 | return 0; 105 | dl_err: 106 | dlclose(realGpsLib); 107 | return -EINVAL; 108 | } 109 | 110 | static struct hw_module_methods_t gps_module_methods = { 111 | .open = open_gps 112 | }; 113 | 114 | struct hw_module_t HAL_MODULE_INFO_SYM = { 115 | .tag = HARDWARE_MODULE_TAG, 116 | .module_api_version = 1, 117 | .hal_api_version = 0, 118 | .id = GPS_HARDWARE_MODULE_ID, 119 | .name = "BCM451x GPS shim", 120 | .author = "The CyanogenMod Project", 121 | .methods = &gps_module_methods 122 | }; 123 | -------------------------------------------------------------------------------- /shims/libgps-shim/gps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The CyanogenMod 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 | #include 17 | 18 | /* CellID for 2G, 3G and LTE, used in AGPS. */ 19 | typedef struct { 20 | AGpsRefLocationType type; 21 | /** Mobile Country Code. */ 22 | uint16_t mcc; 23 | /** Mobile Network Code .*/ 24 | uint16_t mnc; 25 | /** Location Area Code in 2G, 3G and LTE. In 3G lac is discarded. In LTE, 26 | * lac is populated with tac, to ensure that we don't break old clients that 27 | * might rely in the old (wrong) behavior. 28 | */ 29 | uint16_t lac; 30 | /** Cell id in 2G. Utran Cell id in 3G. Cell Global Id EUTRA in LTE. */ 31 | uint32_t cid; 32 | #if 0 // introduced in N. 33 | /** Tracking Area Code in LTE. */ 34 | uint16_t tac; 35 | /** Physical Cell id in LTE (not used in 2G and 3G) */ 36 | uint16_t pcid; 37 | #endif 38 | } AGpsRefLocationCellIDNoLTE; 39 | 40 | /** Represents ref locations */ 41 | typedef struct { 42 | AGpsRefLocationType type; 43 | union { 44 | AGpsRefLocationCellIDNoLTE cellID; 45 | AGpsRefLocationMac mac; 46 | } u; 47 | } AGpsRefLocationNoLTE; 48 | 49 | 50 | -------------------------------------------------------------------------------- /shims/libsecril-shim/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_SRC_FILES:= secril-shim.c 6 | LOCAL_SHARED_LIBRARIES := liblog libbinder 7 | LOCAL_MODULE:= libsecril-shim 8 | 9 | include $(BUILD_SHARED_LIBRARY) 10 | -------------------------------------------------------------------------------- /shims/libsecril-shim/secril-shim.c: -------------------------------------------------------------------------------- 1 | #define LOG_TAG "secril-shim" 2 | #define RIL_SHLIB 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #define REAL_RIL_NAME "/system/lib/libsec-ril.so" 31 | 32 | 33 | static RIL_RadioFunctions const *mRealRadioFuncs; 34 | static const struct RIL_Env *mEnv; 35 | 36 | static void rilOnRequest(int request, void *data, size_t datalen, RIL_Token t) 37 | { 38 | switch (request) { 39 | case RIL_REQUEST_GET_RADIO_CAPABILITY: 40 | RLOGW("Returning NOT_SUPPORTED on GET_RADIO_CAPABILITY"); 41 | mEnv->OnRequestComplete(t, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0); 42 | break; 43 | default: 44 | mRealRadioFuncs->onRequest(request, data, datalen, t); 45 | } 46 | } 47 | 48 | static void patchMem(void *libHandle) { 49 | /* 50 | * MAX_TIMEOUT is used for a call to pthread_cond_timedwait_relative_np. 51 | * The issue is bionic has switched to using absolute timeouts instead of 52 | * relative timeouts, and a maximum time value can cause an overflow in 53 | * the function converting relative to absolute timespecs if unpatched. 54 | * 55 | * By patching this to 0x01FFFFFF from 0x7FFFFFFF, the timeout should 56 | * expire in about a year rather than 68 years, and the RIL should be good 57 | * up until the year 2036 or so. 58 | */ 59 | uint32_t *MAX_TIMEOUT; 60 | 61 | MAX_TIMEOUT = (uint32_t *)dlsym(libHandle, "MAX_TIMEOUT"); 62 | if (CC_UNLIKELY(!MAX_TIMEOUT)) { 63 | RLOGE("%s: MAX_TIMEOUT could not be found!", __FUNCTION__); 64 | return; 65 | } 66 | RLOGD("%s: MAX_TIMEOUT found at %p!", __FUNCTION__, MAX_TIMEOUT); 67 | RLOGD("%s: MAX_TIMEOUT is currently 0x%" PRIX32, __FUNCTION__, *MAX_TIMEOUT); 68 | if (CC_LIKELY(*MAX_TIMEOUT == 0x7FFFFFFF)) { 69 | *MAX_TIMEOUT = 0x01FFFFFF; 70 | RLOGI("%s: MAX_TIMEOUT was changed to 0x0%" PRIX32, __FUNCTION__, *MAX_TIMEOUT); 71 | } else { 72 | RLOGW("%s: MAX_TIMEOUT was not 0x7FFFFFFF; leaving alone", __FUNCTION__); 73 | } 74 | 75 | } 76 | 77 | const RIL_RadioFunctions* RIL_Init(const struct RIL_Env *env, int argc, char **argv) 78 | { 79 | RIL_RadioFunctions const* (*fRealRilInit)(const struct RIL_Env *env, int argc, char **argv); 80 | static RIL_RadioFunctions rilInfo; 81 | void *realRilLibHandle; 82 | int i; 83 | 84 | 85 | //save the env; 86 | mEnv = env; 87 | 88 | //get the real RIL 89 | realRilLibHandle = dlopen(REAL_RIL_NAME, RTLD_LOCAL); 90 | if (!realRilLibHandle) { 91 | RLOGE("Failed to load the real RIL '" REAL_RIL_NAME "': %s\n", dlerror()); 92 | return NULL; 93 | } 94 | 95 | //remove "-c" command line as Samsung's RIL does not understand it - it just barfs instead 96 | for (i = 0; i < argc; i++) { 97 | if (!strcmp(argv[i], "-c") && i != argc -1) { //found it 98 | memcpy(argv + i, argv + i + 2, sizeof(char*[argc - i - 2])); 99 | argc -= 2; 100 | } 101 | } 102 | 103 | //load the real RIL 104 | fRealRilInit = dlsym(realRilLibHandle, "RIL_Init"); 105 | if (!fRealRilInit) { 106 | RLOGE("Failed to find the real RIL's entry point\n"); 107 | goto out_fail; 108 | } 109 | 110 | RLOGD("Calling the real RIL's entry point with %u args\n", argc); 111 | for (i = 0; i < argc; i++) 112 | RLOGD(" argv[%2d] = '%s'\n", i, argv[i]); 113 | 114 | // Fix RIL issues by patching memory 115 | patchMem(realRilLibHandle); 116 | 117 | //try to init the real ril 118 | mRealRadioFuncs = fRealRilInit(env, argc, argv); 119 | if (!mRealRadioFuncs) { 120 | RLOGE("The real RIL's entry point failed\n"); 121 | goto out_fail; 122 | } 123 | 124 | //copy the real RIL's info struct, then replace the onRequest pointer with our own 125 | rilInfo = *mRealRadioFuncs; 126 | rilInfo.onRequest = rilOnRequest; 127 | 128 | RLOGD("Wrapped RIL version is '%s'\n", mRealRadioFuncs->getVersion()); 129 | 130 | //we're all good - return to caller 131 | return &rilInfo; 132 | 133 | out_fail: 134 | dlclose(realRilLibHandle); 135 | return NULL; 136 | } 137 | -------------------------------------------------------------------------------- /system.prop: -------------------------------------------------------------------------------- 1 | # 2 | # system.prop for i9300 3 | # 4 | 5 | config.disable_atlas=true 6 | dalvik.vm.dexopt-data-only=1 7 | dalvik.vm.dex2oat-Xmx=256m 8 | rild.libpath=/system/lib/libsecril-shim.so 9 | rild.libargs=-d /dev/ttyS0 10 | ro.ril.telephony.mqanelements=5 11 | ro.sf.lcd_density=320 12 | ro.lcd_min_brightness=20 13 | 14 | # EGL blobs crash on screen off 15 | ro.egl.destroy_after_detach=true 16 | --------------------------------------------------------------------------------