Not able to apply Policy of Android Enterprise - android

I am creating an app with the use of Android Enterprise.
For that, I added dependencies in the build.gradle file.
implementation 'com.google.apis:google-api-services-androidmanagement:v1-rev84-1.25.0'
I am trying to disable uninstalling application using below code from here
try{
Policy policy = new Policy();
policy.setUninstallAppsDisabled(true);
} catch (Exception e) {
e.printStackTrace();
}
But above code is not working. No any Exception or Warning arise
What I am missing? Not able to found proper documentation that how to use Enterprise Management API.

Using the client library of the Android Management API from an Android app is not enough the manage the device the app is running on. You need to first set up the device as managed. For that you can follow the instructions in the quickstart guide.

Related

Get the version of a library in my Android app programmatically

I have a library in my Android app like UnityAds. I want to get the version name and the version code of it in runtime. I wrote the below code, but always exception occurred. What is the best practice to get this information programmatically?
implementation 'com.unity3d.ads:unity-ads:3.7.1'
try {
Log.d("Version", getPackageManager().getPackageInfo("com.unity3d.ads", 0).versionName);
} catch (PackageManager.NameNotFoundException e) {
Log.e("error", e.getMessage());
}
That won’t work, PackageManager APIs help you check for any valid packages/apps installed using a package name lookup.
Since the library is in the class path for your own package the only way to reference these ids at runtime would be to have a workflow to record these during compilation and expose it to your application at runtime.
Following approaches are viable:
Expose library metadata in build config/resources (https://developer.android.com/studio/build/gradle-tips#simplify-app-development)
Custom gradle plugin to capture all libraries in classpath into assets which can be read at runtime, something similar to https://github.com/google/play-services-plugins
With (1) you can’t scale it for multiple libraries conveniently so it’s only useful for very specific needs.
(2) might require some customisations for your usecase (adding version info) but is definitely scalable.

How to emulate outdated SSL Provider on Android?

I'm implementing 'Update security provider' feature for an Android application.
I implemented as it said in 'Patch asynchronously' and need to test/emulate all outcomes: user prompt demonstration and the error is unrecoverable.
I tried to delete Play Store updates, use previous com.google.gms:google-services version or android 6.0 — it always silently goes to onProviderInstalled(), never shows prompt or goes to onProviderInstallFailed().
I did exactly as said at https://developer.android.com/training/articles/security-gms-provider#example_async
Also in android\build.gradle:
buildscript {
...
dependencies {
...
classpath("com.google.gms:google-services:4.3.3")
}
}

App crashes on Launch when made as system application

I developed an application that uses DJI SDK. When installed as an system application it crashes on Launch because its not able to load the libraries. It works fine when installed as normal application.
Steps followed to make system application
1)Rooted the device
2)Copied the .apk file to system/app directory
3)Rebooted the device
4)App was installed as default application but crashed on Launch
After commenting out the following line related to DJI SDK and followed the same steps as above. It worked fine as system app.
Helper.install(context);
The implementation of Helper class which is in DJI SDK is as below:
public static void install(Application app) {
Object var1 = null;
try {
System.loadLibrary("DexHelper_sdk");
if (PPATH != null) {
System.load(PPATH);
}
} catch (Error var3) {
;
}
String app_dataDir = app.getApplicationInfo().dataDir;
DexInstall.install(app, new File(app_dataDir + "/.cache_sdk/sdkclasses.jar"));
}
As far as my understanding the crash is because the system is failing to load the libraries.
My gradle looks similar as in the following link:
https://github.com/dji-sdk/Mobile-SDK-Android/blob/master/Sample%20Code/app/build.gradle
this issue has been fixed since 4.6 version of Android MSDK, pls try to update to the later version, right now the 4.7.1 has been released.

How to obtain code coverage from manual testing on android application (Android studio and gradle)

Currently, I'm researching about GUI automated testing on Android and for some reason, I need a tool that can generate code coverage report from manual testing.
After a long searching, I found that Jacoco and Emma mention the manual approach on their website.
But unfortunately, There is not any up-to-date-working example on the internet.
I have tried a lot of suggesting solution, for example, https://groups.google.com/forum/#!searchin/jacoco/manual$20android%7Csort:date/jacoco/vx0g_6TKY8Q/0Tg3fX84CAAJ .
It generated a coverage.exec but the file's size was only few byte (of course, Jacoco failed to generate any report from it.)
Here is what I have tried: https://github.com/kindraywind/MyDummy
In app/build.gradle
apply plugin: 'jacoco'
jacoco {
toolVersion ="0.7.8+" //I did try "0.7.4+" as the suggest.
}
task jacocoTestReport(type: JacocoReport) { … }
In jacoco-agent.properties
destfile=/storage/sdcard/coverage.exec
In app/src/main/AndroidManifest.xml`
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
In MainActivity.java
protected void onStop()
{
super.onStop();
if(BuildConfig.DEBUG)
{
String TAG = "jacoco";
try {
String covPath = Environment.getExternalStorageDirectory().getPath() + "/coverage.exec";
File coverageFile = new File(covPath);
Class<?> emmaRTClass = Class.forName("com.vladium.emma.rt.RT");
Method dumpCoverageMethod = emmaRTClass.getMethod("dumpCoverageData",coverageFile.getClass(), boolean.class, boolean.class);
dumpCoverageMethod.invoke(null, coverageFile, true, false);
} catch (Exception e) {
}
}
}
The emulator is Nexus 5 API 19 (I did try most of the versions.)
The log from device
EMMA: runtime coverage data merged into [/storage/sdcard/coverage.exec] {in 8 ms}
The log after run ./gradlew jacocoTestReport
Unable to read execution data file /Users/MyDummy/app/coverage.exec
I'm using OSX10.12.3 if it related.
To sum up, I need to know (or any working example) how to obtain code coverage while:
Test the app manually.
On Android application.
Which is using Gradle not Maven or Ant.
Android Studio not Eclipse.
I see no way out and would really appreciate a help.
I've provided a detailed how-to guide on how to obtain code coverage during manual testing at my blog. Following it you should obtain a code coverage report. You seem to be headed in the right direction, but please read the post thoroughly.
A bit more advanced and complete solution is described in another blog post. It uses NanoHttpd to create a REST server on the device/emulator. The API provides a single endpoint that writes the report file as a response. Additionally, a custom (much faster) CSV report writer is provided.
Feel free to contact me if you want to discuss GUI automated testing (related to Android) further :)

Google play services out of date. Requires 5089000 but found 3136130

I'm trying to use Google cloud messaging for an android app (Target name: Google APIs, platform: 4.3, API level: 18. I implemented my GCM client by following the isntructions here: http://developer.android.com/google/gcm/client.html, and setup play services by following the steps here:
http://developer.android.com/google/play-services/setup.html#Setup, but still get the above error Most of the solutions I've found on stack overflow redirect to the above two links, or suggest that we change the dependencies {} in the gradle settings, but I'm using eclipse and don't have gradle setup.
Update: Sorry yes I'm using the emulator and not a device
Any ideas?Thanks!
If you need to provide an option for the user to update the google services you can do this:
switch (isGooglePlayServicesAvailable(this)) {
case 2: //out date
try {
GooglePlayServicesUtil.getErrorDialog(2, this, 0).show();
} catch (Exception e) {
e.printStackTrace();
}
break;
}
This will prompt an update dialog for the user to update play services
The final solution was creating a new emulator under Android 4.4.2, with the build target of the project set to Google APIs (x86 System Image). Thanks to Pedro Oliveira!

Categories

Resources