Search in sources :

Example 21 with VisibleForTesting

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;
}
Also used : JSONObject(org.json.JSONObject) Device(com.microsoft.appcenter.ingestion.models.Device) JSONException(org.json.JSONException) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 22 with VisibleForTesting

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;
    }
}
Also used : ErrorReport(com.microsoft.appcenter.crashes.model.ErrorReport) Log.getStackTraceString(android.util.Log.getStackTraceString) UUID(java.util.UUID) File(java.io.File) NativeException(com.microsoft.appcenter.crashes.model.NativeException) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 23 with VisibleForTesting

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;
        }
    }
}
Also used : AlertDialog(android.app.AlertDialog) Dialog(android.app.Dialog) VisibleForTesting(androidx.annotation.VisibleForTesting) UiThread(androidx.annotation.UiThread)

Example 24 with VisibleForTesting

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();
}
Also used : ByteBuffer(java.nio.ByteBuffer) Mac(javax.crypto.Mac) VisibleForTesting(androidx.annotation.VisibleForTesting) RequiresApi(androidx.annotation.RequiresApi)

Example 25 with VisibleForTesting

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();
}
Also used : AlertDialog(android.app.AlertDialog) NetworkCallback(android.net.ConnectivityManager.NetworkCallback) OnResume(com.android.settingslib.core.lifecycle.events.OnResume) WifiInfo(android.net.wifi.WifiInfo) FeatureFlags(com.android.settings.core.FeatureFlags) WifiTrackerFactory(com.android.settingslib.wifi.WifiTrackerFactory) NET_CAPABILITY_CAPTIVE_PORTAL(android.net.NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL) ImageView(android.widget.ImageView) PreferenceControllerMixin(com.android.settings.core.PreferenceControllerMixin) NET_CAPABILITY_VALIDATED(android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED) NetworkCapabilities(android.net.NetworkCapabilities) MetricsFeatureProvider(com.android.settingslib.core.instrumentation.MetricsFeatureProvider) Drawable(android.graphics.drawable.Drawable) LinkProperties(android.net.LinkProperties) InetAddress(java.net.InetAddress) NET_CAPABILITY_PARTIAL_CONNECTIVITY(android.net.NetworkCapabilities.NET_CAPABILITY_PARTIAL_CONNECTIVITY) RouteInfo(android.net.RouteInfo) Handler(android.os.Handler) Duration(java.time.Duration) Log(android.util.Log) WifiConfiguration(android.net.wifi.WifiConfiguration) R(com.android.settings.R) OnPause(com.android.settingslib.core.lifecycle.events.OnPause) ConnectivityManager(android.net.ConnectivityManager) PreferenceScreen(androidx.preference.PreferenceScreen) WifiDppUtils(com.android.settings.wifi.dpp.WifiDppUtils) TRANSPORT_WIFI(android.net.NetworkCapabilities.TRANSPORT_WIFI) IntentFilter(android.content.IntentFilter) LifecycleObserver(com.android.settingslib.core.lifecycle.LifecycleObserver) NetworkInfo(android.net.NetworkInfo) ActionButtonsPreference(com.android.settingslib.widget.ActionButtonsPreference) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BroadcastReceiver(android.content.BroadcastReceiver) Network(android.net.Network) Collectors(java.util.stream.Collectors) AlertDialog(android.app.AlertDialog) FeatureFlagUtils(android.util.FeatureFlagUtils) WifiDialog(com.android.settings.wifi.WifiDialog) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) BidiFormatter(androidx.core.text.BidiFormatter) Utils(com.android.settings.Utils) EntityHeaderController(com.android.settings.widget.EntityHeaderController) NetworkUtils(android.net.NetworkUtils) Context(android.content.Context) LayoutPreference(com.android.settingslib.widget.LayoutPreference) PreferenceCategory(androidx.preference.PreferenceCategory) Intent(android.content.Intent) PreferenceFragmentCompat(androidx.preference.PreferenceFragmentCompat) WifiDialogListener(com.android.settings.wifi.WifiDialog.WifiDialogListener) VectorDrawable(android.graphics.drawable.VectorDrawable) Toast(android.widget.Toast) FeatureFlagPersistent(com.android.settings.development.featureflags.FeatureFlagPersistent) AccessPoint(com.android.settingslib.wifi.AccessPoint) SettingsEnums(android.app.settings.SettingsEnums) TextUtils(android.text.TextUtils) LinkAddress(android.net.LinkAddress) NetworkRequest(android.net.NetworkRequest) Preference(androidx.preference.Preference) Inet4Address(java.net.Inet4Address) UnknownHostException(java.net.UnknownHostException) WifiManager(android.net.wifi.WifiManager) Inet6Address(java.net.Inet6Address) CountDownTimer(android.os.CountDownTimer) WifiUtils(com.android.settings.wifi.WifiUtils) Bitmap(android.graphics.Bitmap) StringJoiner(java.util.StringJoiner) WifiTracker(com.android.settingslib.wifi.WifiTracker) WifiDataUsageSummaryPreferenceController(com.android.settings.datausage.WifiDataUsageSummaryPreferenceController) Activity(android.app.Activity) VisibleForTesting(androidx.annotation.VisibleForTesting) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) VisibleForTesting(androidx.annotation.VisibleForTesting)

Aggregations

VisibleForTesting (androidx.annotation.VisibleForTesting)385 Intent (android.content.Intent)36 ArrayList (java.util.ArrayList)36 Context (android.content.Context)34 Bundle (android.os.Bundle)30 Uri (android.net.Uri)18 View (android.view.View)18 Preference (androidx.preference.Preference)18 TextView (android.widget.TextView)16 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)16 MetricsFeatureProvider (com.android.settingslib.core.instrumentation.MetricsFeatureProvider)16 SuppressLint (android.annotation.SuppressLint)15 Activity (android.app.Activity)14 RemoteException (android.os.RemoteException)14 SubscriptionInfo (android.telephony.SubscriptionInfo)12 ImageView (android.widget.ImageView)12 BluetoothDevice (android.bluetooth.BluetoothDevice)11 ComponentName (android.content.ComponentName)11 Drawable (android.graphics.drawable.Drawable)11 SharedPreferences (android.content.SharedPreferences)10