Search in sources :

Example 1 with UsageStatsManagerInternal

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

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

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

the class NetworkPolicyManagerServiceTest method registerLocalServices.

@BeforeClass
public static void registerLocalServices() {
    addLocalServiceMock(PowerManagerInternal.class);
    addLocalServiceMock(DeviceIdleController.LocalService.class);
    final UsageStatsManagerInternal usageStats = addLocalServiceMock(UsageStatsManagerInternal.class);
    when(usageStats.getIdleUidsForUser(anyInt())).thenReturn(new int[] {});
}
Also used : UsageStatsManagerInternal(android.app.usage.UsageStatsManagerInternal) BeforeClass(org.junit.BeforeClass)

Example 3 with UsageStatsManagerInternal

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

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

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

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 5 with UsageStatsManagerInternal

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

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