Java Code Examples for android.os.Bundle#clear()

The following examples show how to use android.os.Bundle#clear() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: SecondScreen   File: BundleScrubber.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
/**
 * 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;
}
 
Example 3
/**
 * 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;
}
 
Example 4
Source Project: Taskbar   File: BundleScrubber.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 5
/**
 * 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;
}
 
Example 6
/**
 * 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;
}
 
Example 7
Source Project: KA27   File: BundleScrubber.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 8
Source Project: kernel_adiutor   File: BundleScrubber.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 9
/**
 * 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;
}
 
Example 10
Source Project: Sensor-Disabler   File: BundleScrubber.java    License: MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example 11
Source Project: AndroidPirateBox   File: BundleScrubber.java    License: MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example 12
Source Project: android_9.0.0_r45   File: MockProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int getStatus(Bundle extras) {
    if (mHasStatus) {
        extras.clear();
        extras.putAll(mExtras);
        return mStatus;
    } else {
        return LocationProvider.AVAILABLE;
    }
}
 
Example 13
@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);
}
 
Example 14
@Override
protected void onSaveInstanceState(Bundle outState) {
    if (toolbar != null) {
        outState.putString(STATE_TOOLBAR_TITLE, toolbar.getTitle().toString());
    }

    super.onSaveInstanceState(outState);
    outState.clear();
}
 
Example 15
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;
}
 
Example 16
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        savedInstanceState.clear();
    }
    super.onRestoreInstanceState(savedInstanceState);
}
 
Example 17
Source Project: ScreenCapture   File: SocketClientFragment.java    License: MIT License 4 votes vote down vote up
@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();
    }
}
 
Example 18
Source Project: PlayerBase   File: EventDispatcher.java    License: Apache License 2.0 4 votes vote down vote up
private void recycleBundle(Bundle bundle){
    if(bundle!=null)
        bundle.clear();
}
 
Example 19
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
	super.onSaveInstanceState(savedInstanceState);

	savedInstanceState.clear();
}
 
Example 20
@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);

}