io.appium.settings 3.4.0 → 3.5.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
@@ -286,6 +286,23 @@ The example of the resulting data:
286
286
  ```
287
287
 
288
288
 
289
+ ## Media Scanning
290
+
291
+ Since version 3.5 Appium Settings supports broadcast messages handling
292
+ that performs media scanning in response to `io.appium.settings.scan_media`
293
+ intent. This was done due to `android.intent.action.MEDIA_SCANNER_SCAN_FILE` deprecation
294
+ since Android API version 30. To scan the given file or folder for media data simply run:
295
+
296
+ ```bash
297
+ $ adb shell am broadcast -a io.appium.settings.scan_media --es path /sdcard/media
298
+ ```
299
+
300
+ This command will _recursively_ scan all files inside of `/sdcard/media` folder
301
+ and add them to the media library if their MIME types are supported. If the
302
+ file/folder in _path_ does not exist/is not readable or is not provided then an
303
+ error will be returned and the corresponding log message would be written into logs.
304
+
305
+
289
306
  ## Notes:
290
307
 
291
308
  * You have to specify the receiver class if the app has never been executed before:
Binary file
package/app/build.gradle CHANGED
@@ -1,14 +1,13 @@
1
1
  apply plugin: 'com.android.application'
2
2
 
3
3
  android {
4
- compileSdkVersion 28
5
- buildToolsVersion '28.0.3'
4
+ compileSdkVersion 29
6
5
 
7
6
  defaultConfig {
8
7
  minSdkVersion 18
9
- targetSdkVersion 28
10
- versionCode 30
11
- versionName "3.4.0"
8
+ targetSdkVersion 29
9
+ versionCode 31
10
+ versionName "3.5.0"
12
11
  applicationId "io.appium.settings"
13
12
  }
14
13
 
@@ -4,6 +4,7 @@
4
4
  package="io.appium.settings">
5
5
 
6
6
  <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
7
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
7
8
  <uses-permission android:name="android.permission.WAKE_LOCK"/>
8
9
  <uses-permission android:name="android.permission.INTERNET" />
9
10
  <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
@@ -132,5 +133,8 @@
132
133
  <receiver android:name=".receivers.SmsReader"
133
134
  android:exported="true"
134
135
  tools:ignore="ExportedReceiver" />
136
+ <receiver android:name=".receivers.MediaScannerReceiver"
137
+ android:exported="true"
138
+ tools:ignore="ExportedReceiver" />
135
139
  </application>
136
140
  </manifest>
@@ -24,7 +24,7 @@ import android.os.Bundle;
24
24
  import android.os.Handler;
25
25
  import android.util.Log;
26
26
 
27
- import java.util.ArrayList;
27
+ import java.util.Arrays;
28
28
  import java.util.List;
29
29
 
30
30
  import io.appium.settings.receivers.AnimationSettingReceiver;
@@ -34,6 +34,7 @@ import io.appium.settings.receivers.DataConnectionSettingReceiver;
34
34
  import io.appium.settings.receivers.HasAction;
35
35
  import io.appium.settings.receivers.LocaleSettingReceiver;
36
36
  import io.appium.settings.receivers.LocationInfoReceiver;
37
+ import io.appium.settings.receivers.MediaScannerReceiver;
37
38
  import io.appium.settings.receivers.NotificationsReceiver;
38
39
  import io.appium.settings.receivers.SmsReader;
39
40
  import io.appium.settings.receivers.UnpairBluetoothDevicesReceiver;
@@ -50,18 +51,19 @@ public class Settings extends Activity {
50
51
 
51
52
  LocationTracker.getInstance().start(this);
52
53
 
53
- final List<Class<? extends BroadcastReceiver>> receiverClasses = new ArrayList<>();
54
- receiverClasses.add(WiFiConnectionSettingReceiver.class);
55
- receiverClasses.add(AnimationSettingReceiver.class);
56
- receiverClasses.add(DataConnectionSettingReceiver.class);
57
- receiverClasses.add(LocaleSettingReceiver.class);
58
- receiverClasses.add(LocationInfoReceiver.class);
59
- receiverClasses.add(ClipboardReceiver.class);
60
- receiverClasses.add(BluetoothConnectionSettingReceiver.class);
61
- receiverClasses.add(UnpairBluetoothDevicesReceiver.class);
62
- receiverClasses.add(NotificationsReceiver.class);
63
- receiverClasses.add(SmsReader.class);
64
- registerSettingsReceivers(receiverClasses);
54
+ registerSettingsReceivers(Arrays.asList(
55
+ WiFiConnectionSettingReceiver.class,
56
+ AnimationSettingReceiver.class,
57
+ DataConnectionSettingReceiver.class,
58
+ LocaleSettingReceiver.class,
59
+ LocationInfoReceiver.class,
60
+ ClipboardReceiver.class,
61
+ BluetoothConnectionSettingReceiver.class,
62
+ UnpairBluetoothDevicesReceiver.class,
63
+ NotificationsReceiver.class,
64
+ SmsReader.class,
65
+ MediaScannerReceiver.class
66
+ ));
65
67
 
66
68
  // https://developer.android.com/about/versions/oreo/background-location-limits
67
69
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@@ -0,0 +1,91 @@
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.receivers;
18
+
19
+ import android.app.Activity;
20
+ import android.content.BroadcastReceiver;
21
+ import android.content.Context;
22
+ import android.content.Intent;
23
+ import android.media.MediaScannerConnection;
24
+ import android.util.Log;
25
+
26
+ import java.io.File;
27
+ import java.util.ArrayList;
28
+ import java.util.Collections;
29
+ import java.util.List;
30
+
31
+ public class MediaScannerReceiver extends BroadcastReceiver
32
+ implements HasAction {
33
+ private static final String TAG = MediaScannerReceiver.class.getSimpleName();
34
+ private static final String ACTION = "io.appium.settings.scan_media";
35
+ private static final String PATH = "path";
36
+
37
+ private List<String> fetchFiles(File root) {
38
+ if (root.isFile()) {
39
+ return root.canRead()
40
+ ? Collections.singletonList(root.toString())
41
+ : Collections.emptyList();
42
+ }
43
+ File[] items = root.listFiles();
44
+ if (items == null) {
45
+ return Collections.emptyList();
46
+ }
47
+ List<String> filePaths = new ArrayList<>();
48
+ for (File item : items) {
49
+ filePaths.addAll(fetchFiles(item));
50
+ }
51
+ return filePaths;
52
+ }
53
+
54
+ /**
55
+ * Responds to broadcast requests like
56
+ * am broadcast -a io.appium.settings.scan_media -e path /sdcard/yolo
57
+ * by scanning all files/folders under the given path
58
+ */
59
+ @Override
60
+ public void onReceive(Context context, Intent intent) {
61
+ Log.d(TAG, "Scanning the requested media");
62
+ if (!intent.hasExtra(PATH)) {
63
+ Log.e(TAG, "No path has been provided");
64
+ setResultCode(Activity.RESULT_CANCELED);
65
+ setResultData("");
66
+ return;
67
+ }
68
+ File item = new File(intent.getStringExtra(PATH));
69
+ if (!item.exists()) {
70
+ Log.e(TAG, String.format("The item at '%s' does not exist", item.toString()));
71
+ setResultCode(Activity.RESULT_CANCELED);
72
+ setResultData("");
73
+ return;
74
+ }
75
+ List<String> filePaths = fetchFiles(item);
76
+ if (filePaths.isEmpty()) {
77
+ Log.i(TAG, String.format("Found no files to scan at '%s'", item.toString()));
78
+ } else {
79
+ MediaScannerConnection.scanFile(context, filePaths.toArray(new String[0]), null, null);
80
+ Log.i(TAG, String.format("Successfully scanned %s file(s) at '%s'",
81
+ filePaths.size(), item.toString()));
82
+ }
83
+ setResultCode(Activity.RESULT_OK);
84
+ setResultData("");
85
+ }
86
+
87
+ @Override
88
+ public String getAction() {
89
+ return ACTION;
90
+ }
91
+ }
package/build.gradle CHANGED
@@ -5,7 +5,7 @@ buildscript {
5
5
  jcenter()
6
6
  }
7
7
  dependencies {
8
- classpath 'com.android.tools.build:gradle:4.0.2'
8
+ classpath 'com.android.tools.build:gradle:7.0.3'
9
9
  }
10
10
  }
11
11
 
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
3
3
  distributionPath=wrapper/dists
4
4
  zipStoreBase=GRADLE_USER_HOME
5
5
  zipStorePath=wrapper/dists
6
- distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip
6
+ distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "io.appium.settings",
3
- "version": "3.4.0",
3
+ "version": "3.5.0",
4
4
  "description": "App for dealing with Android settings",
5
5
  "main": "index.js",
6
6
  "scripts": {