Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
apk_product
/
IPTVLaunchTest
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
0d19e527
...
0d19e52783a0764ff4babf0d5c14f8571b77b4f0
authored
2024-10-14 09:07:50 +0800
by
胡波
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
新增烽火盒子stb协议
1 parent
42a1199e
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
2068 additions
and
15 deletions
.idea/deploymentTargetSelector.xml
app/build.gradle
app/src/main/AndroidManifest.xml
app/src/main/java/com/topdraw/iptvlaunchertest/MainActivity.java
app/src/main/java/com/topdraw/iptvlaunchertest/TestConfig.java
app/src/main/java/com/topdraw/iptvlaunchertest/fh/FHActivityUtil.java
app/src/main/java/com/topdraw/iptvlaunchertest/fh/FHDownLoadManager.java
app/src/main/java/com/topdraw/iptvlaunchertest/fh/FHFileTool.java
app/src/main/java/com/topdraw/iptvlaunchertest/fh/FHJsonUtil.java
app/src/main/java/com/topdraw/iptvlaunchertest/fh/IDownLoadListener.java
app/src/main/java/com/topdraw/iptvlaunchertest/fh/IProgressDialogListener.java
app/src/main/java/com/topdraw/iptvlaunchertest/fh/STBAppManager.java
app/src/main/java/com/topdraw/iptvlaunchertest/fh/Util.java
app/src/main/java/com/topdraw/iptvlaunchertest/ApkTool.java → app/src/main/java/com/topdraw/iptvlaunchertest/sky/ApkTool.java
app/src/main/java/com/topdraw/iptvlaunchertest/ApkTool28.java → app/src/main/java/com/topdraw/iptvlaunchertest/sky/ApkTool28.java
app/src/main/java/com/topdraw/iptvlaunchertest/CloseUtils.java → app/src/main/java/com/topdraw/iptvlaunchertest/sky/CloseUtils.java
app/src/main/java/com/topdraw/iptvlaunchertest/HttpDownloader.java → app/src/main/java/com/topdraw/iptvlaunchertest/sky/HttpDownloader.java
app/src/main/java/com/topdraw/iptvlaunchertest/InstallResultReceiver.java → app/src/main/java/com/topdraw/iptvlaunchertest/sky/InstallResultReceiver.java
app/src/main/java/com/topdraw/iptvlaunchertest/STBAppManager.java → app/src/main/java/com/topdraw/iptvlaunchertest/sky/STBAppManager.java
app/src/main/java/com/topdraw/iptvlaunchertest/TaskExecutor.java → app/src/main/java/com/topdraw/iptvlaunchertest/sky/TaskExecutor.java
gradle/libs.versions.toml
.idea/deploymentTargetSelector.xml
View file @
0d19e52
...
...
@@ -4,6 +4,14 @@
<selectionStates>
<SelectionState
runConfigName=
"app"
>
<option
name=
"selectionMode"
value=
"DROPDOWN"
/>
<DropdownSelection
timestamp=
"2024-10-12T05:40:06.328823Z"
>
<Target
type=
"DEFAULT_BOOT"
>
<handle>
<DeviceId
pluginId=
"Default"
identifier=
"serial=0123456789;connection=725ee2fc"
/>
</handle>
</Target>
</DropdownSelection>
<DialogSelection
/>
</SelectionState>
</selectionStates>
</component>
...
...
app/build.gradle
View file @
0d19e52
...
...
@@ -8,7 +8,7 @@ android {
defaultConfig
{
applicationId
"com.topdraw.iptvlaunchertest"
minSdk
21
minSdk
19
targetSdk
34
versionCode
1
versionName
"1.0"
...
...
@@ -30,6 +30,7 @@ android {
buildFeatures
{
buildConfig
true
}
flavorDimensions
'APP'
productFlavors
{
chongqing
{
...
...
app/src/main/AndroidManifest.xml
View file @
0d19e52
...
...
@@ -4,7 +4,9 @@
<uses-permission
android:name=
"android.permission.INSTALL_PACKAGES"
/>
<uses-permission
android:name=
"android.permission.DELETE_PACKAGES"
/>
<uses-permission
android:name=
"android.permission.INTERACT_ACROSS_USERS"
/>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.KILL_BACKGROUND_PROCESSES"
/>
<uses-permission
android:name=
"android.permission.READ_EXTERNAL_STORAGE"
/>
<uses-permission
android:name=
"android.permission.WRITE_EXTERNAL_STORAGE"
/>
...
...
app/src/main/java/com/topdraw/iptvlaunchertest/MainActivity.java
View file @
0d19e52
package
com
.
topdraw
.
iptvlaunchertest
;
import
android.Manifest
;
import
android.content.pm.PermissionInfo
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.webkit.WebSettings
;
...
...
@@ -13,11 +12,9 @@ import androidx.core.graphics.Insets;
import
androidx.core.view.ViewCompat
;
import
androidx.core.view.WindowInsetsCompat
;
import
java.security.acl.Permission
;
public
class
MainActivity
extends
AppCompatActivity
{
private
WebView
webView
;
private
STBAppManager
stbAppManager
;
private
String
[]
permissions
=
new
String
[]{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
,
...
...
@@ -52,8 +49,12 @@ public class MainActivity extends AppCompatActivity {
settings
.
setAllowUniversalAccessFromFileURLs
(
true
);
}
//注册接口
private
void
initObject
(){
this
.
stbAppManager
=
new
STBAppManager
(
this
);
webView
.
addJavascriptInterface
(
this
.
stbAppManager
,
"STBAppManager"
);
if
(
TestConfig
.
testDist
==
TestConfig
.
Skyworth
){
webView
.
addJavascriptInterface
(
new
com
.
topdraw
.
iptvlaunchertest
.
sky
.
STBAppManager
(
this
),
"STBAppManager"
);
}
else
if
(
TestConfig
.
testDist
==
TestConfig
.
FiberHome
){
webView
.
addJavascriptInterface
(
new
com
.
topdraw
.
iptvlaunchertest
.
fh
.
STBAppManager
(
this
),
"STBAppManager"
);
}
}
}
\ No newline at end of file
...
...
app/src/main/java/com/topdraw/iptvlaunchertest/TestConfig.java
0 → 100644
View file @
0d19e52
package
com
.
topdraw
.
iptvlaunchertest
;
public
class
TestConfig
{
//创维盒子
public
static
final
int
Skyworth
=
0
;
//烽火盒子
public
static
final
int
FiberHome
=
1
;
public
static
int
testDist
=
FiberHome
;
}
app/src/main/java/com/topdraw/iptvlaunchertest/fh/FHActivityUtil.java
0 → 100644
View file @
0d19e52
package
com
.
topdraw
.
iptvlaunchertest
.
fh
;
import
android.content.Context
;
import
android.content.pm.PackageInfo
;
import
android.text.TextUtils
;
import
android.util.Log
;
public
class
FHActivityUtil
{
public
static
String
parseAppFile
(
Context
context
,
String
appName
)
{
String
pkgName
=
null
;
Log
.
d
(
"FHActivityUtil"
,
"parseAppFile appName = "
+
appName
);
if
((
TextUtils
.
isEmpty
(
appName
))
||
context
==
null
)
{
return
null
;
}
try
{
PackageInfo
pkgInfo
=
context
.
getPackageManager
().
getPackageArchiveInfo
(
appName
,
0
);
if
(
pkgInfo
!=
null
)
{
pkgName
=
pkgInfo
.
packageName
;
}
Log
.
d
(
"FHActivityUtil"
,
"parseAppFile pkgName = "
+
pkgName
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
pkgName
;
}
}
app/src/main/java/com/topdraw/iptvlaunchertest/fh/FHDownLoadManager.java
0 → 100644
View file @
0d19e52
package
com
.
topdraw
.
iptvlaunchertest
.
fh
;
import
android.content.Context
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.HandlerThread
;
import
android.os.Message
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
com.topdraw.iptvlaunchertest.App
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.SocketTimeoutException
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Map
;
public
class
FHDownLoadManager
{
private
static
final
int
MSG_BASE
=
7000
;
private
static
final
int
MSG_FHIPTV_DLOAD_TASK_CANCEL
=
7003
;
private
static
final
int
MSG_FHIPTV_DLOAD_TASK_COPYFILE
=
7005
;
private
static
final
int
MSG_FHIPTV_DLOAD_TASK_START
=
7001
;
private
static
final
int
MSG_FHIPTV_DLOAD_TASK_TIMEOUT
=
7004
;
private
static
final
String
TAG
=
"FHDownLoadManager"
;
private
static
final
int
TIMEOUT_VAR
=
5000
;
private
static
FHDownLoadManager
mInstance
=
null
;
private
Context
mContext
=
null
;
private
ArrayList
<
IDownLoadListener
>
mDownloadObserversList
;
private
IProgressDialogListener
mProgressDialogObserver
=
null
;
private
HandlerThread
mDLoadHandleThread
=
null
;
private
Handler
mEventHandle
=
null
;
private
long
mTaskCount
=
0
;
private
String
mCookie
=
null
;
/* loaded from: classes-dex2jar.jar:com/fiberhome/iptv/common/FHDownLoadManager$HttpResponseInfo.class */
public
static
class
HttpResponseInfo
{
public
static
byte
[]
data
=
new
byte
[
0
];
public
static
URL
url
=
null
;
public
HttpResponseInfo
(
FHDownLoadManager
fHDownLoadManager
)
{
}
}
private
FHDownLoadManager
()
{
this
.
mDownloadObserversList
=
null
;
this
.
mContext
=
App
.
getInstance
();
this
.
mDownloadObserversList
=
new
ArrayList
<>();
initEventHandleThread
();
}
public
static
boolean
checkURLConnStatus
(
String
str
,
int
i
)
{
boolean
z
;
HttpURLConnection
httpURLConnection
=
null
;
HttpURLConnection
httpURLConnection2
=
null
;
HttpURLConnection
httpURLConnection3
=
null
;
Log
.
d
(
TAG
,
"checkURLConnStatus() URL = "
+
str
+
", waitMilliSecond= "
+
i
);
if
(
str
.
startsWith
(
"file://"
))
{
int
indexOf
=
str
.
indexOf
(
63
);
int
length
=
str
.
length
();
if
(
indexOf
>
0
)
{
length
=
indexOf
;
}
z
=
new
File
(
str
.
substring
(
8
,
length
)).
exists
();
Log
.
d
(
TAG
,
"checkURLConnStatus() files exists = "
+
z
);
}
else
{
try
{
try
{
try
{
HttpURLConnection
httpURLConnection4
=
(
HttpURLConnection
)
new
URL
(
str
).
openConnection
();
httpURLConnection4
.
setUseCaches
(
false
);
httpURLConnection4
.
setInstanceFollowRedirects
(
true
);
httpURLConnection4
.
setConnectTimeout
(
i
);
httpURLConnection4
.
setReadTimeout
(
i
);
httpURLConnection4
.
connect
();
int
responseCode
=
httpURLConnection4
.
getResponseCode
();
httpURLConnection3
=
httpURLConnection4
;
httpURLConnection
=
httpURLConnection4
;
httpURLConnection2
=
httpURLConnection4
;
Log
.
d
(
TAG
,
"checkURLConnStatus() response code = "
+
responseCode
);
boolean
z2
=
false
;
if
(
responseCode
>=
100
)
{
z2
=
false
;
if
(
responseCode
<
400
)
{
z2
=
true
;
}
}
z
=
z2
;
if
(
httpURLConnection4
!=
null
)
{
httpURLConnection4
.
disconnect
();
z
=
z2
;
}
}
catch
(
SocketTimeoutException
e
)
{
httpURLConnection2
=
httpURLConnection3
;
e
.
printStackTrace
();
z
=
false
;
if
(
httpURLConnection3
!=
null
)
{
httpURLConnection3
.
disconnect
();
z
=
false
;
}
}
}
catch
(
Exception
e2
)
{
e2
.
printStackTrace
();
httpURLConnection2
=
httpURLConnection
;
sleepTime
(
i
);
z
=
false
;
if
(
httpURLConnection
!=
null
)
{
httpURLConnection
.
disconnect
();
z
=
false
;
}
}
}
catch
(
Throwable
th
)
{
if
(
httpURLConnection2
!=
null
)
{
httpURLConnection2
.
disconnect
();
}
throw
th
;
}
}
return
z
;
}
private
boolean
copyFile
(
String
str
,
String
str2
,
boolean
z
)
{
FileInputStream
fileInputStream
;
Throwable
th
;
boolean
z2
=
false
;
try
{
FileInputStream
fileInputStream2
=
null
;
FileOutputStream
fileOutputStream
=
null
;
FileOutputStream
fileOutputStream2
=
null
;
Log
.
d
(
TAG
,
"copyFile srcPath="
+
str
+
", dstPath="
+
str2
);
try
{
File
file
=
new
File
(
str
);
String
str3
=
str2
+
".tmp"
;
File
file2
=
new
File
(
str3
);
if
(
str
!=
null
&&
str
.
equals
(
str2
))
{
Log
.
e
(
TAG
,
"ignore copyFile, src file and dst file is same."
);
try
{
if
(
0
!=
0
)
{
throw
new
NullPointerException
();
}
z2
=
true
;
if
(
0
!=
0
)
{
throw
new
NullPointerException
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
z2
=
true
;
}
}
else
if
(!
file
.
exists
())
{
Log
.
e
(
TAG
,
"copyFile failed, src file is not existed, srcPath="
+
str
);
try
{
if
(
0
!=
0
)
{
throw
new
NullPointerException
();
}
z2
=
false
;
if
(
0
!=
0
)
{
throw
new
NullPointerException
();
}
}
catch
(
Exception
e2
)
{
e2
.
printStackTrace
();
z2
=
false
;
}
}
else
{
if
(
file2
.
exists
()
&&
!
file2
.
delete
())
{
Log
.
e
(
TAG
,
"delete temp file failed."
);
}
fileInputStream2
=
new
FileInputStream
(
file
);
try
{
FileOutputStream
fileOutputStream3
=
new
FileOutputStream
(
file2
);
try
{
byte
[]
bArr
=
new
byte
[
512
];
while
(
true
)
{
int
read
=
fileInputStream2
.
read
(
bArr
);
if
(
read
<=
0
)
{
break
;
}
fileOutputStream3
.
write
(
bArr
,
0
,
read
);
}
FHFileTool
.
deleteFile
(
str2
);
FHFileTool
.
renameFile
(
str3
,
str2
,
z
);
z2
=
true
;
if
(
fileInputStream2
!=
null
)
{
try
{
fileInputStream2
.
close
();
}
catch
(
Exception
e3
)
{
e3
.
printStackTrace
();
}
}
if
(
fileOutputStream3
!=
null
)
{
fileOutputStream3
.
close
();
}
}
catch
(
Exception
e
)
{
fileOutputStream2
=
fileOutputStream3
;
e
.
printStackTrace
();
if
(
fileInputStream2
!=
null
)
{
try
{
fileInputStream2
.
close
();
}
catch
(
Exception
e5
)
{
e5
.
printStackTrace
();
z2
=
false
;
}
}
z2
=
false
;
if
(
fileOutputStream2
!=
null
)
{
fileOutputStream2
.
close
();
z2
=
false
;
}
return
z2
;
}
catch
(
Throwable
th2
)
{
th
=
th2
;
fileOutputStream
=
fileOutputStream3
;
fileInputStream
=
fileInputStream2
;
if
(
fileInputStream
!=
null
)
{
try
{
fileInputStream
.
close
();
}
catch
(
Exception
e6
)
{
e6
.
printStackTrace
();
throw
th
;
}
}
if
(
fileOutputStream
!=
null
)
{
fileOutputStream
.
close
();
}
throw
th
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
catch
(
Throwable
th3
)
{
th
=
th3
;
fileInputStream
=
fileInputStream2
;
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
z2
;
}
catch
(
Throwable
th4
)
{
th
=
th4
;
}
return
z2
;
}
private
void
dialogProgressChange
(
long
j
)
{
if
(
this
.
mProgressDialogObserver
!=
null
)
{
this
.
mProgressDialogObserver
.
onDialogProgressChange
(
j
);
}
}
private
void
dismissProgressDialog
()
{
Log
.
d
(
TAG
,
"dismissProgressDialog() function in."
);
if
(
this
.
mProgressDialogObserver
!=
null
)
{
this
.
mProgressDialogObserver
.
onDismissProgressDialog
();
}
}
public
void
downloadTaskCopyFile
(
Bundle
bundle
)
{
String
string
=
bundle
.
getString
(
"path_src"
);
String
string2
=
bundle
.
getString
(
"path_dst"
);
long
j
=
bundle
.
getLong
(
"id"
);
String
string3
=
bundle
.
getString
(
"md5"
);
boolean
z
=
bundle
.
getBoolean
(
"owner_only"
);
if
(
new
File
(
string2
).
exists
()
&&
FHFileTool
.
compareMD5
(
FHFileTool
.
getFileMD5
(
string2
),
string3
))
{
Log
.
d
(
TAG
,
"ignore copy file task, file is exist and same, taskid= "
+
j
);
}
else
if
(
copyFile
(
string
,
string2
,
z
))
{
Log
.
d
(
TAG
,
"copy file task taskid= "
+
j
+
" success, saved to = "
+
string2
);
}
else
{
Log
.
e
(
TAG
,
"copy file task failed, taskid= "
+
j
);
}
}
public
boolean
downloadFile
(
String
downloadURL
,
String
saveFilePath
,
boolean
progressDialog
)
{
FileOutputStream
fileOutputStream
=
null
;
InputStream
stream
=
null
;
HttpURLConnection
conn
=
null
;
boolean
success
=
false
;
try
{
// 打印下载 URL
Log
.
d
(
"FHDownLoadManager"
,
"downloadFile() URL = "
+
downloadURL
);
// 打开连接
conn
=
(
HttpURLConnection
)
new
URL
(
downloadURL
).
openConnection
();
conn
.
setUseCaches
(
false
);
conn
.
setInstanceFollowRedirects
(
true
);
conn
.
setConnectTimeout
(
5000
);
conn
.
setReadTimeout
(
5000
);
// 如果存在 Cookie,则添加请求头
if
(
this
.
mCookie
!=
null
)
{
conn
.
setRequestProperty
(
"Cookie"
,
this
.
mCookie
);
}
conn
.
setRequestProperty
(
"Pragma"
,
"no-cache"
);
conn
.
setRequestProperty
(
"Cache-Control"
,
"no-cache"
);
conn
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
conn
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/4.0 (compatible; MS IE 6.0; (ziva))"
);
// 建立连接
conn
.
connect
();
int
respCode
=
conn
.
getResponseCode
();
// 检查响应码
if
(
respCode
!=
200
)
{
Log
.
e
(
"FHDownLoadManager"
,
"downloadFile() URL is not accessible, response code = "
+
respCode
);
return
false
;
}
// 获取文件大小
long
contentLen
=
conn
.
getContentLength
();
if
(
contentLen
<=
0
)
{
Log
.
e
(
"FHDownLoadManager"
,
"downloadFile() failed, content length is error, contentLen= "
+
contentLen
);
return
false
;
}
// 显示进度对话框(如果需要)
if
(
progressDialog
)
{
this
.
showProgressDialog
(
contentLen
);
}
// 准备读取数据
long
readLen
=
0
;
byte
[]
buffer
=
new
byte
[
1024
];
stream
=
conn
.
getInputStream
();
File
file
=
new
File
(
saveFilePath
);
// 如果文件已存在,删除旧文件
if
(
file
.
exists
()
&&
!
file
.
delete
())
{
Log
.
e
(
"FHDownLoadManager"
,
"origin file delete failed!"
);
}
// 打开文件输出流
fileOutputStream
=
new
FileOutputStream
(
file
);
// 读取文件
while
(
readLen
<
contentLen
)
{
int
len
=
stream
.
read
(
buffer
);
if
(
len
<=
0
)
break
;
fileOutputStream
.
write
(
buffer
,
0
,
len
);
fileOutputStream
.
flush
();
readLen
+=
len
;
// 更新进度
if
(
progressDialog
)
{
this
.
dialogProgressChange
(
readLen
);
}
}
// 检查是否完全下载
if
(
readLen
==
contentLen
)
{
success
=
true
;
}
else
{
Log
.
e
(
"FHDownLoadManager"
,
"downloadFile() error, readLen= "
+
readLen
+
", contentLen= "
+
contentLen
);
if
(
file
.
exists
()
&&
!
file
.
delete
())
{
Log
.
e
(
"FHDownLoadManager"
,
"file delete failed."
);
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
// 关闭输入流、文件流和连接
try
{
if
(
stream
!=
null
)
{
stream
.
close
();
}
if
(
fileOutputStream
!=
null
)
{
fileOutputStream
.
close
();
}
if
(
conn
!=
null
)
{
conn
.
disconnect
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
// 隐藏进度对话框(如果需要)
if
(
progressDialog
)
{
this
.
dismissProgressDialog
();
}
}
return
success
;
}
public
int
downloadTaskProc
(
Bundle
bundle
)
{
int
i
=
0
;
String
string
=
bundle
.
getString
(
"md5"
);
String
string2
=
bundle
.
getString
(
"url"
);
String
string3
=
bundle
.
getString
(
"path_dst"
);
long
j
=
bundle
.
getLong
(
"id"
);
String
string4
=
bundle
.
getString
(
"file_type"
);
boolean
z
=
bundle
.
getBoolean
(
"auto_open"
);
boolean
z2
=
bundle
.
getBoolean
(
"dialog_progress"
);
boolean
z3
=
bundle
.
getBoolean
(
"owner_only"
);
String
str
=
null
;
Log
.
d
(
TAG
,
"downloadTaskProc() function in"
);
String
str2
=
string3
;
if
(!
TextUtils
.
isEmpty
(
string3
))
{
str2
=
string3
;
if
(
string3
.
endsWith
(
"/"
))
{
File
file
=
new
File
(
string3
.
substring
(
0
,
string3
.
length
()
-
1
));
if
(!
file
.
exists
()
&&
!
file
.
mkdir
())
{
Log
.
d
(
TAG
,
"download dir is not exist, mkdir failed."
);
}
if
(!
file
.
exists
())
{
Log
.
e
(
TAG
,
"download file task failed, mkdir fail"
);
i
=
-
1
;
}
else
{
String
genSavedFileFullPath
=
genSavedFileFullPath
(
string2
,
string3
);
str2
=
genSavedFileFullPath
;
if
(
TextUtils
.
isEmpty
(
genSavedFileFullPath
))
{
Log
.
e
(
TAG
,
"download file task failed, saved path= "
+
string3
);
i
=
-
1
;
}
}
return
i
;
}
}
String
str3
=
str2
+
".tmp"
;
File
file2
=
new
File
(
str2
);
if
(
file2
.
exists
())
{
str
=
FHFileTool
.
getFileMD5
(
str2
);
}
if
(
file2
.
exists
()
&&
FHFileTool
.
compareMD5
(
str
,
string
))
{
Log
.
d
(
TAG
,
"ignore download file task, file is existed and same, taskid="
+
j
);
i
=
0
;
}
else
if
(!
downloadFile
(
string2
,
str3
,
z2
))
{
Log
.
e
(
TAG
,
"download file task failed, taskid="
+
j
);
i
=
-
1
;
}
else
{
File
file3
=
new
File
(
str3
);
if
(!
file3
.
exists
()
||
file3
.
length
()
==
0
)
{
FHFileTool
.
deleteFile
(
str3
);
Log
.
e
(
TAG
,
"download file failed"
);
i
=
-
1
;
}
else
{
if
(!
TextUtils
.
isEmpty
(
string
))
{
String
fileMD5
=
FHFileTool
.
getFileMD5
(
str3
);
if
(!
FHFileTool
.
compareMD5
(
fileMD5
,
string
))
{
FHFileTool
.
deleteFile
(
str3
);
Log
.
e
(
TAG
,
"download file task failed, file md5 is NOK, fileMD5="
+
fileMD5
);
i
=
-
1
;
}
}
FHFileTool
.
deleteFile
(
str2
);
FHFileTool
.
renameFile
(
str3
,
str2
,
z3
);
Log
.
d
(
TAG
,
"download success, the file saved to:"
+
str2
);
if
(
z
)
{
Log
.
d
(
TAG
,
"try to open file:"
+
str2
);
String
str4
=
string4
;
if
(
TextUtils
.
isEmpty
(
string4
))
{
str4
=
FHFileTool
.
getMIMEType
(
str2
);
}
try
{
if
(!(
this
.
mContext
==
null
||
str4
==
null
))
{
FHFileTool
.
openFile
(
this
.
mContext
,
str2
,
str4
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
i
=
1
;
}
}
return
i
;
}
public
static
String
genSavedFileFullPath
(
String
str
,
String
str2
)
{
String
str3
=
null
;
String
str4
=
null
;
try
{
if
(!
TextUtils
.
isEmpty
(
str
))
{
str4
=
FHFileTool
.
getFileNameFromUrl
(
str
);
}
String
str5
=
str4
;
if
(
TextUtils
.
isEmpty
(
str4
))
{
str5
=
"unknownfile"
;
}
str3
=
str2
+
str5
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
str3
;
}
public
static
FHDownLoadManager
getInstance
()
{
FHDownLoadManager
fHDownLoadManager
;
synchronized
(
FHDownLoadManager
.
class
)
{
try
{
if
(
mInstance
==
null
)
{
mInstance
=
new
FHDownLoadManager
();
}
fHDownLoadManager
=
mInstance
;
}
catch
(
Throwable
th
)
{
throw
th
;
}
}
return
fHDownLoadManager
;
}
public
static
Map
<
String
,
String
>
getURLReqParams
(
String
str
)
{
HashMap
hashMap
=
new
HashMap
();
String
str2
=
null
;
if
(!
TextUtils
.
isEmpty
(
str
))
{
str2
=
null
;
if
(
str
.
length
()
>
1
)
{
String
[]
split
=
str
.
trim
().
split
(
"[?]"
);
str2
=
null
;
if
(
split
.
length
>
1
)
{
str2
=
null
;
if
(
split
[
1
]
!=
null
)
{
str2
=
split
[
1
];
}
}
}
}
if
(
str2
!=
null
)
{
for
(
String
str3
:
str2
.
split
(
"[&]"
))
{
String
[]
split2
=
str3
.
split
(
"[=]"
);
if
(
split2
.
length
>
1
)
{
hashMap
.
put
(
split2
[
0
],
split2
[
1
]);
}
else
if
(!
TextUtils
.
isEmpty
(
split2
[
0
]))
{
hashMap
.
put
(
split2
[
0
],
""
);
}
}
}
return
hashMap
;
}
private
void
initEventHandleThread
()
{
this
.
mDLoadHandleThread
=
new
HandlerThread
(
"mDLoadHandleThread"
);
this
.
mDLoadHandleThread
.
start
();
this
.
mEventHandle
=
new
Handler
(
this
.
mDLoadHandleThread
.
getLooper
())
{
@Override
public
void
handleMessage
(
Message
message
)
{
Bundle
data
=
message
.
getData
();
switch
(
message
.
what
)
{
case
FHDownLoadManager
.
MSG_FHIPTV_DLOAD_TASK_START
/* 7001 */
:
downloadTaskProc
(
data
);
return
;
case
7002
:
case
FHDownLoadManager
.
MSG_FHIPTV_DLOAD_TASK_CANCEL
/* 7003 */
:
case
FHDownLoadManager
.
MSG_FHIPTV_DLOAD_TASK_TIMEOUT
/* 7004 */
:
default
:
return
;
case
FHDownLoadManager
.
MSG_FHIPTV_DLOAD_TASK_COPYFILE
/* 7005 */
:
downloadTaskCopyFile
(
data
);
return
;
}
}
};
}
private
void
showProgressDialog
(
long
j
)
{
Log
.
d
(
TAG
,
"showProgressDialog() max="
+
j
);
if
(
this
.
mProgressDialogObserver
!=
null
)
{
this
.
mProgressDialogObserver
.
onShowProgressDialog
(
""
,
j
);
}
}
private
static
void
sleepTime
(
int
i
)
{
Log
.
d
(
TAG
,
"sleepTime milliSecond = "
+
i
);
try
{
Thread
.
sleep
((
long
)
i
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
try
{
Thread
.
currentThread
().
interrupt
();
}
catch
(
Exception
e2
)
{
e2
.
printStackTrace
();
}
}
}
public
long
asyncCopyFile
(
String
str
,
String
str2
,
String
str3
,
boolean
z
)
{
long
j
=
-
1
;
if
(
TextUtils
.
isEmpty
(
str
)
||
TextUtils
.
isEmpty
(
str2
))
{
Log
.
e
(
TAG
,
"copy file task failed, file path is empty"
);
}
else
if
(!
FHFileTool
.
isFileExist
(
str
))
{
Log
.
e
(
TAG
,
"copy file task failed, src file is not exist"
);
}
else
{
this
.
mTaskCount
++;
if
(
this
.
mTaskCount
<
0
)
{
this
.
mTaskCount
=
1
;
}
Log
.
d
(
TAG
,
"copy file task is started, taskid= "
+
this
.
mTaskCount
);
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
"path_src"
,
str
);
bundle
.
putString
(
"path_dst"
,
str2
);
bundle
.
putLong
(
"id"
,
this
.
mTaskCount
);
bundle
.
putBoolean
(
"owner_only"
,
z
);
if
(!
TextUtils
.
isEmpty
(
str3
))
{
bundle
.
putString
(
"md5"
,
str3
);
}
Message
message
=
new
Message
();
message
.
setData
(
bundle
);
message
.
what
=
MSG_FHIPTV_DLOAD_TASK_COPYFILE
;
this
.
mEventHandle
.
sendMessage
(
message
);
j
=
this
.
mTaskCount
;
}
return
j
;
}
public
long
asyncDownloadFile
(
String
str
,
String
str2
,
boolean
z
,
boolean
z2
,
String
str3
,
String
str4
,
boolean
z3
)
{
long
j
;
if
(
TextUtils
.
isEmpty
(
str
)
||
TextUtils
.
isEmpty
(
str2
))
{
j
=
-
1
;
}
else
{
this
.
mTaskCount
++;
if
(
this
.
mTaskCount
<
0
)
{
this
.
mTaskCount
=
1
;
}
Log
.
d
(
TAG
,
"download file task is started, taskid= "
+
this
.
mTaskCount
);
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
"url"
,
str
);
bundle
.
putString
(
"path_dst"
,
str2
);
if
(!
TextUtils
.
isEmpty
(
str4
))
{
bundle
.
putString
(
"md5"
,
str4
);
}
if
(!
TextUtils
.
isEmpty
(
str3
))
{
bundle
.
putString
(
"file_type"
,
str3
);
}
bundle
.
putBoolean
(
"auto_open"
,
z
);
bundle
.
putBoolean
(
"dialog_progress"
,
z2
);
bundle
.
putLong
(
"id"
,
this
.
mTaskCount
);
bundle
.
putBoolean
(
"owner_only"
,
z3
);
Message
message
=
new
Message
();
message
.
setData
(
bundle
);
message
.
what
=
MSG_FHIPTV_DLOAD_TASK_START
;
this
.
mEventHandle
.
sendMessage
(
message
);
j
=
this
.
mTaskCount
;
}
return
j
;
}
public
void
disregistDownloadObsever
(
IDownLoadListener
iDownLoadListener
)
{
this
.
mDownloadObserversList
.
remove
(
iDownLoadListener
);
}
public
void
disregistProgressDialogObsever
(
IProgressDialogListener
iProgressDialogListener
)
{
this
.
mProgressDialogObserver
=
null
;
}
public
HttpResponseInfo
getHttpResponse
(
String
str
)
{
InputStream
inputStream
=
null
;
HttpURLConnection
httpURLConnection
=
null
;
HttpResponseInfo
httpResponseInfo
;
int
read
;
try
{
HttpResponseInfo
httpResponseInfo2
=
new
HttpResponseInfo
(
this
);
InputStream
inputStream2
=
null
;
HttpURLConnection
httpURLConnection2
=
null
;
Log
.
d
(
TAG
,
"getHttpResponse() URL = "
+
str
);
try
{
HttpURLConnection
httpURLConnection3
=
(
HttpURLConnection
)
new
URL
(
str
).
openConnection
();
httpURLConnection3
.
setUseCaches
(
false
);
httpURLConnection3
.
setInstanceFollowRedirects
(
true
);
httpURLConnection3
.
setConnectTimeout
(
TIMEOUT_VAR
);
httpURLConnection3
.
setReadTimeout
(
TIMEOUT_VAR
);
if
(
this
.
mCookie
!=
null
)
{
httpURLConnection3
.
setRequestProperty
(
"Cookie"
,
this
.
mCookie
);
}
httpURLConnection3
.
setRequestProperty
(
"Pragma"
,
"no-cache"
);
httpURLConnection3
.
setRequestProperty
(
"Cache-Control"
,
"no-cache"
);
httpURLConnection3
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
httpURLConnection3
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/4.0 (compatible; MS IE 6.0; (ziva))"
);
httpURLConnection3
.
connect
();
int
contentLength
=
httpURLConnection3
.
getContentLength
();
if
(
contentLength
<=
0
)
{
try
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
0
!=
0
)
{
throw
new
NullPointerException
();
}
if
(
httpURLConnection3
!=
null
)
{
httpURLConnection3
.
disconnect
();
}
httpResponseInfo
=
null
;
}
else
{
InputStream
inputStream3
=
httpURLConnection3
.
getInputStream
();
int
i
=
0
;
HttpResponseInfo
.
url
=
httpURLConnection3
.
getURL
();
HttpResponseInfo
.
data
=
new
byte
[
contentLength
];
byte
[]
bArr
=
new
byte
[
1024
];
while
(
i
<
contentLength
&&
(
read
=
inputStream3
.
read
(
bArr
))
>
0
&&
i
+
read
<=
contentLength
)
{
System
.
arraycopy
(
bArr
,
0
,
HttpResponseInfo
.
data
,
i
,
read
);
i
+=
read
;
}
if
(
i
!=
contentLength
)
{
Log
.
e
(
TAG
,
"getHttpResponse error happen, readLen= "
+
i
+
", contentLen= "
+
contentLength
);
HttpResponseInfo
.
data
=
new
byte
[
0
];
httpURLConnection2
=
httpURLConnection3
;
inputStream2
=
inputStream3
;
httpURLConnection
=
httpURLConnection3
;
inputStream
=
inputStream3
;
HttpResponseInfo
.
url
=
null
;
}
if
(
inputStream3
!=
null
)
{
try
{
inputStream3
.
close
();
}
catch
(
Exception
e2
)
{
e2
.
printStackTrace
();
httpResponseInfo
=
httpResponseInfo2
;
}
}
httpResponseInfo
=
httpResponseInfo2
;
if
(
httpURLConnection3
!=
null
)
{
httpURLConnection3
.
disconnect
();
httpResponseInfo
=
httpResponseInfo2
;
}
}
}
catch
(
Exception
e3
)
{
e3
.
printStackTrace
();
if
(
inputStream2
!=
null
)
{
try
{
inputStream2
.
close
();
}
catch
(
Exception
e4
)
{
e4
.
printStackTrace
();
httpResponseInfo
=
null
;
}
}
httpResponseInfo
=
null
;
if
(
httpURLConnection2
!=
null
)
{
httpURLConnection2
.
disconnect
();
httpResponseInfo
=
null
;
}
}
return
httpResponseInfo
;
}
catch
(
Throwable
th
)
{
if
(
inputStream
!=
null
)
{
try
{
inputStream
.
close
();
}
catch
(
Exception
e5
)
{
e5
.
printStackTrace
();
throw
th
;
}
}
if
(
httpURLConnection
!=
null
)
{
httpURLConnection
.
disconnect
();
}
throw
th
;
}
}
public
void
registDownloadObsever
(
IDownLoadListener
iDownLoadListener
)
{
this
.
mDownloadObserversList
.
add
(
iDownLoadListener
);
}
public
void
registProgressDialogObsever
(
IProgressDialogListener
iProgressDialogListener
)
{
if
(
iProgressDialogListener
!=
null
)
{
this
.
mProgressDialogObserver
=
iProgressDialogListener
;
}
}
public
void
setCookie
(
String
str
)
{
this
.
mCookie
=
str
;
}
public
int
syncDownloadFile
(
String
str
,
String
str2
,
boolean
z
,
boolean
z2
,
String
str3
,
String
str4
,
boolean
z3
)
{
int
i
;
if
(
TextUtils
.
isEmpty
(
str
)
||
TextUtils
.
isEmpty
(
str2
))
{
i
=
-
1
;
}
else
{
this
.
mTaskCount
++;
if
(
this
.
mTaskCount
<
0
)
{
this
.
mTaskCount
=
1
;
}
Bundle
bundle
=
new
Bundle
();
bundle
.
putString
(
"url"
,
str
);
bundle
.
putString
(
"path_dst"
,
str2
);
if
(!
TextUtils
.
isEmpty
(
str4
))
{
bundle
.
putString
(
"md5"
,
str4
);
}
if
(!
TextUtils
.
isEmpty
(
str3
))
{
bundle
.
putString
(
"file_type"
,
str3
);
}
bundle
.
putBoolean
(
"auto_open"
,
z
);
bundle
.
putBoolean
(
"dialog_progress"
,
z2
);
bundle
.
putLong
(
"id"
,
this
.
mTaskCount
);
bundle
.
putBoolean
(
"owner_only"
,
z3
);
i
=
downloadTaskProc
(
bundle
);
}
return
i
;
}
}
app/src/main/java/com/topdraw/iptvlaunchertest/fh/FHFileTool.java
0 → 100644
View file @
0d19e52
package
com
.
topdraw
.
iptvlaunchertest
.
fh
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
com.topdraw.iptvlaunchertest.App
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.security.MessageDigest
;
import
java.util.Locale
;
/* loaded from: classes-dex2jar.jar:com/fiberhome/iptv/common/FHFileTool.class */
public
class
FHFileTool
{
private
static
final
String
ASSETS_DIRECTORY
=
"file:///android_asset/html/"
;
private
static
final
String
ASSETS_ERRORPAGE_PATH
=
"html/nodomain.html"
;
private
static
final
int
ASSETS_FILE_TYPE
=
1
;
private
static
final
String
CUSTOM_DIRECTORY
=
"file:///system/opt/iptv/html/"
;
private
static
final
String
CUSTOM_ERRORPAGE_PATH
=
"/system/opt/iptv/html/nodomain.html"
;
private
static
final
String
[][]
MIME_MapTable
=
{
new
String
[]{
".apk"
,
"application/vnd.android.package-archive"
},
new
String
[]{
".3gp"
,
"video/3gpp"
},
new
String
[]{
".asf"
,
"video/x-ms-asf"
},
new
String
[]{
".avi"
,
"video/x-msvideo"
},
new
String
[]{
".bin"
,
"application/octet-stream"
},
new
String
[]{
".bmp"
,
"image/bmp"
},
new
String
[]{
".c"
,
"text/plain"
},
new
String
[]{
".class"
,
"application/octet-stream"
},
new
String
[]{
".conf"
,
"text/plain"
},
new
String
[]{
".cpp"
,
"text/plain"
},
new
String
[]{
".doc"
,
"application/msword"
},
new
String
[]{
".docx"
,
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
},
new
String
[]{
".xls"
,
"application/vnd.ms-excel"
},
new
String
[]{
".xlsx"
,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
},
new
String
[]{
".exe"
,
"application/octet-stream"
},
new
String
[]{
".gif"
,
"image/gif"
},
new
String
[]{
".gtar"
,
"application/x-gtar"
},
new
String
[]{
".gz"
,
"application/x-gzip"
},
new
String
[]{
".h"
,
"text/plain"
},
new
String
[]{
".htm"
,
"text/html"
},
new
String
[]{
".html"
,
"text/html"
},
new
String
[]{
".jar"
,
"application/java-archive"
},
new
String
[]{
".java"
,
"text/plain"
},
new
String
[]{
".js"
,
"application/x-javascript"
},
new
String
[]{
".log"
,
"text/plain"
},
new
String
[]{
".m3u"
,
"audio/x-mpegurl"
},
new
String
[]{
".m4a"
,
"audio/mp4a-latm"
},
new
String
[]{
".m4b"
,
"audio/mp4a-latm"
},
new
String
[]{
".m4p"
,
"audio/mp4a-latm"
},
new
String
[]{
".m4u"
,
"video/vnd.mpegurl"
},
new
String
[]{
".m4v"
,
"video/x-m4v"
},
new
String
[]{
".mov"
,
"video/quicktime"
},
new
String
[]{
".mp3"
,
"audio/x-mpeg"
},
new
String
[]{
".mp4"
,
"video/mp4"
},
new
String
[]{
".mpc"
,
"application/vnd.mpohun.certificate"
},
new
String
[]{
".mpe"
,
"video/mpeg"
},
new
String
[]{
".mpeg"
,
"video/mpeg"
},
new
String
[]{
".mpg"
,
"video/mpeg"
},
new
String
[]{
".mpg4"
,
"video/mp4"
},
new
String
[]{
".mpga"
,
"audio/mpeg"
},
new
String
[]{
".msg"
,
"application/vnd.ms-outlook"
},
new
String
[]{
".ogg"
,
"audio/ogg"
},
new
String
[]{
".pdf"
,
"application/pdf"
},
new
String
[]{
".jpeg"
,
"image/jpeg"
},
new
String
[]{
".jpg"
,
"image/jpeg"
},
new
String
[]{
".png"
,
"image/png"
},
new
String
[]{
".pps"
,
"application/vnd.ms-powerpoint"
},
new
String
[]{
".ppt"
,
"application/vnd.ms-powerpoint"
},
new
String
[]{
".pptx"
,
"application/vnd.openxmlformats-officedocument.presentationml.presentation"
},
new
String
[]{
".prop"
,
"text/plain"
},
new
String
[]{
".rc"
,
"text/plain"
},
new
String
[]{
".rmvb"
,
"audio/x-pn-realaudio"
},
new
String
[]{
".rtf"
,
"application/rtf"
},
new
String
[]{
".sh"
,
"text/plain"
},
new
String
[]{
".tar"
,
"application/x-tar"
},
new
String
[]{
".tgz"
,
"application/x-compressed"
},
new
String
[]{
".txt"
,
"text/plain"
},
new
String
[]{
".wav"
,
"audio/x-wav"
},
new
String
[]{
".wma"
,
"audio/x-ms-wma"
},
new
String
[]{
".wmv"
,
"audio/x-ms-wmv"
},
new
String
[]{
".wps"
,
"application/vnd.ms-works"
},
new
String
[]{
".xml"
,
"text/plain"
},
new
String
[]{
".z"
,
"application/x-compress"
},
new
String
[]{
".zip"
,
"application/x-zip-compressed"
},
new
String
[]{
""
,
"*/*"
}};
private
static
final
int
REGULAR_FILE_TYPE
=
0
;
private
static
final
String
TAG
=
"FHFileTool"
;
public
static
void
clearDirFiles
(
String
str
)
{
if
(!
TextUtils
.
isEmpty
(
str
))
{
Log
.
d
(
TAG
,
"clearDirFiles() dirPath = "
+
str
);
File
[]
fileList
=
getFileList
(
str
);
if
(
fileList
==
null
)
{
Log
.
d
(
TAG
,
"clearDirFiles() "
+
str
+
" is not exist"
);
return
;
}
try
{
for
(
File
file
:
fileList
)
{
Log
.
d
(
TAG
,
"clearDirFiles() delete "
+
file
.
getPath
());
if
(!
file
.
delete
())
{
Log
.
e
(
TAG
,
"clearDirFiles() delete file failed"
);
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
public
static
boolean
compareMD5
(
String
str
,
String
str2
)
{
boolean
z
=
false
;
if
(!
TextUtils
.
isEmpty
(
str
))
{
if
(
TextUtils
.
isEmpty
(
str2
))
{
z
=
false
;
}
else
{
String
str3
=
str
;
if
(
str
.
length
()
!=
32
)
{
str3
=
Util
.
strLeftPad
(
str
,
32
,
'0'
);
}
String
str4
=
str2
;
if
(
str2
.
length
()
!=
32
)
{
str4
=
Util
.
strLeftPad
(
str2
,
32
,
'0'
);
}
z
=
false
;
if
(
str3
.
equalsIgnoreCase
(
str4
))
{
z
=
true
;
}
}
}
return
z
;
}
public
static
boolean
deleteFile
(
String
str
)
{
boolean
z
;
if
(
TextUtils
.
isEmpty
(
str
))
{
z
=
false
;
}
else
{
try
{
File
file
=
new
File
(
str
);
z
=
false
;
if
(
file
.
exists
())
{
z
=
false
;
if
(
file
.
isFile
())
{
Log
.
e
(
TAG
,
"deleteFile() file "
+
str
);
if
(!
file
.
delete
())
{
Log
.
e
(
TAG
,
"deleteFile() file failed."
);
}
z
=
true
;
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
z
=
false
;
}
}
return
z
;
}
public
static
String
getAppPackagePath
()
{
return
App
.
getInstance
().
getFilesDir
().
getParent
();
}
public
static
String
getFileExtension
(
String
str
)
{
String
lowerCase
;
if
(
TextUtils
.
isEmpty
(
str
))
{
lowerCase
=
""
;
}
else
{
int
lastIndexOf
=
str
.
lastIndexOf
(
46
);
if
(
lastIndexOf
==
-
1
)
{
lowerCase
=
""
;
}
else
{
lowerCase
=
str
.
substring
(
lastIndexOf
+
1
).
toLowerCase
(
Locale
.
US
);
Log
.
d
(
TAG
,
"getFileExtension extension= "
+
lowerCase
);
}
}
return
lowerCase
;
}
public
static
File
[]
getFileList
(
String
str
)
{
File
file
=
new
File
(
str
);
return
(!
file
.
exists
()
||
!
file
.
isDirectory
())
?
null
:
file
.
listFiles
();
}
public
static
String
getFileMD5
(
String
str
)
{
Throwable
th
;
String
str2
=
""
;
FileInputStream
fileInputStream
=
null
;
FileInputStream
fileInputStream2
=
null
;
byte
[]
bArr
=
new
byte
[
1024
];
File
file
=
new
File
(
str
);
if
(!
file
.
isFile
())
{
Log
.
e
(
TAG
,
"getFileMD5() not a file."
);
str2
=
null
;
}
else
{
try
{
try
{
MessageDigest
instance
=
MessageDigest
.
getInstance
(
"MD5"
);
FileInputStream
fileInputStream3
=
new
FileInputStream
(
file
);
while
(
true
)
{
try
{
int
read
=
fileInputStream3
.
read
(
bArr
,
0
,
1024
);
if
(
read
==
-
1
)
{
break
;
}
instance
.
update
(
bArr
,
0
,
read
);
}
catch
(
Exception
e
)
{
e
=
e
;
fileInputStream2
=
fileInputStream3
;
fileInputStream
=
fileInputStream2
;
e
.
printStackTrace
();
str2
=
null
;
if
(
fileInputStream2
!=
null
)
{
try
{
fileInputStream2
.
close
();
str2
=
null
;
}
catch
(
Exception
e2
)
{
e2
.
printStackTrace
();
str2
=
null
;
}
}
return
str2
;
}
catch
(
Throwable
th2
)
{
th
=
th2
;
fileInputStream
=
fileInputStream3
;
if
(
fileInputStream
!=
null
)
{
try
{
fileInputStream
.
close
();
}
catch
(
Exception
e3
)
{
e3
.
printStackTrace
();
str2
=
null
;
}
}
throw
th
;
}
}
if
(
fileInputStream3
!=
null
)
{
try
{
fileInputStream3
.
close
();
}
catch
(
Exception
e4
)
{
e4
.
printStackTrace
();
str2
=
null
;
}
}
str2
=
Util
.
byte2Hex
(
instance
.
digest
());
Log
.
d
(
TAG
,
"getFileMD5() MD5= "
+
str2
+
", fileName= "
+
str
);
}
catch
(
Exception
e5
)
{
e5
.
printStackTrace
();
}
}
catch
(
Throwable
th3
)
{
th
=
th3
;
}
}
return
str2
;
}
public
static
String
getFileNameFromUrl
(
String
str
)
{
String
str2
;
try
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(!
TextUtils
.
isEmpty
(
str
))
{
str2
=
str
.
substring
(
str
.
lastIndexOf
(
47
)
+
1
);
return
str2
;
}
str2
=
null
;
return
str2
;
}
public
static
String
getFilePath
(
String
str
)
{
return
new
File
(
str
).
getParent
();
}
public
static
String
getMIMEType
(
String
str
)
{
String
str2
=
"*/*"
;
if
(
TextUtils
.
isEmpty
(
str
))
{
str2
=
null
;
}
else
{
int
lastIndexOf
=
str
.
lastIndexOf
(
46
);
if
(
lastIndexOf
<
0
)
{
str2
=
"*/*"
;
}
else
{
String
lowerCase
=
str
.
substring
(
lastIndexOf
).
toLowerCase
();
if
(
TextUtils
.
isEmpty
(
lowerCase
))
{
str2
=
"*/*"
;
}
else
{
for
(
int
i
=
0
;
i
<
MIME_MapTable
.
length
;
i
++)
{
if
(
lowerCase
.
equalsIgnoreCase
(
MIME_MapTable
[
i
][
0
]))
{
str2
=
MIME_MapTable
[
i
][
1
];
}
}
}
}
}
return
str2
;
}
public
static
boolean
isFileExist
(
File
file
)
{
return
file
!=
null
&&
file
.
exists
();
}
public
static
boolean
isFileExist
(
String
str
)
{
return
isFileExist
(
new
File
(
str
));
}
public
static
boolean
isPictureType
(
String
str
)
{
boolean
z
=
false
;
if
(
TextUtils
.
isEmpty
(
str
))
{
z
=
false
;
}
else
{
String
fileExtension
=
getFileExtension
(
str
);
if
(
TextUtils
.
isEmpty
(
fileExtension
))
{
z
=
false
;
}
else
if
(
"bmp"
.
equals
(
fileExtension
)
||
"gif"
.
equals
(
fileExtension
)
||
"jpeg"
.
equals
(
fileExtension
)
||
"jpg"
.
equals
(
fileExtension
)
||
"png"
.
equals
(
fileExtension
))
{
z
=
true
;
}
}
return
z
;
}
public
static
boolean
isVideoType
(
String
str
)
{
boolean
z
=
false
;
if
(
TextUtils
.
isEmpty
(
str
))
{
z
=
false
;
}
else
{
String
fileExtension
=
getFileExtension
(
str
);
if
(
TextUtils
.
isEmpty
(
fileExtension
))
{
z
=
false
;
}
else
if
(
"avi"
.
equals
(
fileExtension
)
||
"asf"
.
equals
(
fileExtension
)
||
"asx"
.
equals
(
fileExtension
)
||
"divx"
.
equals
(
fileExtension
)
||
"flv"
.
equals
(
fileExtension
)
||
"f4v"
.
equals
(
fileExtension
)
||
"mpg"
.
equals
(
fileExtension
)
||
"mp4"
.
equals
(
fileExtension
)
||
"mov"
.
equals
(
fileExtension
)
||
"m2v"
.
equals
(
fileExtension
)
||
"m4v"
.
equals
(
fileExtension
)
||
"mkv"
.
equals
(
fileExtension
)
||
"m3u8"
.
equals
(
fileExtension
)
||
"ndivx"
.
equals
(
fileExtension
)
||
"ra"
.
equals
(
fileExtension
)
||
"ram"
.
equals
(
fileExtension
)
||
"rm"
.
equals
(
fileExtension
)
||
"rmvb"
.
equals
(
fileExtension
)
||
"swf"
.
equals
(
fileExtension
)
||
"ts"
.
equals
(
fileExtension
)
||
"v8"
.
equals
(
fileExtension
)
||
"wmv"
.
equals
(
fileExtension
)
||
"xvid"
.
equals
(
fileExtension
)
||
"3gp"
.
equals
(
fileExtension
)
||
"3gpp"
.
equals
(
fileExtension
)
||
"3gpp2"
.
equals
(
fileExtension
))
{
z
=
true
;
}
}
return
z
;
}
public
static
boolean
openFile
(
Context
context
,
String
str
,
String
str2
)
{
Log
.
d
(
TAG
,
"openFile: "
+
str
+
", openFileType="
+
str2
);
boolean
z
=
false
;
if
(!
TextUtils
.
isEmpty
(
str2
))
{
if
(
context
==
null
)
{
z
=
false
;
}
else
{
File
file
=
new
File
(
str
);
if
(!
file
.
exists
())
{
Log
.
d
(
TAG
,
"openFile failed, it is not existed"
);
z
=
false
;
}
else
{
Intent
intent
=
new
Intent
();
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
intent
.
setAction
(
"android.intent.action.VIEW"
);
intent
.
setDataAndType
(
Uri
.
fromFile
(
file
),
str2
);
try
{
context
.
startActivity
(
intent
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
z
=
true
;
}
}
}
return
z
;
}
public
static
void
renameFile
(
String
str
,
String
str2
,
String
str3
)
{
if
(!
TextUtils
.
isEmpty
(
str2
)
&&
!
TextUtils
.
isEmpty
(
str3
)
&&
!
str2
.
equals
(
str3
))
{
File
file
=
new
File
(
str
+
str2
);
File
file2
=
new
File
(
str
+
str3
);
try
{
if
(!
file2
.
exists
()
&&
!
file
.
renameTo
(
file2
))
{
Log
.
d
(
TAG
,
"renameFile failed."
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
public
static
void
renameFile
(
String
str
,
String
str2
,
boolean
z
)
{
if
(!
TextUtils
.
isEmpty
(
str
)
&&
!
TextUtils
.
isEmpty
(
str2
)
&&
!
str
.
equals
(
str2
))
{
File
file
=
new
File
(
str
);
File
file2
=
new
File
(
str2
);
try
{
if
(!
file
.
setReadable
(
true
,
z
))
{
Log
.
d
(
TAG
,
"old file setReadable failed."
);
}
if
(!
file
.
setWritable
(
true
,
z
))
{
Log
.
d
(
TAG
,
"old file setWritable failed."
);
}
if
(!
file2
.
setReadable
(
true
,
z
))
{
Log
.
d
(
TAG
,
"new file setReadable failed."
);
}
if
(!
file2
.
setWritable
(
true
,
z
))
{
Log
.
d
(
TAG
,
"new file setWritable failed."
);
}
if
(!
file2
.
exists
()
&&
!
file
.
renameTo
(
file2
))
{
Log
.
d
(
TAG
,
"renameFile failed, newPathName="
+
str2
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
app/src/main/java/com/topdraw/iptvlaunchertest/fh/FHJsonUtil.java
0 → 100644
View file @
0d19e52
package
com
.
topdraw
.
iptvlaunchertest
.
fh
;
import
android.os.Bundle
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Map
;
/**
* 烽火盒子启动参数解析工具
*/
public
class
FHJsonUtil
{
private
static
final
String
TAG
=
"FHJsonUtil"
;
public
static
JSONArray
getArray
(
String
str
)
{
JSONArray
jSONArray
=
null
;
if
(
TextUtils
.
isEmpty
(
str
))
{
Log
.
d
(
TAG
,
"getArray arrStr is null."
);
jSONArray
=
null
;
}
else
{
try
{
jSONArray
=
new
JSONArray
(
str
);
}
catch
(
Exception
e
)
{
}
}
return
jSONArray
;
}
public
static
JSONArray
getArrayParam
(
JSONObject
jSONObject
,
String
str
)
{
JSONArray
jSONArray
=
null
;
if
(
jSONObject
==
null
||
TextUtils
.
isEmpty
(
str
))
{
Log
.
d
(
TAG
,
"getArrayParam jsonObj/name is null."
);
jSONArray
=
null
;
}
else
{
try
{
jSONArray
=
jSONObject
.
getJSONArray
(
str
);
}
catch
(
Exception
e
)
{
}
}
return
jSONArray
;
}
public
static
int
getIntParam
(
JSONObject
jSONObject
,
String
str
)
{
int
i
=
-
1
;
if
(
jSONObject
==
null
||
TextUtils
.
isEmpty
(
str
))
{
Log
.
d
(
TAG
,
"getIntParam jsonObj/name is null."
);
i
=
-
1
;
}
else
{
try
{
i
=
jSONObject
.
getInt
(
str
);
}
catch
(
Exception
e
)
{
}
Log
.
d
(
TAG
,
"getIntParam name = "
+
str
+
", value = "
+
i
);
}
return
i
;
}
public
static
int
getIntParamFromString
(
String
str
,
String
str2
)
{
int
i
=
-
1
;
if
(
TextUtils
.
isEmpty
(
str2
))
{
Log
.
d
(
TAG
,
"getIntParamFromString name is null."
);
i
=
-
1
;
}
else
{
JSONObject
jsonObj
=
getJsonObj
(
str
);
if
(
jsonObj
==
null
)
{
Log
.
d
(
TAG
,
"getIntParamFromString jsonObj null."
);
i
=
-
1
;
}
else
{
try
{
i
=
jsonObj
.
getInt
(
str2
);
}
catch
(
Exception
e
)
{
}
Log
.
d
(
TAG
,
"getIntParamFromString name = "
+
str2
+
", value = "
+
i
);
}
}
return
i
;
}
public
static
JSONObject
getJsonObj
(
String
str
)
{
JSONObject
jSONObject
;
if
(
TextUtils
.
isEmpty
(
str
))
{
Log
.
d
(
TAG
,
"getJsonObj jsonStr is null."
);
jSONObject
=
null
;
}
else
{
try
{
jSONObject
=
new
JSONObject
(
str
);
}
catch
(
Exception
e
)
{
jSONObject
=
null
;
}
}
return
jSONObject
;
}
public
static
JSONObject
getJsonObjFromArray
(
JSONArray
jSONArray
,
int
i
)
{
JSONObject
jSONObject
=
null
;
if
(
jSONArray
==
null
)
{
Log
.
d
(
TAG
,
"getJsonObjFromArray jsonArray is null."
);
jSONObject
=
null
;
}
else
{
try
{
jSONObject
=
jSONArray
.
getJSONObject
(
i
);
}
catch
(
Exception
e
)
{
}
}
return
jSONObject
;
}
public
static
JSONObject
getJsonObjFromString
(
String
str
,
int
i
)
{
JSONObject
jSONObject
=
null
;
if
(
TextUtils
.
isEmpty
(
str
))
{
Log
.
d
(
TAG
,
"getJsonObjFromString jsonStr is null."
);
jSONObject
=
null
;
}
else
{
try
{
jSONObject
=
new
JSONArray
(
str
).
getJSONObject
(
i
);
}
catch
(
Exception
e
)
{
}
}
return
jSONObject
;
}
public
static
String
getStrParam
(
JSONObject
jSONObject
,
String
str
)
{
String
str2
;
if
(
jSONObject
==
null
||
TextUtils
.
isEmpty
(
str
))
{
Log
.
d
(
TAG
,
"getStrParam jsonObj/name is null."
);
str2
=
""
;
}
else
{
str2
=
""
;
try
{
if
(
jSONObject
.
has
(
str
))
{
str2
=
jSONObject
.
getString
(
str
);
}
}
catch
(
Exception
e
)
{
str2
=
""
;
}
Log
.
d
(
TAG
,
"getStrParam value = "
+
str2
);
}
return
str2
;
}
public
static
String
getStrParamFromString
(
String
str
,
String
str2
)
{
String
str3
;
if
(
TextUtils
.
isEmpty
(
str2
))
{
Log
.
d
(
TAG
,
"getStrParamFromString name is null."
);
str3
=
""
;
}
else
{
JSONObject
jsonObj
=
getJsonObj
(
str
);
if
(
jsonObj
==
null
)
{
Log
.
d
(
TAG
,
"getStrParamFromString jsonObj is null."
);
str3
=
""
;
}
else
{
str3
=
""
;
try
{
if
(
jsonObj
.
has
(
str2
))
{
str3
=
jsonObj
.
getString
(
str2
);
}
}
catch
(
Exception
e
)
{
str3
=
""
;
}
Log
.
d
(
TAG
,
"getStrParamFromString value = "
+
str3
);
}
}
return
str3
;
}
public
static
Bundle
jsonStringToBundle
(
String
str
)
{
Bundle
bundle
=
new
Bundle
();
if
(
TextUtils
.
isEmpty
(
str
))
{
Log
.
d
(
TAG
,
"jsonStringToBundle jsonStr is null."
);
}
else
{
try
{
JSONObject
jSONObject
=
new
JSONObject
(
str
);
Iterator
<
String
>
keys
=
jSONObject
.
keys
();
while
(
keys
.
hasNext
())
{
String
next
=
keys
.
next
();
Object
obj
=
jSONObject
.
get
(
next
);
if
(
obj
instanceof
Integer
)
{
bundle
.
putInt
(
next
,
((
Integer
)
obj
).
intValue
());
}
else
if
(
obj
instanceof
Long
)
{
bundle
.
putLong
(
next
,
((
Long
)
obj
).
longValue
());
}
else
if
(
obj
instanceof
Double
)
{
bundle
.
putDouble
(
next
,
((
Double
)
obj
).
doubleValue
());
}
else
if
(
obj
instanceof
String
)
{
bundle
.
putString
(
next
,
(
String
)
obj
);
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
return
bundle
;
}
public
static
Map
jsonToMap
(
String
str
)
{
HashMap
hashMap
=
new
HashMap
();
if
(
TextUtils
.
isEmpty
(
str
))
{
Log
.
d
(
TAG
,
"jsonToMap jsonString is null."
);
}
else
{
try
{
JSONObject
jSONObject
=
new
JSONObject
(
str
);
Iterator
<
String
>
keys
=
jSONObject
.
keys
();
while
(
keys
.
hasNext
())
{
String
next
=
keys
.
next
();
if
(!
TextUtils
.
isEmpty
(
next
))
{
hashMap
.
put
(
next
,
jSONObject
.
getString
(
next
));
}
}
}
catch
(
Exception
e
)
{
}
}
return
hashMap
;
}
public
static
void
putStrParam
(
JSONObject
jSONObject
,
String
str
,
String
str2
)
{
if
(
jSONObject
==
null
||
TextUtils
.
isEmpty
(
str
))
{
Log
.
d
(
TAG
,
"putStrParam jsonObj/name is null."
);
return
;
}
try
{
jSONObject
.
put
(
str
,
str2
);
}
catch
(
Exception
e
)
{
}
}
}
app/src/main/java/com/topdraw/iptvlaunchertest/fh/IDownLoadListener.java
0 → 100644
View file @
0d19e52
package
com
.
topdraw
.
iptvlaunchertest
.
fh
;
public
interface
IDownLoadListener
{
void
OnDownloadStateChange
(
int
i
,
String
str
,
int
i2
);
}
app/src/main/java/com/topdraw/iptvlaunchertest/fh/IProgressDialogListener.java
0 → 100644
View file @
0d19e52
package
com
.
topdraw
.
iptvlaunchertest
.
fh
;
public
interface
IProgressDialogListener
{
void
onDialogProgressChange
(
long
j
);
void
onDismissProgressDialog
();
void
onShowProgressDialog
(
String
str
,
long
j
);
}
app/src/main/java/com/topdraw/iptvlaunchertest/fh/STBAppManager.java
0 → 100644
View file @
0d19e52
package
com
.
topdraw
.
iptvlaunchertest
.
fh
;
import
static
android
.
os
.
UserHandle
.*;
import
android.app.ActivityManager
;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageManager
;
import
android.graphics.Bitmap
;
import
android.net.Uri
;
import
android.os.Parcel
;
import
android.os.UserHandle
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.webkit.JavascriptInterface
;
import
android.widget.Toast
;
import
com.topdraw.iptvlaunchertest.App
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.lang.reflect.Method
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
public
class
STBAppManager
{
private
static
final
String
SAVED_FILE_PATH
=
"/sdcard/.downapp/"
;
private
static
final
String
TAG
=
"STBAppManager"
;
private
static
HashMap
<
String
,
String
>
mInstallAppTbl
=
new
HashMap
<>();
private
static
STBAppManager
mInstance
=
null
;
private
Context
mContext
;
public
STBAppManager
(
Context
context
)
{
this
.
mContext
=
context
;
}
public
static
STBAppManager
getInstance
(
Context
context
)
{
STBAppManager
sTBAppManager
;
synchronized
(
STBAppManager
.
class
)
{
try
{
if
(
mInstance
==
null
)
{
mInstance
=
new
STBAppManager
(
context
);
}
sTBAppManager
=
mInstance
;
}
catch
(
Throwable
th
)
{
throw
th
;
}
}
return
sTBAppManager
;
}
private
boolean
getPersistentFlag
(
String
str
)
{
boolean
z
;
if
(
TextUtils
.
isEmpty
(
str
))
{
z
=
false
;
}
else
{
z
=
false
;
try
{
if
((
this
.
mContext
.
getPackageManager
().
getPackageInfo
(
str
,
1
).
applicationInfo
.
flags
&
8
)
!=
0
)
{
z
=
true
;
}
}
catch
(
Exception
e
)
{
}
}
return
z
;
}
private
Intent
parseIntentMessage
(
String
str
,
int
i
)
{
Intent
intent
;
ComponentName
componentName
;
Intent
intent2
;
JSONArray
jSONArray
=
null
;
JSONObject
jsonObj
=
FHJsonUtil
.
getJsonObj
(
str
);
if
(
jsonObj
==
null
)
{
intent
=
null
;
}
else
{
int
intParam
=
FHJsonUtil
.
getIntParam
(
jsonObj
,
"intentType"
);
int
i2
=
intParam
;
if
(
intParam
==
-
1
)
{
i2
=
0
;
}
String
strParam
=
FHJsonUtil
.
getStrParam
(
jsonObj
,
"appName"
);
String
strParam2
=
FHJsonUtil
.
getStrParam
(
jsonObj
,
"className"
);
String
strParam3
=
FHJsonUtil
.
getStrParam
(
jsonObj
,
"action"
);
String
strParam4
=
FHJsonUtil
.
getStrParam
(
jsonObj
,
"category"
);
String
strParam5
=
FHJsonUtil
.
getStrParam
(
jsonObj
,
"data"
);
if
(
jsonObj
.
has
(
"extra"
))
{
jSONArray
=
FHJsonUtil
.
getArrayParam
(
jsonObj
,
"extra"
);
}
Intent
intent3
=
null
;
if
(
i
==
1
)
{
intent3
=
null
;
if
(
i2
==
0
)
{
Intent
parseIntentMessage
=
null
;
if
(
TextUtils
.
isEmpty
(
strParam
)
||
TextUtils
.
isEmpty
(
strParam2
))
{
componentName
=
null
;
intent2
=
parseIntentMessage
;
if
(!
TextUtils
.
isEmpty
(
strParam
))
{
componentName
=
null
;
intent2
=
parseIntentMessage
;
if
(
TextUtils
.
isEmpty
(
strParam2
))
{
componentName
=
null
;
intent2
=
parseIntentMessage
;
if
(
parseIntentMessage
==
null
)
{
try
{
intent2
=
this
.
mContext
.
getPackageManager
().
getLaunchIntentForPackage
(
strParam
);
componentName
=
null
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
componentName
=
null
;
intent2
=
parseIntentMessage
;
}
}
}
}
}
else
{
componentName
=
new
ComponentName
(
strParam
,
strParam2
);
intent2
=
parseIntentMessage
;
}
Intent
intent4
=
intent2
;
if
(
intent2
==
null
)
{
intent4
=
new
Intent
(
"android.intent.action.MAIN"
);
intent4
.
addCategory
(
"android.intent.category.LAUNCHER"
);
intent4
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
}
intent3
=
intent4
;
if
(
componentName
!=
null
)
{
intent4
.
setComponent
(
componentName
);
intent3
=
intent4
;
}
}
}
intent
=
intent3
;
if
(
intent3
==
null
)
{
Intent
intent5
=
new
Intent
();
intent
=
intent5
;
if
(
i2
==
1
)
{
intent5
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
intent
=
intent5
;
}
}
if
(!
TextUtils
.
isEmpty
(
strParam3
))
{
intent
.
setAction
(
strParam3
);
}
if
(!
TextUtils
.
isEmpty
(
strParam4
))
{
intent
.
addCategory
(
strParam4
);
}
if
(!
TextUtils
.
isEmpty
(
strParam5
))
{
intent
.
setData
(
Uri
.
parse
(
strParam5
));
}
if
(
jSONArray
!=
null
&&
jSONArray
.
length
()
>
0
)
{
for
(
int
i3
=
0
;
i3
<
jSONArray
.
length
();
i3
++)
{
JSONObject
jsonObjFromArray
=
FHJsonUtil
.
getJsonObjFromArray
(
jSONArray
,
i3
);
if
(
jsonObjFromArray
!=
null
)
{
String
strParam6
=
FHJsonUtil
.
getStrParam
(
jsonObjFromArray
,
"name"
);
String
strParam7
=
FHJsonUtil
.
getStrParam
(
jsonObjFromArray
,
"value"
);
if
(!
TextUtils
.
isEmpty
(
strParam6
)
&&
!
TextUtils
.
isEmpty
(
strParam7
))
{
Log
.
d
(
TAG
,
"parseIntentMessage extra1 name = "
+
strParam6
+
", value = "
+
strParam7
);
intent
.
putExtra
(
strParam6
,
strParam7
);
}
else
if
(
TextUtils
.
isEmpty
(
strParam6
)
&&
TextUtils
.
isEmpty
(
strParam7
))
{
Iterator
<
String
>
keys
=
jsonObjFromArray
.
keys
();
while
(
keys
.
hasNext
())
{
String
next
=
keys
.
next
();
try
{
strParam7
=
jsonObjFromArray
.
getString
(
next
);
}
catch
(
Exception
e2
)
{
}
Log
.
d
(
TAG
,
"parseIntentMessage extra2 name = "
+
next
+
", value = "
+
strParam7
);
intent
.
putExtra
(
next
,
strParam7
);
}
}
}
}
}
}
return
intent
;
}
@JavascriptInterface
public
boolean
cleanCache
(
String
str
)
{
Log
.
d
(
TAG
,
"cleanCache pkgNames = "
+
str
);
boolean
z
=
false
;
if
(
TextUtils
.
isEmpty
(
str
))
{
z
=
false
;
}
else
{
try
{
String
[]
split
=
str
.
replaceAll
(
"\"|\\]|\\["
,
""
).
split
(
","
);
ActivityManager
activityManager
=
(
ActivityManager
)
this
.
mContext
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
List
<
ActivityManager
.
RunningAppProcessInfo
>
runningAppProcesses
=
activityManager
.
getRunningAppProcesses
();
if
(
runningAppProcesses
==
null
||
split
==
null
)
{
Log
.
d
(
TAG
,
"runningPros or pkgNameArray is null."
);
z
=
false
;
}
else
{
String
packageName
=
this
.
mContext
.
getPackageName
();
for
(
ActivityManager
.
RunningAppProcessInfo
runningAppProcessInfo
:
runningAppProcesses
)
{
boolean
z2
=
false
;
String
str2
=
runningAppProcessInfo
.
processName
;
int
i
=
runningAppProcessInfo
.
uid
;
boolean
persistentFlag
=
getPersistentFlag
(
str2
);
Log
.
d
(
TAG
,
"running pkgname = "
+
str2
+
", UID = "
+
i
+
", persistentFlag = "
+
persistentFlag
);
if
(
TextUtils
.
isEmpty
(
packageName
)
||
!
packageName
.
equals
(
str2
))
{
for
(
String
str3
:
split
)
{
if
(
str2
.
equals
(
str3
)
||
persistentFlag
)
{
Log
.
d
(
TAG
,
"match, remain this app process."
);
z2
=
true
;
break
;
}
}
if
(!
z2
)
{
Log
.
d
(
TAG
,
"kill task, pkgname = "
+
str2
);
activityManager
.
killBackgroundProcesses
(
str2
);
}
}
else
{
Log
.
d
(
TAG
,
"ignore top package process, pkg = "
+
str2
);
}
}
z
=
true
;
Toast
.
makeText
(
this
.
mContext
,
"clean cache success!"
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
return
z
;
}
public
void
delInstalledAppFile
(
String
str
)
{
Log
.
d
(
TAG
,
"delInstalledAppFile appName="
+
str
);
try
{
if
(
mInstallAppTbl
.
containsKey
(
str
))
{
String
str2
=
mInstallAppTbl
.
get
(
str
);
File
file
=
new
File
(
str2
);
if
(
file
.
exists
())
{
Log
.
d
(
TAG
,
"delInstalledAppFile app Path = "
+
str2
);
if
(!
file
.
delete
())
{
Log
.
d
(
TAG
,
"delInstalledAppFile delete failed."
);
}
mInstallAppTbl
.
remove
(
str
);
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
@JavascriptInterface
public
int
getAppCount
()
{
int
i
=
0
;
try
{
i
=
this
.
mContext
.
getPackageManager
().
getInstalledPackages
(
0
).
size
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
Log
.
d
(
TAG
,
"getAppCount count = "
+
i
);
return
i
;
}
@JavascriptInterface
public
String
getAppList
(
int
i
,
int
i2
)
{
String
str
;
JSONObject
jSONObject
=
new
JSONObject
();
JSONArray
jSONArray
=
new
JSONArray
();
try
{
jSONObject
.
put
(
"apps_count"
,
0
);
jSONObject
.
put
(
"apps"
,
jSONArray
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
PackageManager
packageManager
=
this
.
mContext
.
getPackageManager
();
List
<
PackageInfo
>
installedPackages
=
packageManager
.
getInstalledPackages
(
0
);
int
size
=
installedPackages
.
size
();
if
(
i
>
size
||
i
<
0
||
i2
<=
0
)
{
str
=
jSONObject
.
toString
();
}
else
{
Log
.
d
(
TAG
,
"getAppList position = "
+
i
+
", count="
+
i2
+
", pkgSize="
+
size
);
int
i3
=
i2
;
if
(
size
-
i
<
i2
)
{
i3
=
size
-
i
;
}
for
(
int
i4
=
0
;
i4
<
i3
;
i4
++)
{
try
{
PackageInfo
packageInfo
=
installedPackages
.
get
(
i
+
i4
);
if
(
packageInfo
!=
null
)
{
JSONObject
jSONObject2
=
new
JSONObject
();
jSONObject2
.
put
(
"name"
,
(
String
)
packageManager
.
getApplicationLabel
(
packageInfo
.
applicationInfo
));
jSONObject2
.
put
(
"package"
,
packageInfo
.
applicationInfo
.
packageName
);
jSONObject2
.
put
(
"isSystem"
,
(
packageInfo
.
applicationInfo
.
flags
&
1
)
!=
0
);
jSONArray
.
put
(
jSONObject2
);
}
}
catch
(
Exception
e2
)
{
e2
.
printStackTrace
();
}
}
try
{
jSONObject
.
put
(
"apps_count"
,
i3
);
jSONObject
.
put
(
"apps"
,
jSONArray
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
str
=
jSONObject
.
toString
();
Log
.
d
(
TAG
,
"getAppList() appsResult = "
+
str
);
}
return
str
;
}
@JavascriptInterface
public
String
getAppVersion
(
String
str
)
{
String
str2
=
""
;
Log
.
d
(
TAG
,
"getAppVersion appName = "
+
str
);
if
(
TextUtils
.
isEmpty
(
str
))
{
str2
=
""
;
}
else
{
try
{
PackageInfo
packageInfo
=
this
.
mContext
.
getPackageManager
().
getPackageInfo
(
str
,
0
);
if
(
packageInfo
!=
null
)
{
str2
=
packageInfo
.
versionName
;
}
Log
.
d
(
TAG
,
"getAppVersion versionName = "
+
str2
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
str2
=
""
;
}
}
return
str2
;
}
@JavascriptInterface
public
int
getAppVersionCode
(
String
str
)
{
int
i
=
-
1
;
Log
.
d
(
TAG
,
"getAppVersionCode appName = "
+
str
);
if
(
TextUtils
.
isEmpty
(
str
))
{
i
=
-
1
;
}
else
{
try
{
PackageInfo
packageInfo
=
this
.
mContext
.
getPackageManager
().
getPackageInfo
(
str
,
0
);
if
(
packageInfo
!=
null
)
{
i
=
packageInfo
.
versionCode
;
}
Log
.
d
(
TAG
,
"getAppVersionCode versionCode = "
+
i
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
i
=
-
1
;
}
}
return
i
;
}
@JavascriptInterface
public
String
getApps
()
{
Log
.
d
(
TAG
,
"getApps() function in."
);
String
str
=
""
;
try
{
JSONArray
jSONArray
=
new
JSONArray
();
PackageManager
packageManager
=
this
.
mContext
.
getPackageManager
();
for
(
PackageInfo
packageInfo
:
packageManager
.
getInstalledPackages
(
0
))
{
if
((
packageInfo
.
applicationInfo
.
flags
&
1
)
==
0
)
{
Log
.
d
(
TAG
,
"getApps, packageName = "
+
packageInfo
.
packageName
);
JSONObject
jSONObject
=
new
JSONObject
();
jSONObject
.
put
(
"Version"
,
packageInfo
.
versionName
);
jSONObject
.
put
(
"appName"
,
(
String
)
packageManager
.
getApplicationLabel
(
packageInfo
.
applicationInfo
));
jSONObject
.
put
(
"packageName"
,
packageInfo
.
packageName
);
jSONArray
.
put
(
jSONObject
);
}
}
String
jSONArray2
=
jSONArray
.
toString
();
str
=
jSONArray2
;
Log
.
d
(
TAG
,
"getApps, appInfos = "
+
jSONArray2
);
str
=
jSONArray2
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
str
;
}
@JavascriptInterface
public
void
installApp
(
String
str
)
{
Log
.
d
(
TAG
,
"installApp downloadUrl= "
+
str
);
if
(!
TextUtils
.
isEmpty
(
str
))
{
FHFileTool
.
clearDirFiles
(
SAVED_FILE_PATH
);
FHDownLoadManager
instance
=
FHDownLoadManager
.
getInstance
();
try
{
if
(
str
.
startsWith
(
"http://"
)
||
str
.
startsWith
(
"https://"
))
{
if
(
instance
.
syncDownloadFile
(
str
,
SAVED_FILE_PATH
,
true
,
true
,
"application/vnd.android.package-archive"
,
null
,
false
)
!=
1
)
{
Log
.
d
(
TAG
,
"installApp download apk file failed, URL="
+
str
);
return
;
}
}
else
if
(!
FHFileTool
.
openFile
(
this
.
mContext
,
str
,
"application/vnd.android.package-archive"
))
{
Log
.
d
(
TAG
,
"installApp open apk file failed, URL="
+
str
);
return
;
}
String
fileNameFromUrl
=
FHFileTool
.
getFileNameFromUrl
(
str
);
String
genSavedFileFullPath
=
FHDownLoadManager
.
genSavedFileFullPath
(
str
,
SAVED_FILE_PATH
);
if
(!
TextUtils
.
isEmpty
(
fileNameFromUrl
))
{
String
parseAppFile
=
FHActivityUtil
.
parseAppFile
(
this
.
mContext
,
genSavedFileFullPath
);
Log
.
d
(
TAG
,
"installApp pkgName="
+
parseAppFile
+
", savedFullPath="
+
genSavedFileFullPath
);
mInstallAppTbl
.
put
(
parseAppFile
,
genSavedFileFullPath
);
return
;
}
return
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
@JavascriptInterface
public
boolean
isAppInstalled
(
String
str
)
{
boolean
z
=
false
;
Log
.
d
(
TAG
,
"isAppInstalled appName = "
+
str
);
if
(!
TextUtils
.
isEmpty
(
str
))
{
if
(
str
.
equals
(
"com.android.settings"
))
{
Log
.
d
(
TAG
,
"isAppInstalled com.android.settings will call FHSettings."
);
z
=
true
;
}
else
{
z
=
false
;
try
{
if
(
this
.
mContext
.
getPackageManager
().
getApplicationInfo
(
str
,
0
)
!=
null
)
{
Log
.
d
(
TAG
,
"isAppInstalled: app installed."
);
z
=
true
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
z
=
false
;
}
}
}
return
z
;
}
@JavascriptInterface
public
int
isAppInstalledByVersion
(
String
str
,
int
i
)
{
int
i2
=
-
1
;
if
(
TextUtils
.
isEmpty
(
str
))
{
i2
=
-
1
;
}
else
{
try
{
PackageInfo
packageInfo
=
this
.
mContext
.
getPackageManager
().
getPackageInfo
(
str
,
0
);
if
(
packageInfo
==
null
)
{
Log
.
d
(
TAG
,
"isAppInstalledByVersion "
+
str
+
" is not installed."
);
i2
=
-
1
;
}
else
{
Log
.
d
(
TAG
,
"isAppInstalledByVersion "
+
str
+
" versionCode= "
+
packageInfo
.
versionCode
);
i2
=
packageInfo
.
versionCode
==
i
?
0
:
1
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
return
i2
;
}
@JavascriptInterface
public
void
restartAppByName
(
String
str
)
{
Log
.
d
(
TAG
,
"restartAppByName appName = "
+
str
);
if
(!
TextUtils
.
isEmpty
(
str
))
{
try
{
ActivityManager
activityManager
=
((
ActivityManager
)
this
.
mContext
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
));
Method
method
=
Class
.
forName
(
"android.app.ActivityManager"
).
getMethod
(
"forceStopPackage"
,
String
.
class
);
method
.
invoke
(
activityManager
,
str
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
startAppByName
(
str
);
}
}
@JavascriptInterface
public
void
sendBroadcastByIntent
(
String
str
)
{
Log
.
d
(
TAG
,
"sendBroadcastByIntent intentMessage = "
+
str
);
startBroadcastByIntent
(
str
);
}
@JavascriptInterface
public
void
startActivityByIntent
(
String
str
)
{
startAppByIntent
(
str
);
}
@JavascriptInterface
public
void
startAppByIntent
(
String
str
)
{
Intent
parseIntentMessage
;
Log
.
d
(
TAG
,
"startAppByIntent intentMessage = "
+
str
);
if
(!
TextUtils
.
isEmpty
(
str
)
&&
(
parseIntentMessage
=
parseIntentMessage
(
str
,
1
))
!=
null
)
{
try
{
this
.
mContext
.
startActivity
(
parseIntentMessage
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
@JavascriptInterface
public
void
startAppByName
(
String
str
)
{
if
(!
TextUtils
.
isEmpty
(
str
))
{
Log
.
d
(
TAG
,
"startAppByName appName = "
+
str
);
if
(
str
.
equals
(
"com.android.settings"
))
{
Intent
intent
=
new
Intent
(
"fiberhome.intent.action.FHSETTINGS"
);
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
try
{
this
.
mContext
.
startActivity
(
intent
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
;
}
try
{
Intent
launchIntentForPackage
=
this
.
mContext
.
getPackageManager
().
getLaunchIntentForPackage
(
str
);
if
(
launchIntentForPackage
!=
null
)
{
this
.
mContext
.
startActivity
(
launchIntentForPackage
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
@JavascriptInterface
public
void
startBroadcastByIntent
(
String
str
)
{
Intent
parseIntentMessage
;
Log
.
d
(
TAG
,
"startBroadcastByIntent intentMessage = "
+
str
);
if
(!
TextUtils
.
isEmpty
(
str
)
&&
(
parseIntentMessage
=
parseIntentMessage
(
str
,
2
))
!=
null
)
{
try
{
this
.
mContext
.
sendBroadcast
(
parseIntentMessage
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
@JavascriptInterface
public
void
startLauncherByIntent
()
{
Log
.
e
(
TAG
,
"startLauncherByIntent is not support!"
);
}
@JavascriptInterface
public
void
startService
(
String
str
)
{
Log
.
d
(
TAG
,
"startService intentMessage = "
+
str
);
Intent
parseIntentMessage
=
parseIntentMessage
(
str
,
2
);
if
(
parseIntentMessage
!=
null
)
{
try
{
this
.
mContext
.
startService
(
parseIntentMessage
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
@JavascriptInterface
public
boolean
unInstallApp
(
String
str
)
{
boolean
z
=
false
;
Log
.
d
(
TAG
,
"unInstallApp() appName = "
+
str
);
if
(
TextUtils
.
isEmpty
(
str
))
{
z
=
false
;
}
else
{
try
{
this
.
mContext
.
startActivity
(
new
Intent
(
"android.intent.action.DELETE"
,
Uri
.
parse
(
"package:"
+
str
)));
z
=
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
return
z
;
}
@JavascriptInterface
public
boolean
uninstallApp
(
String
str
)
{
return
unInstallApp
(
str
);
}
}
app/src/main/java/com/topdraw/iptvlaunchertest/fh/Util.java
0 → 100644
View file @
0d19e52
package
com
.
topdraw
.
iptvlaunchertest
.
fh
;
public
class
Util
{
public
static
String
byte2Hex
(
byte
[]
bArr
)
{
String
str
;
String
str2
=
""
;
if
(
bArr
==
null
||
bArr
.
length
==
0
)
{
str
=
null
;
}
else
{
for
(
int
i
=
0
;
i
<
bArr
.
length
;
i
++)
{
String
hexString
=
Integer
.
toHexString
(
bArr
[
i
]
&
255
);
String
str3
=
hexString
.
length
()
==
1
?
str2
+
"0"
+
hexString
:
str2
+
hexString
;
str2
=
str3
;
if
(
i
<
bArr
.
length
-
1
)
{
str2
=
str3
+
""
;
}
}
str
=
str2
.
toUpperCase
();
}
return
str
;
}
public
static
String
strLeftPad
(
String
str
,
int
i
,
char
c
)
{
String
str2
;
if
(
str
==
null
)
{
str2
=
null
;
}
else
{
int
length
=
i
-
str
.
length
();
str2
=
str
;
if
(
length
>
0
)
{
char
[]
cArr
=
new
char
[
length
];
for
(
int
i2
=
0
;
i2
<
cArr
.
length
;
i2
++)
{
cArr
[
i2
]
=
c
;
}
str2
=
new
String
(
cArr
).
concat
(
str
);
}
}
return
str2
;
}
}
app/src/main/java/com/topdraw/iptvlaunchertest/ApkTool.java
→
app/src/main/java/com/topdraw/iptvlaunchertest/
sky/
ApkTool.java
View file @
0d19e52
package
com
.
topdraw
.
iptvlaunchertest
;
package
com
.
topdraw
.
iptvlaunchertest
.
sky
;
import
android.content.Context
;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageManager
;
import
android.os.Build
;
import
android.util.Log
;
import
com.topdraw.iptvlaunchertest.App
;
import
com.topdraw.iptvlaunchertest.BuildConfig
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
...
...
app/src/main/java/com/topdraw/iptvlaunchertest/ApkTool28.java
→
app/src/main/java/com/topdraw/iptvlaunchertest/
sky/
ApkTool28.java
View file @
0d19e52
package
com
.
topdraw
.
iptvlaunchertest
;
package
com
.
topdraw
.
iptvlaunchertest
.
sky
;
import
android.annotation.TargetApi
;
import
android.app.PendingIntent
;
import
android.content.Intent
;
import
android.content.pm.PackageInstaller
;
import
com.topdraw.iptvlaunchertest.App
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
...
...
app/src/main/java/com/topdraw/iptvlaunchertest/CloseUtils.java
→
app/src/main/java/com/topdraw/iptvlaunchertest/
sky/
CloseUtils.java
View file @
0d19e52
package
com
.
topdraw
.
iptvlaunchertest
;
package
com
.
topdraw
.
iptvlaunchertest
.
sky
;
import
java.io.Closeable
;
import
java.io.IOException
;
...
...
app/src/main/java/com/topdraw/iptvlaunchertest/HttpDownloader.java
→
app/src/main/java/com/topdraw/iptvlaunchertest/
sky/
HttpDownloader.java
View file @
0d19e52
package
com
.
topdraw
.
iptvlaunchertest
;
package
com
.
topdraw
.
iptvlaunchertest
.
sky
;
import
android.util.Log
;
...
...
app/src/main/java/com/topdraw/iptvlaunchertest/InstallResultReceiver.java
→
app/src/main/java/com/topdraw/iptvlaunchertest/
sky/
InstallResultReceiver.java
View file @
0d19e52
package
com
.
topdraw
.
iptvlaunchertest
;
package
com
.
topdraw
.
iptvlaunchertest
.
sky
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
...
...
app/src/main/java/com/topdraw/iptvlaunchertest/STBAppManager.java
→
app/src/main/java/com/topdraw/iptvlaunchertest/
sky/
STBAppManager.java
View file @
0d19e52
package
com
.
topdraw
.
iptvlaunchertest
;
package
com
.
topdraw
.
iptvlaunchertest
.
sky
;
import
android.content.Context
;
import
android.content.Intent
;
...
...
app/src/main/java/com/topdraw/iptvlaunchertest/TaskExecutor.java
→
app/src/main/java/com/topdraw/iptvlaunchertest/
sky/
TaskExecutor.java
View file @
0d19e52
package
com
.
topdraw
.
iptvlaunchertest
;
package
com
.
topdraw
.
iptvlaunchertest
.
sky
;
import
android.os.Handler
;
import
android.os.Looper
;
...
...
gradle/libs.versions.toml
View file @
0d19e52
...
...
@@ -3,7 +3,7 @@ agp = "8.6.1"
junit
=
"4.13.2"
junitVersion
=
"1.2.1"
espressoCore
=
"3.6.1"
appcompat
=
"1.
7
.0"
appcompat
=
"1.
2
.0"
material
=
"1.12.0"
activity
=
"1.9.1"
constraintlayout
=
"2.1.4"
...
...
Please
register
or
sign in
to post a comment