├── .gitignore ├── .idea └── vcs.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── aidl │ ├── android │ │ └── content │ │ │ └── om │ │ │ └── OverlayInfo.aidl │ └── tk │ │ └── zwander │ │ └── overlaymanager │ │ ├── IRootBridge.aidl │ │ └── proxy │ │ └── OverlayInfo.aidl │ ├── ic_launcher-web.png │ ├── java │ └── tk │ │ └── zwander │ │ └── overlaymanager │ │ ├── App.kt │ │ ├── MainActivity.kt │ │ ├── data │ │ ├── BatchedUpdate.kt │ │ ├── ObservableHashMap.kt │ │ └── TargetData.kt │ │ ├── proxy │ │ ├── IOverlayManager.kt │ │ └── OverlayInfo.kt │ │ ├── root │ │ ├── IRootBridgeImpl.kt │ │ └── RootBridgeService.kt │ │ ├── ui │ │ ├── OverlayAdapter.kt │ │ └── TargetAdapter.kt │ │ ├── util │ │ ├── DividerItemDecoration.kt │ │ └── Utils.kt │ │ └── views │ │ ├── CheckableImageButton.kt │ │ └── TooltippedImageButton.kt │ └── res │ ├── drawable-v24 │ ├── arrow_collapse_vertical.xml │ ├── arrow_expand_vertical.xml │ ├── ic_launcher_foreground.xml │ └── playlist_remove.xml │ ├── drawable │ ├── divider.xml │ ├── highest_priority_selector.xml │ ├── ic_baseline_error_24.xml │ ├── ic_baseline_playlist_add_check_24.xml │ ├── ic_baseline_vertical_align_bottom_24.xml │ ├── ic_baseline_vertical_align_bottom_24_disabled.xml │ ├── ic_baseline_vertical_align_top_24.xml │ ├── ic_baseline_vertical_align_top_24_disabled.xml │ ├── ic_done_black_24dp.xml │ ├── ic_launcher_background.xml │ ├── lowest_priority_selector.xml │ └── title_border.xml │ ├── layout │ ├── activity_main.xml │ ├── overlay_item.xml │ ├── progress.xml │ └── target_item.xml │ ├── menu │ └── search.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-parcelize' 4 | 5 | android { 6 | compileSdkVersion 33 7 | defaultConfig { 8 | applicationId "tk.zwander.overlaymanager" 9 | minSdkVersion 26 10 | targetSdkVersion 33 11 | versionCode 4 12 | versionName versionCode.toString() 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | packagingOptions { 21 | exclude 'META-INF/atomicfu.kotlin_module' 22 | } 23 | kotlinOptions { 24 | jvmTarget = "11" 25 | } 26 | buildFeatures { 27 | viewBinding = true 28 | } 29 | compileOptions { 30 | sourceCompatibility JavaVersion.VERSION_11 31 | targetCompatibility JavaVersion.VERSION_11 32 | } 33 | } 34 | 35 | dependencies { 36 | implementation fileTree(dir: 'libs', include: ['*.jar']) 37 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" 38 | 39 | implementation 'androidx.appcompat:appcompat:1.5.1' 40 | implementation 'androidx.core:core-ktx:1.9.0' 41 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 42 | implementation 'androidx.recyclerview:recyclerview:1.2.1' 43 | implementation 'androidx.cardview:cardview:1.0.0' 44 | implementation 'com.google.android.material:material:1.8.0-beta01' 45 | 46 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4' 47 | implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4' 48 | 49 | implementation "com.github.topjohnwu.libsu:core:3.2.1" 50 | implementation "com.github.topjohnwu.libsu:service:3.1.2" 51 | implementation 'com.github.2hamed:ProgressCircula:v0.2.1' 52 | implementation 'com.squareup.picasso:picasso:2.71828' 53 | implementation 'com.github.sephiroth74:android-target-tooltip:2.0.4' 54 | 55 | implementation 'dev.rikka.shizuku:api:12.2.0' 56 | implementation 'dev.rikka.shizuku:provider:12.2.0' 57 | implementation 'org.lsposed.hiddenapibypass:hiddenapibypass:4.3' 58 | } 59 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/aidl/android/content/om/OverlayInfo.aidl: -------------------------------------------------------------------------------- 1 | package android.content.om; 2 | 3 | parcelable OverlayInfo; -------------------------------------------------------------------------------- /app/src/main/aidl/tk/zwander/overlaymanager/IRootBridge.aidl: -------------------------------------------------------------------------------- 1 | package tk.zwander.overlaymanager; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import tk.zwander.overlaymanager.proxy.OverlayInfo; 6 | 7 | interface IRootBridge { 8 | void destroy() = 16777114; 9 | 10 | Map getAllOverlays() = 1; 11 | List getOverlayInfosForTarget(in String packageName) = 2; 12 | OverlayInfo getOverlayInfo(in String packageName) = 3; 13 | OverlayInfo getOverlayInfoByIdentifier(in String identifier) = 11; 14 | 15 | boolean setOverlayEnabled(in String packageName, boolean enabled) = 4; 16 | void setOverlayEnabledByIdentifier(in String identifier, boolean enabled) = 5; 17 | boolean setOverlayEnabledExclusive(in String packageName, boolean enabled) = 6; 18 | boolean setOverlayEnabledExclusiveInCategory(in String packageName) = 7; 19 | boolean setOverlayPriority(in String packageName, in String packageToOutrank) = 8; 20 | boolean setOverlayHighestPriority(in String packageName) = 9; 21 | boolean setOverlayLowestPriority(in String packageName) = 10; 22 | void clearCache(in String packageName) = 12; 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/aidl/tk/zwander/overlaymanager/proxy/OverlayInfo.aidl: -------------------------------------------------------------------------------- 1 | package tk.zwander.overlaymanager.proxy; 2 | 3 | parcelable OverlayInfo; -------------------------------------------------------------------------------- /app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharee/OverlayManager/950d9c07859c3c966ab6443fe7ff782100763c87/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /app/src/main/java/tk/zwander/overlaymanager/App.kt: -------------------------------------------------------------------------------- 1 | package tk.zwander.overlaymanager 2 | 3 | import android.app.Application 4 | import android.content.ComponentName 5 | import android.content.Context 6 | import android.content.Intent 7 | 8 | import rikka.shizuku.Shizuku 9 | import rikka.shizuku.Shizuku.UserServiceArgs 10 | import android.os.IBinder 11 | 12 | import android.content.ServiceConnection 13 | import android.os.Build 14 | import android.util.Log 15 | import com.topjohnwu.superuser.Shell 16 | import com.topjohnwu.superuser.ipc.RootService 17 | import kotlinx.coroutines.* 18 | import org.lsposed.hiddenapibypass.HiddenApiBypass 19 | import tk.zwander.overlaymanager.root.IRootBridgeImpl 20 | import tk.zwander.overlaymanager.root.RootBridgeService 21 | import tk.zwander.overlaymanager.util.shizukuAvailable 22 | 23 | 24 | class App : Application(), CoroutineScope by MainScope() { 25 | companion object { 26 | init { 27 | Shell.enableVerboseLogging = BuildConfig.DEBUG 28 | Shell.setDefaultBuilder(Shell.Builder.create() 29 | .setFlags(Shell.FLAG_REDIRECT_STDERR) 30 | .setTimeout(10) 31 | ) 32 | } 33 | } 34 | 35 | val receiver by lazy { Receiver() } 36 | 37 | override fun onCreate() { 38 | super.onCreate() 39 | 40 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { 41 | HiddenApiBypass.setHiddenApiExemptions("L") 42 | } 43 | 44 | async(Dispatchers.IO) { 45 | if (!shizukuAvailable && Shell.rootAccess()) { 46 | receiver.bindRoot(this@App) 47 | } 48 | } 49 | } 50 | 51 | class Receiver : CoroutineScope by MainScope() { 52 | private val userServiceStandaloneProcessArgs = UserServiceArgs( 53 | ComponentName( 54 | BuildConfig.APPLICATION_ID, 55 | IRootBridgeImpl::class.java.name 56 | ) 57 | ) 58 | .daemon(false) 59 | .tag("OverlayManager") 60 | .processNameSuffix("oms") 61 | .debuggable(BuildConfig.DEBUG) 62 | .version(BuildConfig.VERSION_CODE) 63 | 64 | private val userServiceConnection: ServiceConnection = object : ServiceConnection { 65 | override fun onServiceConnected(componentName: ComponentName, binder: IBinder?) { 66 | if (binder != null && binder.pingBinder()) { 67 | val service: IRootBridge = IRootBridge.Stub.asInterface(binder) 68 | ipc = service 69 | } 70 | } 71 | 72 | override fun onServiceDisconnected(componentName: ComponentName) { 73 | ipc = null 74 | } 75 | } 76 | 77 | private val queuedActions = ArrayList<(IRootBridge) -> Unit>() 78 | 79 | private val ipcLock = Any() 80 | 81 | private var ipc: IRootBridge? = null 82 | set(value) { 83 | launch { 84 | synchronized(ipcLock) { 85 | field = value 86 | 87 | if (value != null) { 88 | queuedActions.forEach { it.invoke(ipc!!) } 89 | queuedActions.clear() 90 | } 91 | } 92 | } 93 | } 94 | 95 | fun postAction(action: (IRootBridge) -> Unit) { 96 | if (ipc == null) { 97 | queuedActions.add(action) 98 | } else { 99 | action.invoke(ipc!!) 100 | } 101 | } 102 | 103 | fun tryBindShizuku() { 104 | try { 105 | Log.e("OverlayManager", "starting Shizuku") 106 | if (Shizuku.getVersion() >= 10) { 107 | Shizuku.bindUserService(userServiceStandaloneProcessArgs, userServiceConnection) 108 | } 109 | } catch (tr: Throwable) { 110 | Log.e("OverlayManager", "error starting Shizuku") 111 | tr.printStackTrace() 112 | } 113 | } 114 | 115 | fun bindRoot(context: Context) { 116 | RootService.bind( 117 | Intent(context, RootBridgeService::class.java), 118 | userServiceConnection 119 | ) 120 | } 121 | 122 | suspend fun awaitBridge(): IRootBridge { 123 | return withContext(Dispatchers.IO) { 124 | while (ipc == null) {} 125 | ipc!! 126 | } 127 | } 128 | } 129 | } -------------------------------------------------------------------------------- /app/src/main/java/tk/zwander/overlaymanager/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package tk.zwander.overlaymanager 2 | 3 | import android.content.Context 4 | import android.content.pm.PackageManager 5 | import android.content.res.Configuration 6 | import android.os.Bundle 7 | import android.os.Handler 8 | import android.util.Log 9 | import android.view.Menu 10 | import android.view.MenuItem 11 | import android.view.View 12 | import android.view.ViewTreeObserver 13 | import android.view.inputmethod.InputMethodManager 14 | import androidx.appcompat.app.AppCompatActivity 15 | import androidx.appcompat.widget.SearchView 16 | import androidx.core.view.isVisible 17 | import androidx.recyclerview.widget.LinearLayoutManager 18 | import androidx.recyclerview.widget.RecyclerView 19 | import com.google.android.material.dialog.MaterialAlertDialogBuilder 20 | import com.topjohnwu.superuser.Shell 21 | import kotlinx.coroutines.* 22 | import tk.zwander.overlaymanager.data.BatchedUpdate 23 | import tk.zwander.overlaymanager.data.ObservableHashMap 24 | import tk.zwander.overlaymanager.databinding.ActivityMainBinding 25 | import tk.zwander.overlaymanager.proxy.OverlayInfo 26 | import tk.zwander.overlaymanager.ui.TargetAdapter 27 | import tk.zwander.overlaymanager.util.* 28 | import java.util.* 29 | import kotlin.collections.HashMap 30 | 31 | class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() { 32 | private val batchedUpdates = ObservableHashMap() 33 | private val targetAdapter by lazy { TargetAdapter(this, batchedUpdates) } 34 | private val imm by lazy { getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager } 35 | private val binding by lazy { ActivityMainBinding.inflate(layoutInflater) } 36 | 37 | private var progressItem: MenuItem? = null 38 | private var unappliedAlert: MenuItem? = null 39 | private var doneLoading = false 40 | private var searchView: SearchView? = null 41 | 42 | private val layoutListener = ViewTreeObserver.OnGlobalLayoutListener { 43 | val closed = imm::class.java 44 | .getMethod("getInputMethodWindowVisibleHeight") 45 | .invoke(imm)!!.toString().toInt() <= 0 46 | 47 | if (closed) onKeyboardClose() 48 | else onKeyboardOpen() 49 | } 50 | 51 | override fun onCreate(savedInstanceState: Bundle?) { 52 | super.onCreate(savedInstanceState) 53 | setContentView(binding.root) 54 | setSupportActionBar(binding.bottomBar) 55 | setTitle(R.string.app_name) 56 | 57 | launch(Dispatchers.IO) { 58 | if (Shell.rootAccess() || shizukuGranted) { 59 | doLoad() 60 | } else if (shizukuAvailable && !shizukuGranted) { 61 | requestShizukuPermission(100) { _, result -> 62 | if (result == PackageManager.PERMISSION_GRANTED) { 63 | doLoad() 64 | } else { 65 | finish() 66 | } 67 | } 68 | } else { 69 | launch(Dispatchers.Main) { 70 | MaterialAlertDialogBuilder(this@MainActivity) 71 | .setTitle(R.string.shizuku_root_required_title) 72 | .setMessage(R.string.shizuku_root_required_msg) 73 | .setCancelable(false) 74 | .setPositiveButton(android.R.string.ok) { _, _ -> 75 | finish() 76 | } 77 | .setNegativeButton(R.string.shizuku_root_get_shizuku) { _, _ -> 78 | launchUrl("https://github.com/RikkaApps/Shizuku/releases") 79 | finish() 80 | } 81 | .show() 82 | } 83 | } 84 | } 85 | } 86 | 87 | override fun onRequestPermissionsResult( 88 | requestCode: Int, 89 | permissions: Array, 90 | grantResults: IntArray 91 | ) { 92 | super.onRequestPermissionsResult(requestCode, permissions, grantResults) 93 | 94 | if (requestCode == 100) { 95 | if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { 96 | doLoad() 97 | } else { 98 | finish() 99 | } 100 | } 101 | } 102 | 103 | private fun doLoad() = launch(Dispatchers.Main) { 104 | if (shizukuAvailable) { 105 | app.receiver.tryBindShizuku() 106 | } 107 | 108 | binding.targetList.adapter = targetAdapter 109 | 110 | binding.targetList.layoutManager = LinearLayoutManager(this@MainActivity, RecyclerView.VERTICAL, false) 111 | binding.targetList.addItemDecoration(DividerItemDecoration(this@MainActivity, RecyclerView.VERTICAL)) 112 | 113 | binding.content.layoutTransition = layoutTransition 114 | 115 | binding.matchOverlays.setOnCheckedChangeListener { _, isChecked -> 116 | targetAdapter.matchOverlays = isChecked 117 | } 118 | 119 | val rootBridge = app.receiver.awaitBridge() 120 | 121 | @Suppress("UNCHECKED_CAST") 122 | targetAdapter.setItems( 123 | packageManager, 124 | rootBridge.allOverlays as MutableMap> 125 | ) 126 | 127 | doneLoading = true 128 | progressItem?.isVisible = false 129 | binding.changeAllWrapper.isVisible = true 130 | binding.apply.isVisible = true 131 | 132 | binding.apply.setOnClickListener { 133 | MaterialAlertDialogBuilder(this@MainActivity) 134 | .setTitle(R.string.apply_changes) 135 | .setMessage(R.string.apply_overlays_desc) 136 | .setPositiveButton(android.R.string.ok) {_, _ -> 137 | val copy = HashMap(batchedUpdates) 138 | batchedUpdates.clear() 139 | 140 | copy.forEach { (_, u) -> 141 | u(rootBridge) 142 | } 143 | 144 | targetAdapter.notifyChanged() 145 | } 146 | .setNegativeButton(android.R.string.cancel, null) 147 | .show() 148 | } 149 | 150 | binding.enableAll.setOnClickListener { 151 | targetAdapter.orig.forEach { td -> 152 | td.info.forEach { info -> 153 | val i = info.createEnabledUpdate(true) 154 | batchedUpdates[i.first] = i.second 155 | 156 | info.showEnabled = true 157 | } 158 | } 159 | targetAdapter.notifyChanged() 160 | } 161 | 162 | binding.disableAll.setOnClickListener { 163 | targetAdapter.orig.forEach { td -> 164 | td.info.forEach { info -> 165 | val i = info.createEnabledUpdate(false) 166 | batchedUpdates[i.first] = i.second 167 | 168 | info.showEnabled = false 169 | } 170 | } 171 | targetAdapter.notifyChanged() 172 | } 173 | 174 | binding.expandAll.setOnClickListener { 175 | targetAdapter.setAllExpanded(true) 176 | } 177 | 178 | binding.collapseAll.setOnClickListener { 179 | targetAdapter.setAllExpanded(false) 180 | } 181 | 182 | binding.content.viewTreeObserver.addOnGlobalLayoutListener(layoutListener) 183 | } 184 | 185 | override fun onDestroy() { 186 | super.onDestroy() 187 | 188 | cancel() 189 | binding.content.viewTreeObserver.removeOnGlobalLayoutListener(layoutListener) 190 | } 191 | 192 | override fun setTitle(titleId: Int) { 193 | title = getText(titleId) 194 | } 195 | 196 | override fun setTitle(title: CharSequence?) { 197 | binding.titleText.text = title 198 | super.setTitle(null) 199 | } 200 | 201 | override fun onCreateOptionsMenu(m: Menu): Boolean { 202 | val menu = binding.actionMenu.menu 203 | menuInflater.inflate(R.menu.search, menu) 204 | 205 | val searchItem = menu.findItem(R.id.action_search) 206 | searchView = searchItem?.actionView as SearchView? 207 | 208 | searchView?.setOnSearchClickListener { 209 | binding.matchOverlays.isVisible = true 210 | binding.changeAllWrapper.isVisible = false 211 | } 212 | 213 | searchView?.setOnCloseListener { 214 | binding.matchOverlays.isVisible = false 215 | binding.changeAllWrapper.isVisible = true 216 | false 217 | } 218 | 219 | searchView?.setOnQueryTextListener(targetAdapter) 220 | 221 | progressItem = menu.findItem(R.id.progress) 222 | if (doneLoading) { 223 | progressItem?.isVisible = false 224 | } 225 | 226 | unappliedAlert = menu.findItem(R.id.unappliedChanges) 227 | unappliedAlert?.isVisible = batchedUpdates.isNotEmpty() 228 | unappliedAlert?.setOnMenuItemClickListener { 229 | MaterialAlertDialogBuilder(this) 230 | .setTitle(R.string.unapplied_changes) 231 | .setMessage(R.string.unapplied_changes_desc) 232 | .setPositiveButton(android.R.string.ok, null) 233 | .show() 234 | true 235 | } 236 | 237 | batchedUpdates.addObserver { _, _ -> 238 | val notEmpty = batchedUpdates.isNotEmpty() 239 | unappliedAlert?.isVisible = notEmpty 240 | } 241 | 242 | return true 243 | } 244 | 245 | private fun onKeyboardOpen() { 246 | binding.titleText.isVisible = false 247 | binding.titleBorder.isVisible = false 248 | } 249 | 250 | private fun onKeyboardClose() { 251 | binding.titleText.isVisible = true 252 | binding.titleBorder.isVisible = true 253 | } 254 | } 255 | -------------------------------------------------------------------------------- /app/src/main/java/tk/zwander/overlaymanager/data/BatchedUpdate.kt: -------------------------------------------------------------------------------- 1 | package tk.zwander.overlaymanager.data 2 | 3 | import tk.zwander.overlaymanager.IRootBridge 4 | 5 | data class BatchedUpdate(val key: String, val action: (IRootBridge) -> Unit): (IRootBridge) -> Unit { 6 | override fun invoke(p1: IRootBridge) { 7 | action(p1) 8 | } 9 | } -------------------------------------------------------------------------------- /app/src/main/java/tk/zwander/overlaymanager/data/ObservableHashMap.kt: -------------------------------------------------------------------------------- 1 | package tk.zwander.overlaymanager.data 2 | 3 | import java.util.* 4 | import kotlin.collections.HashMap 5 | 6 | class ObservableHashMap : Observable(), MutableMap { 7 | private val wrapped = HashMap() 8 | 9 | override val size: Int 10 | get() = wrapped.size 11 | override val entries: MutableSet> 12 | get() = wrapped.entries 13 | override val keys: MutableSet 14 | get() = wrapped.keys 15 | override val values: MutableCollection 16 | get() = wrapped.values 17 | 18 | override fun containsKey(key: Key): Boolean { 19 | return wrapped.containsKey(key) 20 | } 21 | 22 | override fun containsValue(value: Value): Boolean { 23 | return wrapped.containsValue(value) 24 | } 25 | 26 | override fun get(key: Key): Value? { 27 | return wrapped[key] 28 | } 29 | 30 | override fun isEmpty(): Boolean { 31 | return wrapped.isEmpty() 32 | } 33 | 34 | override fun clear() { 35 | wrapped.clear() 36 | setChangedAndNotifyObservers() 37 | } 38 | 39 | override fun put(key: Key, value: Value): Value? { 40 | return wrapped.put(key, value).also { 41 | setChangedAndNotifyObservers() 42 | } 43 | } 44 | 45 | override fun putAll(from: Map) { 46 | wrapped.putAll(from) 47 | setChangedAndNotifyObservers() 48 | } 49 | 50 | override fun remove(key: Key): Value? { 51 | return wrapped.remove(key).also { 52 | setChangedAndNotifyObservers() 53 | } 54 | } 55 | 56 | private fun setChangedAndNotifyObservers() { 57 | setChanged() 58 | notifyObservers() 59 | } 60 | } -------------------------------------------------------------------------------- /app/src/main/java/tk/zwander/overlaymanager/data/TargetData.kt: -------------------------------------------------------------------------------- 1 | package tk.zwander.overlaymanager.data 2 | 3 | import android.content.Context 4 | import android.content.pm.ApplicationInfo 5 | import android.graphics.drawable.Drawable 6 | import tk.zwander.overlaymanager.proxy.OverlayInfo 7 | 8 | data class TargetData( 9 | val appInfo: ApplicationInfo, 10 | val info: List, 11 | var expanded: Boolean = false 12 | ) { 13 | private var label: CharSequence? = null 14 | 15 | fun getLabel(context: Context): CharSequence { 16 | if (label != null) return label!! 17 | 18 | return appInfo.loadLabel(context.packageManager) 19 | } 20 | } -------------------------------------------------------------------------------- /app/src/main/java/tk/zwander/overlaymanager/proxy/IOverlayManager.kt: -------------------------------------------------------------------------------- 1 | package tk.zwander.overlaymanager.proxy 2 | 3 | import android.annotation.SuppressLint 4 | import android.os.IBinder 5 | import android.os.Parcelable 6 | import java.lang.reflect.Method 7 | 8 | @Suppress("UNCHECKED_CAST") 9 | @SuppressLint("PrivateApi") 10 | class IOverlayManager { 11 | companion object { 12 | private val clazz = Class.forName("android.content.om.IOverlayManager") 13 | private val stubClass = Class.forName("android.content.om.IOverlayManager\$Stub") 14 | private val omtbClass = 15 | Class.forName("android.content.om.OverlayManagerTransaction\$Builder") 16 | private val omtClass = Class.forName("android.content.om.OverlayManagerTransaction") 17 | private val oiClass = Class.forName("android.content.om.OverlayIdentifier") 18 | 19 | fun getIdentifier(packageName: String, overlayName: String?): Any { 20 | return oiClass.getConstructor( 21 | String::class.java, 22 | String::class.java 23 | ).newInstance(packageName, overlayName) 24 | } 25 | 26 | fun getIdentifier(source: String): Any { 27 | return oiClass.getMethod( 28 | "fromString", 29 | String::class.java 30 | ).invoke( 31 | null, 32 | source 33 | )!! 34 | } 35 | } 36 | 37 | private val obj = run { 38 | val svcManClass = Class.forName("android.os.ServiceManager") 39 | val getService = svcManClass.getMethod("getService", String::class.java) 40 | val asInterface = stubClass.getMethod("asInterface", IBinder::class.java) 41 | 42 | val b = getService.invoke(null, "overlay") 43 | 44 | asInterface.invoke(null, b) 45 | } 46 | 47 | fun getAllOverlays(): MutableMap> { 48 | val r = invokeMethod>(getMethod("getAllOverlays", Int::class.java), -2) 49 | val ret = HashMap>() 50 | 51 | r.forEach { (key, value) -> 52 | val l = ArrayList() 53 | 54 | (value as List<*>).forEach { 55 | l.add(OverlayInfo(it as Parcelable)) 56 | } 57 | 58 | ret[key as String] = l 59 | } 60 | 61 | return ret 62 | } 63 | 64 | fun getOverlayInfosForTarget(packageName: String) = 65 | invokeMethod>( 66 | getMethod( 67 | "getOverlayInfosForTarget", 68 | String::class.java, Int::class.java 69 | ), packageName, -2 70 | ).map { OverlayInfo(it as Parcelable) } 71 | 72 | fun getOverlayInfo(packageName: String) = 73 | OverlayInfo( 74 | invokeMethod( 75 | getMethod( 76 | "getOverlayInfo", 77 | String::class.java, Int::class.java 78 | ), packageName, -2 79 | ) 80 | ) 81 | 82 | fun getOverlayInfoByIdentifier(identifier: Any) = 83 | OverlayInfo( 84 | invokeMethod( 85 | getMethod( 86 | "getOverlayInfoByIdentifier", 87 | oiClass, 88 | Int::class.java 89 | ), 90 | identifier, -2 91 | ) 92 | ) 93 | 94 | fun setEnabled(packageName: String, enable: Boolean) = 95 | invokeMethod( 96 | getMethod("setEnabled", String::class.java, Boolean::class.java, Int::class.java), 97 | packageName, enable, -2 98 | ) 99 | 100 | fun setEnabled(identifier: Any, enable: Boolean) { 101 | val builder = omtbClass.newInstance() 102 | 103 | omtbClass.getMethod( 104 | "setEnabled", 105 | oiClass, 106 | Boolean::class.java, 107 | Int::class.java 108 | ).invoke( 109 | builder, 110 | identifier, 111 | enable, 112 | -2 113 | ) 114 | 115 | commit( 116 | omtbClass.getMethod("build") 117 | .invoke(builder)!! 118 | ) 119 | } 120 | 121 | fun setEnabledExclusive(packageName: String, enable: Boolean) = 122 | invokeMethod( 123 | getMethod( 124 | "setEnabledExclusive", 125 | String::class.java, 126 | Boolean::class.java, 127 | Int::class.java 128 | ), 129 | packageName, enable, -2 130 | ) 131 | 132 | fun setEnabledExclusiveInCategory(packageName: String) = 133 | invokeMethod( 134 | getMethod("setEnabledExclusiveInCategory", String::class.java, Int::class.java), 135 | packageName, -2 136 | ) 137 | 138 | fun setPriority(packageName: String, packageToOutrank: String) = 139 | invokeMethod( 140 | getMethod("setPriority", String::class.java, String::class.java, Int::class.java), 141 | packageName, packageToOutrank, -2 142 | ) 143 | 144 | fun setHighestPriority(packageName: String) = 145 | invokeMethod( 146 | getMethod("setHighestPriority", String::class.java, Int::class.java), 147 | packageName, -2 148 | ) 149 | 150 | fun setLowestPriority(packageName: String) = 151 | invokeMethod( 152 | getMethod("setLowestPriority", String::class.java, Int::class.java), 153 | packageName, -2 154 | ) 155 | 156 | fun commit(transaction: Any) = 157 | invokeMethod( 158 | getMethod("commit", omtClass), 159 | transaction 160 | ) 161 | 162 | fun clearCache(packageName: String) { 163 | invokeMethod( 164 | getMethod("invalidateCachesForOverlay", String::class.java, Int::class.java), 165 | packageName, -2 166 | ) 167 | } 168 | 169 | private fun getMethod(methodName: String, vararg args: Class<*>) = 170 | clazz.getMethod(methodName, *args) 171 | 172 | private fun invokeMethod(method: Method, vararg args: Any): T { 173 | return method.invoke(obj, *args) as T 174 | } 175 | } -------------------------------------------------------------------------------- /app/src/main/java/tk/zwander/overlaymanager/proxy/OverlayInfo.kt: -------------------------------------------------------------------------------- 1 | package tk.zwander.overlaymanager.proxy 2 | 3 | import android.annotation.SuppressLint 4 | import android.os.Build 5 | import android.os.Parcelable 6 | import kotlinx.parcelize.IgnoredOnParcel 7 | import kotlinx.parcelize.Parcelize 8 | import java.lang.reflect.Method 9 | 10 | @Suppress("UNCHECKED_CAST") 11 | @SuppressLint("PrivateApi") 12 | @Parcelize 13 | class OverlayInfo(private var instance: Parcelable) : Parcelable { 14 | companion object { 15 | private val infoClass = Class.forName("android.content.om.OverlayInfo") 16 | 17 | const val STATE_UNKNOWN = -1 18 | const val STATE_MISSING_TARGET = 0 19 | const val STATE_NO_IDMAP = 1 20 | const val STATE_DISABLED = 2 21 | const val STATE_ENABLED = 3 22 | const val STATE_TARGET_UPDGRADING = 4 23 | const val STATE_OVERLAY_UPGRADING = 5 24 | const val STATE_ENABLED_STATIC = 6 25 | 26 | const val CATEGORY_THEME = "android.theme" 27 | 28 | fun stateToString(state: Int): String { 29 | return infoClass.getMethod("stateToString", Int::class.java) 30 | .invoke(null, state) as String 31 | } 32 | } 33 | 34 | init { 35 | if (instance::class.java.canonicalName != infoClass.canonicalName) { 36 | throw IllegalStateException("${instance::class.java.canonicalName} is not an OverlayInfo instance") 37 | } 38 | } 39 | 40 | val packageName: String 41 | get() = getField("packageName") 42 | 43 | val targetPackageName: String 44 | get() = getField("targetPackageName") 45 | 46 | val category: String 47 | get() = getField("category") 48 | 49 | val baseCodePath: String 50 | get() = getField("baseCodePath") 51 | 52 | val state: Int 53 | get() = getField("state") 54 | 55 | val userId: Int 56 | get() = getField("userId") 57 | 58 | val priority: Int 59 | get() = getField("priority") 60 | 61 | val isStatic: Boolean 62 | get() = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) { 63 | !getField("isMutable") 64 | } else getField("isStatic") 65 | 66 | val isEnabled: Boolean 67 | get() = invokeMethod(getMethod("isEnabled")) 68 | 69 | val isFabricated: Boolean 70 | get() = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) { 71 | invokeMethod(getMethod("isFabricated")) 72 | } else { 73 | false 74 | } 75 | 76 | val identifier: Any? 77 | get() = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) { 78 | invokeMethod(getMethod("getOverlayIdentifier")) 79 | } else { 80 | null 81 | } 82 | 83 | val idStringOrPackageName: String 84 | get() = identifier?.toString() ?: packageName 85 | 86 | @IgnoredOnParcel 87 | var showEnabled = isEnabled 88 | 89 | fun updateInstance(instance: OverlayInfo) { 90 | this.instance = instance.instance 91 | showEnabled = isEnabled 92 | } 93 | 94 | private fun getField(fieldName: String) = 95 | infoClass.getField(fieldName).get(instance) as T 96 | 97 | private fun getMethod(methodName: String, vararg args: Class<*>) = 98 | infoClass.getMethod(methodName, *args) 99 | 100 | private fun invokeMethod(method: Method, vararg args: Any) = 101 | method.invoke(instance, *args) as T 102 | } -------------------------------------------------------------------------------- /app/src/main/java/tk/zwander/overlaymanager/root/IRootBridgeImpl.kt: -------------------------------------------------------------------------------- 1 | package tk.zwander.overlaymanager.root 2 | 3 | import android.os.Build 4 | import org.lsposed.hiddenapibypass.HiddenApiBypass 5 | import tk.zwander.overlaymanager.IRootBridge 6 | import tk.zwander.overlaymanager.proxy.IOverlayManager 7 | import tk.zwander.overlaymanager.proxy.OverlayInfo 8 | import kotlin.system.exitProcess 9 | 10 | class IRootBridgeImpl : IRootBridge.Stub() { 11 | init { 12 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { 13 | HiddenApiBypass.setHiddenApiExemptions("L") 14 | } 15 | } 16 | 17 | private val om = IOverlayManager() 18 | 19 | override fun getAllOverlays(): MutableMap> = 20 | om.getAllOverlays() 21 | 22 | override fun getOverlayInfosForTarget(packageName: String): List = 23 | om.getOverlayInfosForTarget(packageName) 24 | 25 | override fun getOverlayInfo(packageName: String) = 26 | om.getOverlayInfo(packageName) 27 | 28 | override fun getOverlayInfoByIdentifier(identifier: String) = 29 | om.getOverlayInfoByIdentifier(IOverlayManager.getIdentifier(identifier)) 30 | 31 | override fun setOverlayEnabled(packageName: String, enabled: Boolean) = 32 | om.setEnabled(packageName, enabled) 33 | 34 | override fun setOverlayEnabledByIdentifier(identifier: String, enabled: Boolean) = 35 | om.setEnabled(IOverlayManager.getIdentifier(identifier), enabled) 36 | 37 | override fun setOverlayEnabledExclusive(packageName: String, enabled: Boolean) = 38 | om.setEnabledExclusive(packageName, enabled) 39 | 40 | override fun setOverlayEnabledExclusiveInCategory(packageName: String) = 41 | om.setEnabledExclusiveInCategory(packageName) 42 | 43 | override fun setOverlayPriority(packageName: String, packageToOutrank: String) = 44 | om.setPriority(packageName, packageToOutrank) 45 | 46 | override fun setOverlayHighestPriority(packageName: String) = 47 | om.setHighestPriority(packageName) 48 | 49 | override fun setOverlayLowestPriority(packageName: String) = 50 | om.setLowestPriority(packageName) 51 | 52 | override fun clearCache(packageName: String) = 53 | om.clearCache(packageName) 54 | 55 | override fun destroy() { 56 | exitProcess(0) 57 | } 58 | } -------------------------------------------------------------------------------- /app/src/main/java/tk/zwander/overlaymanager/root/RootBridgeService.kt: -------------------------------------------------------------------------------- 1 | package tk.zwander.overlaymanager.root 2 | 3 | import android.content.Intent 4 | import android.os.IBinder 5 | import com.topjohnwu.superuser.ipc.RootService 6 | 7 | class RootBridgeService : RootService() { 8 | override fun onBind(intent: Intent): IBinder { 9 | return IRootBridgeImpl() 10 | } 11 | } -------------------------------------------------------------------------------- /app/src/main/java/tk/zwander/overlaymanager/ui/OverlayAdapter.kt: -------------------------------------------------------------------------------- 1 | package tk.zwander.overlaymanager.ui 2 | 3 | import android.view.LayoutInflater 4 | import android.view.View 5 | import android.view.ViewGroup 6 | import androidx.recyclerview.widget.RecyclerView 7 | import androidx.recyclerview.widget.SortedList 8 | import tk.zwander.overlaymanager.R 9 | import tk.zwander.overlaymanager.data.BatchedUpdate 10 | import tk.zwander.overlaymanager.databinding.OverlayItemBinding 11 | import tk.zwander.overlaymanager.proxy.OverlayInfo 12 | import tk.zwander.overlaymanager.util.createEnabledUpdate 13 | import tk.zwander.overlaymanager.util.createPriorityUpdate 14 | 15 | class OverlayAdapter(private val batchedUpdates: MutableMap) : RecyclerView.Adapter() { 16 | private val items = SortedList(OverlayInfo::class.java, object : SortedList.Callback() { 17 | override fun areItemsTheSame(item1: OverlayInfo?, item2: OverlayInfo?) = 18 | item1 == item2 19 | 20 | override fun onMoved(fromPosition: Int, toPosition: Int) { 21 | notifyItemMoved(fromPosition, toPosition) 22 | } 23 | 24 | override fun onChanged(position: Int, count: Int) { 25 | notifyItemRangeChanged(position, count) 26 | } 27 | 28 | override fun onInserted(position: Int, count: Int) { 29 | notifyItemRangeInserted(position, count) 30 | } 31 | 32 | override fun onRemoved(position: Int, count: Int) { 33 | notifyItemRangeRemoved(position, count) 34 | } 35 | 36 | override fun compare(o1: OverlayInfo, o2: OverlayInfo) = 37 | if (o1.showEnabled && !o2.showEnabled) -1 else if (!o1.showEnabled && o2.showEnabled) 1 else { 38 | o1.idStringOrPackageName.compareTo(o2.idStringOrPackageName) 39 | } 40 | 41 | override fun areContentsTheSame(oldItem: OverlayInfo, newItem: OverlayInfo) = 42 | oldItem.idStringOrPackageName == newItem.idStringOrPackageName 43 | 44 | }) 45 | 46 | override fun getItemCount() = items.size() 47 | 48 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): OverlayHolder { 49 | return OverlayHolder( 50 | LayoutInflater.from(parent.context) 51 | .inflate(R.layout.overlay_item, parent, false) 52 | ) 53 | } 54 | 55 | override fun onBindViewHolder(holder: OverlayHolder, position: Int) { 56 | holder.bindInfo(items[position], itemCount) 57 | } 58 | 59 | fun setItems(list: List) { 60 | items.clear() 61 | items.addAll(list) 62 | } 63 | 64 | inner class OverlayHolder(view: View) : RecyclerView.ViewHolder(view) { 65 | private val binding = OverlayItemBinding.bind(itemView) 66 | 67 | fun bindInfo(info: OverlayInfo, size: Int) { 68 | itemView.apply { 69 | binding.overlayPackage.text = info.idStringOrPackageName 70 | 71 | binding.enabled.setOnCheckedChangeListener(null) 72 | 73 | if (info.isStatic) { 74 | binding.enabled.isChecked = true 75 | binding.enabled.isEnabled = false 76 | } else { 77 | binding.enabled.isChecked = info.showEnabled 78 | 79 | binding.enabled.setOnCheckedChangeListener { _, isChecked -> 80 | val item = items.get(bindingAdapterPosition) 81 | val update = item.createEnabledUpdate(isChecked) 82 | 83 | batchedUpdates[update.first] = update.second 84 | item.showEnabled = isChecked 85 | items.recalculatePositionOfItemAt(bindingAdapterPosition) 86 | } 87 | } 88 | 89 | binding.priority.text = itemView.context.resources.getString(R.string.priority, info.priority) 90 | 91 | binding.setHighestPriority.isEnabled = size > 1 && !info.isFabricated 92 | binding.setLowestPriority.isEnabled = size > 1 && !info.isFabricated 93 | 94 | if (size > 1) { 95 | binding.setHighestPriority.setOnClickListener { 96 | val item = items[bindingAdapterPosition] 97 | val update = item.createPriorityUpdate(true) { 98 | notifyItemChanged(bindingAdapterPosition) 99 | } 100 | 101 | batchedUpdates[update.first] = update.second 102 | } 103 | 104 | binding.setLowestPriority.setOnClickListener { 105 | val item = items[bindingAdapterPosition] 106 | val update = item.createPriorityUpdate(false) { 107 | notifyItemChanged(bindingAdapterPosition) 108 | } 109 | 110 | batchedUpdates[update.first] = update.second 111 | } 112 | } 113 | } 114 | } 115 | } 116 | } -------------------------------------------------------------------------------- /app/src/main/java/tk/zwander/overlaymanager/ui/TargetAdapter.kt: -------------------------------------------------------------------------------- 1 | package tk.zwander.overlaymanager.ui 2 | 3 | import android.content.Context 4 | import android.content.pm.PackageManager 5 | import android.net.Uri 6 | import android.view.LayoutInflater 7 | import android.view.View 8 | import android.view.ViewGroup 9 | import androidx.appcompat.widget.SearchView 10 | import androidx.core.graphics.drawable.toBitmap 11 | import androidx.core.view.isVisible 12 | import androidx.recyclerview.widget.LinearLayoutManager 13 | import androidx.recyclerview.widget.RecyclerView 14 | import androidx.recyclerview.widget.SortedList 15 | import com.squareup.picasso.Picasso 16 | import com.squareup.picasso.Request 17 | import com.squareup.picasso.RequestHandler 18 | import kotlinx.coroutines.* 19 | import tk.zwander.overlaymanager.R 20 | import tk.zwander.overlaymanager.data.BatchedUpdate 21 | import tk.zwander.overlaymanager.data.TargetData 22 | import tk.zwander.overlaymanager.databinding.TargetItemBinding 23 | import tk.zwander.overlaymanager.proxy.OverlayInfo 24 | import tk.zwander.overlaymanager.util.DividerItemDecoration 25 | import kotlin.collections.ArrayList 26 | 27 | class TargetAdapter( 28 | private val context: Context, 29 | private val batchedUpdates: MutableMap 30 | ) : RecyclerView.Adapter(), SearchView.OnQueryTextListener, 31 | CoroutineScope by MainScope() { 32 | val items = SortedList(TargetData::class.java, object : SortedList.Callback() { 33 | override fun areItemsTheSame(item1: TargetData?, item2: TargetData?) = 34 | item1 == item2 35 | 36 | override fun onMoved(fromPosition: Int, toPosition: Int) { 37 | notifyItemMoved(fromPosition, toPosition) 38 | } 39 | 40 | override fun onChanged(position: Int, count: Int) { 41 | notifyItemRangeChanged(position, count) 42 | } 43 | 44 | override fun onInserted(position: Int, count: Int) { 45 | notifyItemRangeInserted(position, count) 46 | } 47 | 48 | override fun onRemoved(position: Int, count: Int) { 49 | notifyItemRangeRemoved(position, count) 50 | } 51 | 52 | override fun compare(o1: TargetData, o2: TargetData) = 53 | o1.getLabel(context).toString().compareTo(o2.getLabel(context).toString()) 54 | 55 | override fun areContentsTheSame(oldItem: TargetData, newItem: TargetData) = 56 | oldItem.appInfo.packageName == newItem.appInfo.packageName 57 | 58 | }) 59 | val orig = object : ArrayList() { 60 | override fun add(element: TargetData): Boolean { 61 | if (matches(currentQuery, element)) { 62 | items.add(element) 63 | } 64 | return super.add(element) 65 | } 66 | 67 | override fun addAll(elements: Collection): Boolean { 68 | items.addAll(elements.filter { matches(currentQuery, it) }) 69 | return super.addAll(elements) 70 | } 71 | 72 | override fun remove(element: TargetData): Boolean { 73 | items.remove(element) 74 | return super.remove(element) 75 | } 76 | } 77 | 78 | private var currentQuery: String = "" 79 | private var recyclerView: RecyclerView? = null 80 | 81 | var matchOverlays = false 82 | set(value) { 83 | field = value 84 | 85 | onQueryTextChange(currentQuery) 86 | } 87 | 88 | override fun onQueryTextChange(newText: String?): Boolean { 89 | currentQuery = newText ?: "" 90 | 91 | items.replaceAll(filter(currentQuery)) 92 | recyclerView?.scrollToPosition(0) 93 | 94 | return true 95 | } 96 | 97 | override fun onQueryTextSubmit(query: String?): Boolean { 98 | return false 99 | } 100 | 101 | override fun onAttachedToRecyclerView(recyclerView: RecyclerView) { 102 | this.recyclerView = recyclerView 103 | super.onAttachedToRecyclerView(recyclerView) 104 | } 105 | 106 | override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) { 107 | this.recyclerView = null 108 | cancel() 109 | super.onDetachedFromRecyclerView(recyclerView) 110 | } 111 | 112 | override fun getItemCount() = items.size() 113 | 114 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TargetHolder { 115 | return TargetHolder( 116 | LayoutInflater.from(parent.context) 117 | .inflate(R.layout.target_item, parent, false) 118 | ) 119 | } 120 | 121 | override fun onBindViewHolder(holder: TargetHolder, position: Int) { 122 | holder.bindInfo(items[position]) 123 | } 124 | 125 | fun setAllExpanded(expanded: Boolean) { 126 | orig.forEach { 127 | it.expanded = expanded 128 | } 129 | 130 | notifyDataSetChanged() 131 | } 132 | 133 | suspend fun setItems( 134 | packageManager: PackageManager, 135 | items: MutableMap> 136 | ) { 137 | orig.clear() 138 | orig.addAll( 139 | withContext(Dispatchers.IO) { 140 | items.map { 141 | try { 142 | val appInfo = packageManager.getApplicationInfo(it.key, 0) 143 | TargetData( 144 | appInfo, 145 | it.value 146 | ) 147 | } catch (e: Exception) { 148 | null 149 | } 150 | }.filterNotNull() 151 | } 152 | ) 153 | } 154 | 155 | fun notifyChanged() { 156 | notifyDataSetChanged() 157 | } 158 | 159 | private fun matches(query: String, data: TargetData): Boolean { 160 | if (query.isBlank()) return true 161 | 162 | if (data.getLabel(context).toString() 163 | .contains(query, true) 164 | || data.appInfo.packageName 165 | .contains(query, true) 166 | ) 167 | return true 168 | 169 | if (matchOverlays) { 170 | data.info.forEach { 171 | if (it.idStringOrPackageName.contains(query, true)) return true 172 | } 173 | } 174 | 175 | return false 176 | } 177 | 178 | private fun filter(query: String): List { 179 | val filteredModelList = ArrayList() 180 | 181 | for (i in 0 until orig.size) { 182 | val item = orig[i] 183 | 184 | if (matches(query, item)) filteredModelList.add(item) 185 | } 186 | 187 | return filteredModelList 188 | } 189 | 190 | private val picasso = Picasso.Builder(context) 191 | .addRequestHandler(AppIconHandler(context)) 192 | .build() 193 | 194 | inner class TargetHolder(view: View) : RecyclerView.ViewHolder(view) { 195 | private val binding = TargetItemBinding.bind(itemView) 196 | 197 | fun bindInfo(info: TargetData) { 198 | val adapter = OverlayAdapter(batchedUpdates) 199 | val imgView = binding.targetIcon 200 | 201 | picasso 202 | .load(Uri.parse("${AppIconHandler.SCHEME}:${info.appInfo.packageName}")) 203 | .resize(imgView.maxWidth, imgView.maxHeight) 204 | .onlyScaleDown() 205 | .centerInside() 206 | .into(imgView) 207 | 208 | binding.targetLabel.text = info.getLabel(itemView.context) 209 | binding.targetPkg.text = info.appInfo.packageName 210 | binding.count.text = 211 | itemView.resources.getString(R.string.overlay_count, info.info.size) 212 | binding.overlayList.adapter = adapter 213 | binding.overlayList.addItemDecoration( 214 | DividerItemDecoration( 215 | itemView.context, 216 | LinearLayoutManager.VERTICAL 217 | ) 218 | ) 219 | 220 | binding.overlayList.isVisible = info.expanded 221 | 222 | adapter.setItems(info.info) 223 | 224 | itemView.setOnClickListener { 225 | val i = items[bindingAdapterPosition] 226 | i.expanded = !i.expanded 227 | 228 | notifyItemChanged(bindingAdapterPosition) 229 | } 230 | } 231 | } 232 | 233 | class AppIconHandler(private val context: Context) : RequestHandler() { 234 | companion object { 235 | const val SCHEME = "package" 236 | } 237 | 238 | override fun canHandleRequest(data: Request): Boolean { 239 | return data.uri != null && data.uri.scheme == SCHEME 240 | } 241 | 242 | override fun load(request: Request, networkPolicy: Int): Result? { 243 | return Result( 244 | context.packageManager.getApplicationIcon(request.uri.schemeSpecificPart) 245 | .toBitmap(), 246 | Picasso.LoadedFrom.DISK 247 | ) 248 | } 249 | } 250 | } -------------------------------------------------------------------------------- /app/src/main/java/tk/zwander/overlaymanager/util/DividerItemDecoration.kt: -------------------------------------------------------------------------------- 1 | package tk.zwander.overlaymanager.util 2 | 3 | import android.content.Context 4 | import android.graphics.Canvas 5 | import android.graphics.Rect 6 | import android.graphics.drawable.Drawable 7 | import android.view.View 8 | import android.widget.LinearLayout 9 | import androidx.core.content.ContextCompat 10 | import androidx.recyclerview.widget.RecyclerView 11 | import tk.zwander.overlaymanager.R 12 | 13 | /** 14 | * Modified version of Android's DividerItemDecoration 15 | * that doesn't draw the divider after the last item 16 | * @see androidx.recyclerview.widget.DividerItemDecoration 17 | */ 18 | class DividerItemDecoration(context: Context, orientation: Int) : RecyclerView.ItemDecoration() { 19 | 20 | var divider: Drawable? = null 21 | set(drawable) { 22 | if (drawable == null) { 23 | throw IllegalArgumentException("Divider cannot be nulll") 24 | } 25 | 26 | field = drawable 27 | } 28 | 29 | /** 30 | * Current orientation. Either [.HORIZONTAL] or [.VERTICAL]. 31 | */ 32 | var orientation: Int = 0 33 | set(orientation) { 34 | if (orientation != HORIZONTAL && orientation != VERTICAL) { 35 | throw IllegalArgumentException( 36 | "Invalid orientation. It should be either HORIZONTAL or VERTICAL" 37 | ) 38 | } 39 | 40 | field = orientation 41 | } 42 | 43 | private val bounds = Rect() 44 | 45 | init { 46 | divider = ContextCompat.getDrawable(context, R.drawable.divider) 47 | this.orientation = orientation 48 | } 49 | 50 | override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) { 51 | if (parent.layoutManager == null || divider == null) { 52 | return 53 | } 54 | if (orientation == VERTICAL) { 55 | drawVertical(c, parent) 56 | } else { 57 | drawHorizontal(c, parent) 58 | } 59 | } 60 | 61 | private fun drawVertical(canvas: Canvas, parent: RecyclerView) { 62 | canvas.save() 63 | val left: Int 64 | val right: Int 65 | 66 | if (parent.clipToPadding) { 67 | left = parent.paddingLeft 68 | right = parent.width - parent.paddingRight 69 | canvas.clipRect( 70 | left, parent.paddingTop, right, 71 | parent.height - parent.paddingBottom 72 | ) 73 | } else { 74 | left = 0 75 | right = parent.width 76 | } 77 | 78 | val childCount = parent.childCount 79 | for (i in 0 until childCount - 1) { 80 | val child = parent.getChildAt(i) 81 | parent.getDecoratedBoundsWithMargins(child, bounds) 82 | val bottom = bounds.bottom + Math.round(child.translationY) 83 | val top = bottom - divider!!.intrinsicHeight 84 | divider!!.setBounds(left, top, right, bottom) 85 | divider!!.draw(canvas) 86 | } 87 | canvas.restore() 88 | } 89 | 90 | private fun drawHorizontal(canvas: Canvas, parent: RecyclerView) { 91 | canvas.save() 92 | val top: Int 93 | val bottom: Int 94 | 95 | if (parent.clipToPadding) { 96 | top = parent.paddingTop 97 | bottom = parent.height - parent.paddingBottom 98 | canvas.clipRect( 99 | parent.paddingLeft, top, 100 | parent.width - parent.paddingRight, bottom 101 | ) 102 | } else { 103 | top = 0 104 | bottom = parent.height 105 | } 106 | 107 | val childCount = parent.childCount 108 | for (i in 0 until childCount - 1) { 109 | val child = parent.getChildAt(i) 110 | parent.layoutManager!!.getDecoratedBoundsWithMargins(child, bounds) 111 | val right = bounds.right + Math.round(child.translationX) 112 | val left = right - divider!!.intrinsicWidth 113 | divider!!.setBounds(left, top, right, bottom) 114 | divider!!.draw(canvas) 115 | } 116 | canvas.restore() 117 | } 118 | 119 | override fun getItemOffsets( 120 | outRect: Rect, view: View, parent: RecyclerView, 121 | state: RecyclerView.State 122 | ) { 123 | if (divider == null) { 124 | outRect.set(0, 0, 0, 0) 125 | return 126 | } 127 | if (orientation == VERTICAL) { 128 | outRect.set(0, 0, 0, divider!!.intrinsicHeight) 129 | } else { 130 | outRect.set(0, 0, divider!!.intrinsicWidth, 0) 131 | } 132 | } 133 | 134 | companion object { 135 | const val HORIZONTAL = LinearLayout.HORIZONTAL 136 | const val VERTICAL = LinearLayout.VERTICAL 137 | } 138 | } -------------------------------------------------------------------------------- /app/src/main/java/tk/zwander/overlaymanager/util/Utils.kt: -------------------------------------------------------------------------------- 1 | package tk.zwander.overlaymanager.util 2 | 3 | import android.animation.LayoutTransition 4 | import android.app.Activity 5 | import android.content.Context 6 | import android.content.Intent 7 | import android.content.pm.PackageManager 8 | import android.net.Uri 9 | import android.os.Handler 10 | import android.os.Looper 11 | import android.os.Parcelable 12 | import android.util.Log 13 | import android.view.View 14 | import android.widget.Toast 15 | import it.sephiroth.android.library.xtooltip.ClosePolicy 16 | import it.sephiroth.android.library.xtooltip.Tooltip 17 | import kotlinx.coroutines.CoroutineDispatcher 18 | import kotlinx.coroutines.CoroutineScope 19 | import kotlinx.coroutines.Dispatchers 20 | import rikka.shizuku.Shizuku 21 | import rikka.shizuku.ShizukuProvider 22 | import tk.zwander.overlaymanager.App 23 | import tk.zwander.overlaymanager.IRootBridge 24 | import tk.zwander.overlaymanager.data.BatchedUpdate 25 | import tk.zwander.overlaymanager.proxy.OverlayInfo 26 | import kotlin.coroutines.coroutineContext 27 | import kotlin.jvm.functions.FunctionN 28 | 29 | val Context.app: App 30 | get() = applicationContext as App 31 | 32 | val layoutTransition = LayoutTransition().apply { 33 | enableTransitionType(LayoutTransition.CHANGING) 34 | } 35 | 36 | fun View.addTooltip() { 37 | if (tooltipText != null) { 38 | val tooltip = Tooltip.Builder(context) 39 | .anchor(this) 40 | .text(tooltipText!!) 41 | .arrow(false) 42 | .showDuration(4000L) 43 | .closePolicy(ClosePolicy.TOUCH_ANYWHERE_NO_CONSUME) 44 | 45 | setOnLongClickListener { 46 | tooltip.create().show(rootView, Tooltip.Gravity.TOP) 47 | true 48 | } 49 | } 50 | } 51 | 52 | fun OverlayInfo.createEnabledUpdate(toEnabled: Boolean, extraAction: (() -> Unit)? = null): Pair { 53 | val key = "${idStringOrPackageName}_enabled" 54 | return key to BatchedUpdate(key) { 55 | if (isEnabled != toEnabled) { 56 | if (identifier != null) { 57 | it.setOverlayEnabledByIdentifier(idStringOrPackageName, toEnabled) 58 | } else { 59 | it.setOverlayEnabled(idStringOrPackageName, toEnabled) 60 | } 61 | 62 | updateInstance((if (identifier != null) it.getOverlayInfoByIdentifier(idStringOrPackageName) 63 | else it.getOverlayInfo(idStringOrPackageName))) 64 | 65 | extraAction?.invoke() 66 | } 67 | } 68 | } 69 | 70 | fun OverlayInfo.createPriorityUpdate(high: Boolean, extraAction: (() -> Unit)? = null): Pair { 71 | val key = "${idStringOrPackageName}_priority" 72 | return key to BatchedUpdate(key) { 73 | if (high) { 74 | it.setOverlayHighestPriority(idStringOrPackageName) 75 | } else { 76 | it.setOverlayLowestPriority(idStringOrPackageName) 77 | } 78 | 79 | updateInstance(it.getOverlayInfo(idStringOrPackageName)) 80 | 81 | extraAction?.invoke() 82 | } 83 | } 84 | 85 | val shizukuAvailable: Boolean 86 | get() = Shizuku.pingBinder() 87 | 88 | val Context.shizukuGranted: Boolean 89 | get() = shizukuAvailable && (if (Shizuku.isPreV11() && Shizuku.getVersion() < 11) { 90 | checkCallingOrSelfPermission(ShizukuProvider.PERMISSION) == PackageManager.PERMISSION_GRANTED 91 | } else { 92 | Shizuku.checkSelfPermission() == PackageManager.PERMISSION_GRANTED 93 | }) 94 | 95 | fun Activity.requestShizukuPermission(code: Int, listener: Shizuku.OnRequestPermissionResultListener) { 96 | if (Shizuku.getVersion() >= 11 && !Shizuku.isPreV11()) { 97 | Shizuku.addRequestPermissionResultListener(listener) 98 | Shizuku.requestPermission(code) 99 | } else { 100 | requestPermissions(arrayOf(ShizukuProvider.PERMISSION), code) 101 | } 102 | } 103 | 104 | //Safely launch a URL. 105 | //If no matching Activity is found, silently fail. 106 | fun Context.launchUrl(url: String) { 107 | try { 108 | val browserIntent = 109 | Intent(Intent.ACTION_VIEW, Uri.parse(url)) 110 | startActivity(browserIntent) 111 | } catch (e: Exception) {} 112 | } 113 | -------------------------------------------------------------------------------- /app/src/main/java/tk/zwander/overlaymanager/views/CheckableImageButton.kt: -------------------------------------------------------------------------------- 1 | package tk.zwander.overlaymanager.views 2 | 3 | import android.annotation.SuppressLint 4 | import android.content.Context 5 | import android.util.AttributeSet 6 | import com.google.android.material.internal.CheckableImageButton 7 | import tk.zwander.overlaymanager.util.addTooltip 8 | 9 | @SuppressLint("RestrictedApi") 10 | class CheckableImageButton(context: Context, attrs: AttributeSet) : CheckableImageButton(context, attrs) { 11 | private var mOnCheckedChangeListener: OnCheckedChangeListener? = null 12 | private var mBroadcasting = false 13 | 14 | init { 15 | addTooltip() 16 | } 17 | 18 | fun setOnCheckedChangeListener(listener: OnCheckedChangeListener?) { 19 | mOnCheckedChangeListener = listener 20 | } 21 | 22 | fun setOnCheckedChangeListener(listener: (tk.zwander.overlaymanager.views.CheckableImageButton, Boolean) -> Unit) { 23 | setOnCheckedChangeListener(object : OnCheckedChangeListener { 24 | override fun onCheckedChanged( 25 | buttonView: tk.zwander.overlaymanager.views.CheckableImageButton, 26 | checked: Boolean 27 | ) { 28 | listener(buttonView, checked) 29 | } 30 | }) 31 | } 32 | 33 | override fun performClick(): Boolean { 34 | toggle() 35 | return super.performClick() 36 | } 37 | 38 | //Overridden to avoid annoying warnings 39 | override fun isChecked(): Boolean { 40 | return super.isChecked() 41 | } 42 | 43 | //Overridden to avoid annoying warnings 44 | override fun setChecked(checked: Boolean) { 45 | val changed = checked != isChecked 46 | 47 | super.setChecked(checked) 48 | 49 | if (mBroadcasting) { 50 | return 51 | } 52 | 53 | if (changed) { 54 | mBroadcasting = true 55 | mOnCheckedChangeListener?.onCheckedChanged(this, checked) 56 | mBroadcasting = false 57 | } 58 | } 59 | 60 | interface OnCheckedChangeListener { 61 | fun onCheckedChanged(buttonView: tk.zwander.overlaymanager.views.CheckableImageButton, checked: Boolean) 62 | } 63 | } -------------------------------------------------------------------------------- /app/src/main/java/tk/zwander/overlaymanager/views/TooltippedImageButton.kt: -------------------------------------------------------------------------------- 1 | package tk.zwander.overlaymanager.views 2 | 3 | import android.content.Context 4 | import android.util.AttributeSet 5 | import androidx.appcompat.widget.AppCompatImageButton 6 | import tk.zwander.overlaymanager.util.addTooltip 7 | 8 | class TooltippedImageButton(context: Context, attrs: AttributeSet) : AppCompatImageButton(context, attrs) { 9 | init { 10 | addTooltip() 11 | } 12 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/arrow_collapse_vertical.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/arrow_expand_vertical.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 6 | 8 | 12 | 16 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/playlist_remove.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/divider.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 8 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/highest_priority_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_error_24.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_playlist_add_check_24.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_vertical_align_bottom_24.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_vertical_align_bottom_24_disabled.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_vertical_align_top_24.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_vertical_align_top_24_disabled.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_done_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/lowest_priority_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/title_border.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 26 | 27 | 36 | 37 | 46 | 47 | 57 | 58 | 74 | 75 | 76 | 87 | 88 | 98 | 99 | 109 | 110 | 120 | 121 | 131 | 132 | 133 | 134 | 135 | 136 | 143 | 144 | 149 | 150 | 151 | 152 | 163 | 164 | -------------------------------------------------------------------------------- /app/src/main/res/layout/overlay_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 19 | 20 | 33 | 34 | 42 | 43 | 49 | 50 | 51 | 52 | 59 | 60 | 70 | 71 | 81 | 82 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /app/src/main/res/layout/progress.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/layout/target_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 18 | 19 | 27 | 28 | 34 | 35 | 42 | 43 | 49 | 50 | 51 | 52 | 60 | 61 | 62 | 63 | 74 | 75 | -------------------------------------------------------------------------------- /app/src/main/res/menu/search.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 19 | 20 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #009688 4 | #00796B 5 | #4CAF50 6 | 7 | #353535 8 | #33ffffff 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | OverlayManager 3 | 4 | Enabled 5 | Overlays: %d 6 | Priority: %d 7 | Match Overlays 8 | Apply Changes 9 | Unapplied Changes 10 | 11 | You have unapplied changes! Hit the checkmark FAB to apply them. 12 | Are you sure you want to apply? 13 | 14 | Enable All 15 | Disable All 16 | Expand All 17 | Collapse All 18 | 19 | Set Highest Priority 20 | Set Lowest Priority 21 | 22 | Root Access or Shizuku Required 23 | To use Overlay Manager, you must have root access or have Shizuku set up and running. 24 | Get Shizuku 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.7.21' 3 | repositories { 4 | google() 5 | mavenCentral() 6 | maven { url 'https://jitpack.io' } 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:7.3.1' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | mavenCentral() 18 | maven { url 'https://jitpack.io' } 19 | } 20 | } 21 | 22 | task clean(type: Delete) { 23 | delete rootProject.buildDir 24 | } 25 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zacharee/OverlayManager/950d9c07859c3c966ab6443fe7ff782100763c87/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Oct 26 20:44:10 EDT 2022 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name='OverlayManager' 3 | --------------------------------------------------------------------------------