Search in sources :

Example 56 with RequiresApi

use of androidx.annotation.RequiresApi in project ExoPlayer by google.

the class RequirementsWatcher method unregisterNetworkCallbackV24.

@RequiresApi(24)
private void unregisterNetworkCallbackV24() {
    ConnectivityManager connectivityManager = checkNotNull((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE));
    connectivityManager.unregisterNetworkCallback(checkNotNull(networkCallback));
    networkCallback = null;
}
Also used : ConnectivityManager(android.net.ConnectivityManager) RequiresApi(androidx.annotation.RequiresApi)

Example 57 with RequiresApi

use of androidx.annotation.RequiresApi in project Gadgetbridge by Freeyourgadget.

the class AbstractDeviceSupport method handleGBDeviceEventFindPhoneStartNotification.

@RequiresApi(Build.VERSION_CODES.Q)
private void handleGBDeviceEventFindPhoneStartNotification() {
    LOG.info("Got handleGBDeviceEventFindPhoneStartNotification");
    Intent intent = new Intent(context, FindPhoneActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder notification = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID).setSmallIcon(R.drawable.ic_notification).setOngoing(false).setFullScreenIntent(pi, true).setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true).setContentTitle(context.getString(R.string.find_my_phone_notification));
    notification.setGroup("BackgroundService");
    CompanionDeviceManager manager = (CompanionDeviceManager) context.getSystemService(Context.COMPANION_DEVICE_SERVICE);
    if (manager.getAssociations().size() > 0) {
        GB.notify(GB.NOTIFICATION_ID_PHONE_FIND, notification.build(), context);
        context.startActivity(intent);
        LOG.debug("CompanionDeviceManager associations were found, starting intent");
    } else {
        GB.notify(GB.NOTIFICATION_ID_PHONE_FIND, notification.build(), context);
        LOG.warn("CompanionDeviceManager associations were not found, can't start intent");
    }
}
Also used : CompanionDeviceManager(android.companion.CompanionDeviceManager) NotificationCompat(androidx.core.app.NotificationCompat) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RequiresApi(androidx.annotation.RequiresApi)

Example 58 with RequiresApi

use of androidx.annotation.RequiresApi in project mobile-center-sdk-android by Microsoft.

the class Distribute method showSystemAlertsWindowsSettingsDialog.

/**
 * Show system alerts windows setting dialog.
 */
@RequiresApi(api = Build.VERSION_CODES.Q)
private synchronized void showSystemAlertsWindowsSettingsDialog() {
    /* Do not attempt to show dialog if application is in the background. */
    if (mForegroundActivity == null) {
        AppCenterLog.warn(LOG_TAG, "The application is in background mode, the system alerts windows won't be displayed.");
        return;
    }
    /* Check if we need to replace dialog. */
    if (!shouldRefreshDialog(mAlertSystemWindowsDialog)) {
        return;
    }
    AppCenterLog.debug(LOG_TAG, "Show new system alerts windows dialog.");
    /* Build confirmation dialog on enabled system alerts windows permission. */
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mForegroundActivity);
    dialogBuilder.setMessage(R.string.appcenter_distribute_alert_system_dialog_message);
    dialogBuilder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            mAlertSystemWindowsDialog = null;
            AppCenterLog.debug(LOG_TAG, "Permission request on alert system windows denied. Continue installing...");
            /* It is optional and installing can be continued if customer reject permission request. */
            installUpdate();
        }
    });
    dialogBuilder.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            mAlertSystemWindowsDialog = null;
            AppCenterLog.debug(LOG_TAG, "Permission request on alert system windows denied. Continue installing...");
            /* It is optional and installing can be continued if customer reject permission request. */
            installUpdate();
        }
    });
    dialogBuilder.setPositiveButton(R.string.appcenter_distribute_unknown_sources_dialog_settings, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            /* Open system alerts windows settings activity. */
            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + mForegroundActivity.getPackageName()));
            mForegroundActivity.startActivity(intent);
        }
    });
    mAlertSystemWindowsDialog = dialogBuilder.create();
    showAndRememberDialogActivity(mAlertSystemWindowsDialog);
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint) RequiresApi(androidx.annotation.RequiresApi)

Example 59 with RequiresApi

use of androidx.annotation.RequiresApi in project mobile-center-sdk-android by Microsoft.

the class CryptoAesAndEtmHandler method getMacBytes.

@RequiresApi(api = Build.VERSION_CODES.M)
private byte[] getMacBytes(byte[] authKey, byte[] iv, byte[] cipherText) throws InvalidKeyException, NoSuchAlgorithmException {
    SecretKey macSecureKey = new SecretKeySpec(authKey, KeyProperties.KEY_ALGORITHM_HMAC_SHA256);
    Mac hMac = Mac.getInstance(KeyProperties.KEY_ALGORITHM_HMAC_SHA256);
    hMac.init(macSecureKey);
    hMac.update(iv);
    hMac.update(cipherText);
    return hMac.doFinal();
}
Also used : SecretKey(javax.crypto.SecretKey) SecretKeySpec(javax.crypto.spec.SecretKeySpec) Mac(javax.crypto.Mac) RequiresApi(androidx.annotation.RequiresApi)

Example 60 with RequiresApi

use of androidx.annotation.RequiresApi in project mobile-center-sdk-android by Microsoft.

the class CryptoAesAndEtmHandler method decrypt.

@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public byte[] decrypt(CryptoUtils.ICryptoFactory cryptoFactory, int apiLevel, KeyStore.Entry keyStoreEntry, byte[] data) throws Exception {
    ByteBuffer byteBuffer = ByteBuffer.wrap(data);
    // Check iv data.
    int ivLength = byteBuffer.get();
    if (ivLength != 16) {
        throw new IllegalArgumentException("Invalid IV length.");
    }
    byte[] iv = new byte[ivLength];
    byteBuffer.get(iv);
    // Check mac data.
    int macLength = (byteBuffer.get());
    if (macLength != 32) {
        throw new IllegalArgumentException("Invalid MAC length.");
    }
    byte[] actualHMac = new byte[macLength];
    byteBuffer.get(actualHMac);
    // Get cipher data.
    byte[] cipherText = new byte[byteBuffer.remaining()];
    byteBuffer.get(cipherText);
    // Get secure key and subkeys.
    SecretKey key = ((KeyStore.SecretKeyEntry) keyStoreEntry).getSecretKey();
    byte[] encryptionSubkey = getSubkey(key, ENCRYPTION_KEY_LENGTH);
    byte[] authenticationSubkey = getSubkey(key, AUTHENTICATION_KEY_LENGTH);
    // Calculate mac.
    byte[] expectedHMac = getMacBytes(authenticationSubkey, iv, cipherText);
    // Verity mac value in the encrypted message.
    if (!MessageDigest.isEqual(expectedHMac, actualHMac)) {
        throw new SecurityException("Could not authenticate MAC value.");
    }
    // Decrypt message.
    CryptoUtils.ICipher cipher = cryptoFactory.getCipher(CryptoConstants.CIPHER_AES, null);
    cipher.init(DECRYPT_MODE, new SecretKeySpec(encryptionSubkey, KeyProperties.KEY_ALGORITHM_AES), new IvParameterSpec(iv));
    return cipher.doFinal(cipherText);
}
Also used : SecretKey(javax.crypto.SecretKey) SecretKeySpec(javax.crypto.spec.SecretKeySpec) IvParameterSpec(javax.crypto.spec.IvParameterSpec) ByteBuffer(java.nio.ByteBuffer) RequiresApi(androidx.annotation.RequiresApi)

Aggregations

RequiresApi (androidx.annotation.RequiresApi)117 NotificationChannel (android.app.NotificationChannel)16 Intent (android.content.Intent)13 SuppressLint (android.annotation.SuppressLint)10 NotificationManager (android.app.NotificationManager)9 Uri (android.net.Uri)9 StatusBarNotification (android.service.notification.StatusBarNotification)9 NonNull (androidx.annotation.NonNull)9 IOException (java.io.IOException)8 Notification (android.app.Notification)6 PendingIntent (android.app.PendingIntent)6 Context (android.content.Context)6 ObjectAnimator (android.animation.ObjectAnimator)5 Bundle (android.os.Bundle)5 ByteBuffer (java.nio.ByteBuffer)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 SecretKey (javax.crypto.SecretKey)5 GestureDescription (android.accessibilityservice.GestureDescription)4 TaskStackBuilder (android.app.TaskStackBuilder)4 Bitmap (android.graphics.Bitmap)4