Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aldrigo opened this issue Dec 2, 2021 · 38 comments

Comments

@aldrigo
Copy link

aldrigo commented Dec 2, 2021

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
Copy link
Owner

kolbasa commented Dec 2, 2021

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
Copy link
Author

aldrigo commented Dec 3, 2021

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

@kolbasa
Copy link
Owner

kolbasa commented Dec 3, 2021

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
Copy link
Author

aldrigo commented Dec 3, 2021

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

@kolbasa
Copy link
Owner

kolbasa commented Dec 3, 2021

The easiest way is via ADB.

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

  • The official way is via Google. However, I can't tell you how much effort it takes to whitelist your app.
  • You sign the app with platform keys. You can get these from the device manufacturer.

@aldrigo
Copy link
Author

aldrigo commented Dec 3, 2021

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
Copy link
Author

aldrigo commented Dec 3, 2021

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
Copy link
Author

aldrigo commented Dec 3, 2021

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
Copy link
Owner

kolbasa commented Dec 3, 2021

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
Copy link
Owner

kolbasa commented Dec 3, 2021

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

@aldrigo
Copy link
Author

aldrigo commented Dec 3, 2021

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

@kolbasa
Copy link
Owner

kolbasa commented Dec 3, 2021

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 added a commit that referenced this issue Dec 4, 2021
@kolbasa
Copy link
Owner

kolbasa commented Dec 4, 2021

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
Copy link
Author

aldrigo commented Dec 6, 2021

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
Copy link
Owner

kolbasa commented Dec 6, 2021

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

@aldrigo
Copy link
Author

aldrigo commented Dec 6, 2021

positive
cordova-plugin-apkupdater 3.0.1 "Apk Updater"

@kolbasa
Copy link
Owner

kolbasa commented Dec 6, 2021

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
Copy link
Author

aldrigo commented Dec 6, 2021

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
Copy link
Owner

kolbasa commented Dec 6, 2021

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

@aldrigo
Copy link
Author

aldrigo commented Dec 6, 2021

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
Copy link
Owner

kolbasa commented Dec 6, 2021

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
Copy link
Owner

kolbasa commented Dec 6, 2021

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
Copy link
Author

aldrigo commented Dec 6, 2021

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 kolbasa closed this as completed Dec 6, 2021
@kolbasa kolbasa reopened this Dec 6, 2021
@kolbasa
Copy link
Owner

kolbasa commented Dec 6, 2021

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"
}
  • You have to replace the app ID de.kolbasa.apkupdater.demo with yours under [...]_ADMIN_COMPONENT_NAME.
  • You need a public URL to your apk under [...]_PACKAGE_DOWNLOAD_LOCATION
  • Then you need to generate the signature checksum like so for [...]_SIGNATURE_CHECKSUM:
keytool -printcert -jarfile Demo.apk | grep "SHA1" | awk '{print $2}' | xxd -r -p | openssl base64 | tr -d '=' | tr -- '+/=' '-_'

(This is the bash command. On Windows it will look a little different.)

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 need a clean device. That means you need to reset it.
  • On the welcome screen, you must now tap the "Hello"-text 6 times.
  • You will be prompted to connect the device to the Internet. Do it. (Wifi access data can also be stored in the QR code.)
  • Now it's time to scan the QR code. If everything goes well, the app is now automatically downloaded and activated as a device owner.

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
Copy link
Author

aldrigo commented Dec 6, 2021

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
Copy link
Owner

kolbasa commented Dec 6, 2021

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

@aldrigo
Copy link
Author

aldrigo commented Dec 7, 2021

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

@aldrigo
Copy link
Author

aldrigo commented Dec 7, 2021

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

@kolbasa
Copy link
Owner

kolbasa commented Dec 7, 2021

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

@aldrigo
Copy link
Author

aldrigo commented Dec 7, 2021

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

@kolbasa
Copy link
Owner

kolbasa commented Dec 7, 2021

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
Copy link
Author

aldrigo commented Dec 7, 2021

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
Copy link
Owner

kolbasa commented Dec 7, 2021

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
Copy link
Author

aldrigo commented Dec 7, 2021

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

@kolbasa
Copy link
Owner

kolbasa commented Dec 7, 2021

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
Copy link
Author

aldrigo commented Dec 9, 2021

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
Copy link
Owner

kolbasa commented Dec 9, 2021

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
Copy link
Owner

kolbasa commented Dec 10, 2021

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.

@kolbasa kolbasa closed this as completed Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants