content: package top.niunaijun.blackbox.fake.service;
  
  import static top.niunaijun.blackbox.app.BActivityThread.getUid;
  
  import java.lang.reflect.Method;
  
  import black.android.os.BRINetworkManagementServiceStub;
  import black.android.os.BRServiceManager;
  import top.niunaijun.blackbox.fake.hook.BinderInvocationStub;
  import top.niunaijun.blackbox.fake.hook.MethodHook;
  import top.niunaijun.blackbox.fake.hook.ProxyMethod;
  import top.niunaijun.blackbox.fake.service.base.UidMethodProxy;
  import top.niunaijun.blackbox.utils.MethodParameterUtils;
  import top.niunaijun.blackbox.utils.Slog;
  
  /**
   * Enhanced Network Management Service Proxy for BlackBox
   * Created by BlackBox on 2022/3/5.
   */
  public class INetworkManagementServiceProxy extends BinderInvocationStub {
      public static final String NAME = "network_management";
  
      public INetworkManagementServiceProxy() {
          super(BRServiceManager.get().getService(NAME));
      }
  
      @Override
      protected Object getWho() {
          return BRINetworkManagementServiceStub.get().asInterface(BRServiceManager.get().getService(NAME));
      }
  
      @Override
      protected void inject(Object baseInvocation, Object proxyInvocation) {
          replaceSystemService(NAME);
      }
  
      @Override
      public boolean isBadEnv() {
          return false;
      }
  
      @Override
      protected void onBindMethod() {
          super.onBindMethod();
          addMethodHook(new UidMethodProxy("setUidCleartextNetworkPolicy", 0));
          addMethodHook(new UidMethodProxy("setUidMeteredNetworkBlacklist", 0));
          addMethodHook(new UidMethodProxy("setUidMeteredNetworkWhitelist", 0));
      }
  
      @ProxyMethod("getNetworkStatsUidDetail")
      public static class getNetworkStatsUidDetail extends MethodHook {
          @Override
          protected Object hook(Object who, Method method, Object[] args) throws Throwable {
              MethodParameterUtils.replaceFirstUid(args);
              MethodParameterUtils.replaceFirstAppPkg(args);
              return method.invoke(who, args);
          }
      }
  }
  