首页 > 其他分享 >Android 恢复出厂设置、跳过开机向导、wifi扫描界面筛选显示 的代码实现

Android 恢复出厂设置、跳过开机向导、wifi扫描界面筛选显示 的代码实现

时间:2023-08-22 17:56:13浏览次数:31  
标签:String mExposableScanResults exposableScanResults wifi List scanResult 开机 new An

恢复出厂设置:

//APK侧
        Log.d(TAG, " exeRecovery");
        String timeStamp = DateFormat.format("yyyy-MM-ddTHH:mm:ssZ", System.currentTimeMillis()).toString();
        String localeArg = "--locale=" + Locale.getDefault().toLanguageTag() ;
        Method method;
        try {
            method = Class.forName("android.os.RecoverySystem")
                    .getDeclaredMethod("bootCommand", Context.class, String[].class);
            method.setAccessible(true);
            method.invoke(null, mContext,
                    new String[]{ null, "--wipe_data", "--reason=com.flyme.mobileservice," + timeStamp, localeArg});
        } catch (NoSuchMethodException | ClassNotFoundException | IllegalAccessException |
                 InvocationTargetException e) {
            throw new RuntimeException(e);
        }

 

跳过开机向导:

//APK侧
        Log.d(TAG, "exeJumpBootWizard");
        try {
            Settings.Secure.putInt(mContext.getContentResolver(), "user_setup_complete", 1);
            Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
            Runtime.getRuntime().exec("am force-stop com.开机向导.setup");//开机向导apk具体包名自己去确认即可
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

  

wifi扫描界面筛选显示:

//packages/modules/Wifi/service/java/com/android/server/wifi/WifiServiceImpl.java 
        private List<String> mExposableScanResults = new ArrayList<String>();
        @Override
        public List<ScanResult> getScanResults(String callingPackage, String callingFeatureId) {
        enforceAccessPermission();
        int uid = Binder.getCallingUid();
        long ident = Binder.clearCallingIdentity();
        if (isVerboseLoggingEnabled()) {
            mLog.info("getScanResults uid=%").c(uid).flush();
        }
        try {
            mWifiPermissionsUtil.enforceCanAccessScanResults(callingPackage, callingFeatureId,
                    uid, null);
            List<ScanResult> scanResults = mWifiThreadRunner.call(
                    mScanRequestProxy::getScanResults, Collections.emptyList());
            if (mExposableScanResults.isEmpty()) {
                return scanResults;
            } else {
                Log.d(TAG, "begin to check mExposableScanResults...");
                List<ScanResult> scanCheckRes = new ArrayList<>();
                for(ScanResult scanResult:scanResults){
                    if (isContainsWifi(scanResult.SSID))
                        scanCheckRes.add(scanResult);
                }
                return scanCheckRes;
            }
        } catch (SecurityException e) {
            Log.w(TAG, "Permission violation - getScanResults not allowed for uid="
                    + uid + ", packageName=" + callingPackage + ", reason=" + e);
            return new ArrayList<>();
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }
    private boolean isContainsWifi(String SSID) {
        for(String scanResult:mExposableScanResults){
            if (scanResult.equals(SSID))
                return true;
        }
        return false;
    }
    public void setExposableScanResults(@NonNull List<String> exposableScanResults) {
        Log.d(TAG, "mExposableScanResults clearing...");
        mExposableScanResults.clear();
        Log.d(TAG, "mExposableScanResults putting...");
        for(String scanResult:exposableScanResults){
            mExposableScanResults.add(scanResult);
            Log.d(TAG, "mExposableScanResults add " + scanResult);
        }
    }

//packages/modules/Wifi/framework/java/android/net/wifi/WifiManager.java 
    public void setExposableScanResults(@NonNull List<String> exposableScanResults) {
        try {
            mService.setExposableScanResults(exposableScanResults);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

//packages/modules/Wifi/framework/java/android/net/wifi/IWifiManager.aidl 
    void setExposableScanResults(in List<String> exposableScanResults);

//packages/modules/Wifi/framework/java/android/net/wifi/BaseWifiService.java 
    public void setExposableScanResults(@NonNull List<String> exposableScanResults) {
        throw new UnsupportedOperationException();
    }

//APK侧
        List<String> exposableScanResults = new ArrayList<String>(){{
            add("TEST");
            add("TEST-GUEST");
            add("TEST-SDWAN");
        }};
        WifiManager wifiManager = ((WifiManager) mContext.getSystemService(WIFI_SERVICE));

        try {
            Method method = Class.forName("android.net.wifi.WifiManager")
                    .getMethod("setExposableScanResults", List.class);
            method.invoke(wifiManager, exposableScanResults);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException |
                 ClassNotFoundException e) {
            e.printStackTrace();
        }

 

标签:String,mExposableScanResults,exposableScanResults,wifi,List,scanResult,开机,new,An
From: https://www.cnblogs.com/1118zjg/p/17649270.html

相关文章

  • 如何使用Android访问文件系统路径
    Android中获取文件路径的方法:使用Context)方法:Android中获取文件路径的方法:1.使用Context.getFilesDir()方法:该方法返回的是一个File对象,它指向应用的私有文件目录,比如/data/data//files,可以通过该方法获取到应用的文件路径。代码示例:StringfilePath=getApplicationConte......
  • 零基础学Android,通俗易懂的Android教程
    前言对于一个想要入门Android的新手同学来说最重要的就是找对入门的学习路线,那样可以少走很多弯路,今天,小编就来和大家唠唠Android入门的学习方法。首先,一定要有一定的JAVA基础。我们都知道AndroidSDK是基于JAVA开发的,也是用的JAVA语言,比如在Android中要使用到的接口、继承、覆盖......
  • Android之获取DNS,优先返回本地网络DNS(插网线),其次选择Wifi网络的DNS
    code参考:https://www.cnblogs.com/alex-zhao/p/5254624.html/***获取DNS,优先返回本地网络DNS(插网线),其次选择Wifi网络的DNS**/publicstaticStringgetLocalDNS(Contextcontext){StringTAG="WiFiUtil_getLocalDNS";ProcesscmdProce......
  • 让Android Studo 不编译某个Java文件
    有时为了调试,让某些文件暂时不需编译,这样可以排除错误带来的无法运行情况,可以在build.gradle中加入:excludes=['com.coolweather.myble/AddrInterceptor.java'],如下compileOptions{sourceCompatibilityJavaVersion.VERSION_1_8targetCompatibilityJavaVers......
  • 直播平台软件开发,Android studio设置分割线
    直播平台软件开发,Androidstudio设置分割线该方法在xml布局文件中添加ImageView控件设置竖直分割线时,设置宽度为0.5dp,高度为match_parent(与父控件等高),颜色设置为black(黑色),此处数值可根据需求自行更改     <ImageView      android:layout_width=......
  • 直播带货源码,Android studio设计app登录界面
    直播带货源码,Androidstudio设计app登录界面TextView:用于显示标题和“用户名"和"密码"的提示;标题设置   <TextView    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="登录页面"    a......
  • 记录一次在Android Studio中,任务:app:compileDebugJavaWithJavac的执行失败了
    因为我命令行覆盖提交了一次git代码,导致git原本的版本不见了,构建项目的时候提示会找不到SDK排查过程:构建项目时提示找不到SDK目录,经过排查后发现是gitpull的时候没有把local.properties这个文件上传上去,导致后面下载回来的项目都没有,而原本的本地目录被我删了 随机根据最初原始目......
  • STM32 Wifi开发
    一、概述1.用到的资源说明1.1wifi模块:ESP8266EX1.2串口,串口接收不定长数据采用定时器超时的方式判断一帧数据是否接收完成,定时器1ms中断一次;2.采用AP+Station模式,这种模式比较实用。AP用来设置wifi信息的,连接ESP8266wifi信号,此时ESP8266就是服务端,可以写一个上位机socket......
  • android.os.handlerexecutor
    android.os.HandlerExecutor是一个Android平台的Executor,它可以将任务发布到指定的Handler运行。可以将HandlerExecutor视为一种将任务提交到Handler的简单方法,与使用Handler.post(Runnable)相比,HandlerExecutor具有更好的可读性和可维护性。在Android中,UI线程(也称为主线程)用于处理......
  • t113-c-制作wifi设置页面
    c转命令行首先我们要用到命令行,c和命令行这么转换呢?https://blog.csdn.net/arv002/article/details/112711673根据这篇文章那么:popen:什么是popen?https://www.cnblogs.com/52php/p/5722238.html简单来说就是c语言和cmmd的交互函数,注意这个函数会产生子进程简单的测试一下:#......