Search in sources :

Example 36 with RequiresApi

use of androidx.annotation.RequiresApi in project Signal-Android by WhisperSystems.

the class KeyStoreHelper method seal.

@RequiresApi(Build.VERSION_CODES.M)
public static SealedData seal(@NonNull byte[] input) {
    SecretKey secretKey = getOrCreateKeyStoreEntry();
    try {
        Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);
        byte[] iv = cipher.getIV();
        byte[] data = cipher.doFinal(input);
        return new SealedData(iv, data);
    } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) {
        throw new AssertionError(e);
    }
}
Also used : SecretKey(javax.crypto.SecretKey) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) Cipher(javax.crypto.Cipher) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BadPaddingException(javax.crypto.BadPaddingException) InvalidKeyException(java.security.InvalidKeyException) RequiresApi(androidx.annotation.RequiresApi)

Example 37 with RequiresApi

use of androidx.annotation.RequiresApi in project Signal-Android by WhisperSystems.

the class KeyStoreHelper method hasKeyStoreEntry.

@RequiresApi(Build.VERSION_CODES.M)
private static boolean hasKeyStoreEntry() {
    try {
        KeyStore ks = KeyStore.getInstance(ANDROID_KEY_STORE);
        ks.load(null);
        return ks.containsAlias(KEY_ALIAS) && ks.entryInstanceOf(KEY_ALIAS, KeyStore.SecretKeyEntry.class);
    } catch (KeyStoreException | IOException | NoSuchAlgorithmException | CertificateException e) {
        throw new AssertionError(e);
    }
}
Also used : CertificateException(java.security.cert.CertificateException) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStore(java.security.KeyStore) RequiresApi(androidx.annotation.RequiresApi)

Example 38 with RequiresApi

use of androidx.annotation.RequiresApi in project Signal-Android by WhisperSystems.

the class CameraXUtil method toJpeg.

@SuppressWarnings("SuspiciousNameCombination")
@RequiresApi(21)
public static ImageResult toJpeg(@NonNull ImageProxy image, boolean flip) throws IOException {
    ImageProxy.PlaneProxy[] planes = image.getPlanes();
    ByteBuffer buffer = planes[0].getBuffer();
    Rect cropRect = shouldCropImage(image) ? image.getCropRect() : null;
    byte[] data = new byte[buffer.capacity()];
    int rotation = image.getImageInfo().getRotationDegrees();
    buffer.get(data);
    try {
        Pair<Integer, Integer> dimens = BitmapUtil.getDimensions(new ByteArrayInputStream(data));
        if (dimens.first != image.getWidth() && dimens.second != image.getHeight()) {
            Log.w(TAG, String.format(Locale.ENGLISH, "Decoded image dimensions differed from stated dimensions! Stated: %d x %d, Decoded: %d x %d", image.getWidth(), image.getHeight(), dimens.first, dimens.second));
            Log.w(TAG, "Ignoring the stated rotation and rotating the crop rect 90 degrees (stated rotation is " + rotation + " degrees).");
            rotation = 0;
            if (cropRect != null) {
                cropRect = new Rect(cropRect.top, cropRect.left, cropRect.bottom, cropRect.right);
            }
        }
    } catch (BitmapDecodingException e) {
        Log.w(TAG, "Failed to decode!", e);
    }
    if (cropRect != null || rotation != 0 || flip) {
        data = transformByteArray(data, cropRect, rotation, flip);
    }
    int width = cropRect != null ? (cropRect.right - cropRect.left) : image.getWidth();
    int height = cropRect != null ? (cropRect.bottom - cropRect.top) : image.getHeight();
    if (rotation == 90 || rotation == 270) {
        int swap = width;
        width = height;
        height = swap;
    }
    return new ImageResult(data, width, height);
}
Also used : Rect(android.graphics.Rect) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteBuffer(java.nio.ByteBuffer) SuppressLint(android.annotation.SuppressLint) BitmapDecodingException(org.thoughtcrime.securesms.util.BitmapDecodingException) RequiresApi(androidx.annotation.RequiresApi)

Example 39 with RequiresApi

use of androidx.annotation.RequiresApi in project Signal-Android by WhisperSystems.

the class BackupUtil method getAllBackupsNewestFirstApi29.

@RequiresApi(29)
private static List<BackupInfo> getAllBackupsNewestFirstApi29() {
    Uri backupDirectoryUri = SignalStore.settings().getSignalBackupDirectory();
    if (backupDirectoryUri == null) {
        Log.i(TAG, "Backup directory is not set. Returning an empty list.");
        return Collections.emptyList();
    }
    DocumentFile backupDirectory = DocumentFile.fromTreeUri(ApplicationDependencies.getApplication(), backupDirectoryUri);
    if (backupDirectory == null || !backupDirectory.exists() || !backupDirectory.canRead()) {
        Log.w(TAG, "Backup directory is inaccessible. Returning an empty list.");
        return Collections.emptyList();
    }
    DocumentFile[] files = backupDirectory.listFiles();
    List<BackupInfo> backups = new ArrayList<>(files.length);
    for (DocumentFile file : files) {
        if (file.isFile() && file.getName() != null && file.getName().endsWith(".backup")) {
            long backupTimestamp = getBackupTimestamp(file.getName());
            if (backupTimestamp != -1) {
                backups.add(new BackupInfo(backupTimestamp, file.length(), file.getUri()));
            }
        }
    }
    Collections.sort(backups, (a, b) -> Long.compare(b.timestamp, a.timestamp));
    return backups;
}
Also used : DocumentFile(androidx.documentfile.provider.DocumentFile) ArrayList(java.util.ArrayList) Uri(android.net.Uri) RequiresApi(androidx.annotation.RequiresApi)

Example 40 with RequiresApi

use of androidx.annotation.RequiresApi in project xabber-android by redsolution.

the class NotificationChannelUtils method createPresistentConnectionChannel.

@RequiresApi(api = Build.VERSION_CODES.O)
public static String createPresistentConnectionChannel(NotificationManager notifManager) {
    NotificationChannel channel = new NotificationChannel(PERSISTENT_CONNECTION_CHANNEL_ID, getString(R.string.channel_persistent_connection_title), android.app.NotificationManager.IMPORTANCE_NONE);
    channel.setShowBadge(false);
    channel.setDescription(getString(R.string.channel_persistent_connection_description));
    notifManager.createNotificationChannel(channel);
    return channel.getId();
}
Also used : NotificationChannel(android.app.NotificationChannel) RequiresApi(androidx.annotation.RequiresApi)

Aggregations

RequiresApi (androidx.annotation.RequiresApi)161 NotificationChannel (android.app.NotificationChannel)20 Intent (android.content.Intent)16 NonNull (androidx.annotation.NonNull)16 SuppressLint (android.annotation.SuppressLint)14 Uri (android.net.Uri)14 NotificationManager (android.app.NotificationManager)13 IOException (java.io.IOException)13 StatusBarNotification (android.service.notification.StatusBarNotification)10 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)10 Context (android.content.Context)9 Rect (android.graphics.Rect)8 Notification (android.app.Notification)7 ByteBuffer (java.nio.ByteBuffer)7 ArrayList (java.util.ArrayList)7 SecretKey (javax.crypto.SecretKey)7 PendingIntent (android.app.PendingIntent)6 Bitmap (android.graphics.Bitmap)5 Point (android.graphics.Point)5 Build (android.os.Build)5