Example #1
1
  public Intent getIntent() {

    if (mIntent != null) {
      return mIntent;
    }
    if (mShortcutUrl != null) {
      try {
        mIntent = Intent.parseUri(mShortcutUrl, 0);
        mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
      } catch (URISyntaxException e) {
        e.printStackTrace();
      }
    } else if (getCategoryComponentName() != null) {
      mIntent = new Intent(Intent.ACTION_MAIN);
      mIntent.setComponent(mComponentName);
      if (!SearchActivity.class.getName().equals(mComponentName.getClassName())) {
        mIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
      } else {
        mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      }
    }
    return mIntent;
  }
Example #2
0
  public final ViewGroup createView(Context context, ComponentName providerName) {
    try {
      Class<?> clazz = Class.forName(providerName.getClassName());
      Class[] paramTypes = {Context.class};
      Object[] params = {Launcher.getInstance()}; // 方法传入的参数
      Constructor con = clazz.getConstructor(paramTypes); // 主要就是这句了
      RelativeLayout base = (RelativeLayout) con.newInstance(params); // BatcherBase

      if (base != null) {
        hostView = new CooeeWidgetView(context);
        hostView.addView(base);
        return hostView;
      } else {
        return null;
      }
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (NoSuchMethodException e) {
      e.printStackTrace();
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
    }
    return null;
  }
 @Override
 public void onServiceDisconnected(ComponentName componentName) {
   if (SinchService.class.getName().equals(componentName.getClassName())) {
     mSinchServiceInterface = null;
     onServiceDisconnected();
   }
 }
  @Override
  public ActivityInfo getActivityInfo(ComponentName className, int flags)
      throws NameNotFoundException {
    String packageName = className.getPackageName();
    AndroidManifest androidManifest = androidManifests.get(packageName);
    String activityName = className.getClassName();
    ActivityData activityData = androidManifest.getActivityData(activityName);
    ActivityInfo activityInfo = new ActivityInfo();
    activityInfo.packageName = packageName;
    activityInfo.name = activityName;
    if (activityData != null) {
      activityInfo.parentActivityName = activityData.getParentActivityName();
      activityInfo.metaData = metaDataToBundle(activityData.getMetaData().getValueMap());
      ResourceIndex resourceIndex = shadowsAdapter.getResourceLoader().getResourceIndex();
      String themeRef;

      // Based on ShadowActivity
      if (activityData.getThemeRef() != null) {
        themeRef = activityData.getThemeRef();
      } else {
        themeRef = androidManifest.getThemeRef();
      }
      if (themeRef != null) {
        ResName style = ResName.qualifyResName(themeRef.replace("@", ""), packageName, "style");
        activityInfo.theme = resourceIndex.getResourceId(style);
      }
    }
    activityInfo.applicationInfo = getApplicationInfo(packageName, flags);
    return activityInfo;
  }
Example #5
0
  @Override
  public ActivityInfo getReceiverInfo(ComponentName className, int flags)
      throws NameNotFoundException {
    String packageName = className.getPackageName();
    AndroidManifest androidManifest = androidManifests.get(packageName);
    String classString = className.getClassName();
    int index = classString.indexOf('.');
    if (index == -1) {
      classString = packageName + "." + classString;
    } else if (index == 0) {
      classString = packageName + classString;
    }

    ActivityInfo activityInfo = new ActivityInfo();
    activityInfo.packageName = packageName;
    activityInfo.name = classString;
    if ((flags & GET_META_DATA) != 0) {
      for (BroadcastReceiverData receiver : androidManifest.getBroadcastReceivers()) {
        if (receiver.getClassName().equals(classString)) {
          activityInfo.metaData = metaDataToBundle(receiver.getMetaData().getValueMap());
          break;
        }
      }
    }
    return activityInfo;
  }
 @Override
 public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
   if (SinchService.class.getName().equals(componentName.getClassName())) {
     mSinchServiceInterface = (SinchService.SinchServiceInterface) iBinder;
     onServiceConnected();
   }
 }
Example #7
0
  /**
   * @Description 判断是否是顶部activity
   *
   * @param context
   * @param activityName
   * @return
   */
  public static boolean isTopActivy(Context context, String activityName) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ComponentName cName =
        am.getRunningTasks(1).size() > 0 ? am.getRunningTasks(1).get(0).topActivity : null;

    if (null == cName) return false;
    return cName.getClassName().equals(activityName);
  }
Example #8
0
 private static void executeBadgeByBroadcast(
     Context context, ComponentName componentName, int badgeCount) {
   Intent intent = new Intent(INTENT_ACTION);
   intent.putExtra(INTENT_EXTRA_PACKAGE_NAME, componentName.getPackageName());
   intent.putExtra(INTENT_EXTRA_ACTIVITY_NAME, componentName.getClassName());
   intent.putExtra(INTENT_EXTRA_MESSAGE, String.valueOf(badgeCount));
   intent.putExtra(INTENT_EXTRA_SHOW_MESSAGE, badgeCount > 0);
   context.sendBroadcast(intent);
 }
Example #9
0
 /** Find an ApplicationInfo object for the given packageName and className. */
 private AppInfo findApplicationInfoLocked(String packageName, String className) {
   for (AppInfo info : data) {
     final ComponentName component = info.intent.getComponent();
     if (packageName.equals(component.getPackageName())
         && className.equals(component.getClassName())) {
       return info;
     }
   }
   return null;
 }
Example #10
0
 /** Returns whether <em>apps</em> contains <em>component</em>. */
 private static boolean findActivity(List<ResolveInfo> apps, ComponentName component) {
   final String className = component.getClassName();
   for (ResolveInfo info : apps) {
     final ActivityInfo activityInfo = info.activityInfo;
     if (activityInfo.name.equals(className)) {
       return true;
     }
   }
   return false;
 }
  public static void load(Context ctx, String pkg)
      throws NameNotFoundException, XmlPullParserException, IOException {

    sPackageName = pkg;
    Context extCtx = ctx.createPackageContext(pkg, Context.CONTEXT_IGNORE_SECURITY);
    sRes = extCtx.getResources();
    int id = sRes.getIdentifier("appfilter", "xml", sPackageName);
    boolean loadFromAssets = false;
    if (id != 0) {
      sParser = sRes.getXml(id);
    } else {
      loadFromAssets = true;
      Log.e(
          TAG,
          "Failed to get appfilter.xml from resources of package "
              + sPackageName
              + ", attempting load from assets...");
    }

    if (loadFromAssets) {
      InputStream is = sRes.getAssets().open("appfilter.xml");
      sParser = XmlPullParserFactory.newInstance().newPullParser();
      sParser.setInput(is, null);
    }

    if (sParser == null) throw new XmlPullParserException("Parser is null!");

    SharedPreferences prefs = ctx.getSharedPreferences("icon_pack", Context.MODE_PRIVATE);
    prefs.edit().clear().commit();
    SharedPreferences.Editor editor = prefs.edit();

    while (sParser.getEventType() != XmlPullParser.END_DOCUMENT) {
      int type = sParser.getEventType();
      switch (type) {
        case XmlPullParser.START_TAG:
          String currentComponent = sParser.getAttributeValue(null, "component");
          String drawable = sParser.getAttributeValue(null, "drawable");
          if (currentComponent != null) {
            ComponentName cmpName = ComponentNameParser.parse(currentComponent);
            if (cmpName != null && drawable != null) {
              int drawableId = sRes.getIdentifier(drawable, "drawable", sPackageName);
              if (drawableId != 0) {
                // TODO: replace by SQL database
                String pref = cmpName.getPackageName() + "/" + cmpName.getClassName();
                editor.putInt(pref, drawableId);
              }
            }
          }
          break;
      }

      sParser.next();
    }
    editor.commit();
  }
Example #12
0
 public static String getTopActivityName(Context context) {
   String topActivityClassName = null;
   ActivityManager activityManager =
       (ActivityManager) (context.getSystemService(android.content.Context.ACTIVITY_SERVICE));
   List<RunningTaskInfo> runningTaskInfos = activityManager.getRunningTasks(1);
   if (runningTaskInfos != null) {
     ComponentName f = runningTaskInfos.get(0).topActivity;
     topActivityClassName = f.getClassName();
   }
   return topActivityClassName;
 }
Example #13
0
 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
     ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
     List<RunningTaskInfo> runningTasks = manager.getRunningTasks(1);
     RunningTaskInfo cinfo = runningTasks.get(0);
     ComponentName component = cinfo.topActivity;
     Log.e("current activity is ", component.getClassName());
     System.out.println("类名=" + component.getClassName());
     if ((System.currentTimeMillis() - exitTime) > 2000) {
       Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
       exitTime = System.currentTimeMillis();
     } else {
       MyActivityManager.finish();
       System.exit(0);
     }
     return true;
   }
   return super.onKeyDown(keyCode, event);
 }
Example #14
0
  /**
   * Send request to Sony badge content provider to set badge in Sony home launcher.
   *
   * @param context the context to use
   * @param componentName the componentName to use
   * @param badgeCount the badge count
   */
  private void executeBadgeByContentProvider(
      Context context, ComponentName componentName, int badgeCount) {
    if (badgeCount < 0) {
      return;
    }

    if (mQueryHandler == null) {
      mQueryHandler =
          new AsyncQueryHandler(context.getApplicationContext().getContentResolver()) {};
    }
    insertBadgeAsync(badgeCount, componentName.getPackageName(), componentName.getClassName());
  }
Example #15
0
 public static ComponentName isServiceExisted(Context context, String s)
 {
     Iterator iterator = ((ActivityManager)context.getSystemService("activity")).getRunningServices(0x7fffffff).iterator();
     ComponentName componentname;
     do
     {
         if (!iterator.hasNext())
         {
             return null;
         }
         componentname = ((android.app.ActivityManager.RunningServiceInfo)iterator.next()).service;
     } while (!componentname.getPackageName().equals(s) || !componentname.getClassName().equals((new StringBuilder(String.valueOf(s))).append(".business.RemoteSSOService").toString()));
     return componentname;
 }
  /**
   * Returns true if the recording service is running.
   *
   * @param context the current context
   */
  public static boolean isRecordingServiceRunning(Context context) {
    ActivityManager activityManager =
        (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> services = activityManager.getRunningServices(Integer.MAX_VALUE);

    for (RunningServiceInfo serviceInfo : services) {
      ComponentName componentName = serviceInfo.service;
      String serviceName = componentName.getClassName();
      if (TrackRecordingService.class.getName().equals(serviceName)) {
        return true;
      }
    }
    return false;
  }
    @Override
    public void reportEvent(ComponentName component, int userId, int eventType) {
      if (component == null) {
        Slog.w(TAG, "Event reported without a component name");
        return;
      }

      UsageEvents.Event event = new UsageEvents.Event();
      event.mPackage = component.getPackageName();
      event.mClass = component.getClassName();

      // This will later be converted to system time.
      event.mTimeStamp = SystemClock.elapsedRealtime();

      event.mEventType = eventType;
      mHandler.obtainMessage(MSG_REPORT_EVENT, userId, 0, event).sendToTarget();
    }
Example #18
0
 @Override
 public void run() {
   if (remComponenName != null) {
     if (remComponenName.getClassName().equals(SCRRENOFF_ACTIVITY)) {
       openDeskLyric();
     } else {
       closeDeskLyric();
     }
     Intent intent = new Intent();
     intent.setComponent(remComponenName);
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     try {
       startActivity(intent);
     } catch (Exception e) {
     }
   }
 }
 private boolean isMtkCameraApServiceLaunched(Context context) {
   ActivityManager activityManager =
       (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
   List<ActivityManager.RunningServiceInfo> serviceList =
       activityManager.getRunningServices(Integer.MAX_VALUE);
   if (!(serviceList.size() > 0)) {
     return false;
   }
   for (int i = 0; i < serviceList.size(); i++) {
     RunningServiceInfo serviceInfo = serviceList.get(i);
     ComponentName servcieName = serviceInfo.service;
     if ("com.mediatek.camera.addition.remotecamera.service.MtkCameraService"
         .equals(servcieName.getClassName())) {
       Log.i(TAG, "isMtkCameraApServiceLaunched true");
       return true;
     }
   }
   return false;
 }
Example #20
0
  @Override
  public ServiceInfo getServiceInfo(ComponentName className, int flags)
      throws NameNotFoundException {
    String packageName = className.getPackageName();
    AndroidManifest androidManifest = androidManifests.get(packageName);
    String serviceName = className.getClassName();
    ServiceData serviceData = androidManifest.getServiceData(serviceName);
    if (serviceData == null) {
      throw new NameNotFoundException();
    }

    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.packageName = packageName;
    serviceInfo.name = serviceName;
    serviceInfo.applicationInfo = getApplicationInfo(packageName, flags);
    serviceInfo.permission = serviceData.getPermission();
    if ((flags & GET_META_DATA) != 0) {
      serviceInfo.metaData = metaDataToBundle(serviceData.getMetaData().getValueMap());
    }
    return serviceInfo;
  }
Example #21
0
  @Override
  public ActivityInfo getActivityInfo(ComponentName className, int flags)
      throws NameNotFoundException {
    ActivityInfo activityInfo = new ActivityInfo();
    String packageName = className.getPackageName();
    String activityName = className.getClassName();
    activityInfo.name = activityName;
    activityInfo.packageName = packageName;

    AndroidManifest androidManifest = androidManifests.get(packageName);

    // In the cases where there is no manifest entry for the activity, e.g: a test that creates
    // simply an android.app.Activity just return what we have.
    if (androidManifest == null) {
      return activityInfo;
    }

    ActivityData activityData = androidManifest.getActivityData(activityName);
    if (activityData != null) {
      activityInfo.parentActivityName = activityData.getParentActivityName();
      activityInfo.metaData = metaDataToBundle(activityData.getMetaData().getValueMap());
      String themeRef;

      // Based on ShadowActivity
      if (activityData.getThemeRef() != null) {
        themeRef = activityData.getThemeRef();
      } else {
        themeRef = androidManifest.getThemeRef();
      }
      if (themeRef != null) {
        activityInfo.theme =
            RuntimeEnvironment.application
                .getResources()
                .getIdentifier(themeRef.replace("@", ""), "style", packageName);
      }
    }
    activityInfo.applicationInfo = getApplicationInfo(packageName, flags);
    return activityInfo;
  }
Example #22
0
  /**
   * 获取服务是否开启
   *
   * @param context
   * @param className 服务的全类名
   * @return 服务开启的状态
   */
  public static boolean isRunningService(Context context, String className) {
    boolean isRunning = false;
    // 这里是进程的管理者,活动的管理者
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    // 获取正在运行的服务,maxNum:上限值,如果小于上限值有多少返回多少,大于只返回上限值个数的服务
    List<ActivityManager.RunningServiceInfo> serviceInfos = am.getRunningServices(1000);
    // 遍历集合
    for (ActivityManager.RunningServiceInfo serviceInfo : serviceInfos) {
      // 先得到service component 再通过getClassName得打组件的全类名,这里不是getPackageName,因为一个应用有多个服务
      ComponentName component_Name = serviceInfo.service;
      // 获取服务全类名
      String componentName = component_Name.getClassName();

      // 判断获取类名和传递进来的类名是否一致,一致返回true表示正在运行,不一致返回false表示没有运行
      if (!TextUtils.isEmpty(className) && className.equals(componentName)) {
        // 如果包含该服务,说明服务已经开启了
        isRunning = true;
        LogUtil.i(TAG, "service is running:" + isRunning);
      }
    }
    return isRunning;
  }
  /**  * 用来判断服务是否运行.  * @param context  * @param className 判断的服务名字  * @return true 在运行 false 不在运行 */
  public static boolean isServiceRunning(Context context, String packageName, String className) {
    boolean isRunning = false;
    ActivityManager activityManager =
        (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> serviceList = activityManager.getRunningServices(30);
    if (!(serviceList.size() > 0)) {
      return false;
    }
    for (int i = 0; i < serviceList.size(); i++) {
      ComponentName cpn = serviceList.get(i).service;

      if (cpn != null) {
        String pn = cpn.getPackageName();
        String cn = cpn.getClassName();
        if (packageName.equals(pn) && className.equals(cn)) {
          isRunning = true;
          break;
        }
      }
    }

    return isRunning;
  }
    public void onClick(View v) {

      Intent intent = null;
      @SuppressWarnings("rawtypes")
      Class nextActivity = null;

      switch (buttonId) {
        case BUTTON_USERS:
          intent = new Intent(SideBarActivity.this, UsersActivity.class);
          nextActivity = UsersActivity.class;
          break;
        case BUTTON_GROUPS:
          intent = new Intent(SideBarActivity.this, GroupsActivity.class);
          nextActivity = GroupsActivity.class;
          break;
        case BUTTON_PROFILE:
          intent = new Intent(SideBarActivity.this, MyProfileActivity.class);
          nextActivity = MyProfileActivity.class;
          break;
        case BUTTON_INFORMATION:
          intent = new Intent(SideBarActivity.this, InformationActivity.class);
          nextActivity = InformationActivity.class;
          break;
        case BUTTON_SETTINGS:
          intent = new Intent(SideBarActivity.this, SettingsActivity.class);
          nextActivity = SettingsActivity.class;
          break;
        case BUTTON_LOGOUT:
          SideBarActivity.this.logout();
          break;
        case BUTTON_PRIVATE_WALL:
          intent = new Intent(SideBarActivity.this, WallActivity.class);
          nextActivity = WallActivity.class;
          break;
        case NOTIFICATIONS:
          intent = new Intent(SideBarActivity.this, RecentActivityActivity.class);
          nextActivity = RecentActivityActivity.class;
          break;
        default:
          break;
      }

      if (nextActivity == null) return;

      boolean returnToActivity =
          nextActivity.getCanonicalName().equals(componentName.getClassName());
      boolean logout = nextActivity.getCanonicalName().contains("SignInActivity");
      boolean openBaseActivity = componentName.getClassName().contains("RecentActivity");
      boolean openWall = nextActivity.getCanonicalName().contains("WallActivity");

      if (intent != null) {

        if (returnToActivity && !openWall) {
          SideBarActivity.this.closeSideBar();
        } else if (logout) {
          appLogout(false, false, false);
        } else {
          if (openWall) {
            SettingsManager.ResetSettings();
            WallActivity.gIsRefreshUserProfile = true;
            if (WallActivity.gCurrentMessages != null) {
              WallActivity.gCurrentMessages.clear();
            }
            UsersManagement.setToUser(UsersManagement.getSupportUser());
            UsersManagement.setToGroup(null);
          }
          if (openBaseActivity || openWall) {
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
          } else {
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            SideBarActivity.this.finish();
          }
          SideBarActivity.this.startActivity(intent);
          SideBarActivity.this.overridePendingTransition(
              R.anim.slide_in_right, R.anim.slide_out_left);
        }
      }
    }
Example #25
0
 @Override
 public void onCallStateChanged(int state, String incomingNumber) {
   switch (state) {
     case TelephonyManager.CALL_STATE_OFFHOOK:
       IDLE = true;
       if (myFV == null) {
         wm =
             (WindowManager)
                 currentActivity.getAppContext().getSystemService(Context.WINDOW_SERVICE);
         View view =
             LayoutInflater.from(currentActivity.getAppContext())
                 .inflate(R.layout.module_diallistener, null);
         ImageView ivClose = (ImageView) view.findViewById(R.id.dial_listener_btn_close);
         ivClose.setOnClickListener(
             new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                 // 关闭悬浮窗口
                 if (wm != null && myFV != null) {
                   wm.removeView(myFV);
                   myFV = null;
                 }
               }
             });
         TextView tvMessage = (TextView) view.findViewById(R.id.dial_listener_text);
         tvMessage.setText("您正在与" + SP_CALL_DIAL + "录音通话中…");
         myFV = new DialFloatView(currentActivity.getAppContext());
         myFV.addView(view);
         // 设置LayoutParams(全局变量)相关参数
         WindowManager.LayoutParams wmParams = myFV.getMywmParams();
         // 设置window type
         wmParams.type = LayoutParams.TYPE_PHONE;
         // 设置图片格式,效果为背景透明
         wmParams.format = PixelFormat.RGBA_8888;
         // 设置Window flag
         wmParams.flags =
             LayoutParams.FLAG_NOT_TOUCH_MODAL | LayoutParams.FLAG_NOT_FOCUSABLE;
         // 调整悬浮窗口至左上角
         wmParams.gravity = Gravity.LEFT | Gravity.TOP;
         // 以屏幕左上角为原点,设置x、y初始值
         wmParams.x = 0;
         wmParams.y = 0;
         // 设置悬浮窗口长宽数据
         wmParams.width = android.view.ViewGroup.LayoutParams.MATCH_PARENT;
         wmParams.height = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
         // 显示myFloatView图像
         wm.addView(myFV, wmParams);
       }
       break;
     case TelephonyManager.CALL_STATE_IDLE:
       // 拨打电话状态顺序1.CALL_STATE_IDLE 2.CALL_STATE_OFFHOOK
       // 3.CALL_STATE_IDLE由于只需要取最后一个CALL_STATE_IDLE所以在这里需要一个逻辑判断
       if (IDLE) {
         IDLE = false;
         // 停止监听手机通话状态
         if (manager != null) {
           manager.listen(stateListener, PhoneStateListener.LISTEN_NONE);
         }
         // 通话结束后关闭悬浮窗口
         if (wm != null && myFV != null) {
           wm.removeView(myFV);
           myFV = null;
         }
         // 设置拨打的号码为空
         BaseContext.getSharedPreferences()
             .putString(Constant.Preferences.SP_CALL_DIAL, AppConstant.EMPTYSTR);
         ActivityManager am =
             (ActivityManager) currentActivity.getSystemService(Context.ACTIVITY_SERVICE);
         ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
         if (!cn.getClassName().equals(MainActivity.class.getName())) {
           // Android4.0以上系统默认打完电话后会跳转到
           Intent intent = new Intent(currentActivity, MainActivity.class);
           intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
           currentActivity.startActivity(intent);
         }
       }
       break;
   }
 }
Example #26
0
  /**
   * Dispatches inbound messages that are in the WAP PDU format. See wap-230-wsp-20010705-a section
   * 8 for details on the WAP PDU format.
   *
   * @param pdu The WAP PDU, made up of one or more SMS PDUs
   * @return a result code from {@link android.provider.Telephony.Sms.Intents}, or {@link
   *     Activity#RESULT_OK} if the message has been broadcast to applications
   */
  public int dispatchWapPdu(byte[] pdu, BroadcastReceiver receiver, InboundSmsHandler handler) {

    if (DBG) Rlog.d(TAG, "Rx: " + IccUtils.bytesToHexString(pdu));

    try {
      int index = 0;
      int transactionId = pdu[index++] & 0xFF;
      int pduType = pdu[index++] & 0xFF;

      // Should we "abort" if no subId for now just no supplying extra param below
      int phoneId = handler.getPhone().getPhoneId();

      if ((pduType != WspTypeDecoder.PDU_TYPE_PUSH)
          && (pduType != WspTypeDecoder.PDU_TYPE_CONFIRMED_PUSH)) {
        index =
            mContext
                .getResources()
                .getInteger(com.android.internal.R.integer.config_valid_wappush_index);
        if (index != -1) {
          transactionId = pdu[index++] & 0xff;
          pduType = pdu[index++] & 0xff;
          if (DBG)
            Rlog.d(
                TAG,
                "index = "
                    + index
                    + " PDU Type = "
                    + pduType
                    + " transactionID = "
                    + transactionId);

          // recheck wap push pduType
          if ((pduType != WspTypeDecoder.PDU_TYPE_PUSH)
              && (pduType != WspTypeDecoder.PDU_TYPE_CONFIRMED_PUSH)) {
            if (DBG) Rlog.w(TAG, "Received non-PUSH WAP PDU. Type = " + pduType);
            return Intents.RESULT_SMS_HANDLED;
          }
        } else {
          if (DBG) Rlog.w(TAG, "Received non-PUSH WAP PDU. Type = " + pduType);
          return Intents.RESULT_SMS_HANDLED;
        }
      }

      WspTypeDecoder pduDecoder = new WspTypeDecoder(pdu);

      /**
       * Parse HeaderLen(unsigned integer). From wap-230-wsp-20010705-a section 8.1.2 The maximum
       * size of a uintvar is 32 bits. So it will be encoded in no more than 5 octets.
       */
      if (pduDecoder.decodeUintvarInteger(index) == false) {
        if (DBG) Rlog.w(TAG, "Received PDU. Header Length error.");
        return Intents.RESULT_SMS_GENERIC_ERROR;
      }
      int headerLength = (int) pduDecoder.getValue32();
      index += pduDecoder.getDecodedDataLength();

      int headerStartIndex = index;

      /**
       * Parse Content-Type. From wap-230-wsp-20010705-a section 8.4.2.24
       *
       * <p>Content-type-value = Constrained-media | Content-general-form Content-general-form =
       * Value-length Media-type Media-type = (Well-known-media | Extension-Media) *(Parameter)
       * Value-length = Short-length | (Length-quote Length) Short-length = <Any octet 0-30> (octet
       * <= WAP_PDU_SHORT_LENGTH_MAX) Length-quote = <Octet 31> (WAP_PDU_LENGTH_QUOTE) Length =
       * Uintvar-integer
       */
      if (pduDecoder.decodeContentType(index) == false) {
        if (DBG) Rlog.w(TAG, "Received PDU. Header Content-Type error.");
        return Intents.RESULT_SMS_GENERIC_ERROR;
      }

      String mimeType = pduDecoder.getValueString();
      long binaryContentType = pduDecoder.getValue32();
      index += pduDecoder.getDecodedDataLength();

      byte[] header = new byte[headerLength];
      System.arraycopy(pdu, headerStartIndex, header, 0, header.length);

      byte[] intentData;

      if (mimeType != null && mimeType.equals(WspTypeDecoder.CONTENT_TYPE_B_PUSH_CO)) {
        intentData = pdu;
      } else {
        int dataIndex = headerStartIndex + headerLength;
        intentData = new byte[pdu.length - dataIndex];
        System.arraycopy(pdu, dataIndex, intentData, 0, intentData.length);
      }

      if (SmsManager.getDefault().getAutoPersisting()) {
        // Store the wap push data in telephony
        long[] subIds = SubscriptionManager.getSubId(phoneId);
        // FIXME (tomtaylor) - when we've updated SubscriptionManager, change
        // SubscriptionManager.DEFAULT_SUB_ID to SubscriptionManager.getDefaultSmsSubId()
        long subId =
            (subIds != null) && (subIds.length > 0) ? subIds[0] : SmsManager.getDefaultSmsSubId();
        writeInboxMessage(subId, intentData);
      }

      /**
       * Seek for application ID field in WSP header. If application ID is found, WapPushManager
       * substitute the message processing. Since WapPushManager is optional module, if
       * WapPushManager is not found, legacy message processing will be continued.
       */
      if (pduDecoder.seekXWapApplicationId(index, index + headerLength - 1)) {
        index = (int) pduDecoder.getValue32();
        pduDecoder.decodeXWapApplicationId(index);
        String wapAppId = pduDecoder.getValueString();
        if (wapAppId == null) {
          wapAppId = Integer.toString((int) pduDecoder.getValue32());
        }

        String contentType = ((mimeType == null) ? Long.toString(binaryContentType) : mimeType);
        if (DBG) Rlog.v(TAG, "appid found: " + wapAppId + ":" + contentType);

        try {
          boolean processFurther = true;
          IWapPushManager wapPushMan = mWapPushManager;

          if (wapPushMan == null) {
            if (DBG) Rlog.w(TAG, "wap push manager not found!");
          } else {
            Intent intent = new Intent();
            intent.putExtra("transactionId", transactionId);
            intent.putExtra("pduType", pduType);
            intent.putExtra("header", header);
            intent.putExtra("data", intentData);
            intent.putExtra("contentTypeParameters", pduDecoder.getContentParameters());
            SubscriptionManager.putPhoneIdAndSubIdExtra(intent, phoneId);

            int procRet = wapPushMan.processMessage(wapAppId, contentType, intent);
            if (DBG) Rlog.v(TAG, "procRet:" + procRet);
            if ((procRet & WapPushManagerParams.MESSAGE_HANDLED) > 0
                && (procRet & WapPushManagerParams.FURTHER_PROCESSING) == 0) {
              processFurther = false;
            }
          }
          if (!processFurther) {
            return Intents.RESULT_SMS_HANDLED;
          }
        } catch (RemoteException e) {
          if (DBG) Rlog.w(TAG, "remote func failed...");
        }
      }
      if (DBG) Rlog.v(TAG, "fall back to existing handler");

      if (mimeType == null) {
        if (DBG) Rlog.w(TAG, "Header Content-Type error.");
        return Intents.RESULT_SMS_GENERIC_ERROR;
      }

      String permission;
      int appOp;

      if (mimeType.equals(WspTypeDecoder.CONTENT_TYPE_B_MMS)) {
        permission = android.Manifest.permission.RECEIVE_MMS;
        appOp = AppOpsManager.OP_RECEIVE_MMS;
      } else {
        permission = android.Manifest.permission.RECEIVE_WAP_PUSH;
        appOp = AppOpsManager.OP_RECEIVE_WAP_PUSH;
      }

      Intent intent = new Intent(Intents.WAP_PUSH_DELIVER_ACTION);
      intent.setType(mimeType);
      intent.putExtra("transactionId", transactionId);
      intent.putExtra("pduType", pduType);
      intent.putExtra("header", header);
      intent.putExtra("data", intentData);
      intent.putExtra("contentTypeParameters", pduDecoder.getContentParameters());
      SubscriptionManager.putPhoneIdAndSubIdExtra(intent, phoneId);

      // Direct the intent to only the default MMS app. If we can't find a default MMS app
      // then sent it to all broadcast receivers.
      ComponentName componentName = SmsApplication.getDefaultMmsApplication(mContext, true);
      if (componentName != null) {
        // Deliver MMS message only to this receiver
        intent.setComponent(componentName);
        if (DBG)
          Rlog.v(
              TAG,
              "Delivering MMS to: "
                  + componentName.getPackageName()
                  + " "
                  + componentName.getClassName());
      }

      handler.dispatchIntent(intent, permission, appOp, receiver, UserHandle.OWNER);
      return Activity.RESULT_OK;
    } catch (ArrayIndexOutOfBoundsException aie) {
      // 0-byte WAP PDU or other unexpected WAP PDU contents can easily throw this;
      // log exception string without stack trace and return false.
      Rlog.e(TAG, "ignoring dispatchWapPdu() array index exception: " + aie);
      return Intents.RESULT_SMS_GENERIC_ERROR;
    }
  }
Example #27
0
 public static String getTopActivity(Context context) {
   ActivityManager am = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);
   ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
   return cn.getClassName();
 }
Example #28
0
  public void swap3rdappTvapp() {
    ActivityManager mActivityManager =
        (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> runningTaskList = mActivityManager.getRunningTasks(8);
    List<RunningTaskInfo> newRunningTaskList = mActivityManager.getMtkRunningTasks();

    if (runningTaskList.size() > newRunningTaskList.size()) {
      int i = 0, j = 0;
      while (i < runningTaskList.size() && j < newRunningTaskList.size()) {
        RunningTaskInfo child = runningTaskList.get(i);
        RunningTaskInfo newChild = newRunningTaskList.get(i);
        if (child.id != newChild.id) {
          runningTaskList.remove(i);
        } else {
          i++;
          j++;
        }
      }
      while (i < runningTaskList.size()) {
        runningTaskList.remove(i);
      }
    }

    if (runningTaskList != null && runningTaskList.size() > 1) {
      RunningTaskInfo currenTaskInfo = runningTaskList.get(0);
      ComponentName currentActivity = runningTaskList.get(0).topActivity;

      GetCurrentTask ct = GetCurrentTask.getInstance(mContext);

      if ("com.mediatek.ui.TurnkeyUiMainActivity".equals(currentActivity.getClassName())) {
        Intent mIntent = new Intent(START_ACTION);
        mContext.sendBroadcast(mIntent);
        if (mBreComponentName) {
          pauseMainOutput();

          try {
            ActivityManagerNative.getDefault().moveTaskToFront(mLastTastId, 0, null);
          } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }

          myHandler.removeMessages(MessageType.MESSAGE_FOR_CHECK_SWAP);
          MtkLog.d(TAG, "come in send MessageType.MESSAGE_FOR_CHECK_SWAP");
          myHandler.sendEmptyMessageDelayed(MessageType.MESSAGE_FOR_CHECK_SWAP, 700);
        }
      } else {
        if (ct.isCurActivtyMeidaMainActivity()) {
          toastNofunction();
          return;
        }

        if (!ct.isCurTaskTKUI()) {
          mBreComponentName = true;
          mLastTastId = currenTaskInfo.id;

          changeModeToNormal();

          try {
            for (int i = 0; i < runningTaskList.size(); i++) {
              if ("com.mediatek.ui.TurnkeyUiMainActivity"
                  .equals(runningTaskList.get(i).baseActivity.getClassName())) {
                ActivityManagerNative.getDefault()
                    .moveTaskToFront(runningTaskList.get(i).id, 0, null);
                break;
              }
            }
          } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }
    }
  }