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
93a4dece
Commit
93a4dece
authored
Aug 12, 2019
by
huangzhencheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:修改列表页选中问题,完成wifi白名单需求
parent
a5af3646
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
1161 additions
and
153 deletions
+1161
-153
misc.xml
.idea/misc.xml
+1
-1
AndroidManifest-common.xml
Launcher3/AndroidManifest-common.xml
+6
-0
AndroidManifest.xml
Launcher3/AndroidManifest.xml
+7
-1
build.gradle
Launcher3/build.gradle
+15
-0
activity_wifi_white_list.xml
Launcher3/res/layout/activity_wifi_white_list.xml
+13
-1
item_add_wifi_white.xml
Launcher3/res/layout/item_add_wifi_white.xml
+24
-0
item_wifi_white_list.xml
Launcher3/res/layout/item_wifi_white_list.xml
+51
-0
colors.xml
Launcher3/res/values/colors.xml
+1
-0
Launcher.java
Launcher3/src/com/android/launcher3/Launcher.java
+73
-2
AppChooseActivity.java
...src/com/android/launcher3/settings/AppChooseActivity.java
+3
-2
AppChooseListAdapter.java
.../com/android/launcher3/settings/AppChooseListAdapter.java
+84
-95
Prefs.java
Launcher3/src/com/android/launcher3/settings/Prefs.java
+14
-0
SettingActivity.java
...3/src/com/android/launcher3/settings/SettingActivity.java
+86
-31
String2ListHelper.java
...src/com/android/launcher3/settings/String2ListHelper.java
+7
-1
Gson2ListHelper.java
.../com/android/launcher3/settings/wifi/Gson2ListHelper.java
+25
-0
NetworkConnectChangedReceiver.java
...auncher3/settings/wifi/NetworkConnectChangedReceiver.java
+116
-0
WifiAutoConnectManager.java
...droid/launcher3/settings/wifi/WifiAutoConnectManager.java
+204
-0
WifiInfo.java
...er3/src/com/android/launcher3/settings/wifi/WifiInfo.java
+0
-4
WifiInfoBean.java
...src/com/android/launcher3/settings/wifi/WifiInfoBean.java
+41
-0
WifiManagerUtils.java
...com/android/launcher3/settings/wifi/WifiManagerUtils.java
+117
-0
WifiScanService.java
.../com/android/launcher3/settings/wifi/WifiScanService.java
+78
-0
WifiWhiteListActivity.java
...ndroid/launcher3/settings/wifi/WifiWhiteListActivity.java
+157
-13
WifiWhiteListAdapter.java
...android/launcher3/settings/wifi/WifiWhiteListAdapter.java
+38
-2
No files found.
.idea/misc.xml
View file @
93a4dece
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
8
"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
7
"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<output
url=
"file://$PROJECT_DIR$/build/classes"
/>
</component>
<component
name=
"ProjectType"
>
...
...
Launcher3/AndroidManifest-common.xml
View file @
93a4dece
...
...
@@ -45,6 +45,9 @@
<uses-permission
android:name=
"android.permission.RECEIVE_BOOT_COMPLETED"
/>
<uses-permission
android:name=
"android.permission.WRITE_EXTERNAL_STORAGE"
/>
<uses-permission
android:name=
"android.permission.ACCESS_WIFI_STATE"
/>
<uses-permission
android:name=
"android.permission.CHANGE_WIFI_STATE"
/>
<uses-permission
android:name=
"android.permission.READ_PHONE_STATE"
/>
<uses-permission
android:name=
"android.permission.ACCESS_NETWORK_STATE"
/>
<application
android:backupAgent=
"com.android.launcher3.LauncherBackupAgent"
...
...
@@ -124,6 +127,9 @@
android:name=
".settings.wifi.WifiWhiteListActivity"
android:excludeFromRecents=
"true"
android:theme=
"@style/AppTheme"
/>
<service
android:name=
".settings.wifi.WifiScanService"
android:enabled=
"true"
android:exported=
"true"
/>
<!--
Should point to the content provider which can be used to dump Launcher3 compatible
...
...
Launcher3/AndroidManifest.xml
View file @
93a4dece
...
...
@@ -5,6 +5,7 @@
<uses-sdk
android:minSdkVersion=
"21"
android:targetSdkVersion=
"23"
/>
<!--
Manifest entries specific to Launcher3. This is merged with AndroidManifest-common.xml.
Refer comments around specific entries on how to extend individual components.
...
...
@@ -43,7 +44,12 @@
android:restoreAnyVersion=
"true"
android:supportsRtl=
"true"
android:theme=
"@style/LauncherTheme"
>
<activity
android:name=
".settings.wifi.WifiWhiteListActivity"
></activity>
<service
android:name=
".settings.wifi.WifiScanService"
android:enabled=
"true"
android:exported=
"true"
></service>
<activity
android:name=
".settings.wifi.WifiWhiteListActivity"
/>
<activity
android:name=
".settings.SettingActivity"
/>
<activity
android:name=
".ManagerAuthActivity"
/>
<!--
...
...
Launcher3/build.gradle
View file @
93a4dece
...
...
@@ -52,6 +52,11 @@ android {
signingConfig
signingConfigs
.
debug
}
release
{
minifyEnabled
false
signingConfig
signingConfigs
.
debug
}
}
productFlavors
{
...
...
@@ -108,6 +113,16 @@ dependencies {
androidTestCompile
"com.android.support:support-annotations:${SUPPORT_LIBS_VERSION}"
compile
project
(
path:
':lib_common'
)
implementation
'com.secspace:provider_mdm_engine:1.0.0.32'
implementation
'com.skr:activation:1.0.1'
implementation
'io.reactivex.rxjava2:rxjava:2.0.0'
implementation
'io.reactivex.rxjava2:rxandroid:2.0.0'
implementation
'com.squareup.okhttp3:logging-interceptor:3.4.1'
implementation
'com.squareup.retrofit2:converter-gson:2.0.2'
implementation
'com.squareup.retrofit2:retrofit:2.0.2'
implementation
'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
implementation
'com.google.code.gson:gson:2.7'
implementation
'com.skr.library:DialogAct:1.0.0'
implementation
'pub.devrel:easypermissions:1.1.3'
}
...
...
Launcher3/res/layout/activity_wifi_white_list.xml
View file @
93a4dece
...
...
@@ -68,10 +68,11 @@
android:layout_weight=
"1"
></android.support.v7.widget.RecyclerView>
<LinearLayout
android:orientation=
"horizontal"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<TextView
android:layout_weight=
"1"
android:id=
"@+id/tv_add"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
...
...
@@ -80,6 +81,17 @@
android:padding=
"20dp"
android:text=
"添加"
android:textSize=
"18dp"
/>
<TextView
android:layout_weight=
"1"
android:id=
"@+id/tv_delete"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginBottom=
"20dp"
android:gravity=
"center"
android:padding=
"20dp"
android:text=
"删除"
android:textSize=
"18dp"
/>
</LinearLayout>
</LinearLayout>
Launcher3/res/layout/item_add_wifi_white.xml
0 → 100644
View file @
93a4dece
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/item_ll"
android:padding=
"20dp"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
>
<EditText
android:inputType=
"text"
android:id=
"@+id/edit_mac"
android:paddingLeft=
"20dp"
android:hint=
"请输入mac"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
<EditText
android:id=
"@+id/edit_ssid"
android:paddingLeft=
"20dp"
android:hint=
"请输入ssid"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
</LinearLayout>
\ No newline at end of file
Launcher3/res/layout/item_wifi_white_list.xml
0 → 100644
View file @
93a4dece
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<RelativeLayout
android:layout_centerVertical=
"true"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
>
<TextView
android:id=
"@+id/tv_mac_tip"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"10dp"
android:text=
"mac:"
/>
<TextView
android:id=
"@+id/tv_mac"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"10dp"
android:layout_toRightOf=
"@id/tv_mac_tip"
android:text=
"23:34:3r:rw"
/>
<TextView
android:layout_marginLeft=
"10dp"
android:id=
"@+id/tv_ssid_tip"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@id/tv_mac_tip"
android:text=
"ssid: "
/>
<TextView
android:id=
"@+id/tv_ssid"
android:layout_marginLeft=
"10dp"
android:layout_toRightOf=
"@id/tv_ssid_tip"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@id/tv_mac_tip"
android:text=
"fafsafweefsf"
/>
</RelativeLayout>
<CheckBox
android:id=
"@+id/cb_delete"
android:layout_centerVertical=
"true"
android:layout_alignParentRight=
"true"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
</RelativeLayout>
\ No newline at end of file
Launcher3/res/values/colors.xml
View file @
93a4dece
...
...
@@ -49,4 +49,5 @@
<color
name=
"legacy_icon_background"
>
#FFFFFF
</color>
<color
name=
"icon_background"
>
#E0E0E0
</color>
<!-- Gray 300 -->
<color
name=
"btn_background"
>
#A6D2F5
</color>
<!-- Gray 300 -->
</resources>
Launcher3/src/com/android/launcher3/Launcher.java
View file @
93a4dece
...
...
@@ -49,6 +49,7 @@ import android.graphics.Point;
import
android.graphics.Rect
;
import
android.graphics.drawable.BitmapDrawable
;
import
android.graphics.drawable.Drawable
;
import
android.net.wifi.WifiManager
;
import
android.net.Uri
;
import
android.os.AsyncTask
;
import
android.os.Build
;
...
...
@@ -118,6 +119,8 @@ import com.android.launcher3.popup.PopupContainerWithArrow;
import
com.android.launcher3.popup.PopupDataProvider
;
import
com.android.launcher3.settings.Prefs
;
import
com.android.launcher3.settings.String2ListHelper
;
import
com.android.launcher3.settings.wifi.NetworkConnectChangedReceiver
;
import
com.android.launcher3.settings.wifi.WifiScanService
;
import
com.android.launcher3.shortcuts.DeepShortcutManager
;
import
com.android.launcher3.shortcuts.ShortcutKey
;
import
com.android.launcher3.userevent.nano.LauncherLogProto
;
...
...
@@ -143,6 +146,8 @@ import com.secspace.lib.common.event.RefreshWorkSpaceEvent;
import
com.secspace.lib.common.utils.DpmHelper
;
import
com.secspace.lib.common.utils.FileUtil
;
import
com.secspace.mdmengine.api.manager.MdmFactoryManager
;
import
com.skr.activation.api.ActivationApi
;
import
com.skr.activation.network.linstener.CheckActiveStatusListener
;
import
org.greenrobot.eventbus.EventBus
;
import
org.greenrobot.eventbus.Subscribe
;
...
...
@@ -215,6 +220,7 @@ public class Launcher extends BaseActivity
private
static
final
String
RUNTIME_STATE_PENDING_ACTIVITY_RESULT
=
"launcher.activity_result"
;
static
final
String
APPS_VIEW_SHOWN
=
"launcher.apps_view_shown"
;
private
NetworkConnectChangedReceiver
mNetworkConnectChangedReceiver
;
static
final
String
WALLPAPER_NAME
=
"wallpaper"
;
...
...
@@ -498,7 +504,8 @@ public class Launcher extends BaseActivity
mLauncherCallbacks
.
onCreate
(
savedInstanceState
);
}
EventBus
.
getDefault
().
register
(
this
);
registerNetworkReceiver
();
ActivationApi
.
getInstance
().
init
(
getApplicationContext
(),
null
);
if
(
mWallpaperPath
!=
null
)
{
Bitmap
bitmap
=
BitmapFactory
.
decodeFile
(
mWallpaperPath
);
View
launcher
=
findViewById
(
R
.
id
.
launcher
);
...
...
@@ -514,6 +521,22 @@ public class Launcher extends BaseActivity
View
launcher
=
findViewById
(
R
.
id
.
launcher
);
launcher
.
setBackground
(
new
BitmapDrawable
(
getResources
(),
bitmap
));
}
}
private
void
registerNetworkReceiver
()
{
//wifi连接监听
mNetworkConnectChangedReceiver
=
new
NetworkConnectChangedReceiver
(
this
);
IntentFilter
filter
=
new
IntentFilter
();
filter
.
addAction
(
WifiManager
.
NETWORK_STATE_CHANGED_ACTION
);
registerReceiver
(
mNetworkConnectChangedReceiver
,
filter
);
}
private
void
unregisterNetworkReceiver
(){
if
(
mNetworkConnectChangedReceiver
!=
null
){
unregisterReceiver
(
mNetworkConnectChangedReceiver
);
}
}
@Override
...
...
@@ -1130,6 +1153,9 @@ public class Launcher extends BaseActivity
if
(
mLauncherCallbacks
!=
null
)
{
mLauncherCallbacks
.
onResume
();
}
if
(!
activeByCode
(
this
)){
return
;
}
if
(!
DpmHelper
.
getInstance
(
this
).
isMiddlewareInstalled
())
{
DpmHelper
.
getInstance
(
this
).
installMiddleWare
();
return
;
...
...
@@ -1142,7 +1168,9 @@ public class Launcher extends BaseActivity
mdmFactoryManager
.
getDeviceSettingsManager
().
setRestoreFactoryDisabled
(
true
);
mdmFactoryManager
.
getDeviceApplicationManager
().
addDisabledDeactivateMdmPackages
(
getPersistentList
());
mdmFactoryManager
.
getDeviceApplicationManager
().
addDisallowedUninstallPackages
(
getPersistentList
());
mdmFactoryManager
.
getDeviceRestrictionManager
().
setStatusBarExpandPanelDisabled
(
true
);
mdmFactoryManager
.
getDeviceRestrictionManager
().
setStatusBarExpandPanelDisabled
(
false
);
mdmFactoryManager
.
getDeviceRestrictionManager
().
setDeviceOwnerApp
(
this
.
getPackageName
());
startWifiScanService
();
if
(
Prefs
.
isAutoStartSelf
(
this
))
{
MdmUtils
.
setDefaultLauncher
(
this
);
}
else
{
...
...
@@ -1151,6 +1179,10 @@ public class Launcher extends BaseActivity
mModel
.
startLoader
(-
1001
);
}
private
void
startWifiScanService
()
{
startService
(
new
Intent
(
this
,
WifiScanService
.
class
));
}
@Subscribe
(
threadMode
=
ThreadMode
.
MAIN
,
sticky
=
true
)
public
void
refreshWorkspace
(
RefreshWorkSpaceEvent
refreshWorkSpaceEvent
){
...
...
@@ -1997,6 +2029,7 @@ public class Launcher extends BaseActivity
if
(
mLauncherCallbacks
!=
null
)
{
mLauncherCallbacks
.
onDestroy
();
}
unregisterNetworkReceiver
();
}
public
LauncherAccessibilityDelegate
getAccessibilityDelegate
()
{
...
...
@@ -4268,4 +4301,42 @@ public class Launcher extends BaseActivity
}
}
}
private
boolean
activeByCode
(
final
Context
context
){
boolean
isActivate
=
ActivationApi
.
getInstance
().
isActiveFromLocal
(
this
.
getPackageName
());
if
(!
isActivate
){
ActivationApi
.
getInstance
().
startActivateActivity
(
this
,
this
.
getPackageName
(),
false
);
}
else
{
ActivationApi
.
getInstance
().
checkActivateCodeStatus
(
this
.
getPackageName
(),
new
CheckActiveStatusListener
()
{
@Override
public
void
activedFailed
()
{
if
(!
DpmHelper
.
getInstance
(
context
).
isMiddlewareInstalled
()&&
DpmHelper
.
getInstance
(
context
).
isMiddlewareDPMActived
())
{
MdmUtils
.
clearDefaultLauncher
(
context
);
}
Launcher
.
this
.
finish
();
}
@Override
public
void
trialCodeWillPastDue
()
{
}
@Override
public
void
hasActived
()
{
}
@Override
public
void
serverError
()
{
}
@Override
public
void
onError
(
Throwable
throwable
)
{
}
});
}
return
isActivate
;
}
}
Launcher3/src/com/android/launcher3/settings/AppChooseActivity.java
View file @
93a4dece
...
...
@@ -123,12 +123,13 @@ public class AppChooseActivity extends AppCompatActivity implements LoaderManage
else
mUserApps
.
add
(
appModel
);
}
mAppInfoAdapterUserApp
.
readResult
(
getApplicationContext
());
mAppInfoAdapterSystemApp
.
readResult
(
getApplicationContext
());
mAppInfoAdapterSystemApp
.
setList
(
mSystemApps
);
mAppInfoAdapterSystemApp
.
notifyDataSetChanged
();
mAppInfoAdapterUserApp
.
setList
(
mUserApps
);
mAppInfoAdapterUserApp
.
notifyDataSetChanged
();
mAppInfoAdapterUserApp
.
readResult
(
getApplicationContext
());
mAppInfoAdapterSystemApp
.
readResult
(
getApplicationContext
());
}
@Override
...
...
Launcher3/src/com/android/launcher3/settings/AppChooseListAdapter.java
View file @
93a4dece
This diff is collapsed.
Click to expand it.
Launcher3/src/com/android/launcher3/settings/Prefs.java
View file @
93a4dece
...
...
@@ -14,6 +14,20 @@ public class Prefs {
public
static
final
String
AUTO_START_SELF
=
"auto_start_self"
;
public
static
final
String
ALLOW_NEW_APP
=
"allow_new_app"
;
public
static
final
String
WIFI_WHITE_LIST
=
"wifi_white_list"
;
/**
* 设置wifi白名单列表
* @param context
* @param stringList
*/
public
static
void
setWifiWhiteList
(
Context
context
,
String
stringList
){
putString
(
context
,
WIFI_WHITE_LIST
,
stringList
);
}
public
static
String
getWifiWhiteList
(
Context
context
){
return
getString
(
context
,
WIFI_WHITE_LIST
,
""
);
}
/**
* 获取是否允许本身是否自启
...
...
Launcher3/src/com/android/launcher3/settings/SettingActivity.java
View file @
93a4dece
...
...
@@ -4,9 +4,6 @@ import android.app.AlertDialog;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.graphics.drawable.BitmapDrawable
;
import
android.net.Uri
;
import
android.support.v7.app.AppCompatActivity
;
import
android.os.Bundle
;
...
...
@@ -15,13 +12,14 @@ import android.view.LayoutInflater;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
com.android.launcher3.BuildConfig
;
import
com.android.launcher3.Launcher
;
import
com.android.launcher3.R
;
import
com.android.launcher3.mdm.MdmUtils
;
import
com.android.launcher3.settings.wifi.WifiWhiteListActivity
;
import
com.secspace.
lib.common.utils.FileUtil
;
import
com.secspace.
mdmengine.api.manager.MdmFactoryManager
;
public
class
SettingActivity
extends
AppCompatActivity
implements
View
.
OnClickListener
{
private
static
final
int
REQUEST_PICK_WALLPAPER
=
10
;
...
...
@@ -35,21 +33,40 @@ public class SettingActivity extends AppCompatActivity implements View.OnClickLi
private
Button
mBtnAtuoStart
;
private
Button
mWifiWhiteList
;
//允许添加先安装应用
public
static
final
int
ALLOW_NEW_APP
=
0
;
public
static
final
int
ALLOW_NEW_APP
=
0
;
//允许本身自启
public
static
final
int
AUTO_START_SELF
=
1
;
public
static
final
int
AUTO_START_SELF
=
1
;
private
Context
mContext
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_setting
);
mContext
=
this
;
mContext
=
this
;
initView
();
initListener
();
initData
();
}
@Override
protected
void
onResume
()
{
super
.
onResume
();
setBtnBackground
();
}
private
void
setBtnBackground
(){
if
(
Prefs
.
isAllowNewApp
(
this
))
{
mBtnAllowNewApp
.
setBackgroundColor
(
getResources
().
getColor
(
R
.
color
.
btn_background
));
}
else
{
mBtnAllowNewApp
.
setBackgroundColor
(
getResources
().
getColor
(
R
.
color
.
notification_color_beneath
));
}
if
(
Prefs
.
isAutoStartSelf
(
this
))
{
mBtnAtuoStart
.
setBackgroundColor
(
getResources
().
getColor
(
R
.
color
.
btn_background
));
}
else
{
mBtnAtuoStart
.
setBackgroundColor
(
getResources
().
getColor
(
R
.
color
.
notification_color_beneath
));
}
}
private
void
initListener
()
{
mBtnAllowNewApp
.
setOnClickListener
(
this
);
mBtnChangePwd
.
setOnClickListener
(
this
);
...
...
@@ -67,7 +84,7 @@ public class SettingActivity extends AppCompatActivity implements View.OnClickLi
mBtnAllowNewApp
=
findViewById
(
R
.
id
.
btn_allow_new_app
);
mBtnInvisibleMenu
=
findViewById
(
R
.
id
.
btn_invisible_menu
);
mBtnAtuoStart
=
findViewById
(
R
.
id
.
btn_auto_start
);
mWifiWhiteList
=
findViewById
(
R
.
id
.
btn_wifi_whitelist
);
mWifiWhiteList
=
findViewById
(
R
.
id
.
btn_wifi_whitelist
);
findViewById
(
R
.
id
.
tv_back
).
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
...
...
@@ -81,10 +98,13 @@ public class SettingActivity extends AppCompatActivity implements View.OnClickLi
}
private
void
showPwdDialog
(
final
String
t
ext
,
final
int
type
)
{
private
void
showPwdDialog
(
final
String
t
ip
,
final
int
type
,
String
text
)
{
AlertDialog
alertDialog
;
TextView
textView
=
new
TextView
(
this
);
View
view
=
LayoutInflater
.
from
(
this
).
inflate
(
R
.
layout
.
item_ll
,
null
);
textView
.
setText
(
text
);
final
LinearLayout
ll
=
view
.
findViewById
(
R
.
id
.
item_ll
);
ll
.
addView
(
textView
);
alertDialog
=
new
AlertDialog
.
Builder
(
this
)
.
setTitle
(
"提示"
)
.
setCancelable
(
false
)
...
...
@@ -95,27 +115,55 @@ public class SettingActivity extends AppCompatActivity implements View.OnClickLi
dialog
.
dismiss
();
}
})
.
setPositiveButton
(
t
ext
,
new
DialogInterface
.
OnClickListener
()
{
.
setPositiveButton
(
t
ip
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
switch
(
type
){
switch
(
type
)
{
case
ALLOW_NEW_APP:
if
(
t
ext
.
equals
(
"打开"
))
{
Prefs
.
setAllowNewApp
(
mContext
,
true
);
}
else
{
Prefs
.
setAllowNewApp
(
mContext
,
false
);
if
(
t
ip
.
equals
(
"打开"
))
{
Prefs
.
setAllowNewApp
(
mContext
,
true
);
}
else
{
Prefs
.
setAllowNewApp
(
mContext
,
false
);
}
break
;
case
AUTO_START_SELF:
if
(
t
ext
.
equals
(
"打开"
))
{
Prefs
.
setAutoStartSelf
(
mContext
,
true
);
if
(
t
ip
.
equals
(
"打开"
))
{
Prefs
.
setAutoStartSelf
(
mContext
,
true
);
MdmUtils
.
setDefaultLauncher
(
mContext
);
}
else
{
Prefs
.
setAutoStartSelf
(
mContext
,
false
);
MdmFactoryManager
.
getInstance
().
getDeviceRestrictionManager
().
setStatusBarExpandPanelDisabled
(
true
);
}
else
{
Prefs
.
setAutoStartSelf
(
mContext
,
false
);
MdmUtils
.
clearDefaultLauncher
(
mContext
);
MdmFactoryManager
.
getInstance
().
getDeviceRestrictionManager
().
setStatusBarExpandPanelDisabled
(
false
);
}
break
;
}
setBtnBackground
();
dialog
.
dismiss
();
}
})
.
create
();
if
(!
alertDialog
.
isShowing
())
{
alertDialog
.
show
();
}
}
private
void
showTipDialog
(
String
text
)
{
AlertDialog
alertDialog
;
TextView
textView
=
new
TextView
(
this
);
View
view
=
LayoutInflater
.
from
(
this
).
inflate
(
R
.
layout
.
item_ll
,
null
);
textView
.
setText
(
text
);
final
LinearLayout
ll
=
view
.
findViewById
(
R
.
id
.
item_ll
);
ll
.
addView
(
textView
);
alertDialog
=
new
AlertDialog
.
Builder
(
this
)
.
setTitle
(
"提示"
)
.
setCancelable
(
false
)
.
setView
(
view
)
.
setNegativeButton
(
R
.
string
.
work_cancel
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
dialog
.
dismiss
();
}
})
...
...
@@ -128,21 +176,28 @@ public class SettingActivity extends AppCompatActivity implements View.OnClickLi
@Override
public
void
onClick
(
View
v
)
{
switch
(
v
.
getId
()){
switch
(
v
.
getId
())
{
case
R
.
id
.
btn_change_pwd
:
showTipDialog
(
"开发中"
);
break
;
case
R
.
id
.
btn_set_pwdcar
:
showTipDialog
(
"开发中"
);
break
;
case
R
.
id
.
btn_auto_start
:
boolean
autoStartSelf
=
Prefs
.
isAutoStartSelf
(
this
);
if
(!
autoStartSelf
){
showPwdDialog
(
"打开"
,
AUTO_START_SELF
);
}
else
{
showPwdDialog
(
"关闭"
,
AUTO_START_SELF
);
if
(!
autoStartSelf
)
{
showPwdDialog
(
"打开"
,
AUTO_START_SELF
,
"开启后[移动管家]固定在前台不可退出,关闭可退出到普通桌面"
);
}
else
{
showPwdDialog
(
"关闭"
,
AUTO_START_SELF
,
"开启后[移动管家]固定在前台不可退出,关闭可退出到普通桌面"
);
}
break
;
case
R
.
id
.
btn_allow_new_app
:
boolean
allowNewApp
=
Prefs
.
isAllowNewApp
(
this
);
if
(!
allowNewApp
){
showPwdDialog
(
"打开"
,
AUTO_START_SELF
);
}
else
{
showPwdDialog
(
"关闭"
,
AUTO_START_SELF
);
boolean
allowNewApp
=
Prefs
.
isAllowNewApp
(
this
);
if
(!
allowNewApp
)
{
showPwdDialog
(
"打开"
,
ALLOW_NEW_APP
,
"打开后新安装应用自动在桌面显示"
);
}
else
{
showPwdDialog
(
"关闭"
,
ALLOW_NEW_APP
,
"打开后新安装应用自动在桌面显示"
);
}
break
;
case
R
.
id
.
btn_wifi_whitelist
:
...
...
@@ -160,13 +215,13 @@ public class SettingActivity extends AppCompatActivity implements View.OnClickLi
final
int
requestCode
,
final
int
resultCode
,
final
Intent
data
)
{
if
(
requestCode
==
REQUEST_PICK_WALLPAPER
)
{
if
(
resultCode
==
RESULT_OK
)
{
Log
.
e
(
"WWWW"
,
"AAAAA"
);
Log
.
e
(
"WWWW"
,
"AAAAA"
);
Uri
selectedImage
=
data
.
getData
();
Intent
intent
=
new
Intent
();
intent
.
setPackage
(
getPackageName
());
intent
.
setAction
(
ACTION_CHANGE_WALLPAPER
);
intent
.
setClass
(
this
,
Launcher
.
class
);
intent
.
putExtra
(
"uri"
,
selectedImage
);
intent
.
putExtra
(
"uri"
,
selectedImage
);
startActivity
(
intent
);
finish
();
}
...
...
Launcher3/src/com/android/launcher3/settings/String2ListHelper.java
View file @
93a4dece
...
...
@@ -3,7 +3,12 @@ package com.android.launcher3.settings;
import
java.util.List
;
public
class
String2ListHelper
{
/**
* 将String 转化为只有报名的list
* @param pkgs
* @param pkgsList
* @return
*/
public
static
List
<
String
>
getPkgsList
(
String
pkgs
,
List
<
String
>
pkgsList
){
if
(
pkgsList
.
equals
(
"null"
)){
return
pkgsList
;
...
...
@@ -15,4 +20,5 @@ public class String2ListHelper {
return
pkgsList
;
}
}
Launcher3/src/com/android/launcher3/settings/wifi/Gson2ListHelper.java
0 → 100644
View file @
93a4dece
package
com
.
android
.
launcher3
.
settings
.
wifi
;
import
android.content.Context
;
import
android.text.TextUtils
;
import
com.android.launcher3.settings.Prefs
;
import
com.google.gson.Gson
;
import
com.google.gson.reflect.TypeToken
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
Gson2ListHelper
{
public
static
List
<
WifiInfoBean
>
stringWifiWhite2List
(
Context
context
)
{
List
<
WifiInfoBean
>
wifiInfos
=
new
ArrayList
<>();
String
wifiWhiteList
=
Prefs
.
getWifiWhiteList
(
context
);
if
(
TextUtils
.
isEmpty
(
wifiWhiteList
))
{
return
wifiInfos
;
}
Gson
gson
=
new
Gson
();
wifiInfos
=
gson
.
fromJson
(
wifiWhiteList
,
new
TypeToken
<
List
<
WifiInfoBean
>>()
{
}.
getType
());
return
wifiInfos
;
}
}
Launcher3/src/com/android/launcher3/settings/wifi/NetworkConnectChangedReceiver.java
0 → 100644
View file @
93a4dece
package
com
.
android
.
launcher3
.
settings
.
wifi
;
import
android.arch.lifecycle.LiveData
;
import
android.arch.lifecycle.Observer
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.net.NetworkInfo
;
import
android.net.wifi.WifiInfo
;
import
android.net.wifi.WifiManager
;
import
android.os.Parcelable
;
import
android.support.annotation.Nullable
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.widget.Toast
;
import
com.google.gson.Gson
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
android
.
content
.
Context
.
WIFI_SERVICE
;
public
class
NetworkConnectChangedReceiver
extends
BroadcastReceiver
{
private
static
final
String
TAG
=
NetworkConnectChangedReceiver
.
class
.
getSimpleName
();
private
Context
mContext
;
private
WifiManager
mWifiManager
;
private
List
<
String
>
mWifiMacs
=
new
ArrayList
<>();
public
NetworkConnectChangedReceiver
(
Context
context
)
{
mContext
=
context
;
mWifiManager
=
(
WifiManager
)
mContext
.
getApplicationContext
().
getSystemService
(
WIFI_SERVICE
);
}
private
WifiManager
getWifiManager
()
{
if
(
mWifiManager
==
null
)
{
mWifiManager
=
(
WifiManager
)
mContext
.
getApplicationContext
().
getSystemService
(
WIFI_SERVICE
);
}
return
mWifiManager
;
}
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
String
action
=
intent
.
getAction
();
Log
.
i
(
TAG
,
"NetworkConnectChangedReceiver-onReceive: "
+
action
);
if
(
WifiManager
.
NETWORK_STATE_CHANGED_ACTION
.
equals
(
action
))
{
Parcelable
parcelableExtra
=
intent
.
getParcelableExtra
(
WifiManager
.
EXTRA_NETWORK_INFO
);
String
bssid
=
intent
.
getStringExtra
(
WifiManager
.
EXTRA_BSSID
);
if
(
null
!=
parcelableExtra
)
{
NetworkInfo
networkInfo
=
(
NetworkInfo
)
parcelableExtra
;
NetworkInfo
.
State
state
=
networkInfo
.
getState
();
Log
.
e
(
TAG
,
"NetworkConnectChangedReceiver-onReceive: state="
+
state
+
"\nbssid="
+
bssid
);
if
(
state
==
NetworkInfo
.
State
.
CONNECTING
)
{
WifiManager
wifiManager
=
getWifiManager
();
WifiInfo
wifiInfo
=
wifiManager
.
getConnectionInfo
();
if
(
TextUtils
.
isEmpty
(
bssid
))
{
bssid
=
wifiInfo
.
getBSSID
();
}
if
(
wifiInfo
!=
null
&&
!
TextUtils
.
isEmpty
(
bssid
))
{
bssid
=
bssid
.
toUpperCase
();
int
networkId
=
wifiInfo
.
getNetworkId
();
Log
.
e
(
TAG
,
"NetworkConnectChangedReceiver-onReceive: networkId="
+
networkId
+
" =bssid="
+
bssid
);
Log
.
e
(
TAG
,
"NetworkConnectChangedReceiver-onReceive contains:"
+
getmWifiMacs
(
context
).
contains
(
bssid
));
//检测bssid是否是否是禁用的。(数据库检测)
if
(
getmWifiMacs
(
context
).
size
()
>
0
&&
!(
getmWifiMacs
(
context
).
contains
(
bssid
)))
{
Toast
.
makeText
(
context
,
"此wifi不允许连接"
,
Toast
.
LENGTH_LONG
).
show
();
boolean
removeNetwork
=
WifiManagerUtils
.
getInstance
(
context
).
removeNetwork
(
networkId
);
Log
.
i
(
TAG
,
"removeNetwork: "
+
removeNetwork
);
}
}
}
if
(
state
==
NetworkInfo
.
State
.
CONNECTED
)
{
WifiManager
wifiManager
=
getWifiManager
();
WifiInfo
wifiInfo
=
wifiManager
.
getConnectionInfo
();
if
(
TextUtils
.
isEmpty
(
bssid
))
{
bssid
=
wifiInfo
.
getBSSID
();
}
if
(
wifiInfo
!=
null
&&
!
TextUtils
.
isEmpty
(
bssid
))
{
bssid
=
bssid
.
toUpperCase
();
int
networkId
=
wifiInfo
.
getNetworkId
();
Log
.
e
(
TAG
,
"NetworkConnectChangedReceiver-onReceive: networkId="
+
networkId
+
" =bssid="
+
bssid
);
//检测bssid是否是否是禁用的。(数据库检测)
if
(
getmWifiMacs
(
context
).
size
()
>
0
&&
!(
getmWifiMacs
(
context
).
contains
(
bssid
)))
{
Toast
.
makeText
(
context
,
"此wifi不允许连接"
,
Toast
.
LENGTH_LONG
).
show
();
boolean
removeNetwork
=
WifiManagerUtils
.
getInstance
(
context
).
removeNetwork
(
networkId
);
Log
.
i
(
TAG
,
"removeNetwork: "
+
removeNetwork
);
}
}
}
}
}
}
private
List
<
String
>
getmWifiMacs
(
Context
context
){
mWifiMacs
.
clear
();
List
<
WifiInfoBean
>
wifiInfoBeans
=
Gson2ListHelper
.
stringWifiWhite2List
(
context
);
for
(
int
i
=
0
;
i
<
wifiInfoBeans
.
size
();
i
++)
{
mWifiMacs
.
add
(
wifiInfoBeans
.
get
(
i
).
getMac
());
}
Log
.
i
(
TAG
,
"getmWifiMacs: "
+
mWifiMacs
.
toString
());
mWifiMacs
.
add
(
"00:00:00:00:00:00"
);
return
mWifiMacs
;
}
}
Launcher3/src/com/android/launcher3/settings/wifi/WifiAutoConnectManager.java
0 → 100644
View file @
93a4dece
package
com
.
android
.
launcher3
.
settings
.
wifi
;
import
android.net.wifi.WifiConfiguration
;
import
android.net.wifi.WifiConfiguration.AuthAlgorithm
;
import
android.net.wifi.WifiConfiguration.KeyMgmt
;
import
android.net.wifi.WifiManager
;
import
android.os.Handler
;
import
android.os.Message
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
java.util.List
;
/**
* wifi连接管理。
*/
public
class
WifiAutoConnectManager
{
private
static
final
String
TAG
=
WifiAutoConnectManager
.
class
.
getSimpleName
();
WifiManager
wifiManager
;
Handler
mHandler
;
public
void
sendMsg
(
String
info
)
{
if
(
mHandler
!=
null
)
{
Message
msg
=
new
Message
();
msg
.
obj
=
info
;
mHandler
.
sendMessage
(
msg
);
// 向Handler发送消息
}
else
{
Log
.
e
(
"wifi"
,
info
);
}
}
// 定义几种加密方式,一种是WEP,一种是WPA,还有没有密码的情况
public
enum
WifiCipherType
{
WIFICIPHER_WEP
,
WIFICIPHER_WPA
,
WIFICIPHER_NOPASS
,
WIFICIPHER_INVALID
}
// 构造函数
public
WifiAutoConnectManager
(
WifiManager
wifiManager
)
{
this
.
wifiManager
=
wifiManager
;
}
// 提供一个外部接口,传入要连接的无线网
public
void
connect
(
String
ssid
,
String
password
,
WifiCipherType
type
,
String
bssid
)
{
Thread
thread
=
new
Thread
(
new
ConnectRunnable
(
ssid
,
password
,
type
,
bssid
));
thread
.
start
();
}
// 查看以前是否也配置过这个网络
private
WifiConfiguration
isExsits
(
String
SSID
)
{
List
<
WifiConfiguration
>
existingConfigs
=
wifiManager
.
getConfiguredNetworks
();
for
(
WifiConfiguration
existingConfig
:
existingConfigs
)
{
if
(
existingConfig
.
SSID
.
equals
(
"\""
+
SSID
+
"\""
))
{
return
existingConfig
;
}
}
return
null
;
}
private
WifiConfiguration
createWifiInfo
(
String
SSID
,
String
Password
,
WifiCipherType
Type
,
String
bssid
)
{
WifiConfiguration
config
=
new
WifiConfiguration
();
config
.
allowedAuthAlgorithms
.
clear
();
config
.
allowedGroupCiphers
.
clear
();
config
.
allowedKeyManagement
.
clear
();
config
.
allowedPairwiseCiphers
.
clear
();
config
.
allowedProtocols
.
clear
();
config
.
SSID
=
"\""
+
SSID
+
"\""
;
config
.
BSSID
=
"\""
+
bssid
+
"\""
;
// nopass
if
(
Type
==
WifiCipherType
.
WIFICIPHER_NOPASS
)
{
// config.wepKeys[0] = "";
config
.
allowedKeyManagement
.
set
(
KeyMgmt
.
NONE
);
// config.wepTxKeyIndex = 0;
}
// wep
if
(
Type
==
WifiCipherType
.
WIFICIPHER_WEP
)
{
if
(!
TextUtils
.
isEmpty
(
Password
))
{
if
(
isHexWepKey
(
Password
))
{
config
.
wepKeys
[
0
]
=
Password
;
}
else
{
config
.
wepKeys
[
0
]
=
"\""
+
Password
+
"\""
;
}
}
config
.
allowedAuthAlgorithms
.
set
(
AuthAlgorithm
.
OPEN
);
config
.
allowedAuthAlgorithms
.
set
(
AuthAlgorithm
.
SHARED
);
config
.
allowedKeyManagement
.
set
(
KeyMgmt
.
NONE
);
config
.
wepTxKeyIndex
=
0
;
}
// wpa
if
(
Type
==
WifiCipherType
.
WIFICIPHER_WPA
)
{
config
.
preSharedKey
=
"\""
+
Password
+
"\""
;
config
.
hiddenSSID
=
true
;
config
.
allowedAuthAlgorithms
.
set
(
AuthAlgorithm
.
OPEN
);
config
.
allowedGroupCiphers
.
set
(
WifiConfiguration
.
GroupCipher
.
TKIP
);
config
.
allowedKeyManagement
.
set
(
KeyMgmt
.
WPA_PSK
);
config
.
allowedPairwiseCiphers
.
set
(
WifiConfiguration
.
PairwiseCipher
.
TKIP
);
// 此处需要修改否则不能自动重联
// config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
config
.
allowedGroupCiphers
.
set
(
WifiConfiguration
.
GroupCipher
.
CCMP
);
config
.
allowedPairwiseCiphers
.
set
(
WifiConfiguration
.
PairwiseCipher
.
CCMP
);
config
.
status
=
WifiConfiguration
.
Status
.
ENABLED
;
}
return
config
;
}
// 打开wifi功能
private
boolean
openWifi
()
{
boolean
bRet
=
true
;
if
(!
wifiManager
.
isWifiEnabled
())
{
bRet
=
wifiManager
.
setWifiEnabled
(
true
);
}
return
bRet
;
}
class
ConnectRunnable
implements
Runnable
{
private
String
ssid
;
private
String
password
;
private
WifiCipherType
type
;
private
String
bssid
;
public
ConnectRunnable
(
String
ssid
,
String
password
,
WifiCipherType
type
,
String
bssid
)
{
this
.
ssid
=
ssid
;
this
.
password
=
password
;
this
.
type
=
type
;
this
.
bssid
=
bssid
;
}
@Override
public
void
run
()
{
try
{
// 打开wifi
openWifi
();
sendMsg
(
"opened"
);
Thread
.
sleep
(
200
);
// 开启wifi功能需要一段时间(我在手机上测试一般需要1-3秒左右),所以要等到wifi
// 状态变成WIFI_STATE_ENABLED的时候才能执行下面的语句
while
(
wifiManager
.
getWifiState
()
==
WifiManager
.
WIFI_STATE_ENABLING
)
{
try
{
// 为了避免程序一直while循环,让它睡个100毫秒检测……
Thread
.
sleep
(
100
);
}
catch
(
InterruptedException
ie
)
{
}
}
WifiConfiguration
wifiConfig
=
createWifiInfo
(
ssid
,
password
,
type
,
bssid
);
//
if
(
wifiConfig
==
null
)
{
sendMsg
(
"wifiConfig is null!"
);
return
;
}
WifiConfiguration
tempConfig
=
isExsits
(
ssid
);
if
(
tempConfig
!=
null
)
{
wifiManager
.
removeNetwork
(
tempConfig
.
networkId
);
}
int
netID
=
wifiManager
.
addNetwork
(
wifiConfig
);
boolean
enabled
=
wifiManager
.
enableNetwork
(
netID
,
true
);
sendMsg
(
"enableNetwork status enable="
+
enabled
);
boolean
connected
=
wifiManager
.
reconnect
();
sendMsg
(
"enableNetwork connected="
+
connected
);
sendMsg
(
"连接成功!"
);
}
catch
(
Exception
e
)
{
sendMsg
(
e
.
getMessage
());
e
.
printStackTrace
();
}
}
}
private
static
boolean
isHexWepKey
(
String
wepKey
)
{
final
int
len
=
wepKey
.
length
();
// WEP-40, WEP-104, and some vendors using 256-bit WEP (WEP-232?)
if
(
len
!=
10
&&
len
!=
26
&&
len
!=
58
)
{
return
false
;
}
return
isHex
(
wepKey
);
}
private
static
boolean
isHex
(
String
key
)
{
for
(
int
i
=
key
.
length
()
-
1
;
i
>=
0
;
i
--)
{
final
char
c
=
key
.
charAt
(
i
);
if
(!(
c
>=
'0'
&&
c
<=
'9'
||
c
>=
'A'
&&
c
<=
'F'
||
c
>=
'a'
&&
c
<=
'f'
))
{
return
false
;
}
}
return
true
;
}
}
Launcher3/src/com/android/launcher3/settings/wifi/WifiInfo.java
deleted
100644 → 0
View file @
a5af3646
package
com
.
android
.
launcher3
.
settings
.
wifi
;
public
class
WifiInfo
{
}
Launcher3/src/com/android/launcher3/settings/wifi/WifiInfoBean.java
0 → 100644
View file @
93a4dece
package
com
.
android
.
launcher3
.
settings
.
wifi
;
public
class
WifiInfoBean
{
private
String
mac
;
private
String
ssid
;
private
String
pwd
;
private
boolean
isDelete
;
public
String
getMac
()
{
return
mac
;
}
public
void
setMac
(
String
mac
)
{
this
.
mac
=
mac
;
}
public
String
getSsid
()
{
return
ssid
;
}
public
void
setSsid
(
String
ssid
)
{
this
.
ssid
=
ssid
;
}
public
boolean
isDelete
()
{
return
isDelete
;
}
public
void
setDelete
(
boolean
delete
)
{
isDelete
=
delete
;
}
public
String
getPwd
()
{
return
pwd
;
}
public
void
setPwd
(
String
pwd
)
{
this
.
pwd
=
pwd
;
}
}
Launcher3/src/com/android/launcher3/settings/wifi/WifiManagerUtils.java
0 → 100644
View file @
93a4dece
package
com
.
android
.
launcher3
.
settings
.
wifi
;
import
android.content.Context
;
import
android.net.NetworkInfo
;
import
android.net.wifi.WifiInfo
;
import
android.net.wifi.WifiManager
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.widget.Toast
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
com
.
android
.
launcher3
.
Launcher
.
TAG
;
public
class
WifiManagerUtils
{
private
static
WifiManagerUtils
wifiManagerUtils
;
private
static
final
Object
object
=
new
Object
();
private
Context
mContext
;
private
WifiManager
mWifiManager
;
private
WifiManagerUtils
(
Context
context
)
{
mContext
=
context
;
mWifiManager
=
(
WifiManager
)
mContext
.
getApplicationContext
().
getSystemService
(
Context
.
WIFI_SERVICE
);
}
public
WifiManager
getWifiManager
()
{
if
(
mWifiManager
==
null
)
{
mWifiManager
=
(
WifiManager
)
mContext
.
getApplicationContext
().
getSystemService
(
Context
.
WIFI_SERVICE
);
}
return
mWifiManager
;
}
public
static
WifiManagerUtils
getInstance
(
Context
context
)
{
if
(
wifiManagerUtils
==
null
)
{
synchronized
(
object
)
{
if
(
wifiManagerUtils
==
null
)
{
wifiManagerUtils
=
new
WifiManagerUtils
(
context
);
}
}
}
return
wifiManagerUtils
;
}
/**
* 移除保存的网络
*/
public
boolean
removeNetwork
(
int
networkId
)
{
WifiManager
wifiManager
=
getWifiManager
();
//此方法系统签名才会全局生效
return
wifiManager
.
removeNetwork
(
networkId
);
}
public
boolean
isEnabled
()
{
return
getWifiManager
().
isWifiEnabled
();
}
/**
* 获取当前连接WIFI的SSID
*/
public
void
isIllegalWifi
()
{
WifiManager
wifiManager
=
getWifiManager
();
if
(
wifiManager
!=
null
)
{
WifiInfo
wifiInfo
=
wifiManager
.
getConnectionInfo
();
if
(
wifiInfo
!=
null
)
{
String
bssid
=
wifiInfo
.
getBSSID
();
if
(
wifiInfo
!=
null
&&
!
TextUtils
.
isEmpty
(
bssid
))
{
bssid
=
bssid
.
toUpperCase
();
int
networkId
=
wifiInfo
.
getNetworkId
();
Log
.
e
(
TAG
,
"NetworkConnectChangedReceiver-onReceive: networkId="
+
networkId
+
" =bssid="
+
bssid
);
//检测bssid是否是否是禁用的。(数据库检测)
if
(
getWifiMacs
(
mContext
).
size
()
>
0
&&
!(
getWifiMacs
(
mContext
).
contains
(
bssid
)))
{
Toast
.
makeText
(
mContext
,
"此wifi不允许连接"
,
Toast
.
LENGTH_LONG
).
show
();
boolean
removeNetwork
=
WifiManagerUtils
.
getInstance
(
mContext
).
removeNetwork
(
networkId
);
Log
.
i
(
TAG
,
"removeNetwork: "
+
removeNetwork
);
}
}
}
}
}
public
boolean
isConnectedWifi
(){
WifiManager
wifiManager
=
getWifiManager
();
if
(
wifiManager
!=
null
)
{
WifiInfo
wifiInfo
=
wifiManager
.
getConnectionInfo
();
if
(
wifiInfo
!=
null
)
{
String
bssid
=
wifiInfo
.
getBSSID
();
if
(
wifiInfo
!=
null
&&
!
TextUtils
.
isEmpty
(
bssid
))
{
bssid
=
bssid
.
toUpperCase
();
int
networkId
=
wifiInfo
.
getNetworkId
();
Log
.
e
(
TAG
,
"NetworkConnectChangedReceiver-onReceive: networkId="
+
networkId
+
" =bssid="
+
bssid
);
//检测bssid是否是否是禁用的。(数据库检测)
if
(
bssid
.
equals
(
"00:00:00:00:00:00"
)){
return
false
;
}
else
{
return
true
;
}
}
}
}
return
false
;
}
private
List
<
String
>
getWifiMacs
(
Context
context
){
List
<
String
>
mWifiMacs
=
new
ArrayList
<>();
List
<
WifiInfoBean
>
wifiInfoBeans
=
Gson2ListHelper
.
stringWifiWhite2List
(
context
);
for
(
int
i
=
0
;
i
<
wifiInfoBeans
.
size
();
i
++)
{
mWifiMacs
.
add
(
wifiInfoBeans
.
get
(
i
).
getMac
());
}
return
mWifiMacs
;
}
}
Launcher3/src/com/android/launcher3/settings/wifi/WifiScanService.java
0 → 100644
View file @
93a4dece
package
com
.
android
.
launcher3
.
settings
.
wifi
;
import
android.annotation.SuppressLint
;
import
android.app.Service
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.net.wifi.ScanResult
;
import
android.net.wifi.WifiManager
;
import
android.os.Handler
;
import
android.os.IBinder
;
import
android.os.Message
;
import
android.util.Log
;
import
java.util.List
;
public
class
WifiScanService
extends
Service
{
Context
mContext
;
WifiAutoConnectManager
mWifiAutoConnectManager
;
private
Handler
mHandler
=
new
Handler
()
{
@Override
public
void
handleMessage
(
Message
msg
)
{
super
.
handleMessage
(
msg
);
if
(
WifiManagerUtils
.
getInstance
(
mContext
).
isEnabled
())
{
List
<
ScanResult
>
wifiList
=
getWifiList
();
List
<
WifiInfoBean
>
wifiInfoBean
=
getWifiInfoBean
();
boolean
isBreak
=
false
;
for
(
int
i
=
0
;
i
<
wifiList
.
size
();
i
++)
{
for
(
int
j
=
0
;
j
<
wifiInfoBean
.
size
();
j
++)
{
if
(
wifiList
.
get
(
i
).
SSID
.
equals
(
wifiInfoBean
.
get
(
j
).
getSsid
())){
if
(!
WifiManagerUtils
.
getInstance
(
mContext
).
isConnectedWifi
()){
mWifiAutoConnectManager
.
connect
(
wifiInfoBean
.
get
(
j
).
getSsid
(),
wifiInfoBean
.
get
(
j
).
getPwd
(),
WifiAutoConnectManager
.
WifiCipherType
.
WIFICIPHER_WPA
,
wifiInfoBean
.
get
(
j
).
getMac
());
isBreak
=
true
;
break
;
}
}
}
if
(
isBreak
){
break
;
}
}
}
sendEmptyMessageDelayed
(
1
,
10000
);
}
};
@Override
public
void
onCreate
()
{
super
.
onCreate
();
mWifiAutoConnectManager
=
new
WifiAutoConnectManager
(
WifiManagerUtils
.
getInstance
(
this
).
getWifiManager
());
mContext
=
this
;
mHandler
.
sendEmptyMessage
(
1
);
}
private
List
<
ScanResult
>
getWifiList
()
{
WifiManager
wifiManager
=
(
WifiManager
)
mContext
.
getApplicationContext
().
getSystemService
(
Context
.
WIFI_SERVICE
);
if
(!
wifiManager
.
isWifiEnabled
())
{
wifiManager
.
setWifiEnabled
(
true
);
}
wifiManager
.
startScan
();
List
<
ScanResult
>
wifiList
=
wifiManager
.
getScanResults
();
return
wifiList
;
}
private
List
<
WifiInfoBean
>
getWifiInfoBean
()
{
return
Gson2ListHelper
.
stringWifiWhite2List
(
this
);
}
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
return
super
.
onStartCommand
(
intent
,
flags
,
startId
);
}
@Override
public
IBinder
onBind
(
Intent
intent
)
{
return
null
;
}
}
Launcher3/src/com/android/launcher3/settings/wifi/WifiWhiteListActivity.java
View file @
93a4dece
package
com
.
android
.
launcher3
.
settings
.
wifi
;
import
android.app.AlertDialog
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.net.wifi.WifiManager
;
import
android.support.v7.app.AppCompatActivity
;
import
android.os.Bundle
;
import
android.support.v7.widget.DefaultItemAnimator
;
import
android.support.v7.widget.DividerItemDecoration
;
import
android.support.v7.widget.LinearLayoutManager
;
import
android.support.v7.widget.RecyclerView
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.widget.CompoundButton
;
import
android.widget.EditText
;
import
android.widget.LinearLayout
;
import
android.widget.Switch
;
import
android.widget.TextView
;
import
com.android.launcher3.R
;
import
com.secspace.mdmengine.api.manager.MdmFactoryManager
;
import
com.android.launcher3.settings.Prefs
;
import
com.google.gson.Gson
;
import
com.secspace.lib.common.utils.InputUtil
;
import
com.secspace.lib.common.utils.ToastUtil
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
WifiWhiteListActivity
extends
AppCompatActivity
implements
View
.
OnClickListener
{
public
static
final
String
TAG
=
"WifiWhiteListActivity"
;
private
LinearLayout
mLlWifi
;
private
Switch
mSwitchWifi
;
private
RecyclerView
mRecycleWifiWhiteList
;
private
List
<
WifiInfo
>
mWifiInfoList
;
private
List
<
WifiInfo
Bean
>
mWifiInfoList
;
WifiManager
mWifiManager
;
WifiWhiteListAdapter
mWifiWhiteListAdapter
;
private
TextView
mTvAdd
;
private
TextView
mTvDelete
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_wifi_white_list
);
mWifiInfoList
=
new
ArrayList
<>();
mWifiInfoList
=
new
ArrayList
<>();
initView
();
initListener
();
initData
();
...
...
@@ -33,25 +52,57 @@ public class WifiWhiteListActivity extends AppCompatActivity implements View.OnC
private
void
initData
()
{
mWifiManager
=
(
WifiManager
)
getApplicationContext
().
getSystemService
(
Context
.
WIFI_SERVICE
);
initAdapter
();
initRecycle
();
}
@Override
protected
void
onResume
()
{
super
.
onResume
();
wifiJudge
();
}
private
void
initRecycle
()
{
LinearLayoutManager
linearLayout
=
new
LinearLayoutManager
(
this
);
mRecycleWifiWhiteList
.
setLayoutManager
(
linearLayout
);
mRecycleWifiWhiteList
.
setItemAnimator
(
new
DefaultItemAnimator
());
mRecycleWifiWhiteList
.
addItemDecoration
(
new
DividerItemDecoration
(
this
,
DividerItemDecoration
.
HORIZONTAL
));
mRecycleWifiWhiteList
.
setAdapter
(
mWifiWhiteListAdapter
);
mWifiInfoList
=
loadWifiListData
();
mWifiWhiteListAdapter
.
setList
(
mWifiInfoList
);
}
private
void
initAdapter
()
{
mWifiWhiteListAdapter
=
new
WifiWhiteListAdapter
();
mWifiWhiteListAdapter
.
setItemViewId
(
R
.
layout
.
item_wifi_white_list
);
}
private
void
wifiJudge
()
{
if
(
isWifiOpened
()){
if
(
isWifiOpened
())
{
mSwitchWifi
.
setChecked
(
true
);
}
else
{
}
else
{
mSwitchWifi
.
setChecked
(
false
);
}
}
private
void
initListener
()
{
mLlWifi
.
setOnClickListener
(
this
);
mTvAdd
.
setOnClickListener
(
this
);
mTvDelete
.
setOnClickListener
(
this
);
}
private
void
initView
()
{
mLlWifi
=
findViewById
(
R
.
id
.
ll_wifi
);
mSwitchWifi
=
findViewById
(
R
.
id
.
swich_wifi
);
mRecycleWifiWhiteList
=
findViewById
(
R
.
id
.
recycle_wifi_white_list
);
mLlWifi
=
findViewById
(
R
.
id
.
ll_wifi
);
mSwitchWifi
=
findViewById
(
R
.
id
.
swich_wifi
);
mTvAdd
=
findViewById
(
R
.
id
.
tv_add
);
mTvDelete
=
findViewById
(
R
.
id
.
tv_delete
);
mRecycleWifiWhiteList
=
findViewById
(
R
.
id
.
recycle_wifi_white_list
);
mSwitchWifi
.
setOnCheckedChangeListener
(
new
CompoundButton
.
OnCheckedChangeListener
()
{
@Override
public
void
onCheckedChanged
(
CompoundButton
buttonView
,
boolean
isChecked
)
{
setWifiState
(
mSwitchWifi
.
isChecked
());
}
});
findViewById
(
R
.
id
.
tv_back
).
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
...
...
@@ -62,16 +113,109 @@ public class WifiWhiteListActivity extends AppCompatActivity implements View.OnC
@Override
public
void
onClick
(
View
v
)
{
switch
(
v
.
getId
()){
case
R
.
id
.
ll_wifi
:
setWifiState
(!
mSwitchWifi
.
isChecked
());
switch
(
v
.
getId
())
{
case
R
.
id
.
tv_add
:
showPwdDialog
(
this
);
break
;
case
R
.
id
.
tv_delete
:
List
<
WifiInfoBean
>
deletePosition
=
mWifiWhiteListAdapter
.
getDeletePosition
();
for
(
int
i
=
0
;
i
<
deletePosition
.
size
();
i
++)
{
if
(
mWifiInfoList
.
contains
(
deletePosition
.
get
(
i
)))
{
mWifiInfoList
.
remove
(
deletePosition
.
get
(
i
));
}
}
Gson
gson
=
new
Gson
();
String
list2Json
=
gson
.
toJson
(
mWifiInfoList
);
Log
.
i
(
TAG
,
"onClick: "
+
list2Json
);
Prefs
.
setWifiWhiteList
(
this
,
list2Json
);
WifiManagerUtils
.
getInstance
(
this
).
isIllegalWifi
();
mWifiWhiteListAdapter
.
notifyDataSetChanged
();
break
;
}
}
// 24:69:68:FD:F5:A8
@Override
protected
void
onStop
()
{
super
.
onStop
();
}
private
boolean
isWifiOpened
()
{
return
mWifiManager
.
isWifiEnabled
();
}
private
void
setWifiState
(
boolean
state
){
mWifiManager
.
setWifiEnabled
(
state
);
private
void
setWifiState
(
boolean
state
)
{
boolean
b
=
mWifiManager
.
setWifiEnabled
(
state
);
Log
.
i
(
TAG
,
"setWifiState: "
+
b
);
}
private
List
<
WifiInfoBean
>
loadWifiListData
()
{
return
Gson2ListHelper
.
stringWifiWhite2List
(
this
);
}
private
void
showPwdDialog
(
final
Context
context
)
{
AlertDialog
alertDialog
;
final
EditText
editMac
=
new
EditText
(
this
);
final
EditText
editSsid
=
new
EditText
(
this
);
final
EditText
editPwd
=
new
EditText
(
this
);
editMac
.
setMaxLines
(
1
);
editSsid
.
setMaxLines
(
1
);
editPwd
.
setMaxLines
(
1
);
editMac
.
setHint
(
"请输入mac"
);
editSsid
.
setHint
(
"请输入ssid"
);
editPwd
.
setHint
(
"请输入密码"
);
View
view
=
LayoutInflater
.
from
(
this
).
inflate
(
R
.
layout
.
item_ll
,
null
);
final
LinearLayout
ll
=
view
.
findViewById
(
R
.
id
.
item_ll
);
ll
.
addView
(
editMac
);
ll
.
addView
(
editSsid
);
ll
.
addView
(
editPwd
);
alertDialog
=
new
AlertDialog
.
Builder
(
this
)
.
setTitle
(
"添加新的wifi管控"
)
.
setCancelable
(
false
)
.
setView
(
view
)
.
setNegativeButton
(
R
.
string
.
work_cancel
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
dialog
.
dismiss
();
}
})
.
setPositiveButton
(
R
.
string
.
work_sure
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
String
mac
=
editMac
.
getText
().
toString
();
String
ssid
=
editSsid
.
getText
().
toString
();
if
(
TextUtils
.
isEmpty
(
mac
)
||
TextUtils
.
isEmpty
(
ssid
))
{
ToastUtil
.
showShort
(
WifiWhiteListActivity
.
this
,
"输入不能为空请重新输入"
);
return
;
}
for
(
int
i
=
0
;
i
<
mWifiInfoList
.
size
();
i
++)
{
String
mac1
=
mWifiInfoList
.
get
(
i
).
getMac
();
String
ssid1
=
mWifiInfoList
.
get
(
i
).
getSsid
();
if
(
TextUtils
.
equals
(
mac
,
mac1
)
||
TextUtils
.
equals
(
ssid
,
ssid1
))
{
ToastUtil
.
showShort
(
WifiWhiteListActivity
.
this
,
"输入不能为空请重新输入"
);
return
;
}
}
WifiInfoBean
wifiInfo
=
new
WifiInfoBean
();
wifiInfo
.
setMac
(
mac
);
wifiInfo
.
setSsid
(
ssid
);
wifiInfo
.
setPwd
(
TextUtils
.
isEmpty
(
editPwd
.
getText
().
toString
())
?
""
:
editPwd
.
getText
().
toString
());
mWifiInfoList
.
add
(
wifiInfo
);
mWifiWhiteListAdapter
.
notifyDataSetChanged
();
Gson
gson
=
new
Gson
();
String
list2Json
=
gson
.
toJson
(
mWifiInfoList
);
Prefs
.
setWifiWhiteList
(
context
,
list2Json
);
InputUtil
.
closeSoftInput
(
getApplicationContext
(),
editSsid
);
dialog
.
dismiss
();
WifiManagerUtils
.
getInstance
(
context
).
isIllegalWifi
();
}
})
.
create
();
if
(!
alertDialog
.
isShowing
())
{
alertDialog
.
show
();
}
}
}
Launcher3/src/com/android/launcher3/settings/wifi/WifiWhiteListAdapter.java
View file @
93a4dece
package
com
.
android
.
launcher3
.
settings
.
wifi
;
import
android.support.v7.widget.RecyclerView
;
import
android.widget.CheckBox
;
import
android.widget.CompoundButton
;
import
android.widget.TextView
;
import
com.android.launcher3.R
;
import
com.android.launcher3.settings.BaseRecyclerViewAdapter
;
public
class
WifiWhiteListAdapter
extends
BaseRecyclerViewAdapter
<
WifiInfo
>
{
import
java.util.ArrayList
;
import
java.util.List
;
public
class
WifiWhiteListAdapter
extends
BaseRecyclerViewAdapter
<
WifiInfoBean
>
{
private
List
<
WifiInfoBean
>
mDeletePosition
=
new
ArrayList
<>();
@Override
public
void
onBindViewHolder
(
RecyclerView
.
ViewHolder
holder
,
int
position
)
{
public
void
onBindViewHolder
(
RecyclerView
.
ViewHolder
holder
,
final
int
position
)
{
super
.
onBindViewHolder
(
holder
,
position
);
MyViewHolder
myViewHolder
=
(
MyViewHolder
)
holder
;
TextView
tvMac
=
myViewHolder
.
get
(
R
.
id
.
tv_mac
);
TextView
tvSsid
=
myViewHolder
.
get
(
R
.
id
.
tv_ssid
);
CheckBox
checkBox
=
myViewHolder
.
get
(
R
.
id
.
cb_delete
);
tvMac
.
setText
(
mList
.
get
(
position
).
getMac
());
tvSsid
.
setText
(
mList
.
get
(
position
).
getSsid
());
checkBox
.
setOnCheckedChangeListener
(
new
CompoundButton
.
OnCheckedChangeListener
()
{
@Override
public
void
onCheckedChanged
(
CompoundButton
buttonView
,
boolean
isChecked
)
{
if
(
buttonView
.
isPressed
())
{
if
(
isChecked
)
{
if
(!
mDeletePosition
.
contains
(
mList
.
get
(
position
))){
mDeletePosition
.
add
(
mList
.
get
(
position
));
}
}
else
{
if
(
mDeletePosition
.
contains
(
mList
.
get
(
position
))){
mDeletePosition
.
remove
(
mList
.
get
(
position
));
}
}
}
}
});
}
public
List
<
WifiInfoBean
>
getDeletePosition
(){
return
mDeletePosition
;
}
}
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