Search in sources :

Example 1 with AppItem

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

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 2 with AppItem

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

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 3 with AppItem

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

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 4 with AppItem

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

the class AppDataUsage method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    final Bundle args = getArguments();
    try {
        mStatsSession = services.mStatsService.openSession();
    } catch (RemoteException e) {
        throw new RuntimeException(e);
    }
    mAppItem = (args != null) ? (AppItem) args.getParcelable(ARG_APP_ITEM) : null;
    mTemplate = (args != null) ? (NetworkTemplate) args.getParcelable(ARG_NETWORK_TEMPLATE) : null;
    mPolicyManager = NetworkPolicyManager.from(getActivity());
    if (mTemplate == null) {
        Context context = getContext();
        mTemplate = DataUsageSummary.getDefaultTemplate(context, DataUsageSummary.getDefaultSubscriptionId(context));
    }
    if (mAppItem == null) {
        int uid = (args != null) ? args.getInt(AppInfoBase.ARG_PACKAGE_UID, -1) : getActivity().getIntent().getIntExtra(AppInfoBase.ARG_PACKAGE_UID, -1);
        if (uid == -1) {
            // TODO: Log error.
            getActivity().finish();
        } else {
            addUid(uid);
            mAppItem = new AppItem(uid);
            mAppItem.addUid(uid);
        }
    } else {
        for (int i = 0; i < mAppItem.uids.size(); i++) {
            addUid(mAppItem.uids.keyAt(i));
        }
    }
    addPreferencesFromResource(R.xml.app_data_usage);
    mTotalUsage = findPreference(KEY_TOTAL_USAGE);
    mForegroundUsage = findPreference(KEY_FOREGROUND_USAGE);
    mBackgroundUsage = findPreference(KEY_BACKGROUND_USAGE);
    mCycle = (SpinnerPreference) findPreference(KEY_CYCLE);
    mCycleAdapter = new CycleAdapter(getContext(), mCycle, mCycleListener, false);
    if (mAppItem.key > 0) {
        if (mPackages.size() != 0) {
            PackageManager pm = getPackageManager();
            try {
                ApplicationInfo info = pm.getApplicationInfo(mPackages.valueAt(0), 0);
                mIcon = info.loadIcon(pm);
                mLabel = info.loadLabel(pm);
                mPackageName = info.packageName;
            } catch (PackageManager.NameNotFoundException e) {
            }
        }
        if (!UserHandle.isApp(mAppItem.key)) {
            removePreference(KEY_UNRESTRICTED_DATA);
            removePreference(KEY_RESTRICT_BACKGROUND);
            removePreference(KEY_RESTRICT_ALL_DATA);
            removePreference(KEY_RESTRICT_ALL_WIFI);
        } else {
            mRestrictBackground = (SwitchPreference) findPreference(KEY_RESTRICT_BACKGROUND);
            mRestrictBackground.setOnPreferenceChangeListener(this);
            mUnrestrictedData = (SwitchPreference) findPreference(KEY_UNRESTRICTED_DATA);
            mUnrestrictedData.setOnPreferenceChangeListener(this);
            mRestrictAllData = (SwitchPreference) findPreference(KEY_RESTRICT_ALL_DATA);
            mRestrictAllData.setOnPreferenceChangeListener(this);
            mRestrictAllWifi = (SwitchPreference) findPreference(KEY_RESTRICT_ALL_WIFI);
            mRestrictAllWifi.setOnPreferenceChangeListener(this);
        }
        mDataSaverBackend = new DataSaverBackend(getContext());
        mAppSettings = findPreference(KEY_APP_SETTINGS);
        mAppSettingsIntent = new Intent(Intent.ACTION_MANAGE_NETWORK_USAGE);
        mAppSettingsIntent.addCategory(Intent.CATEGORY_DEFAULT);
        PackageManager pm = getPackageManager();
        boolean matchFound = false;
        for (String packageName : mPackages) {
            mAppSettingsIntent.setPackage(packageName);
            if (pm.resolveActivity(mAppSettingsIntent, 0) != null) {
                matchFound = true;
                break;
            }
        }
        if (!matchFound) {
            removePreference(KEY_APP_SETTINGS);
            mAppSettings = null;
        }
        if (mPackages.size() > 1) {
            mAppList = (PreferenceCategory) findPreference(KEY_APP_LIST);
            final int packageSize = mPackages.size();
            final BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(packageSize);
            final ThreadPoolExecutor executor = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_SECONDS, TimeUnit.SECONDS, workQueue);
            for (int i = 1; i < mPackages.size(); i++) {
                final AppPrefLoader loader = new AppPrefLoader();
                loader.executeOnExecutor(executor, mPackages.valueAt(i));
            }
        } else {
            removePreference(KEY_APP_LIST);
        }
    } else {
        final Context context = getActivity();
        UidDetail uidDetail = new UidDetailProvider(context).getUidDetail(mAppItem.key, true);
        mIcon = uidDetail.icon;
        mLabel = uidDetail.label;
        mPackageName = context.getPackageName();
        removePreference(KEY_UNRESTRICTED_DATA);
        removePreference(KEY_APP_SETTINGS);
        removePreference(KEY_RESTRICT_BACKGROUND);
        removePreference(KEY_APP_LIST);
        removePreference(KEY_RESTRICT_ALL_DATA);
        removePreference(KEY_RESTRICT_ALL_WIFI);
    }
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) NetworkTemplate(android.net.NetworkTemplate) UidDetail(com.android.settingslib.net.UidDetail) PackageManager(android.content.pm.PackageManager) AppItem(com.android.settingslib.AppItem) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) RemoteException(android.os.RemoteException) UidDetailProvider(com.android.settingslib.net.UidDetailProvider)

Example 5 with AppItem

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

the class DataUsageList method accumulate.

/**
     * Accumulate data usage of a network stats entry for the item mapped by the collapse key.
     * Creates the item if needed.
     * @param collapseKey the collapse key used to map the item.
     * @param knownItems collection of known (already existing) items.
     * @param entry the network stats entry to extract data usage from.
     * @param itemCategory the item is categorized on the list view by this category. Must be
     */
private static long accumulate(int collapseKey, final SparseArray<AppItem> knownItems, NetworkStats.Entry entry, int itemCategory, ArrayList<AppItem> items, long largest) {
    final int uid = entry.uid;
    AppItem item = knownItems.get(collapseKey);
    if (item == null) {
        item = new AppItem(collapseKey);
        item.category = itemCategory;
        items.add(item);
        knownItems.put(item.key, item);
    }
    item.addUid(uid);
    item.total += entry.rxBytes + entry.txBytes;
    return Math.max(largest, item.total);
}
Also used : AppItem(com.android.settingslib.AppItem)

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