Android Open Source - K6nele Caller






From Project

Back to project page K6nele.

License

The source code is released under:

Apache License

If you think the Android project K6nele listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2011-2013, Institute of Cybernetics at Tallinn University of Technology
 */*from   w w  w  . j  a va 2  s  .c om*/
 * 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 ee.ioc.phon.android.speak;

import android.app.PendingIntent;
import android.os.Bundle;

/**
 * <p>Description of the caller that receives the transcription.
 * If the extras specify a pending intent (I've never encountered such an app though),
 * then the pending intent's target package's name is returned.</p>
 *
 * <p>Otherwise we use EXTRA_CALLING_PACKAGE because there does not seem to be a way to
 * find out which Activity called us, i.e. this does not work:</p>
 *
 * <pre>
 * ComponentName callingActivity = getCallingActivity();
 * if (callingActivity != null) {
 *     return callingActivity.getPackageName();
 * }
 * </pre>
 *
 * <p>The above tries to detect the "primary caller" (e.g. a keyboard app). We also
 * look for the "secondary caller" (e.g. an app in which the keyboard is used).
 * by parsing the extras looking for another package name, e.g. included in the
 * <code>android.speech.extras.RECOGNITION_CONTEXT</code> extra which some keyboard
 * apps set.</p>
 *
 * <p>The caller description can be obtained in two ways. First a string in the form
 * "1st-caller/2nd-caller" which can be used as a User-Agent string. Examples:</p>
 *
 * <ul>
 * <li>VoiceIME/com.google.android.apps.plus (standard keyboard in Google Plus app)</li>
 * <li>SwypeIME/com.timsu.astrid</li>
 * <li>mobi.mgeek.TunnyBrowser/null</li>
 * <li>null/null (if no caller-identifying info was found in the extras)</li>
 * </ul>
 *
 * <p>Secondly, we try to determine which caller string is more informative so
 * that it can be used in the Apps-database, for counting, and server/grammar assignment.
 * There should be no difference in terms of grammar assigning if speech recognition
 * in the app is used via the keyboard or via a dedicated speech input button.</p>
 */
public class Caller {

    private static final String KEY_PACKAGE_NAME = "packageName";

  private final String mPrimaryCaller;
  private final String mSecondaryCaller;

  public Caller(PendingIntent pendingIntent, Bundle bundle) {
    if (pendingIntent == null) {
      mPrimaryCaller = bundle.getString(RecognizerIntent.EXTRA_CALLING_PACKAGE);
    } else {
      mPrimaryCaller = pendingIntent.getTargetPackage();
    }
    mSecondaryCaller = getPackageName(bundle);
  }


  public String getActualCaller() {
    if (mSecondaryCaller == null) {
      if (mPrimaryCaller == null) {
        return "null";
      }
      return mPrimaryCaller;
    }
    return mSecondaryCaller;
  }


  public String toString() {
    return mPrimaryCaller + "/" + mSecondaryCaller;
  }


  /**
   * <p>Traverses the given bundle (which can contain other bundles)
   * looking for the key "packageName".
   * Returns its corresponding value if finds it.</p>
   *
   * @param bundle bundle (e.g. intent extras)
   * @return package name possibly hidden deep into the given bundle
   */
  private static String getPackageName(Bundle bundle) {
    Object obj = Utils.getBundleValue(bundle, KEY_PACKAGE_NAME);
    if (obj instanceof String) {
      return (String) obj;
    }
    return null;
  }

}




Java Source Code List

ee.ioc.phon.android.speak.AboutActivity.java
ee.ioc.phon.android.speak.AppListActivity.java
ee.ioc.phon.android.speak.AppListCursorAdapter.java
ee.ioc.phon.android.speak.AudioCue.java
ee.ioc.phon.android.speak.AudioPauser.java
ee.ioc.phon.android.speak.Caller.java
ee.ioc.phon.android.speak.ChunkedWebRecSessionBuilder.java
ee.ioc.phon.android.speak.Constants.java
ee.ioc.phon.android.speak.DetailsActivity.java
ee.ioc.phon.android.speak.ExecutableString.java
ee.ioc.phon.android.speak.Executable.java
ee.ioc.phon.android.speak.Extras.java
ee.ioc.phon.android.speak.GetLanguageDetailsReceiver.java
ee.ioc.phon.android.speak.GrammarListActivity.java
ee.ioc.phon.android.speak.Log.java
ee.ioc.phon.android.speak.MicButton.java
ee.ioc.phon.android.speak.OnSwipeTouchListener.java
ee.ioc.phon.android.speak.PackageNameRegistry.java
ee.ioc.phon.android.speak.PreferencesRecognitionServiceHttp.java
ee.ioc.phon.android.speak.PreferencesRecognitionServiceWs.java
ee.ioc.phon.android.speak.Preferences.java
ee.ioc.phon.android.speak.RawAudioRecorder.java
ee.ioc.phon.android.speak.RecognizerIntentActivity.java
ee.ioc.phon.android.speak.RecognizerIntentListActivity.java
ee.ioc.phon.android.speak.RecognizerIntentService.java
ee.ioc.phon.android.speak.RecognizerIntent.java
ee.ioc.phon.android.speak.ServerListActivity.java
ee.ioc.phon.android.speak.SpeechRecognitionService.java
ee.ioc.phon.android.speak.Utils.java
ee.ioc.phon.android.speak.VoiceImeService.java
ee.ioc.phon.android.speak.VoiceImeView.java
ee.ioc.phon.android.speak.WebSocketRecognizer.java
ee.ioc.phon.android.speak.WebSocketResponse.java
ee.ioc.phon.android.speak.demo.AbstractRecognizerDemoActivity.java
ee.ioc.phon.android.speak.demo.ExtrasDemo.java
ee.ioc.phon.android.speak.demo.RepeaterDemo.java
ee.ioc.phon.android.speak.demo.SimpleDemo.java
ee.ioc.phon.android.speak.demo.VoiceSearchDemo.java
ee.ioc.phon.android.speak.provider.App.java
ee.ioc.phon.android.speak.provider.AppsContentProvider.java
ee.ioc.phon.android.speak.provider.BaseColumnsImpl.java
ee.ioc.phon.android.speak.provider.FileContentProvider.java
ee.ioc.phon.android.speak.provider.Grammar.java
ee.ioc.phon.android.speak.provider.Server.java