Example #1
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;
  }
 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);
 }
  @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 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());
  }
 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;
 }
 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();
 }
  /**
   * 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);
    }
  }
 /**
  * Gets the activity or application icon for an activity. Uses the local icon cache for fast
  * repeated lookups.
  *
  * @param component Name of an activity.
  * @return A drawable, or {@code null} if neither the activity nor the application has an icon
  *     set.
  */
 private Drawable getActivityIconWithCache(ComponentName component) {
   // First check the icon cache
   String componentIconKey = component.flattenToShortString();
   // Using containsKey() since we also store null values.
   if (mOutsideDrawablesCache.containsKey(componentIconKey)) {
     Drawable.ConstantState cached = mOutsideDrawablesCache.get(componentIconKey);
     return cached == null ? null : cached.newDrawable(mProviderContext.getResources());
   }
   // Then try the activity or application icon
   Drawable drawable = getActivityIcon(component);
   // Stick it in the cache so we don't do this lookup again.
   Drawable.ConstantState toCache = drawable == null ? null : drawable.getConstantState();
   mOutsideDrawablesCache.put(componentIconKey, toCache);
   return drawable;
 }
 /**
  * Gets the activity or application icon for an activity.
  *
  * @param component Name of an activity.
  * @return A drawable, or {@code null} if neither the acitivy or the application have an icon set.
  */
 private Drawable getActivityIcon(ComponentName component) {
   PackageManager pm = mContext.getPackageManager();
   final ActivityInfo activityInfo;
   try {
     activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
   } catch (NameNotFoundException ex) {
     Log.w(LOG_TAG, ex.toString());
     return null;
   }
   int iconId = activityInfo.getIconResource();
   if (iconId == 0) return null;
   String pkg = component.getPackageName();
   Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo);
   if (drawable == null) {
     Log.w(
         LOG_TAG, "Invalid icon resource " + iconId + " for " + component.flattenToShortString());
     return null;
   }
   return drawable;
 }
Example #10
0
  /**
   * Read a pre-loaded icon from the persistent icon cache.
   *
   * @param componentName the component that should own the icon
   * @returns a bitmap if one is cached, or null.
   */
  private Bitmap getPreloadedIcon(ComponentName componentName, UserHandleCompat user) {
    final String key = componentName.flattenToShortString();

    // We don't keep icons for other profiles in persistent cache.
    if (!user.equals(UserHandleCompat.myUserHandle())) {
      return null;
    }

    if (DEBUG) Log.v(TAG, "looking for pre-load icon for " + key);
    Bitmap icon = null;
    FileInputStream resourceFile = null;
    try {
      resourceFile = mContext.openFileInput(getResourceFilename(componentName));
      byte[] buffer = new byte[1024];
      ByteArrayOutputStream bytes = new ByteArrayOutputStream();
      int bytesRead = 0;
      while (bytesRead >= 0) {
        bytes.write(buffer, 0, bytesRead);
        bytesRead = resourceFile.read(buffer, 0, buffer.length);
      }
      if (DEBUG) Log.d(TAG, "read " + bytes.size());
      icon = BitmapFactory.decodeByteArray(bytes.toByteArray(), 0, bytes.size());
      if (icon == null) {
        Log.w(TAG, "failed to decode pre-load icon for " + key);
      }
    } catch (FileNotFoundException e) {
      if (DEBUG) Log.d(TAG, "there is no restored icon for: " + key);
    } catch (IOException e) {
      Log.w(TAG, "failed to read pre-load icon for: " + key, e);
    } finally {
      if (resourceFile != null) {
        try {
          resourceFile.close();
        } catch (IOException e) {
          Log.d(TAG, "failed to manage pre-load icon file: " + key, e);
        }
      }
    }

    return icon;
  }
Example #11
0
 private void saveToDB(ContentValues values) {
   values.put(ObjectInfoColumns.OBJECT_NAME, mName);
   values.put(ObjectInfoColumns.OBJECT_TYPE, mType);
   values.put(ObjectInfoColumns.SHADER_TYPE, mShaderType);
   values.put(ObjectInfoColumns.SCENE_NAME, mSceneName);
   if (mComponentName != null) {
     values.put(ObjectInfoColumns.COMPONENT_NAME, mComponentName.flattenToShortString());
   }
   values.put(ObjectInfoColumns.CLASS_NAME, mClassName);
   values.put(ObjectInfoColumns.SLOT_TYPE, mSlotType);
   values.put(ObjectInfoColumns.WIDGET_ID, mAppWidgetId);
   values.put(ObjectInfoColumns.SHORTCUT_URL, mShortcutUrl);
   if (mIsNativeObject) {
     values.put(ObjectInfoColumns.IS_NATIVE_OBJ, 1);
   } else {
     values.put(ObjectInfoColumns.IS_NATIVE_OBJ, 0);
   }
   if (mShortcutIcon != null && !mShortcutIcon.isRecycled()) {
     HomeUtils.writeBitmap(values, mShortcutIcon);
   }
   values.put(ObjectInfoColumns.DISPLAY_NAME, mDisplayName);
   values.put(ObjectInfoColumns.OBJECT_INDEX, mIndex);
 }
  final void processNextBroadcast(boolean fromMsg) {
    synchronized (mService) {
      BroadcastRecord r;

      if (DEBUG_BROADCAST)
        Slog.v(
            TAG,
            "processNextBroadcast ["
                + mQueueName
                + "]: "
                + mParallelBroadcasts.size()
                + " broadcasts, "
                + mOrderedBroadcasts.size()
                + " ordered broadcasts");

      mService.updateCpuStats();

      if (fromMsg) {
        mBroadcastsScheduled = false;
      }

      // First, deliver any non-serialized broadcasts right away.
      while (mParallelBroadcasts.size() > 0) {
        r = mParallelBroadcasts.remove(0);
        r.dispatchTime = SystemClock.uptimeMillis();
        r.dispatchClockTime = System.currentTimeMillis();
        mCurrentBroadcast = r;
        final int N = r.receivers.size();
        if (DEBUG_BROADCAST_LIGHT)
          Slog.v(TAG, "Processing parallel broadcast [" + mQueueName + "] " + r);
        for (int i = 0; i < N; i++) {
          Object target = r.receivers.get(i);
          if (DEBUG_BROADCAST)
            Slog.v(
                TAG,
                "Delivering non-ordered on ["
                    + mQueueName
                    + "] to registered "
                    + target
                    + ": "
                    + r);
          deliverToRegisteredReceiverLocked(r, (BroadcastFilter) target, false);
        }
        addBroadcastToHistoryLocked(r);
        mCurrentBroadcast = null;
        if (DEBUG_BROADCAST_LIGHT)
          Slog.v(TAG, "Done with parallel broadcast [" + mQueueName + "] " + r);
      }

      // Now take care of the next serialized one...

      // If we are waiting for a process to come up to handle the next
      // broadcast, then do nothing at this point.  Just in case, we
      // check that the process we're waiting for still exists.
      if (mPendingBroadcast != null) {
        if (DEBUG_BROADCAST_LIGHT) {
          Slog.v(
              TAG,
              "processNextBroadcast [" + mQueueName + "]: waiting for " + mPendingBroadcast.curApp);
        }

        boolean isDead;
        synchronized (mService.mPidsSelfLocked) {
          isDead = (mService.mPidsSelfLocked.get(mPendingBroadcast.curApp.pid) == null);
        }
        if (!isDead) {
          // It's still alive, so keep waiting
          return;
        } else {
          Slog.w(
              TAG,
              "pending app  ["
                  + mQueueName
                  + "]"
                  + mPendingBroadcast.curApp
                  + " died before responding to broadcast");
          mPendingBroadcast.state = BroadcastRecord.IDLE;
          mPendingBroadcast.nextReceiver = mPendingBroadcastRecvIndex;
          mPendingBroadcast = null;
        }
      }

      boolean looped = false;

      do {
        if (mOrderedBroadcasts.size() == 0) {
          // No more broadcasts pending, so all done!
          mService.scheduleAppGcsLocked();
          if (looped) {
            // If we had finished the last ordered broadcast, then
            // make sure all processes have correct oom and sched
            // adjustments.
            mService.updateOomAdjLocked();
          }
          return;
        }
        r = mOrderedBroadcasts.get(0);
        mCurrentBroadcast = r;
        boolean forceReceive = false;

        // Ensure that even if something goes awry with the timeout
        // detection, we catch "hung" broadcasts here, discard them,
        // and continue to make progress.
        //
        // This is only done if the system is ready so that PRE_BOOT_COMPLETED
        // receivers don't get executed with timeouts. They're intended for
        // one time heavy lifting after system upgrades and can take
        // significant amounts of time.
        int numReceivers = (r.receivers != null) ? r.receivers.size() : 0;
        if (mService.mProcessesReady && r.dispatchTime > 0) {
          long now = SystemClock.uptimeMillis();
          if ((numReceivers > 0) && (now > r.dispatchTime + (2 * mTimeoutPeriod * numReceivers))) {
            Slog.w(
                TAG,
                "Hung broadcast ["
                    + mQueueName
                    + "] discarded after timeout failure:"
                    + " now="
                    + now
                    + " dispatchTime="
                    + r.dispatchTime
                    + " startTime="
                    + r.receiverTime
                    + " intent="
                    + r.intent
                    + " numReceivers="
                    + numReceivers
                    + " nextReceiver="
                    + r.nextReceiver
                    + " state="
                    + r.state);
            broadcastTimeoutLocked(false); // forcibly finish this broadcast
            forceReceive = true;
            r.state = BroadcastRecord.IDLE;
          }
        }

        if (r.state != BroadcastRecord.IDLE) {
          if (DEBUG_BROADCAST)
            Slog.d(
                TAG,
                "processNextBroadcast("
                    + mQueueName
                    + ") called when not idle (state="
                    + r.state
                    + ")");
          return;
        }

        if (r.receivers == null
            || r.nextReceiver >= numReceivers
            || r.resultAbort
            || forceReceive) {
          // No more receivers for this broadcast!  Send the final
          // result if requested...
          if (r.resultTo != null) {
            try {
              if (DEBUG_BROADCAST) {
                int seq = r.intent.getIntExtra("seq", -1);
                Slog.i(
                    TAG,
                    "Finishing broadcast ["
                        + mQueueName
                        + "] "
                        + r.intent.getAction()
                        + " seq="
                        + seq
                        + " app="
                        + r.callerApp);
              }
              performReceiveLocked(
                  r.callerApp,
                  r.resultTo,
                  new Intent(r.intent),
                  r.resultCode,
                  r.resultData,
                  r.resultExtras,
                  false,
                  false,
                  r.userId);
              // Set this to null so that the reference
              // (local and remote) isnt kept in the mBroadcastHistory.
              r.resultTo = null;
            } catch (RemoteException e) {
              Slog.w(
                  TAG, "Failure [" + mQueueName + "] sending broadcast result of " + r.intent, e);
            }
          }

          if (DEBUG_BROADCAST) Slog.v(TAG, "Cancelling BROADCAST_TIMEOUT_MSG");
          cancelBroadcastTimeoutLocked();

          if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, "Finished with ordered broadcast " + r);

          // ... and on to the next...
          addBroadcastToHistoryLocked(r);
          mOrderedBroadcasts.remove(0);
          mCurrentBroadcast = null;
          r = null;
          looped = true;
          continue;
        }
      } while (r == null);

      // Get the next receiver...
      int recIdx = r.nextReceiver++;

      // Keep track of when this receiver started, and make sure there
      // is a timeout message pending to kill it if need be.
      r.receiverTime = SystemClock.uptimeMillis();
      if (recIdx == 0) {
        r.dispatchTime = r.receiverTime;
        r.dispatchClockTime = System.currentTimeMillis();
        if (DEBUG_BROADCAST_LIGHT)
          Slog.v(TAG, "Processing ordered broadcast [" + mQueueName + "] " + r);
      }
      if (!mPendingBroadcastTimeoutMessage) {
        long timeoutTime = r.receiverTime + mTimeoutPeriod;
        if (DEBUG_BROADCAST)
          Slog.v(
              TAG,
              "Submitting BROADCAST_TIMEOUT_MSG ["
                  + mQueueName
                  + "] for "
                  + r
                  + " at "
                  + timeoutTime);
        setBroadcastTimeoutLocked(timeoutTime);
      }

      Object nextReceiver = r.receivers.get(recIdx);
      if (nextReceiver instanceof BroadcastFilter) {
        // Simple case: this is a registered receiver who gets
        // a direct call.
        BroadcastFilter filter = (BroadcastFilter) nextReceiver;
        if (DEBUG_BROADCAST)
          Slog.v(TAG, "Delivering ordered [" + mQueueName + "] to registered " + filter + ": " + r);
        deliverToRegisteredReceiverLocked(r, filter, r.ordered);
        if (r.receiver == null || !r.ordered) {
          // The receiver has already finished, so schedule to
          // process the next one.
          if (DEBUG_BROADCAST)
            Slog.v(
                TAG,
                "Quick finishing ["
                    + mQueueName
                    + "]: ordered="
                    + r.ordered
                    + " receiver="
                    + r.receiver);
          r.state = BroadcastRecord.IDLE;
          scheduleBroadcastsLocked();
        }
        return;
      }

      // Hard case: need to instantiate the receiver, possibly
      // starting its application process to host it.

      ResolveInfo info = (ResolveInfo) nextReceiver;
      ComponentName component =
          new ComponentName(info.activityInfo.applicationInfo.packageName, info.activityInfo.name);

      boolean skip = false;
      int perm =
          mService.checkComponentPermission(
              info.activityInfo.permission,
              r.callingPid,
              r.callingUid,
              info.activityInfo.applicationInfo.uid,
              info.activityInfo.exported);
      if (perm != PackageManager.PERMISSION_GRANTED) {
        if (!info.activityInfo.exported) {
          Slog.w(
              TAG,
              "Permission Denial: broadcasting "
                  + r.intent.toString()
                  + " from "
                  + r.callerPackage
                  + " (pid="
                  + r.callingPid
                  + ", uid="
                  + r.callingUid
                  + ")"
                  + " is not exported from uid "
                  + info.activityInfo.applicationInfo.uid
                  + " due to receiver "
                  + component.flattenToShortString());
        } else {
          Slog.w(
              TAG,
              "Permission Denial: broadcasting "
                  + r.intent.toString()
                  + " from "
                  + r.callerPackage
                  + " (pid="
                  + r.callingPid
                  + ", uid="
                  + r.callingUid
                  + ")"
                  + " requires "
                  + info.activityInfo.permission
                  + " due to receiver "
                  + component.flattenToShortString());
        }
        skip = true;
      }
      if (info.activityInfo.applicationInfo.uid != Process.SYSTEM_UID
          && r.requiredPermission != null) {
        try {
          perm =
              AppGlobals.getPackageManager()
                  .checkPermission(
                      r.requiredPermission, info.activityInfo.applicationInfo.packageName);
        } catch (RemoteException e) {
          perm = PackageManager.PERMISSION_DENIED;
        }
        if (perm != PackageManager.PERMISSION_GRANTED) {
          Slog.w(
              TAG,
              "Permission Denial: receiving "
                  + r.intent
                  + " to "
                  + component.flattenToShortString()
                  + " requires "
                  + r.requiredPermission
                  + " due to sender "
                  + r.callerPackage
                  + " (uid "
                  + r.callingUid
                  + ")");
          skip = true;
        }
      }
      if (r.appOp != AppOpsManager.OP_NONE) {
        int mode =
            mService.mAppOpsService.checkOperation(
                r.appOp, info.activityInfo.applicationInfo.uid, info.activityInfo.packageName);
        if (mode != AppOpsManager.MODE_ALLOWED) {
          if (DEBUG_BROADCAST)
            Slog.v(
                TAG,
                "App op "
                    + r.appOp
                    + " not allowed for broadcast to uid "
                    + info.activityInfo.applicationInfo.uid
                    + " pkg "
                    + info.activityInfo.packageName);
          skip = true;
        }
      }
      // MUTT
      if (mMuttFilter.hasAction(r.intent.getAction())) {
        Slog.v(TAG, "MUTT: whitelist broadcast " + r.intent.toString());
      } else {
        if (mService.mBatteryStatsService.allowMutt(
                info.activityInfo.applicationInfo.uid, info.activityInfo.packageName)
            != 0) {
          Slog.w(
              TAG,
              "MUTT: skipping broadcasting "
                  + r.intent.toString()
                  + " from "
                  + r.callerPackage
                  + " (pid="
                  + r.callingPid
                  + ", uid="
                  + r.callingUid
                  + " to "
                  + component.flattenToShortString()
                  + ")");

          skip = true;
        }
      }

      boolean isSingleton = false;
      try {
        isSingleton =
            mService.isSingleton(
                info.activityInfo.processName,
                info.activityInfo.applicationInfo,
                info.activityInfo.name,
                info.activityInfo.flags);
      } catch (SecurityException e) {
        Slog.w(TAG, e.getMessage());
        skip = true;
      }
      if ((info.activityInfo.flags & ActivityInfo.FLAG_SINGLE_USER) != 0) {
        if (ActivityManager.checkUidPermission(
                android.Manifest.permission.INTERACT_ACROSS_USERS,
                info.activityInfo.applicationInfo.uid)
            != PackageManager.PERMISSION_GRANTED) {
          Slog.w(
              TAG,
              "Permission Denial: Receiver "
                  + component.flattenToShortString()
                  + " requests FLAG_SINGLE_USER, but app does not hold "
                  + android.Manifest.permission.INTERACT_ACROSS_USERS);
          skip = true;
        }
      }
      if (r.curApp != null && r.curApp.crashing) {
        // If the target process is crashing, just skip it.
        if (DEBUG_BROADCAST)
          Slog.v(
              TAG,
              "Skipping deliver ordered ["
                  + mQueueName
                  + "] "
                  + r
                  + " to "
                  + r.curApp
                  + ": process crashing");
        skip = true;
      }

      if (skip) {
        if (DEBUG_BROADCAST)
          Slog.v(
              TAG,
              "Skipping delivery of ordered [" + mQueueName + "] " + r + " for whatever reason");
        r.receiver = null;
        r.curFilter = null;
        r.state = BroadcastRecord.IDLE;
        scheduleBroadcastsLocked();
        return;
      }

      r.state = BroadcastRecord.APP_RECEIVE;
      String targetProcess = info.activityInfo.processName;
      r.curComponent = component;
      if (r.callingUid != Process.SYSTEM_UID && isSingleton) {
        info.activityInfo = mService.getActivityInfoForUser(info.activityInfo, 0);
      }
      r.curReceiver = info.activityInfo;
      if (DEBUG_MU && r.callingUid > UserHandle.PER_USER_RANGE) {
        Slog.v(
            TAG_MU,
            "Updated broadcast record activity info for secondary user, "
                + info.activityInfo
                + ", callingUid = "
                + r.callingUid
                + ", uid = "
                + info.activityInfo.applicationInfo.uid);
      }

      // Broadcast is being executed, its package can't be stopped.
      try {
        AppGlobals.getPackageManager()
            .setPackageStoppedState(
                r.curComponent.getPackageName(), false, UserHandle.getUserId(r.callingUid));
      } catch (RemoteException e) {
      } catch (IllegalArgumentException e) {
        Slog.w(
            TAG, "Failed trying to unstop package " + r.curComponent.getPackageName() + ": " + e);
      }

      // Is this receiver's application already running?
      ProcessRecord app =
          mService.getProcessRecordLocked(targetProcess, info.activityInfo.applicationInfo.uid);
      if (app != null && app.thread != null) {
        try {
          app.addPackage(info.activityInfo.packageName);
          processCurBroadcastLocked(r, app);
          return;
        } catch (RemoteException e) {
          Slog.w(TAG, "Exception when sending broadcast to " + r.curComponent, e);
        } catch (RuntimeException e) {
          Log.wtf(TAG, "Failed sending broadcast to " + r.curComponent + " with " + r.intent, e);
          // If some unexpected exception happened, just skip
          // this broadcast.  At this point we are not in the call
          // from a client, so throwing an exception out from here
          // will crash the entire system instead of just whoever
          // sent the broadcast.
          logBroadcastReceiverDiscardLocked(r);
          finishReceiverLocked(r, r.resultCode, r.resultData, r.resultExtras, r.resultAbort, true);
          scheduleBroadcastsLocked();
          // We need to reset the state if we failed to start the receiver.
          r.state = BroadcastRecord.IDLE;
          return;
        }

        // If a dead object exception was thrown -- fall through to
        // restart the application.
      }

      // Not running -- get it started, to be executed when the app comes up.
      if (DEBUG_BROADCAST)
        Slog.v(
            TAG, "Need to start app [" + mQueueName + "] " + targetProcess + " for broadcast " + r);
      if ((r.curApp =
              mService.startProcessLocked(
                  targetProcess,
                  info.activityInfo.applicationInfo,
                  true,
                  r.intent.getFlags() | Intent.FLAG_FROM_BACKGROUND,
                  "broadcast",
                  r.curComponent,
                  (r.intent.getFlags() & Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0,
                  false))
          == null) {
        // Ah, this recipient is unavailable.  Finish it if necessary,
        // and mark the broadcast record as ready for the next.
        Slog.w(
            TAG,
            "Unable to launch app "
                + info.activityInfo.applicationInfo.packageName
                + "/"
                + info.activityInfo.applicationInfo.uid
                + " for broadcast "
                + r.intent
                + ": process is bad");
        logBroadcastReceiverDiscardLocked(r);
        finishReceiverLocked(r, r.resultCode, r.resultData, r.resultExtras, r.resultAbort, true);
        scheduleBroadcastsLocked();
        r.state = BroadcastRecord.IDLE;
        return;
      }

      mPendingBroadcast = r;
      mPendingBroadcastRecvIndex = recIdx;
    }
  }
Example #13
0
 private static String getResourceFilename(ComponentName component) {
   String resourceName = component.flattenToShortString();
   String filename = resourceName.replace(File.separatorChar, '_');
   return RESOURCE_FILE_PREFIX + filename;
 }
 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));
     }
 }