Correct handling of Launch Browser command.

1) Stk: Create STK Default Url via System Property

- Create a default url, specific to the STK module that
  can be set via a system property.
- This url will be used when processing a launch browser
  proactive command that contains no url data associated
  with it.

2) Stk: Update Launch Browser If Not Already Launched Behavior

- Since the default browser supports tabs, it will never be considered
  unavailable. Thus, there is no  need to send a terminal
  response with a browser unavailable result code.
- Suppress user confirmation when the browser mode is
  launch if not already launched and the alphaid is null or contains
  no text.

BUG=22637280
Change-Id: I44cc1736da3f962cc5a6d7afd7b7f84d845fdb25
diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java
index 937acec..7c85616 100644
--- a/src/com/android/stk/StkAppService.java
+++ b/src/com/android/stk/StkAppService.java
@@ -27,6 +27,7 @@
 import android.app.ActivityManager;
 import android.app.ActivityManager.RecentTaskInfo;
 import android.app.ActivityManager.RunningAppProcessInfo;
+import android.content.ComponentName;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
@@ -40,8 +41,10 @@
 import android.os.Looper;
 import android.os.Message;
 import android.os.PowerManager;
+import android.os.SystemProperties;
 import android.provider.Settings;
 import android.telephony.TelephonyManager;
+import android.text.TextUtils;
 import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -77,6 +80,7 @@
 import com.android.internal.telephony.GsmAlphabet;
 import com.android.internal.telephony.cat.CatService;
 
+import java.util.Iterator;
 import java.util.LinkedList;
 import java.lang.System;
 import java.util.List;
@@ -249,6 +253,9 @@
         }
     }
 
+    // system property to set the STK specific default url for launch browser proactive cmds
+    private static final String STK_BROWSER_DEFAULT_URL_SYSPROP = "persist.radio.stk.default_url";
+
     @Override
     public void onCreate() {
         CatLog.d(LOG_TAG, "onCreate()+");
@@ -909,7 +916,22 @@
             launchEventMessage(slotId);
             break;
         case LAUNCH_BROWSER:
-            launchConfirmationDialog(mStkContext[slotId].mCurrentCmd.geTextMessage(), slotId);
+            TextMessage alphaId = mStkContext[slotId].mCurrentCmd.geTextMessage();
+            if ((mStkContext[slotId].mCurrentCmd.getBrowserSettings().mode
+                    == LaunchBrowserMode.LAUNCH_IF_NOT_ALREADY_LAUNCHED) &&
+                    ((alphaId == null) || TextUtils.isEmpty(alphaId.text))) {
+                // don't need user confirmation in this case
+                // just launch the browser or spawn a new tab
+                CatLog.d(this, "Browser mode is: launch if not already launched " +
+                        "and user confirmation is not currently needed.\n" +
+                        "supressing confirmation dialogue and confirming silently...");
+                mStkContext[slotId].launchBrowser = true;
+                mStkContext[slotId].mBrowserSettings =
+                        mStkContext[slotId].mCurrentCmd.getBrowserSettings();
+                sendResponse(RES_ID_CONFIRM, slotId, true);
+            } else {
+                launchConfirmationDialog(alphaId, slotId);
+            }
             break;
         case SET_UP_CALL:
             TextMessage mesg = mStkContext[slotId].mCurrentCmd.getCallSettings().confirmMsg;
@@ -1442,30 +1464,31 @@
             return;
         }
 
-        Intent intent = null;
         Uri data = null;
-
-        if (settings.url != null) {
-            CatLog.d(LOG_TAG, "settings.url = " + settings.url);
-            if ((settings.url.startsWith("http://") || (settings.url.startsWith("https://")))) {
-                data = Uri.parse(settings.url);
-            } else {
-                String modifiedUrl = "http://" + settings.url;
-                CatLog.d(LOG_TAG, "modifiedUrl = " + modifiedUrl);
-                data = Uri.parse(modifiedUrl);
-            }
-        }
-        if (data != null) {
-            intent = new Intent(Intent.ACTION_VIEW);
-            intent.setData(data);
-        } else {
+        String url;
+        if (settings.url == null) {
             // if the command did not contain a URL,
             // launch the browser to the default homepage.
-            CatLog.d(LOG_TAG, "launch browser with default URL ");
-            intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
-                    Intent.CATEGORY_APP_BROWSER);
+            CatLog.d(this, "no url data provided by proactive command." +
+                       " launching browser with stk default URL ... ");
+            url = SystemProperties.get(STK_BROWSER_DEFAULT_URL_SYSPROP,
+                    "http://www.google.com");
+        } else {
+            CatLog.d(this, "launch browser command has attached url = " + settings.url);
+            url = settings.url;
         }
 
+        if (url.startsWith("http://") || url.startsWith("https://")) {
+            data = Uri.parse(url);
+            CatLog.d(this, "launching browser with url = " + url);
+        } else {
+            String modifiedUrl = "http://" + url;
+            data = Uri.parse(modifiedUrl);
+            CatLog.d(this, "launching browser with modified url = " + modifiedUrl);
+        }
+
+        Intent intent = new Intent(Intent.ACTION_VIEW);
+        intent.setData(data);
         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         switch (settings.mode) {
         case USE_EXISTING_BROWSER: