use of android.app.admin.DevicePolicyManager in project platform_frameworks_base by android.
the class TrustAgentWrapper method updateDevicePolicyFeatures.
boolean updateDevicePolicyFeatures() {
boolean trustDisabled = false;
if (DEBUG)
Slog.v(TAG, "updateDevicePolicyFeatures(" + mName + ")");
try {
if (mTrustAgentService != null) {
DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
if ((dpm.getKeyguardDisabledFeatures(null, mUserId) & DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS) != 0) {
List<PersistableBundle> config = dpm.getTrustAgentConfiguration(null, mName, mUserId);
trustDisabled = true;
if (DEBUG)
Slog.v(TAG, "Detected trust agents disabled. Config = " + config);
if (config != null && config.size() > 0) {
if (DEBUG) {
Slog.v(TAG, "TrustAgent " + mName.flattenToShortString() + " disabled until it acknowledges " + config);
}
mSetTrustAgentFeaturesToken = new Binder();
mTrustAgentService.onConfigure(config, mSetTrustAgentFeaturesToken);
}
} else {
mTrustAgentService.onConfigure(Collections.EMPTY_LIST, null);
}
final long maxTimeToLock = dpm.getMaximumTimeToLockForUserAndProfiles(mUserId);
if (maxTimeToLock != mMaximumTimeToLock) {
// If the timeout changes, cancel the alarm and send a timeout event to have
// the agent re-evaluate trust.
mMaximumTimeToLock = maxTimeToLock;
if (mAlarmPendingIntent != null) {
mAlarmManager.cancel(mAlarmPendingIntent);
mAlarmPendingIntent = null;
mHandler.sendEmptyMessage(MSG_TRUST_TIMEOUT);
}
}
}
} catch (RemoteException e) {
onError(e);
}
if (mTrustDisabledByDpm != trustDisabled) {
mTrustDisabledByDpm = trustDisabled;
mTrustManagerService.updateTrust(mUserId, 0);
}
return trustDisabled;
}
use of android.app.admin.DevicePolicyManager in project platform_frameworks_base by android.
the class WallpaperManagerService method isSetWallpaperAllowed.
@Override
public boolean isSetWallpaperAllowed(String callingPackage) {
final PackageManager pm = mContext.getPackageManager();
String[] uidPackages = pm.getPackagesForUid(Binder.getCallingUid());
boolean uidMatchPackage = Arrays.asList(uidPackages).contains(callingPackage);
if (!uidMatchPackage) {
// callingPackage was faked.
return false;
}
final DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
if (dpm.isDeviceOwnerApp(callingPackage) || dpm.isProfileOwnerApp(callingPackage)) {
return true;
}
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
return !um.hasUserRestriction(UserManager.DISALLOW_SET_WALLPAPER);
}
use of android.app.admin.DevicePolicyManager in project platform_frameworks_base by android.
the class ContactsInternal method maybeStartManagedQuickContact.
/**
* If the URI in {@code intent} is of a corp contact, launch quick contact on the managed
* profile.
*
* @return the URI in {@code intent} is of a corp contact thus launched on the managed profile.
*/
private static boolean maybeStartManagedQuickContact(Context context, Intent originalIntent) {
final Uri uri = originalIntent.getData();
// Decompose into an ID and a lookup key.
final List<String> pathSegments = uri.getPathSegments();
final boolean isContactIdIgnored = pathSegments.size() < 4;
final long contactId = isContactIdIgnored ? //contact id will be ignored
ContactsContract.Contacts.ENTERPRISE_CONTACT_ID_BASE : ContentUris.parseId(uri);
final String lookupKey = pathSegments.get(2);
final String directoryIdStr = uri.getQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY);
final long directoryId = (directoryIdStr == null) ? ContactsContract.Directory.ENTERPRISE_DIRECTORY_ID_BASE : Long.parseLong(directoryIdStr);
// See if it has a corp lookupkey.
if (TextUtils.isEmpty(lookupKey) || !lookupKey.startsWith(ContactsContract.Contacts.ENTERPRISE_CONTACT_LOOKUP_PREFIX)) {
// It's not a corp lookup key.
return false;
}
if (!ContactsContract.Contacts.isEnterpriseContactId(contactId)) {
throw new IllegalArgumentException("Invalid enterprise contact id: " + contactId);
}
if (!ContactsContract.Directory.isEnterpriseDirectoryId(directoryId)) {
throw new IllegalArgumentException("Invalid enterprise directory id: " + directoryId);
}
// Launch Quick Contact on the managed profile, if the policy allows.
final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
final String actualLookupKey = lookupKey.substring(ContactsContract.Contacts.ENTERPRISE_CONTACT_LOOKUP_PREFIX.length());
final long actualContactId = (contactId - ContactsContract.Contacts.ENTERPRISE_CONTACT_ID_BASE);
final long actualDirectoryId = (directoryId - ContactsContract.Directory.ENTERPRISE_DIRECTORY_ID_BASE);
dpm.startManagedQuickContact(actualLookupKey, actualContactId, isContactIdIgnored, actualDirectoryId, originalIntent);
return true;
}
use of android.app.admin.DevicePolicyManager in project NotificationPeekPort by lzanita09.
the class MainActivity method sendTestNotification.
/**
* Lock device screen and send test notification.
*/
private void sendTestNotification() {
final DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
Handler handler = new Handler(getMainLooper());
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
final Notification.Builder builder = new Notification.Builder(this);
builder.setSmallIcon(R.drawable.ic_launcher).setTicker(getString(R.string.diagnosis_notification_title)).setContentTitle(getString(R.string.diagnosis_notification_title_content)).setContentText(getString(R.string.diagnosis_notification_content)).setLights(Color.GREEN, 1000, 5000).setAutoCancel(true).setContentIntent(pendingIntent);
handler.postDelayed(new Runnable() {
@Override
public void run() {
devicePolicyManager.lockNow();
}
}, LOCK_SCREEN_DELAY);
handler.postDelayed(new Runnable() {
@Override
public void run() {
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(TEST_ID, builder.build());
finish();
}
}, SEND_NOTIFICATION_DELAY);
}
use of android.app.admin.DevicePolicyManager in project NotificationPeekPort by lzanita09.
the class AccessChecker method isDeviceAdminEnabled.
public static boolean isDeviceAdminEnabled(Context context) {
ComponentName admin;
if (mAdminComponentName == null || mAdminComponentName.get() == null) {
admin = new ComponentName(context, LockscreenDeviceAdminReceiver.class);
mAdminComponentName = new WeakReference<ComponentName>(admin);
} else {
admin = mAdminComponentName.get();
}
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
return dpm.isAdminActive(admin);
}
Aggregations