Search in sources :

Example 6 with UsageStatsManagerInternal

use of android.app.usage.UsageStatsManagerInternal in project android_frameworks_base by crdroidandroid.

the class UsageStatsBackupHelper method getBackupPayload.

@Override
protected byte[] getBackupPayload(String key) {
    if (KEY_USAGE_STATS.equals(key)) {
        UsageStatsManagerInternal localUsageStatsManager = LocalServices.getService(UsageStatsManagerInternal.class);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(baos);
        try {
            out.writeInt(UserHandle.USER_SYSTEM);
            out.write(localUsageStatsManager.getBackupPayload(UserHandle.USER_SYSTEM, key));
        } catch (IOException ioe) {
            if (DEBUG)
                Log.e(TAG, "Failed to backup Usage Stats", ioe);
            baos.reset();
        }
        return baos.toByteArray();
    }
    return null;
}
Also used : DataOutputStream(java.io.DataOutputStream) UsageStatsManagerInternal(android.app.usage.UsageStatsManagerInternal) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 7 with UsageStatsManagerInternal

use of android.app.usage.UsageStatsManagerInternal in project android_frameworks_base by crdroidandroid.

the class UsageStatsBackupHelper method applyRestoredPayload.

@Override
protected void applyRestoredPayload(String key, byte[] payload) {
    if (KEY_USAGE_STATS.equals(key)) {
        UsageStatsManagerInternal localUsageStatsManager = LocalServices.getService(UsageStatsManagerInternal.class);
        DataInputStream in = new DataInputStream(new ByteArrayInputStream(payload));
        try {
            int user = in.readInt();
            byte[] restoreData = new byte[payload.length - 4];
            in.read(restoreData, 0, restoreData.length);
            localUsageStatsManager.applyRestoredPayload(user, key, restoreData);
        } catch (IOException ioe) {
            if (DEBUG)
                Log.e(TAG, "Failed to restore Usage Stats", ioe);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) UsageStatsManagerInternal(android.app.usage.UsageStatsManagerInternal) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 8 with UsageStatsManagerInternal

use of android.app.usage.UsageStatsManagerInternal in project platform_frameworks_base by android.

the class UsageStatsBackupHelper method getBackupPayload.

@Override
protected byte[] getBackupPayload(String key) {
    if (KEY_USAGE_STATS.equals(key)) {
        UsageStatsManagerInternal localUsageStatsManager = LocalServices.getService(UsageStatsManagerInternal.class);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(baos);
        try {
            out.writeInt(UserHandle.USER_SYSTEM);
            out.write(localUsageStatsManager.getBackupPayload(UserHandle.USER_SYSTEM, key));
        } catch (IOException ioe) {
            if (DEBUG)
                Log.e(TAG, "Failed to backup Usage Stats", ioe);
            baos.reset();
        }
        return baos.toByteArray();
    }
    return null;
}
Also used : DataOutputStream(java.io.DataOutputStream) UsageStatsManagerInternal(android.app.usage.UsageStatsManagerInternal) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 9 with UsageStatsManagerInternal

use of android.app.usage.UsageStatsManagerInternal in project android_frameworks_base by AOSPA.

the class UsageStatsBackupHelper method getBackupPayload.

@Override
protected byte[] getBackupPayload(String key) {
    if (KEY_USAGE_STATS.equals(key)) {
        UsageStatsManagerInternal localUsageStatsManager = LocalServices.getService(UsageStatsManagerInternal.class);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(baos);
        try {
            out.writeInt(UserHandle.USER_SYSTEM);
            out.write(localUsageStatsManager.getBackupPayload(UserHandle.USER_SYSTEM, key));
        } catch (IOException ioe) {
            if (DEBUG)
                Log.e(TAG, "Failed to backup Usage Stats", ioe);
            baos.reset();
        }
        return baos.toByteArray();
    }
    return null;
}
Also used : DataOutputStream(java.io.DataOutputStream) UsageStatsManagerInternal(android.app.usage.UsageStatsManagerInternal) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 10 with UsageStatsManagerInternal

use of android.app.usage.UsageStatsManagerInternal in project android_frameworks_base by AOSPA.

the class UsageStatsBackupHelper method applyRestoredPayload.

@Override
protected void applyRestoredPayload(String key, byte[] payload) {
    if (KEY_USAGE_STATS.equals(key)) {
        UsageStatsManagerInternal localUsageStatsManager = LocalServices.getService(UsageStatsManagerInternal.class);
        DataInputStream in = new DataInputStream(new ByteArrayInputStream(payload));
        try {
            int user = in.readInt();
            byte[] restoreData = new byte[payload.length - 4];
            in.read(restoreData, 0, restoreData.length);
            localUsageStatsManager.applyRestoredPayload(user, key, restoreData);
        } catch (IOException ioe) {
            if (DEBUG)
                Log.e(TAG, "Failed to restore Usage Stats", ioe);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) UsageStatsManagerInternal(android.app.usage.UsageStatsManagerInternal) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Aggregations

UsageStatsManagerInternal (android.app.usage.UsageStatsManagerInternal)11 IOException (java.io.IOException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 DataInputStream (java.io.DataInputStream)5 DataOutputStream (java.io.DataOutputStream)5 BeforeClass (org.junit.BeforeClass)1