public TabInfo(
     ManageApplications owner,
     ApplicationsState apps,
     CharSequence label,
     int listType,
     AppClickListener clickListener,
     Bundle savedInstanceState) {
   mOwner = owner;
   mApplicationsState = apps;
   mLabel = label;
   mListType = listType;
   switch (listType) {
     case LIST_TYPE_DOWNLOADED:
       mFilter = FILTER_APPS_THIRD_PARTY;
       break;
     case LIST_TYPE_SDCARD:
       mFilter = FILTER_APPS_SDCARD;
       break;
     default:
       mFilter = FILTER_APPS_ALL;
       break;
   }
   mClickListener = clickListener;
   mInvalidSizeStr = owner.getActivity().getText(R.string.invalid_size_value);
   mComputingSizeStr = owner.getActivity().getText(R.string.computing_size);
   mSavedInstanceState = savedInstanceState;
 }
 void handleRunningProcessesAvail() {
   mLoadingContainer.startAnimation(
       AnimationUtils.loadAnimation(mOwner.getActivity(), android.R.anim.fade_out));
   mRunningProcessesView.startAnimation(
       AnimationUtils.loadAnimation(mOwner.getActivity(), android.R.anim.fade_in));
   mRunningProcessesView.setVisibility(View.VISIBLE);
   mLoadingContainer.setVisibility(View.GONE);
 }
    public View build(LayoutInflater inflater, ViewGroup contentParent, View contentChild) {
      if (mRootView != null) {
        return mRootView;
      }

      mInflater = inflater;
      mRootView =
          inflater.inflate(
              mListType == LIST_TYPE_RUNNING
                  ? R.layout.manage_applications_running
                  : R.layout.manage_applications_apps,
              null);
      mRootView.setLayoutDirection(
          mRootView.getResources().getConfiguration().getLayoutDirection());
      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);
        mListView.setAdapter(mApplications);
        mListView.setRecyclerListener(mApplications);
        mColorBar = (LinearColorBar) mListContainer.findViewById(R.id.storage_color_bar);
        mStorageChartLabel = (TextView) mListContainer.findViewById(R.id.storageChartLabel);
        mUsedStorageText = (TextView) mListContainer.findViewById(R.id.usedStorageText);
        mFreeStorageText = (TextView) mListContainer.findViewById(R.id.freeStorageText);
        Utils.prepareCustomPreferencesList(contentParent, contentChild, mListView, false);
        if (mFilter == FILTER_APPS_SDCARD) {
          mStorageChartLabel.setText(mOwner.getActivity().getText(R.string.sd_card_storage));
        } else {
          mStorageChartLabel.setText(mOwner.getActivity().getText(R.string.internal_storage));
        }
        applyCurrentStorage();
      }
      mRunningProcessesView = (RunningProcessesView) mRootView.findViewById(R.id.running_processes);
      if (mRunningProcessesView != null) {
        mRunningProcessesView.doCreate(mSavedInstanceState);
      }

      return mRootView;
    }
 void applyCurrentStorage() {
   // If view hierarchy is not yet created, no views to update.
   if (mRootView == null) {
     return;
   }
   if (mTotalStorage > 0) {
     BidiFormatter bidiFormatter = BidiFormatter.getInstance();
     mColorBar.setRatios(
         (mTotalStorage - mFreeStorage - mAppStorage) / (float) mTotalStorage,
         mAppStorage / (float) mTotalStorage,
         mFreeStorage / (float) mTotalStorage);
     long usedStorage = mTotalStorage - mFreeStorage;
     if (mLastUsedStorage != usedStorage) {
       mLastUsedStorage = usedStorage;
       String sizeStr =
           bidiFormatter.unicodeWrap(
               Formatter.formatShortFileSize(mOwner.getActivity(), usedStorage));
       mUsedStorageText.setText(
           mOwner
               .getActivity()
               .getResources()
               .getString(R.string.service_foreground_processes, sizeStr));
     }
     if (mLastFreeStorage != mFreeStorage) {
       mLastFreeStorage = mFreeStorage;
       String sizeStr =
           bidiFormatter.unicodeWrap(
               Formatter.formatShortFileSize(mOwner.getActivity(), mFreeStorage));
       mFreeStorageText.setText(
           mOwner
               .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("");
     }
   }
 }
    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();
    }
 public void enableFilter(int filter) {
   if (mFilterOptions.contains(filter)) return;
   if (DEBUG) Log.d(TAG, "Enabling filter " + filter);
   mFilterOptions.add(filter);
   Collections.sort(mFilterOptions);
   mManageApplications.mSpinnerHeader.setVisibility(
       mFilterOptions.size() > 1 ? View.VISIBLE : View.GONE);
   notifyDataSetChanged();
   if (mFilterOptions.size() == 1) {
     if (DEBUG) Log.d(TAG, "Auto selecting filter " + filter);
     mManageApplications.mFilterSpinner.setSelection(0);
     mManageApplications.onItemSelected(null, null, 0, 0);
   }
 }
 public void disableFilter(int filter) {
   if (!mFilterOptions.remove((Integer) filter)) {
     return;
   }
   if (DEBUG) Log.d(TAG, "Disabling filter " + filter);
   Collections.sort(mFilterOptions);
   mManageApplications.mSpinnerHeader.setVisibility(
       mFilterOptions.size() > 1 ? View.VISIBLE : View.GONE);
   notifyDataSetChanged();
   if (mManageApplications.mFilter == filter) {
     if (mFilterOptions.size() > 0) {
       if (DEBUG) Log.d(TAG, "Auto selecting filter " + mFilterOptions.get(0));
       mManageApplications.mFilterSpinner.setSelection(0);
       mManageApplications.onItemSelected(null, null, 0, 0);
     }
   }
 }
 public ApplicationsAdapter(
     ApplicationsState state, ManageApplications manageApplications, int filterMode) {
   mState = state;
   mSession = state.newSession(this);
   mManageApplications = manageApplications;
   mContext = manageApplications.getActivity();
   mPm = mContext.getPackageManager();
   mFilterMode = filterMode;
   if (mManageApplications.mListType == LIST_TYPE_NOTIFICATION) {
     mExtraInfoBridge =
         new AppStateNotificationBridge(
             mContext.getPackageManager(), mState, this, manageApplications.mNotifBackend);
   } else if (mManageApplications.mListType == LIST_TYPE_USAGE_ACCESS) {
     mExtraInfoBridge = new AppStateUsageBridge(mContext, mState, this);
   } else if (mManageApplications.mListType == LIST_TYPE_HIGH_POWER) {
     mExtraInfoBridge = new AppStatePowerBridge(mState, this);
   } else if (mManageApplications.mListType == LIST_TYPE_OVERLAY) {
     mExtraInfoBridge = new AppStateOverlayBridge(mContext, mState, this);
   } else if (mManageApplications.mListType == LIST_TYPE_WRITE_SETTINGS) {
     mExtraInfoBridge = new AppStateWriteSettingsBridge(mContext, mState, this);
   } else {
     mExtraInfoBridge = null;
   }
 }
 @Override
 public void onRunningStateChanged(boolean running) {
   mManageApplications.getActivity().setProgressBarIndeterminateVisibility(running);
 }
    public void rebuild(boolean eraseold) {
      if (!mHasReceivedLoadEntries && (mExtraInfoBridge == null || mHasReceivedBridgeCallback)) {
        // Don't rebuild the list until all the app entries are loaded.
        return;
      }
      if (DEBUG) Log.i(TAG, "Rebuilding app list...");
      ApplicationsState.AppFilter filterObj;
      Comparator<AppEntry> comparatorObj;
      boolean emulated = Environment.isExternalStorageEmulated();
      if (emulated) {
        mWhichSize = SIZE_TOTAL;
      } else {
        mWhichSize = SIZE_INTERNAL;
      }
      filterObj = FILTERS[mFilterMode];
      if (mOverrideFilter != null) {
        filterObj = mOverrideFilter;
      }
      if (!mManageApplications.mShowSystem) {
        filterObj = new CompoundFilter(filterObj, ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER);
      }
      switch (mLastSortMode) {
        case R.id.sort_order_size:
          switch (mWhichSize) {
            case SIZE_INTERNAL:
              comparatorObj = ApplicationsState.INTERNAL_SIZE_COMPARATOR;
              break;
            case SIZE_EXTERNAL:
              comparatorObj = ApplicationsState.EXTERNAL_SIZE_COMPARATOR;
              break;
            default:
              comparatorObj = ApplicationsState.SIZE_COMPARATOR;
              break;
          }
          break;
        default:
          comparatorObj = ApplicationsState.ALPHA_COMPARATOR;
          break;
      }
      ArrayList<ApplicationsState.AppEntry> entries = mSession.rebuild(filterObj, comparatorObj);
      if (entries == null && !eraseold) {
        // Don't have new list yet, but can continue using the old one.
        return;
      }
      mBaseEntries = entries;
      if (mBaseEntries != null) {
        mEntries = applyPrefixFilter(mCurFilterPrefix, mBaseEntries);
      } else {
        mEntries = null;
      }
      notifyDataSetChanged();

      if (mSession.getAllApps().size() != 0
          && mManageApplications.mListContainer.getVisibility() != View.VISIBLE) {
        Utils.handleLoadingContainer(
            mManageApplications.mLoadingContainer, mManageApplications.mListContainer, true, true);
      }
      if (mManageApplications.mListType == LIST_TYPE_USAGE_ACCESS) {
        // No enabled or disabled filters for usage access.
        return;
      }

      mManageApplications.setHasDisabled(mState.haveDisabledApps());
    }
 private CharSequence getFilterString(int filter) {
   return mManageApplications.getString(FILTER_LABELS[filter]);
 }
 public FilterSpinnerAdapter(ManageApplications manageApplications) {
   super(manageApplications.getActivity(), R.layout.filter_spinner_item);
   setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
   mManageApplications = manageApplications;
 }