fix locking bag / refuse device admin
This commit is contained in:
parent
d7dd44fea3
commit
0bbea17f56
8 changed files with 56 additions and 39 deletions
|
@ -708,6 +708,5 @@ interface IOsmAndAidlInterface {
|
|||
boolean setCustomization(in CustomizationInfoParams params);
|
||||
long registerForVoiceRouterMessages(in ANavigationVoiceRouterMessageParams params, IOsmAndAidlCallback callback);
|
||||
|
||||
boolean isMapActivityActive();
|
||||
boolean changeMapActivityKeyguardFlags(in boolean enable);
|
||||
}
|
|
@ -1164,17 +1164,6 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMapActivityActive() {
|
||||
try {
|
||||
OsmandAidlApi api = getApi("isMapActivityActive");
|
||||
return api != null && api.isUpdateAllowed();
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean changeMapActivityKeyguardFlags(boolean enable) {
|
||||
try {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
package="net.osmand.turnScreenOn">
|
||||
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.GET_TASKS" />
|
||||
|
||||
<application
|
||||
android:name=".app.TurnScreenApp"
|
||||
|
@ -11,8 +12,9 @@
|
|||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity android:name=".OsmandInstallActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar"></activity>
|
||||
android:theme="@style/AppTheme.NoActionBar"/>
|
||||
<activity
|
||||
android:name=".PluginDescriptionActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
|
|
|
@ -709,6 +709,5 @@ interface IOsmAndAidlInterface {
|
|||
boolean setCustomization(in CustomizationInfoParams params);
|
||||
long registerForVoiceRouterMessages(in ANavigationVoiceRouterMessageParams params, IOsmAndAidlCallback callback);
|
||||
|
||||
boolean isMapActivityActive();
|
||||
boolean changeMapActivityKeyguardFlags(in boolean enable);
|
||||
}
|
|
@ -1,15 +1,23 @@
|
|||
package net.osmand.turnScreenOn.helpers;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static android.content.Context.ACTIVITY_SERVICE;
|
||||
import static android.content.Context.POWER_SERVICE;
|
||||
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
|
||||
|
||||
|
@ -33,12 +41,39 @@ public class AndroidUtils {
|
|||
|
||||
public static boolean isScreenOn(Context context) {
|
||||
PowerManager powerManager = (PowerManager) context.getSystemService(POWER_SERVICE);
|
||||
return Build.VERSION.SDK_INT>= Build.VERSION_CODES.KITKAT_WATCH&&powerManager.isInteractive()
|
||||
|| Build.VERSION.SDK_INT< Build.VERSION_CODES.KITKAT_WATCH&&powerManager.isScreenOn();
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH && powerManager.isInteractive()
|
||||
|| Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH && powerManager.isScreenOn();
|
||||
}
|
||||
|
||||
public static boolean isScreenLocked(Context context) {
|
||||
KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
|
||||
return keyguardManager.inKeyguardRestrictedInputMode();
|
||||
}
|
||||
|
||||
public static boolean isOnForeground(Context ctx, String appPackage) {
|
||||
if (ContextCompat.checkSelfPermission(ctx, Manifest.permission.GET_TASKS)
|
||||
== PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityManager manager = (ActivityManager) ctx.getSystemService(ACTIVITY_SERVICE);
|
||||
List<ActivityManager.RunningTaskInfo> runningTaskInfo = manager.getRunningTasks(1);
|
||||
|
||||
ComponentName componentInfo = runningTaskInfo.get(0).topActivity;
|
||||
if (componentInfo.getPackageName().equals(appPackage)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isOpened(Context ctx, String appPackage) {
|
||||
ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses();
|
||||
|
||||
for (int i = 0; i < runningAppProcessInfo.size(); i++) {
|
||||
if (runningAppProcessInfo.get(i).processName.equals(appPackage)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.content.ComponentName;
|
|||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManager;
|
||||
import android.util.Log;
|
||||
|
||||
import net.osmand.turnScreenOn.app.TurnScreenApp;
|
||||
import net.osmand.turnScreenOn.listener.LockObservable;
|
||||
|
@ -35,7 +36,9 @@ public class LockHelper implements LockObservable {
|
|||
|
||||
private void releaseWakeLocks() {
|
||||
if (wakeLock != null) {
|
||||
if (wakeLock.isHeld()) {
|
||||
wakeLock.release();
|
||||
}
|
||||
wakeLock = null;
|
||||
}
|
||||
}
|
||||
|
@ -44,26 +47,26 @@ public class LockHelper implements LockObservable {
|
|||
if (readyToLock()) {
|
||||
notifyOnLock();
|
||||
releaseWakeLocks();
|
||||
if (functionEnable && !AndroidUtils.isScreenLocked(app)) {
|
||||
/*if (functionEnable) {
|
||||
mDevicePolicyManager.lockNow();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
public void unlock() {
|
||||
public void unlock(long timeInMills) {
|
||||
if (readyToUnlock()) {
|
||||
notifyOnUnlock();
|
||||
PowerManager pm = (PowerManager) app.getSystemService(Context.POWER_SERVICE);
|
||||
wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
|
||||
| PowerManager.ACQUIRE_CAUSES_WAKEUP
|
||||
| PowerManager.ON_AFTER_RELEASE, "tso:wakelocktag");
|
||||
wakeLock.acquire();
|
||||
| PowerManager.ACQUIRE_CAUSES_WAKEUP, "tso:wakelocktag");
|
||||
wakeLock.acquire(timeInMills);
|
||||
}
|
||||
}
|
||||
|
||||
public void timedUnlock(long millis) {
|
||||
Log.d("ttpl", "timedUnlock: try to unlock");
|
||||
uiHandler.removeCallbacks(lockRunnable);
|
||||
unlock();
|
||||
unlock(millis);
|
||||
uiHandler.postDelayed(lockRunnable, millis);
|
||||
}
|
||||
|
||||
|
@ -74,6 +77,7 @@ public class LockHelper implements LockObservable {
|
|||
}
|
||||
|
||||
private boolean readyToUnlock() {
|
||||
releaseWakeLocks();
|
||||
return wakeLock == null;
|
||||
}
|
||||
|
||||
|
|
|
@ -130,16 +130,6 @@ public class OsmAndAidlHelper implements MessageObservable {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isMapActivityActive() {
|
||||
try {
|
||||
if (mIOsmAndAidlInterface != null) {
|
||||
return mIOsmAndAidlInterface.isMapActivityActive();
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void changeMapActivityKeyguardFlags(boolean newState) {
|
||||
try {
|
||||
if (mIOsmAndAidlInterface != null) {
|
||||
|
|
|
@ -4,12 +4,10 @@ import net.osmand.turnScreenOn.PluginSettings;
|
|||
import net.osmand.turnScreenOn.app.TurnScreenApp;
|
||||
import net.osmand.turnScreenOn.helpers.AndroidUtils;
|
||||
import net.osmand.turnScreenOn.helpers.LockHelper;
|
||||
import net.osmand.turnScreenOn.helpers.OsmAndAidlHelper;
|
||||
|
||||
public class UnlockMessageListener implements OnMessageListener {
|
||||
private TurnScreenApp app;
|
||||
private PluginSettings settings;
|
||||
private OsmAndAidlHelper osmAndAidlHelper;
|
||||
private LockHelper lockHelper;
|
||||
|
||||
public UnlockMessageListener(TurnScreenApp app) {
|
||||
|
@ -17,14 +15,15 @@ public class UnlockMessageListener implements OnMessageListener {
|
|||
|
||||
settings = app.getSettings();
|
||||
lockHelper = app.getLockHelper();
|
||||
osmAndAidlHelper = app.getOsmAndAidlHelper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceive() {
|
||||
boolean isScreenOn = AndroidUtils.isScreenOn(app);
|
||||
boolean isScreenLocked = AndroidUtils.isScreenLocked(app);
|
||||
if ((!isScreenOn || isScreenLocked) && osmAndAidlHelper.isMapActivityActive()) {
|
||||
boolean isOnForeground = AndroidUtils.isOpened(app, settings.getOsmandVersion().getPath());
|
||||
|
||||
if ((!isScreenOn || isScreenLocked) && isOnForeground) {
|
||||
if (settings != null && lockHelper != null) {
|
||||
if (settings.isAdminDevicePermissionAvailable()) {
|
||||
PluginSettings.UnlockTime time = settings.getTime();
|
||||
|
|
Loading…
Reference in a new issue