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


Java StrictMode.VmPolicy方法代码示例

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


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

示例1: onCreate

import android.os.StrictMode; //导入方法依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();
    if (BuildConfig.DEVELOPER_MODE) {
        StrictMode.ThreadPolicy threadPolicy = new StrictModeCompat.ThreadPolicy.Builder()
                .detectResourceMismatches()
                .detectCustomSlowCalls()
                .detectUnbufferedIo()
                .penaltyLog()
                .build();

        StrictMode.VmPolicy vmPolicy = new StrictModeCompat.VmPolicy.Builder()
                .detectFileUriExposure()
                .detectLeakedRegistrationObjects()
                .detectCleartextNetwork()
                .detectUntaggedSockets()
                .detectContentUriWithoutPermission()
                .penaltyLog()
                .build();

        StrictModeCompat.setPolicies(threadPolicy, vmPolicy);
    }
}
 
开发者ID:kirich1409,项目名称:StrictModeCompat,代码行数:24,代码来源:SampleApplication.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包/类
/**
 * Gets the current VM policy.
 */
@Nullable
public static StrictMode.VmPolicy getVmPolicy() {
    return STRICT_MODE_IMPL.getVmPolicy();
}
 
开发者ID:kirich1409,项目名称:StrictModeCompat,代码行数:8,代码来源:StrictModeCompat.java

示例5: setVmPolicy

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

示例6: build

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

示例7: setPolicies

import android.os.StrictMode; //导入方法依赖的package包/类
/**
 * Set Thread and VM policies in one method.
 *
 * @param threadPolicy the thread policy to put into place
 * @param vmPolicy     the vm policy to put into place
 */
public static void setPolicies(StrictMode.ThreadPolicy threadPolicy,
                               StrictMode.VmPolicy vmPolicy) {
    setThreadPolicy(threadPolicy);
    setVmPolicy(vmPolicy);
}
 
开发者ID:kirich1409,项目名称:StrictModeCompat,代码行数:12,代码来源:StrictModeCompat.java


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