6.3.0 - 新增 ocr / notice / s13n / Color 模块; 新增前台时保持屏幕常亮; 修复构建脚本依赖; 修复并优化控制台浮动窗口
This commit is contained in:
148
app/src/main/java/ezy/assist/compat/RomUtil.java
Normal file
148
app/src/main/java/ezy/assist/compat/RomUtil.java
Normal file
@@ -0,0 +1,148 @@
|
||||
package ezy.assist.compat;
|
||||
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class RomUtil {
|
||||
private static final String TAG = "RomUtil";
|
||||
|
||||
public static final String ROM_MIUI = "MIUI";
|
||||
public static final String ROM_EMUI = "EMUI";
|
||||
public static final String ROM_FLYME = "FLYME";
|
||||
public static final String ROM_OPPO = "OPPO";
|
||||
public static final String ROM_SMARTISAN = "SMARTISAN";
|
||||
|
||||
public static final String ROM_VIVO = "VIVO";
|
||||
public static final String ROM_QIKU = "QIKU";
|
||||
|
||||
public static final String ROM_LENOVO = "LENOVO";
|
||||
public static final String ROM_SAMSUNG = "SAMSUNG";
|
||||
|
||||
private static final String KEY_VERSION_MIUI = "ro.miui.ui.version.name";
|
||||
private static final String KEY_VERSION_EMUI = "ro.build.version.emui";
|
||||
private static final String KEY_VERSION_OPPO = "ro.build.version.opporom";
|
||||
private static final String KEY_VERSION_SMARTISAN = "ro.smartisan.version";
|
||||
private static final String KEY_VERSION_VIVO = "ro.vivo.os.version";
|
||||
private static final String KEY_VERSION_GIONEE = "ro.gn.sv.version";
|
||||
private static final String KEY_VERSION_LENOVO = "ro.lenovo.lvp.version";
|
||||
private static final String KEY_VERSION_FLYME = "ro.build.display.id";
|
||||
|
||||
|
||||
private static final String KEY_EMUI_VERSION_CODE = "ro.build.hw_emui_api_level";
|
||||
|
||||
private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";
|
||||
private static final String KEY_MIUI_HANDY_MODE_SF = "ro.miui.has_handy_mode_sf";
|
||||
private static final String KEY_MIUI_REAL_BLUR = "ro.miui.has_real_blur";
|
||||
|
||||
private static final String KEY_FLYME_PUBLISHED = "ro.flyme.published";
|
||||
private static final String KEY_FLYME_FLYME = "ro.meizu.setupwizard.flyme";
|
||||
|
||||
private static final String KEY_FLYME_ICON_FALG = "persist.sys.use.flyme.icon";
|
||||
private static final String KEY_FLYME_SETUP_FALG = "ro.meizu.setupwizard.flyme";
|
||||
private static final String KEY_FLYME_PUBLISH_FALG = "ro.flyme.published";
|
||||
|
||||
private static final String KEY_VIVO_OS_NAME = "ro.vivo.os.name";
|
||||
private static final String KEY_VIVO_OS_VERSION = "ro.vivo.os.version";
|
||||
private static final String KEY_VIVO_ROM_VERSION = "ro.vivo.rom.version";
|
||||
|
||||
public static boolean isEmui() {
|
||||
return check(ROM_EMUI);
|
||||
}
|
||||
|
||||
public static boolean isMiui() {
|
||||
return check(ROM_MIUI);
|
||||
}
|
||||
|
||||
public static boolean isVivo() {
|
||||
return check(ROM_VIVO);
|
||||
}
|
||||
|
||||
public static boolean isOppo() {
|
||||
return check(ROM_OPPO);
|
||||
}
|
||||
|
||||
public static boolean isFlyme() {
|
||||
return check(ROM_FLYME);
|
||||
}
|
||||
|
||||
public static boolean isQiku() {
|
||||
return check(ROM_QIKU) || check("360");
|
||||
}
|
||||
|
||||
public static boolean isSmartisan() {
|
||||
return check(ROM_SMARTISAN);
|
||||
}
|
||||
|
||||
private static String sName;
|
||||
|
||||
public static String getName() {
|
||||
if (sName == null) {
|
||||
check("");
|
||||
}
|
||||
return sName;
|
||||
}
|
||||
|
||||
private static String sVersion;
|
||||
|
||||
public static String getVersion() {
|
||||
if (sVersion == null) {
|
||||
check("");
|
||||
}
|
||||
return sVersion;
|
||||
}
|
||||
|
||||
public static boolean check(String rom) {
|
||||
if (sName != null) {
|
||||
return sName.equals(rom);
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_MIUI))) {
|
||||
sName = ROM_MIUI;
|
||||
} else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_EMUI))) {
|
||||
sName = ROM_EMUI;
|
||||
} else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_OPPO))) {
|
||||
sName = ROM_OPPO;
|
||||
} else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_VIVO))) {
|
||||
sName = ROM_VIVO;
|
||||
} else if (!TextUtils.isEmpty(sVersion = getProp(KEY_VERSION_SMARTISAN))) {
|
||||
sName = ROM_SMARTISAN;
|
||||
} else {
|
||||
sVersion = Build.DISPLAY;
|
||||
if (sVersion.toUpperCase().contains(ROM_FLYME)) {
|
||||
sName = ROM_FLYME;
|
||||
} else {
|
||||
sVersion = Build.UNKNOWN;
|
||||
sName = Build.MANUFACTURER.toUpperCase();
|
||||
}
|
||||
}
|
||||
return sName.equals(rom);
|
||||
}
|
||||
|
||||
public static String getProp(String name) {
|
||||
String line;
|
||||
BufferedReader input = null;
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec("getprop " + name);
|
||||
input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
|
||||
line = input.readLine();
|
||||
input.close();
|
||||
} catch (IOException ex) {
|
||||
Log.e(TAG, "Unable to read prop " + name, ex);
|
||||
return null;
|
||||
} finally {
|
||||
if (input != null) {
|
||||
try {
|
||||
input.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return line;
|
||||
}
|
||||
}
|
||||
184
app/src/main/java/ezy/assist/compat/SettingsCompat.java
Normal file
184
app/src/main/java/ezy/assist/compat/SettingsCompat.java
Normal file
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright 2016 czy1121
|
||||
*
|
||||
* 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 ezy.assist.compat;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Binder;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
||||
public class SettingsCompat {
|
||||
private static final String TAG = "ezy-settings-compat";
|
||||
|
||||
public static boolean canDrawOverlays(Context context) {
|
||||
return Settings.canDrawOverlays(context);
|
||||
}
|
||||
|
||||
public static boolean canWriteSettings(Context context) {
|
||||
return Settings.System.canWrite(context);
|
||||
}
|
||||
|
||||
public static void manageDrawOverlays(Context context) {
|
||||
if (manageDrawOverlaysForRom(context)) {
|
||||
return;
|
||||
}
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
|
||||
intent.setData(Uri.parse("package:" + context.getPackageName()));
|
||||
context.startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
public static void manageWriteSettings(Context context) {
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
|
||||
intent.setData(Uri.parse("package:" + context.getPackageName()));
|
||||
context.startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
private static boolean manageDrawOverlaysForRom(Context context) {
|
||||
if (RomUtil.isMiui()) {
|
||||
return manageDrawOverlaysForMiui(context);
|
||||
}
|
||||
if (RomUtil.isEmui()) {
|
||||
return manageDrawOverlaysForEmui(context);
|
||||
}
|
||||
if (RomUtil.isFlyme()) {
|
||||
return manageDrawOverlaysForFlyme(context);
|
||||
}
|
||||
if (RomUtil.isOppo()) {
|
||||
return manageDrawOverlaysForOppo(context);
|
||||
}
|
||||
if (RomUtil.isVivo()) {
|
||||
return manageDrawOverlaysForVivo(context);
|
||||
}
|
||||
if (RomUtil.isQiku()) {
|
||||
return manageDrawOverlaysForQihu(context);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static boolean checkOp(Context context, int op) {
|
||||
AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
||||
try {
|
||||
Method method = AppOpsManager.class.getDeclaredMethod("checkOp", int.class, int.class, String.class);
|
||||
return AppOpsManager.MODE_ALLOWED == (int) method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName());
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, Log.getStackTraceString(e));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean startSafely(Context context, Intent intent) {
|
||||
if (context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0) {
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
} else {
|
||||
Log.e(TAG, "Intent is not available! " + intent);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 小米
|
||||
private static boolean manageDrawOverlaysForMiui(Context context) {
|
||||
Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
|
||||
intent.putExtra("extra_pkgname", context.getPackageName());
|
||||
intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
|
||||
if (startSafely(context, intent)) {
|
||||
return true;
|
||||
}
|
||||
intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");
|
||||
return startSafely(context, intent);
|
||||
}
|
||||
|
||||
private final static String HUAWEI_PACKAGE = "com.huawei.systemmanager";
|
||||
|
||||
// 华为
|
||||
private static boolean manageDrawOverlaysForEmui(Context context) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClassName(HUAWEI_PACKAGE, "com.huawei.systemmanager.addviewmonitor.AddViewMonitorActivity");
|
||||
if (startSafely(context, intent)) {
|
||||
return true;
|
||||
}
|
||||
// Huawei Honor P6|4.4.4|3.0
|
||||
intent.setClassName(HUAWEI_PACKAGE, "com.huawei.notificationmanager.ui.NotificationManagmentActivity");
|
||||
intent.putExtra("showTabsNumber", 1);
|
||||
if (startSafely(context, intent)) {
|
||||
return true;
|
||||
}
|
||||
intent.setClassName(HUAWEI_PACKAGE, "com.huawei.permissionmanager.ui.MainActivity");
|
||||
return startSafely(context, intent);
|
||||
}
|
||||
|
||||
// VIVO
|
||||
private static boolean manageDrawOverlaysForVivo(Context context) {
|
||||
// 不支持直接到达悬浮窗设置页,只能到 i管家 首页
|
||||
Intent intent = new Intent("com.iqoo.secure");
|
||||
intent.setClassName("com.iqoo.secure", "com.iqoo.secure.MainActivity");
|
||||
// com.iqoo.secure.ui.phoneoptimize.SoftwareManagerActivity
|
||||
// com.iqoo.secure.ui.phoneoptimize.FloatWindowManager
|
||||
return startSafely(context, intent);
|
||||
}
|
||||
|
||||
// OPPO
|
||||
private static boolean manageDrawOverlaysForOppo(Context context) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("packageName", context.getPackageName());
|
||||
// OPPO A53|5.1.1|2.1
|
||||
intent.setAction("com.oppo.safe");
|
||||
intent.setClassName("com.oppo.safe", "com.oppo.safe.permission.floatwindow.FloatWindowListActivity");
|
||||
if (startSafely(context, intent)) {
|
||||
return true;
|
||||
}
|
||||
// OPPO R7s|4.4.4|2.1
|
||||
intent.setAction("com.color.safecenter");
|
||||
intent.setClassName("com.color.safecenter", "com.color.safecenter.permission.floatwindow.FloatWindowListActivity");
|
||||
if (startSafely(context, intent)) {
|
||||
return true;
|
||||
}
|
||||
intent.setAction("com.coloros.safecenter");
|
||||
intent.setClassName("com.coloros.safecenter", "com.coloros.safecenter.sysfloatwindow.FloatWindowListActivity");
|
||||
return startSafely(context, intent);
|
||||
}
|
||||
|
||||
// 魅族
|
||||
private static boolean manageDrawOverlaysForFlyme(Context context) {
|
||||
Intent intent = new Intent("com.meizu.safe.security.SHOW_APPSEC");
|
||||
intent.setClassName("com.meizu.safe", "com.meizu.safe.security.AppSecActivity");
|
||||
intent.putExtra("packageName", context.getPackageName());
|
||||
return startSafely(context, intent);
|
||||
}
|
||||
|
||||
// 360
|
||||
private static boolean manageDrawOverlaysForQihu(Context context) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClassName("com.android.settings", "com.android.settings.Settings$OverlaySettingsActivity");
|
||||
if (startSafely(context, intent)) {
|
||||
return true;
|
||||
}
|
||||
intent.setClassName("com.qihoo360.mobilesafe", "com.qihoo360.mobilesafe.ui.index.AppEnterActivity");
|
||||
return startSafely(context, intent);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user