/
ActivityAccessibilityImpl.java
52 lines (40 loc) · 1.55 KB
/
ActivityAccessibilityImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package top.trumeet.common.ita.impl;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.util.Log;
import top.trumeet.common.ita.DetectionService;
import top.trumeet.common.ita.ITopActivity;
/**
* Created by zts1993 on 2018/2/18.
*/
public class ActivityAccessibilityImpl implements ITopActivity {
private final static String TAG = "ActivityAccessibility";
@Override
public boolean isEnabled(Context context) {
int accessibilityEnabled = 0;
try {
accessibilityEnabled = Settings.Secure.getInt(context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_ENABLED);
} catch (Settings.SettingNotFoundException e) {
Log.e(TAG, e.getMessage(), e);
}
if (accessibilityEnabled == 1) {
String services = Settings.Secure.getString(context.getContentResolver(),
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
if (services != null) {
return services.toLowerCase().contains(context.getPackageName().toLowerCase());
}
}
return false;
}
@Override
public void guideToEnable(Context context) {
Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
public boolean isAppForeground(Context context, String packageName) {
return packageName.equals(DetectionService.getForegroundPackageName());
}
}