private void toggleCamera(boolean isNeedEnableCam) {

    // TODO temporary insertion will be removed when GLVideoView will be fixed
    DisplayMetrics displaymetrics = new DisplayMetrics();
    displaymetrics.setToDefaults();

    ViewGroup.LayoutParams layoutParams = imgMyCameraOff.getLayoutParams();

    layoutParams.height = localVideoView.getHeight();
    layoutParams.width = localVideoView.getWidth();

    imgMyCameraOff.setLayoutParams(layoutParams);

    Log.d(
        TAG,
        "Width is: "
            + imgMyCameraOff.getLayoutParams().width
            + " height is:"
            + imgMyCameraOff.getLayoutParams().height);

    if (SessionManager.getCurrentSession() != null) {
      SessionManager.getCurrentSession().setVideoEnabled(isNeedEnableCam);
      cameraToggle.setChecked(isNeedEnableCam);

      if (isNeedEnableCam) {
        Log.d(TAG, "Camera is on");
        switchCameraToggle.setVisibility(View.VISIBLE);
        imgMyCameraOff.setVisibility(View.INVISIBLE);
      } else {
        Log.d(TAG, "Camera is off");
        switchCameraToggle.setVisibility(View.INVISIBLE);
        imgMyCameraOff.setVisibility(View.VISIBLE);
      }
    }
  }
Example #2
0
  /**
   * 获取一个apk文件的签名,思路是更具PackageParser对象反射而来
   *
   * @param path apk文件的路径
   * @return
   */
  public static String getApkSign(String path) {
    String packageParserStr = "android.content.pm.PackageParser";
    // 方法的参数类型
    Class<?>[] typeArgs = new Class[1];

    // 方法需要传入的参数值
    Object[] valueArgs = new Object[1];

    try {
      // 实例化PackageParser对象
      Class<?> pkgParserCls = Class.forName(packageParserStr);
      typeArgs[0] = String.class;
      Constructor<?> pkgParserCt = pkgParserCls.getConstructor(typeArgs);
      valueArgs[0] = path;
      Object pkgParser = pkgParserCt.newInstance(valueArgs);

      // 执行parsePackage方法
      typeArgs = new Class[4];
      typeArgs[0] = File.class;
      typeArgs[1] = String.class;
      typeArgs[2] = DisplayMetrics.class;
      typeArgs[3] = int.class;
      Method parsePackageMtd = pkgParserCls.getDeclaredMethod("parsePackage", typeArgs);

      valueArgs = new Object[4];
      valueArgs[0] = new File(path);
      valueArgs[1] = path;
      DisplayMetrics metrics = new DisplayMetrics();
      metrics.setToDefaults();
      valueArgs[2] = metrics;
      valueArgs[3] = PackageManager.GET_SIGNATURES;

      // 得到PackageParser.Package对象
      Object pkgParserPkg = parsePackageMtd.invoke(pkgParser, valueArgs);

      // 执行collectCertificates方法
      typeArgs = new Class[2];
      typeArgs[0] = pkgParserPkg.getClass();
      typeArgs[1] = int.class;
      Method collectCertificatedsMtd = pkgParserCls.getMethod("collectCertificates", typeArgs);

      valueArgs = new Object[2];
      valueArgs[0] = pkgParserPkg;
      valueArgs[1] = PackageManager.GET_SIGNATURES;
      collectCertificatedsMtd.invoke(pkgParser, valueArgs);

      // 获取mSignature的属性值
      Field mSignatures = pkgParserPkg.getClass().getDeclaredField("mSignatures");
      Signature[] signatures = (Signature[]) mSignatures.get(pkgParserPkg);

      return signatures[0].toCharsString();

    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
Example #3
0
  public static PackageParser.Package getPackageInfoFromPackage(
      String filePath, boolean collectSignature) {
    PackageParser packageParser = new PackageParser(filePath);
    File sourceFile = new File(filePath);
    DisplayMetrics metrics = new DisplayMetrics();
    metrics.setToDefaults();
    PackageParser.Package pkg = packageParser.parsePackage(sourceFile, filePath, metrics, 0);
    if (pkg != null && collectSignature) {
      packageParser.collectCertificates(pkg, 0);
    }

    return pkg;
  }
 public static Drawable geTApkIcon(Context context, String Path) {
   // 未安装的程序通过apk文件获取icon
   String apkPath = Path; // apk 文件所在的路径
   String PATH_PackageParser = "android.content.pm.PackageParser";
   String PATH_AssetManager = "android.content.res.AssetManager";
   try {
     Class<?> pkgParserCls = Class.forName(PATH_PackageParser);
     Class<?>[] typeArgs = {String.class};
     Constructor<?> pkgParserCt = pkgParserCls.getConstructor(typeArgs);
     Object[] valueArgs = {apkPath};
     Object pkgParser = pkgParserCt.newInstance(valueArgs);
     DisplayMetrics metrics = new DisplayMetrics();
     metrics.setToDefaults();
     typeArgs = new Class<?>[] {File.class, String.class, DisplayMetrics.class, int.class};
     Method pkgParser_parsePackageMtd = pkgParserCls.getDeclaredMethod("parsePackage", typeArgs);
     valueArgs = new Object[] {new File(apkPath), apkPath, metrics, 0};
     Object pkgParserPkg = pkgParser_parsePackageMtd.invoke(pkgParser, valueArgs);
     Field appInfoFld = pkgParserPkg.getClass().getDeclaredField("applicationInfo");
     ApplicationInfo info = (ApplicationInfo) appInfoFld.get(pkgParserPkg);
     Class<?> assetMagCls = Class.forName(PATH_AssetManager);
     Object assetMag = assetMagCls.newInstance();
     typeArgs = new Class[1];
     typeArgs[0] = String.class;
     Method assetMag_addAssetPathMtd = assetMagCls.getDeclaredMethod("addAssetPath", typeArgs);
     valueArgs = new Object[1];
     valueArgs[0] = apkPath;
     assetMag_addAssetPathMtd.invoke(assetMag, valueArgs);
     Resources res = context.getResources();
     typeArgs = new Class[3];
     typeArgs[0] = assetMag.getClass();
     typeArgs[1] = res.getDisplayMetrics().getClass();
     typeArgs[2] = res.getConfiguration().getClass();
     Constructor<Resources> resCt = Resources.class.getConstructor(typeArgs);
     valueArgs = new Object[3];
     valueArgs[0] = assetMag;
     valueArgs[1] = res.getDisplayMetrics();
     valueArgs[2] = res.getConfiguration();
     res = (Resources) resCt.newInstance(valueArgs);
     if (info != null) {
       if (info.icon != 0) {
         Drawable icon = res.getDrawable(info.icon);
         return icon;
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Example #5
0
  public static Drawable getIconFromPackage(Context context, String archiveFilePath) {
    PackageParser packageParser = new PackageParser(archiveFilePath);
    File sourceFile = new File(archiveFilePath);
    DisplayMetrics metrics = new DisplayMetrics();
    metrics.setToDefaults();
    PackageParser.Package pkg = packageParser.parsePackage(sourceFile, archiveFilePath, metrics, 0);
    if (pkg == null) {
      return context.getResources().getDrawable(R.drawable.android);
    }
    ApplicationInfo info = pkg.applicationInfo;

    Resources pRes = context.getResources();
    AssetManager assmgr = new AssetManager();
    assmgr.addAssetPath(archiveFilePath);
    Resources res = new Resources(assmgr, pRes.getDisplayMetrics(), pRes.getConfiguration());

    if (info.icon != 0) {
      Drawable icon = res.getDrawable(info.icon);
      return icon;
    } else {
      return context.getResources().getDrawable(R.drawable.android);
    }
  }
Example #6
0
  /**
   * 判断一个文件存在且apk完整有效
   *
   * @return true 完整有效
   */
  public static boolean isEffectiveApk(String archiveFilePath, Context activity) {
    try {
      String PATH_PackageParser = "android.content.pm.PackageParser";
      Class pkgParserCls = Class.forName(PATH_PackageParser);
      Class[] typeArgs = new Class[1];
      typeArgs[0] = String.class;
      Constructor pkgParserCt = pkgParserCls.getConstructor(typeArgs);
      Object[] valueArgs = new Object[1];
      valueArgs[0] = archiveFilePath;
      Object pkgParser = pkgParserCt.newInstance(valueArgs);
      DisplayMetrics metrics = new DisplayMetrics();
      metrics.setToDefaults();

      final File sourceFile = new File(archiveFilePath);
      typeArgs = new Class[4];
      typeArgs[0] = File.class;
      typeArgs[1] = String.class;
      typeArgs[2] = DisplayMetrics.class;
      typeArgs[3] = Integer.TYPE;
      // PackageParser.parsePackage();
      Method pkgParser_parsePackageMtd = pkgParserCls.getDeclaredMethod("parsePackage", typeArgs);
      valueArgs = new Object[4];
      valueArgs[0] = sourceFile;
      valueArgs[1] = archiveFilePath;
      valueArgs[2] = metrics;
      valueArgs[3] = 0;
      // PackageParser.Package
      Object pkgParserPkg = pkgParser_parsePackageMtd.invoke(pkgParser, valueArgs);
      if (pkgParserPkg == null) {
        return false;
      } else {
        return true;
      }
    } catch (Exception e) {
      return false;
    }
  }