Esempio n. 1
1
 public void register(Context context, Looper thread, UserHandle user, boolean externalStorage) {
   if (mRegisteredContext != null) {
     throw new IllegalStateException("Already registered");
   }
   mRegisteredContext = context;
   if (thread == null) {
     synchronized (sLock) {
       if (sBackgroundThread == null) {
         sBackgroundThread =
             new HandlerThread("PackageMonitor", android.os.Process.THREAD_PRIORITY_BACKGROUND);
         sBackgroundThread.start();
         sBackgroundHandler = new Handler(sBackgroundThread.getLooper());
       }
       mRegisteredHandler = sBackgroundHandler;
     }
   } else {
     mRegisteredHandler = new Handler(thread);
   }
   if (user != null) {
     context.registerReceiverAsUser(this, user, sPackageFilt, null, mRegisteredHandler);
     context.registerReceiverAsUser(this, user, sNonDataFilt, null, mRegisteredHandler);
     if (externalStorage) {
       context.registerReceiverAsUser(this, user, sExternalFilt, null, mRegisteredHandler);
     }
   } else {
     context.registerReceiver(this, sPackageFilt, null, mRegisteredHandler);
     context.registerReceiver(this, sNonDataFilt, null, mRegisteredHandler);
     if (externalStorage) {
       context.registerReceiver(this, sExternalFilt, null, mRegisteredHandler);
     }
   }
 }
Esempio n. 2
0
  public void systemReady(boolean safeMode) {
    mSafeMode = safeMode;

    mAppWidgetServices.get(0).systemReady(safeMode);

    // Register for the boot completed broadcast, so we can send the
    // ENABLE broacasts. If we try to send them now, they time out,
    // because the system isn't ready to handle them yet.
    mContext.registerReceiverAsUser(
        mBroadcastReceiver,
        UserHandle.ALL,
        new IntentFilter(Intent.ACTION_BOOT_COMPLETED),
        null,
        null);

    // Register for configuration changes so we can update the names
    // of the widgets when the locale changes.
    mContext.registerReceiverAsUser(
        mBroadcastReceiver,
        UserHandle.ALL,
        new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED),
        null,
        null);

    // Register for broadcasts about package install, etc., so we can
    // update the provider list.
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addDataScheme("package");
    mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);
    // Register for events related to sdcard installation.
    IntentFilter sdFilter = new IntentFilter();
    sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
    sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
    mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, sdFilter, null, null);

    IntentFilter userFilter = new IntentFilter();
    userFilter.addAction(Intent.ACTION_USER_REMOVED);
    userFilter.addAction(Intent.ACTION_USER_STOPPING);
    mContext.registerReceiver(
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            if (Intent.ACTION_USER_REMOVED.equals(intent.getAction())) {
              onUserRemoved(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL));
            } else if (Intent.ACTION_USER_STOPPING.equals(intent.getAction())) {
              onUserStopping(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL));
            }
          }
        },
        userFilter);
  }
  // Intended to be called only once at startup, after the system is ready. Installs a broadcast
  // receiver to monitor ongoing UID changes, so this shouldn't/needn't be called again.
  public synchronized void startMonitoring() {
    log("Monitoring");

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_USER_ADDED);
    intentFilter.addAction(Intent.ACTION_USER_REMOVED);
    mContext.registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, intentFilter, null, null);

    intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    intentFilter.addDataScheme("package");
    mContext.registerReceiverAsUser(mIntentReceiver, UserHandle.ALL, intentFilter, null, null);

    List<PackageInfo> apps = mPackageManager.getInstalledPackages(GET_PERMISSIONS);
    if (apps == null) {
      loge("No apps");
      return;
    }

    for (PackageInfo app : apps) {
      int uid = app.applicationInfo != null ? app.applicationInfo.uid : -1;
      if (uid < 0) {
        continue;
      }

      boolean isNetwork = hasNetworkPermission(app);
      boolean isSystem = hasSystemPermission(app);

      if (isNetwork || isSystem) {
        Boolean permission = mApps.get(uid);
        // If multiple packages share a UID (cf: android:sharedUserId) and ask for different
        // permissions, don't downgrade (i.e., if it's already SYSTEM, leave it as is).
        if (permission == null || permission == NETWORK) {
          mApps.put(uid, isSystem);
        }
      }
    }

    List<UserInfo> users = mUserManager.getUsers(true); // exclude dying users
    if (users != null) {
      for (UserInfo user : users) {
        mUsers.add(user.id);
      }
    }

    log("Users: " + mUsers.size() + ", Apps: " + mApps.size());
    update(mUsers, mApps, true);
  }
 void register(Context context) {
   IntentFilter filter = new IntentFilter();
   filter.addAction(Intent.ACTION_USER_STOPPED);
   filter.addAction(Intent.ACTION_USER_STARTED);
   filter.addAction(Intent.ACTION_USER_INFO_CHANGED);
   context.registerReceiverAsUser(this, UserHandle.ALL, filter, null, null);
 }
  public LocationControllerImpl(Context context, Looper bgLooper) {
    mContext = context;

    // Register to listen for changes in location settings.
    IntentFilter filter = new IntentFilter();
    filter.addAction(LocationManager.HIGH_POWER_REQUEST_CHANGE_ACTION);
    filter.addAction(LocationManager.MODE_CHANGED_ACTION);
    context.registerReceiverAsUser(this, UserHandle.ALL, filter, null, new Handler(bgLooper));

    mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
    mStatusBarManager = (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE);

    // Initialize last active mode. If state was off use the default high accuracy mode
    mLastActiveMode = getLocationCurrentState();
    if (mLastActiveMode == Settings.Secure.LOCATION_MODE_OFF)
      mLastActiveMode = Settings.Secure.LOCATION_MODE_HIGH_ACCURACY;

    // Examine the current location state and initialize the status view.
    updateActiveLocationRequests();
    refreshViews();
  }