io.appium.settings 4.2.0 → 4.2.1

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.
Files changed (61) hide show
  1. package/apks/settings_apk-debug.apk +0 -0
  2. package/package.json +2 -8
  3. package/app/build.gradle +0 -38
  4. package/app/src/main/AndroidManifest.xml +0 -149
  5. package/app/src/main/java/io/appium/settings/AppiumIME.java +0 -153
  6. package/app/src/main/java/io/appium/settings/ForegroundService.java +0 -70
  7. package/app/src/main/java/io/appium/settings/LocationService.java +0 -215
  8. package/app/src/main/java/io/appium/settings/LocationTracker.java +0 -313
  9. package/app/src/main/java/io/appium/settings/NLService.java +0 -134
  10. package/app/src/main/java/io/appium/settings/Settings.java +0 -260
  11. package/app/src/main/java/io/appium/settings/UnicodeIME.java +0 -187
  12. package/app/src/main/java/io/appium/settings/Unlock.java +0 -75
  13. package/app/src/main/java/io/appium/settings/handlers/AbstractSettingHandler.java +0 -64
  14. package/app/src/main/java/io/appium/settings/handlers/AnimationSettingHandler.java +0 -66
  15. package/app/src/main/java/io/appium/settings/handlers/BluetoothConnectionSettingHandler.java +0 -42
  16. package/app/src/main/java/io/appium/settings/handlers/DataConnectionSettingHandler.java +0 -134
  17. package/app/src/main/java/io/appium/settings/handlers/LocaleSettingHandler.java +0 -86
  18. package/app/src/main/java/io/appium/settings/handlers/WiFiConnectionSettingHandler.java +0 -40
  19. package/app/src/main/java/io/appium/settings/helpers/NotificationHelpers.java +0 -67
  20. package/app/src/main/java/io/appium/settings/helpers/PlayServicesHelpers.java +0 -30
  21. package/app/src/main/java/io/appium/settings/helpers/Utils.java +0 -29
  22. package/app/src/main/java/io/appium/settings/location/FusedLocationProvider.java +0 -99
  23. package/app/src/main/java/io/appium/settings/location/LocationBuilder.java +0 -80
  24. package/app/src/main/java/io/appium/settings/location/LocationManagerProvider.java +0 -97
  25. package/app/src/main/java/io/appium/settings/location/MockLocationProvider.java +0 -31
  26. package/app/src/main/java/io/appium/settings/notifications/StoredNotification.java +0 -103
  27. package/app/src/main/java/io/appium/settings/notifications/StoredNotifications.java +0 -50
  28. package/app/src/main/java/io/appium/settings/receivers/AbstractSettingReceiver.java +0 -62
  29. package/app/src/main/java/io/appium/settings/receivers/AnimationSettingReceiver.java +0 -40
  30. package/app/src/main/java/io/appium/settings/receivers/BluetoothConnectionSettingReceiver.java +0 -49
  31. package/app/src/main/java/io/appium/settings/receivers/ClipboardReceiver.java +0 -91
  32. package/app/src/main/java/io/appium/settings/receivers/DataConnectionSettingReceiver.java +0 -40
  33. package/app/src/main/java/io/appium/settings/receivers/HasAction.java +0 -21
  34. package/app/src/main/java/io/appium/settings/receivers/LocaleSettingReceiver.java +0 -127
  35. package/app/src/main/java/io/appium/settings/receivers/LocationInfoReceiver.java +0 -67
  36. package/app/src/main/java/io/appium/settings/receivers/MediaScannerReceiver.java +0 -91
  37. package/app/src/main/java/io/appium/settings/receivers/NotificationsReceiver.java +0 -100
  38. package/app/src/main/java/io/appium/settings/receivers/SmsReader.java +0 -113
  39. package/app/src/main/java/io/appium/settings/receivers/UnpairBluetoothDevicesReceiver.java +0 -84
  40. package/app/src/main/java/io/appium/settings/receivers/WiFiConnectionSettingReceiver.java +0 -39
  41. package/app/src/main/java/io/appium/settings/recorder/RecorderConstant.java +0 -94
  42. package/app/src/main/java/io/appium/settings/recorder/RecorderService.java +0 -202
  43. package/app/src/main/java/io/appium/settings/recorder/RecorderThread.java +0 -459
  44. package/app/src/main/java/io/appium/settings/recorder/RecorderUtil.java +0 -298
  45. package/app/src/main/res/drawable-hdpi/ic_launcher.png +0 -0
  46. package/app/src/main/res/drawable-ldpi/ic_launcher.png +0 -0
  47. package/app/src/main/res/drawable-mdpi/ic_launcher.png +0 -0
  48. package/app/src/main/res/drawable-xhdpi/ic_launcher.png +0 -0
  49. package/app/src/main/res/drawable-xxhdpi/ic_launcher.png +0 -0
  50. package/app/src/main/res/drawable-xxxhdpi/ic_launcher.png +0 -0
  51. package/app/src/main/res/layout/main.xml +0 -29
  52. package/app/src/main/res/values/dimens.xml +0 -7
  53. package/app/src/main/res/values/strings.xml +0 -9
  54. package/app/src/main/res/xml/method.xml +0 -3
  55. package/build.gradle +0 -17
  56. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  57. package/gradle/wrapper/gradle-wrapper.properties +0 -6
  58. package/gradle.properties +0 -15
  59. package/gradlew +0 -160
  60. package/gradlew.bat +0 -90
  61. package/settings.gradle +0 -1
@@ -1,260 +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;
18
-
19
- import android.app.Activity;
20
- import android.content.BroadcastReceiver;
21
- import android.content.Context;
22
- import android.content.Intent;
23
- import android.content.IntentFilter;
24
- import android.media.projection.MediaProjectionManager;
25
- import android.os.Build;
26
- import android.os.Bundle;
27
- import android.os.Handler;
28
- import android.util.Log;
29
-
30
- import java.io.File;
31
- import java.nio.file.Paths;
32
- import java.util.Arrays;
33
- import java.util.List;
34
-
35
- import io.appium.settings.receivers.AnimationSettingReceiver;
36
- import io.appium.settings.receivers.BluetoothConnectionSettingReceiver;
37
- import io.appium.settings.receivers.ClipboardReceiver;
38
- import io.appium.settings.receivers.DataConnectionSettingReceiver;
39
- import io.appium.settings.receivers.HasAction;
40
- import io.appium.settings.receivers.LocaleSettingReceiver;
41
- import io.appium.settings.receivers.LocationInfoReceiver;
42
- import io.appium.settings.receivers.MediaScannerReceiver;
43
- import io.appium.settings.receivers.NotificationsReceiver;
44
- import io.appium.settings.receivers.SmsReader;
45
- import io.appium.settings.receivers.UnpairBluetoothDevicesReceiver;
46
- import io.appium.settings.receivers.WiFiConnectionSettingReceiver;
47
- import io.appium.settings.recorder.RecorderService;
48
- import io.appium.settings.recorder.RecorderUtil;
49
-
50
- import static io.appium.settings.recorder.RecorderConstant.ACTION_RECORDING_BASE;
51
- import static io.appium.settings.recorder.RecorderConstant.ACTION_RECORDING_FILENAME;
52
- import static io.appium.settings.recorder.RecorderConstant.ACTION_RECORDING_MAX_DURATION;
53
- import static io.appium.settings.recorder.RecorderConstant.ACTION_RECORDING_PRIORITY;
54
- import static io.appium.settings.recorder.RecorderConstant.ACTION_RECORDING_RESOLUTION;
55
- import static io.appium.settings.recorder.RecorderConstant.ACTION_RECORDING_RESULT_CODE;
56
- import static io.appium.settings.recorder.RecorderConstant.ACTION_RECORDING_ROTATION;
57
- import static io.appium.settings.recorder.RecorderConstant.ACTION_RECORDING_START;
58
- import static io.appium.settings.recorder.RecorderConstant.ACTION_RECORDING_STOP;
59
- import static io.appium.settings.recorder.RecorderConstant.NO_PATH_SET;
60
- import static io.appium.settings.recorder.RecorderConstant.NO_RESOLUTION_MODE_SET;
61
- import static io.appium.settings.recorder.RecorderConstant.RECORDING_MAX_DURATION_DEFAULT_MS;
62
- import static io.appium.settings.recorder.RecorderConstant.RECORDING_PRIORITY_DEFAULT;
63
- import static io.appium.settings.recorder.RecorderConstant.RECORDING_ROTATION_DEFAULT_DEGREE;
64
- import static io.appium.settings.recorder.RecorderConstant.REQUEST_CODE_SCREEN_CAPTURE;
65
-
66
- public class Settings extends Activity {
67
- private static final String TAG = "APPIUM SETTINGS";
68
-
69
- private String recordingOutputPath = NO_PATH_SET;
70
- private int recordingRotation = RECORDING_ROTATION_DEFAULT_DEGREE;
71
- private int recordingPriority = RECORDING_PRIORITY_DEFAULT;
72
- private int recordingMaxDuration = RECORDING_MAX_DURATION_DEFAULT_MS;
73
- private String recordingResolutionMode = NO_RESOLUTION_MODE_SET;
74
-
75
- @Override
76
- public void onCreate(Bundle savedInstanceState) {
77
- super.onCreate(savedInstanceState);
78
- setContentView(R.layout.main);
79
- Log.d(TAG, "Entering the app");
80
-
81
- registerSettingsReceivers(Arrays.asList(
82
- WiFiConnectionSettingReceiver.class,
83
- AnimationSettingReceiver.class,
84
- DataConnectionSettingReceiver.class,
85
- LocaleSettingReceiver.class,
86
- LocationInfoReceiver.class,
87
- ClipboardReceiver.class,
88
- BluetoothConnectionSettingReceiver.class,
89
- UnpairBluetoothDevicesReceiver.class,
90
- NotificationsReceiver.class,
91
- SmsReader.class,
92
- MediaScannerReceiver.class
93
- ));
94
-
95
- // https://developer.android.com/about/versions/oreo/background-location-limits
96
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
97
- startForegroundService(ForegroundService.getForegroundServiceIntent(Settings.this));
98
- } else {
99
- LocationTracker.getInstance().start(this);
100
- }
101
-
102
- handleRecording(getIntent());
103
- }
104
-
105
- private void handleRecording(Intent intent) {
106
- if (intent == null) {
107
- Log.e(TAG, "handleRecording: Unable to retrieve intent instance");
108
- finishActivity();
109
- return;
110
- }
111
-
112
- String recordingAction = intent.getAction();
113
- if (recordingAction == null) {
114
- Log.e(TAG, "handleRecording: Unable to retrieve intent.action instance");
115
- finishActivity();
116
- return;
117
- }
118
-
119
- if (!recordingAction.startsWith(ACTION_RECORDING_BASE)) {
120
- Log.i(TAG, "handleRecording: Received different intent with action: "
121
- + recordingAction);
122
- finishActivity();
123
- return;
124
- }
125
-
126
- if (RecorderUtil.isLowerThanQ()) {
127
- Log.e(TAG, "handleRecording: Current Android OS Version is lower than Q");
128
- finishActivity();
129
- return;
130
- }
131
-
132
- if (!RecorderUtil.areRecordingPermissionsGranted(getApplicationContext())) {
133
- Log.e(TAG, "handleRecording: Required permissions are not granted");
134
- finishActivity();
135
- return;
136
- }
137
-
138
- if (recordingAction.equals(ACTION_RECORDING_START)) {
139
- String recordingFilename = intent.getStringExtra(ACTION_RECORDING_FILENAME);
140
- if (!RecorderUtil.isValidFileName(recordingFilename)) {
141
- Log.e(TAG, "handleRecording: Invalid filename passed by user: "
142
- + recordingFilename);
143
- finishActivity();
144
- return;
145
- }
146
-
147
- /*
148
- External Storage File Directory for app
149
- (i.e /storage/emulated/0/Android/data/io.appium.settings/files) may not be created
150
- so we need to call getExternalFilesDir() method twice
151
- source:https://www.androidbugfix.com/2021/10/getexternalfilesdirnull-returns-null-in.html
152
- */
153
- File externalStorageFile = getExternalFilesDir(null);
154
- if (externalStorageFile == null) {
155
- externalStorageFile = getExternalFilesDir(null);
156
- }
157
- // if path is still null despite calling method twice, early exit
158
- if (externalStorageFile == null) {
159
- Log.e(TAG, "handleRecording: Unable to retrieve external storage file path");
160
- finishActivity();
161
- return;
162
- }
163
-
164
- recordingOutputPath = Paths
165
- .get(externalStorageFile.getAbsolutePath(), recordingFilename)
166
- .toAbsolutePath()
167
- .toString();
168
-
169
- recordingRotation = RecorderUtil.getDeviceRotationInDegree(getApplicationContext());
170
-
171
- recordingPriority = RecorderUtil.getRecordingPriority(intent);
172
-
173
- recordingMaxDuration = RecorderUtil.getRecordingMaxDuration(intent);
174
-
175
- recordingResolutionMode = RecorderUtil.getRecordingResolutionMode(intent);
176
-
177
- // start record
178
- final MediaProjectionManager manager
179
- = (MediaProjectionManager) getSystemService(
180
- Context.MEDIA_PROJECTION_SERVICE);
181
-
182
- if (manager == null) {
183
- Log.e(TAG, "handleRecording: " +
184
- "Unable to retrieve MediaProjectionManager instance");
185
- finishActivity();
186
- return;
187
- }
188
-
189
- final Intent permissionIntent = manager.createScreenCaptureIntent();
190
-
191
- startActivityForResult(permissionIntent, REQUEST_CODE_SCREEN_CAPTURE);
192
- } else if (recordingAction.equals(ACTION_RECORDING_STOP)) {
193
- // stop record
194
- final Intent recorderIntent = new Intent(this, RecorderService.class);
195
- recorderIntent.setAction(ACTION_RECORDING_STOP);
196
- startService(recorderIntent);
197
-
198
- finishActivity();
199
- } else {
200
- Log.e(TAG, "handleRecording: Unknown recording intent with action:"
201
- + recordingAction);
202
- finishActivity();
203
- }
204
- }
205
-
206
- private void finishActivity() {
207
- Log.d(TAG, "Closing the app");
208
- Handler handler = new Handler();
209
- handler.postDelayed(Settings.this::finish, 0);
210
- }
211
-
212
- @Override
213
- protected void onActivityResult(final int requestCode, final int resultCode, final Intent data)
214
- {
215
- super.onActivityResult(requestCode, resultCode, data);
216
- if (REQUEST_CODE_SCREEN_CAPTURE != requestCode) {
217
- Log.e(TAG, "handleRecording: onActivityResult: " +
218
- "Received unknown request with code: " + requestCode);
219
- finishActivity();
220
- return;
221
- }
222
-
223
- if (resultCode != Activity.RESULT_OK) {
224
- Log.e(TAG, "handleRecording: onActivityResult: " +
225
- "MediaProjection permission is not granted, " +
226
- "Did you apply appops adb command?");
227
- finishActivity();
228
- return;
229
- }
230
-
231
- final Intent intent = new Intent(this, RecorderService.class);
232
- intent.setAction(ACTION_RECORDING_START);
233
- intent.putExtra(ACTION_RECORDING_RESULT_CODE, resultCode);
234
- intent.putExtra(ACTION_RECORDING_FILENAME, recordingOutputPath);
235
- intent.putExtra(ACTION_RECORDING_ROTATION, recordingRotation);
236
- intent.putExtra(ACTION_RECORDING_PRIORITY, recordingPriority);
237
- intent.putExtra(ACTION_RECORDING_MAX_DURATION, recordingMaxDuration);
238
- intent.putExtra(ACTION_RECORDING_RESOLUTION, recordingResolutionMode);
239
- intent.putExtras(data);
240
-
241
- startService(intent);
242
-
243
- finishActivity();
244
- }
245
-
246
- private void registerSettingsReceivers(List<Class<? extends BroadcastReceiver>> receiverClasses)
247
- {
248
- for (Class<? extends BroadcastReceiver> receiverClass: receiverClasses) {
249
- try {
250
- final BroadcastReceiver receiver = receiverClass.newInstance();
251
- IntentFilter filter = new IntentFilter(((HasAction) receiver).getAction());
252
- getApplicationContext().registerReceiver(receiver, filter);
253
- } catch (IllegalAccessException e) {
254
- e.printStackTrace();
255
- } catch (InstantiationException e) {
256
- e.printStackTrace();
257
- }
258
- }
259
- }
260
- }
@@ -1,187 +0,0 @@
1
- /*
2
- * Copyright 2013 TOYAMA Sumio <jun.nama@gmail.com>
3
- *
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
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
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;
18
-
19
- import android.annotation.SuppressLint;
20
- import android.inputmethodservice.InputMethodService;
21
- import android.text.method.MetaKeyKeyListener;
22
- import android.util.Log;
23
- import android.view.KeyEvent;
24
- import android.view.inputmethod.EditorInfo;
25
-
26
- import java.nio.ByteBuffer;
27
- import java.nio.CharBuffer;
28
- import java.nio.charset.CharacterCodingException;
29
- import java.nio.charset.Charset;
30
- import java.nio.charset.CharsetDecoder;
31
-
32
- /**
33
- * <p>
34
- * UnicodeIME enables users to input any Unicode character by using only the
35
- * hardware keyboard. The selection of word candidates is not necessary. <br />
36
- * Using automated testing tools such as Uiautomator, it is impossible to input
37
- * non-ASCII characters directly. UnicodeIME helps you to input any
38
- * characters by using Uiautomator.
39
- * </p>
40
- * <p>
41
- * String that is input from the keyboard, must be encoded in Modified UTF-7
42
- * (see RFC 3501).
43
- * </p>
44
- *
45
- * @author TOYAMA Sumio
46
- */
47
- public class UnicodeIME extends InputMethodService {
48
- private static final String TAG = UnicodeIME.class.getSimpleName();
49
-
50
- @SuppressWarnings("InjectedReferences")
51
- private static final Charset UTF7_MODIFIED = Charset.forName("x-IMAP-mailbox-name");
52
- private static final Charset ASCII = Charset.forName("US-ASCII");
53
-
54
- private static final CharsetDecoder UTF7_DECODER = UTF7_MODIFIED.newDecoder();
55
-
56
- /**
57
- * Special character to shift to Modified BASE64 in modified UTF-7.
58
- */
59
- private static final char M_UTF7_SHIFT = '&';
60
-
61
- /**
62
- * Special character to shift back to US-ASCII in modified UTF-7.
63
- */
64
- private static final char M_UTF7_UNSHIFT = '-';
65
-
66
- /**
67
- * Indicates if current UTF-7 state is Modified BASE64 or not.
68
- */
69
- private boolean isShifted = false;
70
- private long metaState = 0;
71
- private StringBuilder unicodeString = new StringBuilder();
72
-
73
- @Override
74
- public void onStartInput(EditorInfo attribute, boolean restarting) {
75
- Log.i(TAG, "onStartInput");
76
- super.onStartInput(attribute, restarting);
77
-
78
- if (!restarting) {
79
- metaState = 0;
80
- isShifted = false;
81
- }
82
- unicodeString = new StringBuilder();
83
- }
84
-
85
- @Override
86
- public void onFinishInput() {
87
- Log.i(TAG, String.format("onFinishInput: %s", unicodeString));
88
- super.onFinishInput();
89
- unicodeString = new StringBuilder();
90
- }
91
-
92
- @Override
93
- public boolean onEvaluateFullscreenMode() {
94
- return false;
95
- }
96
-
97
- @SuppressLint("MissingSuperCall")
98
- @Override
99
- public boolean onEvaluateInputViewShown() {
100
- return false;
101
- }
102
-
103
- @Override
104
- public boolean onKeyDown(int keyCode, KeyEvent event) {
105
- Log.i(TAG, String.format("onKeyDown (keyCode='%s', event.keyCode='%s', metaState='%s')",
106
- keyCode, event.getKeyCode(), event.getMetaState()));
107
- int c = getUnicodeChar(keyCode, event);
108
-
109
- if (c == 0) {
110
- return super.onKeyDown(keyCode, event);
111
- }
112
-
113
- if (!isShifted) {
114
- if (c == M_UTF7_SHIFT) {
115
- shift();
116
- return true;
117
- }
118
- if (isAsciiPrintable(c)) {
119
- commitChar(c);
120
- return true;
121
- }
122
- return super.onKeyDown(keyCode, event);
123
- }
124
-
125
- if (c == M_UTF7_UNSHIFT) {
126
- unshift();
127
- } else {
128
- appendChar(c);
129
- }
130
- return true;
131
- }
132
-
133
- @Override
134
- public boolean onKeyUp(int keyCode, KeyEvent event) {
135
- Log.i(TAG, String.format("onKeyUp (keyCode='%s', event.keyCode='%s', metaState='%s')",
136
- keyCode, event.getKeyCode(), event.getMetaState()));
137
- metaState = MetaKeyKeyListener.handleKeyUp(metaState, keyCode, event);
138
- return super.onKeyUp(keyCode, event);
139
- }
140
-
141
- private void shift() {
142
- isShifted = true;
143
- unicodeString = new StringBuilder();
144
- appendChar(M_UTF7_SHIFT);
145
- }
146
-
147
- private void unshift() {
148
- isShifted = false;
149
- unicodeString.append(M_UTF7_UNSHIFT);
150
- String decoded = decodeUtf7(unicodeString.toString());
151
- getCurrentInputConnection().commitText(decoded, 1);
152
- unicodeString = new StringBuilder();
153
- }
154
-
155
- private int getUnicodeChar(int keyCode, KeyEvent event) {
156
- metaState = MetaKeyKeyListener.handleKeyDown(metaState, keyCode, event);
157
- int c = event.getUnicodeChar(event.getMetaState());
158
- metaState = MetaKeyKeyListener.adjustMetaAfterKeypress(metaState);
159
- return c;
160
- }
161
-
162
- private void commitChar(int c) {
163
- getCurrentInputConnection().commitText(String.valueOf((char) c), 1);
164
- }
165
-
166
- private void appendChar(int c) {
167
- unicodeString.append((char) c);
168
- }
169
-
170
- private static String decodeUtf7(String encStr) {
171
- ByteBuffer encoded = ByteBuffer.wrap(encStr.getBytes(ASCII));
172
- String decoded;
173
- try {
174
- CharBuffer buf = UTF7_DECODER.decode(encoded);
175
- decoded = buf.toString();
176
- } catch (CharacterCodingException e) {
177
- Log.e(TAG, e.getMessage());
178
- decoded = encStr;
179
- }
180
- return decoded;
181
- }
182
-
183
- private static boolean isAsciiPrintable(int c) {
184
- return c >= 0x20 && c <= 0x7E;
185
- }
186
-
187
- }
@@ -1,75 +0,0 @@
1
- package io.appium.settings;
2
-
3
- import android.annotation.SuppressLint;
4
- import android.app.Activity;
5
- import android.app.KeyguardManager;
6
- import android.content.Context;
7
- import android.os.Bundle;
8
- import android.os.PowerManager;
9
- import android.util.Log;
10
- import android.view.Window;
11
-
12
- import static android.os.PowerManager.ACQUIRE_CAUSES_WAKEUP;
13
- import static android.os.PowerManager.FULL_WAKE_LOCK;
14
- import static android.os.PowerManager.PARTIAL_WAKE_LOCK;
15
- import static android.os.PowerManager.SCREEN_BRIGHT_WAKE_LOCK;
16
- import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
17
- import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
18
- import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
19
-
20
- public class Unlock extends Activity {
21
- private static final String TAG = Unlock.class.getSimpleName();
22
-
23
- @Override
24
- public void onCreate(Bundle savedInstanceState) {
25
- super.onCreate(savedInstanceState);
26
- // Set window flags to unlock screen. This works on most devices by itself.
27
- Window window = this.getWindow();
28
- window.addFlags(FLAG_SHOW_WHEN_LOCKED);
29
- window.addFlags(FLAG_TURN_SCREEN_ON);
30
- window.addFlags(FLAG_DISMISS_KEYGUARD);
31
-
32
- unlockUsingWakeLock();
33
-
34
- unlockUsingKeyguard();
35
- }
36
-
37
- @SuppressLint("WakelockTimeout")
38
- private void unlockUsingWakeLock() {
39
- // some devices needs waking up screen first before disable keyguard
40
- PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
41
- if (powerManager == null) {
42
- Log.w(TAG, "Cannot retrieve the power manager instance");
43
- return;
44
- }
45
- final PowerManager.WakeLock[] wakeLocks = {
46
- powerManager.newWakeLock(SCREEN_BRIGHT_WAKE_LOCK | FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP, getLocalClassName()),
47
- powerManager.newWakeLock(PARTIAL_WAKE_LOCK, getLocalClassName())
48
- };
49
- for (PowerManager.WakeLock wakeLock : wakeLocks) {
50
- wakeLock.acquire();
51
- if (wakeLock.isHeld()) {
52
- wakeLock.release();
53
- }
54
- }
55
- }
56
-
57
- private void unlockUsingKeyguard() {
58
- // On most other devices, using the KeyguardManager + the permission in
59
- // AndroidManifest.xml will do the trick
60
- KeyguardManager mKeyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
61
- if (mKeyguardManager == null) {
62
- Log.w(TAG, "Cannot retrieve the keyguard manager instance");
63
- return;
64
- }
65
- if (mKeyguardManager.inKeyguardRestrictedInputMode()) {
66
- mKeyguardManager.newKeyguardLock(getLocalClassName()).disableKeyguard();
67
- }
68
- }
69
-
70
- @Override
71
- protected void onPostCreate(Bundle savedInstanceState) {
72
- super.onPostCreate(savedInstanceState);
73
- moveTaskToBack(true);
74
- }
75
- }
@@ -1,64 +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.handlers;
18
-
19
- import android.content.Context;
20
- import android.content.pm.PackageManager;
21
- import android.util.Log;
22
-
23
- public abstract class AbstractSettingHandler {
24
- private static final String TAG = AbstractSettingHandler.class.getSimpleName();
25
- protected Context mContext;
26
- private String[] permissions;
27
-
28
- AbstractSettingHandler(Context context, String... permissions) {
29
- this.mContext = context;
30
- this.permissions = permissions;
31
- }
32
-
33
- public boolean enable() {
34
- Log.d(TAG, "Enabling " + getSettingDescription());
35
- if (!hasPermissions()) {
36
- return false;
37
- }
38
- return setState(true);
39
- }
40
-
41
- public boolean disable() {
42
- Log.d(TAG, "Disabling " + getSettingDescription());
43
- if (!hasPermissions()) {
44
- return false;
45
- }
46
- return setState(false);
47
- }
48
-
49
- protected boolean hasPermissions() {
50
- for (String p : permissions) {
51
- if (mContext.checkCallingOrSelfPermission(p) != PackageManager.PERMISSION_GRANTED) {
52
- String logMessage = String.format("The permission %s is not set. Cannot change state of %s.",
53
- p, getSettingDescription());
54
- Log.e(TAG, logMessage);
55
- return false;
56
- }
57
- }
58
- return true;
59
- }
60
-
61
- protected abstract boolean setState(boolean state);
62
-
63
- protected abstract String getSettingDescription();
64
- }
@@ -1,66 +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.handlers;
18
-
19
- import android.annotation.SuppressLint;
20
- import android.content.Context;
21
- import android.os.IBinder;
22
- import android.util.Log;
23
-
24
- import java.lang.reflect.Method;
25
- import java.util.Arrays;
26
-
27
- public class AnimationSettingHandler extends AbstractSettingHandler {
28
- private static final String TAG = "APPIUM SETTINGS (ANIMATION)";
29
- private static final String ANIMATION_PERMISSION = "android.permission.SET_ANIMATION_SCALE";
30
-
31
- public AnimationSettingHandler(Context context) {
32
- super(context, ANIMATION_PERMISSION);
33
- }
34
-
35
- @SuppressLint("LongLogTag")
36
- @Override
37
- protected boolean setState(boolean state) {
38
- try {
39
- Class<?> serviceManagerClass = Class.forName("android.os.ServiceManager");
40
- Method getServiceMethod = serviceManagerClass.getDeclaredMethod("getService", String.class);
41
- IBinder windowManagerBinder = (IBinder) getServiceMethod.invoke(null, "window");
42
-
43
- Class<?> windowManagerClass = Class.forName("android.view.IWindowManager");
44
- Method setAnimationScales = windowManagerClass.getDeclaredMethod("setAnimationScales",
45
- float[].class);
46
- Method getAnimationScales = windowManagerClass.getDeclaredMethod("getAnimationScales");
47
-
48
- Class<?> windowManagerStubClass = Class.forName("android.view.IWindowManager$Stub");
49
- Method asInterfaceMethod = windowManagerStubClass.getDeclaredMethod("asInterface", IBinder.class);
50
- Object windowManagerObj = asInterfaceMethod.invoke(null, windowManagerBinder);
51
-
52
- float[] currentScales = (float[]) getAnimationScales.invoke(windowManagerObj);
53
- Arrays.fill(currentScales, (state == true) ? 1.0f : 0.0f);
54
- setAnimationScales.invoke(windowManagerObj, currentScales);
55
- return true;
56
- } catch (Exception e) {
57
- Log.w(TAG, "Cannot set animation scale.", e);
58
- }
59
- return false;
60
- }
61
-
62
- @Override
63
- protected String getSettingDescription() {
64
- return "animation";
65
- }
66
- }
@@ -1,42 +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.handlers;
18
-
19
- import android.annotation.SuppressLint;
20
- import android.bluetooth.BluetoothAdapter;
21
- import android.content.Context;
22
-
23
- @SuppressLint("MissingPermission")
24
- public class BluetoothConnectionSettingHandler extends AbstractSettingHandler {
25
-
26
- private BluetoothAdapter bluetoothAdapter;
27
-
28
- public BluetoothConnectionSettingHandler(Context context, BluetoothAdapter bluetoothAdapter) {
29
- super(context);
30
- this.bluetoothAdapter = bluetoothAdapter;
31
- }
32
-
33
- @Override
34
- protected boolean setState(boolean state) {
35
- return state ? bluetoothAdapter.enable() : bluetoothAdapter.disable();
36
- }
37
-
38
- @Override
39
- protected String getSettingDescription() {
40
- return "Bluetooth";
41
- }
42
- }