android4.0修改bug系列二

1,、在launcher中隐藏不需要的widget,例如隐藏“路况”

packages/apps/Launcher2/src/com/android/launcher2/AppsCustomizePagedView.java

在updatePackages() 中
   有一下代码
        for (AppWidgetProviderInfo widget : widgets) {
            if (widget.minWidth > 0 && widget.minHeight > 0) {
                if(widget.toString().contains("TrafficAppWidget"))  //路况widget的名字包括字符串“TrafficAppWidget
                {
                        continue;
                }

                 mWidgets.add(widget);
            } else {
                Log.e(LOG_TAG, "Widget " + widget.provider + " has invalid dimensions (" +
                        widget.minWidth + ", " + widget.minHeight + ")");
            }

2.是机器进入recover模式,并且重启

try {
                    Runtime.getRuntime().exec("go_recovery");
                      new Thread().sleep(2000);
                      Runtime.getRuntime().exec(new String[]{"su","-c","reboot now"});
                       } catch (Exception e) {
                       // TODO: handle exception
                     e.printStackTrace();
                      }
3.删除不需要的语言,例如删除西班牙语和葡萄牙语
frameworks/base/core/java/com/android/internal/app/LocalePicker.java中加入标记的这几行就可以把这两种语言去除
        for (int i = 0 ; i < origSize; i++ ) {
            final String s = locales[i];
            final int len = s.length();
            if (len == 5) {
                String language = s.substring(0, 2);
                String country = s.substring(3, 5);
             
  if(language.equals("es"))
                {
                        continue;
                }
                if(language.equals("pt"))
                {
                        continue;
                }

                final Locale l = new Locale(language, country);
.........
4.launcher是如把应用加载到主界面,
  public void add(ApplicationInfo info) {
        if (findActivity(data, info.componentName)) {
            return;
        }
.......
// 这个表示在主界面中不显示这包名为这两个的应用。
       if("com.spreadwin.factorytest.JH".equals(info.componentName.getPackageName())||
               "com.spreadwin.s.test".equals(info.componentName.getPackageName()))
        {
               return;
        }
.......
      data.add(info);
        added.add(info);
    }

5.launcher中强制显示没有CATEGORY_LAUNCHER这种属性的应用
    private static List<ResolveInfo> findActivitiesForPackage(Context context, String packageName) {
        final PackageManager packageManager = context.getPackageManager();
        final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        if(packageName.equals("com.spreadwin.factorytest.JH")||packageName.equals("com.spreadwin.s.test"))
        {
                mainIntent.setPackage(packageName);
                Log.i("zhou", "findActivitiesForPackage--"+packageName);
        }
        else
        {
                mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            mainIntent.setPackage(packageName);
        }

        final List<ResolveInfo> apps = packageManager.queryIntentActivities(mainIntent, 0);
        return apps != null ? apps : new ArrayList<ResolveInfo>();
    }

6.在launcher中的launcher.java文件中注册T卡的插拔广播

在oncreate里面加入registersdcard()函数。

 private void registersdcard() {
        if(sdcardReceiver==null)
        {
                sdcardReceiver = new BroadcastReceiver() {
                        @Override

                public void onReceive(Context context, Intent intent) {
                                 if(intent.getAction().equals(Intent.ACTION_MEDIA_MOUNTED))
                                        {
//                                       Log.i("sdcard", "sdcard ----mount");
//                                       AppConfigCommon.sdcardflag=true;
                                         Intent intent_1=new Intent();
                                         intent_1.setAction("com.spreadwin.sdcard.in");
                                         context.sendBroadcast(intent_1);
                                        File chumo_file=new File("/mnt/extsd/chumo.ini");
                                        if(chumo_file.exists())
                                         {
                                                 Intent chumointent=new Intent();
                                                 chumointent.setClassName("org.zeroxlab.util.tscal", "org.zeroxlab.util.tscal.TSCalibration");
                                                 chumointent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                                 startActivity(chumointent);
                                         }


                                        }else if(intent.getAction().equals(Intent.ACTION_MEDIA_REMOVED)
                                                        ||intent.getAction().equals(Intent.ACTION_MEDIA_UNMOUNTED)
                                                        ||intent.getAction().equals(Intent.ACTION_MEDIA_BAD_REMOVAL))
                                        {
//                                               Log.i("sdcard", "sdcard ----unmount");
//                                              AppConfigCommon.sdcardflag=false;
                                                Intent intent_2=new Intent();
                                                 intent_2.setAction("com.spreadwin.sdcard.out");
                                                 context.sendBroadcast(intent_2);


                                        }
                }
        };
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);
        filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        filter.addAction(Intent.ACTION_MEDIA_REMOVED);
        filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
        filter.addDataScheme("file");
        registerReceiver(sdcardReceiver, filter);
        }
    }

7.在launcher中实现插拔T卡时,进行安装卸载,其实有一个类叫LauncherModel.java,他是继续

 @Override
    public void onReceive(Context context, Intent intent) {
        if (DEBUG_LOADERS) Log.d(TAG, "onReceive intent=" + intent);


        final String action = intent.getAction();


        if (Intent.ACTION_PACKAGE_CHANGED.equals(action)
                || Intent.ACTION_PACKAGE_REMOVED.equals(action)
                || Intent.ACTION_PACKAGE_ADDED.equals(action)) {
            final String packageName = intent.getData().getSchemeSpecificPart();
            final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
            int op = PackageUpdatedTask.OP_NONE;
            if (packageName == null || packageName.length() == 0) {
                // they sent us a bad intent
                return;
            }
            if (Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
                op = PackageUpdatedTask.OP_UPDATE;
            } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
                if (!replacing) {
                    op = PackageUpdatedTask.OP_REMOVE;
                }
                // else, we are replacing the package, so a PACKAGE_ADDED will be sent
                // later, we will update the package at this time
            } else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
                if (!replacing) {
                    op = PackageUpdatedTask.OP_ADD;
                } else {
                    op = PackageUpdatedTask.OP_UPDATE;
                }
            }
            if (op != PackageUpdatedTask.OP_NONE) {
                enqueuePackageUpdated(new PackageUpdatedTask(op, new String[] { packageName }));
            }
        }

一下部分就是接收到了第6条中发过来的广播。

else if("com.spreadwin.sdcard.in".equals(action)||"com.spreadwin.sdcard.out".equals(action))
        {
                final String packagename2="com.spreadwin.s.test";
            final String packagename3="com.spreadwin.factorytest.JH";
            int op = PackageUpdatedTask.OP_NONE;
            if ("com.spreadwin.sdcard.in".equals(action)) {
                 op = PackageUpdatedTask.OP_ADD;
//               Log.i("out", "com.spreadwin.sdcard.in");
            } else if ("com.spreadwin.sdcard.out".equals(action)) {
//               Log.i("out", "com.spreadwin.sdcard.out");
                    op = PackageUpdatedTask.OP_REMOVE;
                }
                // else, we are replacing the package, so a PACKAGE_ADDED will be sent
                // later, we will update the package at this time
            if (op != PackageUpdatedTask.OP_NONE) {
                {
                        enqueuePackageUpdated(new PackageUpdatedTask(op, new String[] { packagename2,packagename3}));
                }
            }
        }

........................省掉

}

内部类 private class PackageUpdatedTask implements Runnable ,在run()方法中进行安装和卸载操作

        public void run() {
            final Context context = mApp;


            final String[] packages = mPackages;
            final int N = packages.length;
            switch (mOp) {
                case OP_ADD:
                    for (int i=0; i<N; i++) {
                        if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.addPackage " + packages[i]);
//                        mAllAppsList.addPackage(context, packages[i]);
                        tcardfile=new File("/mnt/extsd/setting.ini");
                        if(!tcardfile.exists())
                        {
//                              Log.i("yang", "tcardfile.exists---no add");

//判断tcardfile文件是否存在,不存在时,遇到这两个包就不进行加载,其他包仍然进行加载
                                 for(int j=0;j<mAllAppsList.size()-1;j++)
                             {
                                if("com.spreadwin.factorytest.JH".equals(mAllAppsList.get(j).componentName.getPackageName())||
                                        "com.spreadwin.s.test".equals(mAllAppsList.get(j).componentName.getPackageName())       )
                                {
                                        continue;
                                }
                                else
                                {
                                   mAllAppsList.addPackage(context, packages[i]);
                                   continue;


                                }


                             }


                        }

//如果tcardfile文件存在,遇到这两个把就进行加载

  else if(tcardfile.exists())
                        {
//                              Log.i("yang", "tcardfile.exists---add");
                                for(int j=0;j<mAllAppsList.size()-1;j++)
                            {
                                if("com.spreadwin.factorytest.JH".equals(mAllAppsList.get(j).componentName.getPackageName())||
                                        "com.spreadwin.s.test".equals(mAllAppsList.get(j).componentName.getPackageName())       )
                                {
                                        mAllAppsList.addPackage(context, packages[i]);
                                        continue;
                                }
                                else
                                {
                                        mAllAppsList.addPackage(context, packages[i]);
                                        continue;
                                }


                            }


                        }

                    }
                    break;

 case OP_UPDATE:
                    for (int i=0; i<N; i++) {
                        if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.updatePackage " + packages[i]);
                        mAllAppsList.updatePackage(context, packages[i]);
                    }
                    break;
                case OP_REMOVE:
                case OP_UNAVAILABLE:
                    for (int i=0; i<N; i++) {
                        if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.removePackage " + packages[i]);
                       if(packages[i].equals("com.android.camera"))
                       {
                           AppConfigCommon.cameraexits=false;
                       }


                       for(int j=0;j<mAllAppsList.size()-1;j++)
                       {


                        if("com.spreadwin.factorytest.JH".equals(mAllAppsList.get(j).componentName.getPackageName()))
                        {
                                mAllAppsList.removePackage(packages[i],1);
                                continue;
                        }
                        if("com.spreadwin.s.test".equals(mAllAppsList.get(j).componentName.getPackageName()))
                        {
                                mAllAppsList.removePackage(packages[i],1);
                                continue;
                        }
                       }


                        mAllAppsList.removePackage(packages[i]);
                    }
                    break;
            }

。。。。。。。省掉

8.实现7之前要先在LauncherApplication.java中的oncreate()中加入这个launchermodle的注册

filter = new IntentFilter(); 
     filter.addAction("com.spreadwin.sdcard.in");
     filter.addAction("com.spreadwin.sdcard.out");
     registerReceiver(mModel, filter);

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值