Example usage for android.util Log getStackTraceString

List of usage examples for android.util Log getStackTraceString

Introduction

In this page you can find the example usage for android.util Log getStackTraceString.

Prototype

public static String getStackTraceString(Throwable tr) 

Source Link

Document

Handy function to get a loggable stack trace from a Throwable

Usage

From source file:com.yeldi.yeldibazaar.ManageRepo.java

private void redraw() {
    try {//from ww  w .  j  a v a 2  s  .co m
        DB db = DB.getDB();
        repos = db.getRepos();
    } finally {
        DB.releaseDB();
    }

    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
    Map<String, Object> server_line;

    for (DB.Repo repo : repos) {
        server_line = new HashMap<String, Object>();
        server_line.put("address", repo.address);
        if (repo.inuse) {
            server_line.put("inuse", R.drawable.btn_check_on);
        } else {
            server_line.put("inuse", R.drawable.btn_check_off);
        }
        if (repo.pubkey != null) {
            try {
                MessageDigest digest = MessageDigest.getInstance("SHA-1");
                digest.update(Hasher.unhex(repo.pubkey));
                byte[] fingerprint = digest.digest();
                Formatter formatter = new Formatter(new StringBuilder());
                formatter.format("%02X", fingerprint[0]);
                for (int i = 1; i < fingerprint.length; i++) {
                    formatter.format(i % 5 == 0 ? " %02X" : ":%02X", fingerprint[i]);
                }
                server_line.put("fingerprint", formatter.toString());
                formatter.close();
            } catch (Exception e) {
                Log.w("FDroid", "Unable to get certificate fingerprint.\n" + Log.getStackTraceString(e));
            }
        }
        result.add(server_line);
    }
    SimpleAdapter show_out = new SimpleAdapter(this, result, R.layout.repolisticons,
            new String[] { "address", "inuse", "fingerprint" },
            new int[] { R.id.uri, R.id.img, R.id.fingerprint });

    setListAdapter(show_out);
}

From source file:io.teak.sdk.DebugConfiguration.java

public void printBugReportInfo(@NonNull Context context, @NonNull AppConfiguration appConfiguration,
        @NonNull DeviceConfiguration deviceConfiguration) {
    if (Teak.isDebug) {
        try {//from  w  w  w  .java  2  s  .c  o m
            HashMap<String, Object> debugInfoMap = new HashMap<>();

            HashMap<String, Object> sdkInfo = new HashMap<>();
            sdkInfo.put("teakAndroidVersion", Teak.SDKVersion);

            String airSdkVersion = Helpers.getStringResourceByName("io_teak_air_sdk_version", context);
            if (airSdkVersion != null) {
                sdkInfo.put("teakAirVersion", airSdkVersion);
            }

            debugInfoMap.put("sdk", sdkInfo);
            debugInfoMap.put("appConfiguration", appConfiguration.to_h());
            debugInfoMap.put("deviceConfiguration", deviceConfiguration.to_h());
            if (!DebugConfiguration.externalDebugInfo.isEmpty()) {
                debugInfoMap.put("externalDebugInfo", DebugConfiguration.externalDebugInfo);
            }

            String debugInfo = new JSONObject(debugInfoMap).toString();
            Log.d(LOG_TAG,
                    "Please include the following JSON blob with any bug reports you submit: " + debugInfo);

            if (this.bugReportUrl != null) {
                Log.d(LOG_TAG, String.format(Locale.US, "Or use this link:\n%s?body=%s", this.bugReportUrl,
                        URLEncoder.encode("DESCRIBE THE ISSUE HERE\n\n" + debugInfo, "UTF-8")));
            }
        } catch (Exception e) {
            Log.e(LOG_TAG, "Error in printBugReportInfo() " + Log.getStackTraceString(e));
        }
    }
}

From source file:org.alfresco.mobile.android.application.configuration.MainMenuConfigManager.java

private void configureView(ViewConfig config, Button buttonView) {
    try {//w w w  .  j  av  a2s  . co m
        Map<String, Object> parameters = config.getParameters();
        String label = config.getLabel();
        if (!TextUtils.isEmpty(label)) {
            if (parameters == null) {
                parameters = new HashMap<String, Object>(1);
            }
            parameters.put(ViewTemplate.ARGUMENT_LABEL, label);
        }
        AlfrescoFragmentBuilder fragmentBuilder = FragmentBuilderFactory.createViewConfig(getActivity(),
                config.getType(), parameters);
        fragmentBuilder.createMenuItem(config, buttonView);
        if (!TextUtils.isEmpty(label)) {
            buttonView.setText(label);
        }
    } catch (Exception e) {
        Log.e(TAG, Log.getStackTraceString(e));
        Log.e(TAG, "Error during menu creation : " + config.getIdentifier());
    }
}

From source file:com.kth.common.utils.etc.LogUtil.java

/**
 * DEBUG  ?./*from  w w  w .j  a  va  2  s  . c o  m*/
 * 
 * @param clazz  ??  Class.
 * @param msg .
 * @param tr Throwable.
 */
public static void d(final Class<?> clazz, final String msg, final Throwable tr) {
    if (LogUtil.isDebugEnabled()) {
        Log.println(Log.DEBUG, TAG,
                LogUtil.getClassLineNumber(clazz) + " - " + msg + '\n' + Log.getStackTraceString(tr));

        //  ?? ?   ?.
        if (LogUtil.isFileLogEnabled()) {
            write(Log.DEBUG, LogUtil.getClassLineNumber(clazz), msg, tr);
        }
    }
}

From source file:com.dm.material.dashboard.candybar.activities.CandyBarSplashActivity.java

private void checkRszIo() {
    mCheckRszIo = new AsyncTask<Void, Void, Boolean>() {

        final String rszio = "https://rsz.io/";

        @Override/*  w w w. j  av  a2 s .  c om*/
        protected Boolean doInBackground(Void... voids) {
            while ((!isCancelled())) {
                try {
                    Thread.sleep(1);
                    URL url = new URL(rszio);
                    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                    connection.setReadTimeout(6000);
                    connection.setConnectTimeout(6000);
                    int code = connection.getResponseCode();
                    return code == 200;
                } catch (Exception e) {
                    LogUtil.e(Log.getStackTraceString(e));
                    return false;
                }
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            CandyBarMainActivity.sRszIoAvailable = aBoolean;
            LogUtil.e("rsz.io availability: " + CandyBarMainActivity.sRszIoAvailable);
            mCheckRszIo = null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:com.android.mms.transaction.SendTransaction.java

public void run() {
    Log.d(MmsApp.TXN_TAG, "SendTransaction: run");
    RateController rateCtlr = RateController.getInstance();
    if (rateCtlr.isLimitSurpassed() && !rateCtlr.isAllowedByUser()) {
        Log.e(TAG, "Sending rate limit surpassed.");
        return;//from w w w  .  j  ava  2s .  c o  m
    }

    try {
        final PduPersister persister = PduPersister.getPduPersister(mContext);
        final SendReq sendReq = (SendReq) persister.load(mUri);
        if (sendReq == null) {
            Log.w(MmsApp.TXN_TAG, "Send req is null!");
            return;
        }
        byte[] datas = new PduComposer(mContext, sendReq).make();
        mPduFile = createPduFile(datas, SEND_REQ_NAME + mUri.getLastPathSegment());
        if (mPduFile == null) {
            Log.w(MmsApp.TXN_TAG, "create pdu file req failed!");
            return;
        }

        //Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED);
        //intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);
        //intent.putExtra(TransactionBundle.URI, mUri.toString());
        Log.d(MmsApp.TXN_TAG, "SendTransaction mUri:" + mUri);
        final Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED, mUri, mContext,
                MmsReceiver.class);
        intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);

        PendingIntent sentIntent = PendingIntent.getBroadcast(mContext, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        Log.d(MmsApp.TXN_TAG,
                "send MMS with param, mUri = " + mUri + " mPdufile = " + mPduFile + ", subId = " + mSubId);
        Uri pduFileUri = FileProvider.getUriForFile(mContext, MMS_FILE_PROVIDER_AUTHORITIES, mPduFile);
        /// M: Add MmsService configure param @{
        SmsManager.getSmsManagerForSubscriptionId(mSubId).sendMultimediaMessage(mContext, pduFileUri, null,
                MmsConfig.getMmsServiceConfig(), sentIntent);
        /// @}
    } catch (Throwable t) {
        Log.e(TAG, Log.getStackTraceString(t));
        getState().setState(FAILED);
        getState().setContentUri(mUri);
        notifyObservers();
    }
}

From source file:com.dm.material.dashboard.candybar.tasks.IconRequestTask.java

@Override
protected Boolean doInBackground(Void... voids) {
    while (!isCancelled()) {
        try {//w  w w.  j  ava  2 s.co m
            Thread.sleep(1);
            if (mContext.get().getResources().getBoolean(R.bool.enable_icon_request)
                    || mContext.get().getResources().getBoolean(R.bool.enable_premium_request)) {
                List<Request> requests = new ArrayList<>();
                HashMap<String, String> appFilter = RequestHelper.getAppFilter(mContext.get(),
                        RequestHelper.Key.ACTIVITY);
                if (appFilter.size() == 0) {
                    mError = Extras.Error.APPFILTER_NULL;
                    return false;
                }

                PackageManager packageManager = mContext.get().getPackageManager();

                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                List<ResolveInfo> installedApps = packageManager.queryIntentActivities(intent,
                        PackageManager.GET_RESOLVED_FILTER);
                if (installedApps == null || installedApps.size() == 0) {
                    mError = Extras.Error.INSTALLED_APPS_NULL;
                    return false;
                }

                CandyBarMainActivity.sInstalledAppsCount = installedApps.size();

                try {
                    Collections.sort(installedApps, new ResolveInfo.DisplayNameComparator(packageManager));
                } catch (Exception ignored) {
                }

                for (ResolveInfo app : installedApps) {
                    String packageName = app.activityInfo.packageName;
                    String activity = packageName + "/" + app.activityInfo.name;

                    String value = appFilter.get(activity);

                    if (value == null) {
                        String name = LocaleHelper.getOtherAppLocaleName(mContext.get(), new Locale("en"),
                                packageName);
                        if (name == null) {
                            name = app.activityInfo.loadLabel(packageManager).toString();
                        }

                        boolean requested = Database.get(mContext.get()).isRequested(activity);
                        Request request = Request.Builder().name(name).packageName(app.activityInfo.packageName)
                                .activity(activity).requested(requested).build();

                        requests.add(request);
                    }
                }

                CandyBarMainActivity.sMissedApps = requests;
            }
            return true;
        } catch (Exception e) {
            CandyBarMainActivity.sMissedApps = null;
            mError = Extras.Error.DATABASE_ERROR;
            LogUtil.e(Log.getStackTraceString(e));
            return false;
        }
    }
    return false;
}

From source file:org.alfresco.mobile.android.application.capture.DeviceCapture.java

protected void finalize() {
    try {/* ww  w  . ja  va2 s. co m*/
        if (payload != null) {
            payload.delete();
            payload = null;
        }
        super.finalize();
    } catch (Throwable e) {
        Log.w(DeviceCapture.class.getName(), Log.getStackTraceString(e));
    }
}

From source file:biz.bokhorst.xprivacy.Util.java

public static void bug(XHook hook, Throwable ex) {
    if (ex instanceof InvocationTargetException) {
        InvocationTargetException exex = (InvocationTargetException) ex;
        if (exex.getTargetException() != null)
            ex = exex.getTargetException();
    }/*from   w  w w.  j a v a2  s. co  m*/

    int priority;
    if (ex instanceof ActivityShare.AbortException)
        priority = Log.WARN;
    else if (ex instanceof ActivityShare.ServerException)
        priority = Log.WARN;
    else if (ex instanceof ConnectTimeoutException)
        priority = Log.WARN;
    else if (ex instanceof FileNotFoundException)
        priority = Log.WARN;
    else if (ex instanceof HttpHostConnectException)
        priority = Log.WARN;
    else if (ex instanceof NameNotFoundException)
        priority = Log.WARN;
    else if (ex instanceof NoClassDefFoundError)
        priority = Log.WARN;
    else if (ex instanceof OutOfMemoryError)
        priority = Log.WARN;
    else if (ex instanceof RuntimeException)
        priority = Log.WARN;
    else if (ex instanceof SecurityException)
        priority = Log.WARN;
    else if (ex instanceof SocketTimeoutException)
        priority = Log.WARN;
    else if (ex instanceof SSLPeerUnverifiedException)
        priority = Log.WARN;
    else if (ex instanceof StackOverflowError)
        priority = Log.WARN;
    else if (ex instanceof TransactionTooLargeException)
        priority = Log.WARN;
    else if (ex instanceof UnknownHostException)
        priority = Log.WARN;
    else if (ex instanceof UnsatisfiedLinkError)
        priority = Log.WARN;
    else
        priority = Log.ERROR;

    boolean xprivacy = false;
    for (StackTraceElement frame : ex.getStackTrace())
        if (frame.getClassName() != null && frame.getClassName().startsWith("biz.bokhorst.xprivacy")) {
            xprivacy = true;
            break;
        }
    if (!xprivacy)
        priority = Log.WARN;

    log(hook, priority, ex.toString() + " uid=" + Process.myUid() + "\n" + Log.getStackTraceString(ex));
}

From source file:net.olejon.spotcommander.DonateActivity.java

private void makeDonation(final String product) {
    try {/*ww  w  . j  a  v  a2  s. c  o  m*/
        final Bundle buyIntentBundle = mIInAppBillingService.getBuyIntent(3, getPackageName(), product, "inapp",
                "");

        final PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");

        final IntentSender intentSender = (pendingIntent != null) ? pendingIntent.getIntentSender() : null;

        startIntentSenderForResult(intentSender, 1, new Intent(), 0, 0, 0);
    } catch (Exception e) {
        mTools.showToast(getString(R.string.donate_something_went_wrong), 1);

        Log.e("DonateActivity", Log.getStackTraceString(e));
    }
}