Сравнить коммиты
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
3f83684d02 | ||
|
|
a9d772bfda | ||
|
|
2bc3c78a91 | ||
|
|
8fab55552d | ||
|
|
979963f6a2 | ||
|
|
70d6dfec4e | ||
|
|
43e108de8c | ||
|
|
fedce0e26b | ||
|
|
e24d725feb | ||
|
|
3198bee2f2 |
@@ -9,8 +9,8 @@ android {
|
|||||||
buildConfigField "boolean", "HIDDEN_APP", "false"
|
buildConfigField "boolean", "HIDDEN_APP", "false"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 26
|
targetSdkVersion 26
|
||||||
versionCode 37
|
versionCode 41
|
||||||
versionName '5.0'
|
versionName '5.4'
|
||||||
}
|
}
|
||||||
|
|
||||||
lintOptions {
|
lintOptions {
|
||||||
|
|||||||
@@ -55,6 +55,9 @@
|
|||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||||
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
|
* Copyright 2013 - 2017 Anton Tananaev (anton.tananaev@gmail.com)
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -19,7 +19,6 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.content.WakefulBroadcastReceiver;
|
|
||||||
|
|
||||||
public class AutostartReceiver extends WakefulBroadcastReceiver {
|
public class AutostartReceiver extends WakefulBroadcastReceiver {
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,11 @@ import android.app.Notification;
|
|||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
public class MainApplication extends Application {
|
public class MainApplication extends Application {
|
||||||
|
|
||||||
@@ -33,6 +36,8 @@ public class MainApplication extends Application {
|
|||||||
super.onCreate();
|
super.onCreate();
|
||||||
System.setProperty("http.keepAliveDuration", String.valueOf(30 * 60 * 1000));
|
System.setProperty("http.keepAliveDuration", String.valueOf(30 * 60 * 1000));
|
||||||
|
|
||||||
|
migrateLegacyPreferences(PreferenceManager.getDefaultSharedPreferences(this));
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
registerChannel();
|
registerChannel();
|
||||||
}
|
}
|
||||||
@@ -47,4 +52,22 @@ public class MainApplication extends Application {
|
|||||||
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);
|
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void migrateLegacyPreferences(SharedPreferences preferences) {
|
||||||
|
String port = preferences.getString("port", null);
|
||||||
|
if (port != null) {
|
||||||
|
String host = preferences.getString("address", getString(R.string.settings_url_default_value));
|
||||||
|
String scheme = preferences.getBoolean("secure", false) ? "https" : "http";
|
||||||
|
|
||||||
|
Uri.Builder builder = new Uri.Builder();
|
||||||
|
builder.scheme(scheme).encodedAuthority(host + ":" + port).build();
|
||||||
|
SharedPreferences.Editor editor = preferences.edit();
|
||||||
|
editor.putString(MainFragment.KEY_URL, builder.toString());
|
||||||
|
|
||||||
|
editor.remove("port");
|
||||||
|
editor.remove("address");
|
||||||
|
editor.remove("secure");
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ public class MainFragment extends PreferenceFragment implements OnSharedPreferen
|
|||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||||
migrateLegacyPreferences(sharedPreferences);
|
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
initPreferences();
|
initPreferences();
|
||||||
|
|
||||||
@@ -288,24 +287,4 @@ public class MainFragment extends PreferenceFragment implements OnSharedPreferen
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void migrateLegacyPreferences(SharedPreferences preferences) {
|
|
||||||
String port = preferences.getString("port", null);
|
|
||||||
if (port != null) {
|
|
||||||
Log.d(TAG, "Migrating to URL preference");
|
|
||||||
|
|
||||||
String host = preferences.getString("address", getString(R.string.settings_url_default_value));
|
|
||||||
String scheme = preferences.getBoolean("secure", false) ? "https" : "http";
|
|
||||||
|
|
||||||
Uri.Builder builder = new Uri.Builder();
|
|
||||||
builder.scheme(scheme).encodedAuthority(host + ":" + port).build();
|
|
||||||
SharedPreferences.Editor editor = preferences.edit();
|
|
||||||
editor.putString(KEY_URL, builder.toString());
|
|
||||||
|
|
||||||
editor.remove("port");
|
|
||||||
editor.remove("address");
|
|
||||||
editor.remove("secure");
|
|
||||||
editor.apply();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
|
* Copyright 2015 - 2017 Anton Tananaev (anton.tananaev@gmail.com)
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -75,8 +75,12 @@ public class MixedPositionProvider extends PositionProvider implements LocationL
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
locationManager.requestLocationUpdates(
|
locationManager.requestLocationUpdates(
|
||||||
LocationManager.NETWORK_PROVIDER, requestInterval, 0, backupListener);
|
LocationManager.NETWORK_PROVIDER, requestInterval, 0, backupListener);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
Log.w(TAG, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,10 +56,10 @@ public abstract class PositionProvider {
|
|||||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
|
||||||
deviceId = preferences.getString(MainFragment.KEY_DEVICE, null);
|
deviceId = preferences.getString(MainFragment.KEY_DEVICE, "undefined");
|
||||||
interval = Long.parseLong(preferences.getString(MainFragment.KEY_INTERVAL, null)) * 1000;
|
interval = Long.parseLong(preferences.getString(MainFragment.KEY_INTERVAL, "600")) * 1000;
|
||||||
distance = Integer.parseInt(preferences.getString(MainFragment.KEY_DISTANCE, null));
|
distance = Integer.parseInt(preferences.getString(MainFragment.KEY_DISTANCE, "0"));
|
||||||
angle = Integer.parseInt(preferences.getString(MainFragment.KEY_ANGLE, null));
|
angle = Integer.parseInt(preferences.getString(MainFragment.KEY_ANGLE, "0"));
|
||||||
|
|
||||||
if (distance > 0 || angle > 0) {
|
if (distance > 0 || angle > 0) {
|
||||||
requestInterval = MINIMUM_INTERVAL;
|
requestInterval = MINIMUM_INTERVAL;
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ public class RequestManager {
|
|||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
connection.setReadTimeout(TIMEOUT);
|
connection.setReadTimeout(TIMEOUT);
|
||||||
connection.setConnectTimeout(TIMEOUT);
|
connection.setConnectTimeout(TIMEOUT);
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
connection.connect();
|
connection.connect();
|
||||||
inputStream = connection.getInputStream();
|
inputStream = connection.getInputStream();
|
||||||
while (inputStream.read() != -1);
|
while (inputStream.read() != -1);
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class TrackingController implements PositionProvider.PositionListener, Ne
|
|||||||
networkManager = new NetworkManager(context, this);
|
networkManager = new NetworkManager(context, this);
|
||||||
isOnline = networkManager.isOnline();
|
isOnline = networkManager.isOnline();
|
||||||
|
|
||||||
url = preferences.getString(MainFragment.KEY_URL, null);
|
url = preferences.getString(MainFragment.KEY_URL, context.getString(R.string.settings_url_default_value));
|
||||||
|
|
||||||
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||||
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
|
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.traccar.client;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.PowerManager;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.util.SparseArray;
|
||||||
|
|
||||||
|
public abstract class WakefulBroadcastReceiver extends BroadcastReceiver {
|
||||||
|
private static final String EXTRA_WAKE_LOCK_ID = "android.support.content.wakelockid";
|
||||||
|
private static final SparseArray<PowerManager.WakeLock> mActiveWakeLocks = new SparseArray<>();
|
||||||
|
private static int mNextId = 1;
|
||||||
|
|
||||||
|
public static void startWakefulService(Context context, Intent intent) {
|
||||||
|
synchronized (mActiveWakeLocks) {
|
||||||
|
int id = mNextId;
|
||||||
|
mNextId++;
|
||||||
|
if (mNextId <= 0) {
|
||||||
|
mNextId = 1;
|
||||||
|
}
|
||||||
|
intent.putExtra(EXTRA_WAKE_LOCK_ID, id);
|
||||||
|
ContextCompat.startForegroundService(context, intent);
|
||||||
|
PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
|
||||||
|
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
||||||
|
WakefulBroadcastReceiver.class.getSimpleName());
|
||||||
|
wl.setReferenceCounted(false);
|
||||||
|
wl.acquire(60*1000);
|
||||||
|
mActiveWakeLocks.put(id, wl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean completeWakefulIntent(Intent intent) {
|
||||||
|
final int id = intent.getIntExtra(EXTRA_WAKE_LOCK_ID, 0);
|
||||||
|
if (id == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
synchronized (mActiveWakeLocks) {
|
||||||
|
PowerManager.WakeLock wl = mActiveWakeLocks.get(id);
|
||||||
|
if (wl != null) {
|
||||||
|
wl.release();
|
||||||
|
mActiveWakeLocks.remove(id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,6 @@
|
|||||||
<string name="settings_id_title">Device identifier</string>
|
<string name="settings_id_title">Device identifier</string>
|
||||||
<string name="settings_url_title">Server URL</string>
|
<string name="settings_url_title">Server URL</string>
|
||||||
<string name="settings_url_summary">Tracking server URL</string>
|
<string name="settings_url_summary">Tracking server URL</string>
|
||||||
<string name="settings_url_default_value" translatable="false">http://demo.traccar.org:5055</string>
|
|
||||||
<string name="settings_interval_title">Frequency</string>
|
<string name="settings_interval_title">Frequency</string>
|
||||||
<string name="settings_interval_summary">Reporting interval in seconds</string>
|
<string name="settings_interval_summary">Reporting interval in seconds</string>
|
||||||
<string name="settings_distance_title">Distance</string>
|
<string name="settings_distance_title">Distance</string>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
|
<string name="settings_url_default_value" translatable="false">http://demo.traccar.org:5055</string>
|
||||||
|
|
||||||
<string-array name="settings_provider_values" translatable="false">
|
<string-array name="settings_provider_values" translatable="false">
|
||||||
<item>gps</item>
|
<item>gps</item>
|
||||||
<item>network</item>
|
<item>network</item>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
package org.traccar.client;
|
package org.traccar.client;
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
@@ -12,6 +13,7 @@ import static org.junit.Assert.assertTrue;
|
|||||||
@Config(constants = BuildConfig.class, sdk = 21)
|
@Config(constants = BuildConfig.class, sdk = 21)
|
||||||
public class RequestManagerTest {
|
public class RequestManagerTest {
|
||||||
|
|
||||||
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void testSendRequest() throws Exception {
|
public void testSendRequest() throws Exception {
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user