There could be situation when there are severall appstore supporting in-app billing installed on a device.
We need to imeplement good logic to choose which appstore to use in OpenIAB library.
First, we add a requirements for developers who use OpenIAB that they must have the latest version uploaded to all appstores they support using OpenIAB library. Otherwise it is app responsibility to handle situation when newer version will start communicate with an appstore where new version is not uploaded yet and some new in-app purchase items could be missed.
Then we change Appstore object logic. It answers questions "did you install this app?" not just "yes"/"no" but "yes, 100% sure" / "may be" / "sure not".
So each Appstore has the following methods
- isInstaller: checks if the appstore is sure that it is an installer, if the appstore is not 100% sure (may be) it returns false
- couldBeInstaller: checks if this appstore could be an installer of this app, this method returns false if isInstaller is true
- isServiceSupported: checks if this appstore could provide IAB functionality for this app, regardless did it install it or not, this method should not use network but use only local data
Logic to detect which appstore to work with:
There are two settings that developer can set:
1. Developer can set in settings list of appstore priorities. By default this setting is null and the list of all appstores is shuffled.
2. Developer can set the list of appstores where his/her app is uploaded for sure
Then we enumerate the appstore list several times:
1. Check if IAB for this app was already used, if so continue working with this appstore if it is still installed
-otherwise-
2. Check if any of the appstores isInstaller return true. If there are several of them use random one.
-if all are false-
3. Check if any of the appstores couldBeInstaller return true. If there are several of them use random one.
-if all are false-
4. Check if any of the appstores isServiceSupported return true. If there are several of them use random one.
-if all are false-
5. return null
Here is how the appstores should implement the three methods:
Google Play
- isInstaller: if Android version >= 3.0 we return what packageManager.getInstallerPackageName says, else return false
- couldBeInstaller: if Android version < 3.0 then and Google Play is installed and Google account entered if so return true, else return false
- isServiceSupported: return (Google Play is installed) and (Google account entered)
Amazon AppStore
- isInstaller: Amazon Appstore has API that allows to check if an app was installed by Amazon Appstore or not, this method uses this API
- couldBeInstaller: returns false //we always know for sure if we installed the app
- isServiceSupported: returns if Amazon Appstore is installed
Samsung Apps
- isInstaller: return false
- couldBeInstaller: return (isSamsungApps installed) && (Samsung Account in Samsung Apps is entered//if we can check it)
- isServiceSupported: return (isSamsungApps installed) && (Samsung Account in Samsung Apps is entered//if we can check it)
SK T-Telecom
- isInstaller: return false
- couldBeInstaller: return isSKTStore installed
- isServiceSupported: return isSKTStore installed
OpenStore
- isInstaller: check local appstore settings where the list of all installed apps is stored, returns true if there is a record about installing this app
- couldBeInstaller: return false; //we always know for sure if we installed the app
- isServiceSupported: is appstore name in the list of supported by default appstores then true, if appstores has information on client-side that it supports the app, then true, otherwise false