Skip to content

Commit a57d428

Browse files
committed
Fix formatting
1 parent 344d4ae commit a57d428

11 files changed

Lines changed: 109 additions & 149 deletions

File tree

app/src/main/java/org/lsposed/manager/ConfigManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ public static boolean setDexObfuscateEnabled(boolean enabled) {
385385
public static int getDex2OatWrapperCompatibility() {
386386
try {
387387
return LSPManagerServiceHolder.getService().getDex2OatWrapperCompatibility();
388-
} catch (RemoteException e) {
388+
} catch (RemoteException e) {
389389
Log.e(App.TAG, Log.getStackTraceString(e));
390390
return ILSPManagerService.DEX2OAT_CRASHED;
391391
}
Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
1-
<!--
2-
~ This file is part of LSPosed.
3-
~
4-
~ LSPosed is free software: you can redistribute it and/or modify
5-
~ it under the terms of the GNU General Public License as published by
6-
~ the Free Software Foundation, either version 3 of the License, or
7-
~ (at your option) any later version.
8-
~
9-
~ LSPosed is distributed in the hope that it will be useful,
10-
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
~ GNU General Public License for more details.
13-
~
14-
~ You should have received a copy of the GNU General Public License
15-
~ along with LSPosed. If not, see <https://www.gnu.org/licenses/>.
16-
~
17-
~ Copyright (C) 2021 LSPosed Contributors
18-
-->
19-
201
<vector xmlns:android="http://schemas.android.com/apk/res/android"
212
android:width="24dp"
223
android:height="24dp"
234
android:viewportWidth="24"
245
android:viewportHeight="24"
256
android:tint="?attr/colorControlNormal" >
26-
<path
7+
<path
278
android:fillColor="@android:color/white"
289
android:pathData="M3.2383,3.1211C2.4531,3.332 1.8086,3.9375 1.5391,4.7188L1.4297,5.0391L1.4297,18.9609L1.5391,19.2813C1.75,19.8828 2.1563,20.3672 2.7109,20.6641C3.2891,20.9727 2.6758,20.9531 12,20.9531C21.3242,20.9531 20.7109,20.9727 21.2891,20.6641C21.8438,20.3672 22.25,19.8828 22.4609,19.2813L22.5703,18.9609L22.5703,5.0391L22.4609,4.7188C22.25,4.1172 21.8438,3.6328 21.2891,3.3359C20.7109,3.0273 21.3281,3.0469 11.9766,3.0508C4.7188,3.0508 3.4531,3.0625 3.2383,3.1211ZM20.9453,12.9805C20.9297,18.8125 20.9297,18.8398 20.832,18.9648C20.6875,19.1641 20.5156,19.2695 20.293,19.3164C20.0234,19.3672 3.9766,19.3672 3.707,19.3164C3.4844,19.2695 3.3125,19.1641 3.168,18.9648C3.0703,18.8398 3.0703,18.8125 3.0547,12.9805L3.0469,7.125L20.9531,7.125ZM20.9453,12.9805,M6.4219,10.9922L7.8516,12.4219L5.0391,15.2344L7.1016,15.2344L9.9141,12.4219L7.0547,9.5625L4.9922,9.5625ZM6.4219,10.9922,M11.6328,13.7383C11.207,13.9492 11.0664,14.5391 11.3594,14.9219C11.6055,15.2422 11.5508,15.2383 14.0938,15.2266L16.3828,15.2109L16.543,15.0977C16.7266,14.9688 16.8711,14.6719 16.875,14.4336C16.875,14.1719 16.6914,13.875 16.4531,13.75L16.25,13.6406L14.043,13.6406C11.8867,13.6406 11.832,13.6445 11.6328,13.7383ZM11.6328,13.7383" />
2910
</vector>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
<string name="settings_xposed_api_call_protection_summary">Block dynamically loaded module code to use Xposed API, this may break some modules but benefit security</string>
212212
<string name="settings_group_cli">Command line interface</string>
213213
<string name="pref_title_enable_cli">Enable CLI feature</string>
214-
<!-- Default summary when disabled -->
214+
<!-- Default summary when disabled -->
215215
<string name="pref_summary_enable_cli">Automate LSPosed with shell scripts via PIN authentication</string>
216216
<!-- Summary for Release builds when enabled -->
217217
<string name="pref_summary_cli_pin">Your CLI auth PIN is: <B>%1$s</B><br/></string>

daemon/proguard-rules.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
-keep class picocli.CommandLine { *; }
77
-keep class picocli.CommandLine$* { *; }
8+
-keep class org.lsposed.lspd.cli.* {*;}
89

910
-keepclassmembers class * extends java.util.concurrent.Callable {
1011
public java.lang.Integer call();
1112
}
12-
-keep class org.lsposed.lspd.cli.* {*;}
13+
1314
-keepclasseswithmembers class org.lsposed.lspd.cli.Main {
1415
public static void main(java.lang.String[]);
1516
}
16-
1717
-keepclasseswithmembers class org.lsposed.lspd.Main {
1818
public static void main(java.lang.String[]);
1919
}

daemon/src/main/java/org/lsposed/lspd/cli/Main.java

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public Integer call() throws RemoteException {
260260

261261
@CommandLine.Command(name = "modules", subcommands = {ListModulesCommand.class, SetModulesCommand.class})
262262
class ModulesCommand implements Runnable {
263-
@CommandLine.ParentCommand
263+
@CommandLine.ParentCommand
264264
Main parent;
265265

266266
@CommandLine.Option(names = {"-h", "--help", "help"}, usageHelp = true, description = "display this help message")
@@ -428,7 +428,7 @@ public Integer call() throws RemoteException {
428428

429429
@CommandLine.Command(name = "scope", subcommands = {ListScopeCommand.class, SetScopeCommand.class})
430430
class ScopeCommand implements Runnable {
431-
@CommandLine.ParentCommand
431+
@CommandLine.ParentCommand
432432
Main parent;
433433

434434
@CommandLine.Option(names = {"-h", "--help", "help"}, usageHelp = true, description = "display this help message")
@@ -665,7 +665,7 @@ public Integer call() throws RemoteException {
665665

666666
@CommandLine.Command(name = CMDNAME, subcommands = {LogCommand.class, LoginCommand.class, BackupCommand.class, ModulesCommand.class, RestoreCommand.class, ScopeCommand.class, StatusCommand.class, RevokePinCommand.class}, version = "0.3")
667667
public class Main implements Runnable {
668-
@CommandLine.Option(names = {"-p", "--pin"}, description = "Authentication PIN for the CLI.", scope = CommandLine.ScopeType.INHERIT)
668+
@CommandLine.Option(names = {"-p", "--pin"}, description = "Authentication PIN for the CLI.", scope = CommandLine.ScopeType.INHERIT)
669669
String pin;
670670

671671
@CommandLine.Option(names = {"-V", "--version", "version"}, versionHelp = true, description = "display version info")
@@ -683,13 +683,13 @@ public Main() {
683683
}
684684

685685
public static void main(String[] args) {
686-
System.exit(new CommandLine(new Main())
687-
.setExecutionExceptionHandler((ex, commandLine, parseResult) -> {
688-
commandLine.getErr().println(ex.getMessage());
689-
return ex instanceof SecurityException ? ERRCODES.AUTH_FAILED.ordinal() : ERRCODES.REMOTE_ERROR.ordinal();
690-
})
691-
.execute(args));
692-
}
686+
System.exit(new CommandLine(new Main())
687+
.setExecutionExceptionHandler((ex, commandLine, parseResult) -> {
688+
commandLine.getErr().println(ex.getMessage());
689+
return ex instanceof SecurityException ? ERRCODES.AUTH_FAILED.ordinal() : ERRCODES.REMOTE_ERROR.ordinal();
690+
})
691+
.execute(args));
692+
}
693693

694694
public void run() {
695695
throw new CommandLine.ParameterException(spec.commandLine(), "Missing required subcommand");
@@ -713,7 +713,7 @@ public int handleExecutionException(Exception ex, CommandLine commandLine, Parse
713713
}
714714

715715
public final ICLIService getManager() {
716-
if (objManager == null) {
716+
if (objManager == null) {
717717
try {
718718
objManager = connectToService();
719719
if (objManager == null) {
@@ -728,68 +728,68 @@ public final ICLIService getManager() {
728728
return objManager;
729729
}
730730

731-
private ICLIService connectToService() throws RemoteException {
732-
// 1. Check for credentials provided by the user via arguments or environment.
733-
// We store this in a separate variable to remember if the user even tried to provide a PIN.
734-
String initialPin = this.pin; // `this.pin` is populated by picocli from the --pin arg
735-
if (initialPin == null) {
736-
initialPin = System.getenv("LSPOSED_CLI_PIN");
737-
}
738-
// `this.pin` will be used for the actual connection attempts.
739-
this.pin = initialPin;
740-
741-
// 2. Connect to the basic application service binder (boilerplate).
742-
var activityService = ServiceManager.getService("activity");
743-
if (activityService == null) throw new RemoteException("Could not get activity service.");
744-
745-
var binder = new Binder();
746-
Parcel data = Parcel.obtain();
747-
data.writeInterfaceToken("LSPosed");
748-
data.writeInt(2);
749-
data.writeString("lsp-cli:" + org.lsposed.lspd.util.SignInfo.CLI_UUID);
750-
data.writeStrongBinder(binder);
751-
Parcel reply = Parcel.obtain();
752-
753-
if (!activityService.transact(1598837584, data, reply, 0)) {
754-
throw new RemoteException("Transaction to activity service failed.");
755-
}
756-
757-
reply.readException();
758-
var serviceBinder = reply.readStrongBinder();
759-
if (serviceBinder == null) throw new RemoteException("Daemon did not return a service binder.");
760-
761-
var service = ILSPApplicationService.Stub.asInterface(serviceBinder);
762-
var lstBinder = new ArrayList<IBinder>(1);
763-
764-
// 3. First attempt: Authenticate with the credentials we have (which could be null).
765-
service.requestCLIBinder(this.pin, lstBinder);
766-
767-
// 4. Recovery step: If the first attempt failed, we have no PIN, AND we're in an
768-
// interactive shell, then prompt the user as a last resort.
769-
if (lstBinder.isEmpty() && this.pin == null && System.console() != null) {
770-
System.err.println("Authentication required.");
771-
char[] pinChars = System.console().readPassword("Enter CLI PIN: ");
772-
if (pinChars != null) {
773-
this.pin = new String(pinChars);
774-
// Second attempt: Retry with the PIN from the interactive prompt.
775-
service.requestCLIBinder(this.pin, lstBinder);
776-
}
777-
}
778-
779-
// 5. Final check and smart error reporting.
780-
if (lstBinder.isEmpty()) {
781-
String errorMessage;
782-
if (initialPin == null) {
783-
// The user never provided a PIN. The daemon requires one. Guide the user.
784-
errorMessage = "Authentication required. Use --pin, set LSPOSED_CLI_PIN, or use an interactive shell.";
785-
} else {
786-
// The user provided a PIN, but it was rejected by the daemon.
787-
errorMessage = "Authentication failed. The provided PIN is incorrect or CLI is disabled in the Manager app.";
788-
}
789-
throw new SecurityException(errorMessage);
790-
}
791-
792-
// If we reach here, we are successful.
793-
return ICLIService.Stub.asInterface(lstBinder.get(0));
794-
}
731+
private ICLIService connectToService() throws RemoteException {
732+
// 1. Check for credentials provided by the user via arguments or environment.
733+
// We store this in a separate variable to remember if the user even tried to provide a PIN.
734+
String initialPin = this.pin; // `this.pin` is populated by picocli from the --pin arg
735+
if (initialPin == null) {
736+
initialPin = System.getenv("LSPOSED_CLI_PIN");
737+
}
738+
// `this.pin` will be used for the actual connection attempts.
739+
this.pin = initialPin;
740+
741+
// 2. Connect to the basic application service binder (boilerplate).
742+
var activityService = ServiceManager.getService("activity");
743+
if (activityService == null) throw new RemoteException("Could not get activity service.");
744+
745+
var binder = new Binder();
746+
Parcel data = Parcel.obtain();
747+
data.writeInterfaceToken("LSPosed");
748+
data.writeInt(2);
749+
data.writeString("lsp-cli:" + org.lsposed.lspd.util.SignInfo.CLI_UUID);
750+
data.writeStrongBinder(binder);
751+
Parcel reply = Parcel.obtain();
752+
753+
if (!activityService.transact(1598837584, data, reply, 0)) {
754+
throw new RemoteException("Transaction to activity service failed.");
755+
}
756+
757+
reply.readException();
758+
var serviceBinder = reply.readStrongBinder();
759+
if (serviceBinder == null) throw new RemoteException("Daemon did not return a service binder.");
760+
761+
var service = ILSPApplicationService.Stub.asInterface(serviceBinder);
762+
var lstBinder = new ArrayList<IBinder>(1);
763+
764+
// 3. First attempt: Authenticate with the credentials we have (which could be null).
765+
service.requestCLIBinder(this.pin, lstBinder);
766+
767+
// 4. Recovery step: If the first attempt failed, we have no PIN, AND we're in an
768+
// interactive shell, then prompt the user as a last resort.
769+
if (lstBinder.isEmpty() && this.pin == null && System.console() != null) {
770+
System.err.println("Authentication required.");
771+
char[] pinChars = System.console().readPassword("Enter CLI PIN: ");
772+
if (pinChars != null) {
773+
this.pin = new String(pinChars);
774+
// Second attempt: Retry with the PIN from the interactive prompt.
775+
service.requestCLIBinder(this.pin, lstBinder);
776+
}
777+
}
778+
779+
// 5. Final check and smart error reporting.
780+
if (lstBinder.isEmpty()) {
781+
String errorMessage;
782+
if (initialPin == null) {
783+
// The user never provided a PIN. The daemon requires one. Guide the user.
784+
errorMessage = "Authentication required. Use --pin, set LSPOSED_CLI_PIN, or use an interactive shell.";
785+
} else {
786+
// The user provided a PIN, but it was rejected by the daemon.
787+
errorMessage = "Authentication failed. The provided PIN is incorrect or CLI is disabled in the Manager app.";
788+
}
789+
throw new SecurityException(errorMessage);
790+
}
791+
792+
// If we reach here, we are successful.
793+
return ICLIService.Stub.asInterface(lstBinder.get(0));
794+
}
795795
}

daemon/src/main/java/org/lsposed/lspd/service/CLIService.java

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
/*
2-
* This file is part of LSPosed.
3-
*
4-
* LSPosed is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation, either version 3 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* LSPosed is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
13-
*
14-
* You should have received a copy of the GNU General Public License
15-
* along with LSPosed. If not, see <https://www.gnu.org/licenses/>.
16-
*
17-
* Copyright (C) 2022 LSPosed Contributors
18-
*/
19-
201
package org.lsposed.lspd.service;
212

223
import static org.lsposed.lspd.service.ServiceManager.TAG;
@@ -74,13 +55,13 @@ public class CLIService extends ICLIService.Stub {
7455
CLIService() {
7556
}
7657

77-
@Override
58+
@Override
7859
public void revokeCurrentPin() {
7960
ConfigManager.getInstance().disableCli();
8061
}
8162

8263
public static boolean basicCheck(int uid) {
83-
return uid == 0;
64+
return uid == 0;
8465
}
8566

8667
public static boolean applicationStageNameValid(int pid, String processName) {

daemon/src/main/java/org/lsposed/lspd/service/ConfigManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ synchronized SharedMemory getPreloadDex() {
12521252

12531253
public boolean getAutoInclude(String packageName) {
12541254
try (Cursor cursor = db.query("modules", new String[]{"auto_include"},
1255-
"module_pkg_name = ? and auto_include = 1", new String[]{packageName}, null, null, null, null)) {
1255+
"module_pkg_name = ? and auto_include = 1", new String[]{packageName}, null, null, null, null)) {
12561256
return cursor == null || cursor.moveToNext();
12571257
}
12581258
}

daemon/src/main/java/org/lsposed/lspd/service/LSPApplicationService.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -160,32 +160,31 @@ public ParcelFileDescriptor requestInjectedManagerBinder(List<IBinder> binder) t
160160
return ConfigManager.getInstance().getManagerApk();
161161
}
162162

163-
@Override
163+
@Override
164164
public void requestCLIBinder(String pin, List<IBinder> binder) throws RemoteException {
165165
ensureRegistered(); // Ensures caller is a valid process
166-
167166
ConfigManager config = ConfigManager.getInstance();
168-
169-
boolean allowAccess = false;
170-
// Rule 1: Special case for DEBUG builds.
171-
if (BuildConfig.DEBUG) {
172-
// If the daemon is a debug build AND no PIN has been set in memory yet,
173-
// we allow access by default without a PIN.
174-
if (config.getCurrentCliPin() == null && pin == null) {
175-
allowAccess = true;
176-
}
177-
}
178-
179-
// Rule 2: Standard PIN validation for ALL builds.
180-
// If access wasn't already granted by the debug rule, we perform the normal check.
181-
if (!allowAccess && config.isCliPinValid(pin)) {
182-
allowAccess = true;
183-
}
184-
185-
if (allowAccess) {
186-
binder.add(ServiceManager.getCLIService());
187-
}
188-
}
167+
168+
boolean allowAccess = false;
169+
// Rule 1: Special case for DEBUG builds.
170+
if (BuildConfig.DEBUG) {
171+
// If the daemon is a debug build AND no PIN has been set in memory yet,
172+
// we allow access by default without a PIN.
173+
if (config.getCurrentCliPin() == null && pin == null) {
174+
allowAccess = true;
175+
}
176+
}
177+
178+
// Rule 2: Standard PIN validation for ALL builds.
179+
// If access wasn't already granted by the debug rule, we perform the normal check.
180+
if (!allowAccess && config.isCliPinValid(pin)) {
181+
allowAccess = true;
182+
}
183+
184+
if (allowAccess) {
185+
binder.add(ServiceManager.getCLIService());
186+
}
187+
}
189188

190189
public boolean hasRegister(int uid, int pid) {
191190
return processes.containsKey(new Pair<>(uid, pid));

daemon/src/main/java/org/lsposed/lspd/service/LSPNotificationManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void binderDied() {
6161
}
6262
};
6363

64-
static INotificationManager getNotificationManager() throws RemoteException {
64+
private static INotificationManager getNotificationManager() throws RemoteException {
6565
if (binder == null || notificationManager == null) {
6666
binder = android.os.ServiceManager.getService(Context.NOTIFICATION_SERVICE);
6767
binder.linkToDeath(recipient, 0);
@@ -90,11 +90,11 @@ private static Bitmap getBitmap(int id) {
9090
}
9191
}
9292

93-
static Icon getNotificationIcon() {
93+
private static Icon getNotificationIcon() {
9494
return Icon.createWithBitmap(getBitmap(R.drawable.ic_notification));
9595
}
9696

97-
static boolean hasNotificationChannelForSystem(
97+
private static boolean hasNotificationChannelForSystem(
9898
INotificationManager nm, String channelId) throws RemoteException {
9999
NotificationChannel channel;
100100
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
<string name="status_channel_name">LSPosed status</string>
1212
<string name="lsposed_running_notification_title">LSPosed loaded</string>
1313
<string name="lsposed_running_notification_content">Tap the notification to open manager</string>
14-
<!-- PIN Notification -->
15-
<string name="pin_request_notification_title">PIN Code requested</string>
1614
<string name="xposed_module_request_scope_title">Scope Request</string>
1715
<string name="xposed_module_request_scope_content">%1$s on user %2$s requests to add %3$s to its scope.</string>
1816
<string name="scope_channel_name">Scope request</string>

0 commit comments

Comments
 (0)