コード例 #1
0
    void updateStorageUsage() {
      // Make sure a callback didn't come at an inopportune time.
      if (mOwner.getActivity() == null) return;
      // Doesn't make sense for stuff that is not an app list.
      if (mApplications == null) return;

      mFreeStorage = 0;
      mAppStorage = 0;
      mTotalStorage = 0;

      if (mFilter == FILTER_APPS_SDCARD) {
        if (mContainerService != null) {
          try {
            final long[] stats =
                mContainerService.getFileSystemStats(
                    Environment.getExternalStorageDirectory().getPath());
            mTotalStorage = stats[0];
            mFreeStorage = stats[1];
          } catch (RemoteException e) {
            Log.w(TAG, "Problem in container service", e);
          }
        }

        if (mApplications != null) {
          final int N = mApplications.getCount();
          for (int i = 0; i < N; i++) {
            ApplicationsState.AppEntry ae = mApplications.getAppEntry(i);
            mAppStorage += ae.externalCodeSize + ae.externalDataSize + ae.externalCacheSize;
          }
        }
      } else {
        if (mContainerService != null) {
          try {
            final long[] stats =
                mContainerService.getFileSystemStats(Environment.getDataDirectory().getPath());
            mTotalStorage = stats[0];
            mFreeStorage = stats[1];
          } catch (RemoteException e) {
            Log.w(TAG, "Problem in container service", e);
          }
        }

        final boolean emulatedStorage = Environment.isExternalStorageEmulated();
        if (mApplications != null) {
          final int N = mApplications.getCount();
          for (int i = 0; i < N; i++) {
            ApplicationsState.AppEntry ae = mApplications.getAppEntry(i);
            mAppStorage += ae.codeSize + ae.dataSize;
            if (emulatedStorage) {
              mAppStorage += ae.externalCodeSize + ae.externalDataSize;
            }
          }
        }
        mFreeStorage += mApplicationsState.sumCacheSizes();
      }

      applyCurrentStorage();
    }
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   if (mApplications != null && mApplications.getCount() > position) {
     ApplicationsState.AppEntry entry = mApplications.getAppEntry(position);
     mCurrentPkgName = entry.info.packageName;
     mCurrentUid = entry.info.uid;
     startApplicationDetailsActivity();
   }
 }
 @Override
 public void onResume() {
   super.onResume();
   updateView();
   updateOptionsMenu();
   if (mApplications != null) {
     mApplications.resume(mSortOrder);
     mApplications.updateLoading();
   }
 }
 @Override
 public void onPause() {
   super.onPause();
   if (mApplications != null) {
     mApplications.pause();
   }
 }
  private void createHeader() {
    Activity activity = getActivity();
    FrameLayout pinnedHeader = (FrameLayout) mRootView.findViewById(R.id.pinned_header);
    mSpinnerHeader =
        (ViewGroup)
            activity.getLayoutInflater().inflate(R.layout.apps_filter_spinner, pinnedHeader, false);
    mFilterSpinner = (Spinner) mSpinnerHeader.findViewById(R.id.filter_spinner);
    mFilterAdapter = new FilterSpinnerAdapter(this);
    mFilterSpinner.setAdapter(mFilterAdapter);
    mFilterSpinner.setOnItemSelectedListener(this);
    pinnedHeader.addView(mSpinnerHeader, 0);

    mFilterAdapter.enableFilter(getDefaultFilter());
    if (mListType == LIST_TYPE_MAIN || mListType == LIST_TYPE_NOTIFICATION) {
      if (UserManager.get(getActivity()).getUserProfiles().size() > 1) {
        mFilterAdapter.enableFilter(FILTER_APPS_PERSONAL);
        mFilterAdapter.enableFilter(FILTER_APPS_WORK);
      }
    }
    if (mListType == LIST_TYPE_NOTIFICATION) {
      mFilterAdapter.enableFilter(FILTER_APPS_BLOCKED);
      mFilterAdapter.enableFilter(FILTER_APPS_PRIORITY);
      mFilterAdapter.enableFilter(FILTER_APPS_SENSITIVE);
      mFilterAdapter.enableFilter(FILTER_APPS_NO_PEEKING);
    }
    if (mListType == LIST_TYPE_HIGH_POWER) {
      mFilterAdapter.enableFilter(FILTER_APPS_POWER_WHITELIST_ALL);
    }
    if (mListType == LIST_TYPE_STORAGE) {
      mApplications.setOverrideFilter(new VolumeFilter(mVolumeUuid));
    }
  }
コード例 #6
0
 public void pause() {
   if (mApplications != null) {
     mApplications.pause();
   }
   if (mRunningProcessesView != null) {
     mRunningProcessesView.doPause();
   }
 }
  @Override
  public void onDestroyView() {
    super.onDestroyView();

    if (mApplications != null) {
      mApplications.release();
    }
    mRootView = null;
  }
コード例 #8
0
 @Override
 public void onPause() {
   super.onPause();
   mActivityResumed = false;
   mApplicationsAdapter.pause();
   if (mResumedRunning) {
     mRunningProcessesView.doPause();
     mResumedRunning = false;
   }
   mTabHost.getTabWidget().setEnabled(false);
 }
コード例 #9
0
 private void selectView(int which) {
   if (which == VIEW_LIST) {
     if (mResumedRunning) {
       mRunningProcessesView.doPause();
       mResumedRunning = false;
     }
     if (mCurView != which) {
       mRunningProcessesView.setVisibility(View.GONE);
       mListContainer.setVisibility(View.VISIBLE);
       mLoadingContainer.setVisibility(View.GONE);
     }
     if (mActivityResumed) {
       mApplicationsAdapter.resume(mFilterApps, mSortOrder);
     }
   } else if (which == VIEW_RUNNING) {
     if (!mCreatedRunning) {
       mRunningProcessesView.doCreate(null);
       mRunningProcessesView.mAdapter.setShowBackground(mShowBackground);
       mCreatedRunning = true;
     }
     boolean haveData = true;
     if (mActivityResumed && !mResumedRunning) {
       haveData = mRunningProcessesView.doResume(this, mRunningProcessesAvail);
       mResumedRunning = true;
     }
     mApplicationsAdapter.pause();
     if (mCurView != which) {
       if (haveData) {
         mRunningProcessesView.setVisibility(View.VISIBLE);
       } else {
         mLoadingContainer.setVisibility(View.VISIBLE);
       }
       mListContainer.setVisibility(View.GONE);
     }
   }
   mCurView = which;
   final Activity host = getActivity();
   if (host != null) {
     host.invalidateOptionsMenu();
   }
 }
コード例 #10
0
 public void resume(int sortOrder) {
   if (mApplications != null) {
     mApplications.resume(sortOrder);
   }
   if (mRunningProcessesView != null) {
     boolean haveData = mRunningProcessesView.doResume(mOwner, mRunningProcessesAvail);
     if (haveData) {
       mRunningProcessesView.setVisibility(View.VISIBLE);
       mLoadingContainer.setVisibility(View.INVISIBLE);
     } else {
       mLoadingContainer.setVisibility(View.VISIBLE);
     }
   }
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   int menuId = item.getItemId();
   switch (item.getItemId()) {
     case R.id.sort_order_alpha:
     case R.id.sort_order_size:
       mSortOrder = menuId;
       if (mApplications != null) {
         mApplications.rebuild(mSortOrder);
       }
       break;
     case R.id.show_system:
     case R.id.hide_system:
       mShowSystem = !mShowSystem;
       mApplications.rebuild(false);
       break;
     case R.id.reset_app_preferences:
       mResetAppsHelper.buildResetDialog();
       return true;
     case R.id.advanced:
       ((SettingsActivity) getActivity())
           .startPreferencePanel(
               AdvancedAppSettings.class.getName(),
               null,
               R.string.configure_apps,
               null,
               this,
               ADVANCED_SETTINGS);
       return true;
     default:
       // Handle the home button
       return false;
   }
   updateOptionsMenu();
   return true;
 }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // initialize the inflater
    mInflater = inflater;

    mRootView = inflater.inflate(R.layout.manage_applications_apps, null);
    mLoadingContainer = mRootView.findViewById(R.id.loading_container);
    mLoadingContainer.setVisibility(View.VISIBLE);
    mListContainer = mRootView.findViewById(R.id.list_container);
    if (mListContainer != null) {
      // Create adapter and list view here
      View emptyView = mListContainer.findViewById(com.android.internal.R.id.empty);
      ListView lv = (ListView) mListContainer.findViewById(android.R.id.list);
      if (emptyView != null) {
        lv.setEmptyView(emptyView);
      }
      lv.setOnItemClickListener(this);
      lv.setSaveEnabled(true);
      lv.setItemsCanFocus(true);
      lv.setTextFilterEnabled(true);
      lv.setFastScrollEnabled(true);
      mListView = lv;
      mApplications = new ApplicationsAdapter(mApplicationsState, this, mFilter);
      if (savedInstanceState != null) {
        mApplications.mHasReceivedLoadEntries =
            savedInstanceState.getBoolean(EXTRA_HAS_ENTRIES, false);
      }
      mListView.setAdapter(mApplications);
      mListView.setRecyclerListener(mApplications);

      Utils.prepareCustomPreferencesList(container, mRootView, mListView, false);
    }

    // We have to do this now because PreferenceFrameLayout looks at it
    // only when the view is added.
    if (container instanceof PreferenceFrameLayout) {
      ((PreferenceFrameLayout.LayoutParams) mRootView.getLayoutParams()).removeBorders = true;
    }

    createHeader();

    mResetAppsHelper.onRestoreInstanceState(savedInstanceState);

    return mRootView;
  }
コード例 #13
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   int menuId = item.getItemId();
   if ((menuId == SORT_ORDER_ALPHA) || (menuId == SORT_ORDER_SIZE)) {
     mSortOrder = menuId;
     if (mCurView != VIEW_RUNNING) {
       mApplicationsAdapter.rebuild(mFilterApps, mSortOrder);
     }
   } else if (menuId == SHOW_RUNNING_SERVICES) {
     mShowBackground = false;
     mRunningProcessesView.mAdapter.setShowBackground(false);
   } else if (menuId == SHOW_BACKGROUND_PROCESSES) {
     mShowBackground = true;
     mRunningProcessesView.mAdapter.setShowBackground(true);
   }
   updateOptionsMenu();
   return true;
 }
コード例 #14
0
  void updateStorageUsage() {
    if (mCurView == VIEW_RUNNING) {
      return;
    }

    long freeStorage = 0;
    long appStorage = 0;
    long totalStorage = 0;
    CharSequence newLabel = null;

    if (mFilterApps == FILTER_APPS_SDCARD) {
      if (mLastShowedInternalStorage) {
        mLastShowedInternalStorage = false;
      }
      newLabel = getActivity().getText(R.string.sd_card_storage);
      mSDCardFileStats.restat(Environment.getExternalStorageDirectory().toString());
      try {
        totalStorage = (long) mSDCardFileStats.getBlockCount() * mSDCardFileStats.getBlockSize();
        freeStorage =
            (long) mSDCardFileStats.getAvailableBlocks() * mSDCardFileStats.getBlockSize();
      } catch (IllegalArgumentException e) {
        // use the old value of mFreeMem
      }
      final int N = mApplicationsAdapter.getCount();
      for (int i = 0; i < N; i++) {
        ApplicationsState.AppEntry ae = mApplicationsAdapter.getAppEntry(i);
        appStorage += ae.externalCodeSize + ae.externalDataSize;
      }
    } else {
      if (!mLastShowedInternalStorage) {
        mLastShowedInternalStorage = true;
      }
      newLabel = getActivity().getText(R.string.internal_storage);
      mDataFileStats.restat("/data");
      try {
        totalStorage = (long) mDataFileStats.getBlockCount() * mDataFileStats.getBlockSize();
        freeStorage = (long) mDataFileStats.getAvailableBlocks() * mDataFileStats.getBlockSize();
      } catch (IllegalArgumentException e) {
      }
      final boolean emulatedStorage = Environment.isExternalStorageEmulated();
      final int N = mApplicationsAdapter.getCount();
      for (int i = 0; i < N; i++) {
        ApplicationsState.AppEntry ae = mApplicationsAdapter.getAppEntry(i);
        appStorage += ae.codeSize + ae.dataSize;
        if (emulatedStorage) {
          appStorage += ae.externalCodeSize + ae.externalDataSize;
        }
      }
      freeStorage += mApplicationsState.sumCacheSizes();
    }
    if (newLabel != null) {
      mStorageChartLabel.setText(newLabel);
    }
    if (totalStorage > 0) {
      mColorBar.setRatios(
          (totalStorage - freeStorage - appStorage) / (float) totalStorage,
          appStorage / (float) totalStorage,
          freeStorage / (float) totalStorage);
      long usedStorage = totalStorage - freeStorage;
      if (mLastUsedStorage != usedStorage) {
        mLastUsedStorage = usedStorage;
        String sizeStr = Formatter.formatShortFileSize(getActivity(), usedStorage);
        mUsedStorageText.setText(
            getActivity().getResources().getString(R.string.service_foreground_processes, sizeStr));
      }
      if (mLastFreeStorage != freeStorage) {
        mLastFreeStorage = freeStorage;
        String sizeStr = Formatter.formatShortFileSize(getActivity(), freeStorage);
        mFreeStorageText.setText(
            getActivity().getResources().getString(R.string.service_background_processes, sizeStr));
      }
    } else {
      mColorBar.setRatios(0, 0, 0);
      if (mLastUsedStorage != -1) {
        mLastUsedStorage = -1;
        mUsedStorageText.setText("");
      }
      if (mLastFreeStorage != -1) {
        mLastFreeStorage = -1;
        mFreeStorageText.setText("");
      }
    }
  }
コード例 #15
0
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   ApplicationsState.AppEntry entry = mApplicationsAdapter.getAppEntry(position);
   mCurrentPkgName = entry.info.packageName;
   startApplicationDetailsActivity();
 }
 @Override
 public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
   mFilter = mFilterAdapter.getFilter(position);
   mApplications.setFilter(mFilter);
   if (DEBUG) Log.d(TAG, "Selecting filter " + mFilter);
 }