Search in sources :

Example 6 with AppItem

use of com.android.settingslib.AppItem in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DataUsageList method bindStats.

/**
     * Bind the given {@link NetworkStats}, or {@code null} to clear list.
     */
public void bindStats(NetworkStats stats, int[] restrictedUids) {
    ArrayList<AppItem> items = new ArrayList<>();
    long largest = 0;
    final int currentUserId = ActivityManager.getCurrentUser();
    UserManager userManager = UserManager.get(getContext());
    final List<UserHandle> profiles = userManager.getUserProfiles();
    final SparseArray<AppItem> knownItems = new SparseArray<AppItem>();
    PackageManager pm = getContext().getPackageManager();
    ApplicationInfo ai = null;
    try {
        ai = pm.getApplicationInfo("com.android.dialer", PackageManager.GET_ACTIVITIES);
    } catch (Exception e) {
        Log.d(TAG, "get dialer getApplicationInfo failed " + e);
    }
    NetworkStats.Entry entry = null;
    final int size = stats != null ? stats.size() : 0;
    for (int i = 0; i < size; i++) {
        entry = stats.getValues(i, entry);
        // Decide how to collapse items together
        final int uid = entry.uid;
        final int collapseKey;
        final int category;
        final int userId = UserHandle.getUserId(uid);
        if (UserHandle.isApp(uid)) {
            if (profiles.contains(new UserHandle(userId))) {
                if (userId != currentUserId) {
                    // Add to a managed user item.
                    final int managedKey = UidDetailProvider.buildKeyForUser(userId);
                    largest = accumulate(managedKey, knownItems, entry, AppItem.CATEGORY_USER, items, largest);
                }
                // Add to app item.
                collapseKey = uid;
                category = AppItem.CATEGORY_APP;
            } else {
                // If it is a removed user add it to the removed users' key
                final UserInfo info = userManager.getUserInfo(userId);
                if (info == null) {
                    collapseKey = UID_REMOVED;
                    category = AppItem.CATEGORY_APP;
                } else {
                    // Add to other user item.
                    collapseKey = UidDetailProvider.buildKeyForUser(userId);
                    category = AppItem.CATEGORY_USER;
                }
            }
        } else if (uid == UID_REMOVED || uid == UID_TETHERING) {
            collapseKey = uid;
            category = AppItem.CATEGORY_APP;
        } else if ((ai != null) && (uid == ai.uid) && getContext().getResources().getBoolean(com.android.internal.R.bool.config_video_call_datausage_enable)) {
            collapseKey = uid;
            category = AppItem.CATEGORY_APP;
        } else {
            collapseKey = android.os.Process.SYSTEM_UID;
            category = AppItem.CATEGORY_APP;
        }
        largest = accumulate(collapseKey, knownItems, entry, category, items, largest);
    }
    final int restrictedUidsMax = restrictedUids.length;
    for (int i = 0; i < restrictedUidsMax; ++i) {
        final int uid = restrictedUids[i];
        // Only splice in restricted state for current user or managed users
        if (!profiles.contains(new UserHandle(UserHandle.getUserId(uid)))) {
            continue;
        }
        AppItem item = knownItems.get(uid);
        if (item == null) {
            item = new AppItem(uid);
            item.total = -1;
            items.add(item);
            knownItems.put(item.key, item);
        }
        item.restricted = true;
    }
    Collections.sort(items);
    mApps.removeAll();
    for (int i = 0; i < items.size(); i++) {
        final int percentTotal = largest != 0 ? (int) (items.get(i).total * 100 / largest) : 0;
        AppDataUsagePreference preference = new AppDataUsagePreference(getContext(), items.get(i), percentTotal, mUidDetailProvider);
        preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                AppDataUsagePreference pref = (AppDataUsagePreference) preference;
                AppItem item = pref.getItem();
                startAppDataUsage(item);
                return true;
            }
        });
        mApps.addPreference(preference);
    }
}
Also used : ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) NetworkStats(android.net.NetworkStats) UserInfo(android.content.pm.UserInfo) RemoteException(android.os.RemoteException) SparseArray(android.util.SparseArray) PackageManager(android.content.pm.PackageManager) AppItem(com.android.settingslib.AppItem) Preference(android.support.v7.preference.Preference) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle)

Example 7 with AppItem

use of com.android.settingslib.AppItem in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class InstalledAppDetails method onResume.

@Override
public void onResume() {
    super.onResume();
    if (mFinishing) {
        return;
    }
    mState.requestSize(mPackageName, mUserId);
    AppItem app = new AppItem(mAppEntry.info.uid);
    app.addUid(mAppEntry.info.uid);
    if (mStatsSession != null) {
        getLoaderManager().restartLoader(LOADER_CHART_DATA, ChartDataLoader.buildArgs(getTemplate(getContext()), app), mDataCallbacks);
    }
    new BatteryUpdater().execute();
    new MemoryUpdater().execute();
    updateDynamicPrefs();
}
Also used : AppItem(com.android.settingslib.AppItem)

Example 8 with AppItem

use of com.android.settingslib.AppItem in project android_frameworks_base by crdroidandroid.

the class ChartDataLoader method loadInBackground.

@Override
public ChartData loadInBackground() {
    final NetworkTemplate template = mArgs.getParcelable(KEY_TEMPLATE);
    final AppItem app = mArgs.getParcelable(KEY_APP);
    final int fields = mArgs.getInt(KEY_FIELDS);
    try {
        return loadInBackground(template, app, fields);
    } catch (RemoteException e) {
        // leave with half-baked UI, we bail hard.
        throw new RuntimeException("problem reading network stats", e);
    }
}
Also used : NetworkTemplate(android.net.NetworkTemplate) AppItem(com.android.settingslib.AppItem) RemoteException(android.os.RemoteException)

Example 9 with AppItem

use of com.android.settingslib.AppItem in project platform_frameworks_base by android.

the class ChartDataLoader method loadInBackground.

@Override
public ChartData loadInBackground() {
    final NetworkTemplate template = mArgs.getParcelable(KEY_TEMPLATE);
    final AppItem app = mArgs.getParcelable(KEY_APP);
    final int fields = mArgs.getInt(KEY_FIELDS);
    try {
        return loadInBackground(template, app, fields);
    } catch (RemoteException e) {
        // leave with half-baked UI, we bail hard.
        throw new RuntimeException("problem reading network stats", e);
    }
}
Also used : NetworkTemplate(android.net.NetworkTemplate) AppItem(com.android.settingslib.AppItem) RemoteException(android.os.RemoteException)

Example 10 with AppItem

use of com.android.settingslib.AppItem in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppDataUsageActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    final Intent intent = getIntent();
    final String packageName = intent.getData().getSchemeSpecificPart();
    final PackageManager pm = getPackageManager();
    final int uid;
    try {
        uid = pm.getPackageUid(packageName, 0);
    } catch (PackageManager.NameNotFoundException e) {
        Log.w(TAG, "invalid package: " + packageName);
        try {
            // Activity lifecycle still requires calling onCreate()
            super.onCreate(savedInstanceState);
        } catch (Exception e2) {
            // Ignore - most likely caused by SettingsActivity because of invalid fragment
            if (DEBUG)
                Log.d(TAG, "onCreate() exception", e);
        } finally {
            finish();
        }
        return;
    }
    if (DEBUG)
        Log.d(TAG, "Package: " + packageName + " UID: " + uid);
    final Bundle args = new Bundle();
    final AppItem appItem = new AppItem(uid);
    appItem.addUid(uid);
    args.putParcelable(AppDataUsage.ARG_APP_ITEM, appItem);
    intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
    intent.putExtra(EXTRA_SHOW_FRAGMENT, AppDataUsage.class.getName());
    intent.putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, R.string.app_data_usage);
    super.onCreate(savedInstanceState);
}
Also used : PackageManager(android.content.pm.PackageManager) AppItem(com.android.settingslib.AppItem) Bundle(android.os.Bundle) Intent(android.content.Intent)

Aggregations

AppItem (com.android.settingslib.AppItem)10 RemoteException (android.os.RemoteException)7 NetworkTemplate (android.net.NetworkTemplate)6 PackageManager (android.content.pm.PackageManager)3 Intent (android.content.Intent)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 Bundle (android.os.Bundle)2 Context (android.content.Context)1 UserInfo (android.content.pm.UserInfo)1 NetworkStats (android.net.NetworkStats)1 UserHandle (android.os.UserHandle)1 UserManager (android.os.UserManager)1 Preference (android.support.v7.preference.Preference)1 SparseArray (android.util.SparseArray)1 UidDetail (com.android.settingslib.net.UidDetail)1 UidDetailProvider (com.android.settingslib.net.UidDetailProvider)1 ArrayList (java.util.ArrayList)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1