Drop wake on voice
This commit is contained in:
parent
a79649a4ef
commit
950732187d
8 changed files with 1 additions and 236 deletions
|
@ -744,20 +744,6 @@
|
|||
<receiver android:name="net.osmand.plus.notifications.NotificationDismissReceiver" />
|
||||
|
||||
<activity android:name="net.osmand.plus.activities.PrintDialogActivity" />
|
||||
|
||||
<receiver
|
||||
android:name="net.osmand.plus.DeviceAdminRecv"
|
||||
android:label="@string/app_name"
|
||||
android:permission="android.permission.BIND_DEVICE_ADMIN" >
|
||||
<meta-data
|
||||
android:name="android.app.device_admin"
|
||||
android:resource="@xml/device_admin" />
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
|
||||
<action android:name="android.app.action.DEVICE_ADMIN_DISABLED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<activity android:name=".liveupdates.OsmLiveActivity"
|
||||
android:label="@string/osm_live"/>
|
||||
<activity android:name=".wikivoyage.explore.WikivoyageExploreActivity">
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package net.osmand.plus;
|
||||
|
||||
import android.app.admin.DeviceAdminReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
public class DeviceAdminRecv extends DeviceAdminReceiver {
|
||||
|
||||
private static final String TAG = "DeviceAdminReceiver";
|
||||
|
||||
public void onEnabled(Context context, Intent intent) {
|
||||
Log.d(TAG, "permission disabled");
|
||||
}
|
||||
|
||||
public CharSequence onDisableRequested(Context context, Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void onDisabled(Context context, Intent intent) {
|
||||
Log.d(TAG, "permission enabled");
|
||||
}
|
||||
|
||||
}
|
|
@ -1242,16 +1242,6 @@ public class OsmandSettings {
|
|||
KEEP_INFORMING.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 0);
|
||||
}
|
||||
|
||||
// screen power save
|
||||
public final CommonPreference<Integer> WAKE_ON_VOICE_INT = new IntPreference("wake_on_voice_int", 0).makeProfile();
|
||||
|
||||
{
|
||||
// 0 means never
|
||||
WAKE_ON_VOICE_INT.setModeDefaultValue(ApplicationMode.CAR, 0);
|
||||
WAKE_ON_VOICE_INT.setModeDefaultValue(ApplicationMode.BICYCLE, 0);
|
||||
WAKE_ON_VOICE_INT.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 0);
|
||||
}
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
// try without AUTO_FOLLOW_ROUTE_NAV (see forum discussion 'Simplify our navigation preference menu')
|
||||
//public final CommonPreference<Boolean> AUTO_FOLLOW_ROUTE_NAV = new BooleanPreference("auto_follow_route_navigation", true, false);
|
||||
|
|
|
@ -90,11 +90,9 @@ import net.osmand.plus.firstusage.FirstUsageWelcomeFragment;
|
|||
import net.osmand.plus.firstusage.FirstUsageWizardFragment;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.DiscountHelper;
|
||||
import net.osmand.plus.helpers.DiscountHelper.DiscountBarController;
|
||||
import net.osmand.plus.helpers.ExternalApiHelper;
|
||||
import net.osmand.plus.helpers.ImportHelper;
|
||||
import net.osmand.plus.helpers.ImportHelper.ImportGpxBottomSheetDialogFragment;
|
||||
import net.osmand.plus.helpers.WakeLockHelper;
|
||||
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment;
|
||||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||
import net.osmand.plus.mapcontextmenu.MenuController.MenuState;
|
||||
|
@ -192,7 +190,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
private List<DialogProvider> dialogProviders = new ArrayList<>(2);
|
||||
private StateChangedListener<ApplicationMode> applicationModeListener;
|
||||
private ImportHelper importHelper;
|
||||
private WakeLockHelper wakeLockHelper;
|
||||
private boolean intentLocation = false;
|
||||
|
||||
private DashboardOnMap dashboardOnMap = new DashboardOnMap(this);
|
||||
|
@ -312,7 +309,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
addDialogProvider(mapActions);
|
||||
OsmandPlugin.onMapActivityCreate(this);
|
||||
importHelper = new ImportHelper(this, getMyApplication(), getMapView());
|
||||
wakeLockHelper = new WakeLockHelper(getMyApplication());
|
||||
if (System.currentTimeMillis() - tm > 50) {
|
||||
System.err.println("OnCreate for MapActivity took " + (System.currentTimeMillis() - tm) + " ms");
|
||||
}
|
||||
|
@ -518,15 +514,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
pb.setProgressDrawable(AndroidUtils.createProgressDrawable(bgColor, progressColor));
|
||||
}
|
||||
|
||||
private void changeKeyguardFlags() {
|
||||
if (settings.WAKE_ON_VOICE_INT.get() > 0) {
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
|
||||
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
||||
} else {
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
||||
}
|
||||
}
|
||||
|
||||
public ImportHelper getImportHelper() {
|
||||
return importHelper;
|
||||
}
|
||||
|
@ -673,8 +660,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
}
|
||||
|
||||
changeKeyguardFlags();
|
||||
|
||||
applicationModeListener = new StateChangedListener<ApplicationMode>() {
|
||||
@Override
|
||||
public void stateChanged(ApplicationMode change) {
|
||||
|
@ -1213,7 +1198,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
wakeLockHelper.onStart(this);
|
||||
getMyApplication().getNotificationHelper().showNotifications();
|
||||
}
|
||||
|
||||
|
@ -1227,7 +1211,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
wakeLockHelper.onStop(this);
|
||||
getMyApplication().getNotificationHelper().removeNotifications();
|
||||
if(pendingPause) {
|
||||
onPauseActivity();
|
||||
|
@ -1312,7 +1295,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
}
|
||||
|
||||
public void updateApplicationModeSettings() {
|
||||
changeKeyguardFlags();
|
||||
updateMapSettings();
|
||||
mapViewTrackingUtilities.updateSettings();
|
||||
//app.getRoutingHelper().setAppMode(settings.getApplicationMode());
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package net.osmand.plus.activities;
|
||||
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -23,11 +22,9 @@ import android.view.ViewGroup;
|
|||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuItem;
|
||||
import net.osmand.plus.DeviceAdminRecv;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.OsmandSettings.AutoZoomMap;
|
||||
|
@ -45,9 +42,7 @@ import net.osmand.router.GeneralRouter.RoutingParameter;
|
|||
import net.osmand.router.GeneralRouter.RoutingParameterType;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -67,9 +62,6 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
private ListPreference routerServicePreference;
|
||||
private ListPreference speedLimitExceed;
|
||||
|
||||
private ComponentName mDeviceAdmin;
|
||||
private static final int DEVICE_ADMIN_REQUEST = 5;
|
||||
|
||||
private List<RoutingParameter> avoidParameters = new ArrayList<RoutingParameter>();
|
||||
private List<RoutingParameter> preferParameters = new ArrayList<RoutingParameter>();
|
||||
private List<RoutingParameter> reliefFactorParameters = new ArrayList<RoutingParameter>();
|
||||
|
@ -87,41 +79,6 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
|
||||
createUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == DEVICE_ADMIN_REQUEST) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
// Log.d("DeviceAdmin", "Lock screen permission approved.");
|
||||
} else {
|
||||
settings.WAKE_ON_VOICE_INT.set(0);
|
||||
// Log.d("DeviceAdmin", "Lock screen permission refused.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void requestLockScreenAdmin() {
|
||||
mDeviceAdmin = new ComponentName(getApplicationContext(),
|
||||
DeviceAdminRecv.class);
|
||||
|
||||
DevicePolicyManager mDevicePolicyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
|
||||
|
||||
if (!mDevicePolicyManager.isAdminActive(mDeviceAdmin)) {
|
||||
// request permission from user
|
||||
Intent intent = new Intent(
|
||||
DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
|
||||
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
|
||||
mDeviceAdmin);
|
||||
intent.putExtra(
|
||||
DevicePolicyManager.EXTRA_ADD_EXPLANATION,
|
||||
getString(R.string.lock_screen_request_explanation,
|
||||
Version.getAppName(getMyApplication())));
|
||||
startActivityForResult(intent, DEVICE_ADMIN_REQUEST);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private void createUI() {
|
||||
addPreferencesFromResource(R.xml.navigation_settings);
|
||||
|
@ -176,8 +133,6 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
screenPowerSaveNames[i] = screenPowerSaveValues[i] + " "
|
||||
+ getString(R.string.int_seconds);
|
||||
}
|
||||
registerListPreference(settings.WAKE_ON_VOICE_INT, screen, screenPowerSaveNames, screenPowerSaveValues);
|
||||
|
||||
// registerBooleanPreference(settings.SHOW_ZOOM_BUTTONS_NAVIGATION, screen);
|
||||
|
||||
showAlarms = (Preference) screen.findPreference("show_routing_alarms");
|
||||
|
@ -449,16 +404,6 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
+ settings.ROUTER_SERVICE.get() + "]");
|
||||
prepareRoutingPrefs(getPreferenceScreen());
|
||||
super.updateAllSettings();
|
||||
} else if (id.equals(settings.WAKE_ON_VOICE_INT.getId())) {
|
||||
Integer value;
|
||||
try {
|
||||
value = Integer.parseInt(newValue.toString());
|
||||
} catch (NumberFormatException e) {
|
||||
value = 0;
|
||||
}
|
||||
if (value > 0) {
|
||||
requestLockScreenAdmin();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -203,8 +203,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
|
|||
showViewAngle = routePlanningMode; // disable compass rotation in that mode
|
||||
}
|
||||
registerUnregisterSensor(location, smallSpeedForDirectionOfMovement);
|
||||
if (settings.ANIMATE_MY_LOCATION.get() && !smallSpeedForAnimation && !movingToMyLocation &&
|
||||
settings.WAKE_ON_VOICE_INT.get() == 0) {
|
||||
if (settings.ANIMATE_MY_LOCATION.get() && !smallSpeedForAnimation && !movingToMyLocation) {
|
||||
mapView.getAnimatedDraggingThread().startMoving(
|
||||
location.getLatitude(), location.getLongitude(), zoom, rotation, false);
|
||||
} else {
|
||||
|
|
|
@ -1,103 +0,0 @@
|
|||
package net.osmand.plus.helpers;
|
||||
|
||||
import net.osmand.plus.DeviceAdminRecv;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.routing.VoiceRouter;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManager;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public class WakeLockHelper implements VoiceRouter.VoiceMessageListener {
|
||||
|
||||
private PowerManager.WakeLock wakeLock = null;
|
||||
private ReleaseWakeLocksRunnable releaseWakeLocksRunnable = new ReleaseWakeLocksRunnable();
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
private ComponentName mDeviceAdmin;
|
||||
private Handler uiHandler;
|
||||
private OsmandApplication app;
|
||||
private boolean active;
|
||||
|
||||
public WakeLockHelper(OsmandApplication app){
|
||||
uiHandler = new Handler();
|
||||
this.app = app;
|
||||
mDeviceAdmin = new ComponentName(app, DeviceAdminRecv.class);
|
||||
mDevicePolicyManager = (DevicePolicyManager) app.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
}
|
||||
|
||||
private void releaseWakeLocks() {
|
||||
if (wakeLock != null) {
|
||||
wakeLock.release();
|
||||
wakeLock = null;
|
||||
}
|
||||
|
||||
if (mDevicePolicyManager != null && mDeviceAdmin != null) {
|
||||
OsmandSettings settings = app.getSettings();
|
||||
final Integer screenPowerSave = settings.WAKE_ON_VOICE_INT.get();
|
||||
if (screenPowerSave > 0 && settings.MAP_ACTIVITY_ENABLED.get()) {
|
||||
if (mDevicePolicyManager.isAdminActive(mDeviceAdmin)) {
|
||||
try {
|
||||
mDevicePolicyManager.lockNow();
|
||||
} catch (SecurityException e) {
|
||||
// Log.d(TAG,
|
||||
// "SecurityException: No device admin permission to lock the screen!");
|
||||
}
|
||||
} else {
|
||||
// Log.d(TAG,
|
||||
// "No device admin permission to lock the screen!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ReleaseWakeLocksRunnable implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
releaseWakeLocks();
|
||||
}
|
||||
}
|
||||
|
||||
public void onStart(Activity a) {
|
||||
this.active = true;
|
||||
if (wakeLock == null) {
|
||||
VoiceRouter voiceRouter = app.getRoutingHelper().getVoiceRouter();
|
||||
voiceRouter.removeVoiceMessageListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void onStop(Activity a) {
|
||||
this.active = false;
|
||||
OsmandSettings settings = app.getSettings();
|
||||
if (!a.isFinishing() && (settings.WAKE_ON_VOICE_INT.get() > 0)) {
|
||||
VoiceRouter voiceRouter = app.getRoutingHelper().getVoiceRouter();
|
||||
voiceRouter.addVoiceMessageListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVoiceMessage() {
|
||||
OsmandSettings settings = app.getSettings();
|
||||
final Integer screenPowerSave = settings.WAKE_ON_VOICE_INT.get();
|
||||
if (screenPowerSave > 0) {
|
||||
uiHandler.removeCallbacks(releaseWakeLocksRunnable);
|
||||
|
||||
if (!active && wakeLock == null) {
|
||||
PowerManager pm = (PowerManager) app.getSystemService(Context.POWER_SERVICE);
|
||||
wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
|
||||
| PowerManager.ACQUIRE_CAUSES_WAKEUP,
|
||||
"OsmAndOnVoiceWakeupTag");
|
||||
wakeLock.acquire();
|
||||
}
|
||||
|
||||
uiHandler.postDelayed(releaseWakeLocksRunnable,
|
||||
screenPowerSave * 1000L);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -936,15 +936,5 @@ public class VoiceRouter {
|
|||
}
|
||||
|
||||
public void notifyOnVoiceMessage() {
|
||||
if (settings.WAKE_ON_VOICE_INT.get() > 0) {
|
||||
router.getApplication().runInUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (VoiceMessageListener lnt : voiceMessageListeners.keySet()) {
|
||||
lnt.onVoiceMessage();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue