Search in sources :

Example 1 with NoteOpEvent

use of android.app.AppOpsManager.NoteOpEvent in project robolectric by robolectric.

the class ShadowAppOpsManager method toOpEntry.

protected OpEntry toOpEntry(Integer op, int mode) {
    if (RuntimeEnvironment.getApiLevel() < Build.VERSION_CODES.M) {
        return ReflectionHelpers.callConstructor(OpEntry.class, ClassParameter.from(int.class, op), ClassParameter.from(int.class, mode), ClassParameter.from(long.class, OP_TIME), ClassParameter.from(long.class, REJECT_TIME), ClassParameter.from(int.class, DURATION));
    } else if (RuntimeEnvironment.getApiLevel() < Build.VERSION_CODES.Q) {
        return ReflectionHelpers.callConstructor(OpEntry.class, ClassParameter.from(int.class, op), ClassParameter.from(int.class, mode), ClassParameter.from(long.class, OP_TIME), ClassParameter.from(long.class, REJECT_TIME), ClassParameter.from(int.class, DURATION), ClassParameter.from(int.class, PROXY_UID), ClassParameter.from(String.class, PROXY_PACKAGE));
    } else if (RuntimeEnvironment.getApiLevel() < Build.VERSION_CODES.R) {
        final long key = AppOpsManager.makeKey(AppOpsManager.UID_STATE_TOP, AppOpsManager.OP_FLAG_SELF);
        final LongSparseLongArray accessTimes = new LongSparseLongArray();
        accessTimes.put(key, OP_TIME);
        final LongSparseLongArray rejectTimes = new LongSparseLongArray();
        rejectTimes.put(key, REJECT_TIME);
        final LongSparseLongArray durations = new LongSparseLongArray();
        durations.put(key, DURATION);
        final LongSparseLongArray proxyUids = new LongSparseLongArray();
        proxyUids.put(key, PROXY_UID);
        final LongSparseArray<String> proxyPackages = new LongSparseArray<>();
        proxyPackages.put(key, PROXY_PACKAGE);
        return ReflectionHelpers.callConstructor(OpEntry.class, ClassParameter.from(int.class, op), ClassParameter.from(boolean.class, false), ClassParameter.from(int.class, mode), ClassParameter.from(LongSparseLongArray.class, accessTimes), ClassParameter.from(LongSparseLongArray.class, rejectTimes), ClassParameter.from(LongSparseLongArray.class, durations), ClassParameter.from(LongSparseLongArray.class, proxyUids), ClassParameter.from(LongSparseArray.class, proxyPackages));
    } else {
        final long key = AppOpsManager.makeKey(AppOpsManager.UID_STATE_TOP, AppOpsManager.OP_FLAG_SELF);
        LongSparseArray<NoteOpEvent> accessEvents = new LongSparseArray<>();
        LongSparseArray<NoteOpEvent> rejectEvents = new LongSparseArray<>();
        accessEvents.put(key, new NoteOpEvent(OP_TIME, DURATION, new OpEventProxyInfo(PROXY_UID, PROXY_PACKAGE, null)));
        rejectEvents.put(key, new NoteOpEvent(REJECT_TIME, -1, null));
        return new OpEntry(op, mode, Collections.singletonMap(null, new AttributedOpEntry(op, false, accessEvents, rejectEvents)));
    }
}
Also used : LongSparseLongArray(android.util.LongSparseLongArray) LongSparseArray(android.util.LongSparseArray) NoteOpEvent(android.app.AppOpsManager.NoteOpEvent) AttributedOpEntry(android.app.AppOpsManager.AttributedOpEntry) OpEntry(android.app.AppOpsManager.OpEntry) OpEventProxyInfo(android.app.AppOpsManager.OpEventProxyInfo) AttributedOpEntry(android.app.AppOpsManager.AttributedOpEntry)

Aggregations

AttributedOpEntry (android.app.AppOpsManager.AttributedOpEntry)1 NoteOpEvent (android.app.AppOpsManager.NoteOpEvent)1 OpEntry (android.app.AppOpsManager.OpEntry)1 OpEventProxyInfo (android.app.AppOpsManager.OpEventProxyInfo)1 LongSparseArray (android.util.LongSparseArray)1 LongSparseLongArray (android.util.LongSparseLongArray)1