Skip to content

Commit

Permalink
move all hiddenapi functionality into MultiUser.java
Browse files Browse the repository at this point in the history
  • Loading branch information
infinity0 committed Aug 29, 2023
1 parent 291a878 commit 26da19c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/dev/ukanth/ufirewall/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,8 @@ public static List<PackageInfoData> getApps(Context ctx, GetAppList appList) {

for (PackageInfo pkginfo : installed) {
ApplicationInfo apinfo = pkginfo.applicationInfo;
if (apinfo == null) continue;

int user_id = MultiUser.applicationUserId(apinfo);
Log.d(TAG, "Processing app info: " + apinfo.packageName + " / user " + user_id + " / uid " + apinfo.uid);
count = count + 1;
Expand Down
11 changes: 1 addition & 10 deletions app/src/main/java/dev/ukanth/ufirewall/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@
import com.afollestad.materialdialogs.MaterialDialog;
import com.topjohnwu.superuser.Shell;

import org.lsposed.hiddenapibypass.HiddenApiBypass;

import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
Expand Down Expand Up @@ -164,13 +162,6 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
private static final int DEFAULT_VIEW_LIMIT = 4;
private View view;

static {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
HiddenApiBypass.addHiddenApiExemptions("");
}
}


public boolean isDirty() {
return dirty;
}
Expand All @@ -186,7 +177,7 @@ public void setDirty(boolean dirty) {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MultiUser.setupPermissions();
MultiUser.setup();

initTheme();
G.registerPrivateLink();
Expand Down
13 changes: 9 additions & 4 deletions app/src/main/java/dev/ukanth/ufirewall/MultiUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import com.topjohnwu.superuser.Shell;

import org.lsposed.hiddenapibypass.HiddenApiBypass;

import dev.ukanth.ufirewall.log.Log;


Expand Down Expand Up @@ -55,7 +57,11 @@ public static List<UserInfo> getUsers() {
return res;
}

public static void setupPermissions() {
public static void setup() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
HiddenApiBypass.addHiddenApiExemptions("");
}

Shell.Result result = Shell.cmd("pm grant dev.ukanth.ufirewall android.permission.INTERACT_ACROSS_USERS").exec();
if (!result.isSuccess()) {
Log.w(TAG, "pm grant INTERACT_ACROSS_USERS failed; further errors likely");
Expand Down Expand Up @@ -113,9 +119,8 @@ public static int applicationUserId(ApplicationInfo info) {
}

// Copied from LSPosed daemon/**/PackageService.java
// This requires INTERACT_ACROSS_USERS permission. LSPosed already has it,
// but we need to grant it at runtime from su - call setupPermissions() at
// the start of the app.
// This requires INTERACT_ACROSS_USERS permission. LSPosed already has it, but
// we need to grant it at runtime - make sure you call setup() in app.onCreate(_)
public static List<PackageInfo> getInstalledPackagesFromAllUsers(int flags/*, boolean filterNoProcess*/) throws RemoteException {
List<PackageInfo> res = new ArrayList<>();
IPackageManager pm = getPackageManager();
Expand Down

0 comments on commit 26da19c

Please sign in to comment.