Example usage for android.os SystemClock uptimeMillis

List of usage examples for android.os SystemClock uptimeMillis

Introduction

In this page you can find the example usage for android.os SystemClock uptimeMillis.

Prototype

@CriticalNative
native public static long uptimeMillis();

Source Link

Document

Returns milliseconds since boot, not counting time spent in deep sleep.

Usage

From source file:org.namelessrom.devicecontrol.device.DeviceInformationGeneralFragment.java

@Override
public boolean onPreferenceTreeClick(final PreferenceScreen preferenceScreen,
        @NonNull final Preference preference) {
    final String key = preference.getKey();
    if (!mEasterEggStarted && TextUtils.equals(KEY_PLATFORM_VERSION, key)) {
        System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
        mHits[mHits.length - 1] = SystemClock.uptimeMillis();
        if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) {
            Utils.runRootCommand("am start android/com.android.internal.app.PlatLogoActivity");
            mEasterEggStarted = true;/*from   www  .j a  va  2s.c om*/
        }
        return true;
    } else if (TextUtils.equals("emmc_can_brick", key)) {
        AppHelper.viewInBrowser(Emmc.BRICK_INFO_URL);
        return true;
    }

    return super.onPreferenceTreeClick(preferenceScreen, preference);
}

From source file:com.tencent.wetest.common.util.ReportUtil.java

@SuppressLint("SimpleDateFormat")
public static synchronized String saveReport() {

    try {/*from  www  .j  a  va  2 s.  c o m*/

        path = WTApplication.getContext().getFilesDir().getPath();
        String versionName = ((WTApplication) WTApplication.getContext()).getApkinfo().getVersionName();

        packageName = ((WTApplication) WTApplication.getContext()).getApkinfo().getPackagename();
        appName = ((WTApplication) WTApplication.getContext()).getApkinfo().getAppname();
        ;
        datasource = ((WTApplication) WTApplication.getContext()).getReport();

        if (datasource != null)
            datas = datasource.getDatalist();

        size = datas.size();

        Date now = new Date();

        long timeStart = -1;
        long timeEnd = -1;
        boolean hasBaseTime = false;

        if (datasource.getBaseTime() == -1) {

            hasBaseTime = false;

            timeEnd = (new Date()).getTime();

            if (timeEnd == -1) {

                timeEnd = now.getTime();

                timeStart = (timeEnd - (SystemClock.uptimeMillis() - datasource.getBaseColock()))
                        + (datasource.getTimeStart() - datasource.getBaseColock());

            } else {

                timeStart = (timeEnd - (SystemClock.uptimeMillis() - datasource.getBaseColock()))
                        + (datasource.getTimeStart() - datasource.getBaseColock());

                ((WTApplication) WTApplication.getContext()).getReport().setBaseTime(timeEnd);
                ((WTApplication) WTApplication.getContext()).getReport()
                        .setBaseColock(SystemClock.uptimeMillis());

            }

        } else {

            hasBaseTime = true;

            timeStart = datasource.getBaseTime() + datasource.getTimeStart() - datasource.getBaseColock();

            timeEnd = datasource.getBaseTime() + SystemClock.uptimeMillis() - datasource.getBaseColock();

        }

        File f;
        File indexfile = new File(path + "/wtIndex");

        if (((WTApplication) WTApplication.getContext()).getCurrTestFile() == null) {

            name = "wt" + now.getTime();

            String fileDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/wetest";
            ToolUtil.createDir(fileDir);

            f = new File(fileDir + "/" + name);
            ((WTApplication) WTApplication.getContext()).setCurrTestFile(f);

        } else {
            f = ((WTApplication) WTApplication.getContext()).getCurrTestFile();
            name = f.getName();

        }

        DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String isRoot = ((WTApplication) WTApplication.getContext()).isRoot() ? "1" : "0";

        String content_index = name + "/" + formatter.format(timeEnd) + "/" + appName.replaceFirst("\\s+", "")
                + "/" + packageName + "/" + (timeEnd - timeStart) / 1000 + "/" + timeStart + "/" + timeEnd + "/"
                + versionName + "/" + isRoot + "/" + "";

        ((WTApplication) WTApplication.getContext()).getTestReports().add(name);

        if (!f.exists()) {
            f.createNewFile();
        }

        if (!indexfile.exists())
            indexfile.createNewFile();

        JsonResult json_res = readFileReport(f);

        JSONObject cpu = new JSONObject();

        JSONObject natived = new JSONObject();
        JSONObject dalvik = new JSONObject();
        JSONObject total = new JSONObject();

        JSONObject networkIn = new JSONObject();
        JSONObject networkOut = new JSONObject();

        JSONObject fps = new JSONObject();

        JSONObject time = new JSONObject();

        JSONObject tag = new JSONObject();

        JSONObject temperature = new JSONObject();

        JSONObject current = new JSONObject();

        for (ReportData data : datas) {

            if (!hasBaseTime) {

                long gap = data.getTime() - datasource.getTimeStart();

                long offset = gap > 0 ? gap : 0;

                json_res.getContent_f_time().put((timeStart + offset) / 1000);

                //Logger.debug("dataTime is " + formatter.format(timeStart + offset));

            } else {

                json_res.getContent_f_time().put((data.getTime()) / 1000);

                //Logger.debug("dataTime is " + formatter.format(data.getTime()));

            }

            json_res.getContent_f_cpu().put(data.getCpu());

            json_res.getContent_f_native().put(data.getpNative());
            json_res.getContent_f_dalvik().put(data.getpDalvik());
            json_res.getContent_f_total().put(data.getpTotal());

            json_res.getContent_f_networkIn().put(data.getpNetworUsagekIn());
            json_res.getContent_f_networkOut().put(data.getpNetworUsagekOut());
            json_res.getContent_f_Fps().put(data.getFps());

            json_res.getContent_f_Tag().put(data.getTag());

            json_res.getContent_f_temperature().put(data.getpTemperature());

            json_res.getContent_f_current().put(data.getpCurrent());

        }

        cpu.put("cpu", json_res.getContent_f_cpu());

        natived.put("native", json_res.getContent_f_native());
        dalvik.put("dalvik", json_res.getContent_f_dalvik());
        total.put("total", json_res.getContent_f_total());

        networkIn.put("networkIn", json_res.getContent_f_networkIn());
        networkOut.put("networkOut", json_res.getContent_f_networkOut());
        time.put("time", json_res.getContent_f_time());

        fps.put("fps", json_res.getContent_f_Fps());
        tag.put("tag", json_res.getContent_f_Tag());

        temperature.put("temperature", json_res.getContent_f_temperature());
        current.put("current", json_res.getContent_f_current());

        BufferedWriter writer = new BufferedWriter(new FileWriter(f, false));

        writer.append(cpu.toString());
        writer.newLine();

        writer.append(natived.toString());
        writer.newLine();

        writer.append(dalvik.toString());
        writer.newLine();

        writer.append(total.toString());
        writer.newLine();

        writer.append(networkIn.toString());
        writer.newLine();

        writer.append(networkOut.toString());
        writer.newLine();

        writer.append(time.toString());
        writer.newLine();

        writer.append(fps.toString());
        writer.newLine();

        writer.append(tag.toString());

        writer.flush();
        writer.close();

        updateRecord(indexfile, name, content_index);

    } catch (Exception e) {
        Logger.error("report save exception :" + e.toString());
        e.printStackTrace();
    }

    return name;

}

From source file:com.google.io.accessibility.util.IncrementalAsyncTaskLoader.java

void executePendingTask() {
    if (mCancellingTask == null && mTask != null) {
        if (mTask.waiting) {
            mTask.waiting = false;//from  www .j  a va  2 s . com
            mHandler.removeCallbacks(mTask);
        }
        if (mUpdateThrottle > 0) {
            long now = SystemClock.uptimeMillis();
            if (now < (mLastLoadCompleteTime + mUpdateThrottle)) {
                // Not yet time to do another load.
                if (DEBUG)
                    Log.v(TAG, "Waiting until " + (mLastLoadCompleteTime + mUpdateThrottle) + " to execute: "
                            + mTask);
                mTask.waiting = true;
                mHandler.postAtTime(mTask, mLastLoadCompleteTime + mUpdateThrottle);
                return;
            }
        }
        if (DEBUG)
            Log.v(TAG, "Executing: " + mTask);
        mTask.execute((B[]) null);
        // XXX TO DO: use reflection to call this version.
        //mTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
    }
}

From source file:com.miku.framelite.httpx.core.DownloadHandler.java

public void downloadNotice(long count, long current, boolean mustNoticeUI) {
    if (callback != null) {
        if (mustNoticeUI) {
            publishProgress(UPDATE_LOADING, count, current);
        } else {//www.ja  v  a  2s. c  o  m
            long thisTime = SystemClock.uptimeMillis();
            // ?500ms
            if (thisTime - time >= 500) {
                time = thisTime;
                publishProgress(UPDATE_LOADING, count, current);
            }
        }
    }
}

From source file:edu.ptu.navpattern.tooltip.Tooltip.java

private View getContentView(final Builder builder) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setColor(builder.mBackgroundColor);
    drawable.setCornerRadius(builder.mCornerRadius);
    LinearLayout vgContent = new LinearLayout(builder.mContext);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        vgContent.setBackground(drawable);
    } else {//from   ww  w.  ja v a  2s .  co  m
        //noinspection deprecation
        vgContent.setBackgroundDrawable(drawable);
    }
    int padding = (int) builder.mPadding;
    vgContent.setPadding(padding, padding, padding, padding);
    vgContent.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
    textViewParams.gravity = Gravity.CENTER;
    textViewParams.topMargin = 1;
    vgContent.setLayoutParams(textViewParams);
    vgContent.setDividerDrawable(vgContent.getResources().getDrawable(R.drawable.divider_line));
    vgContent.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);

    if (builder.itemText != null && builder.itemText.length > 0) {
        for (int i = 0; i < builder.itemText.length; i++) {

            TextView textView = new TextView(builder.mContext);
            textView.setText(builder.itemText[i]);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 44);
            textView.setTextColor(0xffffffff);
            textView.setGravity(Gravity.CENTER_VERTICAL);
            if (builder.itemLogo != null && builder.itemLogo.length > i) {
                Drawable drawableLeft = builder.mContext.getResources().getDrawable(builder.itemLogo[i]);
                /// ??,??.
                //                    drawableLeft.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                //                    textView.setCompoundDrawables(drawableLeft, null, null, null);
                //                    textView.setCompoundDrawablePadding(4);
                //                    textView.setBackgroundDrawable(drawableLeft);
                LinearLayout linearLayout = new LinearLayout(builder.mContext);
                linearLayout.setMinimumHeight((int) dpToPx(44f));
                linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                linearLayout.setGravity(Gravity.CENTER_VERTICAL);
                ImageView icon = new ImageView(builder.mContext);
                icon.setImageDrawable(drawableLeft);
                linearLayout.addView(icon);
                linearLayout.addView(textView);
                vgContent.addView(linearLayout);
                final int position = i;
                linearLayout.setClickable(false);
                linearLayout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (builder.mOnItemClickListener != null) {
                            builder.mOnItemClickListener.onClick(position);
                        }
                        mTouchListener.onTouch(v,
                                MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
                                        MotionEvent.ACTION_UP, v.getLeft() + 5, v.getTop() + 5, 0));
                    }
                });
            } else {
                vgContent.addView(textView);
                final int position = i;
                textView.setClickable(false);
                textView.setMinimumHeight((int) dpToPx(44f));
                textView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (builder.mOnItemClickListener != null) {
                            builder.mOnItemClickListener.onClick(position);
                        }
                        mTouchListener.onTouch(v, null);
                    }
                });
            }
        }

    }

    mArrowView = new ImageView(builder.mContext);
    mArrowView.setImageDrawable(builder.mArrowDrawable);

    LinearLayout.LayoutParams arrowLayoutParams;
    if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowWidth, (int) builder.mArrowHeight,
                0);
    } else {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowHeight, (int) builder.mArrowWidth,
                0);
    }
    arrowLayoutParams.gravity = Gravity.CENTER;
    mArrowView.setLayoutParams(arrowLayoutParams);

    mContentView = new LinearLayout(builder.mContext);
    mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    mContentView.setOrientation(mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayout.HORIZONTAL
            : LinearLayout.VERTICAL);

    padding = (int) dpToPx(5);

    switch (mGravity) {
    case Gravity.START:
        mContentView.setPadding(0, 0, padding, 0);
        break;
    case Gravity.TOP:
    case Gravity.BOTTOM:
        mContentView.setPadding(padding, 0, padding, 0);
        break;
    case Gravity.END:
        mContentView.setPadding(padding, 0, 0, 0);
        break;
    }

    if (mGravity == Gravity.TOP || mGravity == Gravity.START) {
        mContentView.addView(vgContent);
        mContentView.addView(mArrowView);
    } else {
        mContentView.addView(mArrowView);
        mContentView.addView(vgContent);
    }

    if (builder.isCancelable || builder.isDismissOnClick) {
        mContentView.setOnTouchListener(mTouchListener);
    }
    return mContentView;
}

From source file:cn.com.dfc.pl.afinal.http.HttpHandler.java

@Override
public void callBack(long count, long current, boolean mustNoticeUI) {
    if (callback != null && callback.isProgress()) {
        if (mustNoticeUI) {
            publishProgress(UPDATE_LOADING, count, current);
        } else {/*from   w w  w  . j a  va  2  s  .c o m*/
            long thisTime = SystemClock.uptimeMillis();
            if (thisTime - time >= callback.getRate()) {
                time = thisTime;
                publishProgress(UPDATE_LOADING, count, current);
            }
        }
    }
}

From source file:org.akop.crosswords.fragment.CrosswordFragment.java

@Override
public void onResume() {
    super.onResume();

    mPlayStartTime = SystemClock.uptimeMillis();
}

From source file:com.android.leanlauncher.IconCache.java

public void loadIconPackDrawables(boolean forceReload) {
    final long t = SystemClock.uptimeMillis();
    synchronized (mIconPackDrawables) {
        if (!forceReload && mIconPackDrawables.size() > 0) {
            return;
        }/*from w ww.j  ava2  s.  c om*/

        // load appfilter.xml from the icon pack package
        try {
            XmlPullParser xpp = null;

            final Resources iconPackRes = getIconPackResources();
            if (iconPackRes == null) {
                return;
            }

            int appfilterid = iconPackRes.getIdentifier("appfilter", "xml", mCurrentIconTheme);
            if (appfilterid > 0) {
                xpp = iconPackRes.getXml(appfilterid);
            } else {
                // no resource found, try to open it from assets folder
                try {
                    InputStream is = iconPackRes.getAssets().open("appfilter.xml");

                    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
                    factory.setNamespaceAware(true);
                    xpp = factory.newPullParser();
                    xpp.setInput(is, "utf-8");
                } catch (IOException e) {
                    Log.d(TAG, "Can't find appfilter.xml file in : " + mCurrentIconTheme);
                }
            }

            if (xpp != null) {
                int eventType = xpp.getEventType();
                while (eventType != XmlPullParser.END_DOCUMENT) {
                    if (eventType == XmlPullParser.START_TAG) {
                        if ("item".equals(xpp.getName())) {
                            String componentName = null;
                            String drawableName = null;

                            for (int i = 0; i < xpp.getAttributeCount(); i++) {
                                if ("component".equals(xpp.getAttributeName(i))) {
                                    componentName = xpp.getAttributeValue(i);
                                } else if ("drawable".equals(xpp.getAttributeName(i))) {
                                    drawableName = xpp.getAttributeValue(i);
                                }
                            }

                            if (TextUtils.isEmpty(componentName) || TextUtils.isEmpty(drawableName)) {
                                eventType = xpp.next();
                                continue;
                            }

                            try {
                                componentName = componentName.substring(componentName.indexOf('{') + 1,
                                        componentName.indexOf('}'));
                            } catch (StringIndexOutOfBoundsException e) {
                                Log.d(TAG, "Can't parse icon for package = " + componentName);
                                eventType = xpp.next();
                                continue;
                            }

                            ComponentName componentNameKey = ComponentName.unflattenFromString(componentName);
                            if (componentNameKey != null) {
                                mIconPackDrawables.put(componentNameKey, drawableName);
                            } else {
                                Log.d(TAG, "ComponentName can't be obtained from: " + componentName);
                            }
                        } else if ("iconback".equals(xpp.getName())) {
                            for (int i = 0; i < xpp.getAttributeCount(); i++) {
                                if (xpp.getAttributeName(i).startsWith("img")) {
                                    mIconBackgrounds.add(loadBitmapFromIconPack(xpp.getAttributeValue(i)));
                                }
                            }
                        } else if ("iconmask".equals(xpp.getName())) {
                            if (xpp.getAttributeCount() > 0 && "img1".equals(xpp.getAttributeName(0))) {
                                mIconMask = loadBitmapFromIconPack(xpp.getAttributeValue(0));
                            }
                        } else if ("iconupon".equals(xpp.getName())) {
                            if (xpp.getAttributeCount() > 0 && "img1".equals(xpp.getAttributeName(0))) {
                                mIconFront = loadBitmapFromIconPack(xpp.getAttributeValue(0));
                            }
                        } else if ("scale".equals(xpp.getName())) {
                            if (xpp.getAttributeCount() > 0 && "factor".equals(xpp.getAttributeName(0))) {
                                mIconScaleFactor = Float.valueOf(xpp.getAttributeValue(0));
                            }
                        }
                    }
                    eventType = xpp.next();
                }
            }
            Log.d(TAG, "Finished parsing icon pack: " + (SystemClock.uptimeMillis() - t) + "ms");
        } catch (XmlPullParserException e) {
            Log.d(TAG, "Cannot parse icon pack appfilter.xml" + e);
        } catch (IOException e) {
            Log.d(TAG, "Exception loading icon pack " + e);
        }
    }
}

From source file:com.my.cloudcontact.http.HttpHandler.java

private void handleResponse(HttpUriRequest request, HttpResponse response) {
    StatusLine status = response.getStatusLine();
    if (status.getStatusCode() >= 300) {
        String errorMsg = "response status error code:" + status.getStatusCode();
        if (status.getStatusCode() == 416 && isResume) {
            errorMsg += " \n maybe you have download complete.";
        }//from w w  w .j a  v a  2s.c o  m
        publishProgress(UPDATE_FAILURE,
                new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()),
                status.getStatusCode(), errorMsg);
    } else {
        try {

            //  ??
            if (mCheckResponse != null) {
                //
                if (mCheckResponse.checkResponse(request, response))
                    return;
            }

            // ?
            HttpEntity entity = response.getEntity();
            Object responseBody = null;
            if (entity != null) {
                time = SystemClock.uptimeMillis();
                if (targetUrl != null) {
                    responseBody = mFileEntityHandler.handleEntity(entity, this, targetUrl, isResume);
                } else {
                    responseBody = mStrEntityHandler.handleEntity(entity, this, charset);
                }
            }
            publishProgress(UPDATE_SUCCESS, responseBody, request, response);
        } catch (IOException e) {
            publishProgress(UPDATE_FAILURE, e, 0, e.getMessage());
        } catch (SeverRequestException e) {
            publishProgress(UPDATE_FAILURE, e, 0, e.getMessage());
        }

    }
}

From source file:com.tapcentive.sdk.touchpoint.nfc.SEManager.java

/**
 * Send and receive.//from   w  ww.  j a va 2s  .c o m
 *
 * @param cmd the cmd
 * @return the data that was read or null if an error occurred
 */
public byte[] sendAndReceive(byte[] cmd) {
    byte[] result;
    byte[] fullBytes = null;
    ByteArrayBuffer fullresult = new ByteArrayBuffer(255);
    boolean hasMore = true;
    byte[] command = cmd;
    boolean gotSuccessSW = false;
    long time1 = SystemClock.uptimeMillis();
    while (hasMore) {
        try {
            result = partialSendAndReceive(command);

            fullresult.append(result, 0, result.length - 2);

            if (result.length < 2) {
                Log.d(TAG, "READ command issue");
                return null;
            }
            // Check if more data is available from touchpoint
            if (result[result.length - 2] == (byte) 0x61) {
                hasMore = true;
            } else {
                if (result[result.length - 2] != (byte) 0x90) {
                    Log.d(TAG,
                            "Bad SW on READ (command/response):"
                                    + ApduUtil.getHexString(command, 0, command.length, "") + " / "
                                    + ApduUtil.getHexString(result, 0, result.length, ""));
                    return null;
                    /*throw new TapcentiveException("An error occurred. Please try again and if this problem persists contact customer service");*/
                } else { // SW 9000
                    hasMore = false;
                    gotSuccessSW = true;
                }
            }
            command = getResponse; // After the first iteration change the command header to a GET RESPONSE
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
    long time2 = SystemClock.uptimeMillis();
    Log.d(TAG, "TIME: send&Receive: " + (time2 - time1));
    /*if (!gotSuccessSW){
       throw new TapcentiveException("An error occurred. Please try again and if this problem persists contact customer service");
    }*/

    if (gotSuccessSW) {
        fullBytes = fullresult.toByteArray();
        Log.d(TAG, "TIME: send&receive apdu size: " + fullBytes.length);
    }

    return fullBytes;
}