Device owner app update Itself silently

柔情痞子 提交于 2021-02-20 18:46:56

问题


is it possible to update a device owner app by itself silently? My app is set to device owner, i want it to update itself silently. is it possible? the method i'm using is given below,

 private void install(Context context,String packageName,String apkPath){
    PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller();

    PackageInstaller.SessionParams params = new PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL);
    params.setAppPackageName(context.getPackageName());

    try {
        int sessionId = packageInstaller.createSession(params);
        PackageInstaller.Session session = packageInstaller.openSession(sessionId);
        OutputStream  out = session.openWrite(packageName,0,-1);
        File apkFile = new File(apkPath);
        InputStream in = new FileInputStream(apkFile);

        byte[] buffer = new byte[65536];
        int c;
        while ((c = in.read(buffer)) != -1) {
            out.write(buffer, 0, c);
        }
        session.fsync(out);
        in.close();
        out.close();

        PendingIntent pendingIntent = PendingIntent.getBroadcast(context,sessionId,
                new Intent("com.afwsamples.testdpc.INSTALL_COMPLETE"),0);
        IntentSender intentSender = pendingIntent.getIntentSender();

        session.commit(intentSender);

    }catch (Exception e){
        Log.d("PackageInstaller","package installer exception");
    }

}

I can install another package using this method through my app but not my app itself. Here is what the log shows when I try to install the same app which is a device owner.

     --------- beginning of system
     07-24 13:53:13.329 4039-4063/system_process I/PackageManager: init_copy 
     idx=0: InstallParams{a5de1df file=/data/app/vmdl1864928398.tmp cid=null}
     07-24 13:53:13.338 4039-4063/system_process I/PackageManager: mcs_bound
     startCopy UserHandle{0}: InstallParams{a5de1df 
     file=/data/app/vmdl1864928398.tmp cid=null}
     07-24 13:53:13.341 3709-4027/? D/audio_hw_primary: 
     out_standby(0xf48e3000)
     do_output_standby(0xf48e3000)
     07-24 13:53:13.341 3709-4027/? I/audio_hw_primary: remove out 
     (0xf48e3000) from index 0
     close pcm 0xf1b90380
     07-24 13:53:13.347 4039-4063/system_process D/PackageManager: 
     /data/app/vmdl1864928398.tmp already staged; skipping copy
     07-24 13:53:13.348 4039-4063/system_process D/PackageManager: 
     installPackageLI: path=/data/app/vmdl1864928398.tmpjava.lang.Throwable
     at com.android.server.pm.PackageManagerService
     .installPackageLI(PackageManagerService.java:12247)
     at com.android.server.pm.PackageManagerService.- 
     wrap25(PackageManagerService.java)
     at com.android.server.pm.PackageManagerService$9
     .run(PackageManagerService.java:10176)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.os.HandlerThread.run(HandlerThread.java:61)
    at com.android.server.ServiceThread.run(ServiceThread.java:46)
    07-24 13:53:13.360 4039-4063/system_process W/PackageParser: Ignoring 
    duplicate uses-permissions/uses-permissions-sdk-m: 
    android.permission.INTERNET in package: com.xyz.cocoapp at: Binary 
    XML file line #23
   Ignoring duplicate uses-permissions/uses-permissions-sdk-m: 
    android.permission.ACCESS_NETWORK_STATE in package: com.xyz.cocoapp 
    at: Binary XML file line #24
    07-24 13:53:13.361 4039-4063/system_process W/PackageParser: Ignoring 
    duplicate uses-permissions/uses-permissions-sdk-m: 
    android.permission.WAKE_LOCK in package: com.xyz.cocoapp at: Binary 
    XML file line #30
   Ignoring duplicate uses-permissions/uses-permissions-sdk-m: 
   android.permission.WAKE_LOCK in package: com.xyz.cocoapp at: Binary 
    XML file line #32
    07-24 13:53:13.362 4039-4063/system_process W/PackageParser: Ignoring 
    duplicate uses-permissions/uses-permissions-sdk-m: 
    android.permission.GET_ACCOUNTS in package: com.xyz.cocoapp at: 
    Binary XML file line #33
    07-24 13:53:13.363 4039-4063/system_process W/PackageParser: Ignoring 
    duplicate uses-permissions/uses-permissions-sdk-m: 
    android.permission.READ_EXTERNAL_STORAGE in package: com.xyz.cocoapp
    at: Binary XML file line #45

    07-24 13:53:13.369 4039-4063/system_process W/PackageManager: 
    installPackageLI

    07-24 13:53:13.391 4039-4063/system_process I/art: 
    Starting a blocking GC Explicit
    07-24 13:53:13.469 4039-4063/system_process I/art: 
    Explicit concurrent mark sweep GC freed 58637(2MB) AllocSpace objects, 
    10(340KB) LOS objects, 
    33% free, 10MB/15MB, paused 3.604ms total 77.999ms
    07-24 13:53:13.470 3710-3710/?
    E/installd: Couldn't opendir/data/app/vmdl1864928398.tmp: No such file 
    or directory

As per this stackoverflow question selfupdate of device owner app is possible. helps please..

来源:https://stackoverflow.com/questions/51503258/device-owner-app-update-itself-silently

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!