Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
huangzhicong
/
SmartCanteen
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1dee9de5
authored
Jul 28, 2020
by
pye52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wifi及shell指令执行失败后不再重试,并且都返回Resul.Success
parent
a41816e3
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
43 additions
and
24 deletions
+43
-24
app/build.gradle
+7
-7
app/src/main/AndroidManifest.xml
+1
-0
app/src/main/java/com/bgycc/smartcanteen/command/CommandHelper.java
+15
-5
app/src/main/java/com/bgycc/smartcanteen/command/ShellCommandWorker.java
+1
-1
app/src/main/java/com/bgycc/smartcanteen/command/WifiConfigCommandWorker.java
+4
-4
app/src/main/java/com/bgycc/smartcanteen/utils/NetworkUtils.java
+6
-3
build.gradle
+1
-1
daemon/build.gradle
+8
-3
No files found.
app/build.gradle
View file @
1dee9de5
apply
plugin:
'com.android.application'
android
{
compileSdkVersion
29
buildToolsVersion
"
29.0.3
"
compileSdkVersion
30
buildToolsVersion
"
30.0.1
"
defaultConfig
{
applicationId
"com.bgycc.smartcanteen"
minSdkVersion
22
targetSdkVersion
29
versionCode
14
0
versionName
"1.4.
0
"
targetSdkVersion
30
versionCode
14
1
versionName
"1.4.
1
"
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
ndk
{
abiFilters
"armeabi"
,
"armeabi-v7a"
,
"x86"
,
"mips"
...
...
@@ -109,7 +109,7 @@ dependencies {
def
lifecycle_version
=
"2.2.0"
implementation
"androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation
"androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
def
work_version
=
"2.
3.4
"
def
work_version
=
"2.
4.0
"
implementation
"androidx.work:work-runtime:$work_version"
implementation
'androidx.appcompat:appcompat:1.1.0'
implementation
'androidx.constraintlayout:constraintlayout:1.1.3'
...
...
@@ -121,7 +121,7 @@ dependencies {
def
okhttp_version
=
"4.7.2"
implementation
"com.squareup.okhttp3:okhttp:$okhttp_version"
implementation
"com.squareup.okhttp3:logging-interceptor:$okhttp_version"
def
retrofit_version
=
"2.8.1"
def
retrofit_version
=
'2.9.0'
implementation
"com.squareup.retrofit2:retrofit:$retrofit_version"
implementation
"com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation
"com.squareup.retrofit2:converter-scalars:$retrofit_version"
...
...
app/src/main/AndroidManifest.xml
View file @
1dee9de5
...
...
@@ -3,6 +3,7 @@
xmlns:tools=
"http://schemas.android.com/tools"
package=
"com.bgycc.smartcanteen"
>
<uses-permission
android:name=
"android.permission.ACCESS_FINE_LOCATION"
/>
<uses-permission
android:name=
"android.permission.RECEIVE_BOOT_COMPLETED"
/>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.WRITE_SETTINGS"
/>
...
...
app/src/main/java/com/bgycc/smartcanteen/command/CommandHelper.java
View file @
1dee9de5
...
...
@@ -4,6 +4,7 @@ import androidx.work.BackoffPolicy;
import
androidx.work.Data
;
import
androidx.work.ListenableWorker
;
import
androidx.work.OneTimeWorkRequest
;
import
androidx.work.WorkRequest
;
import
com.bgycc.smartcanteen.entity.Command
;
import
com.google.gson.Gson
;
...
...
@@ -66,6 +67,7 @@ public class CommandHelper {
public
static
OneTimeWorkRequest
createWorker
(
Gson
gson
,
Command
command
,
String
deviceSN
)
{
OneTimeWorkRequest
worker
=
null
;
Class
<?
extends
ListenableWorker
>
workerClass
=
null
;
boolean
needRetry
=
true
;
switch
(
command
.
getAction
())
{
case
LOG_UPLOAD:
workerClass
=
LogCommandWorker
.
class
;
...
...
@@ -75,22 +77,30 @@ public class CommandHelper {
break
;
case
CONFIG_WIFI:
workerClass
=
WifiConfigCommandWorker
.
class
;
// wifi配置任务不应该重试
needRetry
=
false
;
break
;
case
EXEC_SHELL:
workerClass
=
ShellCommandWorker
.
class
;
// shell任务也不应该重试
needRetry
=
false
;
break
;
}
if
(
workerClass
!=
null
)
{
Data
inputData
=
CommandWorker
.
createBaseData
(
gson
.
toJson
(
command
),
deviceSN
);
worker
=
new
OneTimeWorkRequest
.
Builder
(
workerClass
)
WorkRequest
.
Builder
<
OneTimeWorkRequest
.
Builder
,
OneTimeWorkRequest
>
builder
;
builder
=
new
OneTimeWorkRequest
.
Builder
(
workerClass
)
.
setInputData
(
inputData
)
.
addTag
(
command
.
getAction
())
.
setBackoffCriteria
(
.
addTag
(
command
.
getAction
());
if
(
needRetry
)
{
worker
=
builder
.
setBackoffCriteria
(
BackoffPolicy
.
LINEAR
,
OneTimeWorkRequest
.
MIN_BACKOFF_MILLIS
,
TimeUnit
.
MILLISECONDS
)
TimeUnit
.
MILLISECONDS
)
.
build
();
}
else
{
worker
=
builder
.
build
();
}
}
return
worker
;
}
...
...
app/src/main/java/com/bgycc/smartcanteen/command/ShellCommandWorker.java
View file @
1dee9de5
...
...
@@ -35,7 +35,7 @@ public class ShellCommandWorker extends CommandWorker {
@Override
public
Result
doWork
()
{
if
(
commandShell
.
getData
()
==
null
)
{
return
failed
(
"shell指令非法"
);
return
success
(
"shell指令非法"
);
}
CommandShell
.
CommandShellData
data
=
commandShell
.
getData
();
byte
[]
decryptAES
=
EncryptUtils
.
decryptHexStringAES
(
data
.
getShell
(),
KEY
.
getBytes
(),
TRANSFORMATION
,
IV
.
getBytes
());
...
...
app/src/main/java/com/bgycc/smartcanteen/command/WifiConfigCommandWorker.java
View file @
1dee9de5
...
...
@@ -26,7 +26,7 @@ public class WifiConfigCommandWorker extends CommandWorker {
public
Result
doWork
()
{
CommandWifiConfig
.
CommandWifiConfigData
data
=
wifiConfig
.
getData
();
if
(
data
==
null
)
{
return
failed
();
return
success
();
}
if
(!
NetworkUtils
.
isWifiEnabled
())
{
...
...
@@ -39,7 +39,7 @@ public class WifiConfigCommandWorker extends CommandWorker {
Thread
.
sleep
(
DEFAULT_DELAY
);
}
catch
(
Exception
ignored
)
{
}
return
failed
(
failedMessage
);
return
success
(
failedMessage
);
}
}
...
...
@@ -73,8 +73,8 @@ public class WifiConfigCommandWorker extends CommandWorker {
}
}
catch
(
Exception
e
)
{
LogUtils
.
e
(
TAG
,
"链接wifi过程出错: "
+
e
.
getMessage
(),
e
);
return
failed
(
e
.
getMessage
());
return
success
(
e
.
getMessage
());
}
return
failed
(
"无法连接Wifi"
);
return
success
(
"无法连接Wifi"
);
}
}
app/src/main/java/com/bgycc/smartcanteen/utils/NetworkUtils.java
View file @
1dee9de5
package
com
.
bgycc
.
smartcanteen
.
utils
;
import
android.annotation.SuppressLint
;
import
android.content.Context
;
import
android.net.ConnectivityManager
;
import
android.net.LinkProperties
;
...
...
@@ -196,6 +197,7 @@ public class NetworkUtils {
}
}
// 未做版本适配工作,目前使用机型都为6.0
public
static
void
switchNetwork
(
ConnectivityManager
.
NetworkCallback
callback
)
{
if
(
lastTryNetwork
==
NETWORK_ETHERNET
)
{
lastTryNetwork
=
NETWORK_WIFI
;
...
...
@@ -244,13 +246,14 @@ public class NetworkUtils {
return
connect
(
createWifiConfiguration
(
ssid
,
null
,
pwd
,
null
));
}
@SuppressLint
(
"MissingPermission"
)
public
static
boolean
connect
(
WifiConfiguration
config
)
{
int
netId
=
wifiManager
.
addNetwork
(
config
);
if
(!
wifiManager
.
enableNetwork
(
net
Id
,
true
))
{
wifiManager
.
addNetwork
(
config
);
if
(!
wifiManager
.
enableNetwork
(
config
.
network
Id
,
true
))
{
return
false
;
}
wifiManager
.
reconnect
();
return
tru
e
;
return
fals
e
;
}
public
static
boolean
disconnect
(
int
netId
)
{
...
...
build.gradle
View file @
1dee9de5
...
...
@@ -9,7 +9,7 @@ buildscript {
jcenter
()
}
dependencies
{
classpath
'com.android.tools.build:gradle:4.0.
0
'
classpath
'com.android.tools.build:gradle:4.0.
1
'
}
}
...
...
daemon/build.gradle
View file @
1dee9de5
...
...
@@ -2,13 +2,13 @@ apply plugin: 'com.android.application'
def
signed
=
"Daemon.apk"
android
{
compileSdkVersion
29
buildToolsVersion
"
29.0.3
"
compileSdkVersion
30
buildToolsVersion
"
30.0.1
"
defaultConfig
{
applicationId
"com.bgycc.smartcanteen.daemon"
minSdkVersion
22
targetSdkVersion
29
targetSdkVersion
30
versionCode
rootProject
.
ext
.
daemon_verson_code
versionName
rootProject
.
ext
.
daemon_verson_name
...
...
@@ -96,9 +96,14 @@ private String findAppAssetsDir() {
dependencies
{
implementation
fileTree
(
dir:
'libs'
,
include:
[
'*.jar'
])
def
lifecycle_version
=
"2.2.0"
implementation
"androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation
'androidx.appcompat:appcompat:1.1.0'
testImplementation
'junit:junit:4.13'
androidTestImplementation
'androidx.test.ext:junit:1.1.1'
androidTestImplementation
'androidx.test.espresso:espresso-core:3.2.0'
implementation
'com.blankj:utilcodex:1.29.0'
}
repositories
{
mavenCentral
()
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment