Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mywalkb committed Aug 22, 2023
2 parents 32108c6 + c3cfcd7 commit 490a6ba
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Window;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.lsposed.manager.App;
import org.lsposed.manager.R;
import org.lsposed.manager.util.ThemeUtil;

import rikka.material.app.MaterialActivity;

public class BaseActivity extends MaterialActivity {

private static Bitmap icon = null;

@Override
Expand All @@ -50,21 +51,22 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
@Override
protected void onStart() {
super.onStart();
if (!App.isParasitic) return;
for (var task : getSystemService(ActivityManager.class).getAppTasks()) {
task.setExcludeFromRecents(false);
}
if (icon == null) {
var drawable = getApplicationInfo().loadIcon(getPackageManager());
if (drawable instanceof BitmapDrawable) {
icon = ((BitmapDrawable) drawable).getBitmap();
} else {
} else if (drawable instanceof AdaptiveIconDrawable) {
icon = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(icon);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
}
}
setTaskDescription(new ActivityManager.TaskDescription(getTitle().toString(), icon));
setTaskDescription(new ActivityManager.TaskDescription(getTitle().toString(), icon, getColor(R.color.ic_launcher_background)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,16 @@ public void onDetach() {
parentFragment = null;
}

@Override
public void onResume() {
super.onResume();
MaterialSwitchPreference notificationPreference = findPreference("enable_status_notification");
if (App.isParasitic && notificationPreference != null && notificationPreference.isVisible()) {
setNotificationPreferenceEnabled(notificationPreference, ShortcutUtil.isLaunchShortcutPinned());
}
}

private void setNotificationPreferenceEnabled(MaterialSwitchPreference notificationPreference, boolean enabled) {
private boolean setNotificationPreferenceEnabled(MaterialSwitchPreference notificationPreference, boolean preferenceEnabled) {
var notificationEnabled = ConfigManager.enableStatusNotification();
if (notificationPreference != null) {
notificationPreference.setEnabled(!ConfigManager.enableStatusNotification() || enabled);
notificationPreference.setSummaryOn(enabled ?
notificationPreference.setEnabled(!notificationEnabled || preferenceEnabled);
notificationPreference.setSummaryOn(preferenceEnabled ?
notificationPreference.getContext().getString(R.string.settings_enable_status_notification_summary) :
notificationPreference.getContext().getString(R.string.settings_enable_status_notification_summary) + "\n" +
notificationPreference.getContext().getString(R.string.disable_status_notification_error));
}
return notificationEnabled;
}

@Override
Expand Down Expand Up @@ -179,16 +172,16 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

MaterialSwitchPreference notificationPreference = findPreference("enable_status_notification");
if (notificationPreference != null) {
if (App.isParasitic && !ShortcutUtil.isLaunchShortcutPinned()) {
setNotificationPreferenceEnabled(notificationPreference, false);
}
notificationPreference.setVisible(installed);
notificationPreference.setChecked(installed && ConfigManager.enableStatusNotification());
if (installed && App.isParasitic) {
notificationPreference.setChecked(setNotificationPreferenceEnabled(notificationPreference, ShortcutUtil.isLaunchShortcutPinned()));
}
notificationPreference.setOnPreferenceChangeListener((p, v) -> {
var succeeded = ConfigManager.setEnableStatusNotification((boolean) v);
if ((boolean) v && App.isParasitic && !ShortcutUtil.isLaunchShortcutPinned()) {
setNotificationPreferenceEnabled(notificationPreference, false);
}
return ConfigManager.setEnableStatusNotification((boolean) v);
return succeeded;
});
}

Expand Down
6 changes: 1 addition & 5 deletions app/src/main/java/org/lsposed/manager/util/AppModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import android.content.Context;
import android.content.pm.PackageInfo;
import android.graphics.Bitmap;
import android.graphics.drawable.AdaptiveIconDrawable;

import androidx.annotation.NonNull;

Expand All @@ -44,10 +43,7 @@ public boolean isManifestParsingEnabled() {
@Override
public void registerComponents(Context context, @NonNull Glide glide, Registry registry) {
int iconSize = context.getResources().getDimensionPixelSize(R.dimen.app_icon_size);
var info = context.getApplicationInfo();
var pm = context.getPackageManager();
var shrinkNonAdaptiveIcons = info.loadIcon(pm) instanceof AdaptiveIconDrawable;
var factory = new AppIconModelLoader.Factory(iconSize, shrinkNonAdaptiveIcons, context);
var factory = new AppIconModelLoader.Factory(iconSize, false, context);
registry.prepend(PackageInfo.class, Bitmap.class, factory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void onReceive(Context c, Intent intent) {
}
};
context.registerReceiver(receiver, filter, permission,
null/* main thread */, Context.RECEIVER_NOT_EXPORTED);
null/* main thread */, Context.RECEIVER_EXPORTED);

var intent = new Intent(uuid);
int flags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;
Expand Down
6 changes: 4 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ cmaker {
}
buildTypes {
if (it.name == "release") {
arguments += "-DDEBUG_SYMBOLS_PATH=${buildDir.absolutePath}/symbols"
arguments += "-DDEBUG_SYMBOLS_PATH=${
layout.buildDirectory.dir("symbols").get().asFile.absolutePath
}"
}
}
}
Expand All @@ -74,7 +76,7 @@ val androidSourceCompatibility by extra(JavaVersion.VERSION_17)
val androidTargetCompatibility by extra(JavaVersion.VERSION_17)

tasks.register("Delete", Delete::class) {
delete(rootProject.buildDir)
delete(rootProject.layout.buildDirectory)
}

subprojects {
Expand Down
9 changes: 6 additions & 3 deletions daemon/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ android.applicationVariants.all {
val variantCapped = name.replaceFirstChar { it.uppercase() }
val variantLowered = name.lowercase()

val outSrcDir = file("$buildDir/generated/source/signInfo/${variantLowered}")
val outSrcDir =
layout.buildDirectory.dir("generated/source/signInfo/${variantLowered}").get()
val signInfoTask = tasks.register("generate${variantCapped}SignInfo") {
dependsOn(":app:validateSigning${variantCapped}")
val sign = rootProject.project(":app").extensions.getByType(ApplicationExtension::class.java).buildTypes.named(variantLowered).get().signingConfig
val sign = rootProject.project(":app").extensions
.getByType(ApplicationExtension::class.java)
.buildTypes.named(variantLowered).get().signingConfig
val outSrc = file("$outSrcDir/org/lsposed/lspd/util/SignInfo.java")
outputs.file(outSrc)
doLast {
Expand All @@ -112,7 +115,7 @@ android.applicationVariants.all {
)
}
}
registerJavaGeneratingTask(signInfoTask, outSrcDir)
registerJavaGeneratingTask(signInfoTask, outSrcDir.asFile)
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import static org.lsposed.lspd.service.ServiceManager.TAG;

import android.annotation.SuppressLint;
import android.app.ContentProviderHolder;
import android.app.IActivityManager;
import android.app.IApplicationThread;
Expand All @@ -45,7 +44,7 @@
public class ActivityManagerService {
private static IActivityManager am = null;
private static IBinder binder = null;
private static IApplicationThread thread = null;
private static IApplicationThread appThread = null;
private static IBinder token = null;

private static final IBinder.DeathRecipient deathRecipient = new IBinder.DeathRecipient() {
Expand All @@ -55,7 +54,7 @@ public void binderDied() {
binder.unlinkToDeath(this, 0);
binder = null;
am = null;
thread = null;
appThread = null;
token = null;
}
};
Expand All @@ -81,21 +80,21 @@ public static int broadcastIntentWithFeature(String callingFeatureId,
String resultData, Bundle map, String[] requiredPermissions,
int appOp, Bundle options, boolean serialized, boolean sticky, int userId) throws RemoteException {
IActivityManager am = getActivityManager();
if (am == null || thread == null) return -1;
if (am == null || appThread == null) return -1;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
try {
return am.broadcastIntentWithFeature(thread, callingFeatureId, intent, resolvedType, resultTo,
return am.broadcastIntentWithFeature(appThread, callingFeatureId, intent, resolvedType, resultTo,
resultCode, resultData, null, requiredPermissions, null, null, appOp, null,
serialized, sticky, userId);
} catch (NoSuchMethodError ignored) {
return am.broadcastIntentWithFeature(thread, callingFeatureId, intent, resolvedType, resultTo,
return am.broadcastIntentWithFeature(appThread, callingFeatureId, intent, resolvedType, resultTo,
resultCode, resultData, null, requiredPermissions, null, appOp, null,
serialized, sticky, userId);
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return am.broadcastIntentWithFeature(thread, callingFeatureId, intent, resolvedType, resultTo, resultCode, resultData, map, requiredPermissions, appOp, options, serialized, sticky, userId);
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) {
return am.broadcastIntentWithFeature(appThread, callingFeatureId, intent, resolvedType, resultTo, resultCode, resultData, map, requiredPermissions, appOp, options, serialized, sticky, userId);
} else {
return am.broadcastIntent(thread, intent, resolvedType, resultTo, resultCode, resultData, map, requiredPermissions, appOp, options, serialized, sticky, userId);
return am.broadcastIntent(appThread, intent, resolvedType, resultTo, resultCode, resultData, map, requiredPermissions, appOp, options, serialized, sticky, userId);
}
}

Expand All @@ -111,36 +110,43 @@ public static boolean startUserInBackground(int userId) throws RemoteException {
return am.startUserInBackground(userId);
}

@SuppressLint("NewApi")
public static Intent registerReceiver(String callerPackage,
String callingFeatureId, IIntentReceiver receiver, IntentFilter filter,
String requiredPermission, int userId, int flags) throws RemoteException {
IActivityManager am = getActivityManager();
if (am == null || thread == null) return null;
if (am == null || appThread == null) return null;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
return am.registerReceiverWithFeature(thread, callerPackage, callingFeatureId, "null", receiver, filter, requiredPermission, userId, flags);
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return am.registerReceiverWithFeature(thread, callerPackage, callingFeatureId, receiver, filter, requiredPermission, userId, flags);
return am.registerReceiverWithFeature(appThread, callerPackage, callingFeatureId, "null", receiver, filter, requiredPermission, userId, flags);
else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) {
return am.registerReceiverWithFeature(appThread, callerPackage, callingFeatureId, receiver, filter, requiredPermission, userId, flags);
} else {
return am.registerReceiver(thread, callerPackage, receiver, filter, requiredPermission, userId, flags);
return am.registerReceiver(appThread, callerPackage, receiver, filter, requiredPermission, userId, flags);
}
}

public static void finishReceiver(IBinder who, int resultCode, String resultData, Bundle map,
boolean abortBroadcast, int flags) throws RemoteException {
public static void finishReceiver(IBinder intentReceiver, IBinder applicationThread, int resultCode,
String resultData, Bundle resultExtras, boolean resultAbort,
int flags) throws RemoteException {
IActivityManager am = getActivityManager();
if (am == null || thread == null) return;
am.finishReceiver(who, resultCode, resultData, map, abortBroadcast, flags);
if (am == null || appThread == null) return;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
am.finishReceiver(applicationThread, resultCode, resultData, resultExtras, resultAbort, flags);
} else {
am.finishReceiver(intentReceiver, resultCode, resultData, resultExtras, resultAbort, flags);
}
}

public static int bindService(Intent service,
String resolvedType, IServiceConnection connection, int flags,
String callingPackage, int userId) throws RemoteException {

IActivityManager am = getActivityManager();
if (am == null || thread == null) return -1;
return am.bindService(thread, token, service, resolvedType, connection, flags, callingPackage, userId);
if (am == null || appThread == null) return -1;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
return am.bindService(appThread, token, service, resolvedType, connection, (long) flags, callingPackage, userId);
else
return am.bindService(appThread, token, service, resolvedType, connection, flags, callingPackage, userId);
}

public static boolean unbindService(IServiceConnection connection) throws RemoteException {
Expand All @@ -154,17 +160,17 @@ public static int startActivityAsUserWithFeature(String callingPackage,
IBinder resultTo, String resultWho, int requestCode, int flags,
ProfilerInfo profilerInfo, Bundle options, int userId) throws RemoteException {
IActivityManager am = getActivityManager();
if (am == null || thread == null) return -1;
if (am == null || appThread == null) return -1;
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return am.startActivityAsUserWithFeature(thread, callingPackage, callingFeatureId, intent, resolvedType, resultTo, resultWho, requestCode, flags, profilerInfo, options, userId);
return am.startActivityAsUserWithFeature(appThread, callingPackage, callingFeatureId, intent, resolvedType, resultTo, resultWho, requestCode, flags, profilerInfo, options, userId);
} else {
return am.startActivityAsUser(thread, callingPackage, intent, resolvedType, resultTo, resultWho, requestCode, flags, profilerInfo, options, userId);
return am.startActivityAsUser(appThread, callingPackage, intent, resolvedType, resultTo, resultWho, requestCode, flags, profilerInfo, options, userId);
}
}

public static void onSystemServerContext(IApplicationThread thread, IBinder token) {
ActivityManagerService.thread = thread;
ActivityManagerService.appThread = thread;
ActivityManagerService.token = token;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws
}

switch (code) {
case BridgeService.TRANSACTION_CODE:
case BridgeService.TRANSACTION_CODE -> {
int uid = data.readInt();
int pid = data.readInt();
String processName = data.readString();
Expand All @@ -109,12 +109,14 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws
Log.d(TAG, "LSPSystemServerService.onTransact requestApplicationService rejected");
return false;
}
case LSPApplicationService.OBFUSCATION_MAP_TRANSACTION_CODE:
case LSPApplicationService.DEX_TRANSACTION_CODE:
}
case LSPApplicationService.OBFUSCATION_MAP_TRANSACTION_CODE, LSPApplicationService.DEX_TRANSACTION_CODE -> {
// Proxy LSP dex transaction to Application Binder
return ServiceManager.getApplicationService().onTransact(code, data, reply, flags);
default:
}
default -> {
return super.onTransact(code, data, reply, flags);
}
}
}

Expand Down
Loading

0 comments on commit 490a6ba

Please sign in to comment.