Restrict Test Users by Authentication Information
Basically, it may be impossible to protect your app by only restricting access at the distribution-time because anyone can extract apks from a device without root permission.
However, sometimes you may want to restrict users who can test your app. DeployGate SDK can actualize it by providing authority through DeployGate client app.
How to know user and device attributes
We provide several methods to know if a user has permission to access your app.
DeployGate.isDeployGateAvailable(); // return true if DeployGate client app is available
DeployGate.isAuthorized(); // return true if a user/device is allowed to access your app
DeployGate.getLoginUsername(); // a username of a user
DeployGate.getAuthorUsername(); // a username of an app owner
DeployGate.deployGateAvailable // return true if DeployGate client app is available
DeployGate.authorized // return true if a user/device is allowed to access your app
DeployGate.loginUsername // a username of a user
DeployGate.authorUsername // a username of an app owner
Example
@Override
public void onCreate(@Nullable Bundle savedInstance) {
super.onCreate(savedInstance);
DeployGate.registerCallback(new DeployGateCallback() {
@Override
public void onInitialized(boolean isServiceAvailable) {
if (!isServiceAvailable) {
Toast.makeText(this, "DeployGate client app is not found or is not available", Toast.LENGTH_SHORT).show();
finish();
}
}
@Override
public void onStatusChanged(boolean isManaged, boolean isAuthorized, String loginUsername, boolean isStopped) {
if (!isAuthorized) {
Toast.makeText(this, "This device is not authorized to use this app", Toast.LENGTH_SHORT).show();
finish();
}
}
@Override
public void onUpdateAvailable(int revision, String versionName, int versionCode) {}
}, true);
...
}
override fun onCreate(savedInstance: Bundle?) {
super.onCreate(savedInstance)
DeployGate.registerCallback(object: DeployGateCallback() {
override fun onInitialized(isServiceAvailable: Boolean) {
if (!isServiceAvailable) {
Toast.makeText(this, "DeployGate is not available", Toast.LENGTH_SHORT).show()
finish()
}
}
override fun onStatusChanged(isManaged: Boolean, isAuthorized: Boolean, loginUsername: String?, isStopped: Boolean) {
if (!isAuthorized) {
Toast.makeText(this, "This device is not authorized to use this app", Toast.LENGTH_SHORT).show()
finish()
}
}
override fun onUpdateAvailable(revision: Int, versionName: String, versionCode: int) {}
}, true)
...
}
For example, the code above makes your activity finish if DeployGate client app is unavailable or a user is not authorized to use your app.