Search in sources :

Example 61 with FileNotFoundException

use of java.io.FileNotFoundException in project platform_frameworks_base by android.

the class LockSettingsService method setLockPatternInternal.

private void setLockPatternInternal(String pattern, String savedCredential, int userId) throws RemoteException {
    byte[] currentHandle = getCurrentHandle(userId);
    if (pattern == null) {
        clearUserKeyProtection(userId);
        getGateKeeperService().clearSecureUserId(userId);
        mStorage.writePatternHash(null, userId);
        setKeystorePassword(null, userId);
        fixateNewestUserKeyAuth(userId);
        onUserLockChanged(userId);
        return;
    }
    if (isManagedProfileWithUnifiedLock(userId)) {
        // get credential from keystore when managed profile has unified lock
        try {
            savedCredential = getDecryptedPasswordForTiedProfile(userId);
        } catch (UnrecoverableKeyException | InvalidKeyException | KeyStoreException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException | CertificateException | IOException e) {
            if (e instanceof FileNotFoundException) {
                Slog.i(TAG, "Child profile key not found");
            } else {
                Slog.e(TAG, "Failed to decrypt child profile key", e);
            }
        }
    } else {
        if (currentHandle == null) {
            if (savedCredential != null) {
                Slog.w(TAG, "Saved credential provided, but none stored");
            }
            savedCredential = null;
        }
    }
    byte[] enrolledHandle = enrollCredential(currentHandle, savedCredential, pattern, userId);
    if (enrolledHandle != null) {
        CredentialHash willStore = new CredentialHash(enrolledHandle, CredentialHash.VERSION_GATEKEEPER);
        setUserKeyProtection(userId, pattern, doVerifyPattern(pattern, willStore, true, 0, userId, null));
        mStorage.writePatternHash(enrolledHandle, userId);
        fixateNewestUserKeyAuth(userId);
        onUserLockChanged(userId);
    } else {
        throw new RemoteException("Failed to enroll pattern");
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) CredentialHash(com.android.server.LockSettingsStorage.CredentialHash) FileNotFoundException(java.io.FileNotFoundException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) CertificateException(java.security.cert.CertificateException) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BadPaddingException(javax.crypto.BadPaddingException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) RemoteException(android.os.RemoteException)

Example 62 with FileNotFoundException

use of java.io.FileNotFoundException in project platform_frameworks_base by android.

the class PersistentDataStore method load.

private void load() {
    clearState();
    final InputStream is;
    try {
        is = mAtomicFile.openRead();
    } catch (FileNotFoundException ex) {
        return;
    }
    XmlPullParser parser;
    try {
        parser = Xml.newPullParser();
        parser.setInput(new BufferedInputStream(is), StandardCharsets.UTF_8.name());
        loadFromXml(parser);
    } catch (IOException ex) {
        Slog.w(TAG, "Failed to load display manager persistent store data.", ex);
        clearState();
    } catch (XmlPullParserException ex) {
        Slog.w(TAG, "Failed to load display manager persistent store data.", ex);
        clearState();
    } finally {
        IoUtils.closeQuietly(is);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 63 with FileNotFoundException

use of java.io.FileNotFoundException in project platform_frameworks_base by android.

the class NetworkStatsCollection method readLegacyUid.

@Deprecated
public void readLegacyUid(File file, boolean onlyTags) throws IOException {
    final AtomicFile inputFile = new AtomicFile(file);
    DataInputStream in = null;
    try {
        in = new DataInputStream(new BufferedInputStream(inputFile.openRead()));
        // verify file magic header intact
        final int magic = in.readInt();
        if (magic != FILE_MAGIC) {
            throw new ProtocolException("unexpected magic: " + magic);
        }
        final int version = in.readInt();
        switch(version) {
            case VERSION_UID_INIT:
                {
                    // mapping into NetworkIdentitySet.
                    break;
                }
            case VERSION_UID_WITH_IDENT:
                {
                    // for a short time.
                    break;
                }
            case VERSION_UID_WITH_TAG:
            case VERSION_UID_WITH_SET:
                {
                    // uid := size *(NetworkIdentitySet size *(uid set tag NetworkStatsHistory))
                    final int identSize = in.readInt();
                    for (int i = 0; i < identSize; i++) {
                        final NetworkIdentitySet ident = new NetworkIdentitySet(in);
                        final int size = in.readInt();
                        for (int j = 0; j < size; j++) {
                            final int uid = in.readInt();
                            final int set = (version >= VERSION_UID_WITH_SET) ? in.readInt() : SET_DEFAULT;
                            final int tag = in.readInt();
                            final Key key = new Key(ident, uid, set, tag);
                            final NetworkStatsHistory history = new NetworkStatsHistory(in);
                            if ((tag == TAG_NONE) != onlyTags) {
                                recordHistory(key, history);
                            }
                        }
                    }
                    break;
                }
            default:
                {
                    throw new ProtocolException("unexpected version: " + version);
                }
        }
    } catch (FileNotFoundException e) {
    // missing stats is okay, probably first boot
    } finally {
        IoUtils.closeQuietly(in);
    }
}
Also used : ProtocolException(java.net.ProtocolException) AtomicFile(android.util.AtomicFile) BufferedInputStream(java.io.BufferedInputStream) FileNotFoundException(java.io.FileNotFoundException) NetworkStatsHistory(android.net.NetworkStatsHistory) DataInputStream(java.io.DataInputStream)

Example 64 with FileNotFoundException

use of java.io.FileNotFoundException in project platform_frameworks_base by android.

the class NetworkStatsCollection method readLegacyNetwork.

@Deprecated
public void readLegacyNetwork(File file) throws IOException {
    final AtomicFile inputFile = new AtomicFile(file);
    DataInputStream in = null;
    try {
        in = new DataInputStream(new BufferedInputStream(inputFile.openRead()));
        // verify file magic header intact
        final int magic = in.readInt();
        if (magic != FILE_MAGIC) {
            throw new ProtocolException("unexpected magic: " + magic);
        }
        final int version = in.readInt();
        switch(version) {
            case VERSION_NETWORK_INIT:
                {
                    // network := size *(NetworkIdentitySet NetworkStatsHistory)
                    final int size = in.readInt();
                    for (int i = 0; i < size; i++) {
                        final NetworkIdentitySet ident = new NetworkIdentitySet(in);
                        final NetworkStatsHistory history = new NetworkStatsHistory(in);
                        final Key key = new Key(ident, UID_ALL, SET_ALL, TAG_NONE);
                        recordHistory(key, history);
                    }
                    break;
                }
            default:
                {
                    throw new ProtocolException("unexpected version: " + version);
                }
        }
    } catch (FileNotFoundException e) {
    // missing stats is okay, probably first boot
    } finally {
        IoUtils.closeQuietly(in);
    }
}
Also used : ProtocolException(java.net.ProtocolException) AtomicFile(android.util.AtomicFile) BufferedInputStream(java.io.BufferedInputStream) FileNotFoundException(java.io.FileNotFoundException) NetworkStatsHistory(android.net.NetworkStatsHistory) DataInputStream(java.io.DataInputStream)

Example 65 with FileNotFoundException

use of java.io.FileNotFoundException in project platform_frameworks_base by android.

the class UserManagerService method getUserIcon.

@Override
public ParcelFileDescriptor getUserIcon(int targetUserId) {
    String iconPath;
    synchronized (mPackagesLock) {
        UserInfo targetUserInfo = getUserInfoNoChecks(targetUserId);
        if (targetUserInfo == null || targetUserInfo.partial) {
            Slog.w(LOG_TAG, "getUserIcon: unknown user #" + targetUserId);
            return null;
        }
        final int callingUserId = UserHandle.getCallingUserId();
        final int callingGroupId = getUserInfoNoChecks(callingUserId).profileGroupId;
        final int targetGroupId = targetUserInfo.profileGroupId;
        final boolean sameGroup = (callingGroupId != UserInfo.NO_PROFILE_GROUP_ID && callingGroupId == targetGroupId);
        if ((callingUserId != targetUserId) && !sameGroup) {
            checkManageUsersPermission("get the icon of a user who is not related");
        }
        if (targetUserInfo.iconPath == null) {
            return null;
        }
        iconPath = targetUserInfo.iconPath;
    }
    try {
        return ParcelFileDescriptor.open(new File(iconPath), ParcelFileDescriptor.MODE_READ_ONLY);
    } catch (FileNotFoundException e) {
        Log.e(LOG_TAG, "Couldn't find icon file", e);
    }
    return null;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) UserInfo(android.content.pm.UserInfo) AtomicFile(android.util.AtomicFile) File(java.io.File)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)3572 IOException (java.io.IOException)2027 File (java.io.File)1415 FileInputStream (java.io.FileInputStream)906 InputStream (java.io.InputStream)535 FileOutputStream (java.io.FileOutputStream)522 BufferedReader (java.io.BufferedReader)301 FileReader (java.io.FileReader)267 ArrayList (java.util.ArrayList)232 Path (org.apache.hadoop.fs.Path)224 Test (org.junit.Test)212 InputStreamReader (java.io.InputStreamReader)193 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)189 XmlPullParser (org.xmlpull.v1.XmlPullParser)166 BufferedInputStream (java.io.BufferedInputStream)154 URL (java.net.URL)139 ParcelFileDescriptor (android.os.ParcelFileDescriptor)131 FileStatus (org.apache.hadoop.fs.FileStatus)131 Properties (java.util.Properties)129 HashMap (java.util.HashMap)120