diff --git a/app/build.gradle b/app/build.gradle index 34704bc..f4ea6f4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -112,6 +112,7 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) + compileOnly files('src/main/libs/classes.jar') implementation 'androidx.appcompat:appcompat:1.2.0' //implementation 'com.android.support:multidex:1.0.3' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1519a9d..ea08459 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,10 +11,11 @@ - - - - + + + + + @@ -56,6 +57,16 @@ android:roundIcon="@mipmap/ic_launcher" android:supportsRtl="true" android:theme="@style/AppTheme"> + + + + + + + - @@ -207,7 +219,14 @@ - + + + + + + @@ -242,15 +261,13 @@ - + android:exported="true" /> - + android:value="edf9cec22731b8b2fed56ee6" /> diff --git a/app/src/main/java/com/info/sn/activity/TopActivity.java b/app/src/main/java/com/info/sn/activity/ScreenLockActivity.java similarity index 65% rename from app/src/main/java/com/info/sn/activity/TopActivity.java rename to app/src/main/java/com/info/sn/activity/ScreenLockActivity.java index da20344..575d14b 100644 --- a/app/src/main/java/com/info/sn/activity/TopActivity.java +++ b/app/src/main/java/com/info/sn/activity/ScreenLockActivity.java @@ -3,18 +3,22 @@ package com.info.sn.activity; import android.content.Intent; import android.os.Bundle; import android.view.KeyEvent; +import android.view.MotionEvent; +import android.view.WindowManager; import androidx.appcompat.app.AppCompatActivity; import com.info.sn.R; -public class TopActivity extends AppCompatActivity { +public class ScreenLockActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_top); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); + setContentView(R.layout.activity_screen_lock); + } @Override @@ -30,4 +34,9 @@ public class TopActivity extends AppCompatActivity { } return super.onKeyDown(keyCode, event); } + + @Override + public void onBackPressed() { + + } } diff --git a/app/src/main/java/com/info/sn/receiver/BootReceiver.java b/app/src/main/java/com/info/sn/receiver/BootReceiver.java index 4f94e5b..6709da3 100644 --- a/app/src/main/java/com/info/sn/receiver/BootReceiver.java +++ b/app/src/main/java/com/info/sn/receiver/BootReceiver.java @@ -8,6 +8,7 @@ import android.util.Log; import com.info.sn.service.GuardService; import com.info.sn.service.InitJpushServer; import com.info.sn.service.MyDownloadService; +import com.info.sn.service.ScreenLockService; import com.info.sn.service.StepService; @@ -35,6 +36,8 @@ public class BootReceiver extends BroadcastReceiver { context.startService(new Intent(context, StepService.class)); context.startService(new Intent(context, InitJpushServer.class)); context.startService(new Intent(context, MyDownloadService.class)); + context.startService(new Intent(context, ScreenLockService.class)); + } } } diff --git a/app/src/main/java/com/info/sn/service/InitJpushServer.java b/app/src/main/java/com/info/sn/service/InitJpushServer.java index ad15fc1..dd4da52 100644 --- a/app/src/main/java/com/info/sn/service/InitJpushServer.java +++ b/app/src/main/java/com/info/sn/service/InitJpushServer.java @@ -15,6 +15,7 @@ import android.util.DisplayMetrics; import android.util.Log; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.view.WindowManager; import android.widget.Button; import android.widget.TextView; @@ -27,8 +28,7 @@ import com.info.sn.bean.BaseResponse; import com.info.sn.network.HTTPInterface; import com.info.sn.network.NetWorkManager; import com.info.sn.network.api.ScreenLock; -import com.info.sn.utils.ApkUtils; -import com.info.sn.utils.ForegroundAppUtil; +import com.info.sn.utils.SPUtils; import com.info.sn.utils.TimeUtils; import com.info.sn.utils.Utils; @@ -103,23 +103,38 @@ public class InitJpushServer extends Service { showFloatingWindow("屏幕已锁定"); } screenlocked = true; + SPUtils.put(InitJpushServer.this, LOCK_STATE, 1); } else { if (!timelocked) { hideFloatingWindow(); } screenlocked = false; + SPUtils.put(InitJpushServer.this, LOCK_STATE, 0); } } else { if (!timelocked) { hideFloatingWindow(); } screenlocked = false; + SPUtils.put(InitJpushServer.this, LOCK_STATE, 0); } } @Override public void onError(Throwable e) { - + Log.e("getScreenLockState", "onError: " + e.getMessage()); + int is_screen_lock = (int) SPUtils.get(InitJpushServer.this, LOCK_STATE, 0); + if (is_screen_lock == 1) { + if (!timelocked) { + showFloatingWindow("屏幕已锁定"); + } + screenlocked = true; + } else { + if (!timelocked) { + hideFloatingWindow(); + } + screenlocked = false; + } } @Override @@ -137,6 +152,8 @@ public class InitJpushServer extends Service { boolean screenlocked = false; boolean timelocked = false; + private static final String LOCK_STATE = "SCRENN_LOOCKED_STATE"; + private void showFloatingWindow(String name) { if (Settings.canDrawOverlays(this)) { // 获取WindowManager服务 @@ -159,7 +176,7 @@ public class InitJpushServer extends Service { } }); if (null == topView) { - topView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.activity_top, null); + topView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.activity_screen_lock, null); TextView textView = topView.findViewById(R.id.textView); textView.setText(name); } else { @@ -173,17 +190,26 @@ public class InitJpushServer extends Service { // 设置LayoutParam WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; + layoutParams.type = WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG; + //TYPE_SYSTEM_OVERLAY可以下滑通知栏 +// layoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; } else { layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE; } - layoutParams.flags = WindowManager.LayoutParams.FLAG_BLUR_BEHIND; + layoutParams.flags |= WindowManager.LayoutParams.FLAG_BLUR_BEHIND + | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED + | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; layoutParams.format = PixelFormat.RGBA_8888; - layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; - layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT; + layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; + layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT; + //systemUiVisibility 关闭通知栏和导航栏 + + layoutParams.systemUiVisibility = + View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_IMMERSIVE + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; layoutParams.x = 0; layoutParams.y = 0; - // 将悬浮窗控件添加到WindowManager windowManager.addView(topView, layoutParams); topView.setTag("added"); diff --git a/app/src/main/libs/classes.jar b/app/src/main/libs/classes.jar new file mode 100644 index 0000000..fefe7ec Binary files /dev/null and b/app/src/main/libs/classes.jar differ diff --git a/app/src/main/res/layout-land/activity_top.xml b/app/src/main/res/layout-land/activity_screen_lock.xml similarity index 90% rename from app/src/main/res/layout-land/activity_top.xml rename to app/src/main/res/layout-land/activity_screen_lock.xml index 878af5a..9108cf1 100644 --- a/app/src/main/res/layout-land/activity_top.xml +++ b/app/src/main/res/layout-land/activity_screen_lock.xml @@ -5,13 +5,13 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/gray" - tools:context=".activity.TopActivity"> + tools:context=".activity.ScreenLockActivity"> + tools:context=".activity.ScreenLockActivity">