Example #1
1
 @Override
 public int compare(Intent i1, Intent i2) {
   if (i1 == null && i2 == null) return 0;
   if (i1 == null && i2 != null) return -1;
   if (i1 != null && i2 == null) return 1;
   if (i1.equals(i2)) return 0;
   String action1 = i1.getAction();
   String action2 = i2.getAction();
   if (action1 == null && action2 != null) return -1;
   if (action1 != null && action2 == null) return 1;
   if (action1 != null && action2 != null) {
     if (!action1.equals(action2)) {
       return action1.compareTo(action2);
     }
   }
   Uri data1 = i1.getData();
   Uri data2 = i2.getData();
   if (data1 == null && data2 != null) return -1;
   if (data1 != null && data2 == null) return 1;
   if (data1 != null && data2 != null) {
     if (!data1.equals(data2)) {
       return data1.compareTo(data2);
     }
   }
   ComponentName component1 = i1.getComponent();
   ComponentName component2 = i2.getComponent();
   if (component1 == null && component2 != null) return -1;
   if (component1 != null && component2 == null) return 1;
   if (component1 != null && component2 != null) {
     if (!component1.equals(component2)) {
       return component1.compareTo(component2);
     }
   }
   String package1 = i1.getPackage();
   String package2 = i2.getPackage();
   if (package1 == null && package2 != null) return -1;
   if (package1 != null && package2 == null) return 1;
   if (package1 != null && package2 != null) {
     if (!package1.equals(package2)) {
       return package1.compareTo(package2);
     }
   }
   Set<String> categories1 = i1.getCategories();
   Set<String> categories2 = i2.getCategories();
   if (categories1 == null) return categories2 == null ? 0 : -1;
   if (categories2 == null) return 1;
   if (categories1.size() > categories2.size()) return 1;
   if (categories1.size() < categories2.size()) return -1;
   String[] array1 = categories1.toArray(new String[0]);
   String[] array2 = categories2.toArray(new String[0]);
   Arrays.sort(array1);
   Arrays.sort(array2);
   for (int i = 0; i < array1.length; ++i) {
     int val = array1[i].compareTo(array2[i]);
     if (val != 0) return val;
   }
   return 0;
 }
  private boolean applicationIsRunning(Context context) {
    ActivityManager activityManager =
        (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
      List<RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
      for (ActivityManager.RunningAppProcessInfo processInfo : processInfos) {
        if (processInfo.processName.equals(context.getApplicationContext().getPackageName())) {
          if (processInfo.importance
              == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
            for (String d : processInfo.pkgList) {
              Log.v("ReactSystemNotification", "NotificationEventReceiver: ok: " + d);
              return true;
            }
          }
        }
      }
    } else {
      List<ActivityManager.RunningTaskInfo> taskInfo = activityManager.getRunningTasks(1);
      ComponentName componentInfo = taskInfo.get(0).topActivity;
      if (componentInfo.getPackageName().equals(context.getPackageName())) {
        return true;
      }
    }

    return false;
  }
  private static void logIntent(int intentType, Intent intent, int callerUid, String resolvedType) {
    // The component shouldn't be null, but let's double check just to be safe
    ComponentName cn = intent.getComponent();
    String shortComponent = null;
    if (cn != null) {
      shortComponent = cn.flattenToShortString();
    }

    String callerPackages = null;
    int callerPackageCount = 0;
    IPackageManager pm = AppGlobals.getPackageManager();
    if (pm != null) {
      try {
        String[] callerPackagesArray = pm.getPackagesForUid(callerUid);
        if (callerPackagesArray != null) {
          callerPackageCount = callerPackagesArray.length;
          callerPackages = joinPackages(callerPackagesArray);
        }
      } catch (RemoteException ex) {
        Slog.e(TAG, "Remote exception while retrieving packages", ex);
      }
    }

    EventLogTags.writeIfwIntentMatched(
        intentType,
        shortComponent,
        callerUid,
        callerPackageCount,
        callerPackages,
        intent.getAction(),
        resolvedType,
        intent.getDataString(),
        intent.getFlags());
  }
  @Override
  public ActivityInfo getActivityInfo(ComponentName className, int flags)
      throws NameNotFoundException {
    String packageName = className.getPackageName();
    AndroidManifest androidManifest = androidManifests.get(packageName);
    String activityName = className.getClassName();
    ActivityData activityData = androidManifest.getActivityData(activityName);
    ActivityInfo activityInfo = new ActivityInfo();
    activityInfo.packageName = packageName;
    activityInfo.name = activityName;
    if (activityData != null) {
      activityInfo.parentActivityName = activityData.getParentActivityName();
      activityInfo.metaData = metaDataToBundle(activityData.getMetaData().getValueMap());
      ResourceIndex resourceIndex = shadowsAdapter.getResourceLoader().getResourceIndex();
      String themeRef;

      // Based on ShadowActivity
      if (activityData.getThemeRef() != null) {
        themeRef = activityData.getThemeRef();
      } else {
        themeRef = androidManifest.getThemeRef();
      }
      if (themeRef != null) {
        ResName style = ResName.qualifyResName(themeRef.replace("@", ""), packageName, "style");
        activityInfo.theme = resourceIndex.getResourceId(style);
      }
    }
    activityInfo.applicationInfo = getApplicationInfo(packageName, flags);
    return activityInfo;
  }
 public void replaceDrawable(
     ImageView v, ComponentName component, String name, boolean isService) {
   if (component != null) {
     try {
       PackageManager packageManager = mContext.getPackageManager();
       // Look for the search icon specified in the activity meta-data
       Bundle metaData =
           isService
               ? packageManager.getServiceInfo(component, PackageManager.GET_META_DATA).metaData
               : packageManager.getActivityInfo(component, PackageManager.GET_META_DATA).metaData;
       if (metaData != null) {
         int iconResId = metaData.getInt(name);
         if (iconResId != 0) {
           Resources res = packageManager.getResourcesForApplication(component.getPackageName());
           v.setImageDrawable(res.getDrawable(iconResId));
           return;
         }
       }
     } catch (PackageManager.NameNotFoundException e) {
       Log.w(
           TAG, "Failed to swap drawable; " + component.flattenToShortString() + " not found", e);
     } catch (Resources.NotFoundException nfe) {
       Log.w(TAG, "Failed to swap drawable from " + component.flattenToShortString(), nfe);
     }
   }
   v.setImageDrawable(null);
 }
Example #6
0
  /**
   * Searches the given package for a resource to use to replace the Drawable on the target with the
   * given resource id
   *
   * @param component of the .apk that contains the resource
   * @param name of the metadata in the .apk
   * @param existingResId the resource id of the target to search for
   * @return true if found in the given package and replaced at least one target Drawables
   */
  public boolean replaceTargetDrawablesIfPresent(
      ComponentName component, String name, int existingResId) {
    if (existingResId == 0) return false;

    boolean replaced = false;
    if (component != null) {
      try {
        PackageManager packageManager = getContext().getPackageManager();
        // Look for the search icon specified in the activity meta-data
        Bundle metaData =
            packageManager.getActivityInfo(component, PackageManager.GET_META_DATA).metaData;
        if (metaData != null) {
          int iconResId = metaData.getInt(name);
          if (iconResId != 0) {
            Resources res = packageManager.getResourcesForActivity(component);
            replaced = replaceTargetDrawables(res, existingResId, iconResId);
          }
        }
      } catch (NameNotFoundException e) {
        Log.w(
            TAG, "Failed to swap drawable; " + component.flattenToShortString() + " not found", e);
      } catch (Resources.NotFoundException nfe) {
        Log.w(TAG, "Failed to swap drawable from " + component.flattenToShortString(), nfe);
      }
    }
    if (!replaced) {
      // Restore the original drawable
      replaceTargetDrawables(getContext().getResources(), existingResId, existingResId);
    }
    return replaced;
  }
Example #7
0
  /**
   * 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);
  }
Example #8
0
        public void run() {

          Logger.getLogger().d("block service is running...");

          mBlockList = BlockUtils.getBlockList(getApplicationContext());

          String packageName;

          if (Build.VERSION.SDK_INT >= 21) {
            List<ActivityManager.AppTask> appTasks = getAppTasks();
            ActivityManager.AppTask appTask = appTasks.get(0);

            packageName = appTask.getTaskInfo().baseIntent.getComponent().getPackageName();
          } else {

            ComponentName topActivity = mActivityManager.getRunningTasks(1).get(0).topActivity;
            packageName = topActivity.getPackageName();
          }

          if (mBlockList != null && mBlockList.contains(packageName)) {
            Intent intent = new Intent(getApplicationContext(), WarningActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
          }

          mHandler.postDelayed(mRunnable, delayMillis);
        }
Example #9
0
  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);
  }
  // ensure that this accessibility service is enabled.
  // the service watches for google voice notifications to know when to check for new
  // messages.
  private void ensureEnabled() {
    Set<ComponentName> enabledServices = getEnabledServicesFromSettings();
    ComponentName me = new ComponentName(this, getClass());
    if (enabledServices.contains(me) && connected) return;

    enabledServices.add(me);

    // Update the enabled services setting.
    StringBuilder enabledServicesBuilder = new StringBuilder();
    // Keep the enabled services even if they are not installed since we
    // have no way to know whether the application restore process has
    // completed. In general the system should be responsible for the
    // clean up not settings.
    for (ComponentName enabledService : enabledServices) {
      enabledServicesBuilder.append(enabledService.flattenToString());
      enabledServicesBuilder.append(ENABLED_ACCESSIBILITY_SERVICES_SEPARATOR);
    }
    final int enabledServicesBuilderLength = enabledServicesBuilder.length();
    if (enabledServicesBuilderLength > 0) {
      enabledServicesBuilder.deleteCharAt(enabledServicesBuilderLength - 1);
    }
    Settings.Secure.putString(
        getContentResolver(),
        Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
        enabledServicesBuilder.toString());

    // Update accessibility enabled.
    Settings.Secure.putInt(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0);
    Settings.Secure.putInt(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 1);
  }
Example #11
0
  @Override
  public ActivityInfo getReceiverInfo(ComponentName className, int flags)
      throws NameNotFoundException {
    String packageName = className.getPackageName();
    AndroidManifest androidManifest = androidManifests.get(packageName);
    String classString = className.getClassName();
    int index = classString.indexOf('.');
    if (index == -1) {
      classString = packageName + "." + classString;
    } else if (index == 0) {
      classString = packageName + classString;
    }

    ActivityInfo activityInfo = new ActivityInfo();
    activityInfo.packageName = packageName;
    activityInfo.name = classString;
    if ((flags & GET_META_DATA) != 0) {
      for (BroadcastReceiverData receiver : androidManifest.getBroadcastReceivers()) {
        if (receiver.getClassName().equals(classString)) {
          activityInfo.metaData = metaDataToBundle(receiver.getMetaData().getValueMap());
          break;
        }
      }
    }
    return activityInfo;
  }
Example #12
0
 private ComponentName getSearchWidgetProvider() {
   SearchManager searchManager =
       (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
   ComponentName searchComponent = searchManager.getGlobalSearchActivity();
   if (searchComponent == null) return null;
   return getProviderInPackage(searchComponent.getPackageName());
 }
  @Override
  public void onReceive(Context context, Intent intent) {
    ExtensionManager extensionManager = ExtensionManager.getInstance(context);
    if (extensionManager.cleanupExtensions()) {
      LOGD(TAG, "Extension cleanup performed and action taken.");

      Intent widgetUpdateIntent = new Intent(context, DashClockService.class);
      widgetUpdateIntent.setAction(DashClockService.ACTION_UPDATE_WIDGETS);
      context.startService(widgetUpdateIntent);
    }

    // If this is a replacement or change in the package, update all active extensions from
    // this package.
    String action = intent.getAction();
    if (Intent.ACTION_PACKAGE_CHANGED.equals(action)
        || Intent.ACTION_PACKAGE_REPLACED.equals(action)) {
      String packageName = intent.getData().getSchemeSpecificPart();
      if (TextUtils.isEmpty(packageName)) {
        return;
      }

      List<ComponentName> activeExtensions = extensionManager.getActiveExtensionNames();
      for (ComponentName cn : activeExtensions) {
        if (packageName.equals(cn.getPackageName())) {
          Intent extensionUpdateIntent = new Intent(context, DashClockService.class);
          extensionUpdateIntent.setAction(DashClockService.ACTION_UPDATE_EXTENSIONS);
          extensionUpdateIntent.putExtra(
              DashClockService.EXTRA_COMPONENT_NAME, cn.flattenToShortString());
          context.startService(extensionUpdateIntent);
        }
      }
    }
  }
 private Drawable getActivityIconWithCache(ComponentName componentname)
 {
     String s = componentname.flattenToShortString();
     if (mOutsideDrawablesCache.containsKey(s))
     {
         componentname = (android.graphics.drawable.Drawable.ConstantState)mOutsideDrawablesCache.get(s);
         if (componentname == null)
         {
             return null;
         } else
         {
             return componentname.newDrawable(mProviderContext.getResources());
         }
     }
     Drawable drawable = getActivityIcon(componentname);
     if (drawable == null)
     {
         componentname = null;
     } else
     {
         componentname = drawable.getConstantState();
     }
     mOutsideDrawablesCache.put(s, componentname);
     return drawable;
 }
  // Buffer service controls
  public String startServerService() {
    try {
      intent.putExtra("port", port);
    } catch (final NumberFormatException e) {
      intent.putExtra("port", 1972);
    }

    try {
      intent.putExtra("nSamples", nSamples);
    } catch (final NumberFormatException e) {
      intent.putExtra("nSamples", 10000);
    }

    try {
      intent.putExtra("nEvents", nEvents);
    } catch (final NumberFormatException e) {
      intent.putExtra("nEvents", 1000);
    }

    Log.i(C.TAG, "Attempting to start Buffer Service");
    ComponentName serviceName = context.startService(intent);
    Log.i(C.TAG, "Managed to start service: " + serviceName);

    String result = "Buffer Service was not found";
    if (serviceName != null) result = serviceName.toString();
    return result;
  }
 private Drawable getActivityIcon(ComponentName componentname)
 {
     Object obj = mContext.getPackageManager();
     ActivityInfo activityinfo;
     int i;
     try
     {
         activityinfo = ((PackageManager) (obj)).getActivityInfo(componentname, 128);
     }
     // Misplaced declaration of an exception variable
     catch (ComponentName componentname)
     {
         componentname.toString();
         return null;
     }
     i = activityinfo.getIconResource();
     if (i == 0)
     {
         return null;
     }
     obj = ((PackageManager) (obj)).getDrawable(componentname.getPackageName(), i, activityinfo.applicationInfo);
     if (obj == null)
     {
         (new StringBuilder()).append("Invalid icon resource ").append(i).append(" for ").append(componentname.flattenToShortString()).toString();
         return null;
     } else
     {
         return ((Drawable) (obj));
     }
 }
  /**
   * Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX} provided
   * by the same package which is set to be global search activity. If widgetCategory is not
   * supported, or no such widget is found, returns the first widget provided by the package.
   */
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
  public static AppWidgetProviderInfo getSearchWidgetProvider(Context context) {
    SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
    ComponentName searchComponent = searchManager.getGlobalSearchActivity();
    if (searchComponent == null) return null;
    String providerPkg = searchComponent.getPackageName();

    AppWidgetProviderInfo defaultWidgetForSearchPackage = null;

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    for (AppWidgetProviderInfo info : appWidgetManager.getInstalledProviders()) {
      if (info.provider.getPackageName().equals(providerPkg)) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
          if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) {
            return info;
          } else if (defaultWidgetForSearchPackage == null) {
            defaultWidgetForSearchPackage = info;
          }
        } else {
          return info;
        }
      }
    }
    return defaultWidgetForSearchPackage;
  }
  private void saveFolder(FolderModel folder) {
    FileOutputStream out = null;
    try {
      out = openFileOutput(String.format("folder%d", folder.id), MODE_PRIVATE);

      out.write(String.format("%d\n", folder.width).getBytes());
      out.write(String.format("%d\n", folder.height).getBytes());

      for (ActivityInfo appInFolder : folder.apps) {
        ComponentName name = new ComponentName(appInFolder.packageName, appInFolder.name);

        out.write((name.flattenToString() + "\n").getBytes());
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (out != null) {
        try {
          out.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
  // sets the preferred launcher; if svmp is true, will set to LauncherActivity, otherwise will set
  // to aosp launcher
  protected static void setDefaultLauncher(
      Context context, PackageManager packageManager, boolean svmp) {
    Log.d(TAG, "Setting default launcher to: " + (svmp ? "svmp" : "aosp"));

    // set up args
    IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
    filter.addCategory(Intent.CATEGORY_HOME);
    filter.addCategory(Intent.CATEGORY_DEFAULT);
    int bestMatch = IntentFilter.MATCH_CATEGORY_EMPTY;
    ComponentName aospComponent =
        new ComponentName("com.cyanogenmod.trebuchet", "com.android.launcher3.Launcher");
    ComponentName svmpComponent =
        new ComponentName(context.getPackageName(), LauncherActivity.class.getName());
    ComponentName[] components = new ComponentName[] {aospComponent, svmpComponent};

    // set preferred launcher and clear preferences for other launcher
    ComponentName preferred = svmp ? svmpComponent : aospComponent,
        other = svmp ? aospComponent : svmpComponent;
    packageManager.clearPackagePreferredActivities(other.getPackageName());
    packageManager.addPreferredActivity(filter, bestMatch, components, preferred);

    if (svmp) {
      // start the preferred launcher
      Intent launchIntent = new Intent(Intent.ACTION_MAIN);
      launchIntent.setComponent(preferred);
      launchIntent.addCategory(Intent.CATEGORY_HOME);
      launchIntent.addFlags(
          Intent
              .FLAG_ACTIVITY_NEW_TASK); // required to start an activity from outside of an Activity
                                        // context
      launchIntent.addFlags(
          Intent.FLAG_ACTIVITY_CLEAR_TASK); // when this is started, clear other launcher activities
      context.startActivity(launchIntent);
    }
  }
 static boolean isSystemApp(Context context, Intent intent) {
   PackageManager pm = context.getPackageManager();
   ComponentName cn = intent.getComponent();
   String packageName = null;
   if (cn == null) {
     ResolveInfo info = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
     if ((info != null) && (info.activityInfo != null)) {
       packageName = info.activityInfo.packageName;
     }
   } else {
     packageName = cn.getPackageName();
   }
   if (packageName != null) {
     try {
       PackageInfo info = pm.getPackageInfo(packageName, 0);
       return (info != null)
           && (info.applicationInfo != null)
           && ((info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
     } catch (NameNotFoundException e) {
       return false;
     }
   } else {
     return false;
   }
 }
Example #21
0
  /**
   * @Description 判断是否是顶部activity
   *
   * @param context
   * @param activityName
   * @return
   */
  public static boolean isTopActivy(Context context, String activityName) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ComponentName cName =
        am.getRunningTasks(1).size() > 0 ? am.getRunningTasks(1).get(0).topActivity : null;

    if (null == cName) return false;
    return cName.getClassName().equals(activityName);
  }
Example #22
0
 private static void executeBadgeByBroadcast(
     Context context, ComponentName componentName, int badgeCount) {
   Intent intent = new Intent(INTENT_ACTION);
   intent.putExtra(INTENT_EXTRA_PACKAGE_NAME, componentName.getPackageName());
   intent.putExtra(INTENT_EXTRA_ACTIVITY_NAME, componentName.getClassName());
   intent.putExtra(INTENT_EXTRA_MESSAGE, String.valueOf(badgeCount));
   intent.putExtra(INTENT_EXTRA_SHOW_MESSAGE, badgeCount > 0);
   context.sendBroadcast(intent);
 }
 private synchronized void saveSubscriptions() {
   List<String> serializedSubscriptions = new ArrayList<>();
   for (ComponentName extension : mEnabledExtensions) {
     serializedSubscriptions.add(
         extension.flattenToShortString() + "|" + mSubscriptions.get(extension));
   }
   Timber.d("Saving " + serializedSubscriptions.size() + " subscriptions");
   JSONArray json = new JSONArray(serializedSubscriptions);
   mSharedPrefs.edit().putString(PREF_SUBSCRIPTIONS, json.toString()).commit();
 }
 private void handleServiceConnected(ComponentName paramComponentName, IBinder paramIBinder)
 {
   paramComponentName = (ListenerRecord)mRecordMap.get(paramComponentName);
   if (paramComponentName != null)
   {
     paramComponentName.service = INotificationSideChannel.Stub.asInterface(paramIBinder);
     paramComponentName.retryCount = 0;
     processListenerQueue(paramComponentName);
   }
 }
Example #25
0
 /** Find an ApplicationInfo object for the given packageName and className. */
 private AppInfo findApplicationInfoLocked(String packageName, String className) {
   for (AppInfo info : data) {
     final ComponentName component = info.intent.getComponent();
     if (packageName.equals(component.getPackageName())
         && className.equals(component.getClassName())) {
       return info;
     }
   }
   return null;
 }
 @Override
 public Object call(Object who, Method method, Object... args) throws Throwable {
   ComponentName componentName = (ComponentName) args[0];
   int flags = (int) args[1];
   if (getHostPkg().equals(componentName.getPackageName())) {
     return method.invoke(who, args);
   }
   int userId = VUserHandle.myUserId();
   return VPackageManager.get().getProviderInfo(componentName, flags, userId);
 }
Example #27
0
 @Override
 public void onServiceDisconnected(ComponentName component) {
   if (component.equals(new ComponentName(FileDetailActivity.this, FileDownloader.class))) {
     Log.d(TAG, "Download service disconnected");
     mDownloaderBinder = null;
   } else if (component.equals(new ComponentName(FileDetailActivity.this, FileUploader.class))) {
     Log.d(TAG, "Upload service disconnected");
     mUploaderBinder = null;
   }
 }
  public static void load(Context ctx, String pkg)
      throws NameNotFoundException, XmlPullParserException, IOException {

    sPackageName = pkg;
    Context extCtx = ctx.createPackageContext(pkg, Context.CONTEXT_IGNORE_SECURITY);
    sRes = extCtx.getResources();
    int id = sRes.getIdentifier("appfilter", "xml", sPackageName);
    boolean loadFromAssets = false;
    if (id != 0) {
      sParser = sRes.getXml(id);
    } else {
      loadFromAssets = true;
      Log.e(
          TAG,
          "Failed to get appfilter.xml from resources of package "
              + sPackageName
              + ", attempting load from assets...");
    }

    if (loadFromAssets) {
      InputStream is = sRes.getAssets().open("appfilter.xml");
      sParser = XmlPullParserFactory.newInstance().newPullParser();
      sParser.setInput(is, null);
    }

    if (sParser == null) throw new XmlPullParserException("Parser is null!");

    SharedPreferences prefs = ctx.getSharedPreferences("icon_pack", Context.MODE_PRIVATE);
    prefs.edit().clear().commit();
    SharedPreferences.Editor editor = prefs.edit();

    while (sParser.getEventType() != XmlPullParser.END_DOCUMENT) {
      int type = sParser.getEventType();
      switch (type) {
        case XmlPullParser.START_TAG:
          String currentComponent = sParser.getAttributeValue(null, "component");
          String drawable = sParser.getAttributeValue(null, "drawable");
          if (currentComponent != null) {
            ComponentName cmpName = ComponentNameParser.parse(currentComponent);
            if (cmpName != null && drawable != null) {
              int drawableId = sRes.getIdentifier(drawable, "drawable", sPackageName);
              if (drawableId != 0) {
                // TODO: replace by SQL database
                String pref = cmpName.getPackageName() + "/" + cmpName.getClassName();
                editor.putInt(pref, drawableId);
              }
            }
          }
          break;
      }

      sParser.next();
    }
    editor.commit();
  }
Example #29
0
  /**
   * Lists all of the installed instrumentation, or all for a given package
   *
   * <p>pm list instrumentation [package] [-f]
   */
  private void runListInstrumentation() {
    int flags = 0; // flags != 0 is only used to request meta-data
    boolean showPackage = false;
    String targetPackage = null;

    try {
      String opt;
      while ((opt = nextArg()) != null) {
        if (opt.equals("-f")) {
          showPackage = true;
        } else if (opt.charAt(0) != '-') {
          targetPackage = opt;
        } else {
          System.err.println("Error: Unknown option: " + opt);
          showUsage();
          return;
        }
      }
    } catch (RuntimeException ex) {
      System.err.println("Error: " + ex.toString());
      showUsage();
      return;
    }

    try {
      List<InstrumentationInfo> list = mPm.queryInstrumentation(targetPackage, flags);

      // Sort by target package
      Collections.sort(
          list,
          new Comparator<InstrumentationInfo>() {
            public int compare(InstrumentationInfo o1, InstrumentationInfo o2) {
              return o1.targetPackage.compareTo(o2.targetPackage);
            }
          });

      int count = (list != null) ? list.size() : 0;
      for (int p = 0; p < count; p++) {
        InstrumentationInfo ii = list.get(p);
        System.out.print("instrumentation:");
        if (showPackage) {
          System.out.print(ii.sourceDir);
          System.out.print("=");
        }
        ComponentName cn = new ComponentName(ii.packageName, ii.name);
        System.out.print(cn.flattenToShortString());
        System.out.print(" (target=");
        System.out.print(ii.targetPackage);
        System.out.println(")");
      }
    } catch (RemoteException e) {
      System.err.println(e.toString());
      System.err.println(PM_NOT_RUNNING_ERR);
    }
  }
Example #30
0
 public static String getTopActivityName(Context context) {
   String topActivityClassName = null;
   ActivityManager activityManager =
       (ActivityManager) (context.getSystemService(android.content.Context.ACTIVITY_SERVICE));
   List<RunningTaskInfo> runningTaskInfos = activityManager.getRunningTasks(1);
   if (runningTaskInfos != null) {
     ComponentName f = runningTaskInfos.get(0).topActivity;
     topActivityClassName = f.getClassName();
   }
   return topActivityClassName;
 }