private boolean wouldLaunchResolverActivity(Intent intent) {
   PackageManager packageManager = getContext().getPackageManager();
   ResolveInfo resolved =
       packageManager.resolveActivityAsUser(
           intent, PackageManager.MATCH_DEFAULT_ONLY, getLockPatternUtils().getCurrentUser());
   List<ResolveInfo> appList =
       packageManager.queryIntentActivitiesAsUser(
           intent, PackageManager.MATCH_DEFAULT_ONLY, getLockPatternUtils().getCurrentUser());
   return wouldLaunchResolverActivity(resolved, appList);
 }
 public CameraWidgetInfo getCameraWidgetInfo() {
   CameraWidgetInfo info = new CameraWidgetInfo();
   Intent intent = getCameraIntent();
   PackageManager packageManager = getContext().getPackageManager();
   final List<ResolveInfo> appList =
       packageManager.queryIntentActivitiesAsUser(
           intent, PackageManager.MATCH_DEFAULT_ONLY, getLockPatternUtils().getCurrentUser());
   if (appList.size() == 0) {
     if (DEBUG) Log.d(TAG, "getCameraWidgetInfo(): Nothing found");
     return null;
   }
   ResolveInfo resolved =
       packageManager.resolveActivityAsUser(
           intent,
           PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
           getLockPatternUtils().getCurrentUser());
   if (DEBUG) Log.d(TAG, "getCameraWidgetInfo(): resolved: " + resolved);
   if (wouldLaunchResolverActivity(resolved, appList)) {
     if (DEBUG) Log.d(TAG, "getCameraWidgetInfo(): Would launch resolver");
     return info;
   }
   if (resolved == null || resolved.activityInfo == null) {
     return null;
   }
   if (resolved.activityInfo.metaData == null || resolved.activityInfo.metaData.isEmpty()) {
     if (DEBUG) Log.d(TAG, "getCameraWidgetInfo(): no metadata found");
     return info;
   }
   int layoutId = resolved.activityInfo.metaData.getInt(META_DATA_KEYGUARD_LAYOUT);
   if (layoutId == 0) {
     if (DEBUG) Log.d(TAG, "getCameraWidgetInfo(): no layout specified");
     return info;
   }
   info.contextPackage = resolved.activityInfo.packageName;
   info.layoutId = layoutId;
   return info;
 }
Пример #3
0
 private static String resolveCurrentLauncherPackage(Context context, int userId) {
   final Intent launcherIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME);
   final PackageManager pm = context.getPackageManager();
   final ResolveInfo launcherInfo = pm.resolveActivityAsUser(launcherIntent, 0, userId);
   return launcherInfo.activityInfo.packageName;
 }