MIUI12_Global未知来源安装等待时间patcher

MIUI12_Global未知来源安装等待时间patcher,第1张

概述快过年了,被疫情困在家,实在无聊就给小米9换了个MIUI12_Global的ROM。但是,每次开启USB调试,以及允许安装应用都需要等待5秒才能授权。于是楼主花费了几个钟头的时间终于搞定了五秒的等待时间,虽然只测试了小米9的V12.0.4.0.QFAMIXM,但是其他机型或者其他版本的ROM应该都差不多,感兴趣

快过年了,被疫情困在家,实在无聊就给小米9换了个Miui12_Global 的ROM。但是,每次开启USB调试,以及允许安装应用都需要等待5秒才能授权。于是楼主花费了几个钟头的时间终于搞定了五秒的等待时间,虽然只测试了小米9的V12.0.4.0.QFAMIXM,但是其他机型或者其他版本的ROM应该都差不多,感兴趣的可以测试一下。

机型小米9(cepheus)
ROMV12.0.4.0.QFAMIXM_20210115.0000.00_10.0_global
相关软件设置(/system/product/priv-app/Settings/Settings.apk)
手机管家(/system/priv-app/securitycenter/securitycenter.apk)

 

 

 

 

 

1、定位软件:当前进程(名字就叫当前进程)

我在芥子空间找到了app【当前进程】用来查看当前窗口Activity的软件。

首先打开软件,然后开启悬浮窗进行记录Activity活动,

 

一看这个Activity的名字立马感觉就来了。

二话不说,把securitycenter.apk拿出用jd-gui来看看。

2、分析

找到com.miui.permcenter.privacymanager.SpecialPermissionInterceptActivity 

有第一张图我们可以看到这个Activity的界面有两个button,而且其中button(Text="允许")需要计时结束后,才可点击,但是button(Text="取消")则是随时可点击的。

用jd-gui打开com.miui.permcenter.privacymanager.SpecialPermissionInterceptActivity的源码:

package com.miui.permcenter.privacymanager;import androID.content.Context;import androID.content.Intent;import androID.graphics.drawable.colorDrawable;import androID.graphics.drawable.Drawable;import androID.os.Bundle;import androID.os.Handler;import androID.os.Message;import androID.provIDer.Settings;import androID.text.TextUtils;import androID.vIEw.LayoutInflater;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.vIEw.Window;import androID.Widget.button;import androID.Widget.linearLayout;import androID.Widget.TextVIEw;import b.b.f.j.B;import b.b.f.j.F;import b.b.f.j.o;import com.miui.permcenter.compact.SystemPropertIEsCompat;import java.lang.ref.WeakReference;import java.util.HashMap;import java.util.Map;import miui.app.Activity;public class SpecialPermissionInterceptActivity extends Activity implements VIEw.OnClickListener {  private static final Map<String, b> a = new HashMap<String, b>();    private a b;    private String c;    private String d;    private String e;    private TextVIEw f;    private linearLayout g;    private TextVIEw h;    private button i;    private button j;    private int k;    static {    a.put("perm_install_unkNown", new b(2131757339, 2130903079, 2131757335));    a.put("perm_notification", new b(2131757336, 2130903077, 2131757337));    a.put("perm_app_statistics", new b(2131757338, 2130903078, 2131757337));    a.put("miui_open_deBUG", new b(2131755938, 2130903055, 2131755937));    a.put("miui_close_optimization", new b(2131757023, 2130903063, 2131757022));    a.put("oaID_close", new b(0, 2131757158, 2131757159));  }    private voID a() {    try {      Window window = getwindow();      window.addFlags(-2147483648);      window.getDecorVIEw().setsystemUIVisibility(768);      window.getClass().getmethod("setNavigationbarcolor", new Class[] { int.class }).invoke(window, new Object[] { Integer.valueOf(0) });    } catch (Exception exception) {}  }    private voID a(boolean paramBoolean) {    if ("miui_open_deBUG".equals(this.d) && paramBoolean) {          Settings.Global.putInt(getContentResolver(), "adb_enabled", paramBoolean);    } else if ("miui_close_optimization".equals(this.d) && paramBoolean) {      SystemPropertIEsCompat.set("persist.sys.miui_optimization", Boolean.valueOf(paramBoolean ^ true).toString());    }     if (paramBoolean) {      byte b = -1;    } else {      paramBoolean = false;    }     setResult(paramBoolean);    //设置Activity的Result,现在还用不到,但是在分析设置的时候很有用    finish();  }    private voID b() {//这个方法就是对这个Activity窗口不同的权限请求的判断    String[] arrayofstring;    if (this.d.startsWith("perm") && !TextUtils.isEmpty(this.e)) {//判断是要打开usb还是未知来源的安装请求。      this.f.setText(getString(((b)a.get(this.d)).a, new Object[] { B.j((Context)this, this.c) }));      this.h.setText(getString(((b)a.get(this.d)).c, new Object[] { this.e }));    } else if (this.d.startsWith("miui")) {      this.f.setText(((b)a.get(this.d)).a);      this.h.setText(((b)a.get(this.d)).c);    }     if ("oaID_close".equals(this.d)) {      this.f.setVisibility(4);      this.h.setText(((b)a.get(this.d)).c);      arrayofstring = new String[1];      arrayofstring[0] = getString(((b)a.get(this.d)).b);    } else {      arrayofstring = getResources().getStringArray(((b)a.get(this.d)).b);    }     LayoutInflater layoutInflater = LayoutInflater.from((Context)this);    int i = arrayofstring.length;    for (byte b = 0; b < i; b++) {      String str = arrayofstring[b];      VIEw vIEw = layoutInflater.inflate(2131493425, (VIEwGroup)this.g, false);      TextVIEw textVIEw = (TextVIEw)vIEw.findVIEwByID(2131297085);      if (arrayofstring.length == 1) {        vIEw.findVIEwByID(2131297086).setVisibility(8);        linearLayout.LayoutParams layoutParams = new linearLayout.LayoutParams(textVIEw.getLayoutParams());        layoutParams.leftmargin = 0;        textVIEw.setLayoutParams((VIEwGroup.LayoutParams)layoutParams);      }       textVIEw.setText(str);      this.g.addVIEw(vIEw);    }     this.i.setText(getString(2131755748, new Object[] { Integer.valueOf(this.k) }));    this.b.sendEmptyMessageDelayed(1, 1000L);  }    private voID c() {    int i = --this.k;        //前面已经将k设为5,这里对k的值进行递减    if (i <= 0) {            //判断是否小于0,如果小于0,则this.i.setEnabled(true);      this.i.setText(2131755747);      this.i.setEnabled(true);    //允许 按键被设为可点击。      this.k = 0;    } else {      this.i.setText(getString(2131755748, new Object[] { Integer.valueOf(i) }));      this.b.removeMessages(1);      this.b.sendEmptyMessageDelayed(1, 1000L);    // 时间为1秒    }   }    public voID onBackpressed() {}    public voID onClick(VIEw paramVIEw) {       //这个方法就是两个按钮共同绑定的方法,用户带年纪允许或者取消都会调用这个方法    boolean bool;    int i = paramVIEw.getID();    if (i != 2131297087) { //判断i来确定用户点击了允许还是取消,并且将bool赋值(允许true)                                        if (i != 2131297091)    //查找一下ID可以找到相关信息,这里就跳过了        return;                     bool = false;    } else {      bool = true;    }     a(bool);                  //当用户点击允许,这调用a(bool),这里的bool为true;  }    protected voID onCreate(Bundle paramBundle) {    // 1.先看这个方法    super.onCreate(paramBundle);    Window window = getwindow();    window.setBackgroundDrawable((Drawable)new colorDrawable(getResources().getcolor(2131100554)));    window.setLayout(-1, -1);    window.addFlags(4);    setContentVIEw(2131493424);    a();    this.c = getIntent().getStringExtra("pkgname");    this.d = getIntent().getStringExtra("permname");    this.e = getIntent().getStringExtra("permDesc");    if (!a.containsKey(this.d)) {      finish();      return;    }     if (paramBundle != null) {      this.k = paramBundle.getInt("KET_STEP_COUNT", 5);    //可以合理的怀疑一下k是不是那5秒    } else {      this.k = 5;    }     this.b = new a(this);    this.f = (TextVIEw)findVIEwByID(2131297090);    this.g = (linearLayout)findVIEwByID(2131297088);    this.h = (TextVIEw)findVIEwByID(2131297089);    this.i = (button)findVIEwByID(2131297087);//这里的this.i和this.j其实就是两个button组件            this.j = (button)findVIEwByID(2131297091);    this.i.setEnabled(false);//这里按钮i被设置为不可点击状态,可以断定这个就是“取消”按钮            this.i.setonClickListener(this); //两个按钮绑定了同一个OnClick    this.j.setonClickListener(this);           if (F.a()) {      o.b((VIEw)this.i);      o.b((VIEw)this.j);    }     b();//跟进看一下  }    protected voID onDestroy() {    super.onDestroy();    a a1 = this.b;    if (a1 != null)      a1.removeMessages(1);   }    protected voID onNewIntent(Intent paramIntent) {    super.onNewIntent(paramIntent);  }    protected voID onSaveInstanceState(Bundle paramBundle) {    super.onSaveInstanceState(paramBundle);    paramBundle.putInt("KET_STEP_COUNT", this.k);  }    private static class a extends Handler {    private WeakReference<SpecialPermissionInterceptActivity> a;        public a(SpecialPermissionInterceptActivity param1SpecialPermissionInterceptActivity) {      this.a = new WeakReference<SpecialPermissionInterceptActivity>(param1SpecialPermissionInterceptActivity);    }        public voID handleMessage(Message param1Message) {      super.handleMessage(param1Message);      SpecialPermissionInterceptActivity specialPermissionInterceptActivity = this.a.get();      if (specialPermissionInterceptActivity != null && !specialPermissionInterceptActivity.isFinishing() && !specialPermissionInterceptActivity.isDestroyed())        SpecialPermissionInterceptActivity.a(specialPermissionInterceptActivity);     }  }    public static class b {    int a;        int b;        int c;        public b(int param1Int1, int param1Int2, int param1Int3) {      this.a = param1Int1;      this.b = param1Int2;      this.c = param1Int3;    }  }}

分析到这里,想要去掉这5秒以及是手到擒来的事了。我们可以把k的值在onCreate方法中变成负数,或者将button i 设置为setEnabled(true);即让它直接可以点击。

。。。。。。。

如果仅仅在SpecialPermissionInterceptActivity中修改它的组件属性就任然会有第一张图示的提示消息。楼主进一步琢磨着,准备向魔爪伸向Settings.apk。

当前进程App 可以看到

 

               

             

            

当用户进入这个界面(com.androID,settings.Settings$ManageAppExternalSourcesActivity),点击“允许来自此来源的应用”   就会启动com.miui.permcenter.privacymanager.SpecialPermissionInterceptActivity

所以在Settings.apk(包名:com.androID,settings),启动securitycenter.apk(包名:com.miui.securitycenter)

我们可以在Settings.apk来查找相关的源码,查找是否有与com.miui.securitycenter相关的startActivity()方法。

经过人肉筛选,我定位到

com.androID.settings.applications.appinfo.ExternalSourcesDetails

发现ExternalSourcesDetails类中有个fV()方法会启动com.miui.securitycenter的Activity

Intent intent = new Intent("com.miui.securitycenter.action.UNKNowN_SOURCE_VERIFY");intent.setPackage("com.miui.securitycenter");startActivityForResult(intent, 101);

所以当fV()被调用,向com.miui.securitycenter发送intent,然后就会d出SpecialPermissionInterceptActivity重要警告的窗口,

这里面有个十分关键的方法:

onPreferenceChange() 返回boolean值

这个方法就是当我们点击按钮后响应的方法,它的返回值决定了按钮是否改变。(return false 不改变按钮状态,return true 则将按钮改为相反的状态)

当我们点击“允许来自此来源的应用”就会d出SpecialPermissionInterceptActivity重要警告的窗口,所以我们对onPreferenceChange()进行分析:

  public boolean onPreferenceChange(Preference paramPreference, Object paramObject) {    boolean bool = ((Boolean)paramObject).booleanValue();    if (paramPreference == this.Ps) {      AppStateInstallAppsBrIDge.InstallAppsstate installAppsstate = this.Ws;      if (installAppsstate != null && bool != installAppsstate.gx()) {        if (bool) {          Intent intent = a.c(((AppInfoBase)this).mPackagename, "perm_install_unkNown", this.mContext.getResources().getString(2131889241));          if (a.g(this.mContext, intent)) {            We(102);            return true;          }           if (fV())            return true;         }         We(bool);      }       return true;    }     return false;  } 

我们看这个bool 的值实际上就是onPreferenceChange()第二个实际参数强制转换成的boolean值,

(1)如果bool = true;则会调用fV()启动警告窗口,改变按钮状态

(2)如果bool = false;则会执行We(bool);再看一下

onPreferenceChange()中调用了fV()方法,如果返回真值,就改变按钮状态。然后将bool作为参数执行We()方法

  private voID We(boolean paramBoolean) {    if (Settings.ManageAppExternalSourcesActivity.class.getname().equals(getIntent().getComponent().getClassname())) {      boolean bool;      if (paramBoolean) {        bool = true;      } else {        bool = false;      }       setResult(bool);    }     setCanInstallApps(paramBoolean);    refreshUi();  }

其实很容易看出来,实际上

We(boolean paramBoolean)方法的参数传递给setCanInstallApps()方法。

然后未知来源的安装权限就到手了。

我们可以在onPreferenceChange()方法中将调用fV()方法的代码注释掉,换成执行We(true)的代码就可以完成修改了。

package com.androID.settings.applications.appinfo;import androID.app.Activity;import androID.app.ActivityManager;import androID.app.AlertDialog;import androID.app.AppOpsManager;import androID.content.Context;import androID.content.Intent;import androID.content.pm.PackageInfo;import androID.os.Bundle;import androID.os.UserHandle;import androID.os.UserManager;import androIDx.preference.Preference;import com.androID.internal.annotations.VisibleForTesting;import com.androID.settings.Settings;import com.androID.settings.applications.AppInfoBase;import com.androID.settings.applications.AppInfoWithheader;import com.androID.settings.applications.AppStateInstallAppsBrIDge;import com.androID.settingslib.RestrictedSwitchPreference;import com.androID.settingslib.applications.Applicationsstate;import d.a.a.a;import miui.os.Build;public class ExternalSourcesDetails extends AppInfoWithheader implements Preference.b {  private RestrictedSwitchPreference Ps;    private AppStateInstallAppsBrIDge Vs;    private AppStateInstallAppsBrIDge.InstallAppsstate Ws;    private ActivityManager mActivityManager;    private AppOpsManager mAppOpsManager;    private Context mContext;    private UserManager mUserManager;    private voID Ii(int paramInt) {    if (UserHandle.iscore(paramInt))      return;     this.mActivityManager.killUID(paramInt, "User denIEd OP_REQUEST_INSTALL_PACKAGES");  }    private voID We(boolean paramBoolean) {    if (Settings.ManageAppExternalSourcesActivity.class.getname().equals(getIntent().getComponent().getClassname())) {      boolean bool;      if (paramBoolean) {        bool = true;      } else {        bool = false;      }       setResult(bool);    }     setCanInstallApps(paramBoolean);    refreshUi();  }    public static CharSequence b(Context paramContext, Applicationsstate.a parama) {    UserHandle userHandle = UserHandle.getUserHandleForUID(parama.info.uID);    UserManager userManager = UserManager.get(paramContext);    int i = userManager.getUserRestrictionSource("no_install_unkNown_sources", userHandle);    i = userManager.getUserRestrictionSource("no_install_unkNown_sources_globally", userHandle) | i;    if ((i & 0x1) != 0)      return paramContext.getString(2131888227);     if (i != 0)      return paramContext.getString(2131888224);     if ((new AppStateInstallAppsBrIDge(paramContext, null, null)).s(parama.info.packagename, parama.info.uID).gx()) {      i = 2131886579;    } else {      i = 2131886580;    }     return paramContext.getString(i);  }    private boolean fV() {    if (!Build.IS_INTERNATIONAL_BUILD && !Build.IS_tableT && UserHandle.myUserID() == 0) {      Intent intent = new Intent("com.miui.securitycenter.action.UNKNowN_SOURCE_VERIFY");      intent.setPackage("com.miui.securitycenter");      startActivityForResult(intent, 101);      return true;    }     return false;  }    public int ab() {    return 808;  }    protected AlertDialog k(int paramInt1, int paramInt2) {    return null;  }    public voID onActivityResult(int paramInt1, int paramInt2, Intent paramIntent) {    super.onActivityResult(paramInt1, paramInt2, paramIntent);    boolean bool1 = false;    boolean bool2 = false;    if (paramInt1 == 101) {      if (paramInt2 == -1)        bool2 = true;       We(bool2);    } else if (paramInt1 == 102) {      bool2 = bool1;      if (paramInt2 == -1)        bool2 = true;       AppStateInstallAppsBrIDge.InstallAppsstate installAppsstate = this.Ws;      if (installAppsstate != null && bool2 != installAppsstate.gx()) {        if (bool2 && fV())          return;         We(true);      }     }   }    public voID onCreate(Bundle paramBundle) {    super.onCreate(paramBundle);    Activity activity = getActivity();    this.Vs = new AppStateInstallAppsBrIDge((Context)activity, ((AppInfoBase)this).mState, null);    this.mAppOpsManager = (AppOpsManager)activity.getSystemService("appops");    this.mActivityManager = (ActivityManager)activity.getSystemService(ActivityManager.class);    this.mUserManager = UserManager.get((Context)activity);    addPreferencesFromresource(2132082829);    this.Ps = (RestrictedSwitchPreference)findPreference("external_sources_settings_switch");    this.Ps.setonPreferencechangelistener(this);    this.mContext = (Context)activity;  }    public voID onDestroy() {    this.Vs.release();    super.onDestroy();  }    public boolean onPreferenceChange(Preference paramPreference, Object paramObject) {    boolean bool = ((Boolean)paramObject).booleanValue();    if (paramPreference == this.Ps) {      AppStateInstallAppsBrIDge.InstallAppsstate installAppsstate = this.Ws;      if (installAppsstate != null && bool != installAppsstate.gx()) {        if (bool) {          Intent intent = a.c(((AppInfoBase)this).mPackagename, "perm_install_unkNown", this.mContext.getResources().getString(2131889241));          if (a.g(this.mContext, intent)) {            We(102);            return true;          }           if (fV())            return true;         }         We(bool);      }       return true;    }     return false;  }    protected boolean refreshUi() {    PackageInfo packageInfo = ((AppInfoBase)this).mPackageInfo;    if (packageInfo == null || packageInfo.applicationInfo == null)      return false;     if (this.mUserManager.hasBaseUserRestriction("no_install_unkNown_sources", UserHandle.of(UserHandle.myUserID()))) {      this.Ps.setChecked(false);      this.Ps.setSummary(2131888224);      this.Ps.setEnabled(false);      return true;    }     this.Ps.Ba("no_install_unkNown_sources");    if (!this.Ps.zj())      this.Ps.Ba("no_install_unkNown_sources_globally");     if (this.Ps.zj())      return true;     this.Ws = this.Vs.s(((AppInfoBase)this).mPackagename, ((AppInfoBase)this).mPackageInfo.applicationInfo.uID);    if (!this.Ws.isPotentialAppSource()) {      this.Ps.setEnabled(false);      return true;    }     this.Ps.setChecked(this.Ws.gx());    return true;  }    @VisibleForTesting  voID setCanInstallApps(boolean paramBoolean) {    byte b1;    AppOpsManager appOpsManager = this.mAppOpsManager;    int i = ((AppInfoBase)this).mPackageInfo.applicationInfo.uID;    String str = ((AppInfoBase)this).mPackagename;    if (paramBoolean) {      b1 = 0;    } else {      b1 = 2;    }     appOpsManager.setMode(66, i, str, b1);    if (!paramBoolean)      Ii(((AppInfoBase)this).mPackageInfo.applicationInfo.uID);   }}

 

ps:关于如何定位到代码,就自己慢慢琢磨吧,这是很难解释清楚的。

 

 

 

 

 

总结

以上是内存溢出为你收集整理的MIUI12_Global未知来源安装等待时间patcher全部内容,希望文章能够帮你解决MIUI12_Global未知来源安装等待时间patcher所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1051271.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存