优化:关于软件页面下打开开机启动,将尝试跳转到系统自启动设置界面

优化:限制只能安装只内部卡,避免自启动失败(待验证)
This commit is contained in:
pppscn 2021-12-07 22:51:08 +08:00
parent 040ea0b94c
commit fa3da94147
2 changed files with 186 additions and 1 deletions

View File

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
package="com.idormy.sms.forwarder"> package="com.idormy.sms.forwarder"
android:installLocation="internalOnly">
<uses-permission <uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES" android:name="android.permission.QUERY_ALL_PACKAGES"

View File

@ -7,7 +7,9 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings;
import android.util.Log; import android.util.Log;
import android.widget.Button; import android.widget.Button;
import android.widget.Switch; import android.widget.Switch;
@ -23,6 +25,12 @@ import com.idormy.sms.forwarder.utils.Define;
import com.xuexiang.xupdate.easy.EasyUpdate; import com.xuexiang.xupdate.easy.EasyUpdate;
import com.xuexiang.xupdate.proxy.impl.DefaultUpdateChecker; import com.xuexiang.xupdate.proxy.impl.DefaultUpdateChecker;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@SuppressWarnings("SpellCheckingInspection") @SuppressWarnings("SpellCheckingInspection")
public class AboutActivity extends AppCompatActivity { public class AboutActivity extends AppCompatActivity {
@ -125,6 +133,8 @@ public class AboutActivity extends AppCompatActivity {
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED; : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
pm.setComponentEnabledSetting(cm, newState, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting(cm, newState, PackageManager.DONT_KILL_APP);
Log.d(TAG, "onCheckedChanged:" + isChecked); Log.d(TAG, "onCheckedChanged:" + isChecked);
if (isChecked) startToAutoStartSetting(this);
}); });
} }
@ -154,4 +164,178 @@ public class AboutActivity extends AppCompatActivity {
} }
} }
//Intent跳转到[自启动]页面全网最全适配机型解决方案
private static final HashMap<String, List<String>> hashMap = new HashMap<>() {
{
put("Xiaomi", Arrays.asList(
"com.miui.securitycenter/com.miui.permcenter.autostart.AutoStartManagementActivity",//MIUI10_9.8.1(9.0)
"com.miui.securitycenter"
));
put("samsung", Arrays.asList(
"com.samsung.android.sm_cn/com.samsung.android.sm.ui.ram.AutoRunActivity",
"com.samsung.android.sm_cn/com.samsung.android.sm.ui.appmanagement.AppManagementActivity",
"com.samsung.android.sm_cn/com.samsung.android.sm.ui.cstyleboard.SmartManagerDashBoardActivity",
"com.samsung.android.sm_cn/.ui.ram.RamActivity",
"com.samsung.android.sm_cn/.app.dashboard.SmartManagerDashBoardActivity",
"com.samsung.android.sm/com.samsung.android.sm.ui.ram.AutoRunActivity",
"com.samsung.android.sm/com.samsung.android.sm.ui.appmanagement.AppManagementActivity",
"com.samsung.android.sm/com.samsung.android.sm.ui.cstyleboard.SmartManagerDashBoardActivity",
"com.samsung.android.sm/.ui.ram.RamActivity",
"com.samsung.android.sm/.app.dashboard.SmartManagerDashBoardActivity",
"com.samsung.android.lool/com.samsung.android.sm.ui.battery.BatteryActivity",
"com.samsung.android.sm_cn",
"com.samsung.android.sm"
));
put("HUAWEI", Arrays.asList(
"com.huawei.systemmanager/.startupmgr.ui.StartupNormalAppListActivity",//EMUI9.1.0(方舟,9.0)
"com.huawei.systemmanager/.appcontrol.activity.StartupAppControlActivity",
"com.huawei.systemmanager/.optimize.process.ProtectActivity",
"com.huawei.systemmanager/.optimize.bootstart.BootStartActivity",
"com.huawei.systemmanager"//最后一行可以写包名, 这样如果签名的类路径在某些新版本的ROM中没找到 就直接跳转到对应的安全中心/手机管家 首页.
));
put("vivo", Arrays.asList(
"com.iqoo.secure/.ui.phoneoptimize.BgStartUpManager",
"com.iqoo.secure/.safeguard.PurviewTabActivity",
"com.vivo.permissionmanager/.activity.BgStartUpManagerActivity",
//"com.iqoo.secure/.ui.phoneoptimize.AddWhiteListActivity", //这是白名单, 不是自启动
"com.iqoo.secure",
"com.vivo.permissionmanager"
));
put("Meizu", Arrays.asList(
"com.meizu.safe/.permission.SmartBGActivity",//Flyme7.3.0(7.1.2)
"com.meizu.safe/.permission.PermissionMainActivity",//网上的
"com.meizu.safe"
));
put("OPPO", Arrays.asList(
"com.coloros.safecenter/.startupapp.StartupAppListActivity",
"com.coloros.safecenter/.permission.startup.StartupAppListActivity",
"com.oppo.safe/.permission.startup.StartupAppListActivity",
"com.coloros.oppoguardelf/com.coloros.powermanager.fuelgaue.PowerUsageModelActivity",
"com.coloros.safecenter/com.coloros.privacypermissionsentry.PermissionTopActivity",
"com.coloros.safecenter",
"com.oppo.safe",
"com.coloros.oppoguardelf"
));
put("oneplus", Arrays.asList(
"com.oneplus.security/.chainlaunch.view.ChainLaunchAppListActivity",
"com.oneplus.security"
));
put("letv", Arrays.asList(
"com.letv.android.letvsafe/.AutobootManageActivity",
"com.letv.android.letvsafe/.BackgroundAppManageActivity",//应用保护
"com.letv.android.letvsafe"
));
put("zte", Arrays.asList(
"com.zte.heartyservice/.autorun.AppAutoRunManager",
"com.zte.heartyservice"
));
//金立
put("F", Arrays.asList(
"com.gionee.softmanager/.MainActivity",
"com.gionee.softmanager"
));
//以下为未确定(厂商名也不确定)
put("smartisanos", Arrays.asList(
"com.smartisanos.security/.invokeHistory.InvokeHistoryActivity",
"com.smartisanos.security"
));
//360
put("360", Arrays.asList(
"com.yulong.android.coolsafe/.ui.activity.autorun.AutoRunListActivity",
"com.yulong.android.coolsafe"
));
//360
put("ulong", Arrays.asList(
"com.yulong.android.coolsafe/.ui.activity.autorun.AutoRunListActivity",
"com.yulong.android.coolsafe"
));
//酷派
put("coolpad"/*厂商名称不确定是否正确*/, Arrays.asList(
"com.yulong.android.security/com.yulong.android.seccenter.tabbarmain",
"com.yulong.android.security"
));
//联想
put("lenovo"/*厂商名称不确定是否正确*/, Arrays.asList(
"com.lenovo.security/.purebackground.PureBackgroundActivity",
"com.lenovo.security"
));
put("htc"/*厂商名称不确定是否正确*/, Arrays.asList(
"com.htc.pitroad/.landingpage.activity.LandingPageActivity",
"com.htc.pitroad"
));
//华硕
put("asus"/*厂商名称不确定是否正确*/, Arrays.asList(
"com.asus.mobilemanager/.MainActivity",
"com.asus.mobilemanager"
));
}
};
public static void startToAutoStartSetting(Context context) {
Log.e("Util", "******************当前手机型号为:" + Build.MANUFACTURER);
Set<Map.Entry<String, List<String>>> entries = hashMap.entrySet();
boolean has = false;
for (Map.Entry<String, List<String>> entry : entries) {
String manufacturer = entry.getKey();
List<String> actCompatList = entry.getValue();
if (Build.MANUFACTURER.equalsIgnoreCase(manufacturer)) {
for (String act : actCompatList) {
try {
Intent intent;
if (act.contains("/")) {
intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ComponentName componentName = ComponentName.unflattenFromString(act);
intent.setComponent(componentName);
} else {
//找不到? 网上的做法都是跳转到设置... 这基本上是没意义的 基本上自启动这个功能是第三方厂商自己写的安全管家类app
//所以我是直接跳转到对应的安全管家/安全中心
intent = context.getPackageManager().getLaunchIntentForPackage(act);
}
context.startActivity(intent);
has = true;
break;
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
if (!has) {
Toast.makeText(context, "兼容方案", Toast.LENGTH_SHORT).show();
try {
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
intent.setData(Uri.fromParts("package", context.getPackageName(), null));
context.startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
Intent intent = new Intent(Settings.ACTION_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
}
} }