use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.
the class ShadowAppOpsManager method getPackagesForOps.
/**
* Returns app op details for all packages for which one of {@link #setMode} methods was used to
* set the value of one of the given app ops (it does return those set to 'default' mode, while
* the true implementation usually doesn't). Also, we don't enforce any permission checks which
* might be needed in the true implementation.
*
* @param ops The set of operations you are interested in, or null if you want all of them.
* @return app ops information about each package, containing only ops that were specified as an
* argument
*/
// to be consistent with setMode() shadow implementations
@Implementation(minSdk = KITKAT)
@HiddenApi
protected List<PackageOps> getPackagesForOps(int[] ops) {
Set<Integer> relevantOps;
if (ops != null) {
relevantOps = IntStream.of(ops).boxed().collect(toSet());
} else {
relevantOps = new HashSet<>();
}
// Aggregating op data per each package.
// (uid, packageName) => [(op, mode)]
Multimap<Key, OpEntry> perPackageMap = MultimapBuilder.hashKeys().hashSetValues().build();
for (Map.Entry<Key, Integer> appOpInfo : appModeMap.entrySet()) {
Key key = appOpInfo.getKey();
if (ops == null || relevantOps.contains(key.getOpCode())) {
Key packageKey = Key.create(key.getUid(), key.getPackageName(), null);
OpEntry opEntry = toOpEntry(key.getOpCode(), appOpInfo.getValue());
perPackageMap.put(packageKey, opEntry);
}
}
List<PackageOps> result = new ArrayList<>();
// Creating resulting PackageOps objects using all op info collected per package.
for (Map.Entry<Key, Collection<OpEntry>> packageInfo : perPackageMap.asMap().entrySet()) {
Key key = packageInfo.getKey();
result.add(new PackageOps(key.getPackageName(), key.getUid(), new ArrayList<>(packageInfo.getValue())));
}
return result.isEmpty() ? null : result;
}
use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.
the class ShadowAppOpsManager method getOpsForPackage.
@Implementation(minSdk = KITKAT)
@HiddenApi
public List<PackageOps> getOpsForPackage(int uid, String packageName, int[] ops) {
Set<Integer> opFilter = new HashSet<>();
if (ops != null) {
for (int op : ops) {
opFilter.add(op);
}
}
List<OpEntry> opEntries = new ArrayList<>();
for (Integer op : storedOps.get(Key.create(uid, packageName, null))) {
if (opFilter.isEmpty() || opFilter.contains(op)) {
opEntries.add(toOpEntry(op, AppOpsManager.MODE_ALLOWED));
}
}
return ImmutableList.of(new PackageOps(packageName, uid, opEntries));
}
use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.
the class ShadowArscAssetManager method readAssetChar.
@HiddenApi
@Implementation(minSdk = LOLLIPOP)
protected final int readAssetChar(long asset) {
Asset a = getAsset(asset);
byte[] b = new byte[1];
int res = a.read(b, 1);
return res == 1 ? b[0] & 0xff : -1;
}
use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.
the class ShadowArscAssetManager method getArrayIntResource.
@HiddenApi
@Implementation
public int[] getArrayIntResource(int arrayResId) {
CppAssetManager am = assetManagerForJavaObject();
if (am == null) {
return null;
}
final ResTable res = am.getResources();
// final ResTable::bag_entry* startOfBag;
final Ref<bag_entry[]> startOfBag = new Ref<>(null);
final int N = res.lockBag(arrayResId, startOfBag);
if (N < 0) {
return null;
}
int[] array = new int[N];
if (array == null) {
res.unlockBag(startOfBag);
return null;
}
final Ref<Res_value> valueRef = new Ref<>(null);
bag_entry[] bag = startOfBag.get();
for (int i = 0; i < N; i++) {
valueRef.set(bag[i].map.value);
// Take care of resolving the found resource to its final value.
int block = res.resolveReference(valueRef, bag[i].stringBlock, null, null, null);
if (kThrowOnBadId) {
if (block == BAD_INDEX) {
// seems like this is missing from android_util_AssetManager.cpp?
res.unlockBag(startOfBag);
throw new IllegalStateException("Bad resource!");
// return array;
}
}
Res_value value = valueRef.get();
if (value.dataType >= DataType.TYPE_FIRST_INT && value.dataType <= DataType.TYPE_LAST_INT) {
int intVal = value.data;
// env->SetIntArrayRegion(array, i, 1, &intVal);
array[i] = intVal;
}
}
res.unlockBag(startOfBag);
return array;
}
use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.
the class ShadowArscAssetManager method openNonAssetNative.
@HiddenApi
@Implementation
protected final Number openNonAssetNative(int cookie, String fileName, int accessMode) throws FileNotFoundException {
CppAssetManager am = assetManagerForJavaObject();
if (am == null) {
return RuntimeEnvironment.castNativePtr(0);
}
ALOGV("openNonAssetNative in %s (Java object %s)\n", am, AssetManager.class);
String fileName8 = fileName;
if (fileName8 == null) {
return RuntimeEnvironment.castNativePtr(-1);
}
AccessMode mode = AccessMode.fromInt(accessMode);
if (mode != Asset.AccessMode.ACCESS_UNKNOWN && mode != Asset.AccessMode.ACCESS_RANDOM && mode != Asset.AccessMode.ACCESS_STREAMING && mode != Asset.AccessMode.ACCESS_BUFFER) {
throw new IllegalArgumentException("Bad access mode");
}
Asset a = isTruthy(cookie) ? am.openNonAsset(cookie, fileName8, mode) : am.openNonAsset(fileName8, mode, null);
if (a == null) {
throw new FileNotFoundException(fileName8);
}
long assetId = Registries.NATIVE_ASSET_REGISTRY.register(a);
// todo: something better than this [xw]
a.onClose = () -> destroyAsset(assetId);
// printf("Created Asset Stream: %p\n", a);
return RuntimeEnvironment.castNativePtr(assetId);
}
Aggregations