├── .clang-format ├── Android.bp ├── BesLoudness ├── Android.bp ├── AndroidManifest.xml ├── proguard.flags ├── res │ ├── drawable │ │ └── besloudness_qs_tile_icon.xml │ ├── values-ast-rES │ │ └── strings.xml │ ├── values-az │ │ └── strings.xml │ ├── values-ca │ │ └── strings.xml │ ├── values-da │ │ └── strings.xml │ ├── values-de │ │ └── strings.xml │ ├── values-el │ │ └── strings.xml │ ├── values-en-rAU │ │ └── strings.xml │ ├── values-en-rCA │ │ └── strings.xml │ ├── values-en-rGB │ │ └── strings.xml │ ├── values-en-rIN │ │ └── strings.xml │ ├── values-fr │ │ └── strings.xml │ ├── values-fur-rIT │ │ └── strings.xml │ ├── values-it │ │ └── strings.xml │ ├── values-ja │ │ └── strings.xml │ ├── values-ka │ │ └── strings.xml │ ├── values-ko │ │ └── strings.xml │ ├── values-nl │ │ └── strings.xml │ ├── values-pl │ │ └── strings.xml │ ├── values-pt-rBR │ │ └── strings.xml │ ├── values-pt-rPT │ │ └── strings.xml │ ├── values-ro │ │ └── strings.xml │ ├── values-ru │ │ └── strings.xml │ ├── values-sl │ │ └── strings.xml │ ├── values-sq │ │ └── strings.xml │ ├── values-tr │ │ └── strings.xml │ ├── values-vi │ │ └── strings.xml │ ├── values-zh-rCN │ │ └── strings.xml │ ├── values-zh-rTW │ │ └── strings.xml │ ├── values │ │ ├── config.xml │ │ └── strings.xml │ └── xml │ │ └── besloudness_panel.xml └── src │ └── org │ └── lineageos │ └── settings │ └── device │ ├── BesLoudnessManager.java │ ├── BesLoudnessTileService.java │ ├── BootCompletedReceiver.java │ └── PreferenceActivity.java ├── InCallService ├── Android.bp ├── AndroidManifest.xml ├── res │ └── values │ │ └── strings.xml └── src │ └── org │ └── lineageos │ └── mediatek │ └── incallservice │ ├── CallStateListener.java │ ├── GainUtils.java │ ├── OnLockedBootCompleteReceiver.java │ ├── VolumeChangeReceiver.java │ └── VolumeChangeService.java ├── PowerOffAlarm ├── Android.bp ├── AndroidManifest.xml ├── com.qualcomm.qti.poweroffalarm_whitelist.xml ├── java │ ├── com │ │ └── qualcomm │ │ │ └── qti │ │ │ └── poweroffalarm │ │ │ └── PowerOffAlarmBroadcastReceiver.java │ └── org │ │ └── lineageos │ │ └── poweroffalarm │ │ ├── AlarmDriver.java │ │ ├── Driver.java │ │ ├── PowerOffAlarm.java │ │ ├── RtcDriver.java │ │ └── TimerFdDriver.java ├── jni │ ├── AlarmDriver.cpp │ ├── RtcDriver.cpp │ └── TimerFdDriver.cpp ├── proguard.flags └── res │ ├── drawable │ └── permic_power_off_alarm.xml │ └── values │ ├── config.xml │ └── strings.xml ├── README.md ├── aidl ├── gadget │ ├── Android.bp │ ├── UsbGadget.cpp │ ├── UsbGadget.h │ ├── android.hardware.usb.gadget-service.rc │ ├── android.hardware.usb.gadget-service.xml │ └── service_gadget.cpp ├── health │ ├── Android.bp │ ├── Health.cpp │ ├── android.hardware.health-service.mediatek-recovery.rc │ ├── android.hardware.health-service.mediatek.rc │ └── android.hardware.health-service.mediatek.xml ├── memtrack │ ├── Android.bp │ ├── GpuSysfsReader.cpp │ ├── GpuSysfsReader.h │ ├── Memtrack.cpp │ ├── Memtrack.h │ ├── filesystem.cpp │ ├── filesystem.h │ ├── main.cpp │ ├── memtrack_default.rc │ └── memtrack_default.xml ├── power-mediatek │ ├── Android.bp │ ├── Power.cpp │ ├── Power.h │ ├── power-mtk.xml │ └── types.h ├── thermal │ ├── Android.bp │ ├── OWNERS │ ├── Thermal.cpp │ ├── Thermal.h │ ├── android.hardware.thermal-service.mediatek.rc │ ├── android.hardware.thermal-service.mediatek.xml │ ├── init.thermal.symlinks.sh │ ├── mediatek-thermal-symlinks.rc │ ├── service.cpp │ ├── thermal-helper.cpp │ ├── thermal-helper.h │ ├── utils │ │ ├── config_schema.json │ │ ├── power_files.cpp │ │ ├── power_files.h │ │ ├── powerhal_helper.cpp │ │ ├── powerhal_helper.h │ │ ├── thermal_files.cpp │ │ ├── thermal_files.h │ │ ├── thermal_info.cpp │ │ ├── thermal_info.h │ │ ├── thermal_predictions_helper.cpp │ │ ├── thermal_predictions_helper.h │ │ ├── thermal_stats_helper.cpp │ │ ├── thermal_stats_helper.h │ │ ├── thermal_throttling.cpp │ │ ├── thermal_throttling.h │ │ ├── thermal_watcher.cpp │ │ └── thermal_watcher.h │ └── virtualtemp_estimator │ │ ├── virtualtemp_estimator.cpp │ │ ├── virtualtemp_estimator.h │ │ └── virtualtemp_estimator_data.h ├── usb-legacy │ ├── Android.bp │ ├── Usb.cpp │ ├── Usb.h │ ├── android.hardware.usb-service.mediatek-legacy.rc │ ├── android.hardware.usb-service.mediatek-legacy.xml │ └── service.cpp ├── usb │ ├── Android.bp │ ├── Usb.cpp │ ├── Usb.h │ ├── android.hardware.usb-service.mediatek.rc │ ├── android.hardware.usb-service.mediatek.xml │ └── service.cpp └── vibrator │ ├── Android.bp │ ├── Vibrator.cpp │ ├── Vibrator.h │ ├── VibratorUtils.cpp │ ├── android.hardware.vibrator.mediatek.xml │ ├── main.cpp │ └── vibrator-mediatek.rc ├── create_pl_dev ├── Android.bp ├── create_pl_dev.cpp └── create_pl_dev.rc ├── hidl └── mtkpower │ └── 1.2 │ └── default │ ├── Android.bp │ ├── MtkPerf.cpp │ ├── MtkPerf.h │ ├── MtkPower.cpp │ ├── MtkPower.h │ ├── MtkPowerCallback.cpp │ ├── MtkPowerCallback.h │ ├── service.cpp │ └── vendor.mediatek.hardware.mtkpower@1.2-service.stub.rc ├── interfaces ├── Android.bp ├── mtkpower │ ├── 1.0 │ │ ├── .hidl-autogen │ │ ├── Android.bp │ │ ├── IMtkPerf.hal │ │ └── IMtkPower.hal │ ├── 1.1 │ │ ├── .hidl-autogen │ │ ├── Android.bp │ │ ├── IMtkPerf.hal │ │ ├── IMtkPower.hal │ │ └── IMtkPowerCallback.hal │ └── 1.2 │ │ ├── .hidl-autogen │ │ ├── Android.bp │ │ ├── IMtkPerf.hal │ │ ├── IMtkPower.hal │ │ └── IMtkPowerCallback.hal └── vendor_hal_makefile_generator.sh ├── libmtkperf_client ├── Android.bp ├── mtkperf_client.c └── powerhalwrap_vendor.c ├── libwifi-hal-wrapper ├── Android.bp ├── libwifi-hal-wrapper.xml ├── libwifi-hal.cpp └── wifi_hal_legacy.h ├── sensors ├── Android.bp ├── SensorsSubHal.cpp └── SensorsSubHal.h └── vintf └── mediatek_framework_compatibility_matrix.xml /.clang-format: -------------------------------------------------------------------------------- 1 | ../../build/soong/scripts/system-clang-format -------------------------------------------------------------------------------- /Android.bp: -------------------------------------------------------------------------------- 1 | soong_namespace { 2 | imports: [ 3 | "hardware/google/interfaces", 4 | "hardware/google/pixel", 5 | ], 6 | } 7 | -------------------------------------------------------------------------------- /BesLoudness/Android.bp: -------------------------------------------------------------------------------- 1 | android_app { 2 | name: "BesLoudness", 3 | defaults: ["SettingsLibDefaults"], 4 | 5 | srcs: ["src/**/*.java"], 6 | 7 | certificate: "platform", 8 | platform_apis: true, 9 | system_ext_specific: true, 10 | 11 | static_libs: [ 12 | "androidx.core_core", 13 | "androidx.preference_preference", 14 | ], 15 | 16 | optimize: { 17 | proguard_flags_files: ["proguard.flags"], 18 | }, 19 | } 20 | -------------------------------------------------------------------------------- /BesLoudness/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 27 | 28 | 29 | 30 | 31 | 34 | 35 | 36 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /BesLoudness/proguard.flags: -------------------------------------------------------------------------------- 1 | -keep class org.lineageos.settings.device.* { 2 | *; 3 | } 4 | 5 | -keepclasseswithmembers class * { 6 | public (android.content.Context, android.util.AttributeSet); 7 | } 8 | 9 | -keep class ** extends androidx.preference.PreferenceFragment 10 | -------------------------------------------------------------------------------- /BesLoudness/res/drawable/besloudness_qs_tile_icon.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /BesLoudness/res/values-ast-rES/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness potencia\'l volume de los altavoces ya ameyora la calidá del audiu del preséu automáticamente. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-az/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness, dinamikin səs səviyyəsini artırır və cihazın səs keyfiyyətini avtomatik olaraq yüksəldir. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-ca/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness augmenta el volum de l\'altaveu i millora automàticament la qualitat d\'àudio del dispositiu. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-da/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness øger højttalerens lydstyrke og forbedrer automatisk din enheds lydkvalitet. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-de/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness erhöht die Lautstärke des Lautsprechers und verbessert die Tonqualität deines Geräts automatisch. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-el/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | Το BesLoudness ενισχύει την ένταση του ηχείου και βελτιώνει αυτόματα την ποιότητα ήχου της συσκευής σας. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-en-rAU/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness boosts the speaker volume and enhances the audio quality of your device automatically. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-en-rCA/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness boosts the speaker volume and enhances the audio quality of your device automatically. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-en-rGB/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness boosts the speaker volume and enhances the audio quality of your device automatically. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-en-rIN/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness boosts the speaker volume and enhances the audio quality of your device automatically. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-fr/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness augmente le volume du haut-parleur et améliore automatiquement la qualité sonore de votre appareil. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-fur-rIT/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness al aumente il volum de casse e al miore la cualiât dal audio dal dispositîf in automatic. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-it/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness aumenta il volume dell\'altoparlante e migliora la qualità dell\'audio del dispositivo automaticamente. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-ja/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness はスピーカーの音量を強化し、オーディオ品質を自動的に向上させます。 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-ka/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness აძლიერებს გამოცემული ხმის დონეს და ამასთანავე აუმჯობესებს მის ხარისხს. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-ko/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness는 자동으로 스피커의 볼륨을 키우고 기기의 오디오 품질을 높입니다. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-nl/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudheid verhoogt het luidsprekervolume en verbetert automatisch de audiokwaliteit van uw apparaat. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-pl/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness zwiększa głośność głośnika i automatycznie podnosi jakość dźwięku urządzenia. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-pt-rBR/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness aumenta o volume do alto-falante e melhora automaticamente a qualidade de áudio de seu dispositivo. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-pt-rPT/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | 10 | -------------------------------------------------------------------------------- /BesLoudness/res/values-ro/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness mărește volumul difuzorului și sporește calitatea audio a dispozitivului dvs. automat. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-ru/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness автоматически увеличивает громкость динамика и улучшает качество звука вашего устройства. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-sl/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness ojača glasnost zvočnika in samodejno izboljša kakovost zvoka vaše naprave. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-sq/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesZëri 9 | BesZëri rrit volumin e altoparlantit dhe përmirëson cilësinë e audios së pajisjes suaj automatikisht. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-tr/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | İyileştirilmiş Yüksek Ses 9 | İyileştirilmiş Yüksek Ses, hoparlör sesini artırır ve cihazınızın ses kalitesini otomatik olarak iyileştirir. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-vi/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness tự động tăng âm lượng loa và nâng cao chất lượng âm thanh của thiết bị. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-zh-rCN/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness 会自动提高扬声器音量并增强您设备的音频质量。 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values-zh-rTW/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness 可以提高喇叭音量並自動增強裝置音訊品質。 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/values/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | true 9 | 10 | -------------------------------------------------------------------------------- /BesLoudness/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | BesLoudness 9 | BesLoudness boosts the speaker volume and enhances the audio quality of your device automatically. 10 | 11 | -------------------------------------------------------------------------------- /BesLoudness/res/xml/besloudness_panel.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 11 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /BesLoudness/src/org/lineageos/settings/device/BesLoudnessManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | package org.lineageos.settings.device; 8 | 9 | import android.content.SharedPreferences; 10 | import android.content.BroadcastReceiver; 11 | import android.content.Context; 12 | import android.content.Intent; 13 | import android.media.AudioManager; 14 | import android.util.Log; 15 | 16 | import org.lineageos.settings.besloudness.R; 17 | 18 | public class BesLoudnessManager { 19 | public static final String TAG = "BesLoudness"; 20 | public static final String SHARED_PREFS_NAME = "besloudness"; 21 | public static final String KEY_BESLOUDNESS = "besloudness"; 22 | 23 | public static void set(final Context context, Boolean value) { 24 | final boolean defaultValue = context.getResources().getBoolean( 25 | R.bool.besloudness_default_value); 26 | final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFS_NAME, 0); 27 | if (value != null) { 28 | prefs.edit().putBoolean(KEY_BESLOUDNESS, value).apply(); 29 | } 30 | boolean newValue = prefs.getBoolean(KEY_BESLOUDNESS, defaultValue); 31 | final AudioManager amgr = (AudioManager) context.getSystemService("audio"); 32 | amgr.setParameters("SetBesLoudnessStatus=" + (newValue ? "1" : "0")); 33 | } 34 | 35 | public static boolean get(final Context context) { 36 | final boolean defaultValue = context.getResources().getBoolean( 37 | R.bool.besloudness_default_value); 38 | final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFS_NAME, 0); 39 | boolean expectedValue = prefs.getBoolean(KEY_BESLOUDNESS, defaultValue); 40 | final AudioManager amgr = (AudioManager) context.getSystemService("audio"); 41 | boolean actualValue = !("GetBesLoudnessStatus=0".equals( 42 | amgr.getParameters("GetBesLoudnessStatus"))); 43 | if (actualValue != expectedValue) { 44 | Log.e(TAG, "value mismatch, expected " + expectedValue + ", got " + actualValue); 45 | } 46 | return actualValue; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /BesLoudness/src/org/lineageos/settings/device/BesLoudnessTileService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 The LineageOS Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.lineageos.settings.device; 18 | 19 | import android.service.quicksettings.Tile; 20 | import android.service.quicksettings.TileService; 21 | 22 | public class BesLoudnessTileService extends TileService { 23 | 24 | @Override 25 | public void onStartListening() { 26 | updateQsState(); 27 | super.onStartListening(); 28 | } 29 | 30 | @Override 31 | public void onClick() { 32 | Tile tile = getQsTile(); 33 | BesLoudnessManager.set(this, !BesLoudnessManager.get(this)); 34 | updateQsState(); 35 | super.onClick(); 36 | } 37 | 38 | private void updateQsState() { 39 | Tile tile = getQsTile(); 40 | if (BesLoudnessManager.get(this)) { 41 | tile.setState(Tile.STATE_ACTIVE); 42 | } else { 43 | tile.setState(Tile.STATE_INACTIVE); 44 | } 45 | tile.updateTile(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /BesLoudness/src/org/lineageos/settings/device/BootCompletedReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | package org.lineageos.settings.device; 8 | 9 | import android.content.BroadcastReceiver; 10 | import android.content.Context; 11 | import android.content.Intent; 12 | import android.util.Log; 13 | 14 | public class BootCompletedReceiver extends BroadcastReceiver { 15 | @Override 16 | public void onReceive(final Context context, Intent intent) { 17 | Log.i(BesLoudnessManager.TAG, "Booting"); 18 | BesLoudnessManager.set(context, null); // Apply saved preference 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /BesLoudness/src/org/lineageos/settings/device/PreferenceActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | package org.lineageos.settings.device; 8 | 9 | import android.os.Bundle; 10 | import android.widget.CompoundButton; 11 | import android.widget.CompoundButton.OnCheckedChangeListener; 12 | 13 | import androidx.preference.PreferenceFragment; 14 | 15 | import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity; 16 | import com.android.settingslib.widget.MainSwitchPreference; 17 | 18 | public class PreferenceActivity extends CollapsingToolbarBaseActivity { 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | getFragmentManager() 24 | .beginTransaction() 25 | .replace(com.android.settingslib.collapsingtoolbar.R.id.content_frame, 26 | new SoundPreferenceFragment()) 27 | .commit(); 28 | } 29 | 30 | public static class SoundPreferenceFragment extends PreferenceFragment 31 | implements OnCheckedChangeListener { 32 | 33 | @Override 34 | public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { 35 | addPreferencesFromResource(org.lineageos.settings.besloudness.R.xml.besloudness_panel); 36 | MainSwitchPreference toggle = (MainSwitchPreference) 37 | findPreference(BesLoudnessManager.KEY_BESLOUDNESS); 38 | assert toggle != null; 39 | toggle.updateStatus(BesLoudnessManager.get(getContext())); 40 | toggle.addOnSwitchChangeListener(this); 41 | } 42 | 43 | @Override 44 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 45 | BesLoudnessManager.set(getContext(), isChecked); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /InCallService/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2023 The LineageOS Project 3 | // 4 | // SPDX-License-Identifier: Apache-2.0 5 | // 6 | 7 | android_app { 8 | name: "MtkInCallService", 9 | 10 | srcs: ["src/**/*.java"], 11 | 12 | certificate: "platform", 13 | platform_apis: true, 14 | privileged: true, 15 | 16 | optimize: { 17 | enabled: false, 18 | }, 19 | } 20 | -------------------------------------------------------------------------------- /InCallService/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /InCallService/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | Mediatek In-Call Service 9 | 10 | -------------------------------------------------------------------------------- /InCallService/src/org/lineageos/mediatek/incallservice/CallStateListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | package org.lineageos.mediatek.incallservice; 8 | 9 | import android.media.AudioManager; 10 | 11 | import android.telephony.TelephonyManager; 12 | import android.telephony.TelephonyCallback; 13 | 14 | import android.util.Log; 15 | 16 | public class CallStateListener extends TelephonyCallback implements TelephonyCallback.CallStateListener { 17 | private static final String LOG_TAG = "MtkInCallService"; 18 | private AudioManager mAudioManager; 19 | 20 | public CallStateListener(AudioManager audioManager) { 21 | mAudioManager = audioManager; 22 | } 23 | 24 | @Override 25 | public void onCallStateChanged(int state) { 26 | if (state == TelephonyManager.CALL_STATE_OFFHOOK || state == TelephonyManager.CALL_STATE_RINGING) { 27 | Log.d(LOG_TAG, "CallStateListener: CALL_STATE_OFFHOOK, setting gain."); 28 | GainUtils.setGainLevel(mAudioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL)); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /InCallService/src/org/lineageos/mediatek/incallservice/GainUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | package org.lineageos.mediatek.incallservice; 8 | 9 | import android.media.AudioSystem; 10 | import android.media.AudioDeviceInfo; 11 | import android.os.SystemProperties; 12 | import android.util.Log; 13 | 14 | public class GainUtils { 15 | public static final String LOG_TAG = "MtkInCallService"; 16 | public static final int volSteps = SystemProperties.getInt("ro.config.vc_call_vol_steps", 7); 17 | 18 | /** 19 | * Sets the gain level for a given audio device. 20 | * @param audioDevice The audio device to set the gain level for. 21 | * @param gainIndex The gain level to set. 22 | * @param streamType The stream type to set the gain level for. 23 | */ 24 | public static void setGainLevel(int audioDevice, int gainIndex, int streamType) { 25 | String parameters = String.format("volumeDevice=%d;volumeIndex=%d;volumeStreamType=%d", 26 | audioDevice, Math.min(volSteps, gainIndex), streamType); 27 | Log.d(LOG_TAG, "Setting audio parameters to: " + parameters); 28 | AudioSystem.setParameters(parameters); 29 | } 30 | 31 | /** 32 | * Sets the gain level for built-in earpiece and bluetooth SCO devices. 33 | * @param gainIndex The gain level to set. 34 | */ 35 | public static void setGainLevel(int gainIndex) { 36 | GainUtils.setGainLevel(AudioDeviceInfo.TYPE_BUILTIN_EARPIECE, gainIndex, AudioSystem.STREAM_VOICE_CALL); 37 | GainUtils.setGainLevel(AudioDeviceInfo.TYPE_BLUETOOTH_SCO, gainIndex, AudioSystem.STREAM_VOICE_CALL); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /InCallService/src/org/lineageos/mediatek/incallservice/OnLockedBootCompleteReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | package org.lineageos.mediatek.incallservice; 8 | 9 | import android.content.BroadcastReceiver; 10 | import android.content.Intent; 11 | import android.content.Context; 12 | 13 | import android.util.Log; 14 | 15 | public class OnLockedBootCompleteReceiver extends BroadcastReceiver { 16 | private static final String LOG_TAG = "MediatekInCallService"; 17 | 18 | @Override 19 | public void onReceive(final Context context, Intent intent) { 20 | Log.i(LOG_TAG, "onBoot"); 21 | 22 | Intent sIntent = new Intent(context, VolumeChangeService.class); 23 | context.startService(sIntent); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /InCallService/src/org/lineageos/mediatek/incallservice/VolumeChangeReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | package org.lineageos.mediatek.incallservice; 8 | 9 | import android.content.Intent; 10 | import android.content.Context; 11 | import android.content.BroadcastReceiver; 12 | 13 | import android.media.AudioManager; 14 | import android.media.AudioSystem; 15 | import android.media.AudioDeviceInfo; 16 | 17 | import android.util.Log; 18 | 19 | public class VolumeChangeReceiver extends BroadcastReceiver { 20 | public static final String LOG_TAG = "MediatekInCallService"; 21 | 22 | private AudioManager mAudioManager; 23 | 24 | public VolumeChangeReceiver(AudioManager audioManager) { 25 | mAudioManager = audioManager; 26 | } 27 | 28 | private void handleVolumeStateChange(Intent intent) { 29 | if (intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1) == AudioManager.STREAM_VOICE_CALL) { 30 | AudioDeviceInfo callDevice = mAudioManager.getCommunicationDevice(); 31 | 32 | int volumeIndex = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, -1); 33 | if (volumeIndex == -1) 34 | volumeIndex = mAudioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL); 35 | 36 | GainUtils.setGainLevel(callDevice.getPort().type(), volumeIndex, AudioSystem.STREAM_VOICE_CALL); 37 | } 38 | } 39 | 40 | @Override 41 | public void onReceive(Context context, Intent intent) { 42 | handleVolumeStateChange(intent); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /InCallService/src/org/lineageos/mediatek/incallservice/VolumeChangeService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | package org.lineageos.mediatek.incallservice; 8 | 9 | import android.media.AudioManager; 10 | 11 | import android.telephony.TelephonyManager; 12 | import android.telephony.TelephonyCallback; 13 | 14 | import android.content.Intent; 15 | import android.content.IntentFilter; 16 | import android.content.Context; 17 | import android.app.Service; 18 | import android.os.IBinder; 19 | 20 | import android.util.Log; 21 | 22 | public class VolumeChangeService extends Service { 23 | public static final String LOG_TAG = "MediatekInCallService"; 24 | 25 | private Context mContext; 26 | private VolumeChangeReceiver mVolumeChangeReceiver; 27 | private CallStateListener mCallStateListener; 28 | 29 | @Override 30 | public IBinder onBind(Intent intent) { 31 | return null; 32 | } 33 | 34 | @Override 35 | public void onDestroy() { 36 | super.onDestroy(); 37 | } 38 | 39 | @Override 40 | public int onStartCommand(Intent intent, int flags, int startid) { 41 | mContext = this; 42 | 43 | AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); 44 | TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); 45 | mVolumeChangeReceiver = new VolumeChangeReceiver(audioManager); 46 | mCallStateListener = new CallStateListener(audioManager); 47 | 48 | Log.i(LOG_TAG, "Service is starting..."); 49 | 50 | this.registerReceiver(mVolumeChangeReceiver, 51 | new IntentFilter(AudioManager.VOLUME_CHANGED_ACTION)); 52 | 53 | telephonyManager.registerTelephonyCallback(getMainExecutor(), mCallStateListener); 54 | 55 | return START_STICKY; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /PowerOffAlarm/Android.bp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2023 The LineageOS Project 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | android_app { 7 | name: "PowerOffAlarm", 8 | 9 | srcs: ["java/**/*.java"], 10 | 11 | system_ext_specific: true, 12 | certificate: "platform", 13 | privileged: true, 14 | platform_apis: true, 15 | 16 | optimize: { 17 | proguard_flags_files: ["proguard.flags"], 18 | }, 19 | jni_libs: ["libjni_poweroffalarm"], 20 | required: [ 21 | "com.qualcomm.qti.poweroffalarm_whitelist", 22 | "libjni_poweroffalarm", 23 | ], 24 | } 25 | 26 | cc_library { 27 | name: "libjni_poweroffalarm", 28 | srcs: [ 29 | "jni/AlarmDriver.cpp", 30 | "jni/RtcDriver.cpp", 31 | "jni/TimerFdDriver.cpp", 32 | ], 33 | cflags: [ 34 | "-Werror", 35 | "-Wall", 36 | "-Wextra", 37 | ], 38 | header_libs: [ 39 | "jni_headers", 40 | "libbase_headers", 41 | "generated_kernel_headers", 42 | ], 43 | shared_libs: [ 44 | "liblog", 45 | ], 46 | system_ext_specific: true, 47 | } 48 | 49 | prebuilt_etc { 50 | name: "com.qualcomm.qti.poweroffalarm_whitelist", 51 | system_ext_specific: true, 52 | relative_install_path: "sysconfig", 53 | src: "com.qualcomm.qti.poweroffalarm_whitelist.xml", 54 | filename_from_src: true, 55 | } 56 | -------------------------------------------------------------------------------- /PowerOffAlarm/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | 23 | 27 | 28 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /PowerOffAlarm/com.qualcomm.qti.poweroffalarm_whitelist.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /PowerOffAlarm/java/com/qualcomm/qti/poweroffalarm/PowerOffAlarmBroadcastReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2023 The LineageOS Project 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package com.qualcomm.qti.poweroffalarm; 7 | 8 | import android.content.BroadcastReceiver; 9 | import android.content.Context; 10 | import android.content.Intent; 11 | import android.util.Log; 12 | 13 | import org.lineageos.poweroffalarm.PowerOffAlarm; 14 | 15 | public class PowerOffAlarmBroadcastReceiver extends BroadcastReceiver { 16 | private static final String ACTION_CANCEL_POWEROFF_ALARM = "org.codeaurora.poweroffalarm.action.CANCEL_ALARM"; 17 | private static final String ACTION_SET_POWEROFF_ALARM = "org.codeaurora.poweroffalarm.action.SET_ALARM"; 18 | private static final String TAG = "PowerOffAlarmBroadcastReceiver"; 19 | private static final String TIME = "time"; 20 | 21 | @Override 22 | public void onReceive(Context context, Intent intent) { 23 | if (intent == null) { 24 | Log.w(TAG, "Dropping null intent."); 25 | return; 26 | } 27 | String action = intent.getAction(); 28 | boolean isSetAlarm = ACTION_SET_POWEROFF_ALARM.equals(action); 29 | boolean isCancelAlarm = ACTION_CANCEL_POWEROFF_ALARM.equals(action); 30 | final long alarmTime = intent.getLongExtra(TIME, -1L); 31 | if (!(isSetAlarm || isCancelAlarm) || alarmTime <= 0) { 32 | Log.w(TAG, "Dropping malformed intent with action " + action + ". " 33 | + "alarmTime=" + alarmTime); 34 | return; 35 | } 36 | Log.d(TAG, "Receive " + (isSetAlarm ? "set" : "cancel") + " intent."); 37 | final PowerOffAlarm powerOffAlarm = new PowerOffAlarm(context); 38 | final long alarmInPref = powerOffAlarm.getAlarmFromPreference(); 39 | Log.d(TAG, "alarmTime=" + alarmTime + " alarmInPref=" + alarmInPref); 40 | if (isSetAlarm) { 41 | powerOffAlarm.saveAlarmToPreference(alarmTime); 42 | powerOffAlarm.setAlarmToRtc(alarmTime); 43 | } else if (isCancelAlarm && alarmTime == alarmInPref) { 44 | powerOffAlarm.saveAlarmToPreference(0L); 45 | powerOffAlarm.cancelAlarmInRtc(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /PowerOffAlarm/java/org/lineageos/poweroffalarm/AlarmDriver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2023 The LineageOS Project 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.lineageos.poweroffalarm; 7 | 8 | public class AlarmDriver implements Driver { 9 | 10 | static { 11 | System.loadLibrary("jni_poweroffalarm"); 12 | } 13 | 14 | public native void set(long time); 15 | public native void cancel(); 16 | public native long getRtcTimeOptional(); 17 | public native boolean isSupported(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /PowerOffAlarm/java/org/lineageos/poweroffalarm/Driver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2023 The LineageOS Project 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.lineageos.poweroffalarm; 7 | 8 | /** 9 | * Driver interface 10 | * guranteed to be called on single thread 11 | */ 12 | public interface Driver { 13 | 14 | /** 15 | * Set auto boot to RTC time 16 | * @param time the unix time (as per RTC) when to wake up 17 | */ 18 | public void set(long time); 19 | 20 | /** 21 | * cancel RTC auto boot 22 | */ 23 | public void cancel(); 24 | 25 | /** 26 | * get current unix time as per RTC if supported 27 | * used to account for differences between RTC and AP time 28 | * @return value if supported, or -1L 29 | */ 30 | public long getRtcTimeOptional(); 31 | 32 | /** 33 | * indicate if this driver backend is supported for RTC wakeup 34 | * if this method returns false, it is guranteed that no other methods will be called 35 | * @return true if this driver is supported 36 | */ 37 | public boolean isSupported(); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /PowerOffAlarm/java/org/lineageos/poweroffalarm/PowerOffAlarm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2023 The LineageOS Project 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.lineageos.poweroffalarm; 7 | 8 | import android.content.Context; 9 | import android.content.SharedPreferences; 10 | import android.preference.PreferenceManager; 11 | import android.util.Log; 12 | 13 | import com.qualcomm.qti.poweroffalarm.R; 14 | 15 | public class PowerOffAlarm { 16 | private static final String TAG = "PowerOffAlarm"; 17 | private static final String PREF_KEY_ALARM_TIME = "alarm_time"; 18 | private static final boolean DEBUG = false; 19 | 20 | private final Context mContext; 21 | private final long mPreBootMillisec; 22 | private final Driver mDriver; 23 | private final SharedPreferences mPrefs; 24 | 25 | public PowerOffAlarm(Context context) { 26 | mContext = context; 27 | mPreBootMillisec = mContext.getResources().getInteger(R.integer.config_preBootMillis); 28 | final String driverConfig = mContext.getString(R.string.config_powerOffAlarmDrivers); 29 | Log.d(TAG, "trying driver config " + driverConfig); 30 | final String[] drivers = driverConfig != null ? driverConfig.split(",") : new String[0]; 31 | Driver driver = null; 32 | for (String driverName : drivers) { 33 | Log.d(TAG, "trying driver " + driverName); 34 | switch (driverName) { 35 | case "alarm": 36 | driver = new AlarmDriver(); 37 | break; 38 | case "rtc": 39 | driver = new RtcDriver(); 40 | break; 41 | case "timerfd": 42 | driver = new TimerFdDriver(); 43 | break; 44 | default: 45 | Log.w(TAG, "driver " + driverName + " does not exist"); 46 | break; 47 | } 48 | boolean isSupported = false; 49 | if (driver != null) { 50 | try { 51 | isSupported = driver.isSupported(); 52 | } catch (Exception e) { 53 | Log.e(TAG, Log.getStackTraceString(e)); 54 | } 55 | } 56 | if (isSupported) { 57 | Log.d(TAG, "selected driver " + driverName); 58 | break; 59 | } 60 | Log.d(TAG, "driver " + driverName + " is not supported"); 61 | driver = null; 62 | } 63 | mDriver = driver; 64 | if (mDriver == null) { 65 | Log.w(TAG, "no driver found, disabling PowerOffAlarm"); 66 | } 67 | mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); 68 | } 69 | 70 | public void saveAlarmToPreference(long time) { 71 | mPrefs.edit().putLong(PREF_KEY_ALARM_TIME, time).apply(); 72 | } 73 | 74 | public long getAlarmFromPreference() { 75 | return mPrefs.getLong(PREF_KEY_ALARM_TIME, 0L); 76 | } 77 | 78 | public void cancelAlarmInRtc() { 79 | if (mDriver != null) { 80 | try { 81 | mDriver.cancel(); 82 | } catch (Exception e) { 83 | Log.e(TAG, Log.getStackTraceString(e)); 84 | } 85 | } 86 | } 87 | 88 | public void setAlarmToRtc(long time) { 89 | if (mDriver != null) { 90 | long currentTime = System.currentTimeMillis(); 91 | if (time <= currentTime + mPreBootMillisec) { 92 | Log.w(TAG, time + " is too early, current time is " + currentTime + "!"); 93 | return; 94 | } 95 | long rtcTime = -1; 96 | try { 97 | rtcTime = mDriver.getRtcTimeOptional(); 98 | if (DEBUG) Log.v(TAG, "read rtcTime " + rtcTime + " current " + currentTime); 99 | } catch (Exception e) { 100 | Log.e(TAG, Log.getStackTraceString(e)); 101 | } 102 | if (rtcTime > 0) { 103 | // Account for differences in counting between RTC and AP clock, if needed 104 | long timeDiff = time - currentTime; 105 | time = (rtcTime + timeDiff) - mPreBootMillisec; 106 | } else { 107 | time -= mPreBootMillisec; 108 | } 109 | try { 110 | mDriver.set(time); 111 | } catch (Exception e) { 112 | Log.e(TAG, Log.getStackTraceString(e)); 113 | } 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /PowerOffAlarm/java/org/lineageos/poweroffalarm/RtcDriver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2023 The LineageOS Project 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.lineageos.poweroffalarm; 7 | 8 | public class RtcDriver implements Driver { 9 | 10 | static { 11 | System.loadLibrary("jni_poweroffalarm"); 12 | } 13 | 14 | public native void set(long time); 15 | public native void cancel(); 16 | public native long getRtcTimeOptional(); 17 | public native boolean isSupported(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /PowerOffAlarm/java/org/lineageos/poweroffalarm/TimerFdDriver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2023 The LineageOS Project 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | package org.lineageos.poweroffalarm; 7 | 8 | public class TimerFdDriver implements Driver { 9 | 10 | static { 11 | System.loadLibrary("jni_poweroffalarm"); 12 | } 13 | 14 | public native void set(long time); 15 | public native void cancel(); 16 | public native long getRtcTimeOptional(); 17 | public native boolean isSupported(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /PowerOffAlarm/jni/AlarmDriver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2023 The LineageOS Project 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #define ALARM_IOW(c, type, size) _IOW('a', (c) | ((type) << 4), size) 17 | #define ANDROID_ALARM_SET(type) ALARM_IOW(2,type,struct timespec) 18 | #define ANDROID_ALARM_POWER_ON_LOGO 7 19 | 20 | static std::string alarm_dev = "/dev/alarm"; 21 | 22 | extern "C" jboolean Java_org_lineageos_poweroffalarm_AlarmDriver_isSupported( 23 | JNIEnv*, jobject) { 24 | return access(alarm_dev.c_str(), F_OK) == 0; 25 | } 26 | 27 | extern "C" void Java_org_lineageos_poweroffalarm_AlarmDriver_set( 28 | JNIEnv*, jobject, jlong time) { 29 | android::base::unique_fd fd{open(alarm_dev.c_str(), O_WRONLY)}; 30 | if (!fd.ok()) { 31 | ALOGE("Unable to open %s: %s", alarm_dev.c_str(), strerror(errno)); 32 | return; 33 | } 34 | 35 | struct timespec ts = {}; 36 | ts.tv_sec = time / 1000; 37 | ts.tv_nsec = (time % 1000) * 1000000; 38 | 39 | if (ioctl(fd, ANDROID_ALARM_SET(ANDROID_ALARM_POWER_ON_LOGO), &ts) == -1) { 40 | ALOGV("ANDROID_ALARM_SET ioctl failed: %s", strerror(errno)); 41 | return; 42 | } 43 | } 44 | 45 | extern "C" void Java_org_lineageos_poweroffalarm_AlarmDriver_cancel( 46 | JNIEnv* env, jobject thiz) { 47 | Java_org_lineageos_poweroffalarm_AlarmDriver_set(env, thiz, 0); 48 | } 49 | 50 | extern "C" jlong Java_org_lineageos_poweroffalarm_AlarmDriver_getRtcTimeOptional( 51 | JNIEnv*, jobject) { 52 | return -1L; 53 | } 54 | -------------------------------------------------------------------------------- /PowerOffAlarm/jni/RtcDriver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2023 The LineageOS Project 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #define RTC_POFF_ALM_SET _IOW('p', 0x15, struct rtc_time) 18 | 19 | static std::string rtc_dev = "/dev/rtc0"; 20 | 21 | extern "C" jboolean Java_org_lineageos_poweroffalarm_RtcDriver_isSupported( 22 | JNIEnv*, jobject) { 23 | return access(rtc_dev.c_str(), F_OK) == 0; 24 | } 25 | 26 | extern "C" void Java_org_lineageos_poweroffalarm_RtcDriver_set( 27 | JNIEnv*, jobject, jlong time) { 28 | android::base::unique_fd fd{open(rtc_dev.c_str(), O_WRONLY)}; 29 | if (!fd.ok()) { 30 | ALOGE("Unable to open %s: %s", rtc_dev.c_str(), strerror(errno)); 31 | return; 32 | } 33 | 34 | struct tm tm = {}; 35 | long ctime = time / 1000; 36 | if (!gmtime_r(&ctime, &tm)) { 37 | ALOGV("gmtime_r() failed: %s", strerror(errno)); 38 | return; 39 | } 40 | 41 | struct rtc_time rtc = {}; 42 | rtc.tm_sec = tm.tm_sec; 43 | rtc.tm_min = tm.tm_min; 44 | rtc.tm_hour = tm.tm_hour; 45 | rtc.tm_mday = tm.tm_mday; 46 | rtc.tm_mon = tm.tm_mon; 47 | rtc.tm_year = tm.tm_year; 48 | rtc.tm_wday = tm.tm_wday; 49 | rtc.tm_yday = tm.tm_yday; 50 | rtc.tm_isdst = tm.tm_isdst; 51 | if (ioctl(fd, RTC_POFF_ALM_SET, &rtc) == -1) { 52 | ALOGV("RTC_POFF_ALM_SET ioctl failed: %s", strerror(errno)); 53 | return; 54 | } 55 | } 56 | 57 | extern "C" void Java_org_lineageos_poweroffalarm_RtcDriver_cancel( 58 | JNIEnv* env, jobject thiz) { 59 | Java_org_lineageos_poweroffalarm_RtcDriver_set(env, thiz, 0); 60 | } 61 | 62 | extern "C" jlong Java_org_lineageos_poweroffalarm_RtcDriver_getRtcTimeOptional( 63 | JNIEnv*, jobject) { 64 | android::base::unique_fd fd{open(rtc_dev.c_str(), O_RDWR)}; 65 | if (!fd.ok()) { 66 | ALOGE("Unable to open %s: %s", rtc_dev.c_str(), strerror(errno)); 67 | return -1; 68 | } 69 | 70 | struct rtc_time rtc = {}; 71 | if (ioctl(fd, RTC_RD_TIME, &rtc) == -1) { 72 | ALOGV("RTC_RD_TIME ioctl failed: %s", strerror(errno)); 73 | return -1; 74 | } 75 | 76 | struct tm tm = {}; 77 | tm.tm_sec = rtc.tm_sec; 78 | tm.tm_min = rtc.tm_min; 79 | tm.tm_hour = rtc.tm_hour; 80 | tm.tm_mday = rtc.tm_mday; 81 | tm.tm_mon = rtc.tm_mon; 82 | tm.tm_year = rtc.tm_year; 83 | tm.tm_wday = rtc.tm_wday; 84 | tm.tm_yday = rtc.tm_yday; 85 | tm.tm_isdst = rtc.tm_isdst; 86 | long time = timegm(&tm); 87 | if (time < 0) { 88 | ALOGV("timegm() failed: %s", strerror(errno)); 89 | return -1; 90 | } 91 | 92 | return time * 1000; 93 | } 94 | -------------------------------------------------------------------------------- /PowerOffAlarm/jni/TimerFdDriver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2023 The LineageOS Project 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | extern "C" jboolean Java_org_lineageos_poweroffalarm_TimerFdDriver_isSupported( 18 | JNIEnv*, jobject) { 19 | #ifdef CLOCK_POWER_OFF_ALARM 20 | return true; 21 | #else 22 | return false; 23 | #endif 24 | } 25 | 26 | extern "C" void Java_org_lineageos_poweroffalarm_TimerFdDriver_set( 27 | JNIEnv*, jobject, [[maybe_unused]] jlong time) { 28 | #ifdef CLOCK_POWER_OFF_ALARM 29 | android::base::unique_fd fd{timerfd_create(CLOCK_POWER_OFF_ALARM, TFD_NONBLOCK)}; 30 | if (!fd.ok()) { 31 | ALOGE("Unable to open CLOCK_POWER_OFF_ALARM: %s", strerror(errno)); 32 | return; 33 | } 34 | 35 | struct timespec ts = {}; 36 | ts.tv_sec = time / 1000; 37 | ts.tv_nsec = (time % 1000) * 1000000; 38 | 39 | struct itimerspec spec = {}; 40 | memcpy(&spec.it_value, &ts, sizeof(spec.it_value)); 41 | 42 | timerfd_settime(fd, TFD_TIMER_ABSTIME, &spec, NULL); 43 | #endif 44 | } 45 | 46 | extern "C" void Java_org_lineageos_poweroffalarm_TimerFdDriver_cancel( 47 | JNIEnv*, jobject) { 48 | #ifdef CLOCK_POWER_OFF_ALARM 49 | android::base::unique_fd fd{timerfd_create(CLOCK_POWER_OFF_ALARM, TFD_NONBLOCK)}; 50 | if (!fd.ok()) { 51 | ALOGE("Unable to open CLOCK_POWER_OFF_ALARM: %s", strerror(errno)); 52 | return; 53 | } 54 | 55 | struct itimerspec spec = {}; 56 | timerfd_settime(fd, TFD_TIMER_ABSTIME, &spec, NULL); 57 | #endif 58 | } 59 | 60 | extern "C" jlong Java_org_lineageos_poweroffalarm_TimerFdDriver_getRtcTimeOptional( 61 | JNIEnv*, jobject) { 62 | return -1L; 63 | } 64 | -------------------------------------------------------------------------------- /PowerOffAlarm/proguard.flags: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LineageOS/android_hardware_mediatek/6e579f65d78b86a5aea5c03fa742a5a7b852765c/PowerOffAlarm/proguard.flags -------------------------------------------------------------------------------- /PowerOffAlarm/res/drawable/permic_power_off_alarm.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /PowerOffAlarm/res/values/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 20 | timerfd,alarm,rtc 21 | 22 | 27 | 150000 28 | 29 | 30 | -------------------------------------------------------------------------------- /PowerOffAlarm/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | Power off alarm 8 | set and clear the alarm which will wake up device from the power off state 9 | Power off alarm 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Common hardware components for MediaTek devices 2 | -------------------------------------------------------------------------------- /aidl/gadget/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // SPDX-FileCopyrightText: 2021 The Android Open Source Project 3 | // SPDX-FileCopyrightText: 2024 The LineageOS Project 4 | // SPDX-License-Identifier: Apache-2.0 5 | // 6 | 7 | cc_binary { 8 | name: "android.hardware.usb.gadget-service.mediatek", 9 | relative_install_path: "hw", 10 | init_rc: ["android.hardware.usb.gadget-service.rc"], 11 | vintf_fragments: [ 12 | "android.hardware.usb.gadget-service.xml", 13 | ], 14 | vendor: true, 15 | srcs: [ 16 | "service_gadget.cpp", 17 | "UsbGadget.cpp", 18 | ], 19 | cflags: [ 20 | "-Wall", 21 | "-Werror", 22 | ], 23 | shared_libs: [ 24 | "libbase", 25 | "liblog", 26 | "libutils", 27 | "android.frameworks.stats-V1-ndk", 28 | "android.hardware.usb.gadget-V1-ndk", 29 | "libcutils", 30 | "libbinder_ndk", 31 | ], 32 | static_libs: [ 33 | "libpixelusb-aidl", 34 | ], 35 | proprietary: true, 36 | export_shared_lib_headers: [ 37 | "android.frameworks.stats-V1-ndk", 38 | ], 39 | } 40 | -------------------------------------------------------------------------------- /aidl/gadget/UsbGadget.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2020 The Android Open Source Project 3 | * SPDX-FileCopyrightText: 2024 The LineageOS Project 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace aidl { 30 | namespace android { 31 | namespace hardware { 32 | namespace usb { 33 | namespace gadget { 34 | 35 | using ::aidl::android::hardware::usb::gadget::GadgetFunction; 36 | using ::aidl::android::hardware::usb::gadget::IUsbGadget; 37 | using ::aidl::android::hardware::usb::gadget::IUsbGadgetCallback; 38 | using ::aidl::android::hardware::usb::gadget::Status; 39 | using ::aidl::android::hardware::usb::gadget::UsbSpeed; 40 | using ::android::base::GetProperty; 41 | using ::android::base::ReadFileToString; 42 | using ::android::base::SetProperty; 43 | using ::android::base::Trim; 44 | using ::android::base::unique_fd; 45 | using ::android::base::WriteStringToFile; 46 | using ::android::hardware::google::pixel::usb::addAdb; 47 | using ::android::hardware::google::pixel::usb::addEpollFd; 48 | using ::android::hardware::google::pixel::usb::kDebug; 49 | using ::android::hardware::google::pixel::usb::kDisconnectWaitUs; 50 | using ::android::hardware::google::pixel::usb::linkFunction; 51 | using ::android::hardware::google::pixel::usb::MonitorFfs; 52 | using ::android::hardware::google::pixel::usb::resetGadget; 53 | using ::android::hardware::google::pixel::usb::setVidPid; 54 | using ::android::hardware::google::pixel::usb::unlinkFunctions; 55 | using ::ndk::ScopedAStatus; 56 | using ::std::shared_ptr; 57 | using ::std::string; 58 | 59 | const std::string kGadgetName = GetProperty("sys.usb.controller", ""); 60 | 61 | #define UDC_PATH "/sys/class/udc/" 62 | #define DEVICE "device/" 63 | #define SPEED_PATH "current_speed" 64 | #define SAVING_PATH DEVICE "saving" 65 | 66 | struct UsbGadget : public BnUsbGadget { 67 | UsbGadget(); 68 | 69 | // Makes sure that only one request is processed at a time. 70 | std::mutex mLockSetCurrentFunction; 71 | long mCurrentUsbFunctions; 72 | bool mCurrentUsbFunctionsApplied; 73 | UsbSpeed mUsbSpeed; 74 | MonitorFfs* mMonitorFfs; 75 | 76 | ScopedAStatus setCurrentUsbFunctions(long functions, 77 | const shared_ptr& callback, 78 | int64_t timeout, int64_t in_transactionId) override; 79 | 80 | ScopedAStatus getCurrentUsbFunctions(const shared_ptr& callback, 81 | int64_t in_transactionId) override; 82 | 83 | ScopedAStatus reset(const shared_ptr& callback, 84 | int64_t in_transactionId) override; 85 | 86 | ScopedAStatus getUsbSpeed(const shared_ptr& callback, 87 | int64_t in_transactionId) override; 88 | 89 | ScopedAStatus setVidPid(const char* vid, const char* pid); 90 | 91 | private: 92 | Status tearDownGadget(); 93 | Status setupFunctions(long functions, const shared_ptr& callback, 94 | uint64_t timeout, int64_t in_transactionId); 95 | }; 96 | 97 | } // namespace gadget 98 | } // namespace usb 99 | } // namespace hardware 100 | } // namespace android 101 | } // namespace aidl 102 | -------------------------------------------------------------------------------- /aidl/gadget/android.hardware.usb.gadget-service.rc: -------------------------------------------------------------------------------- 1 | service vendor.usb-gadget-hal /vendor/bin/hw/android.hardware.usb.gadget-service.mediatek 2 | class hal 3 | user system 4 | group system shell mtp 5 | disabled 6 | 7 | on property:sys.usb.configfs=2 8 | enable vendor.usb-gadget-hal 9 | -------------------------------------------------------------------------------- /aidl/gadget/android.hardware.usb.gadget-service.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | android.hardware.usb.gadget 4 | 1 5 | 6 | IUsbGadget 7 | default 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /aidl/gadget/service_gadget.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2021 The Android Open Source Project 3 | * SPDX-FileCopyrightText: 2024 The LineageOS Project 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #define LOG_TAG "android.hardware.usb.gadget-service.mediatek" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "UsbGadget.h" 14 | 15 | using android::OK; 16 | using android::sp; 17 | using android::status_t; 18 | 19 | using aidl::android::hardware::usb::gadget::UsbGadget; 20 | 21 | int main() { 22 | ABinderProcess_setThreadPoolMaxThreadCount(0); 23 | std::shared_ptr usbgadget = ndk::SharedRefBase::make(); 24 | 25 | const std::string instance = std::string() + UsbGadget::descriptor + "/default"; 26 | binder_status_t status = 27 | AServiceManager_addService(usbgadget->asBinder().get(), instance.c_str()); 28 | CHECK(status == STATUS_OK); 29 | 30 | ALOGV("AIDL USB Gadget HAL about to start"); 31 | ABinderProcess_joinThreadPool(); 32 | return -1; // Should never be reached 33 | } 34 | -------------------------------------------------------------------------------- /aidl/health/Android.bp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | cc_defaults { 8 | name: "android.hardware.health-service.mediatek-defaults", 9 | defaults: [ 10 | "libhealth_aidl_impl_user", 11 | "libhealth_aidl_charger_defaults", 12 | ], 13 | relative_install_path: "hw", 14 | vintf_fragments: ["android.hardware.health-service.mediatek.xml"], 15 | srcs: [ 16 | "Health.cpp", 17 | ], 18 | static_libs: [ 19 | "libhealth_aidl_impl", 20 | ], 21 | } 22 | 23 | cc_binary { 24 | name: "android.hardware.health-service.mediatek", 25 | defaults: ["android.hardware.health-service.mediatek-defaults"], 26 | vendor: true, 27 | init_rc: ["android.hardware.health-service.mediatek.rc"], 28 | overrides: ["charger"], 29 | } 30 | 31 | cc_binary { 32 | name: "android.hardware.health-service.mediatek-recovery", 33 | defaults: ["android.hardware.health-service.mediatek-defaults"], 34 | recovery: true, 35 | init_rc: ["android.hardware.health-service.mediatek-recovery.rc"], 36 | overrides: ["charger.recovery"], 37 | } 38 | -------------------------------------------------------------------------------- /aidl/health/Health.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 The Android Open Source Project 3 | * Copyright (C) 2022 The LineageOS Project 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #ifndef CHARGER_FORCE_NO_UI 14 | #define CHARGER_FORCE_NO_UI 0 15 | #endif 16 | 17 | #if !CHARGER_FORCE_NO_UI 18 | #include 19 | #endif 20 | 21 | using aidl::android::hardware::health::HalHealthLoop; 22 | using aidl::android::hardware::health::Health; 23 | 24 | #if !CHARGER_FORCE_NO_UI 25 | using aidl::android::hardware::health::charger::ChargerCallback; 26 | using aidl::android::hardware::health::charger::ChargerModeMain; 27 | #endif 28 | 29 | static constexpr const char* gInstanceName = "default"; 30 | static constexpr std::string_view gChargerArg{"--charger"}; 31 | 32 | #if !CHARGER_FORCE_NO_UI 33 | namespace aidl::android::hardware::health { 34 | class ChargerCallbackImpl : public ChargerCallback { 35 | public: 36 | using ChargerCallback::ChargerCallback; 37 | bool ChargerEnableSuspend() override { return true; } 38 | }; 39 | } // namespace aidl::android::hardware::health 40 | #endif 41 | 42 | int main(int argc, char** argv) { 43 | #ifdef __ANDROID_RECOVERY__ 44 | android::base::InitLogging(argv, android::base::KernelLogger); 45 | #endif 46 | 47 | // make a default health service 48 | auto config = std::make_unique(); 49 | ::android::hardware::health::InitHealthdConfig(config.get()); 50 | auto binder = ndk::SharedRefBase::make(gInstanceName, std::move(config)); 51 | 52 | if (argc >= 2 && argv[1] == gChargerArg) { 53 | #if !CHARGER_FORCE_NO_UI 54 | // If charger shouldn't have UI for your device, simply drop the line below 55 | // for your service implementation. This corresponds to 56 | // ro.charger.no_ui=true 57 | return ChargerModeMain(binder, std::make_shared(binder)); 58 | #endif 59 | 60 | LOG(INFO) << "Starting charger mode without UI."; 61 | } else { 62 | LOG(INFO) << "Starting health HAL."; 63 | } 64 | 65 | auto hal_health_loop = std::make_shared(binder, binder); 66 | return hal_health_loop->StartLoop(); 67 | } 68 | -------------------------------------------------------------------------------- /aidl/health/android.hardware.health-service.mediatek-recovery.rc: -------------------------------------------------------------------------------- 1 | service vendor.health-mediatek /system/bin/hw/android.hardware.health-service.mediatek-recovery 2 | class hal 3 | seclabel u:r:hal_health_default:s0 4 | user system 5 | group system 6 | capabilities WAKE_ALARM BLOCK_SUSPEND 7 | file /dev/kmsg w 8 | -------------------------------------------------------------------------------- /aidl/health/android.hardware.health-service.mediatek.rc: -------------------------------------------------------------------------------- 1 | service vendor.health-mediatek /vendor/bin/hw/android.hardware.health-service.mediatek 2 | class hal 3 | user system 4 | group system 5 | capabilities WAKE_ALARM BLOCK_SUSPEND 6 | file /dev/kmsg w 7 | 8 | service vendor.charger /vendor/bin/hw/android.hardware.health-service.mediatek --charger 9 | class charger 10 | seclabel u:r:charger_vendor:s0 11 | user system 12 | group system wakelock input 13 | capabilities SYS_BOOT 14 | file /dev/kmsg w 15 | file /sys/fs/pstore/console-ramoops-0 r 16 | file /sys/fs/pstore/console-ramoops r 17 | file /proc/last_kmsg r 18 | 19 | on charger 20 | chown system system /dev/graphics/fb0 21 | chown system system /dev/dri/card0 22 | -------------------------------------------------------------------------------- /aidl/health/android.hardware.health-service.mediatek.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | android.hardware.health 4 | 3 5 | IHealth/default 6 | 7 | 8 | -------------------------------------------------------------------------------- /aidl/memtrack/Android.bp: -------------------------------------------------------------------------------- 1 | cc_binary { 2 | name: "android.hardware.memtrack-service.mediatek-mali", 3 | relative_install_path: "hw", 4 | init_rc: ["memtrack_default.rc"], 5 | vintf_fragments: ["memtrack_default.xml"], 6 | vendor: true, 7 | shared_libs: [ 8 | "android.hardware.memtrack-V1-ndk", 9 | "libbase", 10 | "libbinder_ndk", 11 | "liblog", 12 | ], 13 | srcs: [ 14 | "Memtrack.cpp", 15 | "GpuSysfsReader.cpp", 16 | "filesystem.cpp", 17 | "main.cpp", 18 | ], 19 | } 20 | -------------------------------------------------------------------------------- /aidl/memtrack/GpuSysfsReader.cpp: -------------------------------------------------------------------------------- 1 | #include "GpuSysfsReader.h" 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include "filesystem.h" 9 | 10 | #undef LOG_TAG 11 | #define LOG_TAG "memtrack-gpusysfsreader" 12 | 13 | using namespace GpuSysfsReader; 14 | 15 | namespace { 16 | uint64_t readNode(const std::string node, pid_t pid) { 17 | std::stringstream ss; 18 | if (pid) 19 | ss << kSysfsDevicePath << "/" << kProcessDir << "/" << pid << "/" << node; 20 | else 21 | ss << kSysfsDevicePath << "/" << node; 22 | const std::string path = ss.str(); 23 | 24 | if (!filesystem::exists(filesystem::path(path))) { 25 | ALOGV("File not found: %s", path.c_str()); 26 | return 0; 27 | } 28 | 29 | std::ifstream file(path.c_str()); 30 | if (!file.is_open()) { 31 | ALOGW("Failed to open %s path", path.c_str()); 32 | return 0; 33 | } 34 | 35 | uint64_t out; 36 | file >> out; 37 | file.close(); 38 | 39 | return out; 40 | } 41 | } // namespace 42 | 43 | uint64_t GpuSysfsReader::getDmaBufGpuMem(pid_t pid) { return readNode(kDmaBufGpuMemNode, pid); } 44 | 45 | uint64_t GpuSysfsReader::getGpuMemTotal(pid_t pid) { return readNode(kTotalGpuMemNode, pid); } 46 | 47 | uint64_t GpuSysfsReader::getPrivateGpuMem(pid_t pid) { 48 | auto dma_buf_size = getDmaBufGpuMem(pid); 49 | auto gpu_total_size = getGpuMemTotal(pid); 50 | 51 | if (dma_buf_size > gpu_total_size) { 52 | ALOGE("Bug in reader, dma-buf size (%" PRIu64 ") is higher than total gpu size (%" PRIu64 53 | ")", 54 | dma_buf_size, gpu_total_size); 55 | return 0; 56 | } 57 | 58 | return gpu_total_size - dma_buf_size; 59 | } 60 | -------------------------------------------------------------------------------- /aidl/memtrack/GpuSysfsReader.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | namespace GpuSysfsReader { 8 | uint64_t getDmaBufGpuMem(pid_t pid = 0); 9 | uint64_t getGpuMemTotal(pid_t pid = 0); 10 | uint64_t getPrivateGpuMem(pid_t pid = 0); 11 | 12 | constexpr char kSysfsDevicePath[] = "/sys/class/misc/mali0/device"; 13 | constexpr char kProcessDir[] = "kprcs"; 14 | constexpr char kMappedDmaBufsDir[] = "dma_bufs"; 15 | constexpr char kTotalGpuMemNode[] = "total_gpu_mem"; 16 | constexpr char kDmaBufGpuMemNode[] = "dma_buf_gpu_mem"; 17 | } // namespace GpuSysfsReader 18 | -------------------------------------------------------------------------------- /aidl/memtrack/Memtrack.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "GpuSysfsReader.h" 9 | #include "filesystem.h" 10 | 11 | #undef LOG_TAG 12 | #define LOG_TAG "memtrack-core" 13 | 14 | namespace aidl { 15 | namespace android { 16 | namespace hardware { 17 | namespace memtrack { 18 | 19 | ndk::ScopedAStatus Memtrack::getMemory(int pid, MemtrackType type, 20 | std::vector* _aidl_return) { 21 | if (pid < 0) 22 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT)); 23 | 24 | if (type != MemtrackType::OTHER && type != MemtrackType::GL && type != MemtrackType::GRAPHICS && 25 | type != MemtrackType::MULTIMEDIA && type != MemtrackType::CAMERA) 26 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 27 | 28 | _aidl_return->clear(); 29 | 30 | // Other types are retained only for backward compatibility 31 | if (type != MemtrackType::GL && type != MemtrackType::GRAPHICS) 32 | return ndk::ScopedAStatus::ok(); 33 | 34 | // pid 0 is only supported for GL type to report total private memory 35 | if (pid == 0 && type != MemtrackType::GL) 36 | return ndk::ScopedAStatus::ok(); 37 | 38 | uint64_t size = 0; 39 | switch (type) { 40 | case MemtrackType::GL: 41 | size = GpuSysfsReader::getPrivateGpuMem(pid); 42 | break; 43 | case MemtrackType::GRAPHICS: 44 | // TODO(b/194483693): This is not PSS as required by memtrack HAL 45 | // but complete dmabuf allocations. Reporting PSS requires reading 46 | // procfs. This HAL does not have that permission yet. 47 | size = GpuSysfsReader::getDmaBufGpuMem(pid); 48 | break; 49 | default: 50 | break; 51 | } 52 | 53 | MemtrackRecord record = { 54 | .flags = MemtrackRecord::FLAG_SMAPS_UNACCOUNTED, 55 | .sizeInBytes = static_cast(size), 56 | }; 57 | _aidl_return->emplace_back(record); 58 | 59 | return ndk::ScopedAStatus::ok(); 60 | } 61 | 62 | ndk::ScopedAStatus Memtrack::getGpuDeviceInfo(std::vector* _aidl_return) { 63 | auto devPath = filesystem::path(GpuSysfsReader::kSysfsDevicePath); 64 | std::string devName = "default-gpu"; 65 | if (filesystem::exists(devPath) && filesystem::is_symlink(devPath)) { 66 | devName = filesystem::read_symlink(devPath).filename().string(); 67 | } 68 | 69 | DeviceInfo dev_info = {.id = 0, .name = devName}; 70 | 71 | _aidl_return->clear(); 72 | _aidl_return->emplace_back(dev_info); 73 | return ndk::ScopedAStatus::ok(); 74 | } 75 | 76 | } // namespace memtrack 77 | } // namespace hardware 78 | } // namespace android 79 | } // namespace aidl 80 | -------------------------------------------------------------------------------- /aidl/memtrack/Memtrack.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace aidl { 10 | namespace android { 11 | namespace hardware { 12 | namespace memtrack { 13 | 14 | class Memtrack : public BnMemtrack { 15 | public: 16 | ndk::ScopedAStatus getMemory(int pid, MemtrackType type, 17 | std::vector* _aidl_return) override; 18 | 19 | ndk::ScopedAStatus getGpuDeviceInfo(std::vector* _aidl_return) override; 20 | }; 21 | 22 | } // namespace memtrack 23 | } // namespace hardware 24 | } // namespace android 25 | } // namespace aidl 26 | -------------------------------------------------------------------------------- /aidl/memtrack/filesystem.cpp: -------------------------------------------------------------------------------- 1 | #include "filesystem.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace filesystem { 14 | 15 | bool exists(const path& p) { 16 | struct stat s; 17 | return stat(p.string().c_str(), &s) == 0; 18 | } 19 | 20 | bool is_directory(const path& p) { 21 | struct stat s; 22 | if (stat(p.string().c_str(), &s)) 23 | return false; 24 | 25 | return S_ISDIR(s.st_mode); 26 | } 27 | 28 | bool is_symlink(const path& p) { 29 | struct stat s; 30 | if (lstat(p.string().c_str(), &s)) 31 | return false; 32 | 33 | return S_ISLNK(s.st_mode); 34 | } 35 | 36 | path read_symlink(const path& p) { 37 | char* actualPath = realpath(p.string().c_str(), NULL); 38 | if (!actualPath) { 39 | return path(p.string()); 40 | } 41 | 42 | path out(actualPath); 43 | free(actualPath); 44 | return out; 45 | } 46 | 47 | std::vector directory_iterator(const path& p) { 48 | if (!exists(p) || !is_directory(p)) 49 | return {}; 50 | 51 | std::unique_ptr dir(opendir(p.string().c_str()), &closedir); 52 | if (!dir) { 53 | ALOGE("Failed to open %s directory", p.string().c_str()); 54 | } 55 | 56 | std::vector out; 57 | struct dirent* dent; 58 | while ((dent = readdir(dir.get()))) { 59 | if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) 60 | continue; 61 | 62 | std::stringstream ss(p.string()); 63 | ss << "/" << dent->d_name; 64 | out.emplace_back(ss.str()); 65 | } 66 | 67 | return out; 68 | } 69 | 70 | } // namespace filesystem 71 | -------------------------------------------------------------------------------- /aidl/memtrack/filesystem.h: -------------------------------------------------------------------------------- 1 | // TODO(b/147469372): filesystem library in Android's libcxx is not available 2 | // for vendors. It had an unstable ABI and libcxx isn't updated ever since. 3 | 4 | // This simply implements some of the required functions in not-so-safe fashion. 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace filesystem { 18 | class path { 19 | public: 20 | path(const std::string _path) : strPath(_path) {} 21 | 22 | path filename() const { 23 | auto pos = strPath.rfind('/'); 24 | if (pos == std::string::npos) 25 | return path(strPath); 26 | 27 | pos++; 28 | auto l = strPath.size(); 29 | return path(strPath.substr(pos, l - pos)); 30 | } 31 | 32 | std::string string() const { return strPath; } 33 | 34 | private: 35 | std::string strPath; 36 | }; 37 | 38 | class directory_entry { 39 | public: 40 | directory_entry(const std::string _path) : p(_path) {} 41 | 42 | class path path() { 43 | return p; 44 | } 45 | 46 | private: 47 | class path p; 48 | }; 49 | 50 | bool exists(const path& p); 51 | 52 | bool is_directory(const path& p); 53 | 54 | bool is_symlink(const path& p); 55 | 56 | path read_symlink(const path& p); 57 | 58 | // Vector is easier to create than an iterator and serves our purposes well 59 | std::vector directory_iterator(const path& p); 60 | } // namespace filesystem 61 | -------------------------------------------------------------------------------- /aidl/memtrack/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "Memtrack.h" 6 | 7 | #undef LOG_TAG 8 | #define LOG_TAG "memtrack-service" 9 | 10 | using aidl::android::hardware::memtrack::Memtrack; 11 | 12 | int main() { 13 | ABinderProcess_setThreadPoolMaxThreadCount(0); 14 | std::shared_ptr memtrack = ndk::SharedRefBase::make(); 15 | 16 | const std::string instance = std::string() + Memtrack::descriptor + "/default"; 17 | binder_status_t status = 18 | AServiceManager_addService(memtrack->asBinder().get(), instance.c_str()); 19 | CHECK(status == STATUS_OK); 20 | 21 | ABinderProcess_joinThreadPool(); 22 | return EXIT_FAILURE; // Unreachable 23 | } 24 | -------------------------------------------------------------------------------- /aidl/memtrack/memtrack_default.rc: -------------------------------------------------------------------------------- 1 | service vendor.memtrack-default /vendor/bin/hw/android.hardware.memtrack-service.mediatek-mali 2 | class hal 3 | user graphics 4 | group system 5 | -------------------------------------------------------------------------------- /aidl/memtrack/memtrack_default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | android.hardware.memtrack 4 | IMemtrack/default 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /aidl/power-mediatek/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // SPDX-FileCopyrightText: 2024 The LineageOS Project 3 | // SPDX-License-Identifier: Apache-2.0 4 | // 5 | 6 | soong_config_module_type { 7 | name: "mediatek_power_defaults", 8 | module_type: "cc_defaults", 9 | config_namespace: "mediatek_power", 10 | value_variables: [ 11 | "double_tap_to_wake_node", 12 | "powerhal_ext", 13 | ], 14 | properties: [ 15 | "cflags", 16 | "whole_static_libs", 17 | ], 18 | } 19 | 20 | mediatek_power_defaults { 21 | name: "mediatek_power_defaults", 22 | soong_config_variables: { 23 | double_tap_to_wake_node: { 24 | cflags: ["-DTAP_TO_WAKE_NODE=\"%s\""], 25 | }, 26 | powerhal_ext: { 27 | cflags: ["-DMODE_EXT"], 28 | whole_static_libs: ["%s"], 29 | }, 30 | }, 31 | } 32 | 33 | cc_library_shared { 34 | name: "android.hardware.power-service-mediatek", 35 | defaults: ["mediatek_power_defaults"], 36 | vendor: true, 37 | compile_multilib: "64", 38 | vintf_fragments: ["power-mtk.xml"], 39 | srcs: ["Power.cpp"], 40 | 41 | shared_libs: [ 42 | "libbase", 43 | "libbinder_ndk", 44 | "android.hardware.power-V2-ndk", 45 | ], 46 | } 47 | -------------------------------------------------------------------------------- /aidl/power-mediatek/Power.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2020 The Android Open Source Project 3 | * SPDX-FileCopyrightText: 2023 The LineageOS Project 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "types.h" 11 | 12 | #include 13 | 14 | namespace aidl { 15 | namespace android { 16 | namespace hardware { 17 | namespace power { 18 | namespace impl { 19 | namespace mediatek { 20 | 21 | const std::string kTouchBoostDurationProperty = "persist.vendor.powerhal.touchboost_duration"; 22 | const int32_t kDefaultTouchBoostDuration = 1; /* ms */ 23 | const int32_t kLaunchBoostDuration = 30000; /* ms */ 24 | const int32_t kMaxInteractiveDuration = 5000; /* ms */ 25 | const int32_t kMinInteractiveDuration = 400; /* ms */ 26 | const int32_t kMaxTouchBoostDuration = 1000; /* ms */ 27 | 28 | class Power : public BnPower { 29 | public: 30 | Power(); 31 | ~Power(); 32 | ndk::ScopedAStatus setMode(Mode type, bool enabled) override; 33 | ndk::ScopedAStatus isModeSupported(Mode type, bool* _aidl_return) override; 34 | ndk::ScopedAStatus setBoost(Boost type, int32_t durationMs) override; 35 | ndk::ScopedAStatus isBoostSupported(Boost type, bool* _aidl_return) override; 36 | ndk::ScopedAStatus createHintSession(int32_t tgid, int32_t uid, 37 | const std::vector& threadIds, 38 | int64_t durationNanos, 39 | std::shared_ptr* _aidl_return) override; 40 | ndk::ScopedAStatus getHintSessionPreferredRate(int64_t* outNanoseconds) override; 41 | 42 | private: 43 | static long long calcTimespanUs(struct timespec start, struct timespec end); 44 | void handleInteractionHint(int32_t targetDuration); 45 | 46 | libpowerhal_t* mPerf; 47 | 48 | struct timespec mPreviousInteractionTime; 49 | int32_t mTouchBoostDuration; 50 | int32_t mPreviousInteractionDuration; 51 | int32_t mPreviousInteractionHandle; 52 | int32_t mLaunchHandle; 53 | }; 54 | 55 | } // namespace mediatek 56 | } // namespace impl 57 | } // namespace power 58 | } // namespace hardware 59 | } // namespace android 60 | } // namespace aidl 61 | -------------------------------------------------------------------------------- /aidl/power-mediatek/power-mtk.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | android.hardware.power 4 | 2 5 | IPower/default 6 | 7 | 8 | -------------------------------------------------------------------------------- /aidl/power-mediatek/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2023 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | #define POWERHAL_LIB_NAME "libpowerhal.so" 10 | 11 | #define MTKPOWER_HINT_LAUNCH 11 12 | #define MTKPOWER_HINT_APP_TOUCH 25 13 | #define MTKPOWER_HINT_UX_SCROLLING 43 14 | 15 | #define USINSEC 1000000L 16 | #define NSINUS 1000L 17 | 18 | typedef struct libpowerhal_t { 19 | void* perfLib; 20 | void (*Init)(int32_t); 21 | void (*LockRel)(int32_t); 22 | void (*UserScnDisableAll)(void); 23 | void (*UserScnRestoreAll)(void); 24 | int32_t (*CusLockHint)(int32_t, int32_t, __pid_t); 25 | } libpowerhal_t; 26 | -------------------------------------------------------------------------------- /aidl/thermal/Android.bp: -------------------------------------------------------------------------------- 1 | cc_binary { 2 | name: "android.hardware.thermal-service.mediatek", 3 | srcs: [ 4 | "service.cpp", 5 | "Thermal.cpp", 6 | "thermal-helper.cpp", 7 | "utils/thermal_throttling.cpp", 8 | "utils/thermal_info.cpp", 9 | "utils/thermal_files.cpp", 10 | "utils/power_files.cpp", 11 | "utils/powerhal_helper.cpp", 12 | "utils/thermal_stats_helper.cpp", 13 | "utils/thermal_predictions_helper.cpp", 14 | "utils/thermal_watcher.cpp", 15 | "virtualtemp_estimator/virtualtemp_estimator.cpp", 16 | ], 17 | vendor: true, 18 | relative_install_path: "hw", 19 | vintf_fragments: [ 20 | "android.hardware.thermal-service.mediatek.xml", 21 | ], 22 | init_rc: [ 23 | "android.hardware.thermal-service.mediatek.rc", 24 | ], 25 | required: [ 26 | "thermal_symlinks_mediatek", 27 | ], 28 | shared_libs: [ 29 | "libbase", 30 | "libcutils", 31 | "libjsoncpp", 32 | "libutils", 33 | "libnl", 34 | "libbinder_ndk", 35 | "android.frameworks.stats-V2-ndk", 36 | "android.hardware.power-V1-ndk", 37 | "android.hardware.thermal-V3-ndk", 38 | "pixel-power-ext-V1-ndk", 39 | "pixelatoms-cpp", 40 | ], 41 | static_libs: [ 42 | "libpixelstats", 43 | ], 44 | export_shared_lib_headers: [ 45 | "android.frameworks.stats-V2-ndk", 46 | "pixelatoms-cpp", 47 | ], 48 | cflags: [ 49 | "-Wall", 50 | "-Werror", 51 | "-Wextra", 52 | "-Wunused", 53 | ], 54 | tidy: true, 55 | tidy_checks: [ 56 | "android-*", 57 | "cert-*", 58 | "clang-analyzer-security*", 59 | ], 60 | tidy_checks_as_errors: [ 61 | "android-*", 62 | "clang-analyzer-security*", 63 | "cert-*", 64 | ], 65 | } 66 | 67 | sh_binary { 68 | name: "thermal_symlinks_mediatek", 69 | src: "init.thermal.symlinks.sh", 70 | vendor: true, 71 | init_rc: [ 72 | "mediatek-thermal-symlinks.rc", 73 | ], 74 | } 75 | -------------------------------------------------------------------------------- /aidl/thermal/OWNERS: -------------------------------------------------------------------------------- 1 | wvw@google.com 2 | paillon@google.com 3 | jenhaochen@google.com 4 | liumartin@google.com 5 | sayanna@google.com 6 | kamewang@google.com 7 | -------------------------------------------------------------------------------- /aidl/thermal/Thermal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include "thermal-helper.h" 15 | 16 | namespace aidl { 17 | namespace android { 18 | namespace hardware { 19 | namespace thermal { 20 | namespace implementation { 21 | 22 | struct CallbackSetting { 23 | CallbackSetting(std::shared_ptr callback, bool is_filter_type, 24 | TemperatureType type) 25 | : callback(std::move(callback)), is_filter_type(is_filter_type), type(type) {} 26 | std::shared_ptr callback; 27 | bool is_filter_type; 28 | TemperatureType type; 29 | }; 30 | 31 | struct CoolingDeviceCallbackSetting { 32 | CoolingDeviceCallbackSetting(std::shared_ptr callback, 33 | bool is_filter_type, CoolingType type) 34 | : callback(std::move(callback)), is_filter_type(is_filter_type), type(type) {} 35 | std::shared_ptr callback; 36 | bool is_filter_type; 37 | CoolingType type; 38 | }; 39 | 40 | class Thermal : public BnThermal { 41 | public: 42 | Thermal(); 43 | explicit Thermal(const std::shared_ptr &helper); 44 | ~Thermal() = default; 45 | ndk::ScopedAStatus getTemperatures(std::vector *_aidl_return) override; 46 | ndk::ScopedAStatus getTemperaturesWithType(TemperatureType type, 47 | std::vector *_aidl_return) override; 48 | 49 | ndk::ScopedAStatus getTemperatureThresholds( 50 | std::vector *_aidl_return) override; 51 | ndk::ScopedAStatus getTemperatureThresholdsWithType( 52 | TemperatureType type, std::vector *_aidl_return) override; 53 | 54 | ndk::ScopedAStatus registerThermalChangedCallback( 55 | const std::shared_ptr &callback) override; 56 | ndk::ScopedAStatus registerThermalChangedCallbackWithType( 57 | const std::shared_ptr &callback, 58 | TemperatureType type) override; 59 | ndk::ScopedAStatus unregisterThermalChangedCallback( 60 | const std::shared_ptr &callback) override; 61 | 62 | ndk::ScopedAStatus getCoolingDevices(std::vector *_aidl_return) override; 63 | ndk::ScopedAStatus getCoolingDevicesWithType(CoolingType type, 64 | std::vector *_aidl_return) override; 65 | 66 | ndk::ScopedAStatus registerCoolingDeviceChangedCallbackWithType( 67 | const std::shared_ptr &callback, 68 | CoolingType type) override; 69 | ndk::ScopedAStatus unregisterCoolingDeviceChangedCallback( 70 | const std::shared_ptr &callback) override; 71 | ndk::ScopedAStatus forecastSkinTemperature(int32_t forecastSeconds, 72 | float *_aidl_return) override; 73 | 74 | binder_status_t dump(int fd, const char **args, uint32_t numArgs) override; 75 | 76 | // Helper function for calling callbacks 77 | void sendThermalChangedCallback(const Temperature &t); 78 | 79 | private: 80 | class Looper { 81 | public: 82 | struct Event { 83 | std::function handler; 84 | }; 85 | 86 | Looper() { 87 | thread_ = std::thread([&] { loop(); }); 88 | } 89 | ~Looper(); 90 | 91 | void addEvent(const Event &e); 92 | 93 | private: 94 | std::condition_variable cv_; 95 | std::queue events_; 96 | std::mutex mutex_; 97 | std::thread thread_; 98 | bool aborted_; 99 | 100 | void loop(); 101 | }; 102 | 103 | std::shared_ptr thermal_helper_; 104 | std::mutex thermal_callback_mutex_; 105 | std::vector callbacks_; 106 | std::mutex cdev_callback_mutex_; 107 | std::vector cdev_callbacks_; 108 | 109 | Looper looper_; 110 | 111 | ndk::ScopedAStatus getFilteredTemperatures(bool filterType, TemperatureType type, 112 | std::vector *_aidl_return); 113 | ndk::ScopedAStatus getFilteredCoolingDevices(bool filterType, CoolingType type, 114 | std::vector *_aidl_return); 115 | ndk::ScopedAStatus getFilteredTemperatureThresholds( 116 | bool filterType, TemperatureType type, std::vector *_aidl_return); 117 | ndk::ScopedAStatus registerThermalChangedCallback( 118 | const std::shared_ptr &callback, bool filterType, 119 | TemperatureType type); 120 | 121 | void dumpVirtualSensorInfo(std::ostringstream *dump_buf); 122 | void dumpVtEstimatorInfo(std::ostringstream *dump_buf); 123 | void dumpThrottlingInfo(std::ostringstream *dump_buf); 124 | void dumpThrottlingRequestStatus(std::ostringstream *dump_buf); 125 | void dumpPowerRailInfo(std::ostringstream *dump_buf); 126 | void dumpStatsRecord(std::ostringstream *dump_buf, const StatsRecord &stats_record, 127 | std::string_view line_prefix); 128 | void dumpThermalStats(std::ostringstream *dump_buf); 129 | void dumpThermalData(int fd, const char **args, uint32_t numArgs); 130 | }; 131 | 132 | } // namespace implementation 133 | } // namespace thermal 134 | } // namespace hardware 135 | } // namespace android 136 | } // namespace aidl 137 | -------------------------------------------------------------------------------- /aidl/thermal/android.hardware.thermal-service.mediatek.rc: -------------------------------------------------------------------------------- 1 | on property:vendor.thermal.link_ready=1 2 | # queue the trigger to start thermal-hal and continue execute 3 | # per-device thermal setup "on property:vendor.thermal.link_ready=1" 4 | trigger enable-thermal-hal 5 | 6 | on enable-thermal-hal 7 | restart vendor.thermal-hal 8 | 9 | service vendor.thermal-hal /vendor/bin/hw/android.hardware.thermal-service.mediatek 10 | class hal 11 | user system 12 | group system 13 | priority -10 14 | disabled 15 | -------------------------------------------------------------------------------- /aidl/thermal/android.hardware.thermal-service.mediatek.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | android.hardware.thermal 4 | 3 5 | IThermal/default 6 | 7 | 8 | -------------------------------------------------------------------------------- /aidl/thermal/init.thermal.symlinks.sh: -------------------------------------------------------------------------------- 1 | #!/vendor/bin/sh 2 | 3 | for f in /sys/class/thermal/thermal_zone* 4 | do 5 | tz_name=`cat $f/type` 6 | ln -s $f /dev/thermal/tz-by-name/$tz_name 7 | done 8 | for f in /sys/class/thermal/cooling_device* 9 | do 10 | cdev_name=`cat $f/type` 11 | ln -s $f /dev/thermal/cdev-by-name/$cdev_name 12 | done 13 | setprop vendor.thermal.link_ready 1 14 | -------------------------------------------------------------------------------- /aidl/thermal/mediatek-thermal-symlinks.rc: -------------------------------------------------------------------------------- 1 | on boot 2 | mkdir /dev/thermal 0750 system system 3 | mkdir /dev/thermal/tz-by-name 0750 system system 4 | mkdir /dev/thermal/cdev-by-name 0750 system system 5 | start vendor.thermal.symlinks 6 | 7 | service vendor.thermal.symlinks /vendor/bin/thermal_symlinks_mediatek 8 | user system 9 | group system 10 | oneshot 11 | disabled 12 | -------------------------------------------------------------------------------- /aidl/thermal/service.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | #include 7 | #include 8 | #include 9 | 10 | #include "Thermal.h" 11 | 12 | constexpr std::string_view kThermalLogTag("pixel-thermal"); 13 | 14 | using ::android::OK; 15 | using ::android::status_t; 16 | 17 | // Generated AIDL files: 18 | using Thermal = ::aidl::android::hardware::thermal::implementation::Thermal; 19 | 20 | #if !defined(THERMAL_INSTANCE_NAME) 21 | #define THERMAL_INSTANCE_NAME "default" 22 | #endif 23 | 24 | int main(int /* argc */, char ** /* argv */) { 25 | // ignore broken pipe signal to avoid Thermal HAL being killed when dumpsys timeout 26 | signal(SIGPIPE, SIG_IGN); 27 | android::base::SetDefaultTag(kThermalLogTag.data()); 28 | 29 | auto svc = ndk::SharedRefBase::make(); 30 | const auto svcName = std::string() + svc->descriptor + "/" + THERMAL_INSTANCE_NAME; 31 | LOG(INFO) << "Pixel Thermal AIDL Service starting..." + svcName; 32 | ABinderProcess_setThreadPoolMaxThreadCount(0); 33 | 34 | auto svcBinder = svc->asBinder(); 35 | binder_status_t status = AServiceManager_addService(svcBinder.get(), svcName.c_str()); 36 | if (status != STATUS_OK) { 37 | LOG(ERROR) << "Pixel Thermal AIDL Service failed to start: " << status << "."; 38 | return EXIT_FAILURE; 39 | } 40 | LOG(INFO) << "Pixel Thermal HAL AIDL Service started."; 41 | ABinderProcess_joinThreadPool(); 42 | return EXIT_FAILURE; // should not reach 43 | } 44 | -------------------------------------------------------------------------------- /aidl/thermal/utils/config_schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "definitions":{ 3 | 4 | }, 5 | "$schema":"http://json-schema.org/draft-07/schema#", 6 | "$id":"http://example.com/root.json", 7 | "type":"object", 8 | "title":"The Root Schema", 9 | "required":[ 10 | "Sensors" 11 | ], 12 | "properties":{ 13 | "Sensors":{ 14 | "$id":"#/properties/Sensors", 15 | "type":"array", 16 | "title":"The Sensors Schema", 17 | "items":{ 18 | "$id":"#/properties/Sensors/items", 19 | "type":"object", 20 | "title":"The Items Schema", 21 | "required":[ 22 | "Name", 23 | "Type", 24 | "HotThreshold", 25 | "VrThreshold", 26 | "Multiplier" 27 | ], 28 | "properties":{ 29 | "Name":{ 30 | "$id":"#/properties/Sensors/items/properties/Name", 31 | "type":"string", 32 | "title":"The Name Schema", 33 | "default":"", 34 | "examples":[ 35 | "cpu0-silver-usr" 36 | ], 37 | "pattern":"^(.+)$" 38 | }, 39 | "Type":{ 40 | "$id":"#/properties/Sensors/items/properties/Type", 41 | "type":"string", 42 | "title":"The Type Schema", 43 | "default":"", 44 | "examples":[ 45 | "CPU" 46 | ], 47 | "pattern":"^(.+)$" 48 | }, 49 | "HotThreshold":{ 50 | "$id":"#/properties/Sensors/items/properties/HotThreshold", 51 | "type":"array", 52 | "title":"The hot threshold Schema, values are thresholds from ThrottlingSeverity::NONE to ThrottlingSeverity::SHUTDOWN", 53 | "default":"NAN", 54 | "maxItems":7, 55 | "minItems":7, 56 | "items":{ 57 | "$id":"#/properties/Sensors/items/properties/HotThreshold/items", 58 | "type":[ 59 | "string", 60 | "number" 61 | ], 62 | "title":"The Items Schema", 63 | "default":"", 64 | "examples":[ 65 | "NAN", 66 | "NAN", 67 | "NAN", 68 | 95, 69 | "NAN", 70 | "NAN", 71 | 125 72 | ], 73 | "pattern":"^([-+]?[0-9]*\\.?[0-9]+|NAN)$" 74 | } 75 | }, 76 | "HotHysteresis":{ 77 | "$id":"#/properties/Sensors/items/properties/HotHysteresis", 78 | "type":"array", 79 | "title":"The hot hysteresis Schema, values are thresholds from ThrottlingSeverity::NONE to ThrottlingSeverity::SHUTDOWN. Throttling status will be cleared HotThreshold - HotHysteresis.", 80 | "default":null, 81 | "maxItems":7, 82 | "minItems":7, 83 | "items":{ 84 | "$id":"#/properties/Sensors/items/properties/HotHysteresis/items", 85 | "type":[ 86 | "number" 87 | ], 88 | "title":"The Items Schema", 89 | "default":0.0, 90 | "examples":[ 91 | 0.0, 92 | 0.0, 93 | 0.0, 94 | 1.0, 95 | 1.5, 96 | 1.0, 97 | 2.0 98 | ] 99 | } 100 | }, 101 | "ColdThreshold":{ 102 | "$id":"#/properties/Sensors/items/properties/ColdThreshold", 103 | "type":"array", 104 | "title":"The cold threshold Schema, values are thresholds from ThrottlingSeverity::NONE to ThrottlingSeverity::SHUTDOWN, default to NAN", 105 | "default":null, 106 | "maxItems":7, 107 | "minItems":7, 108 | "items":{ 109 | "$id":"#/properties/Sensors/items/properties/ColdThreshold/items", 110 | "type":"string", 111 | "title":"The Items Schema", 112 | "default":"NAN", 113 | "examples":[ 114 | "NAN", 115 | "NAN", 116 | "NAN", 117 | "NAN", 118 | "NAN", 119 | "NAN", 120 | "NAN" 121 | ], 122 | "pattern":"^([-+]?[0-9]*\\.?[0-9]+|NAN)$" 123 | } 124 | }, 125 | "ColdHysteresis":{ 126 | "$id":"#/properties/Sensors/items/properties/ColdHysteresis", 127 | "type":"array", 128 | "title":"The cold hysteresis Schema, values are thresholds from ThrottlingSeverity::NONE to ThrottlingSeverity::SHUTDOWN. Throttling status will be cleared ColdThreshold + ColdHysteresis.", 129 | "default":null, 130 | "maxItems":7, 131 | "minItems":7, 132 | "items":{ 133 | "$id":"#/properties/Sensors/items/properties/ColdHysteresis/items", 134 | "type":[ 135 | "number" 136 | ], 137 | "title":"The Items Schema", 138 | "default":0.0, 139 | "examples":[ 140 | 0.0, 141 | 0.0, 142 | 0.0, 143 | 1.0, 144 | 1.5, 145 | 1.0, 146 | 2.0 147 | ] 148 | } 149 | }, 150 | "VrThreshold":{ 151 | "$id":"#/properties/Sensors/items/properties/VrThreshold", 152 | "type":"string", 153 | "title":"The Vrthreshold Schema", 154 | "default":"", 155 | "examples":[ 156 | "NAN" 157 | ], 158 | "pattern":"^(.*)$" 159 | }, 160 | "Multiplier":{ 161 | "$id":"#/properties/Sensors/items/properties/Multiplier", 162 | "type":"number", 163 | "title":"The Multiplier Schema", 164 | "default":0.001, 165 | "examples":[ 166 | 0.001 167 | ], 168 | "exclusiveMinimum":0.0 169 | }, 170 | "Monitor":{ 171 | "$id":"#/properties/Sensors/items/properties/Monitor", 172 | "type":"boolean", 173 | "title":"The Monitor Schema, if the sensor will be monitored and used to trigger throttling event", 174 | "default":false, 175 | "examples":[ 176 | true 177 | ] 178 | } 179 | } 180 | } 181 | }, 182 | "CoolingDevices":{ 183 | "$id":"#/properties/CoolingDevices", 184 | "type":"array", 185 | "title":"The Coolingdevices Schema", 186 | "items":{ 187 | "$id":"#/properties/CoolingDevices/items", 188 | "type":"object", 189 | "title":"The Items Schema", 190 | "required":[ 191 | "Name", 192 | "Type" 193 | ], 194 | "properties":{ 195 | "Name":{ 196 | "$id":"#/properties/CoolingDevices/items/properties/Name", 197 | "type":"string", 198 | "title":"The Name Schema", 199 | "default":"", 200 | "examples":[ 201 | "thermal-cpufreq-0" 202 | ], 203 | "pattern":"^(.+)$" 204 | }, 205 | "Type":{ 206 | "$id":"#/properties/CoolingDevices/items/properties/Type", 207 | "type":"string", 208 | "title":"The Type Schema", 209 | "default":"", 210 | "examples":[ 211 | "CPU" 212 | ], 213 | "pattern":"^(.+)$" 214 | } 215 | } 216 | } 217 | } 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /aidl/thermal/utils/power_files.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "thermal_info.h" 19 | 20 | namespace aidl { 21 | namespace android { 22 | namespace hardware { 23 | namespace thermal { 24 | namespace implementation { 25 | 26 | using ::android::base::boot_clock; 27 | 28 | struct PowerSample { 29 | uint64_t energy_counter; 30 | uint64_t duration; 31 | }; 32 | 33 | struct PowerStatus { 34 | boot_clock::time_point last_update_time; 35 | // A vector to record the queues of power sample history. 36 | std::vector> power_history; 37 | float last_updated_avg_power; 38 | }; 39 | 40 | struct PowerStatusLog { 41 | boot_clock::time_point prev_log_time; 42 | // energy sample at last logging 43 | std::unordered_map prev_energy_info_map; 44 | }; 45 | 46 | // A helper class for monitoring power rails. 47 | class PowerFiles { 48 | public: 49 | PowerFiles() = default; 50 | ~PowerFiles() = default; 51 | // Disallow copy and assign. 52 | PowerFiles(const PowerFiles &) = delete; 53 | void operator=(const PowerFiles &) = delete; 54 | bool registerPowerRailsToWatch(const Json::Value &config); 55 | // Update the power data from ODPM sysfs 56 | bool refreshPowerStatus(void); 57 | // Log the power data for the duration 58 | void logPowerStatus(const boot_clock::time_point &now); 59 | // Get previous power log time_point 60 | const boot_clock::time_point &GetPrevPowerLogTime() const { 61 | return power_status_log_.prev_log_time; 62 | } 63 | // Get power status map 64 | const std::unordered_map &GetPowerStatusMap() const { 65 | std::shared_lock _lock(power_status_map_mutex_); 66 | return power_status_map_; 67 | } 68 | // Get power rail info map 69 | const std::unordered_map &GetPowerRailInfoMap() const { 70 | return power_rail_info_map_; 71 | } 72 | 73 | private: 74 | // Update energy value to energy_info_map_, return false if the value is failed to update. 75 | bool updateEnergyValues(void); 76 | // Compute the average power for physical power rail. 77 | float updateAveragePower(std::string_view power_rail, std::queue *power_history); 78 | // Update the power data for the target power rail. 79 | float updatePowerRail(std::string_view power_rail); 80 | // Find the energy source path, return false if no energy source found. 81 | bool findEnergySourceToWatch(void); 82 | // The map to record the energy counter for each power rail. 83 | std::unordered_map energy_info_map_; 84 | // The map to record the power data for each thermal sensor. 85 | std::unordered_map power_status_map_; 86 | mutable std::shared_mutex power_status_map_mutex_; 87 | // The map to record the power rail information from thermal config 88 | std::unordered_map power_rail_info_map_; 89 | // The set to store the energy source paths 90 | std::unordered_set energy_path_set_; 91 | PowerStatusLog power_status_log_; 92 | }; 93 | 94 | } // namespace implementation 95 | } // namespace thermal 96 | } // namespace hardware 97 | } // namespace android 98 | } // namespace aidl 99 | -------------------------------------------------------------------------------- /aidl/thermal/utils/powerhal_helper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "thermal_info.h" 22 | 23 | namespace aidl { 24 | namespace android { 25 | namespace hardware { 26 | namespace thermal { 27 | namespace implementation { 28 | 29 | using ::aidl::android::hardware::power::IPower; 30 | using ::aidl::google::hardware::power::extension::pixel::IPowerExt; 31 | 32 | using CdevRequestStatus = std::unordered_map; 33 | 34 | struct PowerHintstatus { 35 | std::unordered_map hint_severity_map; 36 | ThrottlingSeverity prev_hint_severity; 37 | }; 38 | 39 | class PowerHalService { 40 | public: 41 | PowerHalService(); 42 | ~PowerHalService() = default; 43 | bool connect(); 44 | void reconnect(); 45 | bool isAidlPowerHalExist() { return power_hal_aidl_exist_; } 46 | bool isModeSupported(const std::string &type, const ThrottlingSeverity &t); 47 | bool isPowerHalConnected() { return power_hal_aidl_ != nullptr; } 48 | bool isPowerHalExtConnected() { return power_hal_ext_aidl_ != nullptr; } 49 | void setMode(const std::string &type, const ThrottlingSeverity &t, const bool &enable, 50 | const bool error_on_exit = false); 51 | void updateSupportedPowerHints( 52 | const std::unordered_map &sensor_info_map_); 53 | void sendPowerExtHint(const Temperature &t); 54 | 55 | private: 56 | ndk::ScopedAIBinder_DeathRecipient power_hal_ext_aidl_death_recipient_; 57 | static void onPowerHalExtAidlBinderDied(void *cookie) { 58 | if (cookie) { 59 | auto *e = static_cast(cookie); 60 | { 61 | std::lock_guard lock(e->lock_); 62 | e->power_hal_aidl_ = nullptr; 63 | e->power_hal_ext_aidl_ = nullptr; 64 | } 65 | e->reconnect(); 66 | } 67 | } 68 | 69 | bool power_hal_aidl_exist_; 70 | std::shared_ptr power_hal_aidl_; 71 | std::shared_ptr power_hal_ext_aidl_; 72 | std::mutex lock_; 73 | std::unordered_map supported_powerhint_map_; 74 | mutable std::shared_mutex powerhint_status_mutex_; 75 | }; 76 | 77 | } // namespace implementation 78 | } // namespace thermal 79 | } // namespace hardware 80 | } // namespace android 81 | } // namespace aidl 82 | -------------------------------------------------------------------------------- /aidl/thermal/utils/thermal_files.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #define ATRACE_TAG (ATRACE_TAG_THERMAL | ATRACE_TAG_HAL) 8 | 9 | #include "thermal_files.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | 20 | namespace aidl { 21 | namespace android { 22 | namespace hardware { 23 | namespace thermal { 24 | namespace implementation { 25 | 26 | using ::android::base::StringPrintf; 27 | 28 | std::string ThermalFiles::getThermalFilePath(std::string_view thermal_name) const { 29 | auto sensor_itr = thermal_name_to_path_map_.find(thermal_name.data()); 30 | if (sensor_itr == thermal_name_to_path_map_.end()) { 31 | return ""; 32 | } 33 | return sensor_itr->second; 34 | } 35 | 36 | bool ThermalFiles::addThermalFile(std::string_view thermal_name, std::string_view path) { 37 | return thermal_name_to_path_map_.emplace(thermal_name, path).second; 38 | } 39 | 40 | bool ThermalFiles::readThermalFile(std::string_view thermal_name, std::string *data) const { 41 | std::string sensor_reading; 42 | std::string file_path = getThermalFilePath(std::string_view(thermal_name)); 43 | *data = ""; 44 | 45 | ATRACE_NAME(StringPrintf("ThermalFiles::readThermalFile - %s", thermal_name.data()).c_str()); 46 | if (file_path.empty()) { 47 | PLOG(WARNING) << "Failed to find " << thermal_name << "'s path"; 48 | return false; 49 | } 50 | 51 | if (!::android::base::ReadFileToString(file_path, &sensor_reading)) { 52 | PLOG(WARNING) << "Failed to read sensor: " << thermal_name; 53 | return false; 54 | } 55 | 56 | if (sensor_reading.size() <= 1) { 57 | LOG(ERROR) << thermal_name << "'s return size:" << sensor_reading.size() << " is invalid"; 58 | return false; 59 | } 60 | 61 | // Strip the newline. 62 | *data = ::android::base::Trim(sensor_reading); 63 | return true; 64 | } 65 | 66 | bool ThermalFiles::writeCdevFile(std::string_view cdev_name, std::string_view data) { 67 | std::string file_path = 68 | getThermalFilePath(::android::base::StringPrintf("%s_%s", cdev_name.data(), "w")); 69 | 70 | ATRACE_NAME(StringPrintf("ThermalFiles::writeCdevFile - %s", cdev_name.data()).c_str()); 71 | if (!::android::base::WriteStringToFile(data.data(), file_path)) { 72 | PLOG(WARNING) << "Failed to write cdev: " << cdev_name << " to " << data.data(); 73 | return false; 74 | } 75 | 76 | return true; 77 | } 78 | 79 | } // namespace implementation 80 | } // namespace thermal 81 | } // namespace hardware 82 | } // namespace android 83 | } // namespace aidl 84 | -------------------------------------------------------------------------------- /aidl/thermal/utils/thermal_files.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace aidl { 13 | namespace android { 14 | namespace hardware { 15 | namespace thermal { 16 | namespace implementation { 17 | 18 | class ThermalFiles { 19 | public: 20 | ThermalFiles() = default; 21 | ~ThermalFiles() = default; 22 | ThermalFiles(const ThermalFiles &) = delete; 23 | void operator=(const ThermalFiles &) = delete; 24 | 25 | std::string getThermalFilePath(std::string_view thermal_name) const; 26 | // Returns true if add was successful, false otherwise. 27 | bool addThermalFile(std::string_view thermal_name, std::string_view path); 28 | // If thermal_name is not found in the thermal names to path map, this will set 29 | // data to empty and return false. If the thermal_name is found and its content 30 | // is read, this function will fill in data accordingly then return true. 31 | bool readThermalFile(std::string_view thermal_name, std::string *data) const; 32 | bool writeCdevFile(std::string_view thermal_name, std::string_view data); 33 | size_t getNumThermalFiles() const { return thermal_name_to_path_map_.size(); } 34 | 35 | private: 36 | std::unordered_map thermal_name_to_path_map_; 37 | }; 38 | 39 | } // namespace implementation 40 | } // namespace thermal 41 | } // namespace hardware 42 | } // namespace android 43 | } // namespace aidl 44 | -------------------------------------------------------------------------------- /aidl/thermal/utils/thermal_predictions_helper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "thermal_info.h" 19 | 20 | namespace aidl { 21 | namespace android { 22 | namespace hardware { 23 | namespace thermal { 24 | namespace implementation { 25 | 26 | using ::android::base::boot_clock; 27 | constexpr int kToleranceIntervalMs = 1000; 28 | 29 | struct PredictionSample { 30 | PredictionSample(int num_out_samples) { 31 | timestamp = boot_clock::time_point::min(); 32 | values = std::vector(num_out_samples, NAN); 33 | } 34 | boot_clock::time_point timestamp; 35 | std::vector values; 36 | }; 37 | 38 | struct PredictorSensorInfo { 39 | std::string sensor_name; 40 | int sample_duration; 41 | int num_out_samples; 42 | std::vector samples; 43 | int cur_index; 44 | }; 45 | 46 | struct PredictedSensorInfo { 47 | std::string sensor_name; 48 | std::string linked_sensor; 49 | int duration; 50 | int prediction_index; 51 | }; 52 | 53 | class ThermalPredictionsHelper { 54 | public: 55 | ThermalPredictionsHelper() = default; 56 | ~ThermalPredictionsHelper() = default; 57 | // Disallow copy and assign 58 | ThermalPredictionsHelper(const ThermalPredictionsHelper &) = delete; 59 | void operator=(const ThermalPredictionsHelper &) = delete; 60 | 61 | bool initializePredictionSensors( 62 | const std::unordered_map &sensor_info_map); 63 | bool updateSensor(std::string_view sensor_name, std::vector &values); 64 | SensorReadStatus readSensor(std::string_view sensor_name, float *temp); 65 | 66 | private: 67 | std::unordered_map predictor_sensors_; 68 | std::unordered_map predicted_sensors_; 69 | mutable std::shared_mutex sensor_predictions_mutex_; 70 | 71 | bool registerPredictedSensor(std::string_view sensor_name, std::string_view linked_sensor, 72 | int duration); 73 | bool registerPredictorSensor(std::string_view sensor_name, int sample_duration, 74 | int num_out_samples); 75 | }; 76 | 77 | } // namespace implementation 78 | } // namespace thermal 79 | } // namespace hardware 80 | } // namespace android 81 | } // namespace aidl 82 | -------------------------------------------------------------------------------- /aidl/thermal/utils/thermal_throttling.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include "power_files.h" 20 | #include "thermal_info.h" 21 | #include "thermal_stats_helper.h" 22 | 23 | namespace aidl { 24 | namespace android { 25 | namespace hardware { 26 | namespace thermal { 27 | namespace implementation { 28 | 29 | struct ThermalThrottlingStatus { 30 | std::unordered_map pid_power_budget_map; 31 | std::unordered_map pid_cdev_request_map; 32 | std::unordered_map hardlimit_cdev_request_map; 33 | std::unordered_map throttling_release_map; 34 | std::unordered_map cdev_status_map; 35 | float prev_err; 36 | float i_budget; 37 | float prev_target; 38 | float prev_power_budget; 39 | float budget_transient; 40 | int tran_cycle; 41 | std::string profile; 42 | }; 43 | 44 | // Return the control temp target of PID algorithm 45 | size_t getTargetStateOfPID(const SensorInfo &sensor_info, const ThrottlingSeverity curr_severity); 46 | 47 | // A helper class for conducting thermal throttling 48 | class ThermalThrottling { 49 | public: 50 | ThermalThrottling() = default; 51 | ~ThermalThrottling() = default; 52 | // Disallow copy and assign. 53 | ThermalThrottling(const ThermalThrottling &) = delete; 54 | void operator=(const ThermalThrottling &) = delete; 55 | 56 | // Clear throttling data 57 | void clearThrottlingData(std::string_view sensor_name); 58 | // Register map for throttling algo 59 | bool registerThermalThrottling( 60 | std::string_view sensor_name, const std::shared_ptr &throttling_info, 61 | const std::unordered_map &cooling_device_info_map); 62 | // Get throttling status map 63 | const std::unordered_map &GetThermalThrottlingStatusMap() 64 | const { 65 | std::shared_lock _lock(thermal_throttling_status_map_mutex_); 66 | return thermal_throttling_status_map_; 67 | } 68 | // Update thermal throttling request for the specific sensor 69 | void thermalThrottlingUpdate( 70 | const Temperature &temp, const SensorInfo &sensor_info, 71 | const ThrottlingSeverity curr_severity, const std::chrono::milliseconds time_elapsed_ms, 72 | const std::unordered_map &power_status_map, 73 | const std::unordered_map &cooling_device_info_map, 74 | const bool max_throttling = false, 75 | const std::vector &sensor_predictions = std::vector{}); 76 | 77 | // Compute the throttling target from all the sensors' request 78 | void computeCoolingDevicesRequest(std::string_view sensor_name, const SensorInfo &sensor_info, 79 | const ThrottlingSeverity curr_severity, 80 | std::vector *cooling_devices_to_update, 81 | ThermalStatsHelper *thermal_stats_helper); 82 | // Get the aggregated (from all sensor) max request for a cooling device 83 | bool getCdevMaxRequest(std::string_view cdev_name, int *max_state); 84 | 85 | private: 86 | // Check if the thermal throttling profile need to be switched 87 | void parseProfileProperty(std::string_view sensor_name, const SensorInfo &sensor_info); 88 | // PID algo - get the total power budget 89 | float updatePowerBudget( 90 | const Temperature &temp, const SensorInfo &sensor_info, 91 | const std::unordered_map &cooling_device_info_map, 92 | std::chrono::milliseconds time_elapsed_ms, ThrottlingSeverity curr_severity, 93 | const bool max_throttling, 94 | const std::vector &sensor_predictions = std::vector{}); 95 | 96 | // PID algo - return the power number from excluded power rail list 97 | float computeExcludedPower(const SensorInfo &sensor_info, 98 | const ThrottlingSeverity curr_severity, 99 | const std::unordered_map &power_status_map, 100 | std::string *log_buf, std::string_view sensor_name); 101 | 102 | // PID algo - allocate the power to target CDEV according to the ODPM 103 | bool allocatePowerToCdev( 104 | const Temperature &temp, const SensorInfo &sensor_info, 105 | const ThrottlingSeverity curr_severity, const std::chrono::milliseconds time_elapsed_ms, 106 | const std::unordered_map &power_status_map, 107 | const std::unordered_map &cooling_device_info_map, 108 | const bool max_throttling, const std::vector &sensor_predictions); 109 | // PID algo - map the target throttling state according to the power budget 110 | void updateCdevRequestByPower( 111 | std::string sensor_name, 112 | const std::unordered_map &cooling_device_info_map); 113 | // Hard limit algo - assign the throttling state according to the severity 114 | void updateCdevRequestBySeverity(std::string_view sensor_name, const SensorInfo &sensor_info, 115 | ThrottlingSeverity curr_severity); 116 | // Throttling release algo - decide release step according to the predefined power threshold, 117 | // return false if the throttling release is not registered in thermal config 118 | bool throttlingReleaseUpdate( 119 | std::string_view sensor_name, 120 | const std::unordered_map &cooling_device_info_map, 121 | const std::unordered_map &power_status_map, 122 | const ThrottlingSeverity severity, const SensorInfo &sensor_info); 123 | // Update the cooling device request set for new request and notify the caller if there is 124 | // change in max_request for the cooling device. 125 | bool updateCdevMaxRequestAndNotifyIfChange(std::string_view cdev_name, int cur_request, 126 | int new_request); 127 | mutable std::shared_mutex thermal_throttling_status_map_mutex_; 128 | // Thermal throttling status from each sensor 129 | std::unordered_map thermal_throttling_status_map_; 130 | std::shared_mutex cdev_all_request_map_mutex_; 131 | // Set of all request for a cooling device from each sensor 132 | std::unordered_map>> cdev_all_request_map_; 133 | }; 134 | 135 | } // namespace implementation 136 | } // namespace thermal 137 | } // namespace hardware 138 | } // namespace android 139 | } // namespace aidl 140 | -------------------------------------------------------------------------------- /aidl/thermal/utils/thermal_watcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace aidl { 29 | namespace android { 30 | namespace hardware { 31 | namespace thermal { 32 | namespace implementation { 33 | 34 | using ::android::base::boot_clock; 35 | using ::android::base::unique_fd; 36 | using WatcherCallback = std::function &uevent_sensor_map)>; 38 | 39 | // A helper class for monitoring thermal files changes. 40 | class ThermalWatcher : public ::android::Thread { 41 | public: 42 | explicit ThermalWatcher(const WatcherCallback &cb) 43 | : Thread(false), cb_(cb), looper_(new ::android::Looper(true)) {} 44 | ~ThermalWatcher() = default; 45 | 46 | // Disallow copy and assign. 47 | ThermalWatcher(const ThermalWatcher &) = delete; 48 | void operator=(const ThermalWatcher &) = delete; 49 | 50 | // Start the thread and return true if it succeeds. 51 | bool startWatchingDeviceFiles(); 52 | // Give the file watcher a list of files to start watching. This helper 53 | // class will by default wait for modifications to the file with a looper. 54 | // This should be called before starting watcher thread. 55 | // For monitoring uevents. 56 | void registerFilesToWatch(const std::set &sensors_to_watch); 57 | // For monitoring thermal genl events. 58 | void registerFilesToWatchNl(const std::set &sensors_to_watch); 59 | // Wake up the looper thus the worker thread, immediately. This can be called 60 | // in any thread. 61 | void wake(); 62 | 63 | private: 64 | // The work done by the watcher thread. This will use inotify to check for 65 | // modifications to the files to watch. If any modification is seen this 66 | // will callback the registered function with the new data read from the 67 | // modified file. 68 | bool threadLoop() override; 69 | 70 | // Parse uevent message 71 | void parseUevent(std::unordered_map *sensor_map); 72 | 73 | // Parse thermal netlink message 74 | void parseGenlink(std::unordered_map *sensor_map); 75 | 76 | // Maps watcher filer descriptor to watched file path. 77 | std::unordered_map watch_to_file_path_map_; 78 | 79 | // The callback function. Called whenever thermal uevent is seen. 80 | // The function passed in should expect a string in the form (type). 81 | // Where type is the name of the thermal zone that trigger a uevent notification. 82 | // Callback will return thermal trigger status for next polling decision. 83 | const WatcherCallback cb_; 84 | 85 | ::android::sp<::android::Looper> looper_; 86 | 87 | // For uevent socket registration. 88 | ::android::base::unique_fd uevent_fd_; 89 | // For thermal genl socket registration. 90 | ::android::base::unique_fd thermal_genl_fd_; 91 | // Sensor list which monitor flag is enabled. 92 | std::set monitored_sensors_; 93 | // Sleep interval voting result 94 | std::chrono::milliseconds sleep_ms_; 95 | // Timestamp for last thermal update 96 | boot_clock::time_point last_update_time_; 97 | // For thermal genl socket object. 98 | struct nl_sock *sk_thermal; 99 | }; 100 | 101 | } // namespace implementation 102 | } // namespace thermal 103 | } // namespace hardware 104 | } // namespace android 105 | } // namespace aidl 106 | -------------------------------------------------------------------------------- /aidl/thermal/virtualtemp_estimator/virtualtemp_estimator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | #pragma once 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include "virtualtemp_estimator_data.h" 14 | 15 | namespace thermal { 16 | namespace vtestimator { 17 | 18 | enum VtEstimatorStatus { 19 | kVtEstimatorOk = 0, 20 | kVtEstimatorInvalidArgs = 1, 21 | kVtEstimatorInitFailed = 2, 22 | kVtEstimatorInvokeFailed = 3, 23 | kVtEstimatorUnSupported = 4, 24 | kVtEstimatorLowConfidence = 5, 25 | kVtEstimatorUnderSampling = 6, 26 | }; 27 | 28 | enum VtEstimationType { kUseMLModel = 0, kUseLinearModel = 1, kInvalidEstimationType = 2 }; 29 | 30 | struct MLModelInitData { 31 | std::string model_path; 32 | bool use_prev_samples; 33 | size_t prev_samples_order; 34 | size_t output_label_count; 35 | size_t num_hot_spots; 36 | bool enable_input_validation; 37 | std::vector offset_thresholds; 38 | std::vector offset_values; 39 | bool support_under_sampling; 40 | }; 41 | 42 | struct LinearModelInitData { 43 | bool use_prev_samples; 44 | size_t prev_samples_order; 45 | std::vector coefficients; 46 | std::vector offset_thresholds; 47 | std::vector offset_values; 48 | }; 49 | 50 | union VtEstimationInitData { 51 | VtEstimationInitData(VtEstimationType type) { 52 | if (type == kUseMLModel) { 53 | ml_model_init_data.model_path = ""; 54 | ml_model_init_data.use_prev_samples = false; 55 | ml_model_init_data.prev_samples_order = 1; 56 | ml_model_init_data.output_label_count = 1; 57 | ml_model_init_data.num_hot_spots = 1; 58 | ml_model_init_data.enable_input_validation = false; 59 | ml_model_init_data.support_under_sampling = false; 60 | } else if (type == kUseLinearModel) { 61 | linear_model_init_data.use_prev_samples = false; 62 | linear_model_init_data.prev_samples_order = 1; 63 | } 64 | } 65 | ~VtEstimationInitData() {} 66 | 67 | MLModelInitData ml_model_init_data; 68 | LinearModelInitData linear_model_init_data; 69 | }; 70 | 71 | // Class to estimate virtual temperature 72 | class VirtualTempEstimator { 73 | public: 74 | // Implicit copy-move headers. 75 | VirtualTempEstimator(const VirtualTempEstimator &) = delete; 76 | VirtualTempEstimator(VirtualTempEstimator &&) = default; 77 | VirtualTempEstimator &operator=(const VirtualTempEstimator &) = delete; 78 | VirtualTempEstimator &operator=(VirtualTempEstimator &&) = default; 79 | 80 | VirtualTempEstimator(std::string_view sensor_name, VtEstimationType type, 81 | size_t num_linked_sensors); 82 | ~VirtualTempEstimator(); 83 | 84 | // Initializes the estimator based on init_data 85 | VtEstimatorStatus Initialize(const VtEstimationInitData &init_data); 86 | 87 | // Performs the prediction and returns estimated value in output 88 | VtEstimatorStatus Estimate(const std::vector &thermistors, std::vector *output); 89 | 90 | // Dump estimator status 91 | VtEstimatorStatus DumpStatus(std::string_view sensor_name, std::ostringstream *dump_buf); 92 | // Get predict window width in milliseconds 93 | VtEstimatorStatus GetMaxPredictWindowMs(size_t *predict_window_ms); 94 | // Predict temperature after desired milliseconds 95 | VtEstimatorStatus PredictAfterTimeMs(const size_t time_ms, float *output); 96 | // Get entire output buffer of the estimator 97 | VtEstimatorStatus GetAllPredictions(std::vector *output); 98 | 99 | // Adds traces to help debug 100 | VtEstimatorStatus DumpTraces(); 101 | 102 | private: 103 | void LoadTFLiteWrapper(); 104 | VtEstimationType type; 105 | std::unique_ptr common_instance_; 106 | std::unique_ptr tflite_instance_; 107 | std::unique_ptr linear_model_instance_; 108 | 109 | VtEstimatorStatus LinearModelInitialize(LinearModelInitData data); 110 | VtEstimatorStatus TFliteInitialize(MLModelInitData data); 111 | 112 | VtEstimatorStatus LinearModelEstimate(const std::vector &thermistors, 113 | std::vector *output); 114 | VtEstimatorStatus TFliteEstimate(const std::vector &thermistors, 115 | std::vector *output); 116 | VtEstimatorStatus TFliteGetMaxPredictWindowMs(size_t *predict_window_ms); 117 | VtEstimatorStatus TFlitePredictAfterTimeMs(const size_t time_ms, float *output); 118 | VtEstimatorStatus TFliteGetAllPredictions(std::vector *output); 119 | 120 | VtEstimatorStatus TFLiteDumpStatus(std::string_view sensor_name, std::ostringstream *dump_buf); 121 | bool GetInputConfig(Json::Value *config); 122 | bool ParseInputConfig(const Json::Value &config); 123 | }; 124 | 125 | } // namespace vtestimator 126 | } // namespace thermal 127 | -------------------------------------------------------------------------------- /aidl/thermal/virtualtemp_estimator/virtualtemp_estimator_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #pragma once 13 | 14 | namespace thermal { 15 | namespace vtestimator { 16 | 17 | using android::base::boot_clock; 18 | 19 | // Current version only supports single input/output tensors 20 | constexpr int kNumInputTensors = 1; 21 | constexpr int kNumOutputTensors = 1; 22 | 23 | typedef void *(*tflitewrapper_create)(int num_input_tensors, int num_output_tensors); 24 | typedef bool (*tflitewrapper_init)(void *handle, const char *model_path); 25 | typedef bool (*tflitewrapper_invoke)(void *handle, float *input_samples, int num_input_samples, 26 | float *output_samples, int num_output_samples); 27 | typedef void (*tflitewrapper_destroy)(void *handle); 28 | typedef bool (*tflitewrapper_get_input_config_size)(void *handle, int *config_size); 29 | typedef bool (*tflitewrapper_get_input_config)(void *handle, char *config_buffer, 30 | int config_buffer_size); 31 | 32 | struct TFLiteWrapperMethods { 33 | tflitewrapper_create create; 34 | tflitewrapper_init init; 35 | tflitewrapper_invoke invoke; 36 | tflitewrapper_destroy destroy; 37 | tflitewrapper_get_input_config_size get_input_config_size; 38 | tflitewrapper_get_input_config get_input_config; 39 | mutable std::mutex mutex; 40 | }; 41 | 42 | struct InputRangeInfo { 43 | float max_threshold = std::numeric_limits::max(); 44 | float min_threshold = std::numeric_limits::min(); 45 | }; 46 | 47 | struct VtEstimatorCommonData { 48 | VtEstimatorCommonData(std::string_view name, size_t num_input_sensors) { 49 | sensor_name = name; 50 | num_linked_sensors = num_input_sensors; 51 | prev_samples_order = 1; 52 | is_initialized = false; 53 | use_prev_samples = false; 54 | cur_sample_count = 0; 55 | } 56 | std::string sensor_name; 57 | 58 | std::vector offset_thresholds; 59 | std::vector offset_values; 60 | 61 | size_t num_linked_sensors; 62 | size_t prev_samples_order; 63 | size_t cur_sample_count; 64 | bool use_prev_samples; 65 | bool is_initialized; 66 | }; 67 | 68 | struct VtEstimatorTFLiteData { 69 | VtEstimatorTFLiteData() { 70 | scratch_buffer = nullptr; 71 | input_buffer = nullptr; 72 | input_buffer_size = 0; 73 | output_label_count = 1; 74 | num_hot_spots = 1; 75 | output_buffer = nullptr; 76 | output_buffer_size = 1; 77 | support_under_sampling = false; 78 | sample_interval = std::chrono::milliseconds{0}; 79 | max_sample_interval = std::chrono::milliseconds{std::numeric_limits::max()}; 80 | predict_window_ms = 0; 81 | last_update_time = boot_clock::time_point::min(); 82 | prev_sample_time = boot_clock::time_point::min(); 83 | enable_input_validation = false; 84 | 85 | tflite_wrapper = nullptr; 86 | tflite_methods.create = nullptr; 87 | tflite_methods.init = nullptr; 88 | tflite_methods.get_input_config_size = nullptr; 89 | tflite_methods.get_input_config = nullptr; 90 | tflite_methods.invoke = nullptr; 91 | tflite_methods.destroy = nullptr; 92 | } 93 | 94 | void *tflite_wrapper; 95 | float *scratch_buffer; 96 | float *input_buffer; 97 | size_t input_buffer_size; 98 | size_t num_hot_spots; 99 | size_t output_label_count; 100 | float *output_buffer; 101 | size_t output_buffer_size; 102 | std::string model_path; 103 | TFLiteWrapperMethods tflite_methods; 104 | std::vector input_range; 105 | bool support_under_sampling; 106 | std::chrono::milliseconds sample_interval{}; 107 | std::chrono::milliseconds max_sample_interval{}; 108 | size_t predict_window_ms; 109 | boot_clock::time_point last_update_time; 110 | boot_clock::time_point prev_sample_time; 111 | bool enable_input_validation; 112 | 113 | ~VtEstimatorTFLiteData() { 114 | if (tflite_wrapper && tflite_methods.destroy) { 115 | tflite_methods.destroy(tflite_wrapper); 116 | } 117 | 118 | if (scratch_buffer) { 119 | delete scratch_buffer; 120 | } 121 | 122 | if (input_buffer) { 123 | delete input_buffer; 124 | } 125 | 126 | if (output_buffer) { 127 | delete output_buffer; 128 | } 129 | } 130 | }; 131 | 132 | struct VtEstimatorLinearModelData { 133 | VtEstimatorLinearModelData() {} 134 | 135 | ~VtEstimatorLinearModelData() {} 136 | 137 | std::vector> input_samples; 138 | std::vector> coefficients; 139 | mutable std::mutex mutex; 140 | }; 141 | 142 | } // namespace vtestimator 143 | } // namespace thermal 144 | -------------------------------------------------------------------------------- /aidl/usb-legacy/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2021 The Android Open Source Project 3 | // 4 | // SPDX-License-Identifier: Apache-2.0 5 | // 6 | 7 | cc_binary { 8 | name: "android.hardware.usb-service.mediatek-legacy", 9 | relative_install_path: "hw", 10 | init_rc: ["android.hardware.usb-service.mediatek-legacy.rc"], 11 | vintf_fragments: ["android.hardware.usb-service.mediatek-legacy.xml"], 12 | vendor: true, 13 | srcs: [ 14 | "service.cpp", 15 | "Usb.cpp", 16 | ], 17 | shared_libs: [ 18 | "android.hardware.usb-V3-ndk", 19 | "libbase", 20 | "libbinder_ndk", 21 | "libcutils", 22 | "liblog", 23 | "libutils", 24 | ], 25 | } 26 | -------------------------------------------------------------------------------- /aidl/usb-legacy/Usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define UEVENT_MSG_LEN 2048 15 | #define UEVENT_MAX_EVENTS 64 16 | // The type-c stack waits for 4.5 - 5.5 secs before declaring a port non-pd. 17 | // The -partner directory would not be created until this is done. 18 | // Having a margin of ~3 secs for the directory and other related bookeeping 19 | // structures created and uvent fired. 20 | #define PORT_TYPE_TIMEOUT 8 21 | 22 | namespace aidl { 23 | namespace android { 24 | namespace hardware { 25 | namespace usb { 26 | 27 | using ::aidl::android::hardware::usb::IUsbCallback; 28 | using ::aidl::android::hardware::usb::PortRole; 29 | using ::android::sp; 30 | using ::android::base::ReadFileToString; 31 | using ::android::base::WriteStringToFile; 32 | using ::ndk::ScopedAStatus; 33 | using ::std::shared_ptr; 34 | using ::std::string; 35 | 36 | #define PULLUP_PATH "/config/usb_gadget/g1/UDC" 37 | 38 | struct Usb : public BnUsb { 39 | Usb(); 40 | 41 | ScopedAStatus enableContaminantPresenceDetection(const std::string& in_portName, bool in_enable, 42 | int64_t in_transactionId) override; 43 | ScopedAStatus queryPortStatus(int64_t in_transactionId) override; 44 | ScopedAStatus setCallback(const shared_ptr& in_callback) override; 45 | ScopedAStatus switchRole(const string& in_portName, const PortRole& in_role, 46 | int64_t in_transactionId) override; 47 | ScopedAStatus enableUsbData(const string& in_portName, bool in_enable, 48 | int64_t in_transactionId) override; 49 | ScopedAStatus enableUsbDataWhileDocked(const string& in_portName, 50 | int64_t in_transactionId) override; 51 | ScopedAStatus limitPowerTransfer(const std::string& in_portName, bool in_limit, 52 | int64_t in_transactionId) override; 53 | ScopedAStatus resetUsbPort(const std::string& in_portName, int64_t in_transactionId) override; 54 | 55 | shared_ptr mCallback; 56 | // Protects mCallback variable 57 | pthread_mutex_t mLock; 58 | // Protects roleSwitch operation 59 | pthread_mutex_t mRoleSwitchLock; 60 | // Threads waiting for the partner to come back wait here 61 | pthread_cond_t mPartnerCV; 62 | // lock protecting mPartnerCV 63 | pthread_mutex_t mPartnerLock; 64 | // Variable to signal partner coming back online after type switch 65 | bool mPartnerUp; 66 | // Usb Data status 67 | bool mUsbDataEnabled; 68 | 69 | private: 70 | pthread_t mPoll; 71 | }; 72 | 73 | } // namespace usb 74 | } // namespace hardware 75 | } // namespace android 76 | } // namespace aidl 77 | -------------------------------------------------------------------------------- /aidl/usb-legacy/android.hardware.usb-service.mediatek-legacy.rc: -------------------------------------------------------------------------------- 1 | on boot 2 | chown root system /sys/class/dual_role_usb/dual-role-type_c_port0/power_role 3 | chown root system /sys/class/dual_role_usb/dual-role-type_c_port0/data_role 4 | chown root system /sys/class/dual_role_usb/dual-role-type_c_port0/port_type 5 | chmod 664 /sys/class/dual_role_usb/dual-role-type_c_port0/power_role 6 | chmod 664 /sys/class/dual_role_usb/dual-role-type_c_port0/data_role 7 | chmod 664 /sys/class/dual_role_usb/dual-role-type_c_port0/port_type 8 | 9 | service vendor.usb_default /vendor/bin/hw/android.hardware.usb-service.mediatek-legacy 10 | class hal 11 | user system 12 | group system 13 | -------------------------------------------------------------------------------- /aidl/usb-legacy/android.hardware.usb-service.mediatek-legacy.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | android.hardware.usb 4 | 3 5 | 6 | IUsb 7 | default 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /aidl/usb-legacy/service.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "Usb.h" 12 | 13 | using ::aidl::android::hardware::usb::Usb; 14 | 15 | int main() { 16 | ABinderProcess_setThreadPoolMaxThreadCount(0); 17 | std::shared_ptr usb = ndk::SharedRefBase::make(); 18 | 19 | const std::string instance = std::string() + Usb::descriptor + "/default"; 20 | binder_status_t status = AServiceManager_addService(usb->asBinder().get(), instance.c_str()); 21 | CHECK(status == STATUS_OK); 22 | 23 | ABinderProcess_joinThreadPool(); 24 | return -1; // Should never be reached 25 | } 26 | -------------------------------------------------------------------------------- /aidl/usb/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2021 The Android Open Source Project 3 | // 4 | // SPDX-License-Identifier: Apache-2.0 5 | // 6 | 7 | soong_config_module_type { 8 | name: "android_hardware_usb_mediatek_config_default", 9 | module_type: "cc_defaults", 10 | config_namespace: "android_hardware_mediatek_usb", 11 | bool_variables: [ 12 | "audio_accessory_supported", 13 | ], 14 | properties: ["cflags"], 15 | } 16 | 17 | android_hardware_usb_mediatek_config_default { 18 | name: "android_hardware_usb_mediatek_config_defaults", 19 | soong_config_variables: { 20 | audio_accessory_supported: { 21 | cflags: ["-DUSB_AUDIO_ACCESSORY_SUPPORTED"], 22 | }, 23 | }, 24 | } 25 | 26 | cc_binary { 27 | name: "android.hardware.usb-service.mediatek", 28 | defaults: ["android_hardware_usb_mediatek_config_defaults"], 29 | relative_install_path: "hw", 30 | init_rc: ["android.hardware.usb-service.mediatek.rc"], 31 | vintf_fragments: ["android.hardware.usb-service.mediatek.xml"], 32 | vendor: true, 33 | srcs: [ 34 | "service.cpp", 35 | "Usb.cpp", 36 | ], 37 | shared_libs: [ 38 | "android.hardware.usb-V3-ndk", 39 | "libbase", 40 | "libbinder_ndk", 41 | "libcutils", 42 | "liblog", 43 | "libutils", 44 | ], 45 | } 46 | -------------------------------------------------------------------------------- /aidl/usb/Usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define UEVENT_MSG_LEN 2048 15 | #define UEVENT_MAX_EVENTS 64 16 | // The type-c stack waits for 4.5 - 5.5 secs before declaring a port non-pd. 17 | // The -partner directory would not be created until this is done. 18 | // Having a margin of ~3 secs for the directory and other related bookeeping 19 | // structures created and uvent fired. 20 | #define PORT_TYPE_TIMEOUT 8 21 | 22 | namespace aidl { 23 | namespace android { 24 | namespace hardware { 25 | namespace usb { 26 | 27 | using ::aidl::android::hardware::usb::IUsbCallback; 28 | using ::aidl::android::hardware::usb::PortRole; 29 | using ::android::sp; 30 | using ::android::base::ReadFileToString; 31 | using ::android::base::WriteStringToFile; 32 | using ::ndk::ScopedAStatus; 33 | using ::std::shared_ptr; 34 | using ::std::string; 35 | 36 | #define PULLUP_PATH "/config/usb_gadget/g1/UDC" 37 | 38 | struct Usb : public BnUsb { 39 | Usb(); 40 | 41 | ScopedAStatus enableContaminantPresenceDetection(const std::string& in_portName, bool in_enable, 42 | int64_t in_transactionId) override; 43 | ScopedAStatus queryPortStatus(int64_t in_transactionId) override; 44 | ScopedAStatus setCallback(const shared_ptr& in_callback) override; 45 | ScopedAStatus switchRole(const string& in_portName, const PortRole& in_role, 46 | int64_t in_transactionId) override; 47 | ScopedAStatus enableUsbData(const string& in_portName, bool in_enable, 48 | int64_t in_transactionId) override; 49 | ScopedAStatus enableUsbDataWhileDocked(const string& in_portName, 50 | int64_t in_transactionId) override; 51 | ScopedAStatus limitPowerTransfer(const std::string& in_portName, bool in_limit, 52 | int64_t in_transactionId) override; 53 | ScopedAStatus resetUsbPort(const std::string& in_portName, int64_t in_transactionId) override; 54 | 55 | shared_ptr mCallback; 56 | // Protects mCallback variable 57 | pthread_mutex_t mLock; 58 | // Protects roleSwitch operation 59 | pthread_mutex_t mRoleSwitchLock; 60 | // Threads waiting for the partner to come back wait here 61 | pthread_cond_t mPartnerCV; 62 | // lock protecting mPartnerCV 63 | pthread_mutex_t mPartnerLock; 64 | // Variable to signal partner coming back online after type switch 65 | bool mPartnerUp; 66 | // Usb Data status 67 | bool mUsbDataEnabled; 68 | 69 | private: 70 | pthread_t mPoll; 71 | }; 72 | 73 | } // namespace usb 74 | } // namespace hardware 75 | } // namespace android 76 | } // namespace aidl 77 | -------------------------------------------------------------------------------- /aidl/usb/android.hardware.usb-service.mediatek.rc: -------------------------------------------------------------------------------- 1 | service vendor.usb_default /vendor/bin/hw/android.hardware.usb-service.mediatek 2 | class hal 3 | user system 4 | group system 5 | -------------------------------------------------------------------------------- /aidl/usb/android.hardware.usb-service.mediatek.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | android.hardware.usb 4 | 3 5 | 6 | IUsb 7 | default 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /aidl/usb/service.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "Usb.h" 12 | 13 | using ::aidl::android::hardware::usb::Usb; 14 | 15 | int main() { 16 | ABinderProcess_setThreadPoolMaxThreadCount(0); 17 | std::shared_ptr usb = ndk::SharedRefBase::make(); 18 | 19 | const std::string instance = std::string() + Usb::descriptor + "/default"; 20 | binder_status_t status = AServiceManager_addService(usb->asBinder().get(), instance.c_str()); 21 | CHECK(status == STATUS_OK); 22 | 23 | ABinderProcess_joinThreadPool(); 24 | return -1; // Should never be reached 25 | } 26 | -------------------------------------------------------------------------------- /aidl/vibrator/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // SPDX-FileCopyrightText: 2024 The LineageOS Project 3 | // SPDX-License-Identifier: Apache-2.0 4 | // 5 | 6 | soong_config_module_type { 7 | name: "mediatek_vibrator_defaults", 8 | module_type: "cc_defaults", 9 | config_namespace: "mediatek_vibrator", 10 | bool_variables: [ 11 | "supports_effects", 12 | ], 13 | properties: [ 14 | "cflags", 15 | ], 16 | } 17 | 18 | mediatek_vibrator_defaults { 19 | name: "mediatek_vibrator_defaults", 20 | soong_config_variables: { 21 | supports_effects: { 22 | cflags: ["-DVIBRATOR_SUPPORTS_EFFECTS"], 23 | }, 24 | }, 25 | } 26 | 27 | cc_binary { 28 | name: "android.hardware.vibrator-service.mediatek", 29 | defaults: ["mediatek_vibrator_defaults"], 30 | vintf_fragments: ["android.hardware.vibrator.mediatek.xml"], 31 | init_rc: ["vibrator-mediatek.rc"], 32 | vendor: true, 33 | relative_install_path: "hw", 34 | 35 | srcs: [ 36 | "Vibrator.cpp", 37 | "VibratorUtils.cpp", 38 | "main.cpp", 39 | ], 40 | 41 | shared_libs: [ 42 | "libbase", 43 | "libbinder_ndk", 44 | "android.hardware.vibrator-V2-ndk", 45 | ], 46 | } 47 | -------------------------------------------------------------------------------- /aidl/vibrator/Vibrator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include "Vibrator.h" 8 | 9 | #include 10 | #include 11 | 12 | namespace aidl { 13 | namespace android { 14 | namespace hardware { 15 | namespace vibrator { 16 | 17 | #ifdef VIBRATOR_SUPPORTS_EFFECTS 18 | Vibrator::Vibrator() { 19 | if (exists(kVibratorStrength)) { 20 | mVibratorStrengthSupported = true; 21 | mVibratorStrengthMax = getNode(kVibratorStrengthMax, 9); 22 | } 23 | } 24 | #endif 25 | 26 | ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) { 27 | LOG(VERBOSE) << "Vibrator reporting capabilities"; 28 | *_aidl_return = IVibrator::CAP_ON_CALLBACK; 29 | 30 | #ifdef VIBRATOR_SUPPORTS_EFFECTS 31 | *_aidl_return |= IVibrator::CAP_PERFORM_CALLBACK; 32 | 33 | if (mVibratorStrengthSupported) *_aidl_return |= IVibrator::CAP_AMPLITUDE_CONTROL; 34 | #endif 35 | 36 | return ndk::ScopedAStatus::ok(); 37 | } 38 | 39 | ndk::ScopedAStatus Vibrator::off() { 40 | LOG(VERBOSE) << "Vibrator off"; 41 | return setNode(kVibratorActivate, 0); 42 | } 43 | 44 | ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, 45 | const std::shared_ptr& callback) { 46 | ndk::ScopedAStatus status; 47 | 48 | LOG(VERBOSE) << "Vibrator on for timeoutMs: " << timeoutMs; 49 | 50 | status = activate(timeoutMs); 51 | if (!status.isOk()) return status; 52 | 53 | if (callback != nullptr) { 54 | std::thread([=] { 55 | LOG(VERBOSE) << "Starting on on another thread"; 56 | usleep(timeoutMs * 1000); 57 | LOG(VERBOSE) << "Notifying on complete"; 58 | if (!callback->onComplete().isOk()) { 59 | LOG(ERROR) << "Failed to call onComplete"; 60 | } 61 | }).detach(); 62 | } 63 | return ndk::ScopedAStatus::ok(); 64 | } 65 | 66 | ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength, 67 | const std::shared_ptr& callback, 68 | int32_t* _aidl_return) { 69 | ndk::ScopedAStatus status; 70 | int32_t timeoutMs; 71 | 72 | if (vibEffects.find(effect) == vibEffects.end()) 73 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 74 | 75 | if (vibStrengths.find(strength) == vibStrengths.end()) 76 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 77 | 78 | #ifdef VIBRATOR_SUPPORTS_EFFECTS 79 | setAmplitude(vibStrengths[strength]); 80 | #endif 81 | 82 | timeoutMs = vibEffects[effect]; 83 | 84 | status = activate(timeoutMs); 85 | if (!status.isOk()) return status; 86 | 87 | if (callback != nullptr) { 88 | std::thread([=] { 89 | LOG(VERBOSE) << "Starting perform on another thread"; 90 | usleep(timeoutMs * 1000); 91 | LOG(VERBOSE) << "Notifying perform complete"; 92 | callback->onComplete(); 93 | }).detach(); 94 | } 95 | 96 | *_aidl_return = timeoutMs; 97 | return ndk::ScopedAStatus::ok(); 98 | } 99 | 100 | ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector* _aidl_return) { 101 | for (auto const& pair : vibEffects) 102 | _aidl_return->push_back(pair.first); 103 | 104 | return ndk::ScopedAStatus::ok(); 105 | } 106 | 107 | ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) { 108 | #ifdef VIBRATOR_SUPPORTS_EFFECTS 109 | int32_t intensity; 110 | #endif 111 | 112 | if (amplitude <= 0.0f || amplitude > 1.0f) 113 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT)); 114 | 115 | #ifdef VIBRATOR_SUPPORTS_EFFECTS 116 | LOG(VERBOSE) << "Setting amplitude: " << amplitude; 117 | 118 | intensity = amplitude * mVibratorStrengthMax; 119 | 120 | LOG(VERBOSE) << "Setting intensity: " << intensity; 121 | 122 | if (mVibratorStrengthSupported) setNode(kVibratorStrength, intensity); 123 | #endif 124 | 125 | return ndk::ScopedAStatus::ok(); 126 | } 127 | 128 | ndk::ScopedAStatus Vibrator::setExternalControl(bool enabled __unused) { 129 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 130 | } 131 | 132 | ndk::ScopedAStatus Vibrator::getCompositionDelayMax(int32_t* maxDelayMs __unused) { 133 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 134 | } 135 | 136 | ndk::ScopedAStatus Vibrator::getCompositionSizeMax(int32_t* maxSize __unused) { 137 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 138 | } 139 | 140 | ndk::ScopedAStatus Vibrator::getSupportedPrimitives( 141 | std::vector* supported __unused) { 142 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 143 | } 144 | 145 | ndk::ScopedAStatus Vibrator::getPrimitiveDuration(CompositePrimitive primitive __unused, 146 | int32_t* durationMs __unused) { 147 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 148 | } 149 | 150 | ndk::ScopedAStatus Vibrator::compose(const std::vector& composite __unused, 151 | const std::shared_ptr& callback __unused) { 152 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 153 | } 154 | 155 | ndk::ScopedAStatus Vibrator::getSupportedAlwaysOnEffects( 156 | std::vector* _aidl_return __unused) { 157 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 158 | } 159 | 160 | ndk::ScopedAStatus Vibrator::alwaysOnEnable(int32_t id __unused, Effect effect __unused, 161 | EffectStrength strength __unused) { 162 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 163 | } 164 | 165 | ndk::ScopedAStatus Vibrator::alwaysOnDisable(int32_t id __unused) { 166 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 167 | } 168 | 169 | ndk::ScopedAStatus Vibrator::getResonantFrequency(float* resonantFreqHz __unused) { 170 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 171 | } 172 | 173 | ndk::ScopedAStatus Vibrator::getQFactor(float* qFactor __unused) { 174 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 175 | } 176 | 177 | ndk::ScopedAStatus Vibrator::getFrequencyResolution(float* freqResolutionHz __unused) { 178 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 179 | } 180 | 181 | ndk::ScopedAStatus Vibrator::getFrequencyMinimum(float* freqMinimumHz __unused) { 182 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 183 | } 184 | 185 | ndk::ScopedAStatus Vibrator::getBandwidthAmplitudeMap(std::vector* _aidl_return __unused) { 186 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 187 | } 188 | 189 | ndk::ScopedAStatus Vibrator::getPwlePrimitiveDurationMax(int32_t* durationMs __unused) { 190 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 191 | } 192 | 193 | ndk::ScopedAStatus Vibrator::getPwleCompositionSizeMax(int32_t* maxSize __unused) { 194 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 195 | } 196 | 197 | ndk::ScopedAStatus Vibrator::getSupportedBraking(std::vector* supported __unused) { 198 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 199 | } 200 | 201 | ndk::ScopedAStatus Vibrator::composePwle(const std::vector& composite __unused, 202 | const std::shared_ptr& callback 203 | __unused) { 204 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); 205 | } 206 | 207 | } // namespace vibrator 208 | } // namespace hardware 209 | } // namespace android 210 | } // namespace aidl 211 | -------------------------------------------------------------------------------- /aidl/vibrator/Vibrator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace aidl { 13 | namespace android { 14 | namespace hardware { 15 | namespace vibrator { 16 | 17 | const std::string kVibratorPropPrefix = "ro.vendor.vibrator.hal."; 18 | const std::string kVibratorPropDuration = ".duration"; 19 | 20 | const std::string kVibratorState = "/sys/class/leds/vibrator/state"; 21 | const std::string kVibratorDuration = "/sys/class/leds/vibrator/duration"; 22 | const std::string kVibratorActivate = "/sys/class/leds/vibrator/activate"; 23 | 24 | #ifdef VIBRATOR_SUPPORTS_EFFECTS 25 | const std::string kVibratorStrength = "/sys/class/leds/vibrator/vmax"; 26 | const std::string kVibratorStrengthMax = "/sys/class/leds/vibrator/vmax_max"; 27 | #endif 28 | 29 | static std::map vibStrengths = { 30 | {EffectStrength::LIGHT, 0.25}, {EffectStrength::MEDIUM, 0.5}, {EffectStrength::STRONG, 1}}; 31 | 32 | class Vibrator : public BnVibrator { 33 | public: 34 | #ifdef VIBRATOR_SUPPORTS_EFFECTS 35 | Vibrator(); 36 | #endif 37 | ndk::ScopedAStatus getCapabilities(int32_t* _aidl_return) override; 38 | ndk::ScopedAStatus off() override; 39 | ndk::ScopedAStatus on(int32_t timeoutMs, 40 | const std::shared_ptr& callback) override; 41 | ndk::ScopedAStatus perform(Effect effect, EffectStrength strength, 42 | const std::shared_ptr& callback, 43 | int32_t* _aidl_return) override; 44 | ndk::ScopedAStatus getSupportedEffects(std::vector* _aidl_return) override; 45 | ndk::ScopedAStatus setAmplitude(float amplitude) override; 46 | ndk::ScopedAStatus setExternalControl(bool enabled) override; 47 | ndk::ScopedAStatus getCompositionDelayMax(int32_t* maxDelayMs); 48 | ndk::ScopedAStatus getCompositionSizeMax(int32_t* maxSize); 49 | ndk::ScopedAStatus getSupportedPrimitives(std::vector* supported) override; 50 | ndk::ScopedAStatus getPrimitiveDuration(CompositePrimitive primitive, 51 | int32_t* durationMs) override; 52 | ndk::ScopedAStatus compose(const std::vector& composite, 53 | const std::shared_ptr& callback) override; 54 | ndk::ScopedAStatus getSupportedAlwaysOnEffects(std::vector* _aidl_return) override; 55 | ndk::ScopedAStatus alwaysOnEnable(int32_t id, Effect effect, EffectStrength strength) override; 56 | ndk::ScopedAStatus alwaysOnDisable(int32_t id) override; 57 | ndk::ScopedAStatus getResonantFrequency(float* resonantFreqHz) override; 58 | ndk::ScopedAStatus getQFactor(float* qFactor) override; 59 | ndk::ScopedAStatus getFrequencyResolution(float* freqResolutionHz) override; 60 | ndk::ScopedAStatus getFrequencyMinimum(float* freqMinimumHz) override; 61 | ndk::ScopedAStatus getBandwidthAmplitudeMap(std::vector* _aidl_return) override; 62 | ndk::ScopedAStatus getPwlePrimitiveDurationMax(int32_t* durationMs) override; 63 | ndk::ScopedAStatus getPwleCompositionSizeMax(int32_t* maxSize) override; 64 | ndk::ScopedAStatus getSupportedBraking(std::vector* supported) override; 65 | ndk::ScopedAStatus composePwle(const std::vector& composite, 66 | const std::shared_ptr& callback) override; 67 | 68 | private: 69 | static ndk::ScopedAStatus setNode(const std::string path, const int32_t value); 70 | static int getIntProperty(const std::string& key, const int fallback); 71 | std::map vibEffects = { 72 | {Effect::CLICK, getIntProperty("click" + kVibratorPropDuration, 50)}, 73 | {Effect::TICK, getIntProperty("tick" + kVibratorPropDuration, 32)}, 74 | {Effect::TEXTURE_TICK, getIntProperty("texture_tick" + kVibratorPropDuration, 25)}, 75 | }; 76 | #ifdef VIBRATOR_SUPPORTS_EFFECTS 77 | static bool exists(const std::string path); 78 | static int getNode(const std::string path, const int fallback); 79 | bool mVibratorStrengthSupported; 80 | int mVibratorStrengthMax; 81 | #endif 82 | ndk::ScopedAStatus activate(const int32_t timeoutMs); 83 | }; 84 | 85 | } // namespace vibrator 86 | } // namespace hardware 87 | } // namespace android 88 | } // namespace aidl 89 | -------------------------------------------------------------------------------- /aidl/vibrator/VibratorUtils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include "Vibrator.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace aidl { 14 | namespace android { 15 | namespace hardware { 16 | namespace vibrator { 17 | 18 | ndk::ScopedAStatus Vibrator::setNode(const std::string path, const int32_t value) { 19 | std::ofstream file(path); 20 | 21 | if (!file.is_open()) { 22 | LOG(ERROR) << "Failed to write " << value << " to " << path; 23 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC)); 24 | } 25 | 26 | file << value << std::endl; 27 | 28 | return ndk::ScopedAStatus::ok(); 29 | } 30 | 31 | ndk::ScopedAStatus Vibrator::activate(const int32_t timeoutMs) { 32 | ndk::ScopedAStatus status; 33 | 34 | /* timeoutMs under 1 = turn off vibrator */ 35 | if (timeoutMs < 1) { 36 | return off(); 37 | } 38 | 39 | status = setNode(kVibratorState, 1); 40 | if (!status.isOk()) return status; 41 | 42 | status = setNode(kVibratorDuration, timeoutMs); 43 | if (!status.isOk()) return status; 44 | 45 | status = setNode(kVibratorActivate, 1); 46 | if (!status.isOk()) return status; 47 | 48 | return ndk::ScopedAStatus::ok(); 49 | } 50 | 51 | #ifdef VIBRATOR_SUPPORTS_EFFECTS 52 | bool Vibrator::exists(const std::string path) { 53 | std::ofstream file(path); 54 | return file.is_open(); 55 | } 56 | 57 | int Vibrator::getNode(const std::string path, const int fallback) { 58 | std::ifstream file(path); 59 | int value; 60 | 61 | if (!file.is_open()) { 62 | LOG(ERROR) << "failed to read from " << path.c_str(); 63 | return fallback; 64 | } 65 | 66 | file >> value; 67 | return value; 68 | } 69 | #endif 70 | 71 | int Vibrator::getIntProperty(const std::string& key, const int fallback) { 72 | return ::android::base::GetIntProperty(kVibratorPropPrefix + key, fallback); 73 | } 74 | 75 | } // namespace vibrator 76 | } // namespace hardware 77 | } // namespace android 78 | } // namespace aidl 79 | -------------------------------------------------------------------------------- /aidl/vibrator/android.hardware.vibrator.mediatek.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | android.hardware.vibrator 4 | 2 5 | IVibrator/default 6 | 7 | 8 | -------------------------------------------------------------------------------- /aidl/vibrator/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 The Android Open Source Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include "Vibrator.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | using aidl::android::hardware::vibrator::Vibrator; 14 | 15 | int main() { 16 | ABinderProcess_setThreadPoolMaxThreadCount(0); 17 | 18 | // make a default vibrator service 19 | auto vib = ndk::SharedRefBase::make(); 20 | const std::string vibName = std::string() + Vibrator::descriptor + "/default"; 21 | binder_status_t status = AServiceManager_addService(vib->asBinder().get(), vibName.c_str()); 22 | CHECK_EQ(status, STATUS_OK); 23 | 24 | ABinderProcess_joinThreadPool(); 25 | return EXIT_FAILURE; // should not reach 26 | } 27 | -------------------------------------------------------------------------------- /aidl/vibrator/vibrator-mediatek.rc: -------------------------------------------------------------------------------- 1 | on init 2 | chown system system /sys/class/leds/vibrator/vmax 3 | chown system system /sys/class/leds/vibrator/vmax_max 4 | 5 | service vendor.vibrator-mediatek /vendor/bin/hw/android.hardware.vibrator-service.mediatek 6 | class hal 7 | user system 8 | group system 9 | -------------------------------------------------------------------------------- /create_pl_dev/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // SPDX-FileCopyrightText: 2024 The LineageOS Project 3 | // SPDX-License-Identifier: Apache-2.0 4 | // 5 | 6 | cc_binary { 7 | name: "create_pl_dev", 8 | srcs: ["create_pl_dev.cpp"], 9 | init_rc: ["create_pl_dev.rc"], 10 | recovery_available: true, 11 | static_libs: [ 12 | "libfs_mgr", 13 | ], 14 | shared_libs: [ 15 | "libbase", 16 | "liblog", 17 | ], 18 | } 19 | -------------------------------------------------------------------------------- /create_pl_dev/create_pl_dev.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2024 The LineageOS Project 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #define LOG_TAG "create_pl_dev" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #define BLOCK_SIZE 512 18 | 19 | #define EMMC_HSZ 0x800 20 | #define UFS_HSZ 0x1000 21 | 22 | #define COMBO_HEADER_SIZE 4 23 | #define UFS_HEADER_SIZE 3 24 | 25 | #define UFS_HEADER "UFS" 26 | #define EMMC_HEADER "EMMC" 27 | #define COMBO_HEADER "COMB" 28 | 29 | using namespace android::dm; 30 | 31 | struct pl_device { 32 | const char* dm_name; 33 | const char* dev; 34 | }; 35 | 36 | static struct pl_device pl_devices[] = { 37 | {"preloader_raw_a", "/dev/block/sda"}, 38 | {"preloader_raw_b", "/dev/block/sdb"}, 39 | {"preloader_raw_a", "/dev/block/mmcblk0boot0"}, 40 | {"preloader_raw_b", "/dev/block/mmcblk0boot1"}, 41 | }; 42 | 43 | static void create_dm_device(const char* name, const char* dev, int start, int count) { 44 | DeviceMapper& dm = DeviceMapper::Instance(); 45 | DmTable table; 46 | std::unique_ptr target; 47 | std::string path; 48 | 49 | target = std::make_unique(0, count, dev, start); 50 | if (!table.AddTarget(std::move(target))) { 51 | ALOGE("Failed to add target for %s.", name); 52 | return; 53 | } 54 | 55 | if (!dm.CreateDevice(name, table, &path, std::chrono::milliseconds(500))) { 56 | ALOGE("Failed to create device %s.", name); 57 | return; 58 | } 59 | 60 | ALOGI("Created DM device %s at %s.", name, path.c_str()); 61 | } 62 | 63 | int main() { 64 | int fd, size, count, start; 65 | char header[COMBO_HEADER_SIZE]; 66 | 67 | for (int i = 0; i < sizeof(pl_devices) / sizeof(pl_device); i++) { 68 | pl_device* device = &pl_devices[i]; 69 | 70 | if (access(device->dev, F_OK) == -1) { 71 | ALOGE("Device %s not found.", device->dev); 72 | continue; 73 | } 74 | 75 | fd = open(device->dev, O_RDONLY); 76 | if (fd == -1) { 77 | ALOGE("Failed to open %s: %s.", device->dev, strerror(errno)); 78 | continue; 79 | } 80 | 81 | size = lseek(fd, 0, SEEK_END); 82 | if (size == -1) { 83 | ALOGE("Failed to seek %s: %s.", device->dev, strerror(errno)); 84 | close(fd); 85 | continue; 86 | } 87 | 88 | count = size / BLOCK_SIZE; 89 | 90 | if (lseek(fd, 0, SEEK_SET) == -1) { 91 | ALOGE("Failed to seek %s: %s.", device->dev, strerror(errno)); 92 | close(fd); 93 | continue; 94 | } 95 | 96 | if (read(fd, header, COMBO_HEADER_SIZE) != COMBO_HEADER_SIZE) { 97 | ALOGE("Failed to read %s: %s.", device->dev, strerror(errno)); 98 | close(fd); 99 | continue; 100 | } 101 | 102 | close(fd); 103 | 104 | if (strncmp(header, UFS_HEADER, UFS_HEADER_SIZE) == 0 || 105 | strncmp(header, COMBO_HEADER, COMBO_HEADER_SIZE) == 0) { 106 | start = UFS_HSZ / BLOCK_SIZE; 107 | } else if (strncmp(header, EMMC_HEADER, COMBO_HEADER_SIZE) == 0) { 108 | start = EMMC_HSZ / BLOCK_SIZE; 109 | } else { 110 | ALOGE("Unknown header %s for %s.", header, device->dev); 111 | continue; 112 | } 113 | 114 | count -= start; 115 | 116 | create_dm_device(device->dm_name, device->dev, start, count); 117 | } 118 | 119 | return 0; 120 | } 121 | -------------------------------------------------------------------------------- /create_pl_dev/create_pl_dev.rc: -------------------------------------------------------------------------------- 1 | on post-fs 2 | start create_pl_dev 3 | 4 | wait /dev/block/mapper/preloader_raw_a 5 | wait /dev/block/mapper/preloader_raw_b 6 | 7 | symlink /dev/block/mapper/preloader_raw_a /dev/block/by-name/preloader_raw_a 8 | symlink /dev/block/mapper/preloader_raw_b /dev/block/by-name/preloader_raw_b 9 | 10 | symlink /dev/block/mapper/preloader_raw_a /dev/block/platform/bootdevice/by-name/preloader_raw_a 11 | symlink /dev/block/mapper/preloader_raw_b /dev/block/platform/bootdevice/by-name/preloader_raw_b 12 | 13 | symlink /dev/block/mapper/preloader_raw_a /dev/block/platform/11270000.ufshci/by-name/preloader_raw_a 14 | symlink /dev/block/mapper/preloader_raw_b /dev/block/platform/11270000.ufshci/by-name/preloader_raw_b 15 | 16 | symlink /dev/block/mapper/preloader_raw_a /dev/block/platform/11230000.mmc/by-name/preloader_raw_a 17 | symlink /dev/block/mapper/preloader_raw_b /dev/block/platform/11230000.mmc/by-name/preloader_raw_b 18 | 19 | symlink /dev/block/mapper/preloader_raw_a /dev/block/platform/11230000.msdc/by-name/preloader_raw_a 20 | symlink /dev/block/mapper/preloader_raw_b /dev/block/platform/11230000.msdc/by-name/preloader_raw_b 21 | 22 | service create_pl_dev /system/bin/create_pl_dev 23 | user root 24 | group root 25 | seclabel u:r:update_engine:s0 26 | oneshot 27 | disabled 28 | -------------------------------------------------------------------------------- /hidl/mtkpower/1.2/default/Android.bp: -------------------------------------------------------------------------------- 1 | cc_binary { 2 | name: "vendor.mediatek.hardware.mtkpower@1.2-service.stub", 3 | defaults: ["hidl_defaults"], 4 | init_rc: ["vendor.mediatek.hardware.mtkpower@1.2-service.stub.rc"], 5 | vendor: true, 6 | relative_install_path: "hw", 7 | srcs: [ 8 | "MtkPerf.cpp", 9 | "MtkPower.cpp", 10 | "MtkPowerCallback.cpp", 11 | "service.cpp", 12 | ], 13 | shared_libs: [ 14 | "libbase", 15 | "libhidlbase", 16 | "libutils", 17 | "libbinder_ndk", 18 | "android.hardware.power-V2-ndk", 19 | "vendor.mediatek.hardware.mtkpower@1.0", 20 | "vendor.mediatek.hardware.mtkpower@1.1", 21 | "vendor.mediatek.hardware.mtkpower@1.2", 22 | ], 23 | } 24 | -------------------------------------------------------------------------------- /hidl/mtkpower/1.2/default/MtkPerf.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #define LOG_TAG "vendor.mediatek.hardware.mtkpower@1.2-service.stub" 8 | 9 | #include 10 | 11 | #include "MtkPerf.h" 12 | 13 | namespace vendor::mediatek::hardware::mtkpower::implementation { 14 | 15 | // Methods from ::vendor::mediatek::hardware::mtkpower::V1_0::IMtkPerf follow. 16 | Return MtkPerf::perfLockAcquire(int32_t pl_handle, uint32_t duration, const hidl_vec& /* boostsList */, int32_t reserved) { 17 | LOG(INFO) << "perfLockAcquire pl_handle: " << pl_handle 18 | << " duration: " << duration << " reserved: " 19 | << reserved; 20 | return pl_handle; 21 | } 22 | 23 | Return MtkPerf::perfLockRelease(int32_t pl_handle, int32_t reserved) { 24 | LOG(INFO) << "perfLockRelease pl_handle: " << pl_handle 25 | << " reserved: " << reserved; 26 | return Void(); 27 | } 28 | 29 | 30 | // Methods from ::vendor::mediatek::hardware::mtkpower::V1_1::IMtkPerf follow. 31 | Return MtkPerf::perfCusLockHint(int32_t hint, uint32_t duration) { 32 | LOG(INFO) << "perfCusLockHint hint: " << hint 33 | << " duraton: " << duration; 34 | return 233; 35 | } 36 | 37 | 38 | // Methods from ::vendor::mediatek::hardware::mtkpower::V1_2::IMtkPerf follow. 39 | Return MtkPerf::perfLockReleaseSync(int32_t pl_handle, int32_t reserved) { 40 | LOG(INFO) << "perfLockReleaseSync pl_handle: " << pl_handle 41 | << " reserved: " << reserved; 42 | return 0; 43 | } 44 | 45 | } // namespace vendor::mediatek::hardware::mtkpower::implementation 46 | -------------------------------------------------------------------------------- /hidl/mtkpower/1.2/default/MtkPerf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace vendor::mediatek::hardware::mtkpower::implementation { 14 | 15 | using ::android::hardware::hidl_array; 16 | using ::android::hardware::hidl_memory; 17 | using ::android::hardware::hidl_string; 18 | using ::android::hardware::hidl_vec; 19 | using ::android::hardware::Return; 20 | using ::android::hardware::Void; 21 | using ::android::sp; 22 | 23 | struct MtkPerf : public V1_2::IMtkPerf { 24 | // Methods from ::vendor::mediatek::hardware::mtkpower::V1_0::IMtkPerf follow. 25 | Return perfLockAcquire(int32_t pl_handle, uint32_t duration, const hidl_vec& boostsList, int32_t reserved) override; 26 | Return perfLockRelease(int32_t pl_handle, int32_t reserved) override; 27 | 28 | // Methods from ::vendor::mediatek::hardware::mtkpower::V1_1::IMtkPerf follow. 29 | Return perfCusLockHint(int32_t hint, uint32_t duration) override; 30 | 31 | // Methods from ::vendor::mediatek::hardware::mtkpower::V1_2::IMtkPerf follow. 32 | Return perfLockReleaseSync(int32_t pl_handle, int32_t reserved) override; 33 | }; 34 | 35 | } // namespace vendor::mediatek::hardware::mtkpower::implementation 36 | -------------------------------------------------------------------------------- /hidl/mtkpower/1.2/default/MtkPower.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #define LOG_TAG "vendor.mediatek.hardware.mtkpower@1.2-service.stub" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "MtkPower.h" 15 | 16 | static std::shared_ptr gAidlPowerHal; 17 | static const std::string kInstance = 18 | std::string(aidl::android::hardware::power::IPower::descriptor) + "/default"; 19 | 20 | namespace vendor::mediatek::hardware::mtkpower::implementation { 21 | 22 | bool MtkPower::getAidlPowerHal(void) { 23 | if (!gAidlPowerHal) { 24 | ndk::SpAIBinder pwBinder = ndk::SpAIBinder( 25 | AServiceManager_getService(kInstance.c_str())); 26 | gAidlPowerHal = aidl::android::hardware::power::IPower::fromBinder(pwBinder); 27 | } 28 | 29 | return !!gAidlPowerHal; 30 | } 31 | 32 | MtkPower::MtkPower() { 33 | if (!getAidlPowerHal()) { 34 | LOG(ERROR) << "Can't get AIDL Power HAL!"; 35 | } else { 36 | LOG(INFO) << "Connected to power AIDL HAL"; 37 | } 38 | } 39 | 40 | // Methods from ::vendor::mediatek::hardware::mtkpower::V1_0::IMtkPower follow. 41 | Return MtkPower::mtkCusPowerHint(int32_t hint, int32_t data) { 42 | LOG(INFO) << "mtkCusPowerHint hint: " << hint 43 | << " data: " << data; 44 | return Void(); 45 | } 46 | 47 | Return MtkPower::mtkPowerHint(int32_t hint, int32_t data) { 48 | // Forward AUDIO_POWER hints to libperfmgr 49 | if (hint == MTKPOWER_HINT_AUDIO_POWER) { 50 | // Enable the mode if data is non-zero 51 | bool enabled = data != 0; 52 | LOG(INFO) << "mtkPowerhint hint: MTKPOWER_HINT_AUDIO_POWER data: " << data << " enabled: " << enabled; 53 | if (getAidlPowerHal()) { 54 | gAidlPowerHal->setMode( 55 | aidl::android::hardware::power::Mode::AUDIO_STREAMING_LOW_LATENCY, 56 | enabled 57 | ); 58 | } else { 59 | LOG(ERROR) << "mtkPowerHint: Can't get AIDL Power HAL!"; 60 | } 61 | } else { 62 | LOG(INFO) << "mtkPowerHint hint: " << hint 63 | << " data: " << data; 64 | } 65 | return Void(); 66 | } 67 | 68 | Return MtkPower::notifyAppState(const hidl_string& pack, const hidl_string& act, int32_t pid, int32_t state, int32_t uid) { 69 | LOG(INFO) << "notifyAppState pack: " << pack 70 | << " act: " << act << " pid: " << pid 71 | << " state: " << state << " uid: " << uid; 72 | return Void(); 73 | } 74 | 75 | Return MtkPower::querySysInfo(int32_t cmd, int32_t param) { 76 | LOG(INFO) << "querySysInfo cmd: " << cmd 77 | << " param: " << param; 78 | return 0; 79 | } 80 | 81 | Return MtkPower::setSysInfo(int32_t type, const hidl_string& data) { 82 | LOG(INFO) << "setSysInfo type: " << type 83 | << " data: " << data; 84 | return 0; 85 | } 86 | 87 | Return MtkPower::setSysInfoAsync(int32_t type, const hidl_string& data) { 88 | LOG(INFO) << "setSysInfoAsync type: " << type 89 | << " data: " << data; 90 | return Void(); 91 | } 92 | 93 | 94 | // Methods from ::vendor::mediatek::hardware::mtkpower::V1_1::IMtkPower follow. 95 | Return MtkPower::setMtkPowerCallback(const sp<::vendor::mediatek::hardware::mtkpower::V1_1::IMtkPowerCallback>& /* callback */) { 96 | LOG(WARNING) << "setMtkPowerCallback"; 97 | return 0; 98 | } 99 | 100 | 101 | // Methods from ::vendor::mediatek::hardware::mtkpower::V1_2::IMtkPower follow. 102 | Return MtkPower::setMtkScnUpdateCallback(int32_t /* hint */, const sp<::vendor::mediatek::hardware::mtkpower::V1_2::IMtkPowerCallback>& /* callback */) { 103 | LOG(WARNING) << "setMtkScnUpdateCallback"; 104 | return 0; 105 | } 106 | 107 | } // namespace vendor::mediatek::hardware::mtkpower::implementation 108 | -------------------------------------------------------------------------------- /hidl/mtkpower/1.2/default/MtkPower.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #define MTKPOWER_HINT_AUDIO_POWER 47 14 | 15 | namespace vendor::mediatek::hardware::mtkpower::implementation { 16 | 17 | using ::android::hardware::hidl_array; 18 | using ::android::hardware::hidl_memory; 19 | using ::android::hardware::hidl_string; 20 | using ::android::hardware::hidl_vec; 21 | using ::android::hardware::Return; 22 | using ::android::hardware::Void; 23 | using ::android::sp; 24 | 25 | struct MtkPower : public V1_2::IMtkPower { 26 | MtkPower(); 27 | bool getAidlPowerHal(void); 28 | // Methods from ::vendor::mediatek::hardware::mtkpower::V1_0::IMtkPower follow. 29 | Return mtkCusPowerHint(int32_t hint, int32_t data) override; 30 | Return mtkPowerHint(int32_t hint, int32_t data) override; 31 | Return notifyAppState(const hidl_string& pack, const hidl_string& act, int32_t pid, int32_t state, int32_t uid) override; 32 | Return querySysInfo(int32_t cmd, int32_t param) override; 33 | Return setSysInfo(int32_t type, const hidl_string& data) override; 34 | Return setSysInfoAsync(int32_t type, const hidl_string& data) override; 35 | 36 | // Methods from ::vendor::mediatek::hardware::mtkpower::V1_1::IMtkPower follow. 37 | Return setMtkPowerCallback(const sp<::vendor::mediatek::hardware::mtkpower::V1_1::IMtkPowerCallback>& callback) override; 38 | 39 | // Methods from ::vendor::mediatek::hardware::mtkpower::V1_2::IMtkPower follow. 40 | Return setMtkScnUpdateCallback(int32_t hint, const sp<::vendor::mediatek::hardware::mtkpower::V1_2::IMtkPowerCallback>& callback) override; 41 | }; 42 | 43 | } // namespace vendor::mediatek::hardware::mtkpower::implementation 44 | -------------------------------------------------------------------------------- /hidl/mtkpower/1.2/default/MtkPowerCallback.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #define LOG_TAG "vendor.mediatek.hardware.mtkpower@1.2-service.stub" 8 | 9 | #include 10 | 11 | #include "MtkPowerCallback.h" 12 | 13 | namespace vendor::mediatek::hardware::mtkpower::implementation { 14 | 15 | // Methods from ::vendor::mediatek::hardware::mtkpower::V1_1::IMtkPowerCallback follow. 16 | Return MtkPowerCallback::mtkPowerHint(int32_t /* hint */, int32_t /* duration */) { 17 | return Void(); 18 | } 19 | 20 | Return MtkPowerCallback::notifyAppState(const hidl_string& /* pack */, const hidl_string& /* act */, int32_t /* pid */, int32_t /* state */, int32_t /* uid */) { 21 | return Void(); 22 | } 23 | 24 | 25 | // Methods from ::vendor::mediatek::hardware::mtkpower::V1_2::IMtkPowerCallback follow. 26 | Return MtkPowerCallback::notifyScnUpdate(int32_t /* hint */, int32_t /* data */) { 27 | return Void(); 28 | } 29 | 30 | } // namespace vendor::mediatek::hardware::mtkpower::implementation 31 | -------------------------------------------------------------------------------- /hidl/mtkpower/1.2/default/MtkPowerCallback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace vendor::mediatek::hardware::mtkpower::implementation { 14 | 15 | using ::android::hardware::hidl_array; 16 | using ::android::hardware::hidl_memory; 17 | using ::android::hardware::hidl_string; 18 | using ::android::hardware::hidl_vec; 19 | using ::android::hardware::Return; 20 | using ::android::hardware::Void; 21 | using ::android::sp; 22 | 23 | struct MtkPowerCallback : public V1_2::IMtkPowerCallback { 24 | // Methods from ::vendor::mediatek::hardware::mtkpower::V1_1::IMtkPowerCallback follow. 25 | Return mtkPowerHint(int32_t hint, int32_t duration) override; 26 | Return notifyAppState(const hidl_string& pack, const hidl_string& act, int32_t pid, int32_t state, int32_t uid) override; 27 | 28 | // Methods from ::vendor::mediatek::hardware::mtkpower::V1_2::IMtkPowerCallback follow. 29 | Return notifyScnUpdate(int32_t hint, int32_t data) override; 30 | }; 31 | 32 | } // namespace vendor::mediatek::hardware::mtkpower::implementation 33 | -------------------------------------------------------------------------------- /hidl/mtkpower/1.2/default/service.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #define LOG_TAG "vendor.mediatek.hardware.mtkpower@1.2-service.stub" 8 | 9 | #include 10 | #include 11 | 12 | #include "MtkPower.h" 13 | #include "MtkPerf.h" 14 | 15 | using android::OK; 16 | using android::sp; 17 | using android::status_t; 18 | using android::hardware::configureRpcThreadpool; 19 | using android::hardware::joinRpcThreadpool; 20 | 21 | using vendor::mediatek::hardware::mtkpower::V1_2::IMtkPower; 22 | using vendor::mediatek::hardware::mtkpower::V1_2::IMtkPerf; 23 | 24 | using vendor::mediatek::hardware::mtkpower::implementation::MtkPower; 25 | using vendor::mediatek::hardware::mtkpower::implementation::MtkPerf; 26 | 27 | int main() { 28 | configureRpcThreadpool(1, true /*callerWillJoin*/); 29 | 30 | sp mtkPower = new MtkPower(); 31 | sp mtkPerf = new MtkPerf(); 32 | 33 | if (mtkPower->registerAsService() != android::OK) { 34 | LOG(ERROR) << "Can't register MtkPower Stub HAL service"; 35 | return 1; 36 | } 37 | 38 | if (mtkPerf->registerAsService() != android::OK) { 39 | LOG(ERROR) << "Can't register MtkPerf Stub HAL service"; 40 | return 1; 41 | } 42 | 43 | joinRpcThreadpool(); 44 | 45 | return 0; // should never get here 46 | } 47 | -------------------------------------------------------------------------------- /hidl/mtkpower/1.2/default/vendor.mediatek.hardware.mtkpower@1.2-service.stub.rc: -------------------------------------------------------------------------------- 1 | service power-hal-1-2 /vendor/bin/hw/vendor.mediatek.hardware.mtkpower@1.2-service.stub 2 | class hal 3 | user system 4 | group system 5 | -------------------------------------------------------------------------------- /interfaces/Android.bp: -------------------------------------------------------------------------------- 1 | subdirs = [ 2 | "*", 3 | ] 4 | 5 | hidl_package_root { 6 | name: "vendor.mediatek.hardware.mtkpower", 7 | path: "hardware/mediatek/interfaces/mtkpower", 8 | } 9 | 10 | prebuilt_hidl_interfaces { 11 | name: "hidl_vendor_mediatek_hardware_keymaster_attestation_interface", 12 | interfaces: [ 13 | "vendor.mediatek.hardware.keymaster_attestation@1.0::IKeymasterDevice", 14 | "vendor.mediatek.hardware.keymaster_attestation@1.1::IKeymasterDevice" 15 | ] 16 | } 17 | 18 | prebuilt_hidl_interfaces { 19 | name: "hidl_vendor_mediatek_hardware_mmagent_interface", 20 | interfaces: [ 21 | "vendor.mediatek.hardware.mmagent@1.0::IMMAgent", 22 | "vendor.mediatek.hardware.mmagent@1.1::IMMAgent" 23 | ] 24 | } 25 | 26 | prebuilt_hidl_interfaces { 27 | name: "hidl_vendor_mediatek_hardware_mms_interface", 28 | interfaces: [ 29 | "vendor.mediatek.hardware.mms@1.0::IMms", 30 | "vendor.mediatek.hardware.mms@1.1::IMms", 31 | "vendor.mediatek.hardware.mms@1.2::IMms", 32 | "vendor.mediatek.hardware.mms@1.3::IMms", 33 | "vendor.mediatek.hardware.mms@1.4::IMms", 34 | "vendor.mediatek.hardware.mms@1.5::IMms", 35 | "vendor.mediatek.hardware.mms@1.6::IMms" 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /interfaces/mtkpower/1.0/.hidl-autogen: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LineageOS/android_hardware_mediatek/6e579f65d78b86a5aea5c03fa742a5a7b852765c/interfaces/mtkpower/1.0/.hidl-autogen -------------------------------------------------------------------------------- /interfaces/mtkpower/1.0/Android.bp: -------------------------------------------------------------------------------- 1 | // This file is autogenerated by hidl-gen -Landroidbp. 2 | 3 | hidl_interface { 4 | name: "vendor.mediatek.hardware.mtkpower@1.0", 5 | root: "vendor.mediatek.hardware.mtkpower", 6 | system_ext_specific: true, 7 | srcs: [ 8 | "IMtkPerf.hal", 9 | "IMtkPower.hal", 10 | ], 11 | interfaces: [ 12 | "android.hidl.base@1.0", 13 | ], 14 | gen_java: true, 15 | } 16 | -------------------------------------------------------------------------------- /interfaces/mtkpower/1.0/IMtkPerf.hal: -------------------------------------------------------------------------------- 1 | package vendor.mediatek.hardware.mtkpower@1.0; 2 | 3 | interface IMtkPerf { 4 | perfLockAcquire(int32_t pl_handle, uint32_t duration, vec boostsList, int32_t reserved) generates (int32_t ret); 5 | oneway perfLockRelease(int32_t pl_handle, int32_t reserved); 6 | }; 7 | -------------------------------------------------------------------------------- /interfaces/mtkpower/1.0/IMtkPower.hal: -------------------------------------------------------------------------------- 1 | package vendor.mediatek.hardware.mtkpower@1.0; 2 | 3 | interface IMtkPower { 4 | oneway mtkCusPowerHint(int32_t hint, int32_t data); 5 | oneway mtkPowerHint(int32_t hint, int32_t data); 6 | oneway notifyAppState(string pack, string act, int32_t pid, int32_t state, int32_t uid); 7 | querySysInfo(int32_t cmd, int32_t param) generates (int32_t ret); 8 | setSysInfo(int32_t type, string data) generates (int32_t ret); 9 | setSysInfoAsync(int32_t type, string data); 10 | }; 11 | -------------------------------------------------------------------------------- /interfaces/mtkpower/1.1/.hidl-autogen: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LineageOS/android_hardware_mediatek/6e579f65d78b86a5aea5c03fa742a5a7b852765c/interfaces/mtkpower/1.1/.hidl-autogen -------------------------------------------------------------------------------- /interfaces/mtkpower/1.1/Android.bp: -------------------------------------------------------------------------------- 1 | // This file is autogenerated by hidl-gen -Landroidbp. 2 | 3 | hidl_interface { 4 | name: "vendor.mediatek.hardware.mtkpower@1.1", 5 | root: "vendor.mediatek.hardware.mtkpower", 6 | system_ext_specific: true, 7 | srcs: [ 8 | "IMtkPerf.hal", 9 | "IMtkPower.hal", 10 | "IMtkPowerCallback.hal", 11 | ], 12 | interfaces: [ 13 | "android.hidl.base@1.0", 14 | "vendor.mediatek.hardware.mtkpower@1.0", 15 | ], 16 | gen_java: true, 17 | } 18 | -------------------------------------------------------------------------------- /interfaces/mtkpower/1.1/IMtkPerf.hal: -------------------------------------------------------------------------------- 1 | package vendor.mediatek.hardware.mtkpower@1.1; 2 | 3 | import @1.0::IMtkPerf; 4 | 5 | interface IMtkPerf extends @1.0::IMtkPerf { 6 | perfCusLockHint(int32_t hint, uint32_t duration) generates (int32_t ret); 7 | }; -------------------------------------------------------------------------------- /interfaces/mtkpower/1.1/IMtkPower.hal: -------------------------------------------------------------------------------- 1 | package vendor.mediatek.hardware.mtkpower@1.1; 2 | 3 | import @1.0::IMtkPower; 4 | import IMtkPowerCallback; 5 | 6 | interface IMtkPower extends @1.0::IMtkPower { 7 | setMtkPowerCallback(IMtkPowerCallback callback) generates (int32_t ret); 8 | }; -------------------------------------------------------------------------------- /interfaces/mtkpower/1.1/IMtkPowerCallback.hal: -------------------------------------------------------------------------------- 1 | package vendor.mediatek.hardware.mtkpower@1.1; 2 | 3 | interface IMtkPowerCallback { 4 | oneway mtkPowerHint(int32_t hint, int32_t duration); 5 | oneway notifyAppState(string pack, string act, int32_t pid, int32_t state, int32_t uid); 6 | }; -------------------------------------------------------------------------------- /interfaces/mtkpower/1.2/.hidl-autogen: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LineageOS/android_hardware_mediatek/6e579f65d78b86a5aea5c03fa742a5a7b852765c/interfaces/mtkpower/1.2/.hidl-autogen -------------------------------------------------------------------------------- /interfaces/mtkpower/1.2/Android.bp: -------------------------------------------------------------------------------- 1 | // This file is autogenerated by hidl-gen -Landroidbp. 2 | 3 | hidl_interface { 4 | name: "vendor.mediatek.hardware.mtkpower@1.2", 5 | root: "vendor.mediatek.hardware.mtkpower", 6 | system_ext_specific: true, 7 | srcs: [ 8 | "IMtkPerf.hal", 9 | "IMtkPower.hal", 10 | "IMtkPowerCallback.hal", 11 | ], 12 | interfaces: [ 13 | "android.hidl.base@1.0", 14 | "vendor.mediatek.hardware.mtkpower@1.0", 15 | "vendor.mediatek.hardware.mtkpower@1.1", 16 | ], 17 | gen_java: true, 18 | } 19 | -------------------------------------------------------------------------------- /interfaces/mtkpower/1.2/IMtkPerf.hal: -------------------------------------------------------------------------------- 1 | package vendor.mediatek.hardware.mtkpower@1.2; 2 | 3 | import @1.1::IMtkPerf; 4 | 5 | interface IMtkPerf extends @1.1::IMtkPerf { 6 | perfLockReleaseSync(int32_t pl_handle, int32_t reserved) generates (int32_t ret); 7 | }; -------------------------------------------------------------------------------- /interfaces/mtkpower/1.2/IMtkPower.hal: -------------------------------------------------------------------------------- 1 | package vendor.mediatek.hardware.mtkpower@1.2; 2 | 3 | import @1.1::IMtkPower; 4 | import IMtkPowerCallback; 5 | 6 | interface IMtkPower extends @1.1::IMtkPower { 7 | setMtkScnUpdateCallback(int32_t hint, IMtkPowerCallback callback) generates (int32_t ret); 8 | }; -------------------------------------------------------------------------------- /interfaces/mtkpower/1.2/IMtkPowerCallback.hal: -------------------------------------------------------------------------------- 1 | package vendor.mediatek.hardware.mtkpower@1.2; 2 | 3 | import @1.1::IMtkPowerCallback; 4 | 5 | interface IMtkPowerCallback extends @1.1::IMtkPowerCallback { 6 | oneway notifyScnUpdate(int32_t hint, int32_t data); 7 | }; -------------------------------------------------------------------------------- /interfaces/vendor_hal_makefile_generator.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2018, The Linux Foundation. All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are 6 | # met: 7 | # * Redistributions of source code must retain the above copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # * Redistributions in binary form must reproduce the above 10 | # copyright notice, this list of conditions and the following 11 | # disclaimer in the documentation and/or other materials provided 12 | # with the distribution. 13 | # * Neither the name of The Linux Foundation nor the names of its 14 | # contributors may be used to endorse or promote products derived 15 | # from this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18 | # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21 | # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 | # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 | # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE US 27 | 28 | # This file is used to generate blueprint/makefiles for the vendor hals 29 | 30 | # Sanitize host tools 31 | LS=`which ls` 32 | LS=${LS:-ls} 33 | MV=`which mv` 34 | MV=${MV:-mv} 35 | CAT=`which cat` 36 | CAT=${CAT:-cat} 37 | CUT=`which cut` 38 | CUT=${CUT:-cut} 39 | REV=`which rev` 40 | REV=${REV:-rev} 41 | SED=`which sed` 42 | SED=${SED:-sed} 43 | DIFF=`which diff` 44 | DIFF=${DIFF:-diff} 45 | ECHO=`which echo` 46 | ECHO=${ECHO:-echo} 47 | FIND=`which find` 48 | FIND=${FIND:-find} 49 | GREP=`which grep` 50 | GREP=${GREP:-grep} 51 | SORT=`which sort` 52 | SORT=${SORT:-sort} 53 | TOUCH=`which touch` 54 | TOUCH=${TOUCH:-touch} 55 | 56 | function generate_make_files() { 57 | local dir_path="$ANDROID_BUILD_TOP/$1" 58 | pushd $dir_path > /dev/null 59 | 60 | # Due to same package name in different folders we need to detect 61 | # opensource case so that it can be handled. 62 | local flag_opensource=false 63 | if ${ECHO} "$dir_path" | ${GREP} "opensource" > /dev/null;then 64 | flag_opensource=true 65 | fi 66 | 67 | # Search for all HAL files in given dir. 68 | local halFilePaths=`${ECHO} $(${FIND} -iname "*.hal" | ${SORT})` 69 | 70 | #Store package name in below array to create a unique set so that we trigger 71 | #hidl-gen only once for a given package. 72 | package_collection=() 73 | 74 | #Iterate over identified .hal Paths 75 | local prev_path="" 76 | for file in $halFilePaths; do 77 | local hal_path=`${ECHO} "$file" | ${REV} | ${CUT} -d"/" -f2- | ${REV}` 78 | if [ -e "$hal_path/Android.bp" ] && [ ! -e "$hal_path/.hidl-autogen" ]; then 79 | if [ ! "$hal_path" = "$prev_path" ]; then 80 | ${ECHO} "Skipping hidl-gen on $1/$hal_path as Android.bp is not compile-time generated" 81 | prev_path="$hal_path" 82 | fi 83 | continue; 84 | fi 85 | prev_path="$hal_path" 86 | 87 | # Find out package name from HAL file 88 | local hal_package=`${ECHO} $(${CAT} $file | ${GREP} -E -m 1 "^package ") | ${CUT} -d' ' -f2` 89 | 90 | # Get rid of extra delimter 91 | hal_package=${hal_package%?} 92 | 93 | #Check if we already executed hidl-gen for a given package 94 | if ${ECHO} "${package_collection[@]}" | ${GREP} -w $hal_package > /dev/null; then 95 | continue; 96 | else 97 | package_collection+=($hal_package) 98 | local delimeter=`${ECHO} "$file" | ${CUT} -d'/' -f2` 99 | local root=`${ECHO} "$hal_package" | ${SED} "s/$delimeter/#/g" | ${CUT} -d'#' -f1` 100 | #Identify Package Root 101 | root=${root%?} 102 | #Create root arguments for hidl-command 103 | local root_arguments="-r $root:$1 -r $2" 104 | fi 105 | 106 | local hal_path2=$1; 107 | #Handling for opensource HAL to solve package name conflict 108 | if [ "$flag_opensource" = true ]; then 109 | root="$root.$delimeter" 110 | hal_path2="$hal_path2/$delimeter" 111 | fi 112 | 113 | local root_arguments="-r $root:$hal_path2 -r $2" 114 | 115 | update_check=0 116 | if [ -e "$hal_path/Android.bp" ]; then 117 | ${MV} $hal_path/Android.bp $hal_path/.hidl-autogen 118 | update_check=1 119 | fi 120 | ${TOUCH} $hal_path/.hidl-autogen 121 | 122 | ${ECHO} -n "Running hidl-gen on $hal_package: " 123 | hidl-gen -Landroidbp $root_arguments $hal_package; 124 | rc=$?; if [[ $rc != 0 ]]; then return $rc; fi 125 | 126 | if [ "$update_check" -eq 1 ]; then 127 | ${DIFF} -q $hal_path/Android.bp $hal_path/.hidl-autogen > /dev/null 128 | if [ $? -eq 0 ]; then 129 | ${ECHO} "no changes" 130 | ${MV} $hal_path/.hidl-autogen $hal_path/Android.bp 131 | else 132 | ${ECHO} "updated" 133 | fi 134 | else 135 | ${ECHO} "created" 136 | fi 137 | ${TOUCH} $hal_path/.hidl-autogen 138 | done 139 | popd > /dev/null 140 | } 141 | 142 | function start_script_for_interfaces { 143 | #Find interfaces in workspace 144 | local interfaces=$(${LS} -d ${ANDROID_BUILD_TOP}/vendor/mediatek/*/interfaces) 145 | 146 | ${ECHO} "HIDL interfaces: Scanning for changes..." 147 | for interface in $interfaces; do 148 | #generate interfaces 149 | local relative_interface=${interface#${ANDROID_BUILD_TOP}/} 150 | generate_make_files $relative_interface "android.hidl:system/libhidl/transport" 151 | if [ $? -ne 0 ] ; then 152 | ${ECHO} "HIDL interfaces: Update Failed" 153 | return 1; 154 | fi 155 | done 156 | ${ECHO} "HIDL interfaces: Update complete." 157 | } 158 | 159 | #Start script for interfaces 160 | start_script_for_interfaces 161 | 162 | -------------------------------------------------------------------------------- /libmtkperf_client/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2022-2024 The LineageOS Project 3 | // 4 | // SPDX-License-Identifier: Apache-2.0 5 | // 6 | 7 | soong_namespace { 8 | } 9 | 10 | cc_defaults { 11 | name: "libmtkperf_client_defaults", 12 | srcs: ["mtkperf_client.c"], 13 | shared_libs: ["liblog"], 14 | } 15 | 16 | cc_defaults { 17 | name: "libpowerhalwrap_defaults", 18 | srcs: ["powerhalwrap_vendor.c"], 19 | shared_libs: ["liblog"], 20 | } 21 | 22 | cc_library_shared { 23 | name: "libmtkperf_client_vendor", 24 | defaults: ["libmtkperf_client_defaults"], 25 | vendor: true, 26 | } 27 | 28 | cc_library_shared { 29 | name: "libmtkperf_client", 30 | defaults: ["libmtkperf_client_defaults"], 31 | } 32 | 33 | cc_library_shared { 34 | name: "libpowerhalwrap", 35 | defaults: ["libpowerhalwrap_defaults"], 36 | } 37 | 38 | cc_library_shared { 39 | name: "libpowerhalwrap_vendor", 40 | defaults: ["libpowerhalwrap_defaults"], 41 | vendor: true, 42 | } 43 | -------------------------------------------------------------------------------- /libmtkperf_client/mtkperf_client.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #define LOG_TAG "libmtkperf_client" 8 | 9 | #include 10 | 11 | int perf_lock_acq(int hdl, int dur, long num, unsigned int tid) { 12 | ALOGI("[%s] hdl: %d, dur: %d, num: %ld, tid: %u", 13 | __func__, hdl, dur, num, tid); 14 | if (hdl > 0) 15 | return hdl; 16 | 17 | return 233; 18 | } 19 | 20 | int perf_lock_rel(int hdl) { 21 | ALOGI("[%s] hdl: %d", __func__, hdl); 22 | return 0; 23 | } 24 | 25 | int perf_cus_lock_hint(int hint, int dur) { 26 | ALOGI("[%s], hint: %d, dur: %d", __func__, hint, dur); 27 | return 233; 28 | } 29 | -------------------------------------------------------------------------------- /libmtkperf_client/powerhalwrap_vendor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 The LineageOS Project 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #define LOG_TAG "libpowerhalwrap_vendor" 8 | 9 | #include 10 | 11 | int PowerHal_Wrap_mtkPowerHint(int hint, int data) 12 | { 13 | ALOGD("[%s]: hint:%d, data:%d", __func__, hint, data); 14 | return 0; 15 | } 16 | 17 | int PowerHal_Wrap_mtkCusPowerHint(int hint, int data) 18 | { 19 | ALOGD("[%s]: hint:%d, data:%d", __func__, hint, data); 20 | return 0; 21 | } 22 | 23 | int PowerHal_Wrap_querySysInfo(unsigned int param, unsigned int data) 24 | { 25 | ALOGD("[%s]: param:%d, data:%d", __func__, param, data); 26 | return 0; 27 | } 28 | 29 | int64_t PowerHal_Wrap_notifyAppState(const char* pname, const char* aname, unsigned int pid, int status, unsigned int uid) 30 | { 31 | ALOGD("[%s]: pname:%s, aname:%s, pid:%d, status:%d, uid:%d", __func__, pname, aname, pid, status, uid); 32 | return 0; 33 | } 34 | 35 | int PowerHal_Wrap_scnReg() 36 | { 37 | ALOGD("%s called", __func__); 38 | return 0; 39 | } 40 | 41 | int PowerHal_Wrap_scnConfig() 42 | { 43 | ALOGD("%s called", __func__); 44 | return 0; 45 | } 46 | 47 | int PowerHal_Wrap_scnUnreg() 48 | { 49 | ALOGD("%s called", __func__); 50 | return 0; 51 | } 52 | 53 | int PowerHal_Wrap_scnEnable() 54 | { 55 | ALOGD("%s called", __func__); 56 | return 0; 57 | } 58 | 59 | int PowerHal_Wrap_scnDisable() 60 | { 61 | ALOGD("%s called", __func__); 62 | return 0; 63 | } 64 | 65 | int PowerHal_Wrap_scnUltraCfg() 66 | { 67 | ALOGD("%s called", __func__); 68 | return 0; 69 | } 70 | 71 | int PowerHal_TouchBoost(int duration) 72 | { 73 | ALOGD("[%s]: duration %d", __func__, duration); 74 | return 0; 75 | } 76 | 77 | int PowerHal_Wrap_setSysInfo(int type, const char* data) 78 | { 79 | ALOGD("[%s]: type: %d, data: %s", __func__, type, data); 80 | return 0; 81 | } 82 | 83 | int PowerHal_Wrap_setSysInfoAsync(int type, const char* data) 84 | { 85 | ALOGD("[%s]: type: %d, data: %s", __func__, type, data); 86 | return 0; 87 | } 88 | 89 | int PowerHal_Wrap_EnableMultiDisplayMode(int enable, int fps) 90 | { 91 | ALOGD("[%s]: enable: %d, fps: %d", __func__, enable, fps); 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /libwifi-hal-wrapper/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // SPDX-FileCopyrightText: 2024 The LineageOS Project 3 | // 4 | // SPDX-License-Identifier: Apache-2.0 5 | // 6 | 7 | cc_library_shared { 8 | name: "libwifi-hal-wrapper", 9 | vendor: true, 10 | required: [ 11 | "libwifi-hal-wrapper.xml", 12 | ], 13 | srcs: [ 14 | "libwifi-hal.cpp", 15 | ], 16 | shared_libs: [ 17 | "libcutils", 18 | "libutils", 19 | "liblog", 20 | "wifi_legacy", 21 | ], 22 | } 23 | 24 | prebuilt_etc { 25 | name: "libwifi-hal-wrapper.xml", 26 | src: "libwifi-hal-wrapper.xml", 27 | relative_install_path: "wifi/vendor_hals", 28 | vendor: true, 29 | } 30 | -------------------------------------------------------------------------------- /libwifi-hal-wrapper/libwifi-hal-wrapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | /vendor/lib64/libwifi-hal-wrapper.so 4 | 1 5 | 6 | -------------------------------------------------------------------------------- /sensors/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // SPDX-FileCopyrightText: 2024 The LineageOS Project 3 | // SPDX-License-Identifier: Apache-2.0 4 | // 5 | 6 | cc_library_shared { 7 | name: "android.hardware.sensors@2.0-subhal-impl-1.0", 8 | defaults: ["hidl_defaults"], 9 | srcs: [ 10 | "SensorsSubHal.cpp", 11 | ], 12 | shared_libs: [ 13 | "android.hardware.sensors@1.0", 14 | "android.hardware.sensors@2.0", 15 | "android.hardware.sensors@2.0-ScopedWakelock", 16 | "libbase", 17 | "libcutils", 18 | "libfmq", 19 | "libhardware", 20 | "libhidlbase", 21 | "libpower", 22 | "libutils", 23 | ], 24 | static_libs: [ 25 | "android.hardware.sensors@1.0-convert", 26 | "android.hardware.sensors@2.X-multihal", 27 | ], 28 | vendor: true, 29 | } 30 | -------------------------------------------------------------------------------- /sensors/SensorsSubHal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2019 The Android Open Source Project 3 | * SPDX-FileCopyrightText: 2024 The LineageOS Project 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "V2_0/SubHal.h" 15 | 16 | namespace android { 17 | namespace hardware { 18 | namespace sensors { 19 | namespace V2_0 { 20 | namespace subhal { 21 | namespace implementation { 22 | 23 | using ::android::hardware::sensors::V1_0::Event; 24 | using ::android::hardware::sensors::V1_0::OperationMode; 25 | using ::android::hardware::sensors::V1_0::RateLevel; 26 | using ::android::hardware::sensors::V1_0::Result; 27 | using ::android::hardware::sensors::V1_0::SensorInfo; 28 | using ::android::hardware::sensors::V1_0::SharedMemInfo; 29 | using ::android::hardware::sensors::V2_0::implementation::IHalProxyCallback; 30 | using ::android::hardware::sensors::V2_0::implementation::ISensorsSubHal; 31 | 32 | class SensorsSubHal : public ISensorsSubHal { 33 | public: 34 | SensorsSubHal(); 35 | 36 | Return getSensorsList(ISensors::getSensorsList_cb _hidl_cb); 37 | Return injectSensorData(const Event& event); 38 | Return initialize(const sp& halProxyCallback); 39 | 40 | virtual Return setOperationMode(OperationMode mode); 41 | 42 | OperationMode getOperationMode() const { return mCurrentOperationMode; } 43 | 44 | Return activate(int32_t sensorHandle, bool enabled); 45 | 46 | Return batch(int32_t sensorHandle, int64_t samplingPeriodNs, 47 | int64_t maxReportLatencyNs); 48 | 49 | Return flush(int32_t sensorHandle); 50 | 51 | Return registerDirectChannel(const SharedMemInfo& mem, 52 | ISensors::registerDirectChannel_cb _hidl_cb); 53 | 54 | Return unregisterDirectChannel(int32_t channelHandle); 55 | 56 | Return configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate, 57 | ISensors::configDirectReport_cb _hidl_cb); 58 | 59 | Return debug(const hidl_handle& fd, const hidl_vec& args); 60 | 61 | const std::string getName() { return "Sensors1SubHal"; } 62 | 63 | protected: 64 | std::map mSensors; 65 | 66 | sp mCallback; 67 | 68 | private: 69 | OperationMode mCurrentOperationMode = OperationMode::NORMAL; 70 | 71 | static constexpr int32_t kPollMaxBufferSize = 128; 72 | std::thread mPollThread; 73 | sensors_poll_device_1_t* mSensorDevice; 74 | struct sensors_module_t* mSensorModule; 75 | 76 | bool isWakeUpSensor(int32_t handle); 77 | int getHalDeviceVersion() const; 78 | void convertFromSensorEvents(size_t count, const sensors_event_t* srcArray, 79 | std::vector* dstVec, bool* wakeup); 80 | void enumerateSensors(); 81 | void pollForEvents(); 82 | void postEvents(const std::vector& events, bool wakeup); 83 | }; 84 | 85 | } // namespace implementation 86 | } // namespace subhal 87 | } // namespace V2_0 88 | } // namespace sensors 89 | } // namespace hardware 90 | } // namespace android 91 | --------------------------------------------------------------------------------