16 |
17 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | , 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Volume Manager
2 |
3 | **Work in progress**
4 |
5 | Control each app's volume independently. [Shizuku](https://shizuku.rikka.app/) is used to access privileged APIs.
6 |
7 | Requires Android 13.
8 |
9 | 
10 |
11 | ## Download
12 |
13 | Latest development version can be downloaded from [action artifacts](https://github.com/yume-chan/VolumeManager/actions).
14 |
15 | Some hand-picked versions can also be downloaded from [releases](https://github.com/yume-chan/VolumeManager/releases).
16 |
17 | ## Usage
18 |
19 | 1. Install and enable [Shizuku](https://shizuku.rikka.app/)
20 | 2. Launch Volume Manager and request Shizuku permission
21 | 3. It should automatically enable its accessibility service
22 | 4. You can change volume either from
23 | 1. The main interface
24 | 2. Press any volume button and a popup should appear, completely replace the default volume popup
25 | 3. Enable accessibility button and click the button
26 |
27 | ## Compare to [SoundMaster from ShizuTools](https://github.com/legendsayantan/ShizuTools/wiki/SoundMaster)
28 |
29 | This app uses hidden API to directly change each audio stream's volume.
30 |
31 | SoundMaster uses MediaProjection API to record audio from each app and apply post-effects.
32 |
33 | | Feature | Volume Manager | SoundMaster |
34 | | ------------------------------ | --------------- | --------------- |
35 | | Minimal Android version | 13 | 10 |
36 | | Control volume of each app | ✅ | ✅ |
37 | | Set output device for each app | ❌ 1 | ✅ |
38 | | Change left-right balance | ❌ 2 | ✅ |
39 | | Equalizer (EQ) | ❌ | ✅ |
40 | | Control protected apps | ✅ | ❌ 3 |
41 | | Zero latency added | ✅ | ❌ |
42 |
43 | 1: There are APIs to do that, but not implemented in this app
44 |
45 | 2: There are other APIs to do that, but not implemented in this app
46 |
47 | 3: Can be worked around by patching the app
48 |
49 | ## How does it work
50 |
51 | 1. Use [`AudioManager#getActivePlaybackConfigurations()`]() to get list of [`AudioPlaybackConfiguration`](https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/media/java/android/media/AudioPlaybackConfiguration.java;drc=e282cc572ef848b1cb8d622c2c4939aac37c3b27).
52 |
53 | Each `AudioPlaybackConfiguration` represents a audio player, like [`AudioTrack`](https://developer.android.com/reference/android/media/AudioTrack) and [`MediaPlayer`](https://developer.android.com/media/platform/mediaplayer)
54 |
55 | 2. Use [`ActivityManager#getRunningAppProcesses()`]() and [`PackageManager#getApplicationInfo()`]() to map and group `AudioPlaybackConfiguration#getClientPid()` to apps
56 | 3. Use `AudioPlaybackConfiguration#getPlayerProxy()` and [`IPlayer.setVolume()`](https://cs.android.com/android/platform/superproject/main/+/main:frameworks/av/media/libaudioclient/aidl/android/media/IPlayer.aidl;l=29;drc=75e48fea431b1de2bf1715eb5c22ba4c794200bd) to update the internal volume multiplier
57 | 4. Use [`AudioManager#registerAudioPlaybackCallback()`]() to listen for new `AudioPlaybackConfiguration`s and apply current volume to them.
58 |
59 | ## Note
60 |
61 | This app uses the same API as MIUI's "Adjust media sound in multiple apps". Because this API can only setting volume, not reading, the volume set by one app will not be reflected in the other one.
62 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | alias(libs.plugins.android.application)
3 | alias(libs.plugins.kotlin.android)
4 | alias(libs.plugins.kotlin.compose)
5 | }
6 |
7 | android {
8 | namespace = "moe.chensi.volume"
9 | compileSdk = 35
10 |
11 | defaultConfig {
12 | applicationId = "moe.chensi.volume"
13 | minSdk = 33
14 | targetSdk = 35
15 | versionCode = 3
16 | versionName = "0.1"
17 |
18 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
19 | }
20 |
21 | buildTypes {
22 | release {
23 | isMinifyEnabled = false
24 | proguardFiles(
25 | getDefaultProguardFile("proguard-android-optimize.txt"),
26 | "proguard-rules.pro"
27 | )
28 | }
29 | }
30 | compileOptions {
31 | sourceCompatibility = JavaVersion.VERSION_11
32 | targetCompatibility = JavaVersion.VERSION_11
33 | }
34 | kotlinOptions {
35 | jvmTarget = "11"
36 | }
37 |
38 | buildFeatures {
39 | compose = true
40 | aidl = true
41 | }
42 | }
43 |
44 | dependencies {
45 |
46 | implementation(libs.androidx.core.ktx)
47 | implementation(libs.androidx.lifecycle.runtime.ktx)
48 | implementation(libs.androidx.activity.compose)
49 | implementation(platform(libs.androidx.compose.bom))
50 | implementation(libs.androidx.ui)
51 | implementation(libs.androidx.ui.graphics)
52 | implementation(libs.androidx.ui.tooling.preview)
53 | implementation(libs.androidx.material3)
54 |
55 | implementation(libs.shizuku.api)
56 | implementation(libs.shizuku.provider)
57 | implementation(libs.hiddenapibypass)
58 |
59 | implementation(libs.androidx.datastore.core.android)
60 | implementation(libs.androidx.datastore.preferences)
61 |
62 | implementation(libs.joor)
63 |
64 | testImplementation(libs.junit)
65 | androidTestImplementation(libs.androidx.junit)
66 | androidTestImplementation(libs.androidx.espresso.core)
67 | androidTestImplementation(platform(libs.androidx.compose.bom))
68 | androidTestImplementation(libs.androidx.ui.test.junit4)
69 | debugImplementation(libs.androidx.ui.tooling)
70 | debugImplementation(libs.androidx.ui.test.manifest)
71 | }
72 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/app/src/androidTest/java/moe/chensi/volume/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package moe.chensi.volume
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("moe.chensi.volume", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
21 |
22 |
26 |
27 |
28 |
29 |
30 |
33 |
34 |
35 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/app/src/main/aidl/android/media/IPlaybackConfigDispatcher.aidl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package android.media;
18 |
19 | import android.media.AudioPlaybackConfiguration;
20 |
21 | /**
22 | * AIDL for the PlaybackActivityMonitor in AudioService to signal audio playback updates.
23 | *
24 | * {@hide}
25 | */
26 | oneway interface IPlaybackConfigDispatcher {
27 |
28 | void dispatchPlaybackConfigChange(in List configs, in boolean flush);
29 |
30 | }
--------------------------------------------------------------------------------
/app/src/main/java/moe/chensi/volume/Icons.kt:
--------------------------------------------------------------------------------
1 | import androidx.compose.ui.graphics.Color
2 | import androidx.compose.ui.graphics.PathFillType
3 | import androidx.compose.ui.graphics.SolidColor
4 | import androidx.compose.ui.graphics.StrokeCap
5 | import androidx.compose.ui.graphics.StrokeJoin
6 | import androidx.compose.ui.graphics.vector.ImageVector
7 | import androidx.compose.ui.graphics.vector.path
8 | import androidx.compose.ui.unit.dp
9 |
10 | val MaterialMusicNote: ImageVector
11 | get() {
12 | if (_MaterialMusicNote != null) {
13 | return _MaterialMusicNote!!
14 | }
15 | _MaterialMusicNote = ImageVector.Builder(
16 | name = "Music_note",
17 | defaultWidth = 24.dp,
18 | defaultHeight = 24.dp,
19 | viewportWidth = 960f,
20 | viewportHeight = 960f
21 | ).apply {
22 | path(
23 | fill = SolidColor(Color.White),
24 | fillAlpha = 1.0f,
25 | stroke = null,
26 | strokeAlpha = 1.0f,
27 | strokeLineWidth = 1.0f,
28 | strokeLineCap = StrokeCap.Butt,
29 | strokeLineJoin = StrokeJoin.Miter,
30 | strokeLineMiter = 1.0f,
31 | pathFillType = PathFillType.NonZero
32 | ) {
33 | moveTo(400f, 840f)
34 | quadToRelative(-66f, 0f, -113f, -47f)
35 | reflectiveQuadToRelative(-47f, -113f)
36 | reflectiveQuadToRelative(47f, -113f)
37 | reflectiveQuadToRelative(113f, -47f)
38 | quadToRelative(23f, 0f, 42.5f, 5.5f)
39 | reflectiveQuadTo(480f, 542f)
40 | verticalLineToRelative(-382f)
41 | quadToRelative(0f, -17f, 11.5f, -28.5f)
42 | reflectiveQuadTo(520f, 120f)
43 | horizontalLineToRelative(160f)
44 | quadToRelative(17f, 0f, 28.5f, 11.5f)
45 | reflectiveQuadTo(720f, 160f)
46 | verticalLineToRelative(80f)
47 | quadToRelative(0f, 17f, -11.5f, 28.5f)
48 | reflectiveQuadTo(680f, 280f)
49 | horizontalLineTo(560f)
50 | verticalLineToRelative(400f)
51 | quadToRelative(0f, 66f, -47f, 113f)
52 | reflectiveQuadToRelative(-113f, 47f)
53 | }
54 | }.build()
55 | return _MaterialMusicNote!!
56 | }
57 |
58 | private var _MaterialMusicNote: ImageVector? = null
59 |
60 | val MaterialNotifications: ImageVector
61 | get() {
62 | if (_MaterialNotifications != null) {
63 | return _MaterialNotifications!!
64 | }
65 | _MaterialNotifications = ImageVector.Builder(
66 | name = "Notifications",
67 | defaultWidth = 24.dp,
68 | defaultHeight = 24.dp,
69 | viewportWidth = 960f,
70 | viewportHeight = 960f
71 | ).apply {
72 | path(
73 | fill = SolidColor(Color.White),
74 | fillAlpha = 1.0f,
75 | stroke = null,
76 | strokeAlpha = 1.0f,
77 | strokeLineWidth = 1.0f,
78 | strokeLineCap = StrokeCap.Butt,
79 | strokeLineJoin = StrokeJoin.Miter,
80 | strokeLineMiter = 1.0f,
81 | pathFillType = PathFillType.NonZero
82 | ) {
83 | moveTo(200f, 760f)
84 | quadToRelative(-17f, 0f, -28.5f, -11.5f)
85 | reflectiveQuadTo(160f, 720f)
86 | reflectiveQuadToRelative(11.5f, -28.5f)
87 | reflectiveQuadTo(200f, 680f)
88 | horizontalLineToRelative(40f)
89 | verticalLineToRelative(-280f)
90 | quadToRelative(0f, -83f, 50f, -147.5f)
91 | reflectiveQuadTo(420f, 168f)
92 | verticalLineToRelative(-28f)
93 | quadToRelative(0f, -25f, 17.5f, -42.5f)
94 | reflectiveQuadTo(480f, 80f)
95 | reflectiveQuadToRelative(42.5f, 17.5f)
96 | reflectiveQuadTo(540f, 140f)
97 | verticalLineToRelative(28f)
98 | quadToRelative(80f, 20f, 130f, 84.5f)
99 | reflectiveQuadTo(720f, 400f)
100 | verticalLineToRelative(280f)
101 | horizontalLineToRelative(40f)
102 | quadToRelative(17f, 0f, 28.5f, 11.5f)
103 | reflectiveQuadTo(800f, 720f)
104 | reflectiveQuadToRelative(-11.5f, 28.5f)
105 | reflectiveQuadTo(760f, 760f)
106 | close()
107 | moveTo(480f, 880f)
108 | quadToRelative(-33f, 0f, -56.5f, -23.5f)
109 | reflectiveQuadTo(400f, 800f)
110 | horizontalLineToRelative(160f)
111 | quadToRelative(0f, 33f, -23.5f, 56.5f)
112 | reflectiveQuadTo(480f, 880f)
113 | moveTo(320f, 680f)
114 | horizontalLineToRelative(320f)
115 | verticalLineToRelative(-280f)
116 | quadToRelative(0f, -66f, -47f, -113f)
117 | reflectiveQuadToRelative(-113f, -47f)
118 | reflectiveQuadToRelative(-113f, 47f)
119 | reflectiveQuadToRelative(-47f, 113f)
120 | close()
121 | }
122 | }.build()
123 | return _MaterialNotifications!!
124 | }
125 |
126 | private var _MaterialNotifications: ImageVector? = null
127 |
--------------------------------------------------------------------------------
/app/src/main/java/moe/chensi/volume/MainActivity.kt:
--------------------------------------------------------------------------------
1 | @file:OptIn(ExperimentalMaterial3Api::class)
2 |
3 | package moe.chensi.volume
4 |
5 | import android.annotation.SuppressLint
6 | import android.companion.virtual.VirtualDeviceManager
7 | import android.content.pm.PackageManager
8 | import android.os.Build
9 | import android.os.Bundle
10 | import android.os.UserHandle
11 | import android.provider.Settings
12 | import android.util.Log
13 | import androidx.activity.ComponentActivity
14 | import androidx.activity.compose.setContent
15 | import androidx.activity.enableEdgeToEdge
16 | import androidx.compose.foundation.layout.Arrangement
17 | import androidx.compose.foundation.layout.Column
18 | import androidx.compose.foundation.layout.fillMaxSize
19 | import androidx.compose.foundation.layout.padding
20 | import androidx.compose.material3.Button
21 | import androidx.compose.material3.ExperimentalMaterial3Api
22 | import androidx.compose.material3.Scaffold
23 | import androidx.compose.material3.Text
24 | import androidx.compose.material3.TopAppBar
25 | import androidx.compose.runtime.Composable
26 | import androidx.compose.runtime.LaunchedEffect
27 | import androidx.compose.runtime.getValue
28 | import androidx.compose.runtime.mutableStateOf
29 | import androidx.compose.runtime.remember
30 | import androidx.compose.runtime.setValue
31 | import androidx.compose.ui.Alignment
32 | import androidx.compose.ui.Modifier
33 | import androidx.compose.ui.text.style.TextAlign
34 | import androidx.compose.ui.unit.dp
35 | import moe.chensi.volume.ui.theme.VolumeManagerTheme
36 | import org.joor.Reflect
37 | import rikka.shizuku.Shizuku
38 | import rikka.shizuku.ShizukuRemoteProcess
39 |
40 | @SuppressLint("PrivateApi", "SoonBlockedPrivateApi")
41 | class MainActivity : ComponentActivity() {
42 | companion object {
43 | private const val TAG = "VolumeManager.Activity"
44 |
45 | private const val SERVICE_NAME_SEPARATOR = ":"
46 | }
47 |
48 | private lateinit var application: MyApplication
49 |
50 | @SuppressLint("MissingPermission")
51 | private fun grantSelfPermission(permission: String) {
52 | var state = packageManager.checkPermission(permission, packageName)
53 | if (state == PackageManager.PERMISSION_GRANTED) {
54 | return
55 | }
56 |
57 | val process = Reflect.onClass(Shizuku::class.java).call(
58 | "newProcess", arrayOf("pm", "grant", packageName, permission), null, null
59 | ).get()
60 | process.waitFor()
61 |
62 | state = packageManager.checkPermission(permission, packageName)
63 | if (state == PackageManager.PERMISSION_GRANTED) {
64 | return
65 | }
66 |
67 | throw SecurityException("Can't grant self permission $permission")
68 | }
69 |
70 | private fun enableAccessibilityService(name: String) {
71 | Settings.Secure.putInt(contentResolver, Settings.Secure.ACCESSIBILITY_ENABLED, 1)
72 |
73 | var enabledAccessibilityServices = Settings.Secure.getString(
74 | contentResolver, Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES
75 | )
76 |
77 | if (enabledAccessibilityServices.isNullOrBlank()) {
78 | enabledAccessibilityServices = name
79 | } else if (enabledAccessibilityServices.contains(name)) {
80 | return
81 | } else {
82 | enabledAccessibilityServices += SERVICE_NAME_SEPARATOR + name
83 | }
84 |
85 | Settings.Secure.putString(
86 | contentResolver,
87 | Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
88 | enabledAccessibilityServices
89 | )
90 |
91 | enabledAccessibilityServices = Settings.Secure.getString(
92 | contentResolver, Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES
93 | )
94 | if (enabledAccessibilityServices == null || !enabledAccessibilityServices.contains(name)) {
95 | throw SecurityException("Can't enable accessibility service $name")
96 | }
97 | }
98 |
99 | @SuppressLint("DiscouragedPrivateApi")
100 | override fun onCreate(savedInstanceState: Bundle?) {
101 | super.onCreate(savedInstanceState)
102 | enableEdgeToEdge()
103 |
104 | application = super.getApplication() as MyApplication
105 | val manager = Manager(this@MainActivity, application.dataStore)
106 |
107 | setContent {
108 | VolumeManagerTheme {
109 | Scaffold(
110 | modifier = Modifier.fillMaxSize(),
111 | topBar = { TopAppBar(title = { Text("Volume Manager") }) }) { innerPadding ->
112 | Column(
113 | verticalArrangement = Arrangement.spacedBy(16.dp),
114 | modifier = Modifier
115 | .padding(innerPadding)
116 | .padding(16.dp)
117 | ) {
118 | if (manager.shizukuReady) {
119 | if (manager.shizukuPermission) {
120 | AccessibilityService()
121 | AppVolumeList(manager.apps.values)
122 | } else {
123 | Column(
124 | modifier = Modifier.fillMaxSize(),
125 | horizontalAlignment = Alignment.CenterHorizontally,
126 | verticalArrangement = Arrangement.spacedBy(
127 | 16.dp, Alignment.CenterVertically
128 | )
129 | ) {
130 | Text("Shizuku is installed and enabled")
131 | Text(
132 | textAlign = TextAlign.Center,
133 | text = "Allow volume manager to access Shizuku?"
134 | )
135 |
136 | Button(onClick = { Shizuku.requestPermission(0) }) {
137 | Text(text = "Add permission")
138 | }
139 | }
140 | }
141 | } else {
142 | Column(
143 | modifier = Modifier.fillMaxSize(),
144 | horizontalAlignment = Alignment.CenterHorizontally,
145 | verticalArrangement = Arrangement.spacedBy(
146 | 16.dp, Alignment.CenterVertically
147 | )
148 | ) {
149 | Text("Waiting for Shizuku...")
150 | Text(
151 | textAlign = TextAlign.Center,
152 | text = "Make sure Shizuku is installed and enabled"
153 | )
154 | }
155 | }
156 | }
157 | }
158 | }
159 | }
160 | }
161 |
162 | @Composable
163 | fun AccessibilityService() {
164 | var permissionGranted by remember { mutableStateOf(false) }
165 | var serviceEnabled by remember { mutableStateOf(false) }
166 |
167 | LaunchedEffect(0) {
168 | try {
169 | grantSelfPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)
170 | permissionGranted = true
171 | } catch (e: Exception) {
172 | Log.e(TAG, "Failed to grant permission", e)
173 | }
174 |
175 | try {
176 | enableAccessibilityService("$packageName/${Service::class.java.canonicalName}")
177 | serviceEnabled = true
178 | } catch (e: Exception) {
179 | Log.e(TAG, "Failed to enable accessibility service", e)
180 | }
181 | }
182 |
183 | Column {
184 | Text(text = "Permission granted: $permissionGranted")
185 | Text(text = "Service enabled: $serviceEnabled")
186 | }
187 | }
188 | }
189 |
--------------------------------------------------------------------------------
/app/src/main/java/moe/chensi/volume/Manager.kt:
--------------------------------------------------------------------------------
1 | package moe.chensi.volume
2 |
3 | import android.annotation.SuppressLint
4 | import android.app.ActivityManager
5 | import android.content.Context
6 | import android.content.pm.PackageManager
7 | import android.graphics.drawable.Drawable
8 | import android.media.AudioManager
9 | import android.media.AudioPlaybackConfiguration
10 | import androidx.compose.runtime.getValue
11 | import androidx.compose.runtime.mutableFloatStateOf
12 | import androidx.compose.runtime.mutableStateListOf
13 | import androidx.compose.runtime.mutableStateMapOf
14 | import androidx.compose.runtime.mutableStateOf
15 | import androidx.compose.runtime.setValue
16 | import androidx.datastore.core.DataStore
17 | import androidx.datastore.preferences.core.Preferences
18 | import androidx.datastore.preferences.core.edit
19 | import androidx.datastore.preferences.core.floatPreferencesKey
20 | import kotlinx.coroutines.CoroutineScope
21 | import kotlinx.coroutines.Dispatchers
22 | import kotlinx.coroutines.SupervisorJob
23 | import kotlinx.coroutines.launch
24 | import org.joor.Reflect
25 | import rikka.shizuku.Shizuku
26 | import rikka.shizuku.ShizukuBinderWrapper
27 | import rikka.shizuku.SystemServiceHelper
28 | import java.lang.reflect.Method
29 | import java.util.Objects
30 |
31 | @SuppressLint("PrivateApi")
32 | class Manager(private val context: Context, private val dataStore: DataStore) {
33 | companion object {
34 | private val getClientPidMethod: Method =
35 | AudioPlaybackConfiguration::class.java.getDeclaredMethod("getClientPid")
36 | private val getPlayerProxyMethod: Method =
37 | AudioPlaybackConfiguration::class.java.getDeclaredMethod("getPlayerProxy")
38 | private val setVolumeMethod: Method =
39 | Class.forName("android.media.PlayerProxy").getDeclaredMethod(
40 | "setVolume", Float::class.javaPrimitiveType
41 | )
42 |
43 | fun getShizukuService(name: String, type: String): Any {
44 | val binder = SystemServiceHelper.getSystemService(name)
45 | val wrapper = ShizukuBinderWrapper(binder)
46 | return Reflect.onClass("$type\$Stub").call("asInterface", wrapper).get()
47 | }
48 |
49 | }
50 |
51 | private var _shizukuReady by mutableStateOf(false)
52 | val shizukuReady
53 | get() = _shizukuReady
54 |
55 | private var _shizukuPermission by mutableStateOf(false)
56 | val shizukuPermission
57 | get() = _shizukuPermission
58 |
59 | private val packageManager: PackageManager = context.packageManager
60 | private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
61 |
62 | val apps = mutableStateMapOf()
63 |
64 | init {
65 | Shizuku.addBinderReceivedListenerSticky {
66 | if (Shizuku.isPreV11()) {
67 | return@addBinderReceivedListenerSticky
68 | }
69 |
70 | if (Shizuku.checkSelfPermission() == PackageManager.PERMISSION_GRANTED) {
71 | _shizukuPermission = true
72 | start()
73 | } else {
74 | _shizukuPermission = false
75 | }
76 |
77 | _shizukuReady = true
78 | }
79 |
80 | Shizuku.addBinderDeadListener {
81 | _shizukuReady = false
82 | }
83 |
84 | Shizuku.addRequestPermissionResultListener { _, grantResult ->
85 | _shizukuPermission = grantResult == PackageManager.PERMISSION_GRANTED
86 | if (_shizukuPermission) {
87 | start()
88 | }
89 | }
90 | }
91 |
92 | data class Player(val config: AudioPlaybackConfiguration, val player: Any)
93 |
94 | data class App(
95 | val packageName: String,
96 | val name: String,
97 | val icon: Drawable,
98 | val players: MutableList,
99 | val dataStore: DataStore
100 | ) {
101 | companion object {
102 | val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
103 | }
104 |
105 | private var _volume by mutableFloatStateOf(1f)
106 | fun setVolume(value: Float, initializing: Boolean) {
107 | if (initializing) {
108 | volume = value
109 | } else {
110 | _volume = value
111 | }
112 | }
113 |
114 | var volume
115 | get() = _volume
116 | set(value) {
117 | _volume = value
118 |
119 | for (player in players) {
120 | setVolumeMethod.invoke(player.player, value)
121 | }
122 |
123 | scope.launch {
124 | dataStore.edit { preferences ->
125 | preferences[floatPreferencesKey(packageName)] = volume
126 | }
127 | }
128 | }
129 | }
130 |
131 | private fun start() {
132 | Reflect.onClass("android.app.ActivityThread").set(
133 | "sPackageManager", getShizukuService("package", "android.content.pm.IPackageManager")
134 | )
135 |
136 | scope.launch {
137 | var initializing = true
138 |
139 | dataStore.data.collect { preferences ->
140 | for ((key, volume) in preferences.asMap()) {
141 | val packageName = key.name
142 | apps.getOrPut(packageName) {
143 | val appInfo = packageManager.getApplicationInfo(packageName, 0)
144 | App(
145 | packageName,
146 | appInfo.loadLabel(packageManager).toString(),
147 | appInfo.loadIcon(packageManager),
148 | mutableStateListOf(),
149 | dataStore
150 | )
151 | }.setVolume(volume as Float, initializing)
152 | }
153 |
154 | if (initializing) {
155 | Reflect.onClass(AudioManager::class.java).set(
156 | "sService",
157 | getShizukuService(Context.AUDIO_SERVICE, "android.media.IAudioService")
158 | )
159 | val audioManager = context.getSystemService(AudioManager::class.java)!!
160 |
161 | val playbackConfigurations = audioManager.activePlaybackConfigurations
162 |
163 | processAudioPlaybackConfigurations(apps, playbackConfigurations)
164 |
165 | audioManager.registerAudioPlaybackCallback(
166 | object : AudioManager.AudioPlaybackCallback() {
167 | override fun onPlaybackConfigChanged(configs: MutableList) {
168 | for (app in apps.values) {
169 | app.players.clear()
170 | }
171 | processAudioPlaybackConfigurations(apps, configs)
172 | }
173 | }, null
174 | )
175 |
176 | initializing = false
177 | }
178 | }
179 | }
180 | }
181 |
182 | @SuppressLint("DiscouragedPrivateApi")
183 | fun processAudioPlaybackConfigurations(
184 | apps: MutableMap, configs: List
185 | ) {
186 | val activityService =
187 | Reflect.on(getShizukuService(Context.ACTIVITY_SERVICE, "android.app.IActivityManager"))
188 |
189 | val runningProcesses = activityService.call("getRunningAppProcesses")
190 | .get>()
191 |
192 | for (config in configs) {
193 | val player = getPlayerProxyMethod.invoke(config) ?: continue
194 |
195 | val pid = getClientPidMethod.invoke(config) as Int
196 | val process = runningProcesses.find { process -> process.pid == pid } ?: continue
197 |
198 | val packageName = process.processName.split(":")[0]
199 | val app: App = apps[packageName] ?: run {
200 | val appInfo = packageManager.getApplicationInfo(packageName, 0)
201 | App(
202 | packageName,
203 | appInfo.loadLabel(packageManager).toString(),
204 | appInfo.loadIcon(packageManager),
205 | mutableStateListOf(),
206 | dataStore
207 | ).also { apps[packageName] = it }
208 | }
209 |
210 | setVolumeMethod.invoke(player, app.volume)
211 | app.players.add(Player(config, player))
212 | }
213 | }
214 | }
215 |
--------------------------------------------------------------------------------
/app/src/main/java/moe/chensi/volume/MyApplication.kt:
--------------------------------------------------------------------------------
1 | package moe.chensi.volume
2 |
3 | import android.app.Application
4 | import android.content.Context
5 | import androidx.datastore.core.DataStore
6 | import androidx.datastore.preferences.core.Preferences
7 | import androidx.datastore.preferences.preferencesDataStore
8 | import org.lsposed.hiddenapibypass.HiddenApiBypass
9 | import rikka.shizuku.ShizukuProvider
10 |
11 | class MyApplication : Application() {
12 | val dataStore: DataStore by preferencesDataStore(name = "app_volumes")
13 |
14 | override fun attachBaseContext(base: Context?) {
15 | super.attachBaseContext(base)
16 |
17 | ShizukuProvider.enableMultiProcessSupport(true)
18 | HiddenApiBypass.addHiddenApiExemptions("")
19 | }
20 | }
--------------------------------------------------------------------------------
/app/src/main/java/moe/chensi/volume/Service.kt:
--------------------------------------------------------------------------------
1 | package moe.chensi.volume
2 |
3 | import MaterialMusicNote
4 | import MaterialNotifications
5 | import android.accessibilityservice.AccessibilityButtonController
6 | import android.accessibilityservice.AccessibilityButtonController.AccessibilityButtonCallback
7 | import android.accessibilityservice.AccessibilityService
8 | import android.animation.Animator
9 | import android.animation.ValueAnimator
10 | import android.annotation.SuppressLint
11 | import android.content.BroadcastReceiver
12 | import android.content.Context
13 | import android.content.Intent
14 | import android.content.IntentFilter
15 | import android.graphics.PixelFormat
16 | import android.media.AudioManager
17 | import android.os.Build
18 | import android.os.CountDownTimer
19 | import android.util.Log
20 | import android.view.Gravity
21 | import android.view.KeyEvent
22 | import android.view.MotionEvent
23 | import android.view.View
24 | import android.view.WindowManager
25 | import android.view.accessibility.AccessibilityEvent
26 | import android.view.animation.AccelerateDecelerateInterpolator
27 | import androidx.compose.foundation.Image
28 | import androidx.compose.foundation.background
29 | import androidx.compose.foundation.layout.Arrangement
30 | import androidx.compose.foundation.layout.Column
31 | import androidx.compose.foundation.layout.Row
32 | import androidx.compose.foundation.layout.padding
33 | import androidx.compose.foundation.layout.width
34 | import androidx.compose.foundation.shape.RoundedCornerShape
35 | import androidx.compose.material3.MaterialTheme
36 | import androidx.compose.material3.Surface
37 | import androidx.compose.material3.Text
38 | import androidx.compose.runtime.Composable
39 | import androidx.compose.runtime.DisposableEffect
40 | import androidx.compose.runtime.LaunchedEffect
41 | import androidx.compose.runtime.getValue
42 | import androidx.compose.runtime.mutableIntStateOf
43 | import androidx.compose.runtime.remember
44 | import androidx.compose.runtime.setValue
45 | import androidx.compose.ui.Alignment
46 | import androidx.compose.ui.Modifier
47 | import androidx.compose.ui.graphics.Color
48 | import androidx.compose.ui.graphics.vector.ImageVector
49 | import androidx.compose.ui.layout.ContentScale
50 | import androidx.compose.ui.platform.AbstractComposeView
51 | import androidx.compose.ui.unit.dp
52 | import androidx.lifecycle.Lifecycle
53 | import androidx.lifecycle.LifecycleRegistry
54 | import androidx.lifecycle.setViewTreeLifecycleOwner
55 | import androidx.savedstate.SavedStateRegistry
56 | import androidx.savedstate.SavedStateRegistryController
57 | import androidx.savedstate.SavedStateRegistryOwner
58 | import androidx.savedstate.setViewTreeSavedStateRegistryOwner
59 | import org.joor.Reflect
60 | import rikka.shizuku.ShizukuProvider
61 | import java.util.Objects
62 |
63 | class Service : AccessibilityService() {
64 | companion object {
65 | private const val TAG = "VolumeManager.Service"
66 |
67 | private const val ANIMATION_DURATION = 300L
68 | private const val IDLE_TIMEOUT = 5000L
69 | }
70 |
71 | private val windowManager: WindowManager by lazy {
72 | Objects.requireNonNull(
73 | getSystemService(
74 | WindowManager::class.java
75 | )!!
76 | )
77 | }
78 | private val audioManager: AudioManager by lazy {
79 | Objects.requireNonNull(
80 | getSystemService(
81 | AudioManager::class.java
82 | )!!
83 | )
84 | }
85 | private lateinit var manager: Manager
86 |
87 | private var idleTimer: CountDownTimer? = null
88 |
89 | private fun startIdleTimer() {
90 | idleTimer?.cancel()
91 | idleTimer = object : CountDownTimer(IDLE_TIMEOUT, IDLE_TIMEOUT) {
92 | override fun onTick(millisUntilFinished: Long) {}
93 |
94 | override fun onFinish() {
95 | hideView()
96 | }
97 | }.start()
98 | }
99 |
100 | private var lifecycle: LifecycleRegistry? = null
101 |
102 | private fun createView(): View {
103 | return object : AbstractComposeView(this) {
104 | init {
105 | val owner = object : SavedStateRegistryOwner {
106 | private val lifecycleRegistry = LifecycleRegistry(this)
107 |
108 | private val savedStateRegistryController =
109 | SavedStateRegistryController.create(this)
110 |
111 | init {
112 | savedStateRegistryController.performRestore(null)
113 | lifecycleRegistry.currentState = Lifecycle.State.STARTED
114 | this@Service.lifecycle = lifecycleRegistry
115 | }
116 |
117 | override val lifecycle: Lifecycle
118 | get() = lifecycleRegistry
119 |
120 | override val savedStateRegistry: SavedStateRegistry
121 | get() = savedStateRegistryController.savedStateRegistry
122 | }
123 |
124 | setViewTreeLifecycleOwner(owner)
125 | setViewTreeSavedStateRegistryOwner(owner)
126 | }
127 |
128 | override fun onAttachedToWindow() {
129 | super.onAttachedToWindow()
130 |
131 | Log.i(TAG, "onAttachedToWindow")
132 |
133 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && windowManager.isCrossWindowBlurEnabled && isHardwareAccelerated) {
134 | background =
135 | Reflect.on(rootSurfaceControl).call("createBackgroundBlurDrawable").apply {
136 | call("setBlurRadius", 200)
137 | call("setCornerRadius", 40f)
138 | }.get()
139 | }
140 |
141 | startIdleTimer()
142 | }
143 |
144 | @SuppressLint("ClickableViewAccessibility")
145 | override fun onTouchEvent(event: MotionEvent): Boolean {
146 | Log.i(TAG, "onTouchEvent ${event.actionMasked}")
147 |
148 | if (event.actionMasked == MotionEvent.ACTION_OUTSIDE) {
149 | hideView()
150 | return true
151 | }
152 |
153 | return super.onTouchEvent(event)
154 | }
155 |
156 | @Composable
157 | override fun Content() {
158 | var volumeChanged by remember { mutableIntStateOf(0) }
159 |
160 | DisposableEffect(audioManager) {
161 | val receiver = object : BroadcastReceiver() {
162 | override fun onReceive(context: Context?, intent: Intent?) {
163 | volumeChanged++
164 | startIdleTimer()
165 | }
166 | }
167 |
168 | registerReceiver(receiver, IntentFilter("android.media.VOLUME_CHANGED_ACTION"))
169 |
170 | onDispose {
171 | unregisterReceiver(receiver)
172 | }
173 | }
174 |
175 | return MaterialTheme {
176 | Surface(
177 | color = Color.Transparent,
178 | contentColor = Color.White,
179 | ) {
180 | Column(
181 | modifier = Modifier
182 | .background(
183 | Color(1f, 1f, 1f, 0.3f), RoundedCornerShape(40f)
184 | )
185 | .padding(20.dp, 16.dp)
186 | ) {
187 | AppVolumeList(manager.apps.values, onChange = { startIdleTimer() }) {
188 | item(AudioManager.STREAM_MUSIC) {
189 | StreamVolumeSlider(AudioManager.STREAM_MUSIC,
190 | volumeChanged,
191 | MaterialMusicNote,
192 | "Music",
193 | onChange = { startIdleTimer() })
194 | }
195 |
196 | item(AudioManager.STREAM_NOTIFICATION) {
197 | StreamVolumeSlider(AudioManager.STREAM_NOTIFICATION,
198 | volumeChanged,
199 | MaterialNotifications,
200 | "Notifications",
201 | onChange = { startIdleTimer() })
202 | }
203 | }
204 | }
205 | }
206 | }
207 | }
208 | }
209 | }
210 |
211 | private val layoutParams by lazy {
212 | WindowManager.LayoutParams(
213 | WindowManager.LayoutParams.WRAP_CONTENT, // Width
214 | WindowManager.LayoutParams.WRAP_CONTENT, // Height
215 | WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY,
216 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
217 | PixelFormat.TRANSLUCENT // Make the background translucent
218 | ).apply {
219 | gravity = Gravity.CENTER // Center the view
220 | }
221 | }
222 |
223 | private var view: View? = null
224 | private var viewVisible = false
225 |
226 | private fun showView() {
227 | if (view == null) {
228 | Log.i(TAG, "add view")
229 | // The view doesn't respond to input events if reused
230 | view = createView()
231 | layoutParams.alpha = 0f
232 | windowManager.addView(view, layoutParams)
233 | }
234 |
235 | if (!viewVisible) {
236 | Log.i(TAG, "animate in")
237 | animateAlpha(layoutParams.alpha, 1f, ANIMATION_DURATION)
238 | startIdleTimer()
239 | viewVisible = true
240 | }
241 | }
242 |
243 | private fun hideView() {
244 | if (viewVisible) {
245 | Log.i(TAG, "animate out")
246 | animateAlpha(layoutParams.alpha, 0f, ANIMATION_DURATION) {
247 | if (!viewVisible) {
248 | Log.i(TAG, "remove view")
249 | view!!.background = null
250 | lifecycle?.currentState = Lifecycle.State.DESTROYED
251 | windowManager.removeView(view)
252 | view = null
253 | }
254 | }
255 | viewVisible = false
256 | }
257 | }
258 |
259 | private var currentAnimator: ValueAnimator? = null
260 |
261 | private fun animateAlpha(from: Float, to: Float, duration: Long, onEnd: (() -> Unit)? = null) {
262 | currentAnimator?.cancel()
263 |
264 | val animator = ValueAnimator.ofFloat(from, to)
265 | animator.duration = duration
266 | animator.interpolator = AccelerateDecelerateInterpolator()
267 |
268 | animator.addUpdateListener { animation ->
269 | if (view != null) {
270 | layoutParams.alpha = animation.animatedValue as Float
271 | windowManager.updateViewLayout(view, layoutParams)
272 | }
273 | }
274 |
275 | animator.addListener(object : Animator.AnimatorListener {
276 | var canceled = false
277 |
278 | override fun onAnimationStart(animation: Animator) {}
279 |
280 | override fun onAnimationEnd(animation: Animator) {
281 | if (canceled) {
282 | return
283 | }
284 |
285 | layoutParams.alpha = to
286 | windowManager.updateViewLayout(view, layoutParams)
287 |
288 | onEnd?.invoke()
289 | }
290 |
291 | override fun onAnimationCancel(animation: Animator) {
292 | canceled = true
293 | }
294 |
295 | override fun onAnimationRepeat(animation: Animator) {}
296 | })
297 |
298 | animator.start()
299 | currentAnimator = animator
300 | }
301 |
302 | override fun onServiceConnected() {
303 | Log.i(TAG, "onServiceConnected")
304 |
305 | ShizukuProvider.enableMultiProcessSupport(false)
306 | manager = Manager(this, (application as MyApplication).dataStore)
307 |
308 | accessibilityButtonController.registerAccessibilityButtonCallback(object :
309 | AccessibilityButtonCallback() {
310 | override fun onClicked(controller: AccessibilityButtonController?) {
311 | if (manager.shizukuPermission == true) {
312 | showView()
313 | }
314 | }
315 | })
316 |
317 | Log.i(TAG, "onServiceConnected done ${serviceInfo.capabilities.toString(2)}")
318 | }
319 |
320 | override fun onAccessibilityEvent(event: AccessibilityEvent) {
321 | }
322 |
323 | override fun onInterrupt() {
324 | }
325 |
326 | override fun onKeyEvent(event: KeyEvent): Boolean {
327 | Log.i(TAG, "onKeyEvent ${event.action} ${event.keyCode}")
328 |
329 | if (manager.shizukuPermission != true) {
330 | return false
331 | }
332 |
333 | when (event.keyCode) {
334 | KeyEvent.KEYCODE_VOLUME_UP -> {
335 | if (event.action == KeyEvent.ACTION_DOWN) {
336 | if (view != null) {
337 | audioManager.adjustSuggestedStreamVolume(
338 | AudioManager.ADJUST_RAISE, AudioManager.USE_DEFAULT_STREAM_TYPE, 0
339 | )
340 | }
341 | showView()
342 | }
343 | return true
344 | }
345 |
346 | KeyEvent.KEYCODE_VOLUME_DOWN -> {
347 | if (event.action == KeyEvent.ACTION_DOWN) {
348 | if (view != null) {
349 | audioManager.adjustSuggestedStreamVolume(
350 | AudioManager.ADJUST_LOWER, AudioManager.USE_DEFAULT_STREAM_TYPE, 0
351 | )
352 | }
353 | showView()
354 | }
355 | return true
356 | }
357 | }
358 |
359 | return false
360 | }
361 |
362 | @Composable
363 | fun StreamVolumeSlider(
364 | streamType: Int,
365 | triggerChange: Int,
366 | icon: ImageVector,
367 | name: String,
368 | onChange: (() -> Unit)? = null
369 | ) {
370 | var volume by remember { mutableIntStateOf(audioManager.getStreamVolume(streamType)) }
371 |
372 | LaunchedEffect(triggerChange) {
373 | volume = audioManager.getStreamVolume(streamType)
374 | }
375 |
376 | TrackSlider(
377 | cornerRadius = 20.dp,
378 | value = volume.toFloat(),
379 | valueRange = 0f..audioManager.getStreamMaxVolume(streamType).toFloat(),
380 | onValueChange = { value ->
381 | audioManager.setStreamVolume(streamType, value.toInt(), 0)
382 | onChange?.invoke()
383 | },
384 | ) {
385 | Row(
386 | horizontalArrangement = Arrangement.spacedBy(8.dp),
387 | verticalAlignment = Alignment.CenterVertically,
388 | modifier = Modifier.padding(16.dp, 8.dp)
389 | ) {
390 | Image(
391 | imageVector = icon,
392 | contentDescription = name,
393 | modifier = Modifier.width(32.dp),
394 | contentScale = ContentScale.FillWidth
395 | )
396 |
397 | Text(text = name, color = Color.White)
398 | }
399 | }
400 | }
401 | }
402 |
--------------------------------------------------------------------------------
/app/src/main/java/moe/chensi/volume/TrackSlider.kt:
--------------------------------------------------------------------------------
1 | package moe.chensi.volume
2 |
3 | import androidx.compose.foundation.Canvas
4 | import androidx.compose.foundation.Image
5 | import androidx.compose.foundation.gestures.detectHorizontalDragGestures
6 | import androidx.compose.foundation.layout.Arrangement
7 | import androidx.compose.foundation.layout.Box
8 | import androidx.compose.foundation.layout.BoxScope
9 | import androidx.compose.foundation.layout.Row
10 | import androidx.compose.foundation.layout.fillMaxWidth
11 | import androidx.compose.foundation.layout.padding
12 | import androidx.compose.foundation.layout.width
13 | import androidx.compose.foundation.lazy.LazyColumn
14 | import androidx.compose.foundation.lazy.LazyListScope
15 | import androidx.compose.foundation.lazy.items
16 | import androidx.compose.material3.Text
17 | import androidx.compose.runtime.Composable
18 | import androidx.compose.runtime.getValue
19 | import androidx.compose.runtime.rememberUpdatedState
20 | import androidx.compose.ui.Alignment
21 | import androidx.compose.ui.Modifier
22 | import androidx.compose.ui.geometry.CornerRadius
23 | import androidx.compose.ui.geometry.Offset
24 | import androidx.compose.ui.geometry.RoundRect
25 | import androidx.compose.ui.geometry.Size
26 | import androidx.compose.ui.graphics.Color
27 | import androidx.compose.ui.graphics.Path
28 | import androidx.compose.ui.graphics.asImageBitmap
29 | import androidx.compose.ui.graphics.drawscope.clipPath
30 | import androidx.compose.ui.input.pointer.pointerInput
31 | import androidx.compose.ui.layout.ContentScale
32 | import androidx.compose.ui.unit.Dp
33 | import androidx.compose.ui.unit.dp
34 | import androidx.core.graphics.drawable.toBitmap
35 |
36 | @Composable
37 | fun TrackSlider(
38 | value: Float,
39 | onValueChange: (Float) -> Unit,
40 | modifier: Modifier = Modifier,
41 | enabled: Boolean = true,
42 | trackColor: Color = Color.LightGray,
43 | fillColor: Color = Color.Blue,
44 | cornerRadius: Dp = 8.dp,
45 | valueRange: ClosedFloatingPointRange = 0f..1f,
46 | content: @Composable BoxScope.() -> Unit = {}
47 | ) {
48 | val coercedValue = value.coerceIn(valueRange.start, valueRange.endInclusive)
49 | val latestValue by rememberUpdatedState(coercedValue)
50 |
51 | Box(
52 | modifier = modifier
53 | .fillMaxWidth()
54 | .pointerInput(enabled) {
55 | if (enabled) {
56 | var startValue = 0f
57 | var startX = 0f
58 |
59 | detectHorizontalDragGestures(onDragStart = { offset ->
60 | startValue = latestValue
61 | startX = offset.x
62 | }) { change, _ ->
63 | val dragAmount = change.position.x - startX
64 | val changedPercentage = dragAmount / size.width.toFloat()
65 | val totalRange = valueRange.endInclusive - valueRange.start
66 | val newValue = (startValue + changedPercentage * totalRange)
67 | val coercedNewValue =
68 | newValue.coerceIn(valueRange.start, valueRange.endInclusive)
69 | if (coercedNewValue != latestValue) {
70 | onValueChange(coercedNewValue)
71 | }
72 | }
73 | }
74 | },
75 | ) {
76 | Canvas(modifier = Modifier.matchParentSize()) {
77 | // Draw track
78 | drawRoundRect(
79 | color = trackColor,
80 | topLeft = Offset(0f, 0f),
81 | size = size,
82 | cornerRadius = CornerRadius(cornerRadius.toPx())
83 | )
84 |
85 | clipPath(Path().apply {
86 | addRoundRect(
87 | RoundRect(
88 | 0f, 0f, size.width, size.height, CornerRadius(cornerRadius.toPx())
89 | )
90 | )
91 | }) {
92 | // Draw fill
93 | drawRoundRect(
94 | color = fillColor, topLeft = Offset(0f, 0f), size = Size(
95 | (coercedValue - valueRange.start) / (valueRange.endInclusive - valueRange.start) * size.width,
96 | size.height
97 | ), cornerRadius = CornerRadius(2.dp.toPx())
98 | )
99 | }
100 | }
101 | Box(modifier = Modifier.align(Alignment.CenterStart)) {
102 | content()
103 | }
104 | }
105 | }
106 |
107 | @Composable
108 | fun AppVolumeSlider(app: Manager.App, onChange: (() -> Unit)? = null) {
109 | TrackSlider(cornerRadius = 20.dp, value = app.volume, onValueChange = { value ->
110 | app.volume = value
111 | onChange?.invoke()
112 | }) {
113 | Row(
114 | horizontalArrangement = Arrangement.spacedBy(8.dp),
115 | verticalAlignment = Alignment.CenterVertically,
116 | modifier = Modifier.padding(16.dp, 8.dp)
117 | ) {
118 | Image(
119 | bitmap = app.icon.toBitmap().asImageBitmap(),
120 | contentDescription = "App icon",
121 | modifier = Modifier.width(32.dp),
122 | contentScale = ContentScale.FillWidth
123 | )
124 |
125 | Text(text = app.name, color = Color.White)
126 | }
127 | }
128 | }
129 |
130 | @Composable
131 | fun AppVolumeList(
132 | apps: MutableCollection,
133 | onChange: (() -> Unit)? = null,
134 | content: (LazyListScope.() -> Unit)? = null
135 | ) {
136 | LazyColumn(verticalArrangement = Arrangement.spacedBy(12.dp)) {
137 | content?.invoke(this)
138 |
139 | items(items = apps.filter { it.players.size != 0 }.toList(),
140 | key = { app -> app.packageName }) { app ->
141 | AppVolumeSlider(app, onChange)
142 | }
143 | }
144 | }
--------------------------------------------------------------------------------
/app/src/main/java/moe/chensi/volume/ui/theme/Color.kt:
--------------------------------------------------------------------------------
1 | package moe.chensi.volume.ui.theme
2 |
3 | import androidx.compose.ui.graphics.Color
4 |
5 | val Purple80 = Color(0xFFD0BCFF)
6 | val PurpleGrey80 = Color(0xFFCCC2DC)
7 | val Pink80 = Color(0xFFEFB8C8)
8 |
9 | val Purple40 = Color(0xFF6650a4)
10 | val PurpleGrey40 = Color(0xFF625b71)
11 | val Pink40 = Color(0xFF7D5260)
--------------------------------------------------------------------------------
/app/src/main/java/moe/chensi/volume/ui/theme/Theme.kt:
--------------------------------------------------------------------------------
1 | package moe.chensi.volume.ui.theme
2 |
3 | import android.app.Activity
4 | import android.os.Build
5 | import androidx.compose.foundation.isSystemInDarkTheme
6 | import androidx.compose.material3.MaterialTheme
7 | import androidx.compose.material3.darkColorScheme
8 | import androidx.compose.material3.dynamicDarkColorScheme
9 | import androidx.compose.material3.dynamicLightColorScheme
10 | import androidx.compose.material3.lightColorScheme
11 | import androidx.compose.runtime.Composable
12 | import androidx.compose.ui.platform.LocalContext
13 |
14 | private val DarkColorScheme = darkColorScheme(
15 | primary = Purple80,
16 | secondary = PurpleGrey80,
17 | tertiary = Pink80
18 | )
19 |
20 | private val LightColorScheme = lightColorScheme(
21 | primary = Purple40,
22 | secondary = PurpleGrey40,
23 | tertiary = Pink40
24 |
25 | /* Other default colors to override
26 | background = Color(0xFFFFFBFE),
27 | surface = Color(0xFFFFFBFE),
28 | onPrimary = Color.White,
29 | onSecondary = Color.White,
30 | onTertiary = Color.White,
31 | onBackground = Color(0xFF1C1B1F),
32 | onSurface = Color(0xFF1C1B1F),
33 | */
34 | )
35 |
36 | @Composable
37 | fun VolumeManagerTheme(
38 | darkTheme: Boolean = isSystemInDarkTheme(),
39 | // Dynamic color is available on Android 12+
40 | dynamicColor: Boolean = true,
41 | content: @Composable () -> Unit
42 | ) {
43 | val colorScheme = when {
44 | dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
45 | val context = LocalContext.current
46 | if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
47 | }
48 |
49 | darkTheme -> DarkColorScheme
50 | else -> LightColorScheme
51 | }
52 |
53 | MaterialTheme(
54 | colorScheme = colorScheme,
55 | typography = Typography,
56 | content = content
57 | )
58 | }
--------------------------------------------------------------------------------
/app/src/main/java/moe/chensi/volume/ui/theme/Type.kt:
--------------------------------------------------------------------------------
1 | package moe.chensi.volume.ui.theme
2 |
3 | import androidx.compose.material3.Typography
4 | import androidx.compose.ui.text.TextStyle
5 | import androidx.compose.ui.text.font.FontFamily
6 | import androidx.compose.ui.text.font.FontWeight
7 | import androidx.compose.ui.unit.sp
8 |
9 | // Set of Material typography styles to start with
10 | val Typography = Typography(
11 | bodyLarge = TextStyle(
12 | fontFamily = FontFamily.Default,
13 | fontWeight = FontWeight.Normal,
14 | fontSize = 16.sp,
15 | lineHeight = 24.sp,
16 | letterSpacing = 0.5.sp
17 | )
18 | /* Other default text styles to override
19 | titleLarge = TextStyle(
20 | fontFamily = FontFamily.Default,
21 | fontWeight = FontWeight.Normal,
22 | fontSize = 22.sp,
23 | lineHeight = 28.sp,
24 | letterSpacing = 0.sp
25 | ),
26 | labelSmall = TextStyle(
27 | fontFamily = FontFamily.Default,
28 | fontWeight = FontWeight.Medium,
29 | fontSize = 11.sp,
30 | lineHeight = 16.sp,
31 | letterSpacing = 0.5.sp
32 | )
33 | */
34 | )
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yume-chan/VolumeManager/8a385b87e963838d50a3ab750e2df2a006d1f949/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yume-chan/VolumeManager/8a385b87e963838d50a3ab750e2df2a006d1f949/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yume-chan/VolumeManager/8a385b87e963838d50a3ab750e2df2a006d1f949/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yume-chan/VolumeManager/8a385b87e963838d50a3ab750e2df2a006d1f949/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yume-chan/VolumeManager/8a385b87e963838d50a3ab750e2df2a006d1f949/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yume-chan/VolumeManager/8a385b87e963838d50a3ab750e2df2a006d1f949/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yume-chan/VolumeManager/8a385b87e963838d50a3ab750e2df2a006d1f949/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yume-chan/VolumeManager/8a385b87e963838d50a3ab750e2df2a006d1f949/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yume-chan/VolumeManager/8a385b87e963838d50a3ab750e2df2a006d1f949/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yume-chan/VolumeManager/8a385b87e963838d50a3ab750e2df2a006d1f949/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Volume Manager
3 | Keep volume manager running in background, and provide quick access to it via accessibility button or physical volume button.
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/xml-v31/accessibility_service_config.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/accessibility_service_config.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/app/src/test/java/moe/chensi/volume/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package moe.chensi.volume
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle.kts:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | plugins {
3 | alias(libs.plugins.android.application) apply false
4 | alias(libs.plugins.kotlin.android) apply false
5 | alias(libs.plugins.kotlin.compose) apply false
6 | }
--------------------------------------------------------------------------------
/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=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. For more details, visit
12 | # https://developer.android.com/r/tools/gradle-multi-project-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 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/gradle/libs.versions.toml:
--------------------------------------------------------------------------------
1 | [versions]
2 | agp = "8.8.0"
3 | datastore = "1.1.3"
4 | hiddenapibypass = "6.1"
5 | joor = "0.9.15"
6 | kotlin = "2.0.0"
7 | coreKtx = "1.10.1"
8 | junit = "4.13.2"
9 | junitVersion = "1.1.5"
10 | espressoCore = "3.5.1"
11 | lifecycleRuntimeKtx = "2.6.1"
12 | activityCompose = "1.8.0"
13 | composeBom = "2024.04.01"
14 | shizuku = "13.1.5"
15 |
16 | [libraries]
17 | androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
18 | joor = { module = "org.jooq:joor", version.ref = "joor" }
19 | junit = { group = "junit", name = "junit", version.ref = "junit" }
20 | androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
21 | androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
22 | androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
23 | androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
24 | androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
25 | androidx-ui = { group = "androidx.compose.ui", name = "ui" }
26 | androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
27 | androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
28 | androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
29 | androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
30 | androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
31 | androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
32 |
33 | shizuku-api = { group = "dev.rikka.shizuku", name = "api", version.ref = "shizuku" }
34 | shizuku-provider = { group = "dev.rikka.shizuku", name = "provider", version.ref = "shizuku" }
35 | hiddenapibypass = { module = "org.lsposed.hiddenapibypass:hiddenapibypass", version.ref = "hiddenapibypass" }
36 |
37 | androidx-datastore-core-android = { group = "androidx.datastore", name = "datastore-core-android", version.ref = "datastore" }
38 | androidx-datastore-preferences = { group = "androidx.datastore", name = "datastore-preferences", version.ref = "datastore" }
39 |
40 | [plugins]
41 | android-application = { id = "com.android.application", version.ref = "agp" }
42 | kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
43 | kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
44 |
45 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yume-chan/VolumeManager/8a385b87e963838d50a3ab750e2df2a006d1f949/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Mar 08 15:32:58 CST 2025
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yume-chan/VolumeManager/8a385b87e963838d50a3ab750e2df2a006d1f949/screenshot.png
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | google {
4 | content {
5 | includeGroupByRegex("com\\.android.*")
6 | includeGroupByRegex("com\\.google.*")
7 | includeGroupByRegex("androidx.*")
8 | }
9 | }
10 | mavenCentral()
11 | gradlePluginPortal()
12 | }
13 | }
14 | dependencyResolutionManagement {
15 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
16 | repositories {
17 | google()
18 | mavenCentral()
19 | }
20 | }
21 |
22 | rootProject.name = "Volume Manager"
23 | include(":app")
24 |
--------------------------------------------------------------------------------