List of usage examples for android.content.pm PackageManager getNameForUid
public abstract @Nullable String getNameForUid(int uid);
From source file:Main.java
public static String getUidName(Context c, int uid, boolean withUid) { PackageManager pm = c.getPackageManager(); String uidName = ""; if (uid == 0) { uidName = "root"; } else {// w w w .j a va 2 s. co m pm.getNameForUid(uid); } if (withUid) { uidName += " (" + uid + ")"; } return uidName; }
From source file:org.qeo.android.service.ApplicationSecurityStandalone.java
/** * Initialize a new instance.//from w w w .j a va2 s .co m * * @param service Reference to the Qeo service * @param uid the uid belonging to this content * @param pid the pid belonging to this content */ ApplicationSecurityStandalone(QeoService service, int uid, int pid) { LOG.fine("Create new application security for uid: " + uid + ", pid: " + pid); mService = service; mUid = uid; mPid = pid; mRegisteredReadersWriters = new HashSet<Long>(); try { PackageManager pm = mService.getPackageManager(); // Packages with sharedUserId set in manifest will have their uid concatenated in getNameForUid call // What will happen if multiple packages with same sharedUserId make user of Qeo?? mPkgName = pm.getNameForUid(mUid).split(":")[0]; if (mPkgName.equals("org.qeo.android.service")) { // special case, will only be triggered by unit tests mAppVersion = 1; mAppLabel = "junit"; } else { mAppVersion = pm.getPackageInfo(mPkgName, 0).versionCode; ApplicationInfo appInfo = pm.getPackageInfo(mPkgName, 0).applicationInfo; if (appInfo == null) { throw new SecurityException("Can't get application name for uid " + uid); } mAppLabel = appInfo.loadLabel(pm).toString(); if (mAppLabel.isEmpty()) { throw new SecurityException("Can't get application name for uid " + uid); } } LOG.fine("Application security created: " + mPkgName + " -- " + mAppVersion + " -- " + mAppLabel); } catch (NameNotFoundException e) { throw new SecurityException("Can't get application version for uid " + uid, e); } mManifestDialogCallback = null; }
From source file:org.qeo.android.service.ApplicationSecurity.java
/** * Initialize a new instance.//from w w w. j a v a 2s .co m * * @param service Reference to the Qeo service * @param uid the uid belonging to this content * @param pid the pid belonging to this content */ public ApplicationSecurity(QeoService service, int uid, int pid) { LOG.fine("Create new application security for uid: " + uid + ", pid: " + pid); mService = service; mUid = uid; mPid = pid; mRegisteredReadersWriters = new HashSet<Long>(); try { PackageManager pm = mService.getPackageManager(); // Packages with sharedUserId set in manifest will have their uid concatenated in getNameForUid call // What will happen if multiple packages with same sharedUserId make user of Qeo?? mPkgName = pm.getNameForUid(mUid).split(":")[0]; if (mPkgName.equals("org.qeo.android.service")) { // special case, will only be triggered by unit tests mAppVersion = 1; mAppLabel = "junit"; } else { mAppVersion = pm.getPackageInfo(mPkgName, 0).versionCode; ApplicationInfo appInfo = pm.getPackageInfo(mPkgName, 0).applicationInfo; if (appInfo == null) { throw new SecurityException("Can't get application name for uid " + uid); } mAppLabel = appInfo.loadLabel(pm).toString(); if (mAppLabel == null || mAppLabel.isEmpty()) { throw new SecurityException("Can't get application name for uid " + uid); } } LOG.fine("Application security created: " + mPkgName + " -- " + mAppVersion + " -- " + mAppLabel); } catch (NameNotFoundException e) { throw new SecurityException("Can't get application version for uid " + uid, e); } mManifestDialogCallback = null; }
From source file:com.inmobi.rendering.RenderView.java
public boolean m1976g(String str) { boolean z = true; PackageManager packageManager = this.f1770d.getPackageManager(); boolean z2 = true; switch (str.hashCode()) { case -1886160473: if (str.equals("playVideo")) { z2 = true;/* ww w.j a va 2 s.c o m*/ break; } break; case -1647691422: if (str.equals("inlineVideo")) { z2 = true; break; } break; case -587360353: if (str.equals("getGalleryImage")) { z2 = true; break; } break; case -178324674: if (str.equals("calendar")) { z2 = true; break; } break; case 114009: if (str.equals("sms")) { z2 = true; break; } break; case 114715: if (str.equals("tel")) { z2 = false; break; } break; case 451310959: if (str.equals("vibrate")) { z2 = true; break; } break; case 459238621: if (str.equals("storePicture")) { z2 = true; break; } break; case 1247233375: if (str.equals("sendMail")) { z2 = true; break; } break; case 1370921258: if (str.equals("microphone")) { z2 = true; break; } break; case 1509574865: if (str.equals("html5video")) { z2 = true; break; } break; case 1642189884: if (str.equals("saveContent")) { z2 = true; break; } break; case 1895570642: if (str.equals("takeCameraPicture")) { z2 = true; break; } break; case 1921345160: if (str.equals("postToSocial")) { z2 = true; break; } break; } Intent intent; ResolveInfo resolveActivity; switch (z2) { case DurationDV.DURATION_TYPE /*0*/: intent = new Intent("android.intent.action.DIAL"); intent.setData(Uri.parse("tel:123456789")); if (this.f1770d.getPackageManager().resolveActivity(intent, AccessibilityNodeInfoCompat.ACTION_CUT) == null) { return false; } return true; case MainNavigationActivity.REQUEST_CODE /*1*/: case DurationDV.DAYTIMEDURATION_TYPE /*2*/: return true; case ConnectionResult.SERVICE_DISABLED /*3*/: z2 = packageManager.hasSystemFeature("android.hardware.microphone") && packageManager.checkPermission("android.permission.RECORD_AUDIO", packageManager.getNameForUid(Binder.getCallingUid())) == 0; return z2; case ConnectionResult.SIGN_IN_REQUIRED /*4*/: case MetaData.DEFAULT_SMART_REDIRECT_TIMEOUT /*5*/: if (VERSION.SDK_INT >= 11 && !(this.f1786t && m1988p())) { z = false; } Logger.m1744a(InternalLogLevel.INTERNAL, f1748a, "HTML5 video supported:" + z); return z; case ConnectionResult.RESOLUTION_REQUIRED /*6*/: if (this.f1770d.getPackageManager().resolveActivity( new Intent("android.intent.action.SENDTO", Uri.parse("smsto:123456789")), AccessibilityNodeInfoCompat.ACTION_CUT) == null) { return false; } return true; case ConnectionResult.NETWORK_ERROR /*7*/: if (VERSION.SDK_INT >= 19 || packageManager.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", packageManager.getNameForUid(Binder.getCallingUid())) == 0) { return true; } return false; case ConnectionResult.INTERNAL_ERROR /*8*/: intent = new Intent("android.intent.action.SEND"); intent.setType("plain/text"); if (this.f1770d.getPackageManager().resolveActivity(intent, AccessibilityNodeInfoCompat.ACTION_CUT) == null) { return false; } return true; case ConnectionResult.SERVICE_INVALID /*9*/: intent = new Intent("android.intent.action.VIEW"); intent.setType("vnd.android.cursor.item/event"); ResolveInfo resolveActivity2 = this.f1770d.getPackageManager().resolveActivity(intent, AccessibilityNodeInfoCompat.ACTION_CUT); z2 = packageManager.checkPermission("android.permission.WRITE_CALENDAR", packageManager.getNameForUid(Binder.getCallingUid())) == 0; boolean z3; if (packageManager.checkPermission("android.permission.READ_CALENDAR", packageManager.getNameForUid(Binder.getCallingUid())) == 0) { z3 = true; } else { z3 = false; } if (resolveActivity2 != null && z2 && r3) { return true; } return false; case MetaData.DEFAULT_MAX_ADS /*10*/: resolveActivity = this.f1770d.getPackageManager().resolveActivity( new Intent("android.media.action.IMAGE_CAPTURE"), AccessibilityNodeInfoCompat.ACTION_CUT); z2 = packageManager.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", packageManager.getNameForUid(Binder.getCallingUid())) == 0; if (resolveActivity == null || !z2) { return false; } return true; case ConnectionResult.LICENSE_CHECK_FAILED /*11*/: resolveActivity = this.f1770d.getPackageManager().resolveActivity( new Intent("android.intent.action.PICK", Media.EXTERNAL_CONTENT_URI), AccessibilityNodeInfoCompat.ACTION_CUT); z2 = packageManager.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", packageManager.getNameForUid(Binder.getCallingUid())) == 0; if (resolveActivity == null || !z2) { return false; } return true; case Tokens.EXPRTOKEN_NODETYPE_COMMENT /*12*/: if (VERSION.SDK_INT < 9 || packageManager.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", packageManager.getNameForUid(Binder.getCallingUid())) != 0) { return false; } return true; case ConnectionResult.CANCELED /*13*/: Vibrator vibrator = (Vibrator) this.f1770d.getSystemService("vibrator"); if (!(packageManager.checkPermission("android.permission.VIBRATE", packageManager.getNameForUid(Binder.getCallingUid())) == 0) || vibrator == null || VERSION.SDK_INT < 11 || !m1912a(vibrator)) { return false; } return true; default: return false; } }