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;
}
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");
}
}
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);
}
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();
}
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);
}
Aggregations