Updating an application information using other applications (plugins) - java

I am doing a keyboard for Android.
I am willing to have a plugin structure to allow users to improve the prediction engine.
The prediction engine is done with Android NDK and it was coded in C. I have a wrapper class that calls the C code. An instance of this wrapper class is a field in the InputMethodService.
The prediction engine gets updated by sending complete sentences. Something like:
public void updateEngine(String sentence);
Plugins should be calling that method.
An example of the plugin can be a .txt parser. You select a txt file and the plugin will start sending to the main app all sentences.
I would like plugins to be customizable, e.g.: They might have an screen where you can choose max sentence to send, to run on background, etc.
The UI (don't know if it should be on the main app or the plugin, check my questions below) should have the possibility to ask the plugin how many sentence it can send (to do a progress bar).
My questions are:
Should I use Intents or IPC?
I think I should use Intents since I just use primitive types.
Should my operations be atomic or send an array of sentences?
I am willing to start with atomic operations but I am worried about performance.
The plugins must be activities or Services?
They should be Activities and if necessary ("process on background" on) launch a service. Or perhaps they are just services and the main app takes care of the UI.
Who should save information about the last execution. Plugin or the mainApp?
e.g. When was the last time the plugin was used.

Should I use Intents or IPC?
Either works. Intents may be simpler.
Should my operations be atomic or send
an array of sentences?
I'd bundle these up into a single operation if possible. Lots of little cross-process trips is more expensive than one large one, as I understand it.
The plugins must be activities or
Services?
You appear to want the plugin to call into the engine, which is fine, but...when? Plugins won't get control automatically at install time. The choice of trigger mechanism for the plugin calling into the engine will dictate whether the plugin needs an activity or not.
Who should save information about the
last execution. Plugin or the mainApp?
This doesn't make a lot of sense to me given the rest of what you have here, so I can't comment. This may roll back to the lack-of-trigger issue I mention above. For example, under what circumstances would a plugin ever be used more than once?

Related

Android: access internal storage from another app with same signature

Context: I have two apps, both signed with the same signature. The first app has data stored in internal storage that I would like to migrate to the second app.
Question: How can I access the data in the first app from the second app? The Android documentation makes reference to "signature permissions" (https://developer.android.com/guide/topics/permissions/overview#signature and https://developer.android.com/training/articles/security-tips#StoringData) and hints that it is possible to share data between apps with the same signature, but I cannot find clear guidelines about how to do this.
It seems like it might be possible by creating a content provider? Or is it possible to directly access the files, since I understand from the docs that they will be running with the same user / same process?
Ideally this process can happen with minimal intervention from the user, and can all happen from the second app (e.g. the second app can recognize that the first app is installed, prompt the user to migrate, and then read the data from the first app and move it to the second). It would be even better if it was possible to move the files (rather than copy) because we potentially have a lot of data and the user may not have enough disk space to copy the data.
It seems like it might be possible by creating a content provider?
Yes. You can create a signature-level permission and use that to protect access to any of the standard IPC options in Android, including ContentProvider and Service.
Or is it possible to directly access the files, since I understand from the docs that they will be running with the same user / same process?
No, two apps signed by the same signing key to not run as the same user, let alone in the same process. android:sharedUserId has the apps run as the same user. This was never a great idea, is deprecated, and is likely to go away soon.
It would be even better if it was possible to move the files (rather than copy) because we potentially have a lot of data and the user may not have enough disk space to copy the data.
That suggests that having two apps is a bug, not a feature, from the standpoint of the user. The closest you will be able to do to a "move" operation is "delete-after-copy", so plan your copies to be as granular as possible so you can delete as you go.

Accessing resources for Android UI Automator tests

I'm working on a set of tests using UI Automator on Android. I have it working, but my current tests are made with lots of string literals.
The string literals were fine when I was just trying to get things to work in the first place, but they will be bad going forward. If the app is changed, the string literals will need to be changed to match. Also, it's stupid that my tests would have to be completely redone to test localized builds in other languages.
The app itself has all strings stored in resources. Every string has an invariant identifier... here's an example:
<string name="more_options">More options</string>
The app code will always use the name more_options to look up the string resource, rather than hard-coding "More options" into the code.
So what I want is to import all the string resources, store them in some kind of map object, and then in my UI Automator test code use something like m.get("more_options") rather than a literal string "More options" as I do now.
Whatever I do, I want it to just be part of the JAR file that gets built and pushed to the device to run the tests. I don't want to, for example, push the XML string resource files to the device and try to read them at test runtime. I want to have the data built in when the JAR file is built.
I looked at the files produced by building the app, and the names like more_options are just set to integers. These must be indexes or pointers into a store of resources, but I'm not sure how I could copy that store into my UI Automator project and get it connected up; in an Android app you use a Context object to access resources, and a UI Automator JAR file doesn't have a Context.
This has to be a common problem, and people must have solved it already, but my Google searches haven't found any discussions of how people are solving this.
If I don't get any advice, I'm going to write a Python script that imports the XML file and writes a Java file that has a function that builds the map I need, then call that from my UI Automator test programs. (I have a Python script that runs the sequence of command-line tools to kick of a UI Automator test, anyway... I don't mind making that do more work.) But I figure there should be a pure-Java solution for this, probably one that involves grabbing the already-compiled files out of the application's source directory.
You can get context:
val context = InstrumentationRegistry.getTargetContext()
and then in your tests:
context.getString(R.string.more_options)
I usually target a UI element through a resource ID. Those are pretty static. Am I missing something?
I was stuck up with a similar problem.
I ended up creating a static hash map in Java for all the string literals.
So I had files for different languages with the same key and their localized values.
Then wrote a module to manipulate the device language at runtime and return the corresponding localized value for a key.

Overload an APK and create custom Applications

Is is possible to create a new APK by overloading/overriding and existing APK.
Say, we have WhatsApp messenger. Now if I want to show a notification like, "Person X is online now.", in notification area, it is not possible using the existing WhatsApp messenger. So, I'd like to develop a new custom messenger, which uses all the functionality of WhatsApp messenger, with some of my custom code. Just like importing JARs, can we import APK...??
This seems like using another persons work, but just from learning point of view, I'd like to know the possibilities. As of now, lets leave all the, security, vulnerability.
In a nutshell, no.
APKs are not like Jar files such that you can simply import them into your app. They also contain other resources like the XML and assets. The code is kept in a classes.dex file, which is generated from the Jar file of the app code.
Moreover, each app runs in its own DVM, and is sandboxed to prevent this kind of interaction between apps. You cannot simply use WhatsApp's code in your own app as a third party apps.
There are however two ways to achieve what you want.
If the app you are targeting provides an API by means of content providers, or even web services that you can use to access their data and events like users coming online. WhatsApp does not offer any such API
You decompile the target app, and insert your own code to do what you want. This can be very hard because most popular apps, like WhatsApp, obfuscate their code making it hard to decipher (but not impossible). Additionally, WhatsApp encrypts most of its data like messages, contacts, chat threads etc using AES, which adds an additional layer to bypass in some places. Oh, and it also violates several IP and copyright laws if you do this.
Yes and No.
There are a couple of ways for an app - a standalone one - to share its information with other apps. One is through the use of a content provider, the other through custom broadcasts.
If, say, WhatsApp has documented its app and was built such that you can build on it further, you can catch those broadcasts and listen to those providers such that your app can also react upon the changes made in WhatsApp.
you can create a config.properties file and insert it in Asset folder in your wattsup messenger assuming you have the source code,
Now you will have to configure your custom application to write that changes in this file, however you can change these data in several ways such as webservices that allows you to modify that data in that file through them .
ok with the above scenario, you can make the changes,but your application will never update that changes coz your dealing with an APK not a code,therefore you will have to re-generate the APK again so it will take the latest changes .
for an automated APK generating you can use ANT tools, by placing a build.xml file in your wattsp sources
code you can run that script which ant release that will generate the new APK with the latest code
as you said these are possibilities still but in my opinion in the end you cant use the APK as a library

Android App code design message handling for commands

I'm having two main code design problems in my app.
My app mainly consists in sending ssh commands to a remote host.
Right now I have a separated thread (singleton) which gets messages through the handler which specifies which is the next command to be sent, or the username/password/ip (kind of messy but works...).
This approach works good for unidirectional commands, but I'm planning to make it bidirectional which I don't know how to implement. As far as I know Android doesn't allow to change UI elements by another thread so a listener pattern wouldn't be it.
Also, I just read that we shouldn't save things in the application object, which is also what I'm doing by saving whether my app is running full or lite mode... I don't know where should I save it in order to not make it obviously hackable (sqlite-SharedPrefs are easily editable...)
Only a general hint: There is Activity.runOnUiThread() to execute code (later) on main thread.

How do I turn my Java program into an "app" that can send push notifications?

Disclaimer: I am not a professional developer; I'm just a hobbyist, and a relatively inexperienced one at that, so I apologize for what figure to be some very basic questions. (and yes, I've search the forums)
I've recently been working on a "deal finder" program which is written using a combination of Java and R. The basic steps that I've completed so far are:
Load data on various deals into Java using a particular eCommerce API
Write the data that I need to a series of text files
Load the data from the text files into R
Manipulate the data in R and assign a "score" to each deal
Sort by score to produce a ranked list of deals
Here's where I need help: I'm currently running the program manually by running my Java program in Eclipse and subsequently running the R script. This is obviously inconvenient (and also a bit addictive), so what I'd like to do instead is:
Run the program continuously or at some predefined interval (say every minute)
Send a notification to my iPhone or (if that's too difficult) my desktop whenever
there's a new deal whose score is above a certain threshold.
The problem: I have no idea where to begin with the two tasks above. My coding experience is limited to a bit of Java and math/stat languages like R and MATLAB. I have zero experience with web/mobile development, servers, etc., but I am willing to learn. What I'm hoping to get from this forum is not a completely specified solution, but instead just some general direction. If someone can give me a sense of how this should be done, how much work it would be, what language(s) I would need, etc., that would be immensely helpful.
Two more things I should probably mention: 1) This program is only for my personal use, so the resulting application, whether it be on my phone or desktop, can have very minimal functionality beyond the ability to send/receive notifications. 2) If it makes things easier, I think I can eliminate the dependency on R and write everything in Java.
Any help will be greatly, greatly appreciated.
Two more things I should probably mention: 1) This program is only for my personal use, so the resulting application, whether it be on my phone or desktop, can have very minimal functionality beyond the ability to send/receive notifications.
You may want to use a third-party notification app like Boxcar and its Provider API for this, then.
Depending on your operating system, there are programs that allow you to schedule tasks to run. Cron in Linux or Windows Task Scheduler for instance. You can easily find guides for these online.
Have you considered using email? Rather simple to do from java and wouldn't be platform specific.

Categories