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


Java StrictMode.getVmPolicy方法代码示例

本文整理汇总了Java中android.os.StrictMode.getVmPolicy方法的典型用法代码示例。如果您正苦于以下问题:Java StrictMode.getVmPolicy方法的具体用法?Java StrictMode.getVmPolicy怎么用?Java StrictMode.getVmPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.os.StrictMode的用法示例。


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

示例1: setUp

import android.os.StrictMode; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();
    mOldVmPolicy = StrictMode.getVmPolicy();
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                                   .detectLeakedClosableObjects()
                                   .penaltyLog()
                                   .penaltyDeath()
                                   .build());
    mTestFramework = startCronetTestFramework();
    assertTrue(NativeTestServer.startNativeTestServer(getContext()));
    // Add url interceptors after native application context is initialized.
    MockUrlRequestJobFactory.setUp();
    mFile = new File(getContext().getCacheDir().getPath() + "/tmpfile");
    FileOutputStream fileOutputStream = new FileOutputStream(mFile);
    try {
        fileOutputStream.write(LOREM.getBytes("UTF-8"));
    } finally {
        fileOutputStream.close();
    }
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:22,代码来源:UploadDataProvidersTest.java

示例2: startShortcutIntentSafely

import android.os.StrictMode; //导入方法依赖的package包/类
private void startShortcutIntentSafely(Intent intent, Bundle optsBundle, ItemInfo info) {
    try {
        StrictMode.VmPolicy oldPolicy = StrictMode.getVmPolicy();
        try {
            // Temporarily disable deathPenalty on all default checks. For eg, shortcuts
            // containing file Uri's would cause a crash as penaltyDeathOnFileUriExposure
            // is enabled by default on NYC.
            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll()
                    .penaltyLog().build());

            if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
                String id = ((ShortcutInfo) info).getDeepShortcutId();
                String packageName = intent.getPackage();
                DeepShortcutManager.getInstance(this).startShortcut(
                        packageName, id, intent.getSourceBounds(), optsBundle, info.user);
            } else {
                // Could be launching some bookkeeping activity
                startActivity(intent, optsBundle);
            }
        } finally {
            StrictMode.setVmPolicy(oldPolicy);
        }
    } catch (SecurityException e) {
        // Due to legacy reasons, direct call shortcuts require Launchers to have the
        // corresponding permission. Show the appropriate permission prompt if that
        // is the case.

        if (AndroidVersion.isAtLeastMarshmallow) {
            if (intent.getComponent() == null
                    && Intent.ACTION_CALL.equals(intent.getAction())
                    && checkSelfPermission(Manifest.permission.CALL_PHONE) !=
                    PackageManager.PERMISSION_GRANTED) {

                setWaitingForResult(PendingRequestArgs
                        .forIntent(REQUEST_PERMISSION_CALL_PHONE, intent, info));
                requestPermissions(new String[]{Manifest.permission.CALL_PHONE},
                        REQUEST_PERMISSION_CALL_PHONE);
        }

        } else {
            // No idea why this was thrown.
            throw e;
        }
    }
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:46,代码来源:Launcher.java

示例3: startShortcutIntentSafely

import android.os.StrictMode; //导入方法依赖的package包/类
private void startShortcutIntentSafely(Intent intent, Bundle optsBundle, ItemInfo info) {
    try {
        StrictMode.VmPolicy oldPolicy = StrictMode.getVmPolicy();
        try {
            // Temporarily disable deathPenalty on all default checks. For eg, shortcuts
            // containing file Uri's would cause a crash as penaltyDeathOnFileUriExposure
            // is enabled by default on NYC.
            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll()
                    .penaltyLog().build());

            if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
                String id = ((ShortcutInfo) info).getDeepShortcutId();
                String packageName = intent.getPackage();
                LauncherAppState.getInstance().getShortcutManager().startShortcut(
                        packageName, id, intent.getSourceBounds(), optsBundle, info.user);
            } else {
                // Could be launching some bookkeeping activity
                startActivity(intent, optsBundle);
            }
        } finally {
            StrictMode.setVmPolicy(oldPolicy);
        }
    } catch (SecurityException e) {
        // Due to legacy reasons, direct call shortcuts require Launchers to have the
        // corresponding permission. Show the appropriate permission prompt if that
        // is the case.
        if (intent.getComponent() == null
                && Intent.ACTION_CALL.equals(intent.getAction())
                && checkSelfPermission(Manifest.permission.CALL_PHONE) !=
                PackageManager.PERMISSION_GRANTED) {

            setWaitingForResult(PendingRequestArgs
                    .forIntent(REQUEST_PERMISSION_CALL_PHONE, intent, info));
            requestPermissions(new String[]{Manifest.permission.CALL_PHONE},
                    REQUEST_PERMISSION_CALL_PHONE);
        } else {
            // No idea why this was thrown.
            throw e;
        }
    }
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:42,代码来源:Launcher.java

示例4: getVmPolicy

import android.os.StrictMode; //导入方法依赖的package包/类
@Override
public StrictMode.VmPolicy getVmPolicy() {
    return StrictMode.getVmPolicy();
}
 
开发者ID:kirich1409,项目名称:StrictModeCompat,代码行数:5,代码来源:StrictModeCompat.java


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