本文整理汇总了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();
}
}
示例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;
}
}
}
示例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;
}
}
}
示例4: getVmPolicy
import android.os.StrictMode; //导入方法依赖的package包/类
@Override
public StrictMode.VmPolicy getVmPolicy() {
return StrictMode.getVmPolicy();
}