io.appium.settings 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -134,6 +134,12 @@ $ adb shell am startservice --user 0 -n io.appium.settings/.LocationService --es
134
134
  Running the command again stops sending the previously specified location and starts sending updates for the
135
135
  new mock location.
136
136
 
137
+ Additionally the service allows to provide the following optional parameters to the mocked
138
+ location:
139
+
140
+ - `speed`: the speed, in meters/second over ground. A float value greater than zero is acceptable.
141
+ - `bearing`: the bearing, in degrees. Bearing is the horizontal direction of travel of this device, and is not related to the device orientation. The input will be wrapped into the range (0.0, 360.0]
142
+
137
143
  Stop sending new mocklocations and clean up everything (remove the mock location providers) by executing:
138
144
  ```shell
139
145
  $ adb shell am stopservice io.appium.settings/.LocationService
Binary file
package/app/build.gradle CHANGED
@@ -7,8 +7,8 @@ android {
7
7
  defaultConfig {
8
8
  minSdkVersion 18
9
9
  targetSdkVersion 28
10
- versionCode 29
11
- versionName "3.3.0"
10
+ versionCode 30
11
+ versionName "3.4.0"
12
12
  applicationId "io.appium.settings"
13
13
  }
14
14
 
@@ -20,7 +20,6 @@ import android.app.Service;
20
20
  import android.content.Context;
21
21
  import android.content.Intent;
22
22
  import android.content.pm.PackageManager;
23
- import android.location.Criteria;
24
23
  import android.location.Location;
25
24
  import android.location.LocationManager;
26
25
  import android.location.LocationProvider;
@@ -40,22 +39,16 @@ import java.util.TimerTask;
40
39
  import io.appium.settings.helpers.NotificationHelpers;
41
40
  import io.appium.settings.helpers.PlayServicesHelpers;
42
41
  import io.appium.settings.location.FusedLocationProvider;
43
- import io.appium.settings.location.LocationFactory;
42
+ import io.appium.settings.location.LocationBuilder;
44
43
  import io.appium.settings.location.LocationManagerProvider;
45
44
  import io.appium.settings.location.MockLocationProvider;
46
45
 
47
46
  public class LocationService extends Service {
48
47
  private static final String TAG = "MOCKED LOCATION SERVICE";
49
48
 
50
- private static final String LONGITUDE_PARAMETER_KEY = "longitude";
51
- private static final String LATITUDE_PARAMETER_KEY = "latitude";
52
- private static final String ALTITUDE_PARAMETER_KEY = "altitude";
53
- private static final String SPEED_PARAMETER_KEY = "speed";
54
-
55
49
  private static final long UPDATE_INTERVAL_MS = 2000L;
56
50
 
57
51
  private final List<MockLocationProvider> mockLocationProviders = new LinkedList<>();
58
- private final LocationFactory locationFactory = new LocationFactory();
59
52
  private final Timer locationUpdatesTimer = new Timer();
60
53
  private TimerTask locationUpdateTask;
61
54
 
@@ -106,9 +99,7 @@ public class LocationService extends Service {
106
99
  }
107
100
  Log.i(TAG, "INTENT " + intent.getExtras());
108
101
 
109
- // update the locationFactory also if the service is already running to mock.
110
- updateMockLocationFactory(intent);
111
- scheduleLocationUpdate();
102
+ scheduleLocationUpdate(intent);
112
103
  }
113
104
 
114
105
  private void enableLocationProviders() {
@@ -145,7 +136,7 @@ public class LocationService extends Service {
145
136
  Log.d(TAG, String.format("Created mock providers: %s", mockLocationProviders.toString()));
146
137
  }
147
138
 
148
- private void scheduleLocationUpdate() {
139
+ private void scheduleLocationUpdate(final Intent intent) {
149
140
  Log.i(TAG, "Scheduling mock location updates");
150
141
 
151
142
  // If we run 'startservice' again we should schedule an update right away to avoid a delay
@@ -157,7 +148,7 @@ public class LocationService extends Service {
157
148
  @Override
158
149
  public void run() {
159
150
  for (MockLocationProvider mockLocationProvider : mockLocationProviders) {
160
- Location location = locationFactory.createLocation(mockLocationProvider.getProviderName(), Criteria.ACCURACY_FINE);
151
+ Location location = LocationBuilder.buildFromIntent(intent, mockLocationProvider.getProviderName());
161
152
  Log.d(TAG, String.format("Setting location of '%s' to '%s'", mockLocationProvider.getProviderName(), location));
162
153
  try {
163
154
  mockLocationProvider.setLocation(location);
@@ -172,47 +163,6 @@ public class LocationService extends Service {
172
163
  locationUpdatesTimer.schedule(locationUpdateTask, 0, UPDATE_INTERVAL_MS);
173
164
  }
174
165
 
175
- private void updateMockLocationFactory(Intent intent) {
176
- double longitude;
177
- try {
178
- longitude = Double.valueOf(intent.getStringExtra("longitude"));
179
- } catch (NumberFormatException e) {
180
- throw new IllegalArgumentException(
181
- String.format("longitude should be a valid number. '%s' is given instead",
182
- intent.getStringExtra(LONGITUDE_PARAMETER_KEY)));
183
- }
184
- double latitude;
185
- try {
186
- latitude = Double.valueOf(intent.getStringExtra("latitude"));
187
- } catch (NumberFormatException e) {
188
- throw new IllegalArgumentException(
189
- String.format("latitude should be a valid number. '%s' is given instead",
190
- intent.getStringExtra(LATITUDE_PARAMETER_KEY)));
191
- }
192
- double altitude = 0.0;
193
- try {
194
- if (intent.hasExtra(ALTITUDE_PARAMETER_KEY)) {
195
- altitude = Double.valueOf(intent.getStringExtra(ALTITUDE_PARAMETER_KEY));
196
- }
197
- } catch (NumberFormatException e) {
198
- Log.e(TAG, String.format("altitude should be a valid number. '%s' is given instead",
199
- intent.getStringExtra(ALTITUDE_PARAMETER_KEY)));
200
- }
201
- try {
202
- if (intent.hasExtra(SPEED_PARAMETER_KEY)) {
203
- float speed = Float.valueOf(intent.getStringExtra(SPEED_PARAMETER_KEY));
204
-
205
- locationFactory.setLocation(latitude, longitude, altitude, speed);
206
- return;
207
- }
208
- } catch (NumberFormatException e) {
209
- Log.e(TAG, String.format("speed should be a valid number larger then 0.0. '%s' is given instead",
210
- intent.getStringExtra(SPEED_PARAMETER_KEY)));
211
- }
212
-
213
- locationFactory.setLocation(latitude, longitude, altitude);
214
- }
215
-
216
166
  private List<MockLocationProvider> createMockProviders(LocationManager locationManager) {
217
167
  List<String> providers = locationManager.getAllProviders();
218
168
  List<MockLocationProvider> mockProviders = new LinkedList<>();
@@ -16,9 +16,11 @@
16
16
 
17
17
  package io.appium.settings.handlers;
18
18
 
19
+ import android.annotation.SuppressLint;
19
20
  import android.bluetooth.BluetoothAdapter;
20
21
  import android.content.Context;
21
22
 
23
+ @SuppressLint("MissingPermission")
22
24
  public class BluetoothConnectionSettingHandler extends AbstractSettingHandler {
23
25
 
24
26
  private BluetoothAdapter bluetoothAdapter;
@@ -0,0 +1,83 @@
1
+ /*
2
+ Copyright 2012-present Appium Committers
3
+ <p>
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+ <p>
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+ <p>
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ package io.appium.settings.location;
18
+
19
+ import android.content.Intent;
20
+ import android.location.Criteria;
21
+ import android.location.Location;
22
+ import android.os.Build;
23
+ import android.os.SystemClock;
24
+ import android.support.annotation.Nullable;
25
+ import android.util.Log;
26
+
27
+
28
+ public class LocationBuilder {
29
+
30
+ private static final String TAG = "MOCKED LOCATION BUILDER";
31
+ private static final String LONGITUDE_PARAMETER_KEY = "longitude";
32
+ private static final String LATITUDE_PARAMETER_KEY = "latitude";
33
+ private static final String ALTITUDE_PARAMETER_KEY = "altitude";
34
+ private static final String SPEED_PARAMETER_KEY = "speed";
35
+ private static final String BEARING_PARAMETER_KEY = "bearing";
36
+
37
+ @Nullable
38
+ private static Double extractParam(Intent intent, String paramKey) {
39
+ Double value = null;
40
+
41
+ try {
42
+ if (intent.hasExtra(paramKey)) {
43
+ value = Double.parseDouble(intent.getStringExtra(paramKey));
44
+ Log.i(TAG, String.format("Received parameter: %s, value: %s", paramKey, value));
45
+ }
46
+ } catch (NumberFormatException e) {
47
+ Log.e(TAG, String.format("%s should be a valid number. '%s' is given instead",
48
+ paramKey, intent.getStringExtra(paramKey)));
49
+ }
50
+ return value;
51
+ }
52
+
53
+ public static Location buildFromIntent(Intent intent, String providerName) {
54
+ Double longitude = extractParam(intent, LONGITUDE_PARAMETER_KEY);
55
+ Double latitude = extractParam(intent, LATITUDE_PARAMETER_KEY);
56
+ Double altitude = extractParam(intent, ALTITUDE_PARAMETER_KEY);
57
+ Double speed = extractParam(intent, SPEED_PARAMETER_KEY);
58
+ Double bearing = extractParam(intent, BEARING_PARAMETER_KEY);
59
+ Location location = new Location(providerName);
60
+ location.setAccuracy(Criteria.ACCURACY_FINE);
61
+ if (longitude != null) {
62
+ location.setLongitude(longitude);
63
+ }
64
+ if (latitude != null) {
65
+ location.setLatitude(latitude);
66
+ }
67
+ if (altitude != null) {
68
+ location.setAltitude(altitude);
69
+ }
70
+ if (speed != null) {
71
+ location.setSpeed(speed.floatValue());
72
+ }
73
+ if (bearing != null) {
74
+ location.setBearing(bearing.floatValue());
75
+ }
76
+
77
+ location.setTime(System.currentTimeMillis());
78
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
79
+ location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
80
+ }
81
+ return location;
82
+ }
83
+ }
@@ -16,6 +16,7 @@
16
16
 
17
17
  package io.appium.settings.receivers;
18
18
 
19
+ import android.annotation.SuppressLint;
19
20
  import android.app.Activity;
20
21
  import android.bluetooth.BluetoothAdapter;
21
22
  import android.bluetooth.BluetoothDevice;
@@ -27,6 +28,7 @@ import android.util.Log;
27
28
  import java.lang.reflect.InvocationTargetException;
28
29
  import java.util.Set;
29
30
 
31
+ @SuppressLint("MissingPermission")
30
32
  public class UnpairBluetoothDevicesReceiver extends BroadcastReceiver implements HasAction {
31
33
  private static final String TAG = UnpairBluetoothDevicesReceiver.class.getSimpleName();
32
34
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "io.appium.settings",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "App for dealing with Android settings",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,63 +0,0 @@
1
- /*
2
- Copyright 2012-present Appium Committers
3
- <p>
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
- <p>
8
- http://www.apache.org/licenses/LICENSE-2.0
9
- <p>
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- package io.appium.settings.location;
18
-
19
- import android.location.Location;
20
- import android.os.Build;
21
- import android.os.SystemClock;
22
-
23
- public class LocationFactory {
24
-
25
- private double latitude;
26
- private double longitude;
27
- private double altitude;
28
- private float speed;
29
- private boolean hasSpeed = false;
30
-
31
-
32
- public synchronized Location createLocation(String providerName, float accuracy) {
33
- Location l = new Location(providerName);
34
- l.setAccuracy(accuracy);
35
-
36
- l.setLatitude(latitude);
37
- l.setLongitude(longitude);
38
- l.setAltitude(altitude);
39
- if (hasSpeed) {
40
- l.setSpeed(speed);
41
- }
42
- l.setBearing(0);
43
-
44
- l.setTime(System.currentTimeMillis());
45
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
46
- l.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
47
- }
48
- return l;
49
- }
50
-
51
- public synchronized void setLocation(double latitude, double longitude, double altitude, float speed) {
52
- this.setLocation(latitude, longitude, altitude);
53
- this.speed = speed;
54
- this.hasSpeed = true;
55
- }
56
-
57
- public synchronized void setLocation(double latitude, double longitude, double altitude) {
58
- this.latitude = latitude;
59
- this.longitude = longitude;
60
- this.altitude = altitude;
61
- this.hasSpeed = false;
62
- }
63
- }