use of android.content.res.Resources.NotFoundException in project platform_frameworks_base by android.
the class PackageManagerTests method getInstallablePackage.
Uri getInstallablePackage(int fileResId, File outFile) {
Resources res = mContext.getResources();
InputStream is = null;
try {
is = res.openRawResource(fileResId);
} catch (NotFoundException e) {
failStr("Failed to load resource with id: " + fileResId);
}
FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IRWXO, -1, -1);
assertTrue(FileUtils.copyToFile(is, outFile));
FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IRWXO, -1, -1);
return Uri.fromFile(outFile);
}
use of android.content.res.Resources.NotFoundException in project platform_frameworks_base by android.
the class MountServiceTests method copyRawToFile.
private void copyRawToFile(int rawResId, File outFile) {
Resources res = mContext.getResources();
InputStream is = null;
try {
is = res.openRawResource(rawResId);
} catch (NotFoundException e) {
fail("Failed to load resource with id: " + rawResId);
}
FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IRWXO, -1, -1);
assertTrue(FileUtils.copyToFile(is, outFile));
FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IRWXO, -1, -1);
}
use of android.content.res.Resources.NotFoundException in project android_frameworks_base by DirtyUnicorns.
the class InputManagerService method getKeyboardLayoutOverlay.
// Native callback.
private String[] getKeyboardLayoutOverlay(InputDeviceIdentifier identifier) {
if (!mSystemReady) {
return null;
}
String keyboardLayoutDescriptor = getCurrentKeyboardLayoutForInputDevice(identifier);
if (keyboardLayoutDescriptor == null) {
return null;
}
final String[] result = new String[2];
visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {
@Override
public void visitKeyboardLayout(Resources resources, int keyboardLayoutResId, KeyboardLayout layout) {
try {
result[0] = layout.getDescriptor();
result[1] = Streams.readFully(new InputStreamReader(resources.openRawResource(keyboardLayoutResId)));
} catch (IOException ex) {
} catch (NotFoundException ex) {
}
}
});
if (result[0] == null) {
Slog.w(TAG, "Could not get keyboard layout with descriptor '" + keyboardLayoutDescriptor + "'.");
return null;
}
return result;
}
use of android.content.res.Resources.NotFoundException in project android_frameworks_base by DirtyUnicorns.
the class BridgeTypedArray method getTextArray.
/**
* Retrieve the CharSequence[] for the attribute at <var>index</var>.
* This gets the resource ID of the selected attribute, and uses
* {@link Resources#getTextArray Resources.getTextArray} of the owning
* Resources object to retrieve its String[].
*
* @param index Index of attribute to retrieve.
*
* @return CharSequence[] for the attribute, or null if not defined.
*/
@Override
public CharSequence[] getTextArray(int index) {
if (!hasValue(index)) {
return null;
}
ResourceValue resVal = mResourceData[index];
if (resVal instanceof ArrayResourceValue) {
ArrayResourceValue array = (ArrayResourceValue) resVal;
int count = array.getElementCount();
return count >= 0 ? Resources_Delegate.fillValues(mBridgeResources, array, new CharSequence[count]) : null;
}
int id = getResourceId(index, 0);
String resIdMessage = id > 0 ? " (resource id 0x" + Integer.toHexString(id) + ')' : "";
throw new NotFoundException(String.format("%1$s in %2$s%3$s is not a valid array resource.", resVal.getValue(), mNames[index], resIdMessage));
}
use of android.content.res.Resources.NotFoundException in project android_frameworks_base by DirtyUnicorns.
the class Resources_Delegate method openRawResource.
@LayoutlibDelegate
static InputStream openRawResource(Resources resources, int id, TypedValue value) throws NotFoundException {
getValue(resources, id, value, true);
String path = value.string.toString();
File f = new File(path);
if (f.isFile()) {
try {
// and actually load it as a 9-patch instead of a normal bitmap
if (path.toLowerCase().endsWith(NinePatch.EXTENSION_9PATCH)) {
return new NinePatchInputStream(f);
}
return new FileInputStream(f);
} catch (FileNotFoundException e) {
NotFoundException exception = new NotFoundException();
exception.initCause(e);
throw exception;
}
}
throw new NotFoundException();
}
Aggregations