首页 > 其他分享 >android 10 禁止通过adb命令的方式删除特定APK

android 10 禁止通过adb命令的方式删除特定APK

时间:2024-09-25 16:21:09浏览次数:11  
标签:10 return pw packageName userId APK adb flags final

— a/frameworks/base/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
+++ b/frameworks/base/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
@@ -1636,84 +1636,88 @@ class PackageManagerShellCommand extends ShellCommand {
}

 private int runUninstall() throws RemoteException {
  •    final PrintWriter pw = getOutPrintWriter();
    
  •    int flags = 0;
    
  •    int userId = UserHandle.USER_ALL;
    
  •    long versionCode = PackageManager.VERSION_CODE_HIGHEST;
    
  •    String opt;
    
  •    while ((opt = getNextOption()) != null) {
    
  •        switch (opt) {
    
  •            case "-k":
    
  •                flags |= PackageManager.DELETE_KEEP_DATA;
    
  •                break;
    
  •            case "--user":
    
  •                userId = UserHandle.parseUserArg(getNextArgRequired());
    
  •                break;
    
  •            case "--versionCode":
    
  •                versionCode = Long.parseLong(getNextArgRequired());
    
  •                break;
    
  •            default:
    
  •                pw.println("Error: Unknown option: " + opt);
    
  •                return 1;
    
  •        }
    
  •    }
    
  •    final String packageName = getNextArg();
    
  •    if (packageName == null) {
    
  •        pw.println("Error: package name not specified");
    
  •        return 1;
    
  •    }
    
  •    // if a split is specified, just remove it and not the whole package
    
  •    final String splitName = getNextArg();
    
  •    if (splitName != null) {
    
  •        return runRemoveSplit(packageName, splitName);
    
  •    }
    
  •    userId = translateUserId(userId, true /*allowAll*/, "runUninstall");
    
  •    final LocalIntentReceiver receiver = new LocalIntentReceiver();
    
  •    PackageManagerInternal internal = LocalServices.getService(PackageManagerInternal.class);
    
  •    if (internal.isApexPackage(packageName)) {
    
  •        internal.uninstallApex(packageName, versionCode, userId, receiver.getIntentSender());
    
  •    } else {
    
  •        if (userId == UserHandle.USER_ALL) {
    
  •            userId = UserHandle.USER_SYSTEM;
    
  •            flags |= PackageManager.DELETE_ALL_USERS;
    
  •        } else {
    
  •            final PackageInfo info = mInterface.getPackageInfo(packageName,
    
  •                    PackageManager.MATCH_STATIC_SHARED_LIBRARIES, userId);
    
  •            if (info == null) {
    
  •                pw.println("Failure [not installed for " + userId + "]");
    
  •                return 1;
    
  •            }
    
  •            final boolean isSystem =
    
  •                    (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
    
  •            // If we are being asked to delete a system app for just one
    
  •            // user set flag so it disables rather than reverting to system
    
  •            // version of the app.
    
  •            if (isSystem) {
    
  •                flags |= PackageManager.DELETE_SYSTEM_APP;
    
  •            }
    
  •        }
    
  •        mInterface.getPackageInstaller().uninstall(new VersionedPackage(packageName,
    
  •                        versionCode), null /*callerPackageName*/, flags,
    
  •                receiver.getIntentSender(), userId);
    
  •    }
    
  •    final Intent result = receiver.getResult();
    
  •    final int status = result.getIntExtra(PackageInstaller.EXTRA_STATUS,
    
  •            PackageInstaller.STATUS_FAILURE);
    
  •    if (status == PackageInstaller.STATUS_SUCCESS) {
    
  •        pw.println("Success");
    
  •        return 0;
    
  •    } else {
    
  •        pw.println("Failure ["
    
  •                + result.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE) + "]");
    
  •        //add  ycj
           return 1;
    
  •    }
    
  •        //end  ycj
    

+/* final PrintWriter pw = getOutPrintWriter();

  •                   int flags = 0;
    
  •                   int userId = UserHandle.USER_ALL;
    
  •                   long versionCode = PackageManager.VERSION_CODE_HIGHEST;
    
  •                   String opt;
    
  •                   while ((opt = getNextOption()) != null) {
    
  •                           switch (opt) {
    
  •                                   case "-k":
    
  •                                           flags |= PackageManager.DELETE_KEEP_DATA;
    
  •                                           break;
    
  •                                   case "--user":
    
  •                                           userId = UserHandle.parseUserArg(getNextArgRequired());
    
  •                                           break;
    
  •        return 1;
    
  •    }
    
  •    // if a split is specified, just remove it and not the whole package
    
  •    final String splitName = getNextArg();
    
  •    if (splitName != null) {
    
  •        return runRemoveSplit(packageName, splitName);
    
  •    }
    
  •    userId = translateUserId(userId, true /*allowAll*/, "runUninstall");
    
  •    final LocalIntentReceiver receiver = new LocalIntentReceiver();
    
  •    PackageManagerInternal internal = LocalServices.getService(PackageManagerInternal.class);
    
  •    if (internal.isApexPackage(packageName)) {
    
  •        internal.uninstallApex(packageName, versionCode, userId, receiver.getIntentSender());
    
  •    } else {
    
  •        if (userId == UserHandle.USER_ALL) {
    
  •            userId = UserHandle.USER_SYSTEM;
    
  •            flags |= PackageManager.DELETE_ALL_USERS;
    
  •        } else {
    
  •            final PackageInfo info = mInterface.getPackageInfo(packageName,
    
  •                    PackageManager.MATCH_STATIC_SHARED_LIBRARIES, userId);
    
  •            if (info == null) {
    
  •                pw.println("Failure [not installed for " + userId + "]");
    
  •                return 1;
    
  •            }
    
  •            final boolean isSystem =
    
  •                    (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
    
  •            // If we are being asked to delete a system app for just one
    
  •            // user set flag so it disables rather than reverting to system
    
  •            // version of the app.
    
  •            if (isSystem) {
    
  •                flags |= PackageManager.DELETE_SYSTEM_APP;
    
  •            }
    
  •        }
    
  •        mInterface.getPackageInstaller().uninstall(new VersionedPackage(packageName,
    
  •                        versionCode), null /*callerPackageName*/, flags,
    
  •                receiver.getIntentSender(), userId);
    
  •    }
    
  •    final Intent result = receiver.getResult();
    
  •    final int status = result.getIntExtra(PackageInstaller.EXTRA_STATUS,
    
  •            PackageInstaller.STATUS_FAILURE);
    
  •    if (status == PackageInstaller.STATUS_SUCCESS) {
    
  •        pw.println("Success");
    
  •        return 0;
    
  •    } else {
    
  •        pw.println("Failure ["
    
  •                + result.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE) + "]");
    
  •        //add  ycj
           return 1;
    
  •    }
    
  •        //end  ycj
    

+/* final PrintWriter pw = getOutPrintWriter();

  •                   int flags = 0;
    
  •                   int userId = UserHandle.USER_ALL;
    
  •                   long versionCode = PackageManager.VERSION_CODE_HIGHEST;
    
  •                   String opt;
    
  •                   while ((opt = getNextOption()) != null) {
    
  •                           switch (opt) {
    
  •                                   case "-k":
    
  •                                           flags |= PackageManager.DELETE_KEEP_DATA;
    
  •                                           break;
    
  •                                   case "--user":
    
  •                                           userId = UserHandle.parseUserArg(getNextArgRequired());
    
  •                                           break;
    
  •                                   case "--versionCode":
    
  •                                           versionCode = Long.parseLong(getNextArgRequired());
    
  •                                           break;
    
  •                                   default:
    
  •                                           pw.println("Error: Unknown option: " + opt);
    
  •                                           return 1;
    
  •                           }
    
  •                   }
    
  •                   final String packageName = getNextArg();
    
  •                   if (packageName == null) {
    
  •                           pw.println("Error: package name not specified");
    
  •                           return 1;
    
  •                   }
    
  •                   // if a split is specified, just remove it and not the whole package
    
  •                   final String splitName = getNextArg();
    
  •                   if (splitName != null) {
    
  •                           return runRemoveSplit(packageName, splitName);
    
  •                   }
    
  •                   userId = translateUserId(userId, true , "runUninstall");
    
  •                   final LocalIntentReceiver receiver = new LocalIntentReceiver();
    
  •                   PackageManagerInternal internal = LocalServices.getService(PackageManagerInternal.class);
    
  •                   if (internal.isApexPackage(packageName)) {
    
  •                           internal.uninstallApex(packageName, versionCode, userId, receiver.getIntentSender());
    
  •                   } else {
    
  •                           if (userId == UserHandle.USER_ALL) {
    
  •                                   userId = UserHandle.USER_SYSTEM;
    
  •                                   flags |= PackageManager.DELETE_ALL_USERS;
    
  •                           } else {
    
  •                                   final PackageInfo info = mInterface.getPackageInfo(packageName,
    
  •                                                   PackageManager.MATCH_STATIC_SHARED_LIBRARIES, userId);
    
  •                                   if (info == null) {
    
  •                                           pw.println("Failure [not installed for " + userId + "]");
    
  •                                           return 1;
    
  •                                   }
    
  •                                   final boolean isSystem =
    
  •                                                   (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
    
  •                                   // If we are being asked to delete a system app for just one
    
  •                                   // user set flag so it disables rather than reverting to system
    
  •                                   // version of the app.
    
  •                                   if (isSystem) {
    
  •                                           flags |= PackageManager.DELETE_SYSTEM_APP;
    
  •                                   }
    
  •                           }
    
  •                           mInterface.getPackageInstaller().uninstall(new VersionedPackage(packageName,
    
  •                                                           versionCode), null , flags,
    
  •                                           receiver.getIntentSender(), userId);
    
  •                   }
    
  •                   final Intent result = receiver.getResult();
    
  •                   final int status = result.getIntExtra(PackageInstaller.EXTRA_STATUS,
    
  •                                   PackageInstaller.STATUS_FAILURE);
    
  •                   if (status == PackageInstaller.STATUS_SUCCESS) {
    
  •                           pw.println("Success");
    
  •                           return 0;
    
  •                   } else {
    
  •                           pw.println("Failure ["
    
  •                                           + result.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE) + "]");
    
  •                           return 1;
    
  •                   }
    
  •           } */    
    

    }

    private int runRemoveSplit(String packageName, String splitName) throws RemoteException {

标签:10,return,pw,packageName,userId,APK,adb,flags,final
From: https://blog.csdn.net/juzi_bug/article/details/142451625

相关文章

  • KBU1010-ASEMI单向整流桥KBU1010
    编辑:llKBU1010-ASEMI单向整流桥KBU1010型号:KBU1010品牌:ASEMI封装:KBU-4批号:2024+类型:单向整流桥电流(ID):10A电压(VF):1000V安装方式:直插式封装特性:大功率、整流扁桥产品引线数量:4产品内部芯片个数:4产品内部芯片尺寸:MIL工作结温:-55℃~150℃功率:中小功率包装方式:500/盒:3......
  • 【2024潇湘夜雨】WIN 11_IoT_Ent_LTSC_2024_24H2.26100.1876软件选装纯净特别版9.25
    【系统简介】=============================================================1.本次更新母盘来自WIN11_IoT_Ent_LTSC_2024_24H2.26100.1876.2.全程离线精简、无人值守调用优化处理制作。部分优化适配系统可能要重启几次,即使显示适配失败也不要在意,可能部分优化不适用。3.OS版本号......
  • 深入了解ISO 10012测量管理体系认证
    在当今快速发展的市场环境中,企业面临着越来越高的质量管理和测量要求。ISO10012测量管理体系认证应运而生,旨在帮助企业建立一套系统的测量管理流程,确保其测量过程和测量设备的准确性与可靠性。这一认证不仅对企业的内部管理有着深远影响,也为其在市场竞争中提供了有力支持。ISO100......
  • AutoMQ:云原生 Kafka 解决方案,降低10倍成本100%完美兼容
    文章目录AutoMQ:云原生Kafka的全新演绎概述设计理念存储分离至共享云存储服务可靠性与可用性分离AutoMQ的技术优势1.成本效益2.极致弹性3.冷热数据隔离4.服务零中断5.与ApacheKafka完全兼容AutoMQ部署与验证一键安装操作指南创建Topic发送消息消费消息总结公众号,感谢......
  • Validation Failed: 1: this action would add [2] shards, but this cluster current
    在最近部署的一个项目中,是使用elk来记录应用系统日志的,突然发现,近几天的日志在kibana上面没有显示。于是去排查elk的日志,发现logstash中有这样一条警告信息"ValidationFailed:1:thisactionwouldadd[2]shards,butthisclustercurrentlyhas[999]/[1000]maximumn......
  • 数据处理与统计分析篇-day10-Matplotlib数据可视化
    数据可视化简介可视化介绍数据可视化是指直观展现数据,它是数据处理过程的一部分。把数值绘制出来更方便比较。借助数据可视化,能更直观地理解数据,这是直接查看数据表做不到的数据可视化有助于揭示数据中隐藏的模式,数据分析时可以利用这些模式选择模型可视化库介绍基于......
  • 最强Java100道核心面试题
    1.讲讲你理解的nio和bio的区别是啥,谈谈reactor模型。IO(BIO)是面向流的,NIO是面向缓冲区的BIO:BlockIO同步阻塞式IO,就是我们平常使用的传统IO,它的特点是模式简单使用方便,并发处理能力低。NIO:NewIO同步非阻塞IO,是传统IO的升级,客户端和服务器端通过Channel(通道)通......
  • Delphi10.3关键字自动填充完成AutoComplete
    声明两个全局变量varaStringList:TStringList;//读取关键字aMemoInput:string;//当前已输入项procedureTSearchReplaceDemoForm.FormCreate(Sender:TObject);beginaStringList:=TStringList.Create;aStringList.LoadFromFile('keyWord.txt');//从文件......
  • E+H恩得斯豪斯CYK10-A051
    E+H恩德斯豪斯CYK10-A051是一款高性能的PH计数字电极电缆,广泛应用于工业自动化和过程控制领域。以下是关于该产品的详细介绍:主要特性高精度:CYK10-A051电缆具有高精度的测量性能,能够准确传输PH值等电化学参数,确保测量结果的准确性和可靠性。完全防水连接:该电缆具有IP68防护等......
  • 10个超好用的企业文档加密软件丨2024年加密软件大盘点
    都2024年了!泄密事件依旧频发!到底该如何防止文档信息泄密?别急,本文小编为你整理了10款超好用的企业文档加密软件,有力保护你的文档信息安全,快来看看吧,一定有你的菜!1.安企神系统作为国内企业信息安全领域的领军产品,安企神在文档加密方面表现出色。其专为企业设计的加密系......