Android Management API doesn't apply policies - android

I've been following the Android Management API guide quickstart:
https://colab.research.google.com/github/google/android-management-api-samples/blob/master/notebooks/quickstart.ipynb
I have created a dummy project, enterprise, and service account.
I can generate a qrcode with the following python script:
from apiclient.discovery import build
import google.auth
import os
from urllib.parse import urlencode
import webbrowser
# set key as environment variable, so that google.auth.default() can automatically find the project
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "./celtic-bazaar-342809-6536138e074c.json"
credentials, project = google.auth.default()
# Create the API client.
androidmanagement = build('androidmanagement', 'v1')
print('\nAuthentication succeeded.')
enterprise_name = 'enterprises/LC0498xe68'
policy_name = enterprise_name + '/policies/policy2'
# define policy
policy_json = {
'debuggingFeaturesAllowed': True,
'locationMode': 'LOCATION_DISABLED'
}
result = androidmanagement.enterprises().policies().patch(
name=policy_name,
body=policy_json
).execute()
enrollment_token = androidmanagement.enterprises().enrollmentTokens().create(
parent=enterprise_name,
body={"policyName": policy_name}
).execute()
image = {
'cht': 'qr',
'chs': '500x500',
'chl': enrollment_token['qrCode']
}
qrcode_url = 'https://chart.googleapis.com/chart?' + urlencode(image)
webbrowser.open(qrcode_url, new=0)
print('\nIf the code is not displayed automatically, visit this URL to scan the QR code:', qrcode_url)
However when i scan the code with my device, I get the following error:
"Oops Couldn't set up your device. Contact your IT department."
If I just set the policy_json to {'debuggingFeaturesAllowed': True} I don't get the error, but adding any other options (adjustVolumeDisabled, uninstallAppsDisabled, etc.) results in the error and the options aren't applied.
If I go to the device's settings -> security -> Device administrators, I can see that 'Device Policy' is there and cannot be deactivated but none of the options are applied.
The device I am testing this on is an Asus ZenPad Z380M running Android 7.0
What is causing this error?

Are you provisioning a work profile or fully managed device (company owned device after factory-reset ) ?
https://developers.google.com/android/management/reference/rest/v1/enterprises.policies#locationmode
location mode works only on company owned devices.
but this policy as work profile should install.

Turns out the device wasn't being enrolled at all using this method even when there was no error. I checked this with the REST api:
https://developers.google.com/android/management/reference/rest/v1/enterprises.devices/list
The way I got around it was to follow the guide for enrolling an Android 6.0 device:
Turn on a new or factory-reset device.
Follow the setup wizard and enter your Wi-Fi details.
When prompted to sign in, enter afw#setup.
Tap Next, and then accept the installation of Android Device Policy.
Scan the QR code.
Strange since the device definitely was running Android 7.0 but it's an old device so it may be because of that.

Related

Unable to set device owner through programmatically

I tried to execute the following code to set my app as a device owner. I can't use ADB because I have more than 10K android-9 non rooted devices. So, Need to do this programmatically.
String name = AdminReceiver.class.getName();
if (name.startsWith(BuildConfig.APPLICATION_ID)) {
name = name.substring(BuildConfig.APPLICATION_ID.length());
}
final String command = "dpm set-device-owner " + BuildConfig.APPLICATION_ID + '/' + name;
Process process = Runtime.getRuntime().exec(command);
Log.d(TAG,"RETURN VALUE:"process.waitFor();
process.waitFor() always return 1.
Need to do this programmatically
Fortunately, that is not possible, for blindingly obvious security reasons.
Use QR Enrollment instead!
You can generate a QR Code which contains a URL for your Device Owner package. Then you can scan this code in the factory setup process of the device.
See the documentation here
The Data in the QR Code would look something like this:
{
"android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME": "com.google.android.apps.work.clouddpc/.receivers.CloudDeviceAdminReceiver",
"android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM": "I5YvS0O5hXY46mb01BlRjq4oJJGs2kuUcHvVkAPEXlg",
"android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION": "https://play.google.com/managed/downloadManagingApp?identifier=setup"
}
Simply replace the information with your own device owner package information. After scanning, the device will download, install, and set up the device owner.
If you become an EMM Partner with Google, you can even do Zero-Touch-Enrollment by getting preconfigured android devices from the manufacturers. But Google stopped approving requests for custom device policy managers and you must use the Android Management API now.
Footnotes
Instructions on how to scan the QR Code
Device Admin Developer reference for streamlining this into the device admin app

Unique Identifier for Mobile Devices using Cordova and AngularJS

please don't make my post like as duplicate why because am totally confused with those post when i google it.
but i need your valuable statements and real time experience on How to get UNIQUE IDENTIFIER for iOS,Android and Windows Mobiles
i have a scenario that when user login with UserName and Password i send details to server at same time i need to send Device UUID. By using device UUID and User Credentials am going to Restrict second user login when first user is already logged in(Active). but am confused with getting iOS Device UUID but wheen i seen in many post iOS is killing apps in App store when app is Accessing any UUID values.
please suggest me better way to complete mytask.
Link-1
Link-2
sorry for my bad english....!!!
You can use the Unique Device ID plugin.
Install it:
cordova plugin add cordova-plugin-uniquedeviceid
And use it:
window.plugins.uniqueDeviceID.get(function(uuid){
console.log("Unique ID": +uuid);
}, function(error){
console.error(error);
});
This will give you a unique ID per device that persists between installs.
Note that on Android 6 it requires telephony run-time permission to access SIM ID. Also you may need to fork it and update it to get the Windows Phone 8 code working on Windows 10 Mobile.
in the case of angular
you gotta install ngx-device-detector via npm then import it on your module and in the import section add DeviceDetectorModule.forRoot().then in the component you're gonna use import it and add private deviceService: DeviceDetectorService this in the constructor it will generate u a method and add it on the constructor this.epicFunction(), if it doesnt paste this
epicFunction() {
console.log('hello `Home` component');
this.deviceId = this.deviceService.getDeviceInfo();
const isMobile = this.deviceService.isMobile();
const isTablet = this.deviceService.isTablet();
const isDesktopDevice = this.deviceService.isDesktop();
console.log(this.deviceId);
console.log(isMobile); // returns if the device is a mobile device (android / iPhone / windows-phone etc)
console.log(isTablet); // returns if the device us a tablet (iPad etc)
console.log(isDesktopDevice); // returns if the app is running on a Desktop browser.
}
note: the "this.deviceId" is a variable i created in the start of the class
in the case of android just import the security and add the permission on the manifest file

NotificationsRegistrationHandler is not being called on iOS

I have an app working and published in the Apple's app store. We are developing an update with new features and I noticed that the NotificationsRegistrationHandler is not being called anymore on iOS when the user accepts to receive notification (in Android is working fine). Which means the application is not getting the "DeviceToken", so we are unable to send notification. The proc. is very simple, and doesn't look like the issue because it's working for Android devices:
for each
where DeviceType = &DeviceType // enum domain SmartDeviceType
where DeviceId = &DeviceId // Character(128)
DeviceToken = &DeviceToken // Character(255)
DeviceName = &DeviceName // Character(128)
when none
new
DeviceType = &DeviceType
DeviceId = &DeviceId
DeviceToken = &DeviceToken
DeviceName = &DeviceName
endnew
endfor
What I have tried so far:
Generate and install new distribuition certificates and provision profiles.
Rebuild All, Build With This Only, etc.
Tested in "TestFlight" also.
Tested in different devices.
The published app right now is working, however I fear to publish this upgrade and screw up the notification.
I'm using GeneXus Evo 3 U2, .NET generator and Oracle.
Any suggestion how to fix this?
EDIT: Tested with distribuition certificate and sandbox=false, builded for distribuition and sended to testflight, same problem. =/
Have you checked that in the Provisioning Profile (developer.apple.com) the Push Notification service is active:
Enabled Services:
Game Center, In-App Purchase, Push Notifications
I fixed, here is what I did:
Updated from "U2" to "U8". Since "U8" have some OSX and XCode version requirements I updated both to the lastest versions.
Now "NotificationRegistrationHadler" is being called as normal.

Worklight app results in PERSISTENT_STORE_FAILURE with JSONStore on my phone

I just tried a small sample worklight app on my phone to test the JSONStore, the init code for which is as follows in my file jsontest.js.
function wlCommonInit(){
var i;
var collectionName = 'exp';
var options = {};
var collections = {};
//Object that defines the 'people' collection
collections[collectionName] = {};
//Object that defines the Search Fields for the 'people' collection
WL.JSONStore.destroy(options);
collections[collectionName].searchFields = {name: 'string', age: 'integer'};
WL.JSONStore.init(collections, options)
.then(function () {
alert ("JSON Store initialization success!");
})
.fail(function (errorObject) {
alert (errorObject);
});
I'm getting the error -1: PERSISTENT STORE FAILURE when I run the app on my phone (Galaxy Nexus). The following errorObject is returned.
{
"src": "initCollection",
"err": -1,
"msg": "PERSISTENT_STORE_FAILURE",
"col": "exp"
"usr": "jsonstore",
"doc": {},
"res": {}
}
The app works fine in the Worklight console simulator and in the AVD. My phone has enough storage (600 MB left) to run the app so that shouldn't be a problem.
What am I doing wrong here? Does this have anything to do with the fact that I'm running a custom ROM?
UPDATE: I checked the app on my dad's phone (Sony Xperia Sola) and it worked! Very weird. It doesn't run on my phone, even though all other third-party apps that I have downloaded so far on my phone from the Play Store and other sources all work fine.
So, does Worklight not support custom ROMs?
The custom ROM that I am using is VanirAOSP. I applied a popular custom kernel and I'm using the Dalvik runtime (not ART or anything like that).
I also think that the problem might be because Worklight apps are not fully supported on Android 4.4 KitKat.
Would appreciate it if someone would shed some light on this.
There is an issue that affects the JSONstore when using Worklight 6.0 on Android 4.4, which causes the behavior your are seeing. You can get more information about this here:
http://www-01.ibm.com/support/docview.wss?uid=swg27040512
If you are using Worklight Consumer Edition or Worklight Enterprise Edition, you can get a fix for this issue by upgrading to Worklight 6.0.0.2 (a/k/a Worklight 6.0 Fix Pack 2).
If you are using Worklight Developer Edition, you should be able to use the Eclipse "Check for Updates" function to upgrade your Worklight 6.0 Developer Edition installation to Fix Pack 2.
Note that after applying the fix, you must remove the JSONstore feature from your application, and then add it back again; this is described in the APAR document that you can access from the page I've linked above.

Calendar in Android 4 emuator

For development I would like to use the calendar in an Android 4 emulator but the option "Calendars to display" is empty and I am not able to add an account with calendar.
I found several solutions but none of them worked:
m.google.com
Like adding account with m.google.com as server but it keeps telling me "You don't have permission to sync this server. Contact your server's administrator for more information." because it is disabled for new devices.
CalDAV
In the link above they are talking about using CalDAV but how without appstore? I installed the caldav4j apk to use CalDAV but it does not run. logcat tells me java.lang.NoClassDefFoundError: android.provider.Calendar$Events.
Add Google Account
If I add an normal Google account I can only select mail for sync, calendar is missing.
Android x86
Maybe I could avoid this problem by using Android x86 like suggested here as performance booster.
Got it working using AndroVM.
Download VirtualBox and an AndroVM image with gapps. Like androVM_vbox86p_4.1.1_r6.1-20130222-gapps-houdini-flash.ova. vbox86p is for phone and vbox86tp for a table with phone functions.
Follow the configuration tutorial: Import Virtual Machine, activate network
Start the VM and enter your gmail account during setup.
For debugging with eclipse: run AndroVM Config app (on mobile desktop) to get the IP and on the host: adb connect [IP]
Hareware keys: ESC = back, F1 = menu, Pos1 = home/unlock, End = lock
Btw: AndroVM is a speed rocked compared to the normal emulator.

Categories

Resources