-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuws.cpp
More file actions
156 lines (137 loc) · 4.18 KB
/
uws.cpp
File metadata and controls
156 lines (137 loc) · 4.18 KB
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
152
153
154
155
156
#include "uws.h"
#include <QProcess>
extern "C"
JNIEXPORT void JNICALL
Java_com_uwillno_uws_SZK_signal(JNIEnv *env,jobject obj,jstring info){
emit UWS::instance()->info(env->GetStringUTFChars(info,0));
}
extern "C"
JNIEXPORT void JNICALL
Java_com_uwillno_uws_Shell_signal(JNIEnv *env,jobject obj,jstring info){
emit UWS::instance()->info(env->GetStringUTFChars(info,0));
}
// UWS::UWS(QObject *parent)
// : QObject{parent}
// {}
void UWS::execByShizuku(QString command)
{
emit info(tr("通过shizuku执行中"));
emit info(szk.callMethod<jstring>("execCommand",command).toString());
}
void UWS::execByRoot(QString command)
{
(void)QtConcurrent::run(
[&]{
Shell shell;
String c = QJniObject::fromString(command);
String result = shell.callStaticMethod<String>("exec",c);
emit this->info(result.toString());
}
);
}
void UWS::execByRoot(QString command, QQuickItem *item)
{
if(item){
if(!itemList.contains(item)) {
// qDebug() << itemList.length();
itemList << item;
auto future =QtConcurrent::run(
[&]{
Shell shell;
String c = QJniObject::fromString(command);
String result = shell.callStaticMethod<String>("exec",c);
return result.toString();
});/*.then([&](QString res){
QMetaObject::invokeMethod(QApplication::instance(), [=]{
if(item){
itemList.removeOne(item);
item->setProperty("text",res);
}
}, Qt::QueuedConnection);
});*/
QFutureWatcher<QString> *watcher = new QFutureWatcher<QString>(this);
watcher->setFuture(future);
QObject::connect(watcher,&QFutureWatcher<QString>::finished,this,[=]{
if(item){
itemList.removeOne(item);
item->setProperty("text",watcher->result());
}
watcher->deleteLater();
// watcher->result();
});
}
}
}
void UWS::test(QObject *object)
{
// qDebug() << object.;
object->setProperty("text","asdadsasdasd");
}
void UWS::setStoragePermission()
{
// if(!hasStoragePermission()){
String filepermit = Settings::getStaticField<String>("ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION");
String pkgName = QJniObject::fromString("package:com.uwillno.uws");
Uri parseUri = Uri::callStaticMethod<Uri>("parse",pkgName);
Intent intent(filepermit,parseUri);
Context context = QNativeInterface::QAndroidApplication::context();
context.callMethod<void>("startActivity",intent);
// }
}
bool UWS::hasStoragePermission()
{
return Environment::callStaticMethod<jboolean>("isExternalStorageManager");
}
QProcess::ProcessState UWS::pState() const
{
return m_pState;
}
void UWS::setPState(const QProcess::ProcessState &newPState)
{
if (m_pState == newPState)
return;
m_pState = newPState;
emit pStateChanged();
}
// void UWS::setItemText(QString text, QQuickItem *item)
// {
// // item.set
// if(item)
// item->setProperty("text",text);
// }
void UWS::execByProcess(QString command)
{
if(p.state() == QProcess::Running){
p.write((command + "\n").toUtf8());
}else {
emit processReply(tr("程序还未启动"));
}
}
void UWS::toggleProcess(QString program)
{
if(p.state() == QProcess::Running || p.state() == QProcess::Starting){
p.terminate();
p.kill();
}else {
p.start(program);
}
}
void UWS::initShizuku()
{
szk.callMethod<void>("initShizuku");
}
// void UWS::initProcess()
// {
// // p.start("su");
// // emit info("尝试获取root权限");
// // // p.waitForFinished();
// // p.start("whoami");
// // p.startCommand()
// // // p.waitForFinished();
// // QString output = p.readAllStandardOutput().trimmed();
// // if (output == "root") {
// // emit info("已获取root权限");
// // } else {
// // emit info("未取得root权限");
// // }
// }