Skip to content

Commit ed40fa1

Browse files
committed
Fix up Shizuku service and remove more OneUI Tuner references
1 parent 513be5c commit ed40fa1

File tree

43 files changed

+77
-176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+77
-176
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ dependencies {
104104
implementation 'com.github.zacharee:CollapsiblePreferenceCategory:75d1f8b5c5'
105105
implementation 'com.github.zacharee:Android-ExpandableTextView:74f653343d'
106106
implementation 'com.github.zacharee:ComposeIntroSlider:d273cf5734'
107-
implementation 'com.github.zacharee:SystemUITunerSystemSettings:b5d86f98ee'
107+
implementation 'com.github.zacharee:SystemUITunerSystemSettings:0f4f6a0c2d'
108108

109109
implementation 'com.bugsnag:bugsnag-android:6.1.0'
110110
implementation 'com.getkeepsafe.relinker:relinker:1.4.5'

app/src/main/java/com/zacharee1/systemuituner/MainActivity.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.content.res.Configuration
77
import android.os.Build
88
import android.os.Bundle
99
import android.provider.Settings
10+
import android.util.Log
1011
import android.view.*
1112
import android.view.animation.AccelerateInterpolator
1213
import android.view.animation.AnimationUtils
@@ -24,6 +25,7 @@ import com.zacharee1.systemuituner.databinding.ActivityMainBinding
2425
import com.zacharee1.systemuituner.fragments.BasePrefFragment
2526
import com.zacharee1.systemuituner.fragments.HomeFragment
2627
import com.zacharee1.systemuituner.fragments.SearchFragment
28+
import com.zacharee1.systemuituner.systemsettingsaddon.library.settingsAddon
2729
import com.zacharee1.systemuituner.util.*
2830

2931
class MainActivity : AppCompatActivity(), NavController.OnDestinationChangedListener {
@@ -102,6 +104,10 @@ class MainActivity : AppCompatActivity(), NavController.OnDestinationChangedList
102104
setContentView(mainBinding.root)
103105
setSupportActionBar(mainBinding.toolbar)
104106

107+
if (settingsAddon.hasService && !settingsAddon.binderAvailable) {
108+
settingsAddon.bindAddonService()
109+
}
110+
105111
with(supportActionBar) {
106112
this ?: return@with
107113

app/src/main/java/com/zacharee1/systemuituner/fragments/HomeFragment.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ class HomeFragment : BasePrefFragment(), NavController.OnDestinationChangedListe
7171
isVisible = false
7272
}
7373
}
74-
75-
findPreference<Preference>("oneui_tuner_option")?.apply {
76-
if (!requireContext().isTouchWiz || Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
77-
isVisible = false
78-
}
79-
}
8074
}
8175

8276
override fun onDestroy() {

app/src/main/java/com/zacharee1/systemuituner/services/ShizukuOperationsService.kt

Lines changed: 34 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
@file:Suppress("DEPRECATION")
2+
13
package com.zacharee1.systemuituner.services
24

3-
import android.app.ActivityManager
5+
import android.app.ActivityManagerNative
46
import android.app.ActivityThread
57
import android.content.AttributionSource
68
import android.content.ContentValues
@@ -10,37 +12,21 @@ import android.net.Uri
1012
import android.os.Binder
1113
import android.os.Build
1214
import android.os.Bundle
15+
import android.os.UserHandle
1316
import android.provider.Settings
14-
import androidx.core.os.UserHandleCompat
15-
import com.zacharee1.systemuituner.BuildConfig
17+
import android.system.Os
18+
import android.util.Log
1619
import com.zacharee1.systemuituner.IShizukuOperationsService
1720
import com.zacharee1.systemuituner.data.SettingsType
18-
import rikka.shizuku.Shizuku
21+
import kotlin.system.exitProcess
1922

2023
@Suppress("unused")
21-
class ShizukuOperationsService : IShizukuOperationsService.Stub {
24+
class ShizukuOperationsService(private val context: Context) : IShizukuOperationsService.Stub() {
2225
private val contentResolver by lazy {
2326
@Suppress("INACCESSIBLE_TYPE")
2427
(ActivityThread.currentActivityThread().systemContext as Context).contentResolver
2528
}
2629

27-
private val context: Context
28-
29-
constructor() {
30-
@Suppress("INACCESSIBLE_TYPE")
31-
val context = (ActivityThread.systemMain().systemContext as Context)
32-
33-
this.context = context.createPackageContextAsUser(
34-
BuildConfig.APPLICATION_ID,
35-
Context.CONTEXT_INCLUDE_CODE or Context.CONTEXT_IGNORE_SECURITY,
36-
UserHandleCompat.getUserHandleForUid(safeUid()),
37-
)
38-
}
39-
40-
constructor(context: Context) {
41-
this.context = context
42-
}
43-
4430
override fun writeGlobal(key: String?, value: String?, pkg: String?): Boolean {
4531
return write(Settings.Global.CONTENT_URI, key, value, pkg)
4632
}
@@ -83,11 +69,13 @@ class ShizukuOperationsService : IShizukuOperationsService.Stub {
8369
}
8470
}
8571

86-
override fun destroy() {}
72+
override fun destroy() {
73+
exitProcess(0)
74+
}
8775

8876
private fun write(uri: Uri, key: String?, value: String?, pkg: String?): Boolean {
89-
return try {
90-
uri.useProvider {
77+
return uri.useProvider {
78+
try {
9179
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
9280
insert(
9381
AttributionSource(
@@ -114,13 +102,11 @@ class ShizukuOperationsService : IShizukuOperationsService.Stub {
114102
put("package", pkg)
115103
},
116104
)
117-
}
105+
} != null
106+
} catch (e: Throwable) {
107+
Log.e("SystemUITuner", "Error", e)
108+
throw e
118109
}
119-
true
120-
} catch (e: Exception) {
121-
false
122-
} finally {
123-
124110
}
125111
}
126112

@@ -140,56 +126,40 @@ class ShizukuOperationsService : IShizukuOperationsService.Stub {
140126
}
141127

142128
private fun resolveCallingPackage(): String? {
143-
return when (safeUid()) {
144-
android.os.Process.ROOT_UID -> {
145-
"root"
146-
}
147-
148-
android.os.Process.SHELL_UID -> {
149-
"com.android.shell"
150-
}
151-
152-
else -> {
153-
null
154-
}
155-
}
129+
return context.packageManager.getPackagesForUid(safeUid())?.getOrNull(0)
156130
}
157131

158-
private fun <T> Uri.useProvider(block: IContentProvider.() -> T?): T? {
159-
val activityManager = ActivityManager.getService()
160-
val token = Binder()
161-
132+
private fun <T> Uri.useProvider(block: IContentProvider.() -> T): T {
133+
val caller = Binder.clearCallingIdentity()
134+
val activityService = ActivityManagerNative.getDefault()
162135
var provider: IContentProvider? = null
136+
val token = Binder()
163137

164138
try {
165-
val holder = activityManager.getContentProviderExternal(
166-
authority,
167-
safeUid(),
139+
provider = activityService.getContentProviderExternal(
140+
this.authority,
141+
UserHandle.USER_SYSTEM,
168142
token,
169143
"*cmd*",
170-
) ?: throw IllegalStateException("Could not find provider for ${authority}!")
171-
172-
provider = holder.provider
173-
174-
if (provider == null) {
175-
throw java.lang.IllegalStateException("Provider for $authority is null!")
176-
}
144+
)?.provider
177145

178-
return provider.block()
146+
return provider?.block() ?: throw IllegalStateException("Unable to acquire Content Provider ${authority}!")
147+
} catch (e: Throwable) {
148+
Log.e("SystemUITuner", "Error", e)
149+
throw e
179150
} finally {
180151
provider?.also {
181-
activityManager.removeContentProviderExternalAsUser(
182-
authority,
183-
token,
184-
safeUid(),
152+
activityService.removeContentProviderExternal(
153+
this.authority, token,
185154
)
186155
}
156+
Binder.restoreCallingIdentity(caller)
187157
}
188158
}
189159

190160
private fun safeUid(): Int {
191161
return try {
192-
Shizuku.getUid()
162+
Os.getuid()
193163
} catch (e: IllegalStateException) {
194164
2000
195165
}

app/src/main/java/com/zacharee1/systemuituner/util/SettingsUtils.kt

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,27 @@ fun Context.getSetting(type: SettingsType, key: String?, def: Any? = null): Stri
161161
} catch (e: SecurityException) {
162162
BugsnagUtils.notify(IllegalStateException("Unable to read setting ${type}, ${key}, ${def}.", e))
163163
when {
164-
Shizuku.pingBinder() && hasShizukuPermission -> {
165-
shizukuServiceManager.waitForService()
166-
.run {
167-
try {
168-
when (type) {
169-
SettingsType.GLOBAL -> this.readGlobal(key)
170-
SettingsType.SECURE -> this.readSecure(key)
171-
SettingsType.SYSTEM -> this.readSystem(key)
172-
else -> null
164+
Shizuku.pingBinder() -> {
165+
if (hasShizukuPermission) {
166+
shizukuServiceManager.waitForService()
167+
.run {
168+
try {
169+
when (type) {
170+
SettingsType.GLOBAL -> this.readGlobal(key)
171+
SettingsType.SECURE -> this.readSecure(key)
172+
SettingsType.SYSTEM -> this.readSystem(key)
173+
else -> null
174+
}
175+
} catch (e: Throwable) {
176+
BugsnagUtils.notify(IllegalStateException("Failed to read setting through Shizuku.", e))
177+
null
173178
}
174-
} catch (e: Throwable) {
175-
BugsnagUtils.notify(IllegalStateException("Failed to read setting through Shizuku.", e))
176-
null
177179
}
178-
}
180+
} else {
181+
BugsnagUtils.leaveBreadcrumb("No Shizuku permission but it is installed. Requesting permission.")
182+
Shizuku.requestPermission(100)
183+
null
184+
}
179185
}
180186
settingsAddon.hasService -> {
181187
settingsAddon.binder?.readSetting(
@@ -246,17 +252,23 @@ private fun Context.writeSystem(key: String?, value: Any?): Boolean {
246252
.exec()
247253
true
248254
}
249-
Shizuku.pingBinder() && hasShizukuPermission -> {
250-
try {
251-
shizukuServiceManager.waitForService()
252-
.writeSystem(key, value?.toString(), packageName)
253-
} catch (e: Throwable) {
254-
BugsnagUtils.notify(IllegalStateException("Unable to write to Settings.System using Shizuku.", e))
255-
Log.e("SystemUITuner", "Failed to write to System $key $value", e)
256-
false
255+
Shizuku.pingBinder() -> {
256+
if (hasShizukuPermission) {
257+
try {
258+
shizukuServiceManager.waitForService()
259+
.writeSystem(key, value?.toString(), packageName)
260+
} catch (e: Throwable) {
261+
BugsnagUtils.notify(IllegalStateException("Unable to write to Settings.System using Shizuku.", e))
262+
Log.e("SystemUITuner", "Failed to write to System $key $value", e)
263+
false
264+
}
265+
} else {
266+
BugsnagUtils.leaveBreadcrumb("No Shizuku permission but it is installed. Requesting permission.")
267+
Shizuku.requestPermission(100)
268+
null
257269
}
258270
}
259-
settingsAddon.hasService -> {
271+
settingsAddon.hasService && settingsAddon.binderAvailable -> {
260272
val result = settingsAddon.binder?.writeSetting(
261273
com.zacharee1.systemuituner.systemsettingsaddon.library.SettingsType.SYSTEM,
262274
key,

app/src/main/java/com/zacharee1/systemuituner/util/ShizukuServiceManager.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import com.zacharee1.systemuituner.BuildConfig
1111
import com.zacharee1.systemuituner.IShizukuOperationsService
1212
import com.zacharee1.systemuituner.services.ShizukuOperationsService
1313
import rikka.shizuku.Shizuku
14-
import rikka.shizuku.ShizukuProvider
1514
import java.util.concurrent.ConcurrentLinkedQueue
1615

1716
val Context.shizukuServiceManager: ShizukuServiceManager
@@ -60,8 +59,8 @@ class ShizukuServiceManager private constructor(context: Context) : ContextWrapp
6059
)
6160
)
6261
.daemon(false)
63-
.processNameSuffix("service")
64-
.debuggable(BuildConfig.DEBUG)
62+
.processNameSuffix(":service")
63+
.debuggable(true)
6564
.version(BuildConfig.VERSION_CODE)
6665

6766
fun onCreate() {

app/src/main/res/values-ach-rUG/strings.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,6 @@
329329
<string name="more_apps">More Apps</string>
330330
<string name="telegram">Telegram</string>
331331
<string name="mastodon">Mastodon</string>
332-
<string name="oneui_tuner">OneUI Tuner</string>
333-
<string name="oneui_tuner_desc">If you have a Samsung device running Android Pie or later on Samsung\'s One UI, you may have noticed that some options that worked on Oreo no longer work, such as Clock Seconds. I\'ve made a separate app that makes use of system overlays to bring back some of these options. It doesn\'t need root or ADB.</string>
334332
<string name="check_it_out">Check it Out</string>
335333
<string name="add_custom_item">Add Custom Item</string>
336334
<string name="edit_custom_item">Edit Custom Item</string>

app/src/main/res/values-af-rZA/strings.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,6 @@
329329
<string name="more_apps">More Apps</string>
330330
<string name="telegram">Telegram</string>
331331
<string name="mastodon">Mastodon</string>
332-
<string name="oneui_tuner">OneUI Tuner</string>
333-
<string name="oneui_tuner_desc">If you have a Samsung device running Android Pie or later on Samsung\'s One UI, you may have noticed that some options that worked on Oreo no longer work, such as Clock Seconds. I\'ve made a separate app that makes use of system overlays to bring back some of these options. It doesn\'t need root or ADB.</string>
334332
<string name="check_it_out">Check it Out</string>
335333
<string name="add_custom_item">Add Custom Item</string>
336334
<string name="edit_custom_item">Edit Custom Item</string>

app/src/main/res/values-ar-rSA/strings.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,6 @@
329329
<string name="more_apps">المزيد من التطبيقات</string>
330330
<string name="telegram">Telegram</string>
331331
<string name="mastodon">ماستدون</string>
332-
<string name="oneui_tuner">أداة ضبط واجهة ون من سامسونج لمستخدم النظام</string>
333-
<string name="oneui_tuner_desc">إذا كان لديك جهاز سامسونج يعمل بأصدار الفطيرة أندرويد أو ما يليه على واجهة ون الخاصة بسامسونج، ربما كنت قد لاحظت أن بعض الخيارات التي كانت تعمل في أوريو لم تعد تعمل، مثل ساعة العمل الثانية. لقد قمت بإنشاء تطبيق منفصل يستخدم طبقات النظام لاستعادة بعض هذه الخيارات. لا يحتاج إلى الجذر أو ADB.</string>
334332
<string name="check_it_out">تحقق من ذلك</string>
335333
<string name="add_custom_item">إضافة عنصر مخصص</string>
336334
<string name="edit_custom_item">تحرير العنصر المخصص</string>

app/src/main/res/values-ca-rES/strings.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,6 @@
329329
<string name="more_apps">More Apps</string>
330330
<string name="telegram">Telegram</string>
331331
<string name="mastodon">Mastodon</string>
332-
<string name="oneui_tuner">OneUI Tuner</string>
333-
<string name="oneui_tuner_desc">If you have a Samsung device running Android Pie or later on Samsung\'s One UI, you may have noticed that some options that worked on Oreo no longer work, such as Clock Seconds. I\'ve made a separate app that makes use of system overlays to bring back some of these options. It doesn\'t need root or ADB.</string>
334332
<string name="check_it_out">Check it Out</string>
335333
<string name="add_custom_item">Add Custom Item</string>
336334
<string name="edit_custom_item">Edit Custom Item</string>

0 commit comments

Comments
 (0)