gpt4 book ai didi

android - 以编程方式安装具有来自/system/app 的 INSTALL_PACKAGES 权限的应用程序时遇到问题

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:27:13 29 4
gpt4 key购买 nike

我试图在没有用户交互的情况下以编程方式安装应用程序,但出现此错误

 SecurityException: Neither user 10057 nor current process has android.permission.INSTALL_PACKAGES

我的安装程序位于 root 手机的/system/app 中,选中“安装非市场应用程序”,安装程序具有权限

<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>

这是我的通话功能

 private void puk(Context context) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException{

String fileName = PAKAGE_FILE_NAME ;
String dir_type = Environment.DIRECTORY_DOWNLOADS;

File dir= Environment.getExternalStoragePublicDirectory(dir_type);
java.io.File file = new java.io.File(dir ,fileName);
Uri packageUri = Uri.fromFile(file);

PackageManager pm = context.getPackageManager();

Class<? extends PackageManager> o = pm.getClass();
Method[] allMethods=o.getMethods();

for (Method m : allMethods) {
if (m.getName().equals("installPackage")) {
Log.e(TAG, "installing the app.." );
m.invoke(pm,new Object[] { packageUri, null, 1, "com.mic.zapp"});
break;
}
}

}

我遇到了这个错误

 11-15 02:46:23.320: W/System.err(10848): java.lang.reflect.InvocationTargetException
11-15 02:46:23.330: W/System.err(10848): at java.lang.reflect.Method.invokeNative(Native Method)
11-15 02:46:23.330: W/System.err(10848): at java.lang.reflect.Method.invoke(Method.java:507)
11-15 02:46:23.330: W/System.err(10848): at com.mic.pvtapi.PvtApiReflectActivity.puk(PvtApiReflectActivity.java:56)
11-15 02:46:23.330: W/System.err(10848): at com.mic.pvtapi.PvtApiReflectActivity.onCreate(PvtApiReflectActivity.java:28)
11-15 02:46:23.330: W/System.err(10848): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-15 02:46:23.330: W/System.err(10848): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
11-15 02:46:23.330: W/System.err(10848): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
11-15 02:46:23.330: W/System.err(10848): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
11-15 02:46:23.330: W/System.err(10848): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
11-15 02:46:23.330: W/System.err(10848): at android.os.Handler.dispatchMessage(Handler.java:99)
11-15 02:46:23.330: W/System.err(10848): at android.os.Looper.loop(Looper.java:130)
11-15 02:46:23.330: W/System.err(10848): at android.app.ActivityThread.main(ActivityThread.java:3835)
11-15 02:46:23.330: W/System.err(10848): at java.lang.reflect.Method.invokeNative(Native Method)
11-15 02:46:23.330: W/System.err(10848): at java.lang.reflect.Method.invoke(Method.java:507)
11-15 02:46:23.330: W/System.err(10848): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
11-15 02:46:23.330: W/System.err(10848): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
11-15 02:46:23.330: W/System.err(10848): at dalvik.system.NativeStart.main(Native Method)
11-15 02:46:23.330: W/System.err(10848): Caused by: java.lang.SecurityException: Neither user 10057 nor current process has android.permission.INSTALL_PACKAGES.
11-15 02:46:23.340: W/System.err(10848): at android.os.Parcel.readException(Parcel.java:1322)
11-15 02:46:23.340: W/System.err(10848): at android.os.Parcel.readException(Parcel.java:1276)
11-15 02:46:23.340: W/System.err(10848): at android.content.pm.IPackageManager$Stub$Proxy.installPackage(IPackageManager.java:2037)
11-15 02:46:23.340: W/System.err(10848): at android.app.ContextImpl$ApplicationPackageManager.installPackage(ContextImpl.java:2613)

我读到可以通过两种方式获得 INSTALL_PAKAGES 权限:使用固件 key 对应用程序签名或将应用程序放入固件中。我的应用程序是从/system/app 运行的,因此它必须获得特权。

有人知道哪里出了问题并给我一些提示吗?谢谢

编辑:

前进一步,后退两步

我给应用添加了新的权限

 <permission 
android:name="com.mic.pvtapi.permission.INS_AP"
android:label="etichetta_perm"
android:protectionLevel="signatureOrSystem" />

<uses-permission android:name="com.mic.pvtapi.permission.INS_AP"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

没有错误

Neither user 10057 nor current process has android.permission.INSTALL_PACKAGES

但是新的

     11-15 19:43:58.895: I/ActivityManager(1838): Displayed com.mic.pvtapi/.PvtApiReflectActivity: +421ms
11-15 19:43:58.955: D/dalvikvm(4008): GC_EXPLICIT freed 3K, 51% free 2681K/5379K, external 0K/0K, paused 132ms
11-15 19:43:58.955: W/ActivityManager(1838): No content provider found for:
11-15 19:43:58.955: E/PackageManager(1838): Couldn't create temp file for downloaded package file.
11-15 19:43:58.955: W/dalvikvm(1838): threadid=13: thread exiting with uncaught exception (group=0x40018560)
11-15 19:43:58.965: E/AndroidRuntime(1838): *** FATAL EXCEPTION IN SYSTEM PROCESS: PackageManager
11-15 19:43:58.965: E/AndroidRuntime(1838): java.lang.NullPointerException
11-15 19:43:58.965: E/AndroidRuntime(1838): at com.android.server.PackageManagerService$FileInstallArgs.createCopyFile(PackageManagerService.java:5247)
11-15 19:43:58.965: E/AndroidRuntime(1838): at com.android.server.PackageManagerService$FileInstallArgs.copyApk(PackageManagerService.java:5255)
11-15 19:43:58.965: E/AndroidRuntime(1838): at com.android.server.PackageManagerService$InstallParams.handleStartCopy(PackageManagerService.java:5051)
11-15 19:43:58.965: E/AndroidRuntime(1838): at com.android.server.PackageManagerService$HandlerParams.startCopy(PackageManagerService.java:4902)
11-15 19:43:58.965: E/AndroidRuntime(1838): at com.android.server.PackageManagerService$PackageHandler.doHandleMessage(PackageManagerService.java:516)
11-15 19:43:58.965: E/AndroidRuntime(1838): at com.android.server.PackageManagerService$PackageHandler.handleMessage(PackageManagerService.java:461)
11-15 19:43:58.965: E/AndroidRuntime(1838): at android.os.Handler.dispatchMessage(Handler.java:99)
11-15 19:43:58.965: E/AndroidRuntime(1838): at android.os.Looper.loop(Looper.java:130)
11-15 19:43:58.965: E/AndroidRuntime(1838): at android.os.HandlerThread.run(HandlerThread.java:60)
11-15 19:43:58.975: I/Process(1838): Sending signal. PID: 1838 SIG: 9
11-15 19:43:59.005: I/ServiceManager(1637): service 'SurfaceFlinger' died

让我的手机崩溃、死机并重启

最佳答案

引用signatureOrSystem permissions on custom ROM

基本上,

  1. 添加所需的 <uses-permission>
  2. 将apk推送到/system/priv-app

完成(好吧,至少对我有用)。

您不需要添加 android:protectionLevel="signatureOrSystem"或 android:sharedUserId="android.uid.system"。您可以使用任何证书签名。

关于android - 以编程方式安装具有来自/system/app 的 INSTALL_PACKAGES 权限的应用程序时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8130677/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com