use of androidx.annotation.VisibleForTesting in project mobile-center-sdk-android by Microsoft.
the class ErrorLogHelper method parseDevice.
/**
* Look for 'deviceInfo' data in file inside the minidump folder and parse it.
* @param contextInformation - data with information about userId.
* @return deviceInfo or null.
*/
@VisibleForTesting
static Device parseDevice(String contextInformation) {
try {
Device device = new Device();
JSONObject jsonObject = new JSONObject(contextInformation);
JSONObject deviceJson;
if (jsonObject.has(DEVICE_INFO_KEY)) {
deviceJson = new JSONObject(jsonObject.getString(DEVICE_INFO_KEY));
} else {
deviceJson = jsonObject;
}
device.read(deviceJson);
return device;
} catch (JSONException e) {
AppCenterLog.error(Crashes.LOG_TAG, "Failed to deserialize device info.", e);
}
return null;
}
use of androidx.annotation.VisibleForTesting in project mobile-center-sdk-android by Microsoft.
the class Crashes method buildErrorReport.
@VisibleForTesting
ErrorReport buildErrorReport(ManagedErrorLog log) {
UUID id = log.getId();
if (mErrorReportCache.containsKey(id)) {
ErrorReport report = mErrorReportCache.get(id).report;
report.setDevice(log.getDevice());
return report;
} else {
String stackTrace = null;
/* If exception in the log doesn't have stack trace try get it from the .throwable file. */
File file = ErrorLogHelper.getStoredThrowableFile(id);
if (file != null) {
if (file.length() > 0) {
stackTrace = FileManager.read(file);
}
}
if (stackTrace == null) {
if (MINIDUMP_FILE.equals(log.getException().getType())) {
stackTrace = getStackTraceString(new NativeException());
} else {
stackTrace = buildStackTrace(log.getException());
}
}
ErrorReport report = ErrorLogHelper.getErrorReportFromErrorLog(log, stackTrace);
mErrorReportCache.put(id, new ErrorLogReport(log, report));
return report;
}
}
use of androidx.annotation.VisibleForTesting in project mobile-center-sdk-android by Microsoft.
the class Distribute method notifyInstallProgress.
@UiThread
@VisibleForTesting
synchronized void notifyInstallProgress(boolean isInProgress) {
mInstallInProgress = isInProgress;
if (isInProgress) {
/* Do not attempt to show dialog if application is in the background. */
if (mForegroundActivity == null) {
AppCenterLog.warn(LOG_TAG, "Could not display install progress dialog in the background.");
return;
}
if (mReleaseInstallerListener == null) {
return;
}
/* Close to avoid dialog duplicates. */
mReleaseInstallerListener.hideInstallProgressDialog();
/* Create and show a new dialog. */
Dialog progressDialog = mReleaseInstallerListener.showInstallProgressDialog(mForegroundActivity);
showAndRememberDialogActivity(progressDialog);
} else {
if (mReleaseInstallerListener != null) {
mReleaseInstallerListener.hideInstallProgressDialog();
mReleaseInstallerListener = null;
}
}
}
use of androidx.annotation.VisibleForTesting in project mobile-center-sdk-android by Microsoft.
the class CryptoAesAndEtmHandler method getSubkey.
/**
* Get subkey from the secret key.
* This method uses HKDF simple key derivation function (KDF) based on a hash-based message authentication code (HMAC).
* See more: https://en.wikipedia.org/wiki/HKDF
*
* @param secretKey - secret key.
* @param outputDataLength - subkey length.
* @return byte array of the calculated subkey.
* @throws NoSuchAlgorithmException
* @throws InvalidKeyException
*/
@RequiresApi(api = Build.VERSION_CODES.M)
@VisibleForTesting
byte[] getSubkey(@NonNull SecretKey secretKey, int outputDataLength) throws NoSuchAlgorithmException, InvalidKeyException {
if (outputDataLength < 1) {
throw new IllegalArgumentException("Output data length must be greater than zero.");
}
// Init mac.
Mac hMac = Mac.getInstance(KeyProperties.KEY_ALGORITHM_HMAC_SHA256);
hMac.init(secretKey);
// Prepare array and calculate count of iterations.
int iterations = (int) Math.ceil(((double) outputDataLength) / ((double) hMac.getMacLength()));
if (iterations > 255) {
throw new IllegalArgumentException("Output data length must be maximum of 255 * hash-length.");
}
// Calculate subkey.
byte[] tempBlock = new byte[0];
ByteBuffer buffer = ByteBuffer.allocate(outputDataLength);
int restBytes = outputDataLength;
int stepSize;
for (int i = 0; i < iterations; i++) {
hMac.update(tempBlock);
hMac.update((byte) (i + 1));
tempBlock = hMac.doFinal();
stepSize = Math.min(restBytes, tempBlock.length);
buffer.put(tempBlock, 0, stepSize);
restBytes -= stepSize;
}
return buffer.array();
}
use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class WifiDetailPreferenceController method showConfirmForgetDialog.
@VisibleForTesting
protected void showConfirmForgetDialog() {
final AlertDialog dialog = new AlertDialog.Builder(mContext).setPositiveButton(R.string.forget, ((dialog1, which) -> {
try {
mWifiManager.removePasspointConfiguration(mAccessPoint.getPasspointFqdn());
} catch (RuntimeException e) {
Log.e(TAG, "Failed to remove Passpoint configuration for " + mAccessPoint.getPasspointFqdn());
}
mMetricsFeatureProvider.action(mFragment.getActivity(), SettingsEnums.ACTION_WIFI_FORGET);
mFragment.getActivity().finish();
})).setNegativeButton(R.string.cancel, null).setTitle(R.string.wifi_forget_dialog_title).setMessage(R.string.forget_passpoint_dialog_message).create();
dialog.show();
}
Aggregations