Skip to content

Commit 26b2b0b

Browse files
committed
Initial xposed support
A lot still needs to be fixed/implemented - I need to get the wifi info on a different thread, so the UI isn't blocked - I could probable show more on the wifi info screen - I need to find a way to show ads
1 parent 6129a53 commit 26b2b0b

File tree

11 files changed

+271
-38
lines changed

11 files changed

+271
-38
lines changed

app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ android {
2525
dependencies {
2626
implementation fileTree(dir: 'libs', include: ['*.jar'])
2727
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
28+
//noinspection GradleCompatible
2829
implementation 'com.android.support:appcompat-v7:27.1.0'
2930
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
31+
compileOnly 'de.robv.android.xposed:api:82'
32+
compileOnly 'de.robv.android.xposed:api:82:sources'
3033
implementation 'com.github.kenglxn.QRGen:android:2.4.0'
34+
implementation 'com.crossbowffs.remotepreferences:remotepreferences:0.5'
3135

3236
// START AD SERVICES
3337
implementation('com.mopub:mopub-sdk:4.20.0@aar') {

app/proguard-rules.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
# If you keep the line number information, uncomment this to
2020
# hide the original source file name.
2121
#-renamesourcefileattribute SourceFile
22+
-keep class tk.superl2.xwifi.xposed.** { *; }

app/src/main/AndroidManifest.xml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
android:supportsRtl="true"
2020
android:theme="@style/AppTheme">
2121

22+
<meta-data
23+
android:name="xposedmodule"
24+
android:value="true" />
25+
<meta-data
26+
android:name="xposeddescription"
27+
android:value="Adds an option to share a saved wifi network as a QR code in the system settings" />
28+
<meta-data
29+
android:name="xposedminversion"
30+
android:value="82" />
31+
2232
<meta-data android:name="applovin.sdk.key"
2333
android:value="NaAFA-JFGfuBZTVkWkZi7La8TdiU3vrRU_he-0uEfnPDJwyqdVWms6uPkauoUkDzkvbhvUxTFLnTFiNtDvc4_V" />
2434

@@ -32,7 +42,9 @@
3242
<activity
3343
android:name=".SettingsActivity"
3444
android:label="@string/title_activity_settings"
35-
android:parentActivityName=".MainActivity">
45+
android:parentActivityName=".MainActivity" tools:ignore="UnusedAttribute"
46+
android:exported="true"
47+
>
3648
<meta-data
3749
android:name="android.support.PARENT_ACTIVITY"
3850
android:value="tk.superl2.xwifi.MainActivity" />
@@ -45,6 +57,11 @@
4557
<activity android:name="com.mopub.mobileads.MraidVideoPlayerActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
4658
<activity android:name="com.applovin.adview.AppLovinInterstitialActivity" android:configChanges="orientation|screenSize"/>
4759
<activity android:name="com.applovin.adview.AppLovinConfirmationActivity" android:configChanges="orientation|screenSize"/>
60+
61+
<provider
62+
android:name=".PreferenceProvider"
63+
android:authorities="tk.superl2.xwifi.preferences"
64+
android:exported="true" tools:ignore="ExportedContentProvider" />
4865
</application>
4966

5067
</manifest>

app/src/main/assets/xposed_init

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tk.superl2.xwifi.xposed.XposedModule

app/src/main/java/tk/superl2/xwifi/MainActivity.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package tk.superl2.xwifi
22

3+
import android.Manifest
34
import android.app.AlertDialog
45
import android.content.Intent
5-
import android.content.SharedPreferences
6+
import android.content.pm.PackageManager
67
import android.os.AsyncTask
78
import android.os.Build
89
import android.os.Bundle
910
import android.preference.PreferenceManager
11+
import android.support.v4.app.ActivityCompat
12+
import android.support.v4.content.ContextCompat
1013
import android.support.v7.app.AppCompatActivity
1114
import android.support.v7.app.AppCompatDelegate
1215
import android.text.Html
@@ -18,28 +21,26 @@ import android.widget.ImageView
1821
import android.widget.ProgressBar
1922
import android.widget.Toast
2023
import com.applovin.sdk.AppLovinSdk
21-
import com.mopub.mobileads.MoPubView
2224
import kotlinx.android.synthetic.main.activity_main.*
2325
import net.glxn.qrgen.android.QRCode
2426
import net.glxn.qrgen.core.scheme.Wifi
2527

2628
private const val TAG = "MainActivity"
27-
private const val DEFAULT_QR_GENERATION_RESOLUTION = "300"
28-
private const val QR_CODE_DIALOG_BOTTOM_IMAGE_MARGIN = 0
2929
const val PERMISSION_CODE_GROUP_ADS = 0
3030

31+
internal const val QR_CODE_DIALOG_BOTTOM_IMAGE_MARGIN = 0
32+
3133
class MainActivity: AppCompatActivity() {
3234
// This variable holds an ArrayList of WifiEntry objects that each contain a saved wifi SSID and
3335
// password. It is updated whenever focus returns to the app (onResume).
3436
private lateinit var wifiEntries: ArrayList<WifiEntry>
3537
private val wifiEntrySSIDs = ArrayList<String>()
3638
private lateinit var loadWifiEntriesInBackgroundTask: LoadWifiEntriesInBackground
37-
private lateinit var prefs: SharedPreferences
38-
3939
private lateinit var qrDialog: AlertDialog
40+
4041
override fun onCreate(savedInstanceState: Bundle?) {
4142
PreferenceManager.setDefaultValues(this, R.xml.preferences, false)
42-
prefs = PreferenceManager.getDefaultSharedPreferences(this)
43+
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
4344

4445
setThemeFromSharedPrefs(prefs)
4546
super.onCreate(savedInstanceState)
@@ -61,7 +62,7 @@ class MainActivity: AppCompatActivity() {
6162
qrCodeView.setImageBitmap(QRCode
6263
.from(Wifi()
6364
.withSsid(wifiEntrySSIDs[position])
64-
.withPsk(wifiEntries[position].getPassword(true))
65+
.withPsk(wifiEntries[position].password)
6566
.withAuthentication(wifiEntries[position].type.asQRCodeAuth()))
6667
.withColor((if (AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_YES) 0xFF000000 else 0xFFE0E0E0).toInt(), 0x00000000) //TODO Better colour handling - atm, the colours may be wrong if the theme is set to system or auto.
6768
.withSize(prefs.getString("qr_code_resolution", DEFAULT_QR_GENERATION_RESOLUTION).toInt(), prefs.getString("qr_code_resolution", DEFAULT_QR_GENERATION_RESOLUTION).toInt())
@@ -78,14 +79,14 @@ class MainActivity: AppCompatActivity() {
7879
builder.setMessage(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
7980
Html.fromHtml(
8081
"<b>SSID</b>: ${wifiEntries[position].title}<br>" +
81-
(if (wifiEntries[position].getPassword(true) != "") "<b>Password</b>: ${if (wifiEntries[position].type != WifiEntry.Type.WEP) wifiEntries[position].getPassword(true) else wifiEntries[position].getPassword(true).removePrefix("\"").removeSuffix("\"")}<br>" else { "" }) +
82+
(if (wifiEntries[position].password != "") "<b>Password</b>: ${if (wifiEntries[position].type != WifiEntry.Type.WEP) wifiEntries[position].password else wifiEntries[position].password.removePrefix("\"").removeSuffix("\"")}<br>" else { "" }) +
8283
"<b>Type</b>: ${wifiEntries[position].type}",
8384
Html.FROM_HTML_MODE_LEGACY)
8485
} else {
8586
@Suppress("DEPRECATION")
8687
Html.fromHtml(
8788
"<b>SSID</b>: ${wifiEntries[position].title}<br>" +
88-
(if (wifiEntries[position].getPassword(true) != "") "<b>Password</b>: ${if (wifiEntries[position].type != WifiEntry.Type.WEP) wifiEntries[position].getPassword(true) else wifiEntries[position].getPassword(true).removePrefix("\"").removeSuffix("\"")}<br>" else { "" }) +
89+
(if (wifiEntries[position].password != "") "<b>Password</b>: ${if (wifiEntries[position].type != WifiEntry.Type.WEP) wifiEntries[position].password else wifiEntries[position].password.removePrefix("\"").removeSuffix("\"")}<br>" else { "" }) +
8990
"<b>Type</b>: ${wifiEntries[position].type}"
9091
)
9192
}
@@ -126,14 +127,14 @@ class MainActivity: AppCompatActivity() {
126127
private lateinit var errorDialog: AlertDialog
127128
private lateinit var loadingDialog: AlertDialog
128129

129-
private inner class LoadWifiEntriesInBackground : AsyncTask<Unit, Unit, Unit>() {
130+
private inner class LoadWifiEntriesInBackground: AsyncTask<Unit, Unit, Unit>() {
130131
override fun onPreExecute() {
131132
val loadingDialogBuilder = AlertDialog.Builder(this@MainActivity)
132133
loadingDialogBuilder.setCancelable(false)
133134
loadingDialogBuilder.setMessage(R.string.wifi_loading_message)
134135
loadingDialogBuilder.setView(ProgressBar(this@MainActivity))
135136
loadingDialog = loadingDialogBuilder.create()
136-
loadingDialog.show()
137+
runOnUiThread { loadingDialog.show() }
137138
}
138139

139140
override fun doInBackground(vararg params: Unit?) {
@@ -194,7 +195,7 @@ class MainActivity: AppCompatActivity() {
194195
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
195196
return when (item!!.itemId) {
196197
R.id.settingsItem -> {
197-
startActivity(Intent(this, SettingsActivity::class.java))
198+
startActivity(Intent(this, SettingsActivity::class.java).putExtra("xposed", false))
198199
true
199200
}
200201
else -> super.onOptionsItemSelected(item)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package tk.superl2.xwifi
2+
3+
class PreferenceProvider: com.crossbowffs.remotepreferences.RemotePreferenceProvider("tk.superl2.xwifi.preferences", arrayOf("tk.superl2.xwifi_preferences")) {
4+
override fun checkAccess(prefName: String, prefKey: String, write: Boolean): Boolean {
5+
if (write) return false
6+
return when (prefKey) {
7+
"theme" -> false
8+
"qr_code_resolution" -> true
9+
else -> false
10+
}
11+
}
12+
}
Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
11
package tk.superl2.xwifi
22

3-
import android.content.SharedPreferences
4-
import android.os.Build
53
import android.os.Bundle
6-
import android.preference.Preference
7-
import android.preference.PreferenceActivity
84
import android.preference.PreferenceFragment
5+
import android.preference.PreferenceManager
96
import android.support.v7.app.AppCompatActivity
107
import android.support.v7.app.AppCompatDelegate
118
import android.widget.Toast
129

10+
internal const val DEFAULT_QR_GENERATION_RESOLUTION = "300"
1311

14-
/**
15-
* A [PreferenceActivity] that presents a set of application settings. On
16-
* handset devices, settings are presented as a single list. On tablets,
17-
* settings are split by category, with category headers shown to the left of
18-
* the list of settings.
19-
*
20-
* See [Android Design: Settings](http://developer.android.com/design/patterns/settings.html)
21-
* for design guidelines and the [Settings API Guide](http://developer.android.com/guide/topics/ui/settings.html)
22-
* for more information on developing a Settings UI.
23-
*/
2412
class SettingsActivity: AppCompatActivity() {
2513
override fun onCreate(savedInstanceState: Bundle?) {
14+
PreferenceManager.setDefaultValues(this, R.xml.preferences, false)
15+
16+
if (intent.extras.getBoolean("xposed")) {
17+
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
18+
} else {
19+
setThemeFromSharedPrefs(PreferenceManager.getDefaultSharedPreferences(this))
20+
}
21+
2622
super.onCreate(savedInstanceState)
2723

2824
// Display the fragment as the main context
29-
fragmentManager.beginTransaction().replace(android.R.id.content, SettingsFragment()).commit()
25+
fragmentManager.beginTransaction().replace(android.R.id.content, if (intent.extras.getBoolean("xposed")) XposedSettingsFragment() else SettingsFragment()).commit()
3026
}
3127
}
3228

@@ -44,4 +40,11 @@ class SettingsFragment: PreferenceFragment() {
4440
true
4541
}
4642
}
43+
}
44+
45+
class XposedSettingsFragment: PreferenceFragment() {
46+
override fun onCreate(savedInstanceState: Bundle?) {
47+
super.onCreate(savedInstanceState)
48+
addPreferencesFromResource(R.xml.xposed_preferences)
49+
}
4750
}

app/src/main/java/tk/superl2/xwifi/WifiDataUtils.kt

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import java.io.IOException
1010
import java.io.InputStreamReader
1111
import java.util.*
1212

13+
const val ANDROID_SECURITY_NONE = 0
14+
const val ANDROID_SECURITY_WEP = 1
15+
const val ANDROID_SECURITY_PSK = 2
16+
const val ANDROID_SECURITY_EAP = 3
17+
const val ANDROID_PSK_UNKNOWN = 0
18+
const val ANDROID_PSK_WPA = 1
19+
const val ANDROID_PSK_WPA2 = 2
20+
const val ANDROID_PSK_WPA_WPA2 = 3
21+
1322
data class WifiEntry(var title: String = "", var password: String = "", var type: Type = Type.NONE) {
1423
enum class Type {
1524
WPA {
@@ -28,16 +37,23 @@ data class WifiEntry(var title: String = "", var password: String = "", var type
2837
};
2938

3039
abstract fun asQRCodeAuth(): Wifi.Authentication
31-
}
3240

33-
fun getPassword(showAll: Boolean): String =
34-
if (showAll) {
35-
password
36-
} else {
37-
val fill = CharArray(password.length)
38-
Arrays.fill(fill, '*')
39-
String(fill)
41+
companion object {
42+
fun fromAndroidSecurityInt(security: Int, pskType: Int): WifiEntry.Type = when (security) {
43+
ANDROID_SECURITY_WEP -> WEP
44+
ANDROID_SECURITY_PSK -> {
45+
when (pskType) {
46+
ANDROID_PSK_WPA -> WPA
47+
ANDROID_PSK_WPA2 -> WPA
48+
ANDROID_PSK_WPA_WPA2 -> WPA
49+
else -> WPA
50+
}
51+
}
52+
// ANDROID_SECURITY_EAP -> EAP
53+
else -> NONE
4054
}
55+
}
56+
}
4157
}
4258

4359
private const val mOreoLocation = "/data/misc/wifi/WifiConfigStore.xml"

0 commit comments

Comments
 (0)