本文整理汇总了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);
}
}
示例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包/类
/**
* Gets the current VM policy.
*/
@Nullable
public static StrictMode.VmPolicy getVmPolicy() {
return STRICT_MODE_IMPL.getVmPolicy();
}
示例5: setVmPolicy
import android.os.StrictMode; //导入方法依赖的package包/类
@Override
public void setVmPolicy(StrictMode.VmPolicy policy) {
StrictMode.setVmPolicy(policy);
}
示例6: build
import android.os.StrictMode; //导入方法依赖的package包/类
public StrictMode.VmPolicy build() {
return mBuilder.build();
}
示例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);
}