Pages:  1 2 3 4 5 6 7 ... 21 22
lytsing – Page 6 – lytsing's Blog

Author: lytsing

  • PHP: Thread Safety disable

    Debug php core dump 文件,遇到:No symbol “executor_globals” in current context. PHP EG在非多线程情况下 executor_globals 保持了很多执行状态。需要把 Thread Safety 关闭掉,使用 <?php phpinfo(); ?> 即可看出是否支持。我所用的版本是 php-5.4.4 httpd-2.4.2,先编译apache,./configure 带上

     --with-mpm=prefork

    prefork模式,实现了一个非线程型的、预派生的web服务器,还有另外一个是 worker模式,支持多线程多进程。
    php ./configure 带上

    --with-apxs2=/usr/local/apache2/bin/apxs 

    参考:

  • BlackBerry 学习杂记

    我们收到BlackBerry 提供一部9800 手机,三本书《黑莓(BlackBerry)开发从入门到精通》。大概翻翻这本不是很厚的书,写应用跟gtk类似,精髓部分是 push。

    开发环境搭建,花了一个下午的时间尝试,不支持在 Linux 下开发,最佳开发环境是windows,mac 扭扭捏捏支持,但无法运行模拟器,只能编译好了,debug跑在真机上,把app package 到真机,花的时间特别长,而且每装个应用,都得重启系统,对于开发很不方便。BB申请签名,准备挨20美刀,填写表单时,她告诉我,BlackBerry Code Signing Keys are now absolutely free! 看来书与文档过时很快。

    其中,我们比较关心音频播放与录音,在sdk 可以 import很多 samples 示例,Record audio in a BlackBerry device application 是不错的参考 demo。浏览官方开发网站,提供了很多代码,一些放在github上,也值得看看。貌似BB开发者不是很多,Google一些API代码,搜索记录寥寥无几。我们公司就只有客服MM使用BlackBerry,那是一个很特别的女孩。BlackBerry对我们提供很好技术支持,我们也要努力加油,尽快开发出BB 客户端。

  • Sqaure 类产品在Android 机型上的适配问题

    我们已经公布了 盒子支付客户端支持机型列表 ,而Sqaure 也很早在他们帮助中心提示用户他们对Android 设备的兼容情况。很多用户很关心他们的机型为什么不支持。

    众所周知,Android碎片化的问题确实困扰的不少的应用开发商,Animoca 公司最近也大倒苦水,他们购买了400多款手机对应用进行质量测试。

    有人问,为何Square与国内的一些公司支持的 Android 机型比你们更多?因为他们跟盒子支付的音频数据方式完全不一样,他们传输数据量小,通讯不加密且只能单向通讯。实现原理比较简单:通过MIC口实现数据接收,使用 android.media.AudioRecord 实现录音,并对采集下来的模拟信号进行处理。主流的音频通讯速率 1.1k/2.2K,传输的数据有限,对于数据量大,也就需要做更多的校验,保证数据传输正确。

    那难点在哪呢?

    一、硬件问题
    1. Android 厂商硬件配置不一致,需要购买很多机型一个个去调试。
    2. 音频口供电电压高低不一,电压不够带动驱动的,需要加上电池供电。
    3. 音频口引脚接线也尽不相同。像 moto xt800,有些厂家针对这款机器在硬件上做了适配。
    4. 录音得出的波形不满足要求,录音失真,回路干扰等。
    5. 音频口硬件接触不良,插口比较宽或比较深。
    6. 输出过大。

    二、软件问题
    厂商修改 framework 层代码。一些手机原装ROM可以跑,但刷了第三方ROM就出现了问题。传说中的小米手机统常出现线程操作问题,乱跑。

  • Android 屏蔽线控耳机

    研究了Square Android 应用,它在刷卡界面监测耳机按钮事件,全部屏蔽掉线控事件。

    MediaButtonDisabler.java:

    package org.lytsing.square;
    
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.content.IntentFilter;
    import android.util.Log;
    
    public class MediaButtonDisabler extends BroadcastReceiver {
    
        private static final String TAG = "MediaButtonDisabler";
    
        private static final BroadcastReceiver INSTANCE = new MediaButtonDisabler();
    
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(TAG, "Intercepted media button.");
    
            abortBroadcast();
        }
    
        public static void register(Context context) {
            IntentFilter filter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON);
            filter.setPriority(Integer.MAX_VALUE);
            context.registerReceiver(INSTANCE, filter);
        }
    
        public static void unregister(Context context) {
            context.unregisterReceiver(INSTANCE);
        }
    }

    简要说明,设置过滤优先级为最高,int 的最大值(2^32 – 1 = 2147483647),这样,就会在第一时间把线控事件的广播中止,使其他应用无法接收到。

    在Activity 调用:

        @Override
        protected void onPause() {
            super.onPause();
            
            MediaButtonDisabler.unregister(this);
        }
        
        @Override
        protected void onResume() {
            super.onResume();
            
            MediaButtonDisabler.register(this);
        }

    另外,我们发现一些Android手机在音频口插入我们的盒子读卡器后,音乐播放器乱放,反复播放又暂停又播放,开始以为是线控问题,屏蔽掉后,问题依旧。有做这方便的朋友,可以交流交流,分享一下。

  • Downlodas 之 ByUri.startDownloadByUri

    很久以前写过一篇《How to Use Android Downloads Provider》,到了Android 2.2(froyo),Android 提供了更优雅的接口:

    public static long startDownloadByUri(Context context,
                                          String url,
                                          String cookieData,
                                          boolean showDownload,
                                          int downloadDestination,
                                          boolean allowRoaming,
                                          boolean skipIntegrityCheck,
                                          String title,
                                          String notification_package,
                                          String notification_class,
                                          String notification_extras)

    当然这些接口都是hide的,做ROM系统开发的才可以直接使用,用mmm方式编译。签于这个原因,一些国内第三方电子市场直接拿Downloads组件的代码修改成自己的提供使用。代码实现在:

    [deli@violet frameworks]$ find . -type f -name Downloads.java
    ./base/core/java/android/provider/Downloads.java
    ./base/core/java/android/net/Downloads.java

    还有 packages/providers/DownloadProvider

    startDownloadByUri 即这个函数很容易理解,有网友给我发email说不知道如何使用,我贴出系统升级使用的代码片段,希望对大家有帮助。

    [deli@violet update]$ cat Download.java

    /*
     * Copyright (C) 2010 lytsing.org
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     *      http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */
    
    package com.google.android.gsf.update;
    
    import com.google.android.gsf.R;
    
    import android.content.Context;
    import android.util.Log;
    import android.net.Downloads;
    
    public class Download {
    
        private final Context mContext;
    
        private String mNotificationClass;
    
        private String mNotificationPackage;
    
        public Download(Context context) {
            mContext = context;
            mNotificationPackage = context.getPackageName();
            mNotificationClass = SystemUpdateService.Receiver.class.getName();
        }
    
        public boolean downloadUpdate(String url, boolean showDownload, boolean allowRoaming) {
            removeAllDownloads();
            try {
                if (Downloads.ByUri.startDownloadByUri(
                            mContext,
                            url,
                            null,
                            showDownload,
                            2,
                            allowRoaming,
                            true,
                            mContext.getString(R.string.system_update_downloading_notification_title),
                            mNotificationPackage,
                            mNotificationClass,
                            null)== -1) {
                    Log.w("update.Download", "Could not insert download entry into provider");
                    return false;
                } 
    
                Log.i("update.Download",new StringBuilder()
                        .append("Started a new update download: ").append(url).toString());
            } catch (Exception e) {
                Log.e("update.Download", "Could not start update download", e);
                return false;
            }
    
            return true;
        }
    
        public Downloads.StatusInfo getStatus(String url) {
            return Downloads.ByUri.getStatus(mContext, url, 24 * 3600 * 1000);
        }
    
        public void removeAllDownloads() {
            Log.v("update.Download", "deleting all update downloads");
            try {
                Downloads.ByUri.removeAllDownloadsByPackage(mContext, mNotificationPackage,
                        mNotificationClass);
            } catch (Exception ex) {
                Log.e("update.Download", "Couldn\'t delete downloads", ex);
            }
        }
    }