Can an Android app upgrade itself? - android

Is it possible to update application from itself in Android? The app in question is a system app, so I can execute privileged commands. Also note that I don't want to show any notification to user, so everything should work in the background.

It is actually pretty easy for an app to update itself, the hard part is doing it without putting up a prompt to the user. The app needs to download the APK, then send it to the PackageManager API to install it. Android will then put up the install prompt. There is a library to handle that part:
https://gitlab.com/fdroid/update-channels
As for doing it with prompting, the app needs privileged access. If the device is rooted, the app can request root access. The app can also be flashed as a "priv-app" so that it has privileged access. Or you can do it like F-Droid: flash the Privileged Extension as a "priv-app", and make your app send install/uninstall requests to Privileged Extension.
Otherwise, you need to download binary code, and dynamically load it, like #yusuf-x said. Be aware that Google is working to make that impossible in each new release of Android.

Use the Java ClassLoader to dynamically load code that was push or pulled down. – Yusuf X just now edit. I've used this for just such a purpose on Android.

Fdroid is an open source application repository.
Their client app can install/update/delete apps from the fdroid repository, including itself.
See the code for the installer part of the client app here:
https://gitlab.com/fdroid/fdroidclient/tree/master/app/src/main/java/org/fdroid/fdroid/installer

Related

Is it possible for Nodejs to read the system logs of a connected device via a web application?

I am looking for a way to read the system logs of a connected device via a web application. Basically, I want the user to be able to connect their iphone, android, tablet etc and be able to see what is occurring on their device at the system/consoleLog level. Similar to adb logcat. This would be a via a web application and not on software installed locally. Is this feasible using react/nodejs? What technologies should I consider using?
There're several components you need for achieving this.
Backend
File Monitoring (Native Node.js fs.watch)
Real-time update (Socket.io)
Frontend
Any framework you're comfortable with, I'm using React.js with socket.io client
What you are trying to do is possible, but in a very limited sense.
Your users will be required to manually upload their log files to your web application.
You can "ask" them to do this by using the FileReader api in javascript. Here is a demo page.
As you can see you must manually select a file to be uploaded and give the website. To programmatically set the path of a log file and try to call it without the user noticing is not possible.
The reason for this is anything you make that is served via a web application will run in the sandbox of the users browser.
For obvious security reasons a browser won't let random websites read/write to local files of a persons phone without explicit permission.
Node.js won't help you here because in order to use the functions Node.js has such as accessing local system files the app would have to be installed locally and not running in a "browsers sandbox".
I hope this helps. If you want more examples of the filereader api let me know and I can write something up for you.

Caching server for Android or some thing similar

Our Android app will be used in a place without internet. We have one server with limited internet there.
Can user download the app from the server instead of google play, the way we can use ios cache server?
If we keep a copy of app in the server and install from it, how can we update the app with latest version?
Thanks.
You can host the apk file on the server and download it to the devices for installation. However, you first need to enable third party source installation for the devices.
Link how to here,
https://www.cnet.com/how-to/how-to-enable-third-party-app-installation-on-most-android-phones/
In terms of the update, you can always update the apk file anytime but you might need a separate system to notify the users/devices about the update. Probably by using SMS.

Android APK: change backend URL

So, I have this old app, and problem is that app is accessing old backend URL, which no longer exists.
How do I change this url without recompiling app? Is there any app which can redirect traffic of other apps to specific URL?
On Windows, Fiddler can do that.
My phone is not rooted so using hosts file to remap domain is not an option.
What you are asking for is man in the middle application.
On google play there are a plenty of them, and some of them know how to modify request.
For example here: is mentioned that this application can modify request.

Update android application using OTA

I am having my own apps store where all android applications are hosted. Some apps are modified. So How i can send updates to clients/users using OTA. So clients will come to know about new updates and he will be able to download it.
Found an interesting solution on HN a month back. This is related directly update the app on the client without any user interaction. And since you have your own app store, shouldn't face any problems as listed in the HN thread.
The solution working snippets from the website-
...intercepts all calls to startActivityForResult, getResources, and some other functions. When you try to start an activity, Evolve generates a dummy class and sets its superclass to the activity you want to start.
...dynamically generates the bytecode for a new class
...then changes the intent to start the appropriate class
This is still in alpha mode, so would require some effort from your side to integrate.
Link to solution - http://blog.vivekpanyam.com/evolve-seamlessly-deploy-android-apps-to-users
Assuming this is what you are expecting, hope this helps!
1.Create a Web Service which your app can poll whenever the app launches or based on some time limit that can check if there is new version out there.
2.This Web service should return the lastest Version of the apk file that is hosted on the Server along with the URI of the application file that has the new version.
3.When your app gets the response from the Web Service, it will parse the JSON and check your app version to the lastest version that is available on the server.
4 If your app version is lower than the latest version it will prompt the user to start the download process.
5.The download of the new app is handled by the Download Manager.
The download manager will notify your app using Broadcast receiver when the download is complete.
6.Upon completion of the latest version of the application file the you can start the activity to install that file.
At this point user needs to say OKAY, lets do it.
Check this https://code.google.com/p/auto-update-apk-client/
If you have your own app store, then you must have a client app running on the relevant devices that allows them to install/update apps from that app store.
As part of that client, you can have a service, that enumerates the installed apps on the device and checks with your store whether updates are available. If yes, then it presents the user with a prompt to visit the store to update the corresponding apps - or do whatever else is appropriate in the situation.
You may also want to register this service to receive broadcasts of network connection events so that if there is no internet connection, the service will receive a notification when the connection is available again.

How Android ensures security?

I am just starting on Android development. To my nascent knowledge, it seems that anybody can grab any personal info and modify it or phone it home. Like with ContactContentProvider. I know these(permissions) have to be specifically declared in application manifest and the user would be presented with this info during installation. But still how would you you know the application handling your private data is not going to go rouge on it?
Example:
Suppose I create an app with internet
and contact-reading permissions. It
claims that it will backup contacts on
a server specified by user. While
secretly it also copies them to your
own server.
It's no different than you developing an app that does it that runs on a PC, or something that uses your gmail login to see if there's others you know on the same site.
It's all about trust. Also the Apple approval process doesn't safeguard against any of this if you hide it and when found out malicious apps can be killed & uninstalled instantly.

Categories

Resources