我的应用程序如何在Android 4.0中分配更多堆内存?(How can my app allocate more heap memory in Android 4.0? (Not enough memory for my app) [closed])
我对我的应用程序不满意。 我正在为专用条码扫描器基于Android的设备开发应用程序。 它就像一部旧手机(CPU Cortex-A8 OMAP 1Ghz,512MB RAM)和Android 4.0。 我不能根系统,也不能更新它,我已经和制造商谈过了。
问题是无法完成简单(JSON)登录。 它试图分配更多的内存,但它不能。
这是同一个网络中相同的活动和相同的进程,但是在LG G2中(按预期方式进行登录和同步需要大约5秒)
在条形码扫描仪设备中,我删除或休眠了所有应用程序,我已经安装了Zend Launcher(内存占用很少),但我现在已经没有想法了。 我已经尝试过android:largeHeap on manifest,但没有成功。
有人对我有想法吗? 提前致谢
PS:该应用程序必须在该条形码扫描仪中运行,在LG G2上工作仅用于测试和比较目的。
编辑:我不关心后台其他应用程序,因为这个设备基本上将使用这个应用程序,没有别的。
I'm desesperate with my app. I'm developing an app for a dedicated barcode scanner Android based device. It's like an old phone (CPU Cortex-A8 OMAP 1Ghz, 512MB RAM), with Android 4.0. I can't root the system, nor update it, i've talked with the manufacturer.
The problem is that can't finish a simple (JSON) login. It tries to allocate more memory, but it can't.
Here is the same activity and the same process in the same network, but in an LG G2 (it tooks about 5s doing the login and the sync, as expected)
In the barcode scanner device, I removed or hibernated ALL of the apps I can, I've installed Zend Launcher (which has a very little memory footprint), but I'm out of ideas now. I've tried android:largeHeap on manifest, without success.
Somebody has an idea for me? Thanks in advance
PS: The app must run in that barcode scanner, working on LG G2 is only for test and comparative purposes.
EDIT: I don't care about other apps in background, because this device will basically use this app, and nothing else.
原文:https://stackoverflow.com/questions/30231948
最满意答案
AES可能比它的价值更麻烦。 就像我尊重Jeff LaMarche一样,这种实现并不好。 这对于这个目的来说已经足够了,但除非你理解它的正确性和错误,否则不能在我看来复制它。 我通过使用CommonCrypto的AES正确加密,详细讨论了这个问题,并包括如何正确地进行AES; 但是你可能不想在这里正确地做正确的AES麻烦,如果你做的话它也不会给你带来太大帮助。
我的建议是一个简单的校验和哈希:
- (NSUInteger)checksumForScore:(NSUInteger)score player:(GKPlayer *)player { NSString *string = [NSString stringWithFormat:@"%d%@%@", score, [player playerID], kLongRandomPassword]; return [string hash]; }
然后,您将校验和与分数一起存储。 你验证它像:
- (BOOL)isValidChecksum:(NSUInteger)checksum forScore:(NSUInteger)score player:(GKPlayer *)player { return (checksum == [checksumForScore:score player:player]); }
我在这里使用了
GKPlayer playerID
来挑选一些易于使用的东西,但对于设备所有者在玩游戏时更改并非易事。 这样做会使重播攻击变得困难。 我不能把我朋友的plist条目与我的plist的超高分复制。 当用户更换设备或恢复此设备时,它也非常持久。 如果你没有使用GameKit,首先,你应该:D和第二,你必须弄清楚你是否还想要使用其他键。 如果您让用户在某个时刻输入,那么“用户句柄”也可以。 任何对用户来说都是独一无二的东西,他不会只是复制他的朋友。Keychain作为一种混淆技术很有意思。 甚至合法地阅读也是一种皇家的痛苦,因此官方SDK提供了自己的混淆:DI怀疑它值得麻烦,但它是一个“隐藏”少量数据的好地方。
NSCoding
甚至都不是混淆。 任何打算打开plist的人都可以在不到一分钟的时间内读写NSCoding
。 将此转换为NSData
。 将其存储在SQLite或Core Data中也是如此。@CocoaFu对NSDataWritingFileProtectionComplete的建议很聪明,但我怀疑它会对越狱设备产生任何实际影响。 一旦设备解锁,操作系统将为您解密任何文件,因此对于知道设备PIN的人来说,这根本不是障碍。
AES is probably more trouble than it's worth here. Much as I respect Jeff LaMarche, this implementation is not good. It's adequate for this purpose, but it's not something to copy around in my opinion unless you understand what's right and what's wrong with it. I talk about this at length in Properly encrypting with AES with CommonCrypto and include how to do AES correctly; but you probably don't want the hassle of doing AES correctly here, and it wouldn't buy you much if you did.
My recommendation is a simple checksum hash:
- (NSUInteger)checksumForScore:(NSUInteger)score player:(GKPlayer *)player { NSString *string = [NSString stringWithFormat:@"%d%@%@", score, [player playerID], kLongRandomPassword]; return [string hash]; }
You then store the checksum along with the score. You validate it like:
- (BOOL)isValidChecksum:(NSUInteger)checksum forScore:(NSUInteger)score player:(GKPlayer *)player { return (checksum == [checksumForScore:score player:player]); }
I've used
GKPlayer playerID
here to pick something that's easy for you to use, but not trivial for the device owner to change while playing. Doing it this way makes replay attack hard. I can't just copy my friend's plist entry with it's super-highscore to my plist. It's also nicely persistent when the user changes devices or restores this device. If you're not using GameKit, first, you probably should :D and second, you'll have to figure out if there's some other key you want to use. A "user handle" would be fine too if you have the user enter that at some point. Anything that's unique-enough to the user that he wouldn't just copy his friend's.Keychain is interesting as an obfuscation technique. It's a royal pain to read even legitimately, so the official SDK provides its own obfuscation :D I doubt it's worth the trouble, but it is a decent place to "hide" small amounts of data.
NSCoding
isn't even obfuscation. Anyone who's going to bother to open up the plist can read and writeNSCoding
in less than a minute. Same for turning this into anNSData
. Same for storing it in SQLite or Core Data.@CocoaFu's suggestion of
NSDataWritingFileProtectionComplete
is clever, but I doubt it will have any real impact on a jailbroken device. Once the device is unlocked, the OS will will decrypt any file for you, so it's no barrier at all to someone who knows the device's PIN.
相关问答
更多-
磁盘缓存时加密(Encryption while disk caching)[2021-12-12]
谢谢你没有回复:P 但我最终最终解决了它。 这就是我所做的,也许它会帮助其他任何人。 我所要做的就是创建一个自定义磁盘缓存和自定义下载器。 在自定义磁盘缓存类中,在UIL将字节流写入文件的方法中,我加密了字节流。 在自定义下载程序中,我重写了从文件中获取字节流并对其进行解密的方法。 Thanks for not replying :P But I did eventually end up solving it. And here is what I did, maybe It will help anyo ... -
如何将图像保存到磁盘(how save image to disk)[2023-05-08]
您不需要virtualFile 。 您已经在imageStringBugger拥有了图像数据。 从而: with file('filename_to_save_to.png', 'wb') as f: f.write(imageStringBuffer) 足够。 def handle_uploaded_file(f): with open('imgepath', 'wb+') as destination: for chunk in f.chunks(): ... -
如果你对选择有约束力,用户也可以篡改这些值。 只需验证隐藏字段就像使用其他输入一样。 不要担心漂亮的反馈,如果值超出范围,就抛出异常。 如果有人试图摆弄你的表格,谁会在乎他是否有丑陋的错误。 我想更简洁地回答你的问题:你不能防止篡改客户端,你所能做的只是验证 - 服务器端 If you were binding to the select a user could tamper with those values too. Just validate the hidden field like you wo ...
-
使用FMOD将输出保存到磁盘(Save output to disk using FMOD)[2021-12-31]
要将发送到磁盘的所有内容重定向到磁盘,只需使用System :: setOutput函数并传入FMOD_OUTPUTTYPE_WAVWRITER值。 确保在调用System :: init之前调用此函数,完成调用System :: release后,可执行文件旁边会出现一个wav文件。 您还可以通过System :: init extradriverdata参数传递完整路径来指定输出wav文件的名称和位置。 To redirect everything that would go to the speake ... -
防止查询字符串篡改(Prevent query string tampering)[2023-07-16]
无论是通过$_GET查询篡改还是通过基于cURL的查询,您都无法阻止用户进行篡改,这就是它的方式,但是您可以通过使用加密或令牌使用户更难以篡改。 假设您有任何类型的用户输入,它可能会被篡改。 快速说明,我不是任何想象力的密码学专家,所以不要把它作为佳能。 你应该根据自己的需要做更多的研究。 如果您需要保留已登录用户的数据,您应该考虑使用会话而不是通过$_GET查询传递。 双向数据加密: 根据您的需要, openssl可能是一种选择。 如果我想传输数据但是不一定希望最终用户以纯文本形式查看,我会使用这种类型的 ... -
将值保存到磁盘并防止篡改的最佳方法?(Best way to save values to disk and prevent tampering? (Without over-the-top encryption))[2023-12-05]
AES可能比它的价值更麻烦。 就像我尊重Jeff LaMarche一样,这种实现并不好。 这对于这个目的来说已经足够了,但除非你理解它的正确性和错误,否则不能在我看来复制它。 我通过使用CommonCrypto的AES正确加密,详细讨论了这个问题,并包括如何正确地进行AES; 但是你可能不想在这里正确地做正确的AES麻烦,如果你做的话它也不会给你带来太大帮助。 我的建议是一个简单的校验和哈希: - (NSUInteger)checksumForScore:(NSUInteger)score player:( ... -
将数组保存到磁盘(Save an array to disk)[2024-02-27]
一般的解决方案很简单: myvar = ind{1}; save myfilename myvar; load myfilename; 如果未指定变量,则save / load处理工作区/文件中的所有变量。 您可以保存/加载多个特定变量: save myfilename; save myfilename myvar1; save myfilename myvar2; save myfilename myvar1 myvar2; load myfilename; load myfilename myva ... -
除了POST和Post / Redirect /获取建议..一般情况下: 永远不要相信您在HTTP请求中收到的任何信息(包括GET参数,POSTed数据,Cookie和HTTP标头)。 始终确保用户有权对相关数据对象执行每个操作,并且在接受和处理数据之前,始终在服务器端验证数据是否合理。 In addition to the POST and Post/Redirect/Get advice.. In general: Never ever trust any of the information you ...
-
在JSF中,如果使用required="true"明确设置了这些字段,则应该已经不可能了。 如果省略这个和/或替换自定义验证器或者在bean操作方法中进行验证,那么机器人确实能够篡改表单。 因此,要解决此问题,请将显式required="true"添加到具有硬服务器端值的必填字段(因此不需要例如required="#{not empty param.foo}"或者客户端/机器人可以控制param.foo )。 由于视图状态存储在服务器端,因此webbot无法显示/修改状态。 至少,这就是理论。 或者它必须是 ...
-
它看起来好像您在带Retina显示器的Mac上运行您的代码。 如果是这种情况,答案就在这里: 如何保存JavaFX Canvas的高DPI快照 It looks as if you are running your code on a Mac with Retina display. If that is the case, the answer is here: How to save a high DPI snapshot of a JavaFX Canvas