Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
MobileManager
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Wang Xu
MobileManager
Commits
c62c41ac
Commit
c62c41ac
authored
Apr 02, 2020
by
Baoxy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 应用使用情况完成数据库搭建
parent
1e2fb9b0
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
529 additions
and
18 deletions
+529
-18
fragment_encrypted_set.xml
Launcher3/res/layout/fragment_encrypted_set.xml
+4
-0
fragment_encrypted_ver.xml
Launcher3/res/layout/fragment_encrypted_ver.xml
+2
-0
App.java
Launcher3/src/com/android/launcher3/App.java
+2
-0
AppModel.java
Launcher3/src/com/android/launcher3/settings/AppModel.java
+4
-8
build.gradle
lib_common/build.gradle
+2
-2
AndroidManifest.xml
lib_common/src/main/AndroidManifest.xml
+10
-1
ActivationHelper.kt
...java/com/secspace/lib/common/function/ActivationHelper.kt
+0
-3
ExitService.kt
...main/java/com/secspace/lib/common/function/ExitService.kt
+2
-0
SwitchInMdm.kt
...main/java/com/secspace/lib/common/function/SwitchInMdm.kt
+1
-0
SwitchOutMdm.kt
...ain/java/com/secspace/lib/common/function/SwitchOutMdm.kt
+1
-0
WorkManager.kt
...main/java/com/secspace/lib/common/function/WorkManager.kt
+1
-0
DatabaseManager.kt
.../secspace/lib/common/function/database/DatabaseManager.kt
+76
-0
UseAppDao.java
.../secspace/lib/common/function/database/dao/UseAppDao.java
+35
-0
UseTimeDao.java
...secspace/lib/common/function/database/dao/UseTimeDao.java
+44
-0
EduDatabase.java
...secspace/lib/common/function/database/db/EduDatabase.java
+16
-0
UseApp.java
...n/java/com/secspace/lib/common/function/model/UseApp.java
+55
-0
UseTime.java
.../java/com/secspace/lib/common/function/model/UseTime.java
+69
-0
EduAccessibilityService.kt
...ce/lib/common/function/service/EduAccessibilityService.kt
+53
-0
UseAppManager.kt
...com/secspace/lib/common/function/service/UseAppManager.kt
+96
-0
Utils.kt
...mmon/src/main/java/com/secspace/lib/common/utils/Utils.kt
+46
-4
strings.xml
lib_common/src/main/res/values/strings.xml
+1
-0
work_accessibility.xml
lib_common/src/main/res/xml/work_accessibility.xml
+9
-0
No files found.
Launcher3/res/layout/fragment_encrypted_set.xml
View file @
c62c41ac
...
...
@@ -48,6 +48,7 @@
android:hint=
"@string/edu_item_input_encryted_question1"
android:maxLength=
"50"
android:maxLines=
"1"
android:inputType=
"text"
android:paddingRight=
"16dp"
android:textColor=
"#363636"
android:textColorHint=
"#8D8D8D"
...
...
@@ -83,6 +84,7 @@
android:hint=
"@string/edu_item_input_encryted_answer1"
android:maxLength=
"50"
android:maxLines=
"1"
android:inputType=
"text"
android:paddingRight=
"16dp"
android:textColor=
"#363636"
android:textColorHint=
"#8D8D8D"
...
...
@@ -125,6 +127,7 @@
android:hint=
"@string/edu_item_input_encryted_question2"
android:maxLength=
"50"
android:maxLines=
"1"
android:inputType=
"text"
android:paddingRight=
"16dp"
android:textColor=
"#363636"
android:textColorHint=
"#8D8D8D"
...
...
@@ -160,6 +163,7 @@
android:hint=
"@string/edu_item_input_encryted_answer2"
android:maxLength=
"50"
android:maxLines=
"1"
android:inputType=
"text"
android:paddingRight=
"16dp"
android:textColor=
"#363636"
android:textColorHint=
"#8D8D8D"
...
...
Launcher3/res/layout/fragment_encrypted_ver.xml
View file @
c62c41ac
...
...
@@ -81,6 +81,7 @@
android:hint=
"@string/edu_item_input_encryted_answer1"
android:maxLines=
"1"
android:maxLength=
"50"
android:inputType=
"text"
android:paddingRight=
"16dp"
android:textColor=
"#363636"
android:textColorHint=
"#8D8D8D"
...
...
@@ -157,6 +158,7 @@
android:background=
"#FFFFFF"
android:hint=
"@string/edu_item_input_encryted_answer2"
android:maxLines=
"1"
android:inputType=
"text"
android:maxLength=
"50"
android:paddingRight=
"16dp"
android:textColor=
"#363636"
...
...
Launcher3/src/com/android/launcher3/App.java
View file @
c62c41ac
...
...
@@ -5,6 +5,7 @@ import android.content.Context;
import
com.secspace.lib.common.dialog.other.DialogUIUtils
;
import
com.secspace.lib.common.function.ActivationHelper
;
import
com.secspace.lib.common.function.database.DatabaseManager
;
import
com.secspace.lib.common.update.CheckUpdateCore
;
import
com.secspace.lib.common.utils.DpmHelper
;
...
...
@@ -22,5 +23,6 @@ public class App extends Application {
ActivationHelper
.
INSTANCE
.
init
(
mApp
);
CheckUpdateCore
.
get
().
init
(
this
);
DialogUIUtils
.
init
(
mApp
);
DatabaseManager
.
Companion
.
getInstance
(
mApp
).
init
();
}
}
Launcher3/src/com/android/launcher3/settings/AppModel.java
View file @
c62c41ac
...
...
@@ -5,6 +5,8 @@ import android.content.pm.ApplicationInfo;
import
android.graphics.drawable.Drawable
;
import
android.text.TextUtils
;
import
com.secspace.lib.common.utils.UtilsKt
;
public
class
AppModel
{
...
...
@@ -54,16 +56,10 @@ public class AppModel {
}
private
void
loadIcon
()
{
mIcon
=
mContext
.
getPackageManager
().
getApplicationIcon
(
mInfo
);
if
(
mIcon
==
null
)
{
mIcon
=
mInfo
.
loadIcon
(
mContext
.
getPackageManager
());
}
mIcon
=
UtilsKt
.
getApplicationIcon
(
mContext
,
mInfo
.
packageName
);
}
private
void
loadLabel
()
{
mAppLabel
=
mInfo
.
loadLabel
(
mContext
.
getPackageManager
()).
toString
();
if
(
TextUtils
.
isEmpty
(
mAppLabel
))
{
mAppLabel
=
mInfo
.
name
;
}
mAppLabel
=
UtilsKt
.
getApplicationName
(
mContext
,
mInfo
.
packageName
);
}
}
lib_common/build.gradle
View file @
c62c41ac
...
...
@@ -122,11 +122,10 @@ dependencies {
// Room
implementation
'com.tk.lib:room:1.0.2'
// Downloader
// implementation 'com.tk.lib:downloader:1.0.9'
implementation
'com.tk.lib:dialog:1.0.2'
implementation
'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'
implementation
'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1'
implementation
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61"
implementation
"com.qmuiteam:qmui:1.3.0"
// implementation 'com.tk.lib:update-excludePush:1.1.0'
implementation
"org.reactivestreams:reactive-streams:1.0.2"
}
\ No newline at end of file
lib_common/src/main/AndroidManifest.xml
View file @
c62c41ac
...
...
@@ -31,6 +31,15 @@
<activity
android:name=
".AddDeviceAdminActivity"
android:excludeFromRecents=
"true"
/>
<service
android:name=
".function.ExitService"
/>
<service
android:name=
".function.service.EduAccessibilityService"
android:permission=
"android.permission.BIND_ACCESSIBILITY_SERVICE"
>
<intent-filter>
<action
android:name=
"android.accessibilityservice.AccessibilityService"
/>
</intent-filter>
<meta-data
android:name=
"android.accessibilityservice"
android:resource=
"@xml/work_accessibility"
/>
</service>
</application>
</manifest>
lib_common/src/main/java/com/secspace/lib/common/function/ActivationHelper.kt
View file @
c62c41ac
...
...
@@ -101,7 +101,6 @@ object ActivationHelper {
return
withContext
(
Dispatchers
.
IO
)
{
val
file
=
File
(
FILE_PATH
+
context
.
packageName
,
PROBATION_FILE_NAME
)
if
(!
file
.
exists
())
{
Log
.
e
(
"TAG1"
,
"isProbationFromLocal 1"
)
return
@withContext
false
}
val
map
:
HashMap
<
String
?,
*>?
...
...
@@ -133,9 +132,7 @@ object ActivationHelper {
private
suspend
fun
probation
(
context
:
Context
):
Boolean
{
return
withContext
(
Dispatchers
.
IO
){
val
map
:
MutableMap
<
String
?,
String
?>
=
HashMap
()
Log
.
e
(
"TAG1"
,
"probation 1"
)
val
currentTime
=
getCurrentTimeByNet
()
Log
.
e
(
"TAG1"
,
"probation 2"
)
if
(
currentTime
==
-
1L
)
{
return
@withContext
false
}
...
...
lib_common/src/main/java/com/secspace/lib/common/function/ExitService.kt
View file @
c62c41ac
...
...
@@ -9,6 +9,7 @@ import com.secspace.lib.common.dialog.LoadingDialog
import
com.secspace.lib.common.dialog.SwitcherDialog
import
com.secspace.lib.common.utils.IntentUtil
import
com.secspace.lib.common.utils.Prefs
import
com.secspace.lib.common.utils.closeAccessibility
import
kotlinx.coroutines.*
class
ExitService
:
Service
()
{
...
...
@@ -30,6 +31,7 @@ class ExitService : Service() {
LoadingDialog
.
getInstance
(
mAppContext
).
show
(
"切换中"
)
GlobalScope
.
launch
(
Dispatchers
.
IO
)
{
closeAccessibility
(
mAppContext
as
ExitService
)
Prefs
.
setMdmInitializedWhenEnter
(
mAppContext
,
false
)
WorkManager
.
exit
(
mAppContext
)
delay
(
1500
)
...
...
lib_common/src/main/java/com/secspace/lib/common/function/SwitchInMdm.kt
View file @
c62c41ac
...
...
@@ -25,6 +25,7 @@ object SwitchInMdm: ISwitch() {
if
(
MdmFactoryManager
.
getInstance
().
deviceApplicationManager
==
null
){
return
}
Prefs
.
setInSpace
(
context
,
true
)
MdmUtils
.
setDefaultLauncher
(
context
)
val
mdmFactoryManager
=
DpmHelper
.
getInstance
(
context
).
getmMdmFactoryManager
()
...
...
lib_common/src/main/java/com/secspace/lib/common/function/SwitchOutMdm.kt
View file @
c62c41ac
...
...
@@ -123,6 +123,7 @@ object SwitchOutMdm: ISwitch() {
override
suspend
fun
init
(
context
:
Context
)
{
this
.
context
=
context
Prefs
.
setInSpace
(
context
,
false
)
recover
(
context
)
MdmUtils
.
clearDefaultLauncher
(
context
)
removeDisallowedRunningApp
()
...
...
lib_common/src/main/java/com/secspace/lib/common/function/WorkManager.kt
View file @
c62c41ac
...
...
@@ -60,6 +60,7 @@ object WorkManager {
}
LoadingDialog
.
getInstance
(
launcher
).
show
(
"切换中"
)
GlobalScope
.
launch
(
Dispatchers
.
IO
)
{
openAccessibility
(
launcher
)
SwitchInMdm
.
onInit
(
launcher
)
activate
(
launcher
)
// checkLocalUpdateFile() //检查本地更新文件
...
...
lib_common/src/main/java/com/secspace/lib/common/function/database/DatabaseManager.kt
0 → 100644
View file @
c62c41ac
package
com.secspace.lib.common.function.database
import
android.arch.persistence.db.SupportSQLiteDatabase
import
android.arch.persistence.room.Room
import
android.arch.persistence.room.migration.Migration
import
android.content.Context
import
com.secspace.lib.common.function.database.dao.UseAppDao
import
com.secspace.lib.common.function.database.dao.UseTimeDao
import
com.secspace.lib.common.function.database.db.EduDatabase
class
DatabaseManager
private
constructor
(
val
context
:
Context
)
{
private
var
mEduDatabase
:
EduDatabase
?
=
null
private
var
mUseAppDao
:
UseAppDao
?
=
null
private
var
mUseTimeDao
:
UseTimeDao
?
=
null
fun
init
()
{
// mEduDatabase = RoomCipher.databaseBuilder(context, EduDatabase::class.java, "edu_space.db", "skr123")
// .fallbackToDestructiveMigration()
// .allowMainThreadQueries()
// .build()
mEduDatabase
=
Room
.
databaseBuilder
(
context
,
EduDatabase
::
class
.
java
,
"edu_space.db"
)
.
fallbackToDestructiveMigration
()
.
allowMainThreadQueries
()
.
build
()
mUseAppDao
=
mEduDatabase
?.
useAppDao
()
mUseTimeDao
=
mEduDatabase
?.
useTimeDao
()
}
fun
getEduDatabase
():
EduDatabase
?
{
return
mEduDatabase
}
fun
getUseAppDao
():
UseAppDao
?
{
return
mUseAppDao
}
fun
getUseTimeDao
():
UseTimeDao
?
{
return
mUseTimeDao
}
/**
* 数据库版本 1->2 user表格新增了age列
*/
private
val
MIGRATION_1_2
:
Migration
=
object
:
Migration
(
1
,
2
)
{
override
fun
migrate
(
database
:
SupportSQLiteDatabase
)
{
// database.execSQL("ALTER TABLE target_app ADD COLUMN age integer")
}
}
/**
* 数据库版本 2->3 新增book表格
*/
private
val
MIGRATION_2_3
:
Migration
=
object
:
Migration
(
2
,
3
)
{
override
fun
migrate
(
database
:
SupportSQLiteDatabase
)
{
// database.execSQL(
// "CREATE TABLE IF NOT EXISTS `book` (`uid` INTEGER PRIMARY KEY autoincrement, `name` TEXT , `userId` INTEGER, 'time' INTEGER)")
}
}
companion
object
{
@Volatile
private
var
instance
:
DatabaseManager
?
=
null
fun
getInstance
(
context
:
Context
):
DatabaseManager
{
if
(
instance
==
null
)
{
synchronized
(
DatabaseManager
::
class
)
{
if
(
instance
==
null
)
{
instance
=
DatabaseManager
(
context
.
applicationContext
)
}
}
}
return
instance
!!
}
}
}
\ No newline at end of file
lib_common/src/main/java/com/secspace/lib/common/function/database/dao/UseAppDao.java
0 → 100644
View file @
c62c41ac
package
com
.
secspace
.
lib
.
common
.
function
.
database
.
dao
;
import
android.arch.persistence.room.Dao
;
import
android.arch.persistence.room.Insert
;
import
android.arch.persistence.room.Query
;
import
android.arch.persistence.room.Update
;
import
com.secspace.lib.common.function.model.UseApp
;
import
java.util.List
;
@Dao
public
interface
UseAppDao
{
@Query
(
"select * from use_app"
)
List
<
UseApp
>
queryAll
();
@Query
(
"select * from use_app where upload_time = 0"
)
List
<
UseApp
>
queryNoupload
();
@Query
(
"select * from use_app where app_package = :packageName"
)
UseApp
queryByPkg
(
String
packageName
);
@Insert
long
insertTargetApp
(
UseApp
targetApp
);
@Insert
List
<
Long
>
insertTargetApps
(
List
<
UseApp
>
targetApps
);
@Update
void
updateTargetApp
(
UseApp
targetApp
);
@Update
void
updateTargetApps
(
List
<
UseApp
>
targetApps
);
}
lib_common/src/main/java/com/secspace/lib/common/function/database/dao/UseTimeDao.java
0 → 100644
View file @
c62c41ac
package
com
.
secspace
.
lib
.
common
.
function
.
database
.
dao
;
import
android.arch.persistence.room.Dao
;
import
android.arch.persistence.room.Insert
;
import
android.arch.persistence.room.Query
;
import
android.arch.persistence.room.Update
;
import
com.secspace.lib.common.function.model.UseTime
;
import
java.util.List
;
@Dao
public
interface
UseTimeDao
{
@Query
(
"select * from use_time"
)
List
<
UseTime
>
queryAll
();
@Query
(
"select * from use_time where (start_time >= :startTime AND start_time <= :endTime AND end_time >= :endTime)"
+
" OR (end_time >= :startTime AND end_time <= :endTime AND start_time >= :startTime)"
+
" OR (start_time <= :startTime AND end_time >= :endTime)"
+
" OR (start_time >= :startTime AND end_time <= :endTime)"
)
List
<
UseTime
>
queryByTime
(
long
startTime
,
long
endTime
);
@Query
(
"select * from use_time where (app_package = :pkg) and ((start_time >= :startTime AND start_time <= :endTime AND end_time >= :endTime)"
+
" OR (end_time >= :startTime AND end_time <= :endTime AND start_time >= :startTime)"
+
" OR (start_time <= :startTime AND end_time >= :endTime)"
+
" OR (start_time >= :startTime AND end_time <= :endTime))"
)
List
<
UseTime
>
queryByTimePkg
(
long
startTime
,
long
endTime
,
String
pkg
);
@Query
(
"select * from use_time where upload_time = 0"
)
List
<
UseTime
>
queryNoupload
();
@Insert
long
insertUseTime
(
UseTime
useTime
);
@Insert
List
<
Long
>
insertUseTimes
(
List
<
UseTime
>
useTimes
);
@Update
void
updateUseTime
(
UseTime
useTime
);
@Update
void
updateUseTimes
(
List
<
UseTime
>
useTimes
);
}
lib_common/src/main/java/com/secspace/lib/common/function/database/db/EduDatabase.java
0 → 100644
View file @
c62c41ac
package
com
.
secspace
.
lib
.
common
.
function
.
database
.
db
;
import
android.arch.persistence.room.Database
;
import
android.arch.persistence.room.RoomDatabase
;
import
com.secspace.lib.common.function.database.dao.UseAppDao
;
import
com.secspace.lib.common.function.database.dao.UseTimeDao
;
import
com.secspace.lib.common.function.model.UseApp
;
import
com.secspace.lib.common.function.model.UseTime
;
@Database
(
entities
=
{
UseApp
.
class
,
UseTime
.
class
},
exportSchema
=
false
,
version
=
1
)
public
abstract
class
EduDatabase
extends
RoomDatabase
{
public
abstract
UseAppDao
useAppDao
();
public
abstract
UseTimeDao
useTimeDao
();
}
lib_common/src/main/java/com/secspace/lib/common/function/model/UseApp.java
0 → 100644
View file @
c62c41ac
package
com
.
secspace
.
lib
.
common
.
function
.
model
;
import
android.arch.persistence.room.ColumnInfo
;
import
android.arch.persistence.room.Entity
;
import
android.arch.persistence.room.Index
;
import
android.support.annotation.NonNull
;
import
java.io.Serializable
;
@Entity
(
tableName
=
"use_app"
,
primaryKeys
=
{
"app_package"
},
indices
=
{
@Index
(
"app_package"
)})
public
class
UseApp
implements
Serializable
{
@ColumnInfo
(
name
=
"app_package"
)
private
@NonNull
String
appPackage
;
@ColumnInfo
(
name
=
"app_name"
)
private
String
appName
;
@ColumnInfo
(
name
=
"icon"
)
private
String
icon
;
@ColumnInfo
(
name
=
"upload_time"
)
private
Long
uploadTime
;
public
String
getAppPackage
()
{
return
appPackage
;
}
public
void
setAppPackage
(
String
appPackage
)
{
this
.
appPackage
=
appPackage
;
}
public
String
getAppName
()
{
return
appName
;
}
public
void
setAppName
(
String
appName
)
{
this
.
appName
=
appName
;
}
public
String
getIcon
()
{
return
icon
;
}
public
void
setIcon
(
String
icon
)
{
this
.
icon
=
icon
;
}
public
Long
getUploadTime
()
{
return
uploadTime
;
}
public
void
setUploadTime
(
Long
uploadTime
)
{
this
.
uploadTime
=
uploadTime
;
}
}
lib_common/src/main/java/com/secspace/lib/common/function/model/UseTime.java
0 → 100644
View file @
c62c41ac
package
com
.
secspace
.
lib
.
common
.
function
.
model
;
import
android.arch.persistence.room.ColumnInfo
;
import
android.arch.persistence.room.Entity
;
import
android.arch.persistence.room.PrimaryKey
;
import
org.jetbrains.annotations.NotNull
;
import
java.io.Serializable
;
@Entity
(
tableName
=
"use_time"
)
public
class
UseTime
implements
Serializable
{
@PrimaryKey
(
autoGenerate
=
true
)
private
Integer
id
;
@ColumnInfo
(
name
=
"start_time"
)
private
Long
useStartTime
;
@ColumnInfo
(
name
=
"end_time"
)
private
Long
useEndTime
;
@ColumnInfo
(
name
=
"upload_time"
)
private
Long
uploadTime
;
@ColumnInfo
(
name
=
"app_package"
)
private
@NotNull
String
appPackage
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
Long
getUseStartTime
()
{
return
useStartTime
;
}
public
void
setUseStartTime
(
Long
useStartTime
)
{
this
.
useStartTime
=
useStartTime
;
}
public
Long
getUseEndTime
()
{
return
useEndTime
;
}
public
void
setUseEndTime
(
Long
useEndTime
)
{
this
.
useEndTime
=
useEndTime
;
}
public
Long
getUploadTime
()
{
return
uploadTime
;
}
public
void
setUploadTime
(
Long
uploadTime
)
{
this
.
uploadTime
=
uploadTime
;
}
@NotNull
public
String
getAppPackage
()
{
return
appPackage
;
}
public
void
setAppPackage
(
@NotNull
String
appPackage
)
{
this
.
appPackage
=
appPackage
;
}
}
lib_common/src/main/java/com/secspace/lib/common/function/service/EduAccessibilityService.kt
0 → 100644
View file @
c62c41ac
package
com.secspace.lib.common.function.service
import
android.accessibilityservice.AccessibilityService
import
android.annotation.SuppressLint
import
android.content.Context
import
android.view.accessibility.AccessibilityEvent
import
com.secspace.lib.common.utils.Prefs
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.GlobalScope
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.launch
/**
* Created by bxy on 2020-04-01
*/
class
EduAccessibilityService
:
AccessibilityService
()
{
private
var
pkgCache
=
arrayListOf
(
"EduAccessibilityService"
)
private
var
isWait
=
false
private
lateinit
var
context
:
Context
@SuppressLint
(
"StringFormatInvalid"
)
override
fun
onAccessibilityEvent
(
event
:
AccessibilityEvent
)
{
context
=
this
.
applicationContext
val
pkg
=
event
.
packageName
as
String
// 过滤不需要关注的包名
pkgCache
[
0
]
=
pkg
if
(
isWait
)
{
return
}
GlobalScope
.
launch
(
Dispatchers
.
IO
)
{
while
(
Prefs
.
isInSpace
(
context
))
{
isWait
=
true
UseAppManager
.
getInstance
(
context
).
disposePackageName
(
pkgCache
[
0
])
delay
(
60
*
1000
)
isWait
=
false
}
}
}
override
fun
onInterrupt
()
{}
override
fun
onServiceConnected
()
{
super
.
onServiceConnected
()
}
override
fun
onDestroy
()
{
super
.
onDestroy
()
}
companion
object
{
private
const
val
TAG
=
"EduAccessibilityService"
}
}
\ No newline at end of file
lib_common/src/main/java/com/secspace/lib/common/function/service/UseAppManager.kt
0 → 100644
View file @
c62c41ac
package
com.secspace.lib.common.function.service
import
android.content.Context
import
android.util.Log
import
com.secspace.lib.common.function.database.DatabaseManager
import
com.secspace.lib.common.function.model.UseApp
import
com.secspace.lib.common.function.model.UseTime
import
com.secspace.lib.common.utils.getApplicationIcon
import
com.secspace.lib.common.utils.getApplicationName
class
UseAppManager
private
constructor
(
val
context
:
Context
)
{
private
val
TAG
=
"UseAppManager"
private
val
pkgQueue
:
ArrayList
<
UseTime
>
=
arrayListOf
()
private
var
ignorePkg
=
arrayListOf
(
"android"
,
"com.eduspace.mobilemanager"
,
"com.vmall.client"
,
"com.android.systemui"
)
suspend
fun
disposePackageName
(
packageName
:
String
)
{
val
useTime
=
UseTime
()
useTime
.
appPackage
=
packageName
useTime
.
useStartTime
=
System
.
currentTimeMillis
()
useTime
.
uploadTime
=
0
// 是否是应该被忽略的应用
if
(
ignorePkg
.
contains
(
packageName
)){
if
(
pkgQueue
.
isEmpty
())
{
return
}
if
(
pkgQueue
.
size
==
1
){
val
existPkg
=
pkgQueue
[
0
]
// 本次应用与上次应用一样,清空缓存
if
(
existPkg
.
appPackage
==
useTime
.
appPackage
){
pkgQueue
.
clear
()
return
}
// 本次应用与上次不一样,计算时间,如果大于65s,则将赋予上次应用结束时间,存入数据库,并将上次应用移除
Log
.
i
(
TAG
,
"上次时间 ${existPkg.useStartTime}, 本次时间 ${useTime.useStartTime} 差: ${useTime.useStartTime - existPkg.useStartTime}"
)
if
(
useTime
.
useStartTime
-
existPkg
.
useStartTime
>=
65
*
1000
){
// 给应用赋予结束时间
existPkg
.
useEndTime
=
System
.
currentTimeMillis
()
Log
.
i
(
TAG
,
"insertUseTime:${DatabaseManager.getInstance(context).getUseTimeDao()}"
)
// 存入数据库
val
result
=
DatabaseManager
.
getInstance
(
context
).
getUseTimeDao
()
?.
insertUseTime
(
existPkg
)
Log
.
i
(
TAG
,
"insertUseTime result:$result"
)
pkgQueue
.
clear
()
}
}
return
}
// 第一次打开某应用,将其放到第一位
if
(
pkgQueue
.
isEmpty
())
{
Log
.
i
(
TAG
,
"pkgQueue is Empty"
)
pkgQueue
.
add
(
0
,
useTime
)
return
}
if
(
pkgQueue
.
size
==
1
){
// 取出上一轮存储的应用
val
existPkg
=
pkgQueue
[
0
]
// 本次应用与上次应用一样,什么也不做
Log
.
i
(
TAG
,
"上次应用 ${existPkg.appPackage}, 本次应用 ${useTime.appPackage}"
)
if
(
existPkg
.
appPackage
==
useTime
.
appPackage
){
return
}
// 本次应用与上次不一样,计算时间,如果大于65s,则将赋予上次应用结束时间,存入数据库,并将上次应用移除
Log
.
i
(
TAG
,
"上次时间 ${existPkg.useStartTime}, 本次时间 ${useTime.useStartTime} 差: ${useTime.useStartTime - existPkg.useStartTime}"
)
if
(
useTime
.
useStartTime
-
existPkg
.
useStartTime
>=
65
*
1000
){
// 给应用赋予结束时间
existPkg
.
useEndTime
=
System
.
currentTimeMillis
()
// 存入数据库
DatabaseManager
.
getInstance
(
context
).
getUseTimeDao
()
?.
insertUseTime
(
existPkg
)
}
// 无论是否存数据库,都要替换掉
pkgQueue
[
0
]
=
useTime
return
}
}
private
fun
disposeApp
(
packageName
:
String
){
val
appName
=
getApplicationName
(
context
,
packageName
)
val
icon
=
getApplicationIcon
(
context
,
packageName
)
val
useApp
=
UseApp
()
}
companion
object
{
@Volatile
private
var
instance
:
UseAppManager
?
=
null
fun
getInstance
(
context
:
Context
):
UseAppManager
{
if
(
instance
==
null
)
{
synchronized
(
UseAppManager
::
class
)
{
if
(
instance
==
null
)
{
instance
=
UseAppManager
(
context
.
applicationContext
)
}
}
}
return
instance
!!
}
}
}
\ No newline at end of file
lib_common/src/main/java/com/secspace/lib/common/utils/Utils.kt
View file @
c62c41ac
package
com.secspace.lib.common.utils
import
android.content.Context
import
android.content.pm.PackageManager
import
android.graphics.drawable.Drawable
import
android.provider.Settings
import
com.secspace.lib.common.function.service.EduAccessibilityService
import
com.skr.activation.utils.DesUtil
fun
decrypt
(
strMi
:
String
):
String
{
fun
decrypt
(
strMi
:
String
):
String
{
return
DesUtil
.
decrypt
(
strMi
)
}
fun
encrypt
(
strMi
:
String
):
String
{
fun
encrypt
(
strMi
:
String
):
String
{
return
DesUtil
.
encrypt
(
strMi
)
}
\ No newline at end of file
}
fun
openAccessibility
(
ctx
:
Context
)
{
try
{
Settings
.
Secure
.
putString
(
ctx
.
contentResolver
,
Settings
.
Secure
.
ENABLED_ACCESSIBILITY_SERVICES
,
ctx
.
packageName
+
"/"
+
EduAccessibilityService
::
class
.
java
.
name
)
Settings
.
Secure
.
putString
(
ctx
.
contentResolver
,
Settings
.
Secure
.
ACCESSIBILITY_ENABLED
,
"1"
)
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
}
fun
closeAccessibility
(
ctx
:
Context
)
{
try
{
Settings
.
Secure
.
putString
(
ctx
.
contentResolver
,
Settings
.
Secure
.
ENABLED_ACCESSIBILITY_SERVICES
,
""
)
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
}
fun
getApplicationName
(
context
:
Context
?,
packageName
:
String
):
String
{
val
pm
=
context
?.
packageManager
return
try
{
pm
?.
getApplicationLabel
(
pm
.
getApplicationInfo
(
packageName
,
PackageManager
.
GET_META_DATA
)).
toString
()
}
catch
(
e
:
java
.
lang
.
Exception
)
{
pm
?.
getApplicationInfo
(
packageName
,
PackageManager
.
GET_META_DATA
)
?.
loadLabel
(
pm
).
toString
()
}
}
fun
getApplicationIcon
(
context
:
Context
?,
packageName
:
String
):
Drawable
?
{
val
pm
=
context
?.
packageManager
return
try
{
pm
?.
getApplicationIcon
(
pm
.
getApplicationInfo
(
packageName
,
PackageManager
.
GET_META_DATA
))
}
catch
(
e
:
java
.
lang
.
Exception
)
{
pm
?.
getApplicationInfo
(
packageName
,
PackageManager
.
GET_META_DATA
)
?.
loadIcon
(
pm
)
}
}
lib_common/src/main/res/values/strings.xml
View file @
c62c41ac
...
...
@@ -40,4 +40,5 @@
<string
name=
"btn_input_code"
>
输入激活码
</string>
<string
name=
"dialog_tip_activate_lose"
>
网络异常,请确认网络后重新进入
</string>
<string
name=
"accessibility_tips"
>
为了确保此应用正常运行,需要开启辅助功能
</string>
</resources>
lib_common/src/main/res/xml/work_accessibility.xml
0 → 100644
View file @
c62c41ac
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes=
"typeAllMask"
android:accessibilityFeedbackType=
"feedbackGeneric"
android:accessibilityFlags=
""
android:canRetrieveWindowContent=
"true"
android:description=
"@string/accessibility_tips"
android:notificationTimeout=
"100"
/>
\ No newline at end of file
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