kolbasa / cordova-plugin-apkupdater

This plugin allows your Android app to download and install compressed updates without the Google Play Store.
MIT License
97 stars 23 forks source link

is it possible to update an application without user intervention/without using root? #40

Closed aldrigo closed 2 years ago

aldrigo commented 2 years ago

greetings, it is possible to update the app with this new ownerInstall() function without user intervention? I've been using your plugin for some time now, I use it in Kiosk mode. sorry my ingles

kolbasa commented 2 years ago

ownerInstall() can be used on any device to which you have physical access. The setup with adb has to be done only once, after that the app can update itself every time. This method is perfect for kiosk apps.

aldrigo commented 2 years ago

Thank you very much for the feedback, sorry I didn't understand, how to make this ADB setup?

kolbasa commented 2 years ago

No problem. I am happy to help. Have you seen the instructions here?

Steps:

  1. Install your app with the latest plugin version.
  2. Activate the developer mode on the device.
  3. Connect the device to your PC (adb devices should now show your device)
  4. Execute adb shell dpm set-device-owner your.app.id/de.kolbasa.apkupdater.tools.DAReceiver (replace the your.app.id appropriately)
  5. The ownerInstall() method can now update your app.
aldrigo commented 2 years ago

tks! I'm going to test at this point, there's only way to do this ADB config via command prompt?

kolbasa commented 2 years ago

The easiest way is via ADB.

As far as I know there are two more ways to unlock the owner permission:

aldrigo commented 2 years ago

I'm having a return after ADB command:Not allowed to set the device owner because there are already some accounts on the device

aldrigo commented 2 years ago

I ask about the reasons to grant permission because I have hundreds of TOTENS (kiosk mod) spread across Brazil, I can't go to each one to give permission, all I wanted was to be able to update the totems without user intervention

aldrigo commented 2 years ago

I managed to use ownerInstall() on another clean device, my question now is only in relation to the update because I realized that the Application closes and does not open again alone, is that so?

kolbasa commented 2 years ago

there are already some accounts

Ah yes, forgot to say. You have to log out of Google first. It does not work with a linked Google account.

I ask about the reasons to grant permission because I have hundreds of TOTENS

I understand. However, I am not aware of an easier way. Android is quite strict about that.

I realized that the Application closes and does not open again alone

Hmm. Should actually open up again. Here's a video of what it looks like on my app.

kolbasa commented 2 years ago

I may be able to fix the restart thing though. The logic is controlled by the plugin. Which Android version are you using?

aldrigo commented 2 years ago

here it doesn't open again... I'm using android 8.1.0

kolbasa commented 2 years ago

Ok, I'll see if I can reproduce this. Today I don't have time yet, but tomorrow I'll take care of it.

kolbasa commented 2 years ago

I have fixed the bug now:

cordova plugin add https://github.com/kolbasa/cordova-plugin-apkupdater#device-owner-reload

However, it will take a few more days to get that into the main-branch. I want to put some other stuff in the release version. But you can already use it that way.

aldrigo commented 2 years ago

Good Morning! I just did some testing and the problem still persists... my app doesn't open after updating, but it does notify me that it has been updated by adm, android 8.1.0

const apkUpdater = (window as any).ApkUpdater;

await apkUpdater.isDeviceOwner().then(res =>{

  console.log("deu bom")

}).catch(err =>{ console.log("deu ruim")

})// -> true, false

kolbasa commented 2 years ago

Can you please double check that you actually have plugin version 3.0.1 in your app?

aldrigo commented 2 years ago

positive cordova-plugin-apkupdater 3.0.1 "Apk Updater"

kolbasa commented 2 years ago

Ah, I think I know what the problem is. The update, that is the apk you want to update to, must have the new plugin version. The installed app version doesn't matter. So you have to generate your update with the new plugin version.

aldrigo commented 2 years ago

that must be it, this apk is in version 2.0.2 if I'm not mistaken, I thought that only the current apk should have the plugin updated

kolbasa commented 2 years ago

Yeah, it's not going to work that way. Only an apk with the new plugin version will restart itself.

aldrigo commented 2 years ago

now it's working as it should! thank you very much, i'll check how I'm going to do the ADB commands in production line and see if it's going to be feasible to do it that way for the new tetens that come out

kolbasa commented 2 years ago

I read yesterday that you can also activate the device owner status on devices with the help of an NFC tag. If your devices have NFC. https://developers.google.com/android/work/play/emm-api/prov-devices#device_owner_provisioning_methods

kolbasa commented 2 years ago

Oh, apparently also with QR codes, if the devices have a camera:

Some devices, such as tablets, don’t support NFC. QR code provisioning is an easy way 
to provision a distributed fleet of devices that don’t support NFC. An IT admin can send 
QR codes to their users to allow user-driven provisioning.

I'll give that a try when I get a chance.

aldrigo commented 2 years ago

wow!! QR code would be great, I use tablets without NFC, I don't even know what to search for, if you can, I'm very grateful!

kolbasa commented 2 years ago

So, I have tried it now and I am surprised how well it works.

First define which app should be used as device owner. The required format can be found here.

Here is the example configuration for my demo app:

{
    "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME": "de.kolbasa.apkupdater.demo/de.kolbasa.apkupdater.tools.DAReceiver",
    "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM": "24lpCxXMePT5QGa0wHQl8A7jK9j-d23Sq3OXA9_ZgI8",
    "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION": "https://raw.githubusercontent.com/kolbasa/cordova-plugin-apkupdater-demo/master/Demo.apk"
}

Then generate a QR code with this config on any QR generator page, e.g. here: https://zxing.appspot.com/generator/ (Select Text under Contents).

Here is the QR code for my demo app: ApkUpdaterDemo

With this, you can now set up your devices as follows:

You can also try it first with the QR code of my demo. You just have to reset the device afterwards. Once you have the QR code you can quite easily instruct other people how to set up the device. It's only a few steps.

aldrigo commented 2 years ago

I didn't understand very well the part of generating the QR code but tomorrow morning I will try it calmly ... I'm using ionic v3 + macOS

kolbasa commented 2 years ago

I have updated the command so that it also works under macOS.

aldrigo commented 2 years ago

Good Morning! I just didn't understand this part. Then you need to generate the signature checksum for [...]_SIGNATURE_CHECKSUM

aldrigo commented 2 years ago

my device can't install the QR code reader I don't know why

kolbasa commented 2 years ago

Is there an error message? I have successfully tested it with an Android 7 and 10 device.

aldrigo commented 2 years ago

says it is not possible to install QR code, my tablet only has a front camera that must be why

kolbasa commented 2 years ago

says it is not possible to install QR code Have you tried it with my demo QR code? It sounds like the configuration for the QR code is wrong.

aldrigo commented 2 years ago

I couldn't even test your QR code, after I entered the WIFI password, my device did that it's installing the QR code reader, but it can't install it, it must be known that it only has a front camera

kolbasa commented 2 years ago

Ah OK, that's weird. Is the internet connection restricted on the devices? Maybe the connection to Google is blocked. On my Android 7 device, a QR code reader is also downloaded and installed first.

The fact that the tablet only has a front-facing camera should not be a problem. The installed Reader supports both cameras.

aldrigo commented 2 years ago

there is no blocking, i will try on other tablets, i am disappointed... :(

kolbasa commented 2 years ago

I can't really help with that. I would guess that something is wrong with the Internet connection. Faulty DNS, ad blocker, restricted company network, etc. It's a Google feature. That shouldn't actually break so easily.

aldrigo commented 2 years ago

greetings after updating (3.0.1) the plugin in my main project I'm getting an error in the download function: Class not found , could you help me please?

kolbasa commented 2 years ago

Can you give me the full error message? It works for me.

Here is my ionic test with an empty project:

ionic start test blank --type=angular --cordova --no-interactive
cd test
ionic cordova plugin add cordova-androidx-build --no-interactive --confirm
ionic cordova plugin add https://github.com/kolbasa/cordova-plugin-apkupdater#device-owner-reload --no-interactive --confirm
ionic cordova platform add android
ionic cordova run android -l

ionic info:

Ionic:

   Ionic CLI                     : 6.18.1 (@ionic/cli)
   Ionic Framework               : @ionic/angular 5.9.2
   @angular-devkit/build-angular : 12.1.4
   @angular-devkit/schematics    : 12.2.14
   @angular/cli                  : 12.1.4
   @ionic/angular-toolkit        : 4.0.0

Cordova:

   Cordova CLI       : 10.0.0
   Cordova Platforms : android 9.1.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 6 other plugins)

src/app/home/home.page.ts

import {Platform} from '@ionic/angular';
import {Component} from '@angular/core';

import ApkUpdater from 'cordova-plugin-apkupdater';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})

export class HomePage {

  remote = 'https://raw.githubusercontent.com/kolbasa/cordova-plugin-apkupdater-demo/master/update';

  constructor(public platform: Platform) {
    platform.ready().then(this.update.bind(this)).catch(console.error);
  }

  async update() {
    await ApkUpdater.download(
        this.remote + '/update.zip',
        {
          zipPassword: 'aDzEsCceP3BPO5jy',
          onDownloadProgress: progress => console.log(progress),
          onUnzipProgress: progress => console.log(progress)
        }
    );
    await ApkUpdater.install();
  }

}
kolbasa commented 2 years ago

The changes are now in the master branch. I'm going to close this one. If you have any questions, feel free to open it again.