private void deleteLocation(LocationInfo info) {
    if (NavigineApp.Navigation == null) return;

    if (info != null) {
      try {
        (new File(info.archiveFile)).delete();
        info.localVersion = -1;
        info.localModified = false;

        String locationDir = LocationLoader.getLocationDir(mContext, info.title);
        File dir = new File(locationDir);
        File[] files = dir.listFiles();
        for (int i = 0; i < files.length; ++i) files[i].delete();
        dir.delete();

        String mapFile = NavigineApp.Settings.getString("map_file", "");
        if (mapFile.equals(info.archiveFile)) {
          NavigineApp.Navigation.loadArchive(null);
          SharedPreferences.Editor editor = NavigineApp.Settings.edit();
          editor.putString("map_file", "");
          editor.commit();
        }

        mAdapter.updateList();
      } catch (Throwable e) {
        Log.e(TAG, Log.getStackTraceString(e));
      }
    }
  }
Beispiel #2
0
  protected void unpackComponents() throws IOException, FileNotFoundException {
    File applicationPackage = new File(getApplication().getPackageResourcePath());
    File componentsDir = new File(sGREDir, "components");
    if (componentsDir.lastModified() == applicationPackage.lastModified()) return;

    componentsDir.mkdir();
    componentsDir.setLastModified(applicationPackage.lastModified());

    GeckoAppShell.killAnyZombies();

    ZipFile zip = new ZipFile(applicationPackage);

    byte[] buf = new byte[32768];
    try {
      if (unpackFile(zip, buf, null, "removed-files")) removeFiles();
    } catch (Exception ex) {
      // This file may not be there, so just log any errors and move on
      Log.w(LOG_FILE_NAME, "error removing files", ex);
    }

    // copy any .xpi file into an extensions/ directory
    Enumeration<? extends ZipEntry> zipEntries = zip.entries();
    while (zipEntries.hasMoreElements()) {
      ZipEntry entry = zipEntries.nextElement();
      if (entry.getName().startsWith("extensions/") && entry.getName().endsWith(".xpi")) {
        Log.i("GeckoAppJava", "installing extension : " + entry.getName());
        unpackFile(zip, buf, entry, entry.getName());
      }
    }
  }
 @Override
 public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
     this.callbackContext = callbackContext;
     Log.d("WIFI", action);
     if(ACTION_START.equals(action)){
         PluginResult pgRes = new PluginResult(PluginResult.Status.OK, "Registered");
         pgRes.setKeepCallback(true);
         mWifiManager = (WifiManager) this.cordova.getActivity().getSystemService(Context.WIFI_SERVICE);
         this.reciever = new BroadcastReceiver()
         {
             @Override
             public void onReceive(Context c, Intent intent)
             {
                List<ScanResult> scanResults = mWifiManager.getScanResults();
                handleResults(scanResults);
             }
         };
         this.cordova.getActivity().registerReceiver(this.reciever, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
         callbackContext.sendPluginResult(pgRes);
         Log.d("WIFI", "inside " + action);
         return true;
     } else if (ACTION_SCAN.equals(action)){
         PluginResult pgRes = new PluginResult(PluginResult.Status.OK, []);
         pgRes.setKeepCallback(true);
         mWifiManager = (WifiManager) this.cordova.getActivity().getSystemService(Context.WIFI_SERVICE);
         mWifiManager.startScan();
         callbackContext.sendPluginResult(pgRes);
         Log.d("WIFI", "inside " + action);
         return true;
     } else if (ACTION_STOP.equals(action)){
Beispiel #4
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    String filePickerResult = "";
    if (data != null && resultCode == RESULT_OK) {
      try {
        ContentResolver cr = getContentResolver();
        Uri uri = data.getData();
        Cursor cursor =
            GeckoApp.mAppContext
                .getContentResolver()
                .query(uri, new String[] {OpenableColumns.DISPLAY_NAME}, null, null, null);
        String name = null;
        if (cursor != null) {
          try {
            if (cursor.moveToNext()) {
              name = cursor.getString(0);
            }
          } finally {
            cursor.close();
          }
        }
        String fileName = "tmp_";
        String fileExt = null;
        int period;
        if (name == null || (period = name.lastIndexOf('.')) == -1) {
          String mimeType = cr.getType(uri);
          fileExt = "." + GeckoAppShell.getExtensionFromMimeType(mimeType);
        } else {
          fileExt = name.substring(period);
          fileName = name.substring(0, period);
        }
        File file = File.createTempFile(fileName, fileExt, sGREDir);

        FileOutputStream fos = new FileOutputStream(file);
        InputStream is = cr.openInputStream(uri);
        byte[] buf = new byte[4096];
        int len = is.read(buf);
        while (len != -1) {
          fos.write(buf, 0, len);
          len = is.read(buf);
        }
        fos.close();
        filePickerResult = file.getAbsolutePath();
      } catch (Exception e) {
        Log.e(LOG_FILE_NAME, "showing file picker", e);
      }
    }
    try {
      mFilePickerResult.put(filePickerResult);
    } catch (InterruptedException e) {
      Log.i(LOG_FILE_NAME, "error returning file picker result", e);
    }
  }
 private void parseMapsXml() {
   try {
     String fileName = LocationLoader.getLocationDir(NavigineApp.AppContext, null) + "/maps.xml";
     List<LocationInfo> infoList = Parser.parseMapsXml(NavigineApp.AppContext, fileName);
     mInfoList = new ArrayList<LocationInfo>();
     if (infoList != null) mInfoList = infoList;
     mAdapter.updateList();
     new File(fileName).delete();
   } catch (Throwable e) {
     Log.e(TAG, Log.getStackTraceString(e));
   }
 }
  /** Called when the activity is first created */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "LoaderActivity created");
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.content);

    // Instantiate custom adapter
    mAdapter = new LoaderAdapter();

    // Handle listview and assign adapter
    mListView = (ListView) findViewById(R.id.content_list_view);
    mListView.setAdapter(mAdapter);
    mListView.setVisibility(View.GONE);
    mListView.setOnItemLongClickListener(
        new AdapterView.OnItemLongClickListener() {
          public boolean onItemLongClick(AdapterView parent, View view, int position, long id) {
            selectItem(position);
            return true;
          }
        });

    mStatusLabel = (TextView) findViewById(R.id.content_status_label);
    mStatusLabel.setVisibility(View.VISIBLE);

    String userHash = NavigineApp.Settings.getString("user_hash", "");
    if (userHash.length() == 0) showUserHashDialog();
    else refreshMapList();
  }
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
   Log.d(TAG, "Create menu options");
   MenuInflater inflater = getMenuInflater();
   inflater.inflate(R.menu.loader_menu, menu);
   menu.findItem(R.id.loader_menu_refresh_map_list).setVisible(mLoader < 0);
   return true;
 }
Beispiel #8
0
 public void doRestart() {
   try {
     String action = "org.mozilla.gecko.restart";
     Intent intent = new Intent(action);
     intent.setClassName(getPackageName(), getPackageName() + ".Restarter");
     addEnvToIntent(intent);
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
     Log.i(LOG_FILE_NAME, intent.toString());
     GeckoAppShell.killAnyZombies();
     startActivity(intent);
   } catch (Exception e) {
     Log.i(LOG_FILE_NAME, "error doing restart", e);
   }
   finish();
   // Give the restart process time to start before we die
   GeckoAppShell.waitForAnotherGeckoProc();
 }
  @Override
  public void onPause() {
    Log.d(TAG, "LoaderActivity paused");
    super.onPause();

    mTimerTask.cancel();
    mTimerTask = null;
  }
Beispiel #10
0
  private void updateLoader() {
    if (NavigineApp.Navigation == null) return;

    // Log.d(TAG, String.format(Locale.ENGLISH, "Update loader: %d", mLoader));

    long timeNow = DateTimeUtils.currentTimeMillis();
    if (mLoader < 0) return;

    int status = LocationLoader.checkLocationLoader(mLoader);
    if (status < 100) {
      if ((Math.abs(timeNow - mLoaderTime) > LOADER_TIMEOUT / 3 && status == 0)
          || (Math.abs(timeNow - mLoaderTime) > LOADER_TIMEOUT)) {
        mListView.setVisibility(View.GONE);
        mStatusLabel.setVisibility(View.VISIBLE);
        mStatusLabel.setText("Loading timeout!\nPlease, check your internet connection!");
        Log.d(TAG, String.format(Locale.ENGLISH, "Load stopped on timeout!"));
        LocationLoader.stopLocationLoader(mLoader);
        mLoader = -1;
      } else {
        mListView.setVisibility(View.GONE);
        mStatusLabel.setVisibility(View.VISIBLE);
        mStatusLabel.setText(String.format(Locale.ENGLISH, "Loading content (%d%%)", status));
      }
    } else {
      Log.d(TAG, String.format(Locale.ENGLISH, "Load finished with result: %d", status));
      LocationLoader.stopLocationLoader(mLoader);
      mLoader = -1;

      if (status == 100) {
        parseMapsXml();
        if (mInfoList.isEmpty()) {
          mListView.setVisibility(View.GONE);
          mStatusLabel.setVisibility(View.VISIBLE);
          mStatusLabel.setText("No locations available");
        } else {
          mListView.setVisibility(View.VISIBLE);
          mStatusLabel.setVisibility(View.GONE);
        }
      } else {
        mListView.setVisibility(View.GONE);
        mStatusLabel.setVisibility(View.VISIBLE);
        mStatusLabel.setText("Error loading!\nPlease, check your ID!");
      }
    }
  }
Beispiel #11
0
  @Override
  protected void onNewIntent(Intent intent) {
    if (checkLaunchState(LaunchState.GeckoExiting)) {
      // We're exiting and shouldn't try to do anything else just incase
      // we're hung for some reason we'll force the process to exit
      System.exit(0);
      return;
    }
    final String action = intent.getAction();
    if (ACTION_DEBUG.equals(action)
        && checkAndSetLaunchState(LaunchState.Launching, LaunchState.WaitForDebugger)) {

      mMainHandler.postDelayed(
          new Runnable() {
            public void run() {
              Log.i(LOG_FILE_NAME, "Launching from debug intent after 5s wait");
              setLaunchState(LaunchState.Launching);
              launch(null);
            }
          },
          1000 * 5 /* 5 seconds */);
      Log.i(LOG_FILE_NAME, "Intent : ACTION_DEBUG - waiting 5s before launching");
      return;
    }
    if (checkLaunchState(LaunchState.WaitForDebugger) || launch(intent)) return;

    if (Intent.ACTION_MAIN.equals(action)) {
      Log.i(LOG_FILE_NAME, "Intent : ACTION_MAIN");
      GeckoAppShell.sendEventToGecko(new GeckoEvent(""));
    } else if (Intent.ACTION_VIEW.equals(action)) {
      String uri = intent.getDataString();
      GeckoAppShell.sendEventToGecko(new GeckoEvent(uri));
      Log.i(LOG_FILE_NAME, "onNewIntent: " + uri);
    } else if (ACTION_WEBAPP.equals(action)) {
      String uri = intent.getStringExtra("args");
      GeckoAppShell.sendEventToGecko(new GeckoEvent(uri));
      Log.i(LOG_FILE_NAME, "Intent : WEBAPP - " + uri);
    } else if (ACTION_BOOKMARK.equals(action)) {
      String args = intent.getStringExtra("args");
      GeckoAppShell.sendEventToGecko(new GeckoEvent(args));
      Log.i(LOG_FILE_NAME, "Intent : BOOKMARK - " + args);
    }
  }
Beispiel #12
0
  public String showFilePicker(String aMimeType) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType(aMimeType);
    GeckoApp.this.startActivityForResult(
        Intent.createChooser(intent, getString(R.string.choose_file)), FILE_PICKER_REQUEST);
    String filePickerResult = "";

    try {
      while (null == (filePickerResult = mFilePickerResult.poll(1, TimeUnit.MILLISECONDS))) {
        Log.i("GeckoApp", "processing events from showFilePicker ");
        GeckoAppShell.processNextNativeEvent();
      }
    } catch (InterruptedException e) {
      Log.i(LOG_FILE_NAME, "showing file picker ", e);
    }

    return filePickerResult;
  }
Beispiel #13
0
 private String readUpdateStatus(File statusFile) {
   String status = "";
   try {
     BufferedReader reader = new BufferedReader(new FileReader(statusFile));
     status = reader.readLine();
     reader.close();
   } catch (Exception e) {
     Log.i(LOG_FILE_NAME, "error reading update status", e);
   }
   return status;
 }
Beispiel #14
0
  private void refreshMapList() {
    if (mLoader >= 0) return;

    String userHash = NavigineApp.Settings.getString("user_hash", "");
    if (userHash.length() == 0) return;

    // Starting new loader
    String fileName = LocationLoader.getLocationDir(NavigineApp.AppContext, null) + "/maps.xml";
    new File(fileName).delete();
    mLoader = LocationLoader.startLocationLoader(null, fileName, true);
    mLoaderTime = DateTimeUtils.currentTimeMillis();
    mInfoList = new ArrayList<LocationInfo>();
    Log.d(TAG, String.format(Locale.ENGLISH, "Location loader started: %d", mLoader));
  }
Beispiel #15
0
  @Override
  public void onResume() {
    Log.d(TAG, "LoaderActivity resumed");
    super.onResume();

    // Starting interface updates
    mTimerTask =
        new TimerTask() {
          @Override
          public void run() {
            mHandler.post(mRunnable);
          }
        };
    mTimer.schedule(mTimerTask, 100, 100);
  }
Beispiel #16
0
  @Override
  public void onResume() {
    Log.i(LOG_FILE_NAME, "resume");
    if (checkLaunchState(LaunchState.GeckoRunning)) GeckoAppShell.onResume();
    // After an onPause, the activity is back in the foreground.
    // Undo whatever we did in onPause.
    super.onResume();

    // Just in case. Normally we start in onNewIntent
    if (checkLaunchState(LaunchState.PreLaunch) || checkLaunchState(LaunchState.Launching))
      onNewIntent(getIntent());

    registerReceiver(mConnectivityReceiver, mConnectivityFilter);
    GeckoNetworkManager.getInstance().start();
    GeckoScreenOrientationListener.getInstance().start();
  }
Beispiel #17
0
  private void checkAndLaunchUpdate() {
    Log.i(LOG_FILE_NAME, "Checking for an update");

    int statusCode = 8; // UNEXPECTED_ERROR
    File baseUpdateDir = null;
    if (Build.VERSION.SDK_INT >= 8)
      baseUpdateDir = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
    else baseUpdateDir = new File(Environment.getExternalStorageDirectory().getPath(), "download");

    File updateDir = new File(new File(baseUpdateDir, "updates"), "0");

    File updateFile = new File(updateDir, "update.apk");
    File statusFile = new File(updateDir, "update.status");

    if (!statusFile.exists() || !readUpdateStatus(statusFile).equals("pending")) return;

    if (!updateFile.exists()) return;

    Log.i(LOG_FILE_NAME, "Update is available!");

    // Launch APK
    File updateFileToRun = new File(updateDir, getPackageName() + "-update.apk");
    try {
      if (updateFile.renameTo(updateFileToRun)) {
        String amCmd =
            "/system/bin/am start -a android.intent.action.VIEW "
                + "-n com.android.packageinstaller/.PackageInstallerActivity -d file://"
                + updateFileToRun.getPath();
        Log.i(LOG_FILE_NAME, amCmd);
        Runtime.getRuntime().exec(amCmd);
        statusCode = 0; // OK
      } else {
        Log.i(LOG_FILE_NAME, "Cannot rename the update file!");
        statusCode = 7; // WRITE_ERROR
      }
    } catch (Exception e) {
      Log.i(LOG_FILE_NAME, "error launching installer to update", e);
    }

    // Update the status file
    String status = statusCode == 0 ? "succeeded\n" : "failed: " + statusCode + "\n";

    OutputStream outStream;
    try {
      byte[] buf = status.getBytes("UTF-8");
      outStream = new FileOutputStream(statusFile);
      outStream.write(buf, 0, buf.length);
      outStream.close();
    } catch (Exception e) {
      Log.i(LOG_FILE_NAME, "error writing status file", e);
    }

    if (statusCode == 0) System.exit(0);
  }
Beispiel #18
0
  @Override
  public void onStop() {
    Log.i(LOG_FILE_NAME, "stop");
    // We're about to be stopped, potentially in preparation for
    // being destroyed.  We're killable after this point -- as I
    // understand it, in extreme cases the process can be terminated
    // without going through onDestroy.
    //
    // We might also get an onRestart after this; not sure what
    // that would mean for Gecko if we were to kill it here.
    // Instead, what we should do here is save prefs, session,
    // etc., and generally mark the profile as 'clean', and then
    // dirty it again if we get an onResume.

    GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_STOPPING));
    super.onStop();
    GeckoAppShell.putChildInBackground();
  }
Beispiel #19
0
  @Override
  public void onPause() {
    Log.i(LOG_FILE_NAME, "pause");
    GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_PAUSING));
    // The user is navigating away from this activity, but nothing
    // has come to the foreground yet; for Gecko, we may want to
    // stop repainting, for example.

    // Whatever we do here should be fast, because we're blocking
    // the next activity from showing up until we finish.

    // onPause will be followed by either onResume or onStop.
    super.onPause();

    unregisterReceiver(mConnectivityReceiver);
    GeckoNetworkManager.getInstance().stop();
    GeckoScreenOrientationListener.getInstance().stop();
  }
Beispiel #20
0
  private void updateLocationLoaders() {
    if (NavigineApp.Navigation == null) return;

    long timeNow = DateTimeUtils.currentTimeMillis();
    mUpdateLocationLoadersTime = timeNow;

    synchronized (mLoaderMap) {
      Iterator<Map.Entry<String, LoaderState>> iter = mLoaderMap.entrySet().iterator();
      while (iter.hasNext()) {
        Map.Entry<String, LoaderState> entry = iter.next();

        LoaderState loader = entry.getValue();
        if (loader.state < 100) {
          loader.timeLabel = timeNow;
          if (loader.type == DOWNLOAD) loader.state = LocationLoader.checkLocationLoader(loader.id);
          if (loader.type == UPLOAD) loader.state = LocationLoader.checkLocationUploader(loader.id);
        } else if (loader.state == 100) {
          String archivePath = NavigineApp.Navigation.getArchivePath();
          String locationFile =
              LocationLoader.getLocationFile(NavigineApp.AppContext, loader.location);
          if (archivePath != null && archivePath.equals(locationFile)) {
            Log.d(TAG, "Reloading archive " + archivePath);
            if (NavigineApp.Navigation.loadArchive(archivePath)) {
              SharedPreferences.Editor editor = NavigineApp.Settings.edit();
              editor.putString("map_file", archivePath);
              editor.commit();
            }
          }
          if (loader.type == DOWNLOAD) LocationLoader.stopLocationLoader(loader.id);
          if (loader.type == UPLOAD) LocationLoader.stopLocationUploader(loader.id);
          iter.remove();
        } else {
          // Load failed
          if (Math.abs(timeNow - loader.timeLabel) > 5000) {
            if (loader.type == DOWNLOAD) LocationLoader.stopLocationLoader(loader.id);
            if (loader.type == UPLOAD) LocationLoader.stopLocationUploader(loader.id);
            iter.remove();
          }
        }
      }
    }
    updateLocalVersions();
    mAdapter.updateList();
  }
Beispiel #21
0
  @Override
  public void onDestroy() {
    Log.i(LOG_FILE_NAME, "destroy");

    // Tell Gecko to shutting down; we'll end up calling System.exit()
    // in onXreExit.
    if (isFinishing()) GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_SHUTDOWN));

    if (SmsManager.getInstance() != null) {
      SmsManager.getInstance().stop();
      if (isFinishing()) SmsManager.getInstance().shutdown();
    }

    GeckoNetworkManager.getInstance().stop();
    GeckoScreenOrientationListener.getInstance().stop();

    super.onDestroy();

    unregisterReceiver(mBatteryReceiver);
  }
Beispiel #22
0
  private void startUpload(int index) {
    if (NavigineApp.Navigation == null) return;

    String userHash = NavigineApp.Settings.getString("user_hash", "");
    if (userHash.length() == 0) return;

    LocationInfo info = mInfoList.get(index);
    String location = new String(info.title);
    Log.d(TAG, String.format(Locale.ENGLISH, "Start upload: %s", location));

    synchronized (mLoaderMap) {
      if (!mLoaderMap.containsKey(location)) {
        LoaderState loader = new LoaderState();
        loader.location = location;
        loader.type = UPLOAD;
        loader.id = LocationLoader.startLocationUploader(location, info.archiveFile, true);
        mLoaderMap.put(location, loader);
      }
    }
    mAdapter.updateList();
  }
Beispiel #23
0
 @Override
 public void onStart() {
   Log.i(LOG_FILE_NAME, "start");
   GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_START));
   super.onStart();
 }
Beispiel #24
0
  String[] getPluginDirectories() {

    ArrayList<String> directories = new ArrayList<String>();
    PackageManager pm = this.mAppContext.getPackageManager();
    List<ResolveInfo> plugins =
        pm.queryIntentServices(
            new Intent(PLUGIN_ACTION), PackageManager.GET_SERVICES | PackageManager.GET_META_DATA);

    synchronized (mPackageInfoCache) {

      // clear the list of existing packageInfo objects
      mPackageInfoCache.clear();

      for (ResolveInfo info : plugins) {

        // retrieve the plugin's service information
        ServiceInfo serviceInfo = info.serviceInfo;
        if (serviceInfo == null) {
          Log.w(LOGTAG, "Ignore bad plugin");
          continue;
        }

        Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName);

        // retrieve information from the plugin's manifest
        PackageInfo pkgInfo;
        try {
          pkgInfo =
              pm.getPackageInfo(
                  serviceInfo.packageName,
                  PackageManager.GET_PERMISSIONS | PackageManager.GET_SIGNATURES);
        } catch (Exception e) {
          Log.w(LOGTAG, "Can't find plugin: " + serviceInfo.packageName);
          continue;
        }
        if (pkgInfo == null) {
          Log.w(
              LOGTAG,
              "Loading plugin: "
                  + serviceInfo.packageName
                  + ". Could not load package information.");
          continue;
        }

        /*
         * find the location of the plugin's shared library. The default
         * is to assume the app is either a user installed app or an
         * updated system app. In both of these cases the library is
         * stored in the app's data directory.
         */
        String directory = pkgInfo.applicationInfo.dataDir + "/lib";
        final int appFlags = pkgInfo.applicationInfo.flags;
        final int updatedSystemFlags =
            ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
        // preloaded system app with no user updates
        if ((appFlags & updatedSystemFlags) == ApplicationInfo.FLAG_SYSTEM) {
          directory = PLUGIN_SYSTEM_LIB + pkgInfo.packageName;
        }

        // check if the plugin has the required permissions
        String permissions[] = pkgInfo.requestedPermissions;
        if (permissions == null) {
          Log.w(
              LOGTAG,
              "Loading plugin: "
                  + serviceInfo.packageName
                  + ". Does not have required permission.");
          continue;
        }
        boolean permissionOk = false;
        for (String permit : permissions) {
          if (PLUGIN_PERMISSION.equals(permit)) {
            permissionOk = true;
            break;
          }
        }
        if (!permissionOk) {
          Log.w(
              LOGTAG,
              "Loading plugin: "
                  + serviceInfo.packageName
                  + ". Does not have required permission (2).");
          continue;
        }

        // check to ensure the plugin is properly signed
        Signature signatures[] = pkgInfo.signatures;
        if (signatures == null) {
          Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Not signed.");
          continue;
        }

        // determine the type of plugin from the manifest
        if (serviceInfo.metaData == null) {
          Log.e(LOGTAG, "The plugin '" + serviceInfo.name + "' has no type defined");
          continue;
        }

        String pluginType = serviceInfo.metaData.getString(PLUGIN_TYPE);
        if (!TYPE_NATIVE.equals(pluginType)) {
          Log.e(LOGTAG, "Unrecognized plugin type: " + pluginType);
          continue;
        }

        try {
          Class<?> cls = getPluginClass(serviceInfo.packageName, serviceInfo.name);

          // TODO implement any requirements of the plugin class here!
          boolean classFound = true;

          if (!classFound) {
            Log.e(
                LOGTAG,
                "The plugin's class' "
                    + serviceInfo.name
                    + "' does not extend the appropriate class.");
            continue;
          }

        } catch (NameNotFoundException e) {
          Log.e(LOGTAG, "Can't find plugin: " + serviceInfo.packageName);
          continue;
        } catch (ClassNotFoundException e) {
          Log.e(LOGTAG, "Can't find plugin's class: " + serviceInfo.name);
          continue;
        }

        // if all checks have passed then make the plugin available
        mPackageInfoCache.add(pkgInfo);
        directories.add(directory);
      }
    }

    return directories.toArray(new String[directories.size()]);
  }
Beispiel #25
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    mAppContext = this;
    mMainHandler = new Handler();

    if (!sTryCatchAttached) {
      sTryCatchAttached = true;
      mMainHandler.post(
          new Runnable() {
            public void run() {
              try {
                Looper.loop();
              } catch (Exception e) {
                Log.e(LOG_FILE_NAME, "top level exception", e);
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                e.printStackTrace(pw);
                pw.flush();
                GeckoAppShell.reportJavaCrash(sw.toString());
              }
              // resetting this is kinda pointless, but oh well
              sTryCatchAttached = false;
            }
          });
    }

    SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
    String localeCode = settings.getString(getPackageName() + ".locale", "");
    if (localeCode != null && localeCode.length() > 0) GeckoAppShell.setSelectedLocale(localeCode);

    Log.i(LOG_FILE_NAME, "create");
    super.onCreate(savedInstanceState);

    if (sGREDir == null) sGREDir = new File(this.getApplicationInfo().dataDir);

    getWindow()
        .setFlags(
            mFullscreen ? WindowManager.LayoutParams.FLAG_FULLSCREEN : 0,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    if (cameraView == null) {
      cameraView = new SurfaceView(this);
      cameraView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    if (surfaceView == null) surfaceView = new GeckoSurfaceView(this);
    else mainLayout.removeAllViews();

    mainLayout = new AbsoluteLayout(this);
    mainLayout.addView(
        surfaceView,
        new AbsoluteLayout.LayoutParams(
            AbsoluteLayout.LayoutParams.MATCH_PARENT, // level 8
            AbsoluteLayout.LayoutParams.MATCH_PARENT,
            0,
            0));

    setContentView(
        mainLayout,
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));

    mConnectivityFilter = new IntentFilter();
    mConnectivityFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    mConnectivityReceiver = new GeckoConnectivityReceiver();

    IntentFilter batteryFilter = new IntentFilter();
    batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
    mBatteryReceiver = new GeckoBatteryManager();
    registerReceiver(mBatteryReceiver, batteryFilter);

    if (SmsManager.getInstance() != null) {
      SmsManager.getInstance().start();
    }

    GeckoNetworkManager.getInstance().init();

    if (!checkAndSetLaunchState(LaunchState.PreLaunch, LaunchState.Launching)) return;

    checkAndLaunchUpdate();
    mLibLoadThread =
        new Thread(
            new Runnable() {
              public void run() {
                // At some point while loading the gecko libs our default locale gets set
                // so just save it to locale here and reset it as default after the join
                Locale locale = Locale.getDefault();
                GeckoAppShell.loadGeckoLibs(getApplication().getPackageResourcePath());
                Locale.setDefault(locale);
                Resources res = getBaseContext().getResources();
                Configuration config = res.getConfiguration();
                config.locale = locale;
                res.updateConfiguration(config, res.getDisplayMetrics());
              }
            });
    mLibLoadThread.start();
  }
Beispiel #26
0
 @Override
 public void onRestart() {
   Log.i(LOG_FILE_NAME, "restart");
   GeckoAppShell.putChildInForeground();
   super.onRestart();
 }
Beispiel #27
0
 @Override
 public boolean onPrepareOptionsMenu(Menu menu) {
   Log.d(TAG, "Prepare menu options");
   menu.findItem(R.id.loader_menu_refresh_map_list).setVisible(mLoader < 0);
   return true;
 }
Beispiel #28
0
 @Override
 public void onDestroy() {
   Log.d(TAG, "LoaderActivity destroyed");
   super.onDestroy();
 }
Beispiel #29
0
 @Override
 public void onLowMemory() {
   Log.e(LOG_FILE_NAME, "low memory");
   if (checkLaunchState(LaunchState.GeckoRunning)) GeckoAppShell.onLowMemory();
   super.onLowMemory();
 }
Beispiel #30
0
 @Override
 public void onConfigurationChanged(android.content.res.Configuration newConfig) {
   Log.i(LOG_FILE_NAME, "configuration changed");
   // nothing, just ignore
   super.onConfigurationChanged(newConfig);
 }