Search in sources :

Example 96 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by AOSPA.

the class CryptoHelper method createMac.

@NonNull
private byte[] createMac(@NonNull byte[] cipher, @NonNull byte[] iv) throws GeneralSecurityException {
    Mac mac = Mac.getInstance(MAC_ALGORITHM);
    mac.init(mMacKey);
    mac.update(cipher);
    mac.update(iv);
    return mac.doFinal();
}
Also used : Mac(javax.crypto.Mac) NonNull(android.annotation.NonNull)

Example 97 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by AOSPA.

the class DefaultPermissionGrantPolicy method readDefaultPermissionExceptionsLPw.

@NonNull
private ArrayMap<String, List<DefaultPermissionGrant>> readDefaultPermissionExceptionsLPw() {
    File dir = new File(Environment.getRootDirectory(), "etc/default-permissions");
    if (!dir.exists() || !dir.isDirectory() || !dir.canRead()) {
        return new ArrayMap<>(0);
    }
    File[] files = dir.listFiles();
    if (files == null) {
        return new ArrayMap<>(0);
    }
    ArrayMap<String, List<DefaultPermissionGrant>> grantExceptions = new ArrayMap<>();
    // Iterate over the files in the directory and scan .xml files
    for (File file : files) {
        if (!file.getPath().endsWith(".xml")) {
            Slog.i(TAG, "Non-xml file " + file + " in " + dir + " directory, ignoring");
            continue;
        }
        if (!file.canRead()) {
            Slog.w(TAG, "Default permissions file " + file + " cannot be read");
            continue;
        }
        try (InputStream str = new BufferedInputStream(new FileInputStream(file))) {
            XmlPullParser parser = Xml.newPullParser();
            parser.setInput(str, null);
            parse(parser, grantExceptions);
        } catch (XmlPullParserException | IOException e) {
            Slog.w(TAG, "Error reading default permissions file " + file, e);
        }
    }
    return grantExceptions;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) ArrayMap(android.util.ArrayMap) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) ArrayList(java.util.ArrayList) List(java.util.List) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) File(java.io.File) NonNull(android.annotation.NonNull)

Example 98 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by AOSPA.

the class Main method setUp.

/**
     * Initialize the bridge and the resource maps.
     */
@BeforeClass
public static void setUp() {
    File data_dir = new File(PLATFORM_DIR, "data");
    File res = new File(data_dir, "res");
    sFrameworkRepo = new FrameworkResources(new FolderWrapper(res));
    sFrameworkRepo.loadResources();
    sFrameworkRepo.loadPublicResources(getLogger());
    sProjectResources = new ResourceRepository(new FolderWrapper(TEST_RES_DIR + APP_TEST_RES), false) {

        @NonNull
        @Override
        protected ResourceItem createResourceItem(@NonNull String name) {
            return new ResourceItem(name);
        }
    };
    sProjectResources.loadResources();
    File fontLocation = new File(data_dir, "fonts");
    File buildProp = new File(PLATFORM_DIR, "build.prop");
    File attrs = new File(res, "values" + File.separator + "attrs.xml");
    sBridge = new Bridge();
    sBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, ConfigGenerator.getEnumMap(attrs), getLayoutLog());
}
Also used : FrameworkResources(com.android.ide.common.resources.FrameworkResources) NonNull(android.annotation.NonNull) FolderWrapper(com.android.io.FolderWrapper) ResourceRepository(com.android.ide.common.resources.ResourceRepository) ResourceItem(com.android.ide.common.resources.ResourceItem) File(java.io.File) Bridge(com.android.layoutlib.bridge.Bridge) BeforeClass(org.junit.BeforeClass)

Example 99 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by AOSPA.

the class ParserFactory method readAndClose.

@NonNull
private static InputStream readAndClose(@NonNull InputStream stream, @Nullable String name, long size) throws XmlPullParserException {
    // just a sanity check. It's doubtful we'll have such big files!
    if (size > Integer.MAX_VALUE) {
        throw new XmlPullParserException("File " + name + " is too big to be parsed");
    }
    int intSize = (int) size;
    // create a buffered reader to facilitate reading.
    BufferedInputStream bufferedStream = new BufferedInputStream(stream);
    try {
        int avail;
        if (intSize != -1) {
            avail = intSize;
        } else {
            // get the size to read.
            avail = bufferedStream.available();
        }
        // create the initial buffer and read it.
        byte[] buffer = new byte[avail];
        int read = stream.read(buffer);
        // this is the easy case.
        if (read == intSize) {
            return new ByteArrayInputStream(buffer);
        }
        // available() returned!)
        while ((avail = bufferedStream.available()) > 0) {
            if (read + avail > buffer.length) {
                // just allocate what is needed. We're mostly reading small files
                // so it shouldn't be too problematic.
                byte[] moreBuffer = new byte[read + avail];
                System.arraycopy(buffer, 0, moreBuffer, 0, read);
                buffer = moreBuffer;
            }
            read += stream.read(buffer, read, avail);
        }
        // return a new stream encapsulating this buffer.
        return new ByteArrayInputStream(buffer);
    } catch (IOException e) {
        throw new XmlPullParserException("Failed to read " + name, null, e);
    } finally {
        try {
            bufferedStream.close();
        } catch (IOException ignored) {
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) NonNull(android.annotation.NonNull)

Example 100 with NonNull

use of android.annotation.NonNull in project android_frameworks_base by AOSPA.

the class Layout method createContentFrame.

@NonNull
private FrameLayout createContentFrame() {
    FrameLayout contentRoot = new FrameLayout(getContext());
    LayoutParams params = createLayoutParams(MATCH_PARENT, MATCH_PARENT);
    int rule = mBuilder.isNavBarVertical() ? START_OF : ABOVE;
    if (mBuilder.hasNavBar() && mBuilder.solidBars()) {
        params.addRule(rule, getId(ID_NAV_BAR));
    }
    int below = -1;
    if (mBuilder.mActionBarSize <= 0 && mBuilder.mTitleBarSize > 0) {
        below = getId(ID_TITLE_BAR);
    } else if (mBuilder.hasStatusBar() && mBuilder.solidBars()) {
        below = getId(ID_STATUS_BAR);
    }
    if (below != -1) {
        params.addRule(BELOW, below);
    }
    contentRoot.setLayoutParams(params);
    return contentRoot;
}
Also used : FrameLayout(android.widget.FrameLayout) NonNull(android.annotation.NonNull)

Aggregations

NonNull (android.annotation.NonNull)322 ArrayList (java.util.ArrayList)46 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)45 IOException (java.io.IOException)35 ComponentName (android.content.ComponentName)25 File (java.io.File)22 XmlPullParser (org.xmlpull.v1.XmlPullParser)20 Intent (android.content.Intent)18 EphemeralResolveInfo (android.content.pm.EphemeralResolveInfo)16 ResolveInfo (android.content.pm.ResolveInfo)16 Bundle (android.os.Bundle)15 RemoteException (android.os.RemoteException)15 FileNotFoundException (java.io.FileNotFoundException)15 Paint (android.graphics.Paint)14 PackageParser (android.content.pm.PackageParser)12 ContentResolver (android.content.ContentResolver)10 UserInfo (android.content.pm.UserInfo)10 StorageManager (android.os.storage.StorageManager)10 VolumeInfo (android.os.storage.VolumeInfo)10 KeyCharacteristics (android.security.keymaster.KeyCharacteristics)10