Example usage for android.content Context DEVICE_POLICY_SERVICE

List of usage examples for android.content Context DEVICE_POLICY_SERVICE

Introduction

In this page you can find the example usage for android.content Context DEVICE_POLICY_SERVICE.

Prototype

String DEVICE_POLICY_SERVICE

To view the source code for android.content Context DEVICE_POLICY_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.admin.DevicePolicyManager for working with global device policy management.

Usage

From source file:org.wso2.iot.agent.activities.AuthenticationActivity.java

/**
 * Start device admin activation request.
 *
 *//*  w w  w.j a v a2  s.  c  om*/
private void startDeviceAdminPrompt() {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP
            && devicePolicyManager.isProfileOwnerApp(getPackageName())) {
        checkManifestPermissions();
        CommonUtils.callSystemApp(context, null, null, null);
        Log.i("onActivityResult", "Administration enabled!");
    } else {
        DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(
                Context.DEVICE_POLICY_SERVICE);
        ComponentName cdmDeviceAdmin = new ComponentName(AuthenticationActivity.this,
                AgentDeviceAdminReceiver.class);
        if (!devicePolicyManager.isAdminActive(cdmDeviceAdmin)) {
            Intent deviceAdminIntent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
            deviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, cdmDeviceAdmin);
            deviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                    getResources().getString(R.string.device_admin_enable_alert));
            startActivityForResult(deviceAdminIntent, ACTIVATION_REQUEST);
        }
    }
}

From source file:com.android.managedprovisioning.ProfileOwnerProvisioningService.java

private void setMdmAsManagedProfileOwner() throws ProvisioningException {
    ProvisionLogger.logd("Setting package " + mParams.deviceAdminComponentName + " as managed profile owner.");

    DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (!dpm.setProfileOwner(mParams.deviceAdminComponentName,
            mParams.deviceAdminComponentName.getPackageName(), mManagedProfileOrUserInfo.id)) {
        ProvisionLogger.logw("Could not set profile owner.");
        throw raiseError("Could not set profile owner.");
    }//from   w  ww.  j  a  v a 2  s.  c o m
}

From source file:org.durka.hallmonitor.CoreStateManager.java

public void stopServices(boolean override_keep_admin) {

    Log.d(LOG_TAG, "Stop all services called.");

    if (getServiceRunning(ViewCoverHallService.class)) {
        mAppContext.stopService(new Intent(mAppContext, ViewCoverHallService.class));
    }//from  w  w  w. ja va2  s.  com
    if (getServiceRunning(ViewCoverProximityService.class)) {
        mAppContext.stopService(new Intent(mAppContext, ViewCoverProximityService.class));
    }
    if (getServiceRunning(NotificationService.class)) {
        mAppContext.stopService(new Intent(mAppContext, NotificationService.class));
    }
    if (getServiceRunning(CoreService.class)) {
        mAppContext.stopService(new Intent(mAppContext, CoreService.class));
    }

    // Relinquish device admin (unless asked not to)
    if (!override_keep_admin && !preference_all.getBoolean("pref_keep_admin", false)) {
        DevicePolicyManager dpm = (DevicePolicyManager) mAppContext
                .getSystemService(Context.DEVICE_POLICY_SERVICE);
        ComponentName me = new ComponentName(mAppContext, AdminReceiver.class);
        if (dpm.isAdminActive(me)) {
            dpm.removeActiveAdmin(me);
        }
    }
}

From source file:com.android.managedprovisioning.ProfileOwnerProvisioningService.java

private void setMdmAsActiveAdmin() {
    ProvisionLogger.logd("Setting package " + mParams.deviceAdminComponentName + " as active admin.");

    DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    dpm.setActiveAdmin(mParams.deviceAdminComponentName, true /* refreshing*/, mManagedProfileOrUserInfo.id);
}

From source file:com.android.managedprovisioning.ProfileOwnerProvisioningService.java

private void setOrganizationColor() {
    if (mParams.mainColor != null) {
        DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
        dpm.setOrganizationColorForUser(mParams.mainColor, mManagedProfileOrUserInfo.id);
    }//w ww  .  j a va  2s  .  c  om
}

From source file:com.android.launcher3.Launcher.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(//from  w w  w  . j a  v  a 2 s  . c o m
                new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // or .detectAll() for all detectable problems
                        .penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
                .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (LauncherAppState.PROFILE_STARTUP) {
            Trace.beginSection("Launcher-onCreate");
        }
    }

    predictiveAppsProvider = new PredictiveAppsProvider(this);

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.preOnCreate();
    }

    super.onCreate(savedInstanceState);

    app = LauncherAppState.getInstance();

    // Load configuration-specific DeviceProfile
    mDeviceProfile = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
            ? app.getInvariantDeviceProfile().landscapeProfile
            : app.getInvariantDeviceProfile().portraitProfile;

    mSharedPrefs = Utilities.getPrefs(this);
    mIsSafeModeEnabled = getPackageManager().isSafeMode();
    mModel = app.setLauncher(this);
    mIconCache = app.getIconCache();
    mAccessibilityDelegate = new LauncherAccessibilityDelegate(this);

    mDragController = new DragController(this);
    mAllAppsController = new AllAppsTransitionController(this);
    mStateTransitionAnimation = new LauncherStateTransitionAnimation(this, mAllAppsController);

    mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);

    mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
    mAppWidgetHost.startListening();

    // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
    // this also ensures that any synchronous binding below doesn't re-trigger another
    // LauncherModel load.
    mPaused = false;

    setContentView(R.layout.launcher);

    //Shortcuts variable init
    masterLayout = (InsettableFrameLayout) findViewById(R.id.launcher);
    gridSize = new GridSize((int) app.getInvariantDeviceProfile().numColumns,
            (int) app.getInvariantDeviceProfile().numRows);

    IS_ALLOW_MIC = Utilities.isAllowVoiceInSearchBarPrefEnabled(getApplicationContext());

    setupViews();
    mDeviceProfile.layout(this, false /* notifyListeners */);
    mExtractedColors = new ExtractedColors();
    loadExtractedColorsAndColorItems();

    ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE)).addAccessibilityStateChangeListener(this);

    lockAllApps();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

    if (LauncherAppState.PROFILE_STARTUP) {
        Trace.endSection();
    }

    // We only load the page synchronously if the user rotates (or triggers a
    // configuration change) while launcher is in the foreground
    if (!mModel.startLoader(mWorkspace.getRestorePage())) {
        // If we are not binding synchronously, show a fade in animation when
        // the first page bind completes.
        mDragLayer.setAlpha(0);
    } else {
        setWorkspaceLoading(true);
    }

    // For handling default keys
    mDefaultKeySsb = new SpannableStringBuilder();
    Selection.setSelection(mDefaultKeySsb, 0);

    IntentFilter filter = new IntentFilter(ACTION_APPWIDGET_HOST_RESET);
    registerReceiver(mUiBroadcastReceiver, filter);

    mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation);
    // In case we are on a device with locked rotation, we should look at preferences to check
    // if the user has specifically allowed rotation.
    if (!mRotationEnabled) {
        mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
        mRotationPrefChangeHandler = new RotationPrefChangeHandler();
        mSharedPrefs.registerOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
    }

    // On large interfaces, or on devices that a user has specifically enabled screen rotation,
    // we want the screen to auto-rotate based on the current orientation
    setOrientation();

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onCreate(savedInstanceState);
    }

    activity = this;
    /*if (!isTaskRoot()) {
    finish();
    return;
    }*/

    adminComponent = new ComponentName(Launcher.this, DarClass.class);
    devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

    appHasFingerprint = Utilities.getAppHasFingerprint(getApplicationContext());
    appHasPassword = Utilities.getAppHasPassword(getApplicationContext());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);
    }

    icons = Utilities.getIconPack(Utilities.getAppIconPackageNamePrefEnabled(getApplicationContext()));
    if (icons == null || icons.isEmpty() || icons.size() == 0) {
        if (Utilities.getAppIconPackageNamePrefEnabled(getApplicationContext()) != null && !Utilities
                .getAppIconPackageNamePrefEnabled(getApplicationContext()).equalsIgnoreCase("NULL")) {
            Utilities.answerToRestoreIconPack(this,
                    Utilities.getAppIconPackageNamePrefEnabled(getApplicationContext()));
        }
    }

    if (FirstRun.isFirstLaunch(getApplicationContext())) {
        WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
        try {
            myWallpaperManager.setResource(R.drawable.wallpaper);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    if (Utilities.doCheckPROVersion(getApplicationContext())) {

    }

    mDefaultScreenId = Utilities.getLongCustomDefault(this, Utilities.SETTINGS_UI_HOMESCREEN_DEFAULT_SCREEN_ID,
            1);
}

From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java

@Override
public boolean isAvailable(Context context) {
    DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    String packageName = context.getPackageName();
    return dpm.isProfileOwnerApp(packageName) || dpm.isDeviceOwnerApp(packageName);
}

From source file:com.sentaroh.android.TaskAutomation.Config.ActivityMain.java

final private void switchDeviceAdminStatus(boolean activate) {
    DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    final ComponentName darcn = new ComponentName(mContext, DevAdmReceiver.class);
    if (activate && !dpm.isAdminActive(darcn)) {
        NotifyEvent ntfy = new NotifyEvent(mContext);
        ntfy.setListener(new NotifyEventListener() {
            @Override/*  w  w  w. ja  va2  s  .c o  m*/
            public void positiveResponse(Context c, Object[] o) {
                Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, darcn);
                startActivityForResult(intent, 10);
            }

            @Override
            public void negativeResponse(Context c, Object[] o) {
            }
        });
        if (mApplicationRunFirstTime) {
            mGlblParms.commonDlg.showCommonDialog(false, "I",
                    mContext.getString(R.string.msgs_main_screen_lock_confirm_title),
                    mContext.getString(R.string.msgs_main_screen_lock_confirm_msg), ntfy);
        } else
            ntfy.notifyToListener(true, null);

    } else if (!activate)
        dpm.removeActiveAdmin(darcn);
}

From source file:com.android.settings.HWSettings.java

@Override
public void setListAdapter(ListAdapter adapter) {
    if (adapter == null) {
        super.setListAdapter(null);
    } else {/*w w w  .  j a v a  2s. com*/
        DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
        super.setListAdapter(new HeaderAdapter(this, getHeaders(), mAuthenticatorHelper, dpm));
    }
}