Сравнить коммиты
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
453edfa97e | ||
|
|
4c6c79b6a2 | ||
|
|
93456bf7fb | ||
|
|
a2ff7fcb38 | ||
|
|
7015f75edb | ||
|
|
636ceaf027 |
+10
-9
@@ -1,15 +1,15 @@
|
|||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 28
|
compileSdkVersion 29
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "org.traccar.client"
|
applicationId "org.traccar.client"
|
||||||
buildConfigField "boolean", "HIDDEN_APP", "false"
|
buildConfigField "boolean", "HIDDEN_APP", "false"
|
||||||
minSdkVersion 15
|
minSdkVersion 16
|
||||||
targetSdkVersion 28
|
targetSdkVersion 29
|
||||||
versionCode 55
|
versionCode 59
|
||||||
versionName '5.18'
|
versionName '5.22'
|
||||||
}
|
}
|
||||||
|
|
||||||
lintOptions {
|
lintOptions {
|
||||||
@@ -34,12 +34,13 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.google.android.material:material:1.1.0-alpha02'
|
implementation 'com.google.android.material:material:1.1.0-alpha10'
|
||||||
|
implementation 'androidx.preference:preference:1.1.0'
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
testImplementation 'org.robolectric:robolectric:4.1'
|
testImplementation 'org.robolectric:robolectric:4.1'
|
||||||
googleImplementation 'com.google.firebase:firebase-core:16.0.6'
|
googleImplementation 'com.google.firebase:firebase-core:17.2.0'
|
||||||
googleImplementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
|
googleImplementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
|
||||||
googleImplementation "com.google.android.gms:play-services-location:16.0.0"
|
googleImplementation "com.google.android.gms:play-services-location:17.0.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getGradle().getStartParameter().getTaskRequests().toString().contains("Google")) {
|
if (getGradle().getStartParameter().getTaskRequests().toString().contains("Google")) {
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
|
|
||||||
<application
|
<application
|
||||||
android:name="org.traccar.client.GoogleMainApplication"
|
android:name="org.traccar.client.GoogleMainApplication"
|
||||||
tools:replace="android:name">
|
tools:replace="android:name"
|
||||||
|
tools:ignore="GoogleAppIndexingWarning">
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest
|
<manifest
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
package="org.traccar.client">
|
package="org.traccar.client">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
@@ -21,7 +23,8 @@
|
|||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/AppTheme"
|
android:theme="@style/AppTheme"
|
||||||
android:name=".MainApplication">
|
android:name=".MainApplication"
|
||||||
|
tools:ignore="GoogleAppIndexingWarning">
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="google_analytics_adid_collection_enabled"
|
android:name="google_analytics_adid_collection_enabled"
|
||||||
@@ -45,8 +48,6 @@
|
|||||||
|
|
||||||
<activity android:name=".StatusActivity"/>
|
<activity android:name=".StatusActivity"/>
|
||||||
|
|
||||||
<activity android:name=".AboutActivity"/>
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ShortcutActivity"
|
android:name=".ShortcutActivity"
|
||||||
android:label="@string/menu_shortcuts">
|
android:label="@string/menu_shortcuts">
|
||||||
@@ -56,9 +57,12 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<service android:name=".TrackingService" />
|
<service
|
||||||
|
android:name=".TrackingService"
|
||||||
|
android:foregroundServiceType="location" />
|
||||||
|
|
||||||
<service android:name=".TrackingService$HideNotificationService" />
|
<service
|
||||||
|
android:name=".TrackingService$HideNotificationService" />
|
||||||
|
|
||||||
<receiver android:name=".AutostartReceiver">
|
<receiver android:name=".AutostartReceiver">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org)
|
|
||||||
*
|
|
||||||
* 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.pm.PackageManager.NameNotFoundException;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
public class AboutActivity extends AppCompatActivity {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.about);
|
|
||||||
|
|
||||||
TextView title = findViewById(R.id.title);
|
|
||||||
try {
|
|
||||||
title.setText(title.getText() + " " + getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName);
|
|
||||||
} catch (NameNotFoundException e) {
|
|
||||||
Log.w(AboutActivity.class.getSimpleName(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -25,7 +25,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
getFragmentManager().beginTransaction().replace(android.R.id.content, new MainFragment()).commit();
|
getSupportFragmentManager().beginTransaction().replace(android.R.id.content, new MainFragment()).commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org)
|
* Copyright 2012 - 2019 Anton Tananaev (anton@traccar.org)
|
||||||
*
|
*
|
||||||
* 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.
|
||||||
@@ -27,14 +27,15 @@ import android.content.pm.PackageManager;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.EditTextPreference;
|
|
||||||
import android.preference.Preference;
|
|
||||||
import android.preference.PreferenceFragment;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.preference.TwoStatePreference;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.preference.EditTextPreference;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
|
import androidx.preference.TwoStatePreference;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
@@ -42,9 +43,11 @@ import android.view.MenuItem;
|
|||||||
import android.webkit.URLUtil;
|
import android.webkit.URLUtil;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MainFragment extends PreferenceFragment implements OnSharedPreferenceChangeListener {
|
public class MainFragment extends PreferenceFragmentCompat implements OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
private static final String TAG = MainFragment.class.getSimpleName();
|
private static final String TAG = MainFragment.class.getSimpleName();
|
||||||
|
|
||||||
@@ -66,15 +69,14 @@ public class MainFragment extends PreferenceFragment implements OnSharedPreferen
|
|||||||
private PendingIntent alarmIntent;
|
private PendingIntent alarmIntent;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
super.onCreate(savedInstanceState);
|
if (BuildConfig.HIDDEN_APP && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||||
if (BuildConfig.HIDDEN_APP) {
|
|
||||||
removeLauncherIcon();
|
removeLauncherIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
initPreferences();
|
initPreferences();
|
||||||
|
|
||||||
@@ -129,6 +131,7 @@ public class MainFragment extends PreferenceFragment implements OnSharedPreferen
|
|||||||
if (sharedPreferences.getBoolean(KEY_STATUS, false)) {
|
if (sharedPreferences.getBoolean(KEY_STATUS, false)) {
|
||||||
startTrackingService(true, false);
|
startTrackingService(true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeLauncherIcon() {
|
private void removeLauncherIcon() {
|
||||||
@@ -192,9 +195,6 @@ public class MainFragment extends PreferenceFragment implements OnSharedPreferen
|
|||||||
if (item.getItemId() == R.id.status) {
|
if (item.getItemId() == R.id.status) {
|
||||||
startActivity(new Intent(getActivity(), StatusActivity.class));
|
startActivity(new Intent(getActivity(), StatusActivity.class));
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getItemId() == R.id.about) {
|
|
||||||
startActivity(new Intent(getActivity(), AboutActivity.class));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
@@ -212,11 +212,18 @@ public class MainFragment extends PreferenceFragment implements OnSharedPreferen
|
|||||||
|
|
||||||
private void startTrackingService(boolean checkPermission, boolean permission) {
|
private void startTrackingService(boolean checkPermission, boolean permission) {
|
||||||
if (checkPermission) {
|
if (checkPermission) {
|
||||||
if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
|
Set<String> requiredPermissions = new HashSet<>();
|
||||||
permission = true;
|
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
} else {
|
requiredPermissions.add(Manifest.permission.ACCESS_FINE_LOCATION);
|
||||||
|
}
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
|
||||||
|
&& ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
requiredPermissions.add(Manifest.permission.ACCESS_BACKGROUND_LOCATION);
|
||||||
|
}
|
||||||
|
permission = requiredPermissions.isEmpty();
|
||||||
|
if (!permission) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_REQUEST_LOCATION);
|
requestPermissions(requiredPermissions.toArray(new String[requiredPermissions.size()]), PERMISSIONS_REQUEST_LOCATION);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -224,12 +231,12 @@ public class MainFragment extends PreferenceFragment implements OnSharedPreferen
|
|||||||
|
|
||||||
if (permission) {
|
if (permission) {
|
||||||
setPreferencesEnabled(false);
|
setPreferencesEnabled(false);
|
||||||
ContextCompat.startForegroundService(getActivity(), new Intent(getActivity(), TrackingService.class));
|
ContextCompat.startForegroundService(getContext(), new Intent(getActivity(), TrackingService.class));
|
||||||
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
||||||
ALARM_MANAGER_INTERVAL, ALARM_MANAGER_INTERVAL, alarmIntent);
|
ALARM_MANAGER_INTERVAL, ALARM_MANAGER_INTERVAL, alarmIntent);
|
||||||
} else {
|
} else {
|
||||||
sharedPreferences.edit().putBoolean(KEY_STATUS, false).apply();
|
sharedPreferences.edit().putBoolean(KEY_STATUS, false).apply();
|
||||||
TwoStatePreference preference = (TwoStatePreference) findPreference(KEY_STATUS);
|
TwoStatePreference preference = findPreference(KEY_STATUS);
|
||||||
preference.setChecked(false);
|
preference.setChecked(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package org.traccar.client;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.PowerManager;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -41,18 +40,6 @@ public class TrackingController implements PositionProvider.PositionListener, Ne
|
|||||||
private DatabaseHelper databaseHelper;
|
private DatabaseHelper databaseHelper;
|
||||||
private NetworkManager networkManager;
|
private NetworkManager networkManager;
|
||||||
|
|
||||||
private PowerManager.WakeLock wakeLock;
|
|
||||||
|
|
||||||
private void lock() {
|
|
||||||
wakeLock.acquire(WAKE_LOCK_TIMEOUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void unlock() {
|
|
||||||
if (wakeLock.isHeld()) {
|
|
||||||
wakeLock.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public TrackingController(Context context) {
|
public TrackingController(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
handler = new Handler();
|
handler = new Handler();
|
||||||
@@ -63,9 +50,6 @@ public class TrackingController implements PositionProvider.PositionListener, Ne
|
|||||||
isOnline = networkManager.isOnline();
|
isOnline = networkManager.isOnline();
|
||||||
|
|
||||||
url = preferences.getString(MainFragment.KEY_URL, context.getString(R.string.settings_url_default_value));
|
url = preferences.getString(MainFragment.KEY_URL, context.getString(R.string.settings_url_default_value));
|
||||||
|
|
||||||
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
|
||||||
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
@@ -133,7 +117,6 @@ public class TrackingController implements PositionProvider.PositionListener, Ne
|
|||||||
|
|
||||||
private void write(Position position) {
|
private void write(Position position) {
|
||||||
log("write", position);
|
log("write", position);
|
||||||
lock();
|
|
||||||
databaseHelper.insertPositionAsync(position, new DatabaseHelper.DatabaseHandler<Void>() {
|
databaseHelper.insertPositionAsync(position, new DatabaseHelper.DatabaseHandler<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public void onComplete(boolean success, Void result) {
|
public void onComplete(boolean success, Void result) {
|
||||||
@@ -143,14 +126,12 @@ public class TrackingController implements PositionProvider.PositionListener, Ne
|
|||||||
isWaiting = false;
|
isWaiting = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unlock();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void read() {
|
private void read() {
|
||||||
log("read", null);
|
log("read", null);
|
||||||
lock();
|
|
||||||
databaseHelper.selectPositionAsync(new DatabaseHelper.DatabaseHandler<Position>() {
|
databaseHelper.selectPositionAsync(new DatabaseHelper.DatabaseHandler<Position>() {
|
||||||
@Override
|
@Override
|
||||||
public void onComplete(boolean success, Position result) {
|
public void onComplete(boolean success, Position result) {
|
||||||
@@ -167,14 +148,12 @@ public class TrackingController implements PositionProvider.PositionListener, Ne
|
|||||||
} else {
|
} else {
|
||||||
retry();
|
retry();
|
||||||
}
|
}
|
||||||
unlock();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void delete(Position position) {
|
private void delete(Position position) {
|
||||||
log("delete", position);
|
log("delete", position);
|
||||||
lock();
|
|
||||||
databaseHelper.deletePositionAsync(position.getId(), new DatabaseHelper.DatabaseHandler<Void>() {
|
databaseHelper.deletePositionAsync(position.getId(), new DatabaseHelper.DatabaseHandler<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public void onComplete(boolean success, Void result) {
|
public void onComplete(boolean success, Void result) {
|
||||||
@@ -183,14 +162,12 @@ public class TrackingController implements PositionProvider.PositionListener, Ne
|
|||||||
} else {
|
} else {
|
||||||
retry();
|
retry();
|
||||||
}
|
}
|
||||||
unlock();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void send(final Position position) {
|
private void send(final Position position) {
|
||||||
log("send", position);
|
log("send", position);
|
||||||
lock();
|
|
||||||
String request = ProtocolFormatter.formatRequest(url, position);
|
String request = ProtocolFormatter.formatRequest(url, position);
|
||||||
RequestManager.sendRequestAsync(request, new RequestManager.RequestHandler() {
|
RequestManager.sendRequestAsync(request, new RequestManager.RequestHandler() {
|
||||||
@Override
|
@Override
|
||||||
@@ -201,7 +178,6 @@ public class TrackingController implements PositionProvider.PositionListener, Ne
|
|||||||
StatusActivity.addMessage(context.getString(R.string.status_send_fail));
|
StatusActivity.addMessage(context.getString(R.string.status_send_fail));
|
||||||
retry();
|
retry();
|
||||||
}
|
}
|
||||||
unlock();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org)
|
* Copyright 2012 - 2019 Anton Tananaev (anton@traccar.org)
|
||||||
*
|
*
|
||||||
* 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.
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.traccar.client;
|
package org.traccar.client;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
@@ -26,6 +27,8 @@ import android.os.Build;
|
|||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class TrackingService extends Service {
|
public class TrackingService extends Service {
|
||||||
@@ -33,13 +36,14 @@ public class TrackingService extends Service {
|
|||||||
private static final String TAG = TrackingService.class.getSimpleName();
|
private static final String TAG = TrackingService.class.getSimpleName();
|
||||||
private static final int NOTIFICATION_ID = 1;
|
private static final int NOTIFICATION_ID = 1;
|
||||||
|
|
||||||
|
private PowerManager.WakeLock wakeLock;
|
||||||
private TrackingController trackingController;
|
private TrackingController trackingController;
|
||||||
|
|
||||||
private static Notification createNotification(Context context) {
|
private static Notification createNotification(Context context) {
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, MainApplication.PRIMARY_CHANNEL)
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, MainApplication.PRIMARY_CHANNEL)
|
||||||
.setSmallIcon(R.drawable.ic_stat_notify)
|
.setSmallIcon(R.drawable.ic_stat_notify)
|
||||||
.setPriority(NotificationCompat.PRIORITY_LOW)
|
.setPriority(NotificationCompat.PRIORITY_LOW)
|
||||||
.setCategory(Notification.CATEGORY_SERVICE);
|
.setCategory(NotificationCompat.CATEGORY_SERVICE);
|
||||||
Intent intent;
|
Intent intent;
|
||||||
if (!BuildConfig.HIDDEN_APP) {
|
if (!BuildConfig.HIDDEN_APP) {
|
||||||
intent = new Intent(context, MainActivity.class);
|
intent = new Intent(context, MainActivity.class);
|
||||||
@@ -73,6 +77,7 @@ public class TrackingService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("WakelockTimeout")
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
Log.i(TAG, "service create");
|
Log.i(TAG, "service create");
|
||||||
@@ -81,6 +86,11 @@ public class TrackingService extends Service {
|
|||||||
startForeground(NOTIFICATION_ID, createNotification(this));
|
startForeground(NOTIFICATION_ID, createNotification(this));
|
||||||
|
|
||||||
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
|
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
|
||||||
|
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||||
|
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
|
||||||
|
wakeLock.acquire();
|
||||||
|
|
||||||
trackingController = new TrackingController(this);
|
trackingController = new TrackingController(this);
|
||||||
trackingController.start();
|
trackingController.start();
|
||||||
}
|
}
|
||||||
@@ -111,6 +121,9 @@ public class TrackingService extends Service {
|
|||||||
|
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
|
|
||||||
|
if (wakeLock != null && wakeLock.isHeld()) {
|
||||||
|
wakeLock.release();
|
||||||
|
}
|
||||||
if (trackingController != null) {
|
if (trackingController != null) {
|
||||||
trackingController.stop();
|
trackingController.stop();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:layout_toRightOf="@+id/logo"
|
|
||||||
android:layout_toEndOf="@+id/logo"
|
|
||||||
android:padding="@dimen/spacing_normal"
|
|
||||||
android:orientation="vertical" >
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/title"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="@dimen/spacing_normal"
|
|
||||||
android:text="@string/app_name"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="@dimen/spacing_normal"
|
|
||||||
android:text="@string/about_description" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="@dimen/spacing_normal"
|
|
||||||
android:text="@string/about_license" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/about_web"
|
|
||||||
android:autoLink="web" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
@@ -8,9 +8,4 @@
|
|||||||
android:title="@string/menu_status"
|
android:title="@string/menu_status"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/about"
|
|
||||||
android:title="@string/menu_about"
|
|
||||||
app:showAsAction="never" />
|
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
|
|||||||
@@ -28,12 +28,8 @@
|
|||||||
<string name="settings_foreground_title">Foreground service</string>
|
<string name="settings_foreground_title">Foreground service</string>
|
||||||
<string name="settings_foreground_summary">Increase service priority</string>
|
<string name="settings_foreground_summary">Increase service priority</string>
|
||||||
<string name="menu_status">Status</string>
|
<string name="menu_status">Status</string>
|
||||||
<string name="menu_about">About</string>
|
|
||||||
<string name="menu_shortcuts">Add shortcuts</string>
|
<string name="menu_shortcuts">Add shortcuts</string>
|
||||||
<string name="menu_clear">Clear</string>
|
<string name="menu_clear">Clear</string>
|
||||||
<string name="about_description">Real time GPS tracker for Android devices. Compatible with Traccar Server and other tracking systems.</string>
|
|
||||||
<string name="about_license">This application is free and open source, source code is licensed under Apache License Version 2.0 and available on GitHub.</string>
|
|
||||||
<string name="about_web">For more information visit\nwww.traccar.org/client</string>
|
|
||||||
<string name="status_service_create">Service started</string>
|
<string name="status_service_create">Service started</string>
|
||||||
<string name="status_service_destroy">Service stopped</string>
|
<string name="status_service_destroy">Service stopped</string>
|
||||||
<string name="status_send_success">Send successfully</string>
|
<string name="status_send_success">Send successfully</string>
|
||||||
|
|||||||
+2
-2
@@ -5,8 +5,8 @@ buildscript {
|
|||||||
maven { url 'https://maven.fabric.io/public' }
|
maven { url 'https://maven.fabric.io/public' }
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.2.1'
|
classpath 'com.android.tools.build:gradle:3.5.2'
|
||||||
classpath 'com.google.gms:google-services:4.2.0'
|
classpath 'com.google.gms:google-services:4.3.2'
|
||||||
classpath 'io.fabric.tools:gradle:1.26.1'
|
classpath 'io.fabric.tools:gradle:1.26.1'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-all.zip
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user