Skip to content

Commit d795371

Browse files
authored
Merge pull request #11 from beebird/master
support LSPosed API 101
2 parents 00eb603 + 047f7ce commit d795371

10 files changed

Lines changed: 57 additions & 51 deletions

File tree

app/build.gradle

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
plugins {
22
id 'com.android.application'
33
id 'org.jetbrains.kotlin.android'
4+
id 'org.jetbrains.kotlin.plugin.compose'
45
}
56

67
android {
78
namespace 'moe.lyniko.hiderecent'
8-
compileSdk 34
9+
compileSdk 36
910

1011
defaultConfig {
1112
applicationId "moe.lyniko.hiderecent"
@@ -28,19 +29,16 @@ android {
2829
}
2930
}
3031
compileOptions {
31-
sourceCompatibility JavaVersion.VERSION_1_8
32-
targetCompatibility JavaVersion.VERSION_1_8
32+
sourceCompatibility JavaVersion.VERSION_17
33+
targetCompatibility JavaVersion.VERSION_17
3334
}
3435
kotlinOptions {
35-
jvmTarget = '1.8'
36+
jvmTarget = '17'
3637
}
3738
buildFeatures {
3839
buildConfig true
3940
compose true
4041
}
41-
composeOptions {
42-
kotlinCompilerExtensionVersion '1.4.3'
43-
}
4442
packagingOptions {
4543
resources {
4644
excludes += '/META-INF/{AL2.0,LGPL2.1}'
@@ -49,21 +47,21 @@ android {
4947
}
5048

5149
dependencies {
52-
// module stuff
5350
compileOnly 'de.robv.android.xposed:api:82'
51+
5452
implementation 'org.lsposed.hiddenapibypass:hiddenapibypass:4.3'
5553
def shizuku_version = '13.1.5'
5654
implementation "dev.rikka.shizuku:api:$shizuku_version"
5755
implementation "dev.rikka.shizuku:provider:$shizuku_version"
5856
implementation 'me.zhanghai.compose.preference:library:1.0.0'
5957

6058
// ui stuff
61-
implementation "com.google.accompanist:accompanist-drawablepainter:0.28.0"
59+
implementation "com.google.accompanist:accompanist-drawablepainter:0.36.0"
6260
implementation "androidx.navigation:navigation-compose:2.7.6"
6361
implementation 'androidx.core:core-ktx:1.12.0'
6462
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
6563
implementation 'androidx.activity:activity-compose:1.8.2'
66-
implementation platform('androidx.compose:compose-bom:2022.10.00')
64+
implementation platform('androidx.compose:compose-bom:2024.12.01')
6765
implementation 'androidx.compose.ui:ui'
6866
implementation 'androidx.compose.ui:ui-graphics'
6967
implementation 'androidx.compose.ui:ui-tooling-preview'

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
android:supportsRtl="true"
1616
android:theme="@style/Theme.HideRecentTask"
1717
android:name="moe.lyniko.hiderecent.MyApplication"
18+
android:description="@string/xposeddescription"
1819
tools:targetApi="31">
1920
<meta-data
2021
android:name="xposedmodule"
@@ -43,7 +44,7 @@
4344
android:name=".LauncherActivity"
4445
android:enabled="true"
4546
android:exported="true"
46-
android:targetActivity="${applicationId}.MainActivity">
47+
android:targetActivity=".MainActivity">
4748
<intent-filter>
4849
<action android:name="android.intent.action.MAIN" />
4950
<category android:name="android.intent.category.LAUNCHER" />

app/src/main/java/moe/lyniko/hiderecent/MainActivity.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,7 @@ class MainActivity : ComponentActivity() {
3434

3535
override fun onCreate(savedInstanceState: Bundle?) {
3636
super.onCreate(savedInstanceState)
37-
try {
38-
PreferenceUtils.getInstance(this)
39-
} catch (e: SecurityException) {
40-
Toast.makeText(this, getString(R.string.not_activated), Toast.LENGTH_LONG).show()
41-
finish()
42-
return
43-
}
37+
PreferenceUtils.getInstance(this)
4438
setContent {
4539
MyApplicationTheme {
4640

app/src/main/java/moe/lyniko/hiderecent/MainHook.kt

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,8 @@ class MainHook : IXposedHookLoadPackage {
1919
private fun onAppHooked(lpparam: LoadPackageParam) {
2020
val visibleFilterHook: XC_MethodHook = object : XC_MethodHook() {
2121
override fun beforeHookedMethod(param: MethodHookParam) {
22+
if (!loaded) tryLoadPackages()
2223
val intent = callMethod(param.args[0], "getBaseIntent") as Intent
23-
if (BuildConfig.DEBUG) {
24-
XposedBridge.log("Hide - Current Intent: $intent")
25-
XposedBridge.log("Hide - Current component: ${intent.component}")
26-
XposedBridge.log("Hide - Current package: ${intent.component?.packageName}")
27-
}
2824
val packageName = intent.component?.packageName ?: return
2925
if (packages.contains(packageName)) {
3026
param.result = false
@@ -39,16 +35,29 @@ class MainHook : IXposedHookLoadPackage {
3935
"com.android.server.wm.Task",
4036
visibleFilterHook
4137
)
42-
} catch (ignored: Throwable) {
38+
XposedBridge.log("HideRecent: hook installed, packages=$packages")
39+
} catch (t: Throwable) {
40+
XposedBridge.log("HideRecent: hook FAILED")
41+
XposedBridge.log(t)
4342
}
4443
}
4544

46-
private val packages: MutableSet<String>
45+
@Volatile
46+
private var packages: Set<String> = emptySet()
47+
@Volatile
48+
private var loaded = false
4749

48-
init {
49-
val xsp =
50-
XSharedPreferences(BuildConfig.APPLICATION_ID, PreferenceUtils.functionalConfigName)
50+
private fun tryLoadPackages() {
51+
val xsp = XSharedPreferences(BuildConfig.APPLICATION_ID, PreferenceUtils.functionalConfigName)
5152
xsp.makeWorldReadable()
52-
packages = PreferenceUtils.getPackageListFromPref(xsp)
53+
val pkgs = PreferenceUtils.getPackageListFromPref(xsp)
54+
if (pkgs.isNotEmpty()) {
55+
packages = pkgs
56+
loaded = true
57+
}
58+
}
59+
60+
init {
61+
tryLoadPackages()
5362
}
5463
}

app/src/main/java/moe/lyniko/hiderecent/utils/AppUtils.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,26 +165,27 @@ class ParsedPackage(
165165
) {
166166
// lazy init
167167
val appName: String by lazy {
168-
packageManager.getApplicationLabel(pkg.applicationInfo).toString()
168+
val appInfo = pkg.applicationInfo ?: return@lazy pkg.packageName
169+
packageManager.getApplicationLabel(appInfo).toString()
169170
}
170171
val appIcon: Drawable by lazy {
171-
pkg.applicationInfo.loadIcon(packageManager)
172+
pkg.applicationInfo?.loadIcon(packageManager) ?: packageManager.defaultActivityIcon
172173
}
173174
val packageName: String by lazy {
174175
pkg.packageName
175176
}
176177

177178
@Suppress("unused")
178179
val versionName: String by lazy {
179-
pkg.versionName
180+
pkg.versionName ?: ""
180181
}
181182

182183
@Suppress("unused")
183184
val versionCode: Long by lazy {
184185
pkg.longVersionCode
185186
}
186187
val isSystemApp: Boolean by lazy {
187-
(pkg.applicationInfo.flags and android.content.pm.ApplicationInfo.FLAG_SYSTEM) != 0
188+
(pkg.applicationInfo?.flags?.and(android.content.pm.ApplicationInfo.FLAG_SYSTEM) ?: 0) != 0
188189
}
189190
private val packageNameLowerCase: String by lazy {
190191
packageName.lowercase()

app/src/main/java/moe/lyniko/hiderecent/utils/PreferenceUtils.kt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,14 @@ import moe.lyniko.hiderecent.R
1010
class PreferenceUtils( // init context on constructor
1111
context: Context
1212
) {
13-
// ------ 1. get several SharedPreferences (funcPref is the only accessible during Xposed inject) ------
14-
private var funcPref: SharedPreferences = try {
15-
@Suppress("DEPRECATION")
16-
context.getSharedPreferences(functionalConfigName, Context.MODE_WORLD_READABLE)
17-
} catch (e: SecurityException) {
18-
throw e
19-
// Log.w("PreferenceUtil", "Fallback to Private SharedPref for error!!!: ${e.message}")
20-
// context.getSharedPreferences(functionalConfigName, Context.MODE_PRIVATE)
21-
}
13+
// ------ 1. get several SharedPreferences ------
14+
// Vector/LSPosed hooks checkMode to allow MODE_WORLD_READABLE when the module
15+
// is in its own scope. Fall back to MODE_PRIVATE if the hook isn't active.
16+
private var funcPref: SharedPreferences = openWorldReadable(context, functionalConfigName)
2217

23-
@Suppress("DEPRECATION")
24-
var managerPref: SharedPreferences =
25-
context.getSharedPreferences(managerConfigName, Context.MODE_WORLD_READABLE)
18+
var managerPref: SharedPreferences = openWorldReadable(context, managerConfigName)
2619

27-
@Suppress("DEPRECATION")
28-
private val legacyFuncPref = context.getSharedPreferences(legacyConfigName, Context.MODE_WORLD_READABLE)
20+
private val legacyFuncPref = openWorldReadable(context, legacyConfigName)
2921

3022
// ------ 2. init packages ------
3123
private fun initPackageFromLegacyAndNew(funcPref: SharedPreferences, legacyPref: SharedPreferences) {
@@ -58,6 +50,15 @@ class PreferenceUtils( // init context on constructor
5850
instance ?: PreferenceUtils(context).also { instance = it }
5951
}
6052

53+
@Suppress("DEPRECATION")
54+
private fun openWorldReadable(context: Context, name: String): SharedPreferences {
55+
return try {
56+
context.getSharedPreferences(name, Context.MODE_WORLD_READABLE)
57+
} catch (_: SecurityException) {
58+
context.getSharedPreferences(name, Context.MODE_PRIVATE)
59+
}
60+
}
61+
6162
private const val packagesTag = "packages"
6263
const val functionalConfigName = "functional_config"
6364
const val managerConfigName = "manager_config"

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<string name="not_activated">Please activate this module in LSPosed Manager, then force stop.</string>
1010
<string-array name="xposedscope" translatable="false">
1111
<item>android</item>
12+
<item>moe.lyniko.hiderecent</item>
1213
</string-array>
1314
<string name="title_home">Home</string>
1415
<string name="title_settings">Settings</string>

build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
plugins {
3-
id 'com.android.application' version '8.0.2' apply false
4-
id 'com.android.library' version '8.0.2' apply false
5-
id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
3+
id 'com.android.application' version '8.13.0' apply false
4+
id 'com.android.library' version '8.13.0' apply false
5+
id 'org.jetbrains.kotlin.android' version '2.3.0' apply false
6+
id 'org.jetbrains.kotlin.plugin.compose' version '2.3.0' apply false
67
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Sat Dec 16 19:53:24 GMT+08:00 2023
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

gradlew

100644100755
File mode changed.

0 commit comments

Comments
 (0)