1 /* SPDX-License-Identifier: GPL-2.0-only */
6 #include "NvramToolCli.h"
9 static constexpr char s_sudoProg
[] = "/usr/bin/pkexec";
10 static constexpr char s_nvramToolProg
[] = "/usr/sbin/nvramtool";
14 QMap
<QString
, QString
> NvramToolCli::readParameters(QString
*error
) {
15 return QMap
<QString
,QString
>({
16 {"boot_option","Normal"},
17 {"reboot_counter","0x0"},
18 {"debug_level","Spew"},
20 {"power_profile","Performance"},
21 {"wireless","Enable"},
23 {"microphone","Enable"},
24 {"legacy_8254_timer","Enable"},
25 {"usb_always_on","Disable"},
26 {"kbl_timeout","Never"},
27 {"fn_ctrl_swap","Enable"},
28 {"max_charge","100%"},
29 {"power_on_after_fail","Disable"},
30 {"fn_lock_state","0x2"},
31 {"trackpad_state","0x40"},
32 {"kbl_brightness","0xc4"},
37 QStringList
NvramToolCli::readOptions(const QString
¶meter
, QString
*error
){
38 return (parameter
=="power_profile")?
40 "Power Saver","Balanced","Performance"
46 QMap
<QString
, QString
> NvramToolCli::readParameters(QString
*error
)
48 QProcess nvramtoolProcess
;
49 nvramtoolProcess
.start(s_sudoProg
, {s_nvramToolProg
, "-a"});
51 nvramtoolProcess
.waitForFinished();
53 if(error
) *error
= nvramtoolProcess
.readAllStandardError();
55 if(nvramtoolProcess
.exitCode() != 0){
59 return Util::parseParameters(nvramtoolProcess
);
62 QStringList
NvramToolCli::readOptions(const QString
¶meter
, QString
*error
)
66 QProcess nvramtoolProcess
;
67 nvramtoolProcess
.start(s_sudoProg
, {s_nvramToolProg
, "-e", parameter
});
68 nvramtoolProcess
.waitForFinished();
70 if(error
) *error
= nvramtoolProcess
.readAllStandardError();
72 while (nvramtoolProcess
.canReadLine()) {
73 result
.append(nvramtoolProcess
.readLine().trimmed());
80 bool NvramToolCli::writeParameters(const QMap
<QString
, QString
> ¶meters
, QString
*error
)
84 QTextStream
outStream(stdout
);
86 QProcess nvramtoolProcess
;
87 nvramtoolProcess
.start(s_sudoProg
, {s_nvramToolProg
, "-i"});
88 nvramtoolProcess
.waitForStarted();
89 QTextStream
outStream(&nvramtoolProcess
);
91 for(auto it
= parameters
.begin(); it
!= parameters
.end(); ++it
){
92 outStream
<< it
.key() << " = " << it
.value() << "\n";
99 nvramtoolProcess
.closeWriteChannel();
100 nvramtoolProcess
.waitForFinished();
103 *error
= nvramtoolProcess
.readAllStandardError();
106 return nvramtoolProcess
.exitCode()==0;
112 QString
NvramToolCli::version()
114 QProcess nvramtoolProcess
;
115 nvramtoolProcess
.start(s_nvramToolProg
, {"-v"});
117 nvramtoolProcess
.waitForFinished();
119 return nvramtoolProcess
.readAll();