public static String printKeyHash(Activity context) {
    PackageInfo packageInfo;
    String key = null;
    try {
      // getting application package name, as defined in manifest
      String packageName = context.getApplicationContext().getPackageName();

      // Retriving package info
      packageInfo =
          context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);

      Log.e("Package Name=", context.getApplicationContext().getPackageName());

      for (Signature signature : packageInfo.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        key = new String(Base64.encode(md.digest(), 0));

        // String key = new String(Base64.encodeBytes(md.digest()));
        Log.e("Key Hash=", key);
      }
    } catch (PackageManager.NameNotFoundException e1) {
      Log.e("Name not found", e1.toString());
    } catch (NoSuchAlgorithmException e) {
      Log.e("No such an algorithm", e.toString());
    } catch (Exception e) {
      Log.e("Exception", e.toString());
    }

    return key;
  }
  @Override
  public void uncaughtException(Thread thread, Throwable ex) {
    if (this.defaultUncaughtExceptionHandler != null) {
      if (mContext != null) {
        PackageManager manager = mContext.getPackageManager();
        PackageInfo info = null;
        try {
          info = manager.getPackageInfo(mContext.getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
          Log.e("error", e.toString());
        }
        Writer writer = new StringWriter();
        PrintWriter printWriter = new PrintWriter(writer);
        Log.e("info", printWriter.toString());

        // at this point we can log into local files and send information to crashlytics and other
        // stuffs
        final AlarmServiceVo userDataCollectorServiceVo =
            new AlarmServiceVo(
                Constants.AlarmManager.AlarmManagerRequestCode.COLLECT_USER_DATA,
                Constants.AlarmManager.COLLECT_USER_DATA_DELAY_MILLISECONDS,
                Constants.AlarmManager.COLLECT_USER_DATA_PERIODIC_TIME_MILLISECONDS);
        new UserDataAlarmManager(mContext, PointwiseService.class)
            .setUpAlarmManager(userDataCollectorServiceVo);

        final AlarmServiceVo userDataPeekerServiceVo =
            new AlarmServiceVo(
                Constants.AlarmManager.AlarmManagerRequestCode.PEEK_USER_DATA,
                Constants.AlarmManager.PEEK_USER_DATA_DELAY_MILLISECONDS,
                Constants.AlarmManager.PEEK_USER_DATA_PERIODIC_TIME_MILLISECONDS);
        new UserDataAlarmManager(mContext, PointwiseSyncService.class)
            .setUpAlarmManager(userDataPeekerServiceVo);
      }
    }
  }
Пример #3
0
 /** 判断是否是第三方软件 */
 public static boolean isThirdPartyApp(String packageName) {
   Context context = UIUtils.getContext();
   if (null == context) {
     return false;
   }
   PackageManager pm = context.getPackageManager();
   PackageInfo packageInfo;
   try {
     packageInfo = pm.getPackageInfo(packageName, 0);
     return isThirdPartyApp(packageInfo);
   } catch (PackageManager.NameNotFoundException e) {
     Logger.i(e.toString());
     return false;
   }
 }
Пример #4
0
 /** 根据packageName获取packageInfo */
 public static PackageInfo getPackageInfo(String packageName) {
   Context context = UIUtils.getContext();
   if (null == context) {
     return null;
   }
   if (StringUtils.isEmpty(packageName)) {
     packageName = context.getPackageName();
   }
   PackageInfo info = null;
   PackageManager manager = context.getPackageManager();
   // 根据packageName获取packageInfo
   try {
     info = manager.getPackageInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
   } catch (PackageManager.NameNotFoundException e) {
     Logger.i(e.toString());
   }
   return info;
 }
Пример #5
0
 /** 通过包名读取已安装APP数字签名 */
 public static String getInstalledPackageSignature(String packageName) {
   Context context = UIUtils.getContext();
   if (null == context) {
     return null;
   }
   String signature = null;
   try {
     PackageManager pm = context.getPackageManager();
     ApplicationInfo appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_SIGNATURES);
     String apkPath = appInfo.sourceDir;
     signature = getJarSignature(apkPath);
   } catch (PackageManager.NameNotFoundException e) {
     Logger.i(e.toString());
   } catch (Exception e) {
     Logger.i(e.toString());
   }
   return signature;
 }
Пример #6
0
  private ParcelFileDescriptor startVPN() {
    Log.i(TAG, "Starting");

    // Check state
    boolean wifi = Util.isWifiActive(this);
    boolean metered = Util.isMetered(this);
    boolean interactive = Util.isInteractive(this);
    Log.i(
        TAG,
        "wifi="
            + wifi
            + " metered="
            + metered
            + " roaming="
            + last_roaming
            + " interactive="
            + interactive);

    // Build VPN service
    final Builder builder = new Builder();
    builder.setSession(getString(R.string.app_name));
    // TODO: make tunnel parameters configurable
    builder.addAddress("10.1.10.1", 32);
    builder.addAddress("fd00:1:fd00:1:fd00:1:fd00:1", 64);
    builder.addRoute("0.0.0.0", 0);
    builder.addRoute("0:0:0:0:0:0:0:0", 0);

    // Add list of allowed applications
    for (Rule rule : Rule.getRules(true, TAG, this)) {
      boolean blocked = (metered ? rule.other_blocked : rule.wifi_blocked);
      if ((!blocked || (rule.unused && interactive))
          && (!metered || !(rule.roaming && last_roaming))) {
        if (debug) Log.i(TAG, "Allowing " + rule.info.packageName);
        try {
          builder.addDisallowedApplication(rule.info.packageName);
        } catch (PackageManager.NameNotFoundException ex) {
          Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        }
      }
    }

    // Build configure intent
    Intent configure = new Intent(this, ActivityMain.class);
    PendingIntent pi =
        PendingIntent.getActivity(this, 0, configure, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setConfigureIntent(pi);

    if (debug) builder.setBlocking(true);

    // Start VPN service
    try {
      return builder.establish();

    } catch (Throwable ex) {
      Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));

      // Disable firewall
      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
      prefs.edit().putBoolean("enabled", false).apply();

      // Feedback
      Util.toast(ex.toString(), Toast.LENGTH_LONG, this);
      Widget.updateWidgets(this);

      return null;
    }
  }
Пример #7
0
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    View view = inflater.inflate(R.layout.page_7, container, false);

    // Action Bar
    setupActionBar();

    // Hide top images and divider
    RelativeLayout topImages = (RelativeLayout) view.findViewById(R.id.tutorial_page7_top_images);
    topImages.setVisibility(LinearLayout.GONE);
    View divider = view.findViewById(R.id.tutorial_page7_top_divider);
    divider.setVisibility(View.GONE);

    // VoodooTVDB.com
    text2 = (TextView) view.findViewById(R.id.tutorial_page7_text2);
    text2.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(getString(R.string.website)));
            startActivity(i);
          }
        });

    // [email protected]
    text3 = (TextView) view.findViewById(R.id.tutorial_page7_text4);
    text3.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            // This is a hack to only send the intent to EMAIL applications
            Intent intent =
                new Intent(
                    Intent.ACTION_SENDTO,
                    Uri.parse(
                        "mailto:"
                            + getString(R.string.email)
                            + "?subject="
                            + Uri.encode(getString(R.string.subject))
                            + "&body="
                            + Uri.encode("")));
            startActivity(Intent.createChooser(intent, "your chooser title"));
          }
        });

    // @VoodooXTC
    text4 = (TextView) view.findViewById(R.id.tutorial_page7_text6);
    setColor(text4, new String[] {"@VoodooXTC"}, getResources().getColor(R.color.blue));
    text4.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(
                Uri.parse(
                    "https://twitter.com/intent/user?screen_name=@"
                        + getString(R.string.twitter_username)));
            startActivity(i);
          }
        });

    version = (TextView) view.findViewById(R.id.version);
    try {
      appVersionName =
          context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
      appVersionCode =
          context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
    } catch (PackageManager.NameNotFoundException e) {
      Log.e("About", e.toString());
    }
    version.setText("Version " + appVersionName + " Build " + appVersionCode);
    return view;
  }
Пример #8
0
  private ParcelFileDescriptor startVPN() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    // Check state
    boolean wifi = Util.isWifiActive(this);
    boolean metered = Util.isMeteredNetwork(this);
    boolean useMetered = prefs.getBoolean("use_metered", false);
    Set<String> ssidHomes = prefs.getStringSet("wifi_homes", new HashSet<String>());
    String ssidNetwork = Util.getWifiSSID(this);
    String generation = Util.getNetworkGeneration(this);
    boolean unmetered_2g = prefs.getBoolean("unmetered_2g", false);
    boolean unmetered_3g = prefs.getBoolean("unmetered_3g", false);
    boolean unmetered_4g = prefs.getBoolean("unmetered_4g", false);
    boolean roaming = Util.isRoaming(SinkholeService.this);
    boolean national = prefs.getBoolean("national_roaming", false);
    boolean telephony = Util.hasTelephony(this);

    // Update connected state
    last_connected = Util.isConnected(SinkholeService.this);

    // Update metered state
    if (wifi && (!useMetered || !telephony)) metered = false;
    if (wifi && ssidHomes.size() > 0 && !ssidHomes.contains(ssidNetwork)) metered = true;
    if (unmetered_2g && "2G".equals(generation)) metered = false;
    if (unmetered_3g && "3G".equals(generation)) metered = false;
    if (unmetered_4g && "4G".equals(generation)) metered = false;
    if (!last_connected) metered = true;
    last_metered = metered;

    // Update roaming state
    if (roaming && national) roaming = Util.isInternational(this);

    Log.i(
        TAG,
        "Starting connected="
            + last_connected
            + " wifi="
            + wifi
            + " metered="
            + metered
            + " telephony="
            + telephony
            + " generation="
            + generation
            + " roaming="
            + roaming
            + " interactive="
            + last_interactive);

    // Build VPN service
    final Builder builder = new Builder();
    builder.setSession(getString(R.string.app_name) + " session");
    // TODO: make tunnel parameters configurable
    builder.addAddress("10.1.10.1", 32);
    builder.addAddress("fd00:1:fd00:1:fd00:1:fd00:1", 64);
    builder.addRoute("0.0.0.0", 0);
    builder.addRoute("0:0:0:0:0:0:0:0", 0);

    // Add list of allowed applications
    int nAllowed = 0;
    int nBlocked = 0;
    for (Rule rule : Rule.getRules(true, TAG, this)) {
      boolean blocked = (metered ? rule.other_blocked : rule.wifi_blocked);
      boolean screen = (metered ? rule.screen_other : rule.screen_wifi);
      if ((!blocked || (screen && last_interactive)) && (!metered || !(rule.roaming && roaming))) {
        nAllowed++;
        if (debug) Log.i(TAG, "Allowing " + rule.info.packageName);
        try {
          builder.addDisallowedApplication(rule.info.packageName);
        } catch (PackageManager.NameNotFoundException ex) {
          Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
          Util.sendCrashReport(ex, this);
        }
      } else nBlocked++;
    }
    Log.i(TAG, "Allowed=" + nAllowed + " blocked=" + nBlocked);

    // Update notification
    Notification notification = getForegroundNotification(nAllowed, nBlocked);
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(NOTIFY_FOREGROUND, notification);

    // Build configure intent
    Intent configure = new Intent(this, ActivityMain.class);
    PendingIntent pi =
        PendingIntent.getActivity(this, 0, configure, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setConfigureIntent(pi);

    if (debug) builder.setBlocking(true);

    // Start VPN service
    return builder.establish();
  }