File: authorityservice.cpp

package info (click to toggle)
ukui-settings-daemon 4.0.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,412 kB
  • sloc: cpp: 39,120; ansic: 3,240; xml: 1,570; sh: 88; makefile: 4
file content (151 lines) | stat: -rw-r--r-- 3,441 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
 * -*- coding: utf-8 -*-
 *
 * Copyright (C) 2023 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <QDebug>
#include <QProcess>
#include "authorityservice.h"
#include "brightnesshelper.h"
extern "C" {

#include <linux/types.h>
#include <fcntl.h>
#include <unistd.h>
}

AuthorityService::AuthorityService(QObject *parent) :
    QObject(parent)
{

}

int AuthorityService::isTrialMode()
{
    static int ret = 0xff;
    char *pAck = NULL;
    char CmdAck[256] = "";
    FILE * pPipe;

    if (ret != 0xff) {
        return ret;
    }

    pPipe = popen("cat /proc/cmdline","r");

    if (pPipe) {
        pAck = fgets(CmdAck, sizeof(CmdAck)-1, pPipe);
        if (strstr(CmdAck, "boot=casper")) {
            ret = true;
        } else{
            ret = false;
        }

        pclose(pPipe);
    } else {
        return false;
    }

    return ret;
}

int AuthorityService::setDynamicBrightness(bool state)
{
    int ret = false;
    char CmdAck[256] = "";
    FILE * pPipe;

    if (state) {
        pPipe = popen("gpioset gpiochip0 179=1","r");
    } else {
        pPipe = popen("gpioset gpiochip0 179=0","r");
    }
    //todo 需要读取设置
    if (pPipe) {
        fgets(CmdAck, sizeof(CmdAck)-1, pPipe);
        if (strnlen(CmdAck, 255) == 0) {
            ret = true;//有返回数据就是异常
        }

        pclose(pPipe);
    }

    return ret;
}

QString AuthorityService::popenCommand(QString cmd)
{
    char *pAck = NULL;
    char CmdAck[1024];
    FILE * pPipe;
    QString ret = "";
    //ef列出所有进程,|grep %s | 仅显示含%s的进程, |grep -v grep过滤掉含grep的进程(本条指令),|wc -l 查看行数

    pPipe = popen(cmd.toLatin1().data(),"r");
    if (pPipe) {
        pAck = fgets(CmdAck,sizeof(CmdAck),pPipe);
        ret = QString(CmdAck);
        pclose(pPipe);
    }

    return ret;
}

int AuthorityService::nightModeCanBeSet()
{
    static int ret = 0xff;
    QString VGAInfo = "";
    if (ret != 0xff) {
        return ret;
    }

    VGAInfo = popenCommand("lspci |grep VGA");
    qDebug()<<VGAInfo;

    if (VGAInfo != "") {
        ret = 1;
        Q_FOREACH(QString vga, m_NightModeBlackList) {
            if (VGAInfo.contains(vga)) {
                ret = 0;
                break;
            }
        }
    }
    return ret;
}


int AuthorityService::startColorService()
{
    QString cmd = QString("systemctl start geoclue");
    system(cmd.toLatin1().data());

    cmd = QString("systemctl start colord");
    system(cmd.toLatin1().data());
    return 0;
}


int AuthorityService::stopColorService()
{
    QString cmd = QString("systemctl stop geoclue");
    system(cmd.toLatin1().data());

    cmd = QString("systemctl stop colord");
    system(cmd.toLatin1().data());
    return 0;
}