下面列出了android.os.Bundle#clear ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Scrubs Bundles for private serializable subclasses in the extras. If the Bundle's extras contain a
* private serializable subclass, the Bundle is cleared. If the Bundle is null, has no extras, or the
* extras do not contain a private serializable subclass, the Bundle is not mutated.
*
* @param bundle {@code Bundle} to scrub. This parameter may be mutated if scrubbing is necessary. This
* parameter may be null.
* @return true if the Bundle was scrubbed, false if the Bundle was not modified.
*/
public static boolean scrub(final Bundle bundle)
{
if (null == bundle)
return false;
/*
* Note: This is a hack to work around a private serializable classloader attack
*/
try
{
// if a private serializable exists, this will throw an exception
bundle.containsKey(null);
}
catch (final Exception e)
{
bundle.clear();
return true;
}
return false;
}
/**
* Scrubs Bundles for private serializable subclasses in the extras. If the Bundle's extras contain a
* private serializable subclass, the Bundle is cleared. If the Bundle is null, has no extras, or the
* extras do not contain a private serializable subclass, the Bundle is not mutated.
*
* @param bundle {@code Bundle} to scrub. This parameter may be mutated if scrubbing is necessary. This
* parameter may be null.
* @return true if the Bundle was scrubbed, false if the Bundle was not modified.
*/
public static boolean isSuspicious(@Nullable final Bundle bundle) {
if (bundle != null) {
/*
* Note: This is a hack to work around a private serializable classloader attack
*/
try {
// if a private serializable exists, this will throw an exception
bundle.containsKey(null);
} catch (final Exception e) {
bundle.clear();
return true;
}
}
return false;
}
/**
* Scrubs Bundles for private serializable subclasses in the extras. If the Bundle's extras contain a
* private serializable subclass, the Bundle is cleared. If the Bundle is null, has no extras, or the
* extras do not contain a private serializable subclass, the Bundle is not mutated.
*
* @param bundle {@code Bundle} to scrub. This parameter may be mutated if scrubbing is necessary. This
* parameter may be null.
* @return true if the Bundle was scrubbed, false if the Bundle was not modified.
*/
public static boolean scrub(final Bundle bundle) {
if (null == bundle) {
return false;
}
/*
* Note: This is a hack to work around a private serializable classloader attack
*/
try {
// if a private serializable exists, this will throw an exception
bundle.containsKey(null);
} catch (final Exception e) {
bundle.clear();
return true;
}
return false;
}
/**
* Scrubs Bundles for private serializable subclasses in the extras. If the Bundle's extras contain a
* private serializable subclass, the Bundle is cleared. If the Bundle is null, has no extras, or the
* extras do not contain a private serializable subclass, the Bundle is not mutated.
*
* @param bundle {@code Bundle} to scrub. This parameter may be mutated if scrubbing is necessary. This
* parameter may be null.
* @return true if the Bundle was scrubbed, false if the Bundle was not modified.
*/
public static boolean scrub(final Bundle bundle)
{
if (null == bundle)
return false;
/*
* Note: This is a hack to work around a private serializable classloader attack
*/
try
{
// if a private serializable exists, this will throw an exception
bundle.containsKey(null);
}
catch (final Exception e)
{
bundle.clear();
return true;
}
return false;
}
/**
* Scrubs Bundles for private serializable subclasses in the extras. If the Bundle's extras contain a
* private serializable subclass, the Bundle is cleared. If the Bundle is null, has no extras, or the
* extras do not contain a private serializable subclass, the Bundle is not mutated.
*
* @param bundle {@code Bundle} to scrub. This parameter may be mutated if scrubbing is necessary. This
* parameter may be null.
* @return true if the Bundle was scrubbed, false if the Bundle was not modified.
*/
public static boolean scrub(final Bundle bundle)
{
if (null == bundle)
{
return false;
}
/*
* Note: This is a hack to work around a private serializable classloader attack
*/
try
{
// if a private serializable exists, this will throw an exception
bundle.containsKey(null);
}
catch (final Exception e)
{
bundle.clear();
return true;
}
return false;
}
/**
* Scrubs Bundles for private serializable subclasses in the extras. If the Bundle's extras contain a
* private serializable subclass, the Bundle is cleared. If the Bundle is null, has no extras, or the
* extras do not contain a private serializable subclass, the Bundle is not mutated.
*
* @param bundle {@code Bundle} to scrub. This parameter may be mutated if scrubbing is necessary. This
* parameter may be null.
* @return true if the Bundle was scrubbed, false if the Bundle was not modified.
*/
public static boolean scrub(final Bundle bundle)
{
if (null == bundle)
{
return false;
}
/*
* Note: This is a hack to work around a private serializable classloader attack
*/
try
{
// if a private serializable exists, this will throw an exception
bundle.containsKey(null);
}
catch (final Exception e)
{
bundle.clear();
return true;
}
return false;
}
/**
* Scrubs Bundles for private serializable subclasses in the extras. If the Bundle's extras contain a
* private serializable subclass, the Bundle is cleared. If the Bundle is null, has no extras, or the
* extras do not contain a private serializable subclass, the Bundle is not mutated.
*
* @param bundle {@code Bundle} to scrub. This parameter may be mutated if scrubbing is necessary. This
* parameter may be null.
* @return true if the Bundle was scrubbed, false if the Bundle was not modified.
*/
public static boolean scrub(final Bundle bundle) {
if (null == bundle) return false;
/*
* Note: This is a hack to work around a private serializable classloader attack
*/
try {
// if a private serializable exists, this will throw an exception
bundle.containsKey(null);
} catch (final Exception e) {
bundle.clear();
return true;
}
return false;
}
/**
* Scrubs Bundles for private serializable subclasses in the extras. If the Bundle's extras contain a
* private serializable subclass, the Bundle is cleared. If the Bundle is null, has no extras, or the
* extras do not contain a private serializable subclass, the Bundle is not mutated.
*
* @param bundle {@code Bundle} to scrub. This parameter may be mutated if scrubbing is necessary. This
* parameter may be null.
* @return true if the Bundle was scrubbed, false if the Bundle was not modified.
*/
public static boolean scrub(final Bundle bundle) {
if (null == bundle) return false;
/*
* Note: This is a hack to work around a private serializable classloader attack
*/
try {
// if a private serializable exists, this will throw an exception
bundle.containsKey(null);
} catch (final Exception e) {
bundle.clear();
return true;
}
return false;
}
/**
* Scrubs Bundles for private serializable subclasses in the extras. If the Bundle's extras contain a
* private serializable subclass, the Bundle is cleared. If the Bundle is null, has no extras, or the
* extras do not contain a private serializable subclass, the Bundle is not mutated.
*
* @param bundle {@code Bundle} to scrub. This parameter may be mutated if scrubbing is necessary. This
* parameter may be null.
* @return true if the Bundle was scrubbed, false if the Bundle was not modified.
*/
public static boolean scrub(final Bundle bundle)
{
if (null == bundle)
{
return false;
}
/*
* Note: This is a hack to work around a private serializable classloader attack
*/
try
{
// if a private serializable exists, this will throw an exception
bundle.containsKey(null);
}
catch (final Exception e)
{
bundle.clear();
return true;
}
return false;
}
/**
* Scrubs Bundles for private serializable subclasses in the extras. If the Bundle's extras contain a
* private serializable subclass, the Bundle is cleared. If the Bundle is null, has no extras, or the
* extras do not contain a private serializable subclass, the Bundle is not mutated.
*
* @param bundle {@code Bundle} to scrub. This parameter may be mutated if scrubbing is necessary. This
* parameter may be null.
* @return true if the Bundle was scrubbed, false if the Bundle was not modified.
*/
public static boolean scrub(final Bundle bundle) {
if (null == bundle) {
return false;
}
/*
* Note: This is a hack to work around a private serializable classloader attack
*/
try {
// if a private serializable exists, this will throw an exception
bundle.containsKey(null);
} catch (final Exception e) {
bundle.clear();
return true;
}
return false;
}
/**
* Scrubs Bundles for private serializable subclasses in the extras. If the Bundle's extras contain a
* private serializable subclass, the Bundle is cleared. If the Bundle is null, has no extras, or the
* extras do not contain a private serializable subclass, the Bundle is not mutated.
*
* @param bundle {@code Bundle} to scrub. This parameter may be mutated if scrubbing is necessary. This
* parameter may be null.
* @return true if the Bundle was scrubbed, false if the Bundle was not modified.
*/
public static boolean scrub(final Bundle bundle)
{
if (null == bundle)
{
return false;
}
/*
* Note: This is a hack to work around a private serializable classloader attack
*/
try
{
// if a private serializable exists, this will throw an exception
bundle.containsKey(null);
}
catch (final Exception e)
{
bundle.clear();
return true;
}
return false;
}
@Override
public int getStatus(Bundle extras) {
if (mHasStatus) {
extras.clear();
extras.putAll(mExtras);
return mStatus;
} else {
return LocationProvider.AVAILABLE;
}
}
@Override
protected void onSaveInstanceState(@NotNull Bundle outState) {
outState.clear();
outState.putString(TEI_UID, teiUid);
outState.putString(PROGRAM_UID, programUid);
outState.putString(ENROLLMENT_UID, enrollmentUid);
super.onSaveInstanceState(outState);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
if (toolbar != null) {
outState.putString(STATE_TOOLBAR_TITLE, toolbar.getTitle().toString());
}
super.onSaveInstanceState(outState);
outState.clear();
}
public static boolean scrub(final Bundle bundle) {
if (null == bundle) {
return false;
}
try {
bundle.containsKey(null);
} catch (final Exception e) {
bundle.clear();
return true;
}
return false;
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
if (savedInstanceState != null) {
savedInstanceState.clear();
}
super.onRestoreInstanceState(savedInstanceState);
}
@Override
public void run() {
//定义消息
Message msg = new Message();
msg.what = 0x11;
Bundle bundle = new Bundle();
bundle.clear();
try {
//连接服务器 并设置连接超时为1秒
Socket socket = new Socket();
socket.connect(new InetSocketAddress(ipAddr, PORT), 1000); //端口号为30000
//获取输入输出流
OutputStream ou = socket.getOutputStream();
BufferedReader bff = new BufferedReader(new InputStreamReader(
socket.getInputStream()));
//读取发来服务器信息
String line = null;
StringBuilder stringBuilder = new StringBuilder();
while ((line = bff.readLine()) != null) {
stringBuilder.append(line);
}
//向服务器发送信息 2048byte发一次
int count = 0;
byte[] sendBytes = new byte[2048];
int oriLen = sendOriginData.length;
while (oriLen > 0) {
if (oriLen > 2048) {
for (int i = 0; i < 2048; i++) {
sendBytes[i] = sendOriginData[i + count * 2048];
}
} else { // 最后一段
sendBytes = null;
sendBytes = new byte[oriLen];
for (int i = 0; i < oriLen; i++) {
sendBytes[i] = sendOriginData[i + count * 2048];
}
}
ou.write(sendBytes, 0, sendBytes.length);
ou.flush();
oriLen -= 2048;
count++;
}
bundle.putString("msg", stringBuilder.toString());
msg.setData(bundle);
//发送消息 修改UI线程中的组件
myHandler.sendMessage(msg);
//关闭各种输入输出流1
bff.close();
ou.close();
socket.close();
} catch (SocketTimeoutException aa) {
//连接超时 在UI界面显示消息
bundle.putString("msg", "服务器连接失败!请检查网络是否打开");
msg.setData(bundle);
//发送消息 修改UI线程中的组件
myHandler.sendMessage(msg);
} catch (IOException e) {
e.printStackTrace();
}
}
private void recycleBundle(Bundle bundle){
if(bundle!=null)
bundle.clear();
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.clear();
}
@Override
public void callActivityOnCreate(Activity activity, Bundle icicle) {
if (icicle != null && icicle.getParcelable("android:support:fragments") != null) {
if (ProcessUtil.isPluginProcess()) {
if (AnnotationProcessor.getPluginContainer(activity.getClass()) != null) {
// 加了注解的Activity正在自动恢复且页面包含了Fragment。直接清除fragment,
// 防止如果被恢复的fragment来自插件时,在某些情况下会使用宿主的classloader加载插件fragment
// 导致classnotfound问题
icicle.clear();
icicle = null;
}
}
}
PluginInjector.injectInstrumetionFor360Safe(activity, this);
PluginInjector.injectActivityContext(activity);
Intent intent = activity.getIntent();
if (intent != null) {
intent.setExtrasClassLoader(activity.getClassLoader());
}
if (icicle != null) {
icicle.setClassLoader(activity.getClassLoader());
}
if (ProcessUtil.isPluginProcess()) {
installPluginViewFactory(activity);
if (activity instanceof WaitForLoadingPluginActivity) {
//NOTHING
} else {
AndroidWebkitWebViewFactoryProvider.switchWebViewContext(activity);
}
if (activity.isChild()) {
//修正TabActivity中的Activity的ContextImpl的packageName
Context base = activity.getBaseContext();
while(base instanceof ContextWrapper) {
base = ((ContextWrapper)base).getBaseContext();
}
if (HackContextImpl.instanceOf(base)) {
HackContextImpl impl = new HackContextImpl(base);
String packageName = FairyGlobal.getHostApplication().getPackageName();
String packageName1 = activity.getPackageName();
impl.setBasePackageName(packageName);
impl.setOpPackageName(packageName);
}
}
}
try {
real.callActivityOnCreate(activity, icicle);
} catch (RuntimeException e) {
throw new RuntimeException(
" activity : " + activity.getClassLoader() +
" pluginContainer : " + AnnotationProcessor.getPluginContainer(activity.getClass()) +
", process : " + ProcessUtil.isPluginProcess(), e);
}
monitor.onActivityCreate(activity);
}