Skip to content

Commit

Permalink
Use packageName if targetting app embedding a library
Browse files Browse the repository at this point in the history
  • Loading branch information
p1gp1g authored and mar-v-in committed Sep 28, 2024
1 parent 9e9bec2 commit 2629fe0
Showing 1 changed file with 6 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import static android.os.Build.VERSION.SDK_INT;
Expand Down Expand Up @@ -130,27 +131,17 @@ private String getTargetPackageWithoutPref() {
} catch (PackageManager.NameNotFoundException e) {
Log.d(TAG, USER_MICROG_PACKAGE_NAME + " not found");
}
return null;
return context.getPackageName();
}

private String getTargetPackage() {
SharedPreferences prefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
final String SELF = "SELF";
String target;
if ((target = prefs.getString(PREF_TARGET, null)) != null) {
switch (target) {
case GMS_PACKAGE_NAME:
case USER_MICROG_PACKAGE_NAME:
return target;
case SELF:
return null;
}
}
if ((target = getTargetPackageWithoutPref()) == null ) {
prefs.edit().putString(PREF_TARGET, SELF).apply();
} else {
prefs.edit().putString(PREF_TARGET, target).apply();
return target;
}
target = getTargetPackageWithoutPref();
prefs.edit().putString(PREF_TARGET, target).apply();
return target;
}

Expand Down Expand Up @@ -251,7 +242,7 @@ public Connection(String actionString, boolean requireMicrog) {
private Intent getIntent() {
Intent intent;
ResolveInfo resolveInfo;
if (targetPackage != null) {
if (!Objects.equals(targetPackage, context.getPackageName())) {
intent = new Intent(actionString).setPackage(targetPackage);
if ((resolveInfo = context.getPackageManager().resolveService(intent, 0)) != null) {
if (requireMicrog && !isMicrog(resolveInfo)) {
Expand Down

0 comments on commit 2629fe0

Please sign in to comment.