当前位置: 首页>>代码示例>>Java>>正文


Java DevicePolicyManager类代码示例

本文整理汇总了Java中android.app.admin.DevicePolicyManager的典型用法代码示例。如果您正苦于以下问题:Java DevicePolicyManager类的具体用法?Java DevicePolicyManager怎么用?Java DevicePolicyManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DevicePolicyManager类属于android.app.admin包,在下文中一共展示了DevicePolicyManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toggleState

import android.app.admin.DevicePolicyManager; //导入依赖的package包/类
@Override
public void toggleState(Context context) {
   final DevicePolicyManager pm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
   ComponentName cm = new ComponentName(context, LockAdmin.class);

   if (pm.isAdminActive(cm)) {
     Runnable lockRunnable = new Runnable() {

       @Override
       public void run() {
         pm.lockNow();
       }
     };
     Handler handler = new Handler();
     handler.post(lockRunnable);
     if (Globals.getAppPrefs(context).getBoolean(KEY_DOUBLE_LOCK, DEFAULT_VALUE)) {
       handler.postDelayed(lockRunnable, 500);
     }
   } else {
     Globals.startIntent(context, new Intent(context, ProxyActivity.class)
         .putExtra("proxy", new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN)
             .putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, cm)
             .putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, context.getResources().getString(R.string.admin_explain))));
   }
}
 
开发者ID:sunnygoyal,项目名称:PowerToggles,代码行数:26,代码来源:LockScreenToggle.java

示例2: getCurrentState

import android.app.admin.DevicePolicyManager; //导入依赖的package包/类
private State getCurrentState() {
    ComponentName componentName = componentName();
    DevicePolicyManager policyManager =
            (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (!policyManager.isAdminActive(componentName)) {
        return State.NEEDS_PERMISSIONS;
    }
    if (!policyManager.getCameraDisabled(componentName)) {
        return State.HAS_PERMISSIONS;
    }
    if (!policyManager.isDeviceOwnerApp(BuildConfig.APPLICATION_ID)) {
        return State.CAMERA_DISABLED;
    }
    // Apparently we can't query for user restrictions, so just always set them if they're not
    // already set. We know that we're allowed to because we're the device owner.
    policyManager.addUserRestriction(componentName, UserManager.DISALLOW_ADD_USER);
    policyManager.addUserRestriction(componentName, UserManager.DISALLOW_FACTORY_RESET);
    return State.IS_DEVICE_OWNER;
}
 
开发者ID:disablecamera,项目名称:disablecamera,代码行数:20,代码来源:DisableCameraActivity.java

示例3: removeActiveAdmin

import android.app.admin.DevicePolicyManager; //导入依赖的package包/类
private void removeActiveAdmin() {
    DevicePolicyManager mgr = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
    ComponentName cn = new ComponentName(mContext, AdminReceiver.class);
    if ( mgr.isAdminActive(cn)) {
        mgr.removeActiveAdmin(cn);
    }

}
 
开发者ID:firebirdberlin,项目名称:nightdream,代码行数:9,代码来源:PreferencesFragment.java

示例4: onCreate

import android.app.admin.DevicePolicyManager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_real);
    if (savedInstanceState == null) {
        DevicePolicyManager manager = (DevicePolicyManager)
                getSystemService(Context.DEVICE_POLICY_SERVICE);
        if (manager.isProfileOwnerApp(getApplicationContext().getPackageName())) {
            // If the managed profile is already set up, we show the main screen.
            showMainFragment();
        } else {
            // If not, we show the set up screen.
            showSetupProfile();
        }
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:17,代码来源:MainActivity.java

示例5: isApplicationEnabled

import android.app.admin.DevicePolicyManager; //导入依赖的package包/类
/**
 * Checks if the application is available in this profile.
 *
 * @param packageName The package name
 * @return True if the application is available in this profile.
 */
private boolean isApplicationEnabled(String packageName) {
    Activity activity = getActivity();
    PackageManager packageManager = activity.getPackageManager();
    try {
        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(
                packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
        // Return false if the app is not installed in this profile
        if (0 == (applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED)) {
            return false;
        }
        // Check if the app is not hidden in this profile
        DevicePolicyManager devicePolicyManager =
                (DevicePolicyManager) activity.getSystemService(Activity.DEVICE_POLICY_SERVICE);
        return !devicePolicyManager.isApplicationHidden(
                BasicDeviceAdminReceiver.getComponentName(activity), packageName);
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:26,代码来源:BasicManagedProfileFragment.java

示例6: enableForwarding

import android.app.admin.DevicePolicyManager; //导入依赖的package包/类
/**
 * Enables forwarding of share intent between private account and managed profile.
 */
private void enableForwarding() {
    Activity activity = getActivity();
    if (null == activity || activity.isFinishing()) {
        return;
    }
    DevicePolicyManager manager =
            (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    try {
        IntentFilter filter = new IntentFilter(Intent.ACTION_SEND);
        filter.addDataType("text/plain");
        filter.addDataType("image/jpeg");
        // This is how you can register an IntentFilter as allowed pattern of Intent forwarding
        manager.addCrossProfileIntentFilter(BasicDeviceAdminReceiver.getComponentName(activity),
                filter, FLAG_MANAGED_CAN_ACCESS_PARENT | FLAG_PARENT_CAN_ACCESS_MANAGED);
    } catch (IntentFilter.MalformedMimeTypeException e) {
        e.printStackTrace();
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:22,代码来源:BasicManagedProfileFragment.java

示例7: sendIntent

import android.app.admin.DevicePolicyManager; //导入依赖的package包/类
/**
 * Sends a sample intent of a plain text message.  This is just a utility function to see how
 * the intent forwarding works.
 */
private void sendIntent() {
    Activity activity = getActivity();
    if (null == activity || activity.isFinishing()) {
        return;
    }
    DevicePolicyManager manager =
            (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT,
            manager.isProfileOwnerApp(activity.getApplicationContext().getPackageName())
                    ? "From the managed account" : "From the primary account");
    try {
        startActivity(intent);
        Log.d(TAG, "A sample intent was sent.");
    } catch (ActivityNotFoundException e) {
        Toast.makeText(activity, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:24,代码来源:BasicManagedProfileFragment.java

示例8: removeProfile

import android.app.admin.DevicePolicyManager; //导入依赖的package包/类
/**
 * Wipes out all the data related to this managed profile.
 */
private void removeProfile() {
    Activity activity = getActivity();
    if (null == activity || activity.isFinishing()) {
        return;
    }
    DevicePolicyManager manager =
            (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    manager.wipeData(0);
    // The screen turns off here
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:14,代码来源:BasicManagedProfileFragment.java

示例9: onClick

import android.app.admin.DevicePolicyManager; //导入依赖的package包/类
@Override
public void onClick(View v) {
    // First, persist the policy.  Then, launch intent to trigger the system screen
    // requesting user to confirm the activation of the device administrator.
    writePolicy();
    Intent activateDeviceAdminIntent =
        new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    activateDeviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
            mPolicy.getPolicyAdmin());
    // It is good practice to include the optional explanation text to explain to
    // user why the application is requesting to be a device administrator.  The system
    // will display this message on the activation screen.
    activateDeviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
            getResources().getString(R.string.device_admin_activation_message));
    startActivityForResult(activateDeviceAdminIntent, REQ_ACTIVATE_DEVICE_ADMIN);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:17,代码来源:PolicySetupActivity.java

示例10: keyguardEnforcedByDevicePolicy

import android.app.admin.DevicePolicyManager; //导入依赖的package包/类
public boolean keyguardEnforcedByDevicePolicy() {
    DevicePolicyManager dpm = (DevicePolicyManager)
            mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm != null) {
        int passwordQuality = dpm.getPasswordQuality(null);
        switch (passwordQuality) {
            case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
            case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
            case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
            case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
            case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
            case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
                return true;
        }
    }
    return false;
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:18,代码来源:KeyguardStateMonitor.java

示例11: onCreate

import android.app.admin.DevicePolicyManager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mCN = new ComponentName(this, MainReceiver.class); // Receiver, not Activity!
    mDPM = (DevicePolicyManager)getSystemService(DEVICE_POLICY_SERVICE);

    if (isHuaweiNougat()) {
        launchEmuiLockActivity();
        finish();
    } else if (isAdminActive()) {
        lock();
        finish();
    } else {
        enableAppAsAdministrator();
    }
}
 
开发者ID:seguri,项目名称:Lock,代码行数:18,代码来源:MainActivity.java

示例12: onCreate

import android.app.admin.DevicePolicyManager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	// 设备安全管理服务    2.2之前的版本是没有对外暴露的 只能通过反射技术获取
	devicePolicyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
	boolean isAdminActive = devicePolicyManager.isAdminActive(Dar.getCn(this));

	if (isAdminActive) {
		// 锁屏
		devicePolicyManager.lockNow();
		finish();
	}else{
		startAddDeviceAdminAty();
	}
}
 
开发者ID:aidansu,项目名称:Lockscreen,代码行数:17,代码来源:MainActivity.java

示例13: lockDevice

import android.app.admin.DevicePolicyManager; //导入依赖的package包/类
public static void lockDevice(Context context) {
    ComponentName component = new ComponentName(context, LockDeviceReceiver.class);
    context.getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);

    DevicePolicyManager mDevicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if(mDevicePolicyManager.isAdminActive(component))
        mDevicePolicyManager.lockNow();
    else {
        launchApp(context, () -> {
            Intent intent = new Intent(context, DummyActivity.class);
            intent.putExtra("device_admin", true);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent, getActivityOptionsBundle(ApplicationType.APPLICATION));

            if(context instanceof Activity)
                ((Activity) context).overridePendingTransition(0, 0);
        });
    }
}
 
开发者ID:farmerbb,项目名称:Taskbar,代码行数:21,代码来源:U.java

示例14: uninstall

import android.app.admin.DevicePolicyManager; //导入依赖的package包/类
public static void uninstall(Context context, Prefs prefs) {
    try {
        ComponentName devAdminReceiver = new ComponentName(context, DAReceiver.class);
        DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
        dpm.removeActiveAdmin(devAdminReceiver);
        if (prefs.proximityToLock && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && !Shell.SU.available())
            prefs.setBool(Prefs.KEYS.PROXIMITY_TO_LOCK.toString(), false);
    } catch (Exception ignored) {
    }
    Uri packageUri = Uri.parse("package:" + context.getPackageName());
    Intent uninstallIntent =
            new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
    uninstallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(uninstallIntent);
}
 
开发者ID:rosenpin,项目名称:AlwaysOnDisplayAmoled,代码行数:16,代码来源:PreferencesActivity.java

示例15: isDeviceSecure

import android.app.admin.DevicePolicyManager; //导入依赖的package包/类
public static boolean isDeviceSecure(Context context) {
    // Starting with android 6.0 calling isLockScreenDisabled fails altogether because the signature has changed.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        KeyguardManager keyguardMgr = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
        return keyguardMgr != null && keyguardMgr.isDeviceSecure();
    }

    try {
        String LOCKSCREEN_UTILS_CLASSNAME = "com.android.internal.widget.LockPatternUtils";
        Class<?> lockUtilsClass = Class.forName(LOCKSCREEN_UTILS_CLASSNAME);
        Object lockUtils = lockUtilsClass.getConstructor(Context.class).newInstance(context);
        Method method = lockUtilsClass.getMethod("getActivePasswordQuality");

        // Starting with android 5.x this fails with InvocationTargetException (caused by SecurityException - MANAGE_USERS permission is
        // required because internally some additional logic was added to return false if one can switch between several users)
        // -> therefore if no exception is thrown, we know the screen lock setting is set to Pattern, PIN/PW or something else other than 'None' or 'Swipe'
        Integer lockProtectionLevel = (Integer) method.invoke(lockUtils);
        return lockProtectionLevel >= DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;

    } catch (InvocationTargetException ignored) {
    } catch (Exception e) {
        MobileMessagingLogger.e("Error detecting whether screen lock is disabled: " + e);
    }

    return false;
}
 
开发者ID:infobip,项目名称:mobile-messaging-sdk-android,代码行数:27,代码来源:DeviceInformation.java


注:本文中的android.app.admin.DevicePolicyManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。