Search in sources :

Example 16 with DevicePolicyManager

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;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) IBinder(android.os.IBinder) Binder(android.os.Binder) PersistableBundle(android.os.PersistableBundle) RemoteException(android.os.RemoteException)

Example 17 with DevicePolicyManager

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);
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) UserManager(android.os.UserManager)

Example 18 with DevicePolicyManager

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;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) Uri(android.net.Uri)

Example 19 with DevicePolicyManager

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);
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) NotificationManager(android.app.NotificationManager) Handler(android.os.Handler) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 20 with DevicePolicyManager

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);
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) LockscreenDeviceAdminReceiver(com.reindeercrafts.notificationpeek.LockscreenDeviceAdminReceiver) ComponentName(android.content.ComponentName)

Aggregations

DevicePolicyManager (android.app.admin.DevicePolicyManager)158 ComponentName (android.content.ComponentName)45 UserManager (android.os.UserManager)29 UserInfo (android.content.pm.UserInfo)25 RemoteException (android.os.RemoteException)24 LockPatternUtils (com.android.internal.widget.LockPatternUtils)19 Intent (android.content.Intent)18 PackageManager (android.content.pm.PackageManager)14 PersistableBundle (android.os.PersistableBundle)8 PendingIntent (android.app.PendingIntent)6 IBinder (android.os.IBinder)6 UserHandle (android.os.UserHandle)6 IPackageManager (android.content.pm.IPackageManager)5 Uri (android.net.Uri)5 VrManagerInternal (com.android.server.vr.VrManagerInternal)5 ResolveInfo (android.content.pm.ResolveInfo)4 Point (android.graphics.Point)4 Binder (android.os.Binder)4 KeyStore (android.security.KeyStore)4 ArraySet (android.util.ArraySet)4