关于HDMI添加Screen_timeout
程序员文章站
2022-05-11 23:00:28
...
添加Display>>HDMI settings>>Screen Timeout选项
1,编辑
frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
+import com.mediatek.hdmi.IMtkHdmiManager;
+import android.os.ServiceManager;
@
+private IMtkHdmiManager mHdmiManager = null;
private boolean mLowPowerModeEnabled;
@
+ filter = new IntentFilter();
+ filter.addAction("android.intent.action.HDMI_PLUG");
+ mContext.registerReceiver(new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ TurnonScreen();
+ }
+ }, filter, null, mHandler);
// Register for settings changes.
final ContentResolver resolver = mContext.getContentResolver();
resolver.registerContentObserver(Settings.Secure.getUriFor(
@
+ resolver.registerContentObserver(Settings.System.getUriFor(
+ Settings.System.HDMI_LCD_TIMEOUT),
+ false, mSettingsObserver, UserHandle.USER_ALL);
resolver.registerContentObserver(Settings.System.getUriFor(
Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ),
false, mSettingsObserver, UserHandle.USER_ALL);
@
+ mHdmiManager = IMtkHdmiManager.Stub.asInterface(ServiceManager.getService(Context.HDMI_SERVICE));
// Go.
if (DEBUG) {
Slog.d(TAG, "system ready!");
@
mDirty |= DIRTY_SETTINGS;
+ lcd_delay_timeout = Settings.System.getIntForUser(resolver,
+ Settings.System.HDMI_LCD_TIMEOUT, 10,
+ UserHandle.USER_CURRENT);
+
+ if(isAbleChangeHDMIMode()){
+ TurnonScreen();
+ }
}
private void postAfterBootCompleted(Runnable r) {
@
+ private void TurnonScreen() {
+
+ ContentResolver resolver = mContext.getContentResolver();
+ final long currentTimeout = Settings.System.getLong(resolver,
+ Settings.System.HDMI_LCD_TIMEOUT, 10);
+ mHandlerTimeout.removeCallbacks(mScreenTimeout);
+ if (lcd_delay_timeout != -1) {
+
+ if (mTimeout) {
+ try {
+ setTemporaryScreenBrightnessSettingOverrideInternal(mScreenBrightnessSetting);
+ } catch (Exception e) {
+ Slog.e(TAG, "Exception" + e);
+ }
+ }
+ mTimeout = false;
+ if(isAbleChangeHDMIMode())
+ LockScreenOff();
+ }
+
+ return;
+ }
+
+ private boolean isAbleChangeHDMIMode() {
+
+ if (mHdmiManager == null)
+ return false;
+ boolean shouldEnable = false;
+ try {
+ shouldEnable = mHdmiManager.isSignalOutputting();
+ } catch (RemoteException e) {
+ Slog.w(TAG, "hdmi manager RemoteException: " + e.getMessage());
+ }
+ return (lcd_delay_timeout != -1) && shouldEnable;
+ }
+
+ Runnable mScreenTimeout = new Runnable() {
+ public void run() {
+ synchronized (this) {
+ Slog.d(TAG, "screen time out");
+ if (isAbleChangeHDMIMode()) {
+ try {
+ setTemporaryScreenBrightnessSettingOverrideInternal(1);
+ mTimeout = true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ mTimeout = true;
+ }
+ }
+ }
+ }
+ };
+
+ private void LockScreenOff() {
+ Slog.d(TAG, "LockScreenOff" + String.valueOf(lcd_delay_timeout));
+ mHandlerTimeout.postAtTime(mScreenTimeout, SystemClock.uptimeMillis() + 1000
+ * lcd_delay_timeout);
+ }
+
+ private long lcd_delay_timeout = 10;
+ private Handler mHandlerTimeout = new Handler();
+ private boolean mTimeout = false;
// Called from native code.
private void userActivityFromNative(long eventTime, int event, int flags) {
if (DEBUG_SPEW) {
Slog.d(TAG, "userActivityFromNative");
}
+ synchronized (mLock) {
+ if(isAbleChangeHDMIMode()){
+ TurnonScreen();
+ }
+ }
userActivityInternal(eventTime, event, flags, Process.SYSTEM_UID);
}
@
private int getScreenOffTimeoutLocked(int sleepTimeout) {
+ int nosleep;
int timeout = mScreenOffTimeoutSetting;
if (isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) {
timeout = Math.min(timeout, mMaximumScreenOffTimeoutFromDeviceAdmin);
@
if (mUserActivityTimeoutMin) {
timeout = (int)Math.min(timeout, mUserActivityTimeoutOverrideFromCMD);
}
+ nosleep = mScreenOffTimeoutSetting;
+ if(nosleep < 15000) {
+ nosleep = mMaximumScreenOffTimeoutFromDeviceAdmin ;
+ return Math.max(nosleep, mMaximumScreenOffTimeoutFromDeviceAdmin);
+ }
return Math.max(timeout, mMinimumScreenOffTimeoutConfig);
}
2,编辑xml文件
packages/apps/Settings/res/values-zh-rCN/strings.xml
<string name="bluetooth_talkback_bluetooth" msgid="5615463912185280812">"蓝牙"</string>
<!--xiaozheng add -->
<string name="additional_system_update_settings_list_item_title_edongcustom">系统升级</string>
+
+ <string name="hdmi_lcd_timeout">屏幕休眠</string>
</resources>
3,编辑packages/apps/Settings/res_ext/values/mtk_arrays.xml
<item>pnn</item>
</string-array>
<!-- MTK APN Settings end[SKIP COMMENT] -->
+ <string-array name="hdmi_lcd_timeout_entries">
+ <item>10s</item>
+ <item>20s</item>
+ <item>30s</item>
+ <item>Never</item>
+ </string-array>
+ <string-array name="hdmi_lcd_timeout_values" translatable="false">
+ <item>1</item>
+ <item>2</item>
+ <item>3</item>
+ <item>-1</item>
+ </string-array>
</resources>
4,编辑
packages/apps/Settings/res_ext/values/mtk_strings.xml
<string name="aod_summary">Some system information will always be shown in suspend mode</string>
<!-- MTK AOD settings end -->
<string name="hdmi_wfd_off_hdmi_on">Wireless display will be turned off when you turn on HDMI. Do you want to continue?</string>
+ <string name="hdmi_lcd_timeout">Screen Timeout</string>
</resources>
5,packages/apps/Settings/res_ext/xml/hdmi_settings.xml
android:title="@string/hdmi_audio_output"
android:entries="@array/hdmi_audio_output_entries"
android:entryValues="@array/hdmi_audio_output_entry_values" />
+ <ListPreference
+ android:key="hdmi_lcd_timeout"
+ android:title="@string/hdmi_lcd_timeout"
+ android:entries="@array/hdmi_lcd_timeout_entries"
+ android:entryValues="@array/hdmi_lcd_timeout_values"
+ />
</PreferenceScreen>
6,packages/apps/Settings/src/com/mediatek/hdmi/HdmiSettings.java
+import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
+import android.content.ContentResolver;
+import android.content.SharedPreferences;
private Activity mActivity;
private AlertDialog mHDMIExcludeDialog;
+ private static final String KEY_HDMI_LCD ="hdmi_lcd_timeout";
+ private static final int DEF_HDMI_LCD_TIMEOUT_VALUE = 10;
+ private ListPreference mHdmiLcd;
private boolean mRet;
private Context mContext;
@
mAudioOutputPref = (ListPreference) findPreference(KEY_AUDIO_OUTPUT);
mAudioOutputPref.setOnPreferenceChangeListener(this);
-
+ mHdmiLcd = (ListPreference)findPreference(KEY_HDMI_LCD);
+ mHdmiLcd.setOnPreferenceChangeListener(this);
+ ContentResolver resolver = mActivity .getContentResolver();
+ long lcdTimeout = -1;
+ if((lcdTimeout = Settings.System.getLong(resolver, Settings.System.HDMI_LCD_TIMEOUT,
+ DEF_HDMI_LCD_TIMEOUT_VALUE)) > 0)
+ {
+ lcdTimeout/=10;
+ }
+ mHdmiLcd.setValue(String.valueOf(lcdTimeout));
mHdmiManager = IMtkHdmiManager.Stub.asInterface(ServiceManager
.getService(Context.HDMI_SERVICE));
-
+ if (null == mHdmiManager) {
+ finish();
+ return;
+ }
IntentFilter filter = new IntentFilter();
filter.addAction(DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED);
mContext.registerReceiverAsUser(mActionReceiver, UserHandle.ALL, filter, null, null);
@@ -309,6 +334,18 @@ public class HdmiSettings extends SettingsPreferenceFragment implements
Log.i("@M_" + TAG, "updateSelectedAudioOutput audioOutputMode: " + audioOutputMode);
}
+ private void setHdmiLcdTimeout(int value){
+ if(value != -1){
+ value = (value) * 10;
+ }
+ try {
+ Settings.System.putInt(getContentResolver(), Settings.System.HDMI_LCD_TIMEOUT, value);
+ } catch (NumberFormatException e) {
+ Log.e("@M_" + TAG, "could not persist hdmi lcd timeout setting", e);
+ }
+ }
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
Log.d("@M_" + TAG, key + " preference changed");
@@ -344,6 +381,18 @@ public class HdmiSettings extends SettingsPreferenceFragment implements
Log.d("@M_" + TAG, "AudioSystem.setParameters HDMI_channel = " + maxChannel
+ ",which: " + which);
}
+ else if (KEY_HDMI_LCD.equals(key)){
+ SharedPreferences.Editor editor = getActivity().getPreferences(0).edit();
+ try {
+ int value = Integer.parseInt((String) newValue);
+ setHdmiLcdTimeout(value);
+ } catch (NumberFormatException e){
+ Log.e("@M_" + TAG, "onPreferenceChanged hdmi_lcd_timeout setting error");
+ }
+ editor.commit();
+ }
} catch (RemoteException e) {
Log.w("@M_" + TAG, "hdmi manager RemoteException: " + e.getMessage());
}
7,最后一步,没有这步会编译失败:
2778 * hdmi lcd timeout
2779 * @hide
2780 */
2781 public static final String HDMI_LCD_TIMEOUT = "hdmi_lcd_timeout";
上一篇: Docker——持久化(Volume)
下一篇: Docker数据的持久化
推荐阅读
-
关于Mysql唯一索引的操作方法(添加删除)
-
关于在eclipse中添加windowbuilder插件的问题
-
关于vscode 默认添加python项目的源目录路径到执行环境的问题
-
关于前端ajax请求url为何添加一个随机数
-
关于vscode 默认添加python项目的源目录路径到执行环境的问题
-
关于 注册页面浏览器自动添加账号密码问题?
-
关于如何修改一张表中所有行与选定字段的同sql多行语句的添加方法
-
Python关于动态语言的学习(动态添加方法)
-
关于python scrapy中添加cookie踩坑记录
-
关于在php.ini中添加extension=php_mysqli.dll指令的说明