tyc600 发表于 2023-6-25 06:43

逆向魔改安卓7.0/7.1 systemUI添加"关闭所有程序"广播报错

本帖最后由 tyc600 于 2023-6-25 06:55 编辑

参考网上的思路Android 7.1.1 Framework 修改记录(二) 清理近期任务并排除白名单,想要给安卓7.0/7.1 systemUI添加"关闭所有程序"广播, 我没有系统源代码编译systemUI,因为代码不多,所以采用的直接模仿smali代码的方式在com/android/systemui/下新建了一个新建了一个名为CloseAllAppsReceiver的class,代码如下第一个代码段。第二段代码为在MT管理器转换为java后的代码,然后在AndroidManifest里面注册广播第三段代码。没有在frameworks的AndroidManifest.xml新增protected-broadcast android:name="close.all.apps.by.external.intent". 声明这个广播保护的话,就只允许系统应用调用了吧,计划通过第三方应用(tasker)发送意图来一键执行"关闭所有应用程序",现在魔改后的systemUI,在tasker执行意图后,直接报"systemUI停止工作,关闭应用"。有7.0/7.1的大神,能不能试试整合我的smali代码到你的systemUI,帮忙看看smali代码是否有问题。另外参考博文里面的调用是从外部第三方调用这个systemUI里面的广播的吧?模仿原生系统里声明一个允许被第三方调用的意图广播, 是我的smali代码有问题,还是有其他额外的步骤遗漏,还请各位帮忙看看,谢谢了。
(另外tasker已经魔改过了添加了uses-permission android:name="android.permission.REMOVE_TASKS,并且可以通过内置的java代码能力,成功执行关闭任务的操作,所以第三方应用的关闭任务权限是没有障碍的)

.class public Lcom/android/systemui/CloseAllAppsReceiver;
.super Landroid/content/BroadcastReceiver;
.source "CloseAllAppsReceiver.java"


# static fields
.field private static TAG:Ljava/lang/String; = null

.field public static final action:Ljava/lang/String; = "close.all.apps.by.external.intent"


# instance fields
.field private mAm:Landroid/app/ActivityManager;

.field mRawTasks:Ljava/util/List;
    .annotation system Ldalvik/annotation/Signature;
      value = {
            "Ljava/util/List",
            "<",
            "Landroid/app/ActivityManager$RecentTaskInfo;",
            ">;"
      }
    .end annotation
.end field

# direct methods
.method static constructor <clinit>()V
    .registers 1

    const-string/jumbo v0, "recent"

    sput-object v0, Lcom/android/systemui/CloseAllAppsReceiver;->TAG:Ljava/lang/String;

    return-void
.end method

.method public constructor <init>()V
    .registers 1

    invoke-direct {p0}, Landroid/content/BroadcastReceiver;-><init>()V

    return-void
.end method


# virtual methods
.method public onReceive(Landroid/content/Context;Landroid/content/Intent;)V
    .registers 8

    invoke-virtual {p2}, Landroid/content/Intent;->getAction()Ljava/lang/String;

    move-result-object v0

    sget-object v1, Lcom/android/systemui/CloseAllAppsReceiver;->action:Ljava/lang/String;

    invoke-virtual {v1, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v1

    if-eqz v1, :cond_4a

    const-string/jumbo v1, "activity"

    invoke-virtual {p1, v1}, Landroid/content/Context;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Landroid/app/ActivityManager;

    move-object/from16 p1, p0

    iput-object v1, p1, Lcom/android/systemui/CloseAllAppsReceiver;->mAm:Landroid/app/ActivityManager;

    :try_start_19
    invoke-static {}, Landroid/app/ActivityManager;->getMaxRecentTasksStatic()I

    move-result p0

    const/4 v2, 0x0

    invoke-static {}, Lcom/android/systemui/recents/Recents;->getSystemServices()Lcom/android/systemui/recents/misc/SystemServicesProxy;

    move-result-object v3

    new-instance v0, Landroid/util/ArraySet;

    invoke-direct {v0}, Landroid/util/ArraySet;-><init>()V
   
   const/4 v4, -0x2

    invoke-virtual {v3, p0, v4, v2, v0}, Lcom/android/systemui/recents/misc/SystemServicesProxy;->getRecentTasks(IIZLandroid/util/ArraySet;)Ljava/util/List;

    move-result-object v2
   
   if-eqz v2, :cond_4a

    invoke-interface {v2}, Ljava/util/List;->isEmpty()Z

    move-result v4

    if-nez v4, :cond_4a

    invoke-virtual {v2}, Ljava/util/ArrayList;->iterator()Ljava/util/Iterator;

    move-result-object v2

    :goto_38
    invoke-interface {v2}, Ljava/util/Iterator;->hasNext()Z

    move-result v3

    if-eqz v3, :cond_4a

    invoke-interface {v2}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    iget v4, v0, Landroid/app/ActivityManager$RecentTaskInfo;->persistentId:I

    iget-object v1, p1, Lcom/android/systemui/CloseAllAppsReceiver;->mAm:Landroid/app/ActivityManager;

    invoke-virtual {v1, v4}, Landroid/app/ActivityManager;->removeTask(I)V

    goto :goto_38
    :try_end_4a
    .catch Ljava/lang/Exception; {:try_start_19 .. :try_end_4a} :catch_4b

    :cond_4a
    :goto_4a
    return-void

    :catch_4b
    move-exception v0

    sget-object v3, Lcom/android/systemui/CloseAllAppsReceiver;->TAG:Ljava/lang/String;

    const-string/jumbo v4, "close all apps failed: "

    invoke-static {v3, v4}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    goto :goto_4a
.end method




package com.android.systemui;

import android.app.ActivityManager;
import android.app.ActivityManager.RecentTaskInfo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.ArraySet;
import android.util.Log;
import com.android.systemui.recents.Recents;
import java.util.Iterator;
import java.util.List;

public class CloseAllAppsReceiver extends BroadcastReceiver {
    private static String TAG = "recent";
    public static final String action = "close.all.apps.by.external.intent";
    private ActivityManager mAm;
    List<RecentTaskInfo> mRawTasks;

    public void onReceive(Context context, Intent intent) {
      if (action.equals(intent.getAction())) {
            this.mAm = (ActivityManager) context.getSystemService("activity");
            try {
                Object recentTasks = Recents.getSystemServices().getRecentTasks(ActivityManager.getMaxRecentTasksStatic(), -2, false, new ArraySet());
                if (recentTasks != null && !recentTasks.isEmpty()) {
                  Iterator it = recentTasks.iterator();
                  while (it.hasNext()) {
                        this.mAm.removeTask(it.next().persistentId);
                  }
                }
            } catch (Exception e) {
                Log.e(TAG, "close all apps failed: ");
            }
      }
    }
}

<receiver
       android:name=".CloseAllAppsReceiver"
       android:exported="true">
      <intent-filter>
      <action
         android:name="close.all.apps.by.external.intent"/>
      </intent-filter>
    </receiver>
页: [1]
查看完整版本: 逆向魔改安卓7.0/7.1 systemUI添加"关闭所有程序"广播报错