Search in sources :

Example 51 with ArraySet

use of android.util.ArraySet in project android_frameworks_base by DirtyUnicorns.

the class Settings method writeKernelMappingLPr.

void writeKernelMappingLPr() {
    if (mKernelMappingFilename == null)
        return;
    final String[] known = mKernelMappingFilename.list();
    final ArraySet<String> knownSet = new ArraySet<>(known.length);
    for (String name : known) {
        knownSet.add(name);
    }
    for (final PackageSetting ps : mPackages.values()) {
        // Package is actively claimed
        knownSet.remove(ps.name);
        writeKernelMappingLPr(ps);
    }
    // Remove any unclaimed mappings
    for (int i = 0; i < knownSet.size(); i++) {
        final String name = knownSet.valueAt(i);
        if (DEBUG_KERNEL)
            Slog.d(TAG, "Dropping mapping " + name);
        mKernelMapping.remove(name);
        new File(mKernelMappingFilename, name).delete();
    }
}
Also used : ArraySet(android.util.ArraySet) AtomicFile(android.util.AtomicFile) File(java.io.File) JournaledFile(com.android.internal.util.JournaledFile)

Example 52 with ArraySet

use of android.util.ArraySet in project android_frameworks_base by DirtyUnicorns.

the class AppOpsService method setUidMode.

@Override
public void setUidMode(int code, int uid, int mode) {
    if (Binder.getCallingPid() != Process.myPid()) {
        mContext.enforcePermission(android.Manifest.permission.UPDATE_APP_OPS_STATS, Binder.getCallingPid(), Binder.getCallingUid(), null);
    }
    verifyIncomingOp(code);
    code = AppOpsManager.opToSwitch(code);
    synchronized (this) {
        final int defaultMode = AppOpsManager.opToDefaultMode(code);
        UidState uidState = getUidStateLocked(uid, false);
        if (uidState == null) {
            if (mode == defaultMode) {
                return;
            }
            uidState = new UidState(uid);
            uidState.opModes = new SparseIntArray();
            uidState.opModes.put(code, mode);
            mUidStates.put(uid, uidState);
            scheduleWriteLocked();
        } else if (uidState.opModes == null) {
            if (mode != defaultMode) {
                uidState.opModes = new SparseIntArray();
                uidState.opModes.put(code, mode);
                scheduleWriteLocked();
            }
        } else {
            if (uidState.opModes.get(code) == mode) {
                return;
            }
            if (mode == defaultMode) {
                uidState.opModes.delete(code);
                if (uidState.opModes.size() <= 0) {
                    uidState.opModes = null;
                }
            } else {
                uidState.opModes.put(code, mode);
            }
            scheduleWriteLocked();
        }
    }
    String[] uidPackageNames = getPackagesForUid(uid);
    ArrayMap<Callback, ArraySet<String>> callbackSpecs = null;
    synchronized (this) {
        ArrayList<Callback> callbacks = mOpModeWatchers.get(code);
        if (callbacks != null) {
            final int callbackCount = callbacks.size();
            for (int i = 0; i < callbackCount; i++) {
                Callback callback = callbacks.get(i);
                ArraySet<String> changedPackages = new ArraySet<>();
                Collections.addAll(changedPackages, uidPackageNames);
                callbackSpecs = new ArrayMap<>();
                callbackSpecs.put(callback, changedPackages);
            }
        }
        for (String uidPackageName : uidPackageNames) {
            callbacks = mPackageModeWatchers.get(uidPackageName);
            if (callbacks != null) {
                if (callbackSpecs == null) {
                    callbackSpecs = new ArrayMap<>();
                }
                final int callbackCount = callbacks.size();
                for (int i = 0; i < callbackCount; i++) {
                    Callback callback = callbacks.get(i);
                    ArraySet<String> changedPackages = callbackSpecs.get(callback);
                    if (changedPackages == null) {
                        changedPackages = new ArraySet<>();
                        callbackSpecs.put(callback, changedPackages);
                    }
                    changedPackages.add(uidPackageName);
                }
            }
        }
    }
    if (callbackSpecs == null) {
        return;
    }
    // There are components watching for mode changes such as window manager
    // and location manager which are in our process. The callbacks in these
    // components may require permissions our remote caller does not have.
    final long identity = Binder.clearCallingIdentity();
    try {
        for (int i = 0; i < callbackSpecs.size(); i++) {
            Callback callback = callbackSpecs.keyAt(i);
            ArraySet<String> reportedPackageNames = callbackSpecs.valueAt(i);
            try {
                if (reportedPackageNames == null) {
                    callback.mCallback.opChanged(code, uid, null);
                } else {
                    final int reportedPackageCount = reportedPackageNames.size();
                    for (int j = 0; j < reportedPackageCount; j++) {
                        String reportedPackageName = reportedPackageNames.valueAt(j);
                        callback.mCallback.opChanged(code, uid, reportedPackageName);
                    }
                }
            } catch (RemoteException e) {
                Log.w(TAG, "Error dispatching op op change", e);
            }
        }
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : ArraySet(android.util.ArraySet) IAppOpsCallback(com.android.internal.app.IAppOpsCallback) SparseIntArray(android.util.SparseIntArray) RemoteException(android.os.RemoteException)

Example 53 with ArraySet

use of android.util.ArraySet in project android_frameworks_base by DirtyUnicorns.

the class UsageStatsService method dump.

/**
     * Called by the Binder stub.
     */
void dump(String[] args, PrintWriter pw) {
    synchronized (mLock) {
        IndentingPrintWriter idpw = new IndentingPrintWriter(pw, "  ");
        ArraySet<String> argSet = new ArraySet<>();
        argSet.addAll(Arrays.asList(args));
        final int userCount = mUserState.size();
        for (int i = 0; i < userCount; i++) {
            idpw.printPair("user", mUserState.keyAt(i));
            idpw.println();
            idpw.increaseIndent();
            if (argSet.contains("--checkin")) {
                mUserState.valueAt(i).checkin(idpw);
            } else {
                mUserState.valueAt(i).dump(idpw);
                idpw.println();
                if (args.length > 0) {
                    if ("history".equals(args[0])) {
                        mAppIdleHistory.dumpHistory(idpw, mUserState.keyAt(i));
                    } else if ("flush".equals(args[0])) {
                        UsageStatsService.this.flushToDiskLocked();
                        pw.println("Flushed stats to disk");
                    }
                }
            }
            mAppIdleHistory.dump(idpw, mUserState.keyAt(i));
            idpw.decreaseIndent();
        }
        pw.println();
        pw.println("Carrier privileged apps (have=" + mHaveCarrierPrivilegedApps + "): " + mCarrierPrivilegedApps);
        pw.println();
        pw.println("Settings:");
        pw.print("  mAppIdleDurationMillis=");
        TimeUtils.formatDuration(mAppIdleScreenThresholdMillis, pw);
        pw.println();
        pw.print("  mAppIdleWallclockThresholdMillis=");
        TimeUtils.formatDuration(mAppIdleWallclockThresholdMillis, pw);
        pw.println();
        pw.print("  mCheckIdleIntervalMillis=");
        TimeUtils.formatDuration(mCheckIdleIntervalMillis, pw);
        pw.println();
        pw.print("  mAppIdleParoleIntervalMillis=");
        TimeUtils.formatDuration(mAppIdleParoleIntervalMillis, pw);
        pw.println();
        pw.print("  mAppIdleParoleDurationMillis=");
        TimeUtils.formatDuration(mAppIdleParoleDurationMillis, pw);
        pw.println();
        pw.println();
        pw.print("mAppIdleEnabled=");
        pw.print(mAppIdleEnabled);
        pw.print(" mAppIdleTempParoled=");
        pw.print(mAppIdleTempParoled);
        pw.print(" mCharging=");
        pw.print(mCharging);
        pw.print(" mLastAppIdleParoledTime=");
        TimeUtils.formatDuration(mLastAppIdleParoledTime, pw);
        pw.println();
    }
}
Also used : ArraySet(android.util.ArraySet) IndentingPrintWriter(com.android.internal.util.IndentingPrintWriter)

Example 54 with ArraySet

use of android.util.ArraySet in project android_frameworks_base by DirtyUnicorns.

the class DiskStatsFileLoggerTest method testAppsReported.

@Test
public void testAppsReported() throws Exception {
    PackageStats firstPackage = new PackageStats("com.test.app");
    firstPackage.codeSize = 100;
    firstPackage.dataSize = 1000;
    firstPackage.cacheSize = 20;
    mPackages.add(firstPackage);
    PackageStats secondPackage = new PackageStats("com.test.app2");
    secondPackage.codeSize = 10;
    secondPackage.dataSize = 1;
    secondPackage.cacheSize = 2;
    mPackages.add(secondPackage);
    DiskStatsFileLogger logger = new DiskStatsFileLogger(mMainResult, mDownloadsResult, mPackages, 0L);
    logger.dumpToFile(mOutputFile);
    JSONObject output = getOutputFileAsJson();
    assertThat(output.getLong(DiskStatsFileLogger.APP_SIZE_AGG_KEY)).isEqualTo(1111);
    assertThat(output.getLong(DiskStatsFileLogger.APP_CACHE_AGG_KEY)).isEqualTo(22);
    JSONArray packageNames = output.getJSONArray(DiskStatsFileLogger.PACKAGE_NAMES_KEY);
    assertThat(packageNames.length()).isEqualTo(2);
    JSONArray appSizes = output.getJSONArray(DiskStatsFileLogger.APP_SIZES_KEY);
    assertThat(appSizes.length()).isEqualTo(2);
    JSONArray cacheSizes = output.getJSONArray(DiskStatsFileLogger.APP_CACHES_KEY);
    assertThat(cacheSizes.length()).isEqualTo(2);
    // We need to do this crazy Set over this because the DiskStatsFileLogger provides no
    // guarantee of the ordering of the apps in its output. By using a set, we avoid any order
    // problems.
    ArraySet<AppSizeGrouping> apps = new ArraySet<>();
    for (int i = 0; i < packageNames.length(); i++) {
        AppSizeGrouping app = new AppSizeGrouping(packageNames.getString(i), appSizes.getLong(i), cacheSizes.getLong(i));
        apps.add(app);
    }
    assertThat(apps).containsAllOf(new AppSizeGrouping("com.test.app", 1100, 20), new AppSizeGrouping("com.test.app2", 11, 2));
}
Also used : ArraySet(android.util.ArraySet) JSONObject(org.json.JSONObject) PackageStats(android.content.pm.PackageStats) JSONArray(org.json.JSONArray) Test(org.junit.Test)

Example 55 with ArraySet

use of android.util.ArraySet in project android_frameworks_base by DirtyUnicorns.

the class UserUsageStatsService method rolloverStats.

private void rolloverStats(final long currentTimeMillis) {
    final long startTime = SystemClock.elapsedRealtime();
    Slog.i(TAG, mLogPrefix + "Rolling over usage stats");
    // Finish any ongoing events with an END_OF_DAY event. Make a note of which components
    // need a new CONTINUE_PREVIOUS_DAY entry.
    final Configuration previousConfig = mCurrentStats[UsageStatsManager.INTERVAL_DAILY].activeConfiguration;
    ArraySet<String> continuePreviousDay = new ArraySet<>();
    for (IntervalStats stat : mCurrentStats) {
        final int pkgCount = stat.packageStats.size();
        for (int i = 0; i < pkgCount; i++) {
            UsageStats pkgStats = stat.packageStats.valueAt(i);
            if (pkgStats.mLastEvent == UsageEvents.Event.MOVE_TO_FOREGROUND || pkgStats.mLastEvent == UsageEvents.Event.CONTINUE_PREVIOUS_DAY) {
                continuePreviousDay.add(pkgStats.mPackageName);
                stat.update(pkgStats.mPackageName, mDailyExpiryDate.getTimeInMillis() - 1, UsageEvents.Event.END_OF_DAY);
                notifyStatsChanged();
            }
        }
        stat.updateConfigurationStats(null, mDailyExpiryDate.getTimeInMillis() - 1);
    }
    persistActiveStats();
    mDatabase.prune(currentTimeMillis);
    loadActiveStats(currentTimeMillis);
    final int continueCount = continuePreviousDay.size();
    for (int i = 0; i < continueCount; i++) {
        String name = continuePreviousDay.valueAt(i);
        final long beginTime = mCurrentStats[UsageStatsManager.INTERVAL_DAILY].beginTime;
        for (IntervalStats stat : mCurrentStats) {
            stat.update(name, beginTime, UsageEvents.Event.CONTINUE_PREVIOUS_DAY);
            stat.updateConfigurationStats(previousConfig, beginTime);
            notifyStatsChanged();
        }
    }
    persistActiveStats();
    final long totalTime = SystemClock.elapsedRealtime() - startTime;
    Slog.i(TAG, mLogPrefix + "Rolling over usage stats complete. Took " + totalTime + " milliseconds");
}
Also used : ArraySet(android.util.ArraySet) Configuration(android.content.res.Configuration) UsageStats(android.app.usage.UsageStats)

Aggregations

ArraySet (android.util.ArraySet)521 PublicKey (java.security.PublicKey)94 ArrayList (java.util.ArrayList)87 ComponentName (android.content.ComponentName)82 ArrayMap (android.util.ArrayMap)73 Pair (android.util.Pair)47 RemoteException (android.os.RemoteException)43 ResolveInfo (android.content.pm.ResolveInfo)39 Intent (android.content.Intent)38 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)35 File (java.io.File)33 SSLContext (javax.net.ssl.SSLContext)32 IOException (java.io.IOException)31 PackageManager (android.content.pm.PackageManager)29 UserInfo (android.content.pm.UserInfo)28 ApplicationInfo (android.content.pm.ApplicationInfo)24 Point (android.graphics.Point)24 X509Certificate (java.security.cert.X509Certificate)20 PackageInfo (android.content.pm.PackageInfo)19 Test (org.junit.Test)19