Refinements

This commit is contained in:
Mygod
2018-01-04 13:11:28 +08:00
parent ff7ecedd80
commit c49e8865d9
2 changed files with 5 additions and 9 deletions

View File

@@ -66,7 +66,8 @@ class HotspotService : Service(), WifiP2pManager.ChannelListener {
val group = intent.getParcelableExtra<WifiP2pGroup>(WifiP2pManager.EXTRA_WIFI_P2P_GROUP) val group = intent.getParcelableExtra<WifiP2pGroup>(WifiP2pManager.EXTRA_WIFI_P2P_GROUP)
hostAddress = info.groupOwnerAddress hostAddress = info.groupOwnerAddress
val downstream = group.`interface` val downstream = group.`interface`
if (net.isConnected && downstream != null && this@HotspotService.downstream == null) { if (info.groupFormed && info.isGroupOwner &&
downstream != null && this@HotspotService.downstream == null) {
this@HotspotService.downstream = downstream this@HotspotService.downstream = downstream
if (noisySu("echo 1 >/proc/sys/net/ipv4/ip_forward", if (noisySu("echo 1 >/proc/sys/net/ipv4/ip_forward",
"ip route add default dev $upstream scope link table 62", "ip route add default dev $upstream scope link table 62",
@@ -87,10 +88,6 @@ class HotspotService : Service(), WifiP2pManager.ChannelListener {
showNotification(group) showNotification(group)
Log.d(TAG, "${intent.action}: $info, $net, $group") Log.d(TAG, "${intent.action}: $info, $net, $group")
} }
WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION -> {
val info = intent.getParcelableExtra<WifiP2pInfo>(WifiP2pManager.EXTRA_WIFI_P2P_INFO)
Log.d(TAG, "${intent.action}: $info")
}
} }
} }
@@ -132,10 +129,8 @@ class HotspotService : Service(), WifiP2pManager.ChannelListener {
if (status != Status.IDLE) return START_NOT_STICKY if (status != Status.IDLE) return START_NOT_STICKY
status = Status.STARTING status = Status.STARTING
if (!receiverRegistered) { if (!receiverRegistered) {
registerReceiver(receiver, intentFilter( registerReceiver(receiver, intentFilter(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION,
WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION, WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION))
WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION,
WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION))
receiverRegistered = true receiverRegistered = true
} }
p2pManager.requestGroupInfo(channel, { p2pManager.requestGroupInfo(channel, {

View File

@@ -4,6 +4,7 @@
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
<item name="preferenceCategory_marginBottom">8dp</item>
</style> </style>
</resources> </resources>