public static boolean b(Context context) { PackageManager packageManager = context.getPackageManager(); String packageName = context.getPackageName(); if (packageManager.checkPermission("android.permission.INTERNET", packageName) == -1) { g.b("INTERNET permissions must be enabled in AndroidManifest.xml."); return false; } else if (packageManager.checkPermission( "android.permission.ACCESS_NETWORK_STATE", packageName) != -1) { return true; } else { g.b("ACCESS_NETWORK_STATE permissions must be enabled in AndroidManifest.xml."); return false; } }
/** * Retrieve all dynamic codec plugins available in the platform It will resolve for a given action * available sip plugins * * @param ctxt Context of the application * @param action Action of the plugin to be resolved * @return a map containing plugins infos and registrered component name as key */ public static Map<String, DynCodecInfos> getDynCodecPlugins(Context ctxt, String action) { if (!CACHED_RESOLUTION.containsKey(action)) { HashMap<String, DynCodecInfos> plugins = new HashMap<String, DynCodecInfos>(); PackageManager packageManager = ctxt.getPackageManager(); Intent it = new Intent(action); List<ResolveInfo> availables = packageManager.queryBroadcastReceivers(it, 0); for (ResolveInfo resInfo : availables) { ActivityInfo actInfos = resInfo.activityInfo; if (packageManager.checkPermission( SipManager.PERMISSION_CONFIGURE_SIP, actInfos.packageName) == PackageManager.PERMISSION_GRANTED) { ComponentName cmp = new ComponentName(actInfos.packageName, actInfos.name); DynCodecInfos dynInfos; try { dynInfos = new DynCodecInfos(ctxt, cmp); plugins.put(cmp.flattenToString(), dynInfos); } catch (NameNotFoundException e) { Log.e(THIS_FILE, "Error while retrieving infos from dyn codec ", e); } } } CACHED_RESOLUTION.put(action, plugins); } return CACHED_RESOLUTION.get(action); }
public static Map<String, DynActivityPlugin> getDynActivityPlugins(Context ctxt, String action) { if (!CACHED_ACTIVITY_RESOLUTION.containsKey(action)) { HashMap<String, DynActivityPlugin> plugins = new HashMap<String, DynActivityPlugin>(); PackageManager packageManager = ctxt.getPackageManager(); Intent it = new Intent(action); List<ResolveInfo> availables = packageManager.queryIntentActivities(it, 0); for (ResolveInfo resInfo : availables) { ActivityInfo actInfos = resInfo.activityInfo; if (packageManager.checkPermission(SipManager.PERMISSION_USE_SIP, actInfos.packageName) == PackageManager.PERMISSION_GRANTED) { ComponentName cmp = new ComponentName(actInfos.packageName, actInfos.name); DynActivityPlugin dynInfos; dynInfos = new DynActivityPlugin( actInfos.loadLabel(packageManager).toString(), action, cmp, actInfos.metaData); plugins.put(cmp.flattenToString(), dynInfos); } } CACHED_ACTIVITY_RESOLUTION.put(action, plugins); } return CACHED_ACTIVITY_RESOLUTION.get(action); }
/** * 获取当前网络状态 返回2代表wifi,1代表2G/3G * * @param paramContext * @return */ public static String[] getNetType(Context paramContext) { String[] arrayOfString = {"Unknown", "Unknown"}; PackageManager localPackageManager = paramContext.getPackageManager(); if (localPackageManager.checkPermission( "android.permission.ACCESS_NETWORK_STATE", paramContext.getPackageName()) != 0) { arrayOfString[0] = "Unknown"; return arrayOfString; } ConnectivityManager localConnectivityManager = (ConnectivityManager) paramContext.getSystemService("connectivity"); if (localConnectivityManager == null) { arrayOfString[0] = "Unknown"; return arrayOfString; } NetworkInfo localNetworkInfo1 = localConnectivityManager.getNetworkInfo(1); if (localNetworkInfo1 != null && localNetworkInfo1.getState() == NetworkInfo.State.CONNECTED) { arrayOfString[0] = "2"; return arrayOfString; } NetworkInfo localNetworkInfo2 = localConnectivityManager.getNetworkInfo(0); if (localNetworkInfo2 != null && localNetworkInfo2.getState() == NetworkInfo.State.CONNECTED) { arrayOfString[0] = "1"; arrayOfString[1] = localNetworkInfo2.getSubtypeName(); return arrayOfString; } return arrayOfString; }
/** App needs to give permission to AccountManager to use broker. */ private boolean verifyManifestPermissions() { PackageManager pm = mContext.getPackageManager(); boolean permission = PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.GET_ACCOUNTS", mContext.getPackageName()) && PackageManager.PERMISSION_GRANTED == pm.checkPermission( "android.permission.MANAGE_ACCOUNTS", mContext.getPackageName()) && PackageManager.PERMISSION_GRANTED == pm.checkPermission( "android.permission.USE_CREDENTIALS", mContext.getPackageName()); if (!permission) { Logger.w( TAG, "Broker related permissions are missing for GET_ACCOUNTS, MANAGE_ACCOUNTS, USE_CREDENTIALS", "", ADALError.DEVELOPER_BROKER_PERMISSIONS_MISSING); } return permission; }
private static boolean phoneHaveVibratePermission(Context context) { PackageManager packageManager = context.getPackageManager(); // check permission try { int result = packageManager.checkPermission(Manifest.permission.VIBRATE, context.getPackageName()); if (result == PackageManager.PERMISSION_GRANTED) { return true; } } catch (Exception e) { Log.e("PushWoosh", "error in checking permission", e); } return false; }
public static String[] getNetworkState(Context var0) { String[] var1 = new String[] {"Unknown", "Unknown"}; try { PackageManager var2 = var0.getPackageManager(); if (var2.checkPermission("android.permission.ACCESS_NETWORK_STATE", var0.getPackageName()) != 0) { var1[0] = "Unknown"; return var1; } ConnectivityManager var3 = (ConnectivityManager) var0.getSystemService(Context.CONNECTIVITY_SERVICE); if (var3 == null) { var1[0] = "Unknown"; return var1; } NetworkInfo var4 = var3.getNetworkInfo(1); if (var4.getState() == NetworkInfo.State.CONNECTED) { var1[0] = "Wi-Fi"; return var1; } NetworkInfo var5 = var3.getNetworkInfo(0); if (var5.getState() == NetworkInfo.State.CONNECTED) { var1[0] = "2G/3G"; var1[1] = var5.getSubtypeName(); return var1; } } catch (Exception var6) { var6.printStackTrace(); } return var1; }
public static boolean checkPermission(Context var0, String var1) { PackageManager var2 = var0.getPackageManager(); return var2.checkPermission(var1, var0.getPackageName()) == 0; }
private boolean hasCameraPermission() { PackageManager pm = getPackageManager(); int hasPerm = pm.checkPermission(Manifest.permission.CAMERA, getPackageName()); return hasPerm == PackageManager.PERMISSION_GRANTED; }
public ApplicationList(Context context) { // Get all packages PackageManager manager = context.getPackageManager(); Intent intent = new Intent(); packages = manager.getInstalledPackages(PackageManager.GET_PERMISSIONS); for (int i = 0; i < packages.size(); i++) { // actually processed package PackageInfo pack = packages.get(i); if (pack.applicationInfo.sourceDir.startsWith("/data/app/") && !(pack.applicationInfo.packageName.contains("com.google") || pack.applicationInfo.packageName.contains( "com.android"))) { // dodawaj tylko jeżeli aplikacja niesystemowa // arrays of packages permissions String[] permissions = pack.requestedPermissions; // application uID int uid = pack.applicationInfo.uid; // packages Name String appName = pack.applicationInfo.packageName; // MALWARE PERMISSIONS DETECTION if (manager.checkPermission("android.permission.SYSTEM_ALERT_WINDOW", appName) == PackageManager.PERMISSION_GRANTED) { Log.i("APPLICATION LIST", "WIRUS REGULA NR 7: " + appName); AddMalware(appName, context); } else if ((manager.checkPermission("android.permission.WRITE_SMS", appName) == PackageManager.PERMISSION_GRANTED) || (manager.checkPermission("android.permission.SEND_SMS", appName) == PackageManager.PERMISSION_GRANTED)) { Log.i("APPLICATION LIST", "WIRUS REGULA NR 3: " + appName); AddMalware(appName, context); } // total data sent by the app Long sent = TrafficStats.getUidTxBytes(uid) / 1024; // total data received by the app Long received = TrafficStats.getUidRxBytes(uid) / 1024; // apps Icon Drawable icon = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { icon = context.getDrawable(R.drawable.no_image); } try { icon = context.getPackageManager().getApplicationIcon(appName); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } // get app Broadcast Receivers ArrayList<String> broadcastReceivers = new ArrayList<String>(); intent.setPackage(appName); List<ResolveInfo> infos = manager.queryBroadcastReceivers(intent, PackageManager.GET_RESOLVED_FILTER); for (ResolveInfo info : infos) { broadcastReceivers.add(info.filter.getAction(0)); Log.i(LOG, "BR: " + info.filter.getAction(0)); if (info.filter.getAction(0).compareTo("android.app.action.DEVICE_ADMIN_ENABLED") == 0) { Log.i("APPLICATION LIST", "WIRUS REGULA NR 6: " + appName); AddMalware(appName, context); } } // usuwanie duplikatów HashSet hs = new HashSet(); hs.addAll(broadcastReceivers); broadcastReceivers.clear(); broadcastReceivers.addAll(hs); ApplicationInfo appInfo = new ApplicationInfo( uid, appName, sent, received, icon, permissions, broadcastReceivers); try { applicationInfoList.add(appInfo); } catch (NullPointerException e) { // Toast.makeText(context, "" + icon, Toast.LENGTH_SHORT).show(); } Collections.sort( applicationInfoList, new Comparator<ApplicationInfo>() { public int compare(ApplicationInfo app1, ApplicationInfo app2) { return app2.getTotalDataSent().compareTo(app1.getTotalDataSent()); } }); } } }