Bug 785032 - SD card issues with new Tegras ("INFO: attempting to create file /mnt/sdcard/writetest ... Push File Failed to Validate!"). r=jmaher DONTBUILD
authorClint Talbert <ctalbert@mozilla.com>
Wed, 10 Oct 2012 10:17:50 -0400
changeset 109858 99889cc4affd3ce34091f15b98ba81aae8242279
parent 109857 d2501e3be239b920557b3e54e558689d2252758a
child 109859 180952776fbe65b6556d0fd4ece73435ae0b26e0
push id16239
push userjmaher@mozilla.com
push dateWed, 10 Oct 2012 14:18:42 +0000
treeherdermozilla-inbound@99889cc4affd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs785032
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 785032 - SD card issues with new Tegras ("INFO: attempting to create file /mnt/sdcard/writetest ... Push File Failed to Validate!"). r=jmaher DONTBUILD
build/mobile/sutagent/android/AndroidManifest.xml
build/mobile/sutagent/android/DoCommand.java
build/mobile/sutagent/android/Makefile.in
build/mobile/sutagent/android/SUTAgentAndroid.java
build/mobile/sutagent/android/SUTStartupIntentReceiver.java
build/mobile/sutagent/android/watcher/WatcherService.java
--- a/build/mobile/sutagent/android/AndroidManifest.xml
+++ b/build/mobile/sutagent/android/AndroidManifest.xml
@@ -10,21 +10,16 @@
         <activity android:name=".SUTAgentAndroid"
                   android:screenOrientation="nosensor"
                   android:label="@string/app_name">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
-        <receiver android:name=".SUTStartupIntentReceiver">
-            <intent-filter>
-                 <action android:name="android.intent.action.MEDIA_MOUNTED"></action>
-            </intent-filter>
-        </receiver>
         <service android:name=".service.ASMozStub">
 		    <intent-filter>
 			    <action android:name="com.mozilla.SUTAgentAndroid.service.LISTENER_SERVICE" />
 		    </intent-filter>
 	    </service>
 	</application>
     
     <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="8"/>
--- a/build/mobile/sutagent/android/DoCommand.java
+++ b/build/mobile/sutagent/android/DoCommand.java
@@ -1309,33 +1309,43 @@ private void CancelNotification()
         sRet += "Total Shared Dirty Memory          " + mi[0].getTotalSharedDirty()  + " kb";
 
 
         return(sRet);
         }
 
     public String GetTestRoot()
         {
-        String    sRet = null;
-
-        File tmpFile = new java.io.File("/data/local/tests");
-        if (tmpFile.exists() && tmpFile.isDirectory()) 
+
+        // According to all the docs this should work, but I keep getting an
+        // exception when I attempt to create the file because I don't have
+        // permission, although /data/local/tmp is supposed to be world
+        // writeable/readable
+        File tmpFile = new java.io.File("/data/local/tmp/tests");
+        try{
+            tmpFile.createNewFile();
+        } catch (IOException e){
+            Log.i("SUTAgentAndroid", "Caught exception creating file in /data/local/tmp: " + e.getMessage());
+        }
+   
+        String state = Environment.getExternalStorageState();
+        // Ensure sdcard is mounted and NOT read only
+        if (state.equalsIgnoreCase(Environment.MEDIA_MOUNTED) &&
+            (Environment.MEDIA_MOUNTED_READ_ONLY.compareTo(state) != 0))
             {
+            return(Environment.getExternalStorageDirectory().getAbsolutePath());
+            }
+        if (tmpFile.exists()) 
+            {
+            Log.i("CLINT", "tmpfile exists");
             return("/data/local");
             }
-        if (Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED))
-            {
-            sRet = Environment.getExternalStorageDirectory().getAbsolutePath();
-            }
-        else
-            {
-            sRet = GetTmpDir();
-            }
-
-        return(sRet);
+        Log.e("SUTAgentAndroid", "ERROR: Cannot access world writeable test root");
+
+        return(null);
         }
 
     public String GetAppRoot(String AppName)
         {
         String sRet = sErrorPrefix + " internal error [no context]";
         Context ctx = contextWrapper.getApplicationContext();
 
         if (ctx != null)
--- a/build/mobile/sutagent/android/Makefile.in
+++ b/build/mobile/sutagent/android/Makefile.in
@@ -19,17 +19,16 @@ JAVAFILES = \
   DoAlert.java \
   DoCommand.java \
   FindProcThread.java \
   Power.java \
   RedirOutputThread.java \
   RunCmdThread.java \
   RunDataThread.java \
   SUTAgentAndroid.java \
-  SUTStartupIntentReceiver.java \
   WifiConfiguration.java \
   R.java \
   $(NULL)
 
 RES_FILES = \
   res/drawable/icon.png \
   res/drawable/ateamlogo.png \
   res/drawable/ic_stat_first.png \
--- a/build/mobile/sutagent/android/SUTAgentAndroid.java
+++ b/build/mobile/sutagent/android/SUTAgentAndroid.java
@@ -104,16 +104,22 @@ public class SUTAgentAndroid extends Act
         return(RegSvrIPAddr);
         }
 
     public void pruneCommandLog(String datestamp, String testroot)
         {
 
         String today = "";
         String yesterday = "";
+
+        // test root can be null (if getTestRoot fails), handle that:
+        if (testroot == null) {
+            testroot = "";
+        }
+
         try {
             SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS");
             Date dateObj = sdf.parse(datestamp);
             SimpleDateFormat sdf_file = new SimpleDateFormat("yyyy-MM-dd");
 
             today     = sdf_file.format(dateObj);
             yesterday = sdf_file.format(new Date(dateObj.getTime() - 1000*60*60*24));
         } catch (ParseException pe) {}
deleted file mode 100755
--- a/build/mobile/sutagent/android/SUTStartupIntentReceiver.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-package com.mozilla.SUTAgentAndroid;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-
-public class SUTStartupIntentReceiver extends BroadcastReceiver
-{
-    @Override
-    public void onReceive(Context context, Intent intent)
-        {
-        Intent mySUTAgentIntent = new Intent(context, SUTAgentAndroid.class);
-        mySUTAgentIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        context.startActivity(mySUTAgentIntent);
-        }
-}
--- a/build/mobile/sutagent/android/watcher/WatcherService.java
+++ b/build/mobile/sutagent/android/watcher/WatcherService.java
@@ -37,16 +37,17 @@ import android.os.BatteryManager;
 import android.os.Debug;
 import android.os.IBinder;
 import android.os.PowerManager;
 import android.os.RemoteException;
 import android.provider.Settings;
 import android.util.Log;
 import android.view.Gravity;
 import android.widget.Toast;
+import android.os.Environment;
 
 public class WatcherService extends Service
 {
     String sErrorPrefix = "##Installer Error## ";
     String currentDir = "/";
     String sPingTarget = "";
     long lDelay = 60000;
     long lPeriod = 300000;
@@ -484,19 +485,19 @@ public class WatcherService extends Serv
             nProcs = lProcesses.size();
 
         for (lcv = 0; lcv < nProcs; lcv++)
             {
             strProcName = lProcesses.get(lcv).processName;
             if (strProcName.contains(sProcName))
                 {
                 bRet = true;
+                break;
                 }
             }
-
         return (bRet);
         }
 
     public String RunReboot(OutputStream out)
         {
         String sRet = "";
         String [] theArgs = new String [3];
 
@@ -890,16 +891,18 @@ public class WatcherService extends Serv
             UpdtApp(msPkgName, msPkgFileName, msOutFile, mbReboot);
                bInstalling = false;
         }
     }
 
     private class MyTime extends TimerTask
         {
         int    nStrikes = 0;
+        final int PERIODS_TO_WAIT_FOR_SDCARD = 3;
+        int    nPeriodsWaited = 0;
 
         public MyTime()
             {
             }
 
         @Override
         public void run()
             {
@@ -926,18 +929,33 @@ public class WatcherService extends Serv
                             nStrikes = 0;
                         }
                 }
 
             String sProgramName = "com.mozilla.SUTAgentAndroid";
 
 //            Debug.waitForDebugger();
 
+            // Ensure the sdcard is mounted before we even attempt to start the agent
+            // We will wait for the sdcard to mount for PERIODS_TO_WAIT_FOR_SDCARD
+            // after which time we go ahead and attempt to start the agent.
+            if (nPeriodsWaited++ < PERIODS_TO_WAIT_FOR_SDCARD) {
+                String state = Environment.getExternalStorageState();
+                if (Environment.MEDIA_MOUNTED.compareTo(state) != 0) {
+                    Log.i("SUTAgentWatcher", "SDcard not mounted, waiting another turn");
+                    return;
+                } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
+                    Log.e("SUTAgentWatcher", "SDcard mounted read only not starting agent now, try again in 60s");
+                    return;
+                }
+            }
+
             if (bStartSUTAgent && !GetProcessInfo(sProgramName))
                 {
+                Log.i("SUTAgentWatcher", "Starting SUTAgent from watcher code");
                 Intent agentIntent = new Intent();
                 agentIntent.setPackage(sProgramName);
                 agentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                 agentIntent.setAction(Intent.ACTION_MAIN);
                 try {
                     PackageManager pm = myContext.getPackageManager();
                     PackageInfo pi = pm.getPackageInfo(sProgramName, PackageManager.GET_ACTIVITIES | PackageManager.GET_INTENT_FILTERS);
                     ActivityInfo [] ai = pi.activities;