浏览代码

1.增加开机自启

Tony 5 年之前
父节点
当前提交
d583f90499

+ 0 - 1
androidperformancetoolslibrary/.gitignore

@@ -1 +0,0 @@
-/build

+ 0 - 25
androidperformancetoolslibrary/build.gradle

@@ -1,25 +0,0 @@
-apply plugin: 'com.android.library'
-
-android {
-    compileSdkVersion 25
-
-    defaultConfig {
-        minSdkVersion 14
-        targetSdkVersion 25
-        versionCode 1
-        versionName "1.0"
-
-        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
-
-    }
-    buildTypes {
-        release {
-            minifyEnabled false
-            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
-        }
-    }
-}
-
-dependencies {
-    implementation fileTree(dir: 'libs', include: ['*.jar'])
-}

+ 0 - 25
androidperformancetoolslibrary/proguard-rules.pro

@@ -1,25 +0,0 @@
-# Add project specific ProGuard rules here.
-# By default, the flags in this file are appended to flags specified
-# in F:\android-sdk/tools/proguard/proguard-android.txt
-# You can edit the include path and order by changing the proguardFiles
-# directive in build.gradle.
-#
-# For more details, see
-#   http://developer.android.com/guide/developing/tools/proguard.html
-
-# Add any project specific keep options here:
-
-# If your project uses WebView with JS, uncomment the following
-# and specify the fully qualified class name to the JavaScript interface
-# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
-#   public *;
-#}
-
-# Uncomment this to preserve the line number information for
-# debugging stack traces.
-#-keepattributes SourceFile,LineNumberTable
-
-# If you keep the line number information, uncomment this to
-# hide the original source file name.
-#-renamesourcefileattribute SourceFile

+ 0 - 26
androidperformancetoolslibrary/src/androidTest/java/com/performance/tools/ExampleInstrumentedTest.java

@@ -1,26 +0,0 @@
-package com.performance.tools;
-
-import android.content.Context;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.runner.AndroidJUnit4;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import static org.junit.Assert.*;
-
-/**
- * Instrumentation test, which will execute on an Android device.
- *
- * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
- */
-@RunWith(AndroidJUnit4.class)
-public class ExampleInstrumentedTest {
-    @Test
-    public void useAppContext() throws Exception {
-        // Context of the app under test.
-        Context appContext = InstrumentationRegistry.getTargetContext();
-
-        assertEquals("com.performance.tools.test", appContext.getPackageName());
-    }
-}

+ 0 - 10
androidperformancetoolslibrary/src/main/AndroidManifest.xml

@@ -1,10 +0,0 @@
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-
-    package="com.performance.tools">
-
-    <application android:allowBackup="true" android:label="@string/app_name"
-        android:supportsRtl="true">
-
-    </application>
-
-</manifest>

+ 0 - 100
androidperformancetoolslibrary/src/main/java/com/performance/tools/block/BlockError.java

@@ -1,100 +0,0 @@
-package com.performance.tools.block;
-
-import android.os.Looper;
-
-import java.util.Comparator;
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- * Created by Clock on 2017/5/16.
- */
-
-public class BlockError extends Error {
-
-    private BlockError(ThreadStackInfoWrapper.ThreadStackInfo threadStackInfo) {
-        super("BlockLooper Catch BlockError", threadStackInfo);
-    }
-
-
-    public static BlockError getUiThread() {
-        Thread uiThread = Looper.getMainLooper().getThread();
-        StackTraceElement[] stackTraceElements = uiThread.getStackTrace();
-        ThreadStackInfoWrapper.ThreadStackInfo threadStackInfo = new ThreadStackInfoWrapper(getThreadNameAndState(uiThread), stackTraceElements)
-                .new ThreadStackInfo(null);
-        return new BlockError(threadStackInfo);
-    }
-
-
-    public static BlockError getAllThread() {
-        final Thread uiThread = Looper.getMainLooper().getThread();
-        Map<Thread, StackTraceElement[]> stackTraceElementMap = new TreeMap<Thread, StackTraceElement[]>(new Comparator<Thread>() {
-            @Override
-            public int compare(Thread lhs, Thread rhs) {
-                if (lhs == rhs) {
-                    return 0;
-                } else if (lhs == uiThread) {
-                    return 1;
-                } else if (rhs == uiThread) {
-                    return -1;
-                }
-                return rhs.getName().compareTo(lhs.getName());
-            }
-        });
-
-        for (Map.Entry<Thread, StackTraceElement[]> entry : Thread.getAllStackTraces().entrySet()) {
-            Thread key = entry.getKey();
-            StackTraceElement[] value = entry.getValue();
-            if (value.length > 0) {
-                stackTraceElementMap.put(key, value);
-            }
-        }
-
-        //Fix有时候Thread.getAllStackTraces()不包含UI线程的问题
-        if (!stackTraceElementMap.containsKey(uiThread)) {
-            stackTraceElementMap.put(uiThread, uiThread.getStackTrace());
-        }
-
-        ThreadStackInfoWrapper.ThreadStackInfo threadStackInfo = null;
-        for (Map.Entry<Thread, StackTraceElement[]> entry : stackTraceElementMap.entrySet()) {
-            Thread key = entry.getKey();
-            StackTraceElement[] value = entry.getValue();
-            threadStackInfo = new ThreadStackInfoWrapper(getThreadNameAndState(key), value).
-                    new ThreadStackInfo(threadStackInfo);
-        }
-
-        return new BlockError(threadStackInfo);
-
-    }
-
-    public static String getThreadNameAndState(Thread thread) {
-        return thread.getName() + "-state-" + thread.getState();
-    }
-
-
-    private static class ThreadStackInfoWrapper {
-
-        private String nameAndState;
-        private StackTraceElement[] stackTraceElements;
-
-        private ThreadStackInfoWrapper(String nameAndState, StackTraceElement[] stackTraceElements) {
-            this.nameAndState = nameAndState;
-            this.stackTraceElements = stackTraceElements;
-        }
-
-        private class ThreadStackInfo extends Throwable {
-
-            private ThreadStackInfo(Throwable throwable) {
-                super(nameAndState, throwable);
-            }
-
-            @Override
-            public synchronized Throwable fillInStackTrace() {
-                setStackTrace(stackTraceElements);
-                return this;
-            }
-        }
-    }
-
-
-}

+ 0 - 272
androidperformancetoolslibrary/src/main/java/com/performance/tools/block/BlockLooper.java

@@ -1,272 +0,0 @@
-package com.performance.tools.block;
-
-import android.content.Context;
-import android.os.Debug;
-import android.os.Handler;
-import android.os.Looper;
-import android.util.Log;
-
-
-import com.performance.tools.utils.StorageUtils;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-/**
- * BlockLooper
- * <p>
- * 使用线程轮询的方式监听App是否产生卡顿
- * <p>
- * Created by Clock 2017/5/16.
- */
-
-public class BlockLooper implements Runnable {
-
-    private final static String TAG = BlockLooper.class.getSimpleName();
-    private final static String LOOPER_NAME = "block-looper-thread";
-    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd-HH-mm-ss");
-    /**
-     * 最小的轮询频率(单位:ms)
-     */
-    private final static long MIN_FREQUENCY = 500;
-
-    private static BlockLooper sLooper;
-    private Context appContext;
-    private Handler uiHandler = new Handler(Looper.getMainLooper());
-    private volatile int tickCounter = 0;
-    private Runnable ticker = new Runnable() {
-        @Override
-        public void run() {
-            tickCounter = (tickCounter + 1) % Integer.MAX_VALUE;
-        }
-    };
-    private long frequency;
-    private boolean ignoreDebugger;
-    private boolean reportAllThreadInfo;
-    private boolean saveLog;
-    private OnBlockListener onBlockListener;
-
-    private boolean isStop = true;
-
-    public static void initialize(Configuration configuration) {
-        if (sLooper == null) {
-            synchronized (BlockLooper.class) {
-                if (sLooper == null) {
-                    sLooper = new BlockLooper();
-                }
-            }
-            sLooper.init(configuration);
-        }
-    }
-
-    public static BlockLooper getBlockLooper() {
-        if (sLooper == null) {
-            throw new IllegalStateException("未使用initialize方法初始化BlockLooper");
-        }
-        return sLooper;
-    }
-
-    private BlockLooper() {
-    }
-
-    private void init(Configuration configuration) {
-        this.appContext = configuration.appContext;
-        this.frequency = configuration.frequency < MIN_FREQUENCY ? MIN_FREQUENCY : configuration.frequency;
-        this.ignoreDebugger = configuration.ignoreDebugger;
-        this.reportAllThreadInfo = configuration.reportAllThreadInfo;
-        this.onBlockListener = configuration.onBlockListener;
-        this.saveLog = configuration.saveLog;
-    }
-
-    @Override
-    public void run() {
-        int lastTickNumber;
-        while (!isStop) {
-            lastTickNumber = tickCounter;
-            uiHandler.post(ticker);
-
-            try {
-                Thread.sleep(frequency);
-            } catch (InterruptedException e) {
-                e.printStackTrace();
-                break;
-            }
-
-            if (lastTickNumber == tickCounter) {
-                if (!ignoreDebugger && Debug.isDebuggerConnected()) {
-                    Log.w(TAG, "当前由调试模式引起消息阻塞引起ANR,可以通过setIgnoreDebugger(true)来忽略调试模式造成的ANR");
-                    continue;
-                }
-
-                BlockError blockError;
-                if (!reportAllThreadInfo) {
-                    blockError = BlockError.getUiThread();
-                } else {
-                    blockError = BlockError.getAllThread();
-                }
-
-                if (onBlockListener != null) {
-                    onBlockListener.onBlock(blockError);
-                }
-
-                if (saveLog) {
-                    if (StorageUtils.isMounted()) {
-                        File logDir = getLogDirectory();
-                        saveLogToSdcard(blockError, logDir);
-                    } else {
-                        Log.w(TAG, "sdcard is unmounted");
-                    }
-                }
-            }
-
-        }
-    }
-
-    private void saveLogToSdcard(BlockError blockError, File dir) {
-        if (blockError == null) {
-            return;
-        }
-        if (dir != null && dir.exists() && dir.isDirectory()) {
-            String fileName = getLogFileName();
-            File logFile = new File(dir, fileName);
-            if (!logFile.exists()) {
-                try {
-                    logFile.createNewFile();
-                    PrintStream printStream = new PrintStream(new FileOutputStream(logFile, false), true);
-                    blockError.printStackTrace(printStream);
-                    printStream.close();
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-            }
-        }
-    }
-
-    private File getLogDirectory() {
-        File cacheDir = appContext.getExternalCacheDir();
-        if (cacheDir != null) {
-            File logDir = new File(cacheDir, "block");
-            if (!logDir.exists()) {
-                boolean successful = logDir.mkdirs();
-                if (successful) {
-                    return logDir;
-                } else {
-                    return null;
-                }
-            } else {
-                return logDir;
-            }
-        }
-        return null;
-    }
-
-    private String getLogFileName() {
-        String timeStampString = DATE_FORMAT.format(new Date());
-        String fileName = timeStampString + ".trace";
-        return fileName;
-    }
-
-    public synchronized void start() {
-        if (isStop) {
-            isStop = false;
-            Thread blockThread = new Thread(this);
-            blockThread.setName(LOOPER_NAME);
-            blockThread.start();
-        }
-    }
-
-    public synchronized void stop() {
-        if (!isStop) {
-            isStop = true;
-        }
-    }
-
-    public static class Builder {
-        private Context appContext;
-        private long frequency;
-        private boolean ignoreDebugger;
-        private boolean reportAllThreadInfo = false;
-        private boolean saveLog;
-        private OnBlockListener onBlockListener;
-
-        public Builder(Context appContext) {
-            this.appContext = appContext;
-        }
-
-        public Builder setFrequency(long frequency) {
-            this.frequency = frequency;
-            return this;
-        }
-
-        /**
-         * 设置是否忽略debugger模式引起的卡顿
-         *
-         * @param ignoreDebugger
-         * @return
-         */
-        public Builder setIgnoreDebugger(boolean ignoreDebugger) {
-            this.ignoreDebugger = ignoreDebugger;
-            return this;
-        }
-
-        /**
-         * 设置发生卡顿时,是否上报所有的线程信息,默认是false
-         *
-         * @param reportAllThreadInfo
-         * @return
-         */
-        public Builder setReportAllThreadInfo(boolean reportAllThreadInfo) {
-            this.reportAllThreadInfo = reportAllThreadInfo;
-            return this;
-        }
-
-        public Builder setSaveLog(boolean saveLog) {
-            this.saveLog = saveLog;
-            return this;
-        }
-
-        /**
-         * 设置发生卡顿时的回调
-         *
-         * @param onBlockListener
-         * @return
-         */
-        public Builder setOnBlockListener(OnBlockListener onBlockListener) {
-            this.onBlockListener = onBlockListener;
-            return this;
-        }
-
-        public Configuration build() {
-            Configuration configuration = new Configuration();
-            configuration.appContext = appContext;
-            configuration.frequency = frequency;
-            configuration.ignoreDebugger = ignoreDebugger;
-            configuration.reportAllThreadInfo = reportAllThreadInfo;
-            configuration.saveLog = saveLog;
-            configuration.onBlockListener = onBlockListener;
-            return configuration;
-        }
-    }
-
-    private static class Configuration {
-        private Context appContext;
-        private long frequency;
-        private boolean ignoreDebugger;
-        private boolean reportAllThreadInfo;
-        private boolean saveLog;
-        private OnBlockListener onBlockListener;
-    }
-
-    public static interface OnBlockListener {
-        /**
-         * 发生ANR时产生回调(在非UI线程中回调)
-         *
-         * @param blockError
-         */
-        public void onBlock(BlockError blockError);
-    }
-}

+ 0 - 24
androidperformancetoolslibrary/src/main/java/com/performance/tools/utils/StorageUtils.java

@@ -1,24 +0,0 @@
-package com.performance.tools.utils;
-
-import android.os.Environment;
-
-/**
- * Created by Clock on 2017/5/21.
- */
-
-public class StorageUtils {
-
-    private StorageUtils() {
-
-    }
-
-    /**
-     * SD卡是否挂载
-     *
-     * @return
-     */
-    public static boolean isMounted() {
-        return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
-    }
-
-}

+ 0 - 3
androidperformancetoolslibrary/src/main/res/values/strings.xml

@@ -1,3 +0,0 @@
-<resources>
-    <string name="app_name">library</string>
-</resources>

+ 0 - 17
androidperformancetoolslibrary/src/test/java/com/performance/tools/ExampleUnitTest.java

@@ -1,17 +0,0 @@
-package com.performance.tools;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Example local unit test, which will execute on the development machine (host).
- *
- * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
- */
-public class ExampleUnitTest {
-    @Test
-    public void addition_isCorrect() throws Exception {
-        assertEquals(4, 2 + 2);
-    }
-}

+ 6 - 0
app/src/main/AndroidManifest.xml

@@ -14,6 +14,7 @@
     <uses-permission
         android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
         tools:ignore="ProtectedPermissions" />
+    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
 
     <application
         android:name=".base.BaseApplication"
@@ -88,6 +89,11 @@
                 <action android:name="android.intent.action.Timed_Cleaning_Task" />
             </intent-filter>
         </receiver>
+        <receiver android:name=".receiver.BootBroadcastReceiver">
+            <intent-filter>
+                <action android:name="android.intent.action.BOOT_COMPLETED" />
+            </intent-filter>
+        </receiver>
     </application>
 
 </manifest>

+ 1 - 0
app/src/main/java/com/sunzee/mvp/advertising/AdvertisingPresenter.java

@@ -252,6 +252,7 @@ public class AdvertisingPresenter extends BasePresenter<AdvertisingView> {
                 if ("尚未设定清洗规则".equals(times)) {
                     return;
                 }
+                Log.d(TAG, "onSuccess: ");
                 Log.d(TAG, "onSuccess2: " + times);
                 if (!TextUtils.isEmpty(times)) {
                     String[] Alltime = times.split("\\,");

+ 20 - 0
app/src/main/java/com/sunzee/receiver/BootBroadcastReceiver.java

@@ -0,0 +1,20 @@
+package com.sunzee.receiver;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+import com.sunzee.ui.activity.AdvertisingActivity;
+
+public class BootBroadcastReceiver extends BroadcastReceiver {
+    static final String ACTION = "android.intent.action.BOOT_COMPLETED";
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        if (intent.getAction().equals(ACTION)) {
+            Intent mainActivityIntent = new Intent(context, AdvertisingActivity.class);  // 要启动的Activity
+            mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            context.startActivity(mainActivityIntent);
+        }
+    }
+}

+ 16 - 0
app/src/main/java/com/sunzee/ui/fragment/HomepageFragment.java

@@ -6,7 +6,11 @@ import android.support.annotation.Nullable;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.LinearLayout;
 
+import com.hboxs.serialport.SerialPortSendQueue;
+import com.hboxs.serialport.frame.WriteCommandFrame;
+import com.hboxs.serialport.util.HexUtils;
 import com.sunzee.R;
 import com.sunzee.base.MvpFragment;
 import com.sunzee.mvp.homepage.HomePagePresenter;
@@ -21,9 +25,21 @@ public class HomepageFragment extends MvpFragment<HomePagePresenter> implements
     @Override
     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
         View inflate = inflater.inflate(R.layout.fragment_home, container, false);
+        initView(inflate);
         return inflate;
     }
 
+    private void initView(View inflate) {
+        LinearLayout startNumberClean = inflate.findViewById(R.id.start_number_clean);
+        startNumberClean.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                //可以写入成功。
+                SerialPortSendQueue.sendCommand(new WriteCommandFrame("D120", HexUtils.hexStr2BinStr("0002")), 120, "D120");
+            }
+        });
+    }
+
     @Override
     protected HomePagePresenter createPresenter() {
         return null;

+ 1 - 0
app/src/main/res/layout/fragment_home.xml

@@ -21,6 +21,7 @@
         app:layout_constraintTop_toTopOf="parent">
 
         <LinearLayout
+            android:id="@+id/start_number_clean"
             android:layout_width="0dp"
             android:layout_height="@dimen/dp_55"
             android:layout_marginRight="@dimen/dp_7"

+ 0 - 86
config.gradle

@@ -1,86 +0,0 @@
-ext {
-
-    android = [
-            "compileSdkVersion"            : 28,
-            "minSdkVersion"                : 19,
-            "targetSdkVersion"             : 28,
-            "versionCode"                  : 36,
-            "versionName"                  : "1.0.36",
-
-            "androidSupport"               : "28.0.0",
-            "constraint-layout"            : "1.1.3",
-            "junit"                        : '4.12',
-            "runner"                       : '1.0.2',
-            "espresso"                     : '3.0.2',
-            "rxjava"                       : "2.1.16",
-            "rxandroid"                    : "2.0.2",
-            "eventbus"                     : "3.1.1",
-            "rxpermissions"                : "0.10.1",
-            "retrofitSupport"              : "2.4.0",
-            "logging-interceptor"          : "3.10.0",
-            "BaseRecyclerViewAdapterHelper": "2.9.30",
-            "glideSupport"                 : "4.8.0",
-            "hawk"                         : "2.0.1",
-            "fragmentation"                : "1.3.5",
-            "multidex"                     : "1.0.3",
-            "shape"                        : "1.3.4",
-            "glide-transformations"        : "4.0.1",
-            "logger"                       : "2.2.0",
-            //图表
-            "MPAndroidChart"               : "v3.1.0-alpha",
-            //日历
-            "calendarview"                 : '2.0.1',
-            "spinner"                      : '1.3.1',
-            "getui"                        : '2.13.1.0',
-            //loading
-            "zloading"                     : '1.0.11',
-            //greendao
-            "greendao"                     : '3.2.2',
-            "filedownloader":'1.7.6'
-
-
-
-    ]
-
-    dependencies = [
-
-            "appcompat-v7"                 : "com.android.support:appcompat-v7:${android["androidSupport"]}",
-            "design"                       : "com.android.support:design:${android["androidSupport"]}",
-            "recyclerview"                 : "com.android.support:recyclerview-v7:${android["androidSupport"]}",
-            "cardview"                     : "com.android.support:cardview-v7:${android["androidSupport"]}",
-            "constraint-layout"            : "com.android.support.constraint:constraint-layout:${android["constraint-layout"]}",
-            "junit"                        : "junit:junit:${android["junit"]}",
-            "runner"                       : "com.android.support.test:runner:${android["runner"]}",
-            "espresso"                     : "com.android.support.test.espresso:espresso-core:${android["espresso"]}",
-            "rxjava"                       : "io.reactivex.rxjava2:rxjava:${android["rxjava"]}",
-            "rxandroid"                    : "io.reactivex.rxjava2:rxandroid:${android["rxandroid"]}",
-            "eventbus"                     : "org.greenrobot:eventbus:${android["eventbus"]}",
-            "rxpermissions"                : "com.github.tbruyelle:rxpermissions:${android["rxpermissions"]}",
-            "retrofit"                     : "com.squareup.retrofit2:retrofit:${android["retrofitSupport"]}",
-            "converter-gson"               : "com.squareup.retrofit2:converter-gson:${android["retrofitSupport"]}",
-            "adapter-rxjava2"              : "com.squareup.retrofit2:adapter-rxjava2:${android["retrofitSupport"]}",
-            "logging-interceptor"          : "com.squareup.okhttp3:logging-interceptor:${android["logging-interceptor"]}",
-
-            "BaseRecyclerViewAdapterHelper": "com.github.CymChad:BaseRecyclerViewAdapterHelper:${android["BaseRecyclerViewAdapterHelper"]}",
-            "glide"                        : "com.github.bumptech.glide:glide:${android["glideSupport"]}",
-            "glide-compiler"               : "com.github.bumptech.glide:compiler:${android["glideSupport"]}",
-            "hawk"                         : "com.orhanobut:hawk:${android["hawk"]}",
-            "fragmentation"                : "me.yokeyword:fragmentation:${android["fragmentation"]}",
-            "multidex"                     : "com.android.support:multidex:${android["multidex"]}",
-            "shape"                        : "com.noober.background:core:${android["shape"]}",
-            "glide-transformations"        : "jp.wasabeef:glide-transformations:${android["glide-transformations"]}",
-            "logger"                       : "com.orhanobut:logger:${android["logger"]}",
-            "MPAndroidChart"               : "com.github.PhilJay:MPAndroidChart:${android["MPAndroidChart"]}",
-            "calendarview"                 : "com.github.prolificinteractive:material-calendarview:${android["calendarview"]}",
-            "spinner"                      : "com.jaredrummler:material-spinner:${android["spinner"]}",
-            "getui"                        : "com.getui:sdk:${android["getui"]}'",
-
-            "zloading"                     : "com.zyao89:zloading:${android["zloading"]}",
-            "greendao":"org.greenrobot:greendao:${android[ "greendao"]}",
-
-            "filedownloader": "com.liulishuo.filedownloader:library:${android[ "filedownloader"]}"
-
-
-    ]
-
-}